:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1c2129;
  --muted: #646d7a;
  --border: #dde1e7;
  --accent: #2f5fa8;
  --accent-text: #ffffff;
  --good: #1a7a4f;
  --bad: #c0392b;
  --notice-bg: #fff6dd;
  --notice-text: #6b5200;
  --field: #ffffff;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151a;
    --card: #1b2028;
    --text: #e8ecf2;
    --muted: #99a3b1;
    --border: #2d3440;
    --accent: #6fa0e8;
    --accent-text: #0a1220;
    --good: #4fce94;
    --bad: #ff7b6b;
    --notice-bg: #3a3214;
    --notice-text: #f3dc8a;
    --field: #141920;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%; }
.wrap { max-width: 520px; margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom)); }
a { color: var(--accent); }
h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1rem; margin: 0 0 0.6rem; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

.topnav { display: flex; gap: 4px; margin-bottom: 12px; padding: 4px;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px; }
.topnav a { flex: 1; text-align: center; padding: 8px 4px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-size: 0.9rem; font-weight: 600; }
.topnav a.active { background: var(--accent); color: var(--accent-text); }

.monthbar { display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin: 4px 0 12px; }
.monthbar h1 { flex: 1; text-align: center; }
.arrow { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem; line-height: 1; text-decoration: none; color: var(--text);
  background: var(--card); border: 1px solid var(--border); border-radius: 12px; }
.arrow.disabled { opacity: 0.3; }
.badge { display: inline-block; vertical-align: middle; margin-left: 4px; padding: 2px 8px;
  border-radius: 999px; background: var(--border); color: var(--muted);
  font-size: 0.7rem; font-weight: 600; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px; margin-bottom: 12px; }
.card.narrow { margin-top: 10vh; }
.card.narrow h1 { margin-bottom: 0.8rem; }

label { display: block; margin: 0.7rem 0 0.25rem; font-size: 0.85rem; color: var(--muted); }
.optional { font-weight: normal; opacity: 0.8; }
input[type=text], input[type=email], input[type=password], input[type=date] {
  width: 100%; min-height: 44px; padding: 0.5rem 0.65rem; border: 1px solid var(--border);
  border-radius: 10px; background: var(--field); color: var(--text);
  font: inherit; font-size: 16px; /* 16px stops iOS zooming on focus */
  -webkit-appearance: none; appearance: none; }
input:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; }

button, .button { display: inline-block; min-height: 44px; margin-top: 0.9rem; padding: 0.55rem 1.1rem;
  border: 1px solid var(--border); border-radius: 10px; background: var(--card); color: var(--text);
  font: inherit; font-size: 1rem; font-weight: 600; text-align: center; text-decoration: none;
  cursor: pointer; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent);
  color: var(--accent-text); }
button.danger { color: var(--bad); }
button.link { min-height: 0; margin-top: 0.8rem; padding: 0; border: none; background: none;
  font-size: 0.85rem; font-weight: normal; text-decoration: underline; }
button.icon { min-height: 0; width: 36px; height: 36px; margin: 0; padding: 0; border: none;
  background: none; color: var(--muted); font-size: 1.4rem; line-height: 1; }
.block { display: block; width: 100%; }
.card > .button.block:first-child { margin-top: 0; }

.expense-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.expense-form .wide { grid-column: 1 / -1; }
.expense-form .field { min-width: 0; }
.segmented { display: flex; gap: 4px; padding: 4px; margin-bottom: 4px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--field); }
.segmented label { flex: 1; margin: 0; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: 8px 4px; border-radius: 7px; text-align: center;
  font-size: 0.9rem; font-weight: 600; color: var(--muted); cursor: pointer; }
