:root {
    --bg: #f4f8f7;
    --surface: #ffffff;
    --surface-2: #eaf2f0;
    --border: #d5e2df;
    --text: #12201e;
    --muted: #54675f;
    --accent: #0f766e;
    --accent-fort: #0b5a54;
    --accent-soft: #dff3ef;
    --on-accent: #ffffff;
    --danger: #b91c1c;
    --danger-soft: #fef2f2;
    --warn: #b45309;
    --warn-soft: #fff4e0;
    --ok: #047857;
    --code-bg: #10201e;
    --code-text: #dcf3ee;
    --boite: #0f766e;
    --boite-moyenne: #b45309;
    --boite-basse: #b91c1c;
    --zone: #2563eb;
    --shadow: 0 1px 2px rgba(10, 30, 28, .05), 0 4px 16px rgba(10, 30, 28, .05);
    --radius: 14px;
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b1a19; --surface: #112725; --surface-2: #17322f; --border: #28463f; --text: #e6f4f1; --muted: #9bb7b0;
        --accent: #2dd4bf; --accent-fort: #5eead4; --accent-soft: #14403a; --on-accent: #052e2a;
        --danger: #fca5a5; --danger-soft: #3a1d24; --warn: #fbbf24; --warn-soft: #3a2a0c; --ok: #34d399;
        --code-bg: #07110f; --boite: #2dd4bf; --boite-moyenne: #fbbf24; --boite-basse: #f87171; --zone: #60a5fa;
        --shadow: none; color-scheme: dark;
    }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    background: var(--bg); color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    overflow-wrap: break-word;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 1.1rem; margin-bottom: .75rem; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 1.25rem 0 .4rem; }
