/* ============================================================
   RVM Analysis — Railway-inspired shell
   ============================================================ */

/* Theme tokens. Default theme = railway (deep purple-black). */
:root,
[data-theme="railway"] {
  --bg: #13111c;
  --bg-sunken: #0e0c15;
  --panel: #1a1822;
  --panel-2: #221f2d;
  --hover: #25222f;
  --border: #2a2735;
  --border-strong: #3a3648;
  --text: #e9e7f0;
  --text-mid: #b4b0c1;
  --muted: #6f6a82;
  --accent: #b794f6;
  --accent-strong: #9f7aea;
  --accent-soft: rgba(159, 122, 234, 0.14);
  --accent-ink: #0e0c15;
  --cheap: #2bd47d;
  --cheap-soft: rgba(43, 212, 125, 0.14);
  --rich: #ff6b6b;
  --rich-soft: rgba(255, 107, 107, 0.14);
  --warn: #f6c177;
  --grid-low: #1a1822;
  --grid-high: #9f7aea;
  --plot-grid: #2a2735;
  --plot-paper: #0e0c15;
}

[data-theme="midnight"] {
  --bg: #0a0e1a;
  --bg-sunken: #06080f;
  --panel: #11172a;
  --panel-2: #182039;
  --hover: #1c2542;
  --border: #1f2a44;
  --border-strong: #2d3a5a;
  --text: #e6ecff;
  --text-mid: #aab7d2;
  --muted: #6b779a;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --accent-soft: rgba(14, 165, 233, 0.14);
  --accent-ink: #06080f;
  --cheap: #4ade80;
  --cheap-soft: rgba(74, 222, 128, 0.14);
  --rich: #f87171;
  --rich-soft: rgba(248, 113, 113, 0.14);
  --warn: #fbbf24;
  --grid-low: #11172a;
  --grid-high: #0ea5e9;
  --plot-grid: #1f2a44;
  --plot-paper: #06080f;
}

[data-theme="carbon"] {
  --bg: #0a0a0a;
  --bg-sunken: #050505;
  --panel: #131313;
  --panel-2: #1c1c1c;
  --hover: #222222;
  --border: #262626;
  --border-strong: #383838;
  --text: #f5f5f5;
  --text-mid: #b0b0b0;
  --muted: #707070;
  --accent: #f5a524;
  --accent-strong: #e0911a;
  --accent-soft: rgba(245, 165, 36, 0.13);
  --accent-ink: #050505;
  --cheap: #34d399;
  --cheap-soft: rgba(52, 211, 153, 0.12);
  --rich: #fb7185;
  --rich-soft: rgba(251, 113, 133, 0.13);
  --warn: #fbbf24;
  --grid-low: #131313;
  --grid-high: #e0911a;
  --plot-grid: #262626;
  --plot-paper: #050505;
}

[data-theme="forest"] {
  --bg: #0d1410;
  --bg-sunken: #080d0a;
  --panel: #131c17;
  --panel-2: #1a2620;
  --hover: #1f2d27;
  --border: #243029;
  --border-strong: #324438;
  --text: #e7eee9;
  --text-mid: #aab9af;
  --muted: #6b7c71;
  --accent: #86d29a;
  --accent-strong: #5ab873;
  --accent-soft: rgba(134, 210, 154, 0.12);
  --accent-ink: #080d0a;
  --cheap: #86d29a;
  --cheap-soft: rgba(134, 210, 154, 0.14);
  --rich: #e88c8c;
  --rich-soft: rgba(232, 140, 140, 0.14);
  --warn: #e6c388;
  --grid-low: #131c17;
  --grid-high: #5ab873;
  --plot-grid: #243029;
  --plot-paper: #080d0a;
}

