/*
 * SOLYMEPE — Système Qualité
 * Feuille de style unique, reprise de l'application HTML d'origine et adaptée
 * au rendu serveur : les onglets sont des liens, les sections repliables des
 * éléments <details>, et les fenêtres modales sont devenues des pages.
 */

:root {
  --primary: #4B3E91;
  --primary-dark: #3A2F73;
  --secondary: #6BB6C9;
  --bg: #F5F6FA;
  --card: #FFFFFF;
  --border: #E2E5EE;
  --text: #1F2235;
  --text-muted: #6B7188;
  --success: #2BA84A;
  --danger: #D9342B;
  --warning: #E89B0E;
  --shadow: 0 2px 8px rgba(31, 34, 53, 0.06);
  --shadow-lg: 0 8px 24px rgba(31, 34, 53, 0.10);
  --radius: 10px;
  --pilotage: #6BB6C9;
  --realisation: #4B3E91;
  --supports: #E89B0E;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
body { min-height: 100vh; }
a { color: var(--primary); }

/* ------------------------------- En-tête ------------------------------- */

header.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 50;
}
header.topbar img { height: 44px; }
header.topbar .title { font-weight: 600; font-size: 16px; color: var(--primary); text-decoration: none; display: block; }
header.topbar .subtitle { font-size: 12px; color: var(--text-muted); }
header.topbar .admin-status { margin-left: auto; display: flex; align-items: center; gap: 10px; }

nav.tabs {
  display: flex;
  gap: 2px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  overflow-x: auto;
}
nav.tabs a {
  padding: 14px 18px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
nav.tabs a:hover { color: var(--primary); }
nav.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }

main { padding: 20px 24px; max-width: 1500px; margin: 0 auto; }

