/* Ported from reference/denis-finance/frontend/styles.css: tokens, dark theme, cards, pills, popovers, chart.
   Changed for stage 11: teal accent, income/expense series, better/worse deltas without red, darker muted text. */

:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page-plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #6f6d67;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --critical: #d03b3b;
  --status-warning: #fab219;

  --accent: #0f7a64;
  --accent-wash: rgba(15, 122, 100, 0.10);
  --on-accent: #ffffff;
  --income: #12876f;
  --expense: #5b50d6;
  --expense-soft: rgba(91, 80, 214, 0.55);
  --previous: #8a8880;
  --unaccounted: #8a8880;
  --better: #0f7a64;
  --worse: #a15c00;
  --amber-text: #8a5200;

  --tooltip-muted: rgba(255,255,255,0.62);
  --shadow-card: 0 1px 2px rgba(11,11,11,0.04), 0 1px 12px rgba(11,11,11,0.03);
  --skeleton-base: #ece9e2;
  --skeleton-shine: #f7f5f0;

  /* Type scale - 6 steps, nothing outside this list. */
  --fs-1: 12px;
  --fs-2: 14px;
  --fs-3: 16px;
  --fs-4: 20px;
  --fs-5: 28px;

  /* Spacing - 4px grid. */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;

  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-pill: 999px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page-plane: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #8e8c85;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --critical: #e66767;

    --accent: #2a9d8f;
    --accent-wash: rgba(42, 157, 143, 0.16);
    --on-accent: #0b0b0b;
    --income: #2a9d8f;
    --expense: #7068e0;
    --expense-soft: rgba(112, 104, 224, 0.55);
    --previous: #6f6d67;
    --unaccounted: #6f6d67;
    --better: #2a9d8f;
    --worse: #e3a03f;
    --amber-text: #e3a03f;

    --tooltip-muted: rgba(11,11,11,0.55);
    --shadow-card: 0 1px 2px rgba(0,0,0,0.3), 0 1px 16px rgba(0,0,0,0.25);
    --skeleton-base: #232322;
    --skeleton-shine: #2c2c2a;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page-plane: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #8e8c85;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --critical: #e66767;

  --accent: #2a9d8f;
  --accent-wash: rgba(42, 157, 143, 0.16);
  --on-accent: #0b0b0b;
  --income: #2a9d8f;
  --expense: #7068e0;
  --expense-soft: rgba(112, 104, 224, 0.55);
  --previous: #6f6d67;
  --unaccounted: #6f6d67;
  --better: #2a9d8f;
  --worse: #e3a03f;
  --amber-text: #e3a03f;

  --tooltip-muted: rgba(11,11,11,0.55);
  --shadow-card: 0 1px 2px rgba(0,0,0,0.3), 0 1px 16px rgba(0,0,0,0.25);
  --skeleton-base: #232322;
  --skeleton-shine: #2c2c2a;
}

* { box-sizing: border-box; }

/* Author rules like `.x { display: flex }` otherwise beat the UA [hidden] rule. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: var(--fs-2);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

.page {
  max-width: 1440px;
  margin: 0 auto;
  padding: var(--sp-4) var(--sp-4) var(--sp-6);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

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

/* ---------- Sticky control bar ---------- */

.control-bar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--page-plane);
  padding: var(--sp-3) 0 var(--sp-2);
  margin: 0 0 var(--sp-4);
  border-bottom: 1px solid var(--gridline);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: 0 var(--sp-1) var(--sp-3);
}
.topbar h1 { font-size: var(--fs-4); font-weight: 650; margin: 0; }
.topbar h1 span { font-weight: 400; color: var(--text-muted); margin-left: 6px; }
.brand-mark { display: inline-block; vertical-align: -5px; margin-right: var(--sp-2); border-radius: 6px; }
.topbar-meta { display: flex; align-items: center; justify-content: flex-end; gap: var(--sp-2); flex-wrap: wrap; }

