/* ---- Design tokens ---------------------------------------------------- */
:root {
  /* Cool navy, not neutral gray — every surface below is mixed from this hue
     family so dark and light stay a matched pair instead of two unrelated
     palettes. */
  --bg: #080b13;
  --bg-grad-1: #0f1526a0;
  --bg-grad-2: #080b1300;
  --panel: rgba(15, 20, 32, 0.66);
  --panel-solid: #10141f;
  --panel-strong: rgba(17, 22, 35, 0.86);
  --text: #eef1f8;
  --muted: #7c86a0;
  --border: rgba(148, 163, 196, 0.14);
  --gridline: #232a3d;

  /* categorical series (fixed order — see dataviz skill palette.md) */
  --series-1: #4c9eff; /* blue */
  --series-2: #f0985a; /* orange */
  --series-3: #22c3a6; /* aqua */
  --series-4: #e0b23f; /* yellow */
  --series-5: #e0699b; /* magenta */
  --series-6: #34d399; /* green */
  --series-7: #a78bfa; /* violet */
  --series-8: #f2685f; /* red */
  --series-other: #7c86a0;

  /* status (fixed — never themed, same hex both modes) */
  --status-good: #34d399;
  --status-warning: #f0b429;
  --status-serious: #f0985a;
  --status-critical: #f2685f;

  --accent: var(--series-1);
  --accent-purple: var(--series-7);
  --over: var(--status-critical);
  --under: var(--status-good);

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  --font-mono: "SF Mono", "Cascadia Code", "Consolas", "Roboto Mono", ui-monospace, monospace;

  --radius: 18px;
  --blur: 18px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f5fa;
    --bg-grad-1: #ffffffb0;
    --bg-grad-2: #f3f5fa00;
    --panel: rgba(255, 255, 255, 0.62);
    --panel-solid: #ffffff;
    --panel-strong: rgba(255, 255, 255, 0.84);
    --text: #131a2c;
    --muted: #5b6478;
    --border: rgba(19, 26, 44, 0.09);
    --gridline: #e2e6f0;

    --series-1: #2f7de0;
    --series-2: #d97a3a;
    --series-3: #0f9d84;
    --series-4: #b8860f;
    --series-5: #c94f81;
    --series-6: #199e70;
    --series-7: #7c5cd6;
    --series-8: #d94b42;
    --series-other: #5b6478;

    --status-good: #199e70;
    --status-warning: #b8860f;
    --status-serious: #d97a3a;
    --status-critical: #d94b42;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  background:
    radial-gradient(1100px 620px at 12% -8%, var(--bg-grad-1), var(--bg-grad-2) 60%),
    radial-gradient(900px 520px at 100% 0%, color-mix(in srgb, var(--series-1) 14%, transparent), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}

/* Financial figures line up on their digits wherever they appear — table
   cells, stat values, chart tooltips — so a column of numbers reads as a
   column, not a ragged edge. */
.num, .stat-value, td.num, th.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---- Glass utility ------------------------------------------------------ */
.card, table, .report-body, fieldset {
  background: var(--panel);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.16);
}

.card { padding: 1.25rem 1.5rem; margin-bottom: 1.25rem; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }

nav {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.6rem 0.7rem 0.6rem 1rem;
  margin: 1rem;
  background: var(--panel-strong);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.16);
  position: sticky;
  top: 1rem;
  z-index: 10;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 0.55rem; margin-right: 0.3rem; }
.brand-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--series-1), var(--series-6));
  color: #06131a;
  flex: none;
}
.brand-icon svg { width: 17px; height: 17px; }
.brand-name { font-weight: 700; font-size: 0.98rem; letter-spacing: -0.01em; white-space: nowrap; }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.28rem 0.65rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
  margin-right: 0.3rem;
}
.status-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.status-badge.good { background: color-mix(in srgb, var(--status-good) 16%, var(--panel-strong)); color: var(--status-good); }
.status-badge.warning { background: color-mix(in srgb, var(--status-warning) 16%, var(--panel-strong)); color: var(--status-warning); }
.status-badge.critical { background: color-mix(in srgb, var(--status-critical) 16%, var(--panel-strong)); color: var(--status-critical); }
.status-badge.unknown { background: color-mix(in srgb, var(--muted) 16%, var(--panel-strong)); color: var(--muted); }

