/* =========================================================
   Budget — app-specific tokens & components.
   Shared design language: ../../../shared/tokens.css + base.css.
   ========================================================= */
:root {
  /* Chart bars are a single-hue ordinal ramp keyed to the accent: --bar for
     context, --bar-hi for the highlighted (current) mark. Every pair below was
     run through the dataviz validator against the surface it renders on —
     monotone lightness, and the step nearest the surface clears the floor. */
  --bar: #6E5BB8;
  --bar-hi: #A78BFA;

  --amount-size: 68px;
  --cat-min-h: 82px;

  /* Category identity colours (dark steps — all >= 6:1 on the tile surface).
     Always paired with a distinct glyph and the category name, so colour never
     has to carry identity by itself. */
  --cat-food: #F59E5B;
  --cat-coffee: #A78BFA;
  --cat-groceries: #84CC16;
  --cat-transport: #60A5FA;
  --cat-fuel: #FBBF24;
  --cat-shopping: #F472B6;
  --cat-entertainment: #22D3EE;
  --cat-bills: #34D399;
  --cat-health: #FB7185;
  --cat-other: #94A3B8;
  --cat-custom: #C4B5FD;
  /* Extra slots so custom categories don't all share one look — icons.js
     rotates through cat-custom.. cat-custom-5 by hashing the category name.
     Same >= 6:1 dark / >= 4.6:1 light validation as the defaults above. */
  --cat-custom-2: #A2DAF6;
  --cat-custom-3: #F4DD9A;
  --cat-custom-4: #9AEAD6;
  --cat-custom-5: #D7AFF4;
}

