/* ==========================================================================================================
   Nesting : thème « bleu et noir » (sombre, sobre, professionnel).  Tous les écrans (outil, administration,
   connexion) partagent ce fichier ; aucune couleur en dur hors du bloc :root (et des constantes de viewer.js,
   à garder cohérentes avec --viewer-* ci-dessous).

   Principes : fonds quasi noirs légèrement bleutés, une seule couleur d'accent (bleu), texte clair ; le bleu
   signale ce qui est actionnable (bouton principal, lien, sélection, focus) ; vert/ambre/rouge ne servent qu'aux
   états (réussi / attention / erreur). Contrastes calculés (WCAG 2.x) :
     --text sur --bg 16,1:1, sur --surface 15,1:1, sur --surface-2 13,6:1 ; --text-muted sur --surface 7,4:1 ;
     --accent-text (liens) sur --surface 8,0:1 ; blanc sur --accent-strong 5,7:1 ; --text sur --selected 7,3:1 ;
     bordure des contrôles (--border-control) sur --surface 3,3:1 (≥ 3:1 pour les composants d'interface).
   Polices système uniquement (aucune ressource externe).

   Variables (à utiliser pour tout nouvel élément ; ne jamais écrire une couleur en dur) :
     Fonds       --bg            fond de page (noir bleuté) ; --surface panneaux ; --surface-2 en-têtes, barres,
                                 menus ; --surface-3 survol ; --field fond des champs, tableaux et journal.
     Bordures    --border        séparateurs discrets (non porteurs d'information) ;
                 --border-control bordure des champs/boutons (3:1 minimum) ; --border-strong cadres appuyés.
     Texte       --text principal ; --text-muted secondaire (7:1) ; --text-disabled désactivé (exempté de WCAG).
     Accent      --accent        bleu d'accent (traits, curseurs, marqueurs) ; --accent-text bleu clair pour
                                 le texte/liens ; --accent-strong fond du bouton principal (texte --on-accent) ;
                                 --accent-hover son survol ; --selected / --selected-text ligne sélectionnée ;
                                 --accent-soft voile bleu (zone de dépôt).
     États       --ok / --warn / --error (couleurs de texte ou d'icône sur --surface) et leurs fonds
                 --ok-bg / --warn-bg / --error-bg avec bordures --ok-border / --warn-border / --error-border ;
                 --error-on-bg : texte d'erreur sur --error-bg ou sur --selected.
     Focus       --focus         anneau de focus (2 px), visible sur tous les fonds.
     Graphiques  --chart-line    courbe principale ; --chart-grid quadrillage ; --chart-bad zone/courbe en
                                 défaut ; --chart-label texte des axes ; --chart-fill voile sous la courbe.
     Vue 3D      --viewer-top / --viewer-bottom dégradé de fond de la vue (clearColor de viewer.js = --viewer-bottom).
     Mesures     --radius, --radius-lg, --gap (espacement de base 6 px), --shadow-menu, --font, --mono.
   ========================================================================================================== */
:root {
  color-scheme: dark;
  --bg: #0f141d;
  --surface: #151c28;
  --surface-2: #1b2433;
  --surface-3: #243043;
  --field: #111823;
  --border: #2a3546;
  --border-control: #62748c;
  --border-strong: #35435a;
  --text: #e6ebf2;
  --text-muted: #9aa7bb;
  --text-disabled: #6b7a90;
  --accent: #4f8fe8;
  --accent-text: #6cb0ff;
  --accent-strong: #2563c9;
  --accent-hover: #2e6fdb;
  --on-accent: #ffffff;
  --selected: #1d4a8a;
  --selected-text: #e6ebf2;
  --accent-soft: rgba(76, 154, 255, .14);
  --ok: #8fe0a6;       --ok-bg: #0f2a1a;     --ok-border: #2f7d4a;
  --warn: #ffd27a;     --warn-bg: #2e2408;   --warn-border: #8a6a14;
  --error: #ff8f85;    --error-bg: #3a1512;  --error-border: #a8433a;
  --error-on-bg: #ffb4ab;
  --focus: #8ec5ff;
  --chart-line: #4c9aff;
  --chart-grid: #2a3548;
  --chart-bad: #ff6b61;
  --chart-label: #9aa7bb;
  --chart-fill: rgba(76, 154, 255, .16);
  --viewer-top: #1c2535;
  --viewer-bottom: #0f141d;
  --radius: 6px;
  --radius-lg: 10px;
  --gap: 12px;
  --gap-s: 6px;
  --gap-l: 18px;
  --control-h: 32px;
  --shadow-menu: 0 8px 24px rgba(0, 0, 0, .55);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, .35);
  --font: -apple-system, "Segoe UI", system-ui, sans-serif;
  --mono: "Menlo", "Consolas", monospace;
}

/* Thème clair : choisi dans Account → Appearance (system / dark / light, theme.js), « system » suit la préférence du système. La scène 3D et les aperçus ont un fond clair (viewer.js lit --viewer-bottom et prend des traits plus foncés). Contrastes calculés (WCAG 2.x) :
   --text sur --surface 17,6:1 ; --text-muted sur --surface 7,6:1 ; --accent-text sur --surface 6,9:1 ;
   --on-accent sur --accent-strong 5,9:1 ; --error-on-bg sur --error-bg 8,2:1 ; bordure des contrôles 4,5:1. */