.nav-links { display: flex; align-items: center; gap: 0.15rem; flex-wrap: wrap; }

nav a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.87rem;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  transition: color 0.15s ease, background 0.15s ease;
}

nav a:hover { color: var(--text); }
nav a.active { color: var(--text); background: var(--panel-solid); }

main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 1.5rem 3rem;
}

h1 { margin: 0.5rem 0 1.25rem; font-size: 1.6rem; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; letter-spacing: -0.01em; }

/* ---- Tables -------------------------------------------------------------- */
.table-scroll { overflow-x: auto; border-radius: var(--radius); }

table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
}

th, td {
  text-align: left;
  padding: 0.55rem 0.9rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr:last-child td { border-bottom: none; }
tfoot th { border-top: 1px solid var(--border); border-bottom: none; }

tr.over td:last-child { color: var(--status-critical); font-weight: 600; }
tr.under td:last-child { color: var(--status-good); }

/* ---- Forms & buttons ------------------------------------------------------ */
.inline-form { display: inline-block; margin: 0 0.25rem 0.25rem 0; }
.nowrap { white-space: nowrap; }

input, select, button {
  font: inherit;
  font-size: 0.92rem;
  padding: 0.4rem 0.65rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-strong);
  color: var(--text);
}

input:focus, select:focus, button:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent);
  outline-offset: 1px;
}

button {
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
  font-weight: 600;
  transition: opacity 0.15s ease, transform 0.05s ease;
}

button:hover { opacity: 0.88; }
button:active { transform: scale(0.98); }
button:disabled { opacity: 0.5; cursor: default; }

.btn-green { background: var(--status-good); }
.btn-red { background: var(--status-critical); }
.btn-ghost { background: var(--panel-strong); color: var(--text); }

.muted { color: var(--muted); }

fieldset { padding: 1rem 1.25rem; margin-bottom: 1rem; }

/* ---- Login page ------------------------------------------------------------ */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.login-card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: 2rem 1.75rem;
}
.login-title { margin: 0; font-size: 1.3rem; letter-spacing: -0.01em; text-align: center; }
.login-subtitle { margin: -0.5rem 0 0.3rem; text-align: center; font-size: 0.88rem; }
.login-field { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--muted); }
.login-field input { width: 100%; }
.login-card button[type="submit"] { width: 100%; padding: 0.55rem; margin-top: 0.2rem; }

/* Google's official "Sign in with Google" button spec (Identity Services
   branding guidelines): fixed white/neutral chrome regardless of site
   theme — the button's job is to be an unmistakable, trusted Google
   affordance, not blend into the page — with the logo kept in its
   official colors. Selector specificity matches the button[type="submit"]
   rule above (same class+type+class shape) so this wins on the shared
   width/padding properties by source order rather than needing !important. */
.login-card button.google-signin-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  height: 40px;
  padding: 0 12px;
  margin-top: 0.2rem;
  background: #fff;
  color: #1f1f1f;
  border: 1px solid #747775;
  border-radius: 8px;
  font-family: "Roboto", var(--font-ui);
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: 0.15px;
  transition: box-shadow 0.15s ease, background 0.15s ease;
}
.login-card button.google-signin-btn:hover {
  background: #f8f9fa;
  opacity: 1;
  box-shadow: 0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
}
.login-card button.google-signin-btn:active {
  background: #f1f3f4;
  transform: none;
}
.login-card button.google-signin-btn:focus-visible {
  outline: 2px solid #4285f4;
  outline-offset: 2px;
}
.google-signin-btn__logo { width: 18px; height: 18px; flex-shrink: 0; }
.login-error {
  margin: 0;
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  background: color-mix(in srgb, var(--status-critical) 14%, var(--panel-strong));
  color: var(--status-critical);
  font-size: 0.85rem;
}
.login-forgot { margin: 0.4rem 0 0; font-size: 0.78rem; text-align: center; line-height: 1.5; }

