: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); }

/* Layout fixes for iPhone: keep date box inside the screen, no sideways scrolling */
html, body { overflow-x: hidden; }
.sheet { overflow-x: hidden; }
.two { grid-template-columns: minmax(0, 1fr) minmax(0, 150px); }
.two .field { min-width: 0; }
.field input[type="date"] { -webkit-appearance: none; appearance: none; display: block; width: 100%; min-width: 0; max-width: 100%; text-align: left; line-height: 44px; padding: 0 10px; }
.field input[type="date"]::-webkit-date-and-time-value { text-align: left; margin: 0; }
.field input[type="date"]::-webkit-calendar-picker-indicator { margin-left: 0; }
.amount-box input { font-size: 38px; }

/* Date: fixed-size button with the real date picker invisible on top (iPhone date boxes are wider than their space) */
.date-box { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 6px; height: 46px; border-radius: 12px; border: 1px solid var(--line2); background: var(--card); padding: 0 12px; overflow: hidden; font-size: 15px; white-space: nowrap; }
.date-box i { color: var(--muted); font-size: 18px; }
.field .date-box input[type="date"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; border: 0; padding: 0; margin: 0; min-width: 0; -webkit-appearance: none; appearance: none; background: transparent; z-index: 1; }
/* Lock the add/edit sheet so it can only scroll up and down */
.sheet { overflow-x: clip; touch-action: pan-y; overscroll-behavior: contain; }
.sheet > * { max-width: 100%; min-width: 0; }
.cat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cat-grid button { min-width: 0; }
.amount-box input { min-width: 0; max-width: 100%; }
.field > span.date-box { display: flex; font-size: 15px; color: var(--text); margin-bottom: 0; }

/* v1.4: the sheet content can never be wider than the screen */
.sheet { overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch; width: 100%; }
.sheet-inner { width: 100%; max-width: 100%; overflow: hidden; overflow: clip; }
.sheet-inner > * { max-width: 100%; }
body.locked { position: fixed; left: 0; right: 0; width: 100%; overflow: hidden; }
.ver { text-align: center; font-size: 11px; color: var(--faint); margin: 14px 0 0; }

