:root {
  color-scheme: light dark;
  --page: #f9f9f7;
  --card: #ffffff;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6d68;
  --line: #e1e0d9;
  --track: #ecebe6;
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --income: #2a78d6;
  --expense: #eb6834;
  --good: #006300;
  --critical: #d03b3b;
  --chip: #f0efec;
  --tabs-h: 56px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --card: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #9b9a92;
    --line: #2c2c2a;
    --track: #2c2c2a;
    --accent: #3987e5;
    --accent-ink: #6da7ec;
    --income: #3987e5;
    --expense: #d95926;
    --good: #0ca30c;
    --critical: #e66767;
    --chip: #2c2c2a;
  }
}

/* Category and wallet colors. --on is the icon color drawn on top of --cat. */
.c-blue { --cat: #2a78d6; --on: #fff; }
.c-orange { --cat: #eb6834; --on: #fff; }
.c-aqua { --cat: #1baf7a; --on: #fff; }
.c-yellow { --cat: #eda100; --on: #0b0b0b; }
.c-magenta { --cat: #e87ba4; --on: #0b0b0b; }
.c-green { --cat: #008300; --on: #fff; }
.c-violet { --cat: #6250d6; --on: #fff; }
.c-red { --cat: #e34948; --on: #fff; }
.c-sky { --cat: #46b7e8; --on: #0b0b0b; }
.c-lime { --cat: #a3b81a; --on: #0b0b0b; }
.c-plum { --cat: #a12d9c; --on: #fff; }
.c-brown { --cat: #92590f; --on: #fff; }
.c-navy { --cat: #24568f; --on: #fff; }
.c-peach { --cat: #f09766; --on: #0b0b0b; }
.c-teal { --cat: #008f8c; --on: #fff; }
.c-rose { --cat: #b3364f; --on: #fff; }
.c-gray { --cat: #77756e; --on: #fff; }
@media (prefers-color-scheme: dark) {
  .c-blue { --cat: #3987e5; }
  .c-orange { --cat: #d95926; }
  .c-aqua { --cat: #199e70; }
  .c-yellow { --cat: #c98500; }
  .c-magenta { --cat: #d55181; --on: #fff; }
  .c-violet { --cat: #9085e9; }
  .c-red { --cat: #e66767; }
  .c-sky { --cat: #2a9ccb; }
  .c-lime { --cat: #8f9f12; }
  .c-plum { --cat: #b84bb3; }
  .c-brown { --cat: #a56f2d; }
  .c-navy { --cat: #5f8fd6; }
  .c-peach { --cat: #c97d4a; --on: #0b0b0b; }
  .c-teal { --cat: #129a96; }
  .c-rose { --cat: #c95571; }
  .c-gray { --cat: #8f8d85; }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  touch-action: manipulation;
  overscroll-behavior-y: none;
}
body.sheet-open { overflow: hidden; }
body.sheet-open #view, body.sheet-open #tabs { visibility: hidden; }
[hidden] { display: none !important; }
[data-a] { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; text-align: left; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

#view {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px
    calc(env(safe-area-inset-bottom) + var(--tabs-h) + 24px);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

/* ---------- Tabs ---------- */
#tabs {
  position: fixed;
  inset: auto 0 0 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 1px solid var(--line);
}
.tab {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 2px;
  font-size: 11px;
  color: var(--muted);
}
.tab svg { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--accent-ink); font-weight: 600; }
.tab-add { justify-items: center; }
.tab-add span {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
}
.tab-add svg { width: 26px; height: 26px; }

/* ---------- Common ---------- */
.card {
  background: var(--card);
  border-radius: 16px;
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  min-width: 0;
}
.card-flush { padding: 0; gap: 0; overflow: hidden; }
.section-title { font-size: 20px; font-weight: 700; }
.small { font-size: 13px; color: var(--muted); }
.row-between { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.link { color: var(--accent-ink); font-weight: 600; min-height: 32px; }
.error { color: var(--critical); font-size: 14px; font-weight: 500; }
.empty { padding: 24px 16px; text-align: center; color: var(--muted); }

.month-nav { display: flex; align-items: center; justify-content: space-between; }
.month-nav h1 { font-size: 22px; font-weight: 700; }
.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: var(--accent-ink);
}
.icon-btn:disabled { color: var(--line); }
.icon-btn svg { width: 22px; height: 22px; }

.banner {
  background: var(--card);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  padding: 12px 14px;
  display: grid;
  gap: 4px;
  font-size: 14px;
}

/* ---------- Home ---------- */
.hero-label { font-size: 14px; color: var(--ink-2); }
.hero-amount {
  font-size: 40px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.5px;
  white-space: nowrap;
}
.hero-medium { font-size: 32px; }
.hero-small { font-size: 26px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.stat-value { font-weight: 600; font-size: 17px; overflow-wrap: anywhere; }
.bar { height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 4px; background: var(--accent); }
.bar.over > i { background: var(--critical); }
.budget-row { display: grid; gap: 6px; }
.over-text { color: var(--critical); font-weight: 600; }
.budget-name { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; min-width: 0; }

/* ---------- Colored icon badges ---------- */
.badge {
  flex: none;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--cat);
  color: var(--on);
}
.badge svg { width: 20px; height: 20px; }
.badge-small { width: 28px; height: 28px; }
.badge-small svg { width: 15px; height: 15px; }
.badge-large { width: 56px; height: 56px; }
.badge-large svg { width: 28px; height: 28px; }

/* ---------- All my money ---------- */
.total-label { display: flex; align-items: center; gap: 4px; font-size: 14px; color: var(--ink-2); }
.total-select {
  border: 0;
  padding: 2px;
  background: none;
  color: var(--accent-ink);
  font-size: 16px;
  font-weight: 600;
}
.wallet-list { margin: 0 -16px; }
.btn-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.reconcile-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
}
.reconcile-row:first-child { border-top: 0; }
.reconcile-main { flex: 1; min-width: 0; display: grid; gap: 1px; }
.reconcile-main .tx-sub { white-space: normal; }
.reconcile-input { flex: none; width: 38%; }
.reconcile-input .input { text-align: right; padding-inline: 8px; }
.reconcile-diff { font-size: 13px; font-weight: 600; color: var(--accent-ink); }
.reconcile-diff:empty { display: none; }
.reconcile-summary { font-size: 14px; font-weight: 500; color: var(--ink-2); }
.amount-currency { text-align: center; font-size: 15px; font-weight: 600; color: var(--muted); }
.missing-rate {
  width: 100%;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--chip);
  font-size: 14px;
  color: var(--ink-2);
}
.missing-rate b { color: var(--accent-ink); font-weight: 600; }

/* ---------- Transaction list ---------- */
.day-head {
  display: flex;
  justify-content: space-between;
  padding: 10px 16px 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.tx {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 8px 16px;
}
.tx-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--chip);
  color: var(--ink-2);
}
.tx-icon svg { width: 20px; height: 20px; }
.tx-main { flex: 1; min-width: 0; }
.tx-title, .tx-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-title { font-weight: 500; }
.tx-sub { font-size: 13px; color: var(--muted); }
.tx-wrap .tx-sub { white-space: normal; }
.tx-amount { flex: none; max-width: 55%; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.tx-amount.income { color: var(--good); }

.filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.filters #search { grid-column: 1 / -1; }

/* ---------- Forms ---------- */
.input, select.input {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  font-size: 16px;
  -webkit-appearance: none;
  appearance: none;
}
select.input {
  padding-right: 30px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 19px, calc(100% - 12px) 19px;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
input[type="date"].input { display: block; text-align: left; }
input[type="date"].input::-webkit-date-and-time-value { text-align: left; }
.field { display: grid; gap: 4px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 500; color: var(--ink-2); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 3px;
  border-radius: 10px;
  background: var(--chip);
}
.seg button {
  min-height: 38px;
  border-radius: 8px;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
}
.seg button[aria-pressed="true"] {
  background: var(--card);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}
.amount-input {
  width: 100%;
  border: 0;
  background: none;
  outline: none;
  text-align: center;
  font-size: 40px;
  font-weight: 700;
  padding: 4px 0;
}
.amount-input:focus-visible { outline: none; }
.cat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.cat {
  display: grid;
  justify-items: center;
  gap: 2px;
  min-height: 64px;
  padding: 6px 0;
  border-radius: 12px;
  border: 2px solid transparent;
  background: var(--chip);
  font-size: 11px;
  line-height: 1.2;
  text-align: center;
  overflow-wrap: anywhere;
}
.cat .badge { width: 34px; height: 34px; }
.cat .badge svg { width: 18px; height: 18px; }
.cat[aria-pressed="true"] { border-color: var(--accent); font-weight: 600; }

.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.preset {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 4px 12px 4px 6px;
  border-radius: 20px;
  background: var(--chip);
  font-size: 14px;
  font-weight: 500;
}
.name-row { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: end; gap: 12px; }
.swatches { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.swatch {
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--cat);
  border: 3px solid var(--page);
  outline: 2px solid transparent;
  outline-offset: -1px;
}
.swatch[aria-pressed="true"] { outline-color: var(--ink); }
.icon-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.icon-choice {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border-radius: 12px;
  background: var(--chip);
  color: var(--ink-2);
}
.icon-choice svg { width: 22px; height: 22px; }
.icon-choice[aria-pressed="true"] { background: var(--cat); color: var(--on); }

.btn {
  display: block;
  width: 100%;
  min-height: 46px;
  border-radius: 12px;
  background: var(--chip);
  text-align: center;
  font-weight: 600;
}
.btn-danger { color: var(--critical); }

/* ---------- Sheets ---------- */
#sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background: var(--page);
}
#sheet.enter { animation: rise 0.2s ease-out; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { #sheet.enter { animation: none; } }
.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 6px) 16px 6px;
  background: var(--page);
  border-bottom: 1px solid var(--line);
}
.sheet-head h2 { font-size: 17px; font-weight: 600; text-align: center; }
.sheet-head button { min-height: 44px; color: var(--accent-ink); }
.sheet-head .save { justify-self: end; font-weight: 700; }
.sheet-body {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 32px);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

/* ---------- Settings ---------- */
.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 50px;
  padding: 8px 16px;
  border-top: 1px solid var(--line);
}
.set-row:first-child { border-top: 0; }
label.set-row { cursor: pointer; }
/* iOS only opens a file picker for an input that stays in the layout, so never display:none. */
.file-input { position: fixed; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.set-row .chev { color: var(--muted); }
.set-row .value { color: var(--muted); font-size: 14px; text-align: right; }
.set-row select { width: auto; border: 0; background-color: transparent; color: var(--accent-ink); }
.rate-row { justify-content: flex-start; }
.rate-row > span { flex: none; font-weight: 500; }
.rate-row .input { flex: 1; text-align: right; }
a { color: var(--accent-ink); }

/* ---------- Insights ---------- */
.cat-bar { display: grid; gap: 6px; width: 100%; min-height: 44px; padding: 4px 0; }
.cat-bar .bar > i { background: var(--cat); }
.donut { position: relative; width: min(100%, 260px); margin: 0 auto; }
.donut svg { display: block; width: 100%; height: auto; }
.slice { fill: none; stroke: var(--cat); stroke-width: 26; }
.slice.dim { opacity: 0.3; }
.donut-center {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 56%;
  height: fit-content;
  text-align: center;
  pointer-events: none;
}
.donut-amount { font-size: 21px; font-weight: 700; line-height: 1.15; white-space: nowrap; }
.donut-amount-long { font-size: 17px; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--ink-2); }
.legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  border-radius: 3px;
}
.chart { display: block; width: 100%; height: auto; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart text.selected { fill: var(--ink); font-weight: 700; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .income { fill: var(--income); }
.chart .expense { fill: var(--expense); }
.chart .hit { fill: transparent; }
.chart .hit.selected { fill: var(--chip); }
details summary { color: var(--accent-ink); font-size: 14px; font-weight: 500; min-height: 28px; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 8px; }
.table th, .table td { padding: 6px 0; text-align: right; border-top: 1px solid var(--line); }
.table th { font-weight: 600; color: var(--muted); border-top: 0; }
.table th:first-child, .table td:first-child { text-align: left; }
.table td { font-variant-numeric: tabular-nums; }

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  z-index: 30;
  left: 16px;
  right: 16px;
  bottom: calc(env(safe-area-inset-bottom) + var(--tabs-h) + 12px);
  max-width: 528px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 8px 16px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--page);
  font-size: 14px;
}
#toast button { font-weight: 700; min-height: 32px; flex: none; }

/* ---------- Import preview ---------- */
.preview { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; font-size: 14px; }
.preview div { display: flex; justify-content: space-between; gap: 12px; }
.preview span:first-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview span:last-child { flex: none; white-space: nowrap; }