.icon-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  cursor: pointer;
  flex: 0 0 auto;
}
.icon-btn:hover { color: var(--text-primary); background: var(--accent-wash); }
.icon-btn, .cmp-btn, .dp-cancel, .dp-apply, .more-btn, .cat-row {
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
}
.icon-btn.spinning svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Trust line, top right next to ⟳: how old the data is, the last reconciliation, open mismatches. */
.trust-line {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 2px var(--sp-2);
  margin-right: var(--sp-1);
  font-size: var(--fs-1); color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.trust-line .sep { color: var(--baseline); }
.trust-line .stale, .trust-line .open-mark { color: var(--amber-text); font-weight: 600; }
.trust-line .has-tip { cursor: help; border-bottom: 1px dashed var(--baseline); }

.error-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  background: color-mix(in srgb, var(--critical) 12%, var(--surface-1));
  border: 1px solid color-mix(in srgb, var(--critical) 35%, transparent);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-2);
  margin-bottom: var(--sp-4);
}
.error-retry {
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  border-radius: var(--radius-pill);
  padding: var(--sp-2) var(--sp-3);
  font: inherit;
  cursor: pointer;
  flex: 0 0 auto;
}

/* Warnings (a missing rate): visible, not hidden in a tooltip. */
.warn-strip {
  display: flex; align-items: center; gap: var(--sp-2);
  background: color-mix(in srgb, var(--status-warning) 14%, var(--surface-1));
  border: 1px solid color-mix(in srgb, var(--status-warning) 40%, transparent);
  border-radius: var(--radius-sm);
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-1);
  margin-bottom: var(--sp-3);
}
.warn-strip .warn-more { margin-left: auto; font-weight: 600; cursor: help; padding: 0 var(--sp-1); }

/* ---------- Range selector ---------- */

.range-row {
  display: flex;
  gap: var(--sp-2);
  overflow-x: auto;
  padding: var(--sp-1);
  scrollbar-width: thin;
}

.range-pill {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 7px var(--sp-4);
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.22s ease, color 0.22s ease, border-color 0.22s ease, transform 0.12s ease;
}
.range-pill:active { transform: scale(0.96); }
.range-pill:hover { background: var(--accent-wash); color: var(--text-primary); }
.range-pill.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.custom-pill { display: inline-flex; align-items: center; gap: 6px; }
.custom-pill svg { flex: 0 0 auto; }

.date-picker {
  position: absolute; z-index: 100;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: 0 8px 28px rgba(0,0,0,0.16);
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-1);
  animation: pop-in 0.18s ease-out;
}
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px); } }
.dp-fields { display: flex; align-items: flex-end; gap: var(--sp-2); }
.dp-fields label { display: flex; flex-direction: column; gap: var(--sp-1); color: var(--text-secondary); }
.dp-fields input {
  font: inherit; font-size: var(--fs-2); color: var(--text-primary);
  background: var(--page-plane); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 6px var(--sp-2);
}
.dp-dash { color: var(--text-muted); padding-bottom: 8px; }
.dp-error { color: var(--critical); margin-top: var(--sp-2); }
.dp-actions { display: flex; justify-content: flex-end; gap: var(--sp-2); margin-top: var(--sp-3); }
.dp-cancel, .dp-apply {
  font: inherit; font-size: var(--fs-1); padding: 6px var(--sp-3); border-radius: var(--radius-pill); cursor: pointer;
  border: 1px solid var(--border); background: transparent; color: var(--text-secondary);
}
.dp-apply { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }

/* ---------- Popover with details (hover on a mouse, tap on a phone) ---------- */

.tip-pop {
  position: absolute;
  z-index: 40;
  background: var(--text-primary);
  color: var(--surface-1);
  border-radius: var(--radius-sm);
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-1);
  line-height: 1.6;
  box-shadow: 0 4px 18px rgba(0,0,0,0.22);
  min-width: 200px;
  max-width: min(340px, calc(100vw - 16px));
  font-variant-numeric: tabular-nums;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s ease;
}
.tip-pop.visible { opacity: 1; }
.tip-pop .fm-row { display: flex; justify-content: space-between; gap: var(--sp-3); }
.tip-pop .fm-head { color: var(--tooltip-muted); margin-top: var(--sp-1); }
.tip-pop .fm-head:first-child { margin-top: 0; }
.tip-pop .fm-title { font-weight: 650; margin-bottom: var(--sp-1); }
.tip-pop .fm-note { color: var(--tooltip-muted); margin-top: var(--sp-2); white-space: normal; line-height: 1.4; }
.tip-pop .fm-note:first-child { margin-top: 0; }
.tip-pop .fm-row.muted { color: var(--tooltip-muted); }
.tip-pop .fm-row.total { font-weight: 650; border-top: 1px solid rgba(127,127,127,0.35); margin-top: 3px; padding-top: 3px; }
.has-tip { cursor: help; }

