:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --text: #14202e;
  --muted: #5d6b7c;
  --border: #e1e6ed;
  --brand: #005aa4;
  --brand-ink: #ffffff;
  --pos: #12805c;
  --neg: #c0392b;
  --warn-bg: #fff6e0;
  --warn-ink: #7a5300;
  --err-bg: #fdecea;
  --err-ink: #9b2c22;
  --shadow: 0 1px 2px rgba(16, 32, 48, 0.06), 0 2px 8px rgba(16, 32, 48, 0.04);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e141b;
    --surface: #151d27;
    --surface-2: #1c2633;
    --text: #e6edf5;
    --muted: #93a2b4;
    --border: #253141;
    --brand: #3d8fe0;
    --pos: #3cc48f;
    --neg: #f07163;
    --warn-bg: #3a2f12;
    --warn-ink: #f3d68a;
    --err-bg: #3d1c19;
    --err-ink: #f7b0a8;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
main { max-width: 1200px; margin: 0 auto; padding: 16px; }
h1 { font-size: clamp(24px, 4vw, 34px); line-height: 1.15; margin: 0 0 12px; }
h2 { font-size: 16px; margin: 0; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
[hidden] { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.logo {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: var(--brand); color: var(--brand-ink); font-size: 13px;
}
.controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.badge { background: var(--warn-bg); color: var(--warn-ink); font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 99px; }

.btn, select, input[type="search"], input[type="number"] {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 9px; padding: 7px 12px;
}
.btn { cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; min-width: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.hint { color: var(--muted); font-size: 13px; }

.landing { display: grid; place-items: center; min-height: 60vh; }
.hero { max-width: 640px; padding: 32px; }
.hero p { color: var(--muted); }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 20px 0 8px; }

.notice { background: var(--warn-bg); color: var(--warn-ink); padding: 10px 14px; border-radius: 10px; font-size: 14px; }
.notice.error { background: var(--err-bg); color: var(--err-ink); }

.loading { display: flex; gap: 12px; align-items: center; justify-content: center; min-height: 50vh; color: var(--muted); }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--brand); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 0; }
.kpi { display: flex; flex-direction: column; gap: 2px; }
.kpi .label { color: var(--muted); font-size: 13px; font-weight: 600; }
.kpi .value { font-size: clamp(20px, 2.6vw, 28px); font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 13px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

.grid.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid.two > .card { margin-bottom: 16px; }
.chart-wrap { position: relative; height: 260px; }
.chart-wrap.small { height: 220px; width: 220px; flex: none; }
.cat-layout { display: flex; gap: 16px; align-items: center; }
.cat-list { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 0; max-height: 240px; overflow: auto; }
.cat-list li { display: flex; align-items: center; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--border); font-size: 14px; cursor: pointer; }
.cat-list li:last-child { border-bottom: 0; }
.cat-list .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.cat-list .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-list .amt { font-variant-numeric: tabular-nums; font-weight: 600; }
.cat-list .pct { color: var(--muted); width: 40px; text-align: right; font-size: 13px; }

.budget { padding: 8px 0; border-bottom: 1px solid var(--border); }
.budget:last-child { border-bottom: 0; }
.budget-row { display: flex; align-items: center; gap: 10px; justify-content: space-between; font-size: 14px; }
.budget-row .name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.budget-row input { width: 110px; padding: 4px 8px; text-align: right; }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; margin-top: 6px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--pos); border-radius: 99px; }
.bar.warn > span { background: #e0a100; }
.bar.over > span { background: var(--neg); }
.budget .meta { color: var(--muted); font-size: 12px; margin-top: 3px; }

.subs { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow: auto; }
.subs li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.subs li:last-child { border-bottom: 0; }
.subs .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.subs .meta { color: var(--muted); font-size: 12px; font-weight: 400; }
.subs .amt { font-variant-numeric: tabular-nums; font-weight: 600; }
.tag { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }

.accounts { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.account { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.account .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account .num { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.account .bal { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 4px; }
.account .avail { color: var(--muted); font-size: 12px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters input[type="search"] { width: 180px; }
.table-wrap { overflow-x: auto; }
table.tx { width: 100%; border-collapse: collapse; font-size: 14px; }
.tx th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; padding: 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tx td { padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tx td.date { white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }
.tx td.desc { min-width: 180px; }
.tx td.desc .main { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.tx td.desc .main img { width: 20px; height: 20px; border-radius: 5px; object-fit: contain; background: #fff; }
.tx td.desc .msg { color: var(--muted); font-size: 12px; }
.tx td.acct { color: var(--muted); white-space: nowrap; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
.table-foot { display: flex; align-items: center; justify-content: space-between; padding-top: 10px; color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); padding: 16px 0; text-align: center; }

footer { text-align: center; color: var(--muted); font-size: 12px; padding: 24px 16px 32px; }

@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid.two { grid-template-columns: 1fr; gap: 0; }
}
@media (max-width: 560px) {
  .kpis { gap: 10px; }
  .kpi { padding: 12px; }
  .cat-layout { flex-direction: column; align-items: stretch; }
  .chart-wrap.small { width: 100%; }
  .filters input[type="search"] { width: 100%; }
  .tx th:nth-child(4), .tx td.acct { display: none; }
  .hero { padding: 22px; }
}
