/* HDG Voiron — gestion de stock CBD. Design sobre, premium, outil d'exploitation.
   Palette : vert profond, neutres chauds/ivoire, encre ; accent laiton pour l'action.
   Mobile-first. Sans dépendance, sans police externe. */

:root {
  /* Vert de marque */
  --green-900: #0f2a1d;
  --green-800: #143425;
  --green-700: #1d5038;
  --green-600: #2a6a4b;
  --green-100: #e6efe8;

  /* Neutres chauds / ivoire / encre */
  --bg:        #f4f1ea;
  --bg-2:      #efebe1;
  --surface:   #ffffff;
  --surface-2: #faf8f2;
  --ink:       #19211d;
  --ink-soft:  #5d665f;
  --ink-faint: #8b9189;
  --line:      #e3ded2;
  --line-2:    #d8d2c4;

  /* Accent action (cuivre — distinct de l'ambre d'alerte --warn) */
  --accent:    #9c5a34;
  --accent-600:#824827;
  --accent-bg: #f1e7dd;
  --accent-line: #e3cdb8;

  /* Sémantiques */
  --ok:        #2f7d52;  --ok-bg:   #e7f1ea;
  --warn:      #b67d12;  --warn-bg: #f7eed7;
  --crit:      #b23b30;  --crit-bg: #f6e1de;

  --radius:   12px;
  --radius-s: 8px;
  --shadow:   0 1px 2px rgba(25,33,29,.05), 0 6px 20px rgba(25,33,29,.06);
  --shadow-s: 0 1px 2px rgba(25,33,29,.06);
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono", Menlo, Consolas, monospace;
  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --nav-w: 240px;
  --bottom-h: 62px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--ui);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-size: 15px;
  line-height: 1.45;
}
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
.ico { width: 22px; height: 22px; display: inline-block; fill: currentColor; vertical-align: middle; }

/* ---------- Layout ---------- */
.app { min-height: 100vh; }
/* B1 : la nav basse est fixée ; on réserve sous le contenu une marge >= hauteur
   de la nav (+ safe-area + tampon) pour que rien ne soit jamais masqué. */
.shell { padding-bottom: calc(var(--bottom-h) + env(safe-area-inset-bottom) + 18px); }

/* Navigation : barre basse en mobile */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--bottom-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; align-items: stretch;
  background: var(--green-900);
  border-top: 1px solid rgba(255,255,255,.06);
}
.brand { display: none; }
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: rgba(255,255,255,.62); font-size: 10.5px; font-weight: 500;
  position: relative; min-width: 0; padding: 4px 2px; letter-spacing: .1px;
}
.nav-item .ico { width: 22px; height: 22px; }
.nav-item span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.nav-item.active { color: #fff; }
.nav-item.active::before {
  content: ""; position: absolute; top: 0; left: 22%; right: 22%; height: 2.5px;
  background: var(--accent); border-radius: 0 0 3px 3px;
}
.nav-badge {
  position: absolute; top: 3px; right: 22%;
  background: var(--crit); color: #fff; font-size: 10px; font-weight: 700;
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center; line-height: 1;
}

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.back-btn {
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink);
  width: 38px; height: 38px; border-radius: 10px; display: inline-flex;
  align-items: center; justify-content: center; padding: 0;
}
/* `display` explicite ci-dessus : il écrase la règle [hidden]{display:none} de la
 * feuille du navigateur. Sans ce rappel, le routeur a beau poser `hidden`, la
 * flèche reste visible sur les douze écrans de premier niveau. */
.back-btn[hidden] { display: none; }
.topbar-title { font-size: 18px; font-weight: 700; margin: 0; letter-spacing: -.2px; flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sync-state {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 12px 5px 10px; box-shadow: var(--shadow-s);
}
.sync-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok);
  box-shadow: 0 0 0 3px var(--ok-bg); flex: none; }
