/*
  Mire — tableau d'outils d'atelier.
  Panneau perforé peint, bandeau en isorel, emplacements arrondis, plaque en
  bouleau accrochée à deux chevilles. Orange atelier réservé à la zone active
  et à l'action principale. Langage fixe des couches : raster bleu, gravure
  brun brûlé, découpe vert. Thème clair au bureau comme à l'atelier,
  thème sombre en isorel foncé selon le système.
*/

:root {
  color-scheme: light dark;

  /* Panneau et matières */
  --board: #e6e9e2;
  --board-hole: #ccd1c7;
  --hardboard: #7a4f31;
  --hardboard-hole: #5f3b22;
  --hardboard-ink: #fff6ea;
  --hardboard-soft: #f1dcc3;
  --slot: #fbfbf8;
  --slot-edge: #d5d9cf;
  --field: #ffffff;
  --field-edge: #c9cec3;
  --field-hover: #a9afa2;
  --birch: #ecd2a4;
  --birch-edge: #c99f69;
  --burn: #3a2314;
  --burn-ink: #4a2c17;
  --cut-line: #5a3a1e;
  --peg: #9a6a43;
  --peg-shade: #5f3b22;

  /* Encre */
  --ink: #2a241f;
  --ink-soft: #5c544c;
  --ink-faint: #7b7269;

  /* Couleurs fonctionnelles */
  --accent: #e8601c;
  --accent-strong: #c24c0e;
  --accent-ink: #ffffff;
  --accent-wash: #fde6d6;
  --raster: #3d6cb0;
  --engrave: #8a5a2b;
  --cut: #1f7f66;
  --error: #b42a2a;
  --error-wash: #fbe9e7;
  --warn: #8a5600;
  --warn-wash: #fbf0d9;
  --ok: #2f7d4a;

  /* Forme */
  --radius-s: 10px;
  --radius-m: 14px;
  --radius-l: 20px;
  --radius-xl: 26px;
  --shadow-slot: 0 1px 0 rgba(60, 40, 20, 0.08), 0 8px 22px -10px rgba(60, 40, 20, 0.28);
  --shadow-btn: 0 2px 0 rgba(40, 20, 5, 0.35), 0 6px 14px -6px rgba(40, 20, 5, 0.45);
  --gap: 16px;
  --pad: 20px;
  --hole: 24px;
  --plate-w: clamp(380px, calc(100vh - 300px), 640px);

  /* Mouvement */
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --fast: 150ms;
  --mid: 250ms;

  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --board: #2a231e;
    --board-hole: #1d1814;
    --hardboard: #1c1612;
    --hardboard-hole: #0f0c09;
    --hardboard-ink: #f6eadb;
    --hardboard-soft: #d9c3a8;
    --slot: #372e28;
    --slot-edge: #4a3f37;
    --field: #2a231e;
    --field-edge: #5b4e44;
    --field-hover: #7d6d60;
    --ink: #f4ece2;
    --ink-soft: #cfc0b0;
    --ink-faint: #ab9b8b;
    --accent: #ff7a33;
    --accent-strong: #ff9152;
    --accent-ink: #2a1408;
    --accent-wash: #4a2a17;
    --raster: #7aa5e6;
    --engrave: #d29a62;
    --cut: #4fc29f;
    --error: #ff8a80;
    --error-wash: #4a2622;
    --warn: #f2c05c;
    --warn-wash: #463619;
    --ok: #7ccf96;
    --shadow-slot: 0 1px 0 rgba(0, 0, 0, 0.4), 0 10px 24px -10px rgba(0, 0, 0, 0.7);
    --peg: #b07d52;
  }
}

/* ---------------------------------------------------------------- base */

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

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

