:root {
  --fond: #f3efe6; --surface: #fffdf8; --surface2: #f8f4ec; --encre: #16202b; --doux: #6d6a62; --trait: #e4ddcf;
  --accent: #0f766e; --accent-encre: #ffffff;
  --critique: #c0392b; --alerte: #c77700; --info: #2563eb; --ok: #15803d;
  --critique-fond: #fbe9e6; --alerte-fond: #fdf1dc; --info-fond: #e7eefc; --ok-fond: #e3f3e7;
  --ombre: 0 1px 2px rgba(22,32,43,.06), 0 4px 16px rgba(22,32,43,.05);
  --rayon: 16px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fond: #0d1b2a; --surface: #13263a; --surface2: #182f47; --encre: #e8eef3; --doux: #93a4b5; --trait: #223a55;
    --accent: #2dd4bf; --accent-encre: #062a27;
    --critique: #f87171; --alerte: #fbbf24; --info: #60a5fa; --ok: #4ade80;
    --critique-fond: #3a1b20; --alerte-fond: #3a2e12; --info-fond: #172c4d; --ok-fond: #143324;
    --ombre: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--fond); color: var(--encre); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; min-height: 100vh;
}
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
p { margin: 0; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Connexion */
.connexion { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.connexion-carte { width: 100%; max-width: 380px; text-align: center; }
.connexion .logo { width: 84px; height: 84px; border-radius: 20px; box-shadow: var(--ombre); }
.connexion h1 { font-size: 30px; margin-top: 16px; }
.connexion form { margin-top: 28px; text-align: left; display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-size: 14px; color: var(--doux); font-weight: 500; }
input[type=password], input[type=text], input[type=date] {
  font: inherit; color: var(--encre); background: var(--surface); border: 1px solid var(--trait);
  border-radius: 12px; padding: 13px 14px; width: 100%; -webkit-appearance: none;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input[name=code] { font-size: 22px; letter-spacing: .25em; text-align: center; font-variant-numeric: tabular-nums; }
.erreur { color: var(--critique); font-size: 14px; min-height: 20px; }

/* ---------- Structure */
.entete {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 14px) 18px 12px; background: color-mix(in srgb, var(--fond) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.entete h1 { font-size: 28px; font-weight: 750; }
.sous { color: var(--doux); font-size: 14px; }
main { max-width: 560px; margin: 0 auto; padding: 4px 16px calc(env(safe-area-inset-bottom) + 96px); }
.onglet { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.btn-rond {
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--trait); background: var(--surface);
  display: grid; place-items: center; cursor: pointer; box-shadow: var(--ombre);
}
.btn-rond.tourne svg { animation: tourne 1s linear infinite; }
@keyframes tourne { to { transform: rotate(360deg); } }

.barre {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; justify-content: space-around;
  padding: 8px 6px calc(env(safe-area-inset-bottom) + 6px); border-top: 1px solid var(--trait);
  background: color-mix(in srgb, var(--surface) 90%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
.barre a {
  position: relative; flex: 1; display: grid; justify-items: center; gap: 2px; padding: 4px 0;
  color: var(--doux); text-decoration: none; font-size: 11px; font-weight: 600;
}
.barre a.actif { color: var(--accent); }
.barre svg { width: 25px; height: 25px; }
.compteur {
  position: absolute; top: 0; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--critique); color: #fff; font: 700 11px/18px system-ui; font-style: normal; text-align: center;
}
.bandeau {
  max-width: 528px; margin: 0 auto 8px; padding: 12px 14px; border-radius: 12px; font-size: 14px;
  background: var(--critique-fond); color: var(--critique); font-weight: 600;
}

/* ---------- Cartes */
.carte { background: var(--surface); border: 1px solid var(--trait); border-radius: var(--rayon); padding: 16px; box-shadow: var(--ombre); }
.carte > h2, .titre-section { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--doux); font-weight: 700; }
.carte > h2 { margin-bottom: 10px; }
.titre-section { margin: 10px 4px -4px; }
.vide { color: var(--doux); font-size: 15px; }

.score { display: flex; align-items: center; gap: 18px; }
.anneau { position: relative; width: 96px; height: 96px; flex: none; }
.anneau svg { width: 96px; height: 96px; transform: rotate(-90deg); }
.anneau circle { stroke-width: 9; fill: none; }
.anneau .piste { stroke: var(--trait); }
.anneau .valeur { stroke-linecap: round; transition: stroke-dashoffset .8s ease; }
.anneau b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }
.score h2 { font-size: 21px; font-weight: 750; }
.score p { color: var(--doux); font-size: 14px; margin-top: 4px; }

.jauges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.jauge { background: var(--surface); border: 1px solid var(--trait); border-radius: 14px; padding: 12px; box-shadow: var(--ombre); }
.jauge span { display: block; font-size: 12px; color: var(--doux); font-weight: 600; }
.jauge b { font-size: 21px; font-variant-numeric: tabular-nums; }
.barre-pct { height: 5px; border-radius: 3px; background: var(--trait); margin-top: 8px; overflow: hidden; }
.barre-pct i { display: block; height: 100%; background: var(--ok); border-radius: 3px; }
.barre-pct i.moyen { background: var(--alerte); } .barre-pct i.haut { background: var(--critique); }

/* ---------- Anomalies */
.anomalie { background: var(--surface); border: 1px solid var(--trait); border-left: 5px solid var(--g); border-radius: 14px; padding: 14px 14px 12px; box-shadow: var(--ombre); }
.g-critique { --g: var(--critique); --gf: var(--critique-fond); }
.g-alerte { --g: var(--alerte); --gf: var(--alerte-fond); }
.g-info { --g: var(--info); --gf: var(--info-fond); }
.anomalie .etiquette { display: inline-block; font-size: 11px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; color: var(--g); background: var(--gf); padding: 2px 8px; border-radius: 6px; }
.anomalie h3 { font-size: 17px; margin-top: 6px; line-height: 1.3; }
.anomalie .detail { color: var(--doux); font-size: 14px; margin-top: 4px; }
.anomalie details { margin-top: 10px; }
.anomalie summary { cursor: pointer; font-weight: 650; font-size: 15px; color: var(--accent); list-style: none; }
.anomalie summary::-webkit-details-marker { display: none; }
.anomalie summary::before { content: "▸ "; }
.anomalie details[open] summary::before { content: "▾ "; }
.anomalie ol { margin: 8px 0 0; padding-left: 20px; font-size: 15px; display: grid; gap: 6px; }
.anomalie ol li::marker { color: var(--doux); font-weight: 700; }
.anomalie code, .code { font: 13px ui-monospace, "SF Mono", Menlo, monospace; background: var(--surface2); padding: 1px 5px; border-radius: 5px; word-break: break-word; }
.anomalie .bas { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }
.anomalie small { color: var(--doux); font-size: 12px; }
.anomalie.surligne { animation: surligne 1.6s ease 2; }
@keyframes surligne { 50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--g) 35%, transparent); } }

/* ---------- Listes */
.liste { display: grid; grid-template-columns: minmax(0, 1fr); }
.ligne { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--trait); }
.ligne:first-child { border-top: 0; padding-top: 2px; }
.ligne .txt { flex: 1; min-width: 0; }
.ligne .txt b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ligne .txt span { display: block; color: var(--doux); font-size: 13px; overflow-wrap: anywhere; }
.point { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--ok); box-shadow: 0 0 0 4px var(--ok-fond); }
.point.ko { background: var(--critique); box-shadow: 0 0 0 4px var(--critique-fond); }
.point.moyen { background: var(--alerte); box-shadow: 0 0 0 4px var(--alerte-fond); }
.puce { font-size: 12px; font-weight: 750; padding: 4px 9px; border-radius: 999px; white-space: nowrap; background: var(--ok-fond); color: var(--ok); }
.puce.alerte { background: var(--alerte-fond); color: var(--alerte); }
.puce.critique { background: var(--critique-fond); color: var(--critique); }
.puce.neutre { background: var(--surface2); color: var(--doux); }

/* ---------- Boutons */
.btn {
  border: 0; border-radius: 11px; padding: 10px 14px; font-weight: 650; font-size: 15px; cursor: pointer;
  background: var(--surface2); color: var(--encre); border: 1px solid var(--trait); white-space: nowrap;
}
.btn.principal { background: var(--accent); color: var(--accent-encre); border-color: transparent; }
.btn.danger { background: var(--critique); color: #fff; border-color: transparent; }
.btn.petit { padding: 7px 11px; font-size: 14px; border-radius: 9px; }
.btn.large { width: 100%; padding: 14px; font-size: 17px; }
.btn:disabled { opacity: .55; }
.btn:active:not(:disabled) { transform: scale(.98); }
.rangee { display: flex; gap: 10px; flex-wrap: wrap; }
.rangee .btn { flex: 1; }

.interrupteur { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--trait); }
.interrupteur:first-of-type { border-top: 0; }
.interrupteur input { appearance: none; -webkit-appearance: none; width: 51px; height: 31px; border-radius: 16px; background: var(--trait); position: relative; flex: none; cursor: pointer; transition: background .2s; }
.interrupteur input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.2); transition: transform .2s; }
.interrupteur input:checked { background: var(--ok); }
.interrupteur input:checked::after { transform: translateX(20px); }
.aide { font-size: 14px; color: var(--doux); }
.aide ol { padding-left: 20px; margin: 8px 0 0; display: grid; gap: 4px; }
.formulaire { display: grid; gap: 12px; margin-top: 4px; }

