/* ============================================================
   EllioCurl 2 — thème & mise en page
   Tokens issus de la palette de référence validée (light + dark)
   ============================================================ */
: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: #2a78d6;
  --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: #3987e5;
  --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);
}

/* ---------------- 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(--seq-400), var(--seq-600));
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px;
}
.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); }

/* ---------------- spécifique ---------------- */
.alarm-strip {
  display: flex; align-items: center; gap: 10px;
  background: color-mix(in srgb, var(--status-critical) 12%, var(--surface-1));
  border: 1px solid color-mix(in srgb, var(--status-critical) 40%, transparent);
  border-radius: 12px; padding: 10px 16px; margin-bottom: 14px;
}
.cascade { display: flex; flex-direction: column; gap: 8px; }
.cascade .step {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px;
  color: var(--text-secondary); background: var(--surface-1);
}
.cascade .step .n {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 700; font-size: 12.5px;
  background: var(--surface-2); color: var(--text-muted);
}
.cascade .step.active { border-color: var(--accent); color: var(--text-primary); }
.cascade .step.active .n { background: var(--accent); color: #fff; }
.cascade .step.saturated { border-color: var(--status-warning); }
.cascade .step.saturated .n { background: var(--status-warning); color: #0b0b0b; }
.cascade .arrow { text-align: center; color: var(--text-muted); font-size: 11px; margin: -3px 0; }

.param-row { display: grid; grid-template-columns: 1.4fr repeat(4, 1fr); gap: 8px; align-items: center; padding: 9px 4px; border-bottom: 1px solid var(--grid); font-size: 13px; }
.param-row.head { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); font-weight: 600; border-bottom: 1px solid var(--axis); }
.param-row .pname { font-weight: 550; }
.param-row .pname small { display: block; color: var(--text-muted); font-weight: 400; }
.param-row .num { font-variant-numeric: tabular-nums; }
.param-row input { width: 84px; padding: 5px 9px; }

.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; }

/* ---------------- Conduite & changement de qualité ---------------- */
.cd-head, .cd-card { padding: 10px 16px 12px; }
.cd-card h3 { margin-bottom: 6px; }
.cd-flow { display: grid; grid-template-columns: auto 1fr auto 1fr 1.2fr; gap: 14px; align-items: center; }
.cd-gauges { display: flex; gap: 8px; align-items: flex-start; }
.cd-gauge { width: 158px; }
.cd-glab { font-size: 10px; color: var(--text-muted); text-align: center; line-height: 1.3; margin-top: 1px; }
.cd-of { display: flex; flex-direction: column; gap: 1px; padding: 7px 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.cd-of.next { border-color: color-mix(in srgb, var(--accent) 45%, transparent); background: color-mix(in srgb, var(--accent) 8%, var(--surface-1)); }
.cd-tag { font-size: 10.5px; text-transform: uppercase; letter-spacing: .6px; font-weight: 700; color: var(--text-muted); }
.cd-tag.accent { color: var(--accent); }
.cd-q { font-size: 21px; font-weight: 700; letter-spacing: .3px; line-height: 1.1; }
.cd-qsel { font-size: 17px; font-weight: 700; padding: 2px 8px; margin: 1px 0; background: var(--surface-1); }
.cd-transition { display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--accent); }
.cd-arrow { font-size: 30px; font-weight: 700; line-height: 1; }
.cd-conf { display: flex; flex-direction: column; gap: 4px; justify-content: center; }
.cd-conf-row { display: flex; align-items: center; gap: 9px; font-size: 12px; }
.cd-conf-row .conf-bar { max-width: 150px; }
.cd-conf-row b { font-variant-numeric: tabular-nums; margin-left: auto; }
@media (max-width: 1000px) { .cd-flow { grid-template-columns: 1fr; } .cd-transition { flex-direction: row; } .cd-arrow { transform: rotate(90deg); } .cd-gauges { justify-content: center; } }