[data-theme="daylight"] {
  --bg: #f4f2eb;
  --bg-sunken: #e6e3d6;
  --panel: #ffffff;
  --panel-2: #f7f5ee;
  --hover: #ece9dd;
  --border: #c8c3b1;
  --border-strong: #a39d87;
  --text: #15130d;
  --text-mid: #45413a;
  --muted: #6d6757;
  --accent: #4f2fd6;
  --accent-strong: #3c1fc4;
  --accent-soft: rgba(79, 47, 214, 0.13);
  --accent-ink: #ffffff;
  --cheap: #1f7d3d;
  --cheap-soft: rgba(31, 125, 61, 0.13);
  --rich: #b5302f;
  --rich-soft: rgba(181, 48, 47, 0.13);
  --warn: #a06f0e;
  --grid-low: #f7f5ee;
  --grid-high: #4f2fd6;
  --plot-grid: #c8c3b1;
  --plot-paper: #ffffff;
}

/* ============================================================
   Base
   ============================================================ */
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
code, .mono, .num { font-family: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace; font-variant-numeric: tabular-nums; }
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
::selection { background: var(--accent-soft); color: var(--text); }

/* ============================================================
   Top bar
   ============================================================ */
.topbar {
  display: flex; align-items: center;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-sunken);
  gap: 6px;
  position: sticky; top: 0; z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--text); padding: 4px 8px; border-radius: 5px; }
.brand:hover { background: var(--hover); }
.brand-mark { color: var(--accent); }
.brand-text { font-weight: 600; font-size: 13px; letter-spacing: -0.01em; }
.crumb-sep { color: var(--muted); padding: 0 2px; }
.crumb-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent; border: 1px solid transparent;
  padding: 4px 10px; border-radius: 5px;
  color: var(--text); font-size: 12.5px;
}
.crumb-btn:hover { background: var(--hover); border-color: var(--border); }
.crumb-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); display: inline-block; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.status-dot.live { background: var(--cheap); box-shadow: 0 0 8px var(--cheap); }
.status-meta {
  display: flex; align-items: center; gap: 6px;
  color: var(--text-mid); font-size: 11.5px;
  padding: 0 10px;
}
.status-meta b { color: var(--text); font-weight: 500; }
.dot-sep { color: var(--muted); }
.icon-btn {
  background: transparent; border: 1px solid var(--border);
  width: 28px; height: 28px; border-radius: 5px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-mid);
}
.icon-btn:hover { background: var(--hover); color: var(--text); border-color: var(--border-strong); }
.btn-ghost {
  background: transparent; border: 1px solid var(--border);
  padding: 5px 10px; border-radius: 5px; font-size: 11.5px;
  color: var(--text);
}
.btn-ghost:hover { background: var(--hover); border-color: var(--border-strong); }
.btn-primary {
  background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent);
  padding: 6px 14px; border-radius: 5px; font-size: 12px; font-weight: 500;
}
.btn-primary:hover { background: var(--accent-strong); }
.key-status { font-family: "Geist Mono", monospace; font-size: 11px; color: var(--text-mid); }