/* ---- Stat tiles ------------------------------------------------------------ */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.stat-tile { padding: 1.1rem 1.25rem; position: relative; }
.stat-label {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  max-width: calc(100% - 40px);
}
.stat-value { font-size: 1.7rem; font-weight: 650; margin: 0.3rem 0 0.35rem; letter-spacing: -0.01em; }
.stat-delta { font-size: 0.85rem; font-weight: 600; display: flex; align-items: center; gap: 0.3rem; }
.stat-delta.good { color: var(--status-good); }
.stat-delta.bad { color: var(--status-critical); }
.stat-delta.neutral { color: var(--muted); }
.stat-delta::before { font-size: 0.75rem; }
.stat-delta.good::before { content: "↗"; }
.stat-delta.bad::before { content: "↘"; }
.stat-value.good { color: var(--status-good); }
.stat-value.bad { color: var(--status-critical); }
.stat-value.warning { color: var(--status-warning); }

.stat-icon {
  position: absolute;
  top: 1.1rem;
  right: 1.1rem;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  color: var(--muted);
}
.stat-icon svg { width: 15px; height: 15px; }
.stat-icon.good { color: var(--status-good); }
.stat-icon.bad { color: var(--status-critical); }
.stat-icon.accent { color: var(--accent); }

.mask-toggle-btn {
  position: absolute;
  top: 1.1rem;
  right: 2.6rem;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  color: var(--muted);
}
.mask-toggle-btn:hover { opacity: 1; background: var(--panel-strong); }
.mask-toggle-btn:active { transform: none; }
.mask-toggle-btn svg { width: 15px; height: 15px; }
.mask-toggle-btn[aria-pressed="true"] { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }

/* ---- Interactive tour -------------------------------------------------- */
/* Giant box-shadow spotlight: the "hole" is just this box's own bounds, and
   the shadow's 9999px spread covers the rest of the viewport in one shape
   with a smooth cut-out, updated by JS as top/left/width/height (transition
   keeps step-to-step movement in Doherty-Threshold-friendly reach — fast
   enough to feel responsive, not so instant it feels like a jump-cut). */
.tour-overlay {
  position: fixed;
  border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(3, 6, 14, 0.72);
  z-index: 9998;
  pointer-events: none;
  transition: top 0.25s ease, left 0.25s ease, width 0.25s ease, height 0.25s ease;
}
.tour-overlay--full { top: 0 !important; left: 0 !important; width: 100vw !important; height: 100vh !important; border-radius: 0; }

.tour-tooltip {
  position: fixed;
  z-index: 9999;
  width: min(320px, calc(100vw - 32px));
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  transition: top 0.25s ease, left 0.25s ease;
  font-family: var(--font-ui);
  color: var(--text);
}
/* Law of Proximity: progress, title, body, and actions sit in one tightly
   spaced stack so the whole tooltip reads as a single grouped unit. */
.tour-progress { display: flex; gap: 5px; margin-bottom: 0.8rem; }
.tour-dot { width: 6px; height: 6px; border-radius: 999px; background: var(--border); transition: width 0.2s ease, background 0.2s ease; }
.tour-dot.active { width: 16px; border-radius: 3px; background: var(--accent); }
.tour-dot.done { background: color-mix(in srgb, var(--accent) 55%, var(--border)); }
.tour-title { margin: 0 0 0.35rem; font-size: 1rem; }
.tour-text { margin: 0 0 1.1rem; font-size: 0.86rem; color: var(--muted); line-height: 1.55; }
.tour-actions { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
/* Fitts's Law: Next/Back get the same generous, familiar button sizing as
   every other primary/secondary button in the app -- not shrunk to fit. */
.tour-skip { background: none; border: none; box-shadow: none; color: var(--muted); font-weight: 500; font-size: 0.82rem; padding: 0.4rem 0.3rem; }
.tour-skip:hover { color: var(--text); opacity: 1; }
.tour-nav { display: flex; gap: 0.5rem; }
.tour-nav button { padding: 0.5rem 0.9rem; }

.sparkline { display: flex; align-items: flex-end; gap: 3px; height: 28px; margin-top: 0.6rem; }
.sparkline .bar { flex: 1; background: var(--muted); opacity: 0.45; border-radius: 2px 2px 0 0; min-height: 3px; }
.sparkline .bar.current { background: var(--accent); opacity: 1; }

.meter-track {
  height: 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 16%, var(--panel-strong));
  overflow: hidden;
  margin-top: 0.5rem;
}
.meter-fill { height: 100%; border-radius: 999px; background: var(--accent); transition: width 0.3s ease; }
.meter-fill.warning { background: var(--status-warning); }
.meter-fill.critical { background: var(--status-critical); }

