:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --card-2: #f7f7fa;
  --text: #111114;
  --muted: #6c6c72;
  --line: rgba(60, 60, 67, 0.16);
  --accent: #4f46e5;
  --accent-ink: #ffffff;
  --accent-soft: rgba(79, 70, 229, 0.10);
  --good: #1f9d55;
  --good-soft: rgba(31, 157, 85, 0.13);
  --warn: #b25e00;
  --warn-soft: rgba(255, 159, 10, 0.18);
  --danger: #d92d20;
  --danger-soft: rgba(217, 45, 32, 0.1);
  --tax: #6b4fd8;
  --tax-soft: rgba(107, 79, 216, 0.13);
  --radius: 14px;
  --tabbar-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --card-2: #242427;
    --text: #f2f2f5;
    --muted: #98989f;
    --line: rgba(84, 84, 88, 0.55);
    --accent: #8b8cf8;
    --accent-soft: rgba(139, 140, 248, 0.16);
    --good: #3ccf7a;
    --good-soft: rgba(60, 207, 122, 0.16);
    --warn: #ffb340;
    --warn-soft: rgba(255, 179, 64, 0.16);
    --danger: #ff6961;
    --danger-soft: rgba(255, 105, 97, 0.14);
    --tax: #a08cff;
    --tax-soft: rgba(160, 140, 255, 0.18);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
/* Fixed to the phone screen: no double-tap zoom, no text auto-resizing; inputs ≥16px so iOS doesn't zoom on focus */
html { touch-action: pan-x pan-y; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 40vh 0; text-align: center; color: var(--muted); }

/* ---------- layout ---------- */
.screen { max-width: 640px; margin: 0 auto; padding: calc(var(--safe-t) + 8px) 16px calc(var(--tabbar-h) + var(--safe-b) + 24px); }
.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 8px 0 12px; }
.topbar h1 { font-size: 32px; line-height: 1.1; margin: 0; letter-spacing: -0.02em; }
.topbar .sub { color: var(--muted); font-size: 14px; margin-top: 4px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px 4px calc(var(--safe-b) + 4px);
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--line);
}
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; border: 0; background: none; color: var(--muted); font-size: 11px; padding: 4px 0; min-height: 48px; cursor: pointer; }
.tab svg { width: 26px; height: 26px; }
.tab[aria-current="page"] { color: var(--accent); }
.tab.add .plus { width: 46px; height: 46px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; margin-top: -4px; box-shadow: 0 4px 14px rgba(10,124,255,.35); }
.tab.add .plus svg { width: 26px; height: 26px; }

