:root {
  --bg: #060b16;
  --bg2: #0d1424;
  --card: rgba(255,255,255,.045);
  --card-solid: #111a2e;
  --card-hi: rgba(255,255,255,.08);
  --line: rgba(255,255,255,.09);
  --text: #f4f3fb;
  --muted: #94a3c0;
  --faint: #64748b;
  --accent: #3b82f6;
  --accent2: #22d3ee;
  --gold: #f5c76b;
  --grad: linear-gradient(135deg, #1e40af 0%, #2563eb 48%, #06b6d4 100%);
  --grad-text: linear-gradient(120deg, #60a5fa 0%, #22d3ee 100%);
  --glow: #2563eb;
  --gold-grad: linear-gradient(135deg, #f5d28b, #d9a548);
  --income: #34d399;
  --expense: #f87171;
  --shadow: 0 18px 50px -20px rgba(0,0,0,.7);
  --radius: 22px;
  --nav-h: 68px;
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #f2f5fa;
  --bg2: #ffffff;
  --card: rgba(255,255,255,.85);
  --card-solid: #ffffff;
  --card-hi: #eaf0f8;
  --line: rgba(15,30,60,.10);
  --text: #0b1730;
  --muted: #5b6b85;
  --faint: #94a3b8;
  --grad-text: linear-gradient(120deg, #1d4ed8 0%, #0891b2 100%);
  --income: #059669;
  --expense: #dc2626;
  --shadow: 0 18px 40px -22px rgba(20,50,110,.35);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Be Vietnam Pro', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100dvh;
  overflow-x: hidden;
}
body::before {
  content: ''; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(60vmax 50vmax at 110% -10%, rgba(37,99,235,.24), transparent 60%),
    radial-gradient(50vmax 40vmax at -20% 110%, rgba(6,182,212,.12), transparent 60%);
}
[data-theme="light"] body::before { opacity: .55; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: inherit; }
.hidden { display: none !important; }

#app { max-width: 600px; margin: 0 auto; padding: 0 16px calc(var(--nav-h) + 96px + env(safe-area-inset-bottom)); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 0 10px;
  background: linear-gradient(var(--bg) 70%, transparent);
}
.topbar .title { flex: 1; min-width: 0; font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; letter-spacing: -.3px; }
.brand-logo { width: 34px; height: 34px; border-radius: 11px; background: var(--grad); display: grid; place-items: center; font-size: 18px; box-shadow: 0 6px 18px -6px var(--glow); }
.brand span b { background: var(--gold-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.icon-btn { width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center; background: var(--card); border: 1px solid var(--line); font-size: 18px; flex: none; }
.icon-btn:active { transform: scale(.94); }
.avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; border: 2px solid var(--line); background: var(--grad); display: grid; place-items: center; font-weight: 700; color: #fff; flex: none; overflow: hidden; }

/* ---------- cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.card + .card, .section + .section { margin-top: 14px; }
.section { margin-top: 22px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 0 2px 10px; }
.section-head h3 { margin: 0; font-size: 16px; font-weight: 700; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.tiny { font-size: 11.5px; }
.income { color: var(--income); }
.expense { color: var(--expense); }
.num { font-variant-numeric: tabular-nums; }

.hero {
  position: relative; overflow: hidden; border-radius: 26px; padding: 22px 20px 20px; color: #fff;
  background: var(--fund-grad, var(--grad));
  box-shadow: 0 24px 50px -24px var(--fund-color, #2563eb);
}
.hero::after { content: ''; position: absolute; width: 220px; height: 220px; right: -70px; top: -90px; border-radius: 50%; background: rgba(255,255,255,.14); }
.hero::before { content: ''; position: absolute; width: 140px; height: 140px; right: 40px; bottom: -80px; border-radius: 50%; background: rgba(255,255,255,.08); }
.hero .label { font-size: 13px; opacity: .85; position: relative; }
.hero .big { font-size: 34px; font-weight: 800; letter-spacing: -1px; margin: 2px 0 14px; position: relative; }
.hero .split { display: flex; gap: 10px; position: relative; }
.hero .split > div { flex: 1; background: rgba(0,0,0,.16); border-radius: 15px; padding: 9px 12px; }
.hero .split .k { font-size: 12px; opacity: .85; }
.hero .split .v { font-weight: 700; font-size: 15px; }

/* fund list */
.fund-card { display: flex; gap: 14px; align-items: center; padding: 16px; cursor: pointer; transition: transform .15s; position: relative; overflow: hidden; }
.fund-card:active { transform: scale(.985); }
.fund-card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--fund-color); }
.fund-emoji { width: 52px; height: 52px; border-radius: 17px; display: grid; place-items: center; font-size: 26px; flex: none; background: var(--fund-soft); border: 1px solid var(--line); }
.fund-info { flex: 1; min-width: 0; }
.fund-info .name { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fund-amt { text-align: right; flex: none; }
.fund-amt .v { font-weight: 800; font-size: 16px; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--card-hi); color: var(--muted); }
.badge.admin { background: rgba(245,199,107,.16); color: var(--gold); }
.badge.off { background: rgba(148,163,184,.15); }

.empty { text-align: center; padding: 40px 20px; }
.empty .e { font-size: 50px; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 48px; padding: 0 20px; border-radius: 16px; font-weight: 700; background: var(--card-hi); border: 1px solid var(--line); transition: transform .12s, opacity .12s; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--grad); color: #fff; border: 0; box-shadow: 0 12px 26px -12px var(--glow); }
.btn.gold { background: var(--gold-grad); color: #2a1d00; border: 0; }
.btn.danger { background: rgba(251,113,133,.14); color: var(--expense); border-color: rgba(251,113,133,.3); }
.btn.block { width: 100%; }
.btn.sm { height: 36px; padding: 0 14px; border-radius: 12px; font-size: 13.5px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.link { color: var(--accent); font-weight: 600; font-size: 14px; text-decoration: none; }
[data-theme="light"] .link { color: #1d4ed8; }

.fab {
  position: fixed; z-index: 30; right: max(18px, calc(50% - 300px + 18px)); bottom: calc(var(--nav-h) + 22px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 20px; background: var(--grad); color: #fff; font-size: 30px; font-weight: 300;
  display: grid; place-items: center; box-shadow: 0 16px 30px -10px var(--glow);
}
.fab:active { transform: scale(.94); }

/* ---------- bottom nav ---------- */
.bottom-nav {
  position: fixed; z-index: 25; left: 50%; transform: translateX(-50%); bottom: calc(10px + env(safe-area-inset-bottom));
  width: min(568px, calc(100% - 24px)); height: var(--nav-h); border-radius: 24px;
  display: flex; padding: 6px; gap: 4px;
  background: color-mix(in srgb, var(--bg2) 82%, transparent); border: 1px solid var(--line);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); box-shadow: var(--shadow);
}
.bottom-nav button { flex: 1; border-radius: 18px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; font-weight: 600; color: var(--muted); }
.bottom-nav button .i { font-size: 20px; line-height: 1; filter: grayscale(.6); opacity: .8; }
.bottom-nav button.on { background: var(--card-hi); color: var(--text); }
.bottom-nav button.on .i { filter: none; opacity: 1; }

/* ---------- transactions ---------- */
.tx-group-head { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); font-weight: 600; margin: 18px 4px 8px; text-transform: capitalize; }
.tx { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 18px; background: var(--card); border: 1px solid var(--line); cursor: pointer; position: relative; overflow: hidden; }
.tx + .tx { margin-top: 8px; }
.tx::before { content: ''; position: absolute; left: 0; top: 10px; bottom: 10px; width: 4px; border-radius: 0 4px 4px 0; background: var(--cat); }
.tx-ic { width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; font-size: 20px; flex: none; background: color-mix(in srgb, var(--cat) 20%, transparent); }
.tx-main { flex: 1; min-width: 0; }
.tx-main .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-main .s { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-amt { font-weight: 800; text-align: right; flex: none; }
.chip-cat { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; background: color-mix(in srgb, var(--cat) 18%, transparent); color: color-mix(in srgb, var(--cat) 75%, var(--text)); }

.filters { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 6px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.pill { flex: none; height: 34px; padding: 0 14px; border-radius: 99px; background: var(--card); border: 1px solid var(--line); font-size: 13px; font-weight: 600; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.pill.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--cat); display: inline-block; flex: none; }

/* ---------- members ---------- */
.member { display: flex; align-items: center; gap: 12px; padding: 11px 4px; border-bottom: 1px solid var(--line); }
.member:last-child { border-bottom: 0; }
.m-ava { width: 38px; height: 38px; border-radius: 13px; display: grid; place-items: center; font-weight: 700; color: #fff; flex: none; font-size: 14px; }
.member .info { flex: 1; min-width: 0; }
.member .info .n { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member .info .e { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member .bal { text-align: right; font-weight: 700; font-size: 14px; flex: none; }
.member.off { opacity: .55; }

/* ---------- reports ---------- */
.chart-box { position: relative; height: 230px; }
.chart-box.tall { height: 260px; }
.donut-wrap { display: grid; grid-template-columns: 170px 1fr; gap: 16px; align-items: center; }
.donut-wrap .chart-box { height: 170px; }
.donut-center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; pointer-events: none; }
.donut-center .v { font-weight: 800; font-size: 15px; }
.legend { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend-row .n { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend-row .p { font-weight: 700; flex: none; }
.bar { height: 6px; border-radius: 99px; background: var(--card-hi); overflow: hidden; margin-top: 4px; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--cat); }
.cat-row { padding: 10px 0; border-bottom: 1px solid var(--line); }
.cat-row:last-child { border-bottom: 0; }
.cat-row .top { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.cat-row .top .n { flex: 1; font-weight: 600; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 12px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-weight: 800; font-size: 15px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 420px) {
  .donut-wrap { grid-template-columns: 1fr; }
  .donut-wrap .chart-box { height: 190px; }
  .hero .big { font-size: 30px; }
}

/* ---------- sheet / modal ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(5,4,15,.6); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); display: flex; align-items: flex-end; justify-content: center; animation: fade .18s; }
.sheet { width: 100%; max-width: 600px; max-height: 92dvh; overflow-y: auto; background: var(--bg2); border: 1px solid var(--line); border-bottom: 0; border-radius: 28px 28px 0 0; padding: 10px 18px calc(22px + env(safe-area-inset-bottom)); animation: up .26s cubic-bezier(.2,.9,.3,1.1); }
.sheet .grip { width: 44px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { margin: 0 0 14px; font-size: 20px; }
@media (min-width: 640px) {
  .overlay { align-items: center; }
  .sheet { border-radius: 28px; border-bottom: 1px solid var(--line); max-height: 86dvh; }
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.field { margin-bottom: 14px; }
.field label, .lbl { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.input, textarea.input, select.input { width: 100%; height: 48px; padding: 0 14px; border-radius: 14px; background: var(--card-hi); border: 1px solid var(--line); outline: none; }
textarea.input { height: auto; min-height: 110px; padding: 12px 14px; resize: vertical; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,.22); }
.amount-input { font-size: 32px; font-weight: 800; height: 64px; letter-spacing: -.5px; text-align: center; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }

.seg { display: flex; padding: 4px; border-radius: 16px; background: var(--card-hi); border: 1px solid var(--line); gap: 4px; }
.seg button { flex: 1; height: 40px; border-radius: 12px; font-weight: 700; color: var(--muted); font-size: 14px; }
.seg button.on { background: var(--bg2); color: var(--text); box-shadow: 0 4px 12px -4px rgba(0,0,0,.4); }
.seg button.on.expense { background: var(--expense); color: #fff; }
.seg button.on.income { background: var(--income); color: #fff; }

.cat-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.cat-opt { display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 12px; border-radius: 12px; font-size: 13.5px; font-weight: 600; background: var(--card-hi); border: 1.5px solid transparent; }
.cat-opt.on { border-color: var(--cat); background: color-mix(in srgb, var(--cat) 22%, transparent); }

.people-box { border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.people-tools { display: flex; gap: 8px; padding: 10px; border-bottom: 1px solid var(--line); background: var(--card-hi); align-items: center; }
.people-tools .input { height: 38px; flex: 1; }
.people-list { max-height: 260px; overflow-y: auto; }
.person { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--line); cursor: pointer; user-select: none; }
.person:last-child { border-bottom: 0; }
.check { width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--faint); display: grid; place-items: center; flex: none; font-size: 13px; color: transparent; }
.person.on .check { background: var(--accent); border-color: var(--accent); color: #fff; }
.person .n { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.summary-box { margin-top: 10px; padding: 12px 14px; border-radius: 14px; background: color-mix(in srgb, var(--accent) 12%, transparent); font-size: 13.5px; }

.menu-list { display: flex; flex-direction: column; }
.menu-list button, .menu-list a { display: flex; align-items: center; gap: 12px; padding: 14px 6px; border-bottom: 1px solid var(--line); font-weight: 600; text-align: left; text-decoration: none; }
.menu-list > :last-child { border-bottom: 0; }
.menu-list .i { width: 36px; height: 36px; border-radius: 12px; background: var(--card-hi); display: grid; place-items: center; font-size: 17px; flex: none; }

.color-row { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 34px; height: 34px; border-radius: 11px; border: 3px solid transparent; }
.swatch.on { border-color: var(--text); }
.emoji-row { display: flex; flex-wrap: wrap; gap: 6px; }
.emoji-row button { width: 42px; height: 42px; border-radius: 12px; background: var(--card-hi); font-size: 21px; border: 2px solid transparent; }
.emoji-row button.on { border-color: var(--accent); }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 30px 6px 60px; }
.login .logo-xl { width: 88px; height: 88px; border-radius: 28px; background: var(--grad); display: grid; place-items: center; font-size: 46px; box-shadow: 0 24px 50px -16px var(--glow); margin-bottom: 26px; }
.login h1 { font-size: 40px; line-height: 1.1; letter-spacing: -1.4px; margin: 0 0 12px; font-weight: 800; }
.login h1 b { background: var(--grad-text); -webkit-background-clip: text; background-clip: text; color: transparent; }
.login p.lead { color: var(--muted); font-size: 16px; margin: 0 0 30px; max-width: 420px; }
.feature-list { display: grid; gap: 10px; margin: 0 0 30px; }
.feature-list div { display: flex; gap: 12px; align-items: center; font-size: 14px; color: var(--muted); }
.feature-list div span { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; background: var(--card-hi); font-size: 17px; flex: none; }
#gbtn { min-height: 44px; color-scheme: normal; }
#gbtn iframe { color-scheme: normal; }

/* ---------- toast & banner ---------- */
.toast { position: fixed; z-index: 90; left: 50%; top: calc(14px + env(safe-area-inset-top)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 14px; font-weight: 600; font-size: 14px; box-shadow: var(--shadow); max-width: calc(100% - 32px); animation: fade .2s; }
.toast.err { background: var(--expense); color: #fff; }
.install-banner { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: 20px; background: linear-gradient(135deg, rgba(245,199,107,.16), rgba(37,99,235,.16)); border: 1px solid rgba(245,199,107,.3); margin-top: 14px; }
.install-banner .t { flex: 1; font-size: 13.5px; }
.install-banner .t b { display: block; font-size: 14.5px; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; margin: 60px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.share-list { max-height: 280px; overflow-y: auto; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv:last-child { border-bottom: 0; }