/* ---------- KPI ---------- */

.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
@media (max-width: 900px) { .kpi-row:not(.cf-kpi) { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-3) var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  min-width: 0;
}
.stat-tile.muted .stat-value { color: var(--text-secondary); }
.stat-tile.empty-tile { grid-column: 1 / -1; align-items: center; text-align: center; color: var(--text-secondary); padding: var(--sp-5); }

/* Centred big numbers, each read on its own. */
.kpi-row .stat-tile { padding: var(--sp-5) var(--sp-4) var(--sp-4); gap: var(--sp-2); align-items: center; text-align: center; }
.kpi-row .stat-value { font-size: 34px; letter-spacing: -0.02em; line-height: 1.1; }
.kpi-row .stat-label { font-size: var(--fs-2); }

.stat-label { font-size: var(--fs-1); color: var(--text-secondary); font-weight: 500; }
.stat-value {
  font-size: var(--fs-4);
  font-weight: 650;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.stat-value.has-tip { width: fit-content; border-bottom: 1px dashed var(--border); }
.stat-value.has-tip:hover { border-bottom-color: var(--accent); }
.stat-sub { font-size: var(--fs-1); color: var(--text-muted); overflow-wrap: anywhere; }
.stat-delta-row { display: inline-flex; align-items: center; gap: var(--sp-2); }

.stat-delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: var(--fs-1);
  font-weight: 600;
  padding: 2px 8px 2px 6px;
  border-radius: var(--radius-pill);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.stat-delta svg { width: 11px; height: 11px; }
/* The arrow says which way, the colour says whether that is good. Never red. */
.stat-delta.better { color: var(--better); background: color-mix(in srgb, var(--better) 14%, transparent); }
.stat-delta.worse { color: var(--worse); background: color-mix(in srgb, var(--worse) 16%, transparent); }
.stat-delta.flat { color: var(--text-muted); background: var(--gridline); }
.kpi-row .stat-delta { font-size: var(--fs-2); }
.kpi-row .stat-delta svg { width: 12px; height: 12px; }

/* ---------- skeleton ---------- */

.sk-line {
  height: 12px;
  border-radius: var(--radius-xs);
  background: linear-gradient(90deg, var(--skeleton-base) 25%, var(--skeleton-shine) 37%, var(--skeleton-base) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}
.stat-tile.skeleton { align-items: stretch !important; }
.sk-w60 { width: 60%; margin: 0 auto; }
.sk-w40 { width: 40%; margin: 0 auto; }
.sk-w80 { width: 80%; margin: 0 auto; }
.sk-tall { height: 26px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* ---------- Cards ---------- */

.cards-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--sp-4);
  align-items: start;
}
.side-col { display: flex; flex-direction: column; gap: var(--sp-4); min-width: 0; }
@media (max-width: 1000px) { .cards-row { grid-template-columns: minmax(0, 1fr); } }

.chart-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-4);
  min-width: 0;
}

