/*
 * EasyDPM - one stylesheet, no framework.
 *
 * Tokens first; every colour below is one of them, redefined for dark mode.
 * The scene colours (dose, chute, gripper) are the ones the DPM viewer uses,
 * so the two tools read the same way. The drop is blue here, where the viewer
 * has it magenta: next to the red of a cut through a dose it read as one.
 *
 * Nothing is fetched from outside: the application has to run offline. The
 * fonts are IBM Plex, served from static/fonts (SIL Open Font License, see
 * OFL.txt there), Latin subset - which covers French.
 */

@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 400; font-display: swap; src: url("../fonts/ibm-plex-sans-400.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 500; font-display: swap; src: url("../fonts/ibm-plex-sans-500.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 600; font-display: swap; src: url("../fonts/ibm-plex-sans-600.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 700; font-display: swap; src: url("../fonts/ibm-plex-sans-700.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 400; font-display: swap; src: url("../fonts/ibm-plex-mono-400.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 500; font-display: swap; src: url("../fonts/ibm-plex-mono-500.woff2") format("woff2"); }

:root {
    --paper: #f3f5f7;
    --surface: #ffffff;
    --surface-2: #f8fafb;
    --ink: #141a21;
    --muted: #5b6571;
    --faint: #8a939e;
    --rule: #d8dee5;
    --rule-soft: #e8ecf0;
    --seg-on: var(--surface);         /* a switch's pressed button, raised above its track */
    --seg-on-shadow: var(--shadow);

    --accent: #1a6f78;
    --accent-hover: #155d65;
    --accent-ink: #ffffff;
    --accent-soft: #e2f0f1;
    --focus: #2b8a95;

    --cut: #1a6f78;
    --chute: #b0660c;
    --drop: #2f5fc4;
    --grip: #5a4fa8;

    --ok: #1f7a4d;
    --ok-soft: #e4f3eb;
    --warn: #8a5a00;
    --warn-soft: #fcf2dc;
    --warn-rule: #ecd39a;
    --bad: #a3254a;
    --bad-soft: #fbe9ee;
    --bad-rule: #eeb9c8;

    --scene-paper: #eef1f4;
    --scene-grid: rgba(60, 80, 100, 0.10);
    --scene-grid-mid: rgba(60, 80, 100, 0.20);
    --scene-grid-major: rgba(60, 80, 100, 0.34);
    --scene-halo: rgba(255, 255, 255, 0.85);
    --scene-ink: #20262d;       /* the blister's outline, its axes and their labels */
    --scene-mark: #5b6571;      /* the pillars and the zone around the die */
    --scene-mark-ink: #3d4651;  /* their labels */

    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.07);
    --shadow-lg: 0 10px 30px rgba(16, 24, 40, 0.14);
    --topbar-h: 68px;

    --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;

    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --paper: #0f1318;
        --surface: #161c23;
        --surface-2: #1b222a;
        --ink: #e5ebf1;
        --muted: #9aa5b2;
        --faint: #6e7986;
        --rule: #2a333e;
        --rule-soft: #212932;
        /* lighter than the track, which is darker than the page: a shadow does not show on it */
        --seg-on: #36414e;
        --seg-on-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.10), 0 1px 2px rgba(0, 0, 0, 0.5);
        --accent: #4fb3bd;
        --accent-hover: #6cc3cc;
        --accent-ink: #0b1317;
        --accent-soft: #173238;
        --focus: #6cc3cc;
        --cut: #54b8c2;
        --chute: #dc9f45;
        --drop: #7ea3f0;
        --grip: #a298ec;
        --ok: #5cc590;
        --ok-soft: #163226;
        --warn: #e0b35c;
        --warn-soft: #2d2513;
        --warn-rule: #5a4a22;
        --bad: #ec7497;
        --bad-soft: #33161f;
        --bad-rule: #5c2a3a;
        --scene-paper: #1a2129;
        --scene-grid: rgba(180, 200, 220, 0.10);
        --scene-grid-mid: rgba(180, 200, 220, 0.18);
        --scene-grid-major: rgba(180, 200, 220, 0.30);
        --scene-halo: rgba(12, 16, 20, 0.75);
        --scene-ink: #d6dde5;
        --scene-mark: #8d99a6;
        --scene-mark-ink: #c9d1da;
        --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
        --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5);
        color-scheme: dark;
    }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font: 15px/1.5 var(--font);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
p { margin: 0; }
img { max-width: 100%; }
[hidden] { display: none !important; }

:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

.icon { flex: none; display: block; }

/* ------------------------------------------------------------------ top bar */

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    height: var(--topbar-h);
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 16px;
    padding: 0 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--rule);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
/* the mark, the name and the client's logo all stand the same 40 px tall */
.brand-mark { width: 40px; height: 40px; object-fit: contain; }
.brand-name { font-weight: 700; font-size: 29px; line-height: 1; letter-spacing: -0.02em; }
.brand-client {
    height: 40px;
    width: auto;
    margin-left: 8px;
    padding-left: 14px;
    border-left: 1px solid var(--rule);
}
.topbar-actions { display: flex; justify-content: flex-end; align-items: center; gap: 4px; }

/* the login: the whole window, until somebody is logged in */
.login {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 16px;
    background: var(--paper);
}
.login-card {
    width: min(100%, 380px);
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 28px 28px 24px;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow, 0 6px 24px rgba(0, 0, 0, 0.08));
}
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card .lede { margin: -8px 0 4px; }
.login-card input { font-family: inherit; min-height: 40px; }

.stepper { display: flex; align-items: center; gap: 4px; }
.stepper-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px 6px 6px;
    border: 0;
    border-radius: 999px;
    background: none;
    color: var(--muted);
    font: 500 14px var(--font);
    cursor: pointer;
    white-space: nowrap;
}
.stepper-item:disabled { cursor: default; color: var(--faint); }
.stepper-item:not(:disabled):hover { background: var(--surface-2); color: var(--ink); }
.stepper-mark {
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 1.5px solid var(--rule);
    font: 600 13px var(--font);
    background: var(--surface);
}
.stepper-item.is-current { color: var(--ink); font-weight: 600; }
.stepper-item.is-current .stepper-mark {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
}
.stepper-item.is-done .stepper-mark {
    background: var(--accent-soft);
    border-color: var(--accent-soft);
    color: var(--accent);
}
.stepper-item.is-open .stepper-mark { border-color: var(--accent); color: var(--accent); }
.stepper-link { width: 28px; height: 1.5px; background: var(--rule); }
.stepper-link.is-done { background: var(--accent); }

