/* =========================================================
   Tokens — industrial control-room dark theme
   ========================================================= */

:root {
  /* Surfaces (cool-neutral near-black) */
  --bg-0: oklch(0.14 0.008 240);   /* page / deepest */
  --bg-1: oklch(0.175 0.008 240);  /* panel */
  --bg-2: oklch(0.21 0.008 240);   /* panel raised */
  --bg-3: oklch(0.255 0.008 240);  /* hover / inset row */

  /* Hairlines & dividers */
  --line: oklch(0.30 0.008 240);
  --line-strong: oklch(0.38 0.008 240);
  --line-soft: oklch(0.24 0.008 240);

  /* Text — bumped for WCAG AA on bg-1 (L=0.175) */
  --fg-0: oklch(0.98 0.003 240);   /* ~15:1 */
  --fg-1: oklch(0.90 0.005 240);   /* ~11:1 — body */
  --fg-2: oklch(0.76 0.007 240);   /* ~7:1  — secondary */
  --fg-3: oklch(0.62 0.008 240);   /* ~4.8:1 — tertiary, meets AA normal */

  /* Semantic channels (strict) — lightened for AA contrast */
  --solar: oklch(0.85 0.15 78);     /* amber — generation */
  --solar-dim: oklch(0.85 0.15 78 / 0.18);
  --battery: oklch(0.82 0.11 180);  /* teal — battery / healthy */
  --battery-dim: oklch(0.82 0.11 180 / 0.18);
  --load: oklch(0.76 0.17 25);      /* coral — consumption / alert */
  --load-dim: oklch(0.76 0.17 25 / 0.18);
  --grid: oklch(0.78 0.13 245);     /* blue — grid */
  --grid-dim: oklch(0.78 0.13 245 / 0.18);

  /* State */
  --ok:    oklch(0.82 0.13 155);
  --warn:  oklch(0.88 0.15 90);
  --err:   oklch(0.74 0.20 28);
  --info:  oklch(0.78 0.13 245);

  /* Type */
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  /* Density (overridden by [data-density]) */
  --pad-panel: 18px;
  --pad-tight: 12px;
  --row-h: 34px;
  --gap: 14px;
  --radius: 4px;

  /* Motion */
  --ease: cubic-bezier(.4,.0,.2,1);
}

[data-density="compact"] {
  --pad-panel: 12px;
  --pad-tight: 8px;
  --row-h: 28px;
  --gap: 10px;
}

/* Base reset */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg-0);
  color: var(--fg-1);
  font-family: var(--font-sans);
  font-size: 13px;
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  height: 100vh;
}

/* Tabular numerics default for mono */
.mono, code {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum", "zero";
  letter-spacing: -0.01em;
}

/* Panels */
.panel {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  position: relative;
}
.panel-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px var(--pad-panel);
  border-bottom: 1px solid var(--line-soft);
  min-height: 38px;
}
.panel-hd h3 {
  margin: 0;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--fg-2);
  font-family: var(--font-sans);
}
.panel-bd { padding: var(--pad-panel); }
.panel-bd.flush { padding: 0; }

/* Semantic color classes */
.c-solar   { color: var(--solar);   }
.c-battery { color: var(--battery); }
.c-load    { color: var(--load);    }
.c-grid    { color: var(--grid);    }
.c-ok      { color: var(--ok);      }
.c-warn    { color: var(--warn);    }
.c-err     { color: var(--err);     }
.c-fg-2    { color: var(--fg-2);    }

/* Numeric readout */
.readout {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  letter-spacing: -0.02em;
}
.readout-xl { font-size: 30px; font-weight: 500; line-height: 1; }
.readout-lg { font-size: 24px; font-weight: 500; line-height: 1; }
.readout-md { font-size: 18px; font-weight: 500; line-height: 1; }
.readout-sm { font-size: 13px; font-weight: 500; line-height: 1; }

