/* Self-hosted fonts (latin subset, variable) — no third-party runtime dependency,
   no render-blocking @import. Weight range covers all weights the UI uses. */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url('fonts/inter-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url('fonts/jetbrains-mono-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --surface2: #f6f8fa;
  --border: #d0d7de;
  --border2: #e8ecf0;
  --ink: #1f2328;
  --ink2: #57606a;
  --ink3: #9198a1;
  --red: #cf222e;
  --red-bg: #fff0ee;
  --green: #1a7f37;
  --green-bg: #f0fff4;
  --amber: #9a6700;
  --amber-bg: #fff8c5;
  --blue: #0969da;
  --purple: #8250df;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 4px 12px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.10);
  /* chart colors (read by chartTheme() in utils.js) */
  --chart-tick: #9198a1;
  --chart-grid: rgba(0,0,0,0.05);
  --chart-axis: #e8ecf0;
  --chart-tip-bg: #ffffff;
  --chart-tip-border: #d0d7de;
  --chart-tip-title: #1f2328;
  --chart-tip-body: #57606a;
  /* live-market panel series colors */
  --lm-price: #0969da;
  --lm-demand: #c2410c;
  --lm-forecast-tint: rgba(15,23,42,0.05);
}

/* ── DARK THEME ─────────────────────────────────────────────── */
:root[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #21262d;
  --border: #30363d;
  --border2: #21262d;
  --ink: #e6edf3;
  --ink2: #adbac7;
  --ink3: #768390;
  --red: #ff7b72;
  --red-bg: #2d1618;
  --green: #3fb950;
  --green-bg: #12261a;
  --amber: #d29922;
  --amber-bg: #2b2410;
  --blue: #58a6ff;
  --purple: #bc8cff;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.55);
  --chart-tick: #7d8590;
  --chart-grid: rgba(240,246,252,0.08);
  --chart-axis: #30363d;
  --chart-tip-bg: #161b22;
  --chart-tip-border: #30363d;
  --chart-tip-title: #e6edf3;
  --chart-tip-body: #adbac7;
  --lm-price: #4493f8;
  --lm-demand: #f0813f;
  --lm-forecast-tint: rgba(240,246,252,0.06);
}
/* dark-mode fixes for components with light-baked colors */
:root[data-theme="dark"] .ga-formula-banner { background: var(--surface2); }
:root[data-theme="dark"] .insight.r { color: #ff9492; border-color: #5a1e1e; }
:root[data-theme="dark"] .insight.g { color: #6fdd8b; border-color: #1a4023; }
:root[data-theme="dark"] .insight.a { color: #e3b341; border-color: #4a3a12; }
:root[data-theme="dark"] .alert-bar.loading { background: #0d2136; border-bottom-color: #1f4c7a; }
:root[data-theme="dark"] .alert-bar.success { background: #0f2417; border-bottom-color: #1a6e33; }
:root[data-theme="dark"] .alert-bar.warn    { background: #2b2410; border-bottom-color: #7d5e00; color: #e3b341; }

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-variant-numeric: tabular-nums;  /* align digits in tables/grids/KPIs */
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── UTILITIES ──────────────────────────────────────────────── */
/* Small monospace caption under charts/tables (replaces repeated inline styles) */
.footnote {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.66rem;
  color: var(--ink3);
  line-height: 1.6;
  margin-top: 8px;
}

/* Loading skeleton (live-market KPIs before first data) */
.skeleton {
  display: inline-block;
  width: 72px;
  height: 1.5rem;
  border-radius: 4px;
  vertical-align: middle;
  background: linear-gradient(90deg, var(--surface2) 25%, var(--border2) 50%, var(--surface2) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.3s ease-in-out infinite;
}
@keyframes skeleton-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── ACCESSIBILITY ──────────────────────────────────────────── */
/* Visible keyboard focus (mouse clicks don't trigger :focus-visible) */
:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
  border-radius: 3px;
}
.subtab:focus-visible,
.sidebar-item:focus-visible { outline-offset: -2px; }

/* Honor OS "reduce motion": kill blink, hover transforms, chart-card flashes */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── TOPNAV ─────────────────────────────────────────────────── */
.topnav {
  height: 44px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 0;
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  z-index: 200;
}
.nav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 20px;
  flex-shrink: 0;
}
.nav-brand-name {
  font-family: 'Inter', sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.nav-brand-sep {
  color: var(--border);
  font-size: 1rem;
  font-weight: 300;
}
.nav-brand-sub {
  font-family: 'Inter', sans-serif;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--ink3);
}
.nav-right {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  color: var(--ink3);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}
.nav-refresh {
  font-family: 'Inter', sans-serif;
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--ink2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 3px 10px;
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
}
.nav-refresh:hover { background: var(--surface2); color: var(--ink); }
.nav-refresh:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── ALERT BAR ──────────────────────────────────────────────── */
.alert-bar {
  padding: 8px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Inter', sans-serif;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--ink2);
  transition: background 0.3s, border-color 0.3s, color 0.3s;
}
.alert-bar.loading {
  background: #ddf4ff;
  border-bottom: 1px solid #54aeff;
  color: var(--blue);
}
.alert-bar.success {
  background: var(--green-bg);
  border-bottom: 1px solid #a8f0b5;
  color: var(--green);
}
.alert-bar.warn {
  background: #fff8c5;
  border-bottom: 1px solid #d4a72c;
  color: #7d4e00;
}
.alert-pip { width: 6px; height: 6px; border-radius: 50%; background: var(--blue); animation: none; flex-shrink: 0; }
.alert-bar.loading .alert-pip { background: var(--blue); animation: blink 1.8s infinite; }
.alert-bar.success .alert-pip { background: var(--green); animation: none; }
.alert-bar.warn .alert-pip { background: #d4a72c; animation: none; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.3} }

/* ── KPI STRIP (GA Trends headline row) ─────────────────────── */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  margin-bottom: 14px;
}
.kpi-strip:empty { display: none; }
.kpi {
  padding: 8px 16px;
  border-right: 1px solid var(--border);
}
.kpi:last-child { border-right: none; }
.kpi-label {
  font-family: 'Inter', sans-serif;
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink3);
  margin-bottom: 4px;
}
.kpi-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.1;
}
.kpi-value.r { color: var(--red); }
.kpi-value.g { color: var(--green); }
.kpi-value.a { color: var(--amber); }
.kpi-sub {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.6rem;
  color: var(--ink3);
  margin-top: 3px;
}

/* ── BODY LAYOUT ────────────────────────────────────────────── */
.body-wrap {
  display: flex;
  flex: 1;
  overflow: hidden;
  padding-top: 44px; /* offset for fixed topnav */
}

/* ── SIDEBAR ────────────────────────────────────────────────── */
.sidebar {
  width: 200px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 14px 10px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--ink2);
  transition: all 0.1s;
  border: none;
  border-left: 2px solid transparent;
  background: none;
  width: 100%;
  text-align: left;
  font-family: 'Inter', sans-serif;
}
.sidebar-item:hover { background: var(--surface2); color: var(--ink); }
.sidebar-item.active {
  background: rgba(9,105,218,0.07);
  color: var(--blue);
  border-left-color: var(--blue);
  padding-left: 6px;
  font-weight: 600;
}
.sidebar-item .si-icon { font-size: 0.85rem; width: 16px; text-align: center; flex-shrink: 0; }

/* ── CONTENT ────────────────────────────────────────────────── */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

/* ── SECTIONS & SUB-TABS ────────────────────────────────────── */
/* Two-level nav: one .section per sidebar entry; .panel sub-views inside.
   Section-level furniture (sub-tabs, KPI strip, shared range) lives in
   .section-head and shows/hides with the section — no JS toggling. */
.section { display: none; }
.section.active { display: block; }
.subtabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.subtab {
  padding: 7px 14px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--ink2);
  cursor: pointer;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  transition: color 0.12s, border-color 0.12s;
  white-space: nowrap;
  font-family: 'Inter', sans-serif;
  display: flex;
  align-items: center;
  gap: 6px;
}
.subtab:hover { color: var(--ink); }
.subtab.active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 600; }
.subtab .live-badge { margin-left: 0; }

