:root {
  --bg: #F6F7F9;
  --card: #FFFFFF;
  --line: #E4E7EC;
  --line-soft: #F2F4F7;
  --ink: #101828;
  --ink-2: #344054;
  --muted: #5B6474;
  --accent: #1D4ED8;
  --accent-ink: #1E3A8A;
  --accent-soft: #EEF4FF;
  --pos: #067647;
  --pos-soft: #ECFDF3;
  --neg: #B42318;
  --neg-soft: #FEF3F2;
  --warn: #9A3412;
  --warn-soft: #FFF4ED;
  --amber: #F79009;
  --radius: 20px;
  --font: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Space Grotesk", Inter, system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.4; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
a:hover { color: var(--accent-ink); }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--display); font-weight: 600; margin: 0; }
h1 { font-size: 26px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.num { font-variant-numeric: tabular-nums; }
.bold { font-weight: 600; }
.display { font-family: var(--display); font-weight: 600; letter-spacing: -0.3px; }
.big { font-family: var(--display); font-weight: 600; font-size: 36px; letter-spacing: -0.5px; line-height: 1.1; }
.mid { font-family: var(--display); font-weight: 600; font-size: 26px; line-height: 1.15; }
.row { display: flex; align-items: center; gap: 10px; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.right { text-align: right; }
.hidden { display: none !important; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Buttons and fields ---------- */
.btn { height: 48px; padding: 0 18px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--accent-ink); color: #fff; }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.secondary { background: var(--card); color: var(--ink-2); border: 1px solid #D0D5DD; }
.btn.secondary:hover { background: var(--line-soft); color: var(--ink); }
.btn.danger { background: var(--card); color: var(--neg); border: 1px solid #FECDCA; }
.btn.danger:hover { background: var(--neg-soft); }
.btn.small { height: 40px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn.lg { height: 52px; font-size: 16px; border-radius: 14px; }
.icon-btn { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; color: var(--ink); flex: 0 0 auto; }
.icon-btn:hover { background: var(--line-soft); }
.link-btn { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 8px 0; font-weight: 600; min-height: 44px; }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.input, select.input, textarea.input { height: 48px; border: 1px solid #D0D5DD; border-radius: 12px; padding: 0 14px; font-size: 16px; color: var(--ink); background: var(--card); width: 100%; font-weight: 400; }
textarea.input { height: auto; min-height: 80px; padding: 12px 14px; }
.input:focus, select.input:focus, textarea.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 14px; color: var(--ink-2); cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.error { background: var(--neg-soft); border: 1px solid #FECDCA; color: #7A271A; border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.note { background: var(--accent-soft); border: 1px solid #C7D7FE; color: #1E3A8A; border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.warnbox { background: var(--warn-soft); border: 1px solid #FDDCAB; color: var(--warn); border-radius: 12px; padding: 10px 12px; font-size: 14px; }

.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; border-radius: 6px; padding: 3px 8px; background: var(--line-soft); color: var(--ink-2); white-space: nowrap; }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.ok { background: var(--pos-soft); color: #054F31; }
.chip.bad { background: var(--neg-soft); color: var(--neg); }
.chip.blue { background: var(--accent-soft); color: var(--accent-ink); }

.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { height: 36px; min-width: 52px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink-2); font-size: 13px; font-weight: 600; cursor: pointer; }
.pill.on { background: var(--ink); border-color: var(--ink); color: #fff; }

/* ---------- Cards and lists ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.card.tight { border-radius: 14px; padding: 12px; }
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tile .label { font-size: 12px; color: var(--muted); }
.tile .value { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list > * { border-bottom: 1px solid var(--line-soft); }
.list > *:last-child { border-bottom: 0; }
.item { width: 100%; border: 0; background: transparent; padding: 14px 16px; display: flex; align-items: center; gap: 12px; text-align: left; color: var(--ink); font-size: 15px; text-decoration: none; }
button.item, a.item { cursor: pointer; }
button.item:hover, a.item:hover { background: #FAFBFC; color: var(--ink); }
.item.pinned { background: #FAFBFF; }
.item .sub { font-size: 12px; color: var(--muted); }
.bar { height: 6px; border-radius: 3px; background: #EEF2F6; overflow: hidden; }
.bar > div { height: 6px; border-radius: 3px; background: var(--accent); }
.split-bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: #EEF2F6; }
.dot { width: 8px; height: 8px; border-radius: 2px; display: inline-block; flex: 0 0 auto; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; padding: 8px 2px 0; gap: 8px; }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }
.codes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 15px; }
.codes span { background: var(--line-soft); border-radius: 8px; padding: 8px; text-align: center; }
.qr { width: 200px; height: 200px; margin: 0 auto; background: #fff; padding: 6px; border-radius: 12px; border: 1px solid var(--line); }
.qr svg { width: 100%; height: 100%; display: block; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
table.table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); }
table.table td { padding: 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table-wrap { overflow-x: auto; }

/* ---------- Auth screens ---------- */
.auth { min-height: 100vh; display: flex; justify-content: center; background: var(--card); }
.auth-footer { margin-top: auto; text-align: center; padding-top: 8px; }
.auth-footer a { color: inherit; }
.auth-inner { width: 100%; max-width: 420px; padding: 72px 24px 32px; display: flex; flex-direction: column; gap: 24px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand img.wordmark { height: 36px; width: auto; max-width: 100%; display: block; }
.brand .name { font-family: var(--display); font-size: 22px; font-weight: 700; line-height: 1.1; }
@media (min-width: 720px) {
  .auth { background: var(--bg); align-items: center; }
  .auth-inner { background: var(--card); border: 1px solid var(--line); border-radius: 24px; padding: 40px 36px; margin: 40px 16px; }
}

/* ---------- App shell ---------- */
.shell { min-height: 100vh; }
.main { padding: 20px 16px 104px; max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; background: rgba(255, 255, 255, 0.96); backdrop-filter: blur(8px); border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 20; }
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; min-height: 52px; color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600; position: relative; }
.tab.on { color: var(--accent); }
.tab:hover { color: var(--accent-ink); }
.badge { position: absolute; top: 2px; left: calc(50% + 6px); background: var(--neg); color: #fff; font-size: 10px; border-radius: 9px; min-width: 18px; height: 18px; padding: 0 5px; display: flex; align-items: center; justify-content: center; }
.sidenav { display: none; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.topbar .title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

@media (min-width: 960px) {
  .tabbar { display: none; }
  .shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); }
  .sidenav { display: flex; flex-direction: column; gap: 4px; padding: 24px 16px; border-right: 1px solid var(--line); background: var(--card); position: sticky; top: 0; height: 100vh; }
  .sidenav .brand { padding: 0 8px 20px; }
  .navlink { display: flex; align-items: center; gap: 10px; padding: 0 12px; height: 44px; border-radius: 10px; color: var(--ink-2); text-decoration: none; font-weight: 600; font-size: 14px; position: relative; }
  .navlink:hover { background: var(--line-soft); color: var(--ink); }
  .navlink.on { background: var(--accent-soft); color: var(--accent-ink); }
  .navlink .badge { position: static; margin-left: auto; }
  .sidenav .foot { margin-top: auto; font-size: 12px; color: var(--muted); padding: 0 12px; }
  .main { padding: 32px 32px 48px; max-width: 1240px; width: 100%; }
  .main.narrow { max-width: 820px; }
  .dash { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); grid-template-areas: "main buckets" "pools buckets"; gap: 20px; align-items: start; }
  .dash > .dash-main { grid-area: main; }
  .dash > .dash-buckets { grid-area: buckets; }
  .dash > .dash-pools { grid-area: pools; }
  .dash > .col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
  .two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
}

/* ---------- Sheets (bottom sheet on phones, modal on desktop) ---------- */
.overlay { position: fixed; inset: 0; background: rgba(16, 24, 40, 0.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade 0.15s ease-out; }
.sheet { background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; border-radius: 24px 24px 0 0; padding: 12px 16px calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 16px; animation: up 0.2s ease-out; }
.sheet .grabber { width: 40px; height: 4px; border-radius: 2px; background: #D0D5DD; margin: 0 auto; }
@media (min-width: 720px) {
  .overlay { align-items: center; }
  .sheet { border-radius: 24px; padding: 24px; margin: 16px; }
  .sheet .grabber { display: none; }
}
@keyframes up { from { transform: translateY(24px); opacity: 0.6; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.toast { position: fixed; left: 50%; bottom: 92px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 12px; font-size: 14px; z-index: 60; max-width: calc(100vw - 32px); box-shadow: 0 8px 24px rgba(16, 24, 40, 0.2); }
.toast.bad { background: var(--neg); }
@media (min-width: 960px) { .toast { bottom: 32px; } }

.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 48px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.chart { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 12px; align-items: center; }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.spark { width: 72px; height: 28px; flex: 0 0 auto; }
@media (max-width: 380px) { .spark { display: none; } .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* Spending: month picker and shortcuts */
.spend-bar { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.spend-bar select { grid-column: 1 / -1; }
@media (min-width: 900px) { .spend-bar { grid-template-columns: minmax(0, 1fr) auto auto; } .spend-bar select { grid-column: auto; } }
.consent { background: var(--bg); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.consent-check { align-items: flex-start; min-height: 0; }
.consent-check input { flex: none; margin-top: 2px; }
.consent a, .auth-inner p.tiny a { color: var(--accent); }