body {
  margin: 0;
  min-height: 100vh;
  font: 400 15px/1.45 var(--font);
  color: var(--ink);
  background-color: var(--board);
  background-image: radial-gradient(circle at calc(var(--hole) / 2) calc(var(--hole) / 2), var(--board-hole) 2.4px, transparent 2.9px);
  background-size: var(--hole) var(--hole);
  font-variant-numeric: tabular-nums;
}

::selection { background: var(--accent); color: var(--accent-ink); }

h1, h2, p { margin: 0; }

button, input { font: inherit; color: inherit; }

svg { flex: none; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip {
  position: absolute; left: 16px; top: -60px; z-index: 30;
  padding: 10px 16px; border-radius: var(--radius-s);
  background: var(--accent); color: var(--accent-ink); font-weight: 600; text-decoration: none;
  transition: top var(--fast) var(--ease);
}
.skip:focus { top: 12px; }

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

/* --------------------------------------------------------------- bandeau */

.bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: 72px; padding: 12px clamp(16px, 3vw, 32px);
  color: var(--hardboard-ink);
  background-color: var(--hardboard);
  background-image: radial-gradient(circle at calc(var(--hole) / 2) calc(var(--hole) / 2), var(--hardboard-hole) 2.4px, transparent 2.9px);
  background-size: var(--hole) var(--hole);
  box-shadow: 0 6px 18px -10px rgba(30, 15, 5, 0.6);
}

.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }

.mark { width: 42px; height: 42px; }
.mark rect { fill: var(--birch); }
.mark circle { fill: var(--hardboard); }
.mark .hot { fill: var(--accent); }

.brand h1 { font-size: 26px; font-weight: 750; letter-spacing: 0.01em; line-height: 1.1; }
.brand p { font-size: 13.5px; color: var(--hardboard-soft); }

.actions { display: flex; gap: 10px; }

/* --------------------------------------------------------- boutons icône */

.icon-btn {
  position: relative;
  display: inline-grid; place-items: center;
  width: 48px; height: 48px; padding: 0;
  border: 0; border-radius: var(--radius-m);
  background: var(--hardboard-ink); color: var(--hardboard);
  box-shadow: var(--shadow-btn);
  cursor: pointer;
  transition: transform var(--fast) var(--ease), background-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:hover { transform: translateY(-1px); }
.icon-btn:active { transform: translateY(1px); box-shadow: 0 1px 0 rgba(40, 20, 5, 0.35); }

.icon-btn.primary { background: var(--accent); color: var(--accent-ink); }
.icon-btn.primary:hover { background: var(--accent-strong); }

.icon-btn[aria-disabled="true"] {
  cursor: not-allowed;
  background: color-mix(in srgb, var(--hardboard-ink) 55%, var(--hardboard));
  color: var(--hardboard);
  transform: none;
}

.icon-btn .when-busy { display: none; }
.icon-btn[aria-busy="true"] .when-busy { display: block; }
.icon-btn[aria-busy="true"] .when-idle { display: none; }

.icon-btn.small {
  width: 36px; height: 36px; margin-left: auto;
  border-radius: var(--radius-s);
  background: transparent; color: var(--ink-soft); box-shadow: none;
}
.icon-btn.small svg { width: 18px; height: 18px; }
.icon-btn.small:hover { background: color-mix(in srgb, var(--ink) 8%, transparent); color: var(--ink); transform: none; }

/* Bouton de téléchargement en deux parties et menu des formats */
.split-button {
  position: relative;
  display: inline-flex;
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-btn);
}
.split-button .icon-btn { box-shadow: none; }
.split-button .icon-btn:active { box-shadow: none; }
.split-main { border-radius: var(--radius-m) 0 0 var(--radius-m); }
.split-toggle {
  width: 32px;
  border-radius: 0 var(--radius-m) var(--radius-m) 0;
  border-left: 1px solid color-mix(in srgb, var(--accent-ink) 35%, transparent);
}
.split-toggle svg { width: 18px; height: 18px; transition: transform var(--fast) var(--ease); }
.split-toggle[aria-expanded="true"] svg { transform: rotate(180deg); }
.split-toggle[aria-expanded="true"]::after { display: none; }
.split-button .icon-btn[aria-disabled="true"] { border-left-color: color-mix(in srgb, var(--hardboard) 30%, transparent); }

