/* ===== DESIGN TOKENS =====
   Three tiers. Primitives are the raw scales; semantic tokens say what a value
   is for; component rules use only semantic tokens. A raw px, hex or shadow in
   a page template is a bug — add or reuse a token here instead.
   Full reference: docs/ui-style-guide.md, rendered at /styleguide. */
:root {
  /* — Type. One sans for text AND figures (tabular where columns align);
       the serif is the brand voice for page titles and the logo only. */
  --font-sans: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "DM Serif Display", Georgia, serif;
  --font-num: var(--font-sans);
  --fs-2xs: 11px;   /* axis ticks, table heads, badges */
  --fs-xs: 12px;    /* captions, hints, sub-lines */
  --fs-sm: 13px;    /* table body, secondary text */
  --fs-md: 14px;    /* body, labels, buttons */
  --fs-lg: 16px;    /* card titles */
  --fs-xl: 20px;    /* tile figures */
  --fs-2xl: 28px;   /* page titles */
  --fs-hero: clamp(28px, 2.6vw, 36px);  /* hero figures */
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;
  --lh-tight: 1.15;
  --lh-normal: 1.5;
  --tracking-tight: -0.02em;
  --tracking-caps: 0.06em;

  /* — Space: one 4px grid. */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px; --sp-12: 48px;
  --gap-grid: var(--sp-4);       /* between cards in a grid */
  --gap-section: var(--sp-8);    /* between page sections */
  --pad-card: var(--sp-6);
  --pad-card-sm: var(--sp-4) var(--sp-5);

  /* — Radius: four steps. */
  --radius-sm: 6px;    /* chips, inputs inside tables, bar ends */
  --radius-md: 10px;   /* buttons, inputs, inner panels */
  --radius-lg: 14px;   /* cards */
  --radius-pill: 999px;

  /* — Elevation: a hairline ring carries the edge, the shadow only lifts. */
  --shadow-sm: 0 1px 2px rgba(41, 37, 36, 0.04), 0 0 0 1px rgba(41, 37, 36, 0.06);
  --shadow-md: 0 6px 20px -6px rgba(41, 37, 36, 0.12), 0 0 0 1px rgba(41, 37, 36, 0.06);
  --shadow-lg: 0 18px 40px -12px rgba(41, 37, 36, 0.22), 0 0 0 1px rgba(41, 37, 36, 0.07);
  --btn-primary-bg: #BB5A08;      /* white text 4.6:1 */
  --btn-primary-hover: #A14C05;
  --btn-primary-ink: #FFFFFF;
  /* Round floating buttons («+», chat, the phone bar's «+»): one look in both
     themes, so they are deliberately absent from the dark overrides. */
  --fab-bg: #BB5A08;              /* white ink 4.6:1 */
  --fab-hover: #A14C05;
  --fab-ink: #FFFFFF;
  --ring-focus: 0 0 0 3px color-mix(in oklab, var(--accent) 35%, transparent);

  --dur-fast: 120ms;
  --dur-base: 200ms;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);

  /* — Surfaces & ink (warm stone neutrals). */
  --bg-primary: #FAFAF7;       /* page */
  --bg-secondary: #F4F1EC;     /* table heads, wells, hover */
  --bg-card: #FFFFFF;          /* raised surface */
  --bg-sidebar: #1C1917;
  --bg-sidebar-hover: #292524;
  --bg-sidebar-active: #3A3532;
  --text-primary: #1C1917;
  --text-secondary: #6F6862;   /* 5.3:1 on card */
  --text-tertiary: #A39C95;    /* axis, placeholders — never body copy */
  --text-sidebar: #E7E5E4;
  --text-sidebar-muted: #A8A29E;
  --border: #ECE8E3;
  --border-strong: #D9D3CC;
  --input-bg: #FFFFFF;
  --input-border: #D6D3D1;

  /* — Accent & status. Status colours mean state and never stand in for a series. */
  --accent: #D97706;
  --accent-hover: #B45309;
  --accent-soft: #FEF3E2;
  --accent-ink: #9A4F06;       /* accent text on light surfaces, 6:1 */
  --profit: #15803D;
  --profit-bg: #F0FDF4;
  --loss: #DC2626;
  --loss-bg: #FEF2F2;
  --warn: #A16207;             /* yellow-brown: must not read as the button */
  --warn-bg: #FEFCE8;
  --info: #2563EB;
  --info-bg: #EFF6FF;

  /* — Data palette. Categorical slots in a fixed, validated order (dataviz
       validator: adjacent CVD ΔE ≥ 8.4, normal-vision ≥ 19.8, both themes).
       Assign by entity through seriesColor(key) in app.js — never by rank. */
  --data-1: #D97706;  /* amber */
  --data-2: #1BAF7A;  /* aqua */
  --data-3: #EB6834;  /* orange */
  --data-4: #2A78D6;  /* blue */
  --data-5: #E87BA4;  /* magenta */
  --data-6: #008300;  /* green */
  --data-7: #6250D6;  /* violet */
  --data-8: #E34948;  /* red */
  --data-other: #A8A29E;
  /* Asset classes keep one colour on every screen (validated all-pairs). */
  --asset-cash: var(--data-2);
  --asset-invest: var(--data-1);
  --asset-property: var(--data-4);
  /* Money flows keep one colour too: what came in, what life cost, what went
     to investments (same entity as the asset class), what went to the cushion. */
  --flow-income: var(--data-2);
  --flow-living: var(--data-5);
  --flow-invest: var(--asset-invest);
  --flow-cushion: var(--data-4);

  --chart-primary: var(--data-1);
  --chart-primary-light: #E5A94E;
  --chart-secondary: #C2785C;
  --chart-green: #65A30D;
  --chart-blue: var(--data-4);
  --chart-grid: rgba(41, 37, 36, 0.07);
  --chart-axis: var(--text-tertiary);

  --sidebar-width: 240px;
  --content-max: 1440px;

  /* Legacy names, kept so older rules resolve; prefer the tokens above. */
  --kpi-gradient-1: linear-gradient(135deg, #FDE8E8 0%, #FECACA 100%);
  --kpi-gradient-2: linear-gradient(135deg, #FEF3C7 0%, #FDE68A 100%);
  --kpi-text: var(--text-primary);
  --bg-input: var(--bg-secondary);
  --border-subtle: var(--border);
  /* Allocation buckets wear the asset-class colours; crypto is violet, as in
     every chart that names it. Currencies get their own three. */
  --alloc-stocks: var(--asset-invest);
  --alloc-crypto: var(--data-7);
  --alloc-cash: var(--asset-cash);
  --alloc-property: var(--asset-property);
  --alloc-other: var(--data-other);
  --cur-kzt: var(--data-3);
  --cur-usd: var(--data-6);
  --cur-crypto: var(--data-7);
  --cur-other: var(--data-other);
}

/* ===== DARK THEME =====
   Warm, like the light theme — not a neutral grey. Declared twice: the media
   query follows the OS, the data-theme attribute follows the switcher. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-primary: #171614;
    --bg-secondary: #23211F;
    --bg-card: #1F1E1C;
    --bg-sidebar: #100F0E;
    --bg-sidebar-hover: #1F1D1B;
    --bg-sidebar-active: #2E2B28;
    --text-primary: #ECE9E4;
    --text-secondary: #A29D96;
    --text-tertiary: #6F6A64;
    --text-sidebar: #E7E5E4;
    --text-sidebar-muted: #8A847D;
    --border: #2E2B28;
    --border-strong: #423E3A;
    --input-bg: #23211F;
    --input-border: #45413C;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.05);
    --shadow-md: 0 8px 24px -8px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.06);
    --shadow-lg: 0 20px 44px -12px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.07);
    --accent: #E08A1E;
    --accent-hover: #F0A040;
    --accent-soft: rgba(224, 138, 30, 0.14);
    --accent-ink: #F2B25C;
    --btn-primary-bg: #E08A1E;     /* dark ink 6.9:1 */
    --btn-primary-hover: #F09A32;
    --btn-primary-ink: #1A1209;
    --profit: #3FB96A;
    --profit-bg: rgba(63, 185, 106, 0.12);
    /* #DC2626 sits at ~3.6:1 on the dark card — under AA for small red figures. */
    --loss: #F87171;
    --loss-bg: rgba(248, 113, 113, 0.12);
    --warn: #F59E0B;
    --warn-bg: rgba(245, 158, 11, 0.12);
    --info-bg: rgba(37, 99, 235, 0.14);
    --data-1: #C98500;
    --data-2: #199E70;
    --data-3: #D95926;
    --data-4: #3987E5;
    --data-5: #D55181;
    --data-6: #008300;
    --data-7: #9085E9;
    --data-8: #E66767;
    --data-other: #6F6A64;
    --chart-primary-light: #8A5A1A;
    --chart-green: #84CC16;
    --chart-grid: rgba(255, 255, 255, 0.06);
    --kpi-gradient-1: linear-gradient(135deg, #3D2020 0%, #4A2525 100%);
    --kpi-gradient-2: linear-gradient(135deg, #3D3520 0%, #4A4025 100%);
  }
}
html[data-theme="dark"] {
  --bg-primary: #171614;
  --bg-secondary: #23211F;
  --bg-card: #1F1E1C;
  --bg-sidebar: #100F0E;
  --bg-sidebar-hover: #1F1D1B;
  --bg-sidebar-active: #2E2B28;
  --text-primary: #ECE9E4;
  --text-secondary: #A29D96;
  --text-tertiary: #6F6A64;
  --text-sidebar: #E7E5E4;
  --text-sidebar-muted: #8A847D;
  --border: #2E2B28;
  --border-strong: #423E3A;
  --input-bg: #23211F;
  --input-border: #45413C;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.05);
  --shadow-md: 0 8px 24px -8px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.06);
  --shadow-lg: 0 20px 44px -12px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.07);
  --accent: #E08A1E;
  --accent-hover: #F0A040;
  --accent-soft: rgba(224, 138, 30, 0.14);
  --accent-ink: #F2B25C;
  --btn-primary-bg: #E08A1E;
  --btn-primary-hover: #F09A32;
  --btn-primary-ink: #1A1209;
  --profit: #3FB96A;
  --profit-bg: rgba(63, 185, 106, 0.12);
  --loss: #F87171;
  --loss-bg: rgba(248, 113, 113, 0.12);
  --warn: #F59E0B;
  --warn-bg: rgba(245, 158, 11, 0.12);
  --info-bg: rgba(37, 99, 235, 0.14);
  --data-1: #C98500;
  --data-2: #199E70;
  --data-3: #D95926;
  --data-4: #3987E5;
  --data-5: #D55181;
  --data-6: #008300;
  --data-7: #9085E9;
  --data-8: #E66767;
  --data-other: #6F6A64;
  --chart-primary-light: #8A5A1A;
  --chart-green: #84CC16;
  --chart-grid: rgba(255, 255, 255, 0.06);
  --kpi-gradient-1: linear-gradient(135deg, #3D2020 0%, #4A2525 100%);
  --kpi-gradient-2: linear-gradient(135deg, #3D3520 0%, #4A4025 100%);
}

/* ===== BASE ===== */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: var(--lh-normal);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  margin: 0;
  padding: 0;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Inline code reads as text in a quieter face, not Bootstrap's pink. */
code { color: inherit; }

/* One visible focus treatment for everything keyboard-reachable. */
a:focus-visible,
button:focus-visible,
[tabindex]:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

::selection { background: color-mix(in oklab, var(--accent) 28%, transparent); }

/* ===== SIDEBAR ===== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background-color: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-sidebar-active) transparent;
}

.sidebar-header {
  padding: var(--sp-6) var(--sp-5) var(--sp-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-logo {
  font-family: var(--font-display);
  font-size: 22px;
  color: var(--text-sidebar);
  text-decoration: none;
}

.sidebar-logo:hover {
  color: var(--text-sidebar);
  text-decoration: none;
}

.sidebar-close {
  background: none;
  border: none;
  color: var(--text-sidebar-muted);
  cursor: pointer;
  padding: var(--sp-1);
}

.sidebar-nav {
  flex: 1;
  padding: var(--sp-1) var(--sp-3);
}

.sidebar-group {
  margin-bottom: var(--sp-3);
}

.sidebar-group-title {
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--text-sidebar-muted);
  padding: var(--sp-2) var(--sp-3) var(--sp-1);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 7px var(--sp-3);
  border-radius: var(--radius-md);
  color: var(--text-sidebar);
  opacity: 0.86;
  text-decoration: none;
  font-size: var(--fs-md);
  font-weight: var(--fw-medium);
  transition: background-color var(--dur-fast), opacity var(--dur-fast);
}

.sidebar-link:hover {
  background-color: var(--bg-sidebar-hover);
  color: var(--text-sidebar);
  opacity: 1;
  text-decoration: none;
}

.sidebar-link.active {
  background-color: var(--bg-sidebar-active);
  color: #fff;
  opacity: 1;
  box-shadow: inset 3px 0 0 var(--accent);
}

.sidebar-link.active i,
.sidebar-link.active svg { color: var(--accent); }

.sidebar-link i,
.sidebar-link svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--bg-sidebar-hover);
}

.theme-switcher {
  display: flex;
  gap: 2px;
  background: var(--bg-sidebar-hover);
  border-radius: var(--radius-md);
  padding: 3px;
  width: 100%;
}

.theme-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-sidebar-muted);
  cursor: pointer;
  padding: 6px 0;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--dur-fast), background var(--dur-fast);
}

.theme-btn:hover {
  color: var(--text-sidebar);
}

.theme-btn--active {
  background: var(--bg-sidebar-active);
  color: #fff;
}

.theme-btn--active:hover {
  color: #fff;
}

/* ===== CONTENT ===== */
.content {
  margin-left: var(--sidebar-width);
  padding: var(--sp-8);
  min-height: 100vh;
}
/* Beyond ~1700px a dashboard row of five tiles turns into a strip of
   stretched boxes; hold the measure and centre it. */
.content > * {
  max-width: var(--content-max);
  margin-left: auto;
  margin-right: auto;
}

/* ===== PAGE HEADER ===== */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-6);
  flex-wrap: wrap;
  gap: var(--sp-4);
}

.page-title {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  font-weight: 400;
  line-height: var(--lh-tight);
  letter-spacing: -0.005em;
  margin: 0;
  color: var(--text-primary);
}
/* One line under the title: the period or scope the page is about. */
.page-subtitle {
  margin: var(--sp-1) 0 0;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}

.page-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  /* Pages with three or four header buttons pushed the whole document sideways
     on a phone; let the row wrap instead. */
  flex-wrap: wrap;
}

/* ===== BUTTONS =====
   Four kinds: primary (one per view), secondary (outline), ghost (quiet, in
   toolbars), icon. Two heights: 36 (default) and 32 (-sm). */
.btn-primary,
.btn-accent,
.btn-outline,
.btn-outline-sm,
.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  height: 36px;
  padding: 0 var(--sp-4);
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast), box-shadow var(--dur-fast);
}
.btn-primary svg, .btn-outline svg, .btn-outline-sm svg, .btn-ghost svg, .btn-accent svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-primary,
.btn-accent {
  background-color: var(--btn-primary-bg);
  color: var(--btn-primary-ink);
  border: 1px solid transparent;
  box-shadow: 0 1px 2px rgba(41, 37, 36, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
.btn-primary:hover,
.btn-accent:hover {
  background-color: var(--btn-primary-hover);
  color: var(--btn-primary-ink);
  text-decoration: none;
}

.btn-outline,
.btn-outline-sm {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
}
.btn-outline:hover,
.btn-outline-sm:hover {
  background: var(--bg-secondary);
  border-color: var(--text-tertiary);
  color: var(--text-primary);
  text-decoration: none;
}
.btn-outline-sm {
  height: 32px;
  padding: 0 var(--sp-3);
  font-size: var(--fs-xs);
}
.btn-outline-sm svg { width: 14px; height: 14px; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
}
.btn-primary:disabled, .btn-accent:disabled, .btn-outline:disabled, .btn-outline-sm:disabled {
  opacity: 0.45;
  cursor: default;
  box-shadow: none;
  pointer-events: none;
}
.btn-ghost:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
  text-decoration: none;
}

/* Period switcher: ‹ Сентябрь 2026 › — the same control on every dated page. */
.period-nav {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.period-nav a,
.period-nav span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 30px;
  min-width: 30px;
  padding: 0 var(--sp-2);
  border-radius: 7px;
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
  text-decoration: none;
  font-variant-numeric: tabular-nums;
}
.period-nav a { color: var(--text-secondary); }
.period-nav a:hover { background: var(--bg-secondary); color: var(--text-primary); }
.period-nav a svg { width: 16px; height: 16px; }
.period-nav .period-current { padding: 0 var(--sp-3); }
.period-nav .is-disabled { opacity: 0.35; pointer-events: none; }

/* ===== TABLES ===== */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}

.data-table thead th {
  background-color: var(--bg-secondary);
  font-family: var(--font-sans);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--text-secondary);
  padding: 10px var(--sp-3);
  border-bottom: 1px solid var(--border-strong);
  position: sticky;
  top: 0;
  z-index: 10;
  white-space: nowrap;
}
.data-table thead th:first-child { border-top-left-radius: var(--radius-sm); }
.data-table thead th:last-child { border-top-right-radius: var(--radius-sm); }

.data-table tbody td {
  padding: 10px var(--sp-3);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tbody tr {
  transition: background-color var(--dur-fast);
}

.data-table tbody tr:hover {
  background-color: color-mix(in oklab, var(--bg-secondary) 70%, transparent);
}

/* A whole row that opens something: the row is the target, not a button in it. */
.data-table tr.row-link { cursor: pointer; }
.data-table tr.row-link:hover td:first-child { color: var(--accent-ink); }

.data-table .num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  text-align: right;
  font-size: var(--fs-sm);
}

.data-table .total-row {
  font-weight: var(--fw-bold);
  background-color: var(--bg-secondary);
}

.data-table tr.row-empty { opacity: 0.3; }

.data-table td.nowrap, .data-table th.nowrap { white-space: nowrap; }

/* Wide tables scroll inside their own box instead of pushing the page sideways. */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ===== Sortable Tables =====
   Click a header to sort by it; numeric columns start descending.
   Behaviour lives in static/js/app.js. */
.sortable-table thead th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: color var(--dur-fast);
}

.sortable-table thead th.sortable:hover { color: var(--text-primary); }

.sortable-table thead th.sortable::after {
  content: "\2195";
  margin-left: 5px;
  font-size: 10px;
  opacity: 0.3;
}

.sortable-table thead th.sortable[aria-sort="ascending"]::after { content: "\2191"; opacity: 0.85; }
.sortable-table thead th.sortable[aria-sort="descending"]::after { content: "\2193"; opacity: 0.85; }

.data-table tfoot td {
  font-weight: var(--fw-semibold);
  border-top: 1px solid var(--border-strong);
  padding: 10px var(--sp-3);
}

/* Rank column of a ranking table: quiet by default, accented for the top three. */
.data-table .rank-cell {
  color: var(--text-secondary);
  width: 40px;
}

.data-table tr.row-podium .rank-cell {
  color: var(--accent-ink);
  font-weight: var(--fw-bold);
}

.data-table .sticky-col {
  position: sticky;
  left: 0;
  background-color: var(--bg-card);
  z-index: 5;
}

/* A sticky header cell has to keep the header's own background, otherwise the
   columns scrolling underneath show through the "Месяц" label. */
.data-table thead .sticky-col {
  background-color: var(--bg-secondary);
  z-index: 11;
}

/* ===== CARDS / PANELS ===== */
.card-panel {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: var(--pad-card);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--gap-grid);
}

.card-panel-title {
  font-family: var(--font-sans);
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  margin-bottom: var(--sp-4);
  color: var(--text-primary);
}

/* Section heading between groups of cards. */
.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  /* Block margins only: a shorthand here reset the auto side margins that
     centre .content's children past 1700px, and the heading slid off to the
     left of the cards it titles. */
  margin-block: var(--gap-section) var(--sp-3);
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
}
.section-title:first-child { margin-top: 0; }
.section-title small,
.section-title .section-link {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--text-secondary);
  text-decoration: none;
}
.section-title .section-link:hover { color: var(--accent-ink); }

/* ===== EMPTY STATE =====
   Says why a block is empty and what to do about it. Markup: the
   "empty-state" component. */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-10) var(--sp-6);
  text-align: center;
  color: var(--text-secondary);
}
.empty-state-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-bottom: var(--sp-1);
  border-radius: var(--radius-pill);
  background: var(--bg-secondary);
  color: var(--text-tertiary);
}
.empty-state-icon svg { width: 22px; height: 22px; }
.empty-state-title { margin: 0; font-size: var(--fs-md); font-weight: var(--fw-semibold); color: var(--text-primary); }
.empty-state-text { margin: 0 0 var(--sp-2); max-width: 42ch; font-size: var(--fs-sm); line-height: var(--lh-normal); }

/* ===== BADGES & CHIPS =====
   Badge: a status or a count, never a button. Chip: a removable/selectable
   filter. */
.badge-soft {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 var(--sp-2);
  border-radius: var(--radius-pill);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semibold);
  line-height: 1;
  white-space: nowrap;
  background: var(--bg-secondary);
  color: var(--text-secondary);
}
.badge-soft svg { width: 12px; height: 12px; }
.badge-soft.is-accent { background: var(--accent-soft); color: var(--accent-ink); }
.badge-soft.is-profit { background: var(--profit-bg); color: var(--profit); }
.badge-soft.is-loss { background: var(--loss-bg); color: var(--loss); }
.badge-soft.is-warn { background: var(--warn-bg); color: var(--warn); }
.badge-soft.is-info { background: var(--info-bg); color: var(--info); }

/* Count bubble on a button ("Действия 28"). */
.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: #fff;
  font-size: var(--fs-2xs);
  font-weight: var(--fw-bold);
  font-variant-numeric: tabular-nums;
}

/* ===== PROGRESS =====
   A thin track; the fill says how far, the colour says whether it is on time. */
.progress-track {
  position: relative;
  width: 100%;
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--bg-secondary);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.6s var(--ease-out);
}
.progress-fill.is-done { background: var(--profit); }
.progress-fill.is-late { background: var(--loss); }
/* A tick on the track: where the fill should be by today. */
.progress-marker {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 2px;
  border-radius: 1px;
  background: var(--text-primary);
  opacity: 0.55;
}

/* ===== STAT STRIP =====
   A row of small figures inside one card, separated by hairlines — for
   breakdowns that are one fact in several parts (P&L by source, etc.). */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr));
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--gap-grid);
}
/* Dividers are drawn between cells, not clipped off at the edges: an
   overflow: hidden on the strip cut every hint popup inside it in half. */
.stat-strip-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--sp-4) var(--sp-5);
}
.stat-strip-item + .stat-strip-item { box-shadow: -1px 0 0 var(--border); }
.stat-strip-label { font-size: var(--fs-xs); color: var(--text-secondary); }
.stat-strip-value { font-size: var(--fs-lg); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; letter-spacing: var(--tracking-tight); }

/* ===== SHARE BAR =====
   One 100% bar split into parts, with a legend that carries the figures:
   what the capital is made of, where the month's growth came from. Colour
   comes from the segment's own class (--sb), set by .sb-* or a data slot. */
.sharebar { display: flex; gap: 2px; height: 28px; margin: var(--sp-1) 0 var(--sp-4); }
.sharebar-seg {
  min-width: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--sb, var(--data-other));
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semibold);
  color: #fff;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  transition: opacity var(--dur-fast);
}
.sharebar-seg:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.sharebar-seg:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.sharebar-seg:only-child { border-radius: var(--radius-sm); }
.sharebar-legend {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 104px), 1fr));
  gap: var(--sp-3) var(--sp-5);
  margin: 0;
  padding: 0;
  list-style: none;
  align-items: start;
}
.sharebar-item { display: grid; grid-template-columns: 10px minmax(0, 1fr); column-gap: var(--sp-2); row-gap: 2px; align-items: baseline; transition: opacity var(--dur-fast); }
.sharebar-item::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--sb, var(--data-other)); align-self: center; }
.sharebar-name { font-size: var(--fs-sm); color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sharebar-value { grid-column: 2; font-size: var(--fs-lg); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; letter-spacing: var(--tracking-tight); }
.sharebar-value small { margin-left: 6px; font-size: var(--fs-xs); font-weight: var(--fw-regular); color: var(--text-secondary); letter-spacing: 0; }
.sharebar-note { grid-column: 2; font-size: var(--fs-xs); color: var(--text-secondary); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sharebar.is-hovering .sharebar-seg:not(.is-on),
.bridge.is-hovering .bridge-seg:not(.is-on),
.sharebar-legend.is-hovering .sharebar-item:not(.is-on),
.bridge-legend.is-hovering .sharebar-item:not(.is-on) { opacity: 0.35; }
/* Four parts: one row where there is room, two by two on a phone — never 3 + 1. */
.sharebar-legend[data-n="4"] { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 640px) {
  .sharebar-legend[data-n="4"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* Two or three parts on a phone read best as a list: name left, figure right. */
  .sharebar-legend:not([data-n="4"]) { grid-template-columns: minmax(0, 1fr); gap: var(--sp-2); }
  .sharebar-legend:not([data-n="4"]) .sharebar-item { grid-template-columns: 10px minmax(0, 1fr) auto; }
  .sharebar-legend:not([data-n="4"]) .sharebar-value { grid-column: 3; grid-row: 1; font-size: var(--fs-md); text-align: right; }
  .sharebar-legend:not([data-n="4"]) .sharebar-note { grid-column: 2 / 4; }
}
.sb-cash { --sb: var(--asset-cash); }
.sb-invest { --sb: var(--asset-invest); }
.sb-property { --sb: var(--asset-property); }
.sb-other { --sb: var(--data-other); }
.sb-1 { --sb: var(--data-1); } .sb-2 { --sb: var(--data-2); } .sb-3 { --sb: var(--data-3); } .sb-4 { --sb: var(--data-4); }
.sb-5 { --sb: var(--data-5); } .sb-6 { --sb: var(--data-6); } .sb-7 { --sb: var(--data-7); } .sb-8 { --sb: var(--data-8); }

/* ===== SEGMENTED CONTROL =====
   Two to five mutually exclusive views of one thing (chart range, period). */
.seg-control {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
}
.seg-control button {
  white-space: nowrap;
  height: 26px;
  padding: 0 var(--sp-3);
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-secondary);
  font: var(--fw-semibold) var(--fs-xs) / 1 var(--font-sans);
  cursor: pointer;
  transition: background var(--dur-fast), color var(--dur-fast);
}
.seg-control button:hover { color: var(--text-primary); }
.seg-control button[aria-pressed="true"] { background: var(--bg-card); color: var(--text-primary); box-shadow: var(--shadow-sm); }

/* Card header with a title on the left and controls on the right. */
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-2) var(--sp-3);
  margin-bottom: var(--sp-4);
}
.card-head .chart-title { margin-bottom: 0; }
.card-head-aside { font-size: var(--fs-sm); color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.card-head-link { font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text-secondary); text-decoration: none; white-space: nowrap; }
.card-head-link:hover { color: var(--accent-ink); }

/* Sparkline inside a hero card: shape of the trend, no axes. */
.hero-spark { position: relative; height: 44px; margin: var(--sp-3) calc(var(--sp-2) * -1) calc(var(--sp-2) * -1); }

