*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* Theme tokens. The default block below is the dark palette; the light
 * override block follows. Pre-paint theme attribute is set by theme-init.js
 * (see ADR-010). Data colours are constant across themes — only chrome
 * tokens swap. */
:root {
  --bg:        #080d19;
  --surface:   #0f172a;
  --surface-2: #1e293b;
  --border:    #1e293b;
  --border-2:  #334155;
  --text:      #f1f5f9;
  --sub:       #94a3b8;
  --muted:     #475569;

  /* Translucent overlays for hover / info-bubble backgrounds. White-on-dark
   * in the default theme; inverted to dark-on-light in the light theme. */
  --overlay-soft:   rgba(255, 255, 255, 0.06);
  --overlay-strong: rgba(255, 255, 255, 0.12);

  --demand:  #3b82f6;
  --wind:    #22c55e;
  --freq:    #a855f7;
  --snsp:    #f59e0b;
  --co2:     #f43f5e;
  --import:  #06b6d4;
  --export:  #f97316;

  --accent:  #a5b4fc;   /* indigo-300 - links on dark tooltip surfaces */
}

:root[data-theme="light"] {
  --bg:        #e2e8f0;   /* slate-200 — gives cards a visible frame against the page */
  --surface:   #ffffff;
  --surface-2: #ffffff;
  --border:    #cbd5e1;   /* slate-300 — visible card edges against the slate-200 body */
  --border-2:  #94a3b8;   /* slate-400 — stronger borders (tooltips, accent edges) */
  --text:      #0f172a;
  --sub:       #334155;
  --muted:     #94a3b8;

  --overlay-soft:   rgba(15, 23, 42, 0.08);
  --overlay-strong: rgba(15, 23, 42, 0.14);

  --accent:  #4f46e5;   /* indigo-600 - links on light tooltip surfaces */
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Header ── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 10;
}

.hd-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.hd-title {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: none;
}

.hd-subtitle {
  font-size: 0.95rem;
  color: var(--sub);
  letter-spacing: 0.04em;
  font-weight: 400;
  margin-left: 0.4rem;
}
.hd-subtitle a {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.hd-subtitle a:hover {
  opacity: 0.8;
}
.hd-right {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  font-size: 0.75rem;
  color: var(--sub);
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}

.dot.live {
  background: #22c55e;
  box-shadow: 0 0 0 3px #22c55e22;
}

.dot.error { background: var(--co2); }

.refresh-btn {
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  color: var(--sub);
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.72rem;
  transition: color 0.15s, border-color 0.15s;
}

.refresh-btn:hover { color: var(--text); border-color: var(--sub); }

/* ── Header tooltips ── */
.hd-tip-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.hd-tip {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 240px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  font-size: 0.72rem;
  line-height: 1.5;
  color: var(--sub);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 200;
}

/* downward arrow */
.hd-tip::before {
  content: '';
  position: absolute;
  top: -6px;
  right: 14px;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 6px solid var(--border-2);
}
.hd-tip::after {
  content: '';
  position: absolute;
  top: -5px;
  right: 15px;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 5px solid var(--surface-2);
}

.hd-tip-wrap:hover .hd-tip { opacity: 1; }

/* ── Main layout ── */
main {
  max-width: 100%;
  margin: 0;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.section-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text);
  margin-bottom: 0.85rem;
}

.section-label-tip {
  position: relative;
  display: inline-block;
}
.section-info {
  display: inline-block;
  width: 14px;
  height: 14px;
  line-height: 14px;
  text-align: center;
  font-size: 0.62rem;
  font-family: Georgia, serif;
  font-style: italic;
  font-weight: 600;
  border-radius: 50%;
  background: var(--overlay-strong);
  color: var(--sub);
  margin-left: 0.45rem;
  vertical-align: 1px;
}
.section-tooltip {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  width: 340px;
  font-size: 0.72rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
  color: var(--text);
  line-height: 1.55;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 50;
}
.section-tooltip::after {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 24px;
  border: 7px solid transparent;
  border-bottom-color: var(--border-2);
}
.section-tooltip.tooltip-open { opacity: 1; pointer-events: auto; }
.section-tooltip strong { color: var(--text); display: block; margin-bottom: 0.3rem; }

