:root {
  color-scheme: light;
  --page: #eef1ef;
  --surface: #fcfcfb;
  --surface-2: #f3f5f4;
  --ink: #15232e;
  --ink-2: #4f5d66;
  --muted: #737e84;
  --line: #dde3e0;
  --line-strong: #c3cbc8;
  --btn: #15232e;
  --btn-ink: #fcfcfb;
  --data: #2a78d6;
  --data-soft: #b7d3f6;
  --data-hatch: #86b6ef;
  --good: #006300;
  --warn: #8a5300;
  --warn-bg: #fff3d6;
  --danger: #b42828;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --radius: 10px;
  --font: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --page: #0f1417;
    --surface: #172024;
    --surface-2: #1d272b;
    --ink: #eef3f1;
    --ink-2: #b9c4c8;
    --muted: #8a959a;
    --line: #2a3438;
    --line-strong: #3b474c;
    --btn: #eef3f1;
    --btn-ink: #0f1417;
    --data: #3987e5;
    --data-soft: #184f95;
    --data-hatch: #1c5cab;
    --good: #0ca30c;
    --warn: #f0b84a;
    --warn-bg: #2e2612;
    --danger: #e66767;
    --grid: #2c2c2a;
    --axis: #383835;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.45 var(--font);
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--data); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.good { color: var(--good); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- shell ---------- */

.shell { display: grid; min-height: 100dvh; grid-template-rows: auto 1fr auto; }
.topbar {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 14px 16px 6px; max-width: 1040px; width: 100%; margin: 0 auto;
}
.brand { font-weight: 650; font-size: 17px; letter-spacing: -0.01em; }
.who { color: var(--muted); font-size: 14px; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; min-height: 32px; }
.who svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.7; }
.tabs a.desktop-only { display: none; }
main { width: 100%; max-width: 1040px; margin: 0 auto; padding: 8px 16px 96px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 4px 10px; text-decoration: none; font-size: 12px; color: var(--muted);
}
.tabs a svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.7; }
.tabs a[aria-current='page'] { color: var(--ink); font-weight: 600; }

@media (min-width: 900px) {
  .shell { grid-template-columns: 200px 1fr; grid-template-rows: auto 1fr; }
  .topbar { grid-column: 1 / -1; max-width: none; padding: 18px 28px 8px; }
  .tabs {
    position: sticky; top: 0; align-self: start; grid-row: 2;
    display: flex; flex-direction: column; gap: 2px; border: 0; background: none; padding: 12px 12px 0 20px;
  }
  .tabs a, .tabs a.desktop-only { display: flex; flex-direction: row; gap: 10px; font-size: 15px; padding: 9px 12px; border-radius: 8px; }
  .who svg { display: none; }
  .tabs a[aria-current='page'] { background: var(--surface); }
  main { grid-row: 2; padding: 12px 28px 48px; margin: 0; }
}

h1 { font-size: 26px; line-height: 1.15; letter-spacing: -0.02em; margin: 6px 0 16px; font-weight: 650; }
h2 { font-size: 17px; margin: 0 0 10px; font-weight: 620; letter-spacing: -0.01em; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stack > * + * { margin-top: 16px; }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: 8px; border: 1px solid transparent;
  background: var(--btn); color: var(--btn-ink); font-weight: 600; cursor: pointer;
}
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.secondary { background: transparent; color: var(--ink); border-color: var(--line-strong); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--line-strong); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 14px; }
.linkish { background: none; border: 0; padding: 0; color: var(--ink-2); text-decoration: underline; cursor: pointer; font-size: 14px; }

label.field { display: block; }
label.field > span { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 4px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 44px; padding: 9px 12px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--surface);
}
textarea.input { min-height: 70px; resize: vertical; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1 1 140px; }

.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button {
  min-height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line-strong);
  background: var(--surface); cursor: pointer; font-size: 14px; color: var(--ink-2);
}
.seg button[aria-pressed='true'] { background: var(--ink); color: var(--surface); border-color: var(--ink); }

.error { color: var(--danger); font-size: 14px; min-height: 1.2em; margin: 6px 0 0; }
.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 20;
  background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 8px; font-size: 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
}
@media (min-width: 900px) { .toast { bottom: 28px; } }

/* ---------- quick entry (the one loud element) ---------- */

