:root {
  --bg: #f6f6f9; --surface: #ffffff; --surface-2: #f0f0f5; --line: #e5e5ee;
  --text: #15151c; --muted: #6b6b7b; --accent: #4f46e5; --accent-ink: #ffffff; --accent-soft: #eef0ff;
  --pos: #059669; --neg: #dc2626; --warn-bg: #fff7e6; --warn-ink: #8a5a00; --bad-bg: #fdecec; --info-bg: #eef4ff;
  --radius: 16px; --shadow: 0 1px 2px rgba(20, 20, 40, .05), 0 4px 16px rgba(20, 20, 40, .04);
  --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: #0d0d12; --surface: #17171f; --surface-2: #20202a; --line: #2a2a36;
    --text: #f2f2f7; --muted: #9a9aab; --accent: #8b85ff; --accent-ink: #0d0d12; --accent-soft: #23224a;
    --pos: #34d399; --neg: #f87171; --warn-bg: #2d2410; --warn-ink: #f5c26b; --bad-bg: #3a1717; --info-bg: #182240;
    --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
}
body.noscroll { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 6px; }

/* layout */
.app { max-width: 560px; margin: 0 auto; min-height: 100dvh; }
.main { padding: calc(var(--safe-t) + 12px) 16px calc(160px + var(--safe-b)); }
.screen { display: flex; flex-direction: column; gap: 14px; }
.top { display: flex; align-items: flex-end; justify-content: space-between; padding-top: 8px; }
h1 { font-size: 30px; line-height: 1.1; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 18px; margin: 0; }
.eyebrow { color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.section-title, .group-label { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 6px 4px 8px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; align-items: center; }
.muted { color: var(--muted); } .small { font-size: 14px; } .tiny { font-size: 12px; }
.strong { font-weight: 600; } .pad { padding: 0 4px; margin: 0; } .mt { margin-top: 12px; }
.pos { color: var(--pos); } .neg { color: var(--neg); }

/* cards */
.card { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); border: 0; text-align: left; width: 100%; }
.card.tight { padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.card-title { margin: 0 0 12px; font-size: 16px; }
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat-label { font-size: 13px; color: var(--muted); font-weight: 500; }
.stat-value { font-size: 24px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--muted); }

