:root {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --surface-2: #eef2ef;
  --text: #15201b;
  --muted: #64716a;
  --line: #dde4df;
  --accent: #0b7a55;
  --accent-ink: #ffffff;
  --accent-soft: #dcefe6;
  --warn: #b25e00;
  --warn-soft: #fff1dc;
  --danger: #c0362c;
  --ai: #5b48c2;
  --ai-soft: #ebe8fb;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .06);
  --radius: 14px;
  --tabbar-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1512;
    --surface: #18201c;
    --surface-2: #212b26;
    --text: #e8eeea;
    --muted: #93a29a;
    --line: #2b3731;
    --accent: #3ccf95;
    --accent-ink: #062016;
    --accent-soft: #1d3a2e;
    --warn: #f0a640;
    --warn-soft: #3a2a12;
    --danger: #f06a5f;
    --ai: #a99bff;
    --ai-soft: #2a2546;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.4em; margin: 0; }

#views { padding: 8px 16px calc(var(--tabbar-h) + 56px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }

/* --- buttons, chips, inputs --- */
.btn {
  border: 0; border-radius: 12px; padding: 12px 16px; background: var(--surface-2);
  font-weight: 600; min-height: 48px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: transparent; color: var(--danger); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.btn:disabled { opacity: .5; }
.icon-btn { width: 48px; min-width: 48px; height: 48px; padding: 0; display: grid; place-items: center; border-radius: 12px; border: 0; }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.ghost { background: transparent; font-size: 1.8rem; color: var(--muted); }

.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 8px 14px; min-height: 40px; font-weight: 500; white-space: nowrap;
}
.chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

input[type=text], input[type=password], input[type=search], input[type=number], input[type=date], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px;
  padding: 12px 14px; min-height: 48px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
label { display: block; font-size: .85rem; color: var(--muted); margin: 12px 0 4px; }
label.toggle { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--text); white-space: nowrap; }
label.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }

/* --- top bar --- */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px; background: var(--bg);
  max-width: 640px; margin: 0 auto;
}
.currency-chip { font-weight: 700; letter-spacing: .02em; }
.trip-banner { flex: 1; min-width: 0; display: flex; justify-content: flex-end; }
.trip-banner .chip { overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.trip-banner .chip.on-trip { background: var(--ai-soft); border-color: transparent; color: var(--ai); font-weight: 600; }
.offline-badge { font-size: .75rem; padding: 4px 8px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); }

/* --- capture --- */
.capture { padding: 4px 0 0; }
.text-form { display: flex; gap: 8px; width: 100%; }
.text-form input { flex: 1; min-width: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 4px; }
.chips .chip small { color: var(--muted); font-weight: 400; margin-left: 4px; }

/* --- cards & lists --- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin: 12px 0; }
.nudge { display: flex; align-items: center; gap: 12px; border-left: 4px solid var(--warn); }
.nudge .body { flex: 1; min-width: 0; }
.nudge .actions { display: flex; flex-direction: column; gap: 6px; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 20px 0 6px; }
.tx-list { list-style: none; padding: 0; margin: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.tx-list:empty { display: none; }
.tx {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line);
  min-height: 60px; width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left;
}
.tx:last-child { border-bottom: 0; }
.tx .main { flex: 1; min-width: 0; }
.tx .item { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .meta { font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .amount { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx .amount .usd { font-size: .8rem; color: var(--muted); }
.tx-list li { border-bottom: 1px solid var(--line); }
.tx-list li:last-child { border-bottom: 0; }
.tx-list li .tx { border-bottom: 0; }
.review-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 0 16px 12px 36px; margin-top: -4px; }
.review-actions .why { flex: 1 1 140px; font-size: .8rem; color: var(--warn); }
.review-actions .acts { display: flex; gap: 6px; margin-left: auto; }
.chips .chip { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.tag { display: inline-block; font-size: .72rem; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); margin-right: 4px; }
.tag.review { background: var(--warn-soft); color: var(--warn); }
.tag.ai { background: var(--ai-soft); color: var(--ai); }
.tag.trip { background: var(--accent-soft); color: var(--accent); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: transparent; }
.dot.review { background: var(--warn); }
.dot.ai { background: var(--ai); }
.empty { text-align: center; color: var(--muted); padding: 24px 0; }
.review-link { display: block; width: 100%; margin-top: 12px; border: 0; background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 12px; font-weight: 600; }
.day-head { display: flex; justify-content: space-between; margin: 18px 4px 6px; font-size: .85rem; color: var(--muted); font-weight: 600; }

/* --- history / month --- */
.month-nav { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 8px; }
.month-nav h2 { font-size: 1.15rem; }
.filters { display: flex; gap: 12px; align-items: center; }
.filters input { flex: 1; }