/* Light theme takes darker steps of the same hues — all >= 4.6:1 on white. */
:root[data-theme="light"] {
  --cat-food: #C2410C;
  --cat-coffee: #7C3AED;
  --cat-groceries: #4D7C0F;
  --cat-transport: #2563EB;
  --cat-fuel: #B45309;
  --cat-shopping: #DB2777;
  --cat-entertainment: #0E7490;
  --cat-bills: #047857;
  --cat-health: #E11D48;
  --cat-other: #475569;
  --cat-custom: #6D28D9;
  --cat-custom-2: #1072A2;
  --cat-custom-3: #85680F;
  --cat-custom-4: #19765F;
  --cat-custom-5: #9832E2;
}
:root[data-accent="teal"]   { --bar: #1F8F6C; --bar-hi: #34D8A5; }
:root[data-accent="violet"] { --bar: #6E5BB8; --bar-hi: #A78BFA; }
:root[data-accent="blue"]   { --bar: #3E6FC0; --bar-hi: #5B9CF6; }
:root[data-accent="amber"]  { --bar: #B07E2E; --bar-hi: #F5B95B; }
:root[data-accent="rose"]   { --bar: #C04C74; --bar-hi: #FB7BA8; }

/* Light theme re-steps the ramp for the light surface — the highlighted mark
   stays the strongest of the pair, so emphasis reads the same in both themes. */
:root[data-theme="light"]                       { --bar: #A48BEE; --bar-hi: #6D4FD0; }
:root[data-theme="light"][data-accent="teal"]   { --bar: #4FBF98; --bar-hi: #12805C; }
:root[data-theme="light"][data-accent="violet"] { --bar: #A48BEE; --bar-hi: #6D4FD0; }
:root[data-theme="light"][data-accent="blue"]   { --bar: #7FAEF0; --bar-hi: #2A5FAF; }
:root[data-theme="light"][data-accent="amber"]  { --bar: #D9A344; --bar-hi: #9A6B12; }
:root[data-theme="light"][data-accent="rose"]   { --bar: #F090B4; --bar-hi: #B93F6C; }

:root[data-compact="true"] {
  --amount-size: 56px;
  --cat-min-h: 72px;
}

/* =========================================================
   Shell
   ========================================================= */
/* App-shell scrolling: the page itself never scrolls, the active view does.
   The tab bar was `position: fixed`, and iOS Safari re-positions fixed elements
   mid-scroll as the address bar collapses — which is what made it drift over
   the content. As a flex child of a non-scrolling shell it simply can't move. */
html, body { overflow: hidden; }

.app {
  max-width: 480px;
  margin: 0 auto;
  /* vh/dvh track the browser chrome and iOS misreports them in standalone
     PWAs, leaving dead space below the tab bar. html/body are height: 100%
     (shared/base.css) against the real viewport, so inheriting that avoids
     the toolbar math entirely. */
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.view {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0 var(--view-pad-x) 20px;
  animation: view-in 0.24s var(--ease);
}
.view--hidden { display: none; }

@keyframes view-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.view-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 20px) 0 14px;
}
.view-head h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
}
.view-head__meta {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-faint);
}

/* =========================================================
   Log view — head
   ========================================================= */
.log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 18px) 0 14px;
}
.log-head__title {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 0;
}

.more-btn {
  flex: none;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: background 0.15s var(--ease), color 0.15s var(--ease), transform 0.15s var(--ease);
}
.more-btn:hover { background: var(--surface-3); color: var(--text); }
.more-btn:active { transform: scale(0.92); }

/* ---- Today / Month summary cards ---- */
.totals {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.total-card {
  padding: 13px 15px;
  border-radius: var(--radius-md);
}
.total-card__label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-dim);
}
.total-card__dot {
  width: 7px;
  height: 7px;
  border-radius: var(--radius-pill);
  background: var(--text-faint);
}
.total-card--accent .total-card__dot { background: var(--accent); }
.total-card__value {
  display: block;
  margin-top: 5px;
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.total-card--accent .total-card__value { color: var(--accent); }

/* =========================================================
   Amount input — the thing the app opens to
   ========================================================= */
.amount { margin: 0 0 18px; }

/* The hero card. The glow is a soft accent wash bled in from the edges — it
   marks this as the live surface without adding a border the eye has to parse.
   `isolation` keeps the ::before wash from painting over the input. */
.amount__card {
  position: relative;
  isolation: isolate;
  padding: 22px 20px 20px;
  border-radius: 30px;
  /* An accent wash bleeding in from the corners, with a dark radial pool
     painted back over the middle — so the light reads as a rim around the
     number rather than a tint across it. */
  background:
    /* dark pool painted back over the middle — keeps the number on black */
    radial-gradient(74% 64% at 50% 52%, var(--surface) 0%, var(--surface) 46%, transparent 92%),
    /* corner lights — mixed toward transparent so the hue stays vivid */
    radial-gradient(50% 60% at 0% 0%, var(--accent) 0%, color-mix(in srgb, var(--accent) 55%, transparent) 30%, transparent 72%),
    radial-gradient(44% 54% at 100% 0%, color-mix(in srgb, var(--accent) 88%, transparent) 0%, color-mix(in srgb, var(--accent) 40%, transparent) 32%, transparent 72%),
    radial-gradient(64% 40% at 50% 104%, color-mix(in srgb, var(--accent) 45%, transparent) 0%, transparent 74%),
    var(--surface);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  box-shadow:
    inset 0 0 30px -12px color-mix(in srgb, var(--accent) 55%, transparent),
    inset 0 1px 0 0 color-mix(in srgb, #fff 14%, transparent),
    0 22px 48px -26px color-mix(in srgb, var(--accent) 85%, transparent),
    var(--shadow-2);
  text-align: center;
  transition: border-color 0.25s var(--ease), box-shadow 0.25s var(--ease);
}

/* Soft bloom spilling outside the card edges. */
.amount__card::before {
  content: "";
  position: absolute;
  inset: -18px;
  z-index: -1;
  border-radius: 44px;
  background:
    radial-gradient(44% 50% at 12% 12%, color-mix(in srgb, var(--accent) 80%, transparent) 0%, transparent 70%),
    radial-gradient(42% 48% at 92% 8%, color-mix(in srgb, var(--accent) 62%, transparent) 0%, transparent 70%),
    radial-gradient(58% 42% at 55% 102%, color-mix(in srgb, var(--accent) 45%, transparent) 0%, transparent 70%);
  filter: blur(22px);
  opacity: 0.95;
  pointer-events: none;
  transition: opacity 0.3s var(--ease);
}

/* Typing lights it up further. */
.amount__card--filled {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  box-shadow:
    inset 0 0 44px -8px color-mix(in srgb, var(--accent) 90%, transparent),
    inset 0 1px 0 0 color-mix(in srgb, #fff 16%, transparent),
    0 24px 54px -24px color-mix(in srgb, var(--accent) 95%, transparent),
    var(--shadow-2);
}
.amount__card--filled::before { opacity: 1.15; }

/* On the light surface the same construction would grey the card out, so the
   wash is dialled back and the bloom carries the accent instead. */
:root[data-theme="light"] .amount__card {
  background:
    radial-gradient(78% 62% at 50% 52%, var(--surface) 42%, color-mix(in srgb, var(--surface) 60%, transparent) 76%, transparent 100%),
    linear-gradient(138deg,
      color-mix(in srgb, var(--accent) 40%, var(--surface)) 0%,
      color-mix(in srgb, var(--accent) 14%, var(--surface)) 28%,
      var(--surface) 50%,
      color-mix(in srgb, var(--accent) 14%, var(--surface)) 76%,
      color-mix(in srgb, var(--accent) 38%, var(--surface)) 100%);
  box-shadow:
    inset 0 0 30px -12px color-mix(in srgb, var(--accent) 55%, transparent),
    0 18px 38px -26px color-mix(in srgb, var(--accent) 75%, transparent),
    var(--shadow-2);
}
:root[data-theme="light"] .amount__card::before { opacity: 0.5; }

.amount__currency {
  display: block;
  font-family: var(--font-mono);
  font-size: 17px;
  font-weight: 500;
  color: var(--text-dim);
  transition: color 0.15s var(--ease);
}
.amount__card--filled .amount__currency { color: var(--text); }

.amount__field {
  display: flex;
  align-items: baseline;
  justify-content: center;
  padding: 2px 0 10px;
}

/* `input.` so this beats the shared base's input[type="text"] box styling. */
input.amount__input {
  /* Deliberately not a boxed field: the number IS the screen. */
  font-family: var(--font-mono);
  font-size: var(--amount-size);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  line-height: 1.05;
  /* Full width rather than sized-to-content: it works in every engine (no
     field-sizing dependency) and makes the whole card row a tap target. */
  width: 100%;
  max-width: 100%;
  padding: 0;
  border: none;
  background: none;
  color: var(--text);
  text-align: center;
  caret-color: var(--accent);
}
input.amount__input::placeholder { color: var(--text-faint); opacity: 0.45; }
input.amount__input:focus,
input.amount__input:focus-visible { outline: none; }

@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  30%, 70% { transform: translateX(4px); }
  50% { transform: translateX(-4px); }
}
.amount--invalid .amount__card { animation: shake 0.32s var(--ease); }

.note-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: var(--radius-pill);
  font-size: 13.5px;
  font-weight: 550;
  color: var(--text-dim);
  background: color-mix(in srgb, var(--text) 7%, transparent);
  border: 1px solid var(--border);
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.note-toggle:hover { background: color-mix(in srgb, var(--text) 12%, transparent); color: var(--text); }
.note-toggle[aria-expanded="true"] {
  color: var(--accent);
  background: var(--accent-dim);
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
}

.enter-hint {
  margin: 10px 0 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--text-faint);
  font-family: var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.enter-hint kbd {
  font-family: inherit;
  padding: 1px 5px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  color: var(--text-dim);
}

input.note-input, textarea.note-input, select.note-input {
  width: 100%;
  margin-top: 12px;
  padding: 11px 14px;
  font-family: var(--font-ui);
  font-size: 14px;
  text-align: center;
  background: color-mix(in srgb, var(--text) 6%, transparent);
  border-color: var(--border);
}

/* =========================================================
   Category grid — the save buttons
   ========================================================= */
/* The tinted glyph badge — the recurring identity chip for a category. */
.cat-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-pill);
  color: var(--c);
  background: color-mix(in srgb, var(--c) 15%, transparent);
}
.cat-badge--square {
  width: 40px;
  height: 40px;
  border-radius: 13px;
}

.cat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 9px;
}

.cat {
  min-height: var(--cat-min-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 2px 11px;
  text-align: center;
  font-size: 11.5px;
  font-weight: 550;
  letter-spacing: -0.015em;
  line-height: 1.15;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 20px;
  transition: background 0.14s var(--ease), border-color 0.14s var(--ease), transform 0.1s var(--ease);
}

/* A long single word ("Entertainment") can't break at a space, so hyphenate it
   rather than letting it split mid-syllable or overflow the tile. */
/* Long names get one deterministic size step down so they stay on one line
   instead of relying on hyphenation, which Chrome applies inconsistently. */
.cat__label--long { font-size: 9.5px; letter-spacing: -0.04em; }

.cat__label {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  overflow-wrap: break-word;
  hyphens: auto;
  -webkit-hyphens: auto;
}
.cat:hover { background: var(--surface-2); border-color: var(--border-strong); }
.cat:active { transform: scale(0.94); }

/* The last category used — where Enter would go. Marked by fill, border and a
   brighter label together, not by colour alone. */
.cat--last {
  background: linear-gradient(165deg, color-mix(in srgb, var(--accent) 34%, var(--surface)), color-mix(in srgb, var(--accent) 16%, var(--surface)));
  border-color: color-mix(in srgb, var(--accent) 60%, transparent);
  box-shadow: 0 10px 26px -14px color-mix(in srgb, var(--accent) 85%, transparent);
}
.cat--last .cat-badge { background: color-mix(in srgb, var(--text) 14%, transparent); }

@keyframes cat-flash {
  0% { transform: scale(1); box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 55%, transparent); }
  35% { transform: scale(1.04); }
  100% { transform: scale(1); box-shadow: 0 0 0 14px transparent; }
}
.cat--saved { animation: cat-flash 0.5s var(--ease); }

/* =========================================================
   Budget strip (log view)
   ========================================================= */
.budget-strip {
  margin-top: 16px;
  padding: 13px var(--card-pad);
  border-radius: 20px;
}
.budget-strip__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
  font-size: 12.5px;
}
.budget-strip__left { color: var(--text-dim); }
.budget-strip__left b {
  color: var(--text);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.budget-strip__right {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

/* ---- Pace row: sparkline + the three numbers that describe the month ---- */
.budget-pace {
  display: flex;
  align-items: stretch;
  gap: 10px;
  margin-top: 13px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.spark {
  flex: none;
  width: 58px;
  display: flex;
  align-items: flex-end;
  color: var(--text-faint);
}
.spark svg { display: block; width: 100%; height: 40px; }
.spark--empty { align-items: center; }

.metric-row {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
}
.metric {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 8px;
  text-align: left;
}
.metric:first-child { padding-left: 0; }
/* Hairline separators between the metrics, none before the first. */
.metric + .metric { border-left: 1px solid var(--border); }
.metric__head {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 550;
  letter-spacing: -0.01em;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.metric__head svg { flex: none; }
.metric__value {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.metric__value--accent { color: var(--accent); }
:root[data-theme="light"] .metric__value--accent { color: color-mix(in srgb, var(--accent) 62%, #000); }
.metric--action { cursor: pointer; }
.metric--action:hover .metric__value { text-decoration: underline; }

/* =========================================================
   Progress bar (shared by strip + budget card)
   ========================================================= */
.progress {
  height: 8px;
  background: var(--surface-3);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.progress__fill {
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--accent);
  transition: width 0.4s var(--ease), background 0.2s var(--ease);
}
.progress--near .progress__fill { background: var(--warn); }
.progress--over .progress__fill { background: var(--bad); }

/* Status colours never carry meaning alone — each pairs with this label. */
.budget-note {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  font-size: 12.5px;
  font-weight: 550;
}
.budget-note--ok { color: var(--text-dim); }
.budget-note--near { color: var(--warn); }
.budget-note--over { color: var(--bad); }
.budget-note svg { flex: none; }

/* =========================================================
   Cards, rows, section heads
   ========================================================= */
/* =========================================================
   Card surfaces, in three tiers so the hierarchy survives.
   1. Hero  — the amount card: full accent bloom (above).
   2. Panel — cards, stat tiles, the budget block: a top-edge sheen, a slight
      vertical gradient and one faint accent corner. Lit, but recessive.
   3. List  — category tiles and expense rows: sheen and gradient only. Dozens
      of them share a screen, so no accent corner or they'd read as noise.
   ========================================================= */
.card,
.stat,
.total-card,
.budget-strip {
  background:
    radial-gradient(80% 62px at 100% 0%, color-mix(in srgb, var(--accent) 10%, transparent) 0%, transparent 72%),
    linear-gradient(168deg, color-mix(in srgb, var(--text) 5%, var(--surface)) 0%, var(--surface) 62%);
  border: 1px solid var(--border);
  box-shadow:
    inset 0 1px 0 0 color-mix(in srgb, #fff 7%, transparent),
    0 10px 26px -22px rgba(0, 0, 0, 0.9);
}

.cat,
.expense {
  background: linear-gradient(168deg, color-mix(in srgb, var(--text) 5%, var(--surface)) 0%, var(--surface) 68%);
  box-shadow: inset 0 1px 0 0 color-mix(in srgb, #fff 5%, transparent);
}

:root[data-theme="light"] .card,
:root[data-theme="light"] .stat,
:root[data-theme="light"] .total-card,
:root[data-theme="light"] .budget-strip {
  box-shadow:
    inset 0 1px 0 0 rgba(255, 255, 255, 0.9),
    0 10px 24px -22px rgba(15, 23, 32, 0.5);
}
:root[data-theme="light"] .cat,
:root[data-theme="light"] .expense {
  box-shadow: inset 0 1px 0 0 rgba(255, 255, 255, 0.9);
}

.card {
  padding: var(--card-pad);
  border-radius: var(--radius-md);
  margin-bottom: 12px;
}
.card--danger { border-color: rgba(249, 113, 102, 0.28); }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.section-head h2 {
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 0;
}
.section-head__meta {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-faint);
}

.link-btn {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent);
  padding: 4px 6px;
  margin: -4px -6px;
  border-radius: var(--radius-sm);
}
.link-btn:hover { background: var(--accent-dim); }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 46px;
  padding: 4px 0;
}
.row + .row { border-top: 1px solid var(--border); }
.row__label { font-size: 14px; font-weight: 500; }
.row__value {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-dim);
  text-align: right;
}
.row__hint {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-faint);
  margin: 8px 0 0;
}

input.row__control, textarea.row__control, select.row__control {
  flex: none;
  width: 46%;
  max-width: 190px;
  padding: 9px 11px;
  font-size: 14px;
  font-family: var(--font-ui);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}
.row__control--num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
}
select.row__control { cursor: pointer; }

/* =========================================================
   Buttons
   ========================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-ui);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  text-decoration: none;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.12s var(--ease);
}
.btn:active { transform: scale(0.97); }
.btn--primary { background: var(--accent); color: #0B0D10; }
.btn--primary:hover { background: var(--accent-strong); }
.btn--ghost {
  background: var(--surface-2);
  border-color: var(--border-strong);
  color: var(--text);
}
.btn--ghost:hover { background: var(--surface-3); }
.btn--danger { background: var(--bad); color: #0B0D10; width: 100%; }
.btn--danger-ghost { color: var(--bad); background: var(--bad-dim); }

.btn-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.btn-row > .btn { flex: 1; }
.btn svg { margin-right: 7px; }

/* =========================================================
   Stacked form field — for values too long to sit beside a label
   (endpoints, tokens). Label above, input full width.
   ========================================================= */
.field { margin-top: 14px; }
.field:first-of-type { margin-top: 4px; }
.field__label {
  display: block;
  margin-bottom: 7px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

input.field__input {
  display: block;
  width: 100%;
  height: 42px;
  padding: 0 13px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
input.field__input::placeholder {
  color: var(--text-faint);
  font-family: var(--font-ui);
  font-size: 13px;
}
input.field__input:focus,
input.field__input:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* The reveal sits inside the field, so the token reads as one control rather
   than an input with a mystery button bolted to its side. */
.field__group { position: relative; }
input.field__input--reveal { padding-right: 44px; }
.field__reveal {
  position: absolute;
  top: 50%;
  right: 3px;
  transform: translateY(-50%);
  width: 38px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--text-faint);
  background: none;
  border: none;
  transition: color 0.15s var(--ease), background 0.15s var(--ease);
}
.field__reveal:hover { color: var(--text); background: var(--surface-3); }
.field__reveal-slash { opacity: 1; transition: opacity 0.15s var(--ease); }
.field__reveal[aria-pressed="true"] { color: var(--accent); }
.field__reveal[aria-pressed="true"] .field__reveal-slash { opacity: 0; }

/* A row that follows a stacked field rather than another row still needs its
   separator. */
.row--standalone {
  margin-top: 16px;
  border-top: 1px solid var(--border);
}

.install-help {
  margin: 10px 0 0;
  padding: 11px 13px;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.install-help b { color: var(--text); font-weight: 650; }

/* =========================================================
   Expense list
   ========================================================= */
.recent { margin-top: 24px; }
.recent .section-head { margin-bottom: 10px; }

.expense-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.expense {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 62px;
  padding: 10px 12px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  transition: background 0.14s var(--ease), transform 0.1s var(--ease);
}
.expense:hover { background: var(--surface-2); }
.expense:active { transform: scale(0.99); }

.expense__body { flex: 1; min-width: 0; }
.expense__cat {
  display: block;
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.expense__meta {
  display: block;
  font-size: 12.5px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.expense__amount {
  flex: none;
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.expense__go {
  flex: none;
  display: flex;
  color: var(--text-faint);
  margin-left: -2px;
}

@keyframes row-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
.expense--new { animation: row-in 0.3s var(--ease); }

/* =========================================================
   History
   ========================================================= */
.search-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.search-row > .search { flex: 1; margin-bottom: 0; }

.advanced-filters {
  padding: 2px 0 4px;
  margin-bottom: 14px;
}

.search {
  position: relative;
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}
.search__icon {
  position: absolute;
  left: 12px;
  color: var(--text-faint);
  pointer-events: none;
}
input.search__input, textarea.search__input, select.search__input {
  width: 100%;
  padding: 11px 38px;
  font-family: var(--font-ui);
  font-size: 14px;
}
.search__input::-webkit-search-cancel-button { display: none; }
.search__clear {
  position: absolute;
  right: 8px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  color: var(--text-faint);
}
.search__clear:hover { background: var(--surface-3); color: var(--text); }

.filter-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 4px;
  margin-bottom: 14px;
  /* Bleed to the screen edges so the scroll affordance reads correctly. */
  margin-left: calc(var(--view-pad-x) * -1);
  margin-right: calc(var(--view-pad-x) * -1);
  padding-left: var(--view-pad-x);
  padding-right: var(--view-pad-x);
}
.filter-row::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  transition: background 0.14s var(--ease), color 0.14s var(--ease), border-color 0.14s var(--ease);
}
.chip__dot {
  width: 7px;
  height: 7px;
  border-radius: var(--radius-pill);
  background: var(--c, var(--text-faint));
}
.chip:hover { background: var(--surface-2); color: var(--text); }
.chip--active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

/* Bucket (Today / Yesterday / This week / Earlier) → optional day sub-groups. */
.bucket { margin-bottom: 22px; }
.bucket__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 0 2px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.bucket__title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.bucket__total {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.day-group + .day-group { margin-top: 14px; }
.day-group__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 0 2px 6px;
}
.day-group__title {
  font-size: 12px;
  font-weight: 550;
  color: var(--text-faint);
}
.day-group__total {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: var(--text-faint);
}

/* =========================================================
   Insights — stat tiles
   ========================================================= */
.stat-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.stat {
  padding: 13px var(--card-pad);
  border-radius: var(--radius-md);
}
.stat__value {
  display: block;
  font-family: var(--font-mono);
  font-size: 21px;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.stat__label {
  display: block;
  font-size: 11.5px;
  color: var(--text-faint);
  margin-top: 3px;
}

/* ---- Budget card ---- */
.budget-card__top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.budget-card__figure {
  font-family: var(--font-mono);
  font-size: 30px;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.budget-card__caption {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 3px;
}
.budget-card__side {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.budget-card__allowance {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-dim);
}
.budget-card__allowance b {
  color: var(--text);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* ---- Comparison ---- */
.compare {
  display: flex;
  align-items: center;
  gap: 12px;
}
.compare__delta {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: var(--radius-pill);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.compare__delta--up { color: var(--bad); background: var(--bad-dim); }
.compare__delta--down { color: var(--good); background: var(--good-dim); }
.compare__delta--flat { color: var(--text-dim); background: var(--surface-2); }
.compare__text { font-size: 12.5px; color: var(--text-dim); line-height: 1.45; }

/* =========================================================
   Charts — single-hue, magnitude only
   ========================================================= */
.bar-list {
  display: flex;
  flex-direction: column;
  gap: 11px;
}
.bar-row__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 5px;
}
.bar-row__name {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 13px;
  font-weight: 550;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cat-badge--sm { width: 24px; height: 24px; border-radius: 8px; }
.bar-row__value {
  flex: none;
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
}
.bar-row__track {
  height: 8px;
  background: var(--surface-3);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.bar-row__fill {
  height: 100%;
  /* 4px rounded data-end, anchored to the baseline at the left. */
  border-radius: 0 4px 4px 0;
  background: var(--c, var(--bar));
  transition: width 0.45s var(--ease);
}

/* ---- Monthly columns ---- */
.month-chart {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 132px;
  padding-top: 18px;
}
.month-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  height: 100%;
  gap: 6px;
  min-width: 0;
}
.month-col__bar {
  width: 100%;
  min-height: 3px;
  /* 4px rounded top; the base sits flat on the axis. */
  border-radius: 4px 4px 0 0;
  background: var(--bar);
  position: relative;
  transition: height 0.45s var(--ease);
}
.month-col--current .month-col__bar { background: var(--bar-hi); }
.month-col__value {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 5px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  color: var(--text-faint);
  white-space: nowrap;
}
.month-col--current .month-col__value { color: var(--text-dim); }
.month-col__label {
  font-size: 11px;
  color: var(--text-faint);
  white-space: nowrap;
}
.month-col--current .month-col__label { color: var(--text); font-weight: 600; }

.chart-empty {
  font-size: 13px;
  color: var(--text-faint);
  text-align: center;
  padding: 18px 0;
}

/* =========================================================
   Settings bits
   ========================================================= */
.chip-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.cat-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px 7px 13px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
}
.cat-tag--fixed { padding-right: 13px; color: var(--text-faint); }
.cat-tag__dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--c, var(--text-faint));
}
.cat-tag__remove {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-pill);
  color: var(--text-faint);
}
.cat-tag__remove:hover { background: var(--bad-dim); color: var(--bad); }

.add-cat {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
input.add-cat__input, textarea.add-cat__input, select.add-cat__input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  font-family: var(--font-ui);
  font-size: 14px;
}

.seg {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border-radius: var(--radius-pill);
}
.seg button {
  padding: 7px 12px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
  border-radius: var(--radius-pill);
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); }

.seg--settings { margin: 0 0 14px; }
.seg--settings button { flex: 1; text-align: center; }

.accents { display: flex; gap: 8px; }
.accent-dot {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.14s var(--ease);
}
.accent-dot:active { transform: scale(0.9); }
.accent-dot span {
  width: 18px;
  height: 18px;
  border-radius: var(--radius-pill);
}
.accent-dot[aria-pressed="true"] { border-color: var(--text); }

.switch {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 46px;
  height: 28px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  border: none;
  position: relative;
  cursor: pointer;
  transition: background 0.2s var(--ease);
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-pill);
  background: var(--text-dim);
  transition: transform 0.2s var(--ease), background 0.2s var(--ease);
}
.switch:checked { background: var(--accent-dim); }
.switch:checked::after { transform: translateX(18px); background: var(--accent); }

/* =========================================================
   Sheet, toast, tab bar, empty state
   ========================================================= */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  z-index: 40;
  animation: fade-in 0.2s var(--ease);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  z-index: 41;
  padding: 8px var(--view-pad-x) calc(env(safe-area-inset-bottom) + 20px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-2);
  animation: sheet-up 0.28s var(--ease);
}
@keyframes sheet-up {
  from { transform: translate(-50%, 100%); }
  to { transform: translate(-50%, 0); }
}
.sheet__grip {
  width: 36px;
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  margin: 0 auto 10px;
}
.sheet__title {
  font-size: 15px;
  font-weight: 650;
  margin: 0 0 6px;
}
.sheet__actions {
  display: flex;
  gap: 8px;
  margin-top: 18px;
}
.sheet__actions .btn { flex: 1; }

/* Import preview list — the one sheet whose content can outgrow the
   viewport (a statement can be dozens of rows), so it scrolls internally
   instead of pushing the sheet's own actions off-screen. */
#importList { max-height: 50vh; overflow-y: auto; margin: 0 -4px; }
.import-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  cursor: pointer;
}
.import-row + .import-row { border-top: 1px solid var(--border); }
.import-row__check { flex: none; width: 18px; height: 18px; accent-color: var(--accent); }
.import-row__main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.import-row__amount { font-family: var(--font-mono); font-size: 14px; font-weight: 600; }
.import-row__desc {
  font-size: 12px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.import-row__category {
  flex: none;
  max-width: 110px;
  padding: 6px 8px;
  font-size: 12.5px;
  font-family: var(--font-ui);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(calc(100% - 32px), 420px);
  padding: 11px 12px 11px 16px;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-2);
  font-size: 13px;
  font-weight: 550;
  animation: toast-in 0.24s var(--ease);
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
.toast__text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast__text b {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.toast__action {
  flex: none;
  padding: 4px 10px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--accent);
  border-radius: var(--radius-pill);
}
.toast__action:hover { background: var(--accent-dim); }

/* Floating pill bar: inset from the edges, with the active tab marked by a
   filled pill that slides between positions. */
.tabbar {
  position: relative; /* anchors .tabbar__pill; no longer fixed — see .app */
  flex: none;
  width: calc(100% - var(--view-pad-x) * 2);
  max-width: calc(480px - var(--view-pad-x) * 2);
  margin: 0 auto calc(env(safe-area-inset-bottom) + 10px);
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: 62px;
  padding: 6px;
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--surface-2) 82%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-2);
}

.tabbar__pill {
  position: absolute;
  top: 6px;
  left: 6px;
  height: calc(100% - 12px);
  width: calc((100% - 12px) / 4);
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  transform: translateX(calc(var(--tab-index, 0) * 100%));
  transition: transform 0.32s var(--ease);
  pointer-events: none;
}

.tab {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border-radius: var(--radius-pill);
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-faint);
  transition: color 0.18s var(--ease);
}
.tab:hover { color: var(--text-dim); }
.tab--active { color: var(--accent); }
/* The accent tokens are dark-theme steps; on the light pill they'd sit around
   2:1, so darken whatever accent is set rather than hard-coding a colour. */
:root[data-theme="light"] .tab--active { color: color-mix(in srgb, var(--accent) 62%, #000); }

.empty {
  text-align: center;
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--text-faint);
  padding: 28px 0;
  margin: 0;
}

/* =========================================================
   Wider screens — the phone layout is the design; desktop just
   gets breathing room and a second stat column.
   ========================================================= */
@media (min-width: 420px) {
  .stat-row { grid-template-columns: repeat(4, 1fr); }
}
@media (min-width: 560px) {
  :root { --amount-size: 68px; }
  .cat-grid { grid-template-columns: repeat(5, 1fr); }
}
