/* Hand-written, custom-property driven. No framework: the UI is a dozen screens. */
:root {
  color-scheme: light dark;
  --bg: #f6f6f4;
  --surface: #ffffff;
  --ink: #1b1d21;
  --muted: #5f6570;
  --line: #e2e2de;
  --accent: #2f6f4e;
  --owed: #b3402f;     /* colour is a secondary signal; the text must stand alone */
  --owing: #2f6f4e;
  --radius: 12px;
  --gap: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131417;
    --surface: #1b1d21;
    --ink: #f0f0ee;
    --muted: #9aa1ac;
    --line: #2b2e34;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  /* Respect the notch and the home indicator on iOS. */
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: calc(env(safe-area-inset-top) + 12px) var(--gap) 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 650; text-decoration: none; color: var(--ink); }

main { padding: var(--gap); max-width: 720px; margin: 0 auto; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--gap);
}

h1 { font-size: 1.4rem; margin: 0 0 8px; }
.muted { color: var(--muted); }

/* --- Components ------------------------------------------------------------ */

h2 { font-size: 1.05rem; margin: 0 0 8px; }
.small { font-size: 0.85rem; }
.centred { text-align: center; }
.card + .card, .card + div > .card, div + div > .card { margin-top: var(--gap); }
.highlight { border-color: var(--accent); }

.nav { display: flex; gap: var(--gap); }
.nav a { color: var(--muted); text-decoration: none; font-size: 0.9rem; }

/* 44px minimum: these are tapped with a thumb, often one-handed. */
.btn {
  display: inline-block;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
}
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-block { display: block; width: 100%; margin-top: 12px; }
.btn-small { min-height: 36px; padding: 6px 12px; font-size: 0.85rem; font-weight: 500; }
.btn-danger { color: var(--owed); border-color: var(--line); }

.stack { display: flex; flex-direction: column; gap: 8px; }
.stack label { font-size: 0.85rem; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; }
input[type="text"] {
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  /* 16px keeps iOS Safari from zooming the viewport on focus. */
  font-size: 16px;
}

.list { list-style: none; margin: 0; padding: 0; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }

.status { min-height: 1.2em; margin: 8px 0 0; font-size: 0.9rem; color: var(--muted); }
.status.error { color: var(--owed); }

.token {
  word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.crumb { margin: 0 0 12px; font-size: 0.9rem; }
.crumb a { color: var(--muted); text-decoration: none; }
.row-title { font-weight: 650; color: var(--ink); text-decoration: none; }
.row h2 { margin: 0; }

/* --- Expenses -------------------------------------------------------------- */

.expense { padding: 10px 0; border-bottom: 1px solid var(--line); }
.expense:last-child { border-bottom: 0; }
.expense .row { padding: 0; border-bottom: 0; align-items: flex-start; }
.amount { text-align: right; font-weight: 650; white-space: nowrap; }
.list.sub { margin: 8px 0; padding-left: 12px; border-left: 2px solid var(--line); }
.list.sub .row { padding: 6px 0; border-bottom: 0; font-size: 0.9rem; }
details summary { cursor: pointer; padding: 4px 0; }
.total { font-weight: 650; border-top: 1px solid var(--line); padding-top: 8px; margin: 8px 0 0; }

/* Add-expense is the most common action, so it gets a thumb-reachable button
   that stays put while the list scrolls (§9). */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.25);
  cursor: pointer;
  z-index: 20;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 30;
}

.sheet {
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: var(--gap);
  padding-bottom: calc(var(--gap) + env(safe-area-inset-bottom));
}
.sheet label { font-size: 0.85rem; color: var(--muted); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; }

.pair { display: flex; gap: 12px; align-items: center; }
.pair > div { flex: 1; }
.pair > span { flex: 1; }
.narrow { max-width: 110px; }

.tabs { display: flex; gap: 6px; }
.tab {
  flex: 1;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}
.tab-on { background: var(--accent); border-color: var(--accent); color: #fff; }

.preview { background: var(--bg); border-radius: 10px; padding: 12px; }
.preview h3 { margin: 0 0 6px; font-size: 0.9rem; color: var(--muted); }

input[type="date"], select {
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  width: 100%;
}

/* Colour carries no meaning on its own here; every balance line reads correctly
   in monochrome (§9). */
.owed-to { color: var(--owing); }
.owes { color: var(--owed); }

.grow { flex: 1; min-width: 0; }
.grow input[type="text"] { width: 100%; }

.detail {
  margin: 6px 0 0;
  padding: 10px;
  background: var(--bg);
  border-radius: 8px;
  font-size: 0.78rem;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* The group's three screens. Sized for a thumb, and spaced away from the
   header above them. */
.tabs-top { margin: var(--gap) 0; }
.tabs-top .tab { min-height: 44px; font-weight: 550; }

.add-member { margin-top: var(--gap); padding-top: var(--gap); border-top: 1px solid var(--line); }
.add-member form + form { margin-top: var(--gap); }
.add-member .pair > select, .add-member .pair > input { flex: 1; }

.version {
  text-align: center;
  margin: var(--gap) 0 calc(var(--gap) * 2);
  /* Commit hashes are easier to read back correctly in a fixed-width face. */
  font-variant-numeric: tabular-nums;
}
.version span { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* A page title with one small action beside it. */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: var(--gap); }
.page-head h1 { margin: 0; }
.page-head + * { margin-top: var(--gap); }

/* A person on the admin page: the row, plus an optional note beneath it. */
.person { padding: 10px 0; border-bottom: 1px solid var(--line); }
.person:last-child { border-bottom: 0; }
.person .row { padding: 0; border-bottom: 0; }
.kept { margin-top: 6px; }
.kept ul { margin: 4px 0 0; padding-left: 18px; }

.export { margin: 10px 4px 0; }
