/* ==========================================================================
   GridPulse ZA — stylesheet
   Theme tokens follow the light/dark pattern: media query for the OS
   setting, [data-theme] override for the in-page toggle (toggle wins).
   Series colors are the validated GridPulse palette (see README).
   ========================================================================== */

:root {
  color-scheme: light;
  --page:        #f9f9f7;
  --surface:     #fcfcfb;
  --ink:         #0b0b0b;
  --ink-2:       #52514e;
  --muted:       #898781;
  --grid:        #e1e0d9;
  --baseline:    #c3c2b7;
  --border:      rgba(11, 11, 11, 0.10);
  --accent:      #6929c4;
  --accent-ink:  #ffffff;
  --brand-ink:   #1d4ed8;
  --brand-purple:#6929c4;
  --wash:        rgba(105, 41, 196, 0.08);

  --s-nuclear:   #4a3aa7;
  --s-coal:      #92551a;
  --s-gas:       #eb6834;
  --s-ocgt:      #c22a48;
  --s-hydro:     #2a78d6;
  --s-ps:        #1baf7a;
  --s-wind:      #56a3f0;
  --s-pv:        #eda100;
  --s-csp:       #d55181;
  --s-other_re:  #008300;
  --s-imports:   #5b7ce2;
  --s-pump:      #0c7d5c;
  --s-exports:   #3b55b5;

  --st-good:     #0ca30c;
  --st-warning:  #fab219;
  --st-serious:  #ec835a;
  --st-critical: #d03b3b;
  --st-good-text: #006300;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:      #0d0d0d;
    --surface:   #1a1a19;
    --ink:       #ffffff;
    --ink-2:     #c3c2b7;
    --muted:     #898781;
    --grid:      #2c2c2a;
    --baseline:  #383835;
    --border:    rgba(255, 255, 255, 0.10);
    --accent:    #9f7ae8;
    --accent-ink:#160a2e;
    --brand-ink: #82a6ff;
    --brand-purple:#9f7ae8;
    --wash:      rgba(159, 122, 232, 0.14);

    --s-nuclear: #9085e9;
    --s-coal:    #92551a;
    --s-gas:     #e86933;
    --s-ocgt:    #b8305e;
    --s-hydro:   #2f7fd9;
    --s-ps:      #199e70;
    --s-wind:    #4396e2;
    --s-pv:      #c98500;
    --s-csp:     #d55181;
    --s-other_re:#008300;
    --s-imports: #6e85e5;
    --s-pump:    #17936a;
    --s-exports: #6c82e0;
    --st-good-text: #0ca30c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:      #0d0d0d;
  --surface:   #1a1a19;
  --ink:       #ffffff;
  --ink-2:     #c3c2b7;
  --muted:     #898781;
  --grid:      #2c2c2a;
  --baseline:  #383835;
  --border:    rgba(255, 255, 255, 0.10);
  --accent:    #9f7ae8;
  --accent-ink:#160a2e;
  --brand-ink: #82a6ff;
  --brand-purple:#9f7ae8;
  --wash:      rgba(159, 122, 232, 0.14);

  --s-nuclear: #9085e9;
  --s-coal:    #92551a;
  --s-gas:     #e86933;
  --s-ocgt:    #b8305e;
  --s-hydro:   #2f7fd9;
  --s-ps:      #199e70;
  --s-wind:    #4396e2;
  --s-pv:      #c98500;
  --s-csp:     #d55181;
  --s-other_re:#008300;
  --s-imports: #6e85e5;
  --s-pump:    #17936a;
  --s-exports: #6c82e0;
  --st-good-text: #0ca30c;
}

