/* ============ Theme tokens ============ */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e6e9f2;
  --text: #0f172a;
  --text-2: #475569;
  --muted: #94a3b8;
  --primary: #4f46e5;
  --primary-2: #7c3aed;
  --primary-soft: #eef2ff;
  --success: #059669;
  --success-soft: #ecfdf5;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --danger: #e11d48;
  --danger-soft: #fff1f2;
  --info: #0284c7;
  --info-soft: #f0f9ff;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .06);
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px -6px rgba(15, 23, 42, .08);
  --shadow-lg: 0 24px 60px -12px rgba(15, 23, 42, .25);
  --radius: 16px;
  --radius-sm: 10px;
  --sidebar: #0f1029;
  --sidebar-2: #1b1c4a;
  --grid: #eef1f6;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0d17; --surface: #141726; --surface-2: #1a1e30; --border: #262a40; --text: #e8eaf3; --text-2: #a5acc4; --muted: #6b7393;
    --primary: #818cf8; --primary-2: #a78bfa; --primary-soft: #1e2142; --success: #34d399; --success-soft: #0f2a24; --warning: #fbbf24;
    --warning-soft: #2b2310; --danger: #fb7185; --danger-soft: #2e141c; --info: #38bdf8; --info-soft: #0f2533;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3); --shadow: 0 8px 24px -6px rgba(0,0,0,.45); --shadow-lg: 0 24px 60px -12px rgba(0,0,0,.6);
    --sidebar: #090a18; --sidebar-2: #15163a; --grid: #20243a; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0d17; --surface: #141726; --surface-2: #1a1e30; --border: #262a40; --text: #e8eaf3; --text-2: #a5acc4; --muted: #6b7393;
  --primary: #818cf8; --primary-2: #a78bfa; --primary-soft: #1e2142; --success: #34d399; --success-soft: #0f2a24; --warning: #fbbf24;
  --warning-soft: #2b2310; --danger: #fb7185; --danger-soft: #2e141c; --info: #38bdf8; --info-soft: #0f2533;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3); --shadow: 0 8px 24px -6px rgba(0,0,0,.45); --shadow-lg: 0 24px 60px -12px rgba(0,0,0,.6);
  --sidebar: #090a18; --sidebar-2: #15163a; --grid: #20243a; color-scheme: dark;
}