/* Theme popover */
.popover {
  position: absolute; top: 50px; right: 100px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px; z-index: 100;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  min-width: 220px;
}
.popover[hidden] { display: none; }
.popover-title { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 6px 8px 4px; }
.scheme-opt {
  width: 100%; text-align: left; background: transparent; border: none;
  padding: 7px 8px; border-radius: 5px;
  display: flex; align-items: center; gap: 10px;
  font-size: 12px; color: var(--text);
}
.scheme-opt:hover { background: var(--hover); }
.scheme-opt.active { background: var(--accent-soft); color: var(--accent); }
.scheme-opt .opt-meta { margin-left: auto; color: var(--muted); font-size: 10.5px; }
.sw { width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--border-strong); display: inline-block; flex-shrink: 0; }
.sw-railway   { background: linear-gradient(135deg, #13111c 50%, #b794f6 50%); }
.sw-midnight  { background: linear-gradient(135deg, #0a0e1a 50%, #38bdf8 50%); }
.sw-carbon    { background: linear-gradient(135deg, #0a0a0a 50%, #f5a524 50%); }
.sw-forest    { background: linear-gradient(135deg, #0d1410 50%, #86d29a 50%); }
.sw-daylight  { background: linear-gradient(135deg, #f6f5f0 50%, #6b4ee6 50%); }

/* ============================================================
   Tab nav
   ============================================================ */
.tabnav {
  display: flex; align-items: center;
  border-bottom: 1px solid var(--border);
  background: var(--bg-sunken);
  padding: 0 18px;
  height: 38px;
}
.tab {
  background: transparent; border: none;
  height: 38px; padding: 0 14px;
  font-size: 12.5px; color: var(--text-mid);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  position: relative;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tabnav-spacer { flex: 1; }
.filter-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent; border: 1px solid var(--border);
  border-radius: 5px; padding: 4px 10px; font-size: 11.5px;
  color: var(--text-mid);
}
.filter-toggle:hover { background: var(--hover); color: var(--text); }
.filter-toggle.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.filter-count {
  background: var(--accent); color: var(--accent-ink);
  border-radius: 10px; min-width: 16px; height: 16px; padding: 0 5px;
  font-size: 10px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
}

/* Active filters strip */
.active-strip {
  padding: 6px 18px;
  display: flex; gap: 5px; flex-wrap: wrap;
  background: var(--bg-sunken);
  border-bottom: 1px solid var(--border);
  min-height: 0;
}
.active-strip:empty { display: none; }
.active-chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--accent-soft); color: var(--accent);
  padding: 2px 4px 2px 8px; border-radius: 10px;
  font-size: 11px;
  border: 1px solid transparent;
}
.active-chip .x { cursor: pointer; padding: 0 4px; opacity: 0.7; }
.active-chip .x:hover { opacity: 1; }

/* Loading banner — panel-style with accent left stripe */
.banner {
  margin: 10px 18px 0;
  padding: 9px 14px 9px 16px;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  font-size: 12px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 1px 0 rgba(0,0,0,0.04);
}
.banner[hidden] { display: none; }
.banner b { color: var(--text); font-weight: 500; }
.banner.error { border-left-color: var(--rich); background: var(--rich-soft); color: var(--text); }
.banner.error .banner-spinner { display: none; }
.banner.error::before {
  content: "!"; font-family: "Geist Mono", monospace; font-weight: 600;
  width: 16px; height: 16px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--rich); color: var(--accent-ink);
  font-size: 11px;
}
.banner a { color: var(--accent); text-decoration: underline; font-weight: 500; }
.banner-spinner {
  width: 12px; height: 12px; border-radius: 50%;
  border: 1.5px solid var(--accent); border-top-color: transparent;
  animation: spin 0.8s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   Shell: rail + main
   ============================================================ */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: calc(100vh - 78px); }
.shell.rail-hidden { grid-template-columns: 0 1fr; }
.shell.rail-hidden .rail { transform: translateX(-100%); border-right-color: transparent; }

.rail {
  background: var(--bg-sunken);
  border-right: 1px solid var(--border);
  padding: 14px 14px 30px;
  overflow-y: auto;
  max-height: calc(100vh - 78px);
  position: sticky; top: 78px;
  transition: transform 0.15s;
}
.rail-section { margin-bottom: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.rail-section:last-child { border-bottom: none; }
/* Accordion variant for less-used filter sections */
.rail-accordion { padding-bottom: 8px; }
.rail-accordion > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; justify-content: space-between;
}
.rail-accordion > summary::-webkit-details-marker { display: none; }
.rail-accordion .rail-accordion-chevron {
  color: var(--muted); font-size: 9px; transition: transform 0.15s;
}
.rail-accordion[open] .rail-accordion-chevron { transform: rotate(180deg); }
.rail-accordion[open] { padding-bottom: 14px; }
.rail-accordion[open] > summary { margin-bottom: 8px; }
.rail-h {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin-bottom: 8px; font-weight: 500;
}
.rail-val { color: var(--text); font-family: "Geist Mono", monospace; text-transform: none; letter-spacing: 0; font-weight: 400; }
.rail-add {
  background: transparent; border: 1px dashed var(--border-strong);
  color: var(--text-mid); padding: 1px 7px; border-radius: 10px; font-size: 10.5px;
}
.rail-add:hover { color: var(--accent); border-color: var(--accent); }
.rail-input {
  width: 100%; background: var(--panel); border: 1px solid var(--border);
  padding: 6px 9px; border-radius: 5px; font-size: 12px; color: var(--text);
  outline: none;
}
.rail-input:focus { border-color: var(--accent); }

/* Range slider (dual-thumb) */
.range-track { position: relative; height: 22px; margin: 4px 4px 8px; }
.range-track::before {
  content: ""; position: absolute; left: 0; right: 0; top: 10px; height: 2px;
  background: var(--border-strong); border-radius: 2px;
}
.range-track input {
  position: absolute; width: 100%; pointer-events: none;
  -webkit-appearance: none; appearance: none; background: transparent;
  top: 4px; height: 14px; margin: 0;
}
.range-track input::-webkit-slider-thumb {
  -webkit-appearance: none; pointer-events: auto;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 2px solid var(--bg-sunken);
  box-shadow: 0 0 0 1px var(--accent);
}
.range-track input::-moz-range-thumb {
  pointer-events: auto;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 2px solid var(--bg-sunken);
  box-shadow: 0 0 0 1px var(--accent);
}
.single-range {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 14px; background: transparent; margin: 4px 0 10px;
}
.single-range::-webkit-slider-runnable-track {
  height: 2px; background: var(--border-strong); border-radius: 2px;
}
.single-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); margin-top: -6px;
  border: 2px solid var(--bg-sunken); box-shadow: 0 0 0 1px var(--accent);
}
.single-range::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg-sunken);
}

/* Segmented control */
.seg {
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 5px; padding: 2px; gap: 2px;
}
.seg-btn {
  background: transparent; border: none;
  padding: 4px 4px; font-size: 11px; color: var(--text-mid);
  border-radius: 4px; cursor: pointer; transition: background 0.1s, color 0.1s;
}
.seg-btn:hover { color: var(--text); background: var(--hover); }
.seg-btn.active { background: var(--accent); color: var(--accent-ink); }

/* Rail hint copy */
.rail-hint {
  font-size: 10.5px; color: var(--muted);
  margin-top: 6px; line-height: 1.4;
}

/* Chips */
.chip-row { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 11px; font-size: 11px; cursor: pointer; user-select: none;
  color: var(--text-mid); transition: background 0.1s, color 0.1s, border 0.1s;
}
.chip:hover { background: var(--hover); color: var(--text); }
.chip.active {
  background: var(--accent-soft); color: var(--accent); border-color: var(--accent);
}
.chip.dismiss .x { color: currentColor; margin-left: 2px; cursor: pointer; font-size: 13px; line-height: 1; opacity: 0.65; }
.chip.dismiss .x:hover { opacity: 1; }

/* Country picker dropdown */
#country-list {
  position: absolute; background: var(--panel); border: 1px solid var(--border);
  border-radius: 5px; max-height: 240px; overflow-y: auto; min-width: 200px;
  z-index: 100; box-shadow: 0 6px 24px rgba(0,0,0,0.4);
}
#country-list input {
  background: var(--panel-2); border: none; border-bottom: 1px solid var(--border);
  padding: 7px 10px; font-size: 12px; width: 100%; outline: none; color: var(--text);
}
#country-list .opt {
  padding: 5px 10px; cursor: pointer; font-size: 12px;
  display: flex; justify-content: space-between; color: var(--text);
}
#country-list .opt:hover { background: var(--hover); color: var(--accent); }
#country-list .opt .count { color: var(--muted); font-family: "Geist Mono", monospace; font-size: 10.5px; }