.segmented input:checked + span { background: var(--accent); color: var(--accent-text); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.row-form { display: flex; gap: 8px; align-items: stretch; }
.row-form input { flex: 1; min-width: 0; }
.row-form button { margin-top: 0; white-space: nowrap; }

.summary { text-align: center; }
.summary .label { margin: 0; font-size: 0.85rem; color: var(--muted); }
.remaining { margin: 2px 0 10px; font-size: 2.6rem; font-weight: 700;
  font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.meter { height: 8px; border-radius: 999px; background: var(--border); overflow: hidden; }
.meter .fill { height: 100%; background: var(--accent); border-radius: 999px; }
.meter .fill.over { background: var(--bad); }
.detail { margin: 8px 0 0; font-size: 0.9rem; color: var(--muted); }

.inline-form { margin-top: 12px; text-align: left; }
.inline-form summary { color: var(--accent); font-size: 0.9rem; cursor: pointer; padding: 4px 0; }
.inline-form .row-form { margin-top: 8px; }
.hint { margin: 0.6rem 0 0; font-size: 0.85rem; color: var(--muted); line-height: 1.45; }
.count { display: inline-block; margin-left: 4px; padding: 1px 8px; border-radius: 999px;
  background: var(--border); color: var(--muted); font-size: 0.75rem; font-weight: 600; }

.lines { list-style: none; margin: 0; padding: 0; }
.lines li { display: flex; align-items: center; gap: 8px; padding: 10px 0;
  border-top: 1px solid var(--border); }
.lines li:first-child { border-top: none; padding-top: 2px; }
.line-main { flex: 1; min-width: 0; }
.vendor { display: block; font-weight: 600; overflow-wrap: anywhere; }
.meta { display: block; font-size: 0.8rem; color: var(--muted); overflow-wrap: anywhere; }
.amount { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.fund-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.fund-head h2 { margin: 0; overflow-wrap: anywhere; }
.fund-head .amount { font-size: 1.2rem; }

.choices { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; }
.choices.inline { flex-direction: row; gap: 16px; }
.choice { display: flex; align-items: center; gap: 10px; min-height: 40px; margin: 0;
  font-size: 1rem; color: var(--text); }
.choice input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); flex: none; }
.choice .meta { display: inline; }

.flash { margin: 0 0 12px; padding: 10px 12px; border-radius: 10px; font-size: 0.9rem;
  line-height: 1.4; border: 1px solid var(--border); background: var(--card); }
.flash.ok { color: var(--good); }
.flash.error { color: var(--bad); }
.flash.notice { background: var(--notice-bg); color: var(--notice-text); border-color: transparent; }
form .flash { margin: 12px 0 0; }

/* --- Attendance app additions --- */
.wrap { max-width: 640px; }
.wrap.wide { max-width: 980px; }
h3 { font-size: 0.9rem; margin: 1.1rem 0 0.4rem; color: var(--muted); }
.page-title { margin: 0 0 12px; font-size: 1.35rem; overflow-wrap: anywhere; }
.crumbs { margin: 0 0 6px; font-size: 0.85rem; color: var(--muted); }
.badge.warn { background: var(--notice-bg); color: var(--notice-text); }
input[type=search], input[type=tel], input[type=time], select, textarea {
  width: 100%; min-height: 44px; padding: 0.5rem 0.65rem; border: 1px solid var(--border);
  border-radius: 10px; background: var(--field); color: var(--text);
  font: inherit; font-size: 16px; }
input[type=search], input[type=tel], input[type=time] { -webkit-appearance: none; appearance: none; }
textarea { resize: vertical; }
select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: 0.5; cursor: default; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid2 > div { min-width: 0; }
.row-form select { flex: 1; min-width: 0; }
.row-form .button { margin-top: 0; }
a.line-main { color: inherit; text-decoration: none; }
.note { display: block; margin-top: 2px; font-size: 0.9rem; white-space: pre-line; overflow-wrap: anywhere; }
.chev { color: var(--muted); font-size: 1.3rem; }

.subnav, .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.subnav a, .chips a { padding: 6px 12px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--card); color: var(--muted); font-size: 0.85rem; font-weight: 600;
  text-decoration: none; }
.subnav a.active, .chips a.active { background: var(--accent); border-color: var(--accent);
  color: var(--accent-text); }
.chips a.active .count { background: transparent; color: inherit; }

.search { position: relative; margin-bottom: 12px; }
.search input { padding-right: 2.8rem; }
input[type=search]::-webkit-search-cancel-button { display: none; }
.clear { position: absolute; top: 0; right: 0; width: 2.8rem; height: 100%; min-height: 0;
  margin: 0; padding: 0; border: 0; background: none; color: var(--muted); font-size: 1.5rem;
  line-height: 1; }

/* Attendance page */
.monthbar h1 { position: relative; }
.monthbar button.arrow { margin: 0; padding: 0; cursor: pointer; }
.pick { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
#tabs { margin-bottom: 12px; background: var(--card); }
#tabs button { flex: 1; min-height: 40px; margin: 0; padding: 6px 4px; border: 0; border-radius: 7px;
  background: none; color: var(--muted); font-size: 0.9rem; }
#tabs button[aria-selected=true] { background: var(--accent); color: var(--accent-text); }
#tabs button[aria-selected=true] .count { background: transparent; color: inherit; }
#tabs .count { display: inline-block; margin-left: 2px; padding: 1px 6px; border-radius: 999px;
  font-size: 0.75rem; cursor: inherit; }
#summary { margin: 0 0 12px; text-align: center; }

.section { margin-bottom: 12px; padding: 0; overflow: hidden; }
.section > summary { display: flex; align-items: center; gap: 8px; padding: 12px 16px;
  font-weight: 700; cursor: pointer; list-style: none; }
.section > summary::-webkit-details-marker { display: none; }
.section > summary::after { content: "›"; margin-left: auto; color: var(--muted);
  font-size: 1.3rem; transition: transform 0.15s; }