/* -------------------------------- Cartes ------------------------------- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card h2 {
  font-size: 16px;
  color: var(--primary);
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.card h3 { font-size: 14px; color: var(--text); margin: 14px 0 8px; }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.grid-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

@media (max-width: 760px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  main { padding: 12px; }
  header.topbar { padding: 10px 12px; flex-wrap: wrap; }
}

/* ----------------------------- Formulaires ----------------------------- */

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.field input,
.field select,
.field textarea {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  background: #FFF;
  width: 100%;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(75, 62, 145, 0.12);
}
.field input:disabled { background: #F1F2F7; color: var(--text-muted); }
.field .help { font-size: 12px; color: var(--text-muted); }
.field .errors { font-size: 12px; color: var(--danger); list-style: none; }
.field.has-error input,
.field.has-error select,
.field.has-error textarea { border-color: var(--danger); }

/* ------------------------------- Boutons ------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary);
  color: white;
  border: none;
  padding: 9px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--primary-dark); color: white; }
.btn.secondary { background: var(--secondary); }
.btn.secondary:hover { background: #559DAF; }
.btn.outline { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
.btn.outline:hover { background: var(--primary); color: white; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #B82923; }
.btn.warn { background: var(--warning); }
.btn.warn:hover { background: #C9860C; }
.btn.small { padding: 5px 10px; font-size: 12px; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; align-items: center; }
.actions form { display: inline; }

/* ------------------------------- Tableaux ------------------------------ */

table { width: 100%; border-collapse: collapse; font-size: 13px; }
table thead th {
  background: #F1F2F7;
  text-align: left;
  padding: 10px 8px;
  font-weight: 600;
  color: var(--primary);
  border-bottom: 2px solid var(--border);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
table tbody td { padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table tbody tr:hover { background: #FAFAFD; }
table tbody td a.ligne { color: inherit; text-decoration: none; display: block; }
table tbody td a.ligne:hover { color: var(--primary); }
.table-wrap { overflow-x: auto; }

/* ------------------------------- Badges -------------------------------- */

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.badge.success { background: #E6F5EA; color: var(--success); }
.badge.danger { background: #FBE7E5; color: var(--danger); }
.badge.warning { background: #FCF1D8; color: var(--warning); }
.badge.info { background: #E4F1F5; color: #2C7E94; }
.badge.muted { background: #ECEDF2; color: var(--text-muted); }
.badge.pilotage { background: #E4F1F5; color: #2C7E94; }
.badge.realisation { background: #ECE9F7; color: var(--primary); }
.badge.supports { background: #FCF1D8; color: #815700; }

/* ------------------------- Messages et encadrés ------------------------ */

.empty { text-align: center; padding: 40px 20px; color: var(--text-muted); font-style: italic; }
.notice { padding: 10px 12px; border-radius: 6px; font-size: 13px; margin-bottom: 12px; }
.notice.info { background: #E4F1F5; color: #1E5F73; border-left: 3px solid var(--secondary); }
.notice.warn { background: #FCF1D8; color: #815700; border-left: 3px solid var(--warning); }
.notice.danger { background: #FBE7E5; color: #7C1813; border-left: 3px solid var(--danger); }
.notice.success { background: #E6F5EA; color: #1B6B31; border-left: 3px solid var(--success); }
.subtle { color: var(--text-muted); font-size: 12px; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }

/* ------------------------------ Barre d'outils ------------------------- */

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.toolbar input.search {
  flex: 1;
  min-width: 200px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
}
.toolbar select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: #FFF;
}
.toolbar form.filtres { display: flex; gap: 10px; flex-wrap: wrap; flex: 1; align-items: center; }

/* ------------------------------ Statistiques --------------------------- */

.stat-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 16px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  box-shadow: var(--shadow);
  text-decoration: none;
  display: block;
  color: inherit;
}
.stat-card .number { font-size: 28px; font-weight: 700; color: var(--primary); line-height: 1.1; }
.stat-card .label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-top: 4px;
}
.stat-card.warn .number { color: var(--warning); }
.stat-card.danger .number { color: var(--danger); }
.stat-card.success .number { color: var(--success); }

/* Répartition par processus */
.repartition { display: flex; flex-direction: column; gap: 10px; }
.repartition .ligne { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.repartition .nom { width: 110px; font-weight: 600; }
.repartition .barre { flex: 1; height: 10px; background: var(--bg); border-radius: 6px; overflow: hidden; }
.repartition .barre span { display: block; height: 100%; border-radius: 6px; }
.repartition .barre span.pilotage { background: var(--pilotage); }
.repartition .barre span.realisation { background: var(--realisation); }
.repartition .barre span.supports { background: var(--supports); }
.repartition .valeur { width: 40px; text-align: right; color: var(--text-muted); }

/* --------------------------- Historique / fichiers --------------------- */

.history-item {
  border-left: 3px solid var(--primary);
  padding: 10px 12px;
  background: #FAFAFD;
  margin-bottom: 8px;
  border-radius: 0 6px 6px 0;
}
.history-item .head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.history-item .rev { font-weight: 700; color: var(--primary); }
.history-item .date { font-size: 12px; color: var(--text-muted); }
.history-item .motif { margin-top: 4px; font-size: 13px; }
.history-item .actions-line { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

.file-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--primary);
  text-decoration: none;
  font-size: 12px;
  padding: 3px 8px;
  background: #F1F2F7;
  border-radius: 4px;
}
.file-link:hover { background: #E2E5EE; }

/* ------------------------------- Alertes ------------------------------- */

.alert-row td { background: #FFF7E6; }
.alert-row.critical td { background: #FDECEB; }

.alert-card {
  border-left: 4px solid var(--warning);
  padding: 12px 14px;
  margin-bottom: 10px;
  background: #FFFDF7;
  border-radius: 0 6px 6px 0;
}
.alert-card.critical { border-color: var(--danger); background: #FFF7F6; }
.alert-card .ref { font-weight: 700; color: var(--primary); text-decoration: none; }
.alert-card .title { color: var(--text); font-weight: 500; }
.alert-card .meta { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.alert-card .actions-line { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* ------------------------ Arborescence des processus ------------------- */

.process-section { margin-bottom: 20px; }
.process-section > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--primary);
  color: white;
  border-radius: var(--radius) var(--radius) 0 0;
  cursor: pointer;
  list-style: none;
}
.process-section > summary::-webkit-details-marker { display: none; }
.process-section.pilotage > summary { background: var(--pilotage); }
.process-section.realisation > summary { background: var(--realisation); }
.process-section.supports > summary { background: var(--supports); }
.process-section > summary h2 { color: white; font-size: 15px; margin: 0; padding: 0; border: 0; }
.process-section > summary .count {
  background: rgba(255, 255, 255, 0.25);
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
}
.process-section > summary .toggle { margin-left: auto; font-size: 18px; }
.process-section > summary::after { content: '−'; margin-left: auto; font-size: 18px; }
.process-section:not([open]) > summary::after { content: '+'; }

.subprocess > summary {
  background: var(--card);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  list-style: none;
}
.subprocess > summary::-webkit-details-marker { display: none; }
.subprocess > summary:hover { background: #FAFAFD; }
.subprocess > summary .name { font-weight: 600; color: var(--text); }
.subprocess > summary .count {
  background: var(--bg);
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  color: var(--text-muted);
}
.subprocess > summary::after { content: '−'; margin-left: auto; color: var(--text-muted); }
.subprocess:not([open]) > summary::after { content: '+'; }
.subprocess .contenu { background: var(--card); border-bottom: 1px solid var(--border); }

.process-tag {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* ------------------------------- Connexion ----------------------------- */

.login-pad { display: flex; gap: 6px; align-items: center; }
.login-pad input {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  max-width: 150px;
}

/* ------------------------------ Assistant ------------------------------ */

.chat {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #FAFAFD;
  padding: 16px;
  min-height: 260px;
  max-height: 60vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 12px;
}
.chat-msg { display: flex; }
.chat-msg.user { justify-content: flex-end; }
.chat-msg .bulle {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.55;
}
.chat-msg.user .bulle {
  background: var(--primary);
  color: #FFF;
  border-bottom-right-radius: 3px;
}
.chat-msg.assistant .bulle {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 3px;
}
.chat-msg.assistant .bulle p { margin-bottom: 8px; }
.chat-msg.assistant .bulle p:last-child { margin-bottom: 0; }
.chat-msg.assistant .bulle ul,
.chat-msg.assistant .bulle ol { margin: 6px 0 10px 20px; }
.chat-msg.assistant .bulle li { margin-bottom: 4px; }
.chat-msg.assistant .bulle h4 { color: var(--primary); font-size: 14px; margin: 10px 0 6px; }
.chat-msg.assistant .bulle table { margin: 8px 0; font-size: 13px; }
.chat-msg.assistant .bulle th,
.chat-msg.assistant .bulle td { border: 1px solid var(--border); padding: 5px 8px; text-align: left; }
.chat-msg.assistant .bulle th { background: #F1F2F7; color: var(--primary); }
.chat-msg.assistant .bulle code {
  background: #F1F2F7;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}
.chat-attente { color: var(--text-muted); font-style: italic; }

.chat-vide { color: var(--text-muted); font-size: 13px; margin: auto 0; }
.chat-vide ul { margin: 8px 0 0 20px; }
.chat-vide li { margin-bottom: 4px; }

.chat-form { display: flex; gap: 10px; align-items: flex-end; }
.chat-form textarea {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  min-height: 44px;
}
.chat-form textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(75, 62, 145, 0.12);
}
.chat-form.chat-desactive textarea { background: #F1F2F7; }

/* ------------------------------ Connexion ------------------------------ */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
}
.login-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 32px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.login-box .login-logo { max-height: 64px; margin-bottom: 16px; }
.login-box h1 { font-size: 20px; color: var(--primary); margin-bottom: 4px; }
.login-box .subtitle { color: var(--text-muted); font-size: 13px; margin-bottom: 20px; }
.login-box .field { text-align: left; }

.hidden { display: none !important; }

/* ---- Module Indicateurs : mini-graphique en barres ---- */
.ligne-famille td { background: var(--bg); color: var(--text-muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; }
.graphe { margin: .5rem 0; }
.graphe-ligne { display: flex; align-items: center; gap: .6rem; margin: .28rem 0; }
.graphe-label { flex: 0 0 60px; font-size: .82rem; color: var(--text-muted); text-align: right; }
.graphe-piste { flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; height: 18px; overflow: hidden; }
.graphe-barre { display: block; height: 100%; border-radius: 5px 0 0 5px; background: var(--secondary); }
.graphe-barre.success { background: var(--success); }
.graphe-barre.danger { background: var(--danger); }
.graphe-barre.warning { background: var(--warning); }
.graphe-barre.muted { background: var(--secondary); }
.graphe-valeur { flex: 0 0 110px; font-size: .9rem; }

/* ---- Saisie assistée des mesures ---- */
.bloc-assiste { margin: .5rem 0 1rem; border: 1px dashed var(--border); border-radius: 8px; padding: .3rem .8rem; background: var(--bg); }
.bloc-assiste summary { cursor: pointer; color: var(--primary); font-size: .92rem; padding: .3rem 0; }