/* ── Header centre notice ── */
.hd-center {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  max-width: 560px;
  margin: 0 auto;
  padding: 0.45rem 0.9rem;
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.75rem;
  line-height: 1.4;
  text-align: center;
}

.hd-center-icon {
  color: #f59e0b;
  font-size: 0.9rem;
  line-height: 1;
  flex-shrink: 0;
}

.hd-center a {
  color: #f59e0b;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.hd-center a:hover {
  text-decoration: underline;
}

/* ── Gauge cards ── */
.gauges-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.75rem;
}

.gauge-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.4rem 0.6rem 0.1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  height: 190px;
  transition: border-color 0.2s;
}

.gauge-card {
  position: relative; /* needed for tooltip positioning */
}

.gauge-card:hover { border-color: var(--border-2); }

/* ── Gap indicator on a gauge card. A clearly-visible dot with a click-to-open
   popover (same interaction as the ⓘ info tooltips) explaining the gap, when it
   started, and a link to the docs. Colour signals severity:
     .gap-badge--fill  (orange) - no reading at the exact time being viewed
                                   (forward fill); a mild "data note".
     .gap-badge--stale (red)    - the live value is hours old, no longer current;
                                   a longer gap that warrants more attention.
   The popover holds a real <a>, so the link is visible and on its own line. ── */
.gap-badge {
  --gap-color: #f97316;           /* orange - forward fill (mild) */
  position: absolute;
  top: 9px;
  right: 8px;
  width: 12px;
  height: 12px;
  z-index: 2;
}
.gap-badge--stale { --gap-color: #ef4444; }  /* red - longer / stale gap */

.gap-dot {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--gap-color);
  /* A light ring lifts the dot off the card so it reads as an indicator and
     isn't missed, without a loud pulsing glow. */
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--gap-color) 35%, transparent),
              0 0 0 4px var(--surface-2);
  cursor: pointer;
}

.gap-pop {
  position: absolute;
  top: 18px;
  right: -6px;
  min-width: 180px;
  max-width: 240px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-2);   /* neutral chrome, same as info tooltips */
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;          /* never interactive while hidden */
  transform: translateY(-3px);
  transition: opacity 0.15s, transform 0.15s;
  z-index: 30;
}
/* Click-to-open, same as the info (ⓘ) tooltips: the dot toggles `.tooltip-open`
   on the popover. Only then does it accept pointer events, so the link stays
   reachable (it doesn't vanish on hover-out) and the invisible surface never
   intercepts clicks over neighbouring gauges. */
.gap-pop.tooltip-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
.gap-pop-head {
  margin: 0;
  font-size: 0.74rem;
  font-weight: 600;
}
.gap-pop-since {
  margin: 0.25rem 0 0;
  font-size: 0.7rem;
  color: var(--sub);
}
/* The docs link reuses .g-learn - the same style every ⓘ info tooltip uses. */

.g-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: var(--text);
  margin-bottom: 0.2rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

/* Info icon — pinned to the top-LEFT corner of the panel so the tooltip can
   open straight underneath it without colliding with the chart expand button
   or the gap-badge (which sit top-right). The icon and its tooltip share an
   `.info-tip` wrapper; pinning the wrapper to the corner keeps the icon in its
   original place while letting the tooltip anchor to it (open directly below). */
.info-tip {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 4;
}
.chart-card .info-tip {
  top: 0.9rem;
  left: 0.9rem;
}
/* When this panel's tooltip is open, lift the whole wrapper above every other
   panel's info icon so neighbouring icons don't bleed through the open tooltip. */
.info-tip:has(.tooltip-open) {
  z-index: 60;
}
.g-info, .mix-info {
  font-style: normal;
  font-size: 0.85rem;
  color: var(--sub);
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  line-height: 1;
}

/* canvas wrapper — fixed height so both gauge rows are equal height */
.g-canvas-wrap {
  width: 100%;
  height: 85px;
  position: relative;
}

