:root {
  --g900: #04342C; --g800: #085041; --g700: #0B5E4B; --g600: #0F6E56; --g400: #1D9E75; --g200: #5DCAA5; --g100: #9FE1CB; --g50: #E1F5EE;
  --bg: #F3F7F5; --card: #FFFFFF; --card2: #EEF3F1; --line: rgba(0,0,0,.08); --line2: rgba(0,0,0,.14);
  --text: #12201B; --muted: #5E6B66; --faint: #95A19C;
  --red: #D93B3A; --red-bg: #FCEBEB; --amber: #C77A0E; --amber-bg: #FAEEDA; --ok: #1D9E75; --ok-bg: #E1F5EE;
  --accent: var(--g600); --on-accent: #fff; --hero: #0F6E56; --hero-text: #fff; --hero-sub: #9FE1CB;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(15,110,86,.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0B1311; --card: #131D1A; --card2: #1A2622; --line: rgba(255,255,255,.08); --line2: rgba(255,255,255,.16);
    --text: #E8F1ED; --muted: #9AAAA4; --faint: #64736E;
    --red: #F07C7B; --red-bg: #3A1C1C; --amber: #F2B25C; --amber-bg: #3A2B12; --ok: #5DCAA5; --ok-bg: #12332A;
    --accent: #1D9E75; --hero: #0F6E56; --hero-sub: #9FE1CB;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.45; }
body { min-height: 100vh; min-height: 100dvh; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, select { font: inherit; color: var(--text); }
h1 { font-size: 24px; margin: 8px 0 4px; font-weight: 600; }
h2 { font-size: 18px; margin: 0; font-weight: 600; }
.muted { color: var(--muted); } .small { font-size: 13px; } .center-text { text-align: center; }
.err { color: var(--red); font-size: 13px; margin: 6px 0 0; min-height: 0; }
.err:empty { margin: 0; }

.screen { max-width: 520px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; }
.screen.center { display: flex; align-items: center; justify-content: center; padding: 24px 20px calc(24px + env(safe-area-inset-bottom)); }
.auth-card { width: 100%; background: var(--card); border-radius: 22px; padding: 28px 22px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.logo { width: 56px; height: 56px; border-radius: 16px; background: var(--g600); color: #fff; display: grid; place-items: center; font-size: 30px; }
.logo.small { width: 48px; height: 48px; font-size: 24px; margin: 0 auto 10px; }
.field { display: block; margin-top: 14px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select { width: 100%; height: 46px; border-radius: 12px; border: 1px solid var(--line2); background: var(--card); padding: 0 12px; outline: none; }
.field input:focus, .field select:focus, .amount-box input:focus { border-color: var(--g400); box-shadow: 0 0 0 3px rgba(29,158,117,.18); }
.code-input { letter-spacing: 10px; font-size: 22px !important; text-align: center; font-weight: 600; }
.btn { height: 48px; border-radius: 12px; padding: 0 18px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line2); background: var(--card); }
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.btn.primary:active { filter: brightness(.92); }
.btn.block { width: 100%; margin-top: 16px; }
.btn.grow { flex: 1; }
.btn.danger-ghost { color: var(--red); border-color: transparent; background: var(--red-bg); }
.btn.small { height: 36px; font-size: 13px; padding: 0 12px; border-radius: 10px; }
.btn[disabled] { opacity: .6; }
.link { color: var(--accent); font-weight: 600; font-size: 14px; padding: 8px 0; }
.row-links { display: flex; justify-content: space-between; margin-top: 8px; }

/* PIN */
.pin-wrap { width: 100%; max-width: 320px; text-align: center; }
.pin-dots { display: flex; justify-content: center; gap: 16px; margin: 18px 0 6px; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--g400); }
.pin-dots i.on { background: var(--g400); }
.pin-dots.shake { animation: shake .35s; }
@keyframes shake { 20%,60% { transform: translateX(-8px); } 40%,80% { transform: translateX(8px); } }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 14px; }
.keypad button { height: 66px; border-radius: 50%; width: 66px; margin: 0 auto; font-size: 26px; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); }
.keypad button:active { background: var(--g50); }
.keypad .kp-text { font-size: 13px; color: var(--accent); font-weight: 600; background: none; border: 0; box-shadow: none; }
.keypad button[data-k="del"] { background: none; border: 0; box-shadow: none; font-size: 26px; }

/* App shell */
.topbar-progress { position: fixed; top: 0; left: 0; height: 3px; width: 0; background: var(--g200); z-index: 50; transition: width .4s ease, opacity .3s; opacity: 0; }
.topbar-progress.on { width: 85%; opacity: 1; transition: width 3s cubic-bezier(.1,.7,.3,1); }
.app-head { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 4px; padding: calc(10px + env(safe-area-inset-top)) 12px 10px; background: var(--bg); }
.month-label { font-size: 18px; font-weight: 600; padding: 6px 8px; border-radius: 10px; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 22px; color: var(--muted); }
.icon-btn:active { background: var(--card2); }
.icon-btn.right { margin-left: auto; }
.icon-btn.spin i { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
main { padding: 0 14px calc(110px + env(safe-area-inset-bottom)); }
.view { animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

.tabbar { position: fixed; bottom: 0; left: 0; right: 0; max-width: 520px; margin: 0 auto; display: flex; background: var(--card); border-top: 1px solid var(--line); padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); z-index: 20; }
.tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--faint); padding: 4px 0; }
.tabbar button i { font-size: 23px; }
.tabbar button.on { color: var(--accent); font-weight: 600; }
.tab-gap { width: 72px; }
.fab { position: fixed; z-index: 21; left: 50%; transform: translateX(-50%); bottom: calc(22px + env(safe-area-inset-bottom)); width: 60px; height: 60px; border-radius: 50%; background: var(--g600); color: #fff; font-size: 30px; display: grid; place-items: center; box-shadow: 0 6px 18px rgba(15,110,86,.35); border: 4px solid var(--bg); }
.fab:active { transform: translateX(-50%) scale(.94); }

/* Cards */
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-top: 12px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.card-h { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.card-h h3 { margin: 0; font-size: 15px; font-weight: 600; }
.card-h .link { padding: 0; font-size: 13px; }
.hero { background: var(--hero); color: var(--hero-text); border-radius: 20px; padding: 18px; margin-top: 4px; position: relative; overflow: hidden; }
.hero::after { content: ""; position: absolute; right: -40px; top: -50px; width: 170px; height: 170px; border-radius: 50%; background: rgba(255,255,255,.06); }
.hero .lab { font-size: 13px; color: var(--hero-sub); }
.hero .big { font-size: 34px; font-weight: 700; letter-spacing: -.5px; margin: 2px 0 14px; }
.hero .big small { font-size: 16px; font-weight: 600; opacity: .8; margin-right: 4px; }
.hero .big.neg { color: #FFC9C9; }
.hero-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; position: relative; z-index: 1; }
.hero-row div { background: rgba(255,255,255,.1); border-radius: 12px; padding: 8px 10px; }
.hero-row span { display: block; font-size: 11px; color: var(--hero-sub); }
.hero-row b { font-size: 15px; font-weight: 600; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.tile { background: var(--card); border-radius: var(--radius); padding: 12px; border: 1px solid var(--line); box-shadow: var(--shadow); }
.tile span { font-size: 12px; color: var(--muted); display: block; }
.tile b { font-size: 20px; font-weight: 700; display: block; margin-top: 2px; }
.tile em { font-style: normal; font-size: 11px; color: var(--faint); }

.bud { padding: 8px 0; border-top: 1px solid var(--line); }
.bud:first-of-type { border-top: 0; padding-top: 0; }
.bud-top { display: flex; align-items: center; gap: 10px; }
.cat-ic { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-size: 18px; flex: none; background: var(--g50); color: var(--g700); }
@media (prefers-color-scheme: dark) { .cat-ic { background: #183129; color: var(--g100); } }
.bud-name { flex: 1; min-width: 0; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bud-amt { font-size: 13px; color: var(--muted); white-space: nowrap; }
.bud-amt b { color: var(--text); font-weight: 600; }
.bar { height: 7px; border-radius: 4px; background: var(--card2); margin: 7px 0 0 44px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 4px; background: var(--ok); }
.bar.warn i { background: #EF9F27; } .bar.over i { background: var(--red); }
.bud-st { font-size: 11px; margin: 3px 0 0 44px; color: var(--faint); }
.bud-st.warn { color: var(--amber); } .bud-st.over { color: var(--red); font-weight: 600; }

.ent { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); width: 100%; text-align: left; }
.ent:first-child { border-top: 0; }
.ent-mid { flex: 1; min-width: 0; }
.ent-mid b { font-weight: 500; font-size: 14px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ent-mid span { font-size: 12px; color: var(--faint); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ent-amt { font-weight: 600; font-size: 14px; white-space: nowrap; }
.ent-amt.inc { color: var(--ok); }
.cat-ic.inc { background: var(--ok-bg); color: var(--ok); }
.day-h { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin: 16px 2px 4px; font-weight: 600; }
.empty { text-align: center; padding: 28px 10px; color: var(--muted); }
.empty i { font-size: 36px; color: var(--g200); display: block; margin-bottom: 6px; }

.search-row { margin-top: 4px; }
.search { display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; height: 44px; }
.search i { color: var(--faint); font-size: 18px; }
.search input { border: 0; outline: 0; background: none; flex: 1; height: 100%; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.chip { height: 34px; padding: 0 14px; border-radius: 17px; background: var(--card); border: 1px solid var(--line2); font-size: 13px; }
.chip.on { background: var(--g600); color: #fff; border-color: transparent; }

/* Charts */
.donut-wrap { display: flex; align-items: center; gap: 14px; }
.donut { width: 140px; height: 140px; flex: none; }
.legend { flex: 1; min-width: 0; font-size: 12px; }
.legend div { display: flex; align-items: center; gap: 6px; padding: 3px 0; }
.legend i { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.legend span { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.legend b { font-weight: 600; }
.keyrow { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.keyrow i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 4px; }
.hbar { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 5px 0; }
.hbar span { width: 92px; color: var(--muted); }
.hbar div { flex: 1; height: 10px; border-radius: 5px; background: var(--card2); overflow: hidden; }
.hbar div i { display: block; height: 100%; background: var(--g400); border-radius: 5px; }
.hbar b { width: 70px; text-align: right; font-weight: 600; }
svg text { fill: var(--muted); font-family: var(--font); }

/* Budget settings */
.set-cat { border-top: 1px solid var(--line); padding: 10px 0; }
.set-cat:first-of-type { border-top: 0; }
.set-r1 { display: flex; gap: 8px; align-items: center; }
.set-r2 { display: flex; gap: 8px; align-items: center; margin-top: 8px; padding-left: 44px; }
.inp { height: 40px; border-radius: 10px; border: 1px solid var(--line2); background: var(--card); padding: 0 10px; outline: none; min-width: 0; }
.inp:focus { border-color: var(--g400); }
.inp.name { flex: 1; }
.inp.money { width: 110px; }
.inp.sel { flex: 1; }
.cat-ic.btnic { cursor: pointer; border: 1px dashed var(--g200); }
.del-x { width: 36px; height: 36px; border-radius: 10px; color: var(--faint); font-size: 18px; display: grid; place-items: center; flex: none; }
.del-x:active { background: var(--red-bg); color: var(--red); }
.simple-row { display: flex; gap: 8px; align-items: center; padding: 5px 0; }
.add-row { margin-top: 8px; color: var(--accent); font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 4px; padding: 6px 0; }
.savebar { position: fixed; left: 0; right: 0; max-width: 520px; margin: 0 auto; bottom: calc(86px + env(safe-area-inset-bottom)); padding: 0 14px; z-index: 22; }
.savebar .inner { background: var(--text); color: var(--bg); border-radius: 14px; padding: 10px 10px 10px 16px; display: flex; align-items: center; gap: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.savebar .inner span { flex: 1; font-size: 13px; }
.savebar .btn { height: 38px; }
.acct-row { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-top: 1px solid var(--line); width: 100%; text-align: left; font-size: 14px; }
.acct-row:first-of-type { border-top: 0; }
.acct-row i { font-size: 20px; color: var(--muted); }
.acct-row.danger, .acct-row.danger i { color: var(--red); }

/* Sheet */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; animation: fadebg .2s; }
@keyframes fadebg { from { opacity: 0; } }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; max-width: 520px; margin: 0 auto; background: var(--bg); border-radius: 22px 22px 0 0; z-index: 41; padding: 6px 16px calc(16px + env(safe-area-inset-bottom)); max-height: 94vh; max-height: 94dvh; overflow-y: auto; animation: up .25s cubic-bezier(.2,.8,.2,1); }
@keyframes up { from { transform: translateY(100%); } }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line2); margin: 4px auto 8px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.seg { display: flex; background: var(--card2); border-radius: 12px; padding: 3px; }
.seg button { flex: 1; height: 38px; border-radius: 10px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.seg button.on[data-t="Expense"] { background: var(--red); color: #fff; }
.seg button.on[data-t="Income"] { background: var(--ok); color: #fff; }
.amount-box { display: block; text-align: center; margin-top: 12px; }
.amount-box span { font-size: 12px; color: var(--muted); }
.amount-box input { display: block; width: 100%; text-align: center; font-size: 38px; font-weight: 700; border: 1px solid transparent; background: none; outline: none; border-radius: 12px; padding: 4px; }
.lbl { font-size: 12px; color: var(--muted); margin: 14px 0 6px; }
.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cat-grid button { background: var(--card); border: 1.5px solid var(--line); border-radius: 12px; padding: 9px 2px 7px; font-size: 11px; line-height: 1.2; display: flex; flex-direction: column; align-items: center; gap: 4px; min-height: 66px; }
.cat-grid button i { font-size: 21px; color: var(--g600); }
.cat-grid button span { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; }
.cat-grid button.on { border-color: var(--g600); background: var(--g50); color: var(--g800); }
@media (prefers-color-scheme: dark) { .cat-grid button i { color: var(--g200); } .cat-grid button.on { background: #183129; color: var(--g50); } }
.two { display: grid; grid-template-columns: 1fr 140px; gap: 10px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }

.icon-pop { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; }
.icon-pop-inner { background: var(--bg); width: 100%; max-width: 520px; border-radius: 22px 22px 0 0; padding: 10px 16px calc(20px + env(safe-area-inset-bottom)); }
.icon-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.icon-grid button { height: 48px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); font-size: 22px; color: var(--g600); }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(96px + env(safe-area-inset-bottom)); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 70; max-width: 90%; text-align: center; animation: fade .2s; }
.toast.err { background: var(--red); color: #fff; }
.skel { background: linear-gradient(90deg, var(--card2), var(--card), var(--card2)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 14px; }
@keyframes sk { to { background-position: -200% 0; } }

.seg button.on[data-t="Card bill"] { background: #185FA5; color: #fff; }
.hint { font-size: 12px; color: var(--muted); background: var(--card2); border-radius: 10px; padding: 8px 10px; margin: 10px 0 0; }
.chip.sub { height: 32px; }
.ent-amt.bill { color: var(--muted); font-weight: 500; }
.cat-ic.bill { background: #E6F1FB; color: #185FA5; }
@media (prefers-color-scheme: dark) { .cat-ic.bill { background: #0C2A47; color: #85B7EB; } }
.cc-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.cc-row:first-of-type { border-top: 0; padding-top: 0; }
.cc-mid { flex: 1; min-width: 0; }
.cc-mid b { font-weight: 500; font-size: 14px; display: block; }
.cc-mid span { font-size: 12px; color: var(--faint); }
.cc-owed { text-align: right; font-size: 11px; color: var(--muted); }
.cc-owed b { display: block; font-size: 15px; color: var(--text); font-weight: 600; }
.cc-owed b.clear { color: var(--ok); }

/* iPhone: stop double-tap zoom on fast taps (PIN pad, buttons) and zoom-on-focus for text boxes */
html, body { touch-action: manipulation; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
button, a, input, select, label, .keypad button { touch-action: manipulation; }
input, select, textarea, .field input, .field select, .inp, .search input { font-size: 16px; }
.keypad, .keypad button { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.keypad button.down { background: var(--g50); transform: scale(.94); }
