/* ============================================================
   EllioERP — thème & mise en page
   Même socle que les autres démonstrateurs Ellio (clair + sombre),
   accent vert sarcelle propre à l'ERP de cartonnerie.
   ============================================================ */
:root {
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --surface-2: #f0efec;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;
  --series-2: #1baf7a;
  --series-3: #eda100;
  --series-5: #4a3aa7;
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;
  --seq-100: #cde2fb; --seq-200: #9ec5f4; --seq-300: #6da7ec;
  --seq-400: #3987e5; --seq-500: #256abf; --seq-600: #184f95; --seq-700: #0d366b;
  --accent: #0f8f88;                       /* ← couleur propre au produit */
  --accent-soft: rgba(15, 143, 136, .12); /* ← idem, accent à 12 % */
  --accent-deep: #0a6b66;                  /* ← accent assombri : dégradé de marque */
  --on-accent: #ffffff;                    /* ← texte posé sur un aplat d'accent */
  --shadow: 0 1px 3px rgba(0, 0, 0, .07);
}
[data-theme="dark"] {
  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #242423;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;
  --series-2: #199e70;
  --series-3: #c98500;
  --series-5: #9085e9;
  --accent: #2cb5ad;                       /* ← couleur propre au produit */
  --accent-soft: rgba(44, 181, 173, .14); /* ← idem, accent à 14 % */
  --accent-deep: #17827c;                  /* ← accent assombri : dégradé de marque */
  --on-accent: #ffffff;                    /* ← texte posé sur un aplat d'accent */
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--page);
}
a { color: var(--accent); }

/* ---------------- structure ---------------- */
#app { display: grid; grid-template-columns: 218px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  padding: 18px 12px;
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; }
.brand-logo {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px;
}
.brand-logo svg { width: 21px; height: 21px; stroke: #fff; fill: none; stroke-width: 1.9; stroke-linejoin: round; stroke-linecap: round; }
.brand b { font-size: 16px; letter-spacing: .2px; }
.brand span { display: block; font-size: 11px; color: var(--text-muted); }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 9px;
  color: var(--text-secondary); text-decoration: none;
  font-weight: 500; transition: background .12s, color .12s;
}
.nav-item svg { width: 17px; height: 17px; flex: none; stroke-width: 1.9; }
.nav-item:hover { background: var(--surface-2); color: var(--text-primary); }
.nav-item.active { background: var(--surface-2); color: var(--accent); }
.nav-item .pill {
  margin-left: auto; background: var(--status-critical); color: #fff;
  font-size: 11px; font-weight: 700; border-radius: 99px;
  min-width: 19px; height: 19px; display: grid; place-items: center; padding: 0 5px;
}
.sidebar-foot { margin-top: auto; padding: 10px 12px; font-size: 11px; color: var(--text-muted); }

.main { padding: 20px 26px 46px; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.topbar h1 { font-size: 21px; font-weight: 650; letter-spacing: .2px; }
.topbar .spacer { flex: 1; }
.live-dot {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--text-secondary);
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 99px; padding: 6px 12px;
}
.live-dot i {
  width: 8px; height: 8px; border-radius: 50%; background: var(--status-good);
  animation: pulse 1.6s infinite;
}
.live-dot.stale i { background: var(--text-muted); animation: none; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }

/* ---------------- composants ---------------- */
.grid { display: grid; gap: 14px; }
.cols-2 { grid-template-columns: 1fr 1fr; }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1150px) { .cols-4 { grid-template-columns: repeat(2, 1fr); } .cols-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 800px) {
  #app { grid-template-columns: 64px 1fr; }
  .sidebar .label, .brand div, .sidebar-foot { display: none; }
  .cols-2, .cols-3, .cols-4 { grid-template-columns: 1fr; }
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card h3 {
  font-size: 12.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .6px; color: var(--text-muted); margin-bottom: 12px;
  display: flex; align-items: center; gap: 8px;
}
.card h3 .right { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 500; }

.kpi { display: flex; flex-direction: column; gap: 3px; }
.kpi .v { font-size: 26px; font-weight: 650; line-height: 1.15; }
.kpi .v small { font-size: 14px; font-weight: 500; color: var(--text-secondary); }
.kpi .l { font-size: 12px; color: var(--text-muted); }
.kpi .sub { font-size: 12px; color: var(--text-secondary); }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 600; border-radius: 99px; padding: 3px 10px;
  background: var(--surface-2); color: var(--text-secondary);
}
.badge.good { background: color-mix(in srgb, var(--status-good) 16%, transparent); color: var(--status-good); }
.badge.warn { background: color-mix(in srgb, var(--status-warning) 18%, transparent); color: color-mix(in srgb, var(--status-warning) 70%, var(--text-primary)); }
.badge.serious { background: color-mix(in srgb, var(--status-serious) 18%, transparent); color: var(--status-serious); }
.badge.crit { background: color-mix(in srgb, var(--status-critical) 16%, transparent); color: var(--status-critical); }
.badge.accent { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }

button, .btn {
  font: inherit; cursor: pointer;
  background: var(--surface-2); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 9px;
  padding: 7px 14px; font-weight: 550;
  transition: filter .12s, background .12s;
}
button:hover { filter: brightness(1.06); }
.btn-primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 4px 10px; font-size: 12.5px; border-radius: 7px; }
.btn-icon { padding: 7px 9px; display: inline-grid; place-items: center; }
.btn-icon svg { width: 16px; height: 16px; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: none; background: transparent; padding: 6px 14px; border-radius: 7px; color: var(--text-secondary); }
.seg button.on { background: var(--surface-1); color: var(--text-primary); box-shadow: var(--shadow); font-weight: 600; }
.seg button.on.mode-auto { color: var(--status-good); }
.seg button.on.mode-suspendu { color: var(--status-critical); }

input, select {
  font: inherit; color: var(--text-primary);
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 9px; padding: 7px 11px; outline: none; min-width: 0;
}
input:focus, select:focus { border-color: var(--accent); }
input[type="number"] { width: 90px; }
.filters { display: flex; flex-wrap: wrap; gap: 9px; align-items: end; margin-bottom: 14px; }
.filters .f { display: flex; flex-direction: column; gap: 4px; font-size: 11.5px; color: var(--text-muted); }

/* ---------------- tables ---------------- */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-muted); font-weight: 600; padding: 8px 10px;
  border-bottom: 1px solid var(--grid); white-space: nowrap;
}
.tbl td { padding: 8px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
.tbl tbody tr { cursor: pointer; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl .num { font-variant-numeric: tabular-nums; text-align: right; }
.tbl th.num { text-align: right; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: end; margin-top: 12px; font-size: 12.5px; color: var(--text-secondary); }


/* ---------------- barre de progression & tuiles de valeur ---------------- */
.conf-bar { height: 7px; border-radius: 99px; background: var(--surface-2); overflow: hidden; flex: 1; }
.conf-bar i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--seq-300), var(--seq-500)); }

.sensor-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.sensor-tile { border: 1px solid var(--border); border-radius: 10px; padding: 10px 13px; cursor: pointer; background: var(--surface-1); }
.sensor-tile:hover { background: var(--surface-2); }
.sensor-tile .sv { font-size: 21px; font-weight: 650; font-variant-numeric: tabular-nums; }
.sensor-tile .sn { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }

/* ---------------- modal & tooltip ---------------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .5);
  display: grid; place-items: center; z-index: 50; padding: 20px;
}
.modal {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 14px; padding: 20px 22px;
  width: min(880px, 100%); max-height: 90vh; overflow-y: auto;
}
.modal h2 { font-size: 17px; margin-bottom: 14px; display: flex; align-items: center; gap: 10px; }
.modal h2 button { margin-left: auto; }

.chart-tip {
  position: absolute; z-index: 99; pointer-events: none;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 9px; padding: 8px 11px; font-size: 12.5px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .25); color: var(--text-primary);
  display: none; max-width: 260px;
}
.chart-tip .tt-head { color: var(--text-muted); font-size: 11.5px; margin-bottom: 4px; }
.chart-tip div { line-height: 1.5; }
.chart-tip i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 6px; }

/* ---------------- utilitaires ---------------- */
.muted { color: var(--text-muted); }
.sec { color: var(--text-secondary); }
.mt { margin-top: 12px; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-secondary); margin-top: 8px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
canvas { display: block; width: 100%; }
.empty { text-align: center; color: var(--text-muted); padding: 40px 0; }

