:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;
  --series-1-wash: rgba(42, 120, 214, 0.10);
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --reference: #898781;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --seq-1: #cde2fb; --seq-2: #9ec5f4; --seq-3: #6da7ec; --seq-4: #3987e5; --seq-5: #256abf; --seq-6: #184f95;
  --focus: #2a78d6;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 1px 0 rgba(11, 11, 11, 0.02);
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
    --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5; --series-1-wash: rgba(57, 135, 229, 0.12); --series-2: #d95926; --series-3: #199e70;
    --good-text: #0ca30c;
    --seq-1: #184f95; --seq-2: #1c5cab; --seq-3: #256abf; --seq-4: #2a78d6; --seq-5: #5598e7; --seq-6: #86b6ef;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
  --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5; --series-1-wash: rgba(57, 135, 229, 0.12); --series-2: #d95926; --series-3: #199e70;
  --good-text: #0ca30c;
  --seq-1: #184f95; --seq-2: #1c5cab; --seq-3: #256abf; --seq-4: #2a78d6; --seq-5: #5598e7; --seq-6: #86b6ef;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 15px; }

/* ---------- barre du haut ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 10px 24px;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; }
.brand svg { width: 22px; height: 22px; color: var(--warning); }
.tabs { display: flex; gap: 4px; flex: 1; }
.tab {
  border: 0; background: none; padding: 7px 12px; border-radius: 8px;
  color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px;
}
.tab:hover { background: var(--surface-2); }
.tab[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--border); }
.badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--critical); color: #fff; font-size: 12px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
}
.user { display: flex; align-items: center; gap: 12px; color: var(--ink-2); font-size: 14px; }
.btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
  padding: 6px 12px; color: var(--ink);
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--series-1); border-color: transparent; color: #fff; }
.btn.small { padding: 3px 9px; font-size: 13px; }
.demo-banner {
  background: var(--surface-2); color: var(--ink-2); text-align: center;
  font-size: 13px; padding: 6px; border-bottom: 1px solid var(--border);
}

/* ---------- mise en page ---------- */
main { max-width: 1240px; margin: 0 auto; padding: 24px; display: grid; gap: 16px; }
.view { display: grid; gap: 16px; min-width: 0; }
.inverter .status { white-space: normal; align-items: flex-start; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); min-width: 0;
}
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin-right: auto; }
.card-sub { color: var(--muted); font-size: 13px; }
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }

.sys-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.sys-title { display: flex; flex-direction: column; gap: 4px; }
.sys-meta { color: var(--ink-2); font-size: 14px; display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }
.sys-select { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 4px 8px; }
.day-nav { display: flex; gap: 6px; align-items: center; }
.day-nav input { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 5px 8px; }