/* Touch: every control at least 40px tall, header toolbars stay on one row. */
@media (pointer: coarse) {
  .btn-primary, .btn-accent, .btn-outline, .btn-ghost { height: 44px; }
  .btn-outline-sm { height: 40px; }
  .period-nav a, .period-nav span { height: 38px; min-width: 38px; }
}
@media (max-width: 640px) {
  .page-actions .btn-outline-sm { padding: 0 10px; }
  .dash-hero-card { padding: var(--sp-5); }
  .dash-hero-card .hero-spark { height: 32px; }
}

/* ===== FORMS ===== */
.form-input {
  background: var(--input-bg);
  border: none;
  border-bottom: 2px solid var(--input-border);
  color: var(--text-primary);
  padding: 6px 4px;
  font-size: var(--fs-sm);
  width: 100%;
  transition: border-color var(--dur-base);
}

.form-input:focus {
  outline: none;
  border-bottom-color: var(--accent);
}

.form-input.num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* ===== FORM LAYOUT ===== */
.form-group {
  margin-bottom: var(--sp-4);
}

.form-label {
  display: block;
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  min-height: 40px;
  padding: 8px var(--sp-3);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  background: var(--input-bg);
  color: var(--text-primary);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}

.form-control::placeholder {
  color: var(--text-tertiary);
  opacity: 1;
}

.form-control:focus {
  border-color: var(--accent);
  box-shadow: var(--ring-focus);
  /* Bootstrap paints a focused field white; on the dark theme that left
     light figures on a white box. */
  background: var(--input-bg);
  color: var(--text-primary);
}

/* A select is a field like any other: same height, type and border as
   .form-control; Bootstrap keeps only the chevron. */
.form-select {
  min-height: 40px;
  padding-top: 8px; padding-bottom: 8px; padding-left: var(--sp-3);
  font-family: var(--font-sans); font-size: var(--fs-md);
  background-color: var(--input-bg); color: var(--text-primary);
  border: 1px solid var(--input-border); border-radius: var(--radius-md);
}
.form-select:focus { border-color: var(--accent); box-shadow: var(--ring-focus); }

.form-control:disabled {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: not-allowed;
}

.form-control.input-number {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* Direction toggle in target label */
.direction-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  transition: background var(--dur-fast);
}
.direction-toggle:hover {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.direction-toggle .dir-icon-down { display: none; }
.direction-toggle .dir-icon-up { display: inline; color: var(--accent); }
.direction-toggle.down .dir-icon-down { display: inline; color: var(--accent); }
.direction-toggle.down .dir-icon-up { display: none; }

/* Styled checkbox */
.goal-checkbox {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-strong);
  border-radius: 5px;
  background: var(--input-bg);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: all var(--dur-fast) ease;
}
.goal-checkbox:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.goal-checkbox:checked::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 1px;
  width: 5px;
  height: 9px;
  border: solid var(--bg-primary);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.goal-checkbox:hover {
  border-color: var(--accent);
}

.form-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-top: var(--sp-6);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--border);
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-4);
}

/* ===== CHARTS ===== */
.chart-container {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: var(--pad-card);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--gap-grid);
}

.chart-title {
  font-family: var(--font-sans);
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  line-height: 1.3;
  margin-bottom: var(--sp-4);
  color: var(--text-primary);
}
/* Says what range a chart covers when it differs from the page's period. */
.chart-scope {
  font-size: var(--fs-xs);
  font-weight: var(--fw-regular);
  color: var(--text-secondary);
}

/* Chart canvas box: the height lives here, not in a style attribute. */
.chart-box { position: relative; height: 280px; }
.chart-box--sm { height: 200px; }
.chart-box--lg { height: 340px; }
@media (max-width: 640px) {
  .chart-box { height: 240px; }
  .chart-box--lg { height: 280px; }
}

/* Charts side-by-side row */
.ea-charts-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--gap-grid);
}
@media (max-width: 900px) {
  .ea-charts-row { grid-template-columns: 1fr; }
}



/* ===== MOBILE HEADER ===== */
.mobile-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background-color: var(--bg-sidebar);
  display: flex;
  align-items: center;
  padding: 0 var(--sp-2);
  gap: var(--sp-2);
  z-index: 999;
}

.hamburger {
  background: none;
  border: none;
  color: var(--text-sidebar);
  cursor: pointer;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
}

.mobile-title {
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--text-sidebar);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(12, 10, 9, 0.5);
  backdrop-filter: blur(2px);
  z-index: 999;
}

.sidebar-overlay.show {
  display: block;
}

/* ===== TOAST ===== */
.toast-container {
  position: fixed;
  bottom: var(--sp-6);
  right: var(--sp-6);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.toast {
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--radius-md);
  font-size: var(--fs-md);
  color: #fff;
  box-shadow: var(--shadow-md);
  animation: slide-in-right 0.3s var(--ease-out);
  max-width: 360px;
}

/* Bootstrap hides every .toast without .show and adds a border and a fixed
   width; ours are plain notices that appear on creation. */
.toast-container .toast { display: block; width: auto; border: 0; }
.toast.success { background-color: var(--profit); }
.toast.error { background-color: var(--loss); }
.toast.info { background-color: var(--info); }

/* ===== ANIMATIONS ===== */
@keyframes fade-in-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slide-in-right {
  from {
    opacity: 0;
    transform: translateX(100px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== UTILITY ===== */
.text-profit { color: var(--profit); }
.text-loss { color: var(--loss); }
.text-secondary { color: var(--text-secondary); }
/* Not .text-muted: Bootstrap owns that name with a fixed dark grey that vanishes on the dark theme. */
.text-quiet { color: var(--text-secondary); }
.text-faint { color: var(--text-tertiary); }
.text-warn { color: var(--warn); }
/* Historic name; figures use the one sans with tabular digits now. */
.text-mono { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
/* Button text that gives way to the icon alone on a narrow phone. */
@media (max-width: 400px) { .hide-xs { display: none; } }
/* Table columns that give way on a phone so the ones that matter fit. */
@media (max-width: 640px) { .hide-sm { display: none !important; } }
@media (min-width: 641px) { .show-sm { display: none !important; } }

.bg-profit { background-color: var(--profit-bg); }
.bg-loss { background-color: var(--loss-bg); }

/* ===== RESPONSIVE ===== */

/* Tablet: sidebar collapses to icons */
@media (max-width: 1200px) and (min-width: 768px) {
  .sidebar {
    width: 64px;
  }
  .sidebar-group-title,
  .sidebar-link span,
  .sidebar-logo {
    display: none;
  }
  .sidebar-header {
    padding: var(--sp-4) var(--sp-3);
    justify-content: center;
  }
  .sidebar-nav { padding: var(--sp-1) var(--sp-2); }
  .sidebar-group { padding-top: var(--sp-2); border-top: 1px solid var(--bg-sidebar-hover); }
  .sidebar-group:first-child { border-top: 0; }
  .sidebar-link {
    justify-content: center;
    padding: 10px;
  }
  .sidebar-footer {
    padding: var(--sp-2);
  }
  .theme-switcher {
    flex-direction: column;
    width: auto;
  }
  .content {
    margin-left: 64px;
    padding: var(--sp-6);
  }
}

/* Mobile: sidebar hidden behind hamburger */
@media (max-width: 767.98px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s var(--ease-out);
    width: min(300px, 86vw);
  }
  .sidebar.show {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
  .content {
    margin-left: 0;
    padding: 72px var(--sp-4) var(--sp-8);
  }
  .page-header { margin-bottom: var(--sp-5); gap: var(--sp-3); }
  .page-title {
    font-size: 24px;
  }
  .card-panel { padding: var(--sp-4); }
}

/* Desktop */
@media (min-width: 768px) {
  .mobile-header {
    display: none !important;
  }
}

/* ===== SCROLLBAR ===== */
.table-scroll {
  overflow-x: auto;
}

/* ===== BUDGET PAGE ===== */
/* One month: a plan while it is open, plan against fact once it is closed.
   Header carries the month switcher and the rate; the hero row answers
   "how did the month go"; the variance strip says where; the tables are
   where figures are entered. */
.budget-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px;
  align-items: start;
}

/* Display rules below would otherwise beat the hidden attribute. */
.budget-layout [hidden]:not(.budget-ref-delta),
.budget-variance [hidden] { display: none !important; }

.budget-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.budget-main > .card-panel { margin-bottom: 0; }

.budget-sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: 24px;
}
.budget-sidebar > .card-panel { margin-bottom: 0; }

@media (max-width: 1200px) {
  .budget-layout { grid-template-columns: minmax(0, 1fr); }
  .budget-sidebar { position: static; }
}

/* Header */
.budget-header { margin-bottom: 24px; }

.budget-phase {
  margin-left: 8px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--bg-secondary);
  color: var(--text-secondary);
}
.budget-phase--current { background: var(--warn-bg); color: var(--warn); }

.budget-rate {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 4px 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  font-size: 13px;
  color: var(--text-secondary);
}
.budget-rate:focus-within { border-color: var(--accent); }
.budget-rate-input {
  width: 64px;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  text-align: right;
  padding: 0;
}
.budget-rate-reset {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 26px;
  margin-left: 2px;
  padding: 0 8px;
  border: none;
  border-radius: 6px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font: inherit;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.budget-rate-reset:hover { color: var(--accent); }

/* Hero: three cards, one row on desktop */
.budget-hero { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 16px; }
.budget-hero .dash-hero-card { padding: 24px 28px; margin-bottom: 0; }
.budget-hero .dash-hero-sub { line-height: 1.5; }
@media (max-width: 1000px) {
  .budget-hero { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .budget-hero .dash-hero-card { padding: 18px 20px; }
}

/* Variance strip */
.budget-variance {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px 24px;
  margin-bottom: 24px;
}
.budget-variance[hidden], .budget-variance-group[hidden] { display: none; }
.budget-variance-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}
.budget-variance-group {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  align-items: baseline;
  gap: 8px 12px;
}
.budget-variance-label { font-size: 13px; color: var(--text-secondary); }
.budget-variance-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.budget-variance-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  min-height: 30px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text-primary);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.budget-variance-chip:hover { border-color: var(--border-strong); background: var(--bg-secondary); }
.budget-variance-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.budget-variance-chip .mono-number { font-weight: 600; }
.budget-variance-more { align-self: center; font-size: 12px; color: var(--text-secondary); padding: 0 4px; }
@media (max-width: 640px) {
  .budget-variance { padding: 16px; }
  .budget-variance-group { grid-template-columns: minmax(0, 1fr); gap: 6px; }
}

/* Tables */
.budget-card { padding-bottom: 8px; }
.budget-table { table-layout: fixed; }
.budget-table .budget-col-num { width: 112px; }
.budget-table .budget-col-trend { width: 68px; }
.budget-table .budget-col-ref { width: 168px; }
.budget-table thead th.text-center { text-align: center; }
.budget-table td { white-space: nowrap; }
.budget-table td.budget-name {
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.35;
}
.budget-tag {
  display: inline-block;
  margin-left: 4px;
  padding: 0 6px;
  border-radius: 4px;
  font-size: 11px;
  line-height: 18px;
  color: var(--profit);
  background: var(--profit-bg);
  vertical-align: 1px;
  white-space: nowrap;
}

.budget-table .input-number {
  width: 100%;
  max-width: 116px;
  padding: 6px 8px;
  text-align: right;
  font: inherit;
  font-size: 13px;
  background: transparent;
  color: var(--text-primary);
  border: none;
  border-bottom: 1px solid var(--input-border);
  border-radius: 0;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.budget-table .input-number::placeholder { color: var(--text-secondary); opacity: 0.6; }
.budget-table .input-number:hover { border-bottom-color: var(--text-secondary); }
.budget-table .input-number:focus {
  border-bottom-color: var(--accent);
  background: var(--bg-secondary);
}

/* Investment rows: told apart by the tag, not by a second background. */
.investment-row { background: none; }

/* Over plan: the remaining cell is red; a hairline on the left lets the eye
   find the row while scrolling. */
.budget-table tbody tr.is-over td:first-child { box-shadow: inset 2px 0 0 var(--loss); }

.budget-table tbody tr.is-flash { animation: budgetFlash 1.6s ease-out; }
@keyframes budgetFlash {
  0%, 30% { background: var(--warn-bg); }
  100% { background: transparent; }
}
@media (prefers-reduced-motion: reduce) {
  .budget-table tbody tr.is-flash { animation: none; background: var(--warn-bg); }
}

/* Empty rows (no plan, no fact) are folded away until asked for. */
.budget-table tbody tr.budget-row-empty { display: none; }
.budget-table.show-empty tbody tr.budget-row-empty { display: table-row; }
.budget-table .budget-empty-toggle-row td { padding: 0; border-bottom: none; }
.budget-table .budget-empty-toggle-row:hover { background: none; }
.budget-empty-toggle {
  width: 100%;
  padding: 10px 12px;
  border: none;
  background: none;
  text-align: left;
  font: inherit;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
}
.budget-empty-toggle:hover { color: var(--accent); }

/* Expense groups: a heading row per block carrying its subtotals. */
.budget-table tbody.budget-group[hidden] { display: none; }
.budget-table .budget-group-row th,
.budget-table .budget-group-row td {
  padding: 18px 12px 8px;
  border-bottom: 1px solid var(--border-strong);
  background: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}
.budget-table .budget-group-row th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-primary);
}
.budget-table .budget-group-row td.text-loss { color: var(--loss); }
.budget-table .budget-group-row:hover { background: none; }
.budget-table tbody.budget-group:first-of-type .budget-group-row th,
.budget-table tbody.budget-group:first-of-type .budget-group-row td { padding-top: 10px; }

.budget-group-select {
  display: none;
  margin-top: 6px;
  max-width: 100%;
  padding: 3px 6px;
  border: 1px solid var(--input-border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text-primary);
  font: inherit;
  font-size: 12px;
}
.budget-table.is-editing-groups .budget-group-select { display: block; }

/* Toolbar under the expenses heading */
.budget-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0 0 14px;
}
.budget-tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text-primary);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.budget-tool:hover:not(:disabled) { border-color: var(--border-strong); background: var(--bg-secondary); }
.budget-tool:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.budget-tool:disabled { opacity: 0.5; cursor: default; }
.budget-tool[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: var(--warn-bg); }
.budget-tool svg { color: var(--text-secondary); }
.budget-tool[aria-pressed="true"] svg { color: var(--accent); }
.budget-tool-count { color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.budget-toolbar-note { font-size: 12px; color: var(--text-secondary); }
.budget-tool-undo {
  padding: 0;
  border: none;
  background: none;
  font: inherit;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Trend: six past months in grey, this month in colour */
.budget-trend { text-align: center; }
.budget-trend-svg { display: inline-block; vertical-align: middle; }
.budget-trend-svg rect { fill: var(--border-strong); }
.budget-trend-svg rect.is-missing { fill: none; }
.budget-trend-svg rect.is-now { fill: var(--chart-primary); }
.budget-trend-svg rect.is-now.is-over { fill: var(--loss); }

/* Reference: the 3-month average (or last month) — click to copy into the plan. */
.budget-ref-cell { text-align: right; }
.budget-ref {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  padding: 2px 7px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: none;
  font: inherit;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.budget-ref:hover { border-color: var(--accent); color: var(--accent); }
.budget-ref-kind { font-size: 11px; color: var(--text-secondary); }
.budget-ref-delta {
  display: inline-block;
  min-width: 38px;
  margin-left: 4px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  text-align: right;
}
.budget-ref-delta[hidden] { display: inline-block; visibility: hidden; }

.totals-row {
  background: var(--bg-secondary);
  font-weight: 600;
}
.budget-table tfoot td { padding: 10px 12px; white-space: nowrap; }
.budget-table tfoot .totals-row--sub { background: none; font-weight: 500; }
.budget-table tfoot .totals-row--sub td { color: var(--text-secondary); border-bottom: 1px solid var(--border); }
.budget-table tfoot .totals-row--sub td.text-loss { color: var(--loss); }
.budget-table tfoot .budget-usd { font-weight: 500; color: var(--text-secondary); }

.totals-row .sticky-col {
  background-color: var(--bg-secondary);
}

/* Save bar sticks to the bottom of the viewport while the tables scroll. */
/* At rest the bar sits after the tables; once something is edited it sticks to
   the bottom of the viewport, so it only covers rows when there is a reason to. */
.budget-savebar {
  position: static;
  bottom: 16px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px 10px 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: color-mix(in srgb, var(--bg-card) 92%, transparent);
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 24px -12px rgba(28, 25, 23, 0.25);
}
.budget-savebar.is-dirty { position: sticky; }
.budget-savebar-status { font-size: 13px; color: var(--text-secondary); }
.budget-savebar.is-dirty .budget-savebar-status { color: var(--warn); font-weight: 600; }
.budget-savebar.is-dirty .budget-savebar-status::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--warn);
  vertical-align: 1px;
}
.budget-savebar-hint {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-secondary);
  opacity: 0.7;
}
.budget-savebar .btn-accent { min-height: 40px; padding-left: 24px; padding-right: 24px; }
/* Without the shortcut hint the actions still sit at the right edge. */
.budget-savebar-status + .btn-ghost, .budget-savebar-status + .btn-primary { margin-left: auto; }

/* Under the tables, away from Save and from the chat button. */
.budget-danger { display: flex; justify-content: flex-start; padding-top: 24px; }
.budget-delete {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 4px;
  border: none;
  background: none;
  font: inherit;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
}
.budget-delete:hover { color: var(--loss); }

/* Sidebar: consumption structure */
.budget-sidebar .dash-tile { justify-content: flex-start; padding: 20px 22px; }
.budget-structure-legend {
  display: flex;
  gap: 14px;
  margin: 2px 0 12px;
  font-size: 12px;
  color: var(--text-secondary);
}
.budget-structure-key { display: inline-flex; align-items: center; gap: 6px; }
.budget-structure-key::before { content: ""; display: inline-block; }
.budget-structure-key--fact::before { width: 12px; height: 6px; border-radius: 3px; background: var(--chart-primary); }
.budget-structure-key--plan::before { width: 2px; height: 12px; border-radius: 1px; background: var(--text-primary); }
.budget-structure-row {
  display: block;
  width: 100%;
  padding: 6px 0;
  border: none;
  background: none;
  font: inherit;
  text-align: left;
  color: var(--text-primary);
  cursor: pointer;
}
.budget-structure-row:hover .budget-structure-name { color: var(--accent); }
.budget-structure-row:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.budget-structure-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  margin-bottom: 5px;
}
.budget-structure-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-secondary); }
.budget-structure-track {
  position: relative;
  display: block;
  height: 6px;
  border-radius: 3px;
  background: var(--bg-secondary);
}
.budget-structure-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  border-radius: 3px;
  background: var(--chart-primary);
}
.budget-structure-fill.is-over { background: var(--loss); }
.budget-structure-mark {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 2px;
  border-radius: 1px;
  background: var(--text-primary);
}
.budget-structure-foot {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
}
.budget-structure-foot-row { display: flex; justify-content: space-between; gap: 12px; }
.budget-structure-foot:empty { display: none; }
.budget-structure-empty { font-size: 13px; color: var(--text-secondary); }

/* Below the two-column layout the save bar spans the page and would sit
   under the chat button; leave it room. */
@media (max-width: 1200px) {
  .budget-savebar { margin-right: 68px; }
}

/* Phone: each row becomes a small card — name on top, plan and fact side by
   side, so the fact column is never off screen. */
@media (max-width: 640px) {
  .budget-header { align-items: flex-start; }
  .budget-card { padding: 16px; }
  .budget-card .table-scroll-container.table-scroll-container { overflow: visible; box-shadow: none; }
  .budget-table, .budget-table tbody, .budget-table tfoot { display: block; }
  .budget-table colgroup, .budget-table thead { display: none; }
  .budget-table tbody tr, .budget-table tfoot tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px 16px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
  }
  .budget-table tbody tr:hover { background: none; }
  .budget-table.show-empty tbody tr.budget-row-empty { display: grid; }
  .budget-table tbody td, .budget-table tfoot td { display: block; padding: 0; border: none; text-align: left; }
  .budget-table tbody tr[data-name] { grid-template-areas: "name trend" "plan fact" "dev ref"; }
  .budget-table td.budget-name { grid-area: name; font-weight: 600; }
  .budget-table tbody tr[data-name] td[data-label="План"] { grid-area: plan; }
  .budget-table tbody tr[data-name] td[data-label="Факт"] { grid-area: fact; }
  .budget-table tbody tr[data-name] td.budget-dev { grid-area: dev; }
  .budget-table tbody tr[data-name] td.budget-trend { grid-area: trend; text-align: right; align-self: center; }
  .budget-table tbody tr[data-name] td.budget-ref-cell { grid-area: ref; }
  .budget-table .budget-group-row { grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 20px 0 8px; border-bottom: 1px solid var(--border-strong); }
  .budget-table .budget-group-row th { grid-column: 1 / -1; padding: 0; border: none; }
  .budget-table .budget-group-row td { padding: 0; border: none; text-align: left; }
  .budget-table .budget-group-row td:last-child { display: none; }
  .budget-table tbody.budget-group, .budget-table tbody.budget-toggle-body { display: block; }
  .budget-table tbody.budget-group[hidden] { display: none; }
  .budget-table tbody.budget-group:first-of-type .budget-group-row { padding-top: 0; }
  .budget-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 2px;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
  }
  .budget-table .input-number { max-width: none; font-size: 16px; padding: 6px 0; text-align: left; }
  /* Remaining and the reference share the last line: label and figure inline. */
  .budget-table td.budget-dev { align-self: center; font-size: 14px; }
  .budget-table td.budget-dev::before { display: inline; margin: 0 6px 0 0; }
  .budget-table td.budget-ref-cell { align-self: center; text-align: right; }
  .budget-table tbody tr.is-over td:first-child { box-shadow: none; }
  .budget-table tbody tr.is-over { box-shadow: inset 2px 0 0 var(--loss); padding-left: 12px; }
  .budget-table .budget-empty-toggle-row { display: block; padding: 0; border: none; }
  .budget-table .budget-empty-toggle-row td { display: block; }
  .budget-empty-toggle { min-height: 44px; padding: 10px 0; }
  .budget-table tfoot tr { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px 12px; padding: 12px; margin: 0 -12px; }
  .budget-table tfoot td:first-child { grid-column: 1 / -1; }
  .budget-table tfoot td:last-child:empty { display: none; }
  .budget-table tfoot .budget-usd { grid-column: 1 / -1; }
  .budget-ref-delta { min-width: 0; }
  .budget-savebar { bottom: 16px; padding-left: 16px; }
  .budget-savebar-hint, .budget-savebar .btn-ghost { display: none; }
  .budget-savebar-status { min-width: 0; }
  .budget-savebar .btn-primary { margin-left: auto; min-height: 44px; flex-shrink: 0; }
  .budget-savebar .btn-accent { margin-left: auto; min-height: 44px; }
  .budget-rate { height: 40px; }
  .budget-rate-input { font-size: 16px; }
  /* Room for the chat button over the last line of the page. */
  .budget-danger { padding-bottom: 72px; }
}

.col-narrow {
  width: 40px;
}

.table-scroll-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* A table wider than its panel otherwise just ends mid-column with nothing saying
   it scrolls. An inset shadow on the side that still has content reads as "more
   this way" and disappears once that edge is reached. Set by markScrollableTables(). */
.table-scroll-container.has-overflow-right {
  box-shadow: inset -28px 0 22px -24px rgba(0, 0, 0, 0.55);
}
.table-scroll-container.has-overflow-left {
  box-shadow: inset 28px 0 22px -24px rgba(0, 0, 0, 0.55);
}
.table-scroll-container.has-overflow-left.has-overflow-right {
  box-shadow: inset 28px 0 22px -24px rgba(0, 0, 0, 0.55),
              inset -28px 0 22px -24px rgba(0, 0, 0, 0.55);
}

/* Sticky first column: a right-edge shadow (via ::after, since box-shadow doesn't
   render on border-collapse cells) makes columns scrolling underneath read as passing
   behind it instead of looking like an overlap glitch, and hints there's more to scroll. */
.wide-table .sticky-col {
  position: sticky;
  left: 0;
}
.wide-table .sticky-col::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 10px;
  transform: translateX(100%);
  background: linear-gradient(to right, rgba(0, 0, 0, 0.14), rgba(0, 0, 0, 0));
  pointer-events: none;
}

.wide-table {
  min-width: 1200px;
}

.wide-table th,
.wide-table td {
  white-space: nowrap;
  padding: 8px 12px;
}

/* A group heading inside a long table: quiet tint, primary ink. It used to be
   a black sidebar-coloured bar, and the sticky first cell kept the card's
   white background, so the light label vanished on it. */
.section-header,
.section-header td,
.section-header .sticky-col {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.section-header td {
  font-family: var(--font-sans);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  padding: 10px var(--sp-3) 8px;
  border-top: var(--sp-3) solid var(--bg-card);
}
.section-header:hover { background: var(--bg-secondary) !important; }

.balance-row {
  border-top: 2px solid var(--border-strong);
}

.usd-row {
  font-style: italic;
}

.font-bold {
  font-weight: 700;
}

.btn-small {
  display: inline-block;
  padding: 4px 12px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--accent);
  border-radius: 6px;
  text-decoration: none;
  transition: all 0.2s;
}

.btn-small:hover {
  background: var(--accent);
  color: #fff;
}

.th-edit-link {
  color: var(--text-secondary);
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.15s;
}

.th-edit-link:hover {
  color: var(--accent);
}

.th-edit-link:hover i {
  opacity: 1 !important;
}

.table-link {
  color: var(--text-primary);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s;
}

.table-link:hover {
  color: var(--accent);
}


/* ===== GOAL CARDS ===== */
.goals-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
  margin-bottom: 1.5rem;
}

.goal-card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  gap: 16px;
  transition: transform 0.2s;
}

.goal-card:hover {
  transform: translateY(-2px);
}

.goal-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.goal-card-title {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.goal-card-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.goal-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 13px;
  color: var(--text-secondary);
}

.goal-card-meta-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.goal-card-meta-label {
  font-size: var(--fs-xs);
  color: var(--text-secondary);
}

.goal-card-meta-value {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.goal-progress-bar {
  width: 100%;
  height: 8px;
  background: var(--bg-secondary);
  border-radius: 4px;
  overflow: hidden;
}

.goal-progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.6s ease-out;
}

.goal-progress-fill.status-active {
  background: var(--accent);
}

.goal-progress-fill.status-completed {
  background: var(--profit);
}

.goal-progress-fill.status-overdue {
  background: var(--loss);
}

.goal-progress-info {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
}

.completed-goals-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
  width: 100%;
}

.completed-goals-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  color: var(--text-secondary);
  transition: color 0.2s;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.btn-icon:hover {
  color: var(--accent);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 6px;
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
}

.empty-state p {
  margin-bottom: 16px;
}

/* ===== DASHBOARD TILES ===== */
.dash-tiles {
  display: grid;
  /* min(100%, …): on a phone the floor must not exceed the column, or two
     squeezed tiles clip their own titles ("ROI ИНВЕСТИЦ…"). */
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  gap: var(--gap-grid);
  margin-bottom: var(--gap-grid);
}

.dash-tile,
a.dash-tile {
  padding: var(--pad-card-sm);
  display: flex;
  flex-direction: column;
}

