/*
 * Design tokens from the "Aperture Screens" Claude Design project: a fixed near-black system (not a
 * light/dark pair) — mint carries every interactive and positive cue, a blue-to-mint ramp marks
 * allocation, and panels sit on #0e1115 with an 18px radius and a 1px border rather than a fill.
 * Manrope for headlines and body text, IBM Plex Mono for figures and labels.
 */
:root {
  color-scheme: dark;
  --bg: #08090B;
  --surface: #0E1115;
  --surface-2: #14181D;
  --border: #1E232A;
  --text: #E8ECEF;
  --text-muted: #7D8790;
  --text-faint: #6E7881;
  --accent: #5FD3A6;
  --accent-hover: #7CE8C4;
  --accent-soft: #17352A;
  --chart-value: #65C9C1;
  --chart-invested: #EB91B0;
  --up: #5FD3A6;
  --down: #FF5D4E;
  --grid: #191D22;
  --shadow: none;
  --tip-shadow: 0 10px 28px -14px rgba(0, 0, 0, 0.8);
  /* Allocation segments, fixed per asset type (never by rank, so a filter never repaints a type). */
  --alloc-etf: #2340D4;
  --alloc-stock: #2F7FE2;
  --alloc-crypto: #7CE8C4;
  --alloc-pension: #46B3DD;
  --alloc-other: #7D8790;
  --font-figure: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-body: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  /* Shared breakpoints (v0.9.3). Media queries can't read custom properties, so every @media at the end
     of this file repeats these literal values: tablet and below = max-width 1024px, mobile = max-width
     600px. Desktop is anything wider than the tablet breakpoint. */
  --bp-tablet: 1024px;
  --bp-mobile: 600px;
  /* Minimum touch target below the tablet breakpoint. */
  --tap-min: 44px;
  --scroll-shade: rgba(0, 0, 0, 0.6);
  /* Scrim behind the portfolio panel while one account syncs (v0.9.4.1). */
  --overlay: rgba(8, 9, 11, 0.8);
}

/* Light theme (v0.9.3.3). The page follows the OS scheme by default; theme.js resolves "system" to a
   concrete data-theme on <html> before first paint, and the top bar toggle sets "light" | "dark" |
   "system". :root carries the dark tokens above; data-theme="light" swaps in the light set. */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #F5F6F7;
  --surface: #FFFFFF;
  --surface-2: #EEF1F3;
  --border: #E1E5E9;
  --text: #1B1F23;
  --text-muted: #5B6470;
  --text-faint: #7A838E;
  --accent: #0FA97C;
  --accent-hover: #0B8B64;
  --accent-soft: #E3F4EE;
  --chart-value: #258F91;
  --chart-invested: #C84C7D;
  --up: #0E9F6E;
  --down: #D6453A;
  --grid: #EDF0F2;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.05);
  --tip-shadow: 0 10px 28px -14px rgba(16, 24, 40, 0.22);
  --alloc-etf: #2340D4;
  --alloc-stock: #2F7FE2;
  --alloc-crypto: #18A57F;
  --alloc-pension: #0E8FC4;
  --alloc-other: #8A939D;
  --scroll-shade: rgba(16, 24, 40, 0.18);
  --overlay: rgba(245, 246, 247, 0.84);
}

/* Base */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { margin: 0; font-family: var(--font-figure); font-weight: 600; }
p { margin: 0; }
code {
  padding: 0 4px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: 0.86em;
}
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Top bar: the brand, then the menu (nav on the left, sync line and log out on the right). Below the
   tablet breakpoint the menu collapses behind .nav-toggle (media queries at the end; app.js toggles it). */
