:root {
  --bg: #f4f2ee; --card: #ffffff; --ink: #1d2320; --muted: #6b726e; --line: #e4e1db;
  --brand: #1f6f54; --brand-ink: #ffffff; --brand-soft: #e3f0ea;
  --ok: #2f8a5f; --warn: #c98a16; --over: #c2412d; --track: #ebe8e2;
  --ashley: #8a4fbf; --nathan: #2d6cc4; --both: #138a83;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(0,0,0,.05);
  --r: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121514; --card: #1c201e; --ink: #ecefed; --muted: #9aa39e; --line: #2c312e;
    --brand: #3fae84; --brand-ink: #0c1411; --brand-soft: #1d3a2f;
    --ok: #4cbf86; --warn: #e2a93b; --over: #ef6a55; --track: #2a2f2c;
    --ashley: #b68ae0; --nathan: #6ea3ee; --both: #45c2ba;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* touch-action: manipulation kills double-tap-to-zoom (fast keypad taps were zooming the page);
   overscroll-behavior stops pull-to-refresh and edge bounce from dragging the layout around. */
html { touch-action: manipulation; overscroll-behavior: none; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; background: var(--bg); color: var(--ink); overflow-x: hidden; }
body { overscroll-behavior: none; }
body { font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
a { color: var(--brand); }

/* ---------- lock ---------- */
.lock { position: fixed; inset: 0; height: 100dvh; display: flex; overflow-y: auto; overscroll-behavior: contain; background: var(--bg); z-index: 50;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 16px); user-select: none; -webkit-user-select: none; }
.lock-inner { width: 100%; max-width: 300px; text-align: center; margin: auto; } /* margin:auto centers but never clips the top */
.lock-logo { width: 64px; height: 64px; border-radius: 16px; }
.lock h1 { margin: 10px 0 0; font-size: 24px; }
.lock p { margin: 4px 0; }
.dots { display: flex; gap: 12px; justify-content: center; height: 16px; margin: 18px 0 6px; }
.dots i { width: 13px; height: 13px; border-radius: 50%; background: var(--ink); }
.lock-err { min-height: 22px; color: var(--over); font-size: 14px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: min(14px, 1.6dvh); margin-top: 8px; }
.keypad button { --k: clamp(52px, 8.5dvh, 70px); height: var(--k); width: var(--k); border-radius: 50%; touch-action: manipulation; justify-self: center; background: var(--card); box-shadow: var(--shadow); font-size: 26px; border: 1px solid var(--line); }
.keypad button:active { background: var(--brand-soft); }
.keypad .ok { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

/* ---------- layout ---------- */
#main { max-width: 600px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 8px) 16px calc(env(safe-area-inset-bottom) + 96px); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0 12px; }
.topbar h1 { font-size: 20px; margin: 0; text-align: center; flex: 1; }
.iconbtn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; color: var(--muted); }
.iconbtn:active { background: var(--track); }
.iconbtn:disabled { opacity: .25; }
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 16px; margin-bottom: 12px; }
h2.sec { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 20px 4px 8px; font-weight: 600; }

/* ---------- tab bar ---------- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around; align-items: center;
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding: 6px 4px calc(env(safe-area-inset-bottom) + 6px); z-index: 10; }
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 4px 0; max-width: 110px; }
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab.on { color: var(--brand); }
.tab.add { flex: 0 0 auto; width: 58px; height: 58px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); justify-content: center; margin-top: -26px; box-shadow: 0 4px 14px rgba(31,111,84,.4); }
.tab.add svg { width: 30px; height: 30px; stroke-width: 2.6; }
.tab.add:active { transform: scale(.95); }

/* ---------- budget overview ---------- */
.hero .big { font-size: 34px; font-weight: 700; letter-spacing: -.02em; }
.hero .big small { font-size: 16px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.hero .big.neg { color: var(--over); }
.bar { position: relative; height: 10px; border-radius: 6px; background: var(--track); margin: 10px 0 8px; overflow: visible; }
.bar > i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 6px; background: var(--ok); max-width: 100%; }
.bar.warn > i { background: var(--warn); }
.bar.over > i { background: var(--over); }
.bar > b { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink); opacity: .35; border-radius: 1px; }
.bar.thin { height: 6px; margin: 6px 0 4px; }
.row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.who { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; font-size: 14px; }
.who span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.c-Ashley { background: var(--ashley); } .c-Nathan { background: var(--nathan); } .c-Both { background: var(--both); }

.banner { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: var(--brand-soft); border: 1px solid color-mix(in srgb, var(--brand) 30%, transparent); border-radius: var(--r); padding: 12px 14px; margin-bottom: 12px; }
.banner b { color: var(--brand); }
.banner .chev { margin-left: auto; color: var(--muted); }
.banner.install { padding: 8px 6px 8px 14px; }
.banner.install span { flex: 1; }
.btn.sm { padding: 7px 14px; border-radius: 10px; font-size: 14px; }
.lock-install { margin-top: 26px; font-size: 15px; }
.banner.offline { background: color-mix(in srgb, var(--warn) 15%, var(--card)); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }

.cat { display: block; width: 100%; text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.cat:last-child { border-bottom: 0; }
.cat:active { background: var(--track); }
.cat .name { font-weight: 600; font-size: 15px; }
.cat .left { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cat .left.over { color: var(--over); } .cat .left.warn { color: var(--warn); }
.cat .sub { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.list { padding: 0; overflow: hidden; }

/* ---------- history ---------- */
.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 8px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.pill { flex: 0 0 auto; padding: 7px 13px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 14px; white-space: nowrap; }
.pill.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
select.pill { appearance: none; -webkit-appearance: none; padding-right: 26px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%; background-size: 5px 5px; background-repeat: no-repeat; max-width: 60vw; }
.day { font-size: 13px; color: var(--muted); margin: 16px 4px 6px; display: flex; justify-content: space-between; }
.tx { display: flex; width: 100%; gap: 12px; align-items: center; text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.tx:last-child { border-bottom: 0; }
.tx:active { background: var(--track); }
.tx .main { flex: 1; min-width: 0; }
.tx .main b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.tx .main small, .tx .side small { color: var(--muted); font-size: 13px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .main small { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tx .side { text-align: right; flex: 0 0 auto; }
.tx .side b { font-variant-numeric: tabular-nums; }
.tx .thumb { width: 42px; height: 42px; border-radius: 8px; object-fit: cover; flex: 0 0 auto; background: var(--track); }
.badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; color: #fff; font-size: 11px; font-weight: 700; vertical-align: 1px; }
.tag-pending { color: var(--warn); font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.catinfo p { margin: 6px 0 0; font-size: 14px; }

/* ---------- sheet (editor) ---------- */
.sheet { position: fixed; inset: 0; height: 100dvh; z-index: 30; overscroll-behavior: contain; background: var(--bg); display: flex; flex-direction: column; animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: calc(env(safe-area-inset-top) + 8px) 12px 8px; border-bottom: 1px solid var(--line); background: var(--card); }
.sheet-head h2 { font-size: 17px; margin: 0; }
.sheet-head .link { padding: 8px 6px; color: var(--brand); font-size: 16px; min-width: 64px; text-align: left; }
.sheet-head .link.strong { font-weight: 700; text-align: right; }
.sheet-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 14px 16px calc(env(safe-area-inset-bottom) + 30px); max-width: 600px; width: 100%; margin: 0 auto; }
.amount { display: flex; align-items: center; justify-content: center; gap: 4px; font-size: 44px; font-weight: 700; margin: 6px 0 12px; }
.amount span { color: var(--muted); font-weight: 500; }
.amount input { width: 4ch; max-width: 70vw; border: 0; background: transparent; font-size: inherit; font-weight: inherit; text-align: left; outline: none; font-variant-numeric: tabular-nums; padding: 0; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--track); border-radius: 12px; padding: 3px; margin-bottom: 16px; }
.seg button { padding: 9px 0; border-radius: 10px; font-weight: 600; color: var(--muted); display: flex; align-items: center; justify-content: center; gap: 6px; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.field { margin-bottom: 16px; }
.label-row { display: flex; justify-content: space-between; align-items: center; margin: 0 2px 6px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.label-row button { text-transform: none; letter-spacing: 0; color: var(--brand); font-weight: 600; font-size: 14px; padding: 2px 4px; }
.input, textarea.input { width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); outline: none; }
.input:focus { border-color: var(--brand); }
textarea.input { min-height: 70px; resize: vertical; }
.places { margin-top: 8px; display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.places:empty { display: none; }
.place { display: flex; justify-content: space-between; gap: 10px; text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.place:last-child { border-bottom: 0; }
.place.on { background: var(--brand-soft); }
.place b { font-weight: 600; }
.place small { color: var(--muted); font-size: 13px; white-space: nowrap; }
.place .k { display: block; color: var(--muted); font-size: 13px; }
.places .note { padding: 10px 14px; color: var(--muted); font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip { padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 14px; line-height: 1.2; }
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.splits { margin-top: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.split { display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 14px; border-bottom: 1px solid var(--line); }
.split span { flex: 1; font-size: 15px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.split label { display: flex; align-items: center; gap: 2px; color: var(--muted); }
.split input { width: 92px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); text-align: right; font-variant-numeric: tabular-nums; outline: none; }
.split input:focus { border-color: var(--brand); }
.split input.auto { color: var(--muted); font-style: italic; }
.split .x { width: 32px; height: 32px; color: var(--muted); font-size: 20px; }
.split-sum { padding: 9px 14px; font-size: 14px; display: flex; justify-content: space-between; }
.split-sum.bad { color: var(--over); font-weight: 600; } .split-sum.good { color: var(--ok); }
.receipt-box { display: flex; gap: 12px; align-items: center; }
.receipt-box img { width: 84px; height: 84px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-weight: 600; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { color: var(--over); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.when { display: flex; align-items: center; gap: 10px; }
.when input { flex: 1; }

/* ---------- settings ---------- */
.set-cat { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.set-cat:last-child { border-bottom: 0; }
.set-cat .r1 { display: flex; gap: 6px; align-items: center; }
.set-cat .r1 input { flex: 1; min-width: 0; }
.set-cat .r2 { display: flex; gap: 10px; margin-top: 8px; align-items: center; flex-wrap: wrap; }
.set-cat .r2 label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.set-cat .r2 input[type=number] { width: 92px; }
.set-cat.archived { opacity: .55; }
.set-cat .iconbtn { width: 34px; height: 34px; font-size: 16px; }
.input.sm { padding: 8px 10px; border-radius: 10px; }
.stack { display: flex; flex-direction: column; gap: 10px; }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 92px); z-index: 60; background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 12px; font-size: 15px; display: flex; gap: 14px; align-items: center; max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.toast button { color: var(--brand-soft); font-weight: 700; }
@media (prefers-color-scheme: dark) { .toast button { color: var(--brand); } }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: sp .8s linear infinite; vertical-align: -2px; }
@keyframes sp { to { transform: rotate(360deg); } }