.dash-tile-header {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--text-secondary);
  margin-bottom: var(--sp-3);
  min-height: 20px;
}
.dash-tile-header svg,
.dash-tile-header i { width: 16px; height: 16px; flex-shrink: 0; color: var(--accent); }
.dash-tile-header > span:first-of-type {
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  flex: 1;
  min-width: 0;
  /* line-clamp ends a *line*, so a single long word ("ХАЛЫКБАНК", "РАССРОЧКА")
     was sliced mid-letter with no ellipsis to say so. Let it break. */
  overflow-wrap: anywhere;
}

/* Passive-income table: months with no record yet — dim so they read as "future/empty". */
.pi-empty-row td { opacity: 0.4; }
.pi-empty-row .sticky-col { opacity: 0.55; }

.dash-tile-hint {
  position: relative;
  cursor: help;
  display: inline-flex;
  align-items: center;
}
/* The explanation behind a "?" is the same card as every hover card
   (.chart-tip): one surface, border, radius and shadow across the platform. */
.dash-tile-hint .hint-popup {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: var(--fs-xs);
  font-weight: var(--fw-regular);
  text-transform: none;
  letter-spacing: 0;
  white-space: normal;
  width: 240px;
  line-height: 1.5;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  pointer-events: none;
}
.dash-tile-hint:hover .hint-popup,
.dash-tile-hint:focus .hint-popup {
  display: block;
}
/* Set by keepHintsOnScreen() when there is no room to open upwards. */
.dash-tile-hint--below .hint-popup {
  bottom: auto;
  top: calc(100% + 8px);
}
/* Set by keepHintsOnScreen() when the popup's default right-edge anchoring would
   push it off the left side of the window. */
.dash-tile-hint.hint-flip-right .hint-popup {
  right: auto;
  left: 0;
}

.dash-tile-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--sp-3);
  padding: 5px 0;
  font-size: var(--fs-md);
  font-variant-numeric: tabular-nums;
}
.dash-tile-row + .dash-tile-row { border-top: 1px solid var(--border); }
.dash-tile-row > :last-child { white-space: nowrap; }

.dash-tile-label {
  color: var(--text-secondary);
  font-size: var(--fs-sm);
}

.dash-tile-divider {
  height: 1px;
  background: var(--border);
  margin: var(--sp-1) 0;
  margin-top: auto;
}
.dash-tile-divider + .dash-tile-row,
.dash-tile-row + .dash-tile-divider + .dash-tile-row { border-top: 0; }

.dash-tile-big {
  font-family: var(--font-num);
  font-size: var(--fs-xl);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-tight);
  font-variant-numeric: tabular-nums;
  padding: 0;
}
.dash-tile-sub {
  font-size: var(--fs-xs);
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ===== Dashboard Hero Cards ===== */

.dash-hero {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
  gap: var(--gap-grid);
  margin-bottom: var(--gap-grid);
}
.dash-hero-card {
  padding: var(--sp-6);
  margin-bottom: 0;
  animation: fade-in-up 0.4s var(--ease-out) both;
}
.dash-hero-card:nth-child(1) { animation-delay: 0ms; }
.dash-hero-card:nth-child(2) { animation-delay: 60ms; }
.dash-hero-card:nth-child(3) { animation-delay: 120ms; }
.dash-hero-card:nth-child(4) { animation-delay: 180ms; }
.dash-hero-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  margin-bottom: var(--sp-3);
  font-weight: var(--fw-medium);
}
.dash-hero-label > svg:first-child,
.dash-hero-label > i:first-child {
  width: 16px !important;
  height: 16px !important;
  margin-right: 0 !important;
  color: var(--accent);
  flex-shrink: 0;
}
.dash-hero-value {
  font-family: var(--font-num);
  font-size: var(--fs-hero);
  font-weight: var(--fw-semibold);
  letter-spacing: -0.025em;
  font-variant-numeric: lining-nums;
  line-height: var(--lh-tight);
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dash-hero-sub {
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.dash-hero-sub.text-profit { color: var(--profit); }
.dash-hero-sub.text-loss { color: var(--loss); }
/* Tablet: two headline cards per row; a phone gets its own rule below. */
@media (min-width: 641px) and (max-width: 900px) {
  .dash-hero { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-hero > .dash-hero-card:nth-child(odd):last-child { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
  .dash-hero { grid-template-columns: 1fr; }
}

/* ===== Dashboard Tile Links ===== */

/* A card that is a link. It keeps the card's own display (the tiles and hero
   cards are flex columns); a bare "display: block" here used to flatten them. */
a.dash-link {
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  cursor: pointer;
}
a.dash-link:hover {
  box-shadow: var(--shadow-md);
}

/* ===== Goals Progress Card ===== */

.dash-goals-card {
  margin-bottom: 1.5rem;
  padding: 12px 20px 16px;
}
.dash-goals-card .dash-tile-header {
  display: flex;
  align-items: center;
  gap: 6px;
}
.dash-goals-link {
  margin-left: auto;
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
  opacity: 0.7;
  transition: opacity 0.15s ease;
}
.dash-goals-link:hover {
  opacity: 1;
}
.dash-goals-grid {
  display: grid;
  /* min(100%, 240px): a fixed 240px floor cannot fit a 390px phone once the card
     padding is taken out, and the grid pushed the whole page sideways. */
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
  gap: 12px;
}
.dash-goal-item {
  background: var(--bg-input);
  border-radius: 8px;
  padding: 12px 14px;
  transition: background 0.15s ease;
}
.dash-goal-item:hover {
  background: color-mix(in srgb, var(--bg-input) 80%, var(--text-primary));
}
.dash-goal-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.dash-goal-name {
  font-size: 13px;
  line-height: 1.3;
  min-width: 0;
}
.dash-goal-pct {
  font-size: 13px;
  flex-shrink: 0;
  font-weight: 600;
}
.dash-goal-bar {
  width: 100%;
  height: 5px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.dash-goal-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
.dash-goal-bar-done {
  background: var(--profit);
}
.dash-goal-bar-overdue {
  background: var(--loss);
}
.dash-goal-deadline {
  display: block;
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 6px;
}

/* ===== Confirm Dialog ===== */

@keyframes confirmFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes confirmSlideIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.confirm-overlay {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--bg-sidebar) 60%, transparent);
  backdrop-filter: blur(3px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: confirmFadeIn 0.15s ease;
}
.confirm-dialog {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 28px 32px;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 8px 40px color-mix(in srgb, var(--bg-sidebar) 30%, transparent);
  animation: confirmSlideIn 0.2s ease;
}
.confirm-title {
  font-family: var(--font-sans);
  font-weight: var(--fw-semibold);
  font-size: 17px;
  color: var(--text-primary);
}
.confirm-text {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 8px 0 24px;
}
.confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.confirm-btn-cancel,
.confirm-btn-danger,
.confirm-btn-save {
  padding: 8px 20px;
  border-radius: 10px;
  border: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.confirm-btn-cancel {
  background: var(--bg-secondary);
  color: var(--text-primary);
}
.confirm-btn-cancel:hover { background: var(--border); }
.confirm-btn-danger {
  background: var(--loss);
  color: var(--bg-card);
}
.confirm-btn-danger:hover { opacity: 0.9; }
.confirm-btn-save {
  background: var(--accent);
  color: var(--bg-card);
}
.confirm-btn-save:hover { background: var(--accent-hover); }

/* Edit dialog textarea */
.edit-dialog-textarea {
  width: 100%;
  min-height: 60px;
  max-height: 240px;
  margin: 12px 0 20px;
  padding: 10px 12px;
  font-family: "Plus Jakarta Sans", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s;
}
.edit-dialog-textarea:focus {
  border-color: var(--accent);
}

/* ===== Monthly Checklist Trigger ===== */
/* Header toolbar buttons on older pages: the same as .btn-outline-sm. */
.checklist-trigger,
.advisor-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  height: 32px;
  padding: 0 var(--sp-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-primary) !important;
  font: var(--fw-semibold) var(--fs-xs) / 1 var(--font-sans);
  white-space: nowrap;
  text-decoration: none !important;
  cursor: pointer;
  transition: background var(--dur-fast), border-color var(--dur-fast);
}
.checklist-trigger:hover,
.advisor-trigger:hover {
  background: var(--bg-secondary);
  border-color: var(--text-tertiary);
}
.checklist-trigger svg, .advisor-trigger svg { width: 14px !important; height: 14px !important; }
@media (pointer: coarse) { .checklist-trigger, .advisor-trigger { height: 40px; } }
.advisor-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: #fff;
  font-size: var(--fs-2xs);
  font-weight: var(--fw-bold);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

/* ===== Monthly Checklist Modal ===== */
.checklist-overlay {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--bg-sidebar) 60%, transparent);
  backdrop-filter: blur(3px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: confirmFadeIn 0.15s ease;
}
.checklist-modal {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 28px 32px;
  max-width: 440px;
  width: 90%;
  box-shadow: 0 8px 40px color-mix(in srgb, var(--bg-sidebar) 30%, transparent);
  animation: confirmSlideIn 0.2s ease;
}
.checklist-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.checklist-header-title {
  font-family: var(--font-sans);
  font-weight: var(--fw-semibold);
  font-size: 17px;
  color: var(--text-primary);
}
.checklist-header-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}
.checklist-header-nav button {
  background: var(--bg-secondary);
  border: none;
  border-radius: 8px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s;
}
.checklist-header-nav button:hover {
  background: var(--border);
  color: var(--text-primary);
}
.checklist-header-month {
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 500;
  min-width: 110px;
  text-align: center;
}
.checklist-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  font-size: 12px;
  color: var(--text-secondary);
}
.checklist-progress-bar {
  flex: 1;
  height: 4px;
  background: var(--bg-secondary);
  border-radius: 2px;
  overflow: hidden;
}
.checklist-progress-fill {
  height: 100%;
  background: var(--profit);
  border-radius: 2px;
  transition: width 0.3s ease;
}
.checklist-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.checklist-item:last-child {
  border-bottom: none;
}
.checklist-item-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.checklist-item-done .checklist-item-icon {
  color: var(--profit);
}
.checklist-item-pending .checklist-item-icon {
  color: var(--accent);
}
.checklist-item-done .checklist-item-label {
  color: var(--text-secondary);
}
.checklist-item-done .checklist-item-label a {
  color: var(--text-secondary);
  text-decoration: none;
}
.checklist-item-done .checklist-item-label a:hover {
  color: var(--accent);
}
.checklist-item-pending .checklist-item-label a {
  color: var(--text-primary);
  font-weight: 500;
  text-decoration: none;
}
.checklist-item-pending .checklist-item-label a:hover {
  color: var(--accent);
}
.checklist-subitem {
  padding-left: 28px;
}
.checklist-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: all 0.15s;
  margin-left: 8px;
  flex-shrink: 0;
}
.checklist-close:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* ===== PORTFOLIO (shared: stock + crypto) ===== */
.pnl-breakdown-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 12px 24px;
    margin-bottom: 1.5rem;
}
.pnl-breakdown-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 4px 8px;
}
.pnl-breakdown-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
}
/* Verdict line under the "was trading worth it" comparison. */
.timing-note {
    margin: 4px 0 0;
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-secondary);
}

/* Projection charts flow instead of sitting in a fixed two-column row, where an
   odd number of goals left half a row empty. */
.goals-projection-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
    gap: 1rem;
}
/* An odd last chart spans the row instead of leaving half of it blank. */
.goals-projection-grid > :last-child:nth-child(odd) {
    grid-column: 1 / -1;
}

/* ===== Dashboard: secondary charts on small screens =====
   Six full-width charts turn the phone view into a 14 000px scroll. Keep the two
   headline ones and put the rest behind a toggle; on wider screens they are
   always visible and the toggle disappears. */
.dash-more-toggle { display: none; }
.dash-more-label { display: none; }
.dash-more-hide { display: none; }

@media (max-width: 900px) {
    .dash-more-label {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        margin: 0 0 1rem;
        padding: 10px 16px;
        border: 1px solid var(--border);
        border-radius: 10px;
        font-size: 13px;
        color: var(--text-secondary);
        cursor: pointer;
        user-select: none;
    }
    .dash-more-label:hover { color: var(--text-primary); }
    .dash-charts-extra { display: none; }
    #dashMoreCharts:checked ~ .dash-charts-extra { display: block; }
    #dashMoreCharts:checked ~ .dash-more-label .dash-more-show { display: none; }
    #dashMoreCharts:checked ~ .dash-more-label .dash-more-hide { display: inline; }
    #dashMoreCharts:checked ~ .dash-more-label [data-lucide] { transform: rotate(180deg); }
}

/* Two KPI tiles per row on a phone: one per row wasted most of the width on a
   label and a single figure. */
@media (max-width: 640px) {
    .dash-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.625rem; }
    .dash-tile { padding: 12px 14px; }
    .dash-tile-label, .dash-tile-row { font-size: 12px; }
}

/* Technical fields nobody sets on the first pass live behind this. */
.form-extra {
    margin-bottom: 20px;
    border-top: 1px solid var(--border);
    padding-top: 12px;
}
.form-extra-summary {
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    margin-bottom: 10px;
}
.form-extra-summary:hover { color: var(--text-primary); }
.form-hint {
    display: block;
    margin-top: 4px;
    font-size: 11px;
    color: var(--text-secondary);
}

/* Section heading inside an entry form. Used by the net worth and passive income
   forms but never defined, so those headings fell back to the browser's h3 —
   large serif type competing with the page title. */
.form-section-title {
    font-family: "Plus Jakarta Sans", sans-serif;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin: 24px 0 12px;
}
.form-section-title:first-child { margin-top: 0; }

/* A ticker field upper-cases what is typed, but the hint should stay a sentence:
   text-transform applies to the placeholder too, and "НАПРИМЕР: AAPL" shouts. */
.input-ticker { text-transform: uppercase; }
.input-ticker::placeholder { text-transform: none; }

/* ===== Collapsible form sections =====
   Entry forms run several screens on a phone; each category can be folded away
   once it is filled, and on small screens they start folded. */
.form-section {
    margin-bottom: 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}
.form-section-summary {
    padding: 10px 14px;
    background: var(--bg-input);
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}
.form-section-summary:hover { color: var(--text-primary); }
.form-section[open] .form-section-summary { border-bottom: 1px solid var(--border); }
.form-section > .table-scroll-container,
.form-section > table { padding: 0 4px 4px; }
/* Inside a card the section supplies the heading, so it needs no frame of its own. */
.form-section--flush {
    margin: 0;
    border: none;
    border-radius: 0;
}
.form-section--flush > .form-section-summary {
    padding: 0 0 12px;
    background: none;
    font-family: "Plus Jakarta Sans", sans-serif;
    font-size: 15px;
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0;
    color: var(--text-primary);
}
.form-section--flush[open] > .form-section-summary { border-bottom: none; }
.form-section--flush > .table-scroll-container { padding: 0; }

/* Marks a cushion figure derived from budget categories rather than fund accounts. */
.cushion-src {
    font-size: 10px;
    opacity: 0.5;
    cursor: help;
}

/* ===== Goals: pace and projection note ===== */
.goal-card-pace {
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}
.goals-projection-note {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 1.5rem;
    padding: 12px 16px;
    border: 1px dashed var(--border);
    border-radius: 10px;
    font-size: 13px;
    color: var(--text-secondary);
}

/* ===== Goals: empty state =====
   A single line of text on an otherwise blank page said what is missing but not
   what a goal is for, so there was nothing to act on. */
.goals-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 56px 24px;
}
.goals-empty-title {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
}
.goals-empty-text {
    margin: 0;
    max-width: 460px;
    font-size: 13px;
    line-height: 1.6;
}
.goals-empty-examples {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin: 4px 0 8px;
}
.goals-empty-examples span {
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 12px;
    color: var(--text-secondary);
}

/* ===== FIRE projections =====
   Donut, key figures and the passive-income forecast. The inline three-column
   grid this replaces had no minmax(0) and no breakpoint, so on a phone the three
   tracks refused to shrink and pushed the page 2.4x past the viewport. */
.fire-detail-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 2fr);
    gap: 1.5rem;
    margin-top: 1.5rem;
}
@media (max-width: 1100px) {
    .fire-detail-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
    .fire-detail-grid > :last-child { grid-column: 1 / -1; }
}
@media (max-width: 700px) {
    .fire-detail-grid { grid-template-columns: minmax(0, 1fr); }
}

/* ===== Net worth: dormant accounts =====
   Accounts with nothing in them for half a year stay in the table but out of the
   way, behind a checkbox — pure CSS, no state to keep. */
.nw-dormant-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
}
.nw-dormant-toggle input { accent-color: var(--accent); }
.data-table tr.nw-dormant { display: none; }
body:has(#nwShowDormant:checked) .data-table tr.nw-dormant { display: table-row; }

/* ===== Text alignment utilities =====
   Used across every table in the app (393 call sites) but never defined, so all
   the numeric columns rendered left-aligned regardless of the markup. */
.text-left { text-align: left; }
.text-center { text-align: center; }
.text-right { text-align: right; }

/* ===== Numbers =====
   .mono-number marks any figure the user compares or scans down a column, so its
   digits sit in the same slot from row to row. The amounts themselves stay on one
   line via the non-breaking thousands separator in formatMoney — not via nowrap
   here, which would also stop sentences like "50.4% за 34 дн." from wrapping and
   push the layout wider than the viewport. */
.mono-number {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
}

.pnl-breakdown-item .mono-number {
    font-size: 14px;
}
.pnl-breakdown-sep {
    width: 1px;
    height: 32px;
    background: var(--border);
    flex-shrink: 0;
}
@media (max-width: 700px) {
    .pnl-breakdown-bar {
        flex-wrap: wrap;
        gap: 8px;
    }
    .pnl-breakdown-sep {
        display: none;
    }
    .pnl-breakdown-item {
        min-width: 45%;
    }
}
.dash-charts-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}
@media (max-width: 900px) {
    .dash-charts-row {
        grid-template-columns: 1fr;
    }
}
/* ───── Где деньги + Карта позиций (/stock-portfolio/{id}) ─────
   Одна классификация на полосу и на treemap: полоса отвечает «сколько денег
   в минусе», карта — «какие это позиции». Цвет здесь — состояние, не
   украшение. Логика — static/js/portfolio-map.js, данные — buildPortfolioMap(). */
:root {
  --pf-gain: #5FB872;
  --pf-loss: #F4A99C;
  --pf-deep: #DC2626;
  --pf-cashlike: #2E7F8E;
  --pf-cash: #86C9D7;
  --pf-ink-light: #FFFFFF;
  --pf-ink-dark: #1C1917;
}
/* Тёмная тема: «в минусе» — приглушённый, но не бурый красный; яркость
   растёт к «глубоко в минусе», как и на светлой. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --pf-gain: #2F8F4E; --pf-loss: #9E4F4C; --pf-deep: #EF6B6B; --pf-cashlike: #2F7F8D; --pf-cash: #7FC3D1; }
}
html[data-theme="dark"] { --pf-gain: #2F8F4E; --pf-loss: #9E4F4C; --pf-deep: #EF6B6B; --pf-cashlike: #2F7F8D; --pf-cash: #7FC3D1; }
.pf-b-gain { --pf: var(--pf-gain); --pf-ink: var(--pf-ink-light); }
.pf-b-loss { --pf: var(--pf-loss); --pf-ink: var(--pf-ink-dark); }
.pf-b-deep { --pf: var(--pf-deep); --pf-ink: var(--pf-ink-light); }
.pf-b-cashlike { --pf: var(--pf-cashlike); --pf-ink: var(--pf-ink-light); }
.pf-b-cash { --pf: var(--pf-cash); --pf-ink: var(--pf-ink-dark); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .pf-b-loss { --pf-ink: var(--pf-ink-light); }
  :root:not([data-theme="light"]) .pf-b-deep { --pf-ink: var(--pf-ink-dark); }
}
html[data-theme="dark"] .pf-b-loss { --pf-ink: var(--pf-ink-light); }
html[data-theme="dark"] .pf-b-deep { --pf-ink: var(--pf-ink-dark); }

.pf-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-bottom: 16px; }
.pf-head .chart-title { margin-bottom: 0; }

/* Между «в бумагах» и «кэшем» разрыв шире, чем между корзинами: та же
   граница, что делит легенду на две группы. */
.pf-alloc-bar { display: flex; gap: 8px; height: 32px; }
.pf-alloc-bar-group { display: flex; gap: 2px; min-width: 0; }
.pf-alloc-seg {
  min-width: 4px;
  background: var(--pf);
  border-radius: 3px;
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.15s ease;
}
.pf-alloc-seg-label { font-size: 11px; font-weight: 600; color: var(--pf-ink); }
.pf-alloc .is-dim { opacity: 0.35; }

.pf-alloc-groups { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); margin-top: 20px; }
.pf-alloc-group + .pf-alloc-group { border-left: 1px solid var(--border); padding-left: 28px; margin-left: 28px; }
.pf-alloc-group-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding-bottom: 10px; margin-bottom: 14px; border-bottom: 1px solid var(--border);
  font-size: 13px; color: var(--text-secondary);
}
.pf-alloc-group-label { font-weight: 600; color: var(--text-primary); }
.pf-alloc-group-value { font-weight: 600; color: var(--text-primary); }
.pf-alloc-legend {
  --cols: 3;
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 14px 24px;
}
.pf-alloc-group + .pf-alloc-group .pf-alloc-legend { --cols: 2; }
.pf-alloc-item {
  display: grid; grid-template-columns: 10px minmax(0, 1fr);
  grid-template-areas: "sw name" ". figs" ". hint";
  column-gap: 8px; row-gap: 2px; align-items: baseline;
  transition: opacity 0.15s ease;
}
.pf-alloc-item.is-empty { opacity: 0.45; }
.pf-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; background: var(--pf); }
.pf-alloc-item .pf-swatch { grid-area: sw; align-self: center; }
.pf-alloc-name { grid-area: name; font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pf-alloc-figs { grid-area: figs; display: flex; align-items: baseline; gap: 8px; }
.pf-alloc-value { font-size: 18px; font-weight: 600; color: var(--text-primary); }
.pf-alloc-pct { font-size: 12px; color: var(--text-secondary); }
.pf-alloc-hint { grid-area: hint; font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.pf-map-body { position: relative; }
.pf-map-canvas { width: 100%; }
.pf-map-canvas svg { display: block; overflow: visible; }
.pf-tile { cursor: pointer; outline: none; transition: opacity 0.15s ease; }
/* Насыщенность плитки растёт с тяжестью: «глубоко» читается издалека,
   «в минусе» — тише, чем «в плюсе». */
.pf-tile { --pf-fill: 18%; }
.pf-tile.pf-b-loss { --pf-fill: 13%; }
.pf-tile.pf-b-deep { --pf-fill: 28%; }
.pf-tile.pf-b-cash { --pf-fill: 14%; }
.pf-tile rect {
  fill: color-mix(in oklab, var(--pf) var(--pf-fill), var(--bg-card));
  stroke: color-mix(in oklab, var(--pf) 50%, var(--bg-card));
  stroke-width: 1;
}
.pf-tile:hover rect, .pf-tile:focus-visible rect { fill: color-mix(in oklab, var(--pf) calc(var(--pf-fill) + 14%), var(--bg-card)); stroke: var(--pf); }
.pf-tile.is-dim { opacity: 0.4; }
.pf-tile text { pointer-events: none; font-variant-numeric: tabular-nums; }
.pf-tile-sym { fill: var(--text-primary); font-size: 12px; font-weight: 600; letter-spacing: 0.02em; }
.pf-tile-sym.is-center { text-anchor: middle; }
.pf-tile-meta { fill: var(--text-secondary); font-size: 11px; }
.pf-tile-pnl { font-size: 11px; }
.pf-tile-pnl.is-up { fill: var(--profit); }
.pf-tile-pnl.is-down { fill: var(--loss); }


.pf-map-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 14px; font-size: 12px; color: var(--text-secondary); }
.pf-map-key { display: inline-flex; align-items: center; gap: 6px; cursor: default; }

.holdings-row.is-flash { animation: pf-flash 1.8s ease-out; }
@keyframes pf-flash {
  0%, 30% { background: color-mix(in oklab, var(--accent) 22%, transparent); }
  100% { background: transparent; }
}
/* Уже, чем пять колонок в ряд: группы друг под другом, колонки совпадают. */
@media (max-width: 1100px) {
  .pf-alloc-groups { grid-template-columns: minmax(0, 1fr); row-gap: 20px; }
  .pf-alloc-group + .pf-alloc-group { border-left: 0; padding-left: 0; margin-left: 0; }
  .pf-alloc-group + .pf-alloc-group .pf-alloc-legend { --cols: 3; }
}
/* Телефон: строка списка — имя слева, цифры справа. */
@media (max-width: 640px) {
  .pf-alloc-legend, .pf-alloc-group + .pf-alloc-group .pf-alloc-legend { --cols: 1; gap: 12px; }
  .pf-alloc-item { grid-template-columns: 10px minmax(0, 1fr) auto; grid-template-areas: "sw name figs" ". hint hint"; }
  .pf-alloc-name { font-size: 14px; color: var(--text-primary); }
  .pf-alloc-value { font-size: 14px; }
  .pf-alloc-pct { min-width: 42px; text-align: right; }
}

.portfolio-grid {
    display: grid;
    /* minmax(0,…): without it a wide holdings table sets the track's floor and
       pushes the grid past the viewport instead of scrolling inside its panel. */
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}
@media (max-width: 900px) {
    .portfolio-grid {
        grid-template-columns: 1fr;
    }
}
.holdings-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px 6px 36px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-strong);
}
.holdings-hdr-name { flex: 1; }
.holdings-hdr-value { width: 150px; text-align: right; }
.holdings-hdr-pnl { width: 145px; text-align: right; }
.holdings-hdr-weight { width: 60px; text-align: right; }
.holdings-table-wrap {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.holdings-group-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    cursor: pointer;
    border-radius: 6px;
    font-weight: 600;
    font-size: 13px;
    background: var(--bg-hover, rgba(255,255,255,0.03));
    user-select: none;
}
.holdings-group-header:hover {
    background: var(--bg-active, rgba(255,255,255,0.06));
}
.holdings-group-toggle {
    display: inline-flex;
    transition: transform 0.2s;
}
.holdings-group.collapsed .holdings-group-toggle {
    transform: rotate(-90deg);
}
.holdings-group-body {
    display: flex;
    flex-direction: column;
}
.holdings-group.collapsed .holdings-group-body {
    display: none;
}
.holdings-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 12px 3px 36px;
    border-bottom: 1px solid var(--border-subtle, rgba(255,255,255,0.04));
    font-size: 13px;
}
.holdings-row:last-child {
    border-bottom: none;
}
.holdings-cell-name {
    flex: 1;
    display: flex;
    flex-direction: row;
    align-items: baseline;
    gap: 6px;
    min-width: 0;
}
.holdings-symbol {
    font-weight: 600;
    font-size: 13px;
    flex-shrink: 0;
}
.holdings-desc {
    font-size: 11px;
    opacity: 0.5;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}
