/* NucTrace — portail web
   Identité : un plan de tuyauterie. Le fil conducteur visuel est la « ligne de vie »,
   un tracé continu découpé en phases (conception → fin de vie), réutilisé sur le
   tableau de bord, la fiche pièce et les listes. Le reste reste sobre et dense. */

:root {
  --paper: #EEF2F2;
  --surface: #FFFFFF;
  --ink: #17262E;
  --ink-2: #4A5C64;
  --ink-3: #7A8B92;
  --line: #CDD6D8;
  --line-soft: #E2E8E9;
  --primary: #0E5A7A;
  --primary-ink: #FFFFFF;
  --primary-soft: #DCEBF1;
  --danger: #B93A16;
  --danger-soft: #FBE4DC;
  --ok: #2C7A3F;
  --ok-soft: #DDF0E1;

  /* une couleur par phase, du froid (conception) au chaud (fin de vie) */
  --ph-DESIGN: #7C8FA6;
  --ph-PROCUREMENT: #5466B0;
  --ph-MANUFACTURING: #3D5BD9;
  --ph-LOGISTICS: #13889A;
  --ph-CONSTRUCTION: #3E9A4F;
  --ph-OPERATION: #1F6B33;
  --ph-DISMANTLING: #B07C14;
  --ph-END_OF_LIFE: #7B5E52;
  --ph-DEVIATION: #B93A16;

  --radius: 6px;
  --sidebar: 232px;
  --font: "Segoe UI", "Helvetica Neue", Arial, system-ui, sans-serif;
  --mono: "Cascadia Mono", "Consolas", "DejaVu Sans Mono", ui-monospace, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0F171B;
    --surface: #172227;
    --ink: #E4ECEE;
    --ink-2: #A9B9BF;
    --ink-3: #74878E;
    --line: #2C3B42;
    --line-soft: #223036;
    --primary: #5AB3D6;
    --primary-ink: #06222E;
    --primary-soft: #18394A;
    --danger: #F08061;
    --danger-soft: #3D1E15;
    --ok: #6CC783;
    --ok-soft: #173322;
    --ph-DESIGN: #8FA3BA;
    --ph-PROCUREMENT: #7D8EDB;
    --ph-MANUFACTURING: #6F8BFF;
    --ph-LOGISTICS: #3FB7C9;
    --ph-CONSTRUCTION: #64C276;
    --ph-OPERATION: #3E9A58;
    --ph-DISMANTLING: #D9A43C;
    --ph-END_OF_LIFE: #A98A7C;
    --ph-DEVIATION: #F08061;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
h1 { font-size: 22px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 12px; }
h3 { font-size: 14px; font-weight: 600; margin: 0 0 8px; color: var(--ink-2); }
.code { font-family: var(--mono); font-size: 13px; letter-spacing: -0.01em; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }

/* ---- Structure ---------------------------------------------------------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.side {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 18px 12px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; font-weight: 700; font-size: 17px; }
.brand svg { flex: none; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius);
  color: var(--ink-2); font-weight: 500;
}
.nav a:hover { background: var(--line-soft); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.nav .sep { height: 1px; background: var(--line-soft); margin: 10px 4px; }
.who { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--line-soft); }
.who b { display: block; }
.main { padding: 24px 32px 48px; min-width: 0; max-width: 1400px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--ink-2); max-width: 70ch; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---- Ligne de vie ------------------------------------------------------- */
.lifeline { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 3px; margin: 4px 0 6px; }
.lifeline .seg { position: relative; padding-top: 14px; min-width: 0; }
.lifeline .seg::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 6px;
  background: var(--c); opacity: .22; border-radius: 3px;
}
.lifeline .seg.done::before { opacity: 1; }
.lifeline .seg.current::before { opacity: 1; height: 10px; top: -2px; }
.lifeline .seg.current::after {
  content: ""; position: absolute; top: -6px; left: calc(var(--pos, 50%) - 9px);
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--surface); border: 4px solid var(--c);
}
.lifeline .name { font-size: 12px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lifeline .seg.current .name { color: var(--ink); font-weight: 600; }
.lifeline .stat { font-size: 12px; color: var(--ink-3); }

/* Variante tableau de bord : segments cliquables avec effectifs */
.fleet .seg { padding-top: 18px; text-align: left; border: 0; background: none; font: inherit; color: inherit; cursor: pointer; }
.fleet .seg::before { opacity: 1; height: 8px; }
.fleet .seg:hover .name { color: var(--primary); }
.fleet .count { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; line-height: 1.1; }
.fleet .seg.empty .count { color: var(--ink-3); }

/* ---- Statuts ------------------------------------------------------------ */
.status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; white-space: nowrap; color: var(--ink);
}
.status::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.status.big { font-size: 14px; padding: 4px 10px; border-radius: 99px; background: color-mix(in srgb, var(--c) 14%, transparent); }