.section[open] > summary::after { transform: rotate(90deg); }
.section .more { display: block; width: calc(100% - 32px); margin: 8px 16px 14px; }
.house { border-top: 1px solid var(--border); }
.house-head, .person { display: flex; align-items: center; gap: 4px; padding: 0 8px 0 6px; }
.check { display: flex; align-items: center; justify-content: center; flex: none;
  width: 44px; height: 48px; margin: 0; cursor: pointer; }
.check input { width: 24px; height: 24px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.house-name { flex: 1; min-width: 0; min-height: 48px; margin: 0; padding: 6px 0; border: 0;
  background: none; color: inherit; font-size: 1rem; font-weight: 600; text-align: left;
  overflow-wrap: anywhere; }
.house-name .meta { font-weight: normal; }
.tally { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums;
  white-space: nowrap; padding-right: 6px; }
.members { padding: 0 0 6px 22px; }
.person { flex-wrap: wrap; }
.person-name { flex: 1; min-width: 0; padding: 6px 0; overflow-wrap: anywhere; }
.person-name .meta { display: block; }
.person a.open, .person button.icon { display: flex; align-items: center; justify-content: center;
  width: 40px; height: 44px; color: var(--muted); text-decoration: none; font-size: 1.2rem; }
.person button.icon.has-note { color: var(--accent); }
.daynote { display: flex; flex-basis: 100%; gap: 8px; align-items: center; padding: 0 4px 8px 48px; }
.daynote input[type=text] { flex: 1; min-width: 0; min-height: 38px; }
.daynote .choice { min-height: 38px; font-size: 0.85rem; white-space: nowrap; gap: 6px; }
.house.unnamed { display: flex; align-items: center; gap: 8px; padding: 8px 12px 8px 16px; }
.unnamed-label { flex: 1; min-width: 0; font-weight: 600; }
.step { width: 44px; height: 44px; min-height: 0; margin: 0; padding: 0; font-size: 1.4rem; line-height: 1; }
.step-count { min-width: 2ch; text-align: center; font-size: 1.2rem; font-weight: 700;
  font-variant-numeric: tabular-nums; }
.daynote.housenote { padding-left: 6px; padding-top: 2px; }
.hintline { display: block; flex-basis: 100%; padding: 0 4px 8px 48px; font-size: 0.8rem; }

dialog { width: min(94vw, 480px); max-height: 92vh; padding: 16px; border: 1px solid var(--border);
  border-radius: 14px; background: var(--card); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 1.25rem);
  transform: translateX(-50%); max-width: calc(100vw - 32px); padding: 0.7rem 1rem;
  border-radius: 10px; background: var(--text); color: var(--bg); font-size: 0.95rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25); z-index: 40; }
.toast.is-error { background: var(--bad); color: #fff; }
.toast a { color: inherit; font-weight: 700; }

/* Person page */
.statrow { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.statrow strong { display: block; font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.statrow span { font-size: 0.75rem; color: var(--muted); }
.strip { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 12px; }
.strip a, .key { width: 12px; height: 12px; border-radius: 3px; background: var(--border); }
.strip .on, .key.on { background: var(--good); }
.strip .off, .key.off { background: var(--bad); }
.strip .excused, .key.excused { background: #d9a400; }
.key { display: inline-block; vertical-align: -1px; margin-left: 6px; }
.legend .key:first-child { margin-left: 0; }

.table { width: 100%; margin-top: 12px; border-collapse: collapse; font-size: 0.9rem;
  font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 7px 8px; border-bottom: 1px solid var(--border); text-align: left;
  vertical-align: top; }
.table th { color: var(--muted); font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
.table.sortable th { cursor: pointer; user-select: none; }
.table.sortable th[aria-sort=ascending]::after { content: " ▲"; }
.table.sortable th[aria-sort=descending]::after { content: " ▼"; }
.table td.num, .table th.num { text-align: right; }
.table.merge .choice { min-height: 0; align-items: flex-start; font-size: 0.9rem; overflow-wrap: anywhere; }
.table.merge .same { color: var(--muted); }
.table a { color: inherit; }
.scroll { overflow-x: auto; }
.checklist { max-height: 340px; overflow-y: auto; margin-top: 10px; padding: 4px 10px;
  border: 1px solid var(--border); border-radius: 10px; }

/* Reports */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.tile { padding: 12px 10px; border: 1px solid var(--border); border-radius: 10px; text-align: center; }
.tile strong { display: block; font-size: 1.8rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.tile span { font-size: 0.8rem; color: var(--muted); }
.controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0 12px; }
.controls label { margin-top: 0; }
.chart { position: relative; height: 280px; }
.chart.short { height: 200px; }
