/* expenses — tokens, base, components, utilities. One file, no build step. */

:root {
  --bg: #F6F7F9;
  --surface: #FFFFFF;
  --ink: #17202A;
  --muted: #5F6E7D;
  --line: #E2E7ED;
  --accent: #0B6E99;
  --accent-ink: #FFFFFF;
  --ok: #1F8A5B;
  --warn: #B9770E;
  --bad: #B5342A;
  --ok-bg: #E7F5EE;
  --warn-bg: #FBF1DC;
  --bad-bg: #FBE7E4;

  --font-display: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;

  --radius-card: 10px;
  --radius-pill: 999px;
  --radius-input: 6px;
  --shadow-card: 0 1px 2px rgba(23, 32, 42, .06), 0 8px 24px rgba(23, 32, 42, .06);

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-6: 24px;
  --sp-8: 32px;

  --tabbar-h: 56px;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1418;
    --surface: #161C22;
    --ink: #E6EBF0;
    --muted: #97A5B2;
    --line: #263039;
    --accent: #5FB3E0;
    --accent-ink: #0B1620;
    --ok: #4CC38A;
    --warn: #E2A33A;
    --bad: #E5665B;
    --ok-bg: #12301F;
    --warn-bg: #33260E;
    --bad-bg: #3A1A16;
  }
}

:root[data-theme="dark"] {
  --bg: #0F1418;
  --surface: #161C22;
  --ink: #E6EBF0;
  --muted: #97A5B2;
  --line: #263039;
  --accent: #5FB3E0;
  --accent-ink: #0B1620;
  --ok: #4CC38A;
  --warn: #E2A33A;
  --bad: #E5665B;
  --ok-bg: #12301F;
  --warn-bg: #33260E;
  --bad-bg: #3A1A16;
}

/* ---------- base ---------- */

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + var(--sp-4));
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.15;
  text-wrap: balance;
  margin: 0 0 var(--sp-2);
}

h1 { font-size: 28px; }
h2 { font-size: 22px; }
h3 { font-size: 15px; }

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

.container {
  max-width: 720px;
  margin: 0 auto;
  padding-inline: 16px;
  padding-block: 16px 24px;
}

.container--wide { max-width: 1040px; }

.eyebrow {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-family: var(--font-body);
}

.lead { font-size: 17px; }

.num, time, .amount, .mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.muted { color: var(--muted); }
.error, .tone-bad { color: var(--bad); }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- form controls ---------- */

input, select, textarea, button {
  font: inherit;
  color: inherit;
}

input[type="text"], input[type="password"], input[type="date"], input[type="time"],
input[type="file"], input[type="search"], select, textarea {
  min-height: 44px;
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius-input);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

input[inputmode="decimal"] {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

button, input[type="submit"], .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 16px;
  font-size: 15px;
  font-weight: 500;
  border-radius: var(--radius-input);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
}

button.primary, input[type="submit"].primary, .button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

button.outline { background: transparent; }

button.full, .button.full { width: 100%; }

form.inline { display: inline-flex; align-items: center; gap: 6px; margin: 0; }

.field-row { display: flex; gap: var(--sp-2); flex-wrap: wrap; margin-bottom: var(--sp-3); }

.filter-row-2col { display: grid; grid-template-columns: 1fr 1fr; }

.button-text {
  min-height: auto;
  padding: 4px 6px;
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
}

.nojs-only { display: none; }
html:not(.js) .nojs-only { display: inline-flex; }

/* ---------- month switcher (summary) ---------- */

.month-switcher {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
}

.month-select-wrap { position: relative; display: inline-flex; }

.month-select-wrap::after {
  content: "";
  position: absolute;
  right: 6px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}

.month-select {
  appearance: none;
  -webkit-appearance: none;
  border: none;
  background: transparent;
  min-height: auto;
  width: auto;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  color: var(--ink);
  padding: 4px 22px 4px 4px;
  cursor: pointer;
}

/* ---------- chips / pills ---------- */

.chip, .pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 36px;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
}

.chip.small, .pill.small { min-height: 24px; padding: 2px 10px; font-size: 12px; color: var(--muted); }

.chip.active, .pill.active, .chip[aria-current="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.chip.outline { background: transparent; }

.currency-code { display: none; }
.currency-group:has(input[value="other"]:checked) .currency-code { display: block; }

.chip-radio { position: relative; }
.chip-radio input { position: absolute; opacity: 0; width: 100%; height: 100%; left: 0; top: 0; margin: 0; cursor: pointer; }
.chip-radio:has(input:checked) { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip-radio:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.chip-row.scroll {
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}

.key-hint {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 4px;
  background: rgba(0,0,0,.08);
  font-size: 10px;
  font-family: var(--font-mono);
}

/* ---------- banners ---------- */

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-card);
  font-size: 14px;
}

.banner-ok { background: var(--ok-bg); color: var(--ok); }
.banner-warn { background: var(--warn-bg); color: var(--warn); }
.banner-bad { background: var(--bad-bg); color: var(--bad); }
.banner-accent { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); color: var(--ink); }

.banner .banner-action { flex-shrink: 0; }

/* ---------- rows / lists ---------- */

ul.list, ul.op-list, ul.rule-list, ul.category-list, ul.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  color: inherit;
}

.row:last-child { border-bottom: none; }