:root[data-theme="light"] {
    color-scheme: light;
    --bg: #eef1f6;  --surface: #ffffff;  --surface-2: #f3f5f9;  --surface-3: #e3e9f3;  --field: #ffffff;
    --border: #d5dbe6;  --border-control: #66758b;  --border-strong: #a9b4c6;
    --text: #131a26;  --text-muted: #46546a;  --text-disabled: #8793a6;
    --accent: #1f6fe0;  --accent-text: #1553b6;  --accent-strong: #1d5fcc;  --accent-hover: #164fb0;  --on-accent: #ffffff;
    --selected: #cfe0fb;  --selected-text: #0f1a2c;  --accent-soft: rgba(31, 111, 224, .12);
    --ok: #146c34;  --ok-bg: #e3f5ea;  --ok-border: #6bbf8a;
    --warn: #7a5200;  --warn-bg: #fff4d6;  --warn-border: #d9a520;
    --error: #b3261e;  --error-bg: #fde8e6;  --error-border: #e08a82;  --error-on-bg: #8c1d17;
    --focus: #0b57d0;
    --viewer-top: #e6ebf3;  --viewer-bottom: #f3f5f9;
    --chart-line: #1f6fe0;  --chart-grid: #d5dbe6;  --chart-bad: #d93025;  --chart-label: #46546a;  --chart-fill: rgba(31, 111, 224, .14);
    --shadow-menu: 0 8px 24px rgba(20, 30, 50, .22);
    --shadow-card: 0 1px 2px rgba(20, 30, 50, .12);
}
/* Sans JavaScript (theme.js absent) : suit la préférence du système. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    color-scheme: light;
    --bg: #eef1f6;  --surface: #ffffff;  --surface-2: #f3f5f9;  --surface-3: #e3e9f3;  --field: #ffffff;
    --border: #d5dbe6;  --border-control: #66758b;  --border-strong: #a9b4c6;
    --text: #131a26;  --text-muted: #46546a;  --text-disabled: #8793a6;
    --accent: #1f6fe0;  --accent-text: #1553b6;  --accent-strong: #1d5fcc;  --accent-hover: #164fb0;  --on-accent: #ffffff;
    --selected: #cfe0fb;  --selected-text: #0f1a2c;  --accent-soft: rgba(31, 111, 224, .12);
    --ok: #146c34;  --ok-bg: #e3f5ea;  --ok-border: #6bbf8a;
    --warn: #7a5200;  --warn-bg: #fff4d6;  --warn-border: #d9a520;
    --error: #b3261e;  --error-bg: #fde8e6;  --error-border: #e08a82;  --error-on-bg: #8c1d17;
    --focus: #0b57d0;
    --viewer-top: #e6ebf3;  --viewer-bottom: #f3f5f9;
    --chart-line: #1f6fe0;  --chart-grid: #d5dbe6;  --chart-bad: #d93025;  --chart-label: #46546a;  --chart-fill: rgba(31, 111, 224, .14);
    --shadow-menu: 0 8px 24px rgba(20, 30, 50, .22);
    --shadow-card: 0 1px 2px rgba(20, 30, 50, .12);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
/* La page défile : hauteur au moins égale à la fenêtre, jamais fixe (tous les panneaux restent atteignables). */
body { min-height: 100vh; display: flex; flex-direction: column; background: var(--bg); color: var(--text);
       font: 14px/1.45 var(--font); }
h1, h2, h3 { line-height: 1.25; }
.skipLink { position: absolute; left: -9999px; top: 0; z-index: 50; padding: 8px 14px; background: var(--accent-strong); color: var(--on-accent);
            border-radius: 0 0 var(--radius) 0; }
.skipLink:focus { left: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
::selection { background: var(--selected); color: var(--selected-text); }
a { color: var(--accent-text); }
a:hover { color: var(--text); }
/* Barres de défilement sombres (Firefox, puis WebKit/Blink). */
* { scrollbar-color: var(--border-control) var(--surface); scrollbar-width: thin; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 5px; border: 2px solid var(--surface); }
::-webkit-scrollbar-thumb:hover { background: var(--border-control); }

/* Focus clavier visible partout (jamais supprimé sans remplacement). */
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
input[type=text]:focus-visible, input[type=number]:focus-visible, input[type=email]:focus-visible,
input[type=password]:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 0; border-color: var(--focus); }

/* Boutons */
button, a.button { padding: 4px 14px; min-height: var(--control-h); background: var(--surface-2); border: 1px solid var(--border-control);
                   border-radius: var(--radius); cursor: pointer; text-decoration: none; color: var(--text); display: inline-flex;
                   align-items: center; justify-content: center; gap: 6px; line-height: 1.2; }
button:hover:not(:disabled), a.button:hover:not(.disabled) { background: var(--surface-3); border-color: var(--accent); color: var(--text); }
button:active:not(:disabled), a.button:active:not(.disabled) { background: var(--surface); }
button:disabled, a.button.disabled { color: var(--text-disabled); background: var(--surface); border-color: var(--border);
                                     cursor: default; pointer-events: none; }