/* ---------- chiffres ---------- */
.kpis { display: grid; grid-template-columns: minmax(260px, 1.2fr) repeat(4, 1fr); gap: 16px; }
.hero .label, .tile .label { color: var(--ink-2); font-size: 13px; }
.hero-value { font-size: 52px; font-weight: 600; line-height: 1.05; letter-spacing: -0.02em; margin: 6px 0 4px; }
.hero-value .unit, .tile .unit { font-size: 0.45em; color: var(--ink-2); font-weight: 500; margin-left: 4px; }
.hero-sub { color: var(--ink-2); font-size: 14px; }
.tile .value { font-size: 26px; font-weight: 600; margin-top: 6px; letter-spacing: -0.01em; }
.tile .unit { font-size: 14px; }
.tile .foot { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---------- statut ---------- */
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; white-space: nowrap; }
.status .ico {
  width: 18px; height: 18px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 11px; font-weight: 700; flex: none;
}
.status.good .ico { background: var(--good); }
.status.warning .ico { background: var(--warning); color: #0b0b0b; }
.status.serious .ico { background: var(--serious); }
.status.critical .ico { background: var(--critical); }
.status.unknown .ico { background: var(--muted); }

/* ---------- alertes ---------- */
.alert-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.alert-item {
  display: grid; grid-template-columns: auto 1fr auto; gap: 4px 14px; align-items: start;
  padding: 12px 14px; border-radius: 10px; background: var(--surface-2);
  border-left: 4px solid var(--muted);
}
.alert-item.critical { border-left-color: var(--critical); }
.alert-item.serious { border-left-color: var(--serious); }
.alert-item.warning { border-left-color: var(--warning); }
.alert-item.resolved { opacity: 0.72; border-left-color: var(--good); }
.alert-item .title { font-weight: 600; }
.alert-item .meta { color: var(--ink-2); font-size: 13px; }
.alert-item .detail { grid-column: 2 / 4; color: var(--ink-2); font-size: 14px; }
.alert-item .actions { display: flex; gap: 6px; align-items: center; }
.empty { color: var(--muted); font-size: 14px; padding: 6px 0; }
.ok-line { display: flex; align-items: center; gap: 10px; }

/* ---------- graphiques ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.gridline { stroke: var(--grid); stroke-width: 1; }
.baseline { stroke: var(--axis); stroke-width: 1; }
.tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.area { fill: var(--series-1-wash); }
.line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.line.ref { stroke: var(--reference); }
.bar { fill: var(--series-1); }
.bar.muted { fill: var(--seq-2); }
.bar.active { fill: var(--seq-5); }
.crosshair { stroke: var(--axis); stroke-width: 1; }
.dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.dot.ref { fill: var(--reference); }
.hit { fill: transparent; }
.end-label { fill: var(--ink-2); font-size: 12px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; font-size: 13px; color: var(--ink-2); }
.key { display: inline-flex; align-items: center; gap: 6px; }
.key .sw { width: 14px; height: 3px; border-radius: 2px; background: var(--series-1); }
.key .sw.ref { background: var(--reference); }
.key .sq { width: 12px; height: 12px; border-radius: 3px; }

#tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 13px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  max-width: 280px;
}
#tooltip .tt-title { font-weight: 600; margin-bottom: 2px; }
#tooltip .tt-row { display: flex; justify-content: space-between; gap: 14px; color: var(--ink-2); }
#tooltip .tt-row b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- panneaux ---------- */
.inverters { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.inverter { border: 1px solid var(--border); border-radius: 10px; padding: 8px; background: var(--surface-2); }
.inverter-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--ink-2); margin-bottom: 6px; gap: 6px; }
.inverter-head .uid { font-variant-numeric: tabular-nums; }
.panel-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 2px; }
.panel-row.ch4 { grid-template-columns: repeat(2, 1fr); }
.panel {
  position: relative; border: 0; border-radius: 6px; height: 64px; padding: 6px;
  display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start;
  text-align: left; color: #fff; font-size: 12px;
}
.panel .kwh { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.panel .ch { opacity: 0.85; }
.panel.s1 { background: var(--seq-1); } .panel.s2 { background: var(--seq-2); } .panel.s3 { background: var(--seq-3); }
.panel.s4 { background: var(--seq-4); } .panel.s5 { background: var(--seq-5); } .panel.s6 { background: var(--seq-6); }
.panel.s0 { background: var(--surface); color: var(--ink-2); box-shadow: inset 0 0 0 1px var(--border); }
.panel.s1, .panel.s2, .panel.s3 { color: #0b0b0b; }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .panel.s1, :root:where(:not([data-theme="light"])) .panel.s2,
  :root:where(:not([data-theme="light"])) .panel.s3 { color: #fff; }
  :root:where(:not([data-theme="light"])) .panel.s6 { color: #0b0b0b; }
}
:root[data-theme="dark"] .panel.s1, :root[data-theme="dark"] .panel.s2, :root[data-theme="dark"] .panel.s3 { color: #fff; }
:root[data-theme="dark"] .panel.s6 { color: #0b0b0b; }
.panel.fault { box-shadow: inset 0 0 0 3px var(--critical); }
.panel.fault.under { box-shadow: inset 0 0 0 3px var(--warning); }
.panel .flag {
  position: absolute; top: 5px; right: 5px; width: 18px; height: 18px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700;
  background: var(--critical); color: #fff;
}
.panel.under .flag { background: var(--warning); color: #0b0b0b; }
.panel[aria-pressed="true"] { outline: 2px solid var(--ink); outline-offset: 1px; }
.panel-detail { margin-top: 16px; border-top: 1px solid var(--grid); padding-top: 14px; }
.panel-detail .card-head { margin-bottom: 6px; }
.seq-scale { display: inline-flex; gap: 2px; align-items: center; }
.seq-scale span { width: 14px; height: 10px; border-radius: 2px; }
.seq-scale .s1 { background: var(--seq-1); } .seq-scale .s2 { background: var(--seq-2); } .seq-scale .s3 { background: var(--seq-3); }
.seq-scale .s4 { background: var(--seq-4); } .seq-scale .s5 { background: var(--seq-5); } .seq-scale .s6 { background: var(--seq-6); }

/* ---------- tableaux ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 6px 10px; border-bottom: 1px solid var(--grid); }
td { padding: 9px 10px; border-bottom: 1px solid var(--grid); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

/* ---------- pied ---------- */
.statusbar {
  max-width: 1240px; margin: 0 auto; padding: 0 24px 32px;
  display: flex; gap: 24px; align-items: center; flex-wrap: wrap; color: var(--ink-2); font-size: 13px;
}
.meter { display: inline-flex; align-items: center; gap: 8px; }
.meter .track { width: 120px; height: 8px; border-radius: 4px; background: var(--seq-1); overflow: hidden; }
.meter .fill { height: 100%; border-radius: 4px; background: var(--series-1); }
.meter .fill.warn { background: var(--warning); }
.meter .fill.crit { background: var(--critical); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 5px 12px; color: var(--ink-2); }
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--ink); font-weight: 500; }

/* ---------- connexion ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; }
.login-card h1 { margin: 10px 0 18px; }
.field { display: grid; gap: 4px; margin-bottom: 12px; font-size: 14px; color: var(--ink-2); }
.field input { border: 1px solid var(--border); background: var(--page); border-radius: 8px; padding: 9px 10px; color: var(--ink); }
.login-card .btn { width: 100%; padding: 10px; }
.error { color: var(--critical); font-size: 14px; min-height: 20px; margin-bottom: 8px; }

@media (max-width: 960px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpis .hero { grid-column: 1 / -1; }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  main { padding: 16px; }
  .topbar { padding: 10px 16px; gap: 10px; flex-wrap: wrap; }
  .user .who { display: none; }
  .hero-value { font-size: 44px; }
  .statusbar { padding: 0 16px 24px; }
  .alert-item { grid-template-columns: 1fr auto; }
  .alert-item > .status { grid-column: 1 / -1; }
  .alert-item .detail { grid-column: 1 / -1; }
}

/* ---------- bilan énergétique ---------- */
.line.s2 { stroke: var(--series-2); }
.dot.s2 { fill: var(--series-2); }
.key .sw.s2 { background: var(--series-2); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 18px; }
.stat .label { color: var(--ink-2); font-size: 13px; }
.stat .value { font-size: 24px; font-weight: 600; margin-top: 4px; }
.stat .unit { font-size: 13px; color: var(--ink-2); font-weight: 500; margin-left: 4px; }
.stat .foot { color: var(--muted); font-size: 12px; margin-top: 2px; }
.seg-wrap { margin-bottom: 14px; }
.seg-label { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); margin-bottom: 6px; }
.segbar { display: flex; gap: 2px; height: 28px; }
.seg-block { min-width: 4px; flex-basis: 0; border-radius: 4px; display: flex; align-items: center; padding: 0 8px; color: #fff; font-size: 12px; font-weight: 600; white-space: nowrap; }
.c-self { background: var(--series-1); }
.c-export { background: var(--series-3); }
.c-import { background: var(--series-2); }
.key .sq.c-self { background: var(--series-1); } .key .sq.c-export { background: var(--series-3); } .key .sq.c-import { background: var(--series-2); }
.energy-chart-head { margin-top: 10px; }
.energy-chart-head h2 { font-size: 14px; }
.chart-note { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); margin: 0 0 8px; }
.panel.unused { background: transparent; color: var(--muted); border: 1px dashed var(--axis); }
.panel.unused .kwh { font-size: 12px; font-weight: 500; }
@media (max-width: 960px) { .stats { grid-template-columns: 1fr 1fr; } }
