:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f1f4fa;
  --border: #e3e7ef;
  --ink: #1b2130;
  --ink-2: #4b5466;
  --muted: #7a8396;
  --accent: #2f5bd3;
  --accent-ink: #ffffff;
  --accent-soft: #e8eefc;
  --good: #1a7f4b;
  --good-soft: #e3f4ea;
  --warn: #9a6200;
  --warn-soft: #fdf1d8;
  --bad: #c0362c;
  --bad-soft: #fbe6e4;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 30, 60, .05), 0 2px 8px rgba(20, 30, 60, .04);
  --nav-h: 64px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", Helvetica, Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  padding-bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
.icon { flex: none; display: block; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }
.hidden { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1100px; margin: 0 auto;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; min-height: 56px;
}
.brand { font-weight: 700; font-size: 16px; color: var(--ink); margin-right: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 10px;
  color: var(--ink-2); background: none; border: 0; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }

/* ---------- Navigation: bottom bar on phones, inline in top bar on desktop ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: 11px; font-weight: 550;
}
.nav a.active { color: var(--accent); }
.nav a.collect-tab .bubble {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center;
  margin-top: -22px; box-shadow: 0 4px 14px rgba(47, 91, 211, .35);
}
.nav a.collect-tab { color: var(--ink); }

@media (min-width: 900px) {
  body { padding-bottom: 40px; }
  .nav {
    position: static; display: flex; height: auto; padding: 0; border: 0; gap: 4px; background: none;
  }
  .nav a { flex-direction: row; font-size: 14px; padding: 8px 12px; border-radius: 10px; gap: 8px; }
  .nav a:hover { background: var(--surface-2); }
  .nav a.active { background: var(--accent-soft); }
  .nav a.collect-tab .bubble { width: auto; height: auto; margin: 0; background: none; color: inherit; box-shadow: none; }
  .nav a.collect-tab { background: var(--accent); color: var(--accent-ink); }
  .nav a.collect-tab:hover { background: #2549b3; }
}

/* ---------- Layout ---------- */
.page { max-width: 1100px; margin: 0 auto; padding: 16px; }
.page-head { display: flex; align-items: center; gap: 12px; margin: 4px 0 16px; flex-wrap: wrap; }
.page-head h1 { margin-right: auto; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--ink-2); font-size: 14px; margin-bottom: 8px; }
.stack > * + * { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
@media (min-width: 900px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3-2 { grid-template-columns: 3fr 2fr; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-head a { font-size: 13px; font-weight: 550; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush .card-head { padding: 16px 16px 0; }

/* ---------- Stat tiles ---------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (min-width: 900px) { .stats { grid-template-columns: repeat(4, 1fr); gap: 16px; } }
.stat .label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; }
.stat.hero { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.stat.hero .label, .stat.hero .sub { color: rgba(255, 255, 255, .85); }
.stat .value.bad { color: var(--bad); }

.meter { height: 6px; background: var(--surface-2); border-radius: 99px; margin-top: 10px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--good); border-radius: 99px; }
.stat.hero .meter { background: rgba(255, 255, 255, .25); }
.stat.hero .meter > span { background: #fff; }

/* ---------- Bar chart ---------- */
.bars { display: flex; align-items: flex-end; gap: 10px; height: 170px; padding-top: 22px; border-bottom: 1px solid var(--border); }
.bar { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; cursor: default; }
.bar .fill { width: 100%; max-width: 44px; background: #9db3ec; border-radius: 4px 4px 0 0; min-height: 2px; transition: background .15s; }
.bar.current .fill { background: var(--accent); }
.bar:hover .fill, .bar:focus .fill { background: #2549b3; }
.bar .tip {
  position: absolute; bottom: calc(var(--h) + 6px); left: 50%; transform: translateX(-50%);
  font-size: 11.5px; font-weight: 600; color: var(--ink-2); white-space: nowrap; font-variant-numeric: tabular-nums;
}
.bar-labels { display: flex; gap: 10px; margin-top: 6px; }
.bar-labels span { flex: 1; text-align: center; font-size: 12px; color: var(--muted); }
.bar-labels span.current { color: var(--ink); font-weight: 600; }

/* ---------- Lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-top: 1px solid var(--border); }
.list > li:first-child { border-top: 0; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; color: var(--ink); min-height: 56px;
}
a.row:hover { background: var(--surface-2); }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { font-size: 13px; color: var(--muted); }
.row .end { text-align: right; flex: none; }
.amount { font-weight: 650; font-variant-numeric: tabular-nums; }
.amount.bad { color: var(--bad); }
.amount.good { color: var(--good); }

.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px;
}

.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 700; border-bottom: 0; }
tbody tr:last-child td { border-bottom: 0; }
td.wrap { white-space: normal; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px;
  background: var(--surface-2); color: var(--ink-2); white-space: nowrap;
}
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- Forms ---------- */
label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.field { margin-bottom: 14px; }
.field .hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--ink);
  background: var(--surface); border: 1px solid #cfd5e1; border-radius: 10px;
  padding: 10px 12px; min-height: 44px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }
.form-row { display: grid; gap: 12px; }
@media (min-width: 600px) { .form-row { grid-template-columns: 1fr 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-size: 15px; font-weight: 600;
  min-height: 44px; padding: 10px 16px; border-radius: 10px;
  border: 1px solid #cfd5e1; background: var(--surface); color: var(--ink); cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #2549b3; }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn.danger { color: var(--bad); border-color: #efc3bf; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.block { width: 100%; }
.btn.lg { min-height: 52px; font-size: 16px; }
.btn.sm { min-height: 34px; padding: 6px 10px; font-size: 13px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row.end { justify-content: flex-end; }

/* Segmented choice (payment mode, filters) */
.segmented { display: flex; gap: 8px; flex-wrap: wrap; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px; }
.segmented label {
  margin: 0; flex: 1; min-width: 80px; text-align: center; cursor: pointer;
  padding: 10px 12px; border: 1px solid #cfd5e1; border-radius: 10px; font-size: 15px; color: var(--ink);
}
.segmented input:checked + label { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.segmented input:focus-visible + label { outline: 2px solid var(--accent); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 6px 12px; border-radius: 99px; font-size: 13.5px; font-weight: 550;
  background: var(--surface); border: 1px solid var(--border); color: var(--ink-2); cursor: pointer;
}
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }

.search { position: relative; }
.search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 40px; }

.filters { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; align-items: end; }
.filters .field { margin: 0; }
@media (min-width: 900px) { .filters { grid-template-columns: repeat(5, 1fr); } }

/* ---------- Flash ---------- */
.flash { padding: 12px 14px; border-radius: 10px; margin-bottom: 16px; font-weight: 550; font-size: 14px; }
.flash.ok { background: var(--good-soft); color: var(--good); }
.flash.error { background: var(--bad-soft); color: var(--bad); }
.errors { background: var(--bad-soft); color: var(--bad); padding: 12px 14px 12px 32px; border-radius: 10px; margin: 0 0 16px; font-size: 14px; }

/* ---------- Profile ---------- */
.profile-head { display: flex; gap: 14px; align-items: center; }
.profile-head .avatar { width: 56px; height: 56px; font-size: 20px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.balance-box { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.balance-box .value { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }

.months { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.month {
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; font-size: 13px; background: var(--surface);
}
.month .m { font-weight: 650; }
.month form { margin-top: 4px; }
.month button { background: none; border: 0; padding: 0; font: inherit; font-size: 12px; color: var(--muted); text-decoration: underline; cursor: pointer; }
.month.paid { border-color: #bfe3cd; background: var(--good-soft); }
.month.partial { border-color: #f1d9a6; background: var(--warn-soft); }
.month.due { border-color: #f1c4bf; background: var(--bad-soft); }
.month.waived { background: var(--surface-2); color: var(--muted); }

/* ---------- Attendance ---------- */
.batch-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 600px) { .batch-grid { grid-template-columns: repeat(4, 1fr); } }
.batch-tile { display: block; color: var(--ink); }
.batch-tile .name { font-size: 22px; font-weight: 700; }
.batch-tile:hover { border-color: var(--accent); }

.att-list .row { cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent; }
.att-toggle {
  flex: none; min-width: 92px; text-align: center; padding: 8px 10px; border-radius: 10px;
  font-weight: 700; font-size: 14px; background: var(--good-soft); color: var(--good); border: 1px solid #bfe3cd;
}
.att-list input { display: none; }
.att-list input[type=checkbox]:checked ~ .att-toggle { background: var(--bad-soft); color: var(--bad); border-color: #f1c4bf; }
.att-list input[type=checkbox]:checked ~ .att-toggle .p { display: none; }
.att-list input[type=checkbox]:not(:checked) ~ .att-toggle .a { display: none; }
.att-list input[type=checkbox]:checked ~ .main .title { color: var(--bad); }

.sticky-actions {
  position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(20, 30, 60, .12); padding: 12px; margin-top: 16px;
  display: flex; align-items: center; gap: 12px;
}
.sticky-actions .summary { flex: 1; font-size: 14px; }
@media (min-width: 900px) { .sticky-actions { bottom: 16px; } }

/* ---------- Collect ---------- */
.amount-input { font-size: 28px; font-weight: 700; padding: 12px 14px 12px 36px; min-height: 60px; }
.amount-wrap { position: relative; }
.amount-wrap::before { content: '₹'; position: absolute; left: 14px; top: 50%; transform: translateY(-50%); font-size: 24px; font-weight: 700; color: var(--muted); }
.quick-amounts { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

.success-mark {
  width: 64px; height: 64px; border-radius: 50%; background: var(--good-soft); color: var(--good);
  display: flex; align-items: center; justify-content: center; margin: 0 auto 12px;
}
.receipt-card { max-width: 480px; margin: 0 auto; text-align: center; }
.receipt-card .kv { text-align: left; margin: 16px 0; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { margin-bottom: 4px; }

.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 4px; margin-bottom: 16px; overflow-x: auto; }
.tabs a { flex: 1; text-align: center; padding: 8px 12px; border-radius: 9px; color: var(--ink-2); font-weight: 600; font-size: 14px; white-space: nowrap; }
.tabs a.active { background: var(--accent-soft); color: var(--accent); }

@media print {
  .topbar, .nav, .btn, .filters, .tabs { display: none !important; }
  body { background: #fff; padding: 0; }
  .card { box-shadow: none; }
}

.bar .tip { opacity: 0; transition: opacity .15s; }
.bar.current .tip, .bar:hover .tip, .bar:focus .tip { opacity: 1; }
.bars:hover .bar.current:not(:hover) .tip { opacity: 0; }
@media (min-width: 900px) { .hide-desktop { display: none !important; } }
