:root {
  --bg: #f6f7f5; --surface: #ffffff; --ink: #18211d; --muted: #5d6963; --line: #dfe4e0;
  --brand: #0f6b4f; --brand-ink: #ffffff; --brand-soft: #e3f1ec;
  --good: #137a4b; --good-soft: #e1f3e8; --warn: #9a6200; --warn-soft: #fbf0d9;
  --bad: #b3261e; --bad-soft: #fbe4e2; --focus: #2a7de1;
  --radius: 12px; --shadow: 0 1px 2px rgba(16, 24, 20, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101513; --surface: #171e1b; --ink: #e8eeea; --muted: #9aa8a1; --line: #2a3530;
    --brand: #3fb98b; --brand-ink: #06140e; --brand-soft: #173329;
    --good: #5fd39d; --good-soft: #15301f; --warn: #f0b850; --warn-soft: #33270f;
    --bad: #ff8a80; --bad-soft: #3a1714; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
h1 { font-size: 1.45rem; margin: .2rem 0 .4rem; line-height: 1.25; }
h2 { font-size: 1.1rem; margin: 0 0 .3rem; }
h3 { font-size: 1rem; margin: 1.4rem 0 .5rem; }
p { margin: .3rem 0 .8rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.pad { padding: 2rem 0; }
.good { color: var(--good); }
.bad { color: var(--bad); }
[hidden] { display: none !important; }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .7rem 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; }
.logo { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: var(--brand-ink); font-size: .8rem; letter-spacing: .02em; }
.who { display: flex; align-items: center; gap: .6rem; }
.app { max-width: 1040px; margin: 0 auto; padding: 1rem 16px 4rem; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; margin: 1.2rem 0; box-shadow: var(--shadow); }
.card.narrow { max-width: 420px; margin: 2.5rem auto; }
.stack { display: grid; gap: .8rem; }
.formgrid { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); align-items: end; }
label { display: grid; gap: .3rem; font-size: .88rem; font-weight: 600; }
label.inline { display: inline-flex; align-items: center; gap: .5rem; font-weight: 500; }
input, select { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: .6rem .7rem; min-height: 44px; width: 100%; }
label.inline input { width: auto; }
input[type="checkbox"] { min-height: auto; width: auto; }
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 9px; padding: .55rem .95rem; min-height: 44px; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 34px; padding: .3rem .7rem; font-size: .85rem; }
.btn:disabled { opacity: .6; cursor: wait; }
.link { font: inherit; background: none; border: 0; padding: 0; color: var(--brand); font-weight: 600; cursor: pointer; text-decoration: underline; }

.grid { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.groupcard { text-align: left; display: grid; gap: .3rem; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; cursor: pointer; box-shadow: var(--shadow); }
.groupcard:hover { border-color: var(--brand); }
.gname { font-weight: 700; font-size: 1.05rem; }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.chip { display: inline-flex; align-items: center; gap: .25rem; font-size: .78rem; font-weight: 600; padding: .1rem .55rem; border-radius: 999px; background: var(--brand-soft); color: var(--ink); }
.chip.quiet { background: var(--bg); color: var(--muted); }
.chip .x { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 1rem; line-height: 1; padding: 0 .1rem; }

.grouphead { display: flex; align-items: flex-start; gap: .8rem; margin-bottom: .6rem; }
.tabs { display: flex; gap: .3rem; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 1rem; scrollbar-width: none; }
.tab { font: inherit; font-weight: 600; background: none; border: 0; border-bottom: 3px solid transparent; color: var(--muted); padding: .6rem .8rem; white-space: nowrap; cursor: pointer; min-height: 44px; }
.tab.on { color: var(--ink); border-bottom-color: var(--brand); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1rem; margin-bottom: .9rem; }
.stats { display: grid; gap: .7rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem .9rem; display: grid; gap: .15rem; }
.stat strong { font-size: 1.2rem; font-variant-numeric: tabular-nums; }

.tablewrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; min-width: 520px; }
th, td { padding: .6rem .75rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--bg); }
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.badge { display: inline-block; font-size: .78rem; font-weight: 700; padding: .1rem .55rem; border-radius: 999px; white-space: nowrap; }
.badge.paid { background: var(--good-soft); color: var(--good); }
.badge.partial { background: var(--warn-soft); color: var(--warn); }
.badge.open { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.badge.overdue { background: var(--bad-soft); color: var(--bad); }
.badge.waived { background: var(--bg); color: var(--muted); }

.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 1.2rem; text-align: center; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); max-width: min(92vw, 520px); padding: .75rem 1rem; border-radius: 10px; font-weight: 600; box-shadow: 0 6px 24px rgba(0, 0, 0, .18); z-index: 20; }
.toast.ok { background: var(--ink); color: var(--bg); }
.toast.err { background: var(--bad); color: #fff; }

@media (max-width: 560px) {
  .hide-sm { display: none; }
  h1 { font-size: 1.25rem; }
  .grouphead { flex-direction: column; gap: .3rem; }
}
