:root {
  --bg: #f4f4f8; --card: #ffffff; --text: #16161d; --muted: #6b6b7b; --line: #e6e6ee;
  --brand: #4f46e5; --brand-2: #6366f1; --brand-ink: #ffffff;
  --pos: #0f8a5f; --neg: #d0461b; --danger: #c62828;
  --radius: 14px; --tabh: 64px;
  --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: #0e0e13; --card: #1a1a22; --text: #f0f0f5; --muted: #9a9aab; --line: #2a2a35;
    --brand: #818cf8; --brand-2: #6366f1; --brand-ink: #0e0e13; --pos: #34d399; --neg: #fb8b5b; --danger: #ef5350; }
}
* { 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;
  padding-bottom: calc(var(--tabh) + var(--safe-b) + 16px); min-height: 100vh; overscroll-behavior-y: none; }
body.notabs { padding-bottom: var(--safe-b); }
body.notabs .tabbar { display: none; }
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 17px; margin: 0; text-align: center; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 4px 8px; font-weight: 600; }
.card h2, .ghead h2 { text-transform: none; letter-spacing: 0; color: var(--text); font-size: 20px; margin: 0 0 2px; }
main { max-width: 640px; margin: 0 auto; padding: 12px 16px; }

header.top { position: sticky; top: 0; z-index: 5; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  padding: calc(var(--safe-t) + 10px) 12px 10px; background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(16px); backdrop-filter: saturate(180%) blur(16px); border-bottom: 1px solid var(--line); }
header .hl { justify-self: start; } header .hr { justify-self: end; }
.hbtn { background: none; border: 0; color: var(--brand); font: inherit; font-size: 16px; padding: 6px 4px; cursor: pointer; }
.hbtn.strong { font-weight: 650; }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: space-around; align-items: center;
  height: calc(var(--tabh) + var(--safe-b)); padding-bottom: var(--safe-b); background: color-mix(in srgb, var(--card) 92%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); border-top: 1px solid var(--line); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 6px 0; }
.tabbar a.on { color: var(--brand); }
.tabbar a .ti { font-size: 20px; filter: grayscale(1); opacity: .7; }
.tabbar a.on .ti { filter: none; opacity: 1; }
.tabbar .tab-add { flex: 0 0 auto; width: 52px; height: 52px; border-radius: 50%; background: var(--brand); color: var(--brand-ink);
  justify-content: center; font-size: 28px; box-shadow: 0 4px 14px rgb(79 70 229 / .35); margin-top: -18px; }

.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin: 10px 0; border: 1px solid var(--line); }
.list { background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; margin: 10px 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; color: var(--text); border-top: 1px solid var(--line);
  width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; font: inherit; text-align: left; }
