/* FinanceFlow – design tokens -------------------------------------------------------------- */
:root {
  color-scheme: light;
  --page: #f4f4f1;
  --surface-1: #fcfcfb;
  --surface-2: #f4f3ef;
  --surface-3: #ebeae5;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #6f6e69;
  --axis: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.18);
  --shadow: 0 1px 2px rgba(11, 11, 11, .04), 0 4px 16px rgba(11, 11, 11, .04);
  --accent: #1c5cab;
  --accent-hover: #184f95;
  --accent-soft: #e3eefc;
  --on-accent: #ffffff;

  /* flow semantics */
  --income: #1baf7a;
  --expense: #eb6834;
  --saving: #2a78d6;
  --unalloc: #898781;
  --critical: #d03b3b;
  --good-text: #006300;

  --radius: 12px;
  --radius-sm: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --surface-2: #222220;
    --surface-3: #2c2c2a;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #a3a29b;
    --axis: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.18);
    --shadow: none;
    --accent: #3987e5;
    --accent-hover: #5598e7;
    --accent-soft: #16263b;
    --on-accent: #ffffff;
    --income: #199e70;
    --expense: #d95926;
    --saving: #3987e5;
    --critical: #e66767;
    --good-text: #0ca30c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #222220;
  --surface-3: #2c2c2a;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #a3a29b;
  --axis: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);
  --shadow: none;
  --accent: #3987e5;
  --accent-hover: #5598e7;
  --accent-soft: #16263b;
  --on-accent: #ffffff;
  --income: #199e70;
  --expense: #d95926;
  --saving: #3987e5;
  --critical: #e66767;
  --good-text: #0ca30c;
}

/* Base ------------------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--text-primary);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 24px; }
h2 { font-size: 15px; }
h3 { font-size: 13px; }
.sub { margin: 2px 0 0; color: var(--text-secondary); font-size: 13px; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--text-muted); }

/* Shell ------------------------------------------------------------------------------------ */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh;
  background: linear-gradient(to right, var(--surface-1) 231px, var(--border) 231px, var(--border) 232px, transparent 232px); }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 18px;
  padding: 20px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 10px; }
.brand-mark { width: 28px; height: 28px; }
.bm-in { fill: var(--income); } .bm-out { fill: var(--expense); } .bm-save { fill: var(--saving); }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--text-secondary); text-decoration: none; font-weight: 550;
}
.nav a svg { width: 18px; height: 18px; fill: currentColor; flex: none; }
.nav a:hover { background: var(--surface-2); color: var(--text-primary); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.whoami { font-size: 12px; color: var(--text-muted); padding: 0 8px; word-break: break-all; }

.main { padding: 28px 32px 48px; min-width: 0; outline: none; }
.view { display: flex; flex-direction: column; gap: 16px; max-width: 1440px; margin: 0 auto; }
.view-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 4px; }
.head-actions { display: flex; gap: 8px; align-items: center; }

/* Cards ------------------------------------------------------------------------------------ */
.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }

/* Filters ---------------------------------------------------------------------------------- */
.filters { display: flex; flex-wrap: wrap; gap: 14px 24px; align-items: flex-end; padding: 14px 18px; }
.filter-group { display: flex; flex-direction: column; gap: 6px; }
.filter-group.grow { flex: 1 1 320px; }
.filter-label { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 12px 0 10px;
  border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface-1);
  color: var(--text-secondary); font: inherit; font-weight: 550; cursor: pointer;
}
.chip .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 2px var(--surface-1); }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--text-primary); }
.chip[aria-pressed="true"]::after { content: "✓"; font-size: 12px; color: var(--accent); font-weight: 700; }
.chip.all { font-weight: 600; }
.chip:hover { border-color: var(--accent); }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: transparent; color: var(--text-secondary); font: inherit; font-weight: 550;
  padding: 5px 12px; border-radius: 7px; cursor: pointer; white-space: nowrap;
}
.seg button[aria-checked="true"] { background: var(--surface-1); color: var(--text-primary); box-shadow: 0 1px 2px rgba(0,0,0,.12); }

