/* Tally styles. iPhone first, safe-area aware, light and dark. */

:root {
  --accent-l: #0d9488;
  --accent-d: #2dd4bf;
  --accent: var(--accent-l);
  --on-accent: #fff;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --surface-3: #e4e7ec;
  --text: #101318;
  --text-2: #5b616e;
  --text-3: #8b919c;
  --line: rgba(16, 19, 24, 0.08);
  --track: rgba(16, 19, 24, 0.08);
  --danger: #dc3b40;
  --danger-bg: rgba(220, 59, 64, 0.1);
  --warn: #c47f00;
  --pos: #16924a;
  --shadow: 0 1px 2px rgba(16, 19, 24, 0.04), 0 4px 18px rgba(16, 19, 24, 0.05);
  --sheet-bg: #f4f5f7;
  --backdrop: rgba(10, 12, 16, 0.38);
  --radius: 18px;
  --radius-sm: 12px;
  --tab-h: 58px;
  --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);
  --gutter: 16px;
  --vvh: 100vh;
  --vvt: 0px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-round: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: var(--accent-d);
    --on-accent: #06110f;
    --bg: #0b0d10;
    --surface: #16191e;
    --surface-2: #1f2329;
    --surface-3: #2a2f37;
    --text: #f1f3f5;
    --text-2: #a3a9b4;
    --text-3: #6f7682;
    --line: rgba(255, 255, 255, 0.07);
    --track: rgba(255, 255, 255, 0.1);
    --danger: #ff6369;
    --danger-bg: rgba(255, 99, 105, 0.14);
    --warn: #f5b840;
    --pos: #3dd68c;
    --shadow: none;
    --sheet-bg: #111317;
    --backdrop: rgba(0, 0, 0, 0.55);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --accent: var(--accent-d);
  --on-accent: #06110f;
  --bg: #0b0d10;
  --surface: #16191e;
  --surface-2: #1f2329;
  --surface-3: #2a2f37;
  --text: #f1f3f5;
  --text-2: #a3a9b4;
  --text-3: #6f7682;
  --line: rgba(255, 255, 255, 0.07);
  --track: rgba(255, 255, 255, 0.1);
  --danger: #ff6369;
  --danger-bg: rgba(255, 99, 105, 0.14);
  --warn: #f5b840;
  --pos: #3dd68c;
  --shadow: none;
  --sheet-bg: #111317;
  --backdrop: rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
  overscroll-behavior-y: none;
}
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
html.locked, html.locked body { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
button:disabled { opacity: 0.45; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { margin: 0; }
p { margin: 0; }

.ic { width: 22px; height: 22px; flex: none; display: block; }
.ic.tiny { width: 15px; height: 15px; }
.ic.accent { color: var(--accent); }
.ic.pos { color: var(--pos); }
.ic.chev { width: 18px; height: 18px; color: var(--text-3); }
.muted { color: var(--text-3); }
.sm { font-size: 13px; }
.pos { color: var(--pos); }
.neg { color: var(--danger); }
.warn { color: var(--warn); }
.center { text-align: center; }

/* ---------- Layout ---------- */
.status-scrim {
  position: fixed; top: 0; left: 0; right: 0; height: var(--sat); z-index: 30;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  pointer-events: none;
}
.view {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(var(--sat) + 10px) calc(var(--gutter) + var(--sar)) calc(var(--tab-h) + var(--sab) + 28px) calc(var(--gutter) + var(--sal));
  min-height: 100vh;
}
.view.animate > * { animation: rise 0.42s cubic-bezier(.2, .8, .2, 1) both; }
.view.animate > *:nth-child(2) { animation-delay: 0.03s; }
.view.animate > *:nth-child(3) { animation-delay: 0.06s; }
.view.animate > *:nth-child(4) { animation-delay: 0.09s; }
.view.animate > *:nth-child(n+5) { animation-delay: 0.12s; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 8px 2px 14px; }
.page-head h1 { font-size: 32px; font-weight: 750; letter-spacing: -0.02em; line-height: 1.1; }
.eyebrow { font-size: 13px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 2px; }
.head-actions { display: flex; gap: 8px; }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; padding: 22px 4px 8px; }
.section-head h3 { font-size: 13px; font-weight: 650; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.06em; }
.hint { font-size: 13px; color: var(--text-3); margin: 10px 4px 0; line-height: 1.45; }
.hint.version { margin: 22px 0 6px; }

/* ---------- Buttons ---------- */
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; color: var(--text-2); flex: none; }
.icon-btn.round { border-radius: 50%; background: var(--surface); box-shadow: var(--shadow); color: var(--text); }
.icon-btn:active { background: var(--surface-2); }
.link-btn { color: var(--accent); font-weight: 600; font-size: 15px; padding: 4px 2px; }
.text-btn { color: var(--accent); font-size: 17px; padding: 8px 4px; }
.text-btn.strong { font-weight: 650; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 18px; border-radius: 14px; font-weight: 650; font-size: 16px;
  transition: transform .12s ease, opacity .12s ease;
}
.btn:active { transform: scale(0.98); opacity: 0.9; }
.btn .ic { width: 19px; height: 19px; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.soft { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
.btn.ghost { color: var(--text-2); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger-soft { background: var(--danger-bg); color: var(--danger); }
.btn.wide { width: 100%; margin-top: 14px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 16px; }
.btn-row .btn { min-height: 44px; font-size: 15px; background: var(--surface-2); box-shadow: none; }
.btn-col { display: grid; gap: 8px; margin-top: 18px; }

/* ---------- Hero ---------- */
.hero {
  position: relative; overflow: hidden;
  padding: 18px 18px 16px;
  background: linear-gradient(145deg, color-mix(in srgb, var(--accent-l) 92%, #fff 8%), color-mix(in srgb, var(--accent-l) 70%, #000 30%));
  color: #fff;
  box-shadow: 0 10px 30px color-mix(in srgb, var(--accent-l) 28%, transparent);
}
.hero::after {
  content: ""; position: absolute; right: -60px; top: -70px; width: 210px; height: 210px; border-radius: 50%;
  border: 26px solid rgba(255, 255, 255, 0.08); pointer-events: none;
}
.hero-top { display: flex; justify-content: space-between; align-items: center; }
.hero-label { font-size: 14px; font-weight: 600; opacity: 0.85; }
.pill { font-size: 12px; font-weight: 650; padding: 4px 10px; border-radius: 99px; background: rgba(255, 255, 255, 0.18); }
.hero-amount { font: 750 44px/1.1 var(--font-round); letter-spacing: -0.02em; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.hero-amount.sm { font-size: 26px; margin: 8px 0 6px; }
.hero-sub { font-size: 14px; opacity: 0.85; }
.hero .bar { margin: 14px 0 14px; background: rgba(255, 255, 255, 0.22); }
.hero .bar span { background: #fff; }
.hero .bar.over span { background: #ffd2d3; }
.hero-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hero-grid > div { background: rgba(255, 255, 255, 0.13); border-radius: 12px; padding: 9px 12px; min-width: 0; }
.hero-grid .k { font-size: 12px; opacity: 0.85; font-weight: 600; }
.hero-grid .v { font: 700 19px/1.25 var(--font-round); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hero-grid small { font-size: 13px; opacity: 0.8; font-weight: 600; }
.btn.on-hero { background: #fff; color: var(--accent-l); margin-top: 14px; min-height: 44px; }

/* ---------- Bars ---------- */
.bar { height: 8px; border-radius: 99px; background: var(--track); overflow: hidden; }
.bar.big { height: 10px; }
.bar.thin { height: 5px; margin-top: 7px; }
.bar span { display: block; height: 100%; width: var(--w); border-radius: inherit; background: var(--bc, var(--accent)); transition: width .5s cubic-bezier(.2, .8, .2, 1); }
.bar.warn span { background: var(--warn); }
.bar.over span { background: var(--danger); }
.view.animate .bar span { animation: grow .8s cubic-bezier(.2, .8, .2, 1) both; }
@keyframes grow { from { width: 0; } }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.stat { padding: 12px; min-width: 0; }
.stat .k, .summary .k { display: flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; color: var(--text-2); }
.stat .v, .summary .v { font: 700 18px/1.3 var(--font-round); margin-top: 3px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.summary { display: grid; grid-template-columns: repeat(3, 1fr); padding: 14px 6px; margin-bottom: 4px; }
.summary > div { padding: 0 10px; min-width: 0; }
.summary > div + div { border-left: 1px solid var(--line); }

/* ---------- Horizontal budgets ---------- */
.h-scroll {
  display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x proximity;
  margin: 0 calc(-1 * var(--gutter)); padding: 2px var(--gutter) 6px; scrollbar-width: none;
  overscroll-behavior-x: contain;
}
.h-scroll::-webkit-scrollbar { display: none; }
.mini-budget { flex: none; width: 112px; padding: 14px 10px 12px; text-align: center; scroll-snap-align: start; display: flex; flex-direction: column; align-items: center; }
.mini-budget:active { transform: scale(0.97); }
.mb-name { font-size: 14px; font-weight: 600; margin-top: 8px; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mb-left { font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.mb-left.neg { color: var(--danger); font-weight: 600; }
.ring-wrap { position: relative; display: grid; place-items: center; flex: none; }
.ring-wrap > .ring-ic, .ring-wrap > .ring-pct { position: absolute; inset: 0; display: grid; place-items: center; }
.ring-ic .ic { width: 22px; height: 22px; }
.ring-wrap.sm .ring-ic .ic { width: 18px; height: 18px; }
.ring-pct { font: 700 17px var(--font-round); }
.ring { display: block; }
.view.animate .ring-fill { animation: ringIn .9s cubic-bezier(.2, .8, .2, 1) both; }
@keyframes ringIn { from { stroke-dasharray: 0 var(--circ); } }

/* ---------- Lists & rows ---------- */
.list { overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 11px 14px; min-height: 58px; position: relative;
}
.list > .row + .row::before, .list > .cat-row + .cat-row::before, .list > .swipe + .swipe::before, .list > .review-row + .review-row::before {
  content: ""; position: absolute; top: 0; left: 62px; right: 0; height: 1px; background: var(--line); z-index: 2;
}
button.row:active, .cat-row-main:active { background: var(--surface-2); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 16px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 13.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.row-sub.neg { color: var(--danger); font-weight: 600; }
.row-sub.warn { color: var(--warn); font-weight: 600; }
.row-amt { font: 650 16px var(--font-round); font-variant-numeric: tabular-nums; white-space: nowrap; flex: none; }
.row-amt.sm { font-size: 14.5px; }
.row.paused { opacity: 0.55; }
.row.danger .row-title { color: var(--danger); }
.row-empty { padding: 18px 16px; color: var(--text-2); font-size: 14.5px; }
.goal-row .row-main { padding-right: 4px; }

.cat-dot {
  width: 36px; height: 36px; border-radius: 11px; flex: none; display: grid; place-items: center;
  background: color-mix(in srgb, var(--c) 16%, transparent); color: var(--c);
}
.cat-dot .ic { width: 19px; height: 19px; }
.cat-dot.xl { width: 72px; height: 72px; border-radius: 22px; }
.cat-dot.xl .ic { width: 34px; height: 34px; }
:root[data-theme="dark"] .cat-dot { background: color-mix(in srgb, var(--c) 24%, transparent); color: color-mix(in srgb, var(--c) 75%, #fff); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .cat-dot { background: color-mix(in srgb, var(--c) 24%, transparent); color: color-mix(in srgb, var(--c) 75%, #fff); } }

.cat-row { display: flex; align-items: center; position: relative; padding-right: 6px; }
.cat-row-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 12px 8px 12px 14px; text-align: left; }
.cats .ring-wrap.sm { width: 44px; }

/* ---------- Transactions ---------- */
.tx-list { margin-bottom: 4px; }
.swipe { position: relative; overflow: hidden; background: var(--surface); }
.swipe-content {
  position: relative; z-index: 1; display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; min-height: 60px; background: var(--surface);
  touch-action: pan-y; will-change: transform; cursor: pointer;
}
.swipe-content:active { background: var(--surface-2); }
.swipe-actions { position: absolute; inset: 0 0 0 auto; display: flex; z-index: 0; width: 100%; justify-content: flex-end; }
.swipe-actions button { width: 74px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: #fff; font-size: 12px; font-weight: 600; }
.swipe-actions .ic { width: 20px; height: 20px; }
.sw-edit { background: #8a8f98; }
.sw-del { background: var(--danger); transition: width .2s ease; }
.swipe.will-delete .sw-edit { width: 0; overflow: hidden; padding: 0; }
.swipe.will-delete .sw-del { width: 100%; align-items: flex-end; padding-right: 26px; }
.swipe.removing { animation: collapse .26s ease forwards; }
@keyframes collapse { to { max-height: 0; min-height: 0; opacity: 0; } }
.swipe { max-height: 120px; }
.tx-main { flex: 1; min-width: 0; }
.tx-title { font-size: 16px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-sub { font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-sub .ic { width: 12px; height: 12px; }
.tx-amt { font: 650 16px var(--font-round); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx-amt.pos { color: var(--pos); }
.day { margin-top: 14px; }
.day-head { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; color: var(--text-2); padding: 0 4px 6px; font-variant-numeric: tabular-nums; }
.tx-summary { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; color: var(--text-2); padding: 12px 4px 0; }
.tx-summary b { color: var(--text); font-weight: 650; }
.tx-summary b.pos { color: var(--pos); }

/* ---------- Search & chips ---------- */
.sticky-tools {
  position: sticky; top: var(--sat); z-index: 10;
  margin: 0 calc(-1 * var(--gutter)); padding: 4px var(--gutter) 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
}
.search {
  display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 12px;
  background: var(--surface); border-radius: 13px; box-shadow: var(--shadow); color: var(--text-3);
}
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; font-size: 16px; color: var(--text); height: 100%; -webkit-appearance: none; appearance: none; }
.search input::-webkit-search-cancel-button { display: none; }
.clear-q { width: 28px; height: 28px; display: grid; place-items: center; color: var(--text-3); }
.clear-q .ic { width: 18px; height: 18px; }
.chip-scroll {
  display: flex; gap: 8px; overflow-x: auto; padding: 10px var(--gutter) 2px; margin: 0 calc(-1 * var(--gutter));
  scrollbar-width: none; overscroll-behavior-x: contain; align-items: center;
}
.chip-scroll::-webkit-scrollbar { display: none; }
.chip-wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; flex: none; height: 36px; padding: 0 13px;
  border-radius: 99px; background: var(--surface); box-shadow: var(--shadow); font-size: 14.5px; font-weight: 560; white-space: nowrap; color: var(--text);
  position: relative;
}
.chip.sm { height: 30px; font-size: 13.5px; padding: 0 10px; }
.chip.on { background: var(--accent); color: var(--on-accent); box-shadow: none; }
.chip.ghost { background: transparent; box-shadow: none; color: var(--accent); }
.chip.static { cursor: default; }
.chip .dot, .legend .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); display: inline-block; flex: none; }
.cat-chip .ic { color: var(--c); }
.cat-chip.on { background: var(--c); color: #fff; }
.cat-chip.on .ic { color: #fff; }

.seg { display: inline-flex; background: var(--surface-3); border-radius: 11px; padding: 3px; gap: 2px; flex: none; }
.seg button { padding: 0 14px; height: 32px; border-radius: 9px; font-size: 14.5px; font-weight: 600; color: var(--text-2); white-space: nowrap; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.seg.small button { height: 30px; padding: 0 11px; font-size: 13.5px; }
.seg.wide { display: flex; width: 100%; }
.seg.wide button { flex: 1; padding: 0 6px; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.seg.center { display: flex; width: max-content; margin: 0 auto; }

/* ---------- Empty ---------- */
.empty { text-align: center; padding: 26px 18px 22px; }
.empty-ic { width: 40px; height: 40px; margin: 0 auto 8px; color: var(--text-3); }
.empty-title { font-weight: 650; font-size: 17px; }
.empty p { color: var(--text-2); font-size: 14.5px; margin-top: 4px; }

/* ---------- Goals ---------- */
.goals { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
.goal { padding: 16px; }
.goal-top { display: flex; align-items: center; gap: 14px; }
.goal-info { flex: 1; min-width: 0; }
.goal-amt { font: 700 20px var(--font-round); font-variant-numeric: tabular-nums; margin-top: 2px; }
.goal-amt .muted { font-size: 15px; font-weight: 600; }
.goal .btn.wide { margin-top: 14px; min-height: 44px; background: var(--surface-2); box-shadow: none; }

/* ---------- Insights ---------- */
.period-nav { display: flex; align-items: center; justify-content: space-between; padding: 6px; }
.pn-label { font-weight: 650; font-size: 16px; }
.chart-card { padding: 16px; margin-top: 12px; }
.card-title { font-size: 17px; font-weight: 650; margin-bottom: 10px; }
.donut-wrap { display: grid; place-items: center; padding: 6px 0 10px; }
.donut { position: relative; }
.donut svg { display: block; overflow: visible; }
.donut .seg { cursor: pointer; transition: stroke-width .2s ease, opacity .2s ease; }
.donut svg:hover .seg { opacity: 0.55; }
.donut svg .seg:hover, .donut .seg:focus-visible { opacity: 1; stroke-width: 30px; outline: none; }
.donut-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; }
.dc-k { font-size: 13px; color: var(--text-2); font-weight: 600; }
.dc-v { font: 750 26px var(--font-round); font-variant-numeric: tabular-nums; }
.dc-d { font-size: 12.5px; font-weight: 650; }
.legend { display: grid; grid-template-columns: minmax(0, 1fr); }
.legend-row { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-top: 1px solid var(--line); text-align: left; font-size: 15px; }
.legend-row:active { background: var(--surface-2); }
.lg-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lg-pct { color: var(--text-3); font-size: 13.5px; font-variant-numeric: tabular-nums; width: 40px; text-align: right; }
.lg-amt { font-weight: 650; font-variant-numeric: tabular-nums; min-width: 78px; text-align: right; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--text-2); margin: -2px 0 8px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; flex: none; }
.bar-sw { width: 10px; height: 10px; border-radius: 3px; background: var(--accent); }
.inc-sw { width: 14px; height: 2.5px; background: var(--pos); border-radius: 2px; }
.bud-sw { width: 14px; height: 0; border-top: 2px dashed var(--text-3); }
.line-sw { width: 14px; height: 2.5px; background: var(--accent); border-radius: 2px; }
.ideal-sw { width: 14px; height: 0; border-top: 2px dashed var(--text-3); }
svg.trend, svg.pace { width: 100%; height: auto; display: block; overflow: visible; }
.trend .grid, .pace .grid { stroke: var(--line); stroke-width: 1; }
.trend .baseline { stroke: var(--text-3); stroke-width: 1; opacity: 0.5; }
.trend .axis, .pace .axis { fill: var(--text-3); font-size: 10.5px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.trend .axis.x { font-size: 11.5px; }
.trend .axis.x.sel { fill: var(--text); font-weight: 700; }
.trend .bar { fill: color-mix(in srgb, var(--accent) 45%, var(--surface)); transition: fill .2s ease; }
.trend .bar-g.sel .bar, .trend .bar-g:hover .bar { fill: var(--accent); }
.trend .bar.over { fill: color-mix(in srgb, var(--danger) 50%, var(--surface)); }
.trend .bar-g.sel .bar.over { fill: var(--danger); }
.trend .bar-g { cursor: pointer; outline: none; }
.trend .inc-mark { stroke: var(--pos); stroke-width: 2.5; stroke-linecap: round; }
.trend .budget-line, .pace .pace-ideal { stroke: var(--text-3); stroke-width: 1.5; stroke-dasharray: 4 4; }
.pace .pace-line { fill: none; stroke: var(--accent); stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.pace .pace-line.over { stroke: var(--danger); }
.pace .pace-area { fill: color-mix(in srgb, var(--accent) 12%, transparent); }
.pace .pace-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2.5; }
.pace .pace-dot.over { fill: var(--danger); }
.hbars { display: grid; gap: 4px; grid-template-columns: minmax(0, 1fr); }
.hbar { min-width: 0; width: 100%; text-align: left; padding: 8px 4px; border-radius: 10px; }
.hbar:active { background: var(--surface-2); }
.hb-top { display: flex; justify-content: space-between; gap: 10px; font-size: 15px; }
.hb-name { font-weight: 560; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.hb-amt { font-weight: 650; font-variant-numeric: tabular-nums; }
.hb-track { height: 8px; border-radius: 99px; background: var(--track); margin: 6px 0 4px; overflow: hidden; }
.hb-track span { display: block; height: 100%; width: var(--w); background: var(--bc); border-radius: 99px; }
.hb-sub { font-size: 12.5px; color: var(--text-3); }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 0 calc(8px + var(--sar)) var(--sab) calc(8px + var(--sal));
  background: color-mix(in srgb, var(--surface) 84%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(20px); backdrop-filter: saturate(1.6) blur(20px);
  border-top: 1px solid var(--line);
}
.tabbar-inner { max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); height: var(--tab-h); align-items: center; }
.tabbar button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: 100%; color: var(--text-3); font-size: 10.5px; font-weight: 600; }
.tabbar button .ic { width: 24px; height: 24px; }
.tabbar button.active { color: var(--accent); }
.add-orb {
  width: 50px; height: 50px; border-radius: 17px; display: grid; place-items: center;
  background: var(--accent); color: var(--on-accent);
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 40%, transparent);
  transition: transform .15s ease;
}
.add-orb .ic { width: 26px; height: 26px; stroke-width: 2.4; }
.tab-add:active .add-orb { transform: scale(0.92); }

/* ---------- Sheets ---------- */
/* The layer exactly matches the visual viewport (above the keyboard). */
.sheet-layer {
  position: fixed; left: 0; right: 0; top: 0; z-index: 50;
  height: var(--vvh); transform: translateY(var(--vvt));
  overscroll-behavior: contain;
}
.sheet-backdrop {
  position: absolute; left: 0; right: 0; top: 0; bottom: -100vh; /* extends under the keyboard */
  background: var(--backdrop); opacity: 0; transition: opacity .28s ease;
  touch-action: none;
}
.sheet-layer.open .sheet-backdrop { opacity: 1; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; top: auto;
  max-height: calc(var(--vvh) - var(--sat) - 10px);
  display: flex; flex-direction: column;
  background: var(--sheet-bg); border-radius: 22px 22px 0 0;
  transform: translateY(105%); transition: transform .34s cubic-bezier(.2, .9, .25, 1);
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.18);
  padding-left: var(--sal); padding-right: var(--sar);
}
/* Paint below the sheet so nothing shows through while the keyboard slides. */
.sheet::after { content: ""; position: absolute; left: 0; right: 0; top: 100%; height: 100vh; background: var(--sheet-bg); pointer-events: none; }
.sheet-layer.open .sheet { transform: none; }
.sheet-layer.closing .sheet { transform: translateY(105%); transition-duration: .26s; }
.sheet-layer.closing .sheet-backdrop { opacity: 0; }
.sheet-head { flex: none; padding: 6px 10px 2px; touch-action: none; cursor: grab; }
.sheet-grab { width: 38px; height: 5px; border-radius: 99px; background: var(--surface-3); margin: 0 auto 4px; }
.sheet-head-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; min-height: 44px; }
.sheet-head-side { display: flex; align-items: center; }
.sheet-head-side.right { justify-content: flex-end; }
.sheet-title { font-size: 17px; font-weight: 650; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 62vw; }
.sheet-body {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 6px var(--gutter) calc(18px + var(--sab));
}
.sheet-foot { flex: none; padding: 8px var(--gutter) calc(10px + var(--sab)); }
.sheet-foot + .keypad-dock, .sheet:has(.sheet-foot) .sheet-body { padding-bottom: 12px; }
html.kb-open .sheet-body, html.kb-open .sheet-foot { padding-bottom: 12px; }
.sheet.typing .sheet-foot, html.kb-open .sheet .sheet-foot:has(.keypad) { display: none; }
.sheet.compact .sheet-body { padding-bottom: calc(20px + var(--sab)); }
.confirm-msg { color: var(--text-2); font-size: 15.5px; text-align: center; padding: 4px 8px 0; line-height: 1.5; }

/* Keypad */
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.key {
  height: clamp(44px, 6.6vh, 56px); border-radius: 14px; background: var(--surface);
  font: 600 24px var(--font-round); color: var(--text); display: grid; place-items: center;
  box-shadow: var(--shadow);
  transition: background .08s ease, transform .08s ease;
}
.key.muted { background: transparent; box-shadow: none; color: var(--text-2); }
.key:active { background: var(--surface-3); transform: scale(0.97); }
.key .ic { width: 26px; height: 26px; }
.save-btn { width: 100%; margin-top: 10px; }
.keypad-dock { display: none; flex: none; padding: 6px var(--gutter) calc(10px + var(--sab)); border-top: 1px solid var(--line); background: var(--sheet-bg); }
.sheet.keypad-open .keypad-dock { display: block; }
.sheet.typing .keypad-dock { display: none; }
.keypad-dock-bar { display: flex; justify-content: space-between; align-items: center; padding: 0 2px 6px; font-size: 13.5px; color: var(--text-2); font-weight: 600; }

/* Quick add */
.qa-amount {
  text-align: center; font: 750 50px/1.15 var(--font-round); letter-spacing: -0.02em; margin: 14px 0 6px;
  font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.qa-amount .sym { font-size: 0.6em; color: var(--text-3); margin-right: 2px; vertical-align: 0.28em; }
.qa-amount .placeholder { color: var(--text-3); }
.shake { animation: shake .35s ease; }
@keyframes shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }
.qa-date { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.date-chip { overflow: hidden; }
.date-chip input[type="date"] {
  position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; font-size: 16px; border: 0; padding: 0; margin: 0;
  -webkit-appearance: none; appearance: none; cursor: pointer;
}
.date-chip input::-webkit-calendar-picker-indicator { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.note-wrap { display: flex; align-items: center; gap: 8px; margin-top: 12px; background: var(--surface); border-radius: 13px; padding: 0 12px; box-shadow: var(--shadow); color: var(--text-3); }
.note-input { flex: 1; min-width: 0; height: 46px; border: 0; outline: 0; background: none; font-size: 16px; color: var(--text); }
.scan-link { display: flex; align-items: center; gap: 6px; margin: 14px auto 0; font-size: 14.5px; }
.quick .sheet-body { padding-bottom: 8px; }
.sheet.quick .cats-pick { padding-top: 12px; }
.notice { display: flex; gap: 10px; padding: 12px 14px; border-radius: 14px; background: color-mix(in srgb, var(--accent) 12%, transparent); font-size: 14px; line-height: 1.45; margin: 10px 0 4px; }
.notice .ic { color: var(--accent); margin-top: 1px; }
.notice.soft { background: var(--surface); box-shadow: var(--shadow); color: var(--text-2); margin-top: 12px; }
.notice.compact { padding: 9px 12px; align-items: center; font-size: 13.5px; margin: 10px 0 0; }
.chip-scroll.cand { padding-top: 8px; gap: 6px; }
.cand-k { font-size: 12.5px; color: var(--text-2); flex: none; font-weight: 600; }

/* Forms */
.form { padding: 2px 0; }
.field-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 52px; padding: 6px 14px; position: relative;
}
.field-row.col { flex-direction: column; align-items: stretch; padding: 12px 14px; gap: 10px; }
.form > .field-row + .field-row::before { content: ""; position: absolute; top: 0; left: 14px; right: 0; height: 1px; background: var(--line); }
.field-row > span:first-child { font-size: 16px; color: var(--text); flex: none; }
.field-row input[type="text"], .field-row select, .field-row input[type="date"] {
  min-width: 0; flex: 1; text-align: right; border: 0; outline: 0; background: none; font-size: 16px; color: var(--text-2);
  height: 40px; -webkit-appearance: none; appearance: none;
}
.field-row select { text-align-last: right; cursor: pointer; padding-right: 2px; }
.field-row input[type="date"] { display: flex; justify-content: flex-end; min-height: 40px; }
.field-row input::-webkit-date-and-time-value { text-align: right; }
.field-row input[type="text"]:focus { color: var(--text); }
.amount-field {
  font: 650 18px var(--font-round); color: var(--text); padding: 6px 10px; border-radius: 10px; min-width: 96px; text-align: right;
  font-variant-numeric: tabular-nums; background: var(--surface-2);
}
.amount-field.active { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); box-shadow: inset 0 0 0 1.5px var(--accent); }
.amount-field .sym { color: var(--text-3); margin-right: 1px; }
.amount-field .placeholder { color: var(--text-3); }
.switch { -webkit-appearance: none; appearance: none; width: 51px; height: 31px; border-radius: 99px; background: var(--surface-3); position: relative; cursor: pointer; transition: background .2s; flex: none; margin: 0; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); transition: transform .2s; }
.switch:checked { background: var(--pos); }
.switch:checked::after { transform: translateX(20px); }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; padding: 2px 2px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; background: var(--c); position: relative; }
.swatch.on::after { content: ""; position: absolute; inset: -5px; border-radius: 50%; border: 2.5px solid var(--c); }
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 8px; }
.icon-pick { height: 46px; border-radius: 12px; display: grid; place-items: center; background: var(--surface); color: var(--text-2); box-shadow: var(--shadow); }
.icon-pick.on { background: var(--accent); color: var(--on-accent); }
.cat-preview { display: grid; place-items: center; padding: 6px 0 14px; }

/* Import */
.import-intro { text-align: center; padding: 10px 4px; }
.import-intro p { color: var(--text-2); margin: 8px 0 6px; line-height: 1.5; }
.big-ic { width: 48px; height: 48px; margin: 6px auto; color: var(--accent); }
.review-row { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; position: relative; }
.review-row.off { opacity: 0.5; }
.review-row .row-main { display: grid; gap: 4px; }
.review-row .row-title { white-space: normal; font-size: 15px; line-height: 1.3; word-break: break-word; }
.review-row .row-amt { font-size: 15px; }
.mini-select { font-size: 16px; padding: 4px 8px; border-radius: 8px; border: 0; background: var(--surface-2); color: var(--text); max-width: 100%; justify-self: start; }
.badge { display: inline-block; font-size: 11.5px; font-weight: 650; padding: 2px 7px; border-radius: 99px; background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.pos { background: color-mix(in srgb, var(--pos) 16%, transparent); color: var(--pos); justify-self: start; }
.check { position: relative; width: 24px; height: 24px; flex: none; margin-top: 2px; }
.check input { position: absolute; inset: 0; opacity: 0; margin: 0; width: 100%; height: 100%; cursor: pointer; }
.check span { position: absolute; inset: 0; border-radius: 7px; border: 2px solid var(--text-3); pointer-events: none; }
.check input:checked + span { background: var(--accent); border-color: var(--accent); }
.check input:checked + span::after { content: ""; position: absolute; left: 6px; top: 2px; width: 6px; height: 11px; border: solid var(--on-accent); border-width: 0 2.5px 2.5px 0; transform: rotate(45deg); }

/* Scan */
.scan { text-align: center; }
.scan-img { position: relative; width: 150px; height: 200px; margin: 8px auto 16px; border-radius: 14px; overflow: hidden; background: var(--surface-2); }
.scan-img img { width: 100%; height: 100%; object-fit: cover; }
.scan-beam { position: absolute; left: 0; right: 0; height: 40px; background: linear-gradient(to bottom, transparent, color-mix(in srgb, var(--accent) 55%, transparent), transparent); animation: beam 1.6s ease-in-out infinite alternate; }
@keyframes beam { from { top: -40px; } to { top: 200px; } }
.scan-status { font-weight: 600; margin-bottom: 10px; }

/* ---------- Toasts ---------- */
#toasts {
  position: fixed; z-index: 100; left: 0; right: 0; top: calc(var(--sat) + 8px);
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px;
}
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 14px; max-width: 440px; width: max-content;
  padding: 11px 12px 11px 16px; border-radius: 16px; font-size: 15px; font-weight: 560;
  background: color-mix(in srgb, #1b1e24 94%, transparent); color: #fff;
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  transform: translateY(-16px) scale(0.98); opacity: 0; transition: transform .3s cubic-bezier(.2, .9, .25, 1), opacity .25s ease;
}
.toast.show { transform: none; opacity: 1; }
.toast.warn .toast-msg::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #f5b840; margin-right: 8px; vertical-align: 1px; }
.toast-msg { min-width: 0; }
.toast-btn { color: var(--accent-d); font-weight: 700; padding: 4px 6px; flex: none; }

/* ---------- Wider screens: center column, dialogs instead of sheets ---------- */
@media (min-width: 700px) and (min-height: 520px) {
  :root { --gutter: 24px; }
  .page-head { padding-top: 22px; }
  .sheet-layer { height: 100%; transform: none; }
  .sheet-backdrop { bottom: 0; }
  .sheet {
    left: 50%; right: auto; top: 50% !important; bottom: auto; width: 520px; max-height: 86vh;
    border-radius: 22px; transform: translate(-50%, -46%) scale(0.98); opacity: 0;
    transition: transform .25s cubic-bezier(.2, .9, .25, 1), opacity .2s ease;
  }
  .sheet::after { display: none; }
  .sheet-layer.open .sheet { transform: translate(-50%, -50%); opacity: 1; }
  .sheet-layer.closing .sheet { transform: translate(-50%, -46%) scale(0.98); opacity: 0; }
  .sheet-grab { visibility: hidden; height: 0; margin: 0; }
  .sheet-head { cursor: default; padding-top: 10px; }
  .key { height: 52px; }
  .sheet-title { max-width: 300px; }
}
@media (hover: hover) {
  button.row:hover, .cat-row-main:hover, .legend-row:hover, .hbar:hover, .swipe-content:hover { background: var(--surface-2); }
  .icon-btn:hover { background: var(--surface-2); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
@media (max-width: 360px) {
  :root { --gutter: 12px; }
  .hero-amount { font-size: 38px; }
  .stat .v { font-size: 16px; }
  .page-head h1 { font-size: 28px; }
}