.row-main { display: flex; flex: 1 1 auto; flex-direction: column; gap: 2px; min-width: 0; }
.row-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 13px; color: var(--muted); }
.row-end { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex-shrink: 0; }

.row-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--accent);
  opacity: .35;
  margin-top: 4px;
}

/* ---------- cards / sheets ---------- */

.card {
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--sp-4);
  margin-bottom: var(--sp-4);
}

.sheet {
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--sp-4);
}

details.sheet-toggle > summary {
  list-style: none;
  cursor: pointer;
}
details.sheet-toggle > summary::-webkit-details-marker { display: none; }

.sheet-body {
  margin-top: var(--sp-3);
  max-height: 60vh;
  overflow-y: auto;
}

.sheet-search { margin-bottom: var(--sp-3); }

.sheet-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-2);
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  top: var(--sp-4);
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  box-shadow: var(--shadow-card);
  z-index: 50;
  animation: toast-in-out 2s ease forwards;
}

@keyframes toast-in-out {
  0% { opacity: 0; transform: translate(-50%, -8px); }
  10%, 80% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -8px); }
}

/* ---------- progress / coverage ---------- */

.progress {
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}

.progress-bar { height: 100%; background: var(--accent); }

.coverage-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9px, 1fr));
  gap: 2px;
}

.coverage-cell {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 14px;
  font-size: 9px;
  border-radius: 2px;
  background: var(--line);
  color: var(--muted);
}

.coverage-cell.covered { background: var(--ok); color: var(--accent-ink); }
.coverage-cell.today { outline: 1.5px solid var(--warn); outline-offset: -1.5px; }

.coverage-cell-n { display: none; }

@media (min-width: 480px) {
  .coverage-cell-n { display: inline; }
}

/* ---------- timeline (queue neighbours) ---------- */

ul.timeline {
  position: relative;
  padding-left: var(--sp-4);
  border-left: 2px solid var(--line);
}

ul.timeline li {
  position: relative;
  padding: var(--sp-2) 0 var(--sp-2) var(--sp-3);
  font-size: 13px;
}

ul.timeline li::before {
  content: "";
  position: absolute;
  left: calc(-1 * var(--sp-4) - 4px);
  top: 14px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--line);
}

ul.timeline li.current::before {
  left: calc(-1 * var(--sp-4) - 5px);
  width: 8px; height: 8px;
  background: var(--accent);
}

ul.timeline li.current { font-weight: 600; }
ul.timeline li.muted::before { background: var(--muted); }
ul.timeline li.pending::before { background: var(--warn); }

/* ---------- table (desktop ops) ---------- */

.op-list { display: block; }
.op-table { display: none; }
@media (min-width: 900px) {
  .op-list { display: none; }
  .op-table { display: table; }
}

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { text-align: left; padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--line); }
table.data thead th { position: sticky; top: 0; background: var(--bg); color: var(--muted); font-weight: 500; }
table.data tbody tr:nth-child(even) { background: color-mix(in srgb, var(--line) 30%, transparent); }
table.data td.num, table.data th.num { text-align: right; }

/* ---------- nav: tab bar (mobile) + top bar (desktop) ---------- */

.tab-icon svg { display: block; width: 20px; height: 20px; }

nav.app-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  z-index: 40;
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 44px;
  font-size: 10px;
  color: var(--muted);
  text-decoration: none;
  position: relative;
  border: none;
  background: none;
  cursor: pointer;
}

.tab-item[aria-current="page"] { color: var(--accent); }

.tab-badge {
  position: absolute;
  top: 2px;
  right: calc(50% - 20px);
  min-width: 15px;
  height: 15px;
  padding: 0 3px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 9px;
  font-family: var(--font-mono);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tab-badge:empty, .tab-badge[data-n="0"] { display: none; }

details.tab-more { position: static; }
details.tab-more[open] > .tab-more-sheet {
  position: fixed;
  left: var(--sp-4);
  right: var(--sp-4);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + var(--sp-2));
  z-index: 41;
}
details.tab-more:not([open]) > .tab-more-sheet { display: none; }

.tab-more-sheet .row { padding: var(--sp-3) var(--sp-2); }

.topbar {
  display: none;
}

@media (min-width: 641px) {
  body { padding-bottom: var(--sp-4); }
  nav.app-nav { display: none; }
  .topbar {
    display: flex;
    align-items: center;
    gap: var(--sp-4);
    max-width: 720px;
    margin: 0 auto;
    padding: var(--sp-3) 16px;
    border-bottom: 1px solid var(--line);
  }
  .container--wide + .topbar, body:has(.container--wide) .topbar { max-width: 1040px; }
  .topbar-brand { font-family: var(--font-display); font-weight: 700; margin-right: auto; }
  .topbar a { color: var(--muted); text-decoration: none; font-size: 14px; position: relative; }
  .topbar a[aria-current="page"] { color: var(--ink); font-weight: 600; }
  .topbar details { position: relative; }
  .topbar details > summary { list-style: none; cursor: pointer; color: var(--muted); font-size: 14px; }
  .topbar details > summary::-webkit-details-marker { display: none; }
  .topbar details .tab-more-sheet {
    position: absolute;
    right: 0; top: calc(100% + 8px);
    min-width: 200px;
    z-index: 41;
  }
}

@media (min-width: 900px) {
  .container--wide { max-width: 1040px; }
}