.format-menu {
  position: absolute; top: calc(100% + 10px); right: 0; z-index: 45;
  min-width: 232px; margin: 0; padding: 6px;
  list-style: none;
  border-radius: var(--radius-m);
  background: var(--slot); color: var(--ink);
  box-shadow: 0 1px 0 rgba(60, 40, 20, 0.08), 0 16px 32px -12px rgba(30, 15, 5, 0.55);
  animation: menu-in var(--fast) var(--ease);
}
.format-menu[hidden] { display: none; }
.format-menu li {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-s);
  cursor: pointer;
  font-weight: 550;
}
.format-menu li:hover,
.format-menu li:focus { background: var(--accent-wash); outline: none; }
.format-menu li:focus-visible { outline: 3px solid var(--accent-strong); outline-offset: -3px; }
.format-menu .tick { width: 18px; height: 18px; color: var(--accent-strong); visibility: hidden; }
.format-menu li[aria-checked="true"] .tick { visibility: visible; }
.format-menu .format-ext { margin-left: auto; color: var(--ink-soft); font-weight: 400; font-variant-numeric: normal; }

@keyframes menu-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .format-menu { animation: none; }
  .split-toggle svg { transition: none; }
}

/* Infobulle, au survol et au focus clavier */
[data-tip]::after {
  content: attr(data-tip);
  position: absolute; top: calc(100% + 10px); right: 0; z-index: 40;
  width: max-content; max-width: 260px;
  padding: 7px 11px; border-radius: var(--radius-s);
  background: var(--ink); color: var(--slot);
  font-size: 13px; font-weight: 500; line-height: 1.3; text-align: left; white-space: normal;
  box-shadow: 0 8px 20px -8px rgba(0, 0, 0, 0.45);
  opacity: 0; transform: translateY(-4px); pointer-events: none;
  transition: opacity var(--fast) var(--ease), transform var(--fast) var(--ease);
}
[data-tip]:hover::after,
[data-tip]:focus-visible::after { opacity: 1; transform: none; transition-delay: 250ms; }
[data-tip]:focus-visible::after { transition-delay: 0ms; }

/* ------------------------------------------------------------- bandeaux */

.banner {
  display: flex; align-items: center; gap: 12px;
  margin: 16px clamp(16px, 3vw, 32px) 0; padding: 12px 16px;
  border-radius: var(--radius-m);
  background: var(--error-wash); color: var(--error);
  font-weight: 600;
}
.banner[hidden] { display: none; }
.banner svg { width: 22px; height: 22px; }
.banner code { font-weight: 500; }

/* ----------------------------------------------------------- établi */

.workbench {
  display: grid;
  grid-template-columns: minmax(400px, 480px) minmax(0, 1fr);
  gap: clamp(20px, 3vw, 40px);
  align-items: start;
  max-width: 1480px; margin: 0 auto;
  padding: 28px clamp(16px, 3vw, 32px) 48px;
}

.board { display: flex; flex-direction: column; gap: var(--gap); }

/* -------------------------------------------------------- emplacements */

.slot {
  position: relative;
  padding: 16px var(--pad) 14px;
  border-radius: var(--radius-l);
  background: var(--slot);
  box-shadow: var(--shadow-slot);
  outline: 3px solid transparent; outline-offset: 3px;
  transition: outline-color var(--mid) var(--ease);
}
.slot.is-active { outline-color: var(--accent); }
.slot.is-invalid { outline-color: transparent; }