/* ============ Base ============ */
* { box-sizing: border-box; }
[hidden] { display: none !important; } /* component display rules must never un-hide an element */
html, body { margin: 0; }
body {
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
.num { font-variant-numeric: tabular-nums; }

/* ============ Layout ============ */
.app { display: grid; grid-template-columns: 264px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  background: radial-gradient(120% 60% at 0% 0%, var(--sidebar-2) 0%, var(--sidebar) 60%);
  color: #c7c9e8; padding: 22px 16px; display: flex; flex-direction: column; gap: 22px; z-index: 40;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px; }
.brand-logo {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #6366f1, #a855f7); box-shadow: 0 8px 20px -6px rgba(124, 58, 237, .7);
}
.brand-logo svg { width: 22px; height: 22px; }
.brand-title { color: #fff; font-weight: 800; font-size: 16px; letter-spacing: -.01em; }
.brand-sub { font-size: 12px; color: #8f92c4; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 12px;
  color: #a9acd6; font-weight: 600; transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: linear-gradient(90deg, rgba(99,102,241,.95), rgba(139,92,246,.85)); color: #fff; box-shadow: 0 8px 20px -8px rgba(99,102,241,.8); }
.sidebar-card {
  margin-top: auto; padding: 16px; border-radius: 14px; background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.08);
}
.sidebar-card-label { font-size: 12px; color: #8f92c4; text-transform: uppercase; letter-spacing: .08em; font-weight: 600; }
.sidebar-card-value { font-size: 22px; font-weight: 800; color: #fff; margin: 4px 0 10px; }
.sidebar-progress { height: 6px; border-radius: 99px; background: rgba(255,255,255,.1); overflow: hidden; }
.sidebar-progress span { display: block; height: 100%; width: 0; border-radius: 99px; background: linear-gradient(90deg, #34d399, #10b981); transition: width .6s ease; }
.sidebar-card-foot { font-size: 12px; margin-top: 8px; color: #a9acd6; }
.scrim { display: none; }

.main { min-width: 0; padding: 0 32px 48px; }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 16px;
  padding: 20px 0 18px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
}
.topbar-title h1 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -.02em; }
.topbar-title p { margin: 2px 0 0; color: var(--text-2); font-size: 13px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.menu-btn { display: none; }
.month-picker {
  display: flex; align-items: center; gap: 2px; padding: 4px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-sm);
}
.month-label { border: 0; background: transparent; font-weight: 700; padding: 6px 10px; min-width: 132px; border-radius: 8px; }
.month-label:hover { background: var(--surface-2); }

/* ============ Buttons ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent;
  padding: 10px 16px; border-radius: 12px; font-weight: 700; font-size: 14px; transition: transform .08s, box-shadow .15s, background .15s; white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { color: #fff; background: linear-gradient(135deg, #6366f1, #7c3aed); box-shadow: 0 8px 20px -8px rgba(99,102,241,.9); }
.btn-primary:hover { box-shadow: 0 10px 24px -8px rgba(99,102,241,1); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-ghost { background: var(--danger-soft); color: var(--danger); }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.icon-btn {
  width: 40px; height: 40px; display: inline-grid; place-items: center; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2); box-shadow: var(--shadow-sm);
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); }
.icon-btn.sm { width: 32px; height: 32px; border-radius: 8px; box-shadow: none; border-color: transparent; background: transparent; }
.icon-btn.sm:hover { background: var(--surface-2); }
.i-sun { display: none; }
:root[data-theme="dark"] .i-sun { display: block; }
:root[data-theme="dark"] .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .i-sun { display: block; }
  :root:not([data-theme="light"]) .i-moon { display: none; }
}
.fab { display: none; }

/* ============ Cards & grid ============ */
.view { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.grid { display: grid; gap: 20px; }
.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 20px; }
.row-2 { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); margin-bottom: 20px; }
.row-2b { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); margin-bottom: 20px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; min-width: 0;
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card-title { font-size: 15px; font-weight: 800; margin: 0; letter-spacing: -.01em; }
.card-sub { font-size: 12.5px; color: var(--text-2); margin: 2px 0 0; }
.link-btn { border: 0; background: none; color: var(--primary); font-weight: 700; font-size: 13px; padding: 4px; }
.link-btn:hover { text-decoration: underline; }

/* KPI */
.kpi { position: relative; overflow: hidden; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; }
.kpi-label { color: var(--text-2); font-size: 13px; font-weight: 600; }
.kpi-icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; }
.kpi-icon svg { width: 20px; height: 20px; }
.kpi-value { font-size: 26px; font-weight: 800; letter-spacing: -.02em; margin: 10px 0 6px; }
.kpi-foot { font-size: 12.5px; color: var(--text-2); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.kpi.hero { color: #fff; border: 0; background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 55%, #a855f7 100%); box-shadow: 0 18px 40px -16px rgba(99,102,241,.8); }
.kpi.hero .kpi-label, .kpi.hero .kpi-foot { color: rgba(255,255,255,.82); }
.kpi.hero .kpi-icon { background: rgba(255,255,255,.18); color: #fff; }
.kpi.hero::after { content: ''; position: absolute; right: -40px; bottom: -60px; width: 170px; height: 170px; border-radius: 50%; background: rgba(255,255,255,.08); }
.kpi.hero::before { content: ''; position: absolute; right: 40px; top: -70px; width: 140px; height: 140px; border-radius: 50%; background: rgba(255,255,255,.06); }
.tone-primary { background: var(--primary-soft); color: var(--primary); }
.tone-success { background: var(--success-soft); color: var(--success); }
.tone-warning { background: var(--warning-soft); color: var(--warning); }
.tone-danger { background: var(--danger-soft); color: var(--danger); }
.tone-info { background: var(--info-soft); color: var(--info); }

.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 700; }
.pill svg { width: 12px; height: 12px; stroke-width: 2.6; }
.pill.up { background: var(--danger-soft); color: var(--danger); }
.pill.down { background: var(--success-soft); color: var(--success); }
.pill.flat { background: var(--surface-2); color: var(--text-2); }
.kpi.hero .pill { background: rgba(255,255,255,.2); color: #fff; }

/* ============ Charts ============ */
.chart { width: 100%; position: relative; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; stroke: none; fill: none; }
.chart text { font-family: inherit; fill: var(--muted); font-size: 11px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.chart-tip {
  position: fixed; pointer-events: none; z-index: 100; background: #0f172a; color: #fff; padding: 8px 12px;
  border-radius: 10px; font-size: 12.5px; box-shadow: var(--shadow-lg); opacity: 0; transform: translate(-50%, -110%); transition: opacity .12s; white-space: nowrap;
}
.chart-tip b { font-weight: 800; }
.chart-tip .muted { color: #a5b4cf; }
.bar-hit { cursor: pointer; }
.donut-wrap { display: grid; grid-template-columns: 160px 1fr; gap: 18px; align-items: center; }
.donut-center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; pointer-events: none; }
.donut-center .v { font-size: 18px; font-weight: 800; color: var(--text); }
.donut-center .l { font-size: 11.5px; color: var(--text-2); }
.donut-legend { display: flex; flex-direction: column; gap: 9px; max-height: 230px; overflow: auto; padding-right: 4px; }
.donut-legend .li { display: grid; grid-template-columns: 10px 1fr auto auto; gap: 10px; align-items: center; font-size: 13px; }
.donut-legend .dot { width: 10px; height: 10px; border-radius: 3px; }
.donut-legend .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.donut-legend .amt { font-weight: 700; }
.donut-legend .pct { color: var(--muted); font-size: 12px; width: 38px; text-align: right; }

/* ============ Budget progress ============ */
.bud-list { display: flex; flex-direction: column; gap: 14px; }
.bud-item { display: grid; grid-template-columns: 38px 1fr; gap: 12px; align-items: center; }
.cat-ico { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; font-size: 18px; }
.bud-row { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; margin-bottom: 6px; }
.bud-row .n { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bud-row .v { color: var(--text-2); white-space: nowrap; }
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); }
.bar > span { display: block; height: 100%; border-radius: 99px; transition: width .7s cubic-bezier(.2,.8,.2,1); }

/* ============ Transactions ============ */
.tx-list { display: flex; flex-direction: column; }
.tx { display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: center; padding: 11px 0; border-bottom: 1px dashed var(--border); }
.tx:last-child { border-bottom: 0; }
.tx .t1 { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .t2 { font-size: 12px; color: var(--text-2); }
.tx .amt { font-weight: 800; text-align: right; }

/* ============ Insights ============ */
.insights { display: flex; flex-direction: column; gap: 12px; }
.insight { display: grid; grid-template-columns: 36px 1fr; gap: 12px; padding: 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.insight .ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; }
.insight .ico svg { width: 18px; height: 18px; }
.insight b { display: block; font-size: 13.5px; margin-bottom: 2px; }
.insight p { margin: 0; font-size: 12.5px; color: var(--text-2); }

/* ============ Table ============ */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.search { position: relative; flex: 1; min-width: 220px; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 38px; }
.input, .select, textarea.input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; outline: none; transition: border .15s, box-shadow .15s;
}
.input:focus, .select:focus { border-color: var(--primary); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 18%, transparent); }
.select { width: auto; padding-right: 30px; }
.table-wrap { overflow-x: auto; border-radius: 12px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; padding: 12px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
.t-right { text-align: right; }
.cat-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 6px; border-radius: 99px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.method { font-size: 12px; font-weight: 600; color: var(--text-2); padding: 3px 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.table-foot { display: flex; justify-content: space-between; align-items: center; padding: 14px 4px 0; color: var(--text-2); font-size: 13px; flex-wrap: wrap; gap: 8px; }
.table-foot b { color: var(--text); font-size: 15px; }

/* ============ Forms / modal ============ */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); backdrop-filter: blur(4px); display: grid; place-items: center; z-index: 80; padding: 16px; animation: fadeIn .15s; }
.modal-backdrop[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } }
.modal { width: 100%; max-width: 520px; background: var(--surface); border-radius: 20px; box-shadow: var(--shadow-lg); border: 1px solid var(--border); animation: pop .2s cubic-bezier(.2,.9,.3,1.2); max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
@keyframes pop { from { transform: scale(.96) translateY(8px); opacity: 0; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 17px; font-weight: 800; }
.modal-body { padding: 20px 22px 22px; overflow: auto; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12.5px; font-weight: 700; color: var(--text-2); }
.amount-input { position: relative; }
.amount-input span { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); font-weight: 800; color: var(--muted); }
.amount-input input { padding-left: 44px; font-size: 22px; font-weight: 800; height: 56px; }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; max-height: 210px; overflow: auto; padding: 2px; }
.cat-opt { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 6px; border-radius: 12px; border: 1.5px solid var(--border); background: var(--surface); font-size: 11.5px; font-weight: 600; text-align: center; line-height: 1.25; color: var(--text-2); }
.cat-opt .e { font-size: 20px; }
.cat-opt:hover { border-color: var(--muted); }
.cat-opt.sel { border-color: var(--primary); background: var(--primary-soft); color: var(--text); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 15%, transparent); }
.seg { display: flex; padding: 4px; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 9px; font-weight: 700; font-size: 13px; color: var(--text-2); }
.seg button.sel { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.form-error { color: var(--danger); font-size: 13px; font-weight: 600; margin-top: 10px; min-height: 1em; }

/* ============ Budget page ============ */
.budget-table td { padding: 10px 14px; }
.budget-table .input { max-width: 160px; text-align: right; font-weight: 700; }
.status { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 99px; white-space: nowrap; }
.status.ok { background: var(--success-soft); color: var(--success); }
.status.warn { background: var(--warning-soft); color: var(--warning); }
.status.over { background: var(--danger-soft); color: var(--danger); }
.status.none { background: var(--surface-2); color: var(--muted); }
.banner { display: flex; gap: 14px; align-items: center; padding: 14px 16px; border-radius: 14px; background: var(--primary-soft); color: var(--text); margin-bottom: 20px; border: 1px solid color-mix(in srgb, var(--primary) 20%, transparent); flex-wrap: wrap; }
.banner svg { color: var(--primary); }
.banner .grow { flex: 1; min-width: 200px; font-size: 13.5px; }

/* ============ Heatmap / compare ============ */
.heat td, .heat th { text-align: right; }
.heat td:first-child, .heat th:first-child { text-align: left; }
.heat .cell { display: inline-block; min-width: 76px; padding: 4px 8px; border-radius: 8px; font-weight: 600; }

/* ============ Empty state ============ */
.empty { text-align: center; padding: 60px 20px; }
.empty-art { width: 120px; height: 120px; margin: 0 auto 20px; border-radius: 32px; display: grid; place-items: center; font-size: 56px; background: linear-gradient(135deg, var(--primary-soft), color-mix(in srgb, var(--primary-2) 15%, var(--surface))); }
.empty h2 { margin: 0 0 6px; font-size: 22px; font-weight: 800; }
.empty p { margin: 0 auto 22px; color: var(--text-2); max-width: 440px; }
.empty .actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.empty-sm { text-align: center; color: var(--muted); padding: 28px 10px; font-size: 13px; }

/* ============ Settings ============ */
.settings-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); }
.cat-edit { display: grid; grid-template-columns: 54px 1fr 44px 36px; gap: 8px; align-items: center; margin-bottom: 8px; }
.cat-edit .input { padding: 8px 10px; }
.cat-edit .emoji { text-align: center; font-size: 18px; }
.cat-edit input[type="color"] { width: 44px; height: 38px; padding: 3px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.divider { height: 1px; background: var(--border); margin: 18px 0; }
.muted { color: var(--text-2); }
.small { font-size: 12.5px; }

/* ============ Toast ============ */
.toast-wrap { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 120; align-items: center; }
.toast { background: #0f172a; color: #fff; padding: 11px 16px; border-radius: 12px; box-shadow: var(--shadow-lg); font-weight: 600; font-size: 13.5px; display: flex; align-items: center; gap: 10px; animation: toastIn .25s cubic-bezier(.2,.9,.3,1.2); }
.toast svg { color: #34d399; }
.toast.err svg { color: #fb7185; }
@keyframes toastIn { from { transform: translateY(12px); opacity: 0; } }

/* ============ Responsive ============ */
@media (max-width: 1200px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row-2, .row-2b, .settings-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; width: 272px; transform: translateX(-100%); transition: transform .25s ease; }
  .sidebar.open { transform: none; }
  .scrim.show { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 35; }
  .menu-btn { display: inline-grid; }
  .main { padding: 0 16px 96px; }
  .topbar { flex-wrap: wrap; gap: 10px; }
  .topbar-title { flex: 1; min-width: 0; }
  .topbar-title p { display: none; }
  .topbar-actions { width: 100%; }
  .month-picker { flex: 1; justify-content: space-between; }
  #addBtn { display: none; }
  .fab { display: grid; place-items: center; position: fixed; right: 20px; bottom: 20px; width: 58px; height: 58px; border-radius: 18px; border: 0; color: #fff; background: linear-gradient(135deg, #6366f1, #7c3aed); box-shadow: 0 14px 30px -10px rgba(99,102,241,1); z-index: 50; }
  .fab svg { width: 26px; height: 26px; }
}
@media (max-width: 560px) {
  .kpis { grid-template-columns: minmax(0, 1fr); }
  .donut-wrap { grid-template-columns: 1fr; }
  .donut-wrap .chart { max-width: 220px; margin: 0 auto; }
  .form-grid { grid-template-columns: 1fr; }
  .kpi-value { font-size: 23px; }
  .hide-sm { display: none; }
}

/* ============ Demo mode ============ */
.demo-banner {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 16px 0 0; padding: 12px 16px; border-radius: 14px;
  color: #fff; background: linear-gradient(90deg, #f59e0b, #ea580c); box-shadow: 0 10px 24px -12px rgba(234,88,12,.8); font-size: 13.5px;
}
.demo-banner[hidden] { display: none; }
.demo-banner .grow { flex: 1; min-width: 200px; }
.demo-dot { width: 10px; height: 10px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 4px rgba(255,255,255,.3); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(255,255,255,0); } }
.demo-banner-btn { background: rgba(255,255,255,.18); color: #fff; border-color: rgba(255,255,255,.35); }
.demo-banner-btn:hover { background: rgba(255,255,255,.28); }
.demo-banner-btn.solid { background: #fff; color: #c2410c; }

/* ============ Profiles ============ */
.avatar {
  --c: #6366f1;
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-size: 19px; flex-shrink: 0;
  background: radial-gradient(circle at 30% 25%, color-mix(in srgb, var(--c) 55%, #fff), var(--c));
  box-shadow: 0 6px 16px -6px var(--c), inset 0 0 0 2px rgba(255,255,255,.25);
}
.avatar.lg { width: 60px; height: 60px; font-size: 30px; }
.avatar.xl { width: 96px; height: 96px; font-size: 46px; }
.avatar.add { background: transparent; border: 2px dashed var(--picker-line); box-shadow: none; color: var(--picker-muted); }
.avatar.add svg { width: 34px; height: 34px; }

.user-chip { display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 12px; border-radius: 14px; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.08); }
.user-chip[hidden] { display: none; }
.user-chip-text { flex: 1; min-width: 0; }
.user-chip-text small { display: block; font-size: 11px; color: #8f92c4; }
.user-chip-text b { display: block; color: #fff; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-switch { width: 32px; height: 32px; border-radius: 9px; border: 0; display: grid; place-items: center; background: rgba(255,255,255,.08); color: #c7c9e8; }
.user-switch:hover { background: rgba(255,255,255,.16); color: #fff; }
.user-switch[hidden] { display: none; }

body.locked { overflow: hidden; }
.picker {
  --picker-line: rgba(255,255,255,.28); --picker-muted: #a9acd6;
  position: fixed; inset: 0; z-index: 70; overflow: auto; color: #fff; display: grid; place-items: center; padding: 40px 16px;
  background:
    radial-gradient(60% 50% at 15% 10%, rgba(99,102,241,.45), transparent 70%),
    radial-gradient(50% 45% at 90% 90%, rgba(168,85,247,.35), transparent 70%),
    #0b0c22;
  animation: fadeIn .2s;
}
.picker[hidden] { display: none; }
.picker-inner { width: 100%; max-width: 860px; text-align: center; animation: pop .25s cubic-bezier(.2,.9,.3,1.2); }
.picker-inner.narrow { max-width: 420px; }
.picker-brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 15px; color: #c7c9e8; margin-bottom: 26px; }
.picker-brand .brand-logo { width: 36px; height: 36px; border-radius: 10px; }
.picker-brand .brand-logo svg { width: 19px; height: 19px; }
.picker h1 { margin: 0 0 8px; font-size: 32px; font-weight: 800; letter-spacing: -.02em; }
.picker-sub { margin: 0 0 34px; color: var(--picker-muted); font-size: 15px; }
.profiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 18px; }
.profile {
  width: 168px; padding: 24px 12px 18px; border-radius: 20px; border: 1px solid rgba(255,255,255,.1); background: rgba(255,255,255,.04);
  color: #fff; display: flex; flex-direction: column; align-items: center; gap: 6px; transition: transform .15s, background .15s, border-color .15s;
}
.profile:hover { transform: translateY(-4px); background: rgba(255,255,255,.09); border-color: rgba(255,255,255,.25); }
.profile .avatar { margin-bottom: 8px; }
.profile b { font-size: 16px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile small { font-size: 12px; color: var(--picker-muted); }
.picker-demo { margin-top: 34px; display: inline-flex; align-items: center; gap: 8px; border: 1px solid rgba(251,191,36,.45); background: rgba(251,191,36,.1); color: #fcd34d; padding: 10px 18px; border-radius: 99px; font-weight: 700; }
.picker-demo:hover { background: rgba(251,191,36,.2); }
.picker-form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.picker .field label { color: #c7c9e8; }
.picker .input { background: rgba(255,255,255,.07); border-color: rgba(255,255,255,.15); color: #fff; }
.picker .input::placeholder { color: #7d80b0; }
.picker .btn-ghost { background: transparent; border-color: rgba(255,255,255,.2); color: #fff; }
.picker .btn-ghost:hover { background: rgba(255,255,255,.08); }
.picker .form-error { color: #fda4af; text-align: center; margin: 0; }
.pin-input { text-align: center; font-size: 28px !important; letter-spacing: .5em; padding: 14px !important; font-weight: 800; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.sw-emoji { width: 40px; height: 40px; border-radius: 12px; border: 1.5px solid var(--border); background: var(--surface-2); font-size: 20px; display: grid; place-items: center; }
.picker .sw-emoji { border-color: rgba(255,255,255,.12); background: rgba(255,255,255,.05); }
.sw-emoji.sel { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 30%, transparent); }
.picker .sw-emoji.sel { border-color: #a5b4fc; }
.sw-color { width: 30px; height: 30px; border-radius: 50%; border: 0; box-shadow: inset 0 0 0 2px rgba(255,255,255,.3); }
.sw-color.sel { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px currentColor; color: var(--text); }
.picker .sw-color.sel { box-shadow: 0 0 0 3px #0b0c22, 0 0 0 5px #fff; }
@media (max-width: 560px) {
  .picker h1 { font-size: 25px; }
  .profile { width: calc(50% - 9px); }
  .avatar.xl { width: 80px; height: 80px; font-size: 38px; }
}
.cat-label { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.cat-search { width: 180px; padding: 6px 10px; font-size: 12.5px; }
.cat-opt[hidden] { display: none; }
.cat-grid { max-height: 240px; }

/* ============ Inline new category (expense form) ============ */
.cat-tools { display: flex; gap: 8px; align-items: center; }
.cat-tools .btn-sm { padding: 6px 10px; }
.cat-tools .btn-sm svg { width: 15px; height: 15px; }
.cat-add { border-style: dashed; color: var(--primary); background: transparent; }
.cat-add .e { display: grid; place-items: center; height: 24px; }
.cat-add svg { width: 20px; height: 20px; }
.cat-add:hover { border-color: var(--primary); background: var(--primary-soft); }
.new-cat {
  border: 1.5px solid color-mix(in srgb, var(--primary) 45%, var(--border)); background: var(--primary-soft);
  border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 10px; animation: fade .2s ease;
}
.new-cat[hidden] { display: none; }
.new-cat-row { display: grid; grid-template-columns: 54px 1fr 44px; gap: 8px; }
.new-cat-row .emoji { text-align: center; font-size: 18px; padding: 8px 4px; }
.new-cat-row input[type="color"] { width: 44px; height: 42px; padding: 3px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.new-cat-emojis { display: flex; flex-wrap: wrap; gap: 4px; }
.new-cat-emojis button { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); font-size: 16px; display: grid; place-items: center; }
.new-cat-emojis button:hover { border-color: var(--primary); }
.new-cat-actions { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.new-cat-actions .form-error { margin-right: auto !important; min-height: 0; }
@media (max-width: 560px) {
  .cat-label { flex-wrap: wrap; }
  .cat-tools { width: 100%; }
  .cat-search { flex: 1; width: auto; }
}

/* ============ v2: accounts, family, recurring ============ */
.signout-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 14px; border-radius: 12px;
  border: 1px solid rgba(255,255,255,.1); background: transparent; color: #a9acd6; font-weight: 600;
}
.signout-btn:hover { background: rgba(255,255,255,.06); color: #fff; }
.donut-seg { transition: stroke-width .15s; }
.donut-seg:hover { stroke-width: 30px; }

.recurring-banner { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 25%, transparent); }
.recurring-banner > svg { color: var(--info); }
.rec-list { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow: auto; }
.rec-row { display: grid; grid-template-columns: 20px 36px 1fr auto; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; }
.rec-row input { width: 18px; height: 18px; accent-color: var(--primary); }
.rec-text { min-width: 0; }
.rec-text b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec-text small { color: var(--text-2); font-size: 12px; }
.rec-amt { font-weight: 800; }
tr.paused td { opacity: .55; }
.check-row { display: flex; gap: 12px; align-items: flex-start; padding: 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; }
.check-row.full { grid-column: 1 / -1; }
.check-row input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--primary); flex-shrink: 0; }
.check-row b { display: block; font-size: 13.5px; }
.check-row small { color: var(--text-2); font-size: 12px; }
.repeat-note { display: flex; gap: 8px; align-items: center; font-size: 12.5px; color: var(--info); background: var(--info-soft); padding: 10px 12px; border-radius: 10px; }

.people-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 20px; margin-bottom: 20px; }
.person-head { display: flex; gap: 12px; align-items: center; }
.person-head b { font-size: 15px; }
.person-head small { display: flex; align-items: center; gap: 4px; color: var(--text-2); font-size: 12px; }
.person-head small svg { width: 12px; height: 12px; }
.person-head .btn svg { width: 14px; height: 14px; }
.you { margin-left: 6px; font-size: 10.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--primary); background: var(--primary-soft); padding: 2px 7px; border-radius: 99px; }
.person-total { font-size: 24px; font-weight: 800; letter-spacing: -.02em; margin: 16px 0 10px; }
.person-top { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); font-size: 13px; color: var(--text-2); }
.person.private { background: repeating-linear-gradient(135deg, var(--surface), var(--surface) 10px, var(--surface-2) 10px, var(--surface-2) 20px); }

.picker-link { margin-top: 26px; border: 0; background: none; color: var(--picker-muted); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.picker-link:hover { color: #fff; }
.inline-save { display: flex; gap: 8px; }
.inline-save .input { flex: 1; }
.danger-zone { display: flex; gap: 14px; align-items: center; justify-content: space-between; padding: 14px; border-radius: 12px; border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); background: var(--danger-soft); }
.danger-zone b { color: var(--danger); }

.onboard { display: flex; flex-direction: column; gap: 10px; }
.onboard-step { display: grid; grid-template-columns: 32px 1fr; gap: 12px; align-items: center; text-align: left; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface-2); }
.onboard-step:hover { border-color: var(--primary); background: var(--primary-soft); }
.onboard-step > span { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; color: #fff; background: linear-gradient(135deg, #6366f1, #7c3aed); }
.onboard-step b { display: block; font-size: 14px; }
.onboard-step small { color: var(--text-2); font-size: 12.5px; }
kbd { font-family: inherit; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--border); background: var(--surface); }
@media (max-width: 560px) {
  .rec-row { grid-template-columns: 20px 1fr auto; }
  .rec-row .cat-ico { display: none; }
  .danger-zone { flex-direction: column; align-items: flex-start; }
}

/* ============ PIN field with show/hide ============ */
.pin-field { position: relative; }
.pin-field .input { width: 100%; padding-right: 46px; }
.pin-eye {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 34px; height: 34px; border: 0; border-radius: 8px;
  display: grid; place-items: center; background: transparent; color: var(--muted);
}
.pin-eye:hover { color: var(--text); background: var(--surface-2); }
.picker .pin-eye { color: #8f92c4; }
.picker .pin-eye:hover { color: #fff; background: rgba(255,255,255,.08); }
.pin-field .pin-input { padding-left: 46px !important; }
/* lets app.js detect (and undo) browser autofill in PIN boxes */
input[data-pin]:-webkit-autofill { animation-name: pinAutofill; animation-duration: 1ms; }
@keyframes pinAutofill { from { opacity: 1; } to { opacity: 1; } }

/* ============ v2.1: profile limit, deleted profiles ============ */
.profile.disabled { opacity: .55; cursor: not-allowed; }
.profile.disabled:hover { transform: none; background: rgba(255,255,255,.04); border-color: rgba(255,255,255,.1); }
.deleted-list { display: flex; flex-direction: column; gap: 8px; }
.deleted-row { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 12px; border: 1px dashed var(--border); background: var(--surface-2); }
.deleted-row .grow { flex: 1; min-width: 0; }
.deleted-row b { display: block; font-size: 13.5px; }
.deleted-row small { color: var(--text-2); font-size: 12px; }