/* ============================================================
   Main content / pages
   ============================================================ */
.main { padding: 22px 26px 40px; overflow-x: hidden; min-width: 0; }
.page { display: none; }
.page.active { display: block; }
.page-h { margin-bottom: 18px; }
.page-h h2 { margin: 0 0 4px; font-size: 19px; font-weight: 600; letter-spacing: -0.01em; }
.page-sub { margin: 0; color: var(--text-mid); font-size: 12.5px; max-width: 760px; }

/* Card primitive */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.card-h {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 14px 9px;
  border-bottom: 1px solid var(--border);
}
.card-h h3 {
  margin: 0; font-size: 12px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-mid);
}
.card-h h3.cheap-h { color: var(--cheap); }
.card-h h3.rich-h { color: var(--rich); }
.badge {
  background: var(--panel-2); color: var(--text-mid);
  border: 1px solid var(--border);
  padding: 1px 7px; border-radius: 9px; font-size: 10.5px;
  font-family: "Geist Mono", monospace;
}

/* KPI tiles — compact variant default */
.kpi-grid {
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px; margin-bottom: 16px;
}
@media (max-width: 1200px) { .kpi-grid { grid-template-columns: repeat(3, 1fr); } }
.kpi {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 7px; padding: 9px 11px;
  position: relative; overflow: hidden;
}
.kpi::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 2px;
  background: var(--accent); opacity: 0.7;
}
.kpi.accent-cheap::before { background: var(--cheap); }
.kpi.accent-rich::before { background: var(--rich); }
.kpi-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.kpi-val {
  font-size: 18px; font-weight: 600; margin: 2px 0 2px;
  font-family: "Geist Mono", monospace; letter-spacing: -0.01em;
  color: var(--text); line-height: 1.1;
}
.kpi.accent-cheap .kpi-val { color: var(--cheap); }
.kpi.accent-rich .kpi-val { color: var(--rich); }
.kpi-foot { font-size: 10.5px; color: var(--text-mid); line-height: 1.3; }
.kpi-divider { color: var(--muted); margin: 0 3px; font-weight: 300; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Card link (e.g. "Open full chart -&gt;") */
.card-link {
  font-size: 11px; color: var(--accent); text-decoration: none;
  text-transform: none; letter-spacing: 0; font-weight: 500;
}
.card-link:hover { text-decoration: underline; }

/* Overview: chart on the left (wide), KPI column on the right (narrow).
   On narrow viewports both stack and KPIs go back to a horizontal grid. */
.overview-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 240px;
  gap: 12px;
  margin-bottom: 14px;
  align-items: stretch;
}
@media (max-width: 1100px) {
  .overview-top { grid-template-columns: 1fr; }
}
.overview-scatter-card { display: flex; flex-direction: column; min-height: 480px; }
#overview-scatter { width: 100%; flex: 1; min-height: 420px; }
/* Vertical KPI column variant — single column, full-height tiles */
.kpi-vertical {
  display: flex; flex-direction: column; gap: 8px;
  grid-template-columns: none;
}
.kpi-vertical .kpi { padding: 10px 12px; }
@media (max-width: 1100px) {
  .kpi-vertical { display: grid; grid-template-columns: repeat(3, 1fr); }
}