/* ------------------------------------------------------------------- layout */

.main { max-width: 1200px; margin: 0 auto; padding: 28px 20px 64px; }
.main:has(.step--wide:not([hidden])) { max-width: 1680px; padding-top: 16px; padding-bottom: 16px; }

.step { display: flex; flex-direction: column; gap: 18px; }

.step-head { display: flex; flex-direction: column; gap: 4px; margin-bottom: 4px; }
.eyebrow {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent);
}
.step-head h1 { font-size: 28px; letter-spacing: -0.02em; font-weight: 650; }
.lede { color: var(--muted); max-width: 70ch; }

.step-foot {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 16px;
    padding-top: 4px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}
.card--tight { padding: 14px 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.card-title { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card > .card-title { margin-bottom: 12px; }
.card-note { color: var(--muted); font-size: 13px; }
.card > .card-note { margin: -6px 0 12px; }

.hint { color: var(--muted); font-size: 13px; }
.hint--right { text-align: right; }
.empty { color: var(--muted); font-size: 13px; padding: 14px 4px 4px; text-align: center; }

.row-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }

/* ------------------------------------------------------------------ buttons */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 36px;
    padding: 7px 14px;
    border: 1px solid var(--rule);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink);
    font: 500 14px var(--font);
    cursor: pointer;
    transition: background-color 0.12s, border-color 0.12s, color 0.12s;
    white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--faint); background: var(--surface-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn--primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn--ghost:hover:not(:disabled) { background: var(--surface-2); border-color: var(--rule); color: var(--ink); }
.btn--small { min-height: 30px; padding: 4px 10px; font-size: 13px; }
.btn--large { min-height: 44px; padding: 10px 20px; font-size: 15px; font-weight: 600; }
.btn--block { width: 100%; }
.btn--reset.is-armed,
.btn--reset.is-armed:hover:not(:disabled) { background: var(--bad-soft); border-color: var(--bad-rule); color: var(--bad); }

.btn[aria-pressed="true"].btn--ghost { background: var(--accent-soft); color: var(--accent); }

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); border-color: var(--rule); color: var(--ink); }
.icon-btn:disabled { opacity: 0.3; cursor: default; }
.icon-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-soft); }
.icon-btn--danger:hover:not(:disabled) { color: var(--bad); background: var(--bad-soft); border-color: var(--bad-rule); }

.seg {
    display: inline-flex;
    padding: 3px;
    gap: 2px;
    border-radius: 8px;
    background: var(--surface-2);
    border: 1px solid var(--rule);
}
.seg button {
    border: 0;
    border-radius: 6px;
    padding: 5px 12px;
    background: transparent;
    color: var(--muted);
    font: 500 13px var(--font);
    cursor: pointer;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--seg-on); color: var(--ink); box-shadow: var(--seg-on-shadow); }
.seg--small button { padding: 3px 12px; }

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
.spinner--large { width: 34px; height: 34px; border-width: 3px; color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------ small pieces */

.chip {
    display: inline-flex;
    align-items: center;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    background: var(--surface-2);
    color: var(--muted);
    border: 1px solid var(--rule);
}
.chip--pince, .chip--ventouse { background: color-mix(in srgb, var(--grip) 12%, transparent); color: var(--grip); border-color: transparent; }

.badge {
    display: inline-grid;
    place-items: center;
    min-width: 22px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 12px;
    font-weight: 600;
}

.notice {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 12px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--rule);
    background: var(--surface);
    font-size: 14px;
}
.notice .icon { margin-top: 1px; }
.notice strong { display: block; font-weight: 600; }
.notice p { color: inherit; opacity: 0.9; }
.notice--warn { background: var(--warn-soft); border-color: var(--warn-rule); color: var(--warn); }
.notice--bad { background: var(--bad-soft); border-color: var(--bad-rule); color: var(--bad); }
.notice--ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.notice--compact { padding: 8px 10px; font-size: 13px; gap: 8px; margin-top: 10px; }
.trim-warn, .split-warn, .pillar-warn, .zone-warn { margin: 4px 0 6px; }

/* the checks switched off: one line in the footer, its explanation in the
   tooltip, and red once ticked */
.bypass {
    flex-basis: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border: 1px dashed var(--rule);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    color: var(--muted);
}
.bypass input { width: 15px; height: 15px; margin: 0; accent-color: var(--bad); flex: none; }
.bypass:has(input:checked) { border-style: solid; border-color: var(--bad-rule); background: var(--bad-soft); color: var(--bad); font-weight: 600; }

/* a warning folded to one line, its explanation on demand */
.fold { margin: 4px 0; border: 1px solid var(--rule); border-radius: var(--radius-sm); font-size: 13px; }
.fold > summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    cursor: pointer;
    list-style: none;
}
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary strong { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fold > summary::after { content: "▸"; color: var(--faint); transition: transform 0.15s; }
.fold[open] > summary::after { transform: rotate(90deg); }
.fold[open] > summary strong { white-space: normal; }
.fold-body { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 0 10px 8px 34px; color: var(--ink); }
.fold--warn { background: var(--warn-soft); border-color: var(--warn-rule); color: var(--warn); }
.fold--bad { background: var(--bad-soft); border-color: var(--bad-rule); color: var(--bad); }
.notice ul { margin: 4px 0 0; padding-left: 18px; }
.notice .btn { margin-top: 8px; }

.facts {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 14px;
    margin: 0;
    font-size: 14px;
}
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-family: var(--mono); font-size: 13.5px; }

