/* ---------- Design tokens ---------- */
:root {
  color-scheme: light;
  --brand: #0A6931;
  --brand-dark: #074f25;
  --brand-deep: #002D32; /* WinACC's footer teal */
  /* Links and other text-coloured accents use WinACC's teal rather than its green: green stays
     for filled surfaces (header, active toggle, checkboxes). WinACC's orange accent is
     deliberately unused — it's near-identical to --series-2, so it would read as chart data. */
  --link: #006875;
  --surface-1: #fcfcfb;
  --page-plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11,11,11,0.10);
  --success-text: #006300;

  --control-panel-h: 60px; /* kept in sync with the real control-panel height via ResizeObserver in app.js */

  /* categorical (light) */
  --series-1: #2a78d6; /* blue */
  --series-2: #eb6834; /* orange */
  --series-3: #1baf7a; /* aqua */
  --series-4: #eda100; /* yellow */
  --series-5: #e87ba4; /* magenta */
  --series-6: #008300; /* green */
  --series-7: #4a3aa7; /* violet */
  --series-8: #e34948; /* red */
}

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

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page-plane: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255,255,255,0.10);
  --success-text: #0ca30c;
  --link: #50B9BE;

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
}

* { box-sizing: border-box; }
/* overflow-x lives on html only, not body — setting it on both establishes body as its own
   scroll container that never actually scrolls (the viewport/html does), which silently
   breaks position: sticky for every descendant (control panel, region toggle). */
html { margin: 0; padding: 0; overflow-x: hidden; max-width: 100%; }
body {
  margin: 0; padding: 0; max-width: 100%;
  font-family: "Roboto", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page-plane);
  color: var(--text-primary);
  line-height: 1.5;
}
h1, h2, h3 { font-family: "Roboto Slab", "Roboto", serif; font-weight: 700; margin: 0; }
a { color: var(--link); }
:root[data-theme="dark"] a, @media (prefers-color-scheme: dark) { }
.wrap { max-width: 900px; margin: 0 auto; padding: 0 20px; }