/* KPIs ------------------------------------------------------------------------------------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--k, var(--axis)); }
.kpi .k-label { font-size: 12px; font-weight: 600; color: var(--text-secondary); display: flex; align-items: center; gap: 6px; }
.kpi .k-value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin-top: 4px; }
.kpi .k-note { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.kpi .k-note.bad { color: var(--critical); font-weight: 600; }
.kpi .k-note.good { color: var(--good-text); font-weight: 600; }

/* Legends ---------------------------------------------------------------------------------- */
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--text-secondary); }
.legend .li { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 12px; height: 12px; border-radius: 3px; background: var(--c); }

/* Flow diagram ----------------------------------------------------------------------------- */
.flow-card { padding-bottom: 8px; }
#flowArea, .flow-body { width: 100%; overflow-x: auto; }
.flow-split { display: grid; grid-template-columns: repeat(auto-fit, minmax(560px, 1fr)); gap: 16px; }
.flow-panel { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 12px 4px; background: var(--surface-1); min-width: 0; }
.flow-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; flex-wrap: wrap; }
.flow-panel-head h3 { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.flow-panel-head .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.flow-panel-stats { display: flex; gap: 12px; font-size: 12px; color: var(--text-secondary); flex-wrap: wrap; }
.flow-panel-stats b { color: var(--text-primary); font-weight: 650; }

svg.sankey { display: block; width: 100%; overflow: visible; }
svg.sankey .link { fill-opacity: .42; transition: fill-opacity .12s; cursor: default; }
svg.sankey .link.dim { fill-opacity: .10; }
svg.sankey .link.hi, svg.sankey .link:hover { fill-opacity: .78; }
:root[data-theme="dark"] svg.sankey .link { fill-opacity: .55; }
:root[data-theme="dark"] svg.sankey .link.dim { fill-opacity: .12; }
:root[data-theme="dark"] svg.sankey .link.hi, :root[data-theme="dark"] svg.sankey .link:hover { fill-opacity: .9; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) svg.sankey .link { fill-opacity: .55; } :root:not([data-theme="light"]) svg.sankey .link.dim { fill-opacity: .12; } }
svg.sankey .node rect { rx: 3px; stroke: var(--surface-1); stroke-width: 1; }
svg.sankey .node { cursor: pointer; }
svg.sankey text { font: 12px var(--font); fill: var(--text-primary); paint-order: stroke; stroke: var(--surface-1); stroke-width: 4px; stroke-linejoin: round; }
svg.sankey text .v { fill: var(--text-secondary); font-variant-numeric: tabular-nums; }
svg.sankey text.col-head { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; fill: var(--text-muted); }
svg.sankey text.person-label { font-weight: 700; font-size: 13px; }

.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  min-height: 220px; text-align: center; color: var(--text-secondary); padding: 24px;
}
.empty svg { width: 56px; height: 56px; opacity: .5; }

/* Donut & allocation ----------------------------------------------------------------------- */
.donut-area { display: grid; grid-template-columns: minmax(200px, 260px) 1fr; gap: 20px; align-items: center; }
.donut-area svg { width: 100%; height: auto; }
.donut-center-value { font-size: 20px; font-weight: 700; fill: var(--text-primary); }
.donut-center-label { font-size: 11px; fill: var(--text-muted); letter-spacing: .06em; text-transform: uppercase; }
.arc { stroke: var(--surface-1); stroke-width: 2px; cursor: default; transition: opacity .12s; }
.arc.dim { opacity: .35; }
.cat-list { width: 100%; border-collapse: collapse; font-size: 13px; }
.cat-list td { padding: 5px 4px; border-bottom: 1px solid var(--grid); }
.cat-list tr:last-child td { border-bottom: 0; }
.cat-list .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--c); margin-right: 8px; vertical-align: -1px; }
.cat-list .type-tag { font-size: 11px; color: var(--text-muted); margin-left: 6px; }

