/* Tally — mobile-first, no inline styles (works under a strict CSP). */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #17202a;
  --muted: #5d6b7a;
  --border: #dde2e8;
  --brand: #0f9d77;
  --brand-ink: #ffffff;
  --brand-hover: #0b8463;
  --pos: #0a8a5f;
  --neg: #c4501a;
  --danger: #c62f2f;
  --warn-bg: #fff6df;
  --warn-ink: #7a5600;
  --err-bg: #fdecec;
  --focus: #3b82f6;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --av0: #d9480f; --av1: #1971c2; --av2: #2f9e44; --av3: #9c36b5; --av4: #e67700; --av5: #0c8599;
}

/* Dark colours follow the system unless the user chose a theme in their
   profile, which sets <html data-theme="light|dark">. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101419;
    --surface: #182029;
    --surface-2: #212b36;
    --text: #e7ecf1;
    --muted: #97a3b0;
    --border: #2c3845;
    --brand: #22c08f;
    --brand-ink: #062419;
    --brand-hover: #3fd3a4;
    --pos: #3fd3a4;
    --neg: #ff9a66;
    --danger: #ff6b6b;
    --warn-bg: #3a2f12;
    --warn-ink: #ffd88a;
    --err-bg: #3b1d1d;
    --shadow: none;
    --cat-general: #5d6673; --cat-food: #fa875a; --cat-groceries: #4bf59b; --cat-transport: #2873d7;
    --cat-travel: #0acdfa; --cat-lodging: #9b82ff; --cat-home: #aa8205; --cat-utilities: #e1cd05;
    --cat-entertainment: #f57dcd; --cat-shopping: #b446af; --cat-health: #0abe64; --cat-gifts: #cd3c3c;
    --cat-rest: #d0d5db;
  }
}
:root[data-theme="dark"] {
  --bg: #101419;
  --surface: #182029;
  --surface-2: #212b36;
  --text: #e7ecf1;
  --muted: #97a3b0;
  --border: #2c3845;
  --brand: #22c08f;
  --brand-ink: #062419;
  --brand-hover: #3fd3a4;
  --pos: #3fd3a4;
  --neg: #ff9a66;
  --danger: #ff6b6b;
  --warn-bg: #3a2f12;
  --warn-ink: #ffd88a;
  --err-bg: #3b1d1d;
  --shadow: none;
  --cat-general: #5d6673; --cat-food: #fa875a; --cat-groceries: #4bf59b; --cat-transport: #2873d7;
  --cat-travel: #0acdfa; --cat-lodging: #9b82ff; --cat-home: #aa8205; --cat-utilities: #e1cd05;
  --cat-entertainment: #f57dcd; --cat-shopping: #b446af; --cat-health: #0abe64; --cat-gifts: #cd3c3c;
  --cat-rest: #d0d5db;
}
:root { color-scheme: light dark; }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; padding-bottom: 2rem; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; margin-top: 1rem; }
p { margin: 0 0 .75rem; }
a { color: var(--brand); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; background: var(--surface-2); padding: .1em .35em; border-radius: 4px; overflow-wrap: anywhere; }
img { max-width: 100%; }

.wrap { width: 100%; max-width: 760px; margin: 0 auto; padding: 0 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.danger { color: var(--danger) !important; }
.center { text-align: center; }

/* ---- Top bar ---- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; position: sticky; top: 0; z-index: 10; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.15rem; color: var(--text); text-decoration: none; }
.topnav { display: flex; align-items: center; gap: .75rem; }
.topnav form { margin: 0; }
.me { display: flex; align-items: center; gap: .5rem; color: var(--text); text-decoration: none; }
/* Account dropdown under the profile photo. */
/* Dropdown menus (<details class="dropdown">): the account menu and the
   home page's list options. */