.chart-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-3);
}
.chart-card-head > div { min-width: 0; }
.chart-card-head h2 { font-size: var(--fs-3); font-weight: 650; margin: 0 0 2px; }
.chart-sub { font-size: var(--fs-1); color: var(--text-muted); margin: 0; display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.head-total { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.head-total .stat-value { font-size: var(--fs-4); }

.legend { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.legend i { display: inline-block; width: 12px; height: 0; border-top: 2.5px solid; border-radius: 2px; }
.legend i.income { border-color: var(--income); }
.legend i.expense { border-color: var(--expense); }
.legend i.previous { border-top: 2px dashed var(--previous); }

/* Segmented control: an accent thumb slides under the chosen option. */
.compare-toggle {
  --cmp-index: 0;
  position: relative;
  display: grid; grid-template-columns: 1fr 1fr; flex: 0 0 auto;
  padding: 2px;
  border: 1px solid var(--border); border-radius: var(--radius-pill); background: var(--page-plane);
}
.cmp-thumb {
  position: absolute; top: 2px; bottom: 2px; left: 2px;
  width: calc((100% - 4px) / 2);
  border-radius: var(--radius-pill);
  background: var(--accent);
  transform: translateX(calc(var(--cmp-index) * 100%));
  transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1);
}
.cmp-btn {
  position: relative; z-index: 1;
  font: inherit; font-size: var(--fs-1); font-weight: 600;
  min-width: 48px; padding: 4px var(--sp-3); border: none; border-radius: var(--radius-pill);
  background: transparent; color: var(--text-secondary); cursor: pointer;
}
.cmp-btn.active { color: var(--on-accent); cursor: default; }

/* ---------- Categories (HTML bars, % widths) ---------- */

.cat-list { display: flex; flex-direction: column; }
.cat-row {
  display: grid;
  grid-template-columns: minmax(0, 190px) minmax(60px, 1fr) 96px 44px;
  grid-template-areas: "label track value share";
  align-items: center;
  column-gap: var(--sp-3);
  padding: 6px var(--sp-1);
  border-radius: var(--radius-sm);
  cursor: help;
}
.cat-row:hover { background: var(--accent-wash); }
.cat-name { grid-area: label; display: flex; align-items: center; gap: 6px; min-width: 0; font-size: var(--fs-2); }
.cat-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-name svg { flex: 0 0 auto; color: var(--text-muted); }
.cat-track { grid-area: track; position: relative; height: 10px; background: var(--gridline); border-radius: var(--radius-pill); }
.cat-bar { position: absolute; left: 0; top: 0; bottom: 0; background: var(--expense-soft); border-radius: var(--radius-pill); min-width: 2px; }
.cat-row.fixed .cat-bar { background: var(--expense); }
.cat-row.unaccounted .cat-bar {
  background: repeating-linear-gradient(135deg, var(--unaccounted) 0 3px, transparent 3px 6px);
  box-shadow: inset 0 0 0 1px var(--unaccounted);
}
.cat-row.negative .cat-bar { display: none; }
/* Where the previous period was: a thin tick on the track. */
.cat-prev { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--text-muted); border-radius: 1px; }
.cat-value { grid-area: value; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cat-share { grid-area: share; text-align: right; font-size: var(--fs-1); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.more-btn {
  display: none;
  margin: var(--sp-2) auto 0; padding: var(--sp-2) var(--sp-4); min-height: 40px;
  border: 1px solid var(--border); border-radius: var(--radius-pill); background: transparent;
  color: var(--text-secondary); font: inherit; cursor: pointer;
}

/* ---------- Accounts ---------- */

.acc-list { display: flex; flex-direction: column; }
.acc-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-1); border-top: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
}
.acc-row:first-child { border-top: none; }
.acc-name { font-size: var(--fs-2); }
.acc-balance { text-align: right; font-weight: 600; white-space: nowrap; }
.acc-base { grid-column: 2; text-align: right; font-size: var(--fs-1); color: var(--text-muted); white-space: nowrap; }
.acc-open { grid-column: 1 / -1; font-size: var(--fs-1); color: var(--amber-text); cursor: help; width: fit-content; }

/* ---------- Chart ---------- */

.chart-body { position: relative; width: 100%; height: 280px; }
.chart-body.short { height: 180px; }
.chart-body svg { display: block; position: absolute; top: 0; left: 0; }

.axis-text { fill: var(--text-muted); font-size: 11px; }
.grid-line { stroke: var(--gridline); stroke-width: 1; }
.baseline-line { stroke: var(--baseline); stroke-width: 1; }
.area-fill { fill: url(#area-grad); }
.line-path { fill: none; stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.line-path.income { stroke: var(--income); }
.line-path.expense { stroke: var(--expense); }
.line-path.previous { stroke: var(--previous); stroke-width: 1.75; stroke-dasharray: 5 4; }
.line-path.partial { stroke-dasharray: 4 4; }
.end-dot { stroke: var(--surface-1); stroke-width: 2; }
.end-dot.income { fill: var(--income); }
.end-dot.expense { fill: var(--expense); }
.crosshair-line { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0; pointer-events: none; }
.hover-dot { stroke: var(--surface-1); stroke-width: 2; opacity: 0; pointer-events: none; }
.hover-dot.income { fill: var(--income); }
.hover-dot.expense { fill: var(--expense); }
.ghost-dot { fill: var(--surface-1); stroke: var(--previous); stroke-width: 2; stroke-dasharray: 2 2; opacity: 0; pointer-events: none; }

.viz-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--text-primary);
  color: var(--surface-1);
  border-radius: var(--radius-sm);
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-1);
  line-height: 1.5;
  box-shadow: 0 4px 18px rgba(0,0,0,0.22);
  opacity: 0;
  transform: translate(-50%, -100%);
  transition: opacity 0.15s ease;
  white-space: nowrap;
  z-index: 20;
  font-variant-numeric: tabular-nums;
}
.viz-tooltip.visible { opacity: 1; }
.viz-tooltip .tt-title { font-weight: 650; margin-bottom: 2px; }
.viz-tooltip .tt-row { display: flex; align-items: center; gap: 6px; }
.viz-tooltip .tt-key { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.viz-tooltip .tt-key.income { background: var(--income); }
.viz-tooltip .tt-key.expense { background: var(--expense); }
.viz-tooltip .tt-key.ghost { background: transparent; border: 1.5px dashed var(--tooltip-muted); }
.viz-tooltip .tt-val { margin-left: auto; padding-left: var(--sp-4); font-weight: 600; }
.viz-tooltip .tt-muted { color: var(--tooltip-muted); }

.empty-state { color: var(--text-muted); font-size: var(--fs-2); padding: var(--sp-5) 0; text-align: center; }

/* ---------- motion: data changes ease in instead of snapping ---------- */

#chart-body, #cat-list, #kpi-row, #acc-list { transition: opacity 0.4s ease; }
.chart-enter .series { animation: series-reveal 1.5s cubic-bezier(0.4, 0, 0.2, 1) both; }
.chart-enter .grid-line, .chart-enter .axis-text { animation: soft-in 0.8s ease both; }
.chart-enter .end-dot { animation: soft-in 0.45s ease 1.35s both; }
@keyframes series-reveal { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes soft-in { from { opacity: 0; } to { opacity: 1; } }

.cat-bar { transition: width 1.1s cubic-bezier(0.25, 0.8, 0.25, 1); }
.cat-row.enter { animation: row-in 0.7s ease both; }
@keyframes row-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- Tabs: «Обзор» and «Cashflow» (stage 13.3) ---------- */

.view-row { display: flex; padding: 0 var(--sp-1) var(--sp-2); }
.tab-toggle .cmp-btn { min-width: 96px; font-size: var(--fs-2); padding: 6px var(--sp-4); }
.tab-toggle .cmp-btn:not(.active):hover { color: var(--text-primary); }
.cf-view { transition: opacity 0.4s ease; }
.cf-view > * + * { margin-top: var(--sp-4); }
.cf-view .cards-row { margin-top: var(--sp-4); }

.cf-kpi { grid-template-columns: repeat(3, minmax(0, 1fr)); }

/* A meter: one hue on the track, never a status colour. */
.cf-meter { width: min(220px, 100%); height: 8px; border-radius: var(--radius-pill); background: var(--gridline); overflow: hidden; }
.cf-meter i { display: block; height: 100%; background: var(--accent); border-radius: var(--radius-pill); transition: width 1.1s cubic-bezier(0.25, 0.8, 0.25, 1); }
.cf-meter.thin { width: 100%; height: 6px; }

/* ---------- Debt screen ---------- */

.debt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--sp-3); }
.debt-card {
  border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--page-plane);
  padding: var(--sp-3) var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-2); min-width: 0;
}
.debt-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-2); }
.debt-name { font-weight: 650; font-size: var(--fs-3); min-width: 0; overflow-wrap: anywhere; }
.debt-rate { font-size: var(--fs-1); color: var(--text-secondary); white-space: nowrap; border-bottom: 1px dashed var(--baseline); }
.debt-left { display: flex; align-items: baseline; gap: var(--sp-2); flex-wrap: wrap; }
.debt-left .stat-value { font-size: var(--fs-5); letter-spacing: -0.02em; }
.debt-base, .debt-paid { font-size: var(--fs-1); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.debt-facts { margin: 0; display: flex; flex-direction: column; gap: 2px; }
.debt-fact { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: var(--sp-2); font-size: var(--fs-2); }
.debt-fact dt { color: var(--text-muted); }
.debt-fact dd { margin: 0; font-variant-numeric: tabular-nums; }
.debt-close dd { font-weight: 600; width: fit-content; }
.debt-extra { border-top: 1px solid var(--gridline); padding-top: var(--sp-2); }
.debt-extra-head { font-size: var(--fs-1); color: var(--text-secondary); font-weight: 600; margin-bottom: var(--sp-1); }
.debt-extra ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.debt-extra li { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: var(--sp-2); font-size: var(--fs-1); font-variant-numeric: tabular-nums; }
.debt-extra li b { font-weight: 600; color: var(--text-primary); white-space: nowrap; }
.debt-extra li span { color: var(--text-secondary); }

.strategies { margin-top: var(--sp-4); border-top: 1px solid var(--gridline); padding-top: var(--sp-3); }
.strategy-head h3 { font-size: var(--fs-2); font-weight: 650; margin: 0 0 var(--sp-3); width: fit-content; }
.strategy-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); }
.strategy { border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--sp-3); display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.strategy.best { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.strategy-title { font-weight: 650; display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.strategy-badge { font-size: var(--fs-1); font-weight: 600; color: var(--better); background: color-mix(in srgb, var(--better) 14%, transparent); border-radius: var(--radius-pill); padding: 1px 8px; }
.strategy-hint { font-size: var(--fs-1); color: var(--text-muted); }
.strategy-row { display: flex; justify-content: space-between; gap: var(--sp-2); font-size: var(--fs-2); font-variant-numeric: tabular-nums; }
.strategy-row span { color: var(--text-secondary); }
.strategy-order { margin: var(--sp-1) 0 0; padding-left: 18px; font-size: var(--fs-1); color: var(--text-secondary); }

/* ---------- Player card: the month, plan against fact ---------- */

.cf-month { display: flex; flex-direction: column; font-variant-numeric: tabular-nums; }
.cf-line { display: grid; grid-template-columns: minmax(0, 1fr) 96px 96px; column-gap: var(--sp-3); align-items: baseline; padding: 5px var(--sp-1); border-radius: var(--radius-sm); }
.cf-line:hover:not(.head) { background: var(--accent-wash); }
.cf-line.head { font-size: var(--fs-1); color: var(--text-muted); padding-bottom: 0; }
.cf-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cf-name em { font-style: normal; font-size: var(--fs-1); color: var(--accent); }
.cf-num { text-align: right; white-space: nowrap; color: var(--text-secondary); }
.cf-num.has-tip { width: auto; justify-self: end; border-bottom: 1px dashed var(--border); }
.cf-num.fact { color: var(--text-primary); font-weight: 600; }
.cf-line.total { border-top: 1px solid var(--gridline); border-radius: 0; font-weight: 650; }
.cf-line.total .cf-num { color: var(--text-primary); }
.cf-line.flow { border-top: 2px solid var(--baseline); font-size: var(--fs-3); }
.cf-group { font-size: var(--fs-1); font-weight: 650; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; margin: var(--sp-3) var(--sp-1) 2px; }
.cf-expense.collapsed .cf-line.extra { display: none; }
.cf-more { display: block; margin: var(--sp-1) auto var(--sp-2); }

/* ---------- Phones (iPhone SE 375 … Pro Max 430) ---------- */

@media (max-width: 640px) {
  .page { padding: var(--sp-3) var(--sp-4) var(--sp-5); }

  /* The header scrolls away: a sticky bar would eat a third of the screen. */
  .control-bar { position: static; margin-bottom: var(--sp-3); padding-top: var(--sp-1); }
  /* Row 1: title | buttons. Row 2: «загружено · сверка». */
  .topbar { flex-wrap: wrap; row-gap: var(--sp-1); padding-bottom: var(--sp-2); }
  .topbar h1 { font-size: var(--fs-3); flex: 1 1 auto; }
  .topbar-meta { display: contents; }
  .topbar-meta .trust-line { order: 3; flex-basis: 100%; justify-content: flex-start; margin-right: 0; }

  .range-row {
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
    margin: 0 calc(-1 * var(--sp-4)); padding: var(--sp-1) var(--sp-4);
  }
  .range-row::-webkit-scrollbar { display: none; }
  .range-pill { min-height: 40px; padding: 8px var(--sp-3); }

  .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-2); margin-bottom: var(--sp-3); }
  .cf-kpi { grid-template-columns: minmax(0, 1fr); }
  .cf-kpi .stat-value { font-size: 26px; }
  .view-row { padding-bottom: var(--sp-1); }
  .debt-grid { grid-template-columns: minmax(0, 1fr); }
  .strategy-grid { grid-template-columns: minmax(0, 1fr); }
  .cf-line { grid-template-columns: minmax(0, 1fr) 84px 84px; column-gap: var(--sp-2); font-size: var(--fs-1); }
  .cf-line.flow { font-size: var(--fs-2); }
  .kpi-row .stat-tile { padding: var(--sp-3) var(--sp-2); gap: var(--sp-1); }
  .kpi-row .stat-label { font-size: var(--fs-1); }
  .kpi-row .stat-value { font-size: 22px; }
  .kpi-row .stat-delta { font-size: var(--fs-1); }
  .kpi-row .stat-sub { font-size: 11px; line-height: 1.3; }

  .cards-row, .side-col { gap: var(--sp-3); }
  .chart-card { padding: var(--sp-3); }
  .chart-card-head h2 { font-size: var(--fs-2); }
  .chart-body { height: 220px; }
  .chart-body.short { height: 160px; }

  .cat-row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "label value" "track track";
    row-gap: 5px;
    padding: 7px var(--sp-1);
  }
  .cat-share { display: none; }
  .cat-track { height: 8px; }
  .cat-list.collapsed .cat-row.extra { display: none; }
  .cat-list.collapsed ~ .more-btn { display: block; }

  .tip-pop { max-width: calc(100vw - 16px); }
  .date-picker { padding: var(--sp-3); }
  .dp-fields input { font-size: var(--fs-3); } /* 16px stops iOS zooming in */
}