/* ------------------------------------------------------------------ base */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}
h1, h2, h3, .brand-name, .hero-figure, .tile-value {
  font-family: "Space Grotesk", "IBM Plex Sans", system-ui, sans-serif;
}
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; }
h1 { font-size: 24px; margin: 0; }
h2 { font-size: 19px; margin: 0; }
h3 { font-size: 15.5px; margin: 0 0 6px; display: flex; align-items: center; gap: 8px; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ------------------------------------------------------------------ header */
.site-head {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}
.head-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding-top: 10px; padding-bottom: 10px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 58px; height: 31px; flex: none; display: block;
  color: var(--brand-purple); }
.brand-name { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: 0.1px;
  color: var(--brand-ink); }
.brand-name .bp { color: var(--brand-purple); }
.brand-tag { margin: 0; font-size: 12.5px; color: var(--ink-2); }
.head-tools { display: flex; align-items: center; gap: 12px; }
.data-stamp { margin: 0; font-size: 12.5px; color: var(--muted); text-align: right; }
.theme-btn {
  width: 34px; height: 34px; border-radius: 9px;
  border: 1px solid var(--border); background: transparent;
  cursor: pointer; font-size: 16px; line-height: 1;
}
.theme-btn:hover { background: var(--wash); }

/* ------------------------------------------------------------------ layout */
main { padding-bottom: 40px; }
section { margin-top: 28px; }
.section-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.section-sub { margin: 0; color: var(--muted); font-size: 13px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
}

/* ------------------------------------------------------------------ hero */
.hero { margin-top: 18px; }
.hero .section-head { margin-bottom: 8px; }
.stale-note {
  margin: 0 0 10px; font-size: 12.5px; color: var(--ink-2);
  border-left: 3px solid var(--st-warning); padding: 5px 0 5px 10px;
}
.stale-note[hidden] { display: none; }
.hero-grid {
  display: flex; gap: 10px; align-items: stretch;
  overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin;
}
.hero .card { padding: 10px 14px; }
.hero-main { display: flex; flex-direction: column; flex: 0 0 260px; }
.tile-label { margin: 0 0 2px; font-size: 11.5px; color: var(--ink-2); }
.hero-figure {
  margin: 1px 0 0; font-weight: 700; font-size: 30px; line-height: 1.05;
  letter-spacing: -0.4px;
}
.hero-unit { font-size: 13px; font-weight: 500; color: var(--ink-2); margin-left: 6px; }
.tile-foot { margin: 3px 0 0; font-size: 11px; color: var(--muted); line-height: 1.35; }
.badge-row { margin-top: auto; padding-top: 6px; display: flex; flex-wrap: wrap; gap: 8px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 600;
  padding: 3px 9px; border-radius: 999px; border: 1px solid var(--border);
}
.badge .dot { font-size: 13px; line-height: 1; }
.badge-good     { color: var(--st-good-text); }
.badge-warning  { color: var(--ink); background: color-mix(in srgb, var(--st-warning) 18%, transparent); }
.badge-serious  { color: var(--ink); background: color-mix(in srgb, var(--st-serious) 20%, transparent); }
.badge-critical { color: var(--ink); background: color-mix(in srgb, var(--st-critical) 20%, transparent); }

.tile-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  flex: 0 0 320px;
}
.tile { padding: 8px 12px; }
.tile-value { margin: 1px 0 0; font-size: 17px; font-weight: 700; line-height: 1.15; }
.tile-unit { font-size: 11px; font-weight: 500; color: var(--ink-2); margin-left: 4px; }

.donut-card {
  display: grid; grid-template-columns: 176px minmax(0, max-content);
  grid-template-rows: auto 1fr; column-gap: 18px;
  justify-content: start;
  flex: 3 1 430px;
}
.donut-card .tile-label { grid-column: 1 / -1; }
.donut-box { min-height: 130px; }
.mini-table { font-size: 11.5px; color: var(--ink-2); align-self: center;
  justify-self: start; }
.mini-table table { width: max-content; border-collapse: collapse; }
.mini-table td { padding: 1.5px 0; }
.mini-table td:last-child { text-align: right; font-variant-numeric: tabular-nums;
  color: var(--ink); padding-left: 14px; }
