:root {
  --bg: #f6f6f2;
  --surface: #ffffff;
  --text: #1c2420;
  --muted: #5f6b64;
  --border: #dde2db;
  --accent: #2c6344;
  --accent-soft: #e6efe9;
  --pos: #2c6344;
  --due: #a3461b;
  --due-soft: #fbeee5;
  --warn-soft: #fff5d6;
  --header: #22402f;
  --header-text: #f3f6f1;
  --on-accent: #ffffff;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111513;
    --surface: #1a1f1c;
    --text: #e3eae5;
    --muted: #9aa79f;
    --border: #2d3631;
    --accent: #82c59b;
    --accent-soft: #1e2c24;
    --pos: #82c59b;
    --due: #f0a26c;
    --due-soft: #33231a;
    --warn-soft: #302a15;
    --header: #16241c;
    --header-text: #e3eae5;
    --on-accent: #0f1a14;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.wrap { max-width: 60rem; margin: 0 auto; padding: 0 16px; }

a { color: var(--accent); }

header.site { background: var(--header); color: var(--header-text); }
header.site .wrap { display: flex; align-items: baseline; gap: .6rem; padding-top: .9rem; padding-bottom: .9rem; }
.brand { color: inherit; font-weight: 700; font-size: 1.1rem; text-decoration: none; letter-spacing: .01em; }
.brand-sub { opacity: .75; font-size: .95rem; }

main.wrap { padding-top: 1.5rem; padding-bottom: 2rem; }

h1 { font-size: 1.7rem; line-height: 1.2; margin: 0 0 .25rem; }
h2 { font-size: 1.2rem; margin: 2.2rem 0 .6rem; }
h3 { font-size: 1.05rem; margin: 0; }
h4.person { display: flex; justify-content: space-between; gap: 1rem; font-size: .95rem; margin: 1rem 0 .25rem; }
h4.person span { font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums; }

.freshness, .muted, .help { color: var(--muted); }
.freshness { margin: 0 0 1.25rem; font-size: .95rem; }
.help { margin: -.2rem 0 .9rem; font-size: .95rem; max-width: 44rem; }
.empty { color: var(--muted); font-style: italic; }

.notice {
  background: var(--warn-soft); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .6rem .9rem; margin: 0 0 1.2rem; font-size: .95rem;
}

/* summary tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: .75rem; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .9rem 1rem;
}
.tile-label { font-size: .9rem; color: var(--muted); font-weight: 600; }
.tile-value { font-size: 1.65rem; font-weight: 700; font-variant-numeric: tabular-nums; margin: .15rem 0; }
.tile-note { font-size: .88rem; color: var(--muted); }

.pos { color: var(--pos); }
.due { color: var(--due); }

/* paying */
.pay {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem 1.25rem;
  background: var(--accent-soft); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .9rem 1rem; margin: .85rem 0 0;
}
.pay-text { display: flex; flex-direction: column; }
.pay-text strong { font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.pay-text span { color: var(--muted); font-size: .92rem; }
.pay-help { margin: .5rem 0 0; }
a.button {
  display: inline-block; text-decoration: none; font-weight: 600; font-size: .95rem;
  padding: .55rem 1rem; border-radius: 8px; white-space: nowrap;
}
a.button.primary { background: var(--accent); color: var(--on-accent); }
a.button.primary:hover { filter: brightness(1.08); }
a.pay-link {
  display: inline-block; margin-left: .5rem; padding: .05rem .6rem; border-radius: 999px;
  border: 1px solid var(--accent); color: var(--accent); font-size: .82rem; font-weight: 600;
  text-decoration: none; vertical-align: 1px;
}
a.pay-link:hover { background: var(--accent-soft); }

/* cards */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1rem .6rem; margin: 0 0 .85rem;
}
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: .25rem 1rem; margin-bottom: .4rem; }
.card-amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.card-amount.muted { font-weight: 500; }
.kind { font-weight: 500; color: var(--muted); font-size: .9rem; margin-left: .35rem; }

details.card { padding-bottom: 1rem; }
details.card > summary { cursor: pointer; list-style: none; margin: 0; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary h3::before { content: "▸"; display: inline-block; width: 1.1em; color: var(--muted); transition: transform .15s; }
details.card[open] > summary h3::before { transform: rotate(90deg); }
details.card[open] > summary { margin-bottom: .5rem; }

/* history tables */
table.history { width: 100%; border-collapse: collapse; font-size: .94rem; }
table.history th {
  text-align: left; font-size: .8rem; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em; padding: .3rem .5rem; border-bottom: 1px solid var(--border);
}
table.history td { padding: .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
table.history tr:last-child td { border-bottom: 0; }
table.history th:first-child, table.history td:first-child { padding-left: 0; }
table.history th:last-child, table.history td:last-child { padding-right: 0; }
td.date { white-space: nowrap; color: var(--muted); width: 8.5rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.history th.num { text-align: right; }
td.amt, td.bal { width: 8rem; }
td.amt.credit { color: var(--pos); }
td.amt.charge { color: var(--due); }
td.bal { color: var(--muted); }
tr.scheduled td { opacity: .7; font-style: italic; }

.tag {
  display: inline-block; font-size: .72rem; font-weight: 600; font-style: normal; text-transform: uppercase;
  letter-spacing: .04em; padding: .05rem .4rem; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); vertical-align: 1px;
}
.tag.warn { background: var(--due-soft); color: var(--due); }
.tag.ok { background: var(--accent-soft); color: var(--accent); }

details.more { margin-top: .25rem; }
details.more > summary { cursor: pointer; color: var(--accent); font-size: .92rem; padding: .35rem 0; }
details.more table.history { border-top: 1px solid var(--border); }

/* admin */
table.grid { width: 100%; border-collapse: collapse; font-size: .92rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table.grid th, table.grid td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
table.grid th.num, table.grid td.num { text-align: right; }
.status dl { display: grid; grid-template-columns: max-content 1fr; gap: .2rem 1rem; margin: 0 0 .75rem; }
.status dt { color: var(--muted); }
.status dd { margin: 0; overflow-wrap: anywhere; }
.alert { background: var(--due-soft); }
.alert h2 { margin-top: 0; }
code { font-size: .88em; }

button {
  font: inherit; font-size: .92rem; padding: .4rem .8rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
}
button:hover { border-color: var(--accent); }

footer.site { border-top: 1px solid var(--border); color: var(--muted); font-size: .9rem; }
footer.site .wrap { padding-top: 1rem; padding-bottom: 2rem; }
.forget { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .8rem; }

.landing { max-width: 34rem; padding: 2rem 0; }

@media (max-width: 640px) {
  h1 { font-size: 1.45rem; }
  .pay a.button { width: 100%; text-align: center; }
  .tile-value { font-size: 1.4rem; }
  table.history thead { display: none; }
  table.history tr {
    display: grid; grid-template-columns: 1fr auto; grid-template-areas: "desc amt" "date bal";
    gap: .1rem .75rem; padding: .55rem 0; border-bottom: 1px solid var(--border);
  }
  table.history tr:last-child { border-bottom: 0; }
  table.history td { border: 0; padding: 0; width: auto; }
  td.desc { grid-area: desc; }
  td.amt { grid-area: amt; }
  td.date { grid-area: date; font-size: .85rem; }
  td.bal { grid-area: bal; font-size: .85rem; }
  td.bal::before { content: "bal "; }
  table.ar td.bal::before { content: "due "; }
  table.grid { display: block; overflow-x: auto; }
}