.holdings-qty {
    font-size: 11px;
    opacity: 0.4;
    flex-shrink: 0;
    white-space: nowrap;
}
.holdings-cell-value,
.holdings-cell-pnl {
    display: flex;
    flex-direction: row;
    align-items: baseline;
    justify-content: flex-end;
    gap: 6px;
    font-size: 12px;
    white-space: nowrap;
}
.holdings-cell-value { width: 150px; gap: 10px; }
.holdings-cell-pnl { width: 145px; }
/* On narrow screens the row keeps the numbers and drops the company name. */
@media (max-width: 640px) {
    .dash-hero { gap: 0.625rem; margin-bottom: 1rem; }
    .dash-hero-card { padding: 16px 18px; }
    .dash-hero-value { font-size: 30px; }
    .dash-hero-label,
    .dash-hero-sub { font-size: 13px; }

    /* Name plus 150 + 145 + 60 needs ~530px, so the fixed columns cannot fit a
       390px phone. Reflow instead of squeezing: the ticker takes its own line and
       the figures sit below it. */
    .holdings-header { display: none; }
    .holdings-row {
        flex-wrap: wrap;
        row-gap: 2px;
        padding: 6px 12px;
    }
    .holdings-group-header { padding-left: 12px; }
    .holdings-desc { display: none; }
    .holdings-cell-name { flex: 1 0 100%; }
    .holdings-cell-value,
    .holdings-cell-pnl {
        width: auto;
        flex: 1 1 auto;
        justify-content: flex-start;
    }
    .holdings-cell-pnl { justify-content: center; }
    .holdings-cell-weight {
        width: auto;
        flex: 0 0 auto;
        margin-left: auto;
    }
}
/* Cost basis and absolute P&L sit behind the figures people scan for. */
.holdings-sub {
    font-size: 11px;
    opacity: 0.45;
}
.holdings-cell-weight {
    width: 50px;
    text-align: right;
    font-size: 12px;
}

/* A chart heading's scope, after its title. */
.chart-title-scope {
  font-family: "Plus Jakarta Sans", sans-serif;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: none;
  letter-spacing: 0;
}

/* Icon picker grid */
.icon-picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
    gap: 6px;
}
.icon-picker-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--text-secondary);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, color 0.15s, box-shadow 0.15s;
}
.icon-picker-btn i,
.icon-picker-btn svg {
    width: 20px;
    height: 20px;
}
.icon-picker-btn:hover {
    border-color: var(--accent);
    color: var(--text-primary);
    background: var(--bg-secondary);
}
.icon-picker-btn.active {
    border-color: var(--accent);
    background: rgba(217, 119, 6, 0.12);
    color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
}

/* Toggle switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
    flex-shrink: 0;
}
.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}
.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--border);
    border-radius: 24px;
    transition: background 0.2s;
}
.toggle-slider::before {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
}
.toggle-switch input:checked + .toggle-slider {
    background: var(--accent);
}
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(24px);
}

/* ===== Tax liability detail ===== */

/* The page answers one question — how much is owed and how that was derived —
   so the figures sit in a calculation chain rather than on a grid of tiles
   where the reader has to do the arithmetic themselves. */
.tax-detail-source {
  font-weight: 400;
  font-size: 16px;
  color: var(--text-secondary);
  margin-left: 8px;
}
.tax-detail-meta {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--text-secondary);
}
.tax-detail-facts {
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.tax-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
}
.tax-status i { width: 14px; height: 14px; }
.tax-status--paid { color: var(--profit); }
.tax-status--pending { color: var(--text-secondary); }

.tax-calc { margin-bottom: 24px; }
.tax-calc-table {
  width: 100%;
  border-collapse: collapse;
}
.tax-calc-table thead th {
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
  font-weight: 500;
  padding-bottom: 8px;
}
.tax-calc-table tbody th {
  text-align: left;
  font-weight: 400;
  color: var(--text-primary);
  padding: 10px 16px 10px 0;
}
.tax-calc-table td {
  padding: 10px 0 10px 16px;
  white-space: nowrap;
}
.tax-calc-table tbody tr + tr th,
.tax-calc-table tbody tr + tr td {
  border-top: 1px solid var(--border);
}
.tax-calc-note {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.tax-calc-muted th,
.tax-calc-muted td { color: var(--text-secondary); }
/* The line the whole chain leads to. */
.tax-calc-total th,
.tax-calc-total td {
  font-weight: 600;
  font-size: 15px;
  border-top: 2px solid var(--border) !important;
}

.tax-section { margin-bottom: 24px; }
/* A date broken over three lines reads as three values. */
.tax-section .data-table td:first-child { white-space: nowrap; }
.tax-missing { color: var(--text-secondary); font-size: 14px; }
.tax-row-current td { background: var(--surface-hover); font-weight: 500; }
.tax-detail-actions { margin-top: 8px; }

@media (max-width: 640px) {
  /* Three columns of figures do not fit a phone; the tenge column is the one
     that matters for the declaration, so the dollar column folds under the label. */
  .tax-calc-table thead { display: none; }
  .tax-calc-table tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: baseline;
    column-gap: 12px;
    padding: 10px 0;
    border-top: 1px solid var(--border);
  }
  .tax-calc-table tbody tr:first-child { border-top: none; }
  .tax-calc-table tbody th,
  .tax-calc-table tbody td {
    padding: 0;
    border: none !important;
  }
  .tax-calc-table tbody th { grid-row: span 2; }
  .tax-calc-table tbody td:first-of-type {
    order: 2;
    font-size: 12px;
    color: var(--text-secondary);
  }
}

/* ===== Tax liabilities list ===== */

/* Which kind of income the year's tax actually comes from — the shape of the
   declaration, readable before the fifty individual rows below it. */
.tax-breakdown { margin-bottom: 24px; }
.tax-breakdown-rows { display: flex; flex-direction: column; gap: 10px; }
.tax-breakdown-row {
  display: grid;
  grid-template-columns: minmax(90px, auto) auto minmax(0, 1fr) 44px auto;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}
.tax-breakdown-count { font-size: 12px; color: var(--text-secondary); }
.tax-breakdown-bar {
  height: 6px;
  border-radius: 3px;
  background: var(--bg-input);
  overflow: hidden;
}
.tax-breakdown-bar > span {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
}
.tax-breakdown-pct { text-align: right; color: var(--text-secondary); font-size: 13px; }
.tax-breakdown-value { text-align: right; font-weight: 500; }

/* A month header carries its own subtotal, so the eye can stop at the month it
   is reconciling instead of scanning every row to the year total. */
.tax-month-row th,
.tax-month-row td {
  background: var(--bg-secondary);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-secondary);
  padding-top: 10px;
  padding-bottom: 10px;
}
.tax-month-row th { text-align: left; }

.tax-row { cursor: pointer; }
/* Paid rows stay legible — dimmed, not hidden; the check in the last column
   carries the status, so no column repeats the word "ожидает" fifty times. */
.tax-row--paid td { opacity: 0.55; }
.tax-pay-btn { padding: 4px 10px; font-size: 12px; white-space: nowrap; }

.tax-list-actions {
  margin-top: 16px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}
.tax-list-actions-note { font-size: 13px; color: var(--text-secondary); }

@media (max-width: 640px) {
  .tax-breakdown-row {
    grid-template-columns: minmax(0, 1fr) auto;
    row-gap: 4px;
  }
  .tax-breakdown-count { text-align: right; }
  .tax-breakdown-bar { grid-column: 1 / -1; }
  .tax-breakdown-pct { text-align: left; }
}

/* ===== Tax: year calculation, income form, settings ===== */

.tax-rate-note {
  font-size: 11px;
  color: var(--text-secondary);
  margin-left: 6px;
}
.tax-flag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  background: var(--bg-input);
  color: var(--text-secondary);
}

/* Everything that could make the figures wrong or provisional, in one place
   next to them rather than buried in a footnote. */
.tax-warnings { margin-bottom: var(--gap-grid); box-shadow: inset 3px 0 0 var(--warn), var(--shadow-sm); }
.tax-warning-list {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* An intermediate result inside the calculation chain: heavier than a line,
   lighter than the total. */
.tax-calc-subtotal th,
.tax-calc-subtotal td {
  font-weight: 500;
  border-top: 1px solid var(--border) !important;
}

.tax-income-intro p {
  margin: 0 0 10px;
  font-size: 14px;
  line-height: 1.55;
  max-width: 68ch;
}
.tax-income-intro p:last-child { margin-bottom: 0; }
.tax-income-note { color: var(--text-secondary); font-size: 13px !important; }

.tax-income-form { margin-top: 24px; }
.tax-income-table td { padding-top: 8px; padding-bottom: 8px; }
.tax-income-table .form-control { margin: 0; }

.tax-settings-form { max-width: 760px; }
.content > .tax-settings-form { margin-left: 0; }
.tax-settings-note {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.55;
  max-width: 68ch;
}
.tax-checkbox {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 14px;
  cursor: pointer;
}
.tax-rate-override {
  display: grid;
  grid-template-columns: minmax(0, 200px) minmax(0, 220px);
  gap: 16px;
  margin-top: 16px;
}

@media (max-width: 640px) {
  .tax-rate-override { grid-template-columns: minmax(0, 1fr); }
  .tax-income-table .form-control { font-size: 16px; } /* no iOS zoom on focus */
}

/* ===== Tax methodology guide ===== */

.guide-deadlines { margin-bottom: 24px; }
.guide-deadline-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.guide-deadline-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.guide-deadline-date { font-size: 22px; font-weight: 600; }
.guide-deadline-note { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

.guide-section { margin-bottom: 24px; }
.guide-text {
  margin: 0 0 12px;
  font-size: 14px;
  line-height: 1.6;
  max-width: 72ch;
}
.guide-text:last-child { margin-bottom: 0; }

/* Numbered procedure: the number is the anchor the eye returns to, so it sits
   outside the text column rather than inline with it. */
.guide-steps,
.guide-formula {
  margin: 0;
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  font-size: 14px;
  line-height: 1.6;
  max-width: 78ch;
}
.guide-steps li::marker,
.guide-formula li::marker {
  color: var(--accent);
  font-weight: 600;
}
.guide-list {
  margin: 0;
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
  line-height: 1.6;
  max-width: 78ch;
}

/* The article a rule comes from, so a figure can be checked rather than trusted. */
.guide-ref {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 4px;
  background: var(--bg-input);
  color: var(--text-secondary);
  font-size: 11px;
  white-space: nowrap;
}
.guide-caveat {
  margin: 16px 0 0;
  padding: 12px 14px;
  border-left: 3px solid var(--accent);
  background: var(--bg-input);
  border-radius: 0 6px 6px 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
  max-width: 78ch;
}

/* A year's transactions run to fifty rows and more. They belong on the page —
   an accountant checks them — but not ahead of the calculation, so each table
   collapses to a line stating what it contains. */
.tax-details { padding-top: 18px; padding-bottom: 18px; }
.tax-details-summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  cursor: pointer;
  list-style: none;
}
.tax-details-summary::-webkit-details-marker { display: none; }
.tax-details-summary .chart-title { margin-bottom: 0; }
.tax-details-summary::after {
  content: "▾";
  color: var(--text-secondary);
  font-size: 12px;
  transition: transform 0.15s ease;
}
.tax-details[open] .tax-details-summary::after { transform: rotate(180deg); }
.tax-details-meta {
  font-size: 13px;
  color: var(--text-secondary);
  margin-left: auto;
}
.tax-details[open] .tax-details-summary { margin-bottom: 16px; }

@media (max-width: 640px) {
  .tax-details-summary { flex-wrap: wrap; row-gap: 4px; }
  .tax-details-meta { margin-left: 0; flex: 1 0 100%; }
}

/* "Add a source" acts on the table above it, not on the form as a whole, so it
   sits with the table rather than in the row of form actions. */
.tax-income-add { margin-top: 12px; }

/* Four input columns cannot share a phone's width — squeezed to 60px each they
   showed "‹" and "Напрі" and could not be filled. Each source becomes a card
   with its fields stacked and labelled. */
@media (max-width: 720px) {
  .tax-income-table thead { display: none; }
  .tax-income-table,
  .tax-income-table tbody,
  .tax-income-table tfoot,
  .tax-income-table tr,
  .tax-income-table td {
    display: block;
    width: 100%;
  }
  .tax-income-row {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    margin-bottom: 12px;
  }
  .tax-income-row td {
    padding: 0 0 10px;
    border: none;
  }
  .tax-income-row td:last-child { padding-bottom: 0; }
  .tax-income-row td::before {
    content: attr(data-label);
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
  }
  .tax-income-row .form-control { width: 100%; }
  .tax-income-row .text-right { text-align: left; }

  .tax-income-total {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 16px;
    padding: 12px 0 0;
    border-top: 1px solid var(--border);
  }
  .tax-income-total td { width: auto; padding: 0; }
  .tax-income-total td:first-child { flex: 1 0 100%; font-weight: 600; }
  .tax-income-total td::before {
    content: attr(data-label) ": ";
    color: var(--text-secondary);
    font-size: 12px;
  }
  .tax-income-add { width: 100%; }
}

/* Page-level links live with the action they belong to, at the foot of the
   calculation — the header carries only the year navigation, as on every other
   year-scoped page. */
.tax-page-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-right: auto;
}
@media (max-width: 640px) {
  .tax-page-links { width: 100%; }
  .tax-page-links > * { flex: 1 1 auto; justify-content: center; }
}

/* ===== STYLEGUIDE (/styleguide) ===== */
.sg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--sp-3); margin-bottom: var(--gap-grid); }
.sg-swatch { display: flex; flex-direction: column; gap: 2px; padding: var(--sp-3); background: var(--bg-card); border-radius: var(--radius-md); box-shadow: var(--shadow-sm); font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.sg-swatch span { display: block; height: 40px; margin-bottom: var(--sp-2); border-radius: var(--radius-sm); background: var(--sw); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06); }
.sg-swatch code, .sg-type code { font-size: var(--fs-2xs); color: var(--text-tertiary); background: none; padding: 0; }
.sg-data { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4); margin-bottom: var(--sp-3); font-size: var(--fs-sm); color: var(--text-secondary); }
.sg-data span { display: inline-flex; align-items: center; gap: 6px; }
.sg-data span::before { content: ""; width: 12px; height: 12px; border-radius: 3px; background: var(--sw); }
.sg-data--assets { padding-bottom: var(--sp-3); border-bottom: 1px solid var(--border); margin-bottom: var(--sp-4); }
.sg-type > div { display: grid; grid-template-columns: 90px 1fr; align-items: baseline; gap: var(--sp-4); padding: var(--sp-2) 0; border-bottom: 1px solid var(--border); }
.sg-type > div:last-child { border-bottom: 0; }
.sg-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3); }

/* ===== DASHBOARD (/dashboard) =====
   Headline → what the capital is made of and where its growth came from →
   the month and the plan (five tiles) → goals → capital over time. */
.dash-hero-unit { margin-left: var(--sp-2); font-size: var(--fs-sm); font-weight: var(--fw-medium); letter-spacing: 0; color: var(--text-secondary); }
.dash-hero-card { display: flex; flex-direction: column; }
.dash-hero-card .hero-spark { margin-top: auto; padding-top: var(--sp-3); }

.dash-pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: var(--gap-grid); margin-bottom: var(--gap-grid); }
.dash-pair > .card-panel { margin-bottom: 0; }

/* Five tiles: one row on a wide screen, 3 + 2 below it — never 4 + 1. */
.dash-tiles--5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
@media (max-width: 1380px) { .dash-tiles--5 { grid-template-columns: repeat(6, minmax(0, 1fr)); } .dash-tiles--5 > * { grid-column: span 2; } .dash-tiles--5 > :nth-child(4), .dash-tiles--5 > :nth-child(5) { grid-column: span 3; } }
@media (max-width: 760px) { .dash-tiles--5 { grid-template-columns: minmax(0, 1fr); } .dash-tiles--5 > *, .dash-tiles--5 > :nth-child(4), .dash-tiles--5 > :nth-child(5) { grid-column: auto; } }
.dash-tiles--5 > .card-panel { margin-bottom: 0; }
.dash-tile .dash-tile-big { margin-bottom: 2px; }
.dash-tile-foot { margin-top: auto; padding-top: var(--sp-3); }
.dash-tile-foot .dash-tile-row:first-child { border-top: 1px solid var(--border); }
.dash-tile-progress { margin: var(--sp-2) 0 var(--sp-1); }
.dash-tile-header .dash-tile-hint, .dash-hero-label .dash-tile-hint, .chart-title .dash-tile-hint { margin-left: auto; }
.chart-title .dash-tile-hint { margin-left: 4px; vertical-align: middle; }
.dash-tile-hint > svg, .dash-tile-hint > i { width: 13px; height: 13px; color: var(--text-tertiary); }

.dash-alerts { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-bottom: var(--gap-grid); }
.dash-alert {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 var(--sp-3) 0 10px;
  border-radius: var(--radius-pill);
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
  font-size: var(--fs-sm);
}
.dash-alert-icon { width: 15px; height: 15px; flex-shrink: 0; }
.dash-alert-high .dash-alert-icon { color: var(--loss); }
.dash-alert-medium .dash-alert-icon { color: var(--warn); }
.dash-alert-low .dash-alert-icon { color: var(--profit); }
.dash-alert-title { font-weight: var(--fw-medium); color: var(--text-primary); text-decoration: none; white-space: nowrap; }
.dash-alert-title:hover { color: var(--accent-ink); }
.dash-alert-info-icon { width: 13px; height: 13px; color: var(--text-tertiary); }

.dash-goals-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); gap: var(--sp-3) var(--sp-6); }
.dash-goal { display: flex; flex-direction: column; gap: var(--sp-2); color: inherit; text-decoration: none; padding: var(--sp-1) 0; }
.dash-goal:hover .dash-goal-name { color: var(--accent-ink); }
.dash-goal .dash-goal-top { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); margin: 0; }
.dash-goal .dash-goal-name { font-size: var(--fs-sm); line-height: 1.35; color: var(--text-primary); transition: color var(--dur-fast); }
.dash-goal .dash-goal-pct { font-size: var(--fs-md); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; }
.dash-goal-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px var(--sp-3); font-size: var(--fs-xs); color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.dash-goal .badge-soft { align-self: flex-start; }

.dash-advice { list-style: none; margin: var(--sp-4) 0 0; padding: var(--sp-3) 0 0; border-top: 1px solid var(--border); display: grid; gap: 6px; font-size: var(--fs-sm); }
.dash-advice li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.dash-advice svg { width: 14px; height: 14px; color: var(--accent); }

/* ===== BUDGET YEAR (/budget) =====
   Twelve rows; each opens its month. The savings column carries a small bar so
   the year reads at a glance before the figures are read. */
.bl-table td, .bl-table th { white-space: nowrap; }
.bl-month { display: flex; align-items: center; gap: var(--sp-2); }
.bl-month a { color: var(--text-primary); font-weight: var(--fw-medium); text-decoration: none; }
.bl-row-empty .bl-month a { color: var(--text-secondary); font-weight: var(--fw-regular); }
.bl-rate-head { width: 26%; }
@media (max-width: 640px) { .bl-rate-track { display: none; } .bl-rate-head { width: auto; } .bl-rate .num { min-width: 0; margin-left: auto; } .bl-table td, .bl-table th { padding-left: var(--sp-2); padding-right: var(--sp-2); } }
.bl-rate { display: flex; align-items: center; gap: var(--sp-3); }
.bl-rate .num { min-width: 56px; }
.bl-rate-track { flex: 1; height: 6px; border-radius: var(--radius-pill); background: var(--bg-secondary); overflow: hidden; min-width: 60px; }
.bl-rate-fill { display: block; height: 100%; border-radius: inherit; background: var(--data-1); }
.bl-rate-fill.is-neg { background: var(--loss); opacity: 0.75; }
tfoot .bl-rate-track { visibility: hidden; }
.bl-actions { width: 1%; }
.bl-delete {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-tertiary); cursor: pointer;
  opacity: 0; transition: opacity var(--dur-fast), background var(--dur-fast), color var(--dur-fast);
}
.bl-delete svg { width: 15px; height: 15px; }
tr:hover .bl-delete, .bl-delete:focus-visible { opacity: 1; }
.bl-delete:hover { background: var(--loss-bg); color: var(--loss); }
@media (hover: none) { .bl-delete { opacity: 1; } }
.bl-create { opacity: 1; color: var(--text-secondary); }
.bl-create:hover { background: var(--accent-soft); color: var(--accent-ink); }
.bl-table td.bl-note { white-space: normal; font-size: var(--fs-xs); }

/* ===== NET WORTH (/net-worth) =====
   Headline → composition → capital by class → the account matrix, newest
   month first, each row with a twelve-month sparkline next to its name. */
.nw-table-head { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4); margin-top: var(--gap-section); }
.nw-table-head .section-title { margin: 0 0 var(--sp-3); }
.nw-table-head .nw-dormant-toggle { margin: 0 0 var(--sp-3); }
.nw-table { min-width: 0; }
.nw-table-wrap { padding: 0; }
.nw-table thead th:first-child { border-top-left-radius: var(--radius-lg); }
.nw-table thead th:last-child { border-top-right-radius: var(--radius-lg); }
.nw-table td.num, .nw-table th { font-size: var(--fs-sm); }
.nw-table .th-edit-link { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 4px; }
.nw-table .th-edit-link svg { width: 11px; height: 11px; opacity: 0; transition: opacity var(--dur-fast); }
.nw-table .th-edit-link:hover { color: var(--accent-ink); }
.nw-table .th-edit-link:hover svg { opacity: 0.7; }
.nw-table thead th:nth-child(2) { color: var(--text-primary); }
.nw-table tbody td:nth-child(2) { font-weight: var(--fw-semibold); }
.nw-total td { font-weight: var(--fw-semibold); font-size: var(--fs-md) !important; }
.nw-name { display: flex; align-items: center; gap: var(--sp-2); min-width: 220px; }
.nw-item .nw-name { padding-left: var(--sp-5); }
.nw-group td { text-transform: none !important; letter-spacing: 0 !important; font-size: var(--fs-sm) !important; }
.nw-dot { width: 10px; height: 10px; border-radius: 3px; background: var(--sb, var(--data-other)); flex-shrink: 0; }
.nw-spark { width: 64px; height: 18px; margin-left: auto; flex-shrink: 0; overflow: visible; }
.nw-spark polyline { fill: none; stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.nw-spark.is-up polyline { stroke: var(--profit); }
.nw-spark.is-down polyline { stroke: var(--loss); }
@media (max-width: 640px) { .nw-name { min-width: 170px; } .nw-spark { width: 44px; } }

/* ===== DIVIDEND CALENDAR (/stock-portfolio/{id}) =====
   Ex-dates for the next 60 days as one list: when, which, how often, how much
   per share and — the figure that matters — roughly how much lands. */
.div-cal { list-style: none; margin: 0; padding: 0; }
.div-cal-row {
  display: grid;
  grid-template-columns: 110px 70px minmax(0, 1fr) auto 110px;
  align-items: baseline;
  gap: var(--sp-3);
  padding: 10px 0;
  border-top: 1px solid var(--border);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
}
.div-cal-row:first-child { border-top: 0; padding-top: 0; }
.div-cal-row.is-past { opacity: 0.45; }
.div-cal-date { color: var(--text-secondary); }
.div-cal-sym { font-weight: var(--fw-semibold); }
.div-cal-freq { color: var(--text-secondary); font-size: var(--fs-xs); }
.div-cal-per { color: var(--text-secondary); text-align: right; }
.div-cal-sum { font-weight: var(--fw-semibold); text-align: right; color: var(--profit); }
@media (max-width: 640px) {
  .div-cal-row { grid-template-columns: 1fr auto; row-gap: 2px; }
  .div-cal-date { grid-column: 1; grid-row: 2; font-size: var(--fs-xs); }
  .div-cal-sym { grid-column: 1; grid-row: 1; }
  .div-cal-freq, .div-cal-per { display: none; }
  .div-cal-sum { grid-column: 2; grid-row: 1 / 3; align-self: center; }
}
.dash-tile-chevron { width: 14px !important; height: 14px !important; margin-left: auto; color: var(--text-tertiary) !important; }

/* Chevron of a disclosure (tax warnings, P&L months): turns when open. */
.adv-overdue-chevron { margin-left: auto; transition: transform var(--dur-fast); color: var(--text-secondary) !important; }
.stat-strip-value small { display: block; margin-top: 2px; font-size: var(--fs-xs); font-weight: var(--fw-regular); color: var(--text-secondary); letter-spacing: 0; }
.stat-strip-value small.text-loss { color: var(--loss); }
.stat-strip-label .dash-tile-hint { vertical-align: middle; }
@media (max-width: 640px) {
  /* Five figures in two columns: the odd one spans, no lone half-cell. */
  .stat-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-strip > .stat-strip-item:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .stat-strip-item { padding: var(--sp-3) var(--sp-4); }
  .stat-strip-item + .stat-strip-item { box-shadow: none; }
  .stat-strip-item:nth-child(even) { box-shadow: -1px 0 0 var(--border); }
  .stat-strip-item:nth-child(n+3) { box-shadow: 0 -1px 0 var(--border); }
  .stat-strip-item:nth-child(even):nth-child(n+3) { box-shadow: -1px 0 0 var(--border), 0 -1px 0 var(--border); }
}

/* ===== ALLOCATION (/allocation) ===== */
.alloc-bars { display: grid; grid-template-columns: 64px minmax(0, 1fr); align-items: center; column-gap: var(--sp-3); row-gap: var(--sp-2); margin-bottom: var(--sp-5); }
.alloc-bars .sharebar { margin: 0; }
.alloc-bar-label { font-size: var(--fs-xs); color: var(--text-secondary); }
.alloc-target-bar { position: relative; }
.alloc-target-bar .sharebar-seg[hidden] { display: none; }
.alloc-target-empty { display: none; }
.alloc-target-bar.is-empty { border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); }
.alloc-target-bar.is-empty .alloc-target-empty { display: flex; align-items: center; padding: 0 var(--sp-3); font-size: var(--fs-xs); color: var(--text-tertiary); }
.alloc-table td { vertical-align: middle; }
.alloc-name { display: inline-flex; align-items: center; gap: var(--sp-2); }
.alloc-input { width: 72px; min-height: 34px; padding: 4px 10px; margin-left: auto; display: block; }
.alloc-other td { color: var(--text-secondary); }
.alloc-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; margin-top: var(--sp-4); padding-top: var(--sp-4); border-top: 1px solid var(--border); }
.alloc-sum { font-size: var(--fs-sm); color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.alloc-sum b { color: var(--text-primary); }
.alloc-sum.is-off, .alloc-sum.is-off b { color: var(--warn); }
.alloc-sum.is-ok b { color: var(--profit); }
.alloc-error { display: flex; align-items: center; gap: var(--sp-2); margin: 0 0 var(--sp-4); padding: var(--sp-3); border-radius: var(--radius-md); background: var(--loss-bg); color: var(--loss); font-size: var(--fs-sm); }
.alloc-error svg { width: 16px; height: 16px; }
.alloc-advice, .alloc-drift { list-style: none; margin: 0; padding: 0; }
.alloc-advice li { display: flex; align-items: baseline; gap: var(--sp-4); padding: 10px 0; border-top: 1px solid var(--border); }
.alloc-advice li:first-child { border-top: 0; padding-top: 0; }
.alloc-advice-sum { min-width: 90px; font-weight: var(--fw-semibold); color: var(--accent-ink); font-variant-numeric: tabular-nums; }
.alloc-advice small { display: block; font-size: var(--fs-xs); color: var(--text-secondary); }
.alloc-drift li { display: flex; gap: var(--sp-2); padding: var(--sp-2) 0; font-size: var(--fs-sm); }
.alloc-drift svg { width: 16px; height: 16px; flex-shrink: 0; color: var(--accent); margin-top: 2px; }
.alloc-drift li.is-kzt svg { color: var(--warn); }
@media (max-width: 640px) { .alloc-bars { grid-template-columns: 1fr; } .alloc-input { width: 60px; } }
.alloc-table tbody tr:last-child td { border-bottom: 0; }

/* Tax notes fold behind one line: the figure leads, the caveats are one click away. */
.tax-warnings { padding: 0; }
.tax-warnings-summary { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-4) var(--sp-5); cursor: pointer; list-style: none; font-size: var(--fs-sm); }
.tax-warnings-summary::-webkit-details-marker { display: none; }
.tax-warnings-summary > svg:first-child { width: 18px; height: 18px; color: var(--warn); flex-shrink: 0; }
.tax-warnings[open] .adv-overdue-chevron { transform: rotate(180deg); }
.tax-warnings .tax-warning-list { margin: 0; padding: 0 var(--sp-5) var(--sp-5) calc(var(--sp-5) + 26px); }