.entry { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px 18px 16px; }
.entry-date { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 14px; margin-bottom: 8px; }
.entry-date input { border: 0; background: none; color: var(--ink-2); padding: 0; min-height: 0; font-size: 14px; }
.entry-line {
  width: 100%; border: 0; border-bottom: 2px solid var(--ink); background: none;
  font-size: 30px; font-weight: 550; letter-spacing: -0.02em; padding: 4px 0 8px; border-radius: 0;
}
.entry-line::placeholder { color: var(--line-strong); font-weight: 450; }
.entry-line:focus { outline: none; border-bottom-color: var(--data); }
.readout {
  display: grid; grid-template-columns: auto 1fr; gap: 2px 16px; align-items: baseline;
  margin: 14px 0 4px; min-height: 52px;
}
.readout .amount { font-size: 34px; font-weight: 650; letter-spacing: -0.03em; line-height: 1.05; grid-row: span 2; }
.readout .amount.back { color: var(--good); }
.readout .desc { font-weight: 550; overflow-wrap: anywhere; }
.readout .cat { color: var(--ink-2); font-size: 14px; }
.readout .hint { grid-column: 1 / -1; color: var(--muted); font-size: 14px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0; }
.chip {
  min-height: 34px; padding: 0 12px; border-radius: 999px; font-size: 14px; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
}
.chip[aria-pressed='true'] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); font-weight: 600; }
.entry-more { display: grid; gap: 10px; grid-template-columns: 1fr; margin-top: 4px; }
@media (min-width: 640px) { .entry-more { grid-template-columns: 1fr 1fr; } }
.entry-actions { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin-top: 14px; }
.entry-actions .btn { flex: 1 1 200px; max-width: 320px; white-space: nowrap; }

/* ---------- expense list ---------- */

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filters .input { width: auto; min-height: 38px; padding: 6px 10px; flex: 1 1 150px; }
.filters select.input { flex: 0 1 220px; }
.filters input[type='search'] { flex: 2 1 180px; }
.month-nav { display: flex; align-items: center; gap: 4px; }
.month-nav button { width: 38px; height: 38px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface); cursor: pointer; }
.month-nav strong { min-width: 118px; text-align: center; font-weight: 600; }
.summary-line { color: var(--ink-2); font-size: 14px; margin: 4px 0 10px; }

.day { margin-bottom: 14px; }
.day-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); padding: 0 4px 4px; }
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.item {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; width: 100%; text-align: left;
  padding: 11px 14px; background: none; border: 0; border-top: 1px solid var(--line); cursor: pointer;
}
.item:first-child { border-top: 0; }
.item:hover { background: var(--surface-2); }
.item .d { font-weight: 550; overflow-wrap: anywhere; }
.item .a { font-weight: 600; text-align: right; }
.item .a.back { color: var(--good); }
.item .c { font-size: 13px; color: var(--muted); grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; }
.tag { font-size: 12px; padding: 0 6px; border-radius: 4px; border: 1px solid var(--line-strong); color: var(--ink-2); }
.tag.guess { border-style: dotted; }
.tag.review { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.empty { padding: 28px 16px; text-align: center; color: var(--ink-2); }

dialog {
  width: min(560px, calc(100vw - 24px)); border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); color: var(--ink); padding: 18px;
}
dialog::backdrop { background: rgba(10, 16, 20, 0.45); }
dialog form { display: grid; gap: 12px; }
dialog .source { font-size: 13px; color: var(--muted); }
.dialog-actions { display: flex; gap: 10px; justify-content: space-between; flex-wrap: wrap; margin-top: 4px; }
.dialog-actions > div { display: flex; gap: 10px; }

/* ---------- statistics ---------- */

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 760px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.tile .k { font-size: 13px; color: var(--ink-2); }
.tile .v { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.2; margin-top: 2px; }
.tile .s { font-size: 13px; color: var(--muted); margin-top: 2px; }