/* ---- Tableaux ----------------------------------------------------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--ink-2); background: var(--surface); position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--line-soft); }
tbody tr.sel { background: var(--primary-soft); }
td.check, th.check { width: 36px; padding-right: 0; }
.empty-state { padding: 32px; text-align: center; color: var(--ink-2); }

/* ---- Formulaires -------------------------------------------------------- */
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); font-weight: 500; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 7px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px var(--primary-soft); }
textarea { font-family: var(--mono); font-size: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; align-items: end; }
button, .btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 7px 14px; border-radius: var(--radius); white-space: nowrap;
}
button:hover { border-color: var(--ink-3); }
button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; color: var(--primary); padding: 4px; font-weight: 500; }
button:disabled { opacity: .45; cursor: not-allowed; filter: none; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button {
  border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none;
  color: var(--ink-2); padding: 8px 14px; font-weight: 500;
}
.tabs button.on { color: var(--primary); border-bottom-color: var(--primary); }
.tabs .n { font-size: 12px; color: var(--ink-3); margin-left: 6px; font-variant-numeric: tabular-nums; }

/* Barre d'action groupée */
.actionbar {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  background: var(--ink); color: var(--paper);
  padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px;
}
.actionbar button { background: transparent; color: var(--paper); border-color: color-mix(in srgb, var(--paper) 35%, transparent); }
.actionbar button.primary { background: var(--paper); color: var(--ink); border-color: var(--paper); }

/* ---- Fiche pièce -------------------------------------------------------- */
.sheet-head { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; margin-bottom: 18px; }
.sheet-head .code { font-size: 24px; font-weight: 600; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.kv dt { color: var(--ink-3); font-size: 13px; }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 14px 1fr; gap: 12px; position: relative; padding-bottom: 14px; }
.timeline li::before { content: ""; position: absolute; left: 6px; top: 14px; bottom: 0; width: 2px; background: var(--line); }
.timeline li:last-child::before { display: none; }
.timeline .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--surface); border: 3px solid var(--c); margin-top: 3px; }
.timeline .t { font-weight: 600; }
.timeline .meta { color: var(--ink-3); font-size: 12px; }
.timeline .payload { font-size: 13px; color: var(--ink-2); }

/* ---- Divers ------------------------------------------------------------- */
.notice { padding: 10px 14px; border-radius: var(--radius); font-size: 13px; }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice.err { background: var(--danger-soft); color: var(--danger); }
.results { margin: 10px 0 0; padding-left: 18px; font-size: 13px; max-height: 180px; overflow: auto; }
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: var(--radius);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: 90vw; z-index: 50;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--danger); color: #fff; }
.chip { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--line-soft); color: var(--ink-2); }
.chip.off { background: var(--danger-soft); color: var(--danger); }

/* Connexion */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; }
.login .lifeline { margin-bottom: 18px; }
.login h1 { font-size: 26px; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); padding: 22px; width: min(560px, 94vw); }
dialog.wide { width: min(920px, 94vw); max-height: 90vh; overflow: auto; }
dialog::backdrop { background: rgba(10, 20, 25, .45); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: 10px 16px; }
  .brand { padding: 0 8px 0 0; }
  .nav { display: flex; flex-wrap: wrap; gap: 2px; }
  .who { margin: 0 0 0 auto; border: 0; padding: 0; }
  .main { padding: 16px; }
  .lifeline .name { font-size: 10px; }
  .fleet { grid-auto-flow: row; grid-template-columns: repeat(2, 1fr); row-gap: 14px; }
  .fleet .count { font-size: 20px; }
  .fleet .name { font-size: 12px; }
  .nav .sep { display: none; }
}
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }

th.custom-col { color: var(--primary); }
.checks { display: flex; flex-direction: column; gap: 6px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--ink-2); }
.table-wrap td { white-space: nowrap; }
[hidden] { display: none !important; }

/* Bandeau qualité du tableau de bord */
.qstrip { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.qcard { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius);
         background: var(--surface); color: var(--ink-2); }
.qcard:hover { text-decoration: none; border-color: var(--primary); }
.qcard .count { font-size: 24px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.qcard.hot { border-left: 4px solid var(--ph-DISMANTLING); }

/* Incohérences : événement enregistré hors du cycle attendu (signalé, jamais bloqué) */
.timeline li.anomaly > div { border-left: 3px solid var(--danger); padding-left: 10px; }
.anomaly-text { color: var(--danger); font-size: 13px; margin-top: 2px; }
.warn { color: var(--danger); font-size: 12px; }
optgroup { font-style: normal; color: var(--ink-2); }

/* lignes de saisie d'un achat direct / d'une réception hors commande */
.od-table { table-layout: fixed; width: 100%; }
.od-table td, .od-table th { padding: 4px 4px; }
.od-table input, .od-table select { width: 100%; min-width: 0; box-sizing: border-box; }

/* Nature de la pièce : conçue (fabriquée sur plan) / achetée (catalogue) — forme et couleur distinctes */
.nature { display: inline-block; padding: 1px 8px; border-radius: 4px; font-size: 12px; font-weight: 600; white-space: nowrap;
          border: 1px solid currentColor; }
:root { --nat-made: #2F5DA8; --nat-bought: #9A5B13; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --nat-made: #8DB0F0; --nat-bought: #E2A65A; } }
:root[data-theme="dark"] { --nat-made: #8DB0F0; --nat-bought: #E2A65A; }
.nature-made { color: var(--nat-made); }
.nature-bought { color: var(--nat-bought); background: color-mix(in srgb, var(--nat-bought) 12%, transparent); border-style: dashed; }
.nature-table td, .nature-table th { white-space: nowrap; }