/* RVM grid page — help line + layout */
.grid-help {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 14px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 7px; padding: 8px 12px; margin-bottom: 12px;
  font-size: 11px; color: var(--text-mid);
}
.kbd-hint { display: inline-flex; align-items: center; gap: 6px; }
.kbd {
  font-family: "Geist Mono", monospace; font-size: 10px;
  background: var(--bg-sunken); border: 1px solid var(--border);
  border-radius: 3px; padding: 2px 6px;
  color: var(--text);
}
.grid-clear {
  margin-left: auto;
  background: transparent; border: 1px solid var(--border);
  color: var(--text-mid); padding: 3px 10px;
  border-radius: 4px; font-size: 11px;
}
.grid-clear:hover { color: var(--accent); border-color: var(--accent); }

.grid-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
}
@media (max-width: 1100px) {
  .grid-layout { grid-template-columns: 1fr; }
  /* On narrow, stack with the live preview ABOVE the grid heatmap
     so the user always sees the scatter feedback as they filter. */
  .grid-inline-card { order: -1; }
}
.grid-inline-card { padding: 0; display: flex; flex-direction: column; }
/* Chart fills the card so both grid + preview cards share visual height */
#grid-inline-scatter { width: 100%; flex: 1; min-height: 460px; padding: 6px 10px 10px; }