.slot[data-zone="raster"] { --zone: var(--raster); }
.slot[data-zone="engrave"] { --zone: var(--engrave); }
.slot[data-zone="cut"] { --zone: var(--cut); }
.slot[data-zone="title"] { --zone: var(--ink-soft); }
.slot[data-zone="assembly"] { --zone: var(--ink-soft); }
.slot[data-zone="machine"] { --zone: var(--ink-soft); }

.slot-head { display: flex; align-items: center; gap: 10px; min-height: 36px; }
.slot-head h2 { font-size: 18px; font-weight: 650; letter-spacing: 0.005em; }
.slot-head label { cursor: inherit; }

.chip {
  display: inline-block; width: 12px; height: 12px; border-radius: 4px;
  background: var(--zone, var(--ink-soft));
}
.slot-icon { display: grid; place-items: center; width: 22px; height: 22px; color: var(--zone, var(--ink-soft)); }
.slot-icon svg { width: 20px; height: 20px; }

.title-field { position: relative; margin-top: 10px; }
.title-field input {
  width: 100%; height: 56px; padding: 0 70px 0 16px;
  font-size: 20px; font-weight: 650;
}
.title-field output {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  font-size: 13px; color: var(--ink-faint);
}
.title-field output.is-near { color: var(--warn); font-weight: 600; }

fieldset.line { margin: 0; padding: 0; border: 0; min-width: 0; }

.line {
  display: grid; grid-template-columns: 124px minmax(0, 1fr);
  align-items: center; gap: 10px;
  margin-top: 12px;
}
.line-label {
  display: flex; align-items: center; gap: 8px; float: left;
  padding: 0; font-size: 14px; color: var(--ink-soft);
}
.line-label svg { width: 18px; height: 18px; color: var(--ink-faint); }

.inputs {
  display: grid; grid-template-columns: minmax(0, 1fr) 18px minmax(0, 1fr) 44px;
  align-items: center; gap: 6px;
}
.inputs.single { grid-template-columns: minmax(0, 1fr) 18px minmax(0, 1fr) 44px; }
.inputs.single input { grid-column: 1; }
.inputs.single .unit { grid-column: 2 / span 2; }
/* Réglage machine (007) : deux valeurs d'unités différentes, chacune suivie de son unité. */
.inputs.pair { grid-template-columns: minmax(0, 1fr) 44px minmax(0, 1fr) 44px; }
/* Section machine : champs seuls sur la grille des paires, tous les champs de même largeur. */
.slot[data-zone="machine"] .inputs.single { grid-template-columns: minmax(0, 1fr) 44px minmax(0, 1fr) 44px; }

.dash { height: 2px; border-radius: 2px; background: var(--field-edge); }
.unit { font-size: 13px; color: var(--ink-faint); white-space: nowrap; }

input {
  width: 100%; min-width: 0; height: 44px; padding: 0 12px;
  border: 2px solid var(--field-edge); border-radius: var(--radius-m);
  background: var(--field);
  font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums;
  caret-color: var(--accent);
  transition: border-color var(--fast) var(--ease), background-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
input::placeholder { color: var(--ink-faint); font-weight: 500; }
input:hover { border-color: var(--field-hover); }
input:focus-visible { outline: none; border-color: var(--accent-strong); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 28%, transparent); }
input[aria-invalid="true"] {
  border-style: dashed; border-color: var(--error);
  background: var(--error-wash);
}

/* Choix exclusif en segments (forme des cases de découpe) */
.choices {
  display: flex; flex-wrap: wrap;
  gap: 4px; padding: 4px;
  border: 2px solid var(--field-edge); border-radius: var(--radius-m);
  background: var(--field);
}
.choice {
  position: relative; flex: 1 1 auto;
  display: flex; white-space: nowrap; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 8px;
  border-radius: calc(var(--radius-m) - 4px);
  font-size: 14px; font-weight: 600; line-height: 1.15; text-align: center;
  color: var(--ink-soft); cursor: pointer;
  transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease);
}
.choice svg {
  flex: none; width: 16px; height: 16px;
  fill: none; stroke: currentColor; stroke-width: 2.2;
}
.choice input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  margin: 0; padding: 0; border: 0; opacity: 0; cursor: pointer;
}
.choice:hover { color: var(--ink); background: color-mix(in srgb, var(--field-edge) 35%, transparent); }
.choice:has(input:checked) { background: var(--accent); color: var(--accent-ink); }
.choice:has(input:focus-visible) { outline: 3px solid var(--accent-strong); outline-offset: 2px; }