/* segmented */
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 6px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--muted); display: flex; align-items: center; justify-content: center; gap: 6px; }
.seg button svg { width: 17px; height: 17px; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg-sm button { padding: 5px 10px; font-size: 13px; }

/* transactions */
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.tx { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; background: none; border: 0; text-align: left; }
.tx + .tx { border-top: 1px solid var(--line); }
.tx:active:not(.static) { background: var(--surface-2); }
.tx-ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 20px; flex-shrink: 0; background: var(--surface-2); }
.tx-ico.big { width: 64px; height: 64px; font-size: 32px; border-radius: 20px; }
.tx-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tx-title { 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-amt { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tx-share { font-size: 12px; color: var(--muted); font-weight: 500; }
.strike { text-decoration: line-through; color: var(--muted); }
.pill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; text-transform: capitalize; white-space: nowrap; }
.pill.ok { background: #dcfce7; color: #166534; } .pill.warn { background: var(--warn-bg); color: var(--warn-ink); }
.pill.bad { background: var(--bad-bg); color: var(--neg); } .pill.muted { background: var(--surface-2); color: var(--muted); }
@media (prefers-color-scheme: dark) { .pill.ok { background: #12301f; color: #6ee7a8; } }

/* banners */
.banner { border-radius: 14px; padding: 12px 14px; font-size: 14px; border: 0; text-align: left; width: 100%; }
.banner.info { background: var(--info-bg); } .banner.warn { background: var(--warn-bg); color: var(--warn-ink); }
.banner.bad { background: var(--bad-bg); color: var(--neg); } .banner.tap { font-weight: 600; }

/* buttons */
.btn { border: 0; border-radius: 12px; padding: 11px 16px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--bad-bg); color: var(--neg); }
.btn.sm { padding: 8px 12px; font-size: 14px; }
.btn.lg { padding: 15px; font-size: 17px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.btn:active:not(:disabled) { transform: scale(.98); }
.link-btn { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 8px; }
.link-btn.danger { color: var(--neg); } .link-btn.tiny { font-size: 12px; padding: 0; }
.icon-btn { background: var(--surface-2); border: 0; border-radius: 99px; width: 36px; height: 36px; display: grid; place-items: center; }
.icon-btn:disabled { opacity: .35; }

/* forms */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field-hint { font-size: 12px; color: var(--muted); } .field-hint.bad { color: var(--neg); }
.input { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px; font-size: 16px; }
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.textarea { resize: vertical; min-height: 80px; }
.input.emoji { width: 56px; text-align: center; flex: none; }
.amount-row { display: flex; align-items: center; gap: 8px; background: var(--surface); border-radius: var(--radius); padding: 8px 12px; }
.cur { border: 0; background: var(--surface-2); border-radius: 10px; padding: 8px; font-weight: 700; font-size: 15px; }
.amount { flex: 1; min-width: 0; border: 0; background: transparent; font-size: 40px; font-weight: 700; letter-spacing: -.02em; padding: 4px; outline: none; font-variant-numeric: tabular-nums; }
.cats { display: flex; flex-wrap: wrap; gap: 8px; }
.cat { border: 1.5px solid var(--line); background: var(--surface); border-radius: 99px; padding: 7px 12px; font-size: 14px; display: inline-flex; gap: 6px; align-items: center; }
.cat.on { font-weight: 600; }
.split-row { display: flex; align-items: center; gap: 10px; padding: 4px 0; font-size: 15px; }
.split-amt { font-weight: 600; min-width: 80px; text-align: right; font-variant-numeric: tabular-nums; }
.pct { display: inline-flex; align-items: center; gap: 2px; }
.pct input { width: 64px; border: 1px solid var(--line); border-radius: 8px; padding: 6px; text-align: right; background: var(--surface); font-size: 16px; }
.receipt { display: flex; align-items: center; gap: 10px; padding: 14px; border: 1.5px dashed var(--line); border-radius: 14px; color: var(--muted); cursor: pointer; }
.toggle { appearance: none; width: 50px; height: 30px; border-radius: 99px; background: var(--line); position: relative; transition: background .2s; flex-shrink: 0; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.toggle:checked { background: var(--pos); } .toggle:checked::after { transform: translateX(20px); }

/* voice */
.mic { width: 96px; height: 96px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; margin: 12px auto 0; box-shadow: 0 8px 24px rgba(79, 70, 229, .35); }
.mic svg { width: 40px; height: 40px; }
.mic.live { background: var(--neg); animation: pulse 1.2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(220, 38, 38, .5); } 70% { box-shadow: 0 0 0 22px rgba(220, 38, 38, 0); } 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); } }

/* sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(10, 10, 20, .45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .2s; }
.sheet { background: var(--bg); width: 100%; max-width: 560px; max-height: 92dvh; border-radius: 22px 22px 0 0; display: flex; flex-direction: column; animation: up .25s cubic-bezier(.2, .8, .2, 1); }
.sheet-full { height: 94dvh; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px; }
.sheet-body { overflow-y: auto; padding: 8px 16px calc(24px + var(--safe-b)); display: flex; flex-direction: column; gap: 14px; -webkit-overflow-scrolling: touch; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* detail */
.detail-hero { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 0; }
.detail-amt { font-size: 36px; font-weight: 800; letter-spacing: -.02em; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 10px 12px; margin: 0; background: var(--surface); padding: 14px; border-radius: var(--radius); }
.kv dt { color: var(--muted); font-size: 14px; } .kv dd { margin: 0; font-weight: 500; }
.raw { font-size: 14px; color: var(--muted); } .raw p { white-space: pre-wrap; }
.receipt-img { width: 100%; border-radius: 14px; }

/* ledger */
.request p { margin: 0 0 10px; font-size: 15px; }
.balance { display: flex; align-items: center; gap: 12px; }
.balance + .balance, .request + .request { margin-top: 8px; }
.bal-people { display: flex; align-items: center; gap: 4px; }
.bal-arrow { color: var(--muted); font-size: 14px; }
.bal-text { font-size: 14px; } .bal-amt { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.settled { text-align: center; font-weight: 600; }
.avatar { display: inline-grid; place-items: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; flex-shrink: 0; }
.avatar.joint { background: var(--surface-2); }

/* insights */
.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.month-nav input { border: 0; background: var(--surface); border-radius: 12px; padding: 8px 12px; font-weight: 600; text-align: center; flex: 1; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.chip-select { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 7px 12px; font-size: 14px; max-width: 100%; }
.donut-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.donut { width: 200px; height: 200px; stroke: none; }
.donut text { stroke: none; }
.donut-track { fill: none; stroke: var(--surface-2); stroke-width: 22; }
.donut-label { fill: var(--muted); font-size: 12px; font-weight: 600; }
.donut-value { fill: var(--text); font-size: 18px; font-weight: 800; }
.legend { list-style: none; margin: 0; padding: 0; width: 100%; display: flex; flex-direction: column; gap: 8px; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.legend-name { flex: 1; } .legend-val { font-weight: 600; font-variant-numeric: tabular-nums; } .legend-pct { color: var(--muted); width: 38px; text-align: right; font-size: 13px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.bars { display: flex; align-items: flex-end; gap: 8px; height: 180px; }
.bar-col { flex: 1; height: 100%; display: flex; flex-direction: column; align-items: center; gap: 4px; background: none; border: 0; padding: 0; }
.bar-val { font-size: 10px; color: var(--muted); height: 14px; white-space: nowrap; }
.bar-track { flex: 1; width: 100%; display: flex; align-items: flex-end; }
.bar { width: 100%; background: var(--accent-soft); border-radius: 8px 8px 4px 4px; min-height: 3px; transition: height .3s; }
.bar-col.hi .bar { background: var(--accent); }
.bar-label { font-size: 12px; color: var(--muted); } .bar-col.hi .bar-label { color: var(--text); font-weight: 700; }
.stacked { display: flex; flex-direction: column; gap: 14px; }
.stacked-legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 13px; }
.stacked-legend span { display: inline-flex; align-items: center; gap: 5px; }
.stacked-head { display: flex; justify-content: space-between; font-size: 14px; font-weight: 600; margin-bottom: 5px; }
.stacked-track { display: flex; height: 12px; border-radius: 6px; overflow: hidden; min-width: 8px; gap: 2px; }
.stacked-parts { display: flex; gap: 12px; font-size: 12px; color: var(--muted); margin-top: 4px; flex-wrap: wrap; }

/* profile */
.members { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.member { display: flex; align-items: center; gap: 10px; }
.invite { display: flex; align-items: center; justify-content: space-between; background: var(--accent-soft); border-radius: 14px; padding: 12px 14px; margin-bottom: 14px; }
.code { font-family: ui-monospace, Menlo, monospace; font-size: 22px; font-weight: 700; letter-spacing: .12em; }
.hh-switch { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 7px 14px; white-space: nowrap; font-weight: 600; font-size: 14px; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* tab bar + fab */
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; display: flex; justify-content: space-around; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-top: 1px solid var(--line); padding: 6px 0 calc(6px + var(--safe-b)); z-index: 20; }
.tabbar button { background: none; border: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 600; color: var(--muted); padding: 4px 12px; min-width: 64px; }
.tabbar button.on { color: var(--accent); }
.tab-ico { position: relative; }
.badge { position: absolute; top: -4px; right: -10px; background: var(--neg); color: #fff; font-size: 10px; font-weight: 700; border-radius: 99px; padding: 1px 5px; }
.fab { position: fixed; right: max(20px, calc(50vw - 260px)); bottom: calc(80px + var(--safe-b)); width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; box-shadow: 0 8px 24px rgba(79, 70, 229, .4); z-index: 31; transition: transform .2s; }
.fab svg { width: 28px; height: 28px; stroke-width: 2.4; }
.fab.open { transform: rotate(45deg); }
.fab-scrim { position: fixed; inset: 0; background: rgba(10, 10, 20, .3); z-index: 29; }
.fab-menu { position: fixed; right: max(20px, calc(50vw - 260px)); bottom: calc(150px + var(--safe-b)); display: flex; flex-direction: column; align-items: flex-end; gap: 10px; z-index: 30; pointer-events: none; }
.fab-menu button { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 0; border-radius: 99px; padding: 10px 16px 10px 12px; font-weight: 600; box-shadow: 0 4px 16px rgba(0,0,0,.15); opacity: 0; transform: translateY(12px) scale(.95); transition: all .18s; }
.fab-menu button svg { color: var(--accent); }
.fab-menu.open { pointer-events: auto; }
.fab-menu.open button { opacity: 1; transform: none; }
.fab-menu.open button:nth-child(2) { transition-delay: .03s; } .fab-menu.open button:nth-child(3) { transition-delay: .06s; }

/* misc */
.empty { text-align: center; padding: 36px 20px; color: var(--muted); }
.empty-ico { font-size: 40px; } .empty-title { font-weight: 700; color: var(--text); margin: 6px 0 4px; } .empty-sub { font-size: 14px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); top: calc(var(--safe-t) + 12px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px; z-index: 100; max-width: calc(100vw - 32px); animation: fade .2s; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.toast.error { background: var(--neg); color: #fff; }
.loading-bar { position: fixed; top: 0; left: 0; height: 3px; width: 40%; background: var(--accent); animation: load 1s infinite ease-in-out; z-index: 60; }
@keyframes load { from { left: -40%; } to { left: 100%; } }
.auth { max-width: 420px; margin: 0 auto; padding: calc(var(--safe-t) + 48px) 20px 40px; display: flex; flex-direction: column; gap: 16px; }
.brand { text-align: center; }
.brand .logo { width: 72px; height: 72px; border-radius: 22px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 38px; font-weight: 800; margin: 0 auto 10px; }
.brand h1 { font-size: 32px; } .brand p { margin: 6px 0 0; }