/* Range-band overlay on the grid (drag-select highlight) */
#grid-table td.cell.band {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
#grid-table td.cell.highlight {
  outline: 2px solid var(--warn);
  outline-offset: -2px;
  box-shadow: inset 0 0 0 2px var(--warn);
}

/* Two-column layout */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 980px) { .two-col { grid-template-columns: 1fr; } }

/* Data tables */
.table-wrap { max-height: 360px; overflow-y: auto; }
.table-wrap.tall { max-height: calc(100vh - 320px); }
.data-table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.data-table th {
  position: sticky; top: 0; z-index: 1;
  background: var(--panel); text-align: left;
  padding: 7px 10px; color: var(--muted); font-weight: 500;
  border-bottom: 1px solid var(--border);
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.04em;
}
.data-table td {
  padding: 6px 10px; border-bottom: 1px solid var(--border);
  cursor: pointer; color: var(--text-mid);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--hover); color: var(--text); }
.data-table tr.selected td { background: var(--accent-soft); color: var(--accent); }
.data-table .num { text-align: right; font-family: "Geist Mono", monospace; }
.data-table .bond-cell { color: var(--text); max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cheap-cell { color: var(--cheap); font-weight: 500; }
.rich-cell { color: var(--rich); font-weight: 500; }
.held-star { color: var(--warn); margin-right: 4px; }

/* Opp toolbar */
.opp-toolbar {
  display: flex; align-items: center; gap: 10px; margin-bottom: 10px;
}
.toolbar-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted);
}

/* Grid page */
.grid-card { padding: 14px 16px; }
#grid-table { border-collapse: collapse; width: 100%; font-size: 10.5px; font-variant-numeric: tabular-nums; }
#grid-table th, #grid-table td { padding: 3px 6px; text-align: right; cursor: pointer; line-height: 1.2; }
#grid-table th:first-child, #grid-table td:first-child { text-align: left; color: var(--text-mid); font-weight: 500; padding-right: 14px; }
#grid-table th {
  font-weight: 500; color: var(--muted); border-bottom: 1px solid var(--border);
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.04em;
}
#grid-table tr.rating-row td:first-child { color: var(--accent); font-family: "Geist Mono", monospace; }
#grid-table td.cell {
  font-family: "Geist Mono", monospace;
  border: 1px solid transparent;
  transition: border 0.1s;
}
#grid-table td.cell:hover { border-color: var(--accent); }
#grid-table td.cell.in-range { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

/* Scatter / drill-in cards */
.chart-card { padding: 14px; }
/* Main + drill-in scatters fill the available viewport height so they
   don't sit in a fixed 560px box with empty space below. The min-height
   stays generous so very tall windows or narrow phones don't degrade. */
#scatter { width: 100%; height: calc(100vh - 240px); min-height: 480px; }
#drillin { width: 100%; height: calc(100vh - 360px); min-height: 380px; margin-top: 10px; }

/* Bond-detail: chart left / credit-profile right. Collapses to one column on narrow screens. */
.detail-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  align-items: stretch;
}
.detail-split .chart-card,
.detail-split .summary-card {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.detail-split #drillin {
  height: calc(100vh - 360px);
  min-height: 380px;
  flex: 1;
}
@media (max-width: 1100px) {
  .detail-split { grid-template-columns: 1fr; }
  .detail-split #drillin { height: 520px; }
}

