/* =========================================================================
   Stack — styles
   Dark, minimal, one accent colour. Change the tokens in :root to re-theme.
   ========================================================================= */

:root {
  /* Surfaces */
  --bg: #0b0f0d;
  --card: #141a17;
  --card-2: #1c241f;
  --sheet: #151c18;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.12);

  /* Ink */
  --text: #eef3f0;
  --muted: #8d9993;
  --dim: #5e6964;

  /* The one accent ("money green") + status colours */
  --accent: #34e89e;
  --accent-dim: rgba(52, 232, 158, 0.14);
  --accent-ink: #04281a;
  --amber: #f5b83d;
  --amber-dim: rgba(245, 184, 61, 0.14);
  --red: #ff6464;
  --red-dim: rgba(255, 100, 100, 0.13);

  /* Breakdown segment colours (validated dark categorical steps) */
  --seg-bills: #3987e5;
  --seg-business: #d95926;
  --seg-plans: #c98500;
  --seg-savings: #9085e9;
  --seg-spent: #d55181;
  --seg-left: var(--accent);

  /* Shape & motion */
  --radius: 20px;
  --radius-sm: 14px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);

  /* iPhone safe areas (notch + home bar) */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --tabbar-h: 58px;

  /* Set by app.js while the on-screen keyboard is open */
  --kb: 0px;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  --font-num: ui-rounded, "SF Pro Rounded", -apple-system, system-ui, sans-serif;

  color-scheme: dark;
}

/* ---------------------------------------------------------------- Base --- */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  overflow: hidden;           /* .main is the only thing that scrolls */
  touch-action: manipulation; /* no double-tap zoom */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

svg { display: block; }

[hidden] { display: none !important; }

.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.pos { color: var(--accent); }
.neg { color: var(--red); }
.warn { color: var(--amber); }
.small { font-size: 13px; }
.center { text-align: center; }
.mt { margin-top: 12px; }
.row-flex { display: flex; align-items: center; gap: 10px; }
.spacer { flex: 1; }

/* ------------------------------------------------------------ App shell -- */
.main {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding:
    calc(var(--safe-top) + 14px)
    calc(var(--safe-right) + 16px)
    calc(var(--tabbar-h) + var(--safe-bottom) + 96px)
    calc(var(--safe-left) + 16px);
}

.view { max-width: 560px; margin: 0 auto; animation: view-in 0.28s var(--ease); }

@keyframes view-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.screen-head { display: flex; align-items: flex-end; gap: 12px; margin: 6px 2px 16px; }
.screen-head .title { flex: 1; }
.title { font-size: 32px; font-weight: 800; letter-spacing: -0.02em; margin: 0; line-height: 1.1; }
.subtitle { color: var(--muted); font-size: 14px; margin-top: 2px; }

/* Tab bar ----------------------------------------------------------------- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: flex;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding: 0 calc(var(--safe-right) + 6px) var(--safe-bottom) calc(var(--safe-left) + 6px);
  background: rgba(11, 15, 13, 0.82);
  -webkit-backdrop-filter: saturate(160%) blur(20px);
  backdrop-filter: saturate(160%) blur(20px);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1;
  min-height: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--dim);
  font-size: 11px;
  font-weight: 600;
  transition: color 0.2s;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--accent); }

/* Floating "+" button ------------------------------------------------------ */
.fab {
  position: fixed;
  z-index: 21;
  right: calc(var(--safe-right) + 18px);
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  width: 64px; height: 64px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  box-shadow: 0 10px 30px rgba(52, 232, 158, 0.28), 0 2px 8px rgba(0, 0, 0, 0.5);
  transition: transform 0.18s var(--ease), opacity 0.2s;
}
.fab svg { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; }
.fab:active { transform: scale(0.92); }
.fab.hide { opacity: 0; transform: scale(0.6); pointer-events: none; }

/* Update banner ------------------------------------------------------------ */
.update-banner {
  position: fixed;
  z-index: 60;
  top: calc(var(--safe-top) + 8px);
  left: 50%;
  transform: translateX(-50%);
  min-height: 44px;
  padding: 0 18px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  animation: drop-in 0.4s var(--ease);
}
@keyframes drop-in { from { transform: translate(-50%, -30px); opacity: 0; } }

