:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #14211f;
  --muted: #62726f;
  --line: #e3e9e7;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --brand-soft: #d9f0ec;
  --income: #15803d;
  --income-soft: #dcf5e4;
  --expense: #c2410c;
  --expense-soft: #fde6da;
  --warn: #b45309;
  --warn-soft: #fdf0cf;
  --danger: #b91c1c;
  --shadow: 0 1px 2px rgba(16, 40, 36, .06), 0 4px 14px rgba(16, 40, 36, .06);
  --radius: 18px;
  --nav-h: 64px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1413;
    --card: #152120;
    --text: #e8f1ef;
    --muted: #94a8a4;
    --line: #243433;
    --brand: #2dd4bf;
    --brand-ink: #04211e;
    --brand-soft: #123a36;
    --income: #4ade80;
    --income-soft: #12301f;
    --expense: #fb923c;
    --expense-soft: #3a2113;
    --warn: #fbbf24;
    --warn-soft: #3a2f0f;
    --danger: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; min-height: 100dvh; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.income { color: var(--income); }
.expense { color: var(--expense); }
.hidden { display: none !important; }

/* layout */
#app { max-width: 560px; margin: 0 auto; min-height: 100dvh; position: relative; }
.page { padding: 16px 16px calc(var(--nav-h) + 40px + env(safe-area-inset-bottom)); display: grid; gap: 14px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.topbar h1 { font-size: 1.25rem; }
.back { border: 0; background: var(--card); width: 40px; height: 40px; border-radius: 12px; box-shadow: var(--shadow); font-size: 1.2rem; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card h2 { font-size: 1rem; margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between; }
.card h2 a, .link { color: var(--brand); font-size: .875rem; font-weight: 600; text-decoration: none; background: none; border: 0; padding: 0; }

/* month switcher */
.month { display: flex; align-items: center; justify-content: space-between; background: var(--card); border-radius: 14px; padding: 4px; box-shadow: var(--shadow); }
.month button { border: 0; background: transparent; width: 44px; height: 40px; border-radius: 10px; font-size: 1.3rem; color: var(--brand); }
.month button:disabled { opacity: .3; }
.month strong { font-size: 1rem; }

/* hero */
.hero { background: linear-gradient(135deg, #0f766e, #115e59); color: #fff; border-radius: 22px; padding: 20px; box-shadow: var(--shadow); }
.hero small { opacity: .85; font-size: .8rem; letter-spacing: .02em; }
.hero .big { font-size: 2rem; font-weight: 700; margin: 2px 0 14px; }
.hero .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hero .pill { background: rgba(255, 255, 255, .14); border-radius: 14px; padding: 10px 12px; }
.hero .pill b { display: block; font-size: 1.05rem; margin-top: 2px; }
.hero .foot { margin-top: 12px; font-size: .8rem; opacity: .9; }

/* progress bars */
.bar { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--income); transition: width .4s; }
.bar.warn > i { background: var(--warn); }
.bar.over > i { background: var(--danger); }
.bud { display: grid; gap: 6px; padding: 10px 0; border-top: 1px solid var(--line); background: none; border-left: 0; border-right: 0; border-bottom: 0; width: 100%; text-align: left; }
.bud:first-of-type { border-top: 0; }
.bud .head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.bud .sub { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); }
.bud .sub .over { color: var(--danger); font-weight: 600; }

/* lists */
.list { display: grid; }
.item { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); background: none; border-left: 0; border-right: 0; border-bottom: 0; width: 100%; text-align: left; }
.list > .item:first-child { border-top: 0; }
.ico { width: 42px; height: 42px; flex: none; border-radius: 13px; display: grid; place-items: center; font-size: 1.3rem; background: var(--brand-soft); }
.ico.expense { background: var(--expense-soft); }
.ico.income { background: var(--income-soft); }
.item .mid { flex: 1; min-width: 0; }
.item .mid b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .mid span { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.item .amt { font-weight: 700; white-space: nowrap; }
.chev { color: var(--muted); }
.daygroup { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); font-weight: 600; padding: 6px 4px 0; }

/* wallets strip */
.strip { display: flex; gap: 10px; overflow-x: auto; margin: 0 -16px; padding: 2px 16px 6px; scroll-snap-type: x proximity; scroll-padding: 0 16px; scrollbar-width: none; }
.strip::-webkit-scrollbar { display: none; }
.wcard { flex: none; min-width: 148px; background: var(--card); border-radius: 16px; padding: 12px 14px; box-shadow: var(--shadow); scroll-snap-align: start; }
.wcard .t { font-size: .8rem; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.wcard b { display: block; margin-top: 4px; font-size: 1.05rem; }

/* donut */
.donut-wrap { display: grid; grid-template-columns: 150px 1fr; gap: 14px; align-items: center; }
.legend { display: grid; gap: 6px; font-size: .85rem; }
.legend div { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.legend span { display: flex; align-items: center; gap: 6px; min-width: 0; }
.legend span em { font-style: normal; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
@media (max-width: 400px) { .donut-wrap { grid-template-columns: 1fr; justify-items: center; } .legend { width: 100%; } }

/* nav */
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: center; pointer-events: none; }
.nav nav { pointer-events: auto; width: 100%; max-width: 560px; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(12px); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; }
.nav a { display: grid; place-items: center; gap: 1px; color: var(--muted); text-decoration: none; font-size: .7rem; font-weight: 600; height: var(--nav-h); }
.nav a svg { width: 24px; height: 24px; }
.nav a.active { color: var(--brand); }
.fab { justify-self: center; width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--brand); color: var(--brand-ink); font-size: 2rem; line-height: 1;
  box-shadow: 0 6px 18px rgba(15, 118, 110, .45); transform: translateY(-14px); }
.fab:active { transform: translateY(-12px) scale(.96); }

/* forms */
label.f { display: grid; gap: 6px; font-size: .85rem; color: var(--muted); font-weight: 600; }
.inp { width: 100%; border: 1.5px solid var(--line); background: var(--bg); border-radius: 12px; padding: 12px 14px; outline: none; color: var(--text); }
.inp:focus { border-color: var(--brand); }
.btn { border: 0; border-radius: 14px; padding: 14px 18px; font-weight: 700; background: var(--brand); color: var(--brand-ink); width: 100%; }
.btn.ghost { background: var(--brand-soft); color: var(--brand); }
.btn.danger { background: transparent; color: var(--danger); }
.btn:disabled { opacity: .5; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--bg); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { border: 0; background: transparent; padding: 10px 6px; border-radius: 9px; font-weight: 600; color: var(--muted); font-size: .9rem; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.seg button.on.expense { color: var(--expense); }
.seg button.on.income { color: var(--income); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1.5px solid var(--line); background: var(--bg); border-radius: 99px; padding: 8px 12px; font-size: .88rem; display: inline-flex; align-items: center; gap: 6px; }
.chip.on { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
.cat { border: 1.5px solid var(--line); background: var(--bg); border-radius: 14px; padding: 10px 4px; display: grid; gap: 2px; justify-items: center; font-size: .72rem; line-height: 1.15; text-align: center; }
.cat span { font-size: 1.4rem; }
.cat.on { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.amount { font-size: 2rem; font-weight: 700; text-align: center; border: 0; background: transparent; width: 100%; outline: none; color: var(--text); padding: 6px 0; }
.amount-wrap { text-align: center; background: var(--bg); border-radius: 16px; padding: 12px; }
.amount-wrap small { color: var(--muted); font-weight: 600; }
.stack { display: grid; gap: 14px; }
.err { color: var(--danger); font-size: .9rem; min-height: 1.2em; }

/* sheet */
.overlay { position: fixed; inset: 0; background: rgba(5, 15, 14, .5); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { background: var(--card); width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto; border-radius: 24px 24px 0 0; padding: 12px 16px calc(20px + env(safe-area-inset-bottom)); animation: up .2s ease-out; }
.sheet .grab { width: 44px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { font-size: 1.1rem; margin-bottom: 14px; text-align: center; }
@keyframes up { from { transform: translateY(40px); opacity: .5; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* auth */
.auth { min-height: 100dvh; display: grid; align-content: center; gap: 18px; padding: 24px 20px; }
.auth .logo { width: 64px; height: 64px; border-radius: 20px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-size: 2rem; }
.auth h1 { font-size: 1.7rem; }
.link-btn { background: none; border: 0; color: var(--brand); font-weight: 700; padding: 8px; }

/* toast */
#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: #14211f; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: .9rem; opacity: 0; pointer-events: none; transition: .25s; z-index: 80; max-width: 90vw; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--danger); }

.empty { text-align: center; color: var(--muted); padding: 22px 8px; font-size: .92rem; }
.empty b { display: block; font-size: 2rem; margin-bottom: 4px; }
.avatar { width: 20px; height: 20px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); font-size: .65rem; font-weight: 800; display: inline-grid; place-items: center; vertical-align: middle; margin-right: 4px; }
.code { font: 700 1.6rem ui-monospace, monospace; letter-spacing: .12em; text-align: center; padding: 12px; background: var(--bg); border-radius: 14px; user-select: all; }
.search { position: relative; }
.search .inp { padding-left: 38px; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
.avatar { font-style: normal; }
a.item { color: inherit; text-decoration: none; }