.cd-legend { font-size: 11.5px; color: var(--text-muted); display: inline-flex; align-items: center; gap: 6px; }
.cd-table { display: flex; flex-direction: column; }
.cd-row {
  display: grid; grid-template-columns: 1.7fr 1.2fr 1.2fr 1.4fr;
  gap: 12px; align-items: center; padding: 4px 6px; border-bottom: 1px solid var(--grid);
}
.cd-hrow { font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); font-weight: 700; border-bottom: 1px solid var(--axis); padding-bottom: 4px; }
.cd-hrow .cd-col-meas { color: var(--accent); }
.cd-group {
  grid-column: 1 / -1; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .7px;
  color: var(--text-secondary); background: var(--surface-2); padding: 2px 10px; border-radius: 6px;
  margin: 4px 0 0; border: none;
}
.cd-var { font-weight: 550; font-size: 13px; }
.cd-var small { color: var(--text-muted); font-weight: 400; font-size: 11px; margin-left: 5px; }
.cd-cell { display: flex; flex-direction: row; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.cd-c-meas { align-items: stretch; }
.cd-c-now { padding-left: 12px; border-left: 2px solid color-mix(in srgb, var(--accent) 30%, transparent); }
.cd-val { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.cd-val.big { font-size: 17px; font-weight: 700; }
.cd-in { width: 92px; font-variant-numeric: tabular-nums; }

.cd-src { font-size: 10px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); font-weight: 600; }
.cd-src.ov { color: var(--series-3); }
.cd-src.der { color: var(--text-muted); }
.cd-chg { font-size: 11.5px; font-weight: 700; font-variant-numeric: tabular-nums; }
.cd-chg.up { color: var(--status-serious); }
.cd-chg.down { color: var(--series-1); }
.cd-chg.none { color: var(--text-muted); font-weight: 500; }

.cd-meas { width: 100%; display: flex; flex-direction: column; gap: 2px; padding: 3px 10px 5px; border-radius: 9px; border: 1px solid transparent; }
.cd-meas-top { display: flex; align-items: center; gap: 7px; }
.cd-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-muted); flex: none; }
.cd-dot.ok, .cd-meas.ok .cd-dot { background: var(--status-good); }
.cd-dot.warn, .cd-meas.warn .cd-dot { background: var(--status-warning); }
.cd-dot.crit, .cd-meas.crit .cd-dot { background: var(--status-critical); }
.cd-act { font-size: 11px; font-weight: 700; margin-left: auto; }
.cd-dev { font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.cd-track { height: 5px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.cd-track i { display: block; height: 100%; border-radius: 99px; background: var(--status-good); transition: width .5s ease; }

.cd-meas.warn { background: color-mix(in srgb, var(--status-warning) 12%, transparent); border-color: color-mix(in srgb, var(--status-warning) 40%, transparent); animation: cd-pulse-warn 1.5s ease-in-out infinite; }
.cd-meas.warn .cd-track i { background: var(--status-warning); }
.cd-meas.warn .cd-act { color: color-mix(in srgb, var(--status-warning) 70%, var(--text-primary)); }
.cd-meas.crit { background: color-mix(in srgb, var(--status-critical) 14%, transparent); border-color: color-mix(in srgb, var(--status-critical) 55%, transparent); animation: cd-pulse-crit 1s ease-in-out infinite; }
.cd-meas.crit .cd-track i { background: var(--status-critical); }
.cd-meas.crit .cd-val { color: var(--status-critical); }
.cd-meas.crit .cd-act { color: var(--status-critical); }
.cd-meas.crit .cd-dot { animation: cd-blink .6s steps(1) infinite; }
@keyframes cd-pulse-warn { 0%,100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--status-warning) 0%, transparent); } 50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--status-warning) 22%, transparent); } }
@keyframes cd-pulse-crit { 0%,100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--status-critical) 0%, transparent); } 50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--status-critical) 28%, transparent); } }
@keyframes cd-blink { 0%,49% { opacity: 1; } 50%,100% { opacity: .25; } }
@media (max-width: 800px) {
  .cd-row { grid-template-columns: 1fr; gap: 4px; }
  .cd-c-now { border-left: none; padding-left: 0; }
  .cd-hrow { display: none; }
}

.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; }
