:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --text: #1c2321;
  --muted: #5f6b67;
  --line: #e2e6e3;
  --accent: #1f7a5a;
  --accent-ink: #ffffff;
  --accent-soft: #e5f2ec;
  --warn: #a4471f;
  --warn-soft: #fbece4;
  --info-soft: #eef1f8;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141816;
    --surface: #1d2220;
    --text: #e8ece9;
    --muted: #a0aba7;
    --line: #2e3532;
    --accent: #4cc095;
    --accent-ink: #0d1411;
    --accent-soft: #1e3a2f;
    --warn: #f0a07c;
    --warn-soft: #3a261d;
    --info-soft: #232a36;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.45; }
h1 { font-size: 1.6rem; margin: 0 0 4px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
.muted { color: var(--muted); }
.error { color: var(--warn); min-height: 1.2em; }
[hidden] { display: none !important; }

.banner { background: var(--info-soft); padding: 10px 16px; text-align: center; font-size: .9rem; }

.shell { display: grid; grid-template-columns: 200px 1fr; min-height: 100vh; }
.nav { background: var(--surface); border-right: 1px solid var(--line); padding: 20px 12px; display: flex; flex-direction: column; gap: 4px; }
.brand { font-weight: 700; padding: 6px 12px 18px; overflow-wrap: anywhere; }
.nav a { color: var(--text); text-decoration: none; padding: 10px 12px; border-radius: 8px; font-weight: 500; }
.nav a:hover { background: var(--bg); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav-signout { margin-top: auto; text-align: left; padding: 10px 12px; }

.view { padding: 32px; max-width: 1000px; width: 100%; outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.tile .label { color: var(--muted); font-size: .9rem; }
.tile .value { font-size: 1.7rem; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .hint { font-size: .85rem; color: var(--muted); margin-top: 2px; }
.tile.warn .value { color: var(--warn); }

.btn { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 10px; padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.link { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 0; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: grid; grid-template-columns: 1fr auto auto; gap: 16px; align-items: center; padding: 14px 4px; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .who { font-weight: 600; }
.list .sub { color: var(--muted); font-size: .88rem; }
.amount { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }
.empty { color: var(--muted); padding: 20px 4px; }

.chip { font-size: .8rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--bg); color: var(--muted); white-space: nowrap; }
.chip.overdue { background: var(--warn-soft); color: var(--warn); }
.chip.paid { background: var(--accent-soft); color: var(--accent); }
.chip.due { background: var(--info-soft); color: var(--text); }

.tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: 6px 14px; border-radius: 999px; font: inherit; cursor: pointer; }
.tabs button[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }

label { display: block; font-weight: 600; margin-bottom: 14px; }
input, select { display: block; width: 100%; margin-top: 6px; padding: 10px 12px; font: inherit; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }

.lines { width: 100%; border-collapse: collapse; margin: 8px 0 16px; }
.lines th { text-align: left; font-size: .85rem; color: var(--muted); font-weight: 600; padding: 4px; }
.lines td { padding: 4px; vertical-align: top; }
.lines input, .lines select { margin: 0; }
.totals { margin-left: auto; width: min(280px, 100%); }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; font-variant-numeric: tabular-nums; }
.totals .grand { font-weight: 700; font-size: 1.15rem; border-top: 1px solid var(--line); padding-top: 8px; }

dialog { border: 0; border-radius: var(--radius); padding: 24px; width: min(760px, calc(100vw - 32px)); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgb(0 0 0 / .35); }

.signin { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.signin-card { width: min(420px, 100%); }

@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; }
  .nav { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px; position: sticky; top: 0; z-index: 1; }
  .brand { display: none; }
  .nav-signout { margin: 0 0 0 auto; }
  .view { padding: 20px 16px; }
  .list li { grid-template-columns: 1fr auto; }
  .list li .chip { grid-column: 1; justify-self: start; }
  .lines thead { display: none; }
  .lines tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--line); }
  .lines td:first-child { grid-column: 1 / -1; }
}

.clickable { cursor: pointer; border-radius: 8px; }
.clickable:hover { background: var(--bg); }
.clickable:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
.btn.danger { color: var(--warn); }
.btn:disabled { opacity: .6; cursor: progress; }
.notice { background: var(--info-soft); border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; }
.card.notice { border: 0; }
label.check { display: flex; gap: 10px; align-items: center; font-weight: 500; }
label.check input { width: auto; margin: 0; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 10px; max-width: calc(100vw - 32px); z-index: 10; }
.chip.void, .chip.draft { background: var(--bg); color: var(--muted); }
.back-home { margin-top: 18px; font-size: .9rem; } .back-home a { color: inherit; }
.banner.plan { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.plan-choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin: 8px 0 12px; }
.plan-choices .btn { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; padding: 14px 16px; }
.plan-choices .btn span { font-size: 1.1rem; font-weight: 700; }
.plan-choices .btn small { font-weight: 500; opacity: .8; }
.invite-form { margin-top: 12px; }
.small-print { font-size: .85rem; }
textarea { display: block; width: 100%; margin-top: 6px; padding: 10px 12px; font: inherit; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); resize: vertical; }
textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.drop { border: 2px dashed var(--line); border-radius: 12px; padding: 18px; }
.drop input { border: 0; padding: 8px 0 0; }