/* ---------------------------------------------------------------- Cards -- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
}
.card-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-title .spacer { flex: 1; }
.card-title .link { text-transform: none; letter-spacing: 0; color: var(--accent); font-weight: 600; font-size: 14px; min-height: 32px; }

[data-action].card, .tap { transition: transform 0.15s var(--ease), background 0.15s; }
[data-action].card:active, .tap:active { transform: scale(0.985); background: var(--card-2); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.grid-2 .card { margin-bottom: 0; }

.stat-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.stat-value { font-family: var(--font-num); font-size: 26px; font-weight: 800; letter-spacing: -0.02em; margin-top: 4px; line-height: 1.15; }
.stat-sub { font-size: 12px; color: var(--dim); margin-top: 2px; }

/* Home hero ---------------------------------------------------------------- */
.hero { padding: 22px 20px 20px; position: relative; overflow: hidden; }
.hero::before {
  content: "";
  position: absolute;
  inset: -40% -20% auto auto;
  width: 260px; height: 260px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--glow, rgba(52, 232, 158, 0.16)), transparent 70%);
  pointer-events: none;
}
.hero.amber { --glow: rgba(245, 184, 61, 0.16); }
.hero.red { --glow: rgba(255, 100, 100, 0.16); }
.hero-label { font-size: 15px; color: var(--muted); font-weight: 600; }
.hero-number {
  font-family: var(--font-num);
  font-size: clamp(54px, 17vw, 76px);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
  margin: 8px 0 10px;
  color: var(--accent);
  transition: color 0.3s;
}
.hero-number .cents { font-size: 0.45em; letter-spacing: -0.01em; opacity: 0.8; }
.hero.amber .hero-number { color: var(--amber); }
.hero.red .hero-number { color: var(--red); }
.hero-meta { color: var(--muted); font-size: 15px; }
.hero-meta b { color: var(--text); font-weight: 600; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
}
.hero.amber .pill { background: var(--amber-dim); color: var(--amber); }
.hero.red .pill { background: var(--red-dim); color: var(--red); }
.pill.muted-pill { background: var(--card-2); color: var(--muted); }
.pills { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

/* Explanation box when spendable is negative */
.alert {
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-top: 14px;
  background: var(--red-dim);
  color: #ffd2d2;
  font-size: 14px;
}
.alert.amber { background: var(--amber-dim); color: #ffe6b3; }
.alert.ok { background: var(--accent-dim); color: #c9f9e4; }
.alert strong { display: block; font-size: 15px; margin-bottom: 6px; color: #fff; }
.alert ul { margin: 6px 0 0; padding-left: 18px; }
.alert li { margin: 3px 0; }

/* Banners on home (backup reminder, payday) */
.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius);
  margin-bottom: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 14px;
}
.banner .emoji { font-size: 24px; }
.banner .grow { flex: 1; }
.banner b { display: block; font-size: 15px; }
.banner.accent { border-color: rgba(52, 232, 158, 0.35); background: linear-gradient(135deg, rgba(52, 232, 158, 0.12), var(--card)); }
.banner.amber { border-color: rgba(245, 184, 61, 0.3); }

/* Progress bars ------------------------------------------------------------ */
.bar { height: 8px; border-radius: 99px; background: rgba(255, 255, 255, 0.07); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; border-radius: 99px; background: var(--accent); transition: width 0.7s var(--ease); }
.bar.amber > i { background: var(--amber); }
.bar.red > i { background: var(--red); }
.bar.thick { height: 10px; }

/* Bars grow in when you open a screen (app.js adds .enter for ~1s) */
.view.enter .bar > i { animation: bar-grow 0.9s var(--ease); }
.view.enter .stackbar { animation: wipe 0.9s var(--ease); }
@keyframes bar-grow { from { width: 0; } }
@keyframes wipe { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }

/* Breakdown (stacked bar + legend) ---------------------------------------- */
.stackbar { display: flex; gap: 2px; height: 14px; border-radius: 6px; overflow: hidden; background: rgba(255, 255, 255, 0.05); }
.stackbar > i { display: block; height: 100%; min-width: 3px; transition: flex-grow 0.6s var(--ease); }
.stackbar > i:first-child { border-radius: 4px 0 0 4px; }
.stackbar > i:last-child { border-radius: 0 4px 4px 0; }
.legend { margin-top: 14px; display: grid; gap: 2px; }
.legend-row { display: flex; align-items: center; gap: 10px; min-height: 32px; font-size: 15px; }
.legend-row .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend-row .lbl { flex: 1; color: var(--text); }
.legend-row .val { font-family: var(--font-num); font-weight: 700; font-variant-numeric: tabular-nums; }
.legend-row .pct { width: 44px; text-align: right; color: var(--dim); font-size: 13px; font-variant-numeric: tabular-nums; }

/* Check list ("this week's moves") ---------------------------------------- */
.check-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  text-align: left;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}
.check-row:last-child { border-bottom: 0; }
.check {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid var(--dim);
  display: grid;
  place-items: center;
  flex: none;
  transition: background 0.2s, border-color 0.2s, transform 0.2s var(--ease);
}
.check svg { width: 14px; height: 14px; fill: none; stroke: var(--accent-ink); stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
.check-row.done .check { background: var(--accent); border-color: var(--accent); transform: scale(1.05); }
.check-row.done .check svg { opacity: 1; }
.check-row.done .check-text { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--dim); }
.check-text { flex: 1; }
.check-amt { font-family: var(--font-num); font-weight: 700; }

/* --------------------------------------------------------- Lists / rows -- */
.list { background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; margin-bottom: 12px; }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 10px 16px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}
.row:last-child { border-bottom: 0; }
button.row:active { background: var(--card-2); }
.row-icon { font-size: 22px; width: 30px; text-align: center; flex: none; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-title { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { display: block; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-value { display: flex; flex-direction: column; align-items: flex-end; font-family: var(--font-num); font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.row-value .row-sub { font-family: var(--font); font-weight: 400; }
.chev { color: var(--dim); font-size: 20px; margin-left: -4px; }
.row.add { color: var(--accent); font-weight: 600; justify-content: center; min-height: 52px; }
.row-total { display: flex; justify-content: space-between; padding: 12px 16px; font-size: 14px; color: var(--muted); background: rgba(255, 255, 255, 0.02); border-bottom: 1px solid var(--line); }
.row-total b { color: var(--text); font-family: var(--font-num); }

.section-label {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 22px 4px 8px;
}
.section-label:first-of-type { margin-top: 4px; }
.section-note { font-size: 13px; color: var(--dim); margin: -2px 4px 10px; }

/* Day groups in the log */
.day-head { display: flex; justify-content: space-between; align-items: baseline; margin: 18px 4px 8px; font-weight: 700; }
.day-head span:last-child { font-family: var(--font-num); color: var(--muted); font-weight: 600; }

/* Swipe-to-delete rows ---------------------------------------------------- */
.swipe { position: relative; overflow: hidden; border-bottom: 1px solid var(--line); background: var(--red); }
.swipe:last-child { border-bottom: 0; }
.swipe .row { position: relative; z-index: 1; border-bottom: 0; touch-action: pan-y; will-change: transform; }
.swipe .row.animating { transition: transform 0.25s var(--ease); }
.swipe-del {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 92px;
  background: var(--red);
  color: #fff;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.swipe.removing { transition: max-height 0.25s var(--ease), opacity 0.25s; max-height: 0 !important; opacity: 0; }

/* -------------------------------------------------------------- Buttons -- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 18px;
  border-radius: var(--radius-sm);
  background: var(--card-2);
  color: var(--text);
  font-weight: 700;
  font-size: 16px;
  transition: transform 0.15s var(--ease), opacity 0.15s;
}
.btn:active { transform: scale(0.97); opacity: 0.85; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--red-dim); color: var(--red); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.small { min-height: 36px; padding: 0 14px; font-size: 14px; border-radius: 11px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: 0.4; pointer-events: none; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; padding: 0 10px; white-space: nowrap; }

.icon-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--card-2);
  color: var(--text);
  font-size: 20px;
  flex: none;
}
.icon-btn:active { opacity: 0.7; }
.icon-btn[disabled] { opacity: 0.3; }

/* Week switcher on the Log screen */
.week-nav { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.week-nav .wk { flex: 1; text-align: center; font-weight: 700; }
.week-nav .wk small { display: block; color: var(--muted); font-weight: 500; font-size: 13px; }

/* Category summary chips */
.cat-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.cat-chip { background: var(--card-2); border-radius: 999px; padding: 6px 12px; font-size: 14px; }
.cat-chip b { font-family: var(--font-num); }

/* Plans ------------------------------------------------------------------- */
.plan { cursor: pointer; }
.plan-top { display: flex; gap: 12px; align-items: flex-start; }
.plan-emoji { font-size: 28px; line-height: 1; width: 44px; height: 44px; border-radius: 14px; background: var(--card-2); display: grid; place-items: center; flex: none; }
.plan-name { font-weight: 700; font-size: 17px; }
.plan-when { color: var(--muted); font-size: 14px; }
.plan-amounts { display: flex; justify-content: space-between; align-items: baseline; margin: 14px 0 8px; font-size: 14px; color: var(--muted); }
.plan-amounts b { font-family: var(--font-num); color: var(--text); font-size: 17px; }
.plan-foot { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.plan-weekly { font-family: var(--font-num); font-weight: 800; font-size: 20px; }
.plan-weekly small { font-family: var(--font); font-weight: 500; font-size: 13px; color: var(--muted); }
.plan.done { opacity: 0.6; }

.empty { text-align: center; padding: 36px 20px; color: var(--muted); }
.empty .big { font-size: 44px; margin-bottom: 8px; }
.empty b { color: var(--text); display: block; font-size: 17px; margin-bottom: 4px; }

/* Onboarding steps */
.steps { display: grid; gap: 8px; margin-top: 6px; }
.step { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 8px 12px; border-radius: 12px; background: var(--card-2); text-align: left; width: 100%; }
.step .n { width: 26px; height: 26px; border-radius: 50%; background: var(--bg); display: grid; place-items: center; font-size: 13px; font-weight: 800; color: var(--muted); flex: none; }
.step.done .n { background: var(--accent); color: var(--accent-ink); }
.step.done span:not(.n) { color: var(--muted); text-decoration: line-through; }

/* Forecast ---------------------------------------------------------------- */
.chart-wrap { position: relative; margin: 4px -6px 0; }
.chart-wrap svg { width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.chart-tip {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  background: #232c27;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 13px;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}
.chart-tip b { font-family: var(--font-num); font-size: 15px; display: block; }
.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-top: 8px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { display: inline-block; width: 16px; height: 0; border-top: 2px solid var(--accent); }
.chart-legend i.buf { border-top: 2px dashed var(--amber); }
.chart-legend i.dot { width: 8px; height: 8px; border: 0; border-radius: 50%; background: var(--red); }

.ftable { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.ftable th { text-align: right; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; padding: 8px 6px; border-bottom: 1px solid var(--line-strong); }
.ftable th:first-child, .ftable td:first-child { text-align: left; padding-left: 0; }
.ftable th:last-child, .ftable td:last-child { padding-right: 0; }
.ftable td { text-align: right; padding: 10px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.ftable td.bal { font-family: var(--font-num); font-weight: 700; }
.ftable tr.low td.bal { color: var(--red); }
.ftable .ev { display: block; font-size: 12px; color: var(--muted); font-weight: 400; text-align: left; margin-top: 2px; }
.ftable tr.low { background: rgba(255, 100, 100, 0.05); }

/* Segmented control ------------------------------------------------------- */
.seg { display: flex; background: var(--bg); border-radius: 12px; padding: 3px; gap: 3px; border: 1px solid var(--line); }
.seg button, .seg label {
  flex: 1;
  min-height: 40px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-weight: 600;
  font-size: 14px;
  color: var(--muted);
  text-align: center;
  padding: 0 4px;
  transition: background 0.2s, color 0.2s;
}
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg .on, .seg label:has(input:checked) { background: var(--card-2); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35); }
.seg.wrap { flex-wrap: wrap; }
.seg.wrap label { flex: 1 1 30%; }

/* Toggle switch ------------------------------------------------------------ */
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: #39423d; transition: background 0.2s; }
.switch span::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.3); transition: transform 0.25s var(--ease); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }

/* ----------------------------------------------------- Sheets & dialogs -- */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity 0.25s;
}
.backdrop.open { opacity: 1; }

.sheet {
  position: fixed;
  z-index: 41;
  left: 0; right: 0;
  bottom: var(--kb);
  margin: 0 auto;
  max-width: 560px;
  max-height: calc(100% - var(--safe-top) - var(--kb) - 16px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background: var(--sheet);
  border-radius: 24px 24px 0 0;
  border: 1px solid var(--line);
  border-bottom: 0;
  padding: 8px calc(var(--safe-right) + 18px) calc(var(--safe-bottom) + 18px) calc(var(--safe-left) + 18px);
  transform: translateY(105%);
  transition: transform 0.32s var(--ease), bottom 0.2s;
  -webkit-user-select: text;
  user-select: text;
}
.sheet.open { transform: none; }
.sheet.kb-open { padding-bottom: 14px; }
.sheet-grip { width: 38px; height: 5px; border-radius: 3px; background: var(--line-strong); margin: 0 auto 10px; }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 21px; font-weight: 800; }

.dialog {
  position: fixed;
  z-index: 51;
  left: 50%; top: 50%;
  width: min(340px, calc(100% - 40px));
  transform: translate(-50%, -46%) scale(0.96);
  opacity: 0;
  transition: transform 0.25s var(--ease), opacity 0.2s;
  background: var(--sheet);
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  padding: 22px 20px 18px;
  -webkit-user-select: text;
  user-select: text;
}
.dialog.open { transform: translate(-50%, -50%); opacity: 1; }
.dialog h3 { margin: 0 0 8px; font-size: 19px; }
.dialog p { margin: 0 0 16px; color: var(--muted); font-size: 15px; white-space: pre-line; }
.backdrop.dim { z-index: 50; }

/* Form fields -------------------------------------------------------------- */
.field { margin-bottom: 14px; }
.field > label, .field > .label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 6px 2px; }
.field .hint { font-size: 12px; color: var(--dim); margin: 6px 2px 0; }
.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap .prefix { position: absolute; left: 14px; color: var(--muted); font-weight: 600; pointer-events: none; font-size: 17px; }
.input-wrap .prefix + input { padding-left: 32px; }

input[type="text"], input[type="number"], input[type="date"], input[type="month"], select, textarea {
  width: 100%;
  min-height: 50px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 17px;          /* ≥16px stops iOS zooming into inputs */
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.15s;
}
input[type="date"] { display: flex; align-items: center; line-height: 50px; }
input::-webkit-date-and-time-value { text-align: left; }
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
input:focus, select:focus { border-color: var(--accent); }
input::placeholder { color: var(--dim); }
.field.invalid input { border-color: var(--red); animation: shake 0.35s; }
@keyframes shake { 25% { transform: translateX(-6px); } 50% { transform: translateX(5px); } 75% { transform: translateX(-3px); } }

.toggle-field { display: flex; align-items: center; gap: 12px; min-height: 50px; margin-bottom: 14px; }
.toggle-field .grow { flex: 1; }
.toggle-field .grow small { display: block; color: var(--dim); font-size: 12px; }

/* Quick-add spend sheet */
.amount-input {
  text-align: center;
  font-family: var(--font-num);
  font-size: 46px !important;
  font-weight: 800;
  min-height: 76px !important;
  border-radius: 16px !important;
  letter-spacing: -0.02em;
}
.amount-wrap .prefix { font-size: 30px; left: 22px; }
.cat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.cat-btn {
  min-height: 72px;
  border-radius: 16px;
  background: var(--card-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-weight: 600;
  font-size: 14px;
  border: 1px solid var(--line);
  transition: transform 0.12s var(--ease), background 0.15s;
}
.cat-btn .e { font-size: 26px; line-height: 1; }
.cat-btn:last-child:nth-child(3n + 2) { grid-column: span 2; } /* 5 categories: last one fills the row */
.cat-btn:active { transform: scale(0.94); background: var(--accent-dim); }
.cat-btn.sel { border-color: var(--accent); background: var(--accent-dim); }
.quick-hint { text-align: center; color: var(--dim); font-size: 13px; margin-top: 10px; }

/* Toasts ------------------------------------------------------------------- */
.toast-wrap {
  position: fixed;
  z-index: 70;
  left: 0; right: 0;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 92px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  padding: 0 16px;
}
.toast {
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: 100%;
  min-height: 46px;
  padding: 6px 8px 6px 16px;
  border-radius: 14px;
  background: #e9efec;
  color: #0b0f0d;
  font-weight: 600;
  font-size: 15px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  pointer-events: auto;
  animation: toast-in 0.3s var(--ease);
}
.toast.out { opacity: 0; transform: translateY(8px); transition: 0.25s; }
.toast button { min-height: 36px; padding: 0 12px; border-radius: 10px; background: #0b0f0d; color: var(--accent); font-weight: 700; }
.toast:not(:has(button)) { padding-right: 16px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(0.98); } }

/* Respect "Reduce Motion" -------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