kbd {
    display: inline-block;
    padding: 0 5px;
    border: 1px solid var(--rule);
    border-bottom-width: 2px;
    border-radius: 4px;
    background: var(--surface-2);
    font: 500 11.5px var(--mono);
    line-height: 18px;
}

.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.field > span { letter-spacing: 0.02em; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"], input[type="text"], input[type="password"], select {
    width: 100%;
    min-height: 34px;
    padding: 6px 9px;
    border: 1px solid var(--rule);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink);
    font: 400 14px var(--mono);
}
input[type="number"]:focus, input[type="text"]:focus, input[type="password"]:focus, select:focus {
    border-color: var(--focus);
    outline: none;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent);
}
/* an empty field's example, far enough from a real value to tell them apart */
input::placeholder { color: var(--faint); font-style: italic; opacity: 1; }
.field-hint { font-weight: 400; color: var(--muted); }
.field-hint.is-ok { color: var(--ok); }

/* ----------------------------------------------------------- 1 Entrées */

.machines {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 12px;
}
.machine {
    position: relative;
    display: grid;
    grid-template-rows: auto auto auto;
    justify-items: center;
    gap: 6px;
    padding: 14px 12px 12px;
    border: 1.5px solid var(--rule);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
    transition: border-color 0.12s, box-shadow 0.12s;
}
.machine:hover { border-color: var(--faint); }
.machine input { position: absolute; opacity: 0; pointer-events: none; }
.machine:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.machine.is-selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}
.machine-image { display: grid; place-items: center; width: 100%; height: 104px; }
.machine-image img { max-height: 104px; object-fit: contain; }
.machine-name { font-weight: 600; }

.slots { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.slot {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: var(--surface-2);
    transition: border-color 0.12s, background-color 0.12s;
}
.slot.is-over { border-color: var(--accent); background: var(--accent-soft); }
.slot-drop {
    display: grid;
    place-items: center;
    aspect-ratio: 4 / 3;
    width: 100%;
    padding: 0;
    overflow: hidden;
    border: 1.5px dashed var(--rule);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--muted);
    cursor: pointer;
}
.slot.is-filled .slot-drop { border-style: solid; }
.slot-drop:hover { border-color: var(--accent); color: var(--accent); }
/* pinned to the box: a percentage height does not resolve inside the button,
   and a portrait photo would overflow it from the top instead of fitting */
.slot-drop { position: relative; }
.slot-drop img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; object-position: center; background: var(--scene-paper); }
.slot-empty { display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; }
/* an empty Dessus / Dessous / Boîte zone shows how to take its photo: the last frame of its
   animation, which drop-guides.js plays under the mouse or a held finger (which must not select
   the prompt nor call up the long-press menu) - 4:3 like the zone, and transparent around the
   support so it sits on either theme. Its prompt moves to a pill at the bottom so it does not
   hide the blister */
.slot:is([data-slot="top"], [data-slot="under"], [data-slot="box"]):not(.is-filled) .slot-drop {
    background: var(--surface) center / contain no-repeat;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}
.slot[data-slot="top"]:not(.is-filled) .slot-drop { background-image: url("../img/blister-placement-pills-up-last.webp"); }
.slot[data-slot="under"]:not(.is-filled) .slot-drop { background-image: url("../img/blister-flip-foil-up-last.webp"); }
.slot[data-slot="box"]:not(.is-filled) .slot-drop { background-image: url("../img/box-placement-last.webp"); }
.slot:is([data-slot="top"], [data-slot="under"], [data-slot="box"]):not(.is-filled) .slot-empty {
    align-self: end;
    flex-direction: row;
    margin-bottom: 8px;
    padding: 4px 12px 4px 8px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--surface) 90%, transparent);
    box-shadow: var(--shadow);
}
.slot-meta { display: flex; flex-direction: column; gap: 1px; min-width: 0; padding: 0 2px; }
.slot-name { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot-actions { display: flex; gap: 6px; }
.box-card { max-width: 520px; display: flex; flex-direction: column; gap: 14px; }
.box-card .slot { gap: 0; }

/* ----------------------------------------------------------- 2 Analyse */

.analysis-run { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 28px; align-items: center; }

.scan {
    position: relative;
    height: min(62vh, 560px);
    overflow: hidden;
    border-radius: var(--radius-sm);
    background: var(--scene-paper);
    display: grid;
    place-items: center;
}
.scan img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: saturate(0.6) contrast(1.05);
    opacity: 0.9;
}
.scan-grid {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(var(--scene-grid-mid) 1px, transparent 1px),
        linear-gradient(90deg, var(--scene-grid-mid) 1px, transparent 1px);
    background-size: 24px 24px;
    mix-blend-mode: multiply;
    pointer-events: none;
}
.scan-beam {
    position: absolute;
    left: 0;
    right: 0;
    height: 28%;
    top: -28%;
    background: linear-gradient(to bottom, transparent, color-mix(in srgb, var(--accent) 22%, transparent) 70%,
        color-mix(in srgb, var(--accent) 65%, transparent) 99%, transparent);
    border-bottom: 2px solid var(--accent);
    animation: scan 2.2s cubic-bezier(0.45, 0, 0.55, 1) infinite;
    pointer-events: none;
}
@keyframes scan { to { top: 100%; } }

