:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1c2330;
  --muted: #5d6778;
  --border: #d9dde4;
  --accent: #1d5fd1;
  --accent-text: #ffffff;
  --good-bg: #dcf3e3;
  --good-text: #17603a;
  --warn-bg: #fdecc8;
  --warn-text: #7a4b00;
  --bad-bg: #fbdcdc;
  --bad-text: #8f1d1d;
  --info-bg: #dde9fb;
  --info-text: #1a438f;
  --neutral-bg: #e8eaee;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --surface: #1e232b;
    --text: #e6e9ee;
    --muted: #9aa4b5;
    --border: #353c48;
    --accent: #6ea3f7;
    --accent-text: #0d1522;
    --good-bg: #173a27;
    --good-text: #8fe0ad;
    --warn-bg: #453208;
    --warn-text: #f5cd7a;
    --bad-bg: #4a1c1c;
    --bad-text: #f5a3a3;
    --info-bg: #1b2f55;
    --info-text: #a9c6f8;
    --neutral-bg: #2b313b;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 0.75rem; }
h2 { font-size: 1.1rem; margin: 0 0 0.6rem; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Layout */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 1rem;
  padding: 0.5rem 1rem;
}
.topbar .brand { font-weight: 700; margin-right: 0.5rem; }
.topbar nav { display: flex; flex-wrap: wrap; gap: 0.25rem; flex: 1; }
.topbar nav a {
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  text-decoration: none;
  color: var(--text);
}
.topbar nav a.current { background: var(--neutral-bg); font-weight: 600; }
.topbar .who { display: flex; align-items: center; gap: 0.6rem; font-size: 0.875rem; }
.topbar .who form { margin: 0; }
main { max-width: 1100px; margin: 0 auto; padding: 1rem; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1rem;
}
.row { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: end; }
.row > .grow { flex: 1 1 14rem; }
.spread { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; justify-content: space-between; }
.narrow { max-width: 34rem; }

/* Forms */
label { display: block; font-size: 0.875rem; font-weight: 600; margin-bottom: 0.2rem; }
input[type="text"], input[type="search"], input[type="number"], input[type="password"], select {
  width: 100%;
  padding: 0.5rem 0.6rem;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}
input:focus-visible, button:focus-visible, a:focus-visible, .result:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.field { margin-bottom: 0.8rem; }
.field .help { color: var(--muted); font-size: 0.8125rem; margin-top: 0.2rem; }
.field.check label { display: inline; font-weight: 400; font-size: 1rem; }
.errorlist { list-style: none; margin: 0.2rem 0 0; padding: 0; color: var(--bad-text); font-size: 0.875rem; }
button, .button {
  display: inline-block;
  padding: 0.5rem 0.9rem;
  font: inherit;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
button.secondary, .button.secondary { color: var(--text); background: var(--surface); border-color: var(--border); }
button.danger { color: var(--bad-text); background: var(--surface); border-color: var(--border); }
button.small, .button.small { padding: 0.2rem 0.55rem; font-size: 0.875rem; }
button.link { background: none; border: none; color: var(--accent); padding: 0; font-weight: 400; text-decoration: underline; }
form.inline { display: inline; margin: 0; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.5rem 0.6rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.8125rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
th.num { text-align: right; }
tbody tr:last-child td { border-bottom: none; }
tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: none; }
tr.inactive td { color: var(--muted); }
td.name a { font-weight: 600; text-decoration: none; }

/* Status */
.pill { display: inline-block; padding: 0.1rem 0.55rem; border-radius: 999px; font-size: 0.8125rem; font-weight: 600; background: var(--neutral-bg); }
.pill.paid { background: var(--good-bg); color: var(--good-text); }
.pill.unpaid, .pill.partial { background: var(--warn-bg); color: var(--warn-text); }
.pill.refund { background: var(--info-bg); color: var(--info-text); }
.pill.out { background: var(--bad-bg); color: var(--bad-text); }
.messages { list-style: none; margin: 0 0 1rem; padding: 0; }
.messages li { padding: 0.6rem 0.8rem; border-radius: 8px; margin-bottom: 0.4rem; background: var(--info-bg); color: var(--info-text); }
.messages li.success { background: var(--good-bg); color: var(--good-text); }
.messages li.error { background: var(--bad-bg); color: var(--bad-text); font-weight: 600; }

/* Summary tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0.75rem 1rem; }
.tile .label { font-size: 0.8125rem; color: var(--muted); }
.tile .value { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Item picker */
.results { margin: 0.5rem 0 0; padding: 0; list-style: none; max-height: 19rem; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
.results:empty { display: none; }
.result { display: flex; gap: 0.75rem; justify-content: space-between; width: 100%; padding: 0.5rem 0.7rem; border: none; border-bottom: 1px solid var(--border); border-radius: 0; background: var(--surface); color: var(--text); font-weight: 400; text-align: left; white-space: normal; }
li:last-child > .result { border-bottom: none; }
.result:hover:not(:disabled) { background: var(--neutral-bg); }
.result:disabled { color: var(--muted); cursor: not-allowed; }
.result .meta { text-align: right; white-space: nowrap; }
.chosen { margin-top: 0.75rem; padding: 0.75rem; border: 1px solid var(--accent); border-radius: 8px; }
.chosen .row > div { flex: 0 1 8rem; }
.chosen .row > .grow { flex: 1 1 12rem; }
[hidden] { display: none !important; }

.total-line { font-size: 1.25rem; font-weight: 700; }

@media print {
  .topbar, .no-print, .messages { display: none !important; }
  body { background: #fff; color: #000; }
  .card { border: none; padding: 0; }
  main { max-width: none; padding: 0; }
}
