/* budget - mobile-first. Light + dark, safe-area aware, no framework. */
:root {
  --bg: #f5f6f8; --card: #ffffff; --text: #10151c; --muted: #667080;
  --line: #e3e6ea; --accent: #0e7c66; --accent-ink: #ffffff;
  --ok: #17916f; --warn: #c98a12; --bad: #c53b2f;
  --shadow: 0 1px 2px rgba(16,21,28,.06), 0 8px 24px rgba(16,21,28,.06);
  --tap: 44px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1319; --card: #181d25; --text: #e9edf2; --muted: #949eab;
    --line: #262d37; --accent: #35b795; --accent-ink: #06201a;
    --ok: #35b795; --warn: #e0a53a; --bad: #ef6b5e;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  /* Stop the rubber-band bounce past the top/bottom. On an iOS home-screen app
     that overscroll is what drags browser chrome into view, and it also removes
     pull-to-refresh, which a standalone app should not have. */
  overscroll-behavior-y: none;
}
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
h1, h2, h3 { margin: 0; font-weight: 650; }
.hide { display: none !important; }

/* ---- layout ---- */
main { max-width: 640px; margin: 0 auto; padding: 12px 14px 4px; }
.card {
  background: var(--card); border-radius: 16px; padding: 16px;
  box-shadow: var(--shadow); margin-bottom: 12px;
}
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pad { padding: 14px; }

/* ---- top bar ---- */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(8px + env(safe-area-inset-top)) 14px 4px;
  max-width: 640px; margin: 0 auto;
}
header h1 { font-size: 19px; letter-spacing: -.01em; }
.iconbtn {
  min-width: var(--tap); min-height: var(--tap); border-radius: 12px;
  display: grid; place-items: center; font-size: 19px; color: var(--muted);
}
.iconbtn:active { background: var(--line); }

/* ---- the alert chip ---- */
.chip-alert {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  background: var(--accent); color: var(--accent-ink); border-radius: 14px;
  padding: 12px 16px; min-height: var(--tap); font-weight: 600; margin-bottom: 12px;
}
.chip-alert:active { filter: brightness(.94); }

/* ---- hero ---- */
.hero { text-align: center; padding: 22px 16px 18px; }
.hero .amount { font-size: 44px; font-weight: 700; letter-spacing: -.03em; line-height: 1.05; }
.hero .amount.neg { color: var(--bad); }
.hero .sub { color: var(--muted); margin-top: 6px; font-size: 14px; }
.hero .perday { margin-top: 2px; font-size: 15px; font-weight: 600; }

/* progress: spend bar with a marker showing how far through the month we are */
.track {
  position: relative; height: 10px; border-radius: 999px;
  background: var(--line); margin-top: 16px; overflow: hidden;
}
.track > i { position: absolute; inset: 0 auto 0 0; border-radius: 999px; background: var(--ok); }
.track > b {
  position: absolute; top: -3px; width: 2px; height: 16px;
  background: var(--text); opacity: .45; border-radius: 2px;
}
.track.warn > i { background: var(--warn); }
.track.bad  > i { background: var(--bad); }
.verdict { margin-top: 8px; font-size: 13px; font-weight: 600; }

/* ---- category bars ---- */
.cat { display: block; width: 100%; text-align: left; padding: 11px 0; border-bottom: 1px solid var(--line); }
.cat:last-child { border-bottom: 0; }
.cat .top { display: flex; justify-content: space-between; gap: 10px; font-size: 15px; }
.cat .pct { color: var(--muted); font-variant-numeric: tabular-nums; }
.cat .bar { height: 7px; border-radius: 999px; background: var(--line); margin-top: 7px; overflow: hidden; }
.cat .bar > i { display: block; height: 100%; border-radius: 999px; background: var(--ok); }
.cat.warn .bar > i { background: var(--warn); }
.cat.bad  .bar > i { background: var(--bad); }
.cat.bad .pct { color: var(--bad); }