.run-side { display: flex; flex-direction: column; gap: 16px; }
.stages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.stage {
    display: grid;
    grid-template-columns: 26px 1fr;
    grid-template-rows: auto auto;
    column-gap: 10px;
    align-items: center;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    color: var(--faint);
}
.stage-mark {
    grid-row: 1 / span 2;
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1.5px solid var(--rule);
}
.stage-label { font-weight: 500; }
.stage-detail { grid-column: 2; font: 12px var(--mono); color: var(--muted); }
.stage-detail:empty { display: none; }
.stage--active { color: var(--ink); background: var(--accent-soft); }
.stage--active .stage-mark { border-color: var(--accent); border-right-color: transparent; animation: spin 0.8s linear infinite; }
.stage--done { color: var(--ink); }
.stage--done .stage-mark { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.stage--failed { color: var(--bad); }
.stage--failed .stage-mark { background: var(--bad); border-color: var(--bad); color: #fff; }

.analysis-result { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.analysis-side { display: flex; flex-direction: column; gap: 14px; }
.stage-card { margin: 0; padding: 0; overflow: hidden; }
.scene-host--analysis { height: min(72vh, 760px); }

.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.summary .facts { grid-column: 1 / -1; margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--rule-soft); }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 10px; border-radius: var(--radius-sm); background: var(--surface-2); }
.stat-value { font: 600 24px var(--mono); line-height: 1.1; }
.stat-label { font-size: 12px; color: var(--muted); }
/* the rule is on a box around the fieldset: on the fieldset itself, it would run through its legend */
.size-edit { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--rule-soft); }
.size-edit .card-note { margin: 8px 0; }
.size-edit .card-note.is-bad { color: var(--bad); }
.actions-card { display: flex; flex-direction: column; gap: 8px; }
.actions-card .hint { margin: -2px 0 4px; }
.fail-card { max-width: 760px; }

/* ----------------------------------------------------------- 3 Ajustement */

.adjust {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 430px;
    gap: 16px;
    align-items: start;
}
.adjust-main {
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
    height: calc(100vh - var(--topbar-h) - 32px);
    min-height: 560px;
    position: sticky;
    top: calc(var(--topbar-h) + 16px);
}
.stage-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 10px 12px;
    border-bottom: 1px solid var(--rule);
}
.stage-title { font-weight: 600; font-size: 14px; margin-right: auto; }
.seg-group { display: flex; align-items: center; gap: 8px; }
.seg-label { font-size: 12px; font-weight: 600; color: var(--muted); }

.legend { display: flex; gap: 14px; margin: 0 0 0 auto; padding: 0; list-style: none; font-size: 12.5px; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 6px; }
.swatch { width: 16px; height: 0; border-top: 3px solid; border-radius: 2px; }
.swatch--dose { border-color: var(--cut); }
.swatch--chute { border-color: var(--chute); }
.swatch--drop { border-color: var(--drop); border-top-style: dashed; }
.swatch--grip { border-color: var(--grip); }
.swatch--pillar { width: 11px; height: 11px; border: 1.5px dashed var(--scene-mark); border-radius: 50%;
    background: color-mix(in srgb, var(--scene-mark) 16%, transparent); }
.swatch--zone { width: 11px; height: 12px; border: 1.5px dashed var(--scene-mark); border-radius: 3px;
    background: color-mix(in srgb, var(--scene-mark) 8%, transparent); }