.alloc-row { display: grid; grid-template-columns: 150px 1fr; gap: 12px; align-items: center; margin: 12px 0; }
.alloc-name { display: flex; align-items: center; gap: 8px; font-weight: 600; min-width: 0; }
.alloc-name span.n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alloc-name .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }
.alloc-bar { position: relative; height: 26px; }
.alloc-seg { position: absolute; top: 0; bottom: 0; background: var(--c); border-radius: 0; color: #fff; font-size: 11px; font-weight: 600; display: flex; align-items: center; padding: 0 6px; overflow: hidden; white-space: nowrap; }
.alloc-seg.first { border-radius: 4px 0 0 4px; }
.alloc-seg.last { border-radius: 0 4px 4px 0; }
.alloc-seg.first.last { border-radius: 4px; }
.alloc-seg.unalloc { background: var(--surface-3); color: var(--text-secondary); }
.alloc-marker { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--text-primary); }
.alloc-meta { grid-column: 2; font-size: 12px; color: var(--text-secondary); margin-top: -6px; }
.alloc-meta .bad { color: var(--critical); font-weight: 600; }

/* Tables ----------------------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted); padding: 8px 10px; border-bottom: 1px solid var(--baseline); white-space: nowrap; }
table.data th.num { text-align: right; }
table.data td { padding: 9px 10px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tfoot td { font-weight: 700; border-bottom: 0; border-top: 1px solid var(--baseline); }
table.data tr.inactive td { color: var(--text-muted); }
table.data tr.inactive td.name::after { content: " (paused)"; font-size: 11px; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.tag { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); font-size: 12px; color: var(--text-secondary); white-space: nowrap; }
.tag .sw { width: 8px; height: 8px; border-radius: 2px; background: var(--c); }

/* Entries sections ------------------------------------------------------------------------- */
.entry-section { margin-bottom: 16px; }
.entry-section .card-head h2 { display: flex; align-items: center; gap: 8px; }
.entry-section .card-head h2 .sw { width: 12px; height: 12px; border-radius: 3px; background: var(--c); }
.section-total { font-weight: 700; font-size: 15px; }

/* People ----------------------------------------------------------------------------------- */
.people-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.person-card { display: flex; flex-direction: column; gap: 12px; }
.person-card .p-head { display: flex; align-items: center; gap: 12px; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--c); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 15px; flex: none; }
.person-card .p-name { font-weight: 700; font-size: 16px; }
.person-card .p-notes { font-size: 12px; color: var(--text-muted); }
.p-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.p-stat { background: var(--surface-2); border-radius: var(--radius-sm); padding: 8px 10px; }
.p-stat .l { font-size: 11px; color: var(--text-muted); font-weight: 600; }
.p-stat .v { font-weight: 700; font-variant-numeric: tabular-nums; }
.mini-bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--surface-3); gap: 2px; }
.mini-bar span { background: var(--c); }
.p-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* Settings --------------------------------------------------------------------------------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; align-items: end; }
.form-actions { display: flex; gap: 8px; }
.cat-columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.cat-col { background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px; }
.cat-col h3 { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cat-item { display: flex; align-items: center; gap: 8px; padding: 6px 6px; border-radius: 6px; }
.cat-item:hover { background: var(--surface-1); }
.cat-item .sw { width: 14px; height: 14px; border-radius: 4px; background: var(--c); flex: none; }
.cat-item .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-item .cnt { font-size: 12px; color: var(--text-muted); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* Forms & buttons -------------------------------------------------------------------------- */
label > span, .field-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 8px 10px; min-height: 36px;
}
textarea { min-height: 70px; resize: vertical; }
input[type="color"] { padding: 2px; height: 36px; cursor: pointer; }
input[type="checkbox"] { width: auto; min-height: 0; accent-color: var(--accent); }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, .chip:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.inline-field { display: flex; align-items: center; gap: 8px; }
.inline-field > span { margin: 0; }
.inline-field select { min-width: 200px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check > span { margin: 0; font-weight: 500; color: var(--text-primary); font-size: 13px; }
.checks { display: flex; gap: 14px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface-1);
  color: var(--text-primary); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-secondary); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text-primary); }
.btn.danger { color: var(--critical); }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; }
.btn svg { width: 16px; height: 16px; fill: currentColor; }
.icon-btn { border: 0; background: transparent; color: var(--text-secondary); width: 30px; height: 30px; border-radius: 6px; cursor: pointer; font-size: 18px; line-height: 1; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--surface-3); color: var(--text-primary); }
.icon-btn svg { width: 16px; height: 16px; fill: currentColor; }
.icon-btn.danger:hover { color: var(--critical); }