button.primary { background: var(--accent-strong); color: var(--on-accent); border-color: var(--accent-strong); padding: 4px 20px; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }
button.primary:active:not(:disabled) { background: var(--selected); border-color: var(--selected); }
button.primary:disabled { background: var(--surface-2); border-color: var(--border); color: var(--text-disabled); }
button.link { background: none; border: 0; padding: 2px 0; min-height: var(--control-h); color: var(--accent-text); }
button.link:hover:not(:disabled) { background: none; color: var(--text); text-decoration: underline; }
button.danger { color: var(--error); border-color: var(--error-border); }
button.danger:hover:not(:disabled) { background: var(--error-bg); border-color: var(--error); color: var(--error-on-bg); }

/* Champs, listes déroulantes, cases, curseurs */
input[type=number], input[type=text], input[type=email], input[type=password], select, textarea {
  background: var(--field); color: var(--text); border: 1px solid var(--border-control); border-radius: var(--radius); padding: 4px 8px; min-height: var(--control-h); }
input::placeholder, textarea::placeholder { color: var(--text-muted); opacity: 1; }
input[type=number] { width: 7em; }
input:hover:not(:disabled):not(:focus), select:hover:not(:disabled):not(:focus), textarea:hover:not(:disabled):not(:focus) { border-color: var(--accent); }
input:disabled, select:disabled, textarea:disabled { color: var(--text-disabled); background: var(--surface); border-color: var(--border); }
input[readonly] { color: var(--text-muted); }
select { max-width: 100%; text-overflow: ellipsis; }
select option { background: var(--surface-2); color: var(--text); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent-strong); width: 18px; height: 18px; min-height: 0; margin: 0 2px 0 0; vertical-align: middle; flex: none; cursor: pointer; }
label:has(> input:disabled) { color: var(--text-disabled); }
/* Curseur générique (réutilisable : <input type="range">). Piste 4 px, poignée bleue. */
input[type=range] { -webkit-appearance: none; appearance: none; background: transparent; height: 18px; padding: 0; margin: 0; border: 0;
                    accent-color: var(--accent); cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; background: var(--border-control); border-radius: 2px; }
input[type=range]::-moz-range-track { height: 4px; background: var(--border-control); border-radius: 2px; }
input[type=range]::-moz-range-progress { height: 4px; background: var(--accent); border-radius: 2px; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 14px; height: 14px; margin-top: -5px;
                    border-radius: 50%; background: var(--accent); border: 2px solid var(--bg); }
input[type=range]::-moz-range-thumb { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg); }
input[type=range]:hover::-webkit-slider-thumb { background: var(--accent-text); }
input[type=range]:hover::-moz-range-thumb { background: var(--accent-text); }
input[type=range]:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
input[type=range]:disabled { cursor: default; opacity: .45; }

/* Textes utilitaires */
.hint { color: var(--text-muted); }
.errorText { color: var(--error); white-space: pre-line; }
/* Zones d'erreur de formulaire : même présentation que les bannières rouges. */
div.errorText:not([hidden]):not(#ppMessage) { padding: 10px 12px; border: 1px solid var(--error-border); border-left-width: 4px; border-radius: var(--radius);
  background: var(--error-bg); color: var(--error-on-bg); }
.sectionTitle { font-size: 16px; font-weight: 650; letter-spacing: .01em; color: var(--text); margin: 0; }
.spacer { flex: 1; }

/* ==== Cadre de l'application (maquette de l'app, 10 novembre 2026) ======================================
   En-tête fin (≈ 38 px) · rail étroit à gauche (Job, History, Profiles, Help, Account) · panneau latéral ·
   scène 3D qui prend tout le reste · panneau « résultat / pièce » repliable à droite · barre d'état discrète. */
body.appPage { height: 100vh; min-height: 0; overflow: hidden; }
#menubar { flex: none; display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 10px; background: var(--surface); border-bottom: 1px solid var(--border); }
#menubar .brand { display: inline-flex; align-items: center; gap: 8px; margin-right: 6px; font-weight: 700; font-size: 14px; letter-spacing: .02em; }
#menubar-title { color: var(--text-muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#menubar a.navlink { color: var(--accent-text); padding: 4px 10px; text-decoration: none; border-radius: var(--radius); }
#menubar a.navlink:hover { background: var(--surface-3); color: var(--text); }
button.iconBtn { width: 28px; height: 28px; min-height: 0; padding: 0; border: 1px solid transparent; background: transparent; color: var(--text-muted); border-radius: 5px; }
button.iconBtn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--border); color: var(--text); }
button.iconBtn svg, .railItem svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
button.avatar { width: 26px; height: 26px; min-height: 0; padding: 0; border-radius: 50%; background: var(--accent-strong); border-color: var(--accent-strong); color: var(--on-accent); font-size: 11px; font-weight: 700; }
button.avatar:hover:not(:disabled), button.avatar.active { background: var(--accent-hover); border-color: var(--focus); color: var(--on-accent); }
.netState { display: inline-flex; align-items: center; color: var(--text-muted); cursor: default; padding: 0 4px; }
.netState .dot { margin: 0; }