.g-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.g-value {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-top: 0.1rem;
}

.g-unit {
  font-size: 0.72rem;
  color: var(--text);
  margin-top: 0.05rem;
}

.g-sub {
  font-size: 0.65rem;
  color: var(--text);
  text-align: center;
  margin-top: 0.1rem;
  line-height: 1.3;
}

/* ── Horizontal gauge layout (bottom row) ── */
.gauge-h {
  justify-content: center;
}

.g-h-body {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  height: 100%;
}

.gauge-h .g-canvas-wrap {
  width: 130px;
  height: 130px;
  flex-shrink: 0;
}

.g-h-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
  gap: 0.1rem;
}

.g-h-text .g-value {
  text-align: left;
  margin-top: 0.2rem;
}

.g-h-text .g-unit,
.g-h-text .g-sub {
  text-align: left;
}

/* ── Gauge tooltip ── */
.g-tooltip {
  position: absolute;
  top: calc(100% + 10px); /* below the card */
  bottom: auto;
  left: 0;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  width: 230px;
  font-size: 0.72rem;
  color: var(--text);
  line-height: 1.55;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 30;
  text-align: left;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

.g-tooltip.tooltip-open { opacity: 1; pointer-events: auto; }

/* Upward-pointing arrow, positioned over the info icon the tooltip hangs from. */
.g-tooltip::after {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 2px;
  border: 7px solid transparent;
  border-bottom-color: var(--border-2);
}

.g-tooltip strong { color: var(--text); display: block; margin-bottom: 0.3rem; }

/* Click-to-open tooltips (ADR-011).
   Tooltips are opened by clicking their card's info icon and dismissed by
   the next mouse click anywhere on the page. Hover does nothing — this
   stops adjacent tooltips overlapping each other and lets the user reach
   the "Learn more →" link without racing the hover-exit. Open state is
   driven by the `.tooltip-open` class added in dashboard.js. */
.g-tooltip p,
.chart-tooltip p,
.mix-tooltip p,
.section-tooltip p {
  margin: 0 0 0.45rem 0;
}
.g-tooltip p:last-of-type,
.chart-tooltip p:last-of-type,
.mix-tooltip p:last-of-type,
.section-tooltip p:last-of-type {
  margin-bottom: 0.2rem;
}
.g-info, .chart-info, .section-info, .mix-info {
  cursor: pointer;
  user-select: none;
}
.g-info:hover, .chart-info:hover, .section-info:hover, .mix-info:hover {
  color: var(--text);
}
.g-learn {
  display: inline-block;
  margin-top: 0.5rem;
  color: var(--accent, #a5b4fc);
  text-decoration: none;
  font-size: 0.7rem;
  font-weight: 600;
}
.g-learn:hover { text-decoration: underline; }

/* ── Interconnectors ── */
.intercon-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.85rem;
}

.ic-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem 1rem;
}

.ic-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.25rem;
}

.ic-name {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.ic-mw {
  font-size: 0.88rem;
  font-weight: 700;
}

.ic-desc {
  font-size: 0.62rem;
  color: var(--text);
  margin-bottom: 0.6rem;
}

.ic-direction {
  font-size: 0.6rem;
  color: var(--sub);
  margin-top: 0.3rem;
}

.flow-track {
  background: var(--surface-2);
  border-radius: 3px;
  height: 6px;
  position: relative;
  overflow: hidden;
}

.flow-track::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--border-2);
  transform: translateX(-50%);
}

.flow-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: 3px;
  transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Charts ── */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.1rem 1.25rem 1rem;
  position: relative;
}

.chart-title {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text);
  margin-bottom: 0.85rem;
}

.chart-info {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--border-2);
  color: var(--sub);
  font-size: 0.62rem;
  font-weight: 700;
  cursor: default;
  vertical-align: middle;
  margin-left: 0.3rem;
  font-style: normal;
  text-transform: none;
  letter-spacing: 0;
}

.chart-tooltip {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  width: 260px;
  font-size: 0.72rem;
  color: var(--text);
  line-height: 1.55;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 30;
  text-align: left;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}