/* Modal ------------------------------------------------------------------------------------ */
.modal { border: 0; padding: 0; border-radius: 14px; background: var(--surface-1); color: var(--text-primary); width: min(620px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal::backdrop { background: rgba(10, 10, 10, .45); backdrop-filter: blur(2px); }
.modal-inner { display: flex; flex-direction: column; max-height: calc(100vh - 64px); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 17px; }
.modal-body { padding: 18px 20px; overflow-y: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.modal-body .full { grid-column: 1 / -1; }
.modal-body hr { grid-column: 1 / -1; border: 0; border-top: 1px solid var(--border); margin: 2px 0; width: 100%; }
.modal-body .section-title { grid-column: 1 / -1; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); }
.modal-error { margin: 0 20px 4px; padding: 10px 12px; border-radius: var(--radius-sm); background: color-mix(in srgb, var(--critical) 12%, transparent); color: var(--critical); font-weight: 600; font-size: 13px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }
.hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.swatches button { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--surface-1); background: var(--c); box-shadow: 0 0 0 1px var(--border-strong); cursor: pointer; padding: 0; }
.swatches button[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--text-primary); }
.swatches input[type="color"] { width: 40px; }

/* Tooltip & toasts ------------------------------------------------------------------------- */
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; max-width: 300px;
  background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border-strong);
  border-radius: 10px; padding: 10px 12px; font-size: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.18);
}
.tooltip .t-title { font-weight: 700; font-size: 13px; margin-bottom: 4px; display: flex; align-items: center; gap: 6px; }
.tooltip .t-title .sw { width: 10px; height: 10px; border-radius: 3px; background: var(--c); }
.tooltip .t-row { display: flex; justify-content: space-between; gap: 16px; color: var(--text-secondary); }
.tooltip .t-row b { color: var(--text-primary); font-variant-numeric: tabular-nums; }
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--text-primary); color: var(--surface-1); padding: 10px 14px; border-radius: 10px; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 360px; }
.toast.error { background: var(--critical); color: #fff; }

/* Responsive ------------------------------------------------------------------------------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; background: none; }
  .sidebar { background: var(--surface-1); }
  .sidebar { position: sticky; top: 0; z-index: 20; height: auto; flex-direction: row; align-items: center; padding: 8px 12px; gap: 8px; border-right: 0; border-bottom: 1px solid var(--border); overflow-x: auto; }
  .brand { padding: 0; }
  .brand-name { display: none; }
  .nav { flex-direction: row; }
  .nav a { padding: 8px 10px; }
  .nav a span { display: none; }
  .sidebar-foot { margin: 0 0 0 auto; flex-direction: row; }
  .sidebar-foot .whoami, #themeToggle span { display: none; }
  .main { padding: 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  .flow-split { grid-template-columns: 1fr; }
  .donut-area { grid-template-columns: 1fr; }
  .alloc-row { grid-template-columns: 96px 1fr; gap: 8px; }
  .modal-body { grid-template-columns: 1fr; }
  .inline-field select { min-width: 0; }
}
@media (forced-colors: active) {
  svg.sankey .link { fill-opacity: 1; }
}
@media print {
  .sidebar, .filters, .btn, .icon-btn { display: none !important; }
  .shell { display: block; }
  .card { break-inside: avoid; box-shadow: none; }
}

/* Authentication screens -------------------------------------------------------------------- */
.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background:
  radial-gradient(1200px 500px at 10% -10%, color-mix(in srgb, var(--income) 14%, transparent), transparent 60%),
  radial-gradient(900px 500px at 110% 110%, color-mix(in srgb, var(--saving) 14%, transparent), transparent 60%), var(--page); }
.auth-card { width: min(420px, 100%); background: var(--surface-1); border: 1px solid var(--border); border-radius: 16px; padding: 28px; box-shadow: 0 10px 40px rgba(0,0,0,.08); display: flex; flex-direction: column; gap: 6px; }
.auth-brand { padding: 0 0 12px; }
.auth-card h1 { font-size: 22px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; }
.auth-card .btn.primary { height: 42px; font-size: 15px; }
.auth-card .modal-error { margin: 10px 0 0; }
.pw-hint { font-size: 12px; color: var(--text-muted); margin-top: -6px; }
.pw-meter { height: 4px; border-radius: 2px; background: var(--surface-3); overflow: hidden; margin-top: 6px; }
.pw-meter span { display: block; height: 100%; width: 0; background: var(--critical); transition: width .15s, background .15s; }

