:root {
  --paper: #f5f6f8; --card: #ffffff; --ink: #1c2430; --muted: #687385; --line: #e1e5eb; --soft: #eef1f5;
  --accent: #1f5f8b; --accent-soft: #e2eef7; --on-accent: #ffffff;
  --good: #1d7a52; --good-soft: #e1f3ea; --bad: #b4402f; --bad-soft: #fbe6e2; --warn: #9a6408; --warn-soft: #fdf0d5;
  --expense: #8a95a6; --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #14181f; --card: #1d232c; --ink: #e8ecf1; --muted: #9aa5b4; --line: #2d3540; --soft: #252c36;
    --accent: #7bb8e6; --accent-soft: #22384a; --on-accent: #0e2232;
    --good: #6fd3a2; --good-soft: #1c3a2d; --bad: #ff9a8a; --bad-soft: #472b28; --warn: #f2c46b; --warn-soft: #43361f; --expense: #6c7686;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--paper); color: var(--ink); }
body { font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
  padding-bottom: calc(76px + var(--safe-bottom)); -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.num, .amount { font-variant-numeric: tabular-nums; }

/* header */
.top { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--paper) 92%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px);
  padding: calc(8px + var(--safe-top)) 16px 8px; border-bottom: 1px solid var(--line); }
.top-row { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.top h1 { font-size: 26px; line-height: 1.1; margin: 0; flex: 1 1 auto; min-width: 0; letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sync { display: inline-flex; align-items: center; gap: 6px; border: 0; background: var(--card); border-radius: 999px; min-height: 34px;
  padding: 6px 12px; font-size: 13px; color: var(--muted); box-shadow: 0 0 0 1px var(--line) inset; max-width: 52vw; flex: 0 1 auto; min-width: 0; }
.sync span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sync .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); flex: none; }
.sync.busy .dot { animation: pulse 1s infinite ease-in-out; }
.sync.warn .dot { background: var(--warn); }
.sync.bad .dot { background: var(--bad); }
@keyframes pulse { 50% { opacity: .25; } }
.icon-button { flex: none; width: 44px; height: 44px; border: 0; background: none; display: grid; place-items: center; margin-right: -8px; }
.icon-button svg { width: 24px; height: 24px; fill: var(--muted); }
.search-row { margin-top: 8px; }
.search-row input, .picker input[type=search] { width: 100%; border: 0; border-radius: 11px; padding: 10px 12px; background: var(--soft); font-size: 16px; }