/* ---------------- spécifique ---------------- */
/* Vocabulaire visuel propre à EllioERP. Aucune couleur littérale ici :
   tout passe par les variables déclarées dans le bloc de tokens ci-dessus. */

/* -- topbar : sélecteur d'unité et repli étroit ------------------------- */
.topbar { flex-wrap: wrap; }
.topbar .seg button { padding: 6px 12px; font-variant-numeric: tabular-nums; }
@media (max-width: 800px) {
  .main { padding: 16px 14px 40px; }
  .topbar h1 { font-size: 18px; }
  .live-dot { display: none; }
}

/* -- onglets (référentiels, atelier, facturation) ----------------------- */
.tabs {
  display: flex; gap: 4px; flex-wrap: wrap;
  border-bottom: 1px solid var(--border); margin-bottom: 14px;
}
.tabs button {
  background: transparent; border: none; border-bottom: 2px solid transparent;
  border-radius: 0; padding: 9px 14px; color: var(--text-secondary); font-weight: 550;
}
.tabs button:hover { color: var(--text-primary); background: var(--surface-2); }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }

/* -- liens internes, références, petites annotations -------------------- */
.link { color: var(--accent); cursor: pointer; text-decoration: none; border-bottom: 1px solid transparent; }
.link:hover { border-bottom-color: var(--accent); }
.tag {
  font-variant-numeric: tabular-nums; font-size: 12px; letter-spacing: .2px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 1px 7px; white-space: nowrap;
}
.sub { font-size: 11.5px; color: var(--text-muted); }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.tight { gap: 5px; }
.right-of { margin-left: auto; }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }

/* -- couples libellé / valeur des fiches -------------------------------- */
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px 18px; }
.kv > div { min-width: 0; }
.kv .k { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); }
.kv .v { font-size: 14.5px; font-weight: 550; font-variant-numeric: tabular-nums; margin-top: 2px; overflow-wrap: anywhere; }
.kv .v small { font-weight: 400; color: var(--text-secondary); }

/* -- sections d'une fiche ---------------------------------------------- */
.sec-title {
  font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px;
  color: var(--text-muted); margin: 18px 0 9px;
  display: flex; align-items: center; gap: 8px;
}
.sec-title:first-child { margin-top: 0; }
.sec-title .right { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 500; }
.panel { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }

/* -- encadré d'explication (méthode, formule, renvoi) ------------------- */
.note {
  border-left: 3px solid var(--accent); background: var(--accent-soft);
  border-radius: 0 9px 9px 0; padding: 10px 14px; font-size: 12.5px;
  color: var(--text-secondary); line-height: 1.55;
}
.note b { color: var(--text-primary); }