/* ===== FIRE (/projections) =====
   The page answers one question — when — and shows how far along the path is. */
.fire-hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr); gap: var(--sp-8); align-items: center; }
.fire-hero-when { display: flex; flex-direction: column; gap: var(--sp-1); }
.fire-hero-date { font-size: clamp(32px, 3.4vw, 44px); font-weight: var(--fw-semibold); letter-spacing: -0.03em; line-height: 1.1; }
.fire-path-figures { display: flex; justify-content: space-between; align-items: baseline; font-size: var(--fs-sm); color: var(--text-secondary); font-variant-numeric: tabular-nums; margin-bottom: var(--sp-2); }
.fire-path-figures b { color: var(--text-primary); font-size: var(--fs-lg); }
.fire-path-pct { font-size: var(--fs-xl); font-weight: var(--fw-semibold); color: var(--accent-ink); }
.fire-path-track { position: relative; height: 14px; border-radius: var(--radius-pill); background: var(--bg-secondary); overflow: hidden; }
.fire-path-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, color-mix(in oklab, var(--accent) 55%, var(--bg-card)), var(--accent)); }
.fire-path-tick { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--bg-card); opacity: 0.9; }
.fire-path-scale { display: flex; justify-content: space-between; margin-top: 6px; font-size: var(--fs-2xs); color: var(--text-tertiary); font-variant-numeric: tabular-nums; }
.fire-path-note { margin: var(--sp-3) 0 0; font-size: var(--fs-xs); color: var(--text-secondary); }
@media (max-width: 900px) { .fire-hero { grid-template-columns: minmax(0, 1fr); gap: var(--sp-5); } }

/* ===== PORTFOLIO CARDS (/stock-portfolio, /crypto-portfolio) =====
   One card per account: identity, value, result, the 90-day shape, the
   state of its positions as a thin strip, and two facts in the footer. The
   dashed card next to them is how a new one is added. */
.pf-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 400px), 1fr)); gap: var(--gap-grid); }
.pf-cards > .card-panel { margin-bottom: 0; }
a.pf-card, .pf-card { display: flex; flex-direction: column; gap: var(--sp-4); }
.pf-card-head { display: flex; align-items: center; gap: var(--sp-3); }
.pf-card-icon { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: var(--radius-md); background: var(--accent-soft); color: var(--accent-ink); flex-shrink: 0; }
.pf-card-icon svg { width: 18px; height: 18px; }
.pf-card-title { display: flex; flex-direction: column; min-width: 0; }
.pf-card-title b { font-size: var(--fs-md); font-weight: var(--fw-semibold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pf-card-title small { font-size: var(--fs-xs); color: var(--text-secondary); }
.pf-card-chevron { width: 18px !important; height: 18px !important; margin-left: auto; color: var(--text-tertiary); transition: transform var(--dur-fast), color var(--dur-fast); }
.pf-card:hover .pf-card-chevron { transform: translateX(2px); color: var(--accent-ink); }
.pf-card-value { display: flex; flex-direction: column; margin-top: var(--sp-1); }
.pf-card-value .dash-hero-value { margin-bottom: 2px; }
.pf-card-spark { position: relative; height: 76px; padding-top: 16px; margin: 0 calc(var(--sp-2) * -1); }
.pf-card-spark-label { position: absolute; top: 0; right: var(--sp-2); font-size: var(--fs-2xs); color: var(--text-tertiary); }
.sharebar--thin { height: 8px; margin: 0 0 var(--sp-2); gap: 2px; }
.pf-card-legend { display: flex; flex-wrap: wrap; gap: 4px var(--sp-3); font-size: var(--fs-xs); color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.pf-card-legend span { display: inline-flex; align-items: center; gap: 5px; }
.pf-card-legend .pf-swatch { width: 8px; height: 8px; }
.pf-card-foot { display: flex; justify-content: space-between; gap: var(--sp-3); padding-top: var(--sp-3); border-top: 1px solid var(--border); font-size: var(--fs-sm); color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.pf-card-foot b { color: var(--text-primary); font-weight: var(--fw-semibold); }
.pf-card-add {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 220px; padding: var(--sp-6);
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius-lg);
  color: var(--text-secondary); text-align: center; text-decoration: none;
  transition: border-color var(--dur-fast), background var(--dur-fast), color var(--dur-fast);
}
.pf-card-add b { font-size: var(--fs-md); color: var(--text-primary); }
.pf-card-add small { max-width: 34ch; font-size: var(--fs-xs); line-height: var(--lh-normal); }
.pf-card-add:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--text-secondary); }
.pf-card-add:hover .empty-state-icon { background: var(--bg-card); color: var(--accent-ink); }
a.card-panel { display: block; }
a.card-panel.dash-tile, a.card-panel.dash-hero-card, a.card-panel.pf-card { display: flex; }

/* Holdings table on /stock-portfolio/{id}: one row per position, sortable,
   filtered by the same states as the bar and the map. */
.pf-hold-table td { vertical-align: top; }
.pf-hold-name { display: flex; align-items: flex-start; gap: var(--sp-2); min-width: 0; }
.pf-hold-name .nw-dot { margin-top: 5px; }
.pf-hold-name b { font-weight: var(--fw-semibold); }
.pf-hold-name small { display: block; max-width: 34ch; font-size: var(--fs-xs); color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pf-hold-sub { display: block; font-size: var(--fs-xs); color: var(--text-secondary); font-weight: var(--fw-regular); }
.pf-hold-weight { display: inline-block; vertical-align: middle; width: 48px; height: 4px; margin-right: var(--sp-2); border-radius: var(--radius-pill); background: var(--bg-secondary); overflow: hidden; }
.pf-hold-weight span { display: block; height: 100%; min-width: 2px; background: var(--text-secondary); border-radius: inherit; }
.pf-hold-table tbody tr { scroll-margin-top: 96px; }
.pf-hold-table tbody tr[hidden] { display: none; }
.pf-hold-empty { margin: var(--sp-4) 0 0; font-size: var(--fs-sm); color: var(--text-secondary); text-align: center; }
@media (max-width: 640px) {
  .pf-hold-name small { max-width: 13ch; }
  .pf-hold-table thead th { letter-spacing: 0.02em; }
  .pf-hold-table td, .pf-hold-table th { padding-left: var(--sp-2); padding-right: var(--sp-2); }
  .pf-holdings .card-head .seg-control { width: 100%; }
  .pf-holdings .card-head .seg-control button { flex: 1; }
}
/* Sortable headers are buttons for the keyboard too. */
.sortable-table thead th.sortable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ===== TABS =====
   Sections of one page (journal: trades / accruals). Underline marks the
   current one; the count says how much is behind each. */
.tabs { display: flex; gap: var(--sp-1); margin-bottom: var(--gap-grid); border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tab { display: inline-flex; align-items: center; gap: var(--sp-2); padding: 10px var(--sp-3); margin-bottom: -1px; border-bottom: 2px solid transparent; font-size: var(--fs-md); font-weight: var(--fw-medium); color: var(--text-secondary); text-decoration: none; white-space: nowrap; transition: color var(--dur-fast), border-color var(--dur-fast); }
.tab:hover { color: var(--text-primary); }
.tab.is-active { color: var(--text-primary); border-bottom-color: var(--accent); }
.tab-count { min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--radius-pill); background: var(--bg-secondary); font-size: var(--fs-2xs); font-weight: var(--fw-semibold); line-height: 20px; text-align: center; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.tab.is-active .tab-count { background: var(--accent-soft); color: var(--accent-ink); }

/* Back link above a page title: where this page sits. */
.page-back { display: inline-flex; align-items: center; gap: 4px; margin-bottom: var(--sp-1); font-size: var(--fs-sm); color: var(--text-secondary); text-decoration: none; }
.page-back svg { width: 15px; height: 15px; }
.page-back:hover { color: var(--accent-ink); }
/* A finger needs 40px; the extra height is padding, the text stays put. */
@media (pointer: coarse) { .page-back { min-height: 40px; margin-block: -10px calc(var(--sp-1) - 10px); padding-right: var(--sp-2); } }

/* Square icon button for row actions. */
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; padding: 0; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-tertiary); cursor: pointer; transition: background var(--dur-fast), color var(--dur-fast); }
.icon-btn svg { width: 15px; height: 15px; }
.icon-btn:hover { background: var(--bg-secondary); color: var(--text-primary); }
.icon-btn.is-danger:hover { background: var(--loss-bg); color: var(--loss); }
@media (pointer: coarse) { .icon-btn { width: 40px; height: 40px; } }

/* ===== LEDGER (journal of trades / accruals) ===== */
.ledger-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.ledger-search { position: relative; flex: 1 1 220px; max-width: 320px; margin: 0; }
.ledger-search svg { position: absolute; left: 12px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); color: var(--text-tertiary); pointer-events: none; }
.ledger-search .form-control { padding-left: 36px; min-height: 36px; }
.ledger-count { margin-left: auto; font-size: var(--fs-sm); color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.ledger-table td { vertical-align: top; }
.ledger-month td { white-space: normal; padding: var(--sp-5) var(--sp-3) var(--sp-2); border-bottom: 1px solid var(--border-strong); background: var(--bg-card); }
.ledger-month:first-child td { padding-top: var(--sp-2); }
.ledger-month:hover { background: transparent !important; }
.ledger-month-name { font-size: var(--fs-md); font-weight: var(--fw-semibold); color: var(--text-primary); margin-right: var(--sp-3); }
.ledger-month-shown, .ledger-month-sum { font-size: var(--fs-xs); color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.ledger-date { width: 72px; color: var(--text-secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ledger-date small { display: block; font-size: var(--fs-2xs); color: var(--text-tertiary); }
.ledger-asset { display: flex; align-items: flex-start; gap: var(--sp-3); min-width: 0; }
.ledger-asset b { font-weight: var(--fw-semibold); }
.ledger-asset small { display: block; max-width: 40ch; font-size: var(--fs-xs); color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ledger-kind { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; flex-shrink: 0; border-radius: var(--radius-sm); background: var(--bg-secondary); color: var(--text-secondary); }
.ledger-kind svg { width: 15px; height: 15px; }
.ledger-kind.is-sell, .ledger-kind.is-dividend, .ledger-kind.is-interest { background: var(--accent-soft); color: var(--accent-ink); }
.ledger-kind.is-withholding_tax { background: var(--loss-bg); color: var(--loss); }
.ledger-kind.is-deposit { background: color-mix(in oklab, var(--asset-cash) 16%, var(--bg-card)); color: var(--asset-cash); }
.ledger-actions { width: 1%; white-space: nowrap; text-align: right; }
.ledger-actions form { display: inline; }
.ledger-actions .icon-btn { opacity: 0; }
.ledger-row:hover .icon-btn, .ledger-actions .icon-btn:focus-visible { opacity: 1; }
@media (hover: none) { .ledger-actions .icon-btn { opacity: 1; } }
.ledger-row[hidden], .ledger-month[hidden] { display: none; }
.ledger-empty { margin: var(--sp-6) 0; text-align: center; font-size: var(--fs-sm); color: var(--text-secondary); }
@media (max-width: 640px) {
  .ledger-search { max-width: none; flex-basis: 100%; }
  .ledger-toolbar .seg-control { flex: 1; }
  .ledger-toolbar .seg-control button { flex: 1; }
  .ledger-count { margin-left: 0; }
  .ledger-asset small { max-width: 13ch; }
  .ledger-kind { width: 24px; height: 24px; }
  .ledger-asset { gap: var(--sp-2); }
  .ledger-date { width: auto; }
  .ledger-table td, .ledger-table th { padding-left: var(--sp-2); padding-right: var(--sp-2); }
}
.ledger-table td.num { white-space: nowrap; }
.pf-hold-sub.text-profit { color: var(--profit); }
.pf-hold-sub.text-loss { color: var(--loss); }
/* Search fields: the browser's blue clear cross, in the app's ink. */
input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
  width: 16px; height: 16px; cursor: pointer;
  background: var(--text-tertiary);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='M18 6 6 18M6 6l12 12'/%3E%3C/svg%3E") center / 14px no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='M18 6 6 18M6 6l12 12'/%3E%3C/svg%3E") center / 14px no-repeat;
}
input[type="search"]::-webkit-search-cancel-button:hover { background: var(--text-primary); }

/* ===== PORTFOLIO P&L (/stock-portfolio/{id}/pnl) ===== */
.pnl-timing-figs { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: var(--sp-4); }
.pnl-timing-figs > div { display: flex; flex-direction: column; gap: 2px; }
.pnl-timing-note { margin: var(--sp-4) 0 0; max-width: 80ch; font-size: var(--fs-sm); color: var(--text-secondary); line-height: var(--lh-normal); }
.pnl-months { margin-top: var(--sp-4); border-top: 1px solid var(--border); }
.pnl-months > summary { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-3) 0; cursor: pointer; list-style: none; font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text-secondary); }
.pnl-months > summary::-webkit-details-marker { display: none; }
.pnl-months > summary:hover { color: var(--text-primary); }
.pnl-months > summary svg { width: 16px; height: 16px; }
.pnl-months[open] .adv-overdue-chevron { transform: rotate(180deg); }
.pnl-asset-table td { vertical-align: top; }
.pnl-asset-table .badge-soft { margin-left: 4px; vertical-align: 1px; }
.pnl-asset-table tbody tr[hidden] { display: none; }
@media (max-width: 640px) { .pnl-months .data-table td, .pnl-months .data-table th { padding-left: var(--sp-2); padding-right: var(--sp-2); letter-spacing: 0.02em; } }
/* Three or four headline cards on a phone: two per row, compact, so the
   page does not open with a screen and a half of single numbers. */
@media (max-width: 640px) {
  .dash-hero:has(> :nth-child(3)) { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); }
  .dash-hero:has(> :nth-child(3)) > .dash-hero-card { padding: var(--sp-4); }
  .dash-hero:has(> :nth-child(3)) > .dash-hero-card:nth-child(odd):last-child { grid-column: 1 / -1; }
  .dash-hero:has(> :nth-child(3)) .dash-hero-value { font-size: 22px; }
  .dash-hero:has(> :nth-child(3)) .dash-hero-label { font-size: var(--fs-xs); margin-bottom: var(--sp-2); align-items: flex-start; }
  .dash-hero:has(> :nth-child(3)) .dash-hero-label > svg:first-child { display: none; }
  .dash-hero:has(> :nth-child(3)) .dash-hero-sub { font-size: var(--fs-xs); }
  .dash-hero:has(> :nth-child(3)) .dash-hero-unit { display: block; margin: 2px 0 0; font-size: var(--fs-xs); }
}

/* Segmented control made of links (windows that are separate URLs). */
.seg-control--links a { display: inline-flex; align-items: center; height: 26px; padding: 0 var(--sp-3); border-radius: 7px; font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--text-secondary); text-decoration: none; white-space: nowrap; }
.seg-control--links a:hover { color: var(--text-primary); }
.seg-control--links a[aria-current="page"] { background: var(--bg-card); color: var(--text-primary); box-shadow: var(--shadow-sm); }
@media (pointer: coarse) { .seg-control--links a { height: 40px; } }

/* Checkbox as a quiet pill next to a card title. */
/* Toggle chip: a pill that switches one thing on or off (aria-pressed). */
.toggle-chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 var(--sp-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius-pill); background: var(--bg-card);
  font: inherit; font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text-secondary);
  cursor: pointer; transition: border-color var(--dur-fast), background var(--dur-fast), color var(--dur-fast);
}
.toggle-chip:hover { color: var(--text-primary); border-color: var(--text-tertiary); }
.toggle-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle-chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }
.toggle-chip[aria-pressed="true"]::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.link-btn { padding: 0; border: 0; background: none; font: inherit; color: var(--accent-ink); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.link-btn:hover { color: var(--accent-hover); }
.check-pill { display: inline-flex; align-items: center; gap: var(--sp-2); margin: 0; font-size: var(--fs-sm); color: var(--text-secondary); cursor: pointer; user-select: none; }
.check-pill input { width: 16px; height: 16px; accent-color: var(--accent); }

.bt-table td { vertical-align: top; }
.bt-table tbody tr[hidden] { display: none; }

/* ===== FORM PAGE =====
   A form under the page header, on the same left edge. Fields that belong
   together share a row; a computed figure is a summary line, not a disabled
   input; the kind of record is a segmented choice, not a select. */
.form-page { max-width: 720px; }
.form-page .card-panel { padding: var(--sp-6); }
.form-row { display: grid; grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); gap: 0 var(--sp-4); }
.form-row--3 { --cols: 3; }
.form-hint { margin: 4px 0 0; font-size: var(--fs-xs); color: var(--text-secondary); }
.form-divider { height: 1px; margin: var(--sp-2) 0 var(--sp-5); background: var(--border); }
.form-total { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); margin: 0 0 var(--sp-4); padding: var(--sp-3) var(--sp-4); border-radius: var(--radius-md); background: var(--bg-secondary); font-size: var(--fs-sm); color: var(--text-secondary); }
.form-total b { font-size: var(--fs-lg); font-weight: var(--fw-semibold); color: var(--text-primary); font-variant-numeric: tabular-nums; }
.form-error { display: flex; gap: var(--sp-2); margin: 0 0 var(--sp-4); padding: var(--sp-3); border-radius: var(--radius-md); background: var(--loss-bg); color: var(--loss); font-size: var(--fs-sm); }
.form-error svg { flex-shrink: 0; width: 16px; height: 16px; margin-top: 2px; }
.form-hint.is-warn { color: var(--warn); }
.form-hint .link-btn { font-size: inherit; }
/* Quick picks under a field: the values that are already there (coins held). */
.form-picks { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-top: var(--sp-2); }
.form-picks .toggle-chip { font-variant-numeric: tabular-nums; }
.form-picks .toggle-chip .text-quiet { font-weight: var(--fw-regular); }

/* A field with its unit inside: "1,1993 ETH", "1 667,52 $". The unit can be a
   button that switches it (commission in $ or in the coin). The wrapper wears
   the field's border, so it focuses and sizes like any .form-control. */
.input-affix { display: flex; align-items: center; min-height: 40px; padding: 0 4px 0 0; background: var(--input-bg); border: 1px solid var(--input-border); border-radius: var(--radius-md); transition: border-color var(--dur-fast), box-shadow var(--dur-fast); }
.input-affix:focus-within { border-color: var(--accent); box-shadow: var(--ring-focus); }
.input-affix input { flex: 1; min-width: 0; height: 38px; padding: 0 var(--sp-2) 0 var(--sp-3); border: 0; outline: none; background: transparent; color: var(--text-primary); font: inherit; font-size: var(--fs-md); font-variant-numeric: tabular-nums; text-align: right; }
.input-affix input::placeholder { color: var(--text-tertiary); }
.input-affix-unit { flex-shrink: 0; min-width: 28px; padding: 0 var(--sp-2) 0 0; font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text-secondary); text-align: left; }
.input-affix-unit:empty { display: none; }
.input-affix-unit.is-switch { display: inline-flex; align-items: center; gap: 4px; height: 30px; padding: 0 var(--sp-2); border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-secondary); font-family: inherit; color: var(--text-primary); cursor: pointer; }
.input-affix-unit.is-switch::after { content: "⇄"; font-weight: var(--fw-regular); color: var(--text-tertiary); }
.input-affix-unit.is-switch:hover { border-color: var(--text-tertiary); }
.input-affix-unit.is-switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* The summary as rows: what moves in money, what moves in coins. */
.form-total--rows { display: grid; justify-content: stretch; align-items: stretch; gap: 6px; margin: var(--sp-1) 0 var(--sp-5); }
.form-total--rows > div { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); }
.form-total--rows dt { font-weight: var(--fw-regular); }
.form-total--rows dd { margin: 0; font-size: var(--fs-md); font-weight: var(--fw-semibold); color: var(--text-primary); font-variant-numeric: tabular-nums; text-align: right; overflow-wrap: anywhere; }
.form-total--rows > div:first-child dd { font-size: var(--fs-lg); }
.form-total--rows > .is-quiet { padding-top: 6px; border-top: 1px solid var(--border); }
.form-total--rows > .is-quiet dd { font-weight: var(--fw-medium); color: var(--text-secondary); }
.form-total--rows > [hidden] { display: none; }
.form-total--rows > .is-quiet.is-warn dd { color: var(--warn); }

/* Segmented radio: a few mutually exclusive kinds. */
.choice { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; border-radius: var(--radius-md); background: var(--bg-secondary); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice label { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 var(--sp-3); border-radius: 7px; font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text-secondary); cursor: pointer; transition: background var(--dur-fast), color var(--dur-fast); }
.choice label svg { width: 15px; height: 15px; }
.choice input:checked + label { background: var(--bg-card); color: var(--text-primary); box-shadow: var(--shadow-sm); }
.choice input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 1px; }
/* The same control with the input inside its label. */
.choice label:has(input:checked) { background: var(--bg-card); color: var(--text-primary); box-shadow: var(--shadow-sm); }
.choice label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }
@media (pointer: coarse) { .choice label { height: 40px; } }

@media (max-width: 640px) {
  .form-page .card-panel { padding: var(--sp-4); }
  .form-row, .form-row--3 { --cols: 1; }
  /* 16px stops iOS from zooming into the field on focus. */
  .form-control, .form-select { font-size: 16px; }
  .choice { display: flex; flex-wrap: nowrap; }
  .choice label { flex: 1; justify-content: center; min-width: 0; padding: 0 var(--sp-2); white-space: nowrap; }
  .input-affix input { font-size: 16px; }
}

/* ===== IMPORT (/stock-portfolio/{id}/import) ===== */
.import-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: var(--gap-grid); align-items: start; }
.import-grid > .card-panel { margin-bottom: 0; }
@media (max-width: 900px) { .import-grid { grid-template-columns: minmax(0, 1fr); } }
.drop-zone { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-2); min-height: 200px; margin: 0; padding: var(--sp-8) var(--sp-5); border: 1.5px dashed var(--border-strong); border-radius: var(--radius-lg); text-align: center; cursor: pointer; transition: border-color var(--dur-fast), background var(--dur-fast); }
.drop-zone:hover, .drop-zone.dragover { border-color: var(--accent); background: var(--accent-soft); }
.drop-zone:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.drop-zone.has-file { border-style: solid; border-color: var(--profit); background: var(--profit-bg); }
.drop-zone.has-file .empty-state-icon { background: var(--bg-card); color: var(--profit); }
.drop-zone.is-error { border-style: solid; border-color: var(--loss); background: var(--loss-bg); }
.drop-zone-title { font-size: var(--fs-md); font-weight: var(--fw-semibold); color: var(--text-primary); word-break: break-all; }
.drop-zone-sub { font-size: var(--fs-sm); color: var(--text-secondary); }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.import-steps { margin: 0 0 var(--sp-3); padding-left: 20px; font-size: var(--fs-sm); line-height: 1.7; color: var(--text-secondary); }
.import-steps b { color: var(--text-primary); font-weight: var(--fw-semibold); }
.import-result .chart-title { display: inline-flex; align-items: center; gap: var(--sp-2); }
.import-ok { width: 20px; height: 20px; color: var(--profit); }
.import-strip { box-shadow: inset 0 0 0 1px var(--border); }
.import-note { font-size: var(--fs-sm); color: var(--text-secondary); }
.import-list { margin-top: var(--sp-3); border-top: 1px solid var(--border); }
.import-list > summary { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-3) 0; cursor: pointer; font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text-secondary); }
.import-list > summary svg { width: 15px; height: 15px; }
.btn-primary.is-loading svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
/* Forms sit on the page's left edge, under the title — not centred in a gulf. */
.content > .form-page { margin-left: 0; }
@media (max-width: 640px) {
  /* Four choices: a 2×2 grid instead of ragged wrapping. Three stay one row
     (a 2-column grid left the third alone on a second line); on the narrowest
     screens they drop their icons to fit. */
  .choice:has(> input:nth-of-type(4)) { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .choice label { white-space: nowrap; }
}
@media (max-width: 420px) {
  .choice:has(> input:nth-of-type(3)):not(:has(> input:nth-of-type(4))) label svg { display: none; }
}
/* Number fields: no browser spinners — amounts are typed, not clicked. */
input.input-number::-webkit-outer-spin-button,
input.input-number::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input.input-number[type="number"] { -moz-appearance: textfield; appearance: textfield; }
/* The drawer's close button belongs to the phone drawer only; on the tablet
   icon rail it showed as a stray × above the icons. */
@media (min-width: 768px) { .sidebar-close { display: none !important; } }
.pi-src-table td { vertical-align: middle; }
/* Each source's last twelve months on its own scale: the rhythm, not the size. */
.pi-spark-head { width: 150px; }
.pi-spark { display: block; width: 130px; height: 28px; }
.pi-spark rect.is-neg { fill: var(--loss) !important; }
.pi-apr-head { width: 34%; }
.pi-trend { width: 14px !important; height: 14px !important; margin-left: 4px; }
.pi-trend.is-up { color: var(--profit); }
.pi-trend.is-down { color: var(--loss); }

/* Passive income forecast: three figures, the chart, what it is made of. */
.pi-hero-link { color: inherit; text-decoration: none; transition: box-shadow var(--dur-fast); }
.pi-hero-link:hover { color: inherit; box-shadow: var(--shadow-md); }
.pi-fc-figs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-4) var(--sp-6); margin: 0 0 var(--sp-5); }
.pi-fc-figs > div { min-width: 0; }
.pi-fc-figs dt { display: flex; align-items: center; gap: 4px; font-size: var(--fs-xs); font-weight: var(--fw-regular); color: var(--text-secondary); }
.pi-fc-figs dd { margin: 0; }
.pi-fc-value { margin-top: 2px !important; font-size: var(--fs-xl); font-weight: var(--fw-semibold); letter-spacing: var(--tracking-tight); font-variant-numeric: tabular-nums; line-height: var(--lh-tight); }
.pi-fc-sub { margin-top: 4px !important; font-size: var(--fs-xs); color: var(--text-secondary); font-variant-numeric: tabular-nums; }
/* FIRE: the chance of being there by the end of each year — one hue, the
   share of futures as its depth. */