.sync-dot.err { background: var(--crit); box-shadow: 0 0 0 3px var(--crit-bg); }
.sync-text { display: flex; flex-direction: column; line-height: 1.1; }
.sync-text em { font-style: normal; font-size: 10px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .4px; }
.sync-text b { font-size: 12.5px; font-weight: 600; }
.sync-ico { width: 16px; height: 16px; color: var(--ink-faint); }
.sync-state.spin .sync-ico { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* View */
.view { padding: 18px 16px calc(28px + env(safe-area-inset-bottom)); max-width: 1180px; margin: 0 auto; outline: none; }
.loading { color: var(--ink-faint); padding: 40px 0; text-align: center; }

/* ---------- Primitives ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-s);
}
.section { margin-bottom: 22px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 2px 12px; }
.section-head h2 { font-size: 17px; font-weight: 700; margin: 0; letter-spacing: -.2px; }
.section-head .hint { font-size: 12.5px; color: var(--ink-faint); }
.muted { color: var(--ink-soft); }
.faint { color: var(--ink-faint); }
.right { text-align: right; }

.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink);
  padding: 9px 14px; border-radius: 10px; font-weight: 600; font-size: 14px;
  transition: background .12s, border-color .12s, transform .04s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn .ico { width: 18px; height: 18px; }
.btn-primary { background: var(--green-700); border-color: var(--green-700); color: #fff; }
.btn-primary:hover { background: var(--green-800); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-600); }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--bg-2); color: var(--ink); }
.btn[disabled] { opacity: .5; pointer-events: none; }

/* Badges & pastilles statut */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600;
  padding: 2px 9px; border-radius: 999px; line-height: 1.6; white-space: nowrap; }
.badge .pip { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.st-ok       { color: var(--ok);   background: var(--ok-bg); }
.st-bas      { color: var(--warn); background: var(--warn-bg); }
.st-critique { color: var(--crit); background: var(--crit-bg); }
.pip-ok { background: var(--ok); } .pip-bas { background: var(--warn); } .pip-critique { background: var(--crit); }
.conf-conforme     { color: var(--ok);   background: var(--ok-bg); }
.conf-non-conforme { color: var(--crit); background: var(--crit-bg); }
.conf-na           { color: var(--ink-faint); background: var(--bg-2); }
.badge-neutral     { color: var(--ink-soft); background: var(--bg-2); }
.badge-neutral .ico { width: 13px; height: 13px; color: var(--ok); }

/* ---------- Profil cannabinoïde (molécules) ---------- */
.chip-mol { display: inline-block; font-size: 11.5px; line-height: 1.5; color: var(--ink-soft);
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px; padding: 2px 9px; white-space: nowrap; }
.mol-profile { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px;
  padding: 12px 14px; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); }
.mol-profile .mol-k { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-faint); }
.mol-profile .mol-v { font-size: 14px; font-weight: 600; color: var(--ink); }