/* -- calcul pas à pas (fiche article : cotes → développé → prix) -------- */
.calc { display: flex; flex-direction: column; gap: 7px; }
.calc-l {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 14px; align-items: baseline;
  padding: 7px 11px; border-radius: 8px; background: var(--surface-2);
}
.calc-l .f { font-size: 12.5px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.calc-l .r { font-size: 14.5px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.calc-l .n { grid-column: 1 / -1; font-size: 11.5px; color: var(--text-muted); }
.calc-l.tot { background: var(--accent-soft); }
.calc-l.tot .r { color: var(--accent); }

/* -- barre empilée : décomposition d'un prix, d'un tonnage, d'un temps -- */
.stackbar { display: flex; height: 12px; border-radius: 99px; overflow: hidden; background: var(--surface-2); }
.stackbar i { display: block; height: 100%; min-width: 1px; }
.stackbar i.s1 { background: var(--series-1); }
.stackbar i.s2 { background: var(--series-2); }
.stackbar i.s3 { background: var(--series-3); }
.stackbar i.s5 { background: var(--series-5); }
.stackbar i.sa { background: var(--accent); }
.stackbar i.sm { background: var(--text-muted); }
.stack-leg { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 9px; font-size: 12px; color: var(--text-secondary); }
.stack-leg span { display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.stack-leg i { width: 10px; height: 10px; border-radius: 3px; flex: none; }

/* -- jauge en ligne dans un tableau (poids restant d'une bobine…) ------- */
.bar-cell { display: flex; align-items: center; gap: 9px; min-width: 130px; }
.bar-cell .conf-bar { height: 6px; }
.bar-cell .conf-bar i.warn { background: linear-gradient(90deg, var(--status-warning), var(--status-serious)); }
.bar-cell .conf-bar i.crit { background: var(--status-critical); }
.bar-cell .conf-bar i.ok { background: linear-gradient(90deg, var(--status-good), var(--seq-400)); }
.bar-cell b { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 44px; text-align: right; }

/* -- programme de coupe dessiné sur la laize (geste n° 3) --------------- */
.laize { display: flex; flex-direction: column; gap: 5px; }
.laize-head { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text-muted); }
.laize-track {
  display: flex; height: 54px; border: 1px solid var(--border); border-radius: 9px;
  overflow: hidden; background: var(--surface-2);
}
.laize-seg {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; min-width: 0; overflow: hidden; padding: 0 2px;
  border-right: 1px solid var(--surface-1); background: var(--accent-soft);
  font-size: 11px; color: var(--text-primary); text-align: center; line-height: 1.25;
}
.laize-seg b { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.laize-seg span { color: var(--text-muted); font-size: 10.5px; white-space: nowrap; }
.laize-seg.f2 { background: color-mix(in srgb, var(--series-2) 15%, transparent); }
.laize-seg.f3 { background: color-mix(in srgb, var(--series-5) 15%, transparent); }
.laize-seg.rogne, .laize-seg.chute {
  background: repeating-linear-gradient(135deg,
      var(--surface-2) 0 5px,
      color-mix(in srgb, var(--status-serious) 30%, transparent) 5px 10px);
  color: var(--text-secondary);
}
.laize-seg.chute { background: repeating-linear-gradient(135deg,
      var(--surface-2) 0 5px,
      color-mix(in srgb, var(--status-critical) 34%, transparent) 5px 10px); }
.laize-track.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.laize-rule { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* -- schémas SVG (développé de caisse, couches du carton, palette) ------ */
.fig { width: 100%; overflow-x: auto; }
.fig svg { display: block; width: 100%; height: auto; max-width: 560px; margin: 0 auto; }
.fig svg .ln { stroke: var(--text-secondary); fill: none; stroke-width: 1.6; }
.fig svg .rain { stroke: var(--accent); fill: none; stroke-width: 1.4; stroke-dasharray: 5 4; }
.fig svg .cote { stroke: var(--text-muted); fill: none; stroke-width: 1; }
.fig svg .face { fill: var(--accent-soft); stroke: var(--text-secondary); stroke-width: 1.4; }
.fig svg .rabat { fill: var(--surface-2); stroke: var(--text-secondary); stroke-width: 1.4; }
.fig svg text { fill: var(--text-muted); font-size: 10.5px; font-family: inherit; }
.fig svg text.on { fill: var(--text-primary); font-weight: 600; }

/* -- Gantt du jour (une ligne par machine) ----------------------------- */
.gantt { display: flex; flex-direction: column; gap: 7px; }
.gantt-row { display: grid; grid-template-columns: 74px 1fr; gap: 10px; align-items: center; }
.gantt-row .m { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.gantt-track {
  position: relative; height: 30px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border); overflow: hidden;
}
.gantt-bar {
  position: absolute; top: 3px; bottom: 3px; border-radius: 6px;
  background: var(--accent); color: var(--on-accent); font-size: 10.5px; font-weight: 600;
  display: flex; align-items: center; padding: 0 6px; overflow: hidden; white-space: nowrap;
  cursor: pointer;
}
.gantt-bar.g2 { background: var(--series-2); }
.gantt-bar.g5 { background: var(--series-5); }
.gantt-bar.stop { background: repeating-linear-gradient(135deg, var(--status-critical) 0 5px, var(--status-serious) 5px 10px); }
.gantt-bar.plan { background: var(--surface-1); border: 1px dashed var(--axis); color: var(--text-secondary); }
.gantt-scale { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; padding-left: 84px; }
.gantt-now { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--status-critical); }

/* -- palettisation (schéma d'une couche) ------------------------------- */
.pal { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.pal-couche {
  display: grid; gap: 3px; padding: 6px;
  border: 1px solid var(--axis); border-radius: 7px; background: var(--surface-2);
}
.pal-case { background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 3px; }
.pal-case.v { background: var(--surface-1); border-color: var(--border); }

/* -- traçabilité amont / aval ------------------------------------------ */
.trace { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.trace-col { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.trace-col > .k {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-muted); font-weight: 600;
}
.trace-node {
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 8px 10px; background: var(--surface-2);
  font-size: 12.5px; cursor: pointer; min-width: 0;
}
.trace-node:hover { border-color: var(--accent); }
.trace-node b { display: block; font-variant-numeric: tabular-nums; }
.trace-node span { color: var(--text-muted); font-size: 11.5px; }
.trace-node.na { border-left-color: var(--text-muted); cursor: default; }

/* -- rapprochement trois voies / avancement d'un flux ------------------- */
.steps { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.step {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); border-radius: 99px; padding: 5px 12px;
  font-size: 12px; color: var(--text-muted); background: var(--surface-2);
}
.step.ok { color: var(--status-good); border-color: color-mix(in srgb, var(--status-good) 40%, transparent); }
.step.ko { color: var(--status-critical); border-color: color-mix(in srgb, var(--status-critical) 40%, transparent); }
.step-sep { color: var(--text-muted); }

/* -- alertes du tableau de bord ---------------------------------------- */
.alerts { display: flex; flex-direction: column; gap: 8px; }
.alert {
  display: flex; gap: 10px; align-items: flex-start;
  border: 1px solid var(--border); border-left: 3px solid var(--text-muted);
  border-radius: 9px; padding: 9px 12px; cursor: pointer; background: var(--surface-2);
}
.alert:hover { border-color: var(--accent); }
.alert.warn { border-left-color: var(--status-warning); }
.alert.serious { border-left-color: var(--status-serious); }
.alert.crit { border-left-color: var(--status-critical); }
.alert svg { width: 16px; height: 16px; flex: none; margin-top: 1px; stroke-width: 2; }
.alert .t { font-size: 13px; font-weight: 550; }
.alert .d { font-size: 11.5px; color: var(--text-muted); margin-top: 1px; }

/* -- listes de valeurs compactes (marge par client, TRS par machine…) --- */
.mini { display: flex; flex-direction: column; gap: 9px; }
.mini-l { display: grid; grid-template-columns: 1fr auto; gap: 3px 12px; align-items: center; }
.mini-l .n { font-size: 12.5px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-l .v { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.mini-l .conf-bar { grid-column: 1 / -1; height: 5px; }

/* -- écran d'accueil ---------------------------------------------------- */
.accueil { width: min(620px, 100%); text-align: left; }
.accueil .logo {
  width: 52px; height: 52px; border-radius: 13px; margin-bottom: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  display: grid; place-items: center;
}
.accueil .logo svg { width: 30px; height: 30px; stroke: var(--on-accent); fill: none; stroke-width: 1.8; stroke-linejoin: round; }
.accueil h2 { font-size: 21px; margin-bottom: 8px; }
.accueil p { color: var(--text-secondary); line-height: 1.6; margin-bottom: 12px; }
.accueil ul { color: var(--text-secondary); line-height: 1.7; margin: 0 0 14px 18px; font-size: 13px; }
.accueil .acts { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 16px; }

/* -- filtres, pastilles de sélection ------------------------------------ */
.filters .f select, .filters .f input { min-width: 132px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-b {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 99px;
  padding: 4px 12px; font-size: 12px; color: var(--text-secondary);
}
.chip-b.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* -- tableaux : tri, largeur, sélection --------------------------------- */
.tbl th.s { cursor: pointer; user-select: none; }
.tbl th.s:hover { color: var(--text-primary); }
.tbl th.s::after { content: ''; }
.tbl th.s.asc::after { content: ' ▲'; font-size: 8px; }
.tbl th.s.desc::after { content: ' ▼'; font-size: 8px; }
.tbl tbody tr.sel { background: var(--accent-soft); }
.tbl td.w { white-space: normal; min-width: 150px; }
.tbl tfoot td { padding: 8px 10px; font-weight: 650; border-top: 1px solid var(--axis); font-variant-numeric: tabular-nums; }

/* -- modales larges ----------------------------------------------------- */
.modal.wide { width: min(1040px, 100%); }
.modal h2 .tag { font-weight: 500; }
.modal h2 .sub { font-weight: 400; }

/* -- bandeau « en direct » de l'onduleuse ------------------------------- */
.direct { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.direct .d {
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: var(--surface-2);
}
.direct .d .v { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.direct .d .l { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }
.src {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600;
  color: var(--accent); background: var(--accent-soft); border-radius: 99px; padding: 2px 9px;
}

/* -- pied de vue -------------------------------------------------------- */
.vue-note { font-size: 11.5px; color: var(--text-muted); margin-top: 6px; line-height: 1.55; }
.lecture-seule { cursor: not-allowed; opacity: .62; }

/* ---------------- mobile ---------------- */
/* Socle mobile de la charte Ellio (references/mobile.css, 06/09/2026).
   À coller tel quel à la fin de app.css, après le bloc « spécifique ».
   Palier « téléphone » ≤ 640 px : rien ici ne s'applique au-dessus, le rendu PC
   reste identique au pixel. Le bloc (hover:none) and (pointer:coarse) ne vise que
   les écrans tactiles sans souris (téléphone, tablette) : un PC à écran tactile,
   dont le pointeur principal est la souris, n'y entre pas.
   Décision de la gamme : sous 640 px la barre latérale devient une barre
   d'onglets fixe en bas, défilante, icône + libellé — même HTML, CSS seul. */

@media (max-width: 640px) {
  :root { --tabbar-h: 60px; --sab: env(safe-area-inset-bottom, 0px); }
  html { -webkit-text-size-adjust: 100%; }

  /* -- coque : barre d'onglets en bas (la .sidebar sort du flux de la grille) -- */
  #app { grid-template-columns: 1fr; min-height: 100vh; min-height: 100dvh; }
  .sidebar {
    position: fixed; top: auto; right: 0; bottom: 0; left: 0; z-index: 40;
    height: auto; flex-direction: row; align-items: stretch; gap: 2px;
    padding: 4px 4px calc(4px + var(--sab));
    border-right: 0; border-top: 1px solid var(--border);
    overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain; scrollbar-width: none; scroll-snap-type: x proximity;
    box-shadow: 0 -2px 10px color-mix(in srgb, var(--text-primary) 8%, transparent);
  }
  .sidebar::-webkit-scrollbar { display: none; }
  .brand, .sidebar-foot { display: none; }
  .nav-item {
    flex: 0 0 auto; flex-direction: column; justify-content: center; gap: 3px;
    min-width: 64px; min-height: 50px; padding: 5px 6px; border-radius: 9px;
    font-size: 10px; line-height: 1.1; text-align: center; position: relative;
    scroll-snap-align: center;
  }
  .nav-item svg { width: 21px; height: 21px; }
  .sidebar .nav-item .label { display: block; white-space: nowrap; } /* bat le repli 800 px (0,2,1 > 0,1,1) */
  .nav-item .pill { position: absolute; top: 2px; right: 6px; margin: 0;
                    min-width: 16px; height: 16px; font-size: 10px; padding: 0 4px; }

  /* -- contenu : marges réduites, place dégagée sous la barre d'onglets -- */
  .main { padding: 12px 12px calc(var(--tabbar-h) + 16px + var(--sab)); }
  .topbar { flex-wrap: wrap; gap: 8px 10px; margin-bottom: 12px; }
  .topbar h1 { flex: 1 1 100%; font-size: 18px; line-height: 1.25; }  /* titre seul sur sa ligne */
  .topbar .spacer { flex: 1 1 0; }                                     /* indicateurs à droite, ligne 2 */
  .topbar .badge, .topbar .live-dot, .topbar .chip { white-space: normal; max-width: 100%; }
  .grid { gap: 10px; }
  /* minmax(0, 1fr) : une colonne 1fr ne descend jamais sous la largeur intrinsèque de son contenu
     (un <select>, un texte nowrap) et ferait déborder la page */
  .cols-2, .cols-3, .cols-4 { grid-template-columns: minmax(0, 1fr); }
  .grid[style] { grid-template-columns: minmax(0, 1fr) !important; }  /* grilles posées en inline par le JS */
  .grid > *, .card { min-width: 0; }
  .card { padding: 12px; border-radius: 11px; }
  .card h3 { flex-wrap: wrap; row-gap: 6px; }
  .card h3 .right { flex-basis: 100%; max-width: 100%; min-width: 0; flex-wrap: wrap; }  /* commandes sous le titre */
  .card h3 .right select { flex: 1 1 100%; width: 100%; }
  .kpi .v { font-size: 24px; }
  .sensor-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .legend { gap: 6px 14px; }
  .pager { flex-wrap: wrap; justify-content: center; }
  .empty { padding: 28px 0; }

  /* -- champs, filtres, segmentés, onglets -- */
  input, select, textarea { font-size: 16px; }   /* sous 16 px, iOS zoome à la prise de focus */
  select { max-width: 100%; }                     /* un <select> prend la largeur de sa plus longue option */
  input[type="number"] { width: 100px; }
  .filters { gap: 8px; }
  .filters .f { flex: 1 1 calc(50% - 8px); min-width: 0; }
  .filters .f select, .filters .f input { width: 100%; min-width: 0; }
  .filters .f input[style], .filters .f select[style] { width: 100% !important; min-width: 0 !important; }
  .filters > button, .filters > .btn { flex: 1 1 100%; }
  .seg { flex-wrap: wrap; max-width: 100%; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { flex: 0 0 auto; white-space: nowrap; }

  /* -- tableaux : ils défilent dans .tbl-wrap ; ombres de bord = indice de défilement
        (les deux calques « surface » suivent le contenu et découvrent l'ombre) -- */
  .tbl-wrap {
    -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain;
    background:
      linear-gradient(to right, var(--surface-1) 40%, transparent) left / 32px 100% no-repeat local,
      linear-gradient(to left,  var(--surface-1) 40%, transparent) right / 32px 100% no-repeat local,
      linear-gradient(to right, color-mix(in srgb, var(--text-primary) 16%, transparent), transparent) left / 12px 100% no-repeat scroll,
      linear-gradient(to left,  color-mix(in srgb, var(--text-primary) 16%, transparent), transparent) right / 12px 100% no-repeat scroll;
  }
  .tbl td { padding: 12px 10px; }   /* lignes cliquables ≈ 44 px */

  /* -- modales : feuille ancrée en bas, hauteur bornée par le viewport dynamique -- */
  .modal-back { padding: 0; align-items: end; }
  .modal, .modal.wide {
    width: 100%; max-height: 92vh; max-height: calc(100dvh - 24px);
    border-radius: 16px 16px 0 0; border-bottom: 0;
    padding: 14px 14px calc(16px + var(--sab));
  }
  .modal h2 { font-size: 16px; flex-wrap: wrap; }

  /* -- info-bulle, toast (au-dessus de la barre d'onglets) -- */
  .chart-tip { max-width: min(300px, calc(100vw - 24px)); }
  .toast { left: 12px; right: 12px; max-width: none; transform: none; animation: none;
           bottom: calc(var(--tabbar-h) + 14px + var(--sab)); }
}

@media (hover: none) and (pointer: coarse) {
  /* cibles tactiles ≥ 44 px ; 40 px pour les commandes compactes */
  button, .btn { min-height: 44px; }
  .btn-icon { min-width: 44px; min-height: 44px; }
  .btn-sm, .seg button, .tabs button, .pager button { min-height: 40px; }
  .btn-sm { min-width: 40px; }
  .seg button { min-width: 40px; }
  a.btn, a.btn-sm { display: inline-flex; align-items: center; }   /* min-height sans effet sur un lien inline */
  a.badge { display: inline-flex; align-items: center; min-height: 40px; }
  input[type="color"] { min-width: 44px; min-height: 40px; }
  summary { min-height: 44px; }
  select, textarea,
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]) { min-height: 44px; }
  input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; }
  input[type="range"] { min-height: 44px; }
  .nav-item { min-height: 50px; }
  /* pas de halo au toucher, retour visuel bref à l'appui */
  a, button, .nav-item, .tbl tbody tr, .sensor-tile { -webkit-tap-highlight-color: transparent; }
  button:active, .btn:active, .nav-item:active { filter: brightness(.9); }
  /* le survol « colle » après un toucher : on le neutralise */
  button:hover, .btn:hover { filter: none; }
  .nav-item:hover { background: transparent; color: var(--text-secondary); }
  .nav-item.active:hover { background: var(--surface-2); color: var(--accent); }
  .tbl tbody tr:hover { background: transparent; }
  .sensor-tile:hover { background: var(--surface-1); }
}

/* ---------------- mobile : spécifique EllioERP ---------------- */
@media (max-width: 640px) {
  /* Programme de coupe : la laize garde son échelle et défile avec sa graduation ;
     les textes nowrap 11/10,5 px ne sont plus rognés */
  .laize { overflow-x: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; padding-bottom: 4px;
    background:
      linear-gradient(to right, var(--surface-1) 40%, transparent) left / 32px 100% no-repeat local,
      linear-gradient(to left,  var(--surface-1) 40%, transparent) right / 32px 100% no-repeat local,
      linear-gradient(to right, color-mix(in srgb, var(--text-primary) 16%, transparent), transparent) left / 12px 100% no-repeat scroll,
      linear-gradient(to left,  color-mix(in srgb, var(--text-primary) 16%, transparent), transparent) right / 12px 100% no-repeat scroll; }
  .laize-track, .laize-rule { min-width: 560px; }
  .laize-head { flex-wrap: wrap; gap: 2px 10px; }
  .laize-seg, .laize-seg span, .laize-rule { font-size: 11px; }
  /* Palettisation (grilles repeat(n, Wpx) posées en inline par le JS, conservées) :
     la couche à l'échelle défile dans son cadre, les couples libellé/valeur passent dessous */
  .pal { flex-direction: column; gap: 12px; }
  .pal-couche { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; justify-content: start; }
  .pal > div[style] { min-width: 0 !important; width: 100%; }
  /* Gantt : nom de machine au-dessus de sa piste, piste pleine largeur */
  .gantt { gap: 9px; }
  .gantt-row { grid-template-columns: 1fr; gap: 2px; }
  .gantt-row .m:empty { display: none; }
  .gantt-track { height: 34px; }
  .gantt-scale { padding-left: 0; font-size: 11px; }
  .gantt-bar { font-size: 11px; }
  /* fiches : couples libellé/valeur en 2 colonnes, bandeau « en direct » plus dense */
  .kv { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px 12px; }
  .direct[style] { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)) !important; }
  .trace { grid-template-columns: 1fr; }
  .fig { -webkit-overflow-scrolling: touch; }
  .fig svg text, .trace-col > .k { font-size: 11px; }
  .accueil { width: 100%; }
  .topbar .seg button { padding: 6px 10px; }
}
@media (hover: none) and (pointer: coarse) {
  .tabs button:hover { background: transparent; color: var(--text-secondary); }
  .tbl th.s:hover { color: var(--text-muted); }
  .link { display: inline-block; padding: 12px 0; margin: -12px 0; }   /* zone de toucher élargie, position inchangée */
  .link:hover { border-bottom-color: transparent; }
}