.fire-figs { margin-top: var(--sp-1); }
.fire-odds { display: grid; gap: var(--sp-2); overflow-x: auto; }
.fire-odds-row { display: grid; grid-template-columns: 170px repeat(10, minmax(52px, 1fr)); gap: 4px; align-items: stretch; }
.fire-odds-name { align-self: center; font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.fire-odds-cell {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 6px 2px;
  border-radius: var(--radius-sm); font-size: var(--fs-sm); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums;
  background: color-mix(in oklab, var(--accent) calc(var(--p) * 0.6%), var(--bg-secondary));
  color: var(--text-primary);
}
.fire-odds-cell small { font-size: var(--fs-2xs); font-weight: var(--fw-regular); color: var(--text-secondary); }
.fire-odds-note { margin: var(--sp-3) 0 0; font-size: var(--fs-xs); color: var(--text-secondary); max-width: 90ch; }
@media (max-width: 640px) { .fire-odds-row { grid-template-columns: 110px repeat(10, 52px); } }

/* Goals: the chance of making the deadline, then the dates. */
.goal-sim-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; }
.goal-sim-head h4 { margin: 0; font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.goal-sim-sub { margin: 4px 0 var(--sp-3); font-size: var(--fs-sm); color: var(--text-secondary); }
.goal-sim-basis { color: var(--text-tertiary); }
.goal-fan { height: 240px; }

/* Trading bots: the exchanges side by side over twelve months. */
.bot-cum-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--sp-2) var(--sp-5); margin: var(--sp-3) 0 0; padding: 0; list-style: none; }
.bot-xs { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--sp-4); }
.bot-x-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); }
.bot-x-name { font-weight: var(--fw-semibold); text-transform: capitalize; }
.bot-x-ret { font-size: var(--fs-lg); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; }
.bot-xs > li + li { padding-top: var(--sp-4); border-top: 1px solid var(--border); }
.bot-x-spark { display: block; width: 100%; height: 56px; margin: var(--sp-3) 0; }
.bot-x-spark line { stroke: var(--border-strong); stroke-width: 0.5; vector-effect: non-scaling-stroke; }
.bot-x-spark rect { fill: var(--profit); opacity: 0.8; }
.bot-x-spark rect.is-neg { fill: var(--loss); }
.bot-x-meta { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-3); margin: 0; }
.bot-x-meta dt { font-size: var(--fs-xs); font-weight: var(--fw-normal); color: var(--text-secondary); }
.bot-x-meta dd { margin: 2px 0 0; font-size: var(--fs-sm); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; }
@media (max-width: 640px) { .bot-x-meta { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* Dashboard: the month's growth as a bridge in dollars. Lane 0 is what
   added, lane 1 what took it back; the dashed tick is where the month ended. */
.bridge { position: relative; height: 64px; margin: var(--sp-3) 0 var(--sp-2); }
.bridge-seg {
  transition: opacity var(--dur-fast);
  position: absolute; height: 24px; display: flex; align-items: center; justify-content: center; overflow: hidden;
  border-radius: 4px; font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: #fff; white-space: nowrap;
  font-variant-numeric: tabular-nums; box-shadow: 0 0 0 1px var(--bg-card); background-color: var(--sb);
}
.bridge-seg.lane-0 { top: 0; }
.bridge-seg.lane-1 { top: 30px; }
.bridge-seg.is-neg { background-image: repeating-linear-gradient(135deg, rgba(255,255,255,0.18) 0 4px, transparent 4px 8px); }
.bridge-zero { position: absolute; top: -4px; bottom: 6px; width: 1px; background: var(--border-strong); }
.bridge-net { position: absolute; top: -6px; bottom: 0; width: 0; border-left: 2px dashed var(--text-primary); }
.bridge-net.is-right b { left: auto; right: 6px; }
.bridge-net b { position: absolute; bottom: -2px; left: 6px; font-size: var(--fs-sm); white-space: nowrap; font-variant-numeric: tabular-nums; }
.bridge-legend { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-2) var(--sp-4); list-style: none; margin: var(--sp-3) 0 0; padding: 0; }

@media (max-width: 640px) { .bridge-legend { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.dash-chart-note { margin: var(--sp-2) 0 0; font-size: var(--fs-xs); color: var(--text-secondary); }
.dash-chart-lead { margin: calc(var(--sp-2) * -1) 0 var(--sp-3); font-size: var(--fs-sm); color: var(--text-secondary); }
.dash-chart-lead b { color: var(--text-primary); font-weight: var(--fw-semibold); }

/* ===== FAN CHART (every simulated forecast) =====
   drawFanChart() in app.js; the legend is components/fan-legend.html. */
.fan-box { position: relative; }
.fan-tip, .chart-tip {
  position: absolute; z-index: 5; pointer-events: none; width: 196px; padding: 10px 12px;
  background: var(--bg-card); border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg); font-size: var(--fs-xs); color: var(--text-secondary); font-variant-numeric: tabular-nums;
  transition: left 80ms linear, top 80ms linear;
}
/* The HTML tooltip of every other chart (htmlChartTooltip in app.js). */
.chart-tip { width: auto; min-width: 170px; max-width: 280px; }
.chart-tip-title { margin-bottom: 6px; color: var(--text-primary); font-weight: var(--fw-semibold); }
.chart-tip-row { display: grid; grid-template-columns: 8px minmax(0, 1fr) auto; align-items: center; gap: 8px; margin-top: 3px; }
.chart-tip-row i { width: 8px; height: 8px; border-radius: 2px; }
.chart-tip-row span { color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-tip-row b { color: var(--text-primary); font-weight: var(--fw-semibold); white-space: nowrap; }
.chart-tip-foot { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); color: var(--text-primary); }
.fan-tip-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px var(--sp-2); }
.fan-tip-head > span:first-child { color: var(--text-primary); font-weight: var(--fw-semibold); white-space: nowrap; }
.fan-tip-tag { padding: 1px 6px; border-radius: var(--radius-pill); background: var(--bg-secondary); font-size: var(--fs-2xs); white-space: nowrap; }
.fan-tip-tag.is-warn { background: var(--warn-bg); color: var(--warn); }
.fan-tip-value { margin: 4px 0 2px; font-size: var(--fs-xl); font-weight: var(--fw-semibold); letter-spacing: var(--tracking-tight); color: var(--text-primary); line-height: var(--lh-tight); }
.fan-tip-range { position: relative; height: 8px; margin: 8px 0 6px; border-radius: 4px; background: var(--bg-secondary); }
.fan-tip-range span { position: absolute; top: 0; bottom: 0; border-radius: 4px; }
.fan-tip-range .is-80 { background: color-mix(in oklab, var(--text-primary) 14%, transparent); }
.fan-tip-range .is-50 { background: color-mix(in oklab, var(--text-primary) 32%, transparent); }
.fan-tip-range .is-med { top: -2px; bottom: -2px; width: 2px; margin-left: -1px; border-radius: 1px; background: var(--text-primary); }
.fan-tip-line { display: flex; justify-content: space-between; gap: var(--sp-3); margin-top: 3px; color: var(--text-primary); }
.fan-tip-line span { color: var(--text-secondary); }
.fan-legend { display: flex; flex-wrap: wrap; gap: 6px var(--sp-5); list-style: none; margin: 0 0 var(--sp-2); padding: 0; font-size: var(--fs-xs); color: var(--text-secondary); }
.fan-legend li { display: inline-flex; align-items: center; gap: 6px; }
.fan-legend line { stroke: var(--text-primary); stroke-width: 2; }
.fan-legend .is-dash { stroke-dasharray: 5 3; }
.fan-legend .is-dot { stroke: var(--text-tertiary); stroke-width: 1.5; stroke-dasharray: 2 3; }
.fan-legend .is-flat { stroke: var(--text-secondary); stroke-width: 1.5; stroke-dasharray: 8 4 2 4; }
.fan-legend .is-target { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 6 3; }
.fan-legend .is-band { fill: color-mix(in oklab, var(--text-primary) 8%, transparent); }
.fan-legend .is-bench { stroke: var(--accent); stroke-width: 1.5; }
.fan-legend .is-own { stroke: var(--text-tertiary); stroke-width: 1.5; stroke-dasharray: 5 4; }
.fan-legend .is-gain { fill: color-mix(in oklab, var(--profit) 28%, transparent); }
.fan-legend .is-lossband { fill: color-mix(in oklab, var(--loss) 28%, transparent); }
.fan-legend .is-flow { fill: var(--bg-card); stroke: var(--text-primary); stroke-width: 1.5; }
.fan-tip-tag.is-flow { background: var(--bg-secondary); color: var(--text-primary); }
.fan-tip-line b { font-weight: var(--fw-semibold); white-space: nowrap; }
.value-lead > span { display: block; }
.value-lead > span + span { margin-top: 2px; }
@media (max-width: 640px) {
  .value-range { width: 100%; }
  .value-range button { flex: 1 1 auto; padding: 0 6px; }
}
.dash-chart-lead b.text-profit { color: var(--profit); }
.dash-chart-lead b.text-loss { color: var(--loss); }
.fan-tip-line b.text-profit { color: var(--profit); }
.fan-tip-line b.text-loss { color: var(--loss); }
.fan-legend .is-band50 { fill: color-mix(in oklab, var(--text-primary) 22%, transparent); }
.pi-fc-subtitle { margin: var(--sp-5) 0 var(--sp-2); font-size: var(--fs-sm); font-weight: var(--fw-semibold); }
/* Name, share and amounts sit close: a row stretched across 1 900px sent the
   eye a long way from a source to its figure. */
.pi-fc-drivers { list-style: none; margin: 0; padding: 0; }
.pi-fc-drivers li { display: grid; grid-template-columns: 10px minmax(0, 1fr) minmax(80px, 200px) 96px 84px; align-items: center; gap: var(--sp-4); padding: 9px 0; border-top: 1px solid var(--border); font-size: var(--fs-sm); }
.pi-fc-year { text-align: right; color: var(--text-secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }
.pi-fc-year small { font-size: var(--fs-xs); }
.pi-fc-drivers li:first-child { border-top: 0; }
.pi-fc-name { min-width: 0; font-weight: var(--fw-medium); }
.pi-fc-name small { display: block; margin-top: 1px; font-size: var(--fs-xs); font-weight: var(--fw-regular); color: var(--text-secondary); }
.pi-fc-share { height: 6px; border-radius: 3px; background: var(--bg-secondary); overflow: hidden; }
.pi-fc-share > span { display: block; height: 100%; border-radius: 3px; }
.pi-fc-amt { text-align: right; font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; white-space: nowrap; }
.pi-fc-amt small { font-weight: var(--fw-regular); color: var(--text-secondary); }
@media (min-width: 641px) and (max-width: 1100px) { .pi-fc-figs { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.pi-fc-bottom { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-6); }
@media (min-width: 1100px) { .pi-fc-bottom { grid-template-columns: minmax(0, 1fr) minmax(260px, 340px); gap: var(--sp-8); } }
.pi-fc-how { align-self: start; padding: var(--sp-4) var(--sp-5); border-radius: var(--radius-md); background: var(--bg-secondary); }
.pi-fc-how .pi-fc-subtitle { margin-top: 0; }
.pi-fc-how ul { margin: 0; padding-left: 1.1em; font-size: var(--fs-xs); line-height: 1.55; color: var(--text-secondary); }
.pi-fc-how li + li { margin-top: 6px; }
.pi-fc-how b { font-weight: var(--fw-semibold); color: var(--text-primary); }
.pi-fc-how .pi-fc-note { margin-top: var(--sp-3); padding-top: var(--sp-3); border-top: 1px solid var(--border); align-items: flex-start; }
.pi-fc-how .pi-fc-note svg { margin-top: 2px; }
.pi-fc-note { display: flex; align-items: center; gap: var(--sp-2); margin: var(--sp-3) 0 0; font-size: var(--fs-xs); color: var(--text-secondary); }
.pi-fc-note svg { width: 14px; height: 14px; flex-shrink: 0; }
@media (max-width: 640px) {
  .pi-fc-figs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pi-fc-drivers li { grid-template-columns: 10px minmax(0, 1fr) auto; column-gap: var(--sp-3); }
  .pi-fc-share { grid-column: 2 / -1; grid-row: 2; margin-top: 6px; }
  .pi-fc-year { display: none; }
}
.section-title small { margin-left: var(--sp-2); }
@media (max-width: 640px) {
  .pi-src-table .bl-rate-track { display: none; }
  .pi-src-table td, .pi-src-table th { padding-left: var(--sp-2); padding-right: var(--sp-2); }
  .pi-apr-head { width: auto; text-align: right; }
}

/* ===== TRADING BOTS (/trading/bots) ===== */
.bot-wd-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: var(--sp-6); align-items: end; }
.bot-advice { display: flex; flex-direction: column; align-items: flex-start; gap: var(--sp-1); min-width: 0; }
.bot-advice-kicker { display: inline-flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); color: var(--text-secondary); }
.bot-advice-amount { font-size: var(--fs-2xl); font-weight: var(--fw-semibold); line-height: 1.15; font-variant-numeric: tabular-nums; }
.bot-advice-amount:empty { display: none; }
.bot-advice-text { margin: 0; max-width: 46ch; font-size: var(--fs-sm); line-height: var(--lh-normal); color: var(--text-secondary); }
.bot-wd-form { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: var(--sp-3); align-items: end; }
.bot-wd-form .form-group { margin: 0; }
.bot-wd-actions { display: flex; gap: var(--sp-2); }
.bot-wd-actions .btn-primary, .bot-wd-actions .btn-outline { min-height: 44px; white-space: nowrap; }
@media (max-width: 900px) {
  .bot-wd-grid { grid-template-columns: minmax(0, 1fr); align-items: start; }
}
@media (max-width: 640px) {
  .bot-wd-form { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .bot-wd-actions { grid-column: 1 / -1; }
  .bot-wd-actions > * { flex: 1; justify-content: center; }
}
.bot-ledger td { vertical-align: middle; }
.bot-ledger td.num, .bot-ledger th { white-space: nowrap; }
.bot-ledger-month { font-weight: var(--fw-semibold); }
.bot-ledger td small, .bot-cell small { display: block; font-size: var(--fs-xs); color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.bot-cell { display: inline-block; margin: -4px -8px; padding: 4px 8px; border-radius: var(--radius-sm); color: inherit; text-decoration: none; }
.bot-cell:hover, .bot-cell:focus-visible { background: var(--bg-secondary); }
.bot-cell.is-empty { color: var(--text-faint); }
.bot-ledger-total { font-weight: var(--fw-semibold); }
.bot-ledger tfoot td { font-weight: var(--fw-semibold); }
/* Staking: coins that paid nothing this year fold away unless asked for. */
.stk-table .stk-idle { display: none; }
body:has(#stkShowIdle:checked) .stk-table .stk-idle { display: table-row; }
.stk-table .stk-year { font-weight: var(--fw-semibold); }
.stk-table .th-edit-link svg { width: 11px; height: 11px; opacity: 0; transition: opacity var(--dur-fast); }
.stk-table .th-edit-link { color: inherit; text-decoration: none; }
.stk-table .th-edit-link:hover { color: var(--accent-ink); }
.stk-table .th-edit-link:hover svg { opacity: 0.7; }
.stk-table { min-width: 960px; }
.inc-table .th-edit-link { color: inherit; text-decoration: none; }
.inc-table .th-edit-link:hover { color: var(--accent-ink); }
.inc-table tfoot .inc-usd-row td { font-weight: var(--fw-regular); color: var(--text-secondary); border-top: 0; padding-top: 0; }

/* ===== EXPENSES (/expenses) =====
   Lines ranked with their share, monthly rate against last year and a
   twelve-month column spark; seasonality as a years × months grid. */
.ea-table th, .ea-table td { white-space: nowrap; }
.ea-name { display: inline-flex; align-items: center; gap: var(--sp-2); font-weight: var(--fw-medium); }
.ea-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; background: var(--data-other); }
.ea-share-cell { width: 200px; }
.ea-share { display: grid; grid-template-columns: minmax(0, 1fr) 36px; align-items: center; gap: var(--sp-2); }
.ea-share .progress-track, .ea-share .progress-fill { display: block; }
.ea-share .progress-fill { background: var(--data-other); }
.ea-share-pct { font-size: var(--fs-xs); color: var(--text-secondary); text-align: right; font-variant-numeric: tabular-nums; }
.ea-spark { width: 70px; height: 20px; display: block; overflow: visible; }
.ea-spark rect { fill: var(--text-tertiary); opacity: 0.7; }
.ea-spark rect:hover { opacity: 1; fill: var(--flow-living); }
.ea-spark rect.is-empty { fill: var(--border); opacity: 1; }
.ea-more-btn { margin-top: var(--sp-3); }
@media (max-width: 640px) {
  .ea-table td:first-child { white-space: normal; }
  .ea-table th, .ea-table td { padding-left: var(--sp-2); padding-right: var(--sp-2); }
  .ea-name { align-items: flex-start; }
  .ea-name .ea-dot { margin-top: 5px; }
}
.ea-more-btn[aria-expanded="true"] svg { transform: rotate(180deg); }

/* Two cards side by side, one height: the chart fills whatever the taller
   card needs. Aligned to the top, a short heatmap left a hole under it, and
   with no margin of its own the grid sat flush on the next card. */
.ea-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: var(--gap-grid); align-items: stretch; margin-bottom: var(--gap-grid); }
.ea-grid > .card-panel { margin-bottom: 0; display: flex; flex-direction: column; }
.ea-grid > .card-panel > .chart-box { flex: 1 1 auto; height: auto; min-height: 240px; }
@media (max-width: 1100px) { .ea-grid { grid-template-columns: minmax(0, 1fr); } }

.heatmap { display: grid; gap: 4px; }
.heatmap-row { display: grid; grid-template-columns: 44px repeat(12, minmax(0, 1fr)) 56px; gap: 4px; align-items: center; }
.heatmap-head span { font-size: var(--fs-2xs); color: var(--text-tertiary); text-align: center; }
.heatmap-year { font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.heatmap-avg { font-size: var(--fs-xs); color: var(--text-secondary); text-align: right; }
.heatmap-head .heatmap-avg { text-align: right; }
.heatmap-cell {
  position: relative; display: flex; align-items: center; justify-content: center;
  height: 36px; border-radius: var(--radius-sm);
  font-size: var(--fs-2xs); font-weight: var(--fw-medium); font-variant-numeric: tabular-nums;
  color: var(--text-primary); text-decoration: none;
  transition: box-shadow var(--dur-fast), transform var(--dur-fast);
}
a.heatmap-cell:hover { color: var(--text-primary); box-shadow: 0 0 0 2px var(--text-primary); }
a.heatmap-cell:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.heatmap-cell.is-empty { background: var(--bg-secondary); opacity: 0.5; }
/* ===== HEATMAP =====
   Years × months grid (.heatmap-row: year, 12 cells, a summary column).
   Sequential steps .lv-1…5 on one hue for amounts; diverging steps
   .dv-n2…dv-p4 around zero for rates, red below and green above. */
/* One hue, light to strong. On the dark theme "more" is brighter, not darker,
   so the top step and its ink flip with the theme. */
:root { --heat-5: color-mix(in oklab, var(--flow-living) 78%, #000); --heat-5-ink: #fff; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --heat-5: color-mix(in oklab, var(--flow-living) 80%, #fff); --heat-5-ink: #1C1917; }
}
html[data-theme="dark"] { --heat-5: color-mix(in oklab, var(--flow-living) 80%, #fff); --heat-5-ink: #1C1917; }
.heatmap-cell.lv-1 { background: color-mix(in oklab, var(--flow-living) 14%, var(--bg-card)); }
.heatmap-cell.lv-2 { background: color-mix(in oklab, var(--flow-living) 30%, var(--bg-card)); }
.heatmap-cell.lv-3 { background: color-mix(in oklab, var(--flow-living) 50%, var(--bg-card)); }
.heatmap-cell.lv-4 { background: color-mix(in oklab, var(--flow-living) 72%, var(--bg-card)); }
.heatmap-cell.lv-5 { background: var(--heat-5); color: var(--heat-5-ink); }
a.heatmap-cell.lv-5:hover { color: var(--heat-5-ink); }
.heatmap-cell.dv-n2 { background: color-mix(in oklab, var(--loss) 70%, var(--bg-card)); }
.heatmap-cell.dv-n1 { background: color-mix(in oklab, var(--loss) 30%, var(--bg-card)); }
.heatmap-cell.dv-0  { background: var(--bg-secondary); }
.heatmap-cell.dv-p1 { background: color-mix(in oklab, var(--profit) 18%, var(--bg-card)); }
.heatmap-cell.dv-p2 { background: color-mix(in oklab, var(--profit) 34%, var(--bg-card)); }
.heatmap-cell.dv-p3 { background: color-mix(in oklab, var(--profit) 52%, var(--bg-card)); }
.heatmap-cell.dv-p4 { background: color-mix(in oklab, var(--profit) 72%, var(--bg-card)); }
.heatmap-cell.is-spike::after {
  content: ""; position: absolute; top: 4px; right: 4px;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-primary); box-shadow: 0 0 0 1.5px var(--bg-card);
}
.heatmap-cell.lv-5.is-spike::after { background: var(--heat-5-ink); box-shadow: none; }
.heatmap-legend { display: flex; align-items: center; gap: 4px; margin-top: var(--sp-3); font-size: var(--fs-2xs); color: var(--text-tertiary); flex-wrap: wrap; }
.heatmap-legend .heatmap-cell { width: 18px; height: 12px; border-radius: 3px; }
.heatmap-legend .heatmap-cell.is-spike { margin-left: var(--sp-3); }
.heatmap-legend .heatmap-cell.is-spike::after { top: 3px; right: 6px; width: 5px; height: 5px; }
@media (max-width: 640px) {
  .heatmap-row { grid-template-columns: 34px repeat(12, minmax(0, 1fr)); gap: 2px; }
  .heatmap-row .heatmap-avg { display: none; }
  .heatmap-cell { height: 28px; }
  .heatmap-cell span { display: none; }
  .heatmap-year { font-size: var(--fs-xs); }
}

.ea-spikes { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--sp-2); }
.ea-spike {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: var(--sp-3); row-gap: 2px;
  padding: var(--sp-3); border-radius: var(--radius-md); border: 1px solid var(--border);
  color: inherit; text-decoration: none; transition: border-color var(--dur-fast), background var(--dur-fast);
}
.ea-spike:hover { color: inherit; border-color: var(--border-strong); background: var(--bg-secondary); }
.ea-spike-month { font-weight: var(--fw-semibold); }
.ea-spike-total { font-weight: var(--fw-semibold); text-align: right; }
.ea-spike-note { grid-column: 1 / -1; font-size: var(--fs-xs); color: var(--text-secondary); }
.ea-spike-driver { grid-column: 1 / -1; display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-xs); color: var(--text-secondary); }
.ea-spike-driver b { color: var(--text-primary); font-weight: var(--fw-semibold); }
.ea-spike-driver .ea-dot { width: 8px; height: 8px; border-radius: 2px; }
.ea-spikes-none { display: flex; align-items: center; gap: var(--sp-2); margin: 0; color: var(--text-secondary); font-size: var(--fs-sm); }
.ea-spikes-none svg { width: 16px; height: 16px; color: var(--profit); }

/* ===== SAVINGS RATE (/savings-rate) ===== */
.sr-table th, .sr-table td { white-space: nowrap; }
.sr-rate-th { width: 180px; }
.sr-rate { display: grid; grid-template-columns: minmax(0, 1fr) 52px; align-items: center; gap: var(--sp-2); }
.sr-rate-bar { position: relative; display: block; height: 6px; border-radius: var(--radius-pill); background: var(--bg-secondary); overflow: hidden; }
.sr-rate-bar > span { display: block; height: 100%; border-radius: inherit; background: var(--profit); }
.sr-rate-bar.is-neg > span { background: var(--loss); }
.sr-rate-val { text-align: right; font-variant-numeric: tabular-nums; font-weight: var(--fw-semibold); }
.sr-sub { display: inline-block; min-width: 34px; margin-left: 6px; font-size: var(--fs-xs); color: var(--text-secondary); text-align: right; }
@media (max-width: 640px) {
  .sr-rate-th { width: auto; }
  .sr-rate { grid-template-columns: 48px 44px; }
  .sr-table th, .sr-table td { padding-left: var(--sp-2); padding-right: var(--sp-2); }
}

/* ===== WHAT-IF (/projections/what-if) =====
   Results on top, controls on the left (sticky on wide screens), charts on
   the right. Every slider marks where the real value sits. */
.wi-results .dash-hero-value, .wi-results .dash-hero-sub { transition: opacity var(--dur-fast); }
.wi-results.is-loading .dash-hero-value { opacity: 0.45; }
.wi-delta:not(:empty)::before { content: " · "; color: var(--text-tertiary); }
.wi-delta--lead:not(:empty)::before { content: none; }
.wi-hero-note { margin-top: 2px; color: var(--text-tertiary); }
.wi-layout { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: var(--gap-grid); align-items: start; }
.wi-controls { position: sticky; top: var(--sp-4); margin-bottom: 0; }
.wi-charts > .card-panel:last-child { margin-bottom: 0; }
@media (max-width: 1000px) {
  .wi-layout { grid-template-columns: minmax(0, 1fr); }
  .wi-controls { position: static; }
}
.wi-presets { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-bottom: var(--sp-2); }
.wi-group { margin: var(--sp-5) 0 0; padding: 0; border: 0; min-width: 0; }
.wi-group legend { float: none; width: auto; margin: 0 0 var(--sp-3); padding: 0; font-size: var(--fs-2xs); font-weight: var(--fw-semibold); letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-tertiary); }
.wi-field { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; column-gap: var(--sp-3); margin-bottom: var(--sp-4); }
.wi-field:last-child { margin-bottom: 0; }
.wi-field label { margin: 0; font-size: var(--fs-sm); color: var(--text-secondary); }
.wi-field output { font-size: var(--fs-sm); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; text-align: right; }
.wi-field output small { display: block; font-size: var(--fs-2xs); font-weight: var(--fw-regular); color: var(--text-tertiary); }
.wi-field.is-changed output { color: var(--accent-ink); }
.wi-field .form-hint { grid-column: 1 / -1; margin: var(--sp-2) 0 0; }
.wi-track { position: relative; grid-column: 1 / -1; margin-top: var(--sp-2); }
.wi-base { position: absolute; top: 50%; left: calc(8px + (100% - 16px) * var(--base, 0%) / 100%); width: 2px; height: 14px; margin: -7px 0 0 -1px; border-radius: 1px; background: var(--text-tertiary); pointer-events: none; }
.wi-field:not(.is-changed) .wi-base { opacity: 0; }
.wi-range {
  --fill: 0%;
  display: block; width: 100%; height: 24px; margin: 0; background: transparent; cursor: pointer;
  -webkit-appearance: none; appearance: none;
}
.wi-range::-webkit-slider-runnable-track { height: 6px; border-radius: var(--radius-pill); background: linear-gradient(to right, var(--accent) var(--fill), var(--border-strong) var(--fill)); }
.wi-range::-moz-range-track { height: 6px; border-radius: var(--radius-pill); background: var(--border-strong); }
.wi-range::-moz-range-progress { height: 6px; border-radius: var(--radius-pill); background: var(--accent); }
.wi-range::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -6px; border-radius: 50%; background: var(--bg-card); border: 2px solid var(--accent); box-shadow: var(--shadow-sm); position: relative; z-index: 1; }
.wi-range::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--bg-card); border: 2px solid var(--accent); box-shadow: var(--shadow-sm); }
.wi-range:focus-visible { outline: none; }
.wi-range:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--accent-soft); }
.wi-range:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 4px var(--accent-soft); }
.wi-warn { display: flex; gap: var(--sp-2); align-items: flex-start; padding: var(--sp-2) var(--sp-3); border-radius: var(--radius-sm); background: var(--warn-bg); color: var(--text-secondary); }
.wi-warn svg { width: 14px; height: 14px; flex-shrink: 0; margin-top: 3px; color: var(--warn); }
.wi-warn[hidden] { display: none; }
.wi-dock { display: none; }
@media (max-width: 1000px) {
  .wi-dock {
    position: fixed; z-index: 40; left: var(--sp-3); right: 84px; bottom: calc(var(--sp-3) + env(safe-area-inset-bottom));
    display: flex; gap: var(--sp-4); padding: var(--sp-2) var(--sp-4);
    border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg-card); box-shadow: var(--shadow-lg, var(--shadow-sm));
    font-size: var(--fs-sm); font-variant-numeric: tabular-nums;
    transform: translateY(calc(100% + 24px)); transition: transform var(--dur-fast) var(--ease-out);
  }
  .wi-dock.is-on { transform: none; }
  .wi-dock > span { display: flex; flex-direction: column; min-width: 0; }
  .wi-dock small { font-size: var(--fs-2xs); color: var(--text-tertiary); }
  .wi-dock b { font-weight: var(--fw-semibold); white-space: nowrap; }
}
@media (max-width: 640px) {
  .wi-range { height: 32px; }
  .wi-range::-webkit-slider-thumb { width: 24px; height: 24px; margin-top: -9px; }
}