.big-total { font-size: 2.4rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.stat { flex: 1; min-width: 96px; background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.stat b { display: block; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: .75rem; color: var(--muted); }
.delta.up { color: var(--danger); }
.delta.down { color: var(--accent); }

.daily { display: flex; align-items: flex-end; gap: 2px; height: 96px; margin-top: 12px; }
.daily .bar { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 1px; opacity: .85; }
.daily .bar.future { background: var(--line); }
.daily-axis { display: flex; justify-content: space-between; font-size: .7rem; color: var(--muted); margin-top: 4px; }

.cat-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.cat-row:last-child { border-bottom: 0; }
.cat-row .name { font-weight: 600; }
.cat-row .val { text-align: right; font-variant-numeric: tabular-nums; }
.cat-row .track { grid-column: 1 / -1; height: 6px; background: var(--surface-2); border-radius: 3px; position: relative; overflow: hidden; }
.cat-row .fill { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: 3px; }
.cat-row .prev { grid-column: 1 / -1; font-size: .75rem; color: var(--muted); }

/* --- trips / settings --- */
.trip-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%; padding: 12px 0; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; }
.trip-row:last-child { border-bottom: 0; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 8px; }
.settings-group h3 { font-size: .95rem; margin-bottom: 4px; }
.watch-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.watch-item:last-child { border-bottom: 0; }
.link-btn { background: none; border: 0; color: var(--accent); padding: 8px 0; font-weight: 600; }

/* --- tab bar --- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
.tabbar button { flex: 1; border: 0; background: none; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .72rem; }
.tabbar svg { width: 24px; height: 24px; fill: currentColor; }
.tabbar button.active { color: var(--accent); font-weight: 600; }

/* the big mic, raised out of the middle of the tab bar: right under the thumb on every screen */
.tab-mic-slot { flex: 1.2; display: flex; justify-content: center; position: relative; }
.tabbar .tab-mic {
  position: absolute; bottom: 10px; width: 84px; height: 84px; border-radius: 50%; flex: none;
  background: var(--accent); color: var(--accent-ink); border: 5px solid var(--bg);
  display: grid; place-items: center; box-shadow: 0 6px 20px rgba(11, 122, 85, .4); transition: transform .15s;
}
.tabbar .tab-mic svg { width: 40px; height: 40px; fill: currentColor; }
.tabbar .tab-mic:active { transform: scale(.94); }
.tabbar .tab-mic.listening { animation: pulse 1.2s ease-in-out infinite; background: var(--danger); box-shadow: 0 6px 20px rgba(192, 54, 44, .45); }
@keyframes pulse { 50% { transform: scale(1.07); } }
@media (prefers-reduced-motion: reduce) { .tabbar .tab-mic.listening { animation: none; } }

.voice-panel {
  position: fixed; left: 16px; right: 16px; z-index: 11; max-width: 600px; margin: 0 auto;
  bottom: calc(var(--tabbar-h) + 44px + env(safe-area-inset-bottom));
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 14px 16px; text-align: center;
}
.voice-panel .transcript { margin: 0; min-height: 1.4em; font-size: 1.1rem; font-weight: 600; }
.voice-panel .mic-hint { margin: 4px 0 0; color: var(--muted); font-size: .85rem; }
.gear { margin-left: 4px; }
.gear svg { width: 24px; height: 24px; }

/* --- bottom sheet --- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; background: var(--surface);
  border-radius: 20px 20px 0 0; padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  max-height: 90vh; overflow-y: auto; max-width: 640px; margin: 0 auto;
  animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet .grabber { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 12px; }
.sheet h2 { margin-bottom: 4px; }
.sheet .actions { display: flex; gap: 8px; margin-top: 16px; }
.sheet .actions .btn { flex: 1; }
.reasons { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 8px 12px; font-size: .9rem; margin-top: 8px; }
.ai-note { background: var(--ai-soft); color: var(--ai); border-radius: 10px; padding: 8px 12px; font-size: .9rem; margin-top: 8px; display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.cat-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.cat-picker .chip { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.amount-input { font-size: 2rem !important; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; }
details summary { color: var(--accent); font-weight: 600; padding: 12px 0 4px; cursor: pointer; }

/* --- toast --- */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabbar-h) + 44px + env(safe-area-inset-bottom)); z-index: 30;
  max-width: 600px; margin: 0 auto; background: var(--text); color: var(--bg); border-radius: 12px;
  padding: 12px 16px; display: flex; align-items: center; gap: 12px; box-shadow: var(--shadow);
}
.toast .msg { flex: 1; min-width: 0; }
.toast button { background: none; border: 0; color: var(--accent); font-weight: 700; padding: 6px 4px; }
@media (prefers-color-scheme: dark) { .toast button { color: #0b7a55; } }

/* --- login --- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; align-items: center; text-align: center; }
.login-card input, .login-card button { width: 100%; }