#workspace { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: 56px minmax(300px, 400px) minmax(0, 1fr); background: var(--bg); }
body.sideClosed #workspace { grid-template-columns: 56px 0 minmax(0, 1fr); }
#rail { display: flex; flex-direction: column; align-items: stretch; background: var(--surface); border-right: 1px solid var(--border); padding: 6px 0; }
button.railItem { flex-direction: column; gap: 2px; width: 100%; min-height: 50px; padding: 6px 0; border: 0; border-radius: 0; background: none; color: var(--text-muted);
                  font-size: 11px; box-shadow: inset 3px 0 0 transparent; }
button.railItem:hover:not(:disabled) { background: var(--surface-3); color: var(--text); border: 0; }
button.railItem.active { color: var(--text); box-shadow: inset 3px 0 0 var(--accent); background: var(--surface-2); }
#side { min-width: 0; overflow-x: hidden; overflow-y: auto; background: var(--surface); border-right: 1px solid var(--border); padding: 10px; display: flex; flex-direction: column; gap: 10px; }
body.sideClosed #side { display: none; }
.view { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
#side .panel { box-shadow: none; background: var(--surface-2); padding: 10px; }
#side fieldset.group, #side details.subgroup, #side details.collapsible { background: var(--surface-2); }
#side .form { grid-template-columns: minmax(0, 1fr); gap: 3px; }
#side .form > label:not(.inline) { text-align: left; margin-top: 6px; }
#side .form > span:empty { display: none; }
#side select, #side input[type=text] { max-width: 100%; }
#side .table-wrap { max-height: 38vh; }
#side #partsTable { font-size: 12px; }
#side td.title { max-width: 120px; }
.helpList { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.helpList button { justify-content: flex-start; }
.accountBox { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.seg { display: inline-flex; border: 1px solid var(--border-control); border-radius: var(--radius); overflow: hidden; }
.seg button { border: 0; border-radius: 0; border-right: 1px solid var(--border-control); background: var(--surface); min-height: 30px; }
.seg button:last-child { border-right: 0; }
.seg button[aria-checked=true] { background: var(--accent-strong); color: var(--on-accent); font-weight: 600; }
.seg button[aria-checked=true]:hover:not(:disabled) { background: var(--accent-hover); color: var(--on-accent); }

/* Scène : la vue 3D occupe tout l'espace ; panneaux et courbe en surimpression, repliables. */
#stage { position: relative; min-width: 0; min-height: 0; display: flex; background: var(--viewer-bottom); }
#viewer { position: relative; flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; background: var(--viewer-bottom); border: 0; border-radius: 0; overflow: hidden; }
#stage .densityBox { position: absolute; left: 12px; bottom: 12px; z-index: 3; width: min(480px, calc(100% - 24px)); margin: 0; background: color-mix(in srgb, var(--surface) 92%, transparent); box-shadow: var(--shadow-menu); }
#stage .densityBox[open] { max-height: 60%; overflow: auto; }
#stage .densitySvg { max-width: none; }
button.stageBtn { min-height: 26px; padding: 1px 10px; font-size: 12px; margin-left: auto; }
button.stageBtn[aria-pressed=true] { border-color: var(--accent); }
body:not(.infoClosed) button.hudStatus { display: none; }
button.hudStatus { position: absolute; right: 12px; top: 48px; z-index: 3; max-width: 55%; min-height: 26px; padding: 2px 14px; border-radius: 13px;
                   font-size: 12px; font-weight: 600; background: var(--surface-2); box-shadow: var(--shadow-card); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
button.hudStatus.ok { background: var(--ok-bg); border-color: var(--ok-border); color: var(--ok); }
button.hudStatus.warn { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn); }
button.hudStatus.error { background: var(--error-bg); border-color: var(--error-border); color: var(--error-on-bg); }

#infoPanel { flex: 0 0 340px; width: 340px; display: flex; flex-direction: column; min-height: 0;
             background: var(--surface); border-left: 1px solid var(--border-strong); overflow: hidden; }
body.infoClosed #infoPanel { display: none; }
.infoTabs { display: flex; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.infoTabs button { flex: 1; border: 0; border-radius: 0; background: none; min-height: 32px; color: var(--text-muted); border-bottom: 2px solid transparent; }
.infoTabs button[aria-selected=true] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.infoBody { flex: 1; min-height: 0; overflow: auto; padding: 10px; display: flex; flex-direction: column; gap: 10px; }
#infoPanel #figures { min-width: 0; }
#infoPanel .figures-row { flex-direction: column; }
#infoPanel #buildWrap { min-width: 0; max-height: 200px; align-self: stretch; }
.inspectorEmpty { margin: 0; }
.exceptionsPanel { border-top: 0; }

#statusBar { flex: none; display: flex; align-items: center; gap: 12px; height: 24px; padding: 0 10px; background: var(--surface); border-top: 1px solid var(--border);
             color: var(--text-muted); font-size: 12px; white-space: nowrap; overflow: hidden; }
#statusMessage { overflow: hidden; text-overflow: ellipsis; }
body.adminPage #menubar { height: auto; min-height: 38px; flex-wrap: wrap; }

/* Machine et matériau (haut du panneau Job) */
#topBar { display: flex; align-items: center; gap: 6px 12px; padding: 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-lg); flex-wrap: wrap; }
#topBar label { display: inline-flex; align-items: center; gap: 6px; min-width: 0; max-width: 100%; }
#topBar .spacer { display: none; }
.groupTitle { flex: 1 0 100%; font-weight: 650; color: var(--text); }
#profileSummary { flex: 1 0 100%; }
#topBar label:has(select) { flex: 1 1 100%; } #topBar select { flex: 1; min-width: 0; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 12px 14px; box-shadow: var(--shadow-card);
         display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }
#partsPanel .table-wrap { min-height: 120px; }
.panel-head { display: flex; align-items: center; gap: 4px 10px; flex-wrap: wrap; }
.panel-head .sectionTitle + .hint { margin-left: 2px; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Groupes d'options (fieldset) et sections repliables (details) */
fieldset.group { margin: 0; padding: 10px 12px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); min-width: 0; }
fieldset.group > legend { padding: 0 6px; font-weight: 650; color: var(--text); }
details.subgroup, details.collapsible { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
details.subgroup > summary, details.collapsible > summary { cursor: pointer; padding: 6px 12px; min-height: var(--control-h, 32px); display: flex; align-items: center; gap: 10px;
  font-weight: 650; list-style: none; border-radius: var(--radius); }
details > summary::-webkit-details-marker { display: none; }
details.subgroup > summary::before, details.collapsible > summary::before { content: "\25B8"; color: var(--accent-text); width: 1em; flex: none; }
details[open].subgroup > summary::before, details[open].collapsible > summary::before { content: "\25BE"; }
details.subgroup > summary:hover, details.collapsible > summary:hover { background: var(--surface-3); }
details.subgroup[open] > summary, details.collapsible[open] > summary { border-bottom: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; }
details.subgroup > .form, details.subgroup > .partDefaults, details.collapsible > .buttons, details.collapsible > .profileShare, details.collapsible > .hint { margin: 10px 12px; }
details.collapsible > summary .sectionTitle { font-size: 16px; }
details.collapsible > summary .hint { font-weight: 400; }

/* Tableaux */
.table-wrap { flex: 1 1 auto; overflow: auto; background: var(--field); border: 1px solid var(--border); border-radius: var(--radius); min-height: 70px; }
.table-wrap.dragover { outline: 2px dashed var(--accent); outline-offset: -4px; background: var(--accent-soft); }
table { border-collapse: collapse; width: 100%; }
th { background: var(--surface-2); color: var(--text); text-align: left; font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--border-strong);
     position: sticky; top: 0; z-index: 1; white-space: nowrap; }
td { padding: 4px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody tr:nth-child(even) { background: var(--surface); }
tbody tr:hover { background: var(--surface-3); }
tbody tr.selected, tbody tr.selected:hover { background: var(--selected) !important; color: var(--selected-text); }
tbody tr.selected td { color: var(--selected-text); }
td.num { text-align: right; }
td.rank, th.rank { color: var(--text-muted); text-align: right; width: 2em; }
tr.selected td.rank { color: var(--selected-text); }
td.check { white-space: normal; min-width: 90px; }
td.check.bad { color: var(--error); }
tr.selected td.check.bad { color: var(--error-on-bg); }
td input[type=number] { width: 5.5em; }
td input[type=text] { width: 8em; }
td.title { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
tr.muted td { color: var(--text-muted); }

.form { display: grid; grid-template-columns: minmax(max-content, 15em) 1fr; gap: 8px 14px; align-items: center; }
.form > label:not(.inline) { text-align: right; color: var(--text-muted); }
.form > label.inline, .inline { min-height: var(--control-h); }
.form select, .form input[type=text] { width: 100%; }
.inline { display: inline-flex; align-items: center; gap: 6px; }
.buttons { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#runPanel > .buttons { padding-top: 4px; }
#runButton { min-width: 7em; }
#stageTable { width: 100%; background: var(--field); border: 1px solid var(--border); }
#stageTable tr.pending td { color: var(--text-disabled); }
#log { margin: 4px 0 0; max-height: 240px; min-height: 80px; overflow: auto; background: var(--field); border: 1px solid var(--border); border-radius: var(--radius);
       padding: 4px 6px; font: 12px var(--mono); color: var(--text); white-space: pre-wrap; word-break: break-word; }

/* Bannières d'état */
.banner { padding: 10px 12px; border: 1px solid var(--border-strong); border-left-width: 4px; border-radius: var(--radius); background: var(--surface-2); color: var(--text);
          font-weight: 600; user-select: text; }
.banner.neutral { background: var(--surface-2); border-color: var(--border-strong); color: var(--text); }
.banner.ok { background: var(--ok-bg); border-color: var(--ok-border); color: var(--ok); }
.banner.warn { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn); }
.banner.error { background: var(--error-bg); border-color: var(--error-border); color: var(--error-on-bg); }
.bannerDetail { color: var(--text-muted); white-space: pre-line; user-select: text; }
.figures-row { display: flex; gap: 12px; flex-wrap: wrap; }
#figures { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; flex: 1; min-width: 220px; padding: 8px 12px;
           background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); align-self: flex-start; }