/* ===== ACTIONS (/actions) =====
   Grouped by urgency; a row is select · title/desc/meta · deadline · tools.
   Selecting rows brings up a bulk bar at the bottom of the viewport. */
.act-strip .stat-strip-sub { display: block; margin-top: 2px; font-size: var(--fs-2xs); color: var(--text-tertiary); }
.act-group .chart-title { display: inline-flex; align-items: center; gap: var(--sp-2); }
.act-group--overdue .count-badge { background: var(--loss-bg); color: var(--loss); }
.act-group-note { margin: calc(var(--sp-2) * -1) 0 var(--sp-3); font-size: var(--fs-sm); color: var(--text-secondary); max-width: 70ch; }
.act-list { list-style: none; margin: 0 calc(var(--sp-6) * -1); padding: 0; }
.act-row {
  display: grid; grid-template-columns: 20px minmax(0, 1fr) 130px auto; column-gap: var(--sp-4); align-items: start;
  padding: var(--sp-3) var(--sp-6); border-top: 1px solid var(--border);
  transition: background var(--dur-fast);
}
.act-row:hover { background: var(--bg-secondary); }
.act-row.is-selected { background: var(--accent-soft); }
.act-check { width: 16px; height: 16px; margin: 3px 0 0; accent-color: var(--accent); cursor: pointer; }
.act-title { font-weight: var(--fw-semibold); line-height: 1.4; }
.act-link { color: var(--text-tertiary); }
.act-link svg { width: 13px; height: 13px; vertical-align: -1px; }
.act-link:hover { color: var(--accent-ink); }
.act-desc { margin: 2px 0 0; font-size: var(--fs-sm); color: var(--text-secondary); line-height: 1.45; max-width: 90ch;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.act-meta { display: flex; flex-wrap: wrap; gap: 4px var(--sp-3); margin-top: 6px; font-size: var(--fs-xs); color: var(--text-tertiary); }
.act-src { display: inline-flex; align-items: center; gap: 4px; color: var(--text-secondary); }
.act-src svg { width: 12px; height: 12px; }
.act-amt { font-variant-numeric: tabular-nums; color: var(--text-secondary); font-weight: var(--fw-medium); }
.act-due { display: flex; flex-direction: column; align-items: flex-end; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; white-space: nowrap; }
.act-due-rel { font-size: var(--fs-xs); color: var(--text-tertiary); }
.act-due--overdue .act-due-rel { color: var(--loss); }
.act-due--today .act-due-rel, .act-due--soon .act-due-rel { color: var(--warn); font-weight: var(--fw-medium); }
.act-tools { display: flex; gap: 2px; opacity: 0.35; transition: opacity var(--dur-fast); }
.act-row:hover .act-tools, .act-row:focus-within .act-tools, .act-row.is-selected .act-tools { opacity: 1; }
.act-tools .act-done:hover { background: var(--profit-bg); color: var(--profit); }
@media (hover: none) { .act-tools { opacity: 1; } }
@media (max-width: 640px) {
  .act-list { margin: 0 calc(var(--sp-4) * -1); }
  .act-row { grid-template-columns: 20px minmax(0, 1fr) auto; padding: var(--sp-3) var(--sp-4); column-gap: var(--sp-3); }
  .act-tools { grid-column: 2 / -1; margin-left: -6px; }
  .act-due { grid-column: 3; grid-row: 1; }
}

.act-processed { padding: 0; }
.act-processed summary { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-4) var(--sp-6); cursor: pointer; list-style: none; font-weight: var(--fw-semibold); }
.act-processed summary::-webkit-details-marker { display: none; }
.act-processed summary svg { width: 16px; height: 16px; color: var(--text-tertiary); }
.act-processed-chev { margin-left: auto; transition: transform var(--dur-fast); }
.act-processed[open] .act-processed-chev { transform: rotate(180deg); }
.act-done-list { list-style: none; margin: 0; padding: 0 0 var(--sp-2); }
.act-done-list li { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto auto; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-6); border-top: 1px solid var(--border); font-size: var(--fs-sm); }
.act-st { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 50%; }
.act-st svg { width: 12px; height: 12px; }
.act-st--done { background: var(--profit-bg); color: var(--profit); }
.act-st--cancelled { background: var(--bg-secondary); color: var(--text-tertiary); }
.act-done-title { color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.act-done-title small { color: var(--text-tertiary); }
.act-done-date { font-size: var(--fs-xs); color: var(--text-tertiary); white-space: nowrap; }
.act-done-tools { display: flex; gap: 2px; }
@media (max-width: 640px) { .act-done-list li { padding: var(--sp-2) var(--sp-4); grid-template-columns: 22px minmax(0, 1fr) auto; } .act-done-date { display: none; } }

.act-bulk {
  position: fixed; z-index: 45; left: var(--sp-4); right: var(--sp-4); bottom: calc(var(--sp-4) + env(safe-area-inset-bottom));
  width: fit-content; max-width: calc(100vw - 2 * var(--sp-4)); margin-inline: auto;
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-2) var(--sp-2) var(--sp-4); border-radius: var(--radius-lg, 14px);
  background: var(--bg-sidebar); color: var(--text-sidebar); box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
}
@media (min-width: 992px) { .act-bulk { left: calc(var(--sidebar-width) + var(--sp-4)); } }
.act-bulk #act-bulk-clear { order: 9; }
/* The bar takes the bottom of the screen; the chat button would sit on it. */
body.has-bulk-bar .chat-fab { display: none; }
@media (max-width: 640px) {
  .act-bulk { padding: var(--sp-3); }
  .act-bulk-count { flex: 1 1 auto; }
  .act-bulk #act-bulk-clear { order: 0; }
  .act-bulk-primary, .act-bulk .btn-outline-sm { flex: 1 1 auto; justify-content: center; }
  .act-bulk-move { flex: 1 1 100%; }
  .act-bulk-move input { flex: 1; }
}
.act-bulk[hidden] { display: none; }
.act-bulk-count { font-size: var(--fs-sm); font-weight: var(--fw-semibold); margin-right: var(--sp-2); white-space: nowrap; }
.act-bulk .btn-outline-sm { background: transparent; color: var(--text-sidebar); border-color: rgba(255, 255, 255, 0.25); }
.act-bulk .btn-outline-sm:hover { border-color: rgba(255, 255, 255, 0.6); color: #fff; }
.act-bulk-primary { min-height: 32px; padding: 0 var(--sp-3); font-size: var(--fs-sm); }
.act-bulk-move { display: inline-flex; gap: 4px; align-items: center; }
.act-bulk input[type="date"] { height: 32px; padding: 0 var(--sp-2); border-radius: var(--radius-sm); border: 1px solid rgba(255, 255, 255, 0.25); background: transparent; color: var(--text-sidebar); color-scheme: dark; font: inherit; font-size: var(--fs-sm); }
.act-bulk .icon-btn { color: var(--text-sidebar-muted); }
.act-bulk .icon-btn:hover { background: var(--bg-sidebar-hover); color: #fff; }
.act-due-quick { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-bottom: var(--sp-2); }
.act-due-input { max-width: 220px; }

/* ===== AI USAGE (/chat/usage) ===== */
.usage-sub { display: block; margin-top: 2px; font-size: var(--fs-2xs); color: var(--text-tertiary); }
.usage-model { font-size: var(--fs-xs); color: var(--text-secondary); background: var(--bg-secondary); padding: 2px 6px; border-radius: var(--radius-sm); }

/* ===== NET WORTH FORM (/net-worth/edit) =====
   The budget page's frame: month arrows and the rate in the header, the
   entry tables on the left, a sticky summary on the right. One amount per
   row in the account's currency (the switch beside it), last month's figure
   to copy and the change in their own columns. */
.content > .nw-edit { max-width: var(--content-max); }
.content > .budget-danger { margin-left: 0; }
.nw-cat { padding: 0; overflow: hidden; }
.nw-cat-head { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); cursor: pointer; list-style: none; }
.nw-cat-head::-webkit-details-marker { display: none; }
.nw-cat-chev { width: 16px; height: 16px; color: var(--text-tertiary); transition: transform var(--dur-fast); }
.nw-cat:not([open]) .nw-cat-chev { transform: rotate(-90deg); }
.nw-cat-name { font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.nw-cat-count { font-size: var(--fs-xs); color: var(--text-tertiary); font-variant-numeric: tabular-nums; }
.nw-cat-total { margin-left: auto; font-size: var(--fs-lg); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; }
.nw-edit-table { width: 100%; border-collapse: collapse; }
.nw-edit-table th {
  padding: 10px var(--sp-3);
  background: var(--bg-secondary);
  font-size: var(--fs-2xs); font-weight: var(--fw-semibold); letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-secondary); white-space: nowrap;
}
.nw-edit-table th:first-child, .nw-edit-table td:first-child { padding-left: var(--sp-5); }
.nw-edit-table th:last-child, .nw-edit-table td:last-child { width: 44px; padding-right: var(--sp-3); }
.nw-edit-table td { padding: 6px var(--sp-3); border-top: 1px solid var(--border); vertical-align: middle; }
.nw-row:hover { background: color-mix(in oklab, var(--bg-secondary) 55%, transparent); }
.nw-name-input {
  width: 100%; min-width: 140px; padding: 6px 8px; margin-left: -8px;
  border: 1px solid transparent; border-radius: var(--radius-sm); background: transparent;
  font: inherit; font-size: var(--fs-md); color: var(--text-primary);
  transition: border-color var(--dur-fast), background var(--dur-fast);
}
.nw-name-input:hover { border-color: var(--border); background: var(--input-bg); }
.nw-name-input:focus { outline: none; border-color: var(--accent); background: var(--input-bg); box-shadow: var(--ring-focus); }
/* The amount: an underlined figure, as in the budget, its currency beside it. */
.nw-amt { width: 190px; }
.nw-amt-field { display: flex; align-items: center; gap: 2px; border-bottom: 1px solid var(--input-border); transition: border-color var(--dur-fast), background var(--dur-fast); }
.nw-amt-field:hover { border-bottom-color: var(--text-secondary); }
.nw-amt-field:focus-within { border-bottom-color: var(--accent); background: var(--bg-secondary); }
.nw-amt-field .input-number {
  flex: 1; min-width: 0; padding: 7px 4px 7px 8px; border: 0; outline: none; background: transparent;
  font: inherit; font-size: var(--fs-md); text-align: right; font-variant-numeric: tabular-nums; color: var(--text-primary);
}
.nw-amt-field .input-number::placeholder { color: var(--text-tertiary); }
.nw-amt-field .input-number[hidden] { display: none; }
.nw-cur {
  flex-shrink: 0; min-width: 28px; height: 28px; padding: 0 6px;
  border: 0; border-radius: var(--radius-sm); background: none;
  font: inherit; font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text-secondary);
  cursor: pointer;
}
.nw-cur:hover { background: var(--bg-card); color: var(--accent-ink); }
.nw-prev, .nw-delta-cell { width: 150px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.nw-prev-btn {
  padding: 4px 6px; margin-right: -6px; border: 0; border-radius: var(--radius-sm); background: none;
  font: inherit; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; color: var(--text-secondary);
  cursor: pointer; text-decoration: underline dotted var(--border-strong); text-underline-offset: 3px;
}
.nw-prev-btn:hover { background: var(--bg-secondary); color: var(--accent-ink); text-decoration-color: currentColor; }
.nw-delta { font-size: var(--fs-sm); color: var(--text-tertiary); }
.nw-delta.is-up { color: var(--profit); }
.nw-delta.is-down { color: var(--loss); }
.nw-remove { opacity: 0; }
.nw-row:hover .nw-remove, .nw-remove:focus-visible { opacity: 1; }
@media (hover: none) { .nw-remove { opacity: 1; } }
.nw-cat-foot { display: flex; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3) var(--sp-3); border-top: 1px solid var(--border); }
/* Summary */
.nwe-sum-value { margin-top: var(--sp-2); font-size: var(--fs-2xl, 28px); font-weight: var(--fw-semibold); letter-spacing: var(--tracking-tight); font-variant-numeric: tabular-nums; line-height: 1.15; }
.nwe-sum-delta { min-height: 1.4em; font-size: var(--fs-sm); color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.nwe-classes { list-style: none; margin: var(--sp-4) 0 0; padding: 0; }
.nwe-classes li { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: var(--sp-3); padding: var(--sp-2) 0; border-top: 1px solid var(--border); font-size: var(--fs-sm); }
.nwe-classes li span { color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nwe-classes li b { font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; text-align: right; }
.nwe-classes li small { grid-column: 2; font-size: var(--fs-xs); text-align: right; font-variant-numeric: tabular-nums; }
.nwe-classes li small:not(.text-profit):not(.text-loss) { color: var(--text-tertiary); }
.nwe-fill { margin-top: var(--sp-3); padding-top: var(--sp-3); border-top: 1px solid var(--border); }
.nwe-fill-head { display: flex; justify-content: space-between; font-size: var(--fs-sm); color: var(--text-secondary); }
.nwe-fill-head b { color: var(--text-primary); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; }
.nwe-note { margin: 0; padding: 0 var(--sp-2); font-size: var(--fs-xs); line-height: 1.55; color: var(--text-secondary); }
@media (max-width: 640px) {
  .nw-cat-head { padding: var(--sp-3) var(--sp-4); gap: var(--sp-2); }
  .nw-cat-name, .nw-cat-total { font-size: var(--fs-md); }
  .nw-cat-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .nw-cat-count { display: none; }
  .nw-edit-table thead { display: none; }
  .nw-edit-table th:first-child, .nw-edit-table td:first-child { padding-left: var(--sp-4); }
  /* A row in two lines: the name across, then last month and its change
     on the left, the amount on the right. */
  .nw-edit .nw-edit-table, .nw-edit .nw-edit-table tbody { display: block; }
  .nw-edit .nw-row { display: grid; grid-template-columns: minmax(0, 1fr) 160px; align-items: center; column-gap: var(--sp-3); padding: var(--sp-2) var(--sp-4); border-top: 1px solid var(--border); }
  .nw-edit .nw-row[hidden] { display: none; }
  .nw-edit .nw-edit-table td, .nw-edit .nw-edit-table td:first-child, .nw-edit .nw-edit-table td:last-child { width: auto; padding: 0; border: 0; }
  .nw-edit .nw-row-name { grid-column: 1 / -1; }
  .nw-edit .nw-amt { grid-column: 2; grid-row: 2 / 4; }
  .nw-edit .nw-row .nw-prev.hide-sm, .nw-edit .nw-row .nw-delta-cell.hide-sm { display: block !important; grid-column: 1; text-align: left; font-size: var(--fs-xs); }
  .nw-edit .nw-prev-btn { margin: 0 0 0 -6px; font-size: var(--fs-xs); }
  .nw-edit .nw-delta { font-size: var(--fs-xs); }
  .nw-name-input { min-width: 0; font-size: 16px; font-weight: var(--fw-medium); }
  .nw-amt-field .input-number { font-size: 16px; }
}

/* The staking form borrows this row shell: boxed inputs, and on a phone
   each row turns into a small card. */
.stk-edit .nw-edit-table .form-control { min-height: 34px; padding: 4px var(--sp-2); }
@media (max-width: 640px) {
  .stk-edit .nw-edit-table, .stk-edit .nw-edit-table tbody { display: block; }
  .stk-edit .nw-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px var(--sp-2); padding: var(--sp-2) var(--sp-4) var(--sp-3); border-top: 1px solid var(--border); }
  .stk-edit .nw-row[hidden] { display: none; }
  .stk-edit .nw-edit-table td, .stk-edit .nw-edit-table td:first-child, .stk-edit .nw-edit-table td:last-child { width: auto; padding: 0; border: 0; }
  .stk-edit .nw-row-name { grid-column: 1 / -1; }
  .stk-edit .nw-edit-table .form-control { font-size: 16px; }
}


/* Passive income form: the automatic sources as a read-only list, each
   linking to where it comes from. */
.pi-auto { margin: 0; border: 1px solid var(--border); border-radius: var(--radius-md); }
.pi-auto > div { display: flex; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-2) var(--sp-3); }
.pi-auto > div + div { border-top: 1px solid var(--border); }
.pi-auto dt { font-weight: var(--fw-regular); font-size: var(--fs-sm); }
.pi-auto dt a { color: var(--text-secondary); text-decoration: none; }
.pi-auto dt a:hover { color: var(--accent-ink); text-decoration: underline; text-underline-offset: 2px; }
.pi-auto dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: var(--fw-medium); }
.pi-rate { max-width: 140px; }

/* Staking form: same row shell as the net worth form, six columns. */
.stk-edit .nw-edit-table td:nth-child(n+2) { width: auto; }
.stk-edit .nw-edit-table td:first-child { width: 30%; }
.stk-edit .nw-edit-table .form-control { width: 120px; margin-left: auto; }
.stk-edit .stk-was { color: var(--text-tertiary); font-size: var(--fs-sm); }
.stk-edit .stk-income { min-width: 80px; font-weight: var(--fw-semibold); }
@media (max-width: 640px) {
  .stk-edit .nw-row { grid-template-columns: 1fr 1fr 1fr; }
  .stk-edit .nw-row-name { grid-column: 1 / 3; grid-row: 1; }
  .stk-edit .stk-income { grid-column: 3; grid-row: 1; text-align: right; }
  .stk-edit .nw-edit-table td:first-child { width: auto; }
  .stk-edit .nw-edit-table .form-control { width: 100%; }
  .stk-edit td[data-label]::before { content: attr(data-label); display: block; margin-bottom: 2px; font-size: var(--fs-2xs); color: var(--text-tertiary); }
}

/* Bot record form: the withdrawal rule's verdict for the typed result. */
.bot-advisor { margin: var(--sp-2) 0 var(--sp-4); padding: var(--sp-3) var(--sp-4); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg-secondary); }
.bot-advisor[hidden] { display: none; }
.bot-advisor-header { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-xs); color: var(--text-secondary); }
.bot-advisor-header svg { width: 14px; height: 14px; color: var(--text-tertiary); }
.bot-advisor-loading { margin-left: auto; color: var(--text-tertiary); }
.bot-advisor-body { display: flex; flex-direction: column; gap: 2px; margin-top: var(--sp-2); }
.bot-advisor-amount { font-size: var(--fs-lg); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; }
.bot-advisor-text { font-size: var(--fs-sm); color: var(--text-secondary); line-height: 1.45; }

/* A single-card form page: the card at the page's left edge under its
   header, a readable width, never centred away from the title. */
.content > .form-card { max-width: 640px; margin-left: 0; }

/* ===== BACKUP (/backup) =====
   When the database was last copied and where to, the copies kept, how to
   bring one back. */
.bk-hero-sub { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1) var(--sp-3); }
.bk-status { display: inline-flex; align-items: center; gap: var(--sp-1); font-weight: var(--fw-medium); }
.bk-status svg { width: 14px; height: 14px; flex: none; }
.bk-error { margin: var(--sp-3) 0 0; padding: var(--sp-2) var(--sp-3); border-radius: var(--radius-md); background: var(--loss-bg); color: var(--loss); font-size: var(--fs-xs); overflow-wrap: anywhere; }
.bk-store { justify-content: flex-start; }
.bk-path, .bk-cmd code { display: block; font-size: var(--fs-xs); line-height: 1.5; color: var(--text-primary); background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow-wrap: anywhere; }
.bk-path { margin: var(--sp-1) 0 var(--sp-1); padding: var(--sp-2) var(--sp-3); }
.bk-table td { vertical-align: middle; }
.bk-unfold { margin-top: var(--sp-2); }
.bk-download { width: 44px; height: 44px; padding: 0; }
.bk-download svg { width: 16px; height: 16px; }
@media (min-width: 576px) {
  .bk-download { width: 36px; height: 36px; }
}
.bk-steps { margin: 0 0 var(--sp-3); padding-left: var(--sp-5); font-size: var(--fs-sm); color: var(--text-primary); }
.bk-steps li + li { margin-top: var(--sp-2); }
.bk-cmd { display: flex; flex-direction: column; align-items: flex-start; gap: var(--sp-2); margin-top: var(--sp-2); }
.bk-cmd code { align-self: stretch; padding: var(--sp-2) var(--sp-3); }
@media (min-width: 576px) {
  .bk-cmd { flex-direction: row; }
  .bk-cmd code { flex: 1; min-width: 0; }
  .bk-cmd .btn-outline-sm { flex: none; }
}

/* ===== ADVISOR (/advisor) =====
   Reading order: the month's analysis, what to do (recommendations), and on
   the side what you committed to (plan), the dates and what moved since last
   month's advice. Every action swaps #adv-work in place; nothing reloads. */
.adv-head-actions { gap: var(--sp-2); }

/* — Разбор месяца — */
.adv-brief { position: relative; }
.adv-brief-title { display: inline-flex; align-items: center; gap: var(--sp-2); }
.adv-brief-title svg { width: 18px; height: 18px; color: var(--accent); }
.adv-brief-tools { display: inline-flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; justify-content: flex-end; }
.adv-btn-sm { height: 30px; padding: 0 var(--sp-3); font-size: var(--fs-xs); }
.adv-btn-sm svg { width: 14px; height: 14px; }
.btn-ghost:disabled { opacity: 0.45; cursor: progress; }
button.htmx-request svg, button[disabled].htmx-request svg { animation: spin 0.9s linear infinite; }

.adv-brief-body { transition: opacity var(--dur-base) var(--ease-out); }
.adv-brief.is-generating .adv-brief-body { opacity: 0.4; pointer-events: none; }
.adv-brief-lead { font-size: var(--fs-lg); line-height: 1.6; color: var(--text-primary); max-width: 74ch; }
.adv-brief-lead p { margin: 0; }
.adv-brief-more { margin-top: var(--sp-3); }
.adv-brief-more > summary {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 0;
  list-style: none; cursor: pointer; font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--accent-ink);
}
.adv-brief-more > summary::-webkit-details-marker { display: none; }
.adv-brief-more > summary svg { width: 16px; height: 16px; transition: transform var(--dur-fast); }
.adv-brief-more[open] > summary svg { transform: rotate(180deg); }
.adv-brief-more .adv-more-open, .adv-brief-more[open] .adv-more-closed { display: none; }
.adv-brief-more[open] .adv-more-open { display: inline; }
.adv-brief-more[open] > summary { order: 2; }
.adv-brief-more > .adv-md { margin-top: var(--sp-2); padding-top: var(--sp-4); border-top: 1px solid var(--border); }

/* The AI's Markdown, rendered on the server. */
.adv-md { font-size: var(--fs-md); line-height: 1.6; color: var(--text-primary); max-width: 74ch; }
.adv-md p { margin: 0 0 var(--sp-3); }
.adv-md > :last-child { margin-bottom: 0; }
.adv-md h3 { margin: var(--sp-5) 0 var(--sp-2); font-size: var(--fs-md); font-weight: var(--fw-bold); }
.adv-md > h3:first-child { margin-top: 0; }
.adv-md ul, .adv-md ol { margin: 0 0 var(--sp-3); padding-left: 1.3em; }
.adv-md li { margin-bottom: 6px; padding-left: 2px; }
.adv-md li::marker { color: var(--text-tertiary); font-variant-numeric: tabular-nums; }
.adv-md strong { font-weight: var(--fw-semibold); }
.adv-md em { color: var(--text-secondary); }
.adv-md code { padding: 1px 5px; border-radius: 4px; background: var(--bg-secondary); font-family: inherit; font-size: 0.92em; }
.adv-md hr { border: 0; border-top: 1px solid var(--border); margin: var(--sp-4) 0; }
.adv-md blockquote { margin: 0 0 var(--sp-3); padding: 2px 0 2px var(--sp-3); border-left: 3px solid var(--accent); color: var(--text-secondary); }

.adv-brief-empty { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4) var(--sp-6); flex-wrap: wrap; }
.adv-brief-empty p { margin: 0; max-width: 64ch; color: var(--text-secondary); line-height: var(--lh-normal); }

.adv-brief-status { display: inline-flex; align-items: center; gap: var(--sp-2); min-height: 30px; font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--accent-ink); font-variant-numeric: tabular-nums; }
.adv-elapsed { min-width: 3.2ch; }
.adv-pulse { position: relative; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.adv-pulse::after { content: ""; position: absolute; inset: 0; border-radius: 50%; background: var(--accent); animation: adv-pulse 1.6s var(--ease-out) infinite; }
@keyframes adv-pulse { from { transform: scale(1); opacity: 0.6; } to { transform: scale(2.8); opacity: 0; } }
.adv-brief-note { margin: var(--sp-3) 0 0; font-size: var(--fs-xs); color: var(--text-secondary); }

/* Same height and rhythm as a lead plus its toggle, so the finished text
   lands without moving what is below it. */
.adv-skeleton { display: grid; gap: calc(1.6em - 14px); padding: calc(0.8em - 7px) 0; max-width: 74ch; font-size: var(--fs-lg); }
.adv-skeleton span {
  height: 14px; border-radius: 7px;
  background: linear-gradient(90deg, var(--bg-secondary) 0%, color-mix(in oklab, var(--bg-secondary) 55%, var(--bg-card)) 50%, var(--bg-secondary) 100%);
  background-size: 200% 100%; animation: adv-shimmer 1.4s linear infinite;
}
/* Five lines on a phone, three on a wide screen: the lead's usual length. */
.adv-skeleton span:nth-child(2) { width: 94%; }
.adv-skeleton span:nth-child(3), .adv-skeleton span:nth-child(5) { width: 82%; }
.adv-skeleton span.is-toggle { width: 8em; height: 12px; margin-top: calc(var(--sp-3) + 4px); margin-bottom: 4px; }
@media (min-width: 641px) { .adv-skeleton span:nth-child(4), .adv-skeleton span:nth-child(5) { display: none; } }
@keyframes adv-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

.adv-brief-error {
  display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap;
  margin-bottom: var(--sp-4); padding: var(--sp-3) var(--sp-4); border-radius: var(--radius-md);
  background: var(--loss-bg); color: var(--text-primary); font-size: var(--fs-sm);
}
.adv-brief-error > svg { width: 18px; height: 18px; color: var(--loss); flex-shrink: 0; }
.adv-brief-error > span { flex: 1 1 260px; }

@media (prefers-reduced-motion: reduce) {
  .adv-pulse::after, .adv-skeleton span, button.htmx-request svg { animation: none; }
}

/* — Layout: recommendations and the side column — */
.adv-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 var(--gap-grid); align-items: start; }
@media (min-width: 1200px) { .adv-grid:not(.is-single) { grid-template-columns: minmax(0, 1fr) 360px; } }
.adv-side { min-width: 0; }