/* ---------- Header ---------- */
.site-header { background: var(--brand); color: #fff; padding: 20px 0; }
.header-row { display: flex; align-items: center; min-width: 0; }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-mark { flex: none; display: block; line-height: 0; }
.brand-mark img { height: 48px; width: auto; display: block; }
.brand-text { min-width: 0; }
.brand-text h1 { font-size: 1.4rem; color: #fff; overflow-wrap: break-word; }
.title-row { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; }
/* Opens the "about" dialog. Kept small and quiet: it flags the site's status to every visitor
   without turning into a banner competing with the charts. */
.wip-chip { font: inherit; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.02em; color: #fff; background: rgba(255,255,255,0.16); border: 1px solid rgba(255,255,255,0.55); border-radius: 999px; padding: 2px 10px; cursor: pointer; white-space: nowrap; }
.wip-chip:hover { background: rgba(255,255,255,0.28); }
.wip-chip:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.brand-sub { margin: 4px 0 0; font-size: 0.85rem; color: rgba(255,255,255,0.85); }
.brand-sub a { color: #fff; text-decoration: underline; }

main.wrap { padding-top: 24px; padding-bottom: 40px; }

/* ---------- Footer & dev banner ---------- */
/* Two quiet lines below the content: the data credit (with the OGL licence link and the full
   attribution statement one click away in the methodology dialog), then the WinACC credit, source
   link and, in a packaged release, its version. Same deep teal as WinACC's own site footer, in
   both themes. */
.site-footer { background: var(--brand-deep); color: rgba(255,255,255,0.85); padding: 14px 0; font-size: 0.82rem; margin-top: 8px; }
.site-footer p { margin: 0; }
.site-footer p + p { margin-top: 4px; }
.site-footer a, .site-footer .link-btn { color: #fff; }
/* Shown only on the GitHub Pages development copy (see deploymentKind() in app.js). */
.dev-banner { background: var(--brand-deep); color: #fff; font-size: 0.78rem; text-align: center; padding: 4px 16px; }
.dev-banner a { color: #fff; }
.dev-banner.is-hidden { display: none; }

/* ---------- Region toggle ---------- */
/* Sticks just below the control panel, but only stays stuck while its own section
   (this row plus the region-scoped cards below it) is on screen — plain CSS sticky
   behaviour, since the sticky item stops sticking once its containing block scrolls
   past. --control-panel-h is kept in sync with the panel's real rendered height by
   ResizeObserver in app.js, since it wraps to two lines on narrow screens. */
.region-toggle-row {
  display: flex; align-items: center; gap: 10px; overflow-x: auto;
  position: sticky; top: var(--control-panel-h, 60px); z-index: 25;
  background: var(--surface-1); border: 1px solid var(--gridline); border-radius: 10px;
  padding: 10px 16px; margin-bottom: 22px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

/* ---------- Energy unit toggle ---------- */
/* Only the generation and consumption charts read this control, unlike the chart scale toggle in
   the region toggle row above (which also governs trend/sector/gas) — so it lives right above
   those two charts instead, and (like the row above it) stops sticking once its own section (this
   row plus the three energy cards below it) scrolls past. Stacks below the control panel and
   region toggle, so its sticky offset is their two heights combined — both kept in sync with
   their real rendered heights by the same ResizeObserver in app.js that already tracks
   --control-panel-h. */
.energy-unit-row {
  display: flex; align-items: center; gap: 10px; overflow-x: auto;
  position: sticky; top: calc(var(--control-panel-h, 60px) + var(--region-toggle-h, 52px)); z-index: 20;
  background: var(--surface-1); border: 1px solid var(--gridline); border-radius: 10px;
  padding: 10px 16px; margin-bottom: 22px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.seg-btn {
  font: inherit; font-size: 0.95rem; font-weight: 500; padding: 9px 16px;
  background: var(--surface-1); color: var(--text-secondary); border: none; cursor: pointer;
  border-right: 1px solid var(--gridline); white-space: nowrap; flex: none;
}
.seg-btn:last-child { border-right: none; }
.seg-btn.is-active { background: var(--brand); color: #fff; font-weight: 700; }

/* Region select — a native <select> rather than a button row, since there are 19 regions
   across three tiers (grouped via <optgroup>, populated from data in app.js). Styled to sit in
   the same card-like shell the old button row used, rather than the browser's bare default. */
.region-select-wrap { flex: 1 1 auto; min-width: 0; }
#region-select {
  font: inherit; font-size: 0.95rem; font-weight: 500; width: 100%;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--gridline); border-radius: 8px; padding: 9px 34px 9px 12px;
  cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%23898781' d='M4 6l4 4 4-4z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
#region-select:focus-visible { outline: 2px solid var(--link); outline-offset: 1px; }

/* ---------- Control panel ---------- */
/* Pinned to the very top of the viewport for the whole page (it governs every chart, not
   just one section), so it needs to stay reachable while scrolling through a long page of
   charts. The page title itself is deliberately left non-sticky — it only needs to show
   while you're at the top of the page. */
.control-panel {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 20px;
  background: var(--surface-1); border: 1px solid var(--gridline); border-radius: 10px;
  padding: 10px 16px; margin-bottom: 22px;
  position: sticky; top: 0; z-index: 30;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.control-group { display: flex; align-items: center; gap: 8px; }
.seg-toggle { display: inline-flex; border: 1px solid var(--gridline); border-radius: 8px; overflow: hidden; }
.seg-toggle .seg-btn[disabled] { opacity: 0.45; cursor: not-allowed; }

/* ---------- Horizon banner & page-wide indicator ---------- */
/* The 20-year GWP view is a page-wide reweighting, not a per-chart option, so its cue needs to
   be visible everywhere at once: a dismissible-feeling banner plus a thin accent border that
   rides along every card and tile for as long as the toggle is set to "20-year". */
.horizon-banner {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: rgba(235,104,52,0.10); border: 1px solid rgba(235,104,52,0.35);
  border-radius: 10px; padding: 10px 16px; margin: -8px 0 22px; font-size: 0.85rem; color: var(--text-secondary);
}
.horizon-banner.is-hidden { display: none; }
.horizon-banner strong { color: var(--series-2); }
body.horizon-gwp20 .card { border-top: 3px solid var(--series-2); }

/* "Provisional boundaries" chip beside the region select, shown only while a proposed unitary is
   selected (syncProvisionalChip in app.js). Opens the "Choosing a region" dialog, where the LGR
   status lives. Delete it once the Government confirms the new unitary boundaries. */
.status-chip {
  font: inherit; font-size: 0.82rem; font-weight: 500; white-space: nowrap; flex: none;
  padding: 4px 10px; border-radius: 999px; cursor: pointer;
  background: none; color: var(--text-secondary); border: 1px dashed var(--text-muted);
}
.status-chip:hover, .status-chip:focus-visible { border-color: var(--link); color: var(--link); outline: none; }
.status-chip.is-hidden { display: none; }

/* ---------- Info button ---------- */
.info-btn {
  width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid var(--text-muted);
  background: none; color: var(--text-muted); font: 600 12px/1 "Roboto", sans-serif;
  cursor: pointer; flex: none; display: inline-flex; align-items: center; justify-content: center;
}
.info-btn:hover, .info-btn:focus-visible { border-color: var(--link); color: var(--link); outline: none; }

/* ---------- Cards ---------- */
/* scroll-margin-top keeps a card's own heading clear of the sticky stack above it (control panel
   + region toggle, and — inside #energy-scoped — the energy unit row too) whenever a browser-
   driven jump lands on it: in-page search (Cmd/Ctrl+F), a fragment link, or Tab focusing an
   element inside the card. It doesn't (and can't) prevent a heading from briefly sitting under
   the sticky bars mid-scroll during ordinary continuous scrolling — that's normal for any sticky
   header design, the same way a page heading scrolls up behind a fixed nav bar on any site — this
   only fixes browser-chosen "jump to here" landings actually stopping in the wrong place. */
.card, .card-head h2, .chart-wrap { scroll-margin-top: calc(var(--control-panel-h, 60px) + var(--region-toggle-h, 52px) + 12px); }
.energy-scoped .card, .energy-scoped .card-head h2, .energy-scoped .chart-wrap { scroll-margin-top: calc(var(--control-panel-h, 60px) + var(--region-toggle-h, 52px) + var(--energy-unit-row-h, 64px) + 12px); }
.card { background: var(--surface-1); border: 1px solid var(--gridline); border-radius: 12px; padding: 18px 20px 20px; margin-bottom: 20px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.card-head h2 { font-size: 1.05rem; }
.chart-wrap { width: 100%; overflow-x: auto; }
.chart-wrap svg { display: block; width: 100%; height: auto; }
.chart-empty-note { color: var(--text-muted); font-size: 0.9rem; }

/* ---------- Sector detail toggle ---------- */
.sector-detail-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px; margin: -2px 0 10px; }
.detail-toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--text-secondary); cursor: pointer; }
.detail-toggle input { accent-color: var(--brand); cursor: pointer; }
.sector-detail-row.is-disabled .detail-toggle { opacity: 0.45; cursor: not-allowed; }
.sector-detail-row.is-disabled .detail-toggle input { cursor: not-allowed; }
/* A toggle that shares its row with another and can be unavailable on its own (the trend chart's
   footprint checkbox), so it's dimmed per group rather than via the row's .is-disabled. Its (i)
   button stays at full strength, since that dialog is what explains why it's unavailable. */
.detail-toggle-group { display: inline-flex; align-items: center; gap: 6px; }
.detail-toggle-group.is-disabled .detail-toggle { opacity: 0.45; cursor: not-allowed; }
.detail-toggle-group.is-disabled .detail-toggle input { cursor: not-allowed; }

/* ---------- Table toggle & table view ---------- */
.table-toggle {
  font: inherit; font-size: 0.82rem; color: var(--link); background: none; border: none;
  cursor: pointer; padding: 6px 0 0; text-decoration: underline;
}
.table-scroll { overflow-x: auto; margin-top: 10px; }
.table-scroll.is-hidden { display: none; }
table.data-table { border-collapse: collapse; width: 100%; font-size: 0.85rem; }
table.data-table th, table.data-table td { text-align: right; padding: 5px 10px; border-bottom: 1px solid var(--gridline); font-variant-numeric: tabular-nums; }
table.data-table th:first-child, table.data-table td:first-child { text-align: left; font-variant-numeric: proportional-nums; }
table.data-table thead th { color: var(--text-secondary); font-weight: 700; border-bottom: 2px solid var(--baseline); }

/* ---------- Legend ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 10px; font-size: 0.82rem; }
.legend-item { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); }
.legend-swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.legend-swatch.line { width: 14px; height: 3px; border-radius: 2px; }
/* Stands for every region's dashed estimated-footprint line at once, so it's neutral grey rather
   than any one region's colour. Dash spacing echoes the chart's 6,4 stroke-dasharray. */
.legend-swatch.dashed {
  width: 18px; height: 2px; border-radius: 0;
  background: repeating-linear-gradient(90deg, var(--text-secondary) 0 6px, transparent 6px 10px);
}

/* ---------- Tooltip ---------- */
.viz-tooltip {
  position: absolute; pointer-events: none; background: var(--surface-1);
  border: 1px solid var(--gridline); border-radius: 8px; padding: 8px 10px;
  font-size: 0.8rem; box-shadow: 0 4px 16px rgba(0,0,0,0.12); z-index: 20;
  opacity: 0; transition: opacity 0.1s; max-width: 360px;
}
.viz-tooltip.is-visible { opacity: 1; }
.viz-tooltip .tt-title { font-weight: 700; margin-bottom: 4px; color: var(--text-primary); }
/* flex-wrap is the real regression fix here: a row whose label + value can't both fit on one
   line used to rely on the label wrapping internally to free up space (see the .tt-key comment
   below) — fine for a multi-word label like a sub-sector name, but a bare single-token label
   like a year ("2024") has nothing to wrap *at*, so instead of wrapping it just collapsed to
   zero width and painted directly on top of the value text. Letting the row itself wrap moves
   the value onto its own line instead in that case, which never overlaps. */
.viz-tooltip .tt-row { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 2px 10px; }
.viz-tooltip .tt-key { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); }
.viz-tooltip .tt-key .stroke { width: 10px; height: 2px; border-radius: 1px; flex: none; }
/* Numbers/units must never break across lines (e.g. "1.08" wrapping away from "t") — a
   multi-word label is what absorbs a width squeeze first, wrapping onto a second line if it has
   to (min-content above still lets that happen); flex-wrap on .tt-row above is the fallback for
   a label with nothing to wrap at, like a bare year. */
.viz-tooltip .tt-val { font-weight: 700; color: var(--text-primary); white-space: nowrap; flex: none; text-align: right; }
.viz-tooltip .tt-subrow { padding-left: 12px; font-size: 0.92em; margin-top: 2px; }
.viz-tooltip .tt-subrow-first { margin-top: 5px; padding-top: 5px; border-top: 1px dashed var(--gridline); }
/* Divider goes AFTER the row instead of before it — for a subrow that closes out its own
   parent row's group (e.g. a per-region population figure in a multi-region tooltip), so the
   line separates it from the next row's group rather than detaching it from its own parent. */
.viz-tooltip .tt-subrow-last { margin-bottom: 5px; padding-bottom: 5px; border-bottom: 1px dashed var(--gridline); }
.viz-tooltip .tt-subrow .tt-key { color: var(--text-muted); }
.viz-tooltip .tt-subrow .tt-val { font-weight: 500; color: var(--text-secondary); }

/* ---------- Footnote ---------- */
.link-btn { font: inherit; font-size: inherit; color: var(--link); background: none; border: none; cursor: pointer; text-decoration: underline; padding: 0; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45); display: flex;
  align-items: center; justify-content: center; padding: 20px; z-index: 100;
}
.modal-overlay.is-hidden { display: none; }
/* The title and close button live in their own non-scrolling head, separate from the scrolling
   body below — otherwise, on a long entry (e.g. "Full methodology & sources"), scrolling down to
   read the rest pushes the close button off the top of the screen too, forcing a scroll back up
   just to dismiss the dialog. */
.modal {
  background: var(--surface-1); border-radius: 12px; max-width: 480px;
  width: 100%; max-height: 80vh; position: relative; box-shadow: 0 12px 40px rgba(0,0,0,0.25);
  display: flex; flex-direction: column;
}
.modal-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  flex: none; padding: 24px 26px 12px;
}
.modal h3 { font-size: 1.1rem; margin: 0; }
#modal-body { overflow-y: auto; min-height: 0; padding: 0 26px 24px; }
.modal p { font-size: 0.9rem; color: var(--text-secondary); margin: 0 0 10px; }
.modal p:last-child { margin-bottom: 0; }
.modal a { color: var(--link); }
.modal-close {
  flex: none; background: none; border: none; font-size: 1.4rem;
  line-height: 1; color: var(--text-muted); cursor: pointer; padding: 4px;
}
.modal-close:hover { color: var(--text-primary); }
/* Inline cross-reference to another dialog entry ([[key|label]] in INFO_CONTENT). Styled as a
   link rather than a button so it reads as part of the sentence, not as a control. */
.info-link {
  font: inherit; color: var(--link); background: none; border: none;
  cursor: pointer; text-decoration: underline; padding: 0; text-align: left;
}
.info-link:hover { text-decoration: none; }

/* Breadcrumb back to the dialog a cross-reference was followed from. Sits above the title in the
   non-scrolling head, so it stays reachable however far down the reader has scrolled. */
.modal-head-text { min-width: 0; }
.modal-back {
  font: inherit; font-size: 0.78rem; color: var(--text-muted); background: none;
  border: none; cursor: pointer; padding: 0 0 4px; display: block; text-align: left;
}
.modal-back:hover { color: var(--link); }
.modal-back.is-hidden { display: none; }

/* The three-part dialog: a summary everyone reads, bullets on reading the chart, then the method
   behind a disclosure. The size step from summary to bullets to method rows is what signals the
   hierarchy — without it the reader has no way to tell which parts they can skip. */
.modal p.modal-summary {
  font-size: 1.02rem; line-height: 1.45; color: var(--text-primary); margin-bottom: 14px;
}
/* A derived headline figure for the current selection (the generation chart's demand
   comparison). A finding, not a caveat, so it leads — set off from the static summary above it. */
.modal p.modal-figure {
  font-size: 0.9rem; color: var(--text-primary);
  background: var(--page-plane); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 14px;
}
.modal ul.read-it { margin: 0 0 16px; padding-left: 20px; font-size: 0.9rem; color: var(--text-secondary); }
.modal ul.read-it li { margin-bottom: 7px; line-height: 1.5; }
.modal ul.read-it li:last-child { margin-bottom: 0; }

.modal details.method-block { border-top: 1px solid var(--border); padding-top: 4px; }
.modal details.method-block > summary {
  cursor: pointer; list-style: none; padding: 8px 0;
  font-size: 0.85rem; font-weight: 500; color: var(--text-muted);
}
.modal details.method-block > summary::-webkit-details-marker { display: none; }
.modal details.method-block > summary::before {
  content: "\25B8"; display: inline-block; width: 14px; transition: transform 0.15s ease;
}
.modal details.method-block[open] > summary::before { transform: rotate(90deg); }
.modal details.method-block > summary:hover { color: var(--link); }

.modal dl { margin: 0 0 4px; font-size: 0.85rem; }
.modal dt { font-weight: 700; margin-top: 12px; color: var(--text-primary); }
.modal dl > dt:first-child { margin-top: 4px; }
.modal dd { margin: 3px 0 0; color: var(--text-secondary); line-height: 1.5; }
.modal p.method-link { font-size: 0.85rem; margin-top: 14px; }

@media (max-width: 480px) {
  .brand-text h1 { font-size: 1.15rem; }
}

/* All three sticky bars stay pinned while scrolling on mobile, so they need to stay a single
   compact row rather than wrapping to two or three — wrapping would eat a large chunk of a
   phone viewport permanently. Buttons shrink and the row scrolls horizontally instead. */
@media (max-width: 640px) {
  .control-panel, .region-toggle-row, .energy-unit-row { flex-wrap: nowrap; overflow-x: auto; gap: 8px 14px; padding: 8px 14px; }
  .control-group { flex: none; }
  .control-panel .seg-btn { padding: 7px 12px; font-size: 0.88rem; }
  #region-select { padding: 7px 30px 7px 10px; font-size: 0.88rem; }
  /* Keep the select readable when the provisional chip shares the row; the row scrolls instead. */
  .region-select-wrap { min-width: 170px; }
  .status-chip { font-size: 0.78rem; padding: 3px 8px; }
  .status-chip .chip-extra { display: none; }
}