.key {
  display: inline-block; width: 14px; height: 3px; border-radius: 2px;
  vertical-align: middle; margin-right: 7px;
}

/* ------------------------------------------------------------------ filters */
.filter-row {
  margin-top: 28px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
}
.presets { display: flex; gap: 4px; flex-wrap: wrap; }
.presets button, .range-nav button {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 9px; padding: 6px 12px; cursor: pointer; font-size: 13.5px;
  color: var(--ink-2);
}
.presets button:hover, .range-nav button:hover { background: var(--wash); }
.presets button.active {
  background: var(--accent); border-color: var(--accent);
  color: var(--accent-ink); font-weight: 600;
}
.range-nav { display: flex; align-items: center; gap: 6px; }
.range-nav input[type="date"] {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  border-radius: 9px; padding: 5px 8px; font: inherit; font-size: 13.5px;
}
.gran-chip {
  font-size: 11.5px; color: var(--muted); border: 1px solid var(--border);
  padding: 3px 8px; border-radius: 999px;
}
.range-note {
  margin: 8px 2px 0; font-size: 12.5px; color: var(--ink-2);
  text-align: right;
}
.range-note:empty { display: none; }

/* ------------------------------------------------------------------ charts */
.chart-card { margin-top: 14px; }
.chart-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 14px; flex-wrap: wrap; margin-bottom: 4px;
}
.chart-sub { margin: 3px 0 0; font-size: 12.5px; color: var(--muted); max-width: 640px; }
.chart-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.seg { display: flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.seg button {
  border: 0; background: transparent; padding: 5px 11px;
  font-size: 12.5px; cursor: pointer; color: var(--ink-2);
}
.seg button + button { border-left: 1px solid var(--border); }
.seg button.active { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg-solo {
  border: 1px solid var(--border); background: transparent; border-radius: 9px;
  padding: 5px 11px; font-size: 12.5px; cursor: pointer; color: var(--ink-2);
}
.seg-solo:hover { background: var(--wash); }
.chart-stat {
  display: flex; align-items: baseline; justify-content: flex-end;
  gap: 8px; margin: 0 4px 0 0;
}
.cs-label { font-size: 12px; color: var(--ink-2); }
.cs-value {
  font-family: "Space Grotesk", "IBM Plex Sans", system-ui, sans-serif;
  font-size: 24px; font-weight: 700; color: var(--ink);
}
.cs-unit { font-size: 11.5px; color: var(--ink-2); }

.chart-box { height: 300px; }
.chart-box.tall { height: 440px; }
.loading .chart-box { opacity: 0.55; transition: opacity 0.15s; }

/* table view (the relief channel — every chart has one) */
.table-box { max-height: 440px; overflow: auto; border-top: 1px solid var(--grid); }
.table-box table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
.table-box th, .table-box td { padding: 5px 10px; text-align: right; white-space: nowrap; }
.table-box th:first-child, .table-box td:first-child { text-align: left; }
.table-box thead th {
  position: sticky; top: 0; background: var(--surface);
  color: var(--ink-2); font-weight: 600; border-bottom: 1px solid var(--baseline);
}
.table-box td { font-variant-numeric: tabular-nums; border-bottom: 1px solid var(--grid); color: var(--ink); }

/* ------------------------------------------------------------------ records */
.rec-nav { margin-left: auto; display: flex; gap: 6px; }
.rec-nav button {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 9px; padding: 4px 12px; cursor: pointer;
  font-size: 15px; color: var(--ink-2);
}
.rec-nav button:hover { background: var(--wash); }
.rec-grid {
  display: grid; grid-auto-flow: column;
  grid-template-rows: repeat(2, 1fr);
  grid-auto-columns: 235px;
  gap: 12px; overflow-x: auto;
  scroll-snap-type: x proximity; padding-bottom: 6px;
  scrollbar-width: thin;
}
.rec-grid .tile-foot { margin-top: 2px; }
button.rec-card {
  font: inherit; text-align: left; cursor: pointer; color: inherit;
  display: block; scroll-snap-align: start;
}
button.rec-card:hover { background: var(--wash); border-color: var(--accent); }
.rec-hint { color: var(--accent); font-weight: 600; }
.rec-label { display: flex; align-items: center; gap: 7px; }
.rec-ico { display: inline-flex; color: var(--muted); flex: none; }
.rec-ico svg { width: 17px; height: 17px; }

/* ------------------------------------------------------------------ know */
.know-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.know p { margin: 0; font-size: 13.5px; color: var(--ink-2); }
.chip {
  display: inline-block; width: 12px; height: 12px; border-radius: 4px; flex: none;
}
.chip-coal    { background: var(--s-coal); }
.chip-nuclear { background: var(--s-nuclear); }
.chip-ocgt    { background: var(--s-ocgt); }
.chip-ps      { background: var(--s-ps); }
.chip-wind    { background: linear-gradient(90deg, var(--s-wind) 50%, var(--s-pv) 50%); }
.chip-imports { background: var(--s-imports); }

/* ------------------------------------------------------------------ faq */
.faq details { border-top: 1px solid var(--grid); }
.faq details:first-of-type { margin-top: 12px; }
.faq summary {
  cursor: pointer; font-weight: 600; font-size: 14px;
  padding: 11px 0; list-style-position: outside;
}
.faq summary:hover { color: var(--accent); }
.faq p { margin: 0 0 12px; font-size: 13.5px; color: var(--ink-2); max-width: 760px; }

/* ------------------------------------------------------------------ feedback */
.feedback .chart-sub { max-width: 640px; }
.fb-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.fb-field { display: block; }
.fb-field span {
  display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 4px;
}
.fb-wide { grid-column: 1 / -1; }
.feedback input, .feedback textarea {
  width: 100%; border: 1px solid var(--border); background: var(--page);
  color: var(--ink); border-radius: 9px; padding: 8px 10px;
  font: inherit; font-size: 13.5px;
}
.feedback textarea { resize: vertical; min-height: 90px; }
.hp { position: absolute; left: -9999px; top: -9999px; height: 0; overflow: hidden; }
.fb-send {
  margin-top: 12px; background: var(--accent); color: var(--accent-ink);
  border: 0; border-radius: 9px; padding: 8px 18px;
  font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer;
}
.fb-send:hover { opacity: 0.9; }
#fbStatus { font-size: 12.5px; color: var(--ink-2); margin: 8px 0 0; }
@media (max-width: 640px) {
  .fb-grid { grid-template-columns: 1fr; }
}

/* ------------------------------------------------------------------ about + footer */
.about p { color: var(--ink-2); font-size: 13.5px; margin: 8px 0 0; }
.about details { margin-top: 12px; font-size: 13.5px; color: var(--ink-2); }
.about summary { cursor: pointer; font-weight: 600; color: var(--ink); }
.about li { margin: 6px 0; }
.site-foot {
  border-top: 1px solid var(--border);
  padding: 18px 0 26px; color: var(--muted); font-size: 12.5px;
}
.site-foot p { margin: 0; }
.noscript-note { padding: 20px; }

/* ------------------------------------------------------------------ responsive */
@media (max-width: 980px) {
  .know-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  body { font-size: 14px; }
  .hero-main { flex-basis: 220px; }
  .donut-card { flex-basis: 330px; grid-template-columns: 92px 1fr; }
  .tile-grid { flex-basis: 300px; }
  .hero-figure { font-size: 25px; }
  .chart-box.tall { height: 360px; }
  .chart-box { height: 260px; }
  .know-grid { grid-template-columns: 1fr; }
  .rec-grid { grid-auto-columns: 205px; }
  .brand-tag { display: none; }
  .data-stamp { display: none; }
}