/* Case à cocher (affichage de la notice LightBurn, 009) */
.slot[data-zone="notice"] { --zone: var(--ink-soft); }
.check-line {
  display: flex; align-items: center; gap: 12px;
  margin-top: 12px; min-height: 44px;
  font-size: 15px; font-weight: 600; cursor: pointer;
}
.check-line input[type="checkbox"] {
  flex: none; width: 22px; height: 22px; margin: 0; padding: 0;
  border-radius: 6px;
  accent-color: var(--accent-strong);
  cursor: pointer;
}
.check-line input[type="checkbox"]:focus-visible { outline: 3px solid var(--accent-strong); outline-offset: 2px; box-shadow: none; }
.help {
  display: flex; align-items: flex-start; gap: 8px;
  margin-top: 6px; font-size: 13.5px; line-height: 1.35; color: var(--ink-soft);
}
.help svg { width: 16px; height: 16px; margin-top: 1px; color: var(--ink-faint); }
.slot[data-zone="notice"] .msg { margin-left: 0; }

/* Messages sous la ligne */
.msg {
  display: none; align-items: flex-start; gap: 8px;
  margin: 8px 0 0 134px; font-size: 13.5px; font-weight: 600; line-height: 1.35;
}
.msg.is-error, .msg.is-warn { display: flex; }
.msg.is-error { color: var(--error); }
.msg.is-warn { color: var(--warn); }
.msg svg { width: 16px; height: 16px; margin-top: 1px; }
.slot[data-zone="title"] .msg { margin-left: 0; }

/* -------------------------------------------------------------- scène */

.stage {
  position: sticky; top: 96px;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  min-width: 0;
  container: stage / inline-size;
}

.hanger {
  position: relative; width: 100%; max-width: var(--plate-w);
  padding-top: 10px;
}

/* Chevilles plantées dans le haut de la plaque : elles la tiennent au panneau. */
.peg {
  position: absolute; top: 10px; z-index: 2;
  width: 18px; height: 18px; border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 35% 35%, color-mix(in srgb, var(--peg) 65%, white), var(--peg) 55%, var(--peg-shade));
  box-shadow:
    0 0 0 3px color-mix(in srgb, var(--burn) 22%, transparent),
    0 4px 5px -1px rgba(30, 15, 5, 0.55);
}
.peg:first-child { left: 11%; }
.peg:nth-child(2) { left: 89%; }

.plate-view {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-xl);
  filter: drop-shadow(0 2px 2px rgba(60, 35, 10, 0.18)) drop-shadow(0 24px 30px rgba(60, 35, 10, 0.32));
  transition: opacity var(--mid) var(--ease), filter var(--mid) var(--ease);
}
.plate-view[aria-busy="true"] { opacity: 0.72; }
.plate-view > svg { display: block; width: 100%; height: 100%; }

.plate-view .plate { fill: var(--birch); stroke: var(--birch-edge); stroke-width: 0.6; }

/* Atténuation portée par les enfants, jamais par le groupe de zone : un groupe
   à opacité partielle isole ses enfants, et le multiply du raster se ferait
   alors sur fond transparent (cases blanchies au lieu de prendre le bouleau). */