/* ---- Bar charts (server-rendered, div-based) ------------------------------- */
.chart-legend { display: flex; gap: 1.1rem; flex-wrap: wrap; margin-bottom: 0.9rem; font-size: 0.85rem; color: var(--muted); }
.chart-legend .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 0.4rem; vertical-align: middle; }

.bar-chart { display: flex; flex-direction: column; gap: 0.55rem; }
.bar-row { display: grid; grid-template-columns: minmax(110px, 160px) 1fr; align-items: center; gap: 0.75rem; }
.bar-row-label { font-size: 0.85rem; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-tracks { display: flex; flex-direction: column; gap: 3px; }
.bar-track { height: 12px; border-radius: 999px; background: color-mix(in srgb, var(--text) 6%, transparent); position: relative; }
.bar-fill {
  height: 100%;
  border-radius: 999px 4px 4px 999px;
  min-width: 3px;
}
.bar-fill.series-1 { background: var(--series-1); }
.bar-fill.series-2 { background: var(--series-2); }
.bar-fill.good { background: var(--status-good); }
.bar-fill.critical { background: var(--status-critical); }

/* part-to-whole stacked bar */
.stack-bar { display: flex; height: 28px; border-radius: 8px; overflow: hidden; background: color-mix(in srgb, var(--text) 6%, transparent); }
.stack-seg { display: flex; align-items: center; justify-content: center; min-width: 2px; border-right: 2px solid var(--panel-solid); font-size: 0.72rem; font-weight: 600; color: white; overflow: hidden; white-space: nowrap; }
.stack-seg:last-child { border-right: none; }

.slot-1 { background: var(--series-1); }
.slot-2 { background: var(--series-2); }
.slot-3 { background: var(--series-3); }
.slot-4 { background: var(--series-4); }
.slot-5 { background: var(--series-5); }
.slot-6 { background: var(--series-6); }
.slot-7 { background: var(--series-7); }
.slot-8 { background: var(--series-8); }
.slot-other { background: var(--series-other); }

.empty-state { color: var(--muted); font-size: 0.9rem; padding: 0.5rem 0; }

/* ---- Dashboard two-column layout ------------------------------------------- */
.dash-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 1.25rem; align-items: start; }
.dash-main, .dash-side { min-width: 0; }
@media (max-width: 900px) {
  .dash-grid { grid-template-columns: 1fr; }
}

/* ---- Budget limits list ------------------------------------------------------ */
.limit-row { padding: 0.85rem 0; border-bottom: 1px solid var(--border); }
.limit-row:last-child { border-bottom: none; padding-bottom: 0; }
.limit-row:first-child { padding-top: 0; }
.limit-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.25rem; }
.limit-name { font-weight: 600; font-size: 0.92rem; }
.limit-amount { font-weight: 650; }
.limit-sub { display: flex; align-items: baseline; justify-content: space-between; gap: 0.75rem; font-size: 0.78rem; color: var(--muted); margin-bottom: 0.45rem; }
.limit-sub .used { font-weight: 600; }
.limit-sub .used.over { color: var(--status-critical); }
.limit-sub .used.under { color: var(--status-good); }
.limit-track { height: 7px; border-radius: 999px; background: color-mix(in srgb, var(--text) 6%, transparent); overflow: hidden; }
.limit-fill { height: 100%; border-radius: 999px; background: var(--status-good); }
.limit-fill.over { background: var(--status-critical); }

