:root {
  color-scheme: light dark;
  --bg: #f2f2f7; --card: #fff; --card2: #e9e9ee; --label: #000; --label2: rgba(60,60,67,.62); --label3: rgba(60,60,67,.35);
  --sep: rgba(60,60,67,.18); --blue: #007aff; --red: #ff3b30; --green: #34c759; --orange: #ff9500; --yellow: #ffcc00; --amber: #b7791f; --amber-soft: #9a6a22; --purple: #af52de;
  --fill: rgba(120,120,128,.14); --tabbar: rgba(249,249,249,.86); --key: rgba(120,120,128,.14);
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", Inter, system-ui, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000; --card: #1c1c1e; --card2: #2c2c2e; --label: #fff; --label2: rgba(235,235,245,.6); --label3: rgba(235,235,245,.3);
    --sep: rgba(84,84,88,.55); --blue: #0a84ff; --red: #ff453a; --green: #30d158; --orange: #ff9f0a; --yellow: #ffd60a; --amber: #f2b84b; --amber-soft: #c9a063; --purple: #bf5af2;
    --fill: rgba(118,118,128,.24); --tabbar: rgba(22,22,24,.86); --key: rgba(255,255,255,.12);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--label); font-family: var(--font);
  -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%; overscroll-behavior-y: none; }
body { font-size: 17px; line-height: 1.3; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- lock ---------- */
.lock { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--bg);
  padding: calc(var(--sat) + 20px) 24px calc(var(--sab) + 20px); z-index: 50; }
.lock-inner { width: 100%; max-width: 320px; text-align: center; display: flex; flex-direction: column; align-items: center; }
.lock-icon { border-radius: 16px; margin-bottom: 18px; }
.lock-title { font-size: 22px; font-weight: 600; margin: 0 0 6px; }
.lock-sub { color: var(--label2); font-size: 15px; margin: 0 0 26px; min-height: 20px; }
.lock-sub.err { color: var(--red); }
.dots { display: flex; gap: 18px; justify-content: center; margin-bottom: 44px; min-height: 14px; }
.dots i { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--label); display: block; transition: background .12s; }
.dots i.on { background: var(--label); }
.dots.shake { animation: shake .4s; }
.dots.busy i { animation: pulse 1s infinite alternate; background: var(--label); }
@keyframes shake { 20%,60% { transform: translateX(-10px); } 40%,80% { transform: translateX(10px); } }
@keyframes pulse { to { opacity: .25; } }
.keypad { display: grid; grid-template-columns: repeat(3, 78px); gap: 16px 24px; justify-content: center; }
.keypad button { width: 78px; height: 78px; border-radius: 50%; background: var(--key); font-size: 34px; font-weight: 400;
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; transition: background .15s; }
.keypad button small { font-size: 10px; letter-spacing: 2px; font-weight: 600; margin-top: 2px; color: var(--label); opacity: .85; }
.keypad button:active { background: var(--label3); }
.keypad .key-del { background: none; font-size: 26px; }
.text-form { display: flex; flex-direction: column; gap: 12px; width: 100%; }
.text-form input { height: 50px; border-radius: 12px; border: 0; background: var(--card); padding: 0 16px; font-size: 17px; }

