:root {
  --bg: #fafaf7; --fg: #1d2421; --muted: #5d6a64; --line: #d9ddd8; --card: #fff;
  --accent: #2f6f5e; --accent-fg: #fff; --pos: #1f7a3d; --neg: #b3261e; --notice: #fff4d6;
  --radius: 10px; --gap: 1rem;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.45; color: var(--fg); background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614; --fg: #e5ebe7; --muted: #9aa8a1; --line: #2c3430; --card: #1a201d;
    --accent: #5fb39b; --accent-fg: #0d1210; --pos: #6fd08f; --neg: #ff8a80; --notice: #3a3320;
  }
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; width: 100%; max-width: 46rem; margin: 0 auto; padding: var(--gap); }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: .5rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .5rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
section { margin-bottom: 1.5rem; }

.top { display: flex; align-items: center; gap: var(--gap); padding: .6rem var(--gap);
  background: var(--accent); color: var(--accent-fg); flex-wrap: wrap; }
.top a, .top .link { color: var(--accent-fg); text-decoration: none; }
.top nav { display: flex; gap: var(--gap); margin-left: auto; align-items: center; }
.brand { font-weight: 700; font-size: 1.2rem; }
footer { text-align: center; padding: var(--gap); font-size: .85rem; color: var(--muted); }

.group-head h1 { margin-bottom: .5rem; }
.tabs { display: flex; gap: .25rem; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: var(--gap); }
.tabs a { padding: .5rem .75rem; text-decoration: none; color: var(--muted); white-space: nowrap; border-bottom: 2px solid transparent; }
.tabs a[aria-current="page"] { color: var(--fg); border-bottom-color: var(--accent); font-weight: 600; }

button, .button { font: inherit; padding: .55rem 1rem; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--card); color: var(--fg); cursor: pointer; text-decoration: none; display: inline-block; }
button.primary, .button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button.danger, .button.danger { color: var(--neg); border-color: var(--neg); }
button.link { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; }
button:disabled { opacity: .5; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
form.inline { display: inline; }

input, select, textarea { font: inherit; padding: .5rem; border: 1px solid var(--line); border-radius: 6px;
  background: var(--card); color: var(--fg); width: 100%; }
input[type="checkbox"], input[type="radio"] { width: auto; }
label { display: block; }
.stack { display: grid; gap: .75rem; }
.stack > label { display: grid; gap: .25rem; }
label.check { display: flex; gap: .5rem; align-items: center; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.row2 > label { display: grid; gap: .25rem; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem; }
legend { padding: 0 .25rem; font-weight: 600; }
.hint { color: var(--muted); font-size: .9rem; }
.error { color: var(--neg); font-weight: 600; }
.flash { background: var(--card); border-left: 4px solid var(--accent); padding: .5rem .75rem; }
.notice { background: var(--notice); padding: .5rem .75rem; border-radius: 6px; }
.tag { font-size: .75rem; padding: .1rem .4rem; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); font-weight: 400; }
.empty { color: var(--muted); }

.cards, .list, .balances, .transfers, .receipts { list-style: none; padding: 0; margin: 0; }
.card { display: flex; justify-content: space-between; gap: var(--gap); padding: .9rem; margin-bottom: .5rem;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--fg); }
.list > li { border-bottom: 1px solid var(--line); }
.row { display: grid; grid-template-columns: 5.5rem 1fr auto; gap: .5rem; padding: .6rem 0; text-decoration: none; color: var(--fg); align-items: baseline; }
.row .date { color: var(--muted); font-size: .85rem; }
.row .main small, .row .amount small { display: block; color: var(--muted); }
.row .amount { text-align: right; }
.balances li { display: flex; justify-content: space-between; padding: .4rem 0; border-bottom: 1px solid var(--line); }
.bal.pos, small.pos { color: var(--pos); }
.bal.neg, small.neg { color: var(--neg); }
.bal.zero { color: var(--muted); }
.transfers li { padding: .75rem 0; border-bottom: 1px solid var(--line); }
.qr img { background: #fff; padding: 8px; border-radius: 6px; }
.pager { display: flex; justify-content: space-between; margin-top: .75rem; }
.receipts { display: flex; flex-wrap: wrap; gap: .75rem; margin-bottom: .75rem; }
.receipts img { object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.comment { border-bottom: 1px solid var(--line); padding: .5rem 0; }
.comment p { margin: .2rem 0; white-space: pre-wrap; }
.meta { color: var(--muted); font-size: .9rem; }
.amount-big { font-size: 1.6rem; font-weight: 700; margin: .25rem 0; }
.amount-big small { font-size: .9rem; font-weight: 400; color: var(--muted); }
.copy { display: flex; gap: .5rem; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .35rem .25rem; border-bottom: 1px solid var(--line); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
meter { width: 100%; }

.expense-form .rate { display: flex; gap: .4rem; align-items: center; }
.expense-form .rate input { width: 9rem; }
.modes { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .5rem; }
.pill { display: flex; gap: .3rem; align-items: center; padding: .3rem .6rem; border: 1px solid var(--line); border-radius: 999px; }
.split input:not([type="checkbox"]) { width: 7rem; }
.split td.for-value { white-space: nowrap; }
.member { display: flex; justify-content: space-between; gap: .5rem; align-items: center; margin: .3rem 0; }
.member input { width: 9rem; }
.preview { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .5rem .75rem; }

/* Field visibility follows the chosen split mode, payer mode and currency; without JS everything shows. */
.js .expense-form[data-mode="equal"] .not-equal,
.js .expense-form:not([data-mode="equal"]) .only-equal,
.js .expense-form:not([data-mode="percent"]) .only-percent,
.js .expense-form[data-mode="exact"] .for-adj,
.js .expense-form[data-multi="1"] .single-payer,
.js .expense-form[data-multi="0"] .multi-payer,
.js .expense-form[data-same-currency] .fx { display: none; }

#toast { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); background: var(--neg); color: #fff;
  padding: .6rem 1rem; border-radius: var(--radius); max-width: 90vw; }
.prose { max-width: 40rem; }

@media (max-width: 30rem) {
  .row { grid-template-columns: 1fr auto; }
  .row .date { grid-column: 1 / -1; }
  .row2 { grid-template-columns: 1fr; }
}
@media print {
  .top nav, .tabs, .actions, form, footer, #toast, .pager { display: none !important; }
  body { background: #fff; color: #000; }
  main { max-width: none; }
}