/* ---------- Feuille, toast */
.voile { position: fixed; inset: 0; background: rgba(5,12,20,.45); z-index: 20; animation: apparait .2s; }
.feuille {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-width: 560px; margin: 0 auto; max-height: 85vh; overflow: auto;
  background: var(--surface); border-radius: 22px 22px 0 0; padding: 10px 20px calc(env(safe-area-inset-bottom) + 20px);
  animation: monte .25s ease;
}
.feuille::before { content: ""; display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--trait); margin: 0 auto 14px; }
.feuille h2 { font-size: 20px; margin-bottom: 8px; }
.feuille pre { white-space: pre-wrap; word-break: break-word; font: 13px/1.5 ui-monospace, Menlo, monospace; background: var(--surface2); border-radius: 10px; padding: 12px; max-height: 40vh; overflow: auto; }
.feuille .rangee { margin-top: 16px; }
@keyframes monte { from { transform: translateY(100%); } }
@keyframes apparait { from { opacity: 0; } }
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 92px); transform: translateX(-50%); z-index: 30;
  background: var(--encre); color: var(--fond); padding: 11px 18px; border-radius: 999px; font-weight: 600; font-size: 15px;
  max-width: 90vw; text-align: center; box-shadow: 0 6px 24px rgba(0,0,0,.25); animation: apparait .2s;
}
.charge { display: inline-block; width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: tourne .7s linear infinite; vertical-align: -3px; }

/* ---------- Fichiers et logiciels */
.admin-bandeau { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px 10px 14px;
  border-radius: 12px; background: var(--alerte-fond); color: var(--alerte); font-weight: 650; font-size: 14px; }
.fil { font: 13px/1.4 ui-monospace, "SF Mono", Menlo, monospace; color: var(--doux); word-break: break-all; }
.fichier { cursor: pointer; }
.fichier .ico { font-size: 22px; width: 28px; text-align: center; flex: none; }
.menu { display: grid; gap: 8px; margin-top: 14px; }
.menu .btn { width: 100%; padding: 13px; }
.envoi { margin-top: 10px; font-size: 13px; color: var(--doux); }
.envoi .barre-pct i { background: var(--accent); transition: width .2s; }
.recherche { display: flex; gap: 8px; }
.recherche input { flex: 1; min-width: 0; }
.barre a span { font-size: 10px; }

/* ---------- Face ID et terminal */
.faceid { text-align: center; }
.faceid .visage { width: 64px; height: 64px; color: var(--accent); stroke-width: 1.4; margin: 6px auto 10px; display: block; }
.faceid .aide { margin-bottom: 4px; }
.carte-terminal { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; cursor: pointer; font: inherit; color: inherit; }
.carte-terminal .ico-term { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; flex: none;
  background: #0b1420; color: #2dd4bf; font: 700 16px ui-monospace, Menlo, monospace; }
.carte-terminal .txt { flex: 1; display: grid; }
.carte-terminal .txt span { color: var(--doux); font-size: 13px; }
.carte-terminal .chevron { font-size: 26px; color: var(--doux); }
.terminal { position: fixed; left: 0; right: 0; top: 0; height: 100vh; z-index: 40; background: #0b1420; display: flex; flex-direction: column; }
.terminal-ouvert { overflow: hidden; }
.terminal-haut { display: flex; align-items: center; justify-content: space-between; padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  color: #93a4b5; font: 600 14px ui-monospace, Menlo, monospace; border-bottom: 1px solid #1c2c3f; }
.terminal-haut .btn { background: #172435; color: #e6edf3; border-color: #223a55; }
.terminal-ecran { flex: 1; min-height: 0; padding: 6px 4px 0 8px; }
.terminal-touches { display: flex; gap: 6px; overflow-x: auto; padding: 8px 8px calc(env(safe-area-inset-bottom) + 8px); background: #101c2b; border-top: 1px solid #1c2c3f; }
.terminal-touches button { flex: none; min-width: 42px; height: 38px; padding: 0 10px; border-radius: 8px; border: 1px solid #223a55;
  background: #172435; color: #e6edf3; font: 600 14px ui-monospace, Menlo, monospace; }
.terminal-touches button.actif { background: #2dd4bf; color: #062a27; }