.swatch--pocket { width: 12px; height: 9px; border: 1.5px solid #ffffff; border-radius: 5px; box-shadow: 0 0 0 1px #20262d; }

/* The views can be zoomed and panned freely, and the grid runs on past the photo in both: a firm
   gutter, darker than either view's paper, is what says where one ends and the other begins. */
.views {
    position: relative; flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr;
    column-gap: 4px;
    background: color-mix(in srgb, var(--ink) 45%, var(--surface));
}
.views[data-view="top"] { grid-template-columns: 1fr; }
.views[data-view="top"] .view--under { display: none; }
.views[data-view="under"] { grid-template-columns: 1fr; }
.views[data-view="under"] .view--top { display: none; }
.view { position: relative; margin: 0; min-width: 0; min-height: 0; display: flex; }
.view figcaption {
    position: absolute;
    top: 8px;
    left: 10px;
    z-index: 1;
    padding: 2px 8px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    border: 1px solid var(--rule);
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    pointer-events: none;
}
.scene-host { flex: 1; min-width: 0; min-height: 0; background: var(--scene-paper); }

.sequence {
    display: grid;
    grid-template-columns: auto minmax(160px, 1fr) auto minmax(0, 1.6fr) auto;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-top: 1px solid var(--rule);
}
.sequence input[type="range"] { width: 100%; accent-color: var(--accent); }
.seq-readout { font: 13px var(--mono); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seq-readout strong { font-family: var(--font); color: var(--ink); font-weight: 600; }
.seq-actions { display: flex; gap: 8px; }

.adjust-side {
    display: flex;
    flex-direction: column;
    gap: 12px;
    height: calc(100vh - var(--topbar-h) - 32px);
    min-height: 560px;
    position: sticky;
    top: calc(var(--topbar-h) + 16px);
    /* when the warnings and the rest leave the list less than its six rows,
       the column scrolls rather than the list shrinking further */
    overflow-y: auto;
    overscroll-behavior: contain;
}
.adjust-side > * { flex: none; }
.adjust-side > .cuts-card { flex: 1 1 auto; display: flex; flex-direction: column; }  /* shrinks to the list's six rows */
.fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
.adjust-side .card-note { margin-top: 8px; }
.side-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 10px; }

.cuts-card .card-head { margin-bottom: 2px; }
.cut-head, .cut-row {
    display: grid;
    grid-template-columns: 14px 28px minmax(0, 1fr) minmax(0, 1fr) 52px 36px 78px;
    align-items: center;
    gap: 5px;
}
.cut-head {
    padding: 8px 6px 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--faint);
}
.cut-list {
    flex: 1 1 auto;
    /* no height of its own: the list fills what the card leaves it, never
       less than six rows - and, since its rows no longer count towards the
       card's minimum, it scrolls instead of stretching the card */
    height: 0;
    min-height: 222px;
    list-style: none;
    margin: 0 -4px;
    padding: 0 4px;
    overflow-y: auto;
    overscroll-behavior: contain;
}
.cut-row {
    position: relative;
    padding: 4px 6px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
}
.cut-row + .cut-row { margin-top: 2px; }
.cut-row:hover { background: var(--surface-2); }
.cut-row.is-current { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.cut-row.is-past .cut-num { opacity: 0.55; }
.cut-row.is-dragging { opacity: 0.4; }
.cut-row.is-drop-before::before, .cut-row.is-drop-after::after {
    content: "";
    position: absolute;
    left: 4px;
    right: 4px;
    height: 2px;
    background: var(--accent);
    border-radius: 2px;
}
.cut-row.is-drop-before::before { top: -2px; }
.cut-row.is-drop-after::after { bottom: -2px; }
.cut-grip { color: var(--faint); cursor: grab; display: grid; place-items: center; }
.cut-grip:active { cursor: grabbing; }
.cut-num {
    display: grid;
    place-items: center;
    height: 26px;
    padding: 0;
    border: 0;
    border-radius: 5px;
    background: color-mix(in srgb, var(--cut) 14%, transparent);
    color: var(--cut);
    font: 600 12.5px var(--mono);
    cursor: pointer;
}
.cut-row.is-chute .cut-num { background: color-mix(in srgb, var(--chute) 16%, transparent); color: var(--chute); }
.cut-row.is-current .cut-num { background: var(--cut); color: #fff; }
.cut-row.is-current.is-chute .cut-num { background: var(--chute); }
/* short of the edge trim: a warning - listed before the clash, which wins */
.cut-row.is-trim .cut-num { background: var(--warn-soft); color: var(--warn); box-shadow: inset 0 0 0 1px var(--warn-rule); }
.cut-row.is-current.is-trim .cut-num { background: var(--warn); color: #fff; box-shadow: none; }
.cut-row.is-angle .cut-num { background: var(--warn-soft); color: var(--warn); box-shadow: inset 0 0 0 1px var(--warn-rule); }
.cut-row.is-current.is-angle .cut-num { background: var(--warn); color: #fff; box-shadow: none; }
.cut-row.is-split .cut-num { background: var(--bad-soft); color: var(--bad); box-shadow: inset 0 0 0 1px var(--bad-rule); }
.cut-row.is-current.is-split .cut-num { background: var(--bad); color: #fff; box-shadow: none; }
.cut-row.is-pillar .cut-num { background: var(--bad-soft); color: var(--bad); box-shadow: inset 0 0 0 1px var(--bad-rule); }
.cut-row.is-current.is-pillar .cut-num { background: var(--bad); color: #fff; box-shadow: none; }
.cut-row.is-zone .cut-num { background: var(--bad-soft); color: var(--bad); box-shadow: inset 0 0 0 1px var(--bad-rule); }
.cut-row.is-current.is-zone .cut-num { background: var(--bad); color: #fff; box-shadow: none; }
.cut-row.is-clash .cut-num { background: var(--bad); color: #fff; }
.cut-row.is-clash { border-color: var(--bad-rule); }
.cut-row input.num { min-height: 28px; padding: 3px 6px; font-size: 13px; text-align: right; }
.cut-chute { display: grid; place-items: center; cursor: pointer; }
.cut-chute input { width: 16px; height: 16px; accent-color: var(--chute); margin: 0; }
.cut-actions { display: flex; justify-content: flex-end; }
.cut-actions .icon-btn { width: 26px; height: 26px; }
.cut-row--drop { margin-top: 6px !important; border-top: 1px dashed var(--rule); border-radius: 0 0 var(--radius-sm) var(--radius-sm); }
.cut-row--drop .cut-num { background: color-mix(in srgb, var(--drop) 14%, transparent); color: var(--drop); }
.cut-row--drop.is-current { background: color-mix(in srgb, var(--drop) 10%, transparent); border-color: transparent; }
.cut-row--drop.is-current .cut-num { background: var(--drop); color: #fff; }
/* the prehensor's row, first of the list as the drop's is last */
.cut-row--grip { margin-bottom: 6px !important; border-bottom: 1px dashed var(--rule); border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.cut-row--grip .cut-num { background: color-mix(in srgb, var(--grip) 14%, transparent); color: var(--grip); }
.cut-row--grip.is-current { background: color-mix(in srgb, var(--grip) 10%, transparent); border-color: transparent; }
.cut-row--grip.is-current .cut-num { background: var(--grip); color: #fff; }
.cut-row--grip.is-clash .cut-num { background: var(--bad); color: #fff; }
.num--static { font: 13px var(--mono); color: var(--muted); padding: 0 7px; }
.cut-drop-note { grid-column: span 2; font-size: 11.5px; color: var(--faint); text-align: right; }

/* the machine and the blister, as the side column's title */
.side-title {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 4px 12px;
    flex-wrap: wrap;
    padding: 10px 14px;
    background: var(--accent-soft);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
}
.side-title h2 { font-size: 17px; font-weight: 600; }
.side-title > span { color: var(--muted); font-size: 13px; }
.side-title > span span { font-family: var(--mono); color: var(--ink); }

/* the shortcuts, behind a button of the sequence bar; the panel opens upwards */
.shortcuts { position: relative; font-size: 13px; color: var(--muted); }
.shortcuts > summary { list-style: none; }
.shortcuts > summary::-webkit-details-marker { display: none; }
.shortcuts[open] > summary { background: var(--accent-soft, var(--surface-2)); }
.shortcuts-panel {
    position: absolute;
    right: 0;
    bottom: calc(100% + 8px);
    z-index: 5;
    width: 380px;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}
.shortcuts dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0 0 10px; align-items: baseline; }
.shortcuts dt { white-space: nowrap; }
.shortcuts dd { margin: 0; }

/* the scene */
.scene { display: block; width: 100%; height: 100%; user-select: none; touch-action: none; }
.scene--panning, .scene--panning * { cursor: grabbing !important; }
/* the analysis's view of the original photo: the board's corners and the blister's, as the backend found them */
.geo-halo { fill: none; stroke: rgba(0, 0, 0, 0.8); stroke-width: 4; vector-effect: non-scaling-stroke; pointer-events: none; }
.geo-line { fill: none; stroke-width: 1.5; vector-effect: non-scaling-stroke; pointer-events: none; }
.geo-line.geo--corner { stroke: #ffea00; }
.geo-line.geo--blister { stroke: #ff5252; }
.geo-line.geo--marker { stroke: #00e5ff; }
.geo-dot { stroke: rgba(0, 0, 0, 0.85); stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: none; }
.geo-dot--used { fill: #00e676; }
.geo-dot--dropped { fill: #ff6d00; }
.geo-dot--arm { fill: #e040fb; }
.geo-dot--extra { fill: rgba(0, 230, 118, 0.25); stroke: #00e676; }
.geo-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0; padding: 6px 12px; font-size: 12.5px; }
.geo-legend span::before { content: ""; display: inline-block; width: 9px; height: 9px; margin-right: 5px; border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.7); vertical-align: -1px; }
.geo-legend .used::before { background: #00e676; }
.geo-legend .dropped::before { background: #ff6d00; }
.geo-legend .extra::before { background: rgba(0, 230, 118, 0.25); border-color: #00e676; }
.geo-legend .arm::before { background: #e040fb; }
.geo-legend .mcorner::before { background: none; border-color: #00e5ff; }
.geo-legend .icorner::before { background: none; border-color: #ffea00; }
.geo-legend .sline::before { background: #ffea00; border: 0; border-radius: 0; height: 2px; width: 13px; vertical-align: 3px; }
.geo-legend .rect::before { background: none; border-color: #ff5252; border-radius: 0; }
.geo-legend .dose::before { background: #fff; border-color: #20262d; }
.geo-legend .unsure::before { background: none; border: 1px dashed #20262d; }
.geo-lens { margin: 0; padding: 6px 12px; font-size: 12.5px; border-top: 1px solid var(--rule-soft); }
.geo-label { font-weight: 700; font-family: var(--font); paint-order: stroke; stroke: rgba(0, 0, 0, 0.85); stroke-linejoin: round; pointer-events: none; }
.geo-label.geo--corner { fill: #ffea00; }
.geo-label.geo--blister { fill: #ff5252; }
.scene-paper { fill: var(--scene-paper); }
.scene-grid line { stroke: var(--scene-grid); stroke-width: 1; vector-effect: non-scaling-stroke; }
.scene-grid line.mid { stroke: var(--scene-grid-mid); }
.scene-grid line.major { stroke: var(--scene-grid-major); }
.scene-grid--over line { stroke: rgba(255, 255, 255, 0.07); }
.scene-grid--over line.mid { stroke: rgba(255, 255, 255, 0.13); }
.scene-grid--over line.major { stroke: rgba(255, 255, 255, 0.24); }
.scene-blister, .scene-blister-halo { fill: none; vector-effect: non-scaling-stroke; }
.scene-blister-halo { stroke: var(--scene-halo); stroke-width: 3; stroke-opacity: 0.6; }
.scene-blister { stroke: var(--scene-ink); stroke-width: 1.2; stroke-dasharray: 5 4; }
.scene-blister-hit { fill: transparent; pointer-events: fill; cursor: move; }
.scene-axes path { stroke: var(--scene-ink); stroke-width: 1.6; fill: none; vector-effect: non-scaling-stroke; }
.scene-axes path.scene-axes-halo { stroke: var(--scene-halo); stroke-width: 4.5; }
.scene-axes .scene-axes-head { fill: var(--scene-ink); stroke: var(--scene-halo); stroke-width: 1; }
.scene-axes-label { font: 600 11px var(--font); fill: var(--scene-ink); paint-order: stroke; stroke: var(--scene-halo); stroke-width: 3.5px; }
.scene-origin { fill: var(--scene-ink); stroke: var(--scene-halo); stroke-width: 1.5; vector-effect: non-scaling-stroke; }

/* the doses the analysis measured: white on the photo, whatever the foil */
.doses rect { fill: none; vector-effect: non-scaling-stroke; pointer-events: none; }
/* the plate's pillars: a solid to stay out of, red where a cut's blister touches it */
.pillars { pointer-events: none; }
.pillar-disc { fill: var(--scene-mark); fill-opacity: 0.16; stroke: var(--scene-mark); stroke-width: 1.6; stroke-dasharray: 6 4; vector-effect: non-scaling-stroke; }
.pillar-centre { stroke: var(--scene-mark); stroke-width: 1.4; vector-effect: non-scaling-stroke; }
.pillar-label { font: 600 11px var(--mono); fill: var(--scene-mark-ink); text-anchor: middle; paint-order: stroke; stroke: var(--scene-halo); stroke-width: 3.5px; }
.pillar--hit .pillar-disc { fill: var(--bad); fill-opacity: 0.22; stroke: var(--bad); stroke-dasharray: none; }
.pillar--hit .pillar-centre { stroke: var(--bad); }
.pillar--hit .pillar-label { fill: var(--bad); }
/* the zone around the die the pince may not enter: red where a cut's jaw is in it */
.die-zones { pointer-events: none; }
.die-zone-shape { fill: var(--scene-mark); fill-opacity: 0.08; stroke: var(--scene-mark); stroke-width: 1.6; stroke-dasharray: 6 4; vector-effect: non-scaling-stroke; }
.die-zone-label { font: 600 11px var(--mono); fill: var(--scene-mark-ink); text-anchor: middle; paint-order: stroke; stroke: var(--scene-halo); stroke-width: 3.5px; }
.die-zone--hit .die-zone-shape { fill: var(--bad); fill-opacity: 0.14; stroke: var(--bad); stroke-dasharray: none; }
.die-zone--hit .die-zone-label { fill: var(--bad); }
.doses .dose-halo { stroke: rgba(12, 16, 20, 0.7); stroke-width: 3.2; }
.doses .dose { stroke: #ffffff; stroke-width: 1.3; }
.doses .dose--freed { stroke: var(--ok); stroke-width: 2; fill: var(--ok); fill-opacity: 0.14; }
.doses .dose--split, .doses .dose--gripped { stroke: var(--bad); stroke-width: 2; fill: var(--bad); fill-opacity: 0.22; }
.doses .dose--unsure { stroke-dasharray: 4 3; }

.die { --die: var(--cut); }
.die--chute { --die: var(--chute); }
.die--drop { --die: var(--drop); }
.die path { fill: none; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
.die .die-halo { stroke: var(--scene-halo); stroke-width: 5; }
.die .die-blade { stroke: var(--die); stroke-width: 2; }
.die--drop .die-blade { stroke-dasharray: 7 5; }
.die--past { opacity: 0.3; }
.die--future { opacity: 0.35; }
.die--future .die-blade { stroke-dasharray: 2 4; }
.die--current .die-blade { stroke-width: 3.2; }
.die--current .die-halo { stroke-width: 7; }
.die .die-fill { fill: var(--die); fill-opacity: 0.08; }
.die .die-hit { stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer; }
.die .die-body { fill: transparent; pointer-events: fill; cursor: move; }
.die-point { fill: var(--die); stroke: var(--scene-halo); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.die-point-hit { fill: transparent; cursor: pointer; }
.die--current .die-point-hit[data-hit="body"] { cursor: move; }
.die-label { font: 600 11px var(--mono); fill: var(--die); paint-order: stroke; stroke: var(--scene-halo); stroke-width: 3.5px; pointer-events: none; }
.die--current .die-label { font-size: 13px; }
.die .die-stem { stroke: var(--die); stroke-width: 1.2; stroke-dasharray: 2 2; }
/* a die that touches the gripper: impossible, whatever else it is */
.die--clash { --die: var(--bad); }
.die--clash .die-fill { fill-opacity: 0.16; }
.handle { fill: var(--surface); stroke-width: 2; vector-effect: non-scaling-stroke; cursor: grab; }
.handle--rotate { stroke: var(--die); }
.handle:hover { fill: var(--accent-soft); }
.gripper { --die: var(--grip); }
.gripper-body { fill: var(--grip); fill-opacity: 0.28; stroke: var(--grip); stroke-width: 2; vector-effect: non-scaling-stroke; }
.gripper-body[data-hit] { cursor: move; }
.gripper-jaw { fill: var(--grip); fill-opacity: 0.85; pointer-events: none; }
.gripper-ref { stroke: var(--grip); stroke-width: 2; vector-effect: non-scaling-stroke; pointer-events: none; }
.handle--grip { stroke: var(--grip); }
.gripper--clash { --grip: var(--bad); }
.gripper--current .gripper-body { stroke-width: 3.5; fill-opacity: 0.42; }
.gripper--blocked .gripper-body { stroke-width: 3.5; animation: blocked 0.45s ease-in-out 3; }
@keyframes blocked { 50% { fill-opacity: 0.6; } }

.clash-alert {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3;
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: calc(100% - 24px);
    padding: 7px 12px;
    border-radius: var(--radius-sm);
    background: var(--bad);
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    pointer-events: none;
}
.gripper .die-stem { stroke: var(--grip); stroke-width: 1.2; stroke-dasharray: 2 2; fill: none; vector-effect: non-scaling-stroke; }

/* ----------------------------------------------------------- 4 Finalisation */

.annots {
    /* One height for the three, taken from the row's own width so that they
       fill it exactly and line up with the fiche below: their widths add up
       to 4/3 + 4/3 + 3/4 = 3.42 heights, plus 3 x 26 px of card padding and
       2 x 16 px of gaps. (Resolved in the cards, against this container.) */
    container-type: inline-size;
    --annot-h: max(220px, calc((100cqw - 110px) / 3.4167));
    display: grid;
    grid-template-columns: repeat(3, auto);
    grid-template-rows: auto auto auto;
    justify-content: space-between;
    column-gap: 16px;
    row-gap: 16px;
}
/* The cards share the grid's three rows - header, image, note - so a header
   that wraps in the narrow card pushes every image down together and the
   three stay level. */
.annot {
    grid-row: span 3;
    display: grid;
    grid-template-rows: subgrid;
    row-gap: 10px;
    /* sized from the shared height and the image's own proportions (--ratio,
       set per card): nothing intrinsic to negotiate */
    width: calc(var(--annot-h) * var(--ratio, 1) + 26px);
    padding: 12px;
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.annot-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 8px; min-height: 30px; }
.annot-head h3 { font-size: 14px; font-weight: 600; }
.annot-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.tool {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 30px;
    padding: 0 10px;
    border: 1px solid var(--rule);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink);
    font: 500 13px var(--font);
    cursor: pointer;
    white-space: nowrap;
}
.tool:hover { background: var(--surface-2); border-color: var(--faint); }
.tool[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.tool--quiet { border-color: transparent; background: transparent; color: var(--muted); }
.tool--quiet:hover { color: var(--ink); }
.annot-frame {
    position: relative;
    height: var(--annot-h);
    width: 100%;
    border-radius: 4px;
    overflow: hidden;
    outline: 1px solid var(--rule);
}
.annot-frame.is-drawing { outline: 2px solid var(--accent); }
.annot-frame canvas { display: block; width: 100%; height: 100%; touch-action: none; }
/* the note wraps inside the image's width instead of widening the card */
.annot-note { font-size: 12.5px; color: var(--muted); width: 0; min-width: 100%; }
.annot-edit {
    position: absolute;
    z-index: 2;
    padding: 0 8px;
    border: 2px solid #ff0000;
    border-radius: 4px;
    background: #fff;
    color: #ff0000;
    font: bold 16px system-ui, sans-serif;
}

.meta-card { display: flex; flex-direction: column; gap: 14px; }
.meta-group { margin: 0; padding: 0; border: 0; min-width: 0; }
.meta-group legend {
    padding: 0 0 8px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}
.meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 22px 18px;
    align-items: start;
}
.meta-grid .field--wide { grid-column: span 2; }
.meta-grid input, .meta-grid select, .meta-grid .seg, .meta-foot select { height: 38px; }
/* two Non / Oui switches side by side in one column, each across its half, its buttons sharing it */
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.meta-grid .seg button { flex: 1; min-width: 0; padding: 0 6px; }
.meta-grid .field-hint.is-changed { color: var(--warn); }
.meta-foot {
    display: flex;
    align-items: flex-end;
    gap: 18px;
    padding-top: 14px;
    border-top: 1px solid var(--rule-soft);
}
.field--speed { width: 140px; }
.meta-foot .hint { flex: 1; text-align: right; }
.flags { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; margin: 0; padding: 0; list-style: none; }
.flag {
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 10px;
    align-items: center;
    padding: 8px 10px;
    border: 1px solid var(--rule);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}
.flag small { grid-column: 2; color: var(--muted); font-size: 12px; }
.flag-value {
    grid-row: span 2;
    min-width: 40px;
    padding: 2px 8px;
    border-radius: 999px;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    background: var(--ok-soft);
    color: var(--ok);
}
.flag.is-on { border-color: var(--warn-rule); background: var(--warn-soft); }
/* a flag the operator has to set: its switch stands where the value is */
.flag--ask .seg { grid-row: span 2; }
.flag--ask.is-missing { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.flag.is-on .flag-value { background: var(--warn); color: #fff; }
.flag-name { font-weight: 600; font-size: 13.5px; }
/* the operator can force a flag over its computed value: the switch sits under it, and a flag that is
   forced says so, in warning colours when it is not what was computed */
.flag .flag-force { grid-column: 1 / -1; justify-self: start; margin-top: 8px; }
.flag .flag-note { grid-column: 1 / -1; margin-top: 6px; }
.flag .flag-note.is-differs { color: var(--warn); font-weight: 600; }
.flag.is-forced { border-style: dashed; }
#meta-forced { margin-top: 10px; }
.field--cip { position: relative; }
.field--cip input { font-size: 16px; letter-spacing: 0.06em; }
.field--cip .field-hint { position: absolute; top: 100%; left: 0; margin-top: 4px; white-space: nowrap; }
.meta-actions { display: flex; justify-content: flex-end; gap: 10px; }

.done-card { display: flex; align-items: center; gap: 18px; border-color: color-mix(in srgb, var(--ok) 40%, transparent); background: var(--ok-soft); }
.done-card h2 { font-size: 18px; color: var(--ok); }
.done-card > div { flex: 1; min-width: 0; }
.done-mark { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 50%; background: var(--ok); color: #fff; flex: none; }
.done-card p { color: var(--muted); }

.loading-card { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 56px 20px; color: var(--muted); }

/* ------------------------------------------------------------------ toasts */

.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 50; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    background: var(--ink);
    color: var(--paper);
    box-shadow: var(--shadow-lg);
    font-size: 14px;
    animation: toast-in 0.18s ease-out;
    transition: opacity 0.3s, transform 0.3s;
}
.toast--error { background: var(--bad); color: #fff; }
.toast.is-leaving { opacity: 0; transform: translateY(6px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* -------------------------------------------------------------- responsive */

@media (max-width: 1320px) {
    .adjust { grid-template-columns: minmax(0, 1fr) 400px; }
}

@media (max-width: 1080px) {
    .topbar { grid-template-columns: auto 1fr auto; }
    .stepper-name { display: none; }
    .stepper-item.is-current .stepper-name { display: inline; }
    .brand-client { display: none; }
    .adjust { grid-template-columns: 1fr; }
    .adjust-main { position: static; height: 76vh; }
    .cut-list { max-height: none; }
    .analysis-run, .analysis-result { grid-template-columns: 1fr; }
    .slots { grid-template-columns: 1fr; }
    .sequence { grid-template-columns: auto 1fr auto; }
    .seq-readout, .seq-actions { grid-column: 1 / -1; }
    /* the two buttons share the line, half each */
    .seq-actions { display: grid; grid-template-columns: 1fr 1fr; }
    .seq-actions .shortcuts > summary { width: 100%; justify-content: center; }
}

@media (max-width: 720px) {
    .main { padding: 18px 12px 48px; }
    .annots { --annot-h: 46vw; grid-template-columns: auto; }
    .meta-grid .field--wide { grid-column: auto; }
    .meta-foot { flex-wrap: wrap; }
    .brand-name { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .gripper--blocked .gripper-body { animation: none; }
    .scan-beam { animation-duration: 6s; }
    .spinner, .stage--active .stage-mark { animation-duration: 2s; }
    .toast { animation: none; }
}

/* ----------------------------------------------------------- 1 Mode */

.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
.mode {
    position: relative;
    display: grid;
    grid-template-columns: 44px 1fr;
    column-gap: 14px;
    row-gap: 4px;
    align-items: start;
    padding: 18px 18px 16px;
    border: 1.5px solid var(--rule);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
    transition: border-color 0.12s, box-shadow 0.12s;
}
.mode:hover { border-color: var(--faint); }
.mode input { position: absolute; opacity: 0; pointer-events: none; }
.mode:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.mode.is-selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}
.mode-icon {
    grid-row: 1 / span 2;
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent);
}
.mode-name { font-weight: 600; font-size: 16px; }
.mode-text { grid-column: 2; color: var(--muted); font-size: 13.5px; }

/* ------------------------------------------- Visualisation : Calibration */

.picker { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
.picker-stage {
    min-width: 0;
    display: grid;
    place-items: center;
    padding: 6px;
    border-radius: var(--radius-sm);
    background: var(--scene-paper);
}
.picker-stage canvas { display: block; max-width: 100%; cursor: crosshair; touch-action: none; border-radius: 4px; }
.picker-side { display: flex; flex-direction: column; gap: 14px; }
.row-actions--stack { flex-direction: column; align-items: stretch; margin-top: 0; }
@media (max-width: 900px) { .picker { grid-template-columns: 1fr; } }

/* The editor as a viewer: what edits is not there, what lays the list out stays. */
.is-view-only [data-edit-only] { display: none !important; }
.step:not(.is-view-only) [data-view-only] { display: none !important; }
/* Nothing to grab or press: the list is laid out without the grip and the actions, so that the
   fields take their room - read-only, a field cannot be clicked to scroll through its digits. */
.is-view-only .cut-grip, .is-view-only .cut-actions { display: none; }
.is-view-only .cut-head > :first-child, .is-view-only .cut-head > :last-child { display: none; }
.is-view-only .cut-head, .is-view-only .cut-row { grid-template-columns: 28px minmax(0, 1fr) minmax(0, 1fr) 76px 36px; }
/* the drop's row: its T is always 0, and its note takes the room of that and of the chute column */
.is-view-only .cut-row--drop > :nth-child(5), .is-view-only .cut-row--grip .cut-drop-note { display: none; }
.is-view-only .cut-row--drop .cut-drop-note { grid-column: 4 / -1; }