/* ---------- cards & lists ---------- */
.card { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.card + .card, .section + .section { margin-top: 18px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 4px 8px; }
.list { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 14px; min-height: 52px; position: relative; width: 100%; text-align: left; background: none; border: 0; cursor: pointer; }
.row + .row::before { content: ""; position: absolute; top: 0; left: 14px; right: 0; border-top: 0.5px solid var(--line); }
.row.has-thumb + .row.has-thumb::before { left: 70px; }
.row:active { background: var(--card-2); }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .amt { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.row .amt.credit { color: var(--good); }
.row .chev { color: var(--muted); }
.thumb { width: 44px; height: 44px; border-radius: 8px; background: var(--card-2); object-fit: cover; flex: none; display: grid; place-items: center; color: var(--muted); }
.thumb svg { width: 22px; height: 22px; }
.badges { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 3px; }
.badge { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 999px; background: var(--card-2); color: var(--muted); }
.badge.tax { background: var(--tax-soft); color: var(--tax); }
.badge.review { background: var(--warn-soft); color: var(--warn); }
.badge.dup { background: var(--danger-soft); color: var(--danger); }
.badge.linked { background: var(--good-soft); color: var(--good); }
.badge.person { background: var(--accent-soft); color: var(--accent); }
.empty { text-align: center; color: var(--muted); padding: 36px 20px; }
.empty strong { display: block; color: var(--text); font-size: 17px; margin-bottom: 4px; }
.month { font-size: 13px; font-weight: 600; color: var(--muted); margin: 18px 4px 6px; display: flex; justify-content: space-between; }

/* ---------- controls ---------- */
.search { width: 100%; border: 0; border-radius: 10px; background: color-mix(in srgb, var(--muted) 14%, transparent); padding: 9px 12px; font-size: 16px; outline: none; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 2px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 0; border-radius: 999px; padding: 7px 13px; background: var(--card); font-size: 14px; font-weight: 500; cursor: pointer; white-space: nowrap; }
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); }
select.chip { font-size: 16px; appearance: none; -webkit-appearance: none; padding-right: 26px; background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%); background-position: calc(100% - 14px) 52%, calc(100% - 9px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600; background: var(--accent-soft); color: var(--accent); cursor: pointer; min-height: 44px; text-decoration: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.plain { background: none; padding: 8px; min-height: 0; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; }
.btn svg { width: 20px; height: 20px; }
.btn-row { display: flex; gap: 10px; }
.btn-row > * { flex: 1; }

.form { display: flex; flex-direction: column; }
.field { display: flex; align-items: center; gap: 12px; padding: 0 14px; min-height: 50px; position: relative; }
.field + .field::before { content: ""; position: absolute; top: 0; left: 14px; right: 0; border-top: 0.5px solid var(--line); }
.field > label { width: 108px; flex: none; color: var(--text); }
.field input, .field select, .field textarea { flex: 1; min-width: 0; border: 0; background: none; padding: 13px 0; outline: none; font-size: 16px; text-align: right; }
.field textarea { text-align: left; resize: vertical; min-height: 70px; }
.field.stack { flex-direction: column; align-items: stretch; gap: 0; padding-top: 10px; }
.field.stack > label { width: auto; font-size: 13px; color: var(--muted); }
.field.stack input, .field.stack textarea { text-align: left; padding: 6px 0 12px; }
.field input.filled { color: var(--accent); }
.field .hint { font-size: 12px; color: var(--muted); }
.note { font-size: 13px; color: var(--muted); padding: 8px 6px 0; }
.input { width: 100%; border: 0; border-radius: 12px; background: var(--card); padding: 14px; font-size: 16px; outline: none; }
.input + .input { margin-top: 10px; }

.seg { display: flex; background: color-mix(in srgb, var(--muted) 16%, transparent); border-radius: 9px; padding: 2px; flex: 1; }
.seg button { flex: 1; border: 0; background: none; border-radius: 7px; padding: 7px 6px; font-size: 14px; font-weight: 500; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg button[aria-pressed="true"] { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.15); font-weight: 600; }

.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: color-mix(in srgb, var(--muted) 30%, transparent); transition: background .2s; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.2); transition: transform .2s; }
.switch input:checked + span { background: var(--good); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.banner { border-radius: 12px; padding: 12px 14px; font-size: 14px; margin: 12px 0; }
.banner.info { background: var(--accent-soft); }
.banner.warn { background: var(--warn-soft); }
.banner.danger { background: var(--danger-soft); }
.banner.tax { background: var(--tax-soft); }
.banner strong { display: block; margin-bottom: 2px; }
.banner .btn { margin-top: 8px; }

/* ---------- sheet (modal) ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.35); display: flex; align-items: flex-end; justify-content: center; animation: fade .18s ease-out; }
.sheet { width: 100%; max-width: 640px; max-height: calc(100% - var(--safe-t) - 12px); background: var(--bg); border-radius: 14px 14px 0 0; display: flex; flex-direction: column; animation: up .25s cubic-bezier(.2,.8,.2,1); }
.sheet.full { height: calc(100% - var(--safe-t) - 12px); }
.sheet header { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 12px 8px 8px; }
.sheet header h2 { font-size: 17px; margin: 0; text-align: center; }
.sheet header .btn { justify-self: start; }
.sheet header .btn:last-child { justify-self: end; }
.sheet .body { overflow-y: auto; padding: 4px 16px calc(var(--safe-b) + 24px); -webkit-overflow-scrolling: touch; }
.action-sheet { padding: 8px 8px calc(var(--safe-b) + 8px); background: transparent; }
.action-sheet .card .row { justify-content: center; color: var(--accent); font-size: 18px; min-height: 56px; }
.action-sheet .card .row svg { width: 22px; height: 22px; }
.action-sheet .card + .card { margin-top: 8px; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

.preview { position: relative; background: var(--card); border-radius: var(--radius); overflow: hidden; display: grid; place-items: center; min-height: 120px; }
.preview img { width: 100%; max-height: 42vh; object-fit: contain; display: block; background: #111; }
.preview .open { position: absolute; right: 10px; bottom: 10px; background: rgba(0,0,0,.55); color: #fff; border-radius: 999px; padding: 6px 12px; font-size: 13px; border: 0; }
.ocr-status { display: flex; align-items: center; gap: 10px; font-size: 14px; padding: 10px 4px; color: var(--muted); }
.progress { flex: 1; height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); transition: width .2s; }

.items .item { display: grid; grid-template-columns: 1fr 96px 36px; gap: 8px; align-items: center; padding: 4px 14px; }
.items .item input { border: 0; background: var(--card-2); border-radius: 8px; padding: 9px 10px; font-size: 16px; min-width: 0; outline: none; }
.items .item input.amt { text-align: right; }
.items .item button { border: 0; background: none; color: var(--danger); font-size: 22px; cursor: pointer; }

table.preview-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.preview-table th, table.preview-table td { text-align: left; padding: 7px 8px; border-bottom: 0.5px solid var(--line); white-space: nowrap; }
table.preview-table td.num, table.preview-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.scroll-x { overflow-x: auto; }

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 12px; }
.stat .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; color: var(--muted); }

.code { font: 600 22px/1.3 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .06em; text-align: center; padding: 14px; background: var(--card); border-radius: 12px; user-select: all; -webkit-user-select: all; word-break: break-all; }
.code.small { font-size: 13px; letter-spacing: 0; }
ol.steps { padding-left: 20px; margin: 8px 0; }
ol.steps li { margin: 6px 0; }
details { margin-top: 12px; }
summary { cursor: pointer; color: var(--accent); font-size: 14px; padding: 6px 4px; }
pre.ocr { white-space: pre-wrap; font-size: 12px; background: var(--card); padding: 12px; border-radius: 12px; max-height: 240px; overflow: auto; }

.auth { max-width: 420px; margin: 0 auto; padding: calc(var(--safe-t) + 48px) 20px 40px; }
.auth .logo { width: 72px; height: 72px; border-radius: 18px; display: block; margin: 0 auto 16px; }
.auth h1 { text-align: center; margin: 0 0 6px; font-size: 28px; }
.auth p.lead { text-align: center; color: var(--muted); margin: 0 0 24px; }
.auth .btn { margin-top: 14px; }
.auth .alt { text-align: center; margin-top: 18px; font-size: 15px; }
.auth .alt button { color: var(--accent); background: none; border: 0; cursor: pointer; font-weight: 600; }
.error { color: var(--danger); font-size: 14px; margin-top: 10px; min-height: 1em; }
.disclaimer { font-size: 12px; color: var(--muted); text-align: center; margin: 22px 8px 0; }

#toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); transform: translateX(-50%) translateY(20px); background: rgba(30,30,32,.92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: all .25s; z-index: 60; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ================= polish layer ================= */
:root { --tile-bl: 95%; --tile-bs: 80%; --tile-fl: 42%; --tile-fs: 62%; }
@media (prefers-color-scheme: dark) { :root { --tile-bl: 19%; --tile-bs: 30%; --tile-fl: 74%; --tile-fs: 75%; } }
.topbar h1 { font-weight: 750; }

/* summary card */
.hero { position: relative; overflow: hidden; border-radius: 20px; padding: 18px; margin: 6px 0 14px; color: #fff;
  background: radial-gradient(120% 90% at 100% 0%, rgba(167,139,250,.35), transparent 60%), linear-gradient(150deg, #1e1b4b 0%, #312e81 55%, #4c1d95 100%);
  box-shadow: 0 12px 28px -16px rgba(30,27,75,.8); animation: rise .35s ease-out both; }
.hero .hi { font-size: 14px; font-weight: 500; color: rgba(255,255,255,.78); }
.hero .big { font-size: 34px; font-weight: 750; letter-spacing: -.02em; line-height: 1.1; margin-top: 6px; font-variant-numeric: tabular-nums; }
.hero .cap { font-size: 13px; color: rgba(255,255,255,.7); }
.hero .pills { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.hero .pill { border: 0; color: #fff; background: rgba(255,255,255,.12); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; cursor: pointer; }
.hero .pill.warn::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #fbbf24; margin-right: 6px; vertical-align: 1px; }
.hero .pill:active { background: rgba(255,255,255,.2); }

/* category tiles */
.cat-ico { width: 42px; height: 42px; border-radius: 12px; flex: none; display: grid; place-items: center;
  background: hsl(var(--h) var(--tile-bs) var(--tile-bl)); color: hsl(var(--h) var(--tile-fs) var(--tile-fl)); }
.cat-ico svg { width: 21px; height: 21px; }
.cat-ico.neutral { background: var(--card-2); color: var(--muted); }
.thumb-wrap { position: relative; flex: none; }
.thumb-wrap .mini { position: absolute; right: -5px; bottom: -5px; width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center;
  background: hsl(var(--h) var(--tile-bs) var(--tile-bl)); color: hsl(var(--h) var(--tile-fs) var(--tile-fl)); box-shadow: 0 0 0 2px var(--card); }
.thumb-wrap .mini.neutral { background: var(--card-2); color: var(--muted); }
.thumb-wrap .mini svg { width: 13px; height: 13px; }
.badge.person { background: color-mix(in srgb, var(--pc, var(--accent)) 13%, transparent); color: var(--pc, var(--accent)); }

/* surfaces & controls */
.card { border-radius: 16px; box-shadow: 0 1px 2px rgba(16,24,40,.05); }
@media (prefers-color-scheme: dark) { .card { box-shadow: none; } }
.stagger > * { animation: rise .25s ease-out both; }
.stagger > :nth-child(2) { animation-delay: .03s; } .stagger > :nth-child(3) { animation-delay: .06s; }
.stagger > :nth-child(n+4) { animation-delay: .09s; }
.month { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.chip[aria-pressed="true"] { background: var(--accent); color: #fff; }
.btn.primary { background: var(--accent); color: #fff; }
.tab[aria-current="page"] { color: var(--accent); }
.tab.add .plus { background: var(--accent); color: #fff; box-shadow: 0 6px 16px -6px color-mix(in srgb, var(--accent) 70%, transparent); }
.empty-ico { width: 52px; height: 52px; border-radius: 16px; margin: 0 auto 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.empty-ico svg { width: 26px; height: 26px; }

/* tax time */
.stat .e { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; margin-bottom: 8px; }
.stat .e svg { width: 17px; height: 17px; }
.stat.s1 .e { background: var(--tax-soft); color: var(--tax); }
.stat.s2 .e { background: var(--warn-soft); color: var(--warn); }
.stat.s3 .e { background: var(--accent-soft); color: var(--accent); }
.bar { height: 4px; border-radius: 2px; background: var(--card-2); margin-top: 7px; overflow: hidden; }
.bar > div { height: 100%; border-radius: 2px; background: var(--accent); transform-origin: left; animation: grow .5s ease-out both; }

#toast { border-radius: 999px; padding: 10px 18px; font-weight: 500; }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } }
@keyframes grow { from { transform: scaleX(0); } }