/* Signed-in user --------------------------------------------------------------------------- */
.user-card { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--radius-sm); background: var(--surface-2); }
.avatar.small { width: 32px; height: 32px; font-size: 12px; background: var(--accent); }
.user-meta { min-width: 0; }
.user-name { font-weight: 650; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.foot-actions { display: flex; flex-wrap: wrap; gap: 2px; }
.foot-actions .btn { padding: 0 8px; }
.role-badge { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: .03em; background: var(--surface-3); color: var(--text-secondary); }
.role-badge.admin { background: color-mix(in srgb, var(--critical) 16%, transparent); color: var(--critical); }
.role-badge.editor { background: color-mix(in srgb, var(--saving) 16%, transparent); color: var(--saving); }
.role-badge.viewer { background: color-mix(in srgb, var(--income) 18%, transparent); color: color-mix(in srgb, var(--income) 70%, var(--text-primary)); }
.readonly-note { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }

/* Users admin ------------------------------------------------------------------------------ */
.role-legend { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px 20px; font-size: 13px; color: var(--text-secondary); }
.role-legend .role-badge { margin-right: 6px; }
.status-pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.status-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--c, var(--axis)); }
.status-pill.ok { --c: #0ca30c; } .status-pill.warn { --c: #fab219; } .status-pill.bad { --c: var(--critical); color: var(--critical); }
.access-list { display: flex; flex-wrap: wrap; gap: 4px; max-width: 320px; }
.access-picker { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); max-height: 180px; overflow-y: auto; }
.access-picker .check { background: var(--surface-2); padding: 4px 10px; border-radius: 999px; }
.temp-pw { display: flex; gap: 8px; align-items: center; }
.temp-pw input { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .02em; }
.secret-box { grid-column: 1 / -1; background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px 14px; }
.secret-box code { font-size: 16px; font-weight: 700; user-select: all; word-break: break-all; }
table.data td.muted-cell { color: var(--text-muted); font-size: 12px; white-space: nowrap; }
@media (max-width: 900px) {
  .user-card { display: none; }
  .foot-actions .btn span { display: none; }
}
@media (max-width: 900px) { .auth-brand .brand-name { display: inline; } }

/* ---- Two-step verification ---------------------------------------------------------------- */
.auth-steps { display: flex; gap: 6px; margin-bottom: 6px; flex-wrap: wrap; }
.auth-steps:empty { display: none; }
.auth-steps span { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-muted); padding: 3px 8px; border-radius: 999px; background: var(--surface-2); }
.auth-steps span.active { background: var(--accent-soft); color: var(--accent); }
.auth-steps span.done { color: var(--good-text); }
.modal-error.info { background: var(--accent-soft); color: var(--accent); }
.otp-input { font-size: 24px; letter-spacing: .3em; text-align: center; font-variant-numeric: tabular-nums; height: 52px !important; }
.qr-wrap { display: grid; place-items: center; padding: 6px 0; }
.qr-wrap svg.qr { width: 196px; height: 196px; border-radius: 8px; box-shadow: 0 0 0 1px var(--border); }
.enrol-steps { margin: 0; padding-left: 20px; color: var(--text-secondary); display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.manual-key summary { cursor: pointer; font-size: 13px; color: var(--accent); }
.manual-key .secret-box { margin-top: 8px; }
.recovery-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px 14px; }
.recovery-grid code { font: 600 14px ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .03em; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.security-summary { display: flex; flex-direction: column; gap: 6px; }
.security-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.t-hint { margin-top: 6px; font-size: 11px; color: var(--text-muted); }
.tooltip .t-row .sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; background: var(--c); margin-right: 6px; }