/* ---------- layout ---------- */
.app { min-height: 100%; }
/* bottom: clear the tab bar AND the floating + (FAB bottom 76px + 56px tall + 20px margin + safe area) */
.view { padding: calc(var(--sat) + 8px) calc(var(--sar) + 16px) calc(var(--sab) + 76px + 56px + 20px) calc(var(--sal) + 16px); max-width: 640px; margin: 0 auto; }
.head { display: flex; align-items: flex-end; justify-content: space-between; margin: 6px 0 14px; gap: 12px; }
.head h1 { font-size: 34px; font-weight: 700; letter-spacing: .3px; margin: 0; line-height: 1.15; }
.head .sub { color: var(--label2); font-size: 13px; margin-top: 2px; }
.head-actions { display: flex; gap: 8px; padding-bottom: 4px; }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; background: var(--fill); color: var(--blue); display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 500; }
.icon-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px calc(var(--sar) + 8px) calc(var(--sab) + 4px) calc(var(--sal) + 8px); background: var(--tabbar);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px); border-top: .5px solid var(--sep); z-index: 10; }
.tabbar button { display: flex; flex-direction: column; align-items: center; gap: 3px; min-height: 50px; justify-content: center; color: var(--label2); font-size: 10.5px; font-weight: 500; }
.tabbar svg { width: 27px; height: 27px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.active { color: var(--blue); }
.tabbar button.active svg { stroke-width: 2.3; }

/* ---------- cards & lists ---------- */
.card { background: var(--card); border-radius: 14px; padding: 16px; margin-bottom: 14px; }
.card.flush { padding: 0; overflow: hidden; }
.section-title { font-size: 13px; text-transform: uppercase; color: var(--label2); letter-spacing: .4px; margin: 22px 4px 7px; display: flex; justify-content: space-between; align-items: baseline; }
.section-title button { text-transform: none; color: var(--blue); font-size: 15px; letter-spacing: 0; }
.big { font-size: 40px; font-weight: 700; letter-spacing: -.5px; line-height: 1.1; }
.big.mid { font-size: 28px; }
.muted { color: var(--label2); }
.small { font-size: 13px; }
.label { font-size: 15px; color: var(--label2); font-weight: 500; margin-bottom: 4px; }
.red { color: var(--red); } .green { color: var(--green); } .orange { color: var(--orange); } .blue { color: var(--blue); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.grid2 .card { margin: 0; }
.tile { display: block; text-align: left; width: 100%; }
.tile .amt { font-size: 24px; font-weight: 700; margin-top: 2px; }

.row { display: flex; align-items: center; gap: 12px; padding: 11px 16px; min-height: 56px; position: relative; width: 100%; text-align: left; }
.row + .row::before { content: ""; position: absolute; top: 0; left: 64px; right: 0; border-top: .5px solid var(--sep); }
.row.noicon + .row.noicon::before { left: 16px; }
button.row:active, .row.tap:active { background: var(--fill); }
.ico { width: 36px; height: 36px; border-radius: 9px; flex: none; display: flex; align-items: center; justify-content: center; font-size: 19px; background: var(--fill); }
.row .main { flex: 1; min-width: 0; }
.row .t1 { font-size: 16px; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; }
.row .t2 { font-size: 13px; color: var(--label2); margin-top: 2px; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; }
.row .end { text-align: right; flex: none; font-variant-numeric: tabular-nums; }
.row .end .t2 { margin-top: 2px; }
.row.dim .t1, .row.dim .amt { color: var(--label2); }
.chev { color: var(--label3); font-size: 20px; margin-left: -4px; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 6px; border-radius: 6px; background: var(--fill); color: var(--label2); vertical-align: 1px; margin-left: 4px; }
.badge.red { background: rgba(255,69,58,.16); color: var(--red); }
.badge.orange { background: rgba(255,159,10,.16); color: var(--orange); }
.badge.blue { background: rgba(10,132,255,.16); color: var(--blue); }
.badge.green { background: rgba(48,209,88,.16); color: var(--green); }
.row.overdue .t1 { color: var(--red); font-weight: 600; }
.row.overdue { background: rgba(255,69,58,.07); }

.bar { height: 8px; border-radius: 4px; background: var(--fill); overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; border-radius: 4px; background: var(--green); transition: width .3s; }
.bar > i.warn { background: var(--orange); } .bar > i.over { background: var(--red); }
.bar.thin { height: 6px; margin-top: 6px; }

.empty { text-align: center; color: var(--label2); padding: 22px 16px; font-size: 15px; }
.note { font-size: 13px; color: var(--label2); margin: 6px 4px 0; line-height: 1.4; }
.banner { background: rgba(255,159,10,.14); color: var(--label); border-radius: 12px; padding: 12px 14px; font-size: 14px; margin-bottom: 14px; line-height: 1.4; }
.banner b { color: var(--orange); }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--fill); border-radius: 9px; padding: 2px; margin-bottom: 14px; }
.seg button { height: 32px; border-radius: 7px; font-size: 14px; font-weight: 600; }
.seg button.on { background: var(--card); box-shadow: 0 2px 6px rgba(0,0,0,.12); }
@media (prefers-color-scheme: dark) { .seg button.on { background: #636366; } }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 34px; padding: 0 14px; border-radius: 17px; background: var(--card); font-size: 14px; font-weight: 500; white-space: nowrap; }
.chip.on { background: var(--blue); color: #fff; }

.monthnav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.monthnav button { width: 44px; height: 44px; font-size: 24px; color: var(--blue); border-radius: 22px; }
.monthnav button:disabled { color: var(--label3); }
.monthnav b { font-size: 17px; }

.search { width: 100%; height: 40px; border-radius: 10px; border: 0; background: var(--fill); padding: 0 12px; font-size: 16px; margin-bottom: 10px; }
.day { font-size: 13px; color: var(--label2); margin: 16px 4px 6px; font-weight: 600; }

.input-row { display: flex; align-items: center; gap: 10px; }
.money-input { display: flex; align-items: center; background: var(--fill); border-radius: 10px; padding: 0 12px; height: 46px; flex: 1; }
.money-input span { color: var(--label2); font-size: 20px; }
.money-input input { border: 0; background: none; outline: none; font-size: 22px; font-weight: 600; width: 100%; padding-left: 4px; }

.order { counter-reset: n; }
.order .row .ico { font-weight: 700; font-size: 15px; color: var(--blue); background: rgba(10,132,255,.14); }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.compare .card { margin: 0; padding: 14px; }
.compare .card.on { box-shadow: inset 0 0 0 2px var(--blue); }
.compare .k { font-size: 13px; color: var(--label2); font-weight: 600; }
.compare .v { font-size: 20px; font-weight: 700; margin-top: 4px; }
.kv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.kv > div { background: var(--fill); border-radius: 10px; padding: 8px 10px; }
.kv .k { font-size: 11px; color: var(--label2); text-transform: uppercase; letter-spacing: .3px; font-weight: 600; }
.kv .v { font-size: 16px; font-weight: 600; margin-top: 2px; }
.debt-card h3 { margin: 0; font-size: 17px; font-weight: 600; }
.debt-card .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }

.btn-primary { height: 50px; border-radius: 12px; background: var(--blue); color: #fff; font-weight: 600; font-size: 17px; width: 100%; }
.btn-plain { height: 50px; border-radius: 12px; background: var(--card); color: var(--blue); font-weight: 500; font-size: 17px; width: 100%; margin-bottom: 10px; }
.btn-plain.danger { color: var(--red); }
.link { color: var(--blue); font-size: 17px; min-height: 44px; padding: 0 4px; }
.link.strong { font-weight: 600; }

/* ---------- sheet ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 40; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); animation: fade .2s; }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 92%; background: var(--bg); border-radius: 14px 14px 0 0;
  display: flex; flex-direction: column; animation: up .28s cubic-bezier(.2,.9,.3,1); padding-bottom: var(--sab); max-width: 640px; margin: 0 auto; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; border-bottom: .5px solid var(--sep); }
.sheet-head h2 { font-size: 17px; font-weight: 600; margin: 0; }
.sheet-body { overflow-y: auto; padding: 16px; -webkit-overflow-scrolling: touch; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }
.form { background: var(--card); border-radius: 12px; overflow: hidden; margin-bottom: 14px; }
.form label { display: flex; align-items: center; gap: 12px; padding: 0 16px; min-height: 50px; position: relative; }
.form label + label::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--sep); }
.form label span { flex: none; width: 112px; font-size: 16px; }
.form input, .form select { flex: 1; min-width: 0; border: 0; background: none; outline: none; font-size: 16px; text-align: right; height: 48px; }
.form select { direction: rtl; -webkit-appearance: none; appearance: none; color: var(--label2); }
.form input::placeholder { color: var(--label3); }

.dots.many { gap: 9px; }
.dots.many i { width: 11px; height: 11px; }
.face-btn { display: flex; align-items: center; gap: 8px; color: var(--blue); font-size: 17px; font-weight: 500; min-height: 44px; padding: 0 16px; margin: -28px 0 14px; border-radius: 22px; }
.face-btn svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.toast { position: fixed; left: 50%; bottom: calc(var(--sab) + 84px); transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: rgba(60,60,67,.92); color: #fff; padding: 11px 16px; border-radius: 14px; font-size: 15px; max-width: calc(100% - 40px);
  text-align: center; transition: opacity .2s, transform .2s; z-index: 60; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.dots[hidden] + .face-btn { margin: -10px 0 18px; }
.sheet-head { display: grid; grid-template-columns: 1fr auto 1fr; }
.sheet-head .link:first-child { justify-self: start; }
.sheet-head #sheetSave { justify-self: end; }

.tabbar button span { white-space: nowrap; }
.trend { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 14px 0 6px; align-items: end; }
.tcol { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.tval { font-size: 12px; color: var(--label2); font-weight: 600; }
.tbar { height: 64px; width: 100%; max-width: 54px; display: flex; align-items: flex-end; background: var(--fill); border-radius: 8px; overflow: hidden; }
.tbar i { display: block; width: 100%; background: rgba(48,209,88,.45); border-radius: 8px 8px 0 0; }
.tbar i.cur { background: var(--green); }
.tlab { font-size: 12px; color: var(--label2); }
.paynext { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: rgba(48,209,88,.10); }
.blue-bar > i { background: var(--blue) !important; }

/* v5 */
.hero .label { display: flex; justify-content: space-between; align-items: center; }
.hero .big { font-size: 44px; }
.fab { position: fixed; right: calc(var(--sar) + 18px); bottom: calc(var(--sab) + 76px); width: 56px; height: 56px; border-radius: 28px;
  background: var(--blue); color: #fff; font-size: 32px; font-weight: 400; line-height: 1; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 20px rgba(0,0,0,.35); z-index: 9; }
.fab:active { transform: scale(.94); }
.qa-amount { text-align: center; font-size: 48px; font-weight: 700; margin: 6px 0 12px; letter-spacing: -.5px; }
.qa-keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.qa-keys button { height: 54px; border-radius: 12px; background: var(--card); font-size: 26px; font-weight: 500; }
.qa-keys button:active { background: var(--fill); }
#qaSave:disabled { opacity: .45; }
.add-amt { display: inline-block; padding: 7px 11px; border-radius: 16px; background: rgba(10,132,255,.16); color: var(--blue); font-size: 14px; font-weight: 600; }
.pay-hist { border-top: .5px solid var(--sep); margin-top: 12px; }
.ph-row { display: grid; grid-template-columns: 56px 1fr auto; gap: 8px; font-size: 14px; padding: 5px 0; align-items: baseline; }
.small-btn { height: 42px; font-size: 16px; margin: 12px 0 0; background: var(--fill); }
.big-input { height: 56px; margin-top: 4px; }
.big-input input { font-size: 30px; }
.debt-card .top.tile { width: 100%; }

/* v7: calm "short" wording for negative safe-to-spend */
.amber { color: var(--amber); } .amber-soft { color: var(--amber-soft); }
.big-suffix { font-size: 20px; font-weight: 600; letter-spacing: 0; }
.after-pay { margin-top: 8px; padding: 8px 10px; border-radius: 10px; background: var(--fill); font-size: 14px; color: var(--label); }

/* v9: neutral, tappable 'No plan yet' */
.noplan { color: var(--label2); font-weight: 500; cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }
