:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f0f3f9;
  --border: #dfe4ee;
  --text: #13213a;
  --muted: #5d6b82;
  --navy: #0b2545;
  --accent: #1f5fd6;
  --accent-soft: #e6eefc;
  --pos: #14804a;
  --pos-soft: #e3f4ea;
  --neg: #b42318;
  --neg-soft: #fdecea;
  --warn: #9a6200;
  --warn-soft: #fff4dc;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1420; --surface: #141d2c; --surface-2: #1a2537; --border: #2a3850; --text: #e6ecf5; --muted: #98a6bd;
    --navy: #0b2545; --accent: #6b9cff; --accent-soft: #1b2b4a; --pos: #4cc38a; --pos-soft: #12301f; --neg: #ff7b72;
    --neg-soft: #3a1714; --warn: #f0b429; --warn-soft: #3a2c0b; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; }
a { color: var(--accent); }
h1 { font-size: 26px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.container { max-width: 1180px; margin: 0 auto; padding: 24px 16px 64px; }
.loading { padding: 80px 0; text-align: center; color: var(--muted); }

/* Top bar */
.topbar { background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1180px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 20px; height: 56px; }
.brand { color: #fff; text-decoration: none; display: flex; align-items: center; gap: 8px; font-size: 16px; white-space: nowrap; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: #fff; color: var(--navy); display: grid; place-items: center; font-weight: 800; }
nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
nav a { color: #c8d4ea; text-decoration: none; padding: 8px 12px; border-radius: 8px; white-space: nowrap; font-size: 14px; }
nav a:hover { color: #fff; background: rgba(255,255,255,.08); }
nav a.active { color: #fff; background: rgba(255,255,255,.16); }
.topbar .btn.ghost { color: #fff; border-color: rgba(255,255,255,.3); }
@media (max-width: 760px) {
  .topbar-inner { flex-wrap: wrap; height: auto; padding: 8px 16px; gap: 8px; }
  nav { order: 3; width: 100%; flex: none; }
  .brand { flex: 1; }
}

/* Page header */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.grid { display: grid; gap: 16px; }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: 2fr 1fr; }
@media (max-width: 900px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g2, .g3 { grid-template-columns: 1fr; } }
@media (max-width: 480px) { .g4 { grid-template-columns: 1fr; } }
.stack > * + * { margin-top: 16px; }

.kpi .label { color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 28px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.kpi .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.kpi.hero { background: var(--navy); color: #fff; border-color: var(--navy); }
.kpi.hero .label, .kpi.hero .sub { color: #b9c7e0; }
.delta.up { color: var(--pos); } .delta.down { color: var(--neg); }
.kpi.hero .delta.up { color: #7ee2a8; } .kpi.hero .delta.down { color: #ffb4ab; }

/* Bars */
.bar-row { display: grid; grid-template-columns: minmax(120px, 1.4fr) 2fr minmax(80px, auto); gap: 10px; align-items: center; padding: 6px 0; font-size: 14px; }
.bar { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 5px; background: var(--accent); }
.bar.liab > span { background: var(--neg); }

/* Badges & status */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.plaid { background: var(--accent-soft); color: var(--accent); }
.badge.ok { background: var(--pos-soft); color: var(--pos); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--neg-soft); color: var(--neg); }
.callout { border-radius: var(--radius); padding: 12px 14px; font-size: 14px; }
.callout.warn { background: var(--warn-soft); color: var(--warn); }
.callout.info { background: var(--accent-soft); color: var(--text); }
.callout.ok { background: var(--pos-soft); color: var(--pos); }
.callout ul { margin: 6px 0 0; padding-left: 18px; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
tr.excluded td { opacity: .5; }
.table-wrap { overflow-x: auto; }

/* Statement */
.line-card { padding: 0; overflow: hidden; }
.line-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; gap: 12px; background: var(--surface); }
.line-head h3 { margin: 0; }
.line-total { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 16px; }
.line-body { border-top: 1px solid var(--border); }
.line-body .empty { padding: 12px 18px; color: var(--muted); font-size: 14px; }
.section-title { display: flex; justify-content: space-between; align-items: baseline; margin: 28px 0 12px; }
.section-title h2 { margin: 0; }

/* Forms */
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; color: var(--text); }
input, select, textarea { width: 100%; font: inherit; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
textarea { min-height: 70px; resize: vertical; }
.field { margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; font-size: 14px; margin-bottom: 8px; }
.check input { width: auto; }
.req::after { content: " *"; color: var(--neg); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; font-size: 14px; padding: 9px 16px; border-radius: 8px; border: 1px solid transparent; cursor: pointer; text-decoration: none; background: var(--accent); color: #fff; white-space: nowrap; }
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.ghost { background: transparent; color: var(--accent); border-color: var(--border); }
.btn.danger { background: var(--neg); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Auth */
.auth-wrap { min-height: calc(100vh - 48px); display: grid; place-items: center; }
.auth-card { width: 100%; max-width: 420px; }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; font-size: 18px; }
.auth-brand .brand-mark { background: var(--navy); color: #fff; }
.err { color: var(--neg); font-size: 14px; margin: 8px 0; min-height: 1px; }
.qr { display: block; margin: 12px auto; border-radius: 8px; background: #fff; padding: 6px; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; font-family: ui-monospace, Menlo, Consolas, monospace; background: var(--surface-2); padding: 12px; border-radius: 8px; margin: 10px 0; }
code.secret { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; word-break: break-all; background: var(--surface-2); padding: 2px 6px; border-radius: 4px; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(9, 15, 28, .55); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 620px; max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal-head { padding: 18px 20px 0; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.modal-body { padding: 16px 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.x { background: none; border: 0; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); }

/* Connect cards */
.connect { display: flex; flex-direction: column; gap: 8px; }
.connect .icon { width: 36px; height: 36px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 800; }

/* Chart */
.chart svg { width: 100%; height: 220px; display: block; }
.chart .axis { stroke: var(--border); }
.chart .lbl { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; }
.chart .area { fill: var(--accent); opacity: .08; }
.chart .dot { fill: var(--accent); }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 60; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; }
#toast.error { background: var(--neg); }
.line-body table { table-layout: fixed; min-width: 560px; }
.line-body th:nth-child(1) { width: 40%; }
.line-body th:nth-child(2) { width: 22%; }
.line-body th:nth-child(3) { width: 10%; }
.line-body th:nth-child(4) { width: 14%; }
.line-body th:nth-child(5) { width: 14%; }
.line-body td { overflow: hidden; text-overflow: ellipsis; }
.line-body td:nth-child(2) .badge { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