/* ---- Card tools, focus bar, full screen ----------------------------------------------------- */
.card-tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.tool-sep { width: 1px; height: 20px; background: var(--border-strong); margin: 0 4px; }
.icon-text { font-size: 10px; font-weight: 700; letter-spacing: .04em; }
.focus-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 12px; margin: -4px 0 10px; border-radius: var(--radius-sm); background: var(--accent-soft); font-size: 13px; }
.focus-bar .focus-label { margin-right: 4px; }
.focus-bar { min-height: 42px; }
.focus-bar.idle { background: var(--surface-2); color: var(--text-muted); }
.focus-hint { font-size: 12px; }
.flow-card:fullscreen { overflow: auto; padding: 24px 28px; border-radius: 0; background: var(--surface-1); }
.flow-card:fullscreen #flowArea svg { margin: 0 auto; }
svg.sankey .node.dim rect { opacity: .35; }
svg.sankey .node.dim text { opacity: .45; }
svg.sankey .node.focus rect { stroke: var(--text-primary); stroke-width: 2; }
svg.sankey .expand-hint { font-size: 10px; fill: var(--accent); font-weight: 600; stroke-width: 3px; }
svg.sankey .node:focus-visible { outline: none; }
svg.sankey .node:focus-visible rect { stroke: var(--accent); stroke-width: 3; }

/* ---- XY charts (trends) and bullet charts (budgets) ------------------------------------------ */
svg.xy-chart { display: block; width: 100%; height: auto; overflow: visible; }
svg.xy-chart .grid line { stroke: var(--grid); stroke-width: 1; }
svg.xy-chart .axis text { fill: var(--text-muted); font: 11px var(--font); font-variant-numeric: tabular-nums; }
svg.xy-chart .axis .baseline { stroke: var(--baseline); }
svg.xy-chart .line { fill: none; stroke-width: 2px; stroke-linejoin: round; stroke-linecap: round; }
svg.xy-chart .area { fill-opacity: .12; stroke: none; }
svg.xy-chart .end-dot, svg.xy-chart .hover-dot { stroke: var(--surface-1); stroke-width: 2px; }
svg.xy-chart .end-label { fill: var(--text-secondary); font: 12px var(--font); }
svg.xy-chart .crosshair { stroke: var(--axis); stroke-width: 1; stroke-dasharray: 3 3; }
svg.xy-chart .bar-seg { transition: opacity .12s; }
svg.xy-chart .bar-seg.dim { opacity: .35; }
svg.bullets .bullet-label { fill: var(--text-primary); font: 12px var(--font); }
svg.bullets .bullet-track { fill: var(--surface-2); }
svg.bullets .bullet-bar.expense { fill: var(--expense); }
svg.bullets .bullet-bar.saving { fill: var(--saving); }
svg.bullets .bullet-bar.bad { fill: var(--critical); }
svg.bullets .bullet-bar.warn { fill: var(--saving); fill-opacity: .55; }
svg.bullets .bullet-target { stroke: var(--text-primary); stroke-width: 2.5px; stroke-linecap: round; }
svg.bullets .bullet-status { font: 600 12px var(--font); fill: var(--text-secondary); }
svg.bullets .bullet-status.good { fill: var(--good-text); }
svg.bullets .bullet-status.bad { fill: var(--critical); }
.target-sw { display: inline-block; width: 2.5px; height: 14px; background: var(--text-primary); border-radius: 2px; }
.budget-input { width: 120px; text-align: right; height: 32px !important; min-height: 32px; padding: 4px 8px; font-variant-numeric: tabular-nums; }
.add-budget { margin-top: 14px; }
.add-budget select { min-width: 260px; max-width: 380px; }
details > summary { cursor: pointer; }

/* ---- Print / Save as PDF --------------------------------------------------------------------- */
.print-header { display: none; }
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; }
  .print-header { display: block; margin-bottom: 12px; }
  .shell { background: none !important; display: block; }
  #flowSub { display: none; }
  .print-header h1 { font-size: 20px; }
  .print-header p { margin: 4px 0 0; color: #52514e; }
  .view-head, .filters, .card-tools, .focus-bar, .head-actions, #toasts, .tooltip, .add-budget, .expand-hint { display: none !important; }
  .main { padding: 0; }
  .card, .kpi { border-color: #ccc; }
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .grid-2 { grid-template-columns: 1fr 1fr; }
  #flowArea, .flow-body { overflow: visible; }
  svg.sankey, svg.xy-chart { width: 100% !important; height: auto !important; }
  details { display: block; }
  details > summary { list-style: none; }
  .budget-input { border: 0; }
}