/* ── PANEL ──────────────────────────────────────────────────── */
.panel { display: none; }
.panel.active { display: block; }

/* ── ANATOMY PAGE ───────────────────────────────────────────── */
.anatomy-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}
.anatomy-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}
/* highlight a card briefly after jumping to it */
@keyframes acard-flash { from { box-shadow: 0 0 0 2px var(--blue); } to { box-shadow: var(--shadow-sm); } }
.acard.jump-target { animation: acard-flash 1.2s ease-out; }
/* .acard extends .card (shared shell); the grid gap replaces the card's
   own bottom margin, so zero it for any card inside the anatomy grid */
.anatomy-grid .card { margin-bottom: 0; }
.acard { transition: box-shadow 0.15s; }
.acard:hover { box-shadow: var(--shadow-md); }
.acard-header {
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--border2);
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.acard-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 4px;
}
.acard-titles { flex: 1; min-width: 0; }
.acard-name {
  font-family: 'Inter', sans-serif;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.01em;
}
.acard-sub {
  font-family: 'Inter', sans-serif;
  font-size: 0.63rem;
  color: var(--ink3);
  margin-top: 2px;
}
.acard-badge {
  font-family: 'Inter', sans-serif;
  font-size: 0.58rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
  flex-shrink: 0;
}
.badge-contracted { background: #ddf4ff; color: #0969da; }
.badge-regulated  { background: #fff8c5; color: #9a6700; }
.badge-opa        { background: #f0fff4; color: #1a7f37; }
.badge-oefc       { background: #ffe9f4; color: #a040a0; }
.badge-offset     { background: #fff0ee; color: #cf222e; }
.acard-body { padding: 14px 16px; }
.cost-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border2);
}
.cost-row:last-child { border-bottom: none; }
.cost-icon {
  font-size: 0.75rem;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
  margin-top: 1px;
}
.cost-content { flex: 1; min-width: 0; }
.cost-label {
  font-family: 'Inter', sans-serif;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 2px;
}
.cost-desc {
  font-family: 'Inter', sans-serif;
  font-size: 0.7rem;
  color: var(--ink2);
  line-height: 1.5;
}
.cost-note {
  font-family: 'Inter', sans-serif;
  font-size: 0.62rem;
  color: var(--ink3);
  margin-top: 2px;
}
.acard-footer {
  padding: 8px 16px 12px;
  background: var(--surface2);
  border-top: 1px solid var(--border2);
  font-family: 'Inter', sans-serif;
  font-size: 0.63rem;
  color: var(--ink3);
  line-height: 1.6;
}
.acard-footer strong { color: var(--ink2); }
.anatomy-legend {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 18px;
  margin-bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px;
  align-items: center;
}
.anatomy-legend-title {
  font-family: 'Inter', sans-serif;
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--ink3);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  flex-basis: 100%;
  margin-bottom: 4px;
}
.leg-item { display: flex; align-items: center; gap: 6px; font-family: 'Inter', sans-serif; font-size: 0.68rem; color: var(--ink2); }
.leg-swatch {
  font-family: 'Inter', sans-serif;
  font-size: 0.58rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
}
.ga-formula-banner {
  background: linear-gradient(135deg, #f6f8fa 0%, #ffffff 100%);
  border: 1px solid var(--border);
  border-left: 4px solid var(--blue);
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 16px;
}
.ga-formula-banner h3 {
  font-family: 'Inter', sans-serif;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 10px;
  letter-spacing: 0.02em;
}
.formula-line {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  color: var(--ink2);
  padding: 4px 0;
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.formula-line .op { color: var(--ink3); }
.formula-line .term { font-weight: 600; color: var(--ink); }
.formula-line .def { color: var(--ink3); font-size: 0.62rem; }
.formula-note { margin-top: 10px; font-family: 'Inter', sans-serif; font-size: 0.68rem; color: var(--ink3); line-height: 1.6; }

/* ── CLASS A / ICI RATE PANEL ───────────────────────────────── */
.rate-grid {
  display: grid;
  grid-template-columns: 52px repeat(12, 1fr) 58px;
  gap: 2px;
  min-width: 600px;
}
.rate-total {
  height: 34px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.58rem;
  font-weight: 600;
  color: var(--ink2);
  background: var(--surface2);
}
.rate-hd {
  font-family: 'Inter', sans-serif;
  font-size: 0.6rem;
  color: var(--ink3);
  text-align: center;
  padding-bottom: 4px;
  font-weight: 600;
}
.rate-yr {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--ink2);
  display: flex;
  align-items: center;
}
.rate-cell {
  height: 34px;
  border-radius: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.58rem;
  font-weight: 500;
  transition: transform 0.08s, filter 0.08s;
  position: relative;
}
.rate-cell:hover { transform: scale(1.1); filter: brightness(1.15); z-index: 5; }
.rate-cell.rc0 { background: #ddf4ff; color: #0969da; }
.rate-cell.rc1 { background: #0550ae22; color: #0550ae; }
.rate-cell.rc2 { background: #0550ae55; color: #fff; }
.rate-cell.rc3 { background: #0550ae99; color: #fff; }
.rate-cell.rc4 { background: #0550aedd; color: #fff; }
.rate-cell.rc5 { background: #033d8b; color: #fff; }
.rate-cell.rcneg { background: #fff0ee; color: var(--red); }
.rate-legend { display: flex; gap: 12px; margin-top: 10px; flex-wrap: wrap; }
.rate-leg { display: flex; align-items: center; gap: 5px; font-family: 'Inter', sans-serif; font-size: 0.62rem; color: var(--ink3); }
.rate-swatch { width: 10px; height: 10px; border-radius: 2px; }

/* peak table */
.peak-table { width: 100%; border-collapse: collapse; font-family: 'JetBrains Mono', monospace; font-size: 0.68rem; }
.peak-table th { text-align: left; padding: 6px 10px; background: var(--surface2); color: var(--ink3); font-family: 'Inter', sans-serif; font-size: 0.6rem; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; border-bottom: 1px solid var(--border); }
.peak-table td { padding: 7px 10px; border-bottom: 1px solid var(--border2); color: var(--ink2); vertical-align: middle; }
.peak-table tr:last-child td { border-bottom: none; }
.peak-table tr:hover td { background: var(--surface2); }
.peak-rank { font-weight: 700; color: var(--blue); }
.peak-avg-row td { font-weight: 700; color: var(--ink); background: var(--surface2) !important; border-top: 1px solid var(--border); }
.bp-select-strip { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.bp-btn { padding: 5px 12px; border-radius: 5px; border: 1px solid var(--border); background: var(--surface); color: var(--ink2); font-family: 'Inter', sans-serif; font-size: 0.68rem; font-weight: 500; cursor: pointer; transition: all 0.12s; }
.bp-btn:hover { background: var(--surface2); color: var(--ink); }
.bp-btn.active { background: rgba(9,105,218,0.08); color: var(--blue); border-color: var(--blue); font-weight: 600; }

/* ICI calculator */
.calc-wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media(max-width:700px){ .calc-wrap{ grid-template-columns:1fr; } }
.calc-inputs { display: flex; flex-direction: column; gap: 14px; }
.calc-field label { display: block; font-family: 'Inter', sans-serif; font-size: 0.65rem; font-weight: 700; color: var(--ink3); text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: 6px; }
.calc-field input, .calc-field select { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 6px; font-family: 'JetBrains Mono', monospace; font-size: 0.78rem; color: var(--ink); background: var(--surface); outline: none; transition: border-color 0.12s, box-shadow 0.12s; }
.calc-field input:focus, .calc-field select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(9,105,218,0.1); }
.calc-note { font-family: 'Inter', sans-serif; font-size: 0.67rem; color: var(--ink3); margin-top: 5px; line-height: 1.55; }
.calc-results { }
.calc-monthly-table { width: 100%; border-collapse: collapse; font-family: 'JetBrains Mono', monospace; font-size: 0.68rem; }
.calc-monthly-table th { text-align: left; padding: 6px 8px; background: var(--surface2); color: var(--ink3); font-family: 'Inter', sans-serif; font-size: 0.6rem; letter-spacing: 0.07em; text-transform: uppercase; border-bottom: 1px solid var(--border); font-weight: 700; }
.calc-monthly-table td { padding: 5px 8px; border-bottom: 1px solid var(--border2); color: var(--ink2); }
.calc-monthly-table td.amt { color: var(--ink); font-weight: 600; }
.calc-monthly-table td.neg { color: var(--red); }
.calc-monthly-table tr.annual-row td { font-weight: 700; color: var(--ink); background: var(--surface2); border-top: 2px solid var(--border); font-size: 0.72rem; }
.calc-kpi-strip { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.calc-kpi { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; box-shadow: var(--shadow-sm); }
.calc-kpi-label { font-family: 'Inter', sans-serif; font-size: 0.6rem; font-weight: 700; color: var(--ink3); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 5px; }
.calc-kpi-value { font-family: 'JetBrains Mono', monospace; font-size: 0.92rem; font-weight: 700; color: var(--blue); }
.formula-box { background: var(--surface2); border: 1px solid var(--border); border-left: 3px solid var(--blue); border-radius: 6px; padding: 10px 14px; font-family: 'JetBrains Mono', monospace; font-size: 0.67rem; color: var(--ink2); line-height: 1.8; margin-bottom: 14px; }
.formula-box strong { color: var(--ink); }
.rate-trend-wrap { position: relative; height: 280px; }
.denom-change-marker { position: absolute; top: 0; width: 1px; background: var(--amber); opacity: 0.6; pointer-events: none; }
.export-btn {
  padding: 8px 18px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink2);
  font-family: 'Inter', sans-serif;
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.01em;
}
.export-btn:hover { background: var(--surface2); color: var(--ink); border-color: var(--ink3); }

/* ── MONTH×HOUR HEATMAP ─────────────────────────────────────── */
.mh-grid {
  display: grid;
  gap: 3px;
  margin-top: 4px;
}
.mh-label {
  font-family: 'Inter', sans-serif;
  font-size: 0.6rem;
  color: var(--ink3);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 6px;
  font-weight: 600;
}
.mh-col-label {
  font-family: 'Inter', sans-serif;
  font-size: 0.62rem;
  color: var(--ink3);
  text-align: center;
  font-weight: 600;
  padding-bottom: 3px;
}
.mh-cell {
  height: 36px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  font-weight: 700;
  cursor: default;
  transition: filter 0.1s;
  position: relative;
}
.mh-cell:hover { filter: brightness(1.15); z-index: 5; }
.mh-cell.mh0  { background: var(--surface2); color: var(--ink3); border: 1px dashed var(--border); font-weight: 400; }
.mh-cell.mh1  { background: #ddf4ff; color: #0969da; }
.mh-cell.mh2  { background: #9ecbff; color: #0550ae; }
.mh-cell.mh3  { background: #54aeff; color: #fff; }
.mh-cell.mh4  { background: #0969da; color: #fff; }
.mh-cell.mh5  { background: #033d8b; color: #fff; }
.mh-legend-strip { display: flex; gap: 8px; margin-top: 8px; align-items: center; flex-wrap: wrap; }
.mh-leg-item { display: flex; align-items: center; gap: 4px; font-family: 'Inter', sans-serif; font-size: 0.6rem; color: var(--ink3); }
.mh-leg-swatch { width: 12px; height: 12px; border-radius: 2px; }

/* ── CARD ───────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 20px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.card-head {
  padding: 13px 18px;
  border-bottom: 1px solid var(--border2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
}
.card-title {
  font-family: 'Inter', sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink);
}
.card-sub {
  font-family: 'Inter', sans-serif;
  font-size: 0.65rem;
  color: var(--ink3);
}
.card-body { padding: 20px; }
.chart-export {
  margin-left: auto;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink3);
  border-radius: 5px;
  padding: 1px 8px 3px;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s;
  flex-shrink: 0;
}
.chart-export:hover { color: var(--blue); border-color: var(--blue); }

.g2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media(max-width:800px){ .g2{ grid-template-columns:1fr; } }

/* ── STATUS GRID (hero) ─────────────────────────────────────── */
.sg-table {
  display: grid;
  grid-template-columns: 44px repeat(12, 1fr);
  gap: 2px;
  min-width: 560px;
}
.sg-hd {
  font-family: 'Inter', sans-serif;
  font-size: 0.6rem;
  color: var(--ink3);
  text-align: center;
  padding-bottom: 4px;
  font-weight: 600;
}
.sg-yr {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--ink2);
  display: flex;
  align-items: center;
}
.sg-cell {
  height: 32px;
  border-radius: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.55rem;
  font-weight: 500;
  transition: transform 0.08s, filter 0.08s;
  color: var(--ink);
  position: relative;
}
.sg-cell:hover { transform: scale(1.1); filter: brightness(1.08); z-index: 5; }
.sg-cell.neg { font-weight: 600; }

/* Display value inside cell */
.sg-cell::before {
  content: attr(data-val);
  font-size: 0.62rem;
  font-weight: 600;
}

/* value bands — light sequential blue ramp (matches rate grid & mh heatmap) */
.v0 { background: var(--red-bg); color: var(--red); }   /* negative */
.v1 { background: #ddf4ff; color: #0969da; }
.v2 { background: #9ecbff; color: #0550ae; }
.v3 { background: #54aeff; color: #ffffff; }
.v4 { background: #0969da; color: #ffffff; }
.v5 { background: #033d8b; color: #ffffff; }
.sg-no-data {
  background-color: var(--surface2);
  background-image: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 4px,
    rgba(0,0,0,0.035) 4px,
    rgba(0,0,0,0.035) 8px
  );
  color: var(--ink3);
  cursor: default;
}
.sg-no-data:hover { transform: none; filter: none; }

.sg-legend {
  display: flex;
  gap: 12px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.sg-leg {
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: 'Inter', sans-serif;
  font-size: 0.62rem;
  color: var(--ink3);
}
.sg-swatch {
  width: 10px; height: 10px;
  border-radius: 2px;
}

/* cell hover tooltip */
.sg-tip {
  position: fixed;
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.68rem;
  line-height: 1.65;
  color: var(--ink);
  pointer-events: none;
  z-index: 9999;
  box-shadow: var(--shadow-md);
  min-width: 160px;
}
.sg-tip strong { color: var(--ink); display: block; margin-bottom: 2px; }
.sg-tip .tip-val { font-size: 1rem; font-weight: 600; }
.sg-tip .tip-pos { color: var(--green); }
.sg-tip .tip-neg { color: var(--red); }

/* ── CONTROLS ───────────────────────────────────────────────── */
.ctrl-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-bottom: 14px;
  padding: 9px 12px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 6px;
}
.ctrl-lbl {
  font-family: 'Inter', sans-serif;
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--ink3);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.ytog {
  padding: 2px 10px;
  border-radius: 4px;
  border: 1px solid;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.62rem;
  font-weight: 500;
  cursor: pointer;
  background: var(--surface);
  transition: opacity 0.12s;
  color: var(--ink);
}
.ytog.off { opacity: 0.25; }
.sld-grp { display: flex; align-items: center; gap: 6px; }
.sld-v {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink);
  min-width: 36px;
  text-align: center;
}
input[type=range] { accent-color: var(--blue); width: 80px; cursor: pointer; }
.yr-sel {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 6px;
  background: var(--surface);
  cursor: pointer;
  outline: none;
}
.yr-sel:focus { border-color: var(--blue); }
.yr-count {
  font-family: 'Inter', sans-serif;
  font-size: 0.62rem;
  color: var(--ink3);
  margin-left: 4px;
}

/* ── INSIGHT CHIP ───────────────────────────────────────────── */
.insight {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: 6px;
  font-family: 'Inter', sans-serif;
  font-size: 0.72rem;
  line-height: 1.55;
}
.insight.r { background: var(--red-bg); color: #82071e; border: 1px solid #ffc1bd; }
.insight.g { background: var(--green-bg); color: #1a4f2a; border: 1px solid #a8f0b5; }
.insight.a { background: var(--amber-bg); color: #5a3e00; border: 1px solid #e8cd6a; }
.insight::before { content: '●'; font-size: 0.42rem; margin-top: 4px; flex-shrink: 0; opacity: 0.7; }

@media(max-width:640px){
  .body-wrap { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; border-right: none; border-bottom: 1px solid var(--border); padding: 8px 12px; gap: 4px; flex-wrap: wrap; overflow: visible; }
  .sidebar-item { width: auto; font-size: 0.72rem; padding: 5px 10px; }
  .subtabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .nav-brand-sub, .nav-brand-sep { display: none; }
}

/* ── LIVE MARKET VIEW ─────────────────────────────────────────── */
.live-badge {
  margin-left: auto;
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: #fff;
  background: #cf222e;
  border-radius: 3px;
  padding: 2px 5px;
  flex-shrink: 0;
}
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}
/* Large hero KPI cards (live market). Child selectors are scoped to
   .kpi-card so they don't override the small .kpi-strip cell styles
   defined above — both components share child class names. */
.kpi-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}
/* Corner badge carrying the tile's unique context (price condition / Class A %). */
.kpi-badge {
  position: absolute;
  top: 13px;
  right: 14px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: 'Inter', sans-serif;
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--ink2);
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}
.kpi-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
  border-color: var(--border2);
}
/* Tabular figures everywhere numbers appear, so digits align column-to-column. */
.kpi-value, .kpi-var, .kpi-sub, .lm-chip, .lm-tt-val, .lm-tt-lbl { font-variant-numeric: tabular-nums; }
/* Keyboard focus rings (mouse clicks stay ringless via :focus-visible). */
.subtab:focus-visible, .sidebar-item:focus-visible, .nav-refresh:focus-visible,
.chart-export:focus-visible, .lm-reset-btn:focus-visible, .lm-legend-item:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
  border-radius: 5px;
}
@media (prefers-reduced-motion: reduce) {
  .kpi-card, .kpi-card:hover { transition: none; transform: none; }
}
.kpi-card .kpi-label {
  font-family: 'Inter', sans-serif;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink3);
  margin-bottom: 7px;
}
.kpi-card .kpi-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--ink);
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: -0.02em;
  line-height: 1;
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}
.kpi-card .kpi-var {
  font-size: 0.85rem;
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0;
  color: var(--ink3);
}
.kpi-card .kpi-var.up   { color: var(--green); }
.kpi-card .kpi-var.down { color: var(--red); }
.kpi-card .kpi-var.over  { color: var(--red); }
.kpi-card .kpi-var.under { color: var(--green); }
.kpi-card .kpi-var-ref {
  color: var(--ink3);
  font-weight: 400;
  font-size: 0.72rem;
}
.kpi-spark {
  height: 26px;
  margin-top: 8px;
  line-height: 0;
}
.kpi-spark svg { display: block; }
.kpi-card .kpi-sub {
  font-size: 0.65rem;
  color: var(--ink3);
  margin-top: 6px;
  font-family: 'Inter', sans-serif;
}

/* ── Live Market — conditional alert (hidden unless something is noteworthy) ── */
.lm-alert {
  display: none;               /* JS flips to flex only when there's an alert */
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin: -6px 0 18px;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: 8px;
  font-family: 'Inter', sans-serif;
  font-size: 0.74rem;
  color: var(--ink);
}
.lm-alert-icon { font-size: 0.85rem; line-height: 1; }
.lm-alert-msg b { font-weight: 700; font-variant-numeric: tabular-nums; }
.lm-alert--crit { background: var(--red-bg);   border-color: var(--red);   border-left-color: var(--red);   color: var(--red); }
.lm-alert--warn { background: var(--amber-bg); border-color: var(--amber); border-left-color: var(--amber); color: var(--amber); }
.lm-alert--info { background: var(--surface);  border-left-color: var(--blue); color: var(--ink2); }
.lm-alert--crit .lm-alert-msg b, .lm-alert--warn .lm-alert-msg b { color: inherit; }
.lm-stat-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.lm-stat-sep { color: var(--border); }
@media(max-width:640px){
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
}

/* ── Live Market — stacked panels ──────────────────────────── */
#lm-panels { cursor: crosshair; }
.lm-panel { position: relative; }
.lm-foot {
  font-family: 'Inter', sans-serif;
  font-size: 0.62rem;
  color: var(--ink3);
  margin-top: 8px;
  text-align: center;
}

/* ── Live Market — header status chips ─────────────────────── */
.lm-head-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-left: auto;
}
.lm-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}
.lm-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: 'Inter', sans-serif;
  font-size: 0.62rem;
  color: var(--ink2);
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 999px;
  padding: 2px 9px;
  white-space: nowrap;
  line-height: 1.5;
}
.lm-chip b { font-weight: 600; color: var(--ink); }
.lm-chip-state { color: var(--ink3); }
.lm-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ink3); flex-shrink: 0; }
.lm-chip--live .lm-dot  { background: var(--green); }
.lm-chip--stale { border-color: var(--amber); background: var(--amber-bg); }
.lm-chip--stale .lm-dot { background: var(--amber); }
.lm-chip--stale .lm-chip-state { color: var(--amber); }
.lm-chip--off { opacity: 0.65; }

/* ── Live Market Legend ────────────────────────────────────── */
.lm-legend {
  display: flex;
  justify-content: center;
  gap: 32px;
  flex-wrap: wrap;
  padding: 4px 12px 12px;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  color: var(--ink2);
}
.lm-legend-group {
  display: flex;
  align-items: center;
  gap: 10px;
}
.lm-legend-subtitle {
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.lm-legend-items {
  display: flex;
  gap: 14px;
}
.lm-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  transition: opacity 0.12s;
}
.lm-legend-item span { color: var(--ink2); }

/* ── Live Market — unified crosshair tooltip ──────────────────── */
.lm-tooltip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  min-width: 132px;
  background: var(--chart-tip-bg);
  border: 1px solid var(--chart-tip-border);
  border-radius: 6px;
  padding: 7px 9px;
  box-shadow: var(--shadow-sm);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--chart-tip-body);
}
.lm-tt-head {
  font-weight: 600;
  color: var(--chart-tip-title);
  margin-bottom: 4px;
  font-size: 11px;
}
.lm-tt-row {
  display: flex;
  align-items: center;
  gap: 6px;
  line-height: 1.6;
}
.lm-tt-sw { width: 9px; height: 3px; border-radius: 1px; flex-shrink: 0; }
.lm-tt-lbl { flex: 1; color: var(--chart-tip-body); }
.lm-tt-val { font-weight: 600; color: var(--chart-tip-title); }
.lm-tt-delta { color: var(--ink3); font-size: 10px; padding-left: 15px; }
.lm-tt-gap { height: 5px; }

/* ── Live Market — Reset Zoom Button ──────────────────────── */
.lm-reset-btn {
  font-family: 'Inter', sans-serif;
  font-size: 0.68rem;
  font-weight: 500;
  color: #4B3B9E;
  background: rgba(75,59,158,0.08);
  border: 1px solid rgba(75,59,158,0.25);
  border-radius: 5px;
  padding: 4px 10px;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.4;
}
.lm-reset-btn:hover { background: rgba(75,59,158,0.16); }

/* ── PRINT ──────────────────────────────────────────────────── */
/* Print only the active view's content (good for the Calculator and the
   Base Period reference). Chrome / furniture / controls are hidden. */
@media print {
  .topnav, .alert-bar, .sidebar, .subtabs, .ctrl-strip, .anatomy-nav,
  .chart-export, .nav-refresh, #kpiStrip, .bp-select-strip { display: none !important; }
  .body-wrap { padding-top: 0; display: block; overflow: visible; }
  .content { overflow: visible; padding: 0; }
  .section { display: none !important; }
  .section.active { display: block !important; }
  .panel { display: none !important; }
  .panel.active { display: block !important; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; margin-bottom: 12px; }
  .g2 { display: block; }
  body { background: #fff; color: #000; }
}