.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.chart { position: relative; margin-top: 6px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--data); }
.chart .bar.low { fill: url(#hatch); }
.chart .bar.dim { opacity: 0.35; }
.chart .hit { fill: transparent; cursor: default; }
.chart .avg { stroke: var(--ink-2); stroke-width: 1; }
.chart .avg-label { fill: var(--ink-2); font-size: 11px; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 3; background: var(--ink); color: var(--surface);
  padding: 7px 10px; border-radius: 6px; font-size: 13px; white-space: nowrap; transform: translate(-50%, -100%);
}
.tooltip b { font-weight: 650; }
.footnote { font-size: 13px; color: var(--muted); margin-top: 8px; display: flex; gap: 8px; align-items: center; }
.swatch-avg { width: 16px; height: 0; border-top: 1px solid var(--ink-2); }
.footnote + .footnote { margin-top: 2px; }
.swatch-hatch { width: 14px; height: 10px; border-radius: 2px; background: repeating-linear-gradient(45deg, var(--data-hatch) 0 2px, transparent 2px 4px); border: 1px solid var(--data-hatch); }

.bars { display: grid; gap: 2px; }
.bar-row {
  display: grid; grid-template-columns: minmax(110px, 38%) 1fr auto; gap: 10px; align-items: center;
  padding: 6px 4px; border-radius: 6px; background: none; border: 0; width: 100%; text-align: left; cursor: pointer;
}
.bar-row:hover { background: var(--surface-2); }
.bar-row .name { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .track { height: 10px; position: relative; }
.bar-row .fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--data); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-row .val { font-size: 14px; text-align: right; min-width: 92px; }
.bar-row .val small { color: var(--muted); margin-left: 6px; }
.bar-row.child { padding-left: 18px; }
.bar-row.child .fill { background: var(--data-soft); }
.bar-row[aria-expanded='true'] .name { font-weight: 600; }

.two-col { display: grid; gap: 16px; }
@media (min-width: 900px) { .two-col { grid-template-columns: 1fr 1fr; } }

table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: left; font-weight: 550; color: var(--ink-2); font-size: 13px; padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.data td { padding: 7px 4px; border-bottom: 1px solid var(--line); }
table.data td.r, table.data th.r { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr:last-child td { border-bottom: 0; }

/* ---------- login ---------- */

.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(380px, 100%); display: grid; gap: 14px; }
.login h1 { margin-bottom: 4px; }

/* ---------- settings ---------- */

.cat-tree { display: grid; gap: 4px; }
.cat-tree .top { font-weight: 600; margin-top: 10px; }
.cat-line { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 4px 0; }
.cat-line.sub { padding-left: 16px; color: var(--ink-2); }
.cat-line.archived { opacity: 0.5; }

@media (prefers-reduced-motion: no-preference) {
  .entry-saved { animation: saved 0.5s ease-out; }
  @keyframes saved { from { background: var(--data-soft); } to { background: var(--surface); } }
}

/* ---------- assistant ---------- */

.chat { display: flex; flex-direction: column; min-height: calc(100dvh - 190px); max-width: 760px; }
.chat-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.chat-head h1 { margin-bottom: 10px; }
.chat-log { flex: 1; display: flex; flex-direction: column; gap: 14px; padding-bottom: 12px; }
.chat-empty p { color: var(--ink-2); margin-top: 0; }
.chat-empty .chip { text-align: left; min-height: 38px; padding: 6px 12px; border-radius: 10px; }
.msg.user { align-self: flex-end; max-width: 85%; }
.msg.user > div { background: var(--ink); color: var(--surface); padding: 9px 13px; border-radius: 14px 14px 4px 14px; overflow-wrap: anywhere; }
.msg.assistant { max-width: 100%; }
.msg.assistant .md { background: var(--surface); border: 1px solid var(--line); border-radius: 4px 14px 14px 14px; padding: 4px 14px; overflow-wrap: anywhere; }
.md p { margin: 9px 0; }
.md ul, .md ol { margin: 9px 0; padding-left: 22px; }
.md li + li { margin-top: 3px; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.md code { font-size: 0.9em; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
.md-table { overflow-x: auto; margin: 8px 0; }
.md-table table { min-width: 320px; }
.chat-tools { font-size: 13px; color: var(--muted); margin: 0 0 5px 2px; }
.chat-tools.working::after { content: ''; display: inline-block; width: 1ch; }
.chat-batch { font-size: 13px; color: var(--ink-2); margin: 6px 0 0 2px; display: flex; gap: 10px; align-items: baseline; }
.composer {
  position: sticky; bottom: calc(62px + env(safe-area-inset-bottom)); z-index: 4;
  display: flex; gap: 8px; align-items: flex-end; padding: 10px 0 12px; background: var(--page);
}
.composer textarea { resize: none; min-height: 44px; max-height: 180px; line-height: 1.4; }
.composer .btn { flex: 0 0 auto; }
@media (min-width: 900px) { .composer { bottom: 0; } }
@media (prefers-reduced-motion: no-preference) {
  .chat-tools.working { animation: pulse 1.4s ease-in-out infinite; }
  @keyframes pulse { 50% { opacity: 0.45; } }
}

/* ---------- trips ---------- */

a.item { text-decoration: none; color: inherit; }
.item-row { display: flex; align-items: stretch; border-top: 1px solid var(--line); }
.item-row:first-child { border-top: 0; }
.item-row .item { border-top: 0; flex: 1; min-width: 0; }
.item-row .remove {
  flex: 0 0 44px; border: 0; border-left: 1px solid var(--line); background: none; color: var(--muted);
  font-size: 20px; cursor: pointer;
}
.item-row .remove:hover { color: var(--danger); background: var(--surface-2); }
.suggestions { display: grid; gap: 10px; }
@media (min-width: 760px) { .suggestions { grid-template-columns: 1fr 1fr; } }
.suggestion { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; background: var(--surface-2); }
.s-head { display: flex; justify-content: space-between; gap: 10px; }
.s-meta { font-size: 13px; margin-top: 2px; }
.s-examples { font-size: 13px; color: var(--ink-2); margin-top: 6px; overflow-wrap: anywhere; }
.s-match { font-size: 13px; margin-top: 6px; }
.s-actions { display: flex; gap: 8px 12px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.picklist { max-height: min(46vh, 420px); overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; margin-top: 4px; }
.pick { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 8px 10px; border-top: 1px solid var(--line); cursor: pointer; }
.pick:first-child { border-top: 0; }
.pick input { width: 18px; height: 18px; }
.pick .p-d { overflow-wrap: anywhere; }
.pick .p-d small { display: block; color: var(--muted); font-size: 12px; }
.pick-toggle { display: flex; gap: 8px; align-items: center; font-size: 14px; min-height: 44px; }
.pick-head { display: flex; justify-content: space-between; align-items: center; }
.trip-controls { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.trip-controls select.input { width: auto; min-height: 34px; padding: 4px 8px; }