.chart-tooltip::after {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 2px;
  border: 7px solid transparent;
  border-bottom-color: var(--border-2);
}
.chart-tooltip.tooltip-open { opacity: 1; pointer-events: auto; }
.chart-tooltip strong { color: var(--text); display: block; margin-bottom: 0.3rem; }

.chart-expand-btn {
  position: absolute;
  top: 0.75rem;
  right: 0.85rem;
  background: var(--overlay-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1;
  padding: 0.25rem 0.4rem;
  cursor: pointer;
  opacity: 0.85;
  transition: opacity 0.15s, background 0.15s;
}
.chart-expand-btn:hover {
  opacity: 1;
  background: var(--overlay-strong);
}
.chart-card:fullscreen .chart-expand-btn,
.chart-card:-webkit-full-screen .chart-expand-btn {
  opacity: 0.7;
}

.chart-card:fullscreen,
.chart-card:-webkit-full-screen {
  background: var(--bg);
  border-radius: 0;
  border: none;
  padding: 1.5rem 2rem;
  display: flex;
  flex-direction: column;
}
.chart-card:fullscreen .chart-wrap,
.chart-card:-webkit-full-screen .chart-wrap {
  flex: 1;
  height: auto;
}
.chart-card:fullscreen .chart-title,
.chart-card:-webkit-full-screen .chart-title {
  font-size: 0.8rem;
  margin-bottom: 1.2rem;
}

.chart-wrap {
  position: relative;
  height: 190px;
}

.chart-spinner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.chart-spinner::after {
  content: '';
  width: 28px;
  height: 28px;
  border: 3px solid var(--surface-2);
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: chart-spin 0.75s linear infinite;
}
@keyframes chart-spin {
  to { transform: rotate(360deg); }
}

/* ── Footer ── */
footer {
  text-align: center;
  padding: 1.5rem 1rem 2rem;
  font-size: 0.936rem;
  color: var(--text);
}

footer a { color: var(--text); text-decoration: underline; }
footer a:hover { color: var(--text); }

/* ── Time slider ── */
.time-controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.tc-inner { flex: 1; }

.tc-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.tc-edge {
  font-size: 0.62rem;
  color: var(--text);
  white-space: nowrap;
  min-width: 3.5rem;
}

.tc-edge:last-child { text-align: right; }

.tc-slider {
  flex: 1;
  accent-color: var(--import);
  cursor: pointer;
}

.tc-meta {
  display: flex;
  justify-content: center;
  margin-top: 0.3rem;
}

.tc-time {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--sub);
}

.tc-latest-btn {
  background: transparent;
  border: 1px solid var(--import);
  color: var(--import);
  padding: 0.35rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
  opacity: 0.35;
}

.tc-latest-btn.active {
  background: var(--import);
  color: var(--text);
  opacity: 1;
}

/* ── Latest available data header (label + unit toggle) ── */
.latest-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.4rem;
}

.latest-header .section-label { margin-bottom: 0; }

.unit-toggle {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: 6px;
  overflow: hidden;
}

.ut-btn {
  background: transparent;
  border: none;
  border-right: 1px solid var(--border-2);
  color: var(--muted);
  padding: 0.2rem 0.55rem;
  cursor: pointer;
  font-size: 0.68rem;
  font-weight: 600;
  transition: color 0.15s, background 0.15s;
}

.ut-btn:last-child { border-right: none; }
.ut-btn:hover { color: var(--text); }
.ut-btn.active { background: var(--border-2); color: var(--text); }

/* ── Gauges full width, mix card in second row ── */
.latest-wrap {
  display: block;
}

.latest-wrap .gauges-grid { width: 100%; }

/* Second row: SNSP + CO2 + mix card in a 3-col grid */
.gauges-row2 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-top: 0.75rem;
}

/* ── Generation mix card ── */
.mix-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.4rem 0.75rem;
  width: auto;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  height: 190px;
  overflow: hidden;
}

.mix-body {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
}

.mix-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 0;
}