p { margin: 0 0 .6rem; }
a { color: var(--accent); }
code, kbd, pre, textarea { font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace; font-size: .88em; }
kbd { background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 0 .35em; }
.muted { color: var(--muted); font-size: .88rem; }
[hidden] { display: none !important; }
.cache { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.visuel-cache { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.skip { position: absolute; left: 16px; top: -60px; background: var(--accent); color: var(--on-accent); padding: .5rem .8rem; border-radius: 8px; z-index: 20; }
.skip:focus { top: 8px; }

/* ---------- Barre du haut ---------- */
.topbar {
    position: sticky; top: 0; z-index: 10;
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: .65rem max(16px, calc((100vw - 980px) / 2));
    background: color-mix(in srgb, var(--surface) 90%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}
.brand { display: flex; gap: .7rem; align-items: center; min-width: 0; text-decoration: none; color: var(--text); }
.brand img { border-radius: 8px; flex: none; }
.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.brand-text .muted { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topnav { display: flex; gap: 1rem; flex: none; }
.topnav a { font-weight: 600; text-decoration: none; padding: .3rem 0; }
.topnav a:hover { text-decoration: underline; }
@media (max-width: 420px) { .brand-text .muted { display: none; } }

main { max-width: 980px; margin: 0 auto; padding: 1.1rem 16px 2rem; display: flex; flex-direction: column; gap: 1rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); min-width: 0; }

/* ---------- Boutons et champs ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    min-height: 40px; padding: .45rem .95rem; border-radius: 10px;
    border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
    font: inherit; font-weight: 600; cursor: pointer; text-align: center;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-fort); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primaire { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primaire:hover:not(:disabled) { background: var(--accent-fort); border-color: var(--accent-fort); }
:root .btn-primaire:hover:not(:disabled) { color: var(--on-accent); }
.btn-grand { min-height: 46px; padding-inline: 1.4rem; font-size: 1rem; }
.rangee { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.actions { margin-top: 1rem; }

.champs { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .8rem; margin-bottom: .6rem; }
.champ { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; font-size: .88rem; min-width: 0; }
.champ-large { grid-column: 1 / -1; }
select, input[type="password"], input[type="text"], textarea {
    width: 100%; min-height: 40px; padding: .45rem .6rem; border-radius: 9px;
    border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 400;
}
textarea { resize: vertical; line-height: 1.45; min-height: 8rem; }
select, input[type="password"] { font-size: 16px; } /* évite le zoom automatique de iOS */

.avance { border-top: 1px solid var(--border); padding: .6rem 0 .1rem; margin-top: .5rem; }
.avance summary { cursor: pointer; font-weight: 600; padding: .25rem 0; }
.avance[open] summary { margin-bottom: .6rem; }
.pastille { display: inline-block; margin-left: .4rem; padding: 0 .55em; border-radius: 99px; font-size: .78rem; background: var(--accent-soft); color: var(--accent-fort); }
.pastille.mauvaise { background: var(--danger-soft); color: var(--danger); }

.limites { margin: .8rem 0 0; padding: .6rem .8rem; border-radius: 10px; background: var(--surface-2); font-size: .9rem; }
.limites.alerte { background: var(--warn-soft); color: var(--warn); }
.statut { margin: .6rem 0 0; color: var(--muted); min-height: 1.4em; }
.erreur { margin: .6rem 0 0; padding: .6rem .8rem; border-radius: 10px; background: var(--danger-soft); color: var(--danger); font-weight: 600; }

/* ---------- Dépôt ---------- */
.depot {
    display: flex; flex-direction: column; align-items: center; gap: .35rem; text-align: center;
    padding: 2rem 1rem; border: 2px dashed var(--border); border-radius: var(--radius);
    background: var(--surface-2); transition: border-color .15s, background .15s;
}
.depot.survol { border-color: var(--accent); background: var(--accent-soft); }
.depot-titre { font-size: 1.1rem; font-weight: 700; margin: 0; }
.depot .btn { margin: .5rem 0 .2rem; }
.depot p { margin: 0; }
#fichier:focus-visible + #depot-info { text-decoration: underline; }
.depot:focus-within .btn { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- Image et boîtes ---------- */
.scene-barre { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .6rem; margin-bottom: .6rem; }
.nom { margin: 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scene {
    position: relative; display: inline-block; max-width: 100%; line-height: 0; vertical-align: top;
    border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
    background: repeating-conic-gradient(var(--surface-2) 0% 25%, var(--surface) 0% 50%) 0 0 / 16px 16px;
}
.scene img { display: block; max-width: 100%; max-height: 70vh; height: auto; width: auto; user-select: none; -webkit-user-drag: none; }
.scene svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.scene.dessin svg { cursor: crosshair; touch-action: none; }
.scene.dessin { touch-action: pan-y; }
.boite { fill: transparent; stroke: var(--boite); stroke-width: 2; vector-effect: non-scaling-stroke; transition: fill .1s; }
.boite.moyenne { stroke: var(--boite-moyenne); }
.boite.basse { stroke: var(--boite-basse); stroke-dasharray: 5 3; }
.boite.actif { fill: color-mix(in srgb, var(--boite) 30%, transparent); stroke-width: 3; }
.boite.moyenne.actif { fill: color-mix(in srgb, var(--boite-moyenne) 30%, transparent); }
.boite.basse.actif { fill: color-mix(in srgb, var(--boite-basse) 30%, transparent); }
.zone-rect { fill: color-mix(in srgb, var(--zone) 14%, transparent); stroke: var(--zone); stroke-width: 2; vector-effect: non-scaling-stroke; }
.zone-rect.brouillon { stroke-dasharray: 6 4; }
.zone-num { fill: var(--zone); font-weight: 700; paint-order: stroke; stroke: #fff; stroke-width: 3px; stroke-linejoin: round; }
@media (prefers-color-scheme: dark) { .zone-num { stroke: #000; } }
.zones-liste { list-style: none; margin: .6rem 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.zones-liste li { display: inline-flex; align-items: center; gap: .3rem; padding: .15rem .2rem .15rem .7rem; border-radius: 99px; background: var(--accent-soft); font-size: .88rem; }
.zones-liste button { border: 0; background: none; color: inherit; cursor: pointer; font: inherit; min-width: 32px; min-height: 32px; border-radius: 99px; }
.zones-liste button:hover { background: var(--surface-2); }

/* ---------- Résultat ---------- */
.titre-rang { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: .5rem; }
.lignes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .3rem; }
.lignes li {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .6rem; align-items: baseline;
    padding: .4rem .65rem; border-radius: 9px; border: 1px solid var(--border); border-left: 4px solid var(--boite); background: var(--surface);
}
.lignes li.moyenne { border-left-color: var(--boite-moyenne); }
.lignes li.basse { border-left-color: var(--boite-basse); background: var(--warn-soft); }
.lignes li.actif, .lignes li:focus-visible { background: var(--accent-soft); border-color: var(--accent); }
.lignes .t { min-width: 0; }
.lignes .c { font-variant-numeric: tabular-nums; font-size: .82rem; color: var(--muted); white-space: nowrap; }
.lignes li.basse .c { color: var(--warn); font-weight: 700; }
.lignes .groupe { display: block; background: none; border: 0; padding: .6rem 0 .1rem; font-weight: 700; color: var(--zone); }

pre { margin: 0 0 .6rem; padding: .85rem 1rem; border-radius: 10px; background: var(--code-bg); color: var(--code-text); overflow-x: auto; max-width: 100%; }
pre code { font-size: .85rem; white-space: pre; }
:not(pre) > code { background: var(--surface-2); padding: .05em .35em; border-radius: 5px; }

.pied { max-width: 980px; margin: 0 auto; padding: 0 16px 2rem; }

@media (max-width: 600px) {
    .depot { padding: 1.4rem .8rem; }
    .btn { flex: 1 1 auto; }
    .rangee .muted { flex-basis: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