.unit { color: var(--fg-3); font-size: 0.55em; margin-left: 4px; font-weight: 400; letter-spacing: 0.05em; }

/* Label caps */
.lbl {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-3);
}

/* Pill / chip */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--bg-2);
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--fg-1);
  letter-spacing: 0.02em;
}
.chip .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
}
.chip-ok  { color: var(--ok); }
.chip-warn{ color: var(--warn); }
.chip-err { color: var(--err); }
.chip-info{ color: var(--info); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 28px;
  padding: 0 12px;
  background: var(--bg-2);
  color: var(--fg-1);
  border: 1px solid var(--line);
  border-radius: 3px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: background 120ms var(--ease), border-color 120ms var(--ease);
}
.btn:hover { background: var(--bg-3); border-color: var(--line-strong); }
.btn.active { background: var(--bg-3); border-color: var(--fg-3); color: var(--fg-0); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--fg-2); }
.btn-ghost:hover { color: var(--fg-0); background: var(--bg-2); }

.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow: hidden;
  background: var(--bg-1);
}
.seg button {
  background: transparent;
  color: var(--fg-2);
  border: none;
  border-right: 1px solid var(--line);
  padding: 0 10px;
  height: 26px;
  font: inherit;
  font-size: 11px;
  font-family: var(--font-mono);
  cursor: pointer;
  letter-spacing: 0.02em;
}
.seg button:last-child { border-right: none; }
.seg button:hover { color: var(--fg-0); background: var(--bg-2); }
.seg button.active { color: var(--fg-0); background: var(--bg-3); }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 4px; border: 2px solid var(--bg-0); }
::-webkit-scrollbar-thumb:hover { background: var(--line-strong); }

/* Overview responsive grid — 6 cols so half-row = span 3, third-row = span 2 */
.overview-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px;
}
.overview-grid .ov-span-2 { grid-column: span 2; }
.overview-grid .ov-span-3 { grid-column: span 3; }
.overview-grid .ov-span-6 { grid-column: 1 / -1; }
@media (max-width: 1500px) {
  .overview-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .overview-grid .ov-span-3 { grid-column: span 2; }
  .overview-grid .ov-span-2 { grid-column: span 2; }
}
@media (max-width: 1100px) {
  .overview-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .overview-grid .ov-span-3,
  .overview-grid .ov-span-2 { grid-column: 1 / -1; }
}
@media (max-width: 700px) {
  .overview-grid { grid-template-columns: 1fr; }
}

/* KPI grid — responsive wrapping tiles */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
}
@media (max-width: 1500px) {
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Topbar responsive hiding */
@media (max-width: 1400px) {
  .topbar-hide-sm { display: none !important; }
}
@media (max-width: 1150px) {
  .topbar-hide-md { display: none !important; }
}

/* Grid helpers */
.grid { display: grid; gap: var(--gap); }
.row  { display: flex; gap: var(--gap); }

/* Corner marks (control-room detail) */
.panel-corner::before,
.panel-corner::after {
  content: ""; position: absolute; width: 7px; height: 7px;
  border-color: var(--line-strong); border-style: solid;
}
.panel-corner::before { top: -1px; left: -1px; border-width: 1px 0 0 1px; }
.panel-corner::after  { top: -1px; right: -1px; border-width: 1px 1px 0 0; }

/* Sparkline/grid ticks */
.gridline { stroke: var(--line-soft); stroke-width: 1; }
.axis-text { fill: var(--fg-3); font-family: var(--font-mono); font-size: 9.5px; letter-spacing: 0.04em; }

/* Live tick pulse */
@keyframes pulse-live {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}
.live-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ok);
  animation: pulse-live 1.6s var(--ease) infinite;
}

/* Sr-only */
.sr { position: absolute; left: -9999px; }

/* Utility */
.divider-v { width: 1px; align-self: stretch; background: var(--line-soft); }
.hline { height: 1px; background: var(--line-soft); }
.spacer { flex: 1; }