#figures dt { color: var(--text-muted); } #figures dd { margin: 0; user-select: text; font-weight: 600; font-variant-numeric: tabular-nums; }
#buildWrap { flex: 1; min-width: 220px; max-height: 150px; overflow: auto; align-self: flex-start; background: var(--field); border: 1px solid var(--border); border-radius: var(--radius); }
#buildTable tbody tr { cursor: pointer; }
.footerNote { color: var(--text-muted); border-top: 1px solid var(--border); padding-top: 8px; font-size: 13px; }
ul.files { margin: 0; padding-left: 18px; }
ul.files a { color: var(--accent-text); }

#historyTable tbody tr { cursor: pointer; }
#historyTable td.num { text-align: right; }
#historyTable td.pin, #historyTable th.pin { width: 1.6em; padding: 0 2px; text-align: center; }
#historyTable tr.pinned td { background: var(--surface-2); }
.pinToggle { border: none; background: none; padding: 0 2px; cursor: pointer; color: var(--text-muted); font-size: 14px; line-height: 1; }
.pinToggle.on { color: var(--accent); }
/* Historique : la liste prend toute la hauteur du panneau latéral (seul le tableau défile, en-tête figé) ; Name prend la place restante. */
#view-history:not([hidden]) { flex: 1 1 auto; min-height: 0; }
#historyPanel { flex: 1 1 auto; min-height: 0; }
#historyPanel .table-wrap { max-height: none; min-height: 0; overflow-x: hidden; overflow-y: auto; }
#historyTable { table-layout: auto; font-size: 12px; }
#historyTable th, #historyTable td { padding: 4px 4px; }
#historyTable td.num, #historyTable th:nth-last-child(-n+2) { text-align: right; }
#historyTable td.name { width: 100%; max-width: 0; overflow: hidden; text-overflow: ellipsis; }
#historyTable td.owner { max-width: 64px; overflow: hidden; text-overflow: ellipsis; }

