:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #2563eb;
  --brand-ink: #ffffff;
  --brand-soft: #eff4ff;
  --ok: #059669;
  --ok-soft: #ecfdf5;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --bad: #dc2626;
  --bad-soft: #fef2f2;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --nav-h: 64px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---------- Header & nav ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--card); border-bottom: 1px solid var(--line);
}
.topbar-inner { max-width: 1100px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; }
.brand { font-weight: 700; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand:hover { text-decoration: none; }
.topnav { display: none; gap: 4px; margin-left: auto; align-items: center; }
.topnav a { color: var(--muted); padding: 8px 12px; border-radius: 8px; font-weight: 500; }
.topnav a:hover { background: var(--bg); text-decoration: none; }
.topnav a.active { color: var(--brand); background: var(--brand-soft); }
.topbar .logout { margin-left: auto; }

.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--card);
  border-top: 1px solid var(--line); display: flex; padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: var(--nav-h); color: var(--muted); font-size: .72rem; font-weight: 500;
}
.bottomnav a:hover { text-decoration: none; }
.bottomnav a.active { color: var(--brand); }
.bottomnav svg { width: 22px; height: 22px; }
.bottomnav .collect-tab span.fab {
  width: 52px; height: 52px; border-radius: 50%; background: var(--brand); color: var(--brand-ink);
  display: grid; place-items: center; margin-top: -26px; box-shadow: 0 4px 12px rgba(37, 99, 235, .4);
}
.bottomnav .collect-tab svg { width: 26px; height: 26px; }

@media (min-width: 900px) {
  body { padding-bottom: 32px; }
  .bottomnav { display: none; }
  .topnav { display: flex; }
  .topbar .logout { margin-left: 8px; }
}

/* ---------- Layout ---------- */
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2 { padding: 16px 16px 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, 1fr); } .grid-2 { grid-template-columns: 1fr 1fr; } }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.stat .label { color: var(--muted); font-size: .8rem; font-weight: 500; }
.stat .value { font-size: 1.35rem; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--muted); font-size: .78rem; margin-top: 2px; }
.stat.bad .value { color: var(--bad); }
.stat.ok .value { color: var(--ok); }

/* ---------- Buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; background: var(--bg); }
.btn-primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn-primary:hover { background: #1d4ed8; }
.btn-danger { color: var(--bad); border-color: #fecaca; }
.btn-danger:hover { background: var(--bad-soft); }
.btn-lg { min-height: 52px; font-size: 1.05rem; width: 100%; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: .85rem; }
.btn[disabled] { opacity: .6; cursor: wait; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.hint { color: var(--muted); font-size: .8rem; margin-top: 4px; font-weight: 400; }
input[type=text], input[type=search], input[type=password], input[type=date], input[type=month],
input[type=tel], input[type=number], input:not([type]), select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 10px;
  font: inherit; font-size: 16px; /* 16px stops iOS zooming in */ background: #fff; color: var(--ink);
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand); }
.form-grid { display: grid; gap: 0 16px; grid-template-columns: 1fr; }
@media (min-width: 700px) { .form-grid { grid-template-columns: 1fr 1fr; } .form-grid .full { grid-column: 1 / -1; } }
.amount-input { font-size: 1.6rem !important; font-weight: 700; min-height: 60px !important; font-variant-numeric: tabular-nums; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.filters > * { flex: 1 1 140px; }
.filters .btn { flex: 0 0 auto; }

/* Segmented radio pills */
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pills input { position: absolute; opacity: 0; pointer-events: none; }
.pills label {
  margin: 0; padding: 10px 14px; border: 1px solid #d1d5db; border-radius: 999px; cursor: pointer;
  font-weight: 600; background: #fff; min-height: 42px; display: flex; align-items: center;
}
.pills input:checked + label { background: var(--brand); border-color: var(--brand); color: #fff; }
.pills input:focus-visible + label { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------- Tables & lists ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #fafafa; }
tr:last-child td { border-bottom: 0; }
tr.voided td { color: var(--muted); text-decoration: line-through; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list a.row, .list .row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; color: var(--ink); }
.list a.row:hover { background: #fafafa; text-decoration: none; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { color: var(--muted); font-size: .82rem; }
.empty { padding: 24px 16px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--brand-soft); color: var(--brand); }
.badge.muted { background: #f3f4f6; color: var(--muted); }

.alert { padding: 12px 14px; border-radius: 10px; margin-bottom: 16px; font-weight: 500; }
.alert.ok { background: var(--ok-soft); color: #065f46; }
.alert.err { background: var(--bad-soft); color: #991b1b; }
.alert ul { margin: 0; padding-left: 18px; }

/* Bars (mode split etc.) */
.bar { height: 8px; background: #f3f4f6; border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.kv { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; }

/* ---------- Attendance ---------- */
.att-list li .row { padding: 10px 16px; }
.att-toggle { display: flex; border: 1px solid #d1d5db; border-radius: 10px; overflow: hidden; flex-shrink: 0; }
.att-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.att-toggle label { margin: 0; width: 52px; min-height: 42px; display: grid; place-items: center; cursor: pointer; font-weight: 700; color: var(--muted); }
.att-toggle input.p:checked + label { background: var(--ok); color: #fff; }
.att-toggle input.a:checked + label { background: var(--bad); color: #fff; }
.att-summary { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); padding: 12px 16px; display: flex; gap: 12px; align-items: center; }
@media (min-width: 900px) { .att-summary { bottom: 0; } }
.register td, .register th { padding: 6px 6px; text-align: center; font-size: .8rem; }
.register td:first-child, .register th:first-child { text-align: left; position: sticky; left: 0; background: #fff; min-width: 140px; }
.register .P { color: var(--ok); font-weight: 700; }
.register .A { color: var(--bad); font-weight: 700; background: var(--bad-soft); }

/* ---------- Search results ---------- */
.search-big { font-size: 1.1rem !important; min-height: 54px !important; }
.balance-hero { text-align: center; padding: 8px 0 4px; }
.balance-hero .value { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.balance-hero.bad .value { color: var(--bad); }
.balance-hero.ok .value { color: var(--ok); }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; }
.success-hero { text-align: center; padding: 8px 0 16px; }
.success-hero .tick { width: 56px; height: 56px; border-radius: 50%; background: var(--ok-soft); color: var(--ok); display: grid; place-items: center; margin: 0 auto 8px; }

details.danger summary { cursor: pointer; color: var(--bad); font-weight: 600; }
.chart-box { position: relative; height: 220px; }

@media (max-width: 600px) { .hide-sm { display: none; } th, td { padding: 10px 6px; } td { font-size: .88rem; } }
/* Keep the Save button clear of the raised Collect button in the bottom nav */
@media (max-width: 899px) { .att-summary { padding-bottom: 40px; } }