/* ---- transaction rows ---- */
.tx { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.tx:last-child { border-bottom: 0; }
.tx .desc { flex: 1; min-width: 0; }
.tx .desc b { display: block; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .amt { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.tx .amt.in { color: var(--ok); }
.pill {
  display: inline-block; border: 1px solid var(--line); border-radius: 999px;
  padding: 3px 10px; font-size: 12px; color: var(--muted); background: var(--bg);
  min-height: 26px; line-height: 20px;
}
.pill.none { border-style: dashed; color: var(--accent); font-weight: 600; }
/* The chip stays visually small, but the THUMB target is a full 44px: a
   transparent ::after overhangs it vertically without disturbing layout.
   This is the most-tapped control in the app - it must not be fiddly. */
button.pill { position: relative; min-height: 30px; min-width: 44px; }
button.pill::after {
  content: ''; position: absolute; left: 0; right: 0; top: 50%;
  height: 44px; transform: translateY(-50%);
}

/* ---- bottom nav + FAB ---- */
nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around; align-items: flex-start;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
nav button {
  flex: 1; min-height: var(--tap); display: grid; place-items: center; gap: 2px;
  color: var(--muted); font-size: 11px; padding: 4px 0;
}
nav button .ico { font-size: 20px; line-height: 1; }
nav button.on { color: var(--accent); }
nav .fab {
  flex: 0 0 auto; width: 58px; height: 58px; margin-top: -20px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-size: 30px; line-height: 1;
  display: grid; place-items: center; box-shadow: 0 6px 18px rgba(14,124,102,.4);
}
nav .fab:active { transform: scale(.94); }

/* ---- sheet / modal ---- */
.scrim {
  position: fixed; inset: 0; z-index: 40; background: rgba(8,11,15,.5);
  display: flex; align-items: flex-end; justify-content: center;
}
/* A sheet opened from inside another sheet (a transaction from a category)
   stacks; the first scrim already dims, so don't dim twice. */
#modal .scrim:nth-child(n+2) { background: transparent; }
.sheet {
  background: var(--card); width: 100%; max-width: 640px;
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 92vh; overflow-y: auto; animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(18px); opacity: .5 } to { transform: none; opacity: 1 } }
.sheet h2 { font-size: 17px; margin-bottom: 14px; }
.grab { width: 38px; height: 4px; border-radius: 999px; background: var(--line); margin: -6px auto 14px; }

.big-choice {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  background: var(--bg); border: 1px solid var(--line); border-radius: 16px;
  padding: 18px 16px; margin-bottom: 10px; font-size: 17px; font-weight: 600;
}
.big-choice .ico { font-size: 26px; }
.big-choice:active { background: var(--line); }

/* ---- forms ---- */
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; min-height: var(--tap);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.amount-in {
  font-size: 34px; font-weight: 700; text-align: center; padding: 14px;
  font-variant-numeric: tabular-nums;
}
.btn {
  display: block; width: 100%; background: var(--accent); color: var(--accent-ink);
  border-radius: 14px; padding: 14px; min-height: var(--tap);
  font-size: 17px; font-weight: 650; text-align: center;
}
.btn:active { filter: brightness(.94); }
.btn.ghost { background: var(--bg); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--bad); }
.btn[disabled] { opacity: .55; }
.seg { display: flex; gap: 8px; margin-bottom: 12px; }
.seg button {
  flex: 1; min-height: var(--tap); border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); font-weight: 600; color: var(--muted);
}
.seg button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ---- category picker grid ---- */
.catgrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.catgrid button {
  min-height: var(--tap); border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); padding: 10px; font-size: 15px; text-align: left;
}
.catgrid button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.catgrid button.guess { border-color: var(--accent); border-width: 2px; font-weight: 650; }

/* ---- review stack ---- */
.review .amount { font-size: 32px; font-weight: 700; text-align: center; }
.review .who { text-align: center; color: var(--muted); margin: 4px 0 2px; }
.review .count { text-align: center; font-size: 13px; color: var(--muted); margin-bottom: 14px; }

/* ---- filters ---- */
.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; }
.filters select { width: auto; flex: 0 0 auto; min-height: 38px; padding: 6px 10px; font-size: 14px; }

/* ---- misc ---- */
.skel { background: var(--line); border-radius: 8px; height: 14px; animation: pulse 1.1s infinite; }
@keyframes pulse { 0%,100% { opacity: .5 } 50% { opacity: .85 } }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(92px + env(safe-area-inset-bottom)); z-index: 60;
  background: var(--text); color: var(--bg); padding: 11px 18px;
  border-radius: 999px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow);
}
.empty { text-align: center; color: var(--muted); padding: 34px 16px; }
.empty .ico { font-size: 34px; display: block; margin-bottom: 8px; }

/* ---- login ---- */
.login-wrap { min-height: 100svh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 360px; }
.login-card h1 { text-align: center; font-size: 26px; margin-bottom: 4px; }
.login-card .tag { text-align: center; color: var(--muted); margin-bottom: 22px; font-size: 14px; }
.err { color: var(--bad); font-size: 14px; text-align: center; min-height: 20px; margin-top: 10px; }
