:root {
  --bg: #18181b;
  --pane: #1c1c20;
  --card: #232328;
  --hover: #2b2b31;
  --stage: #111113;
  --field: #141417;
  --line: rgba(255,255,255,.06);
  --line2: rgba(255,255,255,.10);
  --text: #ececee;
  --muted: #8e8e96;
  --faint: #5f5f67;
  --accent: #7fb89a;
  --accent-h: #93c7ab;
  --accent-d: rgba(127,184,154,.15);
  --accent-ink: #0f2117;
  --red: #e5484d;
  --orange: #f0a43a;
  --green: #46a758;
  --cyan: #3fc6d4;
  --radius: 10px;
  --r-sm: 7px;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  font-feature-settings: "cv11", "ss01";
  color-scheme: dark;
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; color: inherit; }
h1 { font-size: 14px; font-weight: 600; margin: 0; letter-spacing: -.1px; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 11.5px; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Barres de défilement discrètes */
* { scrollbar-width: thin; scrollbar-color: #3a3a41 transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #3a3a41; border-radius: 4px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- En-tête */
.top {
  height: 48px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; background: var(--pane); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; position: relative; }

/* Lien d'accueil (logo + titre) */
.prog {
  display: flex; align-items: center; gap: 10px; background: transparent; border: 0;
  padding: 5px 8px 5px 6px; margin-left: -6px; border-radius: var(--r-sm); cursor: pointer;
  color: inherit; text-decoration: none;
}
.prog:hover { background: var(--card); }
.logo {
  width: 18px; height: 18px; border-radius: 5px;
  background:
    repeating-linear-gradient(0deg, transparent 0 3px, rgba(255,255,255,.28) 3px 4px),
    repeating-linear-gradient(90deg, var(--accent) 0 3px, #4f8a6b 3px 4px);
}
.conn { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.conn.ok { background: var(--green); box-shadow: 0 0 0 3px rgba(70,167,88,.18); }
.conn.err { background: var(--red); box-shadow: 0 0 0 3px rgba(229,72,77,.18); }
.top-actions { display: flex; align-items: center; gap: 6px; }
.busy { color: var(--accent); font-size: 12px; margin-right: 6px; }
.busy::before {
  content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 6px;
  border: 2px solid var(--accent); border-right-color: transparent; border-radius: 50%;
  vertical-align: -1px; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.livetog { display: flex; align-items: center; gap: 8px; color: var(--muted); cursor: pointer; user-select: none; margin-right: 4px; }
.livetog:hover { color: var(--text); }
#btnCalc { min-width: 84px; }
#btnCalc.dirty::after { content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 7px; border-radius: 50%; background: var(--accent-ink); vertical-align: 1px; }

/* ---------- Mise en page */
.layout {
  height: calc(100% - 48px);
  display: grid; grid-template-columns: 236px minmax(0, 1fr) 340px;
}
.pane { min-height: 0; overflow: hidden; }
.gallery, .params { background: var(--pane); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.gallery { border-right: 1px solid var(--line); }
.params { border-left: 1px solid var(--line); overflow-y: auto; gap: 12px; }
.params > * { flex-shrink: 0; }
.viewer { display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.params, .simplepanel { grid-column: 3; grid-row: 1; }

/* ---------- Mode simple */
.simplepanel {
  background: var(--pane); padding: 14px; display: flex; flex-direction: column; gap: 12px;
  border-left: 1px solid var(--line); overflow-y: auto;
}
.simplepanel > * { flex-shrink: 0; }
.simplepanel .card { display: flex; flex-direction: column; gap: 8px; }
.simplepanel .card-h { margin-bottom: 2px; }
.simplepanel .ref-label { margin-bottom: 2px; }
.simplepanel .grow-card { flex: 1 0 160px; min-height: 160px; }
.simplepanel .next-card { border: 1px solid rgba(127,184,154,.35); }
.hint { margin: 0; color: var(--faint); font-size: 11.5px; line-height: 1.45; }
.check.sm { font-size: 12px; line-height: 1.35; align-items: flex-start; }
.check.sm input { margin-top: 2px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
.dot.ok { background: var(--green); } .dot.bad { background: var(--red); }
body:not(.simple):not(.page) .simplepanel, body:not(.simple):not(.page) .toolbox, body:not(.simple):not(.page) .toolhint { display: none !important; }
body.simple .params, body.simple .viewer > .toolbar, body.simple .bottom,
body.simple .livetog, body.simple #btnCalc { display: none !important; }

/* Curseurs de sensibilité */
.sens { display: flex; flex-direction: column; gap: 10px; }
.sens-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center; }
.sens-row label { font-size: 12.5px; }
.sens-row output { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 64px; text-align: right; }
.sens-row output.hi { color: var(--orange); } .sens-row output.lo { color: var(--cyan); }
.sens-row input[type=range] { grid-column: 1 / -1; width: 100%; margin: 0; }
.sens-row .ends { grid-column: 1 / -1; display: flex; justify-content: space-between; color: var(--faint); font-size: 10.5px; margin-top: -2px; }

/* Liste des défauts (mode simple) */
.deflist { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 0; }
.deflist li {
  display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px; cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.deflist li:hover, .deflist li.hl { background: var(--hover); }
.deflist .n { color: var(--faint); width: 18px; text-align: right; font-size: 11.5px; }
.deflist .kind { flex: 1; }
.deflist .a { color: var(--muted); font-size: 11.5px; }
.deflist .x {
  background: none; border: 0; color: var(--faint); cursor: pointer; width: 20px; height: 20px;
  border-radius: 5px; font-size: 14px; line-height: 1; visibility: hidden;
}
.deflist li:hover .x { visibility: visible; }
.deflist .x:hover { background: #393941; color: var(--text); }
.deflist .empty-msg { color: var(--muted); cursor: default; }
.deflist .empty-msg:hover { background: none; }

/* Barre d'outils flottante */
.toolbox {
  position: absolute; left: 14px; top: 14px; z-index: 5; display: flex; flex-direction: column;
  align-items: center; gap: 2px; padding: 4px; user-select: none;
  background: rgba(28,28,32,.92); backdrop-filter: blur(8px);
  border: 1px solid var(--line2); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.45);
}
.tb-grip {
  width: 26px; height: 10px; cursor: move; border-radius: 4px; margin-bottom: 2px;
  background: radial-gradient(circle, #6b6b74 1px, transparent 1.5px) 0 0 / 5px 5px;
}
.toolbox button {
  width: 34px; height: 34px; display: grid; place-items: center; background: transparent; border: 0;
  border-radius: var(--r-sm); color: #c9c9cf; cursor: pointer;
}
.toolbox button:hover { background: var(--hover); color: var(--text); }
.toolbox button.on { background: var(--accent-d); color: var(--accent); box-shadow: inset 0 0 0 1px rgba(127,184,154,.35); }
.toolbox svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.toolbox svg .thin { stroke-width: 1.2; opacity: .55; }
.toolbox svg .fill-ok { fill: var(--green); stroke: none; }
.toolbox svg .fill-bad { fill: var(--red); stroke: none; }
.tb-sep { width: 22px; height: 1px; background: var(--line2); margin: 3px 0; }
.tb-zoom { font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; padding: 1px 0; min-width: 34px; text-align: center; }
.toolhint {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%); z-index: 4;
  padding: 5px 11px; border-radius: 7px; font-size: 12px; font-weight: 500;
  background: rgba(28,28,32,.92); border: 1px solid var(--line2); color: var(--text); pointer-events: none;
  box-shadow: 0 4px 14px rgba(0,0,0,.35); white-space: nowrap;
}
.stage.tool-fg canvas, .stage.tool-bg canvas, .stage.tool-lasso canvas, .stage.tool-erase canvas { cursor: crosshair; }

.row { display: flex; gap: 6px; align-items: center; }
.row.end { justify-content: flex-end; margin-top: 16px; }
.grow { flex: 1; min-width: 0; }

/* ---------- Boutons */
.btn {
  background: var(--card); border: 1px solid transparent; border-radius: var(--r-sm);
  padding: 6px 11px; cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--hover); }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--card); color: var(--text); }
.btn.on { background: var(--accent-d); color: var(--accent); border-color: rgba(127,184,154,.35); }
.btn.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { background: var(--accent-h); }
.card .btn:not(.ghost):not(.on):not(.primary), .card select { background: #303037; }
.card .btn:not(.ghost):not(.on):not(.primary):hover, .card select:hover { background: #393941; }
.card .btn.ghost:hover { background: #303037; }
.btn:disabled { opacity: .45; cursor: default; }
select:disabled { opacity: .4; }
select {
  background: var(--card); border: 1px solid transparent; border-radius: var(--r-sm); padding: 5px 7px; cursor: pointer;
}
select:hover { background: var(--hover); }
.check { display: flex; align-items: center; gap: 7px; color: var(--muted); cursor: pointer; }
input[type=checkbox], input[type=range] { accent-color: var(--accent); }

/* ---------- Galerie */
.drop {
  border: 1.5px dashed var(--line2); border-radius: var(--radius); padding: 16px 10px;
  text-align: center; display: flex; flex-direction: column; gap: 4px; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.drop strong { font-weight: 600; }
.drop span { color: var(--muted); font-size: 11.5px; }
.drop:hover, body.dragging .drop { border-color: var(--accent); background: var(--accent-d); }
.gal-head { color: var(--muted); font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: .6px; margin-top: 4px; }
.thumbs { list-style: none; margin: 0 -4px 0 0; padding: 0 4px 0 0; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 8px; }
.thumbs li {
  position: relative; border-radius: var(--r-sm); overflow: hidden; cursor: pointer;
  outline: 2px solid transparent; outline-offset: -2px; background: #000; flex-shrink: 0;
  transition: outline-color .12s;
}
.thumbs li:hover { outline-color: var(--line2); }
.thumbs li.sel { outline-color: var(--accent); }
.thumbs li img { display: block; width: 100%; aspect-ratio: 16/10; object-fit: cover; }
.thumbs .cap {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 16px 7px 5px;
  background: linear-gradient(transparent, rgba(0,0,0,.82));
  font-size: 11px; display: flex; gap: 6px; align-items: center;
}
.thumbs .cap .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 10.5px; font-weight: 600; padding: 1px 6px; border-radius: 10px; background: #333; font-variant-numeric: tabular-nums; }
.badge.g { background: rgba(70,167,88,.25); color: #8fe0a3; }
.badge.o { background: rgba(240,164,58,.25); color: #ffd18a; }
.badge.r { background: rgba(229,72,77,.28); color: #ffa3a6; }
.thumbs .refmark {
  position: absolute; top: 5px; left: 5px; font-size: 10px; padding: 1px 6px;
  border-radius: 10px; background: var(--cyan); color: #032; font-weight: 600;
}
.thumbs .del {
  position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 6px;
  border: none; background: rgba(0,0,0,.6); cursor: pointer; opacity: 0; line-height: 1;
  transition: opacity .12s, background .12s;
}
.thumbs li:hover .del { opacity: 1; }
.thumbs .del:hover { background: var(--red); }
.thumbs li.new { animation: flash 1.2s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 3px var(--accent); } to { box-shadow: 0 0 0 0 transparent; } }

/* ---------- Barre d'outils */
.toolbar {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; flex-wrap: wrap;
  background: var(--pane); border-bottom: 1px solid var(--line);
}
.seg { display: inline-flex; background: var(--field); border-radius: var(--r-sm); padding: 2px; gap: 2px; }
.seg button {
  background: transparent; border: 0; padding: 4px 11px; cursor: pointer; border-radius: 5px; color: var(--muted);
  transition: background .12s, color .12s;
}
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.35); }
.sep { width: 1px; height: 18px; background: var(--line2); margin: 0 2px; }
.tog { display: flex; align-items: center; gap: 5px; color: var(--muted); cursor: pointer; user-select: none; }
.tog:hover { color: var(--text); }
.tog.op input { width: 64px; }

/* ---------- Vue */
.stage { position: relative; flex: 1; min-height: 200px; background: var(--stage); overflow: hidden; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: grab; }
.stage.roi canvas { cursor: crosshair; }
.stage.panning canvas { cursor: grabbing; }
.empty {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
  justify-content: center; color: var(--muted); pointer-events: none; text-align: center;
}
.empty p { margin: 3px; }
.empty strong { color: var(--text); font-size: 15px; font-weight: 600; }
.readout {
  position: absolute; left: 12px; bottom: 10px; font-size: 11.5px; color: #d4d4d8;
  background: rgba(17,17,19,.75); backdrop-filter: blur(6px); padding: 3px 8px; border-radius: 6px; pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.readout:empty { display: none; }
.cambar {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 6px; align-items: center; background: rgba(28,28,32,.9); backdrop-filter: blur(8px);
  border: 1px solid var(--line2); border-radius: var(--radius); padding: 6px 8px; box-shadow: 0 6px 20px rgba(0,0,0,.4);
}
.cambar select { max-width: 180px; }
.stage.seed canvas { cursor: copy; }
.stage.seed::after, .stage.roi::after {
  position: absolute; top: 12px; right: 12px; padding: 5px 10px; border-radius: 6px;
  font-size: 12px; font-weight: 600; box-shadow: 0 4px 14px rgba(0,0,0,.35);
}
.stage.seed::after {
  content: "Clic gauche = textile · clic droit = fond · clic sur un point = le retirer · Échap pour finir";
  background: var(--green); color: #031;
}
.stage.roi::after {
  content: "Dessine un rectangle sur du tissu sain · Échap pour annuler";
  background: var(--cyan); color: #032;
}
.warn { color: var(--orange); }
.ref-label code { background: var(--field); padding: 0 4px; border-radius: 4px; }

/* ---------- Stats */
.stats {
  display: flex; gap: 6px; padding: 10px 12px; flex-wrap: wrap;
  background: var(--bg); min-height: 42px;
}
.chip {
  background: var(--card); border-radius: 20px; padding: 3px 10px; color: var(--muted);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.chip b { font-weight: 600; color: var(--text); }
.chip.r b { color: var(--red); } .chip.o b { color: var(--orange); } .chip.g b { color: var(--accent); }

/* ---------- Bas */
.bottom {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 0 12px 12px;
  background: var(--bg); height: 200px;
}
.card { background: var(--card); border-radius: var(--radius); padding: 12px; }
.card-h { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-weight: 600; }
.hist { display: flex; flex-direction: column; min-height: 0; }
.hist canvas { flex: 1; width: 100%; min-height: 0; cursor: pointer; }
.legend { font-weight: 400; color: var(--muted); font-size: 11px; display: flex; align-items: center; gap: 4px; }
.lg { display: inline-block; width: 10px; height: 3px; margin-left: 6px; border-radius: 1px; }
.lg.cur { background: var(--accent); height: 8px; }
.lg.ref { background: #c9c9cf; }
.lg.thr { background: var(--red); width: 3px; height: 10px; }
.defects { display: flex; flex-direction: column; min-height: 0; }
.tablewrap { overflow-y: auto; flex: 1; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; position: sticky; top: 0; background: var(--card); }
th, td { padding: 4px 6px; border-bottom: 1px solid var(--line); }
tbody tr { cursor: pointer; }
tbody tr:hover, tbody tr.hl { background: var(--hover); }
.kind { display: inline-flex; align-items: center; gap: 6px; }
.kind::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
.kind.couleur::before { background: var(--orange); }
.kind.fil::before { background: #c86bf0; }
.kind.manuel::before { background: #f472b6; }
.off-engine { display: none !important; }
.bar2 { display: flex; height: 6px; width: 70px; border-radius: 3px; overflow: hidden; background: #333; }
.bar2 i { display: block; height: 100%; }

/* ---------- Paramètres */
.ref-label { font-size: 12px; line-height: 1.45; margin-bottom: 10px; color: var(--muted); }
.ref-label b { color: var(--cyan); font-weight: 600; }
.presets { display: flex; flex-direction: column; gap: 8px; }

.psearch { position: relative; }
.psearch input {
  width: 100%; background: var(--field); border: 1px solid var(--line2); border-radius: var(--r-sm);
  padding: 7px 10px 7px 30px; outline: none; transition: border-color .12s;
}
.psearch input:focus { border-color: var(--accent); }
.psearch::before {
  content: ""; position: absolute; left: 10px; top: 50%; width: 9px; height: 9px; margin-top: -6px;
  border: 1.5px solid var(--muted); border-radius: 50%;
}
.psearch::after {
  content: ""; position: absolute; left: 19px; top: 50%; width: 5px; height: 1.5px; margin-top: 4px;
  background: var(--muted); transform: rotate(45deg);
}
.sec-h {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .6px;
  margin: 6px 2px -4px;
}
.cnt { font-size: 11px; color: var(--accent); font-weight: 500; text-transform: none; letter-spacing: 0; }
.essentials .body { display: flex; flex-direction: column; }
.essentials .prm:first-child { border-top: 0; padding-top: 0; }

.grp { background: var(--card); border-radius: var(--radius); }
.grp + .grp { margin-top: 6px; }
.grp > summary {
  list-style: none; cursor: pointer; padding: 10px 12px; font-weight: 500; display: flex;
  justify-content: space-between; align-items: center; border-radius: var(--radius);
}
.grp > summary:hover { background: var(--hover); }
.grp > summary::-webkit-details-marker { display: none; }
.grp > summary::before { content: "›"; color: var(--muted); width: 14px; font-size: 15px; line-height: 1; transition: transform .15s; display: inline-block; }
.grp[open] > summary::before { transform: rotate(90deg); }
.grp > summary .t { flex: 1; }
.grp .body { padding: 0 12px 8px; }
.prm { padding: 9px 0; border-top: 1px solid var(--line); }
.prm-head { display: flex; align-items: center; gap: 6px; }
.prm-head > label:first-child { flex: 1; cursor: default; }
.prm.changed .prm-head > label:first-child { color: var(--accent); }
.prm .num {
  width: 68px; background: var(--field); border: 1px solid transparent; border-radius: 5px;
  padding: 2px 6px; text-align: right; font-variant-numeric: tabular-nums; outline: none;
}
.prm .num:focus { border-color: var(--accent); }
.prm select.choice { max-width: 150px; background: var(--field); }
#presetInfo:empty { display: none; }
#presetInfo { line-height: 1.45; }
.prm .rst, .prm .inf {
  background: none; border: 0; color: var(--faint); cursor: pointer; padding: 0; width: 18px; height: 18px;
  border-radius: 50%; font-size: 12px; line-height: 18px; text-align: center; flex-shrink: 0;
}
.prm .inf { font-size: 11px; font-weight: 600; font-style: italic; font-family: Georgia, serif; border: 1px solid var(--line2); width: 16px; height: 16px; line-height: 14px; }
.prm .rst { visibility: hidden; }
.prm.changed .rst { visibility: visible; }
.prm .rst:hover, .prm .inf:hover { color: var(--text); }
.prm.open .inf { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.prm input[type=range] { width: 100%; margin: 8px 0 0; }
.prm .help {
  display: none; color: var(--muted); font-size: 11.5px; line-height: 1.5; margin-top: 8px;
  padding: 8px 10px; background: var(--field); border-radius: 6px;
}
.prm.open .help { display: block; }
.prm .stagetag { font-size: 10px; color: var(--muted); border: 1px solid var(--line2); border-radius: 4px; padding: 0 4px; white-space: nowrap; }
.switch { position: relative; display: inline-block; width: 30px; height: 17px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #3a3a41; border-radius: 9px; cursor: pointer; transition: background .15s; }
.switch span::after { content: ""; position: absolute; width: 13px; height: 13px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: transform .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(13px); }
mark { background: rgba(127,184,154,.3); color: inherit; border-radius: 2px; }
.nomatch { text-align: center; padding: 16px 0; }

/* ---------- Modale, toasts */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; z-index: 20; }
.modal-box { background: var(--pane); border: 1px solid var(--line2); border-radius: 14px; padding: 20px; width: min(420px, 92vw); box-shadow: 0 20px 50px rgba(0,0,0,.5); }
.modal-box .qr { display: block; margin: 12px auto; width: 220px; height: 220px; background: #fff; border-radius: 8px; }
.modal-box code { background: var(--card); padding: 2px 6px; border-radius: 4px; user-select: all; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 30; }
.toast {
  background: var(--card); border: 1px solid var(--line2); border-left: 3px solid var(--accent);
  padding: 9px 13px; border-radius: 8px; max-width: 380px; box-shadow: 0 8px 24px rgba(0,0,0,.45);
}
.toast.err { border-left-color: var(--red); }
.toast.ok { border-left-color: var(--green); }

/* ---------- Écrans étroits */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 196px minmax(0, 1fr) 300px; }
  .bottom { grid-template-columns: 1fr; height: 300px; }
}
@media (max-width: 820px) {
  html, body { height: auto; }
  .layout { display: flex; flex-direction: column; height: auto; }
  .gallery { border-right: 0; border-bottom: 1px solid var(--line); max-height: 320px; }
  .stage { height: 60vh; flex: none; }
  .params, .simplepanel { border-left: 0; overflow: visible; }
}

/* Flux webcam : doit rester "visible" pour le navigateur (Firefox suspend
   les vidéos en display:none), mais invisible à l'écran. */
.camsrc { position: absolute; left: 0; top: 0; width: 2px; height: 2px; opacity: 0.01; pointer-events: none; }

.stale { background: var(--red); color: #fff; padding: 8px 14px; font-size: 13px; }
.stale code { background: rgba(0,0,0,.25); padding: 0 4px; border-radius: 3px; }
body:has(.stale) .layout { height: calc(100% - 48px - 36px); }

/* Étapes du parcours (cliquables) */
.steps { display: flex; gap: 4px; align-items: center; margin-left: 18px; }
.steps button {
  font-size: 11.5px; color: var(--faint); padding: 3px 8px; border-radius: 12px; white-space: nowrap;
  background: transparent; border: 0; cursor: pointer;
}
.steps button:hover { color: var(--text); background: var(--card); }
.steps button.done { color: var(--muted); }
.steps button.on { color: var(--accent-ink); background: var(--accent); font-weight: 600; }
.steps i { width: 10px; height: 1px; background: var(--line2); }
body:not(.simple):not(.page) .steps { display: none; }
@media (max-width: 1100px) { .steps { display: none; } }
.flash { animation: flashcard 1.2s ease-out; }
@keyframes flashcard { from { box-shadow: 0 0 0 3px var(--accent); } to { box-shadow: 0 0 0 0 transparent; } }

/* ---------- Projets : en-tête commun */
a.prog { text-decoration: none; color: inherit; }
.projname {
  background: transparent; border: 1px solid transparent; border-radius: 6px; padding: 4px 8px;
  font-weight: 600; font-size: 13.5px; width: 220px; color: var(--text); outline: none;
}
.projname:hover { border-color: var(--line2); }
.projname:focus { border-color: var(--accent); background: var(--field); }
#projSaved { min-width: 90px; font-size: 11px; }
.steps button b { font-weight: 600; opacity: .7; margin-right: 2px; }
.steps button.locked { opacity: .4; cursor: not-allowed; }
.steps button.locked:hover { background: transparent; color: var(--faint); }
@media (max-width: 1350px) { .projname { width: 150px; } #projSaved { display: none; } }

/* Projet : pas de galerie, une seule photo */
body.project .layout { grid-template-columns: minmax(0, 1fr) 340px; }
body.project .gallery { display: none; }
body.project .viewer { grid-column: 1; grid-row: 1; }
body.project .params, body.project .simplepanel { grid-column: 2; }
@media (max-width: 1100px) { body.project .layout { grid-template-columns: minmax(0, 1fr) 300px; } }

/* Choix de la photo d'un projet */
.photopick {
  position: absolute; inset: 0; z-index: 8; background: var(--stage); overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; padding: 40px 24px; gap: 18px;
}
.photopick h2 { font-size: 20px; margin: 0; }
.photopick .sub { color: var(--muted); margin: -8px 0 0; text-align: center; }
.photopick .drop { width: min(560px, 100%); padding: 34px 16px; }
.photopick .drop strong { font-size: 15px; }
.photopick .row { justify-content: center; }
.photopick h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 10px 0 0; font-weight: 600; }
.photogrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; width: min(900px, 100%); }
.photogrid button {
  background: var(--card); border: 1px solid transparent; border-radius: var(--radius); padding: 6px; cursor: pointer;
  display: flex; flex-direction: column; gap: 6px; text-align: left; color: inherit;
}
.photogrid button:hover { border-color: var(--accent); }
.photogrid button.cur { border-color: var(--accent); background: var(--accent-d); }
.photogrid img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 6px; background: #000; }
.photogrid span { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.revalidate { background: rgba(240,164,58,.12); border: 1px solid rgba(240,164,58,.35); border-radius: 7px; padding: 7px 9px; font-size: 12px; line-height: 1.45; color: #f3c27a; }
.adv-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 4px; color: var(--muted); font-size: 12.5px; }