.list > .row:first-child, .list > .month:first-child + .row { border-top: 0; }
a.row:active, button.row:active { background: color-mix(in srgb, var(--brand) 8%, transparent); }
.month { font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 14px 6px; background: var(--bg); text-transform: uppercase; letter-spacing: .04em; }
.grow { flex: 1; min-width: 0; }
.title { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub { font-size: 13px; color: var(--muted); }
.small { font-size: 13px; }
.muted { color: var(--muted); }
.pos { color: var(--pos); } .neg { color: var(--neg); } .danger { color: var(--danger); }
.center { text-align: center; }
.chev { color: var(--muted); font-size: 22px; }
.eff { text-align: right; font-size: 14px; flex: 0 0 auto; max-width: 48%; }
.eff b { display: block; font-size: 15px; }
.txn .date { width: 30px; text-align: center; font-size: 11px; color: var(--muted); line-height: 1.1; }
.txn .date b { display: block; font-size: 17px; color: var(--text); font-weight: 600; }
.cat, .gicon { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; font-size: 20px; background: var(--bg); flex: 0 0 auto; }
.gicon.big { width: 56px; height: 56px; font-size: 30px; border-radius: 14px; }
.txn.payment .title { font-weight: 450; }
.avatar { --h: 240; width: 34px; height: 34px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 13px; font-weight: 650;
  color: hsl(var(--h) 60% 30%); background: hsl(var(--h) 70% 88%); flex: 0 0 auto; }
@media (prefers-color-scheme: dark) { .avatar { color: hsl(var(--h) 70% 85%); background: hsl(var(--h) 35% 28%); } }
.avatar.big { width: 56px; height: 56px; font-size: 20px; }

.summary { display: flex; flex-direction: column; gap: 10px; }
.summary > div:first-child b { font-size: 20px; }
.split2 { display: flex; gap: 12px; } .split2 > div { flex: 1; background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.ghead { display: flex; gap: 14px; align-items: flex-start; }
.bigbal { font-size: 18px; font-weight: 600; margin: 2px 0 6px; }
.bigbal b { font-size: 26px; }
.debts { font-size: 14px; display: grid; gap: 3px; }
.debts details summary { color: var(--muted); cursor: pointer; margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.actions .btn { flex: 1; }
.hint { border-color: color-mix(in srgb, var(--brand) 40%, var(--line)); background: color-mix(in srgb, var(--brand) 7%, var(--card)); font-size: 14px; }
.hint .share { white-space: nowrap; font-weight: 600; }
.hint .link { display: block; margin-top: 6px; }

.btn { display: inline-flex; justify-content: center; align-items: center; gap: 6px; padding: 11px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; font-weight: 600; font-size: 15px; cursor: pointer; text-align: center; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.wide { display: flex; width: 100%; margin: 14px 0; }
.btn:active { transform: scale(.98); }
.link { background: none; border: 0; color: var(--brand); font: inherit; padding: 0; cursor: pointer; }
.link.danger { color: var(--danger); font-size: 14px; }

.form { display: grid; gap: 12px; }
.form.inline { display: flex; gap: 8px; }
.form.inline input { flex: 1; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 500; }
label.check { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 15px; }
input, select, textarea { font: inherit; font-size: 16px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; width: 100%; min-height: 44px; -webkit-appearance: none; appearance: none; }
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
input[type=checkbox] { width: 22px; height: 22px; min-height: 0; padding: 0; border-radius: 6px; flex: 0 0 auto; position: relative; }
input[type=checkbox]:checked { background: var(--brand); border-color: var(--brand); }
input[type=checkbox]:checked::after { content: ""; position: absolute; left: 7px; top: 3px; width: 5px; height: 10px; border: solid var(--brand-ink); border-width: 0 2px 2px 0; transform: rotate(45deg); }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 50%, transparent); outline-offset: 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.search { margin: 4px 0 8px; }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted); padding: 8px 0; border-radius: 9px; cursor: pointer; }
.seg button.on { background: var(--brand); color: var(--brand-ink); }
.prow.off .avatar { opacity: .45; } .prow.off { color: var(--muted); }
.prow .check { font-size: 15px; }
.mini { width: 78px; min-height: 36px; padding: 6px 8px; text-align: right; flex: 0 0 auto; }
.unit { font-size: 13px; color: var(--muted); margin-left: -6px; }
.share { width: 82px; text-align: right; font-size: 14px; color: var(--muted); flex: 0 0 auto; }
.status { text-align: center; font-size: 14px; font-weight: 600; min-height: 20px; }
.emojis { display: flex; flex-wrap: wrap; gap: 6px; }
.emojis button { font-size: 22px; width: 42px; height: 42px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; }
.emojis button.on { border-color: var(--brand); box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand) 40%, transparent); }
.pay { display: flex; align-items: center; justify-content: center; gap: 10px; }
.pay select { flex: 1; }
.arrow { color: var(--muted); font-weight: 600; white-space: nowrap; font-size: 14px; }
.bar { height: 6px; border-radius: 3px; background: var(--bg); margin-top: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--brand); border-radius: 3px; }

.empty { text-align: center; color: var(--muted); padding: 36px 16px; line-height: 2; }
.empty .btn { margin-top: 8px; }
.welcome { max-width: 420px; margin: 0 auto; padding: calc(var(--safe-t) + 48px) 20px 24px; text-align: center; }
.welcome h1 { font-size: 28px; margin: 16px 0 6px; }
.welcome .form { text-align: left; margin-top: 24px; }
.logo { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: linear-gradient(135deg, var(--brand-2), #8b5cf6); color: #fff; font-weight: 800; }
.logo.big { width: 84px; height: 84px; border-radius: 22px; font-size: 44px; }

#toast { position: fixed; left: 50%; bottom: calc(var(--tabh) + var(--safe-b) + 20px); transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 20px; font-size: 14px; font-weight: 600; transition: .25s; z-index: 20; max-width: 90vw; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