/* Visionneuse : fond identique au clearColor de viewer.js (--viewer-bottom). */
.vtoolbar { display: flex; align-items: center; gap: 6px; padding: 5px 10px; flex-wrap: wrap; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 94%, transparent); }
.vtoolbar button, .vtoolbar select { min-height: 26px; padding-top: 1px; padding-bottom: 1px; }
.vtoolbar .vtitle { flex: 1 1 60px; min-width: 40px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 60px; }
.vtoolbar input[type=range] { width: 90px; }
.vbody { flex: 1; display: flex; min-height: 0; position: relative; }
.vcanvas { flex: 3; position: relative; min-width: 0; background: linear-gradient(var(--viewer-top), var(--viewer-bottom)); }
.vcanvas canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
.vcanvas canvas:active { cursor: grabbing; }
.vmessage { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px; color: var(--text-muted); }
.vtree { position: absolute; left: 12px; top: 12px; z-index: 2; width: 300px; max-width: calc(100% - 24px); max-height: calc(100% - 200px); overflow: auto; border: 1px solid var(--border-strong);
         border-radius: var(--radius); background: color-mix(in srgb, var(--surface) 94%, transparent); box-shadow: var(--shadow-menu); }
body.treeHidden .vtree { display: none; }
.vtree table th { font-size: 12px; }
.vtree tr.group td { background: var(--surface-2); font-weight: 600; }
.vtree tr.child.selected { background: var(--selected); color: var(--selected-text); }
.vtree tr.child.hidden-row { display: none; }
.swatch { display: inline-block; width: 10px; height: 10px; margin-right: 5px; vertical-align: middle; border: 1px solid rgba(255,255,255,.35); }
.toggle { cursor: pointer; display: inline-block; width: 1.2em; }

/* Éléments génériques pour les autres modules : vignette de pièce et graphique SVG. */
.thumb { display: inline-block; width: 40px; height: 40px; vertical-align: middle; background: var(--viewer-bottom); border: 1px solid var(--border-strong);
         border-radius: var(--radius); object-fit: contain; overflow: hidden; }
.thumb.large { width: 64px; height: 64px; }
tr.selected .thumb { border-color: var(--selected-text); }
svg.chart { display: block; width: 100%; height: auto; background: var(--field); border: 1px solid var(--border); border-radius: var(--radius); }
.chart-line { fill: none; stroke: var(--chart-line); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-area { fill: var(--chart-fill); stroke: none; }
.chart-grid { stroke: var(--chart-grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart-axis { stroke: var(--border-control); stroke-width: 1; shape-rendering: crispEdges; }
.chart-bad { fill: var(--chart-bad); stroke: var(--chart-bad); }
.chart-bad-line { fill: none; stroke: var(--chart-bad); stroke-width: 2; }
.chart-label { fill: var(--chart-label); font: 11px var(--font); }
.chart-marker { fill: var(--accent); stroke: var(--bg); stroke-width: 1.5; }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; background: var(--text-disabled); }
.dot.on { background: var(--ok); } .dot.off { background: var(--error); }

/* Boîtes de dialogue */
dialog { background: var(--surface-2); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--radius-lg);
         padding: 18px 22px; max-width: min(520px, 94vw); box-shadow: var(--shadow-menu); }
dialog::backdrop { background: rgba(3, 5, 9, .72); }
dialog h3 { margin: 0 0 10px; font-size: 17px; }
#unitOptions label { display: block; padding: 2px 0; }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

.defaultUnit { display: inline-flex; align-items: center; gap: 4px; }
/* Comptes : connexion, inscription, activation, administration */
body.authPage { align-items: center; justify-content: center; padding: 16px;
                background: radial-gradient(ellipse at 50% 0%, var(--surface-2) 0%, var(--bg) 62%); }
.card { background: var(--surface); border: 1px solid var(--border-strong); border-top: 4px solid var(--accent-strong); border-radius: var(--radius-lg);
        padding: 26px 30px; width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow-menu); }