.plate-view g[data-zone] > :not(.zone-frame) { transition: opacity var(--mid) var(--ease); }
.plate-view .k-scan { fill: var(--burn); }
.plate-view .k-image { mix-blend-mode: multiply; }
.plate-view .k-cut { fill: none; stroke: var(--cut-line); stroke-width: 0.35; stroke-linejoin: round; stroke-linecap: round; }
.plate-view .k-label { fill: var(--burn-ink); }
.plate-view .k-line { fill: none; stroke: var(--burn-ink); stroke-width: 0.3; stroke-linecap: round; }

.plate-view .zone-frame {
  fill: none; stroke: var(--accent); stroke-width: 0.9;
  stroke-dasharray: 100; stroke-dashoffset: 100; opacity: 0;
  transition: stroke-dashoffset 420ms var(--ease), opacity var(--fast) var(--ease);
}

.stage[data-active] .plate-view g[data-zone]:not(.is-active):not(.is-invalid) > :not(.zone-frame) { opacity: 0.38; }
.plate-view g.is-active .zone-frame { stroke-dashoffset: 0; opacity: 1; }
.plate-view g.is-invalid .zone-frame {
  stroke: var(--error); stroke-dasharray: 2 1.6; stroke-dashoffset: 0; opacity: 1;
}

/* Légende des valeurs calculées */
.legend {
  width: 100%; max-width: max(var(--plate-w), 480px);
  border-collapse: separate; border-spacing: 0;
  font-size: 14px;
  background: var(--slot); border-radius: var(--radius-l);
  box-shadow: var(--shadow-slot);
  overflow: hidden;
}
.legend th, .legend td { padding: 9px 14px; text-align: left; vertical-align: top; }
.legend thead th { font-size: 12.5px; font-weight: 600; color: var(--ink-faint); padding-bottom: 4px; }
.legend tbody th { font-weight: 650; white-space: nowrap; }
.legend tbody th .chip { margin-right: 8px; vertical-align: -1px; }
.legend td { color: var(--ink-soft); white-space: nowrap; }
.legend .vals { display: inline-flex; gap: 0.6em; }
.legend .vals span { min-width: 2ch; text-align: right; }

/* Légende étroite : vitesses au-dessus des puissances, unité en tête de ligne. */
@container stage (max-width: 620px) {
  .legend thead { display: none; }
  .legend tbody tr { display: grid; grid-template-columns: 104px minmax(0, 1fr); padding: 6px 0; }
  .legend tbody th { grid-row: span 2; padding-top: 10px; }
  .legend td {
    display: grid; grid-template-columns: 3.2em minmax(0, 1fr); align-items: baseline;
    padding: 3px 14px 3px 0; font-size: 13px;
  }
  .legend td::before { content: attr(data-unit); font-size: 12px; color: var(--ink-faint); }
  /* Rangées équilibrées : jamais de valeur orpheline. */
  .legend .vals { display: grid; grid-template-columns: repeat(var(--cols, 4), max-content); gap: 2px 0.6em; justify-items: end; }
}
.legend tr[data-zone="raster"] { --zone: var(--raster); }
.legend tr[data-zone="engrave"] { --zone: var(--engrave); }
.legend tr[data-zone="cut"] { --zone: var(--cut); }
.legend tbody tr { transition: background-color var(--mid) var(--ease); }
.legend tbody tr.is-active { background: var(--accent-wash); }
.legend tbody tr.is-active td { color: var(--ink); }
.legend td.is-stale { color: var(--ink-faint); }

.file {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; color: var(--ink-soft); font-weight: 600;
  overflow-wrap: anywhere; text-align: center;
}
.file svg { width: 16px; height: 16px; color: var(--accent-strong); }
.file:empty { display: none; }

/* --------------------------------------------------------------- toast */

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 50;
  display: flex; align-items: center; gap: 10px;
  max-width: calc(100vw - 32px);
  padding: 12px 18px; border-radius: var(--radius-m);
  background: var(--ink); color: var(--slot);
  font-weight: 600; box-shadow: 0 14px 30px -12px rgba(0, 0, 0, 0.55);
  transform: translate(-50%, 0);
  transition: opacity var(--mid) var(--ease), transform var(--mid) var(--ease);
}
.toast[hidden] { display: flex; opacity: 0; transform: translate(-50%, 16px); pointer-events: none; }
.toast svg { width: 20px; height: 20px; color: var(--ok); }
.toast span { white-space: pre-line; }
.toast.is-error svg { color: var(--error); }

