:root {
  /* Icy-blue palette (OKLCH; contrast verified: ink/muted/red/green ≥4.5:1 on bg+paper). */
  --bg: oklch(0.975 0.014 240); /* frosty body */
  --ink: oklch(0.22 0.025 250); /* cold blue-black — text, borders, shadows */
  --paper: oklch(0.99 0.006 240); /* card/surface near-white */
  --accent: oklch(0.66 0.09 232); /* deep slate blue — fills only; ink text sits on it (5.65:1) */
  --pink: oklch(0.67 0.19 18); /* danger button bg (the one warm note — red reads danger on blue) */
  --red: oklch(0.49 0.2 22); /* readable debt/error text on frosty bg (~6.4:1) */
  --green: oklch(0.52 0.14 155); /* credit text (~4.8:1) */
  --muted: oklch(0.48 0.02 245); /* cool gray-blue secondary text (~6.1:1) */
  --track: oklch(0.9 0.012 240); /* report bar track, tinted to the brand */
  --shadow: 4px 4px 0 var(--ink);
  --border: 3px solid var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  /* ponytail: overscroll off so touch-drag on the drawer doesn't fight the browser bounce */
  overscroll-behavior-y: none;
}

/* the month scrubber replaces the native rail — hide the document scrollbar (scrolling still works) */
html {
  scrollbar-width: none; /* Firefox */
}
html::-webkit-scrollbar {
  display: none; /* Chromium / WebKit / Safari */
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 14px;
  min-height: 100vh;
  min-height: 100dvh;
}

a {
  color: var(--ink);
}

h1,
h2,
h3 {
  margin: 0.2em 0;
  line-height: 1.1;
}

/* ---- buttons ---- */
.btn {
  font: inherit;
  font-weight: 700;
  background: var(--accent);
  color: var(--ink);
  border: var(--border);
  box-shadow: var(--shadow);
  padding: 0.55em 0.9em;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  text-decoration: none;
}
.btn:active {
  transform: translate(3px, 3px);
  box-shadow: 1px 1px 0 var(--ink);
}
.btn.secondary {
  background: var(--paper);
}
.btn.danger {
  background: var(--pink);
  /* ponytail: ink text — white-on-pink was 3.1:1, fails AA normal text; ink clears it and stays on-brand */
  color: var(--ink);
}
.btn.block {
  width: 100%;
  justify-content: center;
}
/* Disabled = clearly non-interactive: dimmed, no shadow, no pointer, no press. */
.btn:disabled {
  opacity: 0.5;
  box-shadow: none;
  cursor: not-allowed;
  pointer-events: none;
}

/* ---- inputs ---- */
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}
.field label {
  font-weight: 700;
  font-size: 0.85rem;
}
input,
select,
textarea {
  font: inherit;
  color: var(--ink);
  border: var(--border);
  border-radius: 6px;
  padding: 0.55em 0.6em;
  background: var(--paper);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.06);
  width: 100%;
}
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  background: #fff;
  /* ponytail: visible neobrutalist focus ring (a11y — was outline:none with no replacement) */
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.06), 0 0 0 3px var(--accent);
}

/* keyboard focus visible on every actionable element */
.btn:focus-visible,
a:focus-visible,
.chip:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

/* ---- cards ---- */
.card {
  background: var(--paper);
  border: var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 14px;
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.spacer {
  flex: 1;
}

/* ---- chips ---- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 0.5em 0.95em;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--paper);
  cursor: pointer;
  user-select: none;
  /* a11y: meet the 44px touch floor on a one-handed mobile app */
  min-height: 40px;
}
.chip.on {
  background: var(--accent);
}

/* selectable chip group (e.g. category picker in the add form) */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.muted {
  color: var(--muted);
  font-size: 0.85rem;
}