.summary-card { padding: 16px 18px; overflow-y: auto; max-height: calc(100vh - 320px); }
.summary-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border, rgba(255,255,255,0.08));
}
.summary-title { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-mid, #888); }
.summary-meta { font-size: 11px; color: var(--text-mid, #888); }
.summary-meta.stale { color: var(--rich, #c47); }
.summary-empty { color: var(--text-mid, #888); font-size: 13px; padding: 24px 0; text-align: center; }
.summary-body { font-size: 13px; line-height: 1.55; color: var(--text, #ddd); }
.summary-body h4 { margin: 14px 0 6px 0; font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--accent, #6cf); font-weight: 600; }
.summary-body h4:first-child { margin-top: 0; }
.summary-body p { margin: 0 0 10px 0; }
.summary-body ul { margin: 0 0 10px 18px; padding: 0; }
.summary-body li { margin: 3px 0; }
.summary-body strong { color: var(--text, #fff); }
.summary-loading { color: var(--text-mid, #888); font-size: 13px; padding: 24px 0; text-align: center; font-style: italic; }
.summary-error { color: var(--rich, #c47); font-size: 12px; padding: 12px 0; }
.summary-sources { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--border, rgba(255,255,255,0.08)); font-size: 11px; color: var(--text-mid, #888); }
.summary-sources .src-label { text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 4px; }
.summary-sources a { color: var(--accent, #6cf); text-decoration: none; margin-right: 8px; }
.summary-sources a:hover { text-decoration: underline; }

/* Bond detail card */
.bond-card {
  display: grid; grid-template-columns: 1fr auto; gap: 24px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 16px 18px; margin-bottom: 12px;
}
.bond-card-isin { font-family: "Geist Mono", monospace; font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.bond-card-desc { font-size: 17px; font-weight: 600; color: var(--text); margin-bottom: 6px; letter-spacing: -0.01em; }
.bond-meta-row { display: flex; gap: 14px; flex-wrap: wrap; color: var(--text-mid); font-size: 12px; }
.bond-meta-row span { display: inline-flex; align-items: center; gap: 4px; }
.bond-meta-row b { color: var(--text); font-weight: 500; }
.bond-card-stats { display: flex; gap: 18px; align-items: flex-start; }
.stat { text-align: right; }
.stat-lbl { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.stat-val { font-family: "Geist Mono", monospace; font-size: 16px; color: var(--text); font-weight: 500; margin-top: 2px; }
.stat-val.cheap { color: var(--cheap); }
.stat-val.rich { color: var(--rich); }

/* Empty state */
.empty-state {
  padding: 60px 20px; text-align: center;
  color: var(--text-mid);
  background: var(--panel); border: 1px dashed var(--border);
  border-radius: 8px;
}
.empty-state svg { color: var(--muted); margin-bottom: 12px; }
.empty-state > div:nth-of-type(1) { font-size: 14px; color: var(--text); margin-bottom: 4px; }
.empty-hint { font-size: 11.5px; color: var(--muted); }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 22px; min-width: 440px; max-width: 540px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
}
.modal h2 { margin: 0 0 4px; font-size: 14px; font-weight: 600; }
.modal p { margin: 0 0 12px; color: var(--text-mid); font-size: 12px; }
.modal p code { background: var(--bg-sunken); padding: 1px 5px; border-radius: 3px; color: var(--accent); font-size: 11px; }
.modal input {
  width: 100%; padding: 8px 10px; background: var(--bg-sunken);
  border: 1px solid var(--border); border-radius: 5px; font-family: "Geist Mono", monospace;
  font-size: 12px; outline: none;
}
.modal input:focus { border-color: var(--accent); }
.modal-actions { margin-top: 14px; display: flex; gap: 8px; justify-content: flex-end; }

/* ============================================================
   v3: Bond Detail hero · Quick views · Empty state polish
   ============================================================ */

/* Overview: Quick views chip strip above the chart/KPI block */
.quickviews {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  margin: 0 0 14px;
  padding: 8px 10px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 7px;
}
.quickviews-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin-right: 4px; padding-left: 4px;
}
.quickview {
  background: var(--bg-sunken); border: 1px solid var(--border);
  color: var(--text-mid);
  padding: 4px 10px; border-radius: 11px; font-size: 11.5px;
  cursor: pointer; transition: background 0.1s, color 0.1s, border 0.1s;
  display: inline-flex; align-items: center; gap: 4px;
}
.quickview:hover { color: var(--text); background: var(--hover); border-color: var(--border-strong); }
.quickview.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.quickview .qv-star { color: var(--warn); }

/* Bond Detail: header back button (icon-button variant) */
.detail-header { display: flex; margin-bottom: 4px; }
.detail-back {
  background: transparent; border: 1px solid var(--border);
  color: var(--text-mid);
  padding: 3px 9px 3px 7px; border-radius: 5px; font-size: 11.5px;
  display: inline-flex; align-items: center; gap: 4px; cursor: pointer;
}
.detail-back:hover { color: var(--accent); border-color: var(--accent); }
.detail-back[hidden] { display: none; }

/* Bond hero block: ISIN · name · meta on left, big verdict chip on right */
.bond-hero {
  display: grid; grid-template-columns: 1fr auto; gap: 18px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 18px 22px; margin-bottom: 12px;
  align-items: start;
}
.bond-hero-isin {
  font-family: "Geist Mono", monospace; font-size: 11px;
  color: var(--muted); margin-bottom: 4px;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.bond-hero-name { margin: 0 0 8px; font-size: 24px; font-weight: 600; color: var(--text); letter-spacing: -0.015em; line-height: 1.15; }
.bond-hero-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 12px; color: var(--text-mid); }
.bond-hero-meta span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.bond-hero-meta b { color: var(--text); font-weight: 500; }
.bond-hero-meta .held-tag { color: var(--warn); font-weight: 500; background: transparent; padding: 0; }

.bond-hero-verdict { text-align: right; min-width: 130px; }
.verdict-chip {
  display: inline-flex; align-items: baseline; gap: 4px;
  padding: 9px 16px; border-radius: 9px;
  font-family: "Geist Mono", monospace; font-size: 22px; font-weight: 600;
  letter-spacing: -0.01em; border: 1px solid; line-height: 1;
}
.verdict-chip.cheap { background: var(--cheap-soft); color: var(--cheap); border-color: var(--cheap); }
.verdict-chip.rich  { background: var(--rich-soft);  color: var(--rich);  border-color: var(--rich); }
.verdict-chip.neutral { background: var(--bg-sunken); color: var(--text-mid); border-color: var(--border-strong); }
.verdict-sub { margin-top: 6px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

/* Bond Detail: Today vs Static stat groups */
.bond-stat-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 12px; margin-bottom: 12px; }
@media (max-width: 980px) { .bond-stat-grid { grid-template-columns: 1fr; } }
.stat-group { background: var(--panel); border: 1px solid var(--border); border-radius: 7px; padding: 12px 14px; }
.stat-group-h { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 10px; font-weight: 500; }
.stat-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat-cell { min-width: 0; }
.stat-cell .stat-lbl { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 4px; }
.stat-cell .stat-val { font-family: "Geist Mono", monospace; font-size: 17px; font-weight: 500; color: var(--text); letter-spacing: -0.01em; }
.stat-cell .stat-val.small { font-size: 13px; }
.stat-cell .stat-val.cheap { color: var(--cheap); }
.stat-cell .stat-val.rich { color: var(--rich); }

/* Empty state — richer: bigger SVG, title + hint + CTA row */
.empty-state .empty-svg { color: var(--accent); margin-bottom: 16px; opacity: 0.85; }
.empty-state .empty-title { font-size: 15px; color: var(--text); margin-bottom: 6px; font-weight: 500; }
.empty-state .empty-hint { font-size: 12px; color: var(--muted); max-width: 380px; margin: 0 auto 14px; }
.empty-state .empty-actions { display: flex; gap: 8px; justify-content: center; }

/* Minimal-aesthetic scrollbars — virtually invisible until hover, on every
   scroll container in the app (rail, table wraps, country picker, modals). */
* {
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
}
*:hover { scrollbar-color: var(--border) transparent; }
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 3px;
  transition: background 0.15s;
}
*:hover::-webkit-scrollbar-thumb { background: var(--border); }
*::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }
*::-webkit-scrollbar-corner { background: transparent; }