.card h1::before { content: ""; display: inline-block; width: 28px; height: 28px; margin-right: 10px; vertical-align: -6px;
                   background: url("/static/icon.svg") center / contain no-repeat; }
.card.wide { max-width: 480px; }
.card h1 { margin: 0; font-size: 22px; }
.authForm { display: flex; flex-direction: column; gap: 6px; }
.authForm a.button { align-self: flex-start; margin-top: 2px; }
.authForm label { color: var(--text-muted); }
.authForm input { width: 100%; padding: 6px 10px; min-height: 38px; }
.authForm button.primary { margin-top: 10px; align-self: flex-start; min-height: 38px; }
#menubar a.navlink { color: var(--accent-text); padding: 6px 12px; text-decoration: none; border-radius: var(--radius); }
#menubar a.navlink:hover { background: var(--surface-3); color: var(--text); }
body.adminPage #adminMain { flex: 1 0 auto; display: flex; flex-direction: column; gap: var(--gap); padding: var(--gap); background: var(--bg); }
body.adminPage .table-wrap { max-height: 360px; }
body.adminPage #adminMain { width: 100%; max-width: 1500px; margin: 0 auto; }
body.adminPage td { white-space: normal; }
body.adminPage td input[type=number] { width: 5em; }
#linkDialog { max-width: 640px; width: 90vw; }
#linkValue { width: 100%; font: 12px var(--mono); padding: 5px; }
.retentionNote { color: var(--text-muted); }
#confirmDialog { max-width: 560px; }

[hidden] { display: none !important; }
/* Menu Help : assistant et formulaire de contact. */
dialog.wide { width: min(640px, 92vw); max-width: 640px; }
dialog.wide textarea { width: 100%; box-sizing: border-box; font: inherit; resize: vertical; }
.chatLog { height: min(320px, 40vh); overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; margin: 6px 0;
  background: var(--field); display: flex; flex-direction: column; gap: 6px; }
.chatMsg { padding: 6px 9px; border-radius: var(--radius-lg); white-space: pre-wrap; overflow-wrap: anywhere; max-width: 88%; }
.chatMsg.user { align-self: flex-end; background: var(--selected); color: var(--selected-text); }
.chatMsg.assistant { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border-strong); }
.chatMsg.pending { color: var(--text-muted); font-style: italic; }
.contactForm { grid-template-columns: max-content 1fr; align-items: start; }
.contactForm > label { padding-top: 3px; }
.messageBody { white-space: pre-wrap; overflow-wrap: anywhere; max-width: 60ch; padding: 4px 0; }

/* Mouvement réduit : pas de transition imposée (aucune n'est définie ici ; garde-fou pour les ajouts). */
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* Courbe de densité (packing density en fonction de z), sur les variables du thème. */
.densityBox { margin: 6px 0; border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius); }
.densityBox > summary { cursor: pointer; padding: 4px 8px; font-size: 12px; color: var(--text); }
.densityBox > summary.bad { color: var(--error); font-weight: 600; }
.densityChart { padding: 4px 8px 8px; }
.densitySvg { width: 100%; max-width: 460px; height: auto; display: block; }
.densitySvg .grid { stroke: var(--chart-grid); stroke-width: 1; }
.densitySvg .axis { stroke: var(--text-muted); stroke-width: 1; }
.densitySvg .tick, .densitySvg .label { fill: var(--chart-label, var(--text-muted)); font-size: 9px; }
.densitySvg .ramp { fill: var(--accent); opacity: 0.10; }
.densitySvg .tube { fill: var(--accent); opacity: 0.30; stroke: none; }
.densitySvg .curve { fill: none; stroke: var(--chart-line); stroke-width: 1.4; stroke-linejoin: round; }
.densitySvg .curve.parts { stroke-dasharray: 4 3; stroke-width: 1.1; opacity: 0.8; }
.densitySvg .violation { fill: var(--chart-bad); }

/* Aperçus des pièces et réglage Upright (preview.js), sur les variables du thème. Les couleurs de tracé du canvas
   viennent de --preview-rgb (pièce, « r g b ») et --preview-axis (triade). */