/* — Что сделать — */
/* One quiet line of totals by kind: "довнести $735 · к уплате 424 229 ₸". */
.adv-sums { display: flex; flex-wrap: wrap; gap: 4px var(--sp-5); margin: calc(var(--sp-2) * -1) 0 var(--sp-3); font-size: var(--fs-sm); }
.adv-sums div { display: inline-flex; align-items: baseline; gap: 6px; }
.adv-sums dt { font-weight: var(--fw-regular); color: var(--text-secondary); }
.adv-sums dd { margin: 0; font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; }

.adv-rec-list { list-style: none; margin: 0 calc(var(--sp-6) * -1); padding: 0; }
.adv-rec {
  display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; column-gap: var(--sp-4); align-items: start;
  padding: var(--sp-4) var(--sp-6); border-top: 1px solid var(--border);
  transition: background var(--dur-fast), opacity var(--dur-base);
}
.adv-rec:hover { background: var(--bg-secondary); }
.adv-rec:has(.htmx-request) { opacity: 0.5; pointer-events: none; }
.adv-rec-icon { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: var(--radius-md); background: var(--bg-secondary); color: var(--text-secondary); }
.adv-rec:hover .adv-rec-icon { background: var(--bg-card); }
.adv-rec-icon svg { width: 16px; height: 16px; }
.adv-rec.is-insight .adv-rec-icon { background: var(--accent-soft); color: var(--accent-ink); }
.adv-rec-title { font-weight: var(--fw-semibold); line-height: 1.4; }
.adv-rec-desc { margin: 4px 0 0; font-size: var(--fs-sm); line-height: 1.5; color: var(--text-secondary); max-width: 78ch; }
.adv-rec .act-meta { align-items: center; margin-top: var(--sp-2); }
.adv-rec .act-amt { color: var(--text-primary); }
.adv-rec-tools { display: flex; align-items: center; gap: var(--sp-2); }
.adv-rec-icons { display: inline-flex; gap: 2px; opacity: 0.7; transition: opacity var(--dur-fast); }
.adv-rec:hover .adv-rec-icons, .adv-rec:focus-within .adv-rec-icons { opacity: 1; }
.adv-rec-icons .adv-mark-done:hover { background: var(--profit-bg); color: var(--profit); }
@media (hover: none) { .adv-rec-icons { opacity: 1; } }
.adv-to-plan { min-width: 88px; }
.adv-in-plan { display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-width: 88px; height: 32px; padding: 0 var(--sp-3); border-radius: var(--radius-md); background: var(--profit-bg); color: var(--profit); font-size: var(--fs-xs); font-weight: var(--fw-semibold); white-space: nowrap; }
.adv-in-plan svg { width: 14px; height: 14px; }

.adv-empty-inline { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-3) 0 var(--sp-1); font-size: var(--fs-sm); color: var(--text-secondary); }
.adv-empty-inline svg { width: 18px; height: 18px; color: var(--profit); }

.adv-fold { margin: 0 calc(var(--sp-6) * -1); border-top: 1px solid var(--border); }
.adv-fold:last-child { margin-bottom: calc(var(--sp-6) * -1); }
.adv-fold > summary { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-3) var(--sp-6); cursor: pointer; list-style: none; font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text-secondary); }
.adv-fold > summary:hover { color: var(--text-primary); }
.adv-fold > summary::-webkit-details-marker { display: none; }
.adv-fold > summary svg { width: 16px; height: 16px; color: var(--text-tertiary); }
.adv-fold .count-badge { background: var(--bg-secondary); color: var(--text-secondary); }
.adv-fold-chev { margin-left: auto; transition: transform var(--dur-fast); }
.adv-fold[open] .adv-fold-chev { transform: rotate(180deg); }
.adv-fold-note { margin: 0; padding: 0 var(--sp-6) var(--sp-2); font-size: var(--fs-xs); color: var(--text-secondary); max-width: 70ch; }
.adv-fold .act-done-list li:has(.htmx-request) { opacity: 0.5; }
.act-st--defer { background: var(--warn-bg); color: var(--warn); }

/* — The side column: plan, dates, what moved — */
.adv-side .card-panel { padding: var(--sp-5); }
.adv-side .chart-title { display: inline-flex; align-items: center; gap: var(--sp-2); }
.adv-side-empty { margin: 0; font-size: var(--fs-sm); line-height: var(--lh-normal); color: var(--text-secondary); }

.adv-plan-list, .adv-date-list, .adv-verdict-list { list-style: none; margin: 0; padding: 0; }
.adv-plan-row { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; gap: var(--sp-3); align-items: start; padding: 10px 0; border-top: 1px solid var(--border); transition: opacity var(--dur-base); }
.adv-plan-row:first-child { border-top: 0; padding-top: 2px; }
.adv-plan-row:has(.htmx-request) { opacity: 0.5; pointer-events: none; }
.adv-plan-check { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; margin-top: 1px; padding: 0; border: 1.5px solid var(--border-strong); border-radius: 50%; background: var(--bg-card); color: transparent; cursor: pointer; transition: border-color var(--dur-fast), color var(--dur-fast), background var(--dur-fast); }
.adv-plan-check svg { width: 13px; height: 13px; }
.adv-plan-check:hover, .adv-plan-check:focus-visible { border-color: var(--profit); color: var(--profit); background: var(--profit-bg); }
.adv-plan-row .act-st { margin-top: 1px; }
.adv-plan-title { font-size: var(--fs-sm); font-weight: var(--fw-medium); line-height: 1.45; }
.adv-plan-row.is-closed .adv-plan-title { color: var(--text-secondary); text-decoration: line-through; text-decoration-color: var(--text-tertiary); }
.adv-plan-due { margin-top: 2px; font-size: var(--fs-xs); color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.adv-plan-due.act-due--overdue, .adv-plan-due.act-due--overdue .act-due-rel { color: var(--loss); }
.adv-plan-cancel { width: 26px; height: 26px; margin-top: -2px; opacity: 0.5; }
.adv-plan-row:hover .adv-plan-cancel { opacity: 1; }
@media (hover: none) { .adv-plan-cancel { opacity: 1; } }
.adv-plan-closed { margin-top: var(--sp-2); border-top: 1px solid var(--border); }
.adv-plan-closed > summary { display: flex; align-items: center; gap: var(--sp-2); padding: 10px 0 2px; cursor: pointer; list-style: none; font-size: var(--fs-sm); color: var(--text-secondary); }
.adv-plan-closed > summary::-webkit-details-marker { display: none; }
.adv-plan-closed > summary:hover { color: var(--text-primary); }
.adv-plan-closed .count-badge { background: var(--bg-secondary); color: var(--text-secondary); }
.adv-plan-closed > summary svg { width: 16px; height: 16px; color: var(--text-tertiary); }
.adv-plan-closed[open] .adv-fold-chev { transform: rotate(180deg); }
.adv-plan-closed .adv-plan-list { margin-top: var(--sp-2); }
.adv-overdue-link { display: flex; align-items: center; gap: var(--sp-2); margin-top: var(--sp-3); padding: var(--sp-2) var(--sp-3); border-radius: var(--radius-md); background: var(--loss-bg); color: var(--loss); font-size: var(--fs-sm); font-weight: var(--fw-medium); text-decoration: none; }
.adv-overdue-link:hover { color: var(--loss); text-decoration: underline; }
.adv-overdue-link svg { width: 16px; height: 16px; flex-shrink: 0; }

.adv-date-row { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: var(--sp-3); align-items: baseline; padding: 8px 0; border-top: 1px solid var(--border); font-size: var(--fs-sm); }
.adv-date-row:first-child { border-top: 0; padding-top: 0; }
.adv-date-day { color: var(--text-secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }
.adv-date-row.is-overdue .adv-date-day { color: var(--loss); }
.adv-date-label { min-width: 0; line-height: 1.4; }
.adv-date-row .badge-soft { white-space: nowrap; }

.adv-verdict-row { display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: var(--sp-3); align-items: baseline; padding: 8px 0; border-top: 1px solid var(--border); }
.adv-verdict-row:first-child { border-top: 0; padding-top: 0; }
.adv-verdict { justify-self: start; padding: 2px 8px; border-radius: var(--radius-pill); font-size: var(--fs-2xs); font-weight: var(--fw-semibold); white-space: nowrap; background: var(--bg-secondary); color: var(--text-secondary); }
.adv-verdict.is-improved { background: var(--profit-bg); color: var(--profit); }
.adv-verdict.is-worse { background: var(--loss-bg); color: var(--loss); }
.adv-verdict-title { font-size: var(--fs-sm); line-height: 1.4; }
.adv-retro { margin: 0; font-size: var(--fs-xs); color: var(--text-secondary); }
.adv-verdict-list + .adv-retro { margin-top: var(--sp-3); padding-top: var(--sp-3); border-top: 1px solid var(--border); }
.adv-verdict-detail { margin-top: 2px; font-size: var(--fs-xs); color: var(--text-secondary); font-variant-numeric: tabular-nums; }

/* — Как прошёл месяц — */
.adv-charts { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 var(--gap-grid); }
@media (min-width: 900px) { .adv-charts { grid-template-columns: repeat(2, minmax(0, 1fr)); } .adv-charts-wide { grid-column: 1 / -1; } }
.adv-cat-box { height: 240px; }

@media (max-width: 640px) {
  .adv-brief-lead { font-size: var(--fs-md); }
  .adv-brief .card-head { flex-wrap: wrap; row-gap: var(--sp-2); }
  .adv-rec-list, .adv-fold { margin-left: calc(var(--sp-4) * -1); margin-right: calc(var(--sp-4) * -1); }
  .adv-fold:last-child { margin-bottom: calc(var(--sp-4) * -1); }
  .adv-rec { grid-template-columns: 28px minmax(0, 1fr); column-gap: var(--sp-3); padding: var(--sp-4); }
  .adv-rec-icon { width: 28px; height: 28px; }
  .adv-rec-tools { grid-column: 2; margin-top: var(--sp-3); justify-content: space-between; }
  .adv-fold > summary { padding: var(--sp-3) var(--sp-4); }
  .adv-fold-note { padding: 0 var(--sp-4) var(--sp-2); }
}

/* Budget: the month against the three before it (edit-budget sidebar). */
.bud-vs { list-style: none; margin: var(--sp-3) 0 0; padding: 0; display: grid; gap: var(--sp-4); }
.bud-vs-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); font-size: var(--fs-sm); }
.bud-vs-head span { color: var(--text-secondary); }
.bud-vs-head b { font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bud-vs-track { position: relative; display: block; height: 6px; margin: 6px 0 4px; border-radius: 3px; background: var(--bg-secondary); }
.bud-vs-bar { display: block; height: 100%; width: 0; border-radius: 3px; background: var(--asset-cash); transition: width var(--dur-fast); }
.bud-vs-avg { position: absolute; top: -4px; width: 2px; height: 14px; margin-left: -1px; border-radius: 1px; background: var(--text-primary); }
.bud-vs small { display: block; font-size: var(--fs-xs); color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.bud-vs-head span[data-plan]:not([data-plan=""])::after { content: " · " attr(data-plan); color: var(--text-tertiary); }

/* ===== Trading month (/stock-portfolio/{id}/month) ===== */
.tm-table td { vertical-align: middle; }
.tm-sub { display: block; font-size: var(--fs-xs); font-weight: var(--fw-normal, 400); color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.tm-table td.num .tm-sub { text-align: right; }
.tm-result-th { width: 34%; text-align: right; }
.tm-result { display: flex; align-items: center; justify-content: flex-end; gap: var(--sp-3); }
.tm-result .num { min-width: 92px; text-align: right; }
.tm-bar { flex: 1; max-width: 220px; height: 8px; border-radius: 4px; background: var(--bg-secondary); overflow: hidden; display: flex; justify-content: flex-end; }
.tm-bar > span { display: block; height: 100%; border-radius: 4px; background: var(--profit); }
.tm-bar > span.is-neg { background: var(--loss); }
.tm-table tfoot td { font-weight: var(--fw-semibold); }
.tm-parking td { color: var(--text-secondary); }
.tm-parking td b { font-weight: var(--fw-medium, 500); }
.tm-compact td, .tm-compact th { font-size: var(--fs-sm); }
.stat-strip-link { color: inherit; text-decoration: none; }
.stat-strip-link:hover { color: var(--accent-ink); }
@media (max-width: 640px) {
  .tm-result-th { width: auto; }
  .tm-bar { display: none; }
  .tm-result .num { min-width: 0; }
}
.tm-more { margin-top: var(--sp-2); }
.tm-bar.is-blank { background: none; }
/* A page title with a status chip beside it (budget phase, a month in progress). */
.page-title-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); }
.page-title-row .page-title { margin: 0; }
.page-title-row .budget-phase { margin-left: 0; }

/* Journals: a second filter row, the cash-parking switch, ticker picks and
   month headers that open the month. */
.ledger-toolbar--sub { margin-top: calc(var(--sp-2) * -1); }
.ledger-check { display: inline-flex; align-items: center; gap: var(--sp-2); min-height: 36px; font-size: var(--fs-sm); color: var(--text-primary); cursor: pointer; }
.ledger-check input { width: 16px; height: 16px; accent-color: var(--accent); }
.ledger-pick { padding: 0; border: 0; background: none; font: inherit; font-weight: var(--fw-semibold); color: inherit; cursor: pointer; }
.ledger-pick:hover { color: var(--accent-ink); text-decoration: underline; text-underline-offset: 3px; }
.ledger-month-link { display: inline-flex; align-items: center; gap: 2px; color: inherit; text-decoration: none; }
.ledger-month-link svg { width: 14px; height: 14px; color: var(--text-tertiary); }
.ledger-month-link:hover { color: var(--accent-ink); }
.ledger-month-link:hover svg { color: currentColor; }
.stat-strip-value [data-ledger-sum] { display: block; }
@media (max-width: 640px) {
  .ledger-toolbar .seg-control { overflow-x: auto; max-width: 100%; }
}
.stat-strip-note { grid-column: 1 / -1; margin: 0; padding: var(--sp-2) var(--sp-5); font-size: var(--fs-xs); color: var(--text-secondary); box-shadow: 0 -1px 0 var(--border) !important; }
.ledger-check small { font-size: var(--fs-xs); }
@media (max-width: 640px) {
  .ledger-toolbar .seg-control { flex: 1 1 100%; overflow-x: auto; scrollbar-width: none; }
  .ledger-toolbar .seg-control button { flex: 1 0 auto; }
  .ledger-check { align-items: flex-start; }
  .ledger-check small { display: block; }
  .stat-strip-note { padding: var(--sp-2) var(--sp-4); }
}
@media (max-width: 640px) {
  /* With a note under the strip the odd last figure is second to last. */
  .stat-strip > .stat-strip-item:nth-child(odd):nth-last-child(2):has(+ .stat-strip-note) { grid-column: 1 / -1; }
}

/* ===== Year heatmap (trading month) =====
   Weeks as columns, Monday on top. Colour is the day's realized result on
   the profit/loss tokens, four steps graded against the year; a day with only
   buys is neutral; a dot marks dividends. The shown month is at full
   strength, the rest of the year a step quieter. */
.heat-summary { margin: calc(var(--sp-2) * -1) 0 var(--sp-4); font-size: var(--fs-sm); color: var(--text-secondary); }
.heat-summary b { font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; }
.heat-scroll { overflow-x: auto; scrollbar-width: thin; }
.heat {
  --gap: 3px;
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  grid-template-areas: ". months" "days grid";
  column-gap: var(--sp-2);
  min-width: calc(var(--weeks) * 13px + 40px);
}
.heat-months { grid-area: months; display: grid; grid-template-columns: repeat(var(--weeks), minmax(0, 1fr)); column-gap: var(--gap); margin-bottom: 6px; }
.heat-month { display: flex; flex-direction: column; min-width: 0; white-space: nowrap; font-size: var(--fs-xs); line-height: 1.3; color: var(--text-secondary); text-decoration: none; }
.heat-month small { font-size: 10px; font-variant-numeric: tabular-nums; }
.heat-month:hover span { color: var(--accent-ink); }
.heat-month.is-current span { color: var(--text-primary); font-weight: var(--fw-semibold); }
.heat-weekdays { grid-area: days; display: grid; grid-template-rows: repeat(7, minmax(0, 1fr)); row-gap: var(--gap); font-size: 10px; color: var(--text-tertiary); }
.heat-weekdays span { display: flex; align-items: center; }
.heat-grid { grid-area: grid; display: grid; grid-template-rows: repeat(7, auto); grid-template-columns: repeat(var(--weeks), minmax(0, 1fr)); grid-auto-flow: column; gap: var(--gap); }
.heat-cell { position: relative; display: block; aspect-ratio: 1; border-radius: 3px; background: var(--bg-secondary); }
.heat-grid .heat-cell:not(.is-month):not(.is-pad) { opacity: 0.55; }
.heat-cell.is-pad { background: none; }
.heat-cell.is-future { background: none; box-shadow: inset 0 0 0 1px var(--border); }
.heat-cell.lv-0 { background: color-mix(in oklab, var(--text-tertiary) 45%, var(--bg-card)); }
.heat-cell.lv-g1 { background: color-mix(in oklab, var(--profit) 28%, var(--bg-card)); }
.heat-cell.lv-g2 { background: color-mix(in oklab, var(--profit) 50%, var(--bg-card)); }
.heat-cell.lv-g3 { background: color-mix(in oklab, var(--profit) 75%, var(--bg-card)); }
.heat-cell.lv-g4 { background: var(--profit); }
.heat-cell.lv-l1 { background: color-mix(in oklab, var(--loss) 28%, var(--bg-card)); }
.heat-cell.lv-l2 { background: color-mix(in oklab, var(--loss) 50%, var(--bg-card)); }
.heat-cell.lv-l3 { background: color-mix(in oklab, var(--loss) 75%, var(--bg-card)); }
.heat-cell.lv-l4 { background: var(--loss); }
.heat-cell.has-income::after { content: ""; position: absolute; right: 18%; bottom: 18%; width: 28%; height: 28%; min-width: 3px; min-height: 3px; border-radius: 50%; background: var(--asset-cash); box-shadow: 0 0 0 1px var(--bg-card); }
a.heat-cell.is-active { cursor: pointer; }
a.heat-cell.is-active:hover, a.heat-cell.is-active:focus-visible, a.heat-cell.is-hot { outline: 2px solid var(--text-primary); outline-offset: 1px; opacity: 1 !important; z-index: 1; }
a.heat-cell:not(.is-active) { pointer-events: none; }
.heat-legend { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-5); margin-top: var(--sp-4); font-size: var(--fs-xs); color: var(--text-secondary); }
.heat-legend-item { display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.heat-legend-item .heat-cell:first-of-type { margin-left: 4px; }
.heat-legend-item .heat-cell:last-of-type { margin-right: 4px; }
.heat-legend .heat-cell { width: 12px; flex: 0 0 12px; opacity: 1 !important; }
.heat-tip-who { color: var(--text-secondary) !important; line-height: 1.5; white-space: normal; }
/* The tooltip is the charts' card, floating over the page so the grid's
   horizontal scroll on a phone cannot cut it. */
.chart-tip.is-floating { position: fixed; z-index: 1000; pointer-events: none; transition: none; }
/* initTips() in app.js: any element with data-tip shows the card it holds in
   <template class="tip"> (components/tip.html). A wide card carries a big
   figure and a strip, like the forecast's. */
.chart-tip.is-wide { min-width: 260px; max-width: 320px; }
.chart-tip .fan-tip-head { margin-bottom: 2px; }
.chart-tip-title i[data-sw] { display: inline-block; width: 8px; height: 8px; margin-right: 8px; border-radius: 2px; vertical-align: 1px; }
.chart-tip .fan-tip-head > span:first-child { white-space: normal; }
.chart-tip .fan-tip-value small { margin-left: 6px; font-size: var(--fs-xs); font-weight: var(--fw-regular); color: var(--text-secondary); letter-spacing: 0; }
.chart-tip .chart-tip-foot { color: var(--text-secondary); white-space: normal; line-height: 1.45; }
.chart-tip-note { max-width: 260px; color: var(--text-secondary); white-space: normal; line-height: 1.45; }
.chart-tip .chart-tip-foot b { color: var(--text-primary); font-weight: var(--fw-semibold); }
.chart-tip b.text-profit, .chart-tip-row b.text-profit { color: var(--profit); }
.chart-tip b.text-loss, .chart-tip-row b.text-loss { color: var(--loss); }
.chart-tip b.text-warn { color: var(--warn); }
.chart-tip b.text-quiet { color: var(--text-secondary); font-weight: var(--fw-regular); }
.fan-tip-tag.is-profit { background: var(--profit-bg); color: var(--profit); }
.fan-tip-tag.is-loss { background: var(--loss-bg); color: var(--loss); }
.fan-tip-range .is-fill { left: 0; background: var(--text-primary); }
.fan-tip-range .is-pace { left: 0; background: color-mix(in oklab, var(--text-primary) 22%, transparent); }
.fan-tip-range .is-pace.is-short { background: color-mix(in oklab, var(--loss) 45%, transparent); }
.fan-tip-scale { display: flex; justify-content: space-between; margin: -2px 0 6px; font-size: var(--fs-2xs); color: var(--text-tertiary); }
template.tip { display: none; }
/* The element whose card is open, where it has no hover look of its own. */
.fire-odds-cell.is-tipped, .sharebar-seg.is-tipped { outline: 2px solid var(--text-primary); outline-offset: 1px; position: relative; z-index: 1; }
@media (max-width: 640px) {
  .heat { min-width: calc(var(--weeks) * 15px + 30px); }
}
/* Day heat as a month calendar: weeks as rows, the day and its result in
   each cell; text on the two strongest grades turns to the card colour. */
.heat-cal-head, .heat-cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.heat-cal-head { margin-bottom: 6px; font-size: var(--fs-xs); color: var(--text-tertiary); }
.heat-cal-head span { padding-left: 8px; }
.heat-cal-head span:nth-child(n+6) { color: var(--text-faint, var(--text-tertiary)); }
.heat-day { aspect-ratio: auto; min-height: 64px; padding: 6px 8px; display: flex; flex-direction: column; justify-content: space-between; border-radius: var(--radius-sm); color: var(--text-secondary); text-decoration: none; font-variant-numeric: tabular-nums; }
.heat-day-n { font-size: var(--fs-xs); }
.heat-day-v { font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* A day without sales: what moved, in the quiet ink — it is not a result. */
.heat-day-v.is-quiet { font-weight: var(--fw-regular); color: var(--text-secondary); }
.heat-day.lv-g3, .heat-day.lv-g4, .heat-day.lv-l3, .heat-day.lv-l4 { color: var(--bg-card); }
.heat-day.lv-g3 .heat-day-v, .heat-day.lv-g4 .heat-day-v, .heat-day.lv-l3 .heat-day-v, .heat-day.lv-l4 .heat-day-v { color: var(--bg-card); }
.heat-day.is-future .heat-day-n { color: var(--text-tertiary); }
.heat-cal .heat-cell.has-income::after { right: 8px; bottom: auto; top: 8px; width: 6px; height: 6px; }
@media (max-width: 640px) {
  .heat-day { min-height: 48px; padding: 4px 5px; }
  .heat-day-v { font-size: 10px; }
  .heat-cal-head span { padding-left: 4px; }
  .heat-cal .heat-cell.has-income::after { right: 5px; top: 5px; width: 5px; height: 5px; }
}

/* Portfolio: a row of facts heading a card (trading by day, dividends). */
/* One line instead of a row of empty figures, while there is nothing to total. */
.heat-note { margin: calc(var(--sp-1) * -1) 0 var(--sp-4); font-size: var(--fs-sm); color: var(--text-secondary); max-width: 65ch; }
.heat-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: var(--sp-2) var(--sp-5); margin: calc(var(--sp-1) * -1) 0 var(--sp-5); }
.heat-fact { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: var(--sp-2) var(--sp-3); margin: 0 calc(var(--sp-3) * -1); border-radius: var(--radius-md); color: inherit; text-decoration: none; }
.heat-fact-label { display: inline-flex; align-items: center; gap: 2px; font-size: var(--fs-xs); color: var(--text-secondary); }
.heat-fact-label svg { width: 13px; height: 13px; color: var(--text-tertiary); }
.heat-fact b { font-size: var(--fs-xl); font-weight: var(--fw-semibold); letter-spacing: var(--tracking-tight); font-variant-numeric: tabular-nums; }
.heat-fact small { font-size: var(--fs-xs); color: var(--text-secondary); }
.heat-fact .heat-fact-unit { font-size: var(--fs-sm); font-weight: var(--fw-regular, 400); }
a.heat-fact.is-link:hover { background: var(--bg-secondary); }
a.heat-fact.is-link:hover .heat-fact-label svg { color: var(--accent-ink); }
/* Dividends: the chart and the coming record dates beside it. */
.div-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-5); }
@media (min-width: 1100px) { .div-layout { grid-template-columns: minmax(0, 1fr) 260px; } }
.div-next { min-width: 0; }
.div-next-title { display: flex; align-items: center; gap: 4px; margin: 0 0 var(--sp-2); font-size: var(--fs-sm); font-weight: var(--fw-semibold); }
.div-next-list { list-style: none; margin: 0; padding: 0; max-height: 360px; overflow-y: auto; }
.div-next-list li { display: grid; grid-template-columns: 76px minmax(0, 1fr) auto; gap: var(--sp-2); align-items: baseline; padding: 7px 0; border-top: 1px solid var(--border); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.div-next-list li.is-past { opacity: 0.5; }
.div-next-date { color: var(--text-secondary); font-size: var(--fs-xs); }
.div-next-sum { color: var(--profit); font-weight: var(--fw-semibold); }
.heat-cal .heat-cell { aspect-ratio: auto; }
.heat-cal .heat-cell.is-pad { min-height: 0; }
.heat-day-v .v-short { display: none; }
@media (max-width: 640px) { .heat-day-v .v-full { display: none; } .heat-day-v .v-short { display: inline; } }
@media (max-width: 640px) {
  .heat-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-1) var(--sp-3); }
  .heat-fact { padding: var(--sp-2); margin: 0 calc(var(--sp-2) * -1); }
  .heat-fact b { font-size: var(--fs-lg); }
}
/* The record dates run the full height of the block, from the figures down,
   and fade out at the bottom instead of cutting a row in half. */
.div-main { min-width: 0; }
.div-main .heat-facts { margin-top: 0; }
@media (min-width: 1100px) {
  .div-layout { align-items: stretch; }
  .div-next { display: flex; flex-direction: column; min-height: 0; padding-left: var(--sp-5); border-left: 1px solid var(--border); }
  .div-next-list { flex: 1 1 0; min-height: 0; max-height: none; }
}
.div-next-list { -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 32px), transparent); mask-image: linear-gradient(to bottom, #000 calc(100% - 32px), transparent); padding-bottom: 24px; }

/* Icons: one stroke across the platform. Lucide's default 2px read heavy at
   the 16–22px the interface uses; 1.75 matches the weight of the text. */
svg.lucide { stroke-width: 1.75; }