.toast-action {
  margin-left: 6px; padding: 6px 12px;
  border: 0; border-radius: var(--radius-s);
  background: color-mix(in srgb, var(--slot) 16%, transparent); color: var(--slot);
  font-weight: 700; cursor: pointer;
}
.toast-action:hover { background: color-mix(in srgb, var(--slot) 26%, transparent); }
.toast-action:focus-visible { outline-color: var(--accent); }
.toast-action[hidden] { display: none; }

/* -------------------------------------------------- profils de machine (009) */

.profile-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px;
  padding: 12px 10px 8px 12px;
  border-radius: var(--radius-l);
  background: var(--slot);
  box-shadow: var(--shadow-slot);
}

/* Liste sur toute la largeur, nom du profil lisible ; intitulé et actions sur la ligne du dessous. */
.profile-picker { position: relative; order: 1; flex: 1 1 100%; min-width: 0; }
.profile-bar h2 {
  order: 2; margin-left: 4px;
  font-size: 13.5px; font-weight: 600; color: var(--ink-soft);
}

.profile-button {
  display: flex; align-items: center; gap: 10px;
  width: 100%; min-height: 44px; padding: 0 12px;
  border: 2px solid var(--field-edge); border-radius: var(--radius-m);
  background: var(--field); color: var(--ink);
  font-weight: 650; text-align: left; cursor: pointer;
  transition: border-color var(--fast) var(--ease);
}
.profile-button:hover { border-color: var(--field-hover); }
.profile-button svg { width: 18px; height: 18px; }
.profile-mark { color: var(--accent-strong); }
.profile-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-button.is-empty .profile-name { color: var(--ink-soft); font-weight: 550; }
.profile-chevron { color: var(--ink-soft); transition: transform var(--fast) var(--ease); }
.profile-button[aria-expanded="true"] .profile-chevron { transform: rotate(180deg); }

.profile-modified {
  flex: none;
  padding: 2px 9px; border-radius: 999px;
  background: var(--warn-wash); color: var(--warn);
  font-size: 12.5px; font-weight: 700;
}
.profile-modified[hidden] { display: none; }

.profile-menu { left: 0; right: auto; width: 100%; max-height: min(60vh, 420px); overflow-y: auto; }
.profile-menu li span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-menu li[aria-disabled="true"] { cursor: default; color: var(--ink-soft); font-weight: 500; }
.profile-menu li[aria-disabled="true"]:hover { background: transparent; }

.profile-actions { order: 3; display: flex; gap: 2px; flex: none; margin-left: auto; margin-bottom: -4px; }
.profile-actions .icon-btn.small { margin-left: 0; }
.profile-actions .icon-btn.small[aria-disabled="true"] {
  background: transparent; color: color-mix(in srgb, var(--ink-soft) 72%, var(--slot));
}
/* Infobulles de la barre : ouvertes vers la gauche depuis le bord droit du bouton. */
.profile-actions [data-tip]::after { right: 0; }