/* ---- Recent activity table -------------------------------------------------- */
.activity-desc { font-weight: 500; }
.pill {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  font-size: 0.76rem;
  color: var(--muted);
  white-space: nowrap;
}
.source-tag { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }
.amount.good { color: var(--status-good); font-weight: 650; }
.amount.bad { color: var(--status-critical); font-weight: 650; }

/* ---- Donut chart (category breakdown) ---------------------------------------- */
.donut-wrap { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.donut {
  width: 132px;
  height: 132px;
  border-radius: 50%;
  flex: none;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.donut-hole {
  position: absolute;
  inset: 20px;
  border-radius: 50%;
  background: var(--panel-solid);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.donut-hole-label { font-size: 0.62rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700; }
.donut-hole-value { font-size: 1rem; font-weight: 650; margin-top: 0.15rem; }
.donut-legend { display: flex; flex-direction: column; gap: 0.5rem; font-size: 0.85rem; flex: 1; min-width: 140px; }
.donut-legend-row { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; }
.donut-legend-row .label { display: flex; align-items: center; gap: 0.5rem; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donut-legend-row .pct { color: var(--muted); font-weight: 600; flex: none; }

/* ---- AI report card ----------------------------------------------------------- */
.ai-card-head { display: flex; align-items: center; gap: 0.7rem; margin-bottom: 0.9rem; }
.ai-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--accent-purple) 22%, var(--panel-strong));
  color: var(--accent-purple);
}
.ai-icon svg { width: 17px; height: 17px; }
.ai-card-title { font-weight: 650; font-size: 0.95rem; }
.ai-card-subtitle { font-size: 0.76rem; color: var(--muted); }
.insights-list { margin: 0; padding-left: 1.1rem; font-size: 0.88rem; line-height: 1.6; }
.insights-list li { margin-bottom: 0.55rem; }
.insights-list li:last-child { margin-bottom: 0; }


/* Inline calculator, used on the budgets page */
.calc { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.calc-input { width: 92px; }
.calc-hint { font-size: 0.72rem; color: var(--muted); min-width: 3.5ch; }
.calc-ops { display: flex; gap: 0.2rem; }
.calc-btn {
  width: 26px;
  height: 26px;
  padding: 0;
  font-size: 0.85rem;
  line-height: 1;
  border-radius: 6px;
}
.calc-eq { background: var(--status-good); }
.calc-clear { background: var(--status-critical); }

/* ---- AI insights card ------------------------------------------------------ */
.insights-list { list-style: none; margin: 0.75rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.6rem; }
.insights-list li {
  padding: 0.65rem 0.9rem;
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 10%, var(--panel-strong));
  border: 1px solid var(--border);
  font-size: 0.9rem;
}
.insights-status { font-size: 0.85rem; color: var(--muted); margin-top: 0.6rem; }
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -2px;
  margin-right: 0.4rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Toasts ----------------------------------------------------------------
   Site-wide feedback for every Save/Add/Delete action. #toast-stack lives in
   base.html so every page gets it for free. A form submit shows "processing"
   immediately (see base.html script) and stays up for as long as the actual
   page navigation takes — no AJAX rewrite needed, since the browser keeps
   rendering the current page, toast included, until the next one is ready.
   The destination page then reads ?status=&message= off its own URL (added
   by every mutating route's _status_redirect) and shows the real outcome. */
#toast-stack {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-width: min(360px, calc(100vw - 2rem));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.8rem 0.95rem;
  border-radius: 14px;
  background: var(--panel-strong);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
  font-size: 0.88rem;
  color: var(--text);
  animation: toast-in 0.22s ease;
  pointer-events: auto;
}
.toast.leaving { animation: toast-out 0.18s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(16px); } }
.toast-icon {
  flex: none;
  width: 20px;
  height: 20px;
  margin-top: 1px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
}
.toast.success .toast-icon { background: color-mix(in srgb, var(--status-good) 22%, transparent); color: var(--status-good); }
.toast.error .toast-icon { background: color-mix(in srgb, var(--status-critical) 22%, transparent); color: var(--status-critical); }
.toast.processing .toast-icon { background: color-mix(in srgb, var(--accent) 20%, transparent); }
.toast-spinner {
  width: 11px;
  height: 11px;
  border: 2px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.toast-message { flex: 1; line-height: 1.35; padding-top: 1px; }
.toast-close {
  background: none;
  border: none;
  color: var(--muted);
  padding: 0 0 0 0.4rem;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  flex: none;
}
.toast-close:hover { color: var(--text); }
@media (prefers-reduced-motion: reduce) {
  .toast, .toast.leaving { animation: none; }
}
@media (max-width: 640px) {
  #toast-stack { left: 1rem; right: 1rem; max-width: none; top: 0.75rem; }
}

@media (max-width: 640px) {
  main { padding: 0 0.75rem 2rem; }
  nav { flex-wrap: wrap; gap: 0.85rem; border-radius: 20px; }
  .bar-row { grid-template-columns: 1fr; gap: 0.3rem; }
  .stat-value { font-size: 1.4rem; }
}

/* Responsive table: always stacks into cards, at every viewport width — no
   breakpoint to mistune. This table (7 columns, 2 text inputs, a select,
   multiple buttons) never lays out comfortably as a real table regardless of
   window size, so it doesn't try to; a plain table view is one thing this
   layout structurally never does. */
.responsive-table thead { display: none; }
.responsive-table, .responsive-table tbody, .responsive-table tr, .responsive-table td {
  display: block;
  width: 100%;
}
.responsive-table tr {
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 14px;
  margin-bottom: 0.75rem;
  padding: 0.4rem 0;
}
.responsive-table td {
  border-bottom: none;
  padding: 0.4rem 0.9rem;
  white-space: normal;
}
.responsive-table td::before {
  content: attr(data-label);
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.3rem;
}
.responsive-table td input,
.responsive-table td select {
  width: 100%;
}
@media (min-width: 640px) {
  .responsive-table tr { max-width: 560px; }
}

/* ---- Data table (Categories, Budgets) --------------------------------------
   Deliberately its own layout, not .responsive-table: that pattern always
   card-stacks (by design, see above) which is right for a wide multi-input
   row but turns a long category list into a very long scroll of tall cards
   on desktop. These tables' columns are narrow enough (badges/pills instead
   of full-width inputs) to read comfortably as a real table above the phone
   breakpoint.

   table-layout: fixed with percentage columns (rather than sizing from
   content, like a normal table would) is the actual fix for the
   horizontal-scroll bug the categories page shipped three different patches
   for: the table's own width can never exceed its container regardless of
   viewport width, so there's no in-between size left to overflow at — the
   same "no breakpoint to mistune" principle .responsive-table already uses,
   applied to a real table instead of forcing card-stacking everywhere.
   Column widths are per-table (.categories-table / .budgets-table below)
   since each has a different column count; everything else is shared. */
.data-table { table-layout: fixed; width: 100%; }
.data-table th {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 0.5rem 0.6rem;
}
.data-table td { padding: 0.45rem 0.6rem; vertical-align: middle; overflow: hidden; }
.data-table tbody tr:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.data-table td input:not(.calc-input), .data-table td select { width: 100%; min-width: 0; }

.categories-table th:nth-child(1) { width: 9%; }
.categories-table th:nth-child(2) { width: 17%; }
.categories-table th:nth-child(3) { width: 15%; }
.categories-table th:nth-child(4) { width: 13%; }
.categories-table th:nth-child(5) { width: 12%; }
.categories-table th:nth-child(6) { width: 19%; }
.categories-table th:nth-child(7) { width: 15%; }

.budgets-table th:nth-child(1) { width: 22%; }
.budgets-table th:nth-child(2) { width: 18%; }
.budgets-table th:nth-child(3) { width: 15%; }
.budgets-table th:nth-child(4) { width: 45%; }

.budget-section { margin-bottom: 1.75rem; }
.budget-section h2 {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin: 0 0 0.6rem;
}
.budget-section-total { font-size: 0.9rem; font-weight: 650; font-variant-numeric: tabular-nums; color: var(--muted); }

.control-cluster { display: flex; align-items: center; gap: 0.5rem; }
.reorder-group { display: inline-flex; flex-direction: column; gap: 2px; }
.reorder-btn {
  padding: 0.1rem 0.4rem;
  font-size: 0.65rem;
  line-height: 1.4;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.reorder-btn:first-child { border-radius: 6px 6px 0 0; }
.reorder-btn:last-child { border-radius: 0 0 6px 6px; margin-top: -1px; }
.reorder-btn:hover { color: var(--text); background: var(--panel-strong); }

.category-name-input {
  font-weight: 650;
  font-size: 0.96rem;
  border-color: transparent;
  background: transparent;
  padding: 0.35rem 0.5rem;
}
.category-name-input:hover, .category-name-input:focus { border-color: var(--border); background: var(--panel-strong); }

.category-name-plain { font-weight: 650; font-size: 0.96rem; padding: 0.35rem 0.5rem; display: block; }

.group-input, .notes-input {
  font-size: 0.85rem;
  color: var(--muted);
  border-color: transparent;
  background: transparent;
  padding: 0.35rem 0.5rem;
}
.group-input:hover, .group-input:focus,
.notes-input:hover, .notes-input:focus { border-color: var(--border); background: var(--panel-strong); color: var(--text); }

.type-select {
  font-weight: 600;
  font-size: 0.78rem;
  border: none;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  cursor: pointer;
}
.type-select.type-expense,
.type-select.type-fixed-expense { background: color-mix(in srgb, var(--series-1) 20%, var(--panel-strong)); color: var(--series-1); }
.type-select.type-variable-expense { background: color-mix(in srgb, var(--series-2) 20%, var(--panel-strong)); color: var(--series-2); }
.type-select.type-income { background: color-mix(in srgb, var(--status-good) 20%, var(--panel-strong)); color: var(--status-good); }
.type-select.type-savings { background: color-mix(in srgb, var(--series-7) 20%, var(--panel-strong)); color: var(--series-7); }
.type-select.type-debt { background: color-mix(in srgb, var(--status-critical) 20%, var(--panel-strong)); color: var(--status-critical); }

.status-pill {
  font-weight: 600;
  font-size: 0.78rem;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}
.status-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.status-pill.status-active { background: color-mix(in srgb, var(--status-good) 16%, var(--panel-strong)); color: var(--status-good); }
.status-pill.status-active:hover { background: color-mix(in srgb, var(--status-good) 28%, var(--panel-strong)); }
.status-pill.status-inactive { background: color-mix(in srgb, var(--muted) 18%, var(--panel-strong)); color: var(--muted); }
.status-pill.status-inactive:hover { background: color-mix(in srgb, var(--muted) 30%, var(--panel-strong)); }
.status-pill.readonly { cursor: default; }

.save-btn { opacity: 0.4; background: var(--panel-strong); color: var(--muted); box-shadow: none; }
.save-btn.dirty { opacity: 1; background: var(--accent); color: white; }

.icon-btn-remove {
  background: transparent;
  color: var(--muted);
  padding: 0.3rem 0.55rem;
  border: 1px solid var(--border);
  font-size: 0.95rem;
  line-height: 1;
}
.icon-btn-remove:hover { color: var(--status-critical); border-color: var(--status-critical); background: color-mix(in srgb, var(--status-critical) 10%, transparent); }

.row-actions { display: flex; align-items: center; gap: 0.4rem; }

@media (max-width: 780px) {
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr, .data-table td {
    display: block;
    width: 100%;
  }
  .data-table tr {
    background: var(--panel-strong);
    border: 1px solid var(--border);
    border-radius: 14px;
    margin-bottom: 0.75rem;
    padding: 0.5rem 0;
  }
  .data-table td { border-bottom: none; padding: 0.4rem 0.9rem; }
  .data-table td::before {
    content: attr(data-label);
    display: block;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    margin-bottom: 0.3rem;
  }
}