/* ---------- KPIs ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.kpi {
  text-align: left; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 14px 10px; box-shadow: var(--shadow-s);
  display: flex; flex-direction: column; gap: 2px; position: relative; overflow: hidden;
  transition: border-color .12s, box-shadow .12s, transform .05s; color: var(--ink); width: 100%;
}
.kpi:hover { border-color: var(--line-2); box-shadow: var(--shadow); }
.kpi:active { transform: translateY(1px); }
.kpi-label { font-size: 12px; color: var(--ink-soft); font-weight: 600; letter-spacing: .1px; }
.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -.6px; line-height: 1.1; }
.kpi-value .unit { font-size: 14px; font-weight: 600; color: var(--ink-faint); margin-left: 3px; }
.kpi .spark { width: 100%; height: 30px; margin-top: 6px; color: var(--green-600); display: block; }
.kpi[data-tone="crit"] .spark { color: var(--crit); }
.kpi[data-tone="warn"] .spark { color: var(--warn); }
.kpi-arrow { position: absolute; top: 12px; right: 12px; color: var(--ink-faint); opacity: .55; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 560px; background: var(--surface); }
table.data th, table.data td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data th { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--ink-faint);
  font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
table.data tbody tr { transition: background .1s; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr.clickable { cursor: pointer; }
table.data td.r, table.data th.r { text-align: right; }
table.data .strong { font-weight: 700; }
.row-flag { box-shadow: inset 3px 0 0 var(--accent); }

/* Filtres */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: center; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > label { font-size: 11px; color: var(--ink-faint); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
input[type="text"], input[type="number"], input[type="search"], input[type="time"], input[type="email"], select {
  font-family: inherit; font-size: 14px; color: var(--ink);
  border: 1px solid var(--line-2); background: var(--surface); border-radius: 9px;
  padding: 9px 11px; outline: none; transition: border-color .12s, box-shadow .12s; min-width: 0;
}
select {
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  padding-right: 32px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235d665f' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 15px;
}
select::-ms-expand { display: none; }
input:focus, select:focus { border-color: var(--green-600); box-shadow: 0 0 0 3px var(--green-100); }
/* B10 : recherche bien visible, pleine largeur sur mobile (ligne dédiée). */
.search { flex: 1 1 100%; min-width: 160px; position: relative; }
.search input { width: 100%; }
.chips { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-soft);
  padding: 7px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
  transition: background .12s, border-color .12s, color .12s;
}
.chip:hover { background: var(--surface-2); border-color: var(--ink-faint); color: var(--ink); }
.chip.on { background: var(--green-700); border-color: var(--green-700); color: #fff; }
.chip.on:hover { background: var(--green-800); border-color: var(--green-800); color: #fff; }

/* ---------- Grids contextuels ---------- */
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 16px; }
.grid-cards { display: grid; grid-template-columns: 1fr; gap: 14px; }

/* Carte graphe */
.chart-card { padding: 16px; }
.chart-card h3 { margin: 0 0 4px; font-size: 14px; font-weight: 700; }
.chart-card .sub { font-size: 12.5px; color: var(--ink-faint); margin-bottom: 10px; }
.linechart { width: 100%; height: auto; display: block; }
.ch-grid { stroke: var(--line); stroke-width: 1; }
.ch-axis { font-size: 10px; fill: var(--ink-faint); font-family: var(--ui); }
.ch-axis-y { }
.ch-area { opacity: .12; }
.ch-line { stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.ch-threshold { stroke: var(--warn); stroke-width: 1.3; stroke-dasharray: 5 4; }
.ch-thr-lbl { fill: var(--warn); font-weight: 600; }
.ch-proj { stroke: var(--crit); stroke-width: 1.8; stroke-dasharray: 4 4; fill: none; opacity: .85; }
.ch-rupt-dot { fill: var(--crit); stroke: #fff; stroke-width: 1.5; }
.ch-rupt { fill: var(--crit); font-weight: 700; }
.barsh { width: 100%; height: auto; display: block; }
.bar-label { font-size: 12px; fill: var(--ink-soft); font-family: var(--ui); }
.bar-value { font-size: 12px; fill: var(--ink); font-weight: 700; font-family: var(--ui); font-variant-numeric: tabular-nums; }
.donut { width: 150px; height: 150px; }
.donut-top { font-size: 22px; font-weight: 700; fill: var(--ink); font-family: var(--ui); font-variant-numeric: tabular-nums; }
.donut-bot { font-size: 10px; fill: var(--ink-faint); font-family: var(--ui); text-transform: uppercase; letter-spacing: .4px; }
.legend { display: flex; flex-direction: column; gap: 7px; font-size: 13px; }
.legend .li { display: flex; align-items: center; gap: 8px; }
.legend .sw { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.legend .lv { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.donut-row { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }

/* ---------- Alertes ---------- */
.alert-list { display: flex; flex-direction: column; gap: 10px; }
.alert {
  display: grid; grid-template-columns: 4px 1fr auto; gap: 0 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow-s); align-items: center;
}
.alert .rail { grid-row: 1 / 4; width: 4px; border-radius: 4px; align-self: stretch; }
.alert.lvl-critique .rail { background: var(--crit); }
.alert.lvl-bas .rail { background: var(--warn); }
.alert.acquittee { opacity: .62; }
.alert-main { min-width: 0; }
.alert-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.alert-name { font-weight: 700; font-size: 14.5px; }
.alert-meta { font-size: 12.5px; color: var(--ink-soft); margin-top: 3px; display: flex; gap: 10px; flex-wrap: wrap; }
.alert-meta b { color: var(--ink); font-variant-numeric: tabular-nums; }
.alert-side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.alert-qty { font-size: 12px; color: var(--ink-soft); text-align: right; }
.alert-qty b { display: block; font-size: 18px; color: var(--ink); font-variant-numeric: tabular-nums; }

/* ---------- Détail produit ---------- */
.detail-head { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.detail-title { font-size: 22px; font-weight: 700; letter-spacing: -.4px; margin: 0; }
.detail-sku { font-family: var(--mono); font-size: 12.5px; color: var(--ink-faint); }
.attrs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.attr { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 10px 12px; }
.attr .k { font-size: 11px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .3px; }
.attr .v { font-size: 16px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }

/* Explicabilité du seuil */
.explain { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.explain h3 { margin: 0 0 4px; font-size: 14px; }
.explain .formula { font-family: var(--mono); font-size: 12.5px; color: var(--ink-soft); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; margin: 8px 0 14px; overflow-x: auto; }
.var-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.var { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 9px 10px; }
.var .sym { font-family: var(--mono); font-weight: 700; color: var(--green-700); font-size: 13px; }
.var .desc { font-size: 10.5px; color: var(--ink-faint); line-height: 1.3; margin: 1px 0 4px; }
.var .val { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.var.hl { background: var(--accent-bg); border-color: var(--accent-line); }
.var.hl .sym { color: var(--accent-600); }

/* Lots */
.lots { display: flex; flex-direction: column; gap: 8px; }
.lot { display: flex; align-items: center; gap: 12px; padding: 11px 12px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-s); }
.lot.nc { border-color: #e7c2bd; background: var(--crit-bg); }
.lot .lot-num { font-family: var(--mono); font-size: 12.5px; font-weight: 600; }
.lot .lot-info { font-size: 12px; color: var(--ink-soft); margin-top: 2px; display: flex; gap: 10px; flex-wrap: wrap; }
.lot .lot-qty { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }

/* ---------- Commande ---------- */
.supplier { margin-bottom: 16px; }
.supplier-head { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; background: var(--green-800); color: #fff; border-radius: var(--radius) var(--radius) 0 0; }
.supplier-head .s-name { font-weight: 700; font-size: 15px; }
.supplier-head .s-total { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 15px; }
.supplier-head .s-total small { font-weight: 500; opacity: .7; font-size: 11px; display: block; text-align: right; }
.supplier-body { border: 1px solid var(--line); border-top: none; border-radius: 0 0 var(--radius) var(--radius); overflow: hidden; }
.qty-input { width: 78px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.order-total-bar { display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  position: sticky; bottom: calc(var(--bottom-h) + 10px); box-shadow: var(--shadow); margin-top: 6px; z-index: 5; }
.order-total-bar .tt { font-size: 12px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .3px; }
.order-total-bar .tv { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.expl-toggle { font-size: 12px; color: var(--accent-600); font-weight: 600; cursor: pointer; }
.calc-detail { font-family: var(--mono); font-size: 11.5px; color: var(--ink-soft); padding: 8px 12px;
  background: var(--surface-2); border-top: 1px dashed var(--line-2); }

/* ---------- Réglages ---------- */
.settings-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
.set-card { padding: 16px; }
.set-card h3 { margin: 0 0 4px; font-size: 14px; }
.set-card .desc { font-size: 12.5px; color: var(--ink-faint); margin-bottom: 14px; }
.set-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.set-row > label { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); }
.inline-row { display: flex; gap: 10px; flex-wrap: wrap; }
.inline-row .field { flex: 1; min-width: 120px; }
.key-field { display: flex; gap: 8px; align-items: stretch; }
.key-field input { flex: 1; font-family: var(--mono); letter-spacing: 1px; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { display: inline-flex; align-items: center; gap: 6px; background: var(--bg-2); border: 1px solid var(--line-2);
  border-radius: 999px; padding: 5px 6px 5px 11px; font-size: 13px; }
.tag button { border: none; background: none; color: var(--ink-faint); font-size: 15px; line-height: 1; padding: 0 2px; }
.tag button:hover { color: var(--crit); }
.actions-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* Empty state */
.empty { text-align: center; color: var(--ink-faint); padding: 40px 16px; }
.empty svg { width: 38px; height: 38px; opacity: .4; margin-bottom: 8px; }

/* Toasts */
.toast-wrap { position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--bottom-h) + 16px + env(safe-area-inset-bottom)); z-index: 60;
  display: flex; flex-direction: column; gap: 8px; width: min(420px, 92vw); }
.toast { background: var(--green-900); color: #fff; border-radius: 10px; padding: 12px 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.22); font-size: 13.5px; display: flex; gap: 10px; align-items: center;
  animation: toast-in .22s ease; }
.toast.ok { background: #1d4a35; }
.toast.warn { background: #6b4e0e; }
.toast.err { background: #7d2a23; }
.toast .ico { width: 18px; height: 18px; flex: none; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.offline-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600;
  color: var(--accent-600); background: var(--accent-bg); border: 1px solid var(--accent-line);
  padding: 3px 9px; border-radius: 999px; }

/* ---------- Commande : cartes (B2 / B5 / B6) ---------- */
.supplier-cond { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 9px 14px;
  background: var(--surface-2); border: 1px solid var(--line); border-top: none;
  font-size: 12px; color: var(--ink-soft); }
.supplier-cond .ok { color: var(--ok); font-weight: 600; }
.supplier-cond .miss { color: var(--warn); font-weight: 600; }
.supplier-cond b { color: var(--ink); font-variant-numeric: tabular-nums; }
.cmd-lines { border: 1px solid var(--line); border-top: none;
  border-radius: 0 0 var(--radius) var(--radius); overflow: hidden; background: var(--surface); }
.cmd-line { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.cmd-line:last-child { border-bottom: none; }
.cmd-line.nc { background: var(--crit-bg); }
.cmd-line-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.cmd-prod { min-width: 0; }
.cmd-prod b { font-weight: 700; font-size: 14px; display: block; }
.cmd-prod .sku { font-family: var(--mono); font-size: 11px; color: var(--ink-faint); }
.cmd-line-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 10px; }
.cmd-cell { display: flex; flex-direction: column; gap: 3px; }
.cmd-cell .cl-k { font-size: 10.5px; text-transform: uppercase; letter-spacing: .3px; color: var(--ink-faint); font-weight: 600; }
.cmd-cell .cl-v { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.cmd-qty { background: var(--accent-bg); border: 1px solid var(--accent-line);
  border-radius: var(--radius-s); padding: 8px 10px; }
.cmd-qty .cl-k { color: var(--accent-600); }
.cmd-qty input { width: 100%; text-align: right; font-size: 19px; font-weight: 700;
  font-variant-numeric: tabular-nums; border-color: var(--accent-line); background: var(--surface); }
.cmd-amount .cl-v { color: var(--green-700); }
.cmd-line .expl-toggle { margin-top: 10px; display: inline-block; }
.cmd-line .calc-detail { margin-top: 8px; border-radius: 8px; border: 1px dashed var(--line-2); }
.cmd-nc-note { display: flex; align-items: center; gap: 6px; margin-top: 8px;
  font-size: 12px; color: var(--crit); font-weight: 600; }

/* B7 : aide en clair (tooltip discret + note sous KPI) */
.help { display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; border-radius: 50%; margin-left: 5px;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-faint);
  font-size: 10px; font-weight: 700; cursor: help; vertical-align: middle; line-height: 1; }
.kpi-sub { font-size: 11.5px; color: var(--ink-soft); font-weight: 600; margin-top: 2px; }
.kpi-sub b { color: var(--ink); font-variant-numeric: tabular-nums; }
.attr.hl-attr { background: var(--accent-bg); border-color: var(--accent-line); }
.attr.hl-attr .k { color: var(--accent-600); }

/* B4/B5 : alertes regroupées + actions */
.alert-actions { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.alert-actions .btn { white-space: nowrap; }
.alert.commandee { opacity: .72; }
.alert-sub { margin: 8px 0 0; padding: 0; border-top: 1px dashed var(--line-2); }
.alert-sub-line { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 0 2px; font-size: 12.5px; }
.alert-sub-line .as-wh { color: var(--ink-soft); }
.alert-sub-line .as-wh b { color: var(--ink); }
.alert-sub-line .as-act { display: flex; gap: 6px; flex-wrap: wrap; }
.group-toggle { margin-left: auto; }
.badge.cmd { color: var(--accent-600); background: var(--accent-bg); }

/* ---------- Desktop ---------- */
@media (min-width: 880px) {
  .shell { margin-left: var(--nav-w); padding-bottom: 0; }
  .nav {
    top: 0; bottom: 0; right: auto; width: var(--nav-w); height: 100vh;
    flex-direction: column; align-items: stretch; padding: 18px 14px;
    border-top: none; border-right: 1px solid rgba(255,255,255,.06); gap: 4px;
    background: linear-gradient(180deg, var(--green-900), var(--green-800));
  }
  .brand { display: flex; flex-direction: column; align-items: stretch; gap: 11px; padding: 4px 8px 20px; color: #fff; }
  .brand-logo { width: 100%; background: #f6f1e7; border-radius: 11px; padding: 11px 12px;
    display: flex; align-items: center; justify-content: center; box-shadow: 0 1px 0 rgba(0,0,0,.15); }
  .brand-logo img { height: 54px; width: auto; max-width: 100%; object-fit: contain; display: block; }
  .brand-text { display: flex; flex-direction: column; line-height: 1.15; padding: 0 2px; }
  .brand-text strong { font-size: 16px; letter-spacing: -.2px; }
  .brand-text em { font-style: normal; font-size: 11px; color: rgba(255,255,255,.5); letter-spacing: .2px; }
  .nav-item {
    flex: none; flex-direction: row; justify-content: flex-start; gap: 12px;
    padding: 11px 12px; border-radius: 10px; font-size: 14px; font-weight: 600;
    color: rgba(255,255,255,.66);
  }
  .nav-item:hover { background: rgba(255,255,255,.05); color: #fff; }
  .nav-item.active { background: rgba(255,255,255,.09); color: #fff; }
  .nav-item.active::before { display: none; }
  .nav-item span { font-size: 14px; max-width: none; }
  .nav-badge { position: static; margin-left: auto; right: auto; top: auto; }

  .topbar { padding: 16px 28px; }
  .view { padding: 24px 28px 40px; }
  .topbar-title { font-size: 21px; }

  .kpi-grid { grid-template-columns: repeat(3, 1fr); gap: 14px; }
  .kpi-value { font-size: 30px; }
  .grid-2 { grid-template-columns: 3fr 2fr; }
  .grid-cards { grid-template-columns: repeat(2, 1fr); }
  .attrs { grid-template-columns: repeat(4, 1fr); }
  .settings-grid { grid-template-columns: repeat(2, 1fr); }
  table.data { min-width: 0; }
  /* Plus de barre de nav basse en desktop : ancrer la barre de total au bas réel. */
  .order-total-bar { bottom: 16px; }
  /* Commande : disposition en ligne sur grand écran. */
  .cmd-line-grid { grid-template-columns: 1fr 1fr 1.2fr 1fr; align-items: end; }
  .search { flex: 1 1 auto; }
  .alert-actions { flex-direction: row; }
}

@media (min-width: 1200px) {
  .kpi-grid { grid-template-columns: repeat(6, 1fr); }
  .kpi-value { font-size: 27px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ============================================================================
   V3 — stock central maître. Extensions de la charte existante :
   connexion, bandeaux, navigation élargie, formulaires, modales, états vides.
   ============================================================================ */

/* ---------- Navigation : 12 destinations, barre basse défilante en mobile ---------- */
.nav { display: flex; }
.nav-liste { display: flex; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none;
  -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity; }
.nav-liste::-webkit-scrollbar { display: none; }
/* Sur téléphone, 4 onglets sur 12 tiennent à l'écran : un dégradé au bord droit
   signale que la barre continue (le 5e onglet coupé net ne suffit pas à le dire).
   Purement décoratif, il ne doit jamais intercepter le pouce. */
.nav::after {
  content: ""; position: absolute; right: 0; bottom: 0;
  height: calc(var(--bottom-h) + env(safe-area-inset-bottom));
  width: 24px; pointer-events: none; z-index: 1;
  background: linear-gradient(to right, transparent, var(--green-900));
}
.nav-item { flex: 0 0 auto; min-width: 76px; scroll-snap-align: start; }
.nav-item.active::before { left: 14%; right: 14%; }

/* ---------- Barre supérieure : session ---------- */
.session { display: flex; align-items: center; gap: 8px; }
.session-nom { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px;
  color: var(--ink-soft); background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 11px; box-shadow: var(--shadow-s); white-space: nowrap; }
.session-nom .ico { width: 14px; height: 14px; color: var(--ink-faint); }
.session-nom b { color: var(--ink); font-weight: 600; }
/* Le rôle est écrit à côté du nom : savoir si l'on est gérant ou employé
   explique d'un coup d'œil pourquoi certains écrans ne sont pas là. */
.session-role { font-style: normal; font-size: 11px; color: var(--ink-faint); }
.session-role::before { content: "· "; }
.session-mot { display: none; }

/* ---------- Bandeaux ---------- */
.bandeau-mode { background: var(--accent); color: #fff; font-size: 12px; font-weight: 700;
  letter-spacing: .3px; padding: 7px 16px; text-align: center; }
.bandeau { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface); margin-bottom: 16px; font-size: 13.5px; }
.bandeau b { font-weight: 700; }
.bandeau-info { background: var(--green-100); border-color: #cfe0d4; color: var(--green-800); }
.bandeau-warn { background: var(--warn-bg); border-color: #e8d6a8; color: #6b4e0e; }
.bandeau-crit { background: var(--crit-bg); border-color: #e7c2bd; color: #7d2a23; }
.bandeau-skus { display: flex; gap: 8px; flex-wrap: wrap; font-family: var(--mono); font-size: 12px; }
.bandeau-skus a { text-decoration: underline; }
.note-honnete { font-size: 12px; color: var(--ink-faint); line-height: 1.45; margin: 10px 2px 0; }
.note-permanente { background: var(--surface-2); border: 1px dashed var(--line-2); border-radius: var(--radius-s);
  padding: 10px 12px; margin: 0 0 18px; color: var(--ink-soft); }

/* ---------- Statuts supplémentaires ---------- */
.st-attente { color: var(--ink-soft); background: var(--bg-2); }
.st-incoherence { color: #fff; background: var(--crit); }
.pip-historique-insuffisant { background: var(--ink-faint); }
.pip-incoherence { background: #fff; }

/* ---------- Écran de connexion (sans navigation ni barre) ---------- */
body.ecran-nu .nav, body.ecran-nu .topbar, body.ecran-nu .bandeau-mode { display: none; }
body.ecran-nu .shell { margin-left: 0; padding-bottom: 0; }
body.ecran-nu .view { padding: 0; max-width: none; }
.login-page { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
  background: radial-gradient(1200px 600px at 50% -10%, #1c4531 0%, var(--green-900) 55%, #0b1f16 100%); }
.login-carte { width: min(400px, 100%); padding: 26px 22px; display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 24px 60px rgba(0,0,0,.35); }
.login-marque { display: flex; align-items: center; gap: 12px; }
.login-marque img { height: 44px; width: auto; }
.login-marque strong { display: block; font-size: 15px; letter-spacing: -.2px; }
.login-marque em { font-style: normal; font-size: 11.5px; color: var(--ink-faint); }
.login-carte h2 { margin: 6px 0 0; font-size: 20px; letter-spacing: -.3px; }
.login-sous { margin: 0; font-size: 12.5px; color: var(--ink-soft); }
.login-carte .field > label { text-transform: none; font-size: 12.5px; color: var(--ink-soft); letter-spacing: 0; }
.login-carte input { width: 100%; font-size: 16px; padding: 11px 12px; }
.login-envoi { width: 100%; padding: 12px; font-size: 15px; margin-top: 2px; }
.login-erreur { background: var(--crit-bg); border: 1px solid #e7c2bd; color: #7d2a23;
  border-radius: var(--radius-s); padding: 9px 11px; font-size: 13px; font-weight: 600; }

/* ---------- États vides accueillants ---------- */
.empty-titre { font-size: 15.5px; font-weight: 700; color: var(--ink); margin-top: 4px; }
.empty-msg { max-width: 46ch; margin: 8px auto 0; font-size: 13.5px; line-height: 1.5; color: var(--ink-soft); }
.empty-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }

.accueil { padding: 22px 18px; }
.accueil h2 { margin: 0 0 6px; font-size: 19px; letter-spacing: -.3px; }
.accueil > p { margin: 0 0 18px; color: var(--ink-soft); font-size: 14px; max-width: 62ch; }
.etapes { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.etapes li { display: flex; gap: 12px; align-items: flex-start; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--radius-s); padding: 13px 14px; }
.etapes b { font-size: 14.5px; }
.etapes p { margin: 3px 0 9px; font-size: 13px; color: var(--ink-soft); line-height: 1.45; }
.etape-n { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--green-700); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; }
/* Étape accomplie : barrée et estompée, sans disparaître — le gérant garde la
   vue d'ensemble de sa mise en service. */
.etapes li.etape-faite { opacity: .62; }
.etapes li.etape-faite b { text-decoration: line-through; }
.etapes li.etape-faite .etape-n { background: var(--ink-faint); }

/* ---------- Formulaires ---------- */
.form-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.champ-large { grid-column: 1 / -1; }
.field .aide { font-size: 11.5px; color: var(--ink-faint); line-height: 1.4; }
.fiche { padding: 16px; }
.fiche input, .fiche select { width: 100%; }
.detail-badges { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.conversion { margin-top: 10px; background: var(--accent-bg); border: 1px solid var(--accent-line);
  color: var(--accent-600); border-radius: var(--radius-s); padding: 9px 11px;
  font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.mol-ligne { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.mol-ligne input[type="text"] { flex: 2; min-width: 0; }
.mol-ligne input[type="number"] { flex: 1; min-width: 0; text-align: right; }
.mol-pct { color: var(--ink-faint); font-size: 13px; }
.btn-danger { background: var(--surface); border-color: #e7c2bd; color: var(--crit); }
.btn-danger:hover { background: var(--crit-bg); }
.btn.en-cours { opacity: .6; pointer-events: none; }

/* ---------- Modales ---------- */
.modale-fond { position: fixed; inset: 0; z-index: 70; background: rgba(15,42,29,.45);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); animation: toast-in .16s ease; }
.modale { position: relative; width: min(520px, 100%); max-height: 86vh; overflow-y: auto; padding: 20px; }
.modale h3 { margin: 0 0 8px; font-size: 17px; letter-spacing: -.2px; padding-right: 28px; }
.modale p { margin: 0 0 10px; font-size: 13.5px; color: var(--ink-soft); line-height: 1.5; }
.modale-sous { margin-bottom: 14px !important; }
.modale-rappel { background: var(--warn-bg); border: 1px solid #e8d6a8; color: #6b4e0e;
  border-radius: var(--radius-s); padding: 9px 11px; font-size: 12.5px; font-weight: 600; }
.modale-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 18px; }
.modale-fermer { position: absolute; top: 10px; right: 12px; border: none; background: none;
  font-size: 22px; line-height: 1; color: var(--ink-faint); padding: 2px 6px; }
.modale-fermer:hover { color: var(--ink); }

/* ---------- Desktop ---------- */
@media (min-width: 880px) {
  .nav-liste { flex-direction: column; overflow: visible; flex: 1; gap: 3px; }
  .nav::after { display: none; } /* rail vertical : rien ne défile */
  .nav-item { min-width: 0; }
  .session-mot { display: inline; }
  .bandeau-mode { position: sticky; top: 0; z-index: 25; }
  .form-grid { grid-template-columns: repeat(2, 1fr); }
  .etapes { grid-template-columns: repeat(2, 1fr); }
  .login-carte { padding: 32px 30px; }
}

/* ============================================================
 * Reprise des attributs `style=` du HTML généré
 *
 * POURQUOI : l'en-tête CSP sert `style-src 'self'` (backend/lib/securite.js),
 * ce qui rend TOUT attribut `style=` inerte — 284 violations style-src-attr
 * relevées sur une seule session au navigateur. Les déclarations qui vivaient
 * dans ces attributs sont donc rapatriées ici, où la feuille les applique
 * vraiment. Ce qui dépend d'une valeur calculée (largeur de jauge, couleur de
 * famille) est posé par le CSSOM côté JS : le CSSOM, lui, n'est pas filtré.
 * ============================================================ */

/* sprite d'icônes : hors flux, il ne doit rien pousser (index.html) */
.sprite-icones { position: absolute; }

/* identifiants techniques en table : SKU, numéro d'envoi (Réserve, fiche produit) */
.cell-mono { font-family: var(--mono); font-size: 11px; }

/* en-tête de section collé au bord d'une carte, sans le retrait latéral de .section-head */
.section-head-plate { margin: 0 0 12px; }
.section-head-carte { margin: 0 0 8px; }
.section-head h3 { margin: 0; }

/* compléments de titre en graisse normale (« / 128 », « · capital immobilisé … ») */
.faint-normal { font-weight: 400; }

/* section qui suit un bloc de cartes (Tableau de bord) */
.section-suite { margin-top: 22px; }

/* fiche produit : bandeau d'actions, trio d'attributs, dépliant du calcul */
.actions-row-fiche { margin-top: 16px; }
.attrs-trio { grid-template-columns: repeat(3, 1fr); margin: 8px 0 0; }
.expl-toggle-espace { margin-top: 12px; }
.expl-corps { margin-top: 10px; }

/* proposition de commande : chapeau et bouton d'export par fournisseur */
.cmd-chapeau { font-size: 12.5px; margin: 0 0 14px; }
.cmd-export-ligne { display: flex; justify-content: flex-end; padding: 10px 0 4px; }

/* flèche des cartes d'indicateurs (Tableau de bord) */
.kpi-arrow .ico { width: 15px; height: 15px; }

/* compteur d'alertes accolé au titre de l'écran */
.badge-titre { margin-left: 6px; }

/* Analytique : barre de filtres dans une carte, sélecteur de produit */
.filters-plate { margin: 0; }
.select-produit { max-width: 260px; }

/* Analytique : sens de la variation sur 7/30 jours.
 * Un jeu de classes plutôt qu'une couleur calculée : la valeur n'a que trois
 * états, une classe se lit mieux qu'un ternaire posé dans un attribut. */
.var-hausse { color: var(--ok); }
.var-baisse { color: var(--crit); }