/* banner, toast */
.banner { margin: 10px 16px 0; padding: 10px 12px; border-radius: 12px; background: var(--bad-soft); color: var(--bad); font-size: 14px; }
.banner .item { display: flex; gap: 8px; align-items: flex-start; padding: 4px 0; }
.banner .item span { flex: 1; }
.banner button { border: 0; background: none; color: inherit; font-weight: 600; padding: 4px 2px; min-height: 32px; }
.toast { position: fixed; left: 12px; right: 12px; bottom: calc(84px + var(--safe-bottom)); z-index: 20; display: flex; align-items: center;
  gap: 12px; background: #1c2430; color: #fff; border-radius: 14px; padding: 12px 14px; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.toast span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast button { border: 0; background: none; color: #9fd0f5; font-weight: 600; padding: 6px 4px; min-height: 36px; }

/* layout */
main { padding: 8px 16px 24px; outline: none; }
.section-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 20px 4px 8px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: 0 0 0 1px var(--line) inset; padding: 14px 16px; margin-bottom: 12px; }
.card h2 { font-size: 15px; margin: 0 0 8px; color: var(--muted); font-weight: 600; }
.big { font-size: 32px; font-weight: 650; letter-spacing: -0.02em; margin: 2px 0 6px; }
.row { display: flex; align-items: baseline; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); }
.row:first-of-type { border-top: 0; }
.row .label { flex: 1; min-width: 0; }
.row .value { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.neg { color: var(--bad); }
.pos { color: var(--good); }
.warn-text { color: var(--warn); }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.trio { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 6px; }
.trio div { min-width: 0; }
.trio .k { font-size: 12px; color: var(--muted); }
.trio .v { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chart { width: 100%; height: 150px; display: block; touch-action: pan-y; }
.chart .inc { fill: var(--accent); }
.chart .exp { fill: var(--expense); }
.chart .sel { fill: var(--soft); }
.chart text { fill: var(--muted); font-size: 10px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.bar { height: 6px; border-radius: 3px; background: var(--soft); margin-top: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); }
.link-button { width: 100%; text-align: left; border: 0; background: none; padding: 0; }

/* transaction list */
.list { background: var(--card); border-radius: var(--radius); box-shadow: 0 0 0 1px var(--line) inset; overflow: hidden; margin-bottom: 12px; }
.tx { border-top: 1px solid var(--line); }
.tx:first-child { border-top: 0; }
.tx-head { display: flex; gap: 10px; align-items: center; width: 100%; border: 0; background: none; text-align: left; padding: 12px 14px; min-height: 60px; }
.tx-main { flex: 1; min-width: 0; }
.tx-payee { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-amount { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; text-align: right; }
.tx.open { background: color-mix(in srgb, var(--accent-soft) 40%, var(--card)); }
.month { font-size: 13px; font-weight: 600; color: var(--muted); margin: 16px 4px 6px; }
.chip { display: inline-block; font-size: 12px; font-weight: 600; border-radius: 999px; padding: 2px 8px; margin: 3px 4px 0 0; background: var(--soft); color: var(--muted); }
.chip.review { background: var(--warn-soft); color: var(--warn); }
.chip.wait { background: var(--accent-soft); color: var(--accent); }
.chip.ok { background: var(--good-soft); color: var(--good); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }

/* in-place editor */
.editor { padding: 0 14px 14px; }
.field { margin-top: 12px; }
.field > .name { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.note { font-size: 14px; color: var(--muted); margin-top: 6px; white-space: pre-wrap; }
input.text, select.text, textarea.text { width: 100%; border: 1px solid var(--line); border-radius: 11px; padding: 11px 12px; background: var(--card); font-size: 16px; min-height: 46px; }
input.text:focus, textarea.text:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input.amount-input { font-size: 30px; font-weight: 650; text-align: right; min-height: 60px; }
.choice { width: 100%; display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); background: var(--card); border-radius: 11px;
  padding: 11px 12px; min-height: 48px; text-align: left; }
.choice .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.choice .chev { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.pick { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 10px 14px; min-height: 44px; font-size: 15px; }
.pick.selected { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.switch { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 6px 0; }
.switch span { flex: 1; }
.switch input { appearance: none; -webkit-appearance: none; width: 51px; height: 31px; border-radius: 16px; background: var(--soft); position: relative; flex: none;
  box-shadow: 0 0 0 1px var(--line) inset; transition: background .15s; margin: 0; }
.switch input::after { content: ''; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked { background: var(--good); }
.switch input:checked::after { transform: translateX(20px); }
.actions { display: flex; gap: 10px; margin-top: 16px; }
.actions button { flex: 1; min-height: 50px; border-radius: 12px; border: 0; font-weight: 600; font-size: 16px; }
.primary { background: var(--accent); color: var(--on-accent); }
.primary:disabled { opacity: .45; }
.secondary { background: var(--soft); color: var(--ink); }
.danger { background: var(--bad-soft); color: var(--bad); }
.error { color: var(--bad); font-size: 14px; margin-top: 10px; }
.photo { display: flex; gap: 12px; align-items: center; }
.photo img { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; box-shadow: 0 0 0 1px var(--line); }
.split-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.split-row .choice { flex: 1; min-width: 0; }
.split-row input { width: 112px; flex: none; text-align: right; }
.split-row .remove { border: 0; background: none; color: var(--muted); font-size: 22px; width: 36px; height: 44px; }
.remaining { font-size: 14px; margin-top: 8px; }

/* account picker (in place) */
.picker { margin-top: 8px; border: 1px solid var(--line); border-radius: 12px; padding: 8px; background: var(--card); }
.picker .group { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 10px 6px 4px; }
.picker .opt { display: flex; width: 100%; gap: 8px; border: 0; background: none; text-align: left; padding: 11px 8px; min-height: 46px; border-radius: 9px; align-items: center; }
.picker .opt:active, .picker .opt.selected { background: var(--accent-soft); }
.picker .opt .code { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; width: 40px; flex: none; }
.picker .list { max-height: 46vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* add view */
.segmented { display: flex; gap: 4px; background: var(--soft); padding: 3px; border-radius: 11px; margin: 6px 0 10px; }
.segmented button { flex: 1; border: 0; background: none; padding: 9px 4px; border-radius: 8px; font-size: 15px; font-weight: 500; color: var(--muted); min-height: 40px; }
.segmented button.selected { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.more { display: block; width: 100%; border: 0; background: var(--card); color: var(--accent); padding: 14px; border-radius: 12px; box-shadow: 0 0 0 1px var(--line) inset; font-weight: 600; min-height: 48px; }

/* bottom tabs */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; background: color-mix(in srgb, var(--card) 94%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px);
  border-top: 1px solid var(--line); padding-bottom: var(--safe-bottom); }
.tabs button { flex: 1; border: 0; background: none; padding: 7px 0 6px; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: 11px; min-height: 56px; position: relative; }
.tabs svg { width: 25px; height: 25px; fill: currentColor; }
.tabs button.selected { color: var(--accent); }
.badge { position: absolute; top: 3px; left: calc(50% + 8px); background: var(--bad); color: #fff; font-size: 11px; line-height: 17px; min-width: 17px; padding: 0 5px; border-radius: 9px; font-weight: 700; }

/* lock screen */
.lock { position: fixed; inset: 0; z-index: 50; background: var(--paper); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  padding: calc(20px + var(--safe-top)) 24px calc(20px + var(--safe-bottom)); }
.lock h2 { margin: 0; font-size: 20px; }
.dots { display: flex; gap: 14px; height: 18px; }
.dots i { width: 14px; height: 14px; border-radius: 50%; box-shadow: 0 0 0 1.5px var(--ink) inset; }
.dots i.on { background: var(--ink); }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 14px; margin-top: 8px; }
.keypad button { width: 76px; height: 76px; border-radius: 50%; border: 0; background: var(--card); box-shadow: 0 0 0 1px var(--line) inset; font-size: 28px; }
.keypad button.text { background: none; box-shadow: none; font-size: 16px; color: var(--accent); }