/* Lend & borrow */
.loan-link { display: flex; align-items: center; gap: 6px; justify-content: center; width: 100%; margin-top: 14px; font-size: 13px; color: var(--accent); font-weight: 600; padding: 8px; border-radius: 10px; background: var(--card2); }
.kind-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.kind-grid button { background: var(--card); border: 1.5px solid var(--line); border-radius: 12px; padding: 9px 10px; text-align: left; }
.kind-grid button b { display: block; font-size: 14px; font-weight: 600; }
.kind-grid button span { font-size: 11px; color: var(--muted); }
.kind-grid button.on { border-color: var(--g600); background: var(--g50); }
.kind-grid button.on.minus { border-color: var(--red); background: var(--red-bg); }
@media (prefers-color-scheme: dark) { .kind-grid button.on { background: #183129; } .kind-grid button.on.minus { background: var(--red-bg); } }
.seg.cur { margin-top: 14px; }
.seg.cur button.on { background: var(--g600); color: #fff; }
.view-head { display: flex; align-items: center; gap: 6px; margin: 2px 0 6px; }
.view-head h2 { flex: 1; }
.lb-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.lb-tile { border-radius: var(--radius); padding: 12px; }
.lb-tile.get { background: var(--hero); color: #fff; }
.lb-tile.owe { background: var(--card); border: 1px solid var(--line); }
.lb-tile span { font-size: 12px; display: block; opacity: .85; }
.lb-tile b { display: block; font-size: 18px; font-weight: 700; margin-top: 2px; line-height: 1.25; }
.lb-tile.owe b { color: var(--red); }
.lb-tile em { font-style: normal; font-size: 11px; opacity: .8; }
.approx { font-size: 12px; color: var(--muted); margin: 8px 2px 0; }
.av { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; flex: none; background: var(--g50); color: var(--g800); }
.av.owe { background: var(--red-bg); color: var(--red); }
.av.done { background: var(--card2); color: var(--faint); }
.av.big { width: 56px; height: 56px; font-size: 22px; margin: 0 auto; }
@media (prefers-color-scheme: dark) { .av { background: #183129; color: var(--g100); } }
.pp { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); width: 100%; text-align: left; }
.pp:first-child { border-top: 0; }
.pp-mid { flex: 1; min-width: 0; }
.pp-mid b { font-weight: 500; font-size: 14px; display: block; }
.pp-mid span { font-size: 12px; color: var(--faint); }
.pp-mid span.late { color: var(--red); font-weight: 600; }
.pp-amt { text-align: right; font-size: 11px; color: var(--muted); }
.pp-amt b { display: block; font-size: 14px; font-weight: 600; color: var(--ok); }
.pp-amt b.neg { color: var(--red); }
.pp-amt b.zero { color: var(--faint); }
.person-top { text-align: center; padding: 8px 0 4px; }
.person-top h2 { margin-top: 6px; }
.person-top .lab { font-size: 12px; color: var(--muted); margin-top: 6px; }
.person-top .amt { font-size: 26px; font-weight: 700; color: var(--ok); line-height: 1.25; }
.person-top .amt.neg { color: var(--red); }
.person-top .due { font-size: 12px; color: var(--muted); }
.person-top .due.late { color: var(--red); font-weight: 600; }
.btn-row { display: flex; gap: 8px; margin-top: 12px; }
.btn-row .btn { flex: 1; height: 44px; font-size: 14px; }
.btn.wa { color: #128C4A; }
.edit-box { margin-top: 10px; }
.lb-home .row { display: flex; gap: 10px; }
.lb-home .row > div { flex: 1; background: var(--card2); border-radius: 12px; padding: 9px 10px; }
.lb-home .row span { font-size: 11px; color: var(--muted); display: block; }
.lb-home .row b { font-size: 15px; font-weight: 600; line-height: 1.3; display: block; }
.lb-home .row .owe b { color: var(--red); }
.lb-home .late { font-size: 12px; color: var(--red); margin-top: 8px; font-weight: 600; }
.ent-amt.loan-in { color: var(--ok); }

/* switches */
.sw-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer; }
.sw-txt { flex: 1; min-width: 0; }
.sw-txt b { display: block; font-weight: 500; font-size: 14px; }
.sw-txt span { font-size: 12px; color: var(--faint); }
.sw { -webkit-appearance: none; appearance: none; width: 46px; height: 28px; border-radius: 14px; background: var(--line2); position: relative; flex: none; cursor: pointer; transition: background .2s; margin: 0; }
.sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.sw:checked { background: var(--g400); }
.sw:checked::after { transform: translateX(18px); }

/* Get back / You owe row in the balance card */
.hero-row.two { grid-template-columns: 1fr 1fr; margin-top: 8px; }
.hero-row.two button { background: rgba(255,255,255,.1); border-radius: 12px; padding: 8px 10px; text-align: left; color: inherit; display: block; }
.hero-row.two button:active { background: rgba(255,255,255,.18); }
.hero-row.two span { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--hero-sub); }
.hero-row.two span .ti { font-size: 13px; }
.hero-row.two b { display: block; font-size: 15px; font-weight: 600; }
.hero-row.two b.inr { font-size: 13px; opacity: .9; }
.hero-row.two .owe b { color: #FFD0C9; }
.hero-row.two em { font-style: normal; font-size: 11px; color: #FFD0C9; font-weight: 600; }
.hero-row.two button { display: flex; flex-direction: column; justify-content: flex-start; align-items: flex-start; }

/* Header on pages without the month bar */
.back-btn { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-size: 22px; background: var(--g50); color: var(--g800); flex: none; }
.back-btn:active { filter: brightness(.95); }
@media (prefers-color-scheme: dark) { .back-btn { background: #183129; color: var(--g100); } }
.head-title { font-size: 18px; font-weight: 600; margin: 0 0 0 6px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Borrowed money left */
.hero-top { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 10px; align-items: start; position: relative; z-index: 1; }
.hero-top .big { font-size: 30px; }
.hero .pot { background: rgba(255,255,255,.12); border-radius: 14px; padding: 9px 11px; text-align: left; color: #fff; display: flex; flex-direction: column; align-items: flex-start; margin-top: 2px; }
.hero .pot span { font-size: 11px; color: #FAC775; }
.hero .pot b { font-size: 18px; font-weight: 700; }
.hero .pot em { font-style: normal; font-size: 11px; color: var(--hero-sub); }
.seg.fund { margin-top: 0; }
.seg.fund button.on { background: var(--g600); color: #fff; }
.seg.fund button.on[data-f="Borrowed"] { background: #BA7517; color: #fff; }

.ent.pending { opacity: .55; }
.ent.pending .ent-mid span { color: var(--accent); font-weight: 600; }

/* v2.4 balance card: aligned top row + soft glass tiles */
.hero { padding: 16px; }
.hero::after { right: -60px; top: -70px; width: 190px; height: 190px; background: rgba(255,255,255,.07); }
.hero::before { content: ""; position: absolute; left: -50px; bottom: -80px; width: 180px; height: 180px; border-radius: 50%; background: rgba(159,225,203,.10); }
.hero-top { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; align-items: stretch; margin-bottom: 10px; }
.hero-top > div, .hero .pot { min-height: 92px; border-radius: 16px; padding: 12px 14px; display: flex; flex-direction: column; justify-content: center; align-items: flex-start; margin: 0; }
.hero-top > div .lab { margin: 0 0 4px; }
.hero-top .big { font-size: 28px; margin: 0; line-height: 1.15; }
.hero-top .big small { font-size: 14px; }
.hero .pot span { font-size: 12px; margin-bottom: 4px; }
.hero .pot b { font-size: 22px; line-height: 1.15; }
.hero .pot em { margin-top: 2px; }
/* glass */
.hero-top > div, .hero .pot, .hero-row div, .hero-row.two button {
  background: linear-gradient(135deg, rgba(255,255,255,.20), rgba(255,255,255,.06));
  border: 1px solid rgba(255,255,255,.22);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.28), 0 6px 16px rgba(4,52,44,.18);
  -webkit-backdrop-filter: blur(10px) saturate(140%); backdrop-filter: blur(10px) saturate(140%);
}
.hero-row div, .hero-row.two button { border-radius: 14px; }
.hero-row.two button:active, .hero .pot:active { background: linear-gradient(135deg, rgba(255,255,255,.28), rgba(255,255,255,.10)); }
.hero-row { position: relative; z-index: 1; }

/* ================= v2.5 theme: Classic mono (light) / All black (dark) ================= */
:root {
  --g900: #000; --g800: #111; --g700: #1A1A1A; --g600: #111; --g400: #333; --g200: #9A9A9A; --g100: #D9D9D9; --g50: #EFEFEF;
  --bg: #F5F5F5; --card: #FFFFFF; --card2: #EEEEEE; --line: rgba(0,0,0,.08); --line2: rgba(0,0,0,.16);
  --text: #111111; --muted: #5F5F5F; --faint: #9A9A9A;
  --ok: #111111; --ok-bg: #EFEFEF; --amber: #9A6A00; --amber-bg: #F6EEDC;
  --accent: #111111; --on-accent: #FFFFFF; --hero: #111111; --hero-text: #FFFFFF; --hero-sub: #BDBDBD;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --g900: #FFF; --g800: #F2F2F2; --g700: #E6E6E6; --g600: #F2F2F2; --g400: #CFCFCF; --g200: #8A8A8A; --g100: #3A3A3A; --g50: #1F1F1F;
    --bg: #0A0A0A; --card: #161616; --card2: #222222; --line: rgba(255,255,255,.08); --line2: rgba(255,255,255,.16);
    --text: #F2F2F2; --muted: #A0A0A0; --faint: #6E6E6E;
    --ok: #F2F2F2; --ok-bg: #222; --amber: #F2B25C; --amber-bg: #2E2410;
    --accent: #F2F2F2; --on-accent: #0A0A0A; --hero: #161616; --hero-sub: #9A9A9A;
  }
  .hero { background: linear-gradient(160deg, #2A2A2A, #121212); border: 1px solid #2E2E2E; }
  .cat-ic, .back-btn, .av { background: #222; color: #F2F2F2; }
  .cat-grid button i { color: #F2F2F2; }
  .cat-grid button.on { background: #262626; color: #F2F2F2; border-color: #F2F2F2; }
  .kind-grid button.on { background: #262626; border-color: #F2F2F2; }
}
/* anything that sat white-on-green now uses the accent pair, so it works in both modes */
.logo, .fab, .chip.on, .seg.cur button.on, .seg.fund button.on, .btn.primary, .sw:checked { background: var(--accent); color: var(--on-accent); }
.fab { box-shadow: 0 6px 18px rgba(0,0,0,.30); }
.sw:checked::after { background: var(--on-accent); }
.seg button.on[data-t="Income"] { background: var(--accent); color: var(--on-accent); }
.seg button.on[data-t="Card bill"] { background: #555; color: #fff; }
.seg.fund button.on[data-f="Borrowed"] { background: #8A6A1F; color: #fff; }
.cat-ic.inc, .cat-ic.bill { background: var(--card2); color: var(--text); }
.cat-grid button.on { border-color: var(--accent); }
.tabbar button.on { color: var(--accent); }
.pin-dots i { border-color: var(--text); } .pin-dots i.on { background: var(--text); }
.hero .pot span { color: #E8C98A; }
.hero-row.two .owe b, .hero-row.two em { color: #FFB4AE; }
.lb-tile.get { background: var(--hero); color: #fff; }
.donut-wrap svg circle { }
/* Budgets box: all-black style in both modes */
.bud-card { background: #111; color: #F2F2F2; border-color: #222; }
.bud-card .card-h h3 { color: #F2F2F2; }
.bud-card .link { color: #F2F2F2; text-decoration: underline; text-underline-offset: 3px; }
.bud-card .bud { border-top-color: rgba(255,255,255,.08); }
.bud-card .cat-ic { background: #222; color: #F2F2F2; }
.bud-card .bud-amt { color: #9A9A9A; } .bud-card .bud-amt b { color: #F2F2F2; }
.bud-card .bar { background: #2A2A2A; }
.bud-card .bar i { background: #F2F2F2; }
.bud-card .bar.warn i { background: #F2B25C; }
.bud-card .bar.over i { background: #E24B4A; }
.bud-card .bud-st { color: #8A8A8A; } .bud-card .bud-st.warn { color: #F2B25C; } .bud-card .bud-st.over { color: #F09595; }
.bud-card .empty { color: #9A9A9A; }
@media (prefers-color-scheme: dark) { .bud-card { background: #161616; border-color: #262626; } }
/* Budget bars keep their meaning: green = on track, amber = near limit (80%+), red = over */
.bud-card .bar i { background: #5DCAA5; }
.bud-card .bar.warn i { background: #F2B25C; }
.bud-card .bar.over i { background: #E24B4A; }
.bud-card .bud-st { color: #5DCAA5; }
.bud-card .bud-st.warn { color: #F2B25C; }
.bud-card .bud-st.over { color: #F09595; }
.hero::before { background: rgba(255,255,255,.06); }

/* Prepaid cards */
.cat-grid .cat-sub { font-style: normal; font-size: 10px; color: var(--faint); }
.chip.wallet { border-style: dashed; }
.chip.wallet.on { border-style: solid; }
.cc-row.wal { width: 100%; text-align: left; }
.wbar { display: block; height: 6px; background: var(--card2); border-radius: 3px; margin: 5px 0 3px; overflow: hidden; }
.wbar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.cc-owed b.zero { color: var(--faint); }

/* Split bills */
.split-sw { border-top: 0; margin-top: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.sp-add { display: flex; gap: 8px; margin-top: 8px; }
.sp-add .inp { flex: 1; }
.sp-rows { margin-top: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px 12px; }
.sp-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 0; border-top: 1px solid var(--line); }
.sp-row:first-child { border-top: 0; }
.sp-row .inp { width: 100px; text-align: right; }
.sp-sum { margin-top: 8px; background: var(--card2); border-radius: 12px; padding: 8px 12px; font-size: 13px; }
.sp-sum > div { display: flex; justify-content: space-between; padding: 2px 0; }
.sp-sum .get b, .sp-sum .get span { color: #1D7A55; }
.sp-sum .owe b, .sp-sum .owe span { color: var(--red); }
@media (prefers-color-scheme: dark) { .sp-sum .get b, .sp-sum .get span { color: #5DCAA5; } }
.lb-tabs { margin: 2px 0 10px; }
.lb-tabs button.on { background: var(--accent); color: var(--on-accent); }
.pp-amt span.get { color: var(--muted); } .pp-amt b.get { color: var(--ok); }
.grp-hero .big { margin-bottom: 10px; }

/* Calendar month picker */
.month-label { display: flex; flex-direction: column; align-items: flex-start; text-align: left; flex: 1; min-width: 0; padding: 2px 4px; line-height: 1.2; }
.month-label #m-text { font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.month-label small { font-size: 11px; color: var(--muted); font-weight: 400; margin-top: 2px; }
.cal-btn { width: 42px; height: 42px; border-radius: 12px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; font-size: 20px; flex: none; margin-left: auto; }
.cal-btn:active { transform: scale(.95); }
.mpick-bg { position: fixed; inset: 0; z-index: 55; background: rgba(0,0,0,.35); animation: fadebg .15s; }
.mpick { position: fixed; z-index: 56; left: 50%; transform: translateX(-50%); top: calc(64px + env(safe-area-inset-top)); width: calc(100% - 28px); max-width: 420px; background: var(--card); color: var(--text); border-radius: 18px; padding: 12px; box-shadow: 0 12px 36px rgba(0,0,0,.25); border: 1px solid var(--line); animation: pop .16s ease; }
@keyframes pop { from { opacity: 0; transform: translateX(-50%) translateY(-6px) scale(.98); } }
.mpick-head { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.mpick-head b { font-size: 17px; min-width: 52px; text-align: center; }
.mpick-head .icon-btn[disabled] { opacity: .3; }
.mp-x { margin-left: auto; width: 34px; height: 34px; border-radius: 50%; background: var(--card2); display: grid; place-items: center; font-size: 16px; }
.mp-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.mp-m { padding: 9px 4px; border-radius: 12px; background: var(--card2); font-weight: 600; font-size: 14px; display: flex; flex-direction: column; align-items: center; gap: 2px; border: 1.5px solid transparent; }
.mp-m small { font-size: 10px; font-weight: 400; color: var(--muted); }
.mp-m.now { border-color: var(--accent); }
.mp-m.on { background: var(--accent); color: var(--on-accent); }
.mp-m.on small { color: inherit; opacity: .75; }
.mp-m[disabled] { opacity: .35; }
