/* Palette roles from the validated data-viz reference instance.
   Light values on bare :root; dark redefined under BOTH the OS media query and
   the explicit [data-theme] scope, so the toggle wins in both directions. */
:root {
  color-scheme: light;
  --surface-1:      #fcfcfb;   /* chart surface */
  --page:           #f9f9f7;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11, 11, 11, 0.10);
  --good:           #006300;

  --series-pv:          #2a78d6;  /* slot 1 blue    — PV production      */
  --series-consumption: #eb6834;  /* slot 2 orange  — total consumption  */
  --series-self:        #1baf7a;  /* slot 3 aqua    — self-consumption   */
  --series-feedin:      #eda100;  /* slot 4 yellow  — grid feed-in       */
  --series-import:      #4a3aa7;  /* slot 7 violet  — grid import        */
  --series-charge:      #008300;  /* slot 6 green   — battery charge     */
  --series-discharge:   #e87ba4;  /* slot 5 magenta — battery discharge  */
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1:      #1a1a19;
    --page:           #0d0d0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255, 255, 255, 0.10);
    --good:           #0ca30c;

    --series-pv:          #3987e5;
    --series-consumption: #d95926;
    --series-self:        #199e70;
    --series-feedin:      #c98500;
    --series-import:      #9085e9;
    --series-charge:      #008300;
    --series-discharge:   #d55181;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1:      #1a1a19;
  --page:           #0d0d0d;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --gridline:       #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(255, 255, 255, 0.10);
  --good:           #0ca30c;

  --series-pv:          #3987e5;
  --series-consumption: #d95926;
  --series-self:        #199e70;
  --series-feedin:      #c98500;
  --series-import:      #9085e9;
  --series-charge:      #008300;
  --series-discharge:   #d55181;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

.wrap { max-width: 1240px; margin: 0 auto; padding: 24px 20px 64px; }

/* ---------- header ---------- */
header.top {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 20px;
}
header.top h1 { font-size: 20px; font-weight: 600; margin: 0; }
header.top .sub { color: var(--text-secondary); font-size: 13px; }
.head-actions { display: flex; gap: 8px; align-items: center; }

/* ---------- controls: ONE filter row above everything it scopes ---------- */
.filters {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 20px;
}
.filters .spacer { flex: 1 1 auto; }
.filters label { color: var(--text-secondary); font-size: 13px; }

button, select, input[type="date"], input[type="password"] {
  font: inherit; font-size: 13px; color: var(--text-primary);
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; min-height: 34px;
}
button { cursor: pointer; }
button:hover { border-color: var(--baseline); }
button.primary {
  background: var(--series-pv); border-color: var(--series-pv); color: #fff;
}

/* ---------- figures ---------- */
.tiles {
  display: grid; gap: 12px; margin-bottom: 20px;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}
.tile {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 16px;
}
.tile .label { color: var(--text-secondary); font-size: 13px; }
.tile .value {
  font-size: 26px; font-weight: 600; margin-top: 2px;
  letter-spacing: -0.01em;              /* proportional figures, not tabular */
}
.tile .unit { font-size: 14px; font-weight: 400; color: var(--text-secondary); }

.hero { grid-column: span 2; }
.hero .value { font-size: 48px; line-height: 1.1; }
@media (max-width: 560px) { .hero { grid-column: span 1; } .hero .value { font-size: 36px; } }

/* ---------- charts ---------- */
.grid2 { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 16px 8px; margin-bottom: 16px;
}
.card h2 { font-size: 15px; font-weight: 600; margin: 0; }
.card .hint { color: var(--text-secondary); font-size: 12.5px; margin: 2px 0 6px; }
/* height includes the x-axis band so the card never gets a nested scrollbar */
.plot { width: 100%; height: 300px; }
.plot.tall { height: 340px; }

.card-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
}
.card-head .expand {
  flex: 0 0 auto; padding: 3px 9px; min-height: 0; font-size: 12px;
  color: var(--text-secondary);
}
.card-head .expand:hover { color: var(--text-primary); }

/* ---------- one chart, full browser viewport ----------
   A CSS overlay, not the native Fullscreen API: the card fills the browser
   window and the browser chrome stays where it is. */
.card.maximized {
  position: fixed; inset: 0; z-index: 50;
  margin: 0; border: 0; border-radius: 0;
  padding: 16px 20px 14px;
  display: flex; flex-direction: column;
  background: var(--surface-1);
}
.card.maximized .card-head { flex: 0 0 auto; }
.card.maximized h2 { font-size: 17px; }
.card.maximized .hint { flex: 0 0 auto; max-width: 90ch; }
/* the plot takes whatever the header leaves; min-height:0 lets it shrink */
.card.maximized .plot { flex: 1 1 auto; height: auto; min-height: 0; }
body.fs-lock { overflow: hidden; }

.stale { opacity: 0.45; transition: opacity 120ms ease; }   /* no skeleton flash */

/* ---------- table view (the relief channel + a11y twin) ---------- */
.tablewrap { overflow-x: auto; margin-top: 8px; }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; }
table.data th, table.data td {
  padding: 5px 10px; text-align: right; white-space: nowrap;
  border-bottom: 1px solid var(--gridline);
}
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data thead th {
  position: sticky; top: 0; background: var(--surface-1);
  color: var(--text-secondary); font-weight: 600;
}
table.data td { font-variant-numeric: tabular-nums; color: var(--text-primary); }
.swatch {
  display: inline-block; width: 10px; height: 10px; border-radius: 2px;
  margin-right: 6px; vertical-align: -1px;
}
.tablewrap { max-height: 460px; overflow-y: auto; }

/* ---------- login ---------- */
.login {
  max-width: 340px; margin: 14vh auto; background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 12px; padding: 24px;
}
.login h1 { font-size: 17px; margin: 0 0 4px; }
.login p { color: var(--text-secondary); font-size: 13px; margin: 0 0 16px; }
.login input { width: 100%; margin-bottom: 12px; }
.login button { width: 100%; }

.error {
  color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--border); border-left: 3px solid #d03b3b;
  border-radius: 8px; padding: 10px 12px; margin-bottom: 16px; font-size: 13.5px;
}
.note { color: var(--text-secondary); font-size: 12.5px; margin-top: 10px; }
[hidden] { display: none !important; }