/* Dialogues : nom du profil, confirmations, conflits à l'import */
.dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 22px 22px 18px;
  border: 0; border-radius: var(--radius-l);
  background: var(--slot); color: var(--ink);
  box-shadow: 0 1px 0 rgba(60, 40, 20, 0.08), 0 24px 48px -16px rgba(30, 15, 5, 0.6);
}
.dialog::backdrop { background: color-mix(in srgb, var(--hardboard-hole) 55%, transparent); }
.dialog[open] { animation: menu-in var(--mid) var(--ease); }
.dialog h2 { font-size: 18px; font-weight: 650; margin-bottom: 14px; }
.dialog p { font-size: 15px; line-height: 1.45; }
.dialog-label { display: block; margin-bottom: 6px; font-size: 14px; color: var(--ink-soft); }
.dialog .msg { margin-left: 0; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.text-btn {
  min-height: 40px; padding: 0 16px;
  border: 2px solid var(--field-edge); border-radius: var(--radius-m);
  background: var(--field); color: var(--ink);
  font-weight: 650; cursor: pointer;
  transition: border-color var(--fast) var(--ease), background-color var(--fast) var(--ease);
}
.text-btn:hover { border-color: var(--field-hover); }
.text-btn.primary { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.text-btn.primary:hover { border-color: var(--accent-strong); background: var(--accent-strong); }
.text-btn.danger { border-color: var(--error); background: var(--error); color: var(--slot); }

@media (prefers-reduced-motion: reduce) {
  .dialog[open] { animation: none; }
  .profile-chevron { transition: none; }
}

.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------- adaptation */

/* Tablette : deux colonnes gardées, libellés au-dessus des champs. */
@media (max-width: 1023px) {
  .workbench { grid-template-columns: minmax(340px, 440px) minmax(300px, 1fr); }
  :root { --plate-w: 100%; }
  .line, fieldset.line { display: block; margin-top: 18px; }
  .line-label { float: none; margin-bottom: 6px; }
  .msg { margin-left: 0; }
}

/* Téléphone : réglages d'abord, plaque compacte accrochée en haut pendant la saisie. */
@media (max-width: 767px) {
  .workbench { grid-template-columns: minmax(0, 1fr); gap: 16px; padding-top: 0; }
  .stage { display: contents; }
  .hanger {
    position: sticky; top: 72px; z-index: 5; order: -1;
    width: auto; max-width: none; display: grid; justify-items: center;
    margin: 0 calc(-1 * clamp(16px, 3vw, 32px)); padding: 14px 16px 12px;
    background: color-mix(in srgb, var(--board) 94%, transparent);
    backdrop-filter: blur(6px);
    box-shadow: 0 10px 16px -14px rgba(40, 25, 10, 0.5);
  }
  .plate-view { width: min(35vh, 100%); }
  .peg:first-child { left: calc(50% - min(35vh, 100%) * 0.39); }
  .peg:nth-child(2) { left: calc(50% + min(35vh, 100%) * 0.39); }
  .peg { top: 14px; }
  .legend { order: 1; max-width: none; }
  .file { order: 2; justify-content: center; }
  .legend tbody tr { display: grid; grid-template-columns: 104px minmax(0, 1fr); padding: 6px 0; }
  .legend thead { display: none; }
  .legend tbody th { grid-row: span 2; padding-top: 10px; }
  .legend td {
    display: grid; grid-template-columns: 3.2em minmax(0, 1fr); align-items: baseline;
    padding: 3px 14px 3px 0; font-size: 13px;
  }
  .legend td::before { content: attr(data-unit); font-size: 12px; color: var(--ink-faint); }
  /* Rangées équilibrées : jamais de valeur orpheline. */
  .legend .vals { display: grid; grid-template-columns: repeat(var(--cols, 4), max-content); gap: 2px 0.6em; justify-items: end; }
}

@media (max-width: 520px) {
  .brand p { display: none; }
  .line, fieldset.line { margin-top: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media (forced-colors: active) {
  .format-menu { border: 1px solid CanvasText; }
  .format-menu li[aria-checked="true"] { outline: 1px solid Highlight; }
  .icon-btn, input, .slot, .profile-bar, .dialog, .text-btn { border: 1px solid CanvasText; }
  .profile-modified { border: 1px solid CanvasText; }
  .slot.is-active { outline-color: Highlight; }
  .choice input { border: 0; }
  .choice:has(input:checked) { outline: 2px solid Highlight; color: Highlight; }
}
