:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --ok: #059669;
  --ok-soft: #ecfdf5;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --wa: #128c7e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color: var(--ink);
  background: var(--bg);
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0; line-height: 1.25; }
h2 { font-size: 1rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
p { margin: .25rem 0 .75rem; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1rem;
  padding: .6rem 1rem; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .55rem; color: var(--ink); font-weight: 700; min-width: 0; }
.brand:hover { text-decoration: none; }
.brand-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo {
  display: inline-grid; place-items: center; flex: none;
  width: 32px; height: 32px; border-radius: 9px; background: var(--primary); color: #fff; font-weight: 700;
}
.logo-lg { width: 56px; height: 56px; font-size: 1.6rem; border-radius: 16px; margin: 0 auto .75rem; }
.topnav { display: none; gap: .25rem; }
.topnav a { padding: .45rem .8rem; border-radius: 9px; color: var(--muted); font-weight: 500; }
.topnav a:hover { background: var(--bg); text-decoration: none; }
.topnav a.on { color: var(--primary); background: var(--primary-soft); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: .5rem; }
.icon-btn { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; color: var(--muted); }
.icon-btn:hover { background: var(--bg); }

/* Bottom nav (mobile) */
.bottomnav {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
  background: var(--card); border-top: 1px solid var(--line);
  padding: .35rem .25rem calc(.35rem + env(safe-area-inset-bottom));
}
.bottomnav a { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: .7rem; padding: .25rem 0; }
.bottomnav a:hover { text-decoration: none; }
.bottomnav a.on { color: var(--primary); }
.bottomnav .fab { color: var(--primary); font-weight: 600; }
.fab span {
  display: grid; place-items: center; width: 54px; height: 54px; margin-top: -26px;
  border-radius: 50%; background: var(--primary); color: #fff; font-size: 1.5rem;
  box-shadow: 0 6px 16px rgba(37, 99, 235, .4); border: 4px solid var(--bg);
}

.container { max-width: 1100px; margin: 0 auto; padding: 1rem; }

/* Layout */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: .25rem 0 1rem; flex-wrap: wrap; }
.page-head p { margin: .15rem 0 0; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem; }
.grid-2 { display: grid; gap: 0 1rem; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.row-between h2 { margin: 0 0 .5rem; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: .9rem 1rem; display: flex; flex-direction: column; gap: .2rem; min-width: 0; }
.stat-label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.stat-value { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-warn .stat-value { color: var(--warn); }
.big { display: block; font-size: 2.2rem; font-weight: 800; margin: .1rem 0 .4rem; font-variant-numeric: tabular-nums; }

.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: .3rem 0; }
.bar span { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.progress-row { margin-bottom: .75rem; }

/* CSS bar chart */
.bars { display: flex; align-items: flex-end; gap: .5rem; height: 190px; padding-top: 1.2rem; }
.bar-col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: .3rem; }
.bar-fill { width: 100%; max-width: 46px; background: #bfdbfe; border-radius: 6px 6px 2px 2px; }
.bar-col.current .bar-fill { background: var(--primary); }
.bar-val { font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.bar-label { font-size: .75rem; color: var(--muted); }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: .75rem; padding: .7rem 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list-main { flex: 1; min-width: 0; display: flex; flex-direction: column; color: var(--ink); }
.list-main:hover { text-decoration: none; }
.list-main:hover strong { color: var(--primary); }
.list-main strong, .list-main span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list li.voided { opacity: .55; }
.amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amount.warn { color: var(--warn); }
.amount.ok { color: var(--ok); }
.chev { color: var(--muted); font-size: 1.4rem; }

.details { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: 0 0 .75rem; }
.details dt { color: var(--muted); font-size: .88rem; }
.details dd { margin: 0; }

/* Badges & chips */
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 99px; font-size: .75rem; font-weight: 600; background: var(--line); color: var(--muted); vertical-align: middle; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .5rem 0 .75rem; }
.chip { padding: .25rem .6rem; border-radius: 99px; background: var(--bg); font-size: .8rem; }
.chip-warn { background: var(--warn-soft); color: #92400e; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .55rem 1rem; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer;
  white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-wa { background: var(--wa); border-color: var(--wa); color: #fff; }
.btn-wa:hover { background: #0e7268; }
.btn-sm { padding: .3rem .7rem; font-size: .85rem; }
.btn-lg { padding: .75rem 1.2rem; }
.btn-xl { padding: 1rem 1.2rem; font-size: 1.05rem; }
.btn-block { width: 100%; }
.btn-danger-link, .link-btn { background: none; border: 0; padding: .3rem 0; color: var(--danger); cursor: pointer; font: inherit; font-weight: 500; }
.link-btn { color: var(--primary); }
.btn:disabled { opacity: .6; cursor: progress; }

/* Forms */
.form label, .filters label, .login-card label { display: flex; flex-direction: column; gap: .3rem; font-size: .88rem; font-weight: 600; color: #374151; margin-bottom: .9rem; }
input, select, textarea {
  font: inherit; font-size: 16px; /* prevents iOS zoom */
  padding: .6rem .75rem; border: 1px solid #d1d5db; border-radius: 10px; background: #fff; color: var(--ink); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }
.input-xl { font-size: 1.8rem; font-weight: 700; padding: .5rem .75rem; }
.hint { font-weight: 400; color: var(--muted); font-size: .8rem; }
.form-row { display: grid; gap: 0 1rem; }
.form-actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; }
.filters input[type=search] { flex: 1 1 220px; }
.filters select, .filters .inline { flex: 1 1 140px; width: auto; }
.filters .inline { margin: 0; }
.filters .btn { flex: none; }
.danger-zone { text-align: center; margin: 1.5rem 0; }

.search-big input { font-size: 1.1rem; padding: .85rem 1rem; margin-bottom: .5rem; }

.quick-amounts { display: flex; flex-wrap: wrap; gap: .4rem; margin: -.4rem 0 .5rem; }
.chip-btn { border: 1px solid var(--line); background: var(--bg); border-radius: 99px; padding: .35rem .8rem; font: inherit; font-size: .85rem; cursor: pointer; }
.chip-btn:hover { border-color: var(--primary); color: var(--primary); }
.pending-line { font-size: 1.05rem; margin-bottom: .25rem; }
.pending-line strong { font-size: 1.4rem; }

.segmented { border: 0; padding: 0; margin: 0 0 .9rem; }
.segmented legend { font-size: .88rem; font-weight: 600; color: #374151; margin-bottom: .3rem; padding: 0; }
.segmented { display: grid; grid-template-columns: repeat(2, 1fr); gap: .4rem; }
.segmented legend { grid-column: 1 / -1; }
.segmented label { margin: 0; }
.segmented input { position: absolute; opacity: 0; width: 1px; }
.segmented span { display: block; text-align: center; padding: .65rem; border: 1px solid #d1d5db; border-radius: 10px; font-weight: 600; cursor: pointer; }
.segmented input:checked + span { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.segmented input:focus-visible + span { outline: 2px solid #bfdbfe; }

/* Flash */
.flash { padding: .7rem 1rem; border-radius: 10px; margin-bottom: 1rem; font-weight: 500; }
.flash-success { background: var(--ok-soft); color: #065f46; }
.flash-error { background: var(--danger-soft); color: #991b1b; }

/* Receipt */
.success-banner { display: flex; align-items: center; gap: .9rem; background: var(--ok-soft); color: #065f46; border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.tick { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: var(--ok); color: #fff; font-size: 1.4rem; flex: none; }
.receipt { position: relative; overflow: hidden; }
.receipt-head { display: flex; flex-direction: column; border-bottom: 1px dashed var(--line); padding-bottom: .6rem; margin-bottom: .8rem; }
.receipt-total { border-top: 1px dashed var(--line); padding-top: .8rem; font-size: 1.1rem; }
.receipt-total strong { font-size: 1.5rem; }
.void-stamp { position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%) rotate(-20deg); font-size: 2.5rem; font-weight: 800; color: rgba(220, 38, 38, .25); border: 4px solid rgba(220, 38, 38, .25); padding: 0 1rem; border-radius: 10px; pointer-events: none; }
.action-stack { display: grid; gap: .6rem; }

/* Tables */
.table-wrap { overflow-x: auto; margin: 0 -1rem; padding: 0 1rem; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: .5rem .5rem; border-bottom: 1px solid var(--line); }
.table td { padding: .6rem .5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tfoot td { font-weight: 700; border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table form { margin: 0; }

/* Tabs */
.tabs { display: flex; gap: .25rem; background: var(--line); padding: .25rem; border-radius: 12px; margin-bottom: 1rem; }
.tabs a { flex: 1; text-align: center; padding: .5rem; border-radius: 9px; color: var(--muted); font-weight: 600; font-size: .9rem; }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.tabs a.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

/* Attendance */
.batch-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; }
.batch-tile { display: flex; flex-direction: column; padding: .8rem; border-radius: 12px; border: 1px solid var(--line); color: var(--ink); background: var(--card); }
.batch-tile:hover { border-color: var(--primary); text-decoration: none; }
.batch-tile strong { font-size: 1.15rem; }
.batch-tile .small { color: var(--muted); }
.batch-tile.done { background: var(--ok-soft); border-color: #a7f3d0; }
.batch-tile.done .tile-status { color: var(--ok); font-weight: 600; }
.att-summary { margin-bottom: .25rem; }
.att-list { list-style: none; padding: 0; margin: .5rem 0 1rem; }
.att-item { display: flex; align-items: center; gap: .75rem; padding: .8rem .75rem; margin-bottom: .4rem; border-radius: 12px; border: 1px solid #a7f3d0; background: var(--ok-soft); cursor: pointer; user-select: none; }
.att-item input { position: absolute; opacity: 0; width: 1px; }
.att-roll { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: #fff; font-weight: 700; font-size: .85rem; flex: none; }
.att-name { flex: 1; font-weight: 600; }
.att-state::after { content: "Present"; font-weight: 700; font-size: .8rem; color: var(--ok); }
.att-item:has(input:not(:checked)) { background: var(--danger-soft); border-color: #fecaca; }
.att-item:has(input:not(:checked)) .att-state::after { content: "Absent"; color: var(--danger); }
.att-item:has(input:focus-visible) { outline: 2px solid #bfdbfe; }

/* Results */
.grid-3 { display: grid; gap: 1rem; }
.podium { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; align-items: end; margin-bottom: .5rem; }
.podium-card { display: flex; flex-direction: column; align-items: center; text-align: center; gap: .15rem; padding: .9rem .5rem; border-radius: 12px; border: 1px solid var(--line); color: var(--ink); min-width: 0; }
.podium-card:hover { border-color: var(--primary); text-decoration: none; }
.podium-card strong { overflow-wrap: anywhere; line-height: 1.25; }
.podium-card.rank-1 { background: #fffbeb; border-color: #fde68a; order: 2; padding-top: 1.4rem; }
.podium-card.rank-2 { background: #f8fafc; order: 1; }
.podium-card.rank-3 { background: #fff7ed; border-color: #fed7aa; order: 3; }
.medal { font-size: 1.8rem; line-height: 1; }
.podium-pct { font-size: 1.35rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.rank-list { list-style: none; margin: 0; padding: 0; }
.rank-list li { display: flex; align-items: center; gap: .75rem; padding: .6rem 0; border-top: 1px solid var(--line); }
.rank-no, .medal-sm { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--bg); font-weight: 700; font-size: .85rem; flex: none; }
.medal-sm { background: none; font-size: 1.2rem; }
.pct { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pct.warn { color: var(--warn); }
.class-col .list li { padding: .5rem 0; }
.bar-warn span { background: var(--warn); }
.bars-sm { height: 150px; }
.bar-fill.grade-ok { background: #6ee7b7; }
.bar-fill.grade-warn { background: #fcd34d; }
.bar-fill.grade-danger { background: #fca5a5; }
.batch-tile a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted-tile { opacity: .6; }
.stat-flat { display: flex; flex-direction: column; gap: .2rem; padding: .75rem 1rem; border-radius: 12px; background: var(--bg); }
.chip-on { background: var(--primary); color: #fff; }
.chip-done { background: var(--ok-soft); color: var(--ok); }
a.chip:hover { text-decoration: none; filter: brightness(.96); }
.marks-list { list-style: none; padding: 0; margin: .5rem 0 1rem; }
.marks-list li { display: flex; align-items: center; gap: .6rem; padding: .5rem 0; border-top: 1px solid var(--line); }
.marks-input { width: 84px; flex: none; text-align: center; font-weight: 700; padding: .5rem; }
.marks-input:disabled { background: var(--bg); }
.ab-toggle { flex: none; cursor: pointer; }
.ab-toggle input { position: absolute; opacity: 0; width: 1px; }
.ab-toggle span { display: block; padding: .5rem .55rem; border: 1px solid #d1d5db; border-radius: 9px; font-size: .8rem; font-weight: 700; color: var(--muted); }
.ab-toggle input:checked + span { background: var(--danger-soft); border-color: #fecaca; color: var(--danger); }
.ab-toggle input:focus-visible + span { outline: 2px solid #bfdbfe; }
.inline-form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .5rem; }
.inline-form input { width: auto; flex: 1 1 120px; }
.inline-form input[type=number] { flex: 0 1 100px; }

.fee-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 1rem; }
.fee-card .form-actions { margin-top: .5rem; }
.empty { text-align: center; padding: 2rem 1rem; }

/* Login */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.login-card { width: 100%; max-width: 380px; text-align: center; padding: 2rem 1.5rem; }
.login-card label { text-align: left; }
.login-card h1 { margin-bottom: .25rem; }
.login-card p { margin-bottom: 1.25rem; }

.hide-sm { display: none; }

@media (min-width: 640px) {
  .stats { grid-template-columns: repeat(4, 1fr); }
  .form-row { grid-template-columns: 1fr 1fr; }
  .segmented { grid-template-columns: repeat(4, 1fr); }
  .batch-grid { grid-template-columns: repeat(4, 1fr); }
  .fee-grid { grid-template-columns: repeat(4, 1fr); }
  .action-stack { grid-template-columns: repeat(3, auto); justify-content: start; }
}

@media (min-width: 900px) {
  body { padding-bottom: 0; }
  .bottomnav { display: none; }
  .topnav { display: flex; }
  .hide-sm { display: inline-flex; }
  .show-sm-only { display: none; }
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .container { padding: 1.5rem; }
}

@media print {
  .topbar, .bottomnav, .action-stack, .danger-zone, .success-banner { display: none !important; }
  body { background: #fff; padding: 0; }
  .card { box-shadow: none; }
}