.amount-pos {
  color: var(--green);
}
.amount-neg {
  color: var(--red);
}
/* The money figure is the hero of every surface: 1.7rem, 800, tabular (DESIGN.md Number-Wins + Display spec). */
.amount {
  font-size: 1.7rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.amount-pos,
.amount-neg {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}
.topbar h1 {
  font-size: 1.15rem;
  font-weight: 700;
  /* truncate long group names so they never wrap-fight the back button on a 390px screen */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty {
  text-align: center;
  padding: 40px 16px;
  color: var(--muted);
}

.err {
  color: var(--red);
  font-weight: 700;
  font-size: 0.9rem;
  margin-top: 4px;
}

/* ---- month grouping: ledger divider with the month total as the hero figure ---- */
.month-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 6px;
}
.month-label {
  font-weight: 800;
  font-size: 1.05rem;
}

/* ---- month scrubber: edge fast-scroll rail (Immich-style). Segments are proportional to
   each month's content; year boundaries carry a label, the rest carry dots. Drag to scrub,
   a cursor line tracks scroll, a bubble labels the month under the pointer. ---- */
.month-scrubber{
  position:fixed; top:76px; bottom:calc(94px + env(safe-area-inset-bottom)); width:34px; z-index:18;
  touch-action:none; cursor:pointer; outline:none;
  /* pin to the centered column's right edge on desktop, the viewport edge on mobile */
  right:max(6px, calc((100vw - 560px) / 2 - 38px));
}
.month-scrubber:focus-visible{ box-shadow:-2px 0 0 var(--ink); }
.ms-seg{ position:absolute; left:0; right:0; display:flex; align-items:flex-end; justify-content:center; }
.ms-year{
  font:600 .6rem/1 ui-monospace, "SF Mono", "Segoe UI", monospace;
  color:var(--ink); opacity:.7; transform:translateY(-1px);
}
.ms-dot{ width:5px; height:5px; border-radius:50%; background:var(--muted); opacity:.5; }
.ms-dot.on{ background:var(--ink); opacity:.95; transform:scale(1.25); }
.ms-cursor{
  position:absolute; left:calc(50% - 7px); width:14px; height:2px; border-radius:2px;
  background:var(--ink); opacity:.85; pointer-events:none; transform:translateY(-1px);
}
.ms-bubble{
  position:fixed; right:max(48px, calc((100vw - 560px) / 2 + 6px)); z-index:19;
  transform:translateY(-50%) scale(.9); opacity:0; pointer-events:none;
  background:var(--ink); color:var(--bg); box-shadow:var(--shadow);
  padding:.5em .7em; border-radius:8px; font-weight:700; font-size:.8rem; white-space:nowrap;
  transition:opacity .12s ease, transform .12s ease;
}
.ms-bubble.show{ opacity:1; transform:translateY(-50%) scale(1); }
/* on mobile the column fills the viewport — reserve a gutter so the rail never covers a card's delete button */
@media (max-width: 600px){
  .expenses-list{ padding-right:40px; }
}

/* ---- trends: 6 monthly bars, current month highlighted ---- */
.trends {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 150px;
}
.trend-col {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  height: 100%;
}
.trend-bar {
  width: 100%;
  min-height: 6px;
  background: var(--track);
  border: 2px solid var(--ink);
  border-radius: 6px 6px 0 0;
}
.trend-bar.on {
  background: var(--accent);
}
.trend-axis {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.trend-axis-col {
  flex: 1 1 0;
  text-align: center;
}
.trend-amount {
  font-size: 0.68rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.trend-axis-col.on .trend-amount {
  color: var(--ink);
}
.trend-label {
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: capitalize;
}

/* ---- skeleton loading (product UI loads into the task, not a spinner) ---- */
.skeleton {
  background: rgba(0, 0, 0, 0.06);
  border: var(--border);
  border-radius: 10px;
  height: 70px;
  position: relative;
  overflow: hidden;
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.5), transparent);
  animation: sk 1.3s ease-in-out infinite;
}
@keyframes sk {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* ---- toast (status confirmation + undo) ---- */
.toast {
  position: fixed;
  left: 14px;
  right: 14px;
  bottom: 100px;
  z-index: 60; /* below drawer, above content */
  background: var(--ink);
  color: var(--bg);
  border: var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 0.6em 0.9em;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  animation: toast-in 0.2s ease-out;
}
@keyframes toast-in {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ---- neobrutalist sheet base (used by both bottom drawers) ---- */
.pane {
  border-top: var(--border) !important;
  border-radius: 16px 16px 0 0 !important;
  box-shadow: 0 -6px 0 var(--ink) !important;
  background: var(--paper) !important;
}
/* neobrutalist grab pill for the bottom drawers */
.drawer-grip {
  width: 44px;
  height: 5px;
  border-radius: 3px;
  background: var(--ink);
  margin: 10px auto 2px;
}
.drawer-head {
  display: flex;
  align-items: center;
  font-weight: 800;
  font-size: 1.05rem;
  padding: 6px 18px 4px;
}
/* grip + header are the drag handle: own the touch so the browser doesn't scroll/bounce,
   and let the transform follow the finger directly (no transition while dragging). */
.drawer-grip,
.drawer-head {
  cursor: grab;
  touch-action: none;
}
.drawer-form {
  padding: 4px 18px 22px;
}
.drawer-form .btn.block { margin-top: 6px; }

/* ---- app shell: sticky header, scrollable main, fixed bottom dock (nav + FAB) ---- */
.app-page {
  min-height: 100vh;
  min-height: 100dvh;
}
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  padding: 6px 0 10px;
  margin-bottom: 12px;
}
.app-header h1 {
  font-size: 1.15rem;
  font-weight: 700;
}
/* clear the fixed bottom dock so the last card isn't hidden behind it */
.app-main {
  padding-bottom: calc(82px + env(safe-area-inset-bottom));
}

/* ponytail: respect reduced motion for the CSS-driven shimmer. */
@media (prefers-reduced-motion: reduce) {
  .skeleton::after { animation: none; }
  * {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* ---- bottom dock: tab navbar + floating add button (YouTube-style bottom nav) ----
   Fixed to the viewport bottom, centered to the 560px column. The FAB sits above the
   bar at bottom-right; the add-expense drawer opens over content (a real drawer, not
   a layout-shifting overlay). */
.dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 560px;
  margin: 0 auto;
  z-index: 30;
}
.bottom-nav {
  display: flex;
  border-top: var(--border);
  background: var(--paper);
  box-shadow: 0 -4px 0 var(--ink);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav-btn {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 9px 0 8px;
  background: transparent;
  border: none;
  font: inherit;
  font-weight: 700;
  font-size: 0.68rem;
  color: var(--ink);
  cursor: pointer;
  min-height: 58px;
}
.bottom-nav-btn .ic {
  width: 24px;
  height: 24px;
  opacity: 0.4;
  transition: opacity 140ms ease-out;
}
.bottom-nav-btn.active {
  background: var(--accent);
}
.bottom-nav-btn.active .ic {
  opacity: 1;
}
.bottom-nav-btn:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: -3px;
}

/* floating "+" action button — summons the add-expense drawer */
.fab {
  position: absolute;
  right: 14px;
  bottom: calc(72px + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  border: var(--border);
  box-shadow: var(--shadow);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 31;
  transition: transform 120ms ease-out, box-shadow 120ms ease-out;
}
.fab:active {
  transform: translate(3px, 3px);
  box-shadow: 1px 1px 0 var(--ink);
}
.fab .ic { width: 28px; height: 28px; }
@media (prefers-reduced-motion: reduce) {
  .fab { transition: none; }
  .bottom-nav-btn .ic { transition: none; }
}

/* ---- logout confirm drawer content ---- */
.pane-confirm {
  padding: 8px 18px 26px;
  background: var(--paper);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}
.pane-confirm-title {
  font-size: 1.15rem;
  font-weight: 800;
}
.pane-confirm .muted {
  margin: 2px 0 10px;
}

/* ---- logout confirm drawer (self-contained bottom sheet) ---- */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: oklch(0.22 0.025 250 / 0.45);
  animation: drawer-fade 0.18s ease-out;
}
/* .pane supplies the neobrutalist border/shadow/radius; this positions it as a sheet */
.drawer-sheet.pane {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 51;
  max-width: 560px;
  max-height: 88dvh;
  overflow-y: auto;
  margin: 0 auto;
  border-top: var(--border);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -6px 0 var(--ink);
  background: var(--paper);
  animation: drawer-up 0.22s cubic-bezier(.2, .9, .2, 1);
}
@keyframes drawer-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes drawer-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) {
  .drawer-backdrop { animation: none; }
  .drawer-sheet.pane { animation: none; }
}

/* ---- chip-toggles: <label class="chip"> wrapping a checkbox/radio ---- */
.chip:has(input:checked) {
  background: var(--accent);
}
.chip input[type="checkbox"],
.chip input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