.dropdown { position: relative; }
.dropdown > summary { cursor: pointer; list-style: none; }
.dropdown > summary::-webkit-details-marker { display: none; }
.dropdown > summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.account-menu > summary { border-radius: 999px; padding: 2px; }
.account-menu > summary::after { content: "▾"; color: var(--muted); font-size: .75rem; }
.menu-button { display: inline-flex; align-items: center; justify-content: center; width: 2.25rem; height: 2.25rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 1.1rem; }
.menu-button:hover, .dropdown[open] > .menu-button { background: var(--surface-2); }
.menu-panel { position: absolute; right: 0; top: calc(100% + .5rem); min-width: 13rem; max-width: calc(100vw - 32px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: .35rem; z-index: 20; }
.menu-who { margin: 0; padding: .5rem .75rem .6rem; border-bottom: 1px solid var(--border); margin-bottom: .35rem; display: flex; flex-direction: column; min-width: 0; }
.menu-who > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-who .muted { font-size: .85rem; }
.account-menu .menu-panel a, .account-menu .menu-panel button { display: block; width: 100%; text-align: left; padding: .55rem .75rem; border: 0; border-radius: 6px; background: none; font: inherit; color: var(--text); text-decoration: none; cursor: pointer; }
.account-menu .menu-panel a:hover, .account-menu .menu-panel button:hover, .account-menu .menu-panel a:focus-visible, .account-menu .menu-panel button:focus-visible { background: var(--surface-2); outline: none; }
.menu-panel form { margin: 0; }
@media (max-width: 480px) { .me-name { display: none; } }

.footer { color: var(--muted); font-size: .8rem; padding-top: 1rem; padding-bottom: 1.5rem; }
.footer a { color: inherit; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  min-height: 40px; padding: .45rem 1rem;
  font: inherit; font-weight: 600; line-height: 1.2;
  color: var(--brand-ink); background: var(--brand);
  border: 1px solid transparent; border-radius: 999px;
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--brand-hover); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); filter: brightness(1.1); }
.btn-sm { min-height: 32px; padding: .25rem .75rem; font-size: .875rem; }
.btn-lg { min-height: 48px; padding: .6rem 1.4rem; font-size: 1.05rem; }
.btn-link { background: none; border: 0; padding: .25rem; font: inherit; color: var(--brand); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.btn[disabled], .htmx-request .btn, .btn.htmx-request { opacity: .6; pointer-events: none; }

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

.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .75rem; }
.actions form { margin: 0; }