@media (max-width: 390px) {
  .kpi-row .stat-value { font-size: 20px; }
  .dp-fields input { width: 132px; }
}

/* ---------- Login page (from denis-finance; teal accent, title like the topbar) ---------- */

.login-body { min-height: 100vh; }
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
}
.login-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: var(--sp-6) var(--sp-5) var(--sp-5);
}
.login-title { font-size: var(--fs-4); font-weight: 650; margin: 0 0 var(--sp-2); }
.login-title span { font-weight: 400; color: var(--text-muted); margin-left: 6px; }

.login-field { display: flex; flex-direction: column; gap: 6px; }
.login-label { font-size: var(--fs-1); font-weight: 600; color: var(--text-secondary); }
.login-field input {
  width: 100%;
  height: 40px;
  padding: 0 var(--sp-3);
  font: inherit;
  font-size: var(--fs-3);
  color: var(--text-primary);
  background: var(--page-plane);
  border: 1px solid var(--baseline);
  border-radius: var(--radius-sm);
}
.login-field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.login-field input[aria-invalid="true"] { border-color: var(--critical); }

.login-password { position: relative; display: block; }
.login-password input { padding-right: 44px; }
.login-reveal {
  position: absolute;
  top: 4px; right: 4px;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-xs);
  cursor: pointer;
}
.login-reveal:hover, .login-reveal[aria-pressed="true"] { color: var(--text-primary); }

.login-error { margin: 0; font-size: var(--fs-2); color: var(--critical); }

.login-submit {
  height: 40px;
  margin-top: var(--sp-1);
  font: inherit;
  font-size: var(--fs-2);
  font-weight: 600;
  color: var(--on-accent);
  background: var(--accent);
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.login-submit:hover:not(:disabled) { filter: brightness(1.08); }
.login-submit:disabled { opacity: 0.6; cursor: default; }
.login-hint { margin: 0; font-size: var(--fs-1); color: var(--text-muted); text-align: center; }