.partThumb, .tiltCanvas { --preview-rgb: 76 154 255; --preview-axis: #8b97a8; display: block; }
.partThumb { background: var(--viewer-bottom); border: 1px solid var(--border-strong); border-radius: var(--radius); }
.thumbCell { width: 52px; padding: 2px 4px; }
th.thumbHead { width: 52px; }
tbody tr.selected .partThumb { border-color: var(--accent); }
.uprightCell { white-space: nowrap; }
button.uprightToggle { padding: 2px 10px; min-width: 3.4em; }
button.uprightToggle.on { background: var(--accent-strong); color: var(--on-accent); border-color: var(--accent); font-weight: 600; }
button.uprightToggle.on:hover:not(:disabled) { background: var(--accent-hover); }
.tiltBadge { margin-left: 6px; font-size: 11px; color: var(--text-muted); }
tr.selected .tiltBadge { color: var(--selected-text); }
.tiltPanel { display: flex; gap: 12px; align-items: flex-start; padding: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.tiltPanel[hidden] { display: none; }
.tiltCanvasBox { display: none; }
.tiltCanvas { background: var(--viewer-bottom); border: 1px solid var(--border-strong); border-radius: var(--radius); }
.tiltSide { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.tiltTitle { font-weight: 600; overflow-wrap: anywhere; }
.tiltSliders { display: grid; grid-template-columns: max-content minmax(80px, 1fr) 3.2em; gap: 6px 10px; align-items: center; }
.tiltSliders[hidden] { display: none; }
.tiltSliders output { text-align: right; font-variant-numeric: tabular-nums; }

#densityWarning { margin-top: 6px; white-space: pre-line; user-select: text; }

/* Options par pièce et par job (9 novembre 2026) */
.sectionSub { font-weight: 600; color: var(--text-muted); }
.partDefaults, .exceptionsPanel { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; padding: 6px 2px; }
.exceptionsPanel { border-top: 1px solid var(--border); }
.exceptionsPanel select { min-width: 7em; }
.exceptionBadge { display: block; width: max-content; margin: 2px 4px 0 0; padding: 0 6px; border-radius: 8px; font-size: 11px;
  background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--warn); white-space: nowrap; }
tr.selected .exceptionBadge { color: var(--warn); }
.repairBadge { display: inline-block; padding: 0 6px; border-radius: 8px; font-size: 11px; background: var(--warn-bg);
  border: 1px solid var(--warn-border); color: var(--warn); }
#repairNote { white-space: pre-line; }
.spacingField { width: 6em; }
.banner.accepted { background: var(--surface-2); border-color: var(--border-strong); color: var(--text); }

/* Profils d'impression (9 novembre 2026) */
#profilesPanel .profileRow select { min-width: 14em; max-width: 24em; }
.profileShare { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.profileShare input[type=text] { font-family: var(--mono); }

/* Angle minimal, densité cible, charge de la tête (9 novembre 2026) */
.angleField { width: 4.5em; }
#targetNote, #faceAngleNote, #headLoadBox { margin-top: 6px; user-select: text; }
#targetNote { white-space: pre-line; }
.headLoad .hlRow { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; }
.hlChart { display: inline-flex; align-items: flex-end; gap: 1px; width: 200px; height: 40px; vertical-align: middle; padding: 1px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }
.hlChart i { flex: 1 1 0; background: var(--accent); min-width: 1px; }
.headLoad .hlTitle { font-weight: 600; color: var(--text-muted); }

/* Portables 1366×768 et plus étroit : panneau latéral plus étroit, panneau de résultat par-dessus la scène. */
@media (max-width: 1100px) {
  #workspace { grid-template-columns: 52px minmax(260px, 340px) minmax(0, 1fr); }
  body.sideClosed #workspace { grid-template-columns: 52px 0 minmax(0, 1fr); }
  #infoPanel { flex-basis: 300px; width: 300px; }
}
@media (max-width: 700px) {
  body.appPage { height: auto; overflow: auto; }
  #workspace { display: flex; flex-direction: column; }
  #rail { flex-direction: row; border-right: 0; border-bottom: 1px solid var(--border); padding: 0; }
  button.railItem { min-height: 44px; box-shadow: none; } button.railItem.active { box-shadow: inset 0 -3px 0 var(--accent); }
  #rail .spacer { display: none; }
  #stage { min-height: 70vh; }
  #menubar-title, .netState { display: none; }
  .form { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .form > label:not(.inline) { text-align: left; margin-top: 6px; }
  .toolbar .spacer { flex: 1 0 100%; }
  .tiltPanel { flex-direction: column; }
  dialog { padding: 14px; }
  .card { padding: 20px 18px; }
}

/* Scène centrale en mode aperçu des pièces (viewer.js, class previewMode) : pas de coupe, de couleur ni d'arbre des builds. */
.previewMode .vresult, #viewer:not(.previewMode) .vpreview, .previewMode .vtree, .previewMode #treeToggle { display: none; }
button.vpreview[hidden] { display: none; }
.vtoolbar button[aria-pressed=true] { border-color: var(--accent); }
.vtoolbar button.iconOnly { width: 28px; padding: 1px 0; font-size: 14px; line-height: 1; }
#stage.partPreview .densityBox { display: none !important; }
.vtoolbar button.vresult:last-child { margin-left: auto; }
/* Historique avec colonne Owner (administrateur, jobs d'autres comptes) : panneau latéral plus large pour garder la colonne Name lisible. */
body:not(.sideClosed) #workspace:has(#view-history:not([hidden]) #ownerHead:not([hidden])) { grid-template-columns: 56px minmax(300px, 470px) minmax(0, 1fr); }

/* Page Download de l'application (masquée tant que le site n'est pas lancé avec --app-downloads). */
.downloadList { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 12px; }
.downloadList li { display: grid; gap: 6px; }
.downloadList .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11px; overflow-wrap: anywhere; }
.densityStats { padding: 4px 8px 0; font-size: 12px; color: var(--muted, #888); }