/* ---- Messages ---- */
.flash { background: var(--surface); border-left: 4px solid var(--brand); padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; box-shadow: var(--shadow); }
.notice { background: var(--warn-bg); color: var(--warn-ink); padding: .75rem 1rem; border-radius: 8px; }
.error-box { background: var(--err-bg); border-left: 4px solid var(--danger); padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.error-box p { margin: 0; }
.field-error { color: var(--danger); font-size: .875rem; margin: .25rem 0 0; }
.warn { color: var(--warn-ink); background: var(--warn-bg); padding: .4rem .75rem; border-radius: 8px; margin: 0; font-size: .9rem; }
.ok { color: var(--pos); font-size: .9rem; margin: .5rem 0 0; }
.hint { color: var(--muted); font-size: .85rem; margin: .25rem 0 0; }
/* "Add expense" floats within thumb reach on phones (the same link sits in
   the page head on wider screens). */
@media (max-width: 639px) {
  .fab {
    position: fixed; right: 16px; z-index: 15;
    bottom: max(16px, calc(env(safe-area-inset-bottom) + 8px)); /* clear of the iPhone home bar */
    padding: .8rem 1.25rem; border-radius: 999px; font-size: 1rem;
    box-shadow: 0 6px 16px rgb(0 0 0 / .25);
  }
  /* The footer stays at the bottom; its text (on the left) just keeps clear of the button. */
  body:has(.fab) .footer { padding-right: 11rem; }
  body:has(.fab) .toast { bottom: calc(max(16px, calc(env(safe-area-inset-bottom) + 8px)) + 4rem); }
}
.toast { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 20; max-width: calc(100% - 32px); background: var(--danger); color: #fff; padding: .75rem 1rem; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.25); }

/* ---- Layout blocks ---- */
.page-head { margin-bottom: 1rem; }
.back { margin-bottom: .75rem; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.summary { font-size: 1.05rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
details.card > summary { cursor: pointer; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary h2 { display: inline; margin: 0; }
details.card > summary::before { content: "+"; display: inline-block; width: 1.25rem; font-weight: 700; color: var(--brand); }
details.card[open] > summary::before { content: "−"; }
details.card[open] > summary { margin-bottom: .75rem; }
details.sub { margin-top: .5rem; }
details.sub summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
/* Sort order and "show inactive" on the home page. Without JavaScript the
   Apply button submits; with it, changes submit straight away. */
.home-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.home-head > #live-overall { flex: 1; min-width: 0; }
.home-head .summary { margin-top: 0; }
.home-head > .btn { flex: none; }
.home-head > .btn + .list-menu { margin-left: 0; }

/* Picking the group for a new expense */
.pick-list { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: .5rem; }
.pick-row { display: flex; align-items: center; gap: .75rem; padding: .75rem 1rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); cursor: pointer; font-weight: normal; }
.pick-row:has(input:checked) { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.pick-row input { flex: none; margin: 0; }
.pick-name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-menu { flex: none; margin-left: auto; }
.list-settings { display: grid; gap: .4rem; padding: .5rem .6rem .6rem; font-size: .9rem; min-width: 14rem; }
.list-settings select { width: 100%; min-height: 0; padding: .35rem .5rem; font-size: inherit; }
.list-settings > label:first-child { font-weight: 600; }
.list-settings .check { margin-top: .35rem; }
.js .autosubmit-btn { display: none; }
.tag { padding: .05rem .45rem; border: 1px solid var(--border); border-radius: 999px; font-size: .75rem; font-weight: 500; color: var(--muted); white-space: nowrap; }
.group-card.inactive .group-name { color: var(--muted); }
.hidden-note { font-size: .9rem; margin-top: -.5rem; }
.live-notice { margin: 0 0 .5rem; text-align: center; font-size: .9rem; }
.hero { text-align: center; padding: 3rem 0; }
.hero h1 { font-size: 2.1rem; }
.lead { font-size: 1.15rem; color: var(--muted); max-width: 32rem; margin: 0 auto 1.5rem; }
.danger-zone h2 { color: var(--danger); }

/* ---- Lists ---- */
.list { list-style: none; margin: 0; padding: 0; }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .6rem 0; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: 0; }
.list-row form { margin: 0; flex-shrink: 0; }
.list-row .actions { margin: 0; flex-shrink: 0; }
.who { display: flex; align-items: center; gap: .6rem; min-width: 0; }

img.avatar { background: var(--surface-2); }
.avatar { width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0; object-fit: cover; display: inline-flex; align-items: center; justify-content: center; font-size: .75rem; font-weight: 700; color: #fff; }
.av0 { background: var(--av0); } .av1 { background: var(--av1); } .av2 { background: var(--av2); }
.av3 { background: var(--av3); } .av4 { background: var(--av4); } .av5 { background: var(--av5); }

/* Groups on the home page */
.groups { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; grid-template-columns: minmax(0, 1fr); gap: .6rem; }
/* Name and members on the left, the viewer's balance on the right. */
/* The empty rows above and below absorb the height of a tall balance, so the
   name and members stay together, centred. */
.group-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: 1fr auto auto 1fr; grid-template-areas: ". bal" "title bal" "members bal" ". bal"; column-gap: 1rem; align-items: center; padding: 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); text-decoration: none; box-shadow: var(--shadow); }
.group-card:hover { border-color: var(--brand); }
/* Clickable cards with selectable text. Each [data-card] contains an
   a.card-link. Without JS the link covers the whole card; with JS (html.js)
   it shrinks to an invisible but focusable link and app.js makes clicks on
   the card follow it, except clicks that end a text selection. */
[data-card] { position: relative; cursor: pointer; }
.card-link { position: absolute; inset: 0; z-index: 1; }
.js .card-link { inset: auto; top: 0; left: 0; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
[data-card]:has(.card-link:focus-visible) { outline: 2px solid var(--focus); outline-offset: -2px; }
.group-name { font-weight: 650; font-size: 1.05rem; }
.group-title { grid-area: title; display: flex; align-items: center; gap: .6rem; min-width: 0; }
.group-name { overflow-wrap: anywhere; }
.group-icon { width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0; object-fit: cover; display: inline-flex; align-items: center; justify-content: center; font-size: .8rem; font-weight: 700; color: #fff; }
img.group-icon { background: var(--surface-2); }
h1.with-icon { display: flex; align-items: center; gap: .6rem; }
h1.with-icon .group-icon { width: 40px; height: 40px; font-size: 1rem; }

/* Large image with upload controls (profile photo, group icon) */
.image-edit { display: flex; gap: 1rem; align-items: flex-start; flex-wrap: wrap; }
.image-lg .avatar, .image-lg .group-icon { width: 96px; height: 96px; font-size: 2rem; }
.upload { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .25rem; }
/* Flex items don't shrink below their content by default, and a file input's
   built-in width is wider than a card on a narrow phone. */
.image-edit > :last-child { flex: 1 1 15rem; min-width: 0; }
[hidden] { display: none !important; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: normal; }
.upload .check { flex-basis: 100%; }
.location { display: flex; align-items: center; flex-wrap: wrap; gap: .25rem .5rem; margin: .75rem 0; }
.upload input[type="file"] { flex: 1 1 12rem; width: auto; min-width: 0; max-width: 100%; min-height: 0; padding: .3rem; }
.receipt-link { display: block; margin-top: 1rem; }
.receipt { display: block; max-width: 100%; max-height: 70vh; border-radius: 8px; border: 1px solid var(--border); }
.photo-controls { margin-top: 1rem; }
.group-bal { grid-area: bal; display: flex; flex-direction: column; gap: .3rem; text-align: right; font-size: .9rem; }
.bal-label { display: block; font-size: .75rem; opacity: .85; }
.bal-amount { display: block; font-size: 1.15rem; font-weight: 650; white-space: nowrap; font-variant-numeric: tabular-nums; }
/* Member names on one line. If they don't fit they're cut off with an
   ellipsis and app.js adds .is-truncated, which shows the member count. */
/* Other members as a row of small, slightly overlapping circles. */
.member-avatars { grid-area: members; display: flex; align-items: center; margin-top: .35rem; min-width: 0; }
.member { display: inline-flex; border-radius: 50%; box-shadow: 0 0 0 2px var(--surface); }
.member + .member { margin-left: -4px; }
.member-avatars .avatar, .member.more { width: 24px; height: 24px; font-size: .6rem; }
.member.more { align-items: center; justify-content: center; background: var(--surface-2); color: var(--muted); font-weight: 700; }

/* Transactions */
.txs { list-style: none; padding: 0; margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.txs > li + li { border-top: 1px solid var(--border); }
.txs .month { padding: .5rem 1rem; background: var(--surface-2); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.txs .more { padding: .75rem; text-align: center; }
.tx { display: grid; grid-template-columns: 2.25rem 2.25rem 1fr auto; align-items: center; gap: .6rem; padding: .7rem 1rem; color: var(--text); text-decoration: none; }
.tx:hover { background: var(--surface-2); }
.tx-date { display: flex; flex-direction: column; align-items: center; line-height: 1.1; color: var(--muted); font-size: .7rem; text-transform: uppercase; }
.tx-date b { font-size: 1.05rem; color: var(--text); }
.tx-icon { font-size: 1.3rem; width: 2.25rem; height: 2.25rem; display: inline-flex; align-items: center; justify-content: center; background: var(--surface-2); border-radius: 8px; }
.tx-icon.big { font-size: 2rem; width: 3.5rem; height: 3.5rem; border-radius: 12px; flex-shrink: 0; }
.tx-main { min-width: 0; display: flex; flex-direction: column; }
.tx-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-sub { font-size: .825rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-me { text-align: right; font-size: .75rem; line-height: 1.2; }
.tx-me b { display: block; font-size: .95rem; }
.tx-payment .tx-name { font-weight: 500; }
/* Upcoming (future-dated) rows: slightly set apart. */
.tx-upcoming { background: color-mix(in srgb, var(--surface-2) 55%, var(--surface)); }
.tx-upcoming .tx-date b { color: var(--muted); }
.tx-upcoming .tx-sub { white-space: normal; } /* "… is scheduled to pay €X" is longer */
.tx-match { font-size: .8rem; color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow-wrap: anywhere; }
.tx-search { display: flex; gap: .5rem; margin: 0 0 .75rem; align-items: stretch; }
.tx-search > input { flex: 1 1 auto; min-width: 0; }
.filter-menu { flex: none; }
.filter-menu > .menu-button { position: relative; width: auto; min-width: 2.75rem; height: 100%; padding: 0 .6rem; }
.badge { position: absolute; top: -.4rem; right: -.4rem; min-width: 1.15rem; height: 1.15rem; padding: 0 .3rem; border-radius: 999px; background: var(--brand); color: var(--brand-ink); font-size: .7rem; font-weight: 700; line-height: 1.15rem; text-align: center; }
.filter-panel { width: min(20rem, calc(100vw - 32px)); padding: .9rem; display: grid; gap: .4rem; }
.filter-panel label:not(.check), .filter-panel legend { font-weight: 600; font-size: .9rem; }
.filter-panel .field-row { gap: .5rem; }
.filter-panel .field { display: grid; gap: .25rem; }
.filter-panel input[type="date"] { width: 100%; min-width: 0; }
.quick-ranges { display: flex; flex-wrap: wrap; gap: .25rem .75rem; margin: 0 0 .25rem; font-size: .85rem; }
.f-type { border: 0; padding: 0; margin: .25rem 0 0; display: flex; flex-wrap: wrap; gap: .25rem .9rem; }
.f-type legend { flex-basis: 100%; padding: 0; margin-bottom: .2rem; }
.filter-panel .actions { margin-top: .5rem; }
.search-note { margin: 0 0 .75rem; color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.search-note p { margin: .5rem 0 0; }
.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: .35rem; padding: .2rem .65rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); text-decoration: none; font-size: .85rem; }
.chip:hover { border-color: var(--muted); }

.tx-hero { display: flex; gap: 1rem; align-items: center; margin-bottom: 1rem; }
.tx-hero h1 { margin: 0; overflow-wrap: anywhere; }
.tx-amount { font-size: 1.6rem; font-weight: 700; margin: 0; }
.tx-hero .small { margin: 0; }
.notes { white-space: pre-wrap; background: var(--surface-2); padding: .75rem; border-radius: 8px; margin-top: 1rem; overflow-wrap: anywhere; }

/* Comments */
.comments { list-style: none; padding: 0; margin: 0 0 1rem; }
.comment { padding: .6rem 0; border-bottom: 1px solid var(--border); }
.comment-head { display: flex; align-items: baseline; gap: .5rem; font-size: .9rem; }
.comment-head form { margin: 0 0 0 auto; }
.comment-head .btn-link { font-size: .8rem; }
.comment-body { white-space: pre-wrap; margin: .25rem 0 0; overflow-wrap: anywhere; }
.comment-form { display: grid; gap: .5rem; }
.comment-form .btn { justify-self: end; }

/* ---- Forms ---- */
.form { display: grid; gap: 1rem; }
.form > .btn { justify-self: start; }
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field-row { display: flex; gap: .75rem; flex-wrap: wrap; }
.field-row .field { flex: 0 0 auto; }
.field-row .field.grow { flex: 1 1 10rem; }
label, legend { font-weight: 600; font-size: .9rem; }
input, select, textarea {
  font: inherit; color: inherit; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px;
  padding: .55rem .7rem; min-height: 44px; width: 100%;
}
textarea { resize: vertical; min-height: 0; }
input[type="checkbox"], input[type="radio"] { width: 1.15rem; height: 1.15rem; min-height: 0; accent-color: var(--brand); }
input:focus, select:focus, textarea:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.inline-form { margin-top: 1rem; }
.inline-form .row { display: flex; gap: .5rem; margin-top: .3rem; }
.inline-form input { flex: 1; }
.payment-parties { align-items: flex-end; }
.payment-parties .arrow { font-size: 1.4rem; padding-bottom: .6rem; color: var(--muted); }

/* Split editor */
fieldset.split, fieldset.when { border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem 1rem; margin: 0; }
fieldset.split legend, fieldset.when legend { padding: 0 .35rem; }
fieldset.when { display: grid; gap: .75rem; }
fieldset.when .hint { margin: 0; }
#s-every { width: 4.5rem; }

/* Schedules: transaction rows without a date column. */
.schedules .tx { grid-template-columns: 2.25rem 1fr auto; }
.schedules .tx-me span { display: block; font-size: .75rem; }
.schedules .tx-sub { white-space: normal; }
.tx-match.warn { display: block; margin-top: .25rem; padding: .2rem .5rem; white-space: normal; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-2); border-radius: 999px; padding: 3px; margin-bottom: .75rem; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label { text-align: center; white-space: nowrap; padding: .4rem .5rem; border-radius: 999px; cursor: pointer; font-weight: 600; font-size: .875rem; color: var(--muted); }
.seg input:checked + label { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg input:focus-visible + label { outline: 2px solid var(--focus); }
.people { list-style: none; margin: 0; padding: 0; }
.people li { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .4rem 0; border-bottom: 1px solid var(--border); }
.people li:last-child { border-bottom: 0; }
.people .who { flex: 1; font-weight: 500; cursor: pointer; min-height: 40px; }
.people .amount-in { width: 7.5rem; flex: 0 0 auto; text-align: right; }
.people .field-error { flex-basis: 100%; text-align: right; }
.only-exact, .only-shares { display: none !important; }
.split:has(#mode-exact:checked) .only-exact,
.split:has(#mode-shares:checked) .only-shares { display: block !important; }
.split:has(#mode-exact:checked) .only-equal,
.split:has(#mode-shares:checked) .only-equal { display: none; }
.split-preview { margin-top: .75rem; min-height: 1.5rem; }
/* The rarely changed fields, after the first submit button. */
.form-more { border-top: 1px solid var(--border); padding-top: 1rem; margin-top: 1rem; display: grid; gap: inherit; }
.preview { list-style: none; margin: 0; padding: .5rem .75rem; background: var(--surface-2); border-radius: 8px; font-size: .9rem; }
.preview li { display: flex; justify-content: space-between; gap: 1rem; padding: .15rem 0; }

.new-token { background: var(--warn-bg); color: var(--warn-ink); border-radius: 8px; padding: .75rem 1rem; margin-bottom: 1rem; }
.token { display: block; padding: .6rem; margin-top: .25rem; cursor: copy; user-select: all; }

/* htmx request indicator for the preview */
.split-preview.htmx-request { opacity: .6; transition: opacity .2s; }

@media (min-width: 640px) {
  h1 { font-size: 1.9rem; }
  .card { padding: 1.25rem 1.5rem; }
}

/* Statistics. Category colours: one per category, the same in every group
   (dark-mode steps are with the other dark tokens). Any two categories can
   sit side by side in a pie, so every pair must stay distinguishable:
   TestCategoryColours checks they're at least 15 apart (OKLab ΔE ×100).
   "rest" is the "Everything else" slice. */
:root {
  --cat-general: #4b5563; --cat-food: #fa6e3c; --cat-groceries: #73e18c; --cat-transport: #1e41b4;
  --cat-travel: #0aaff5; --cat-lodging: #646ee6; --cat-home: #915f00; --cat-utilities: #e1af19;
  --cat-entertainment: #e669c3; --cat-shopping: #a0418c; --cat-health: #28aa5f; --cat-gifts: #87140a;
  --cat-rest: #b4bac3;
}
.pies { display: grid; gap: 1.5rem; }
.pie { margin: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; align-items: center; }
.pie-chart { width: 100%; max-width: 220px; justify-self: center; }
.pie-track { stroke: var(--surface-2); }
.pie-total { margin: 0 0 .5rem; font-size: 1.25rem; font-weight: 650; text-align: center; }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: .35rem; }
.legend li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto 3rem; gap: .5rem; align-items: center; font-size: .9rem; }
.legend-amount { font-variant-numeric: tabular-nums; text-align: right; }
.legend-pct { text-align: right; font-size: .8rem; }
.swatch { width: .8rem; height: .8rem; border-radius: 3px; background: currentColor; }
@media (min-width: 640px) {
  .pie { grid-template-columns: 220px minmax(0, 1fr); }
  .pie-total { text-align: left; }
}
.table-wrap { overflow-x: auto; }
.stats-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.stats-table th, .stats-table td { padding: .4rem .5rem; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.stats-table thead th { color: var(--muted); font-weight: 600; font-size: .8rem; }
.stats-table tbody th { font-weight: 500; }
.stats-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.stats-table tr:last-child th, .stats-table tr:last-child td { border-bottom: 0; }
.slice-general { stroke: var(--cat-general); color: var(--cat-general); }
.slice-food { stroke: var(--cat-food); color: var(--cat-food); }
.slice-groceries { stroke: var(--cat-groceries); color: var(--cat-groceries); }
.slice-transport { stroke: var(--cat-transport); color: var(--cat-transport); }
.slice-travel { stroke: var(--cat-travel); color: var(--cat-travel); }
.slice-lodging { stroke: var(--cat-lodging); color: var(--cat-lodging); }
.slice-home { stroke: var(--cat-home); color: var(--cat-home); }
.slice-utilities { stroke: var(--cat-utilities); color: var(--cat-utilities); }
.slice-entertainment { stroke: var(--cat-entertainment); color: var(--cat-entertainment); }
.slice-shopping { stroke: var(--cat-shopping); color: var(--cat-shopping); }
.slice-health { stroke: var(--cat-health); color: var(--cat-health); }
.slice-gifts { stroke: var(--cat-gifts); color: var(--cat-gifts); }
.slice-rest { stroke: var(--cat-rest); color: var(--cat-rest); }