.topbar {
  position: relative;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 36px;
  min-height: 64px;
  padding: 0 40px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-menu { display: flex; flex: 1; align-items: center; justify-content: space-between; gap: 32px; min-width: 0; }
.nav-toggle { display: none; }
.brand {
  display: flex;
  flex: none;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-family: var(--font-figure);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.brand:hover { color: var(--text); }
.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 3px solid #2F3841;
  border-top-color: var(--accent);
  border-right-color: var(--accent);
}
.nav {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  font-family: var(--font-figure);
  font-size: 14px;
}
.nav a { padding: 7px 12px; border-radius: 8px; color: var(--text-muted); font-weight: 500; white-space: nowrap; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.topbar-right { display: flex; flex: none; align-items: center; gap: 14px; }
.sync-line { color: var(--text-faint); font-size: 13px; }
.sync-line:hover { color: var(--text-muted); }
.sync-line.has-error { color: var(--down); }
.logout {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-family: var(--font-figure);
  font-size: 13.5px;
}
.logout:hover { background: var(--surface-2); color: var(--text); }

/* Theme toggle (v0.9.3.3): cycles system → light → dark, injected into the top bar by app.js. */
.theme-toggle {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
}
.theme-toggle:hover { background: var(--surface-2); color: var(--text); }
.theme-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Page and cards */
.page {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 32px 40px 48px;
}
.card {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.card-body { padding: 20px 24px; }
.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 20px 24px 12px;
}
.card-body > .card-head { padding: 0; }
.card-title { font-size: 17px; }
.card-aside { display: inline-flex; align-items: center; gap: 10px; color: var(--text-faint); font-size: 13px; }
/* Benchmark picker in the returns card's header (v0.9.7) */
.benchmark-picker { display: inline-flex; align-items: center; gap: 8px; color: var(--text-faint); font-size: 13px; }
.benchmark-picker select {
  max-width: 240px;
  min-height: 32px;
  padding: 4px 9px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13.5px;
}
.card-link { font-size: 13.5px; font-weight: 600; }
.card-foot { padding: 12px 24px 16px; border-top: 1px solid var(--grid); color: var(--text-muted); font-size: 12.5px; }
/* Positions table period selector (v0.9.8.16): its own row under the card head, as in the reference. */
.positions-periods { padding: 0 24px 12px; }
.card-lead { padding: 0 24px 16px; }
.card-inner { padding: 0 24px 24px; }
.stack { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.stack-sm { display: flex; flex-direction: column; gap: 14px; }
.split { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.split.even { grid-template-columns: repeat(2, minmax(0, 1fr)); }

/* Portfolio page KPIs mirror the 2:1 split below so the card edges line up. */
.portfolio-kpis { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 20px; }
.portfolio-kpis-left { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.portfolio-kpis-right { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; }
.portfolio-kpis .kpi { min-width: 0; }
.lead { max-width: 80ch; color: var(--text-muted); }
.footnote { max-width: 120ch; color: var(--text-faint); font-size: 12.5px; }
.footnote:empty, .meta:empty { display: none; }
.error-banner {
  padding: 12px 16px;
  border: 1px solid var(--down);
  border-radius: 12px;
  background: var(--surface);
  color: var(--down);
  font-weight: 600;
}
.loading { opacity: 0.55; transition: opacity 0.15s; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 20px; align-items: stretch; }
.kpis.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpi {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.kpi-label { color: var(--text-muted); font-size: 13px; font-weight: 600; }
.kpi-value {
  margin-top: 8px;
  font-family: var(--font-figure);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.15;
  overflow-wrap: anywhere;
}
.kpis.three .kpi-value { margin-top: 6px; font-size: 32px; letter-spacing: -0.025em; }
.kpis.dividends .kpi-value { font-size: 28px; }
.kpi-sub { margin-top: 6px; color: var(--text-faint); font-size: 13px; }

/* Net worth hero */
.hero { padding: 26px 28px 18px; }
.hero-top { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 16px 24px; }
.eyebrow { color: var(--text-muted); font-size: 13px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
.hero-value {
  margin-top: 8px;
  font-family: var(--font-figure);
  font-size: 52px;
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.08;
}
.delta { display: flex; align-items: center; gap: 10px; min-height: 30px; margin-top: 12px; }
.delta-label { color: var(--text-muted); font-size: 14px; }

/* Security header (per-security pages) */
.stock-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 20px; }
.stock-head-main { min-width: 0; }
.stock-name { font-size: 34px; }
.stock-head-side { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 24px; }
.stock-stat { min-width: 96px; }

/* Pills and chips */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-family: var(--font-figure);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}
.pill.up, .pill.ok { background: var(--accent-soft); color: var(--up); }
.pill.down, .pill.fail { border-color: var(--border); color: var(--down); }
.pill.muted { border-color: var(--border); border-style: dashed; color: var(--text-muted); }
.pill.small { padding: 2px 8px; font-family: var(--font-body); font-size: 12px; letter-spacing: 0.03em; }
.chip {
  flex: none;
  padding: 0 5px;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-faint);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.run { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; min-width: 0; }

/* Segmented control and tabs */
.segmented {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.segmented button {
  min-height: 30px;
  padding: 6px 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-figure);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--surface); font-weight: 600; }
.tabs { --scroll-cover: var(--bg); display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--border); }
.tabs button {
  margin-bottom: -1px;
  padding: 10px 14px 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--text-muted);
  font-family: var(--font-figure);
  font-size: 14.5px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { border-bottom-color: var(--accent); color: var(--text); font-weight: 600; }

/* Account name cell on the Settings page (portfolios are renamed in its Portfolios card since v0.9.4). */
.account-name { display: flex; align-items: center; gap: 6px; min-width: 0; }

/* Charts */
.chart { position: relative; margin-top: 14px; }
.chart svg { display: block; width: 100%; height: 210px; overflow: visible; touch-action: pan-y; }
.chart.bars svg { height: 224px; }
.chart.bars.compact svg { height: 150px; }
.chart.bars.mini svg { height: 110px; }
.bar-amount.small { font-size: 11px; }
.chart.portfolio-spark { margin-top: 10px; }
.chart svg:focus-visible { outline-offset: 4px; border-radius: 4px; }
.chart-grid { stroke: var(--grid); stroke-width: 1; }
.chart-baseline { stroke: var(--border); stroke-width: 1; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2.25; stroke-linecap: round; stroke-linejoin: round; }
.chart-line.reconstructed { stroke: var(--text-faint); stroke-width: 2; stroke-dasharray: 5 4; }
.chart-line.projected { stroke: var(--accent); stroke-width: 2; stroke-dasharray: 5 4; }
.chart-fill-top { stop-color: var(--accent); stop-opacity: 0.22; }
.chart-fill-bottom { stop-color: var(--accent); stop-opacity: 0; }
.chart-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart-crosshair { stroke: var(--text-faint); stroke-width: 1; }
.chart-ref { stroke: var(--text-faint); stroke-width: 1; stroke-dasharray: 4 4; }
.chart-ref-goal { stroke: var(--accent); stroke-dasharray: 6 4; }
.chart-ref-label { fill: var(--text-faint); font-family: var(--font-body); font-size: 11.5px; }
.chart-ref-label-goal { fill: var(--accent); }
/* Average-per-month line on the dividend bar charts (v0.9.8.16): on top of the bars, not hoverable. */
.chart-avg { pointer-events: none; }
.chart-avg line { stroke: var(--text-faint); stroke-width: 1; stroke-dasharray: 4 4; }
.chart-avg text {
  fill: var(--text);
  font-weight: 600;
  font-family: var(--font-body);
  font-size: 11.5px;
  /* A surface-coloured halo so the value stays readable over a bar or the hatched forecast. */
  paint-order: stroke;
  stroke: var(--surface);
  stroke-width: 3px;
  stroke-linejoin: round;
}
.chart-ticks { position: relative; height: 22px; color: var(--text-faint); font-size: 12.5px; }
.chart-ticks span { position: absolute; top: 4px; white-space: nowrap; }
.chart-note { margin-top: 6px; color: var(--text-faint); font-size: 12.5px; }
.chart-note:empty { display: none; }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; color: var(--text-muted); font-size: 13px; }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.swatch { flex: none; width: 9px; height: 9px; border-radius: 3px; background: var(--accent); }
.swatch.forecast { border: 1px dashed var(--accent); background: var(--accent-soft); }
.swatch.announced { border: 1px solid var(--accent); background: var(--accent-soft); }
.tip {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 5;
  min-width: 120px;
  padding: 8px 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--tip-shadow);
  font-size: 12.5px;
  line-height: 1.4;
  white-space: nowrap;
  pointer-events: none;
}
.tip-value { color: var(--text); font-family: var(--font-figure); font-size: 14.5px; font-weight: 600; }
.tip-label { color: var(--text-muted); }

/* Dividends per year */
.bar-received { fill: var(--accent); }
.bar-group:hover .bar-received, .bar-group.selected .bar-received { fill: var(--accent-hover); }
.bar-group.selectable { cursor: pointer; }
.bar-forecast { fill: url(#dividend-hatch); stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 5 4; }
/* A payment date Yahoo announced, not received yet: hatched like a projection, but with a solid outline. */
.bar-announced { fill: url(#dividend-hatch); stroke: var(--accent); stroke-width: 1.5; }
.hatch-bg { fill: var(--accent-soft); }
.hatch-line { stroke: var(--accent); stroke-width: 2.4; opacity: 0.55; }
.bar-amount { fill: var(--text); font-family: var(--font-figure); font-size: 14px; font-weight: 600; }
.bar-hit { fill: transparent; }
.bar-axis { position: relative; height: 30px; }
.bar-axis > * {
  position: absolute;
  top: 3px;
  padding: 2px 8px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 13.5px;
  white-space: nowrap;
  transform: translateX(-50%);
}
.bar-axis button { cursor: pointer; }
.bar-axis button:hover { background: var(--surface-2); color: var(--text); }
.bar-axis button[aria-pressed="true"] { color: var(--text); font-weight: 600; }

/* Allocation donut and source bars */
.donut { position: relative; display: flex; justify-content: center; margin-top: 14px; }
.donut svg { width: 200px; height: 200px; overflow: visible; }
.donut-seg { fill: none; stroke-width: 18; transition: stroke-width 0.12s; }
.donut-seg.active { stroke-width: 22; }
.donut-track { fill: none; stroke: var(--surface-2); stroke-width: 18; }
.donut-label { fill: var(--text-muted); font-family: var(--font-body); font-size: 11.5px; letter-spacing: 0.06em; }
.donut-value { fill: var(--text); font-family: var(--font-figure); font-size: 19px; font-weight: 600; }
.alloc-list { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.alloc-row { display: flex; align-items: center; gap: 10px; }
.alloc-name { flex: 1; min-width: 0; }
.alloc-pct { font-family: var(--font-figure); font-weight: 600; }
.alloc-value { width: 96px; color: var(--text-muted); font-family: var(--font-figure); font-size: 13px; text-align: right; }
.bars-list { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
.bar-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.bar-foot { margin-top: 4px; }
.bar-track { height: 6px; margin-top: 7px; overflow: hidden; border-radius: 999px; background: var(--surface-2); }
.bar-fill { height: 100%; border-radius: 999px; background: var(--accent); }

/* Grid tables: each table sets --cols so the header and every row share one column template. */
/* Horizontal scrolling inside a card (and the portfolio tabs), with edge shading as the cue that more is
   off-screen: the covers scroll with the content (local) and hide the shading once that edge is reached. */
.gt-scroll, .tabs {
  background:
    linear-gradient(to right, var(--scroll-cover) 30%, transparent) left center / 32px 100% no-repeat local,
    linear-gradient(to left, var(--scroll-cover) 30%, transparent) right center / 32px 100% no-repeat local,
    radial-gradient(farthest-side at 0 50%, var(--scroll-shade), transparent) left center / 16px 100% no-repeat scroll,
    radial-gradient(farthest-side at 100% 50%, var(--scroll-shade), transparent) right center / 16px 100% no-repeat scroll;
}
.gt-scroll { --scroll-cover: var(--surface); overflow-x: auto; }
.settings-table-outline { border: 1px solid var(--border); border-radius: 12px; overflow-x: auto; }
.settings-table-outline .gt-row { border-bottom-color: var(--border); }
.gt { min-width: var(--gt-min, 0); }
.gt-head, .gt-row {
  display: grid;
  grid-template-columns: var(--cols);
  gap: 16px;
  align-items: center;
  padding-right: 24px;
  padding-left: 24px;
}
.gt-head {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.gt-row { padding-top: 13px; padding-bottom: 13px; border-bottom: 1px solid var(--grid); }
.gt-body .gt-row:last-child { border-bottom: 0; }
.gt-body .gt-row:hover { background: var(--surface-2); }
.gt.compact .gt-row { padding-top: 12px; padding-bottom: 12px; }
.gt.compact .fig, .gt.compact .ident-name { font-size: 14px; }
.gt-foot { border-top: 1px solid var(--border); border-bottom: 0; font-weight: 600; }
.gt-note { grid-column: 1 / -1; margin-top: -4px; font-size: 12.5px; white-space: normal; overflow-wrap: anywhere; }
.gt-empty { padding: 16px 24px 22px; color: var(--text-muted); }
.ident { display: flex; align-items: center; gap: 12px; min-width: 0; }
.ident-mark {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-family: var(--font-figure);
  font-size: 12px;
  font-weight: 600;
}
.gt.compact .ident-mark { width: 32px; height: 32px; font-size: 11.5px; }
.ident-text { min-width: 0; }
.ident-name {
  display: block;
  overflow: hidden;
  font-family: var(--font-figure);
  font-size: 14.5px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ident a.ident-name { color: var(--text); }
.ident a.ident-name:hover { color: var(--accent); }
.ident-sub {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  overflow: hidden;
  color: var(--text-muted);
  font-size: 12.5px;
  white-space: nowrap;
}

/* Buttons and forms */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-figure);
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn.primary { border-color: var(--accent); background: var(--accent); color: var(--surface); }
.btn.primary:hover:not(:disabled) { border-color: var(--accent-hover); background: var(--accent-hover); }
.btn:disabled { cursor: default; opacity: 0.55; }
.form { display: grid; gap: 16px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px 16px; }
.field { display: grid; align-content: start; gap: 6px; color: var(--text-muted); font-size: 13px; font-weight: 600; }
.field input, .field select {
  width: 100%;
  min-height: 38px;
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14.5px;
  font-weight: 400;
}
.field input:focus-visible, .field select:focus-visible { outline-offset: 1px; }
.field input[type="file"] { padding: 5px 8px; }
.field input::file-selector-button {
  margin-right: 10px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.result { display: grid; gap: 8px; }
.result:empty { display: none; }
.switch-label { display: inline-flex; align-items: center; gap: 10px; min-height: 36px; color: var(--text-muted); font-size: 13.5px; cursor: pointer; }
.switch {
  position: relative;
  flex: none;
  width: 38px;
  height: 22px;
  margin: 0;
  border-radius: 999px;
  background: var(--border);
  cursor: pointer;
  transition: background 0.15s;
  appearance: none;
}
.switch::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: transform 0.15s, background 0.15s;
}
.switch:checked { background: var(--accent); }
.switch:checked::before { background: var(--surface); transform: translateX(16px); }
.switch:disabled { cursor: default; opacity: 0.55; }
/* A switch inside a .field would otherwise take the text input styling above (wide, bordered, green bar). */
.field .switch { width: 38px; min-height: 22px; height: 22px; padding: 0; border: 0; border-radius: 999px; background: var(--border); }
.field .switch:checked { background: var(--accent); }
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
  padding: 0 12px 8px;
  border-bottom: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-align: left;
  text-transform: uppercase;
}
.data-table td { padding: 9px 12px; border-bottom: 1px solid var(--grid); vertical-align: top; }
.data-table .num { text-align: right; }

/* Saved credential entries (Settings → Manage) */
.cred-list { display: grid; gap: 10px; }
.cred-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--grid);
}
.cred-row:first-child { padding-top: 0; border-top: 0; }
.cred-main { flex: 1; min-width: 180px; }
.cred-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Login */
.login-page { display: grid; place-items: center; padding: 40px 20px; }
.login-card { display: grid; gap: 20px; width: 100%; max-width: 380px; padding: 28px; }
.login-card h1 { font-size: 22px; letter-spacing: -0.02em; }
.login-card .btn { width: 100%; }

/* Text utilities (last, so they win over component colours) */
.r { text-align: right; }
.fig { font-family: var(--font-figure); font-size: 14.5px; }
.strong { font-weight: 600; }
.sub { color: var(--text-muted); font-size: 12.5px; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.meta { color: var(--text-muted); font-size: 13px; }
.ok { color: var(--up); font-weight: 600; }
.error { color: var(--down); font-weight: 600; }
.up { color: var(--up); }
.down { color: var(--down); }

/* ---- Security icons (v0.9.3.2) ----
   A logo.dev <img> takes the monogram badge's box (.ident-mark sets the size and border). Logos are drawn
   for light backgrounds, so the tile stays white in dark mode too. */
img.ident-logo { display: block; padding: 3px; background: #fff; object-fit: contain; }
.stock-head .ident { gap: 16px; }
.stock-head .ident-mark { width: 52px; height: 52px; border-radius: 12px; font-size: 17px; }
.stock-head img.ident-logo { padding: 5px; }

/* ---- Add account flow (Part A) ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 5vh 16px 32px;
  overflow-y: auto;
  background: rgba(10, 15, 13, 0.55);
}
.modal {
  width: 100%;
  max-width: 700px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--tip-shadow);
}
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 22px 24px 0; }
.modal-body { padding: 18px 24px 24px; }
.modal-close {
  flex: none;
  min-width: 36px;
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.wizard-steps { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 14px 0 18px; color: var(--text-faint); font-size: 12.5px; }
.wizard-steps .active { color: var(--accent); font-weight: 600; }
.wizard-steps .done { color: var(--text-muted); }
.source-grid, .choice-grid, .category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.category-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.source-tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
  min-height: 44px;
  padding: 15px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.source-tile:hover { border-color: var(--accent); background: var(--accent-soft); }
.source-tile-name { font-family: var(--font-figure); font-weight: 600; }
.source-tile-desc { color: var(--text-muted); font-size: 12.5px; }
.wizard-nav { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; margin-top: 20px; }
.wizard-note { margin-top: 14px; color: var(--text-muted); font-size: 12.5px; }

/* ---- Settings (v0.9.3.2): the gear link in the top bar, account actions, Manage view, global settings ----
   The gear is the "settings" glyph from Feather Icons (MIT licence), stroked in the text colour. */
.nav-settings {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  color: var(--text-muted);
  font-family: var(--font-figure);
  font-weight: 500;
}
.nav-settings:hover { background: var(--surface-2); color: var(--text); }
.nav-settings[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav-settings-icon { flex: none; width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
/* The label is for screen readers on desktop and shown next to the gear in the collapsed menu. */
.nav-settings-label { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
/* Stacked, so the Accounts table's last column is one button wide on desktop. */
.row-actions { display: flex; flex-direction: column; align-items: stretch; gap: 6px; }
.account-facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 18px; margin: 4px 0 18px; }
.account-facts dt { color: var(--text-muted); font-size: 13px; }
.account-facts dd { margin: 0; overflow-wrap: anywhere; }
.account-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.account-section { display: grid; gap: 12px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--grid); }
.account-section h3 { font-size: 15px; }
.modal-body > p { margin-top: 12px; }
.settings-form { display: grid; gap: 12px; max-width: 520px; }
.portfolio-names-intro { margin: 12px 0 20px; }
.meta.warn { color: var(--down); }

/* ---- Recent transactions counter (portfolio page) ---- */
.card-head .badge {
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  font-family: var(--font-figure);
  font-size: 12.5px;
  font-weight: 600;
}

/* ---- Performance (v0.9.3.3): return contribution diverging bars and time travel ----
   A centre line marks zero; positive contributions grow right (green), negative grow left (red). */
.contrib-list { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
.contrib-row { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 2.4fr) minmax(0, 0.9fr); align-items: center; gap: 16px; }
.contrib-bar { position: relative; height: 20px; overflow: hidden; border-radius: 999px; background: var(--surface-2); }
.contrib-center { position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: var(--border); }
.contrib-fill { position: absolute; top: 0; bottom: 0; border-radius: 999px; }
.contrib-fill.up { background: var(--up); }
.contrib-fill.down { background: var(--down); }
.contrib-value { text-align: right; }
.timetravel-form { display: flex; align-items: flex-end; gap: 10px; }
.timetravel-form .field { display: flex; align-items: center; gap: 8px; }
.timetravel-form .field input { width: auto; min-height: 36px; }

/* ---- Calendar (v0.9.3.3): event chips, month grid and the "next 7 days" widget ----
   Event colours are fixed across both themes (the tinted background works on dark and light). */
.evt {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 2px 7px;
  border: 0;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
button.evt { cursor: pointer; }
button.evt:hover { filter: brightness(1.08); }
.evt-dividend-pay { background: var(--accent-soft); color: var(--up); }
.evt-dividend-ex { background: rgba(70, 179, 221, 0.18); color: #2E9BC7; }
.evt-earnings { background: rgba(47, 127, 226, 0.18); color: #2F7FE2; }
.evt-cmd { background: rgba(232, 145, 45, 0.18); color: #D9821F; }
.evt-agm { background: rgba(125, 135, 144, 0.18); color: var(--text-muted); }
.swatch.evt-dividend-pay { border: 0; }
.swatch.evt-earnings { border: 0; }

.cal-head { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 14px 0 10px; }
.cal-head .btn { min-width: 40px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal-weekday { padding: 4px 6px; color: var(--text-faint); font-size: 12px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; }
.cal-day {
  min-height: 92px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
.cal-day.outside { border-color: transparent; background: none; }
.cal-day.today { border-color: var(--accent); }
.cal-daynum { color: var(--text-muted); font-family: var(--font-figure); font-size: 13px; font-weight: 600; }
.cal-day.today .cal-daynum { color: var(--accent); }
.cal-events { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; margin-top: 6px; }
.cal-events .evt { max-width: 100%; }
.cal-more { color: var(--text-faint); font-size: 11.5px; padding-left: 2px; }

/* Dashboard "next 7 days" widget (v0.9.3.3). */
.upcoming-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.upcoming-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.upcoming-date { flex: none; width: 44px; color: var(--text-muted); font-family: var(--font-figure); font-size: 13px; text-align: center; }
.upcoming-date strong { display: block; font-size: 15px; color: var(--text); }

/* ---- Calendar (v0.9.4): a type badge with the holding's name beside it, and history navigation ----
   An outlined badge is not yet something that happened: an expected dividend or a scheduled earnings date. */
.evt-projected { background: transparent; box-shadow: inset 0 0 0 1px currentColor; }
/* v0.9.8.7: Confirmed / Estimated flag on a dividend. */
.evt-flag { display: inline-block; flex: none; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; line-height: 1.5; white-space: nowrap; }
.evt-flag.confirmed { background: var(--accent-soft); color: var(--up); }
.evt-flag.announced { background: transparent; color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.evt-flag.estimated { background: transparent; color: var(--text-muted); box-shadow: inset 0 0 0 1px var(--text-faint); }
.evt-cell { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.legend .evt, .legend .evt-flag { vertical-align: middle; }
.legend-group { display: inline-flex; align-items: center; gap: 6px; }
.legend-name { color: var(--text-faint); font-size: 12.5px; }
.legend-note { color: var(--text-faint); font-size: 12.5px; }
.cal-day.past .cal-daynum { color: var(--text-faint); }
.cal-evt {
  display: flex;
  align-items: center;
  gap: 5px;
  width: 100%;
  min-width: 0;
  padding: 1px 0;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}
.cal-evt .evt { flex: none; padding: 1px 6px; font-size: 11px; }
.cal-evt-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-evt:hover .cal-evt-name { color: var(--accent); }
.cal-list-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin: 14px 0 10px; }
.upcoming-row .evt { flex: none; }

/* ---- Add account (v0.9.4): broker search, Import options, security search, money fields ---- */
.broker-search { margin-bottom: 14px; }
.source-tile-tag {
  margin-top: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--up);
  font-size: 11.5px;
  font-weight: 600;
}
.security-field { grid-column: 1 / -1; }
.combo { position: relative; }
.combo-list {
  position: absolute;
  z-index: 5;
  top: calc(100% + 4px);
  right: 0;
  left: 0;
  max-height: 320px;
  margin: 0;
  padding: 4px;
  overflow-y: auto;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--tip-shadow);
}
.combo-option { display: flex; align-items: center; min-height: 44px; padding: 6px 8px; border-radius: 8px; color: var(--text); font-weight: 400; cursor: pointer; }
.combo-option[aria-selected="true"], .combo-option:hover { background: var(--surface-2); }
.combo-option .ident { min-width: 0; }
.combo-empty { padding: 10px 8px; color: var(--text-muted); font-size: 13px; font-weight: 400; }
.security-picked { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px; font-weight: 400; }
.security-picked .ident { flex: 1; min-width: 0; }
.link-btn { padding: 0; border: 0; background: none; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; }
.link-btn.up { color: var(--up); }
.money-input { display: flex; gap: 6px; }
.money-input input { flex: 1; min-width: 0; }
.field .money-input select { flex: none; width: auto; }
details.advanced { padding-top: 12px; border-top: 1px solid var(--grid); }
details.advanced summary { color: var(--text-muted); font-size: 13px; font-weight: 600; cursor: pointer; }
details.advanced[open] summary { margin-bottom: 12px; }
.total-line { font-family: var(--font-figure); font-size: 15px; font-weight: 600; }
.total-line:empty { display: none; }
.total-line .sub { display: block; font-family: var(--font-body); font-weight: 400; }

/* ---- Portfolios (v0.9.4.1): Update, sortable positions, the sync state and account settings ---- */
.portfolio-actions { display: flex; align-items: center; gap: 8px; }
.btn.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  min-width: 38px;
  padding: 0;
}
.btn.icon svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn.danger { border-color: var(--down); color: var(--down); }
.btn.danger:hover { background: var(--surface-2); color: var(--down); }

/* Sortable column headings (the sort state is on the button, the grid columns stay untouched). */
.gt-head button.sort {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.gt-head button.sort.r { justify-content: flex-end; }
.gt-head button.sort:hover { color: var(--text); }
.gt-head button.sort.active { color: var(--text); }
.gt-head button.sort .sort-arrow { color: var(--text-faint); font-size: 11px; line-height: 1; }
.gt-head button.sort.active .sort-arrow { color: var(--accent); }

/* The full-screen "Synchronization in progress" state covers only the portfolio panel. */
#portfolio-view { position: relative; }
.sync-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 24px;
  border-radius: 16px;
  background: var(--overlay);
}
.sync-overlay-card {
  display: grid;
  justify-items: center;
  gap: 12px;
  width: min(420px, 100%);
  padding: 28px 24px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--tip-shadow);
  text-align: center;
}
.sync-marks { display: flex; align-items: center; gap: 12px; }
.sync-mark { display: inline-flex; width: 44px; height: 44px; align-items: center; justify-content: center; border-radius: 12px; background: var(--surface-2); }
.sync-mark .ident-mark { width: 30px; height: 30px; }
.sync-mark-brand { border-radius: 50%; border: 4px solid #2F3841; border-top-color: var(--accent); border-right-color: var(--accent); background: none; }
.sync-line-track { position: relative; width: 90px; height: 3px; overflow: hidden; border-radius: 2px; background: var(--grid); }
.sync-line-fill { position: absolute; inset: 0; width: 40%; border-radius: 2px; background: var(--accent); animation: sync-line 1.4s ease-in-out infinite; }
@keyframes sync-line {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(260%); }
}
.sync-title { font-size: 18px; }
.sync-text { color: var(--text-muted); font-size: 13.5px; }
.progress { width: 100%; height: 6px; overflow: hidden; border-radius: 3px; background: var(--grid); }
.progress-bar { width: 35%; height: 100%; border-radius: 3px; background: var(--accent); animation: progress-slide 1.4s ease-in-out infinite; }
@keyframes progress-slide {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(330%); }
}

/* The combined "Update accounts" modal (v0.9.4.1). */
.update-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--grid); }
.update-row:first-child { border-top: 0; padding-top: 0; }
.update-row-main {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.update-row-text { display: grid; gap: 1px; min-width: 0; }
.update-row-text .sub { color: var(--text-muted); font-size: 12.5px; }
.update-row-text .sub.error { color: var(--down); }
.update-row.syncing { opacity: 0.7; }

/* "Net worth settings" on the Aggregated tab (v0.9.5.2.2): the portfolio list and its Reorder mode. */
.settings-subhead { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.settings-subhead .subhead-title { margin: 0; font-size: 14px; font-weight: 600; }
.settings-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 0;
  border: 0;
  border-top: 1px solid var(--grid);
  background: none;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.settings-subhead + .settings-row { border-top: 0; }
.settings-row.reordering { cursor: default; }
.settings-row .chevron { margin-left: auto; font-size: 20px; line-height: 1; }
.reorder-actions { display: flex; gap: 8px; margin-left: auto; }

/* ---- Transactions (v0.9.5): search/filter toolbar, month groups and the form's total ---- */
.tx-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 0 20px 12px; }
.tx-toolbar .field { margin: 0; }
.tx-search { flex: 1 1 240px; }
.tx-search input { width: 100%; }
.tx-filter { flex: none; }
.tx-toolbar .badge { margin-left: auto; }
.tx-month { border-top: 1px solid var(--grid); }
.tx-month > div { color: var(--text-faint); font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.tx-more { display: flex; justify-content: center; padding: 12px 20px 0; }
.tx-more:empty { display: none; }

/* ---- Settings (v0.9.4): portfolio names and the build line ---- */
.portfolio-names { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px 16px; }
.build-line { color: var(--text-faint); font-family: var(--font-figure); font-size: 12.5px; text-align: center; }

/* ---- Wealth planning (Part M) ---- */
.plan-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 20px; align-items: start; }
.plan-inputs { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px 16px; }
.plan-results { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.plan-result {
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}
.plan-result .kpi-value { font-size: 24px; }
.plan-note { margin-top: 6px; color: var(--text-faint); font-size: 12.5px; }
.plan-summary { margin-top: 16px; color: var(--text-muted); font-size: 13px; }

/* ---- Responsive layout (v0.9.3) ----
   Breakpoints: --bp-tablet (1024px) and --bp-mobile (600px) in :root; desktop is everything above.
   Conventions for new pages:
   - Navigation: the top bar markup is the same on every page; below the tablet breakpoint the menu
     collapses behind .nav-toggle.
   - Touch: below the tablet breakpoint every control is at least --tap-min tall, and inputs use 16px text
     so iOS doesn't zoom on focus.
   - Tables: per-record tables (one row per holding or source, often with a button) get `.reflow` and
     become label/value cards on mobile (`.reflow-tablet` too for tables that are too wide for a tablet);
     app.js copies the column headings onto the cells as data-label. Ledger tables (dated payments,
     import issues) stay in .gt-scroll and scroll inside their card, with edge shading as the cue.
   - Charts render to their container's width (ResizeObserver in each page script) and thin out their
     labels when space is short; range toggles go full width with equal segments on mobile. */

/* Tablet and below */
@media (max-width: 1024px) {
  .topbar { gap: 12px; min-height: 60px; padding: 8px 12px 8px 24px; }
  .brand { min-height: 44px; }
  .nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    margin-left: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
  }
  .nav-toggle-bars, .nav-toggle-bars::before, .nav-toggle-bars::after {
    display: block;
    width: 18px;
    height: 2px;
    border-radius: 1px;
    background: currentColor;
    transition: transform 0.15s, background-color 0.15s, top 0.15s;
  }
  .nav-toggle-bars { position: relative; }
  .nav-toggle-bars::before, .nav-toggle-bars::after { content: ''; position: absolute; left: 0; }
  .nav-toggle-bars::before { top: -6px; }
  .nav-toggle-bars::after { top: 6px; }
  .menu-open .nav-toggle-bars { background-color: transparent; }
  .menu-open .nav-toggle-bars::before { top: 0; transform: rotate(45deg); }
  .menu-open .nav-toggle-bars::after { top: 0; transform: rotate(-45deg); }
  .topbar-menu {
    position: absolute;
    top: 100%;
    right: 0;
    left: 0;
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 8px 16px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--tip-shadow);
  }
  .topbar.menu-open .topbar-menu { display: flex; }
  .nav { flex-direction: column; align-items: stretch; gap: 2px; overflow: visible; font-size: 15px; }
  .nav a { display: flex; align-items: center; min-height: 44px; padding: 0 12px; }
  .topbar-right { justify-content: space-between; gap: 12px; padding-top: 8px; border-top: 1px solid var(--grid); }
  .sync-line { display: block; min-width: 0; overflow: hidden; line-height: 44px; text-overflow: ellipsis; white-space: nowrap; }
  .logout { display: inline-flex; flex: none; align-items: center; min-height: 44px; padding: 0 16px; }
  .topbar-right .sync-line { margin-right: auto; }
  .nav-settings { width: auto; height: 44px; padding: 0 12px; }
  .theme-toggle { width: 44px; height: 44px; }
  .nav-settings-label { position: static; width: auto; height: auto; margin: 0; overflow: visible; clip: auto; }

  .page { padding: 24px 24px 40px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* The three-tile row stays three across on tablets, with figures small enough not to break. */
  .kpis.three .kpi-value, .kpis.dividends .kpi-value { font-size: 24px; }
  .split, .split.even { grid-template-columns: minmax(0, 1fr); }
  .portfolio-kpis { grid-template-columns: minmax(0, 1fr); }

  .btn, .segmented button, .tabs button, .switch-label { min-height: 44px; }
  .segmented button { min-width: 44px; }
  .gt-head button.sort { min-height: 44px; }
  .field input, .field select { min-height: 44px; font-size: 16px; }
  .benchmark-picker select { min-height: 44px; font-size: 16px; }
  .card-link { display: inline-flex; align-items: center; min-height: 44px; }
  .ident a.ident-name { margin: -14px 0; padding: 14px 0; }
  .bar-axis { height: 48px; }
  .bar-axis > * { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; }

  .gt.reflow-tablet { min-width: 0; }
  .gt.reflow-tablet .gt-head { display: none; }
  .gt.reflow-tablet .gt-row { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px 20px; align-items: start; }
  .gt.reflow-tablet .gt-row > :first-child, .gt.reflow-tablet .gt-row > .gt-note, .gt.reflow-tablet .gt-row > .r:has(> .btn) { grid-column: 1 / -1; }
  .gt.reflow-tablet .gt-row > * { text-align: left; }
  .gt.reflow-tablet .gt-row > :not(:first-child)[data-label]:not([data-label=""])::before {
    content: attr(data-label);
    display: block;
    flex-basis: 100%;
    margin-bottom: 2px;
    color: var(--text-faint);
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }
  .gt.reflow-tablet .gt-row > .switch-label, .gt.reflow-tablet .gt-row > .run { flex-wrap: wrap; }
  .gt.reflow-tablet .gt-row .btn { width: 100%; }
}

/* Mobile */
@media (max-width: 600px) {
  .topbar { padding: 8px 8px 8px 16px; }
  .page { gap: 16px; padding: 16px 12px 32px; }
  .kpis, .kpis.three { grid-template-columns: minmax(0, 1fr); }
  .portfolio-kpis-left, .portfolio-kpis-right { grid-template-columns: minmax(0, 1fr); }
  .hero { padding: 18px 16px 14px; }
  .hero-value { font-size: clamp(30px, 9.5vw, 38px); }
  .kpis.three .kpi-value, .kpis.dividends .kpi-value { font-size: 26px; }
  .stock-name { font-size: 28px; }
  .card-body { padding: 16px; }
  .card-head, .gt-head, .gt-row, .card-foot, .gt-empty { padding-right: 16px; padding-left: 16px; }
  .positions-periods { padding: 0 16px 12px; }
  .card-body > .card-head { padding: 0; }
  .card-lead { padding: 0 16px 14px; }
  .card-inner { padding: 0 12px 16px; }
  .hero-top .segmented, .card-head .segmented { width: 100%; }
  .positions-periods .segmented { width: 100%; }
  .segmented button { flex: 1 1 0; padding: 6px 4px; }
  .form-actions > .btn { flex: 1 1 100%; }
  .cred-actions .btn { flex: 1 1 0; }
  .login-page { place-items: start center; padding: max(16px, 7vh) 12px 24px; }
  .login-card { gap: 16px; padding: 22px 18px; }

  .gt.reflow { min-width: 0; }
  .gt.reflow .gt-head { display: none; }
  .gt.reflow .gt-row { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px 16px; align-items: start; }
  .gt.reflow .gt-row > :first-child, .gt.reflow .gt-row > .gt-note, .gt.reflow .gt-row > .r:has(> .btn) { grid-column: 1 / -1; }
  .gt.reflow .gt-row > * { text-align: left; }
  .gt.reflow .gt-row > :not(:first-child)[data-label]:not([data-label=""])::before {
    content: attr(data-label);
    display: block;
    flex-basis: 100%;
    margin-bottom: 2px;
    color: var(--text-faint);
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }
  .gt.reflow .gt-row > .switch-label, .gt.reflow .gt-row > .run { flex-wrap: wrap; }
  .gt.reflow .gt-row .btn { width: 100%; }

  .modal-backdrop { padding: 10px; }
  .modal-head { padding: 18px 16px 0; }
  .modal-body { padding: 16px; }
  .source-grid, .choice-grid, .category-grid { grid-template-columns: minmax(0, 1fr); }
  .wizard-nav .btn { flex: 1 1 100%; }
  .plan-grid, .plan-results { grid-template-columns: minmax(0, 1fr); }
  .contrib-row { grid-template-columns: minmax(0, 1fr); gap: 6px 12px; }
  .contrib-value { text-align: left; }
  .timetravel-form { flex-wrap: wrap; }
  .cal-list-head .segmented { width: 100%; }
  /* The calendar list's first cell is the date, so its holding (name, logo and detail line) takes a full row. */
  #calendar-list .gt.reflow .gt-row > .ident { grid-column: 1 / -1; }
  #calendar-list .gt.reflow .gt-row > .ident::before { display: none; }
  .portfolio-actions { width: 100%; }
  .portfolio-actions .btn:not(.icon) { flex: 1; }
  .sync-overlay { padding: 12px; }
  .sync-overlay-card { padding: 22px 18px; }
  .update-row { flex-wrap: wrap; }
  .update-row > .muted { flex-basis: 100%; }
}

/* v0.9.8.15: forecast rows that expand into their monthly breakdown, and the dividend quality tiles. */
.forecast-group { border-bottom: 1px solid var(--border); }
.forecast-group > .gt-row { cursor: pointer; }
.forecast-group > .gt-row:hover { background: var(--surface-2); }
.forecast-detail { padding: 4px 16px 16px; }
.forecast-detail .chart { margin-top: 4px; }
.forecast-detail p { color: var(--text-muted); font-size: 13px; margin: 8px 0 0; }
.income-tracker { color: var(--text-muted); font-size: 13.5px; margin: 10px 0 0; }
.income-tracker strong { color: var(--text); font-family: var(--font-figure); font-weight: 600; }
.quality-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.quality-tile { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; }
.quality-tile .quality-label { color: var(--text-muted); font-size: 12.5px; }
.quality-tile .quality-value { font-family: var(--font-figure); font-size: 20px; font-weight: 600; margin-top: 2px; }
.quality-tile .quality-sub { color: var(--text-faint); font-size: 12.5px; margin-top: 2px; }

/* Additional allocation views wrap within portfolio cards on narrow screens. */
#allocation-mode { flex-wrap: wrap; }
#allocation-mode button { flex: 1 1 100px; min-width: 100px; }
#goals-list progress { width: 100%; height: 12px; accent-color: var(--accent); }

#goals-list progress { appearance: none; border: 0; border-radius: 6px; overflow: hidden; background: var(--surface-2); }
#goals-list progress::-webkit-progress-bar { background: var(--surface-2); }
#goals-list progress::-webkit-progress-value { background: var(--accent); border-radius: 6px; }
#goals-list progress::-moz-progress-bar { background: var(--accent); border-radius: 6px; }

/* Settings → Bank Sync: private preview data; use existing typography and controls. */
.bank-route-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; margin: 1rem 0; }
.bank-route-grid label { min-width: 0; }
.bank-connection { margin: 1rem 0; }
.bank-connection .btn { margin-right: .5rem; }
.bank-table-scroll { overflow-x: auto; margin: 1rem 0; }
.bank-table { width: 100%; min-width: 600px; border-collapse: collapse; text-align: left; font-size: .85rem; }
.bank-table th, .bank-table td { padding: .8rem; border-bottom: 1px solid var(--border, #6664); vertical-align: top; }
.bank-table td p { margin: .3rem 0; overflow-wrap: anywhere; }
.bank-table th { font-weight: 600; }

.bank-test-row { display: grid; gap: .45rem; margin-top: .65rem; }
.bank-test-row select { max-width: 230px; width: 100%; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: .4rem; }
#bank-approvals .btn { margin: .3rem .5rem .3rem 0; }
#bank-reconciliation-evidence { width: 100%; min-height: 110px; font-family: monospace; }

.bank-table th .btn { border: 0; padding: 0; background: transparent; font-weight: 600; }
.bank-table td:nth-child(3), .bank-table td:nth-child(4) { white-space: nowrap; }

.reauth-dialog { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 18px; max-width: 440px; padding: 24px; }
.reauth-dialog::backdrop { background: #000a; }
.reauth-dialog label { display: grid; gap: 6px; margin: 16px 0; }
.reauth-dialog input { width: 100%; }
.reauth-dialog p { color: var(--text-muted); }
.reauth-dialog button { margin-right: 10px; }

.calendar-key { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; margin: 16px 0; }
.calendar-key > div { padding: 14px; border: 1px solid var(--border); border-radius: 10px; }
.calendar-key h3 { font-size: 13px; margin: 0 0 10px; }
.calendar-key p { font-size: 12px; color: var(--text-muted); margin: 8px 0; line-height: 1.6; }
.login-card .build-line { margin: 0; font-size: 11px; overflow-wrap: anywhere; }

.sync-warning { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 32px; height: 32px; color: var(--down); border-radius: 8px; }
.sync-warning:hover { background: var(--surface-2); }
.sync-warning:focus-visible { outline: 2px solid var(--down); outline-offset: 3px; }
.sync-warning svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.sync-warning .warning-dot { fill: currentColor; stroke: none; }
@media (max-width: 760px) { .sync-warning { width: 44px; height: 44px; } }

.portfolio-dividend-list { max-height: 320px; overflow-y: auto; overscroll-behavior: contain; border-top: 1px solid var(--border); scrollbar-gutter: stable; }
.dividend-month-head { position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; gap: 12px; padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--border); }
.dividend-month-head h3 { margin: 0; font-size: 13px; }
.dividend-payment-row { display: grid; grid-template-columns: minmax(0, 1.6fr) auto minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.dividend-payment-amount { text-align: right; white-space: nowrap; }
@media (max-width: 600px) { .dividend-payment-row { grid-template-columns: minmax(0, 1fr) auto; gap: 8px; padding: 12px; } .dividend-payment-row > .sub { grid-column: 1; } .dividend-month-head { padding: 12px; } }

#allocation-title { flex-basis: 100%; }
#allocation-mode.allocation-tabs { display: flex; flex: 1; flex-wrap: nowrap; overflow-x: auto; min-width: 0; scrollbar-width: none; background: transparent; padding: 0; border: 0; border-radius: 0; }
#allocation-mode.allocation-tabs button { flex: none; border-radius: 0; background: transparent; border-bottom: 2px solid transparent; padding: 10px 12px; }
#allocation-mode.allocation-tabs button[aria-pressed="true"] { border-color: var(--accent); color: var(--text); }
.allocation-next { flex: none; width: 32px; height: 32px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); cursor: pointer; }
#allocation-donut svg { width: min(100%, 280px); height: 280px; }
#allocation-donut .donut-seg { stroke-width: 5; stroke-linecap: round; }
#allocation-donut .donut-seg.active { stroke-width: 7; }
#allocation-donut .donut-track { stroke-width: 5; }
#allocation-donut .donut-label { letter-spacing: 0; font-size: 11px; }
#allocation-donut .donut-value { font-size: 18px; }
.annual-return-chart { display: flex; gap: 10px; overflow-x: auto; padding: 12px 0; }
.annual-return { min-width: 42px; flex: 1; text-align: center; display: flex; flex-direction: column; gap: 7px; }
.annual-return-track { position: relative; height: 130px; background: linear-gradient(transparent calc(50% - .5px), var(--border) 50%, transparent calc(50% + .5px)); }
.annual-return-bar { position: absolute; left: 10%; width: 80%; border-radius: 3px; }
.annual-return-bar.up { background: var(--up); }
.annual-return-bar.down { background: var(--down); }
.annual-return-bar.partial { opacity: .7; outline: 1px dashed var(--text-muted); outline-offset: 2px; }
.annual-return-bar.unknown { background: var(--text-faint); }
.performance-detail { display: flex; justify-content: space-between; gap: 16px; margin: 10px 0; font-size: 13px; }
.performance-detail .fig { text-align: right; }
.portfolio-performance h3 { margin: 18px 0 10px; font-size: 13px; }

#allocation-title { flex: 1 1 calc(100% - 100px); }
#allocation-mode.allocation-tabs { flex: 1 1 calc(100% - 60px); }
.allocation-details { border: 0; background: transparent; padding: 4px 0; color: var(--text-muted); cursor: pointer; }

.portfolio-forecast-details summary { padding: 12px 20px; color: var(--text-muted); font-size: 13px; cursor: pointer; border-top: 1px solid var(--border); }
.portfolio-forecast-details .gt { max-height: 260px; overflow-y: auto; }

.price-quality-cell { display: flex; justify-content: flex-end; align-items: center; gap: 6px; }
.price-quality { flex: 0 0 auto; cursor: pointer; display: flex; padding: 6px 3px; border: 0; background: transparent; }
.quality-dot { display: block; width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted); }
.price-quality.current .quality-dot { background: #38be8c; }
.price-quality.last-known .quality-dot { background: #d6a744; }
.price-quality.unavailable .quality-dot { background: #e46565; }
.quality-popover { position: fixed; margin: 0; width: min(280px, 75vw); max-height: 70dvh; overflow-y: auto; white-space: pre-line; text-align: left; padding: 12px; border: 1px solid var(--border); border-radius: 10px; color: var(--text); background: var(--surface); font-size: 12px; line-height: 1.5; box-shadow: 0 8px 24px #0003; }
.data-quality-notice { border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px; background: var(--surface); font-size: 13px; }
.data-quality-notice summary { cursor: pointer; }
.quality-issue { margin-top: 12px; }
.quality-issue p { white-space: pre-line; margin: 4px 0; }
.reconciliation-dialog { width: min(1050px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0; border: 1px solid var(--border); border-radius: 16px; color: var(--text); background: var(--surface); }
.reconciliation-dialog::backdrop { background: #0009; }
.reconciliation-dialog .modal-head { position: sticky; top: 0; background: var(--surface); z-index: 1; }
.reconciliation-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 16px 0; }
.reconciliation-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; font-size: 12px; }
.reconciliation-field input, .reconciliation-field select { width: 100%; min-width: 0; padding: 8px; border: 1px solid var(--border); border-radius: 8px; color: var(--text); background: var(--surface); }
.reconciliation-check { display: flex; align-items: flex-start; gap: 8px; font-size: 12px; margin: 10px 0; }
.reconciliation-scroll { overflow: auto; max-height: 420px; margin: 12px 0; }
.reconciliation-dialog table { width: 100%; border-collapse: collapse; font-size: 12px; text-align: left; }
.reconciliation-dialog th, .reconciliation-dialog td { padding: 10px; border-bottom: 1px solid var(--border); min-width: 100px; vertical-align: top; }
.reconciliation-dialog th { position: sticky; top: 0; background: var(--surface); }
.reconciliation-dialog td:first-child { min-width: 200px; }
.reconciliation-dialog td:last-child { min-width: 240px; }
.reconciliation-dialog .sub { font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }
.reconciliation-dialog h3 { margin-top: 24px; }
.statement-setup summary { cursor: pointer; margin: 14px 0; font-size: 13px; }
.reconciliation-actions, .reconciliation-counts { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.reconciliation-status { display: inline-block; border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px; font-size: 12px; }
.reconciliation-status.matched { color: #38be8c; }
.reconciliation-status.difference, .reconciliation-status.missing { color: #e46565; }
.reconciliation-status.needs-review { color: #b38d31; }
@media (max-width: 650px) { .reconciliation-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); } .reconciliation-dialog .modal-body { padding: 16px; } .portfolio-actions { flex-wrap: wrap; } }
@media (max-width: 400px) { .reconciliation-fields { grid-template-columns: minmax(0, 1fr); } }

.chart-line.chart-line-invested { stroke: var(--chart-invested); stroke-dasharray: none; }
.chart-invested-dot, .chart-invested-marker { fill: var(--chart-invested); stroke: var(--surface); stroke-width: 1.5; }
.chart-comparison .chart-line { stroke: var(--chart-value); stroke-width: 2.5; }
.chart-comparison .chart-line-invested { stroke: var(--chart-invested); }
.chart-comparison .chart-dot { fill: var(--chart-value); stroke-width: 1.5; }
.chart-comparison .chart-fill-top { stop-color: var(--chart-value); stop-opacity: 0.08; }
.chart-comparison .chart-fill-bottom { stop-color: var(--chart-value); }
.chart-comparison .chart-grid { stroke: var(--border); opacity: 0.65; }
.chart-comparison .chart-grid-vertical { opacity: 0.4; }
.chart-axis-label { fill: var(--text-muted); font: 11.5px var(--font-figure); font-variant-numeric: tabular-nums; }
.portfolio-chart-legend { display: flex; align-items: baseline; flex-wrap: wrap; gap: 8px 24px; font-size: 12px; color: var(--text-muted); margin: 14px 0 10px; }
.portfolio-chart-legend span::before { content: ''; display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--chart-value); margin-right: 8px; vertical-align: baseline; }
.portfolio-chart-legend span + span::before { background: var(--chart-invested); }

.invested-coverage-dialog { margin: auto; padding: 24px; max-height: calc(100dvh - 32px); width: min(700px, calc(100% - 32px)); color: var(--text); overflow-y: auto; }
.invested-coverage-dialog::backdrop { background: rgba(10, 15, 13, 0.55); }
.invested-coverage-dialog form { display: grid; gap: 14px; }
.invested-coverage-dialog input[type="checkbox"] { width: 20px; min-height: 20px; }
