/* Personal Finance Command Center — styles */
:root {
  --bg: #f3f5fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e5e8f0;
  --border-strong: #d4d9e4;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --sidebar: #0c1324;
  --sidebar-2: #151e33;
  --sidebar-text: #aab4c8;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --income: #059669;
  --income-soft: #ecfdf5;
  --expense: #e11d48;
  --expense-soft: #fff1f2;
  --savings: #2563eb;
  --savings-soft: #eff6ff;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 2px 8px rgba(15, 23, 42, .04);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, .18);
  --font: "Segoe UI", -apple-system, BlinkMacSystemFont, "Inter", Roboto, "Helvetica Neue", Arial, sans-serif;
  --sidebar-w: 252px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 16px; font-weight: 650; }
p { margin: 0; }
a { color: var(--accent); }
code { font-family: Consolas, "SFMono-Regular", Menlo, monospace; font-size: .9em; background: rgba(15,23,42,.06); padding: 1px 5px; border-radius: 5px; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.text-income { color: var(--income); }
.text-expense { color: var(--expense); }
.text-savings { color: var(--savings); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }

/* ---------------------------------------------------------------- layout */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  background: linear-gradient(180deg, var(--sidebar) 0%, #0f1830 100%);
  color: var(--sidebar-text);
  display: flex; flex-direction: column; padding: 22px 16px;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 26px; color: #fff; }
.brand-mark { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: linear-gradient(135deg, #6366f1, #4f46e5 60%, #2563eb); box-shadow: 0 6px 18px rgba(79,70,229,.45); }
.brand-mark svg { width: 20px; height: 20px; color: #fff; stroke-width: 2.4; }
.brand-text { font-size: 14.5px; line-height: 1.2; color: #cbd5e1; }
.brand-text strong { display: block; color: #fff; font-size: 16px; font-weight: 700; letter-spacing: .2px; }
.nav { display: flex; flex-direction: column; gap: 3px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  color: var(--sidebar-text); text-decoration: none; font-weight: 500; font-size: 14.5px;
  transition: background .15s, color .15s;
}
.nav a:hover { background: rgba(255,255,255,.05); color: #e2e8f0; }
.nav a.active { background: rgba(99,102,241,.18); color: #fff; box-shadow: inset 3px 0 0 #818cf8; }
.nav a.active svg { color: #a5b4fc; }
.nav-badge { margin-left: auto; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; border-radius: 999px; padding: 1px 7px; }
.sidebar-note { margin-top: auto; display: flex; gap: 10px; padding: 14px; border-radius: 12px; background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.06); font-size: 12.5px; line-height: 1.45; }
.sidebar-note svg { width: 16px; height: 16px; margin-top: 2px; color: #818cf8; }
.sidebar-note strong { color: #e2e8f0; }
.sidebar-note a { color: #a5b4fc; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 18px 32px; background: rgba(243,245,250,.88); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 22px; font-weight: 700; letter-spacing: -.2px; }
.topbar-title p { font-size: 13.5px; margin-top: 2px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.month-switcher { display: flex; align-items: center; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 11px; padding: 4px; box-shadow: var(--shadow); }
.month-switcher.is-hidden { display: none; }
.month-label { min-width: 118px; text-align: center; font-weight: 600; font-size: 14px; font-variant-numeric: tabular-nums; }
#content { padding: 24px 32px 48px; display: flex; flex-direction: column; gap: 20px; }
.view { display: flex; flex-direction: column; gap: 20px; animation: fadeUp .25s ease both; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.notices { padding: 0 32px; display: flex; flex-direction: column; gap: 10px; }
.notices:not(:empty) { padding-top: 16px; }

.grid { display: grid; gap: 20px; }
.grid-dash-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid-dash-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn svg { width: 17px; height: 17px; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 4px 12px rgba(79,70,229,.25); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-ghost { background: var(--surface); color: var(--text-2); border-color: var(--border-strong); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); border-color: #c2c9d6; color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; }
.icon-btn {
  width: 34px; height: 34px; display: inline-grid; place-items: center; border-radius: 8px;
  border: 0; background: transparent; color: var(--text-2); cursor: pointer; transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.icon-btn svg { width: 17px; height: 17px; }
.link-btn { font-size: 13px; font-weight: 600; text-decoration: none; color: var(--accent); white-space: nowrap; }
.link-btn:hover { text-decoration: underline; }
button.link-btn { background: none; border: 0; padding: 0; cursor: pointer; font: inherit; font-size: 13px; font-weight: 600; }
:focus-visible { outline: 3px solid rgba(79,70,229,.45); outline-offset: 2px; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-btn:focus-within { outline: 3px solid rgba(79,70,229,.45); outline-offset: 2px; }

/* ---------------------------------------------------------------- cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card-head p { margin-top: 3px; }
.card-danger { border-color: #fecaca; }
.card-danger h2 { color: var(--danger); }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stats-grid.stats-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 18px 16px; box-shadow: var(--shadow);
}
.stat::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--tone, var(--accent)); }
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stat-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.stat-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: var(--tone, var(--accent)); background: var(--tone-soft, var(--accent-soft)); }
.stat-icon svg { width: 18px; height: 18px; }
.stat-value { font-size: 26px; font-weight: 700; letter-spacing: -.5px; margin-top: 8px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-foot { font-size: 12.5px; color: var(--muted); margin-top: 4px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tone-income { --tone: var(--income); --tone-soft: var(--income-soft); }
.tone-expense { --tone: var(--expense); --tone-soft: var(--expense-soft); }
.tone-savings { --tone: var(--savings); --tone-soft: var(--savings-soft); }
.tone-balance { --tone: var(--accent); --tone-soft: var(--accent-soft); }
.tone-warning { --tone: var(--warning); --tone-soft: var(--warning-soft); }
.tone-danger { --tone: var(--danger); --tone-soft: var(--danger-soft); }
.delta { display: inline-flex; align-items: center; gap: 3px; font-weight: 600; padding: 1px 7px; border-radius: 999px; font-size: 12px; }
.delta svg { width: 13px; height: 13px; }
.delta.good { color: var(--income); background: var(--income-soft); }
.delta.bad { color: var(--expense); background: var(--expense-soft); }
.delta.neutral { color: var(--muted); background: var(--surface-2); }

/* ---------------------------------------------------------------- charts */
.chart-box { position: relative; width: 100%; }
.chart-lg { height: 290px; }
.chart-md { height: 280px; margin-bottom: 18px; }
.chart-donut { height: 220px; width: 220px; max-width: 100%; flex-shrink: 0; }
.chart-fallback { display: grid; place-items: center; height: 100%; text-align: center; color: var(--muted); font-size: 13px; border: 1px dashed var(--border-strong); border-radius: 10px; padding: 12px; }
.legend-inline { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.legend-inline .dot { margin-left: 6px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.dot-income { background: var(--income); }
.dot-expense { background: var(--expense); }
.dot-savings { background: var(--savings); }
.breakdown { display: flex; align-items: center; gap: 24px; }
.breakdown-legend { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 9px; }
.breakdown-legend li { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto auto; align-items: center; gap: 10px; font-size: 13.5px; }
.breakdown-legend .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.breakdown-legend .pct { color: var(--muted); font-size: 12.5px; min-width: 38px; text-align: right; }

/* savings ring */
.ring-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; padding-top: 4px; }
.ring { --p: 0; --ring-color: var(--savings); width: 168px; height: 168px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--ring-color) calc(var(--p) * 1%), #e8edf6 0); transition: --p .6s; }
.ring-inner { width: 132px; height: 132px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; text-align: center; }
.ring-pct { font-size: 28px; font-weight: 700; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.ring-cap { font-size: 12px; color: var(--muted); margin-top: -4px; }
.ring-meta { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ring-meta div { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; }
.ring-meta span { display: block; font-size: 12px; color: var(--muted); }
.ring-meta strong { font-variant-numeric: tabular-nums; font-size: 15px; }

/* ---------------------------------------------------------------- progress */
.progress { height: 8px; border-radius: 999px; background: #e8edf6; overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--bar, var(--accent)); width: 0; transition: width .6s cubic-bezier(.2,.8,.2,1); }
.progress.lg { height: 10px; }
.bar-ok { --bar: var(--income); }
.bar-warning { --bar: var(--warning); }
.bar-over { --bar: var(--danger); }
.bar-none { --bar: #94a3b8; }
.bar-full { --bar: #6366f1; }
.bar-savings { --bar: var(--savings); }

/* mini budget list on dashboard */
.mini-list { display: flex; flex-direction: column; gap: 14px; }
.mini-row-top { display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px; margin-bottom: 6px; }
.mini-row-top .name { font-weight: 600; color: var(--text-2); display: flex; align-items: center; gap: 8px; min-width: 0; }
.mini-row-top .name span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-row-top .val { color: var(--muted); font-size: 12.5px; }

/* ---------------------------------------------------------------- badges & chips */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; letter-spacing: .3px; text-transform: uppercase; padding: 2px 7px; border-radius: 6px; line-height: 1.4; white-space: nowrap; }
.badge-demo { background: #fef3c7; color: #92400e; }
.badge-income { background: var(--income-soft); color: var(--income); }
.badge-expense { background: var(--expense-soft); color: var(--expense); }
.badge-savings { background: var(--savings-soft); color: var(--savings); }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.chip svg { width: 13px; height: 13px; }
.chip-ok { background: var(--income-soft); color: var(--income); }
.chip-warning { background: var(--warning-soft); color: var(--warning); }
.chip-over { background: var(--danger-soft); color: var(--danger); }
.chip-full { background: var(--accent-soft); color: var(--accent); }
.chip-none { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.chip-done { background: var(--income-soft); color: var(--income); }

/* ---------------------------------------------------------------- callouts / notices */
.callout { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: 12px; border: 1px solid; font-size: 14px; line-height: 1.55; }
.callout svg { width: 19px; height: 19px; margin-top: 2px; }
.callout-info { background: var(--accent-soft); border-color: #c7d2fe; color: #3730a3; }
.callout-warning { background: var(--warning-soft); border-color: #fde68a; color: #78350f; }
.callout-danger { background: var(--danger-soft); border-color: #fecaca; color: #7f1d1d; }
.callout-demo { background: #fffbeb; border-color: #fde68a; color: #78350f; align-items: center; }
.callout .callout-body { flex: 1; min-width: 0; }
.callout .callout-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.callout ul { margin: 6px 0 0; padding-left: 18px; }

/* ---------------------------------------------------------------- tables */
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface-2); }
th:first-child { border-top-left-radius: 8px; }
th:last-child { border-top-right-radius: 8px; }
td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: #fafbfe; }
tbody tr:last-child td { border-bottom: 0; }
.ta-r { text-align: right; }
.tx-desc { font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tx-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.tx-amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.tx-amount.income { color: var(--income); }
.tx-amount.expense { color: var(--expense); }
.tx-amount.savings { color: var(--savings); }
.tx-actions { display: flex; justify-content: flex-end; gap: 2px; }
.cat-cell { display: flex; align-items: center; gap: 8px; white-space: nowrap; }

/* transaction filters */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.search-field { position: relative; flex: 1 1 240px; display: block; }
.search-field svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 17px; height: 17px; }
.search-field input { padding-left: 38px; }
.field-inline { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); flex: 0 1 auto; }
.field-inline select { min-width: 140px; }
.tx-summary { display: flex; flex-wrap: wrap; gap: 8px 18px; font-size: 13px; color: var(--muted); padding: 10px 2px 14px; border-top: 1px solid var(--border); }
.tx-summary strong { color: var(--text); font-variant-numeric: tabular-nums; }

/* compact list (recent transactions) */
.compact-list { list-style: none; margin: 0; padding: 0; }
.compact-list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.compact-list li:last-child { border-bottom: 0; }
.tx-icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0; }
.tx-icon svg { width: 17px; height: 17px; }
.tx-icon.income { background: var(--income-soft); color: var(--income); }
.tx-icon.expense { background: var(--expense-soft); color: var(--expense); }
.tx-icon.savings { background: var(--savings-soft); color: var(--savings); }
.compact-list .body { flex: 1; min-width: 0; }
.compact-list .title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.compact-list .meta { font-size: 12.5px; color: var(--muted); }

/* ---------------------------------------------------------------- forms */
input, select, textarea {
  font: inherit; font-size: 14px; color: var(--text);
  width: 100%; height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
select { padding-right: 32px; appearance: none; -webkit-appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; }
input:hover, select:hover { border-color: #b8c0cf; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,70,229,.15); }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(220,38,38,.1); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span, .field-label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--muted); }
.field .error { font-size: 12.5px; color: var(--danger); font-weight: 500; display: flex; gap: 5px; align-items: center; }
.field .error:empty { display: none; }
.money-input { position: relative; }
.money-input::before { content: "RM"; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-size: 13px; font-weight: 600; color: var(--muted); pointer-events: none; }
.money-input input { padding-left: 42px; font-variant-numeric: tabular-nums; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.segmented span { display: flex; align-items: center; justify-content: center; gap: 6px; height: 36px; border-radius: 8px; font-size: 13.5px; font-weight: 600; color: var(--muted); cursor: pointer; transition: background .15s, color .15s, box-shadow .15s; text-align: center; line-height: 1.15; }
.segmented input:checked + span { background: var(--surface); box-shadow: var(--shadow); }
.segmented input:focus-visible + span { outline: 3px solid rgba(79,70,229,.45); }
.segmented input[value="income"]:checked + span { color: var(--income); }
.segmented input[value="expense"]:checked + span { color: var(--expense); }
.segmented input[value="savings"]:checked + span { color: var(--savings); }
.form-note { font-size: 12.5px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.form-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; flex-wrap: wrap; }
.sticky-actions { position: sticky; bottom: 0; background: rgba(243,245,250,.92); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); padding: 12px 0; z-index: 5; }
.sticky-actions .muted { margin-right: auto; }
.sticky-actions.dirty #budget-dirty-note { color: var(--warning); font-weight: 600; }

/* ---------------------------------------------------------------- budgets */
.budget-list { display: flex; flex-direction: column; }
.budget-row { display: grid; grid-template-columns: minmax(150px, 1.3fr) 150px repeat(3, minmax(90px, .8fr)) minmax(150px, 1.2fr); gap: 16px; align-items: center; padding: 14px 4px; border-bottom: 1px solid var(--border); }
.budget-row:last-child { border-bottom: 0; }
.budget-row.head { padding-top: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; }
.budget-row.is-over { background: linear-gradient(90deg, rgba(254,242,242,.8), transparent); border-radius: 8px; }
.budget-name { display: flex; align-items: center; gap: 10px; font-weight: 600; min-width: 0; }
.budget-name .dot { width: 11px; height: 11px; }
.budget-cell { font-variant-numeric: tabular-nums; font-size: 14px; white-space: nowrap; }
.budget-cell .lbl { display: none; }
.budget-progress { display: flex; flex-direction: column; gap: 6px; }
.budget-progress-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12.5px; }
.budget-input .error { font-size: 12px; color: var(--danger); margin-top: 4px; }
.budget-input .error:empty { display: none; }
.savings-target-row { display: grid; grid-template-columns: 220px 1fr; gap: 20px; align-items: center; }

/* ---------------------------------------------------------------- goals */
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.stats-inline { display: flex; gap: 22px; flex-wrap: wrap; font-size: 13.5px; color: var(--muted); }
.stats-inline strong { display: block; font-size: 19px; color: var(--text); font-variant-numeric: tabular-nums; }
.goals-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.goal-card { display: flex; flex-direction: column; gap: 14px; }
.goal-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.goal-head h3 { font-size: 16px; font-weight: 650; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.goal-head p { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.goal-amounts { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.goal-amounts .saved { font-size: 22px; font-weight: 700; letter-spacing: -.4px; font-variant-numeric: tabular-nums; }
.goal-amounts .target { font-size: 13px; color: var(--muted); }
.goal-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-size: 12.5px; color: var(--muted); }
.goal-meta strong { display: block; color: var(--text); font-size: 14px; font-variant-numeric: tabular-nums; }
.goal-actions { display: flex; gap: 8px; margin-top: auto; padding-top: 4px; border-top: 1px solid var(--border); padding-top: 14px; }
.goal-actions .btn { flex: 1; }
.goal-mini { display: flex; flex-direction: column; gap: 14px; }

/* ---------------------------------------------------------------- data page */
.action-list { display: flex; flex-direction: column; }
.action-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.action-row:first-child { padding-top: 0; }
.action-row:last-child { border-bottom: 0; padding-bottom: 0; }
.action-row p { margin-top: 2px; }
.report-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------------------------------------------------------------- empty states */
.empty { text-align: center; padding: 34px 16px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 8px; }
.empty-icon { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); margin-bottom: 4px; }
.empty-icon svg { width: 24px; height: 24px; }
.empty h3 { color: var(--text); font-size: 15.5px; font-weight: 650; }
.empty p { font-size: 13.5px; max-width: 360px; }
.empty .btn { margin-top: 8px; }

/* ---------------------------------------------------------------- modal */
.modal-root { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: rgba(15,23,42,.5); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); animation: fadeIn .15s ease both; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal { width: 100%; max-width: 540px; max-height: calc(100vh - 40px); overflow: auto; background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-lg); animation: pop .18s cubic-bezier(.2,.9,.3,1.2) both; }
.modal.sm { max-width: 440px; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.97); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 20px 22px 0; }
.modal-head h2 { font-size: 18px; }
.modal-head p { margin-top: 3px; }
.modal-body { padding: 18px 22px; display: flex; flex-direction: column; gap: 14px; font-size: 14.5px; color: var(--text-2); }
.modal-body ul { margin: 0; padding-left: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px 20px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.confirm-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--danger-soft); color: var(--danger); }
.confirm-icon.info { background: var(--accent-soft); color: var(--accent); }
.confirm-icon svg { width: 22px; height: 22px; }
.summary-table td, .summary-table th { padding: 8px 10px; }

/* ---------------------------------------------------------------- toasts */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.toast { pointer-events: auto; display: flex; gap: 10px; align-items: center; min-width: 240px; max-width: 380px; padding: 12px 14px; border-radius: 12px; background: #0f172a; color: #fff; font-size: 14px; box-shadow: var(--shadow-lg); animation: toastIn .2s ease both; }
.toast.out { animation: toastOut .2s ease both; }
.toast svg { width: 18px; height: 18px; }
.toast.success svg { color: #34d399; }
.toast.error { background: #7f1d1d; }
.toast.error svg { color: #fecaca; }
.toast.info svg { color: #a5b4fc; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(10px); } }

/* ---------------------------------------------------------------- modes (local browser-only vs cloud account) */
body:not(.mode-cloud) .cloud-only { display: none !important; }
body:not(.mode-local) .local-only { display: none !important; }
/* Until the app has started (sign-in, loading, configuration errors) there is nothing to add to. */
body:not(.mode-local):not(.mode-cloud) .fab { display: none !important; }

/* ---------------------------------------------------------------- spinner, busy buttons */
.spinner { display: inline-block; width: 15px; height: 15px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; flex-shrink: 0; opacity: .85; }
.spinner.lg { width: 30px; height: 30px; border-width: 3px; color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }
.btn.is-busy { cursor: progress; opacity: .85; }
.btn-block { width: 100%; }

/* ---------------------------------------------------------------- boot screen */
.boot-screen { position: fixed; inset: 0; z-index: 300; display: grid; place-items: center; padding: 20px; background: var(--bg); }
.app.is-locked { filter: blur(6px); pointer-events: none; user-select: none; }
.boot-screen:has(.boot-card.wide) { background: rgba(243,245,250,.9); }
.boot-card { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; color: var(--muted); font-size: 14.5px; }
.boot-card .brand-mark { width: 44px; height: 44px; border-radius: 12px; }
.boot-card .brand-mark svg { color: #fff; width: 22px; height: 22px; stroke-width: 2.4; }
.boot-card.wide { max-width: 520px; width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 28px; box-shadow: var(--shadow-lg); color: var(--text-2); }
.boot-card.wide h1 { font-size: 20px; color: var(--text); }
.boot-text { display: flex; flex-direction: column; gap: 10px; text-align: left; width: 100%; }
.boot-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 4px; }

/* ---------------------------------------------------------------- sign-in screens */
.auth-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(320px, 440px) minmax(0, 1fr); }
.auth-aside { background: linear-gradient(180deg, var(--sidebar) 0%, #0f1830 100%); color: var(--sidebar-text); padding: 32px 36px; display: flex; flex-direction: column; gap: 34px; }
.auth-aside .brand { padding: 0; }
.auth-pitch h2 { font-size: 26px; line-height: 1.2; color: #fff; font-weight: 700; letter-spacing: -.3px; }
.auth-pitch p { margin-top: 10px; font-size: 14.5px; line-height: 1.6; }
.auth-points { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 16px; font-size: 14px; line-height: 1.5; }
.auth-points li { display: flex; gap: 12px; }
.auth-points svg { color: #34d399; margin-top: 2px; }
.auth-points strong { color: #e2e8f0; }
.auth-main { display: grid; place-items: center; padding: 32px 20px; }
.auth-card { width: 100%; max-width: 410px; display: flex; flex-direction: column; gap: 16px; animation: fadeUp .25s ease both; }
.auth-card h1 { font-size: 25px; font-weight: 700; letter-spacing: -.3px; }
.auth-card > .muted { margin-top: -8px; font-size: 14.5px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.auth-row { display: flex; justify-content: flex-end; margin-top: -6px; }
.auth-foot { text-align: center; font-size: 14px; color: var(--muted); }
.auth-foot .link-btn { font-size: 14px; display: inline-flex; align-items: center; gap: 4px; }
.auth-foot .link-btn svg { width: 15px; height: 15px; }
.auth-divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12.5px; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.auth-notice { display: flex; gap: 10px; align-items: flex-start; padding: 11px 13px; border-radius: 11px; border: 1px solid; font-size: 13.5px; line-height: 1.5; }
.auth-notice svg { margin-top: 1px; }
.auth-notice.error { background: var(--danger-soft); border-color: #fecaca; color: #7f1d1d; }
.auth-notice.success { background: var(--income-soft); border-color: #a7f3d0; color: #065f46; }
.auth-notice.info { background: var(--accent-soft); border-color: #c7d2fe; color: #3730a3; }
.auth-icon { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.auth-icon svg { width: 24px; height: 24px; }
.auth-tips { margin: 0; padding-left: 18px; font-size: 13.5px; color: var(--text-2); display: flex; flex-direction: column; gap: 6px; }
.btn-google { width: 100%; height: 44px; background: #fff; color: #1f1f1f; border-color: #dadce0; font-weight: 600; gap: 10px; }
.btn-google:hover:not(:disabled) { background: #f8f9fa; border-color: #c6c9cf; }
.google-logo { width: 18px; height: 18px; stroke: none; }
.password-input { position: relative; }
.password-input input { padding-right: 44px; }
.password-input .icon-btn { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }

/* ---------------------------------------------------------------- account, sync status */
.avatar { width: 36px; height: 36px; border-radius: 50%; display: inline-grid; place-items: center; flex-shrink: 0;
  background: linear-gradient(135deg, #6366f1, #2563eb); color: #fff; font-weight: 700; font-size: 13.5px; letter-spacing: .3px; text-decoration: none; }
.avatar.lg { width: 52px; height: 52px; font-size: 18px; }
.avatar-btn:focus-visible { outline-offset: 3px; }
.user-chip { margin-top: auto; display: flex; align-items: center; gap: 11px; padding: 12px; border-radius: 12px; background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.06); text-decoration: none; color: var(--sidebar-text); transition: background .15s; }
.user-chip:hover { background: rgba(255,255,255,.08); }
.user-chip-text { display: flex; flex-direction: column; min-width: 0; font-size: 12.5px; line-height: 1.35; }
.user-chip-text strong { color: #fff; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip-text span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip-status { color: #6ee7b7; }
.sync-pill { display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font: inherit; font-size: 13px; font-weight: 600; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.sync-pill svg { width: 15px; height: 15px; }
.sync-pill .spinner { width: 13px; height: 13px; }
.sync-pill.ok svg { color: var(--income); }
.sync-pill.busy { color: var(--accent); }
.sync-pill.offline { background: var(--warning-soft); border-color: #fde68a; color: #92400e; }
.sync-pill.error { background: var(--danger-soft); border-color: #fecaca; color: var(--danger); }
.sync-pill:hover { border-color: var(--border-strong); }
.profile-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.detail-list { margin: 0 0 18px; display: flex; flex-direction: column; }
.detail-list > div { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.detail-list dt { color: var(--muted); font-weight: 600; font-size: 13px; }
.detail-list dd { margin: 0; overflow-wrap: anywhere; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form { display: flex; gap: 10px; align-items: flex-end; }
.inline-form .field { flex: 1; }
.inline-form .field .error:empty { display: none; }
.account-content { display: flex; flex-direction: column; gap: 20px; }

/* ---------------------------------------------------------------- import review */
.import-review { display: flex; flex-direction: column; gap: 14px; }
.compare-where { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.compare-where > div { border: 1px solid var(--border); border-radius: 11px; padding: 11px 12px; background: var(--surface-2); font-size: 13px; }
.compare-where p { margin-top: 4px; color: var(--muted); }
.where-label { display: flex; align-items: center; gap: 6px; font-weight: 650; color: var(--text); }
.where-label svg { width: 15px; height: 15px; color: var(--accent); }
.check-list { display: flex; flex-direction: column; gap: 10px; }
.check, .choice { display: flex; gap: 10px; align-items: flex-start; font-size: 13.5px; cursor: pointer; }
.check input, .choice input { width: 17px; height: 17px; margin: 2px 0 0; flex-shrink: 0; accent-color: var(--accent); }
.choice-list { display: flex; flex-direction: column; gap: 8px; }
.choice { border: 1px solid var(--border); border-radius: 11px; padding: 11px 12px; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice.danger:has(input:checked) { border-color: #fca5a5; background: var(--danger-soft); }
.choice small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.toast-action { margin-left: auto; background: rgba(255,255,255,.14); color: #fff; border: 0; border-radius: 8px; padding: 6px 10px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.toast-action:hover { background: rgba(255,255,255,.24); }

/* ---------------------------------------------------------------- mobile */
.bottom-nav, .fab { display: none; }

@media (max-width: 1200px) {
  .grid-dash-1 { grid-template-columns: minmax(0, 1fr); }
  #view-reports .grid-dash-2 { grid-template-columns: minmax(0, 1fr); }
  .ring-wrap { max-width: 440px; margin: 0 auto; }
  .breakdown { flex-direction: column; gap: 16px; }
  .breakdown-legend { width: 100%; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .budget-row { grid-template-columns: minmax(140px, 1.2fr) 130px repeat(3, minmax(80px, .8fr)) minmax(130px, 1fr); gap: 12px; }
}

@media (max-width: 960px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(6, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    background: rgba(255,255,255,.96); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 2px; border-radius: 10px; color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600; }
  .bottom-nav a svg { width: 21px; height: 21px; }
  .bottom-nav a.active { color: var(--accent); background: var(--accent-soft); }
  .fab {
    display: grid; place-items: center; position: fixed; right: 18px; bottom: calc(78px + env(safe-area-inset-bottom)); z-index: 60;
    width: 56px; height: 56px; border-radius: 18px; border: 0; background: var(--accent); color: #fff; cursor: pointer;
    box-shadow: 0 10px 24px rgba(79,70,229,.4);
  }
  .fab svg { width: 24px; height: 24px; stroke-width: 2.4; }
  #add-tx-btn { display: none; }
  .topbar { padding: 14px 20px; }
  #content { padding: 18px 20px 120px; }
  .notices { padding: 0 20px; }
  .toasts { bottom: 150px; left: 16px; right: 16px; align-items: center; }
  .grid-dash-1, .grid-dash-2 { grid-template-columns: minmax(0, 1fr); }
  .budget-row { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 14px; }
  .budget-row.head { display: none; }
  .budget-name { grid-column: 1 / -1; }
  .budget-input { grid-column: 1 / -1; }
  .budget-cell .lbl { display: block; font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; font-weight: 600; }
  .budget-progress { grid-column: 1 / -1; }
  .budget-row.is-over { background: rgba(254,242,242,.7); padding-left: 10px; padding-right: 10px; }
  .budget-cell.spent, .budget-cell.remaining, .budget-cell.pctc { grid-column: auto; }
  .sticky-actions { bottom: calc(66px + env(safe-area-inset-bottom)); }
  /* The budget form has its own sticky Save bar; the floating add button would cover it. */
  body[data-view="budgets"] .fab { display: none; }
}

@media (max-width: 720px) {
  body { font-size: 14.5px; }
  .topbar { padding: 12px 16px; }
  .topbar h1 { font-size: 19px; }
  .topbar-title p { display: none; }
  .topbar-actions { width: 100%; }
  .month-switcher { width: 100%; justify-content: space-between; }
  .month-label { flex: 1; }
  #content { padding: 16px 16px 120px; gap: 16px; }
  .view { gap: 16px; }
  .notices { padding: 0 16px; }
  .notices:not(:empty) { padding-top: 12px; }
  .card { padding: 16px; }
  .stats-grid, .stats-grid.stats-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .stat { padding: 14px; }
  .stat-value { font-size: 19px; letter-spacing: -.3px; }
  .stat-icon { width: 28px; height: 28px; border-radius: 8px; }
  .stat-icon svg { width: 15px; height: 15px; }
  .stat-label { font-size: 12px; }
  .stat-foot { font-size: 11.5px; }
  .chart-lg { height: 240px; }
  .breakdown { flex-direction: column; gap: 16px; }
  .chart-donut { width: 200px; height: 200px; }
  .breakdown-legend { width: 100%; }
  .card-head { flex-wrap: wrap; }
  .filters { gap: 8px; }
  .search-field { flex-basis: 100%; }
  .field-inline { flex: 1 1 calc(50% - 4px); }
  .field-inline select { min-width: 0; }
  #f-reset { flex: 1 1 100%; }
  /* transaction table becomes cards */
  .tx-table thead { display: none; }
  .tx-table, .tx-table tbody, .tx-table tr, .tx-table td { display: block; width: 100%; }
  .tx-table tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; padding: 12px 2px; border-bottom: 1px solid var(--border); }
  .tx-table tbody tr:last-child { border-bottom: 0; }
  .tx-table td { padding: 0; border: 0; }
  .tx-table td.c-desc { grid-column: 1; grid-row: 1; }
  .tx-table td.c-amount { grid-column: 2; grid-row: 1; }
  .tx-table td.c-date { grid-column: 1; grid-row: 2; font-size: 12.5px; color: var(--muted); }
  .tx-table td.c-actions { grid-column: 2; grid-row: 2 / span 2; align-self: end; }
  .tx-table td.c-cat { grid-column: 1; grid-row: 3; font-size: 12.5px; color: var(--muted); }
  .tx-table td.c-method, .tx-table td.c-type { display: none; }
  .tx-table .cat-cell .dot { width: 8px; height: 8px; }
  .form-grid { grid-template-columns: 1fr; }
  .modal-root { padding: 0; align-items: end; }
  .modal { max-width: none; border-radius: 18px 18px 0 0; max-height: 92vh; }
  .modal-foot .btn { flex: 1; }
  .goals-grid { grid-template-columns: minmax(0, 1fr); }
  .savings-target-row { grid-template-columns: 1fr; gap: 12px; }
  .action-row { flex-direction: column; align-items: stretch; }
  .action-row .btn { width: 100%; }
  .report-actions .btn { flex: 1 1 100%; }
  .callout-demo { flex-wrap: wrap; align-items: flex-start; }
  .callout-demo .callout-body { flex: 1 1 calc(100% - 32px); }
  .callout-demo .callout-actions, .callout .callout-actions { width: 100%; }
  .callout .callout-actions .btn { flex: 1; }
  .callout { flex-wrap: wrap; }
  .callout .callout-body { flex: 1 1 calc(100% - 32px); }
  .stats-grid.stats-3 > :last-child { grid-column: 1 / -1; }
  .sticky-actions .muted { flex-basis: 100%; }
  .sticky-actions .btn { flex: 1; }
  .ring { width: 150px; height: 150px; }
  .ring-inner { width: 118px; height: 118px; }
  .compare-table th:nth-child(4), .compare-table td:nth-child(4) { display: none; }
}

@media (max-width: 900px) {
  .auth-shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .auth-aside { padding: 18px 20px; gap: 0; }
  .auth-pitch, .auth-points { display: none; }
  .auth-main { place-items: start center; padding: 28px 20px 40px; }
}

@media (max-width: 720px) {
  /* Phone: sync status and account sit next to the page title; the month switcher keeps its full row. */
  .sync-pill span:not(.spinner) { display: none; }
  .sync-pill { position: absolute; top: 10px; right: 56px; width: 34px; padding: 0; justify-content: center; }
  .avatar-btn { position: absolute; top: 10px; right: 16px; width: 34px; height: 34px; font-size: 12.5px; }
  body.mode-cloud .topbar-title { padding-right: 84px; min-height: 34px; display: flex; align-items: center; }
  .detail-list > div { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .inline-form { flex-direction: column; align-items: stretch; }
  .compare-where { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 380px) {
  .stats-grid, .stats-grid.stats-3 { grid-template-columns: minmax(0, 1fr); }
  .month-switcher .btn { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