/* ── Mix card tooltip ── */
.mix-tooltip {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  right: auto;
  transform: none;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  width: 230px;
  font-size: 0.72rem;
  color: var(--text);
  line-height: 1.55;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 30;
  text-align: left;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

.mix-tooltip.tooltip-open { opacity: 1; pointer-events: auto; }

.mix-tooltip::after {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 2px;
  right: auto;
  transform: none;
  border: 7px solid transparent;
  border-bottom-color: var(--border-2);
}

.mix-tooltip strong { color: var(--text); display: block; margin-bottom: 0.3rem; }

.mix-title {
  margin-bottom: 0.2rem !important;
  align-self: flex-start;
}

.mix-chart-wrap {
  position: relative;
  width: 130px;
  height: 130px;
  flex-shrink: 0;
}

.mix-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.mix-center-pct {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1;
}

.mix-center-lbl {
  font-size: 0.55rem;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 0.2rem;
}

.mix-legend {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.mix-leg-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.65rem;
  color: var(--sub);
}

.mix-leg-item strong { color: var(--text); margin-left: auto; }

.mix-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Region toggle ── */
.region-toggle {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  overflow: hidden;
}

.rt-btn {
  background: transparent;
  border: none;
  border-right: 1px solid var(--border-2);
  color: var(--muted);
  padding: 0.3rem 0.65rem;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 600;
  transition: color 0.15s, background 0.15s;
  white-space: nowrap;
}

.rt-btn:last-child { border-right: none; }
.rt-btn:hover { color: var(--text); }
.rt-btn.active { background: var(--import); color: var(--text); }

/* ── Responsive ── */
@media (max-width: 1200px) {
  .gauges-row2 { grid-template-columns: repeat(2, 1fr); }
  .intercon-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 800px) {
  .gauges-grid  { grid-template-columns: repeat(2, 1fr); }  /* 4→2 on small screens */
  .gauges-row2  { grid-template-columns: repeat(2, 1fr); }
  .charts-grid  { grid-template-columns: 1fr; }
  .intercon-grid { grid-template-columns: repeat(2, 1fr); }
  .latest-wrap { flex-direction: column; }
  .mix-card { width: 100%; flex-direction: row; gap: 1.25rem; }
  .mix-title { align-self: auto; }
}

@media (max-width: 480px) {
  header { padding: 0.75rem 1rem; }
  main { padding: 1rem; gap: 1.5rem; }
  .hd-subtitle { display: none; }
  .gauges-grid  { grid-template-columns: 1fr; }
  .gauges-row2  { grid-template-columns: 1fr; }
  .intercon-grid { grid-template-columns: 1fr; }
  .mix-card { flex-direction: column; }
}

/* ── Theme toggle (ADR-010) ── */
.theme-toggle {
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  color: var(--text);
  padding: 0.3rem 0.55rem;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.theme-toggle:hover {
  border-color: var(--sub);
  background: var(--overlay-soft);
}

/* Icon shows the *destination* theme (click to switch).
 * Inline SVG via mask-image so the symbol can be tinted via background-color
 * — sun is amber in dark mode, moon is slate in light mode (both saturated
 * against their respective button backgrounds for instant recognition). */
.theme-icon {
  display: inline-block;
  width: 18px;
  height: 18px;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-size: contain;
  mask-size: contain;
}

/* Sun icon — shown in dark mode (click to go light). */
:root[data-theme="dark"] .theme-icon {
  background-color: #fde047;  /* yellow-300 — brighter than the data-palette amber for stronger header presence */
  -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='12' cy='12' r='4'/><path d='M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M4.93 19.07l1.41-1.41M17.66 6.34l1.41-1.41'/></svg>");
          mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='12' cy='12' r='4'/><path d='M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M4.93 19.07l1.41-1.41M17.66 6.34l1.41-1.41'/></svg>");
}

/* Moon icon — shown in light mode (click to go dark). */
:root[data-theme="light"] .theme-icon {
  background-color: #0f172a;  /* slate-900 — high contrast on white card */
  -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black'><path d='M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z'/></svg>");
          mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black'><path d='M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z'/></svg>");
}

