/* Apple-inspired look: system fonts, light gray canvas, white rounded cards,
   frosted bars, pill buttons, iOS-style grouped lists. */
:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --faint: #86868b;
  --line: #e5e5ea;
  --field: #d2d2d7;
  --fill: #e8e8ed;
  --brand: #0071e3;
  --brand-hover: #0077ed;
  --brand-ink: #ffffff;
  --brand-soft: #e8f1fc;
  --link: #0066cc;
  --good: #248a3d;
  --good-soft: #e3f5e8;
  --warn: #b25000;
  --warn-soft: #fff1e0;
  --bad: #d70015;
  --bad-soft: #ffe9eb;
  --ink: #1d1d1f;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 2px 12px rgba(0, 0, 0, .04);
  --nav-h: 58px;
  --bar: rgba(251, 251, 253, .8);
  font-size: 16px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.47;
  letter-spacing: -.022em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Room for the tab bar plus the floating "Collect fee" button. */
  padding-bottom: calc(var(--nav-h) + 84px + env(safe-area-inset-bottom));
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
a.row:hover, a.btn:hover, .nav a:hover, a.chip:hover, a.section-tile:hover, a.fab:hover, a.brand:hover { text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.1; color: var(--text); }
h1 { font-size: 2rem; font-weight: 700; letter-spacing: -.028em; }
h2 { font-size: 1.2rem; font-weight: 600; letter-spacing: -.02em; }
h3 { font-size: 1rem; font-weight: 600; }
.icon { width: 20px; height: 20px; flex: none; }

/* ---------- Frosted top bar ---------- */
/* On phones the bar must not use backdrop-filter: that would make it the
   containing block for the fixed tab bar nested inside it. */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(251, 251, 253, .96);
  border-bottom: 1px solid rgba(0, 0, 0, .08);
}
@media (min-width: 900px) {
  .topbar {
    background: var(--bar);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
  }
}
.topbar-inner {
  max-width: 1024px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px; height: 48px;
}
.brand { font-weight: 600; color: var(--text); font-size: .95rem; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--muted); font-size: .8rem; }

/* ---------- Navigation: iOS tab bar on phones, inline links on desktop ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around;
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid rgba(0, 0, 0, .1);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--faint); font-size: .65rem; font-weight: 500; letter-spacing: 0;
}
.nav a.active { color: var(--brand); }
.nav a .icon { width: 24px; height: 24px; }

.fab {
  position: fixed; right: 16px; z-index: 31;
  bottom: calc(var(--nav-h) + 14px + env(safe-area-inset-bottom));
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--brand); color: var(--brand-ink);
  padding: 13px 22px; border-radius: 980px; font-weight: 500; font-size: 1rem;
  box-shadow: 0 8px 24px rgba(0, 113, 227, .3);
  transition: background .2s, transform .2s;
}
.fab:hover { background: var(--brand-hover); }
.fab:active { transform: scale(.97); }

@media (min-width: 900px) {
  body { padding-bottom: 48px; }
  .nav {
    position: static; height: auto; border: 0; background: none; padding: 0;
    -webkit-backdrop-filter: none; backdrop-filter: none;
    justify-content: flex-start; gap: 6px; margin-left: 18px;
  }
  .nav a { flex: none; flex-direction: row; gap: 0; font-size: .8rem; font-weight: 400; color: var(--text); opacity: .8; padding: 6px 10px; }
  .nav a:hover { opacity: 1; }
  .nav a.active { color: var(--text); opacity: 1; font-weight: 600; }
  .nav a .icon { display: none; }
  .fab { bottom: 32px; right: 32px; }
}

/* ---------- Layout ---------- */
main { max-width: 1024px; margin: 0 auto; padding: 20px; }
.page-head { display: flex; align-items: center; gap: 12px; margin: 12px 0 24px; flex-wrap: wrap; }
.page-head h1 { flex: 1; min-width: 0; }
.page-head .sub { color: var(--muted); font-size: 1rem; width: 100%; margin-top: -4px; }
.back { display: inline-flex; align-items: center; color: var(--brand); margin-left: -8px; }
.back .icon { width: 28px; height: 28px; }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; margin-bottom: 20px;
}
.card > h2 { margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.card > h2 .link { margin-left: auto; font-size: .85rem; font-weight: 400; letter-spacing: -.01em; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2 { padding: 20px 20px 0; }

.grid { display: grid; gap: 20px; }
.grid > * { min-width: 0; }
@media (min-width: 900px) {
  .grid.two { grid-template-columns: 1fr 1fr; }
  .grid.main-side { grid-template-columns: 3fr 2fr; align-items: start; }
}

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 20px; }
@media (min-width: 900px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; min-width: 0; }
.stat .label { color: var(--muted); font-size: .8rem; font-weight: 500; letter-spacing: -.01em; }
.stat .value { font-size: 1.6rem; font-weight: 700; letter-spacing: -.03em; margin-top: 4px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .hint { color: var(--muted); font-size: .8rem; margin-top: 2px; }
/* Hero tile: dark, like a product tile */
.stat.hero { grid-column: 1 / -1; background: var(--ink); color: #f5f5f7; }
.stat.hero .label, .stat.hero .hint { color: #a1a1a6; }
.stat.hero .value { font-size: 2.4rem; color: #fff; }
.stat.hero a { color: #2997ff; }
@media (min-width: 900px) { .stat.hero { grid-column: auto; } .stat.hero .value { font-size: 1.9rem; } }
.value.bad { color: var(--bad); }

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

/* Bar chart */
.bars { display: flex; align-items: flex-end; gap: 12px; height: 170px; padding-top: 18px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; min-width: 0; }
.bar .fill { width: 100%; max-width: 44px; background: #d6e6fb; border-radius: 10px; min-height: 4px; }
.bar.current .fill { background: var(--brand); }
.bar .amt { font-size: .7rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.bar .mon { font-size: .75rem; color: var(--muted); }
.bar.current .mon { color: var(--text); font-weight: 600; }

/* ---------- Grouped lists (iOS Settings style, inset separators) ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { position: relative; }
.list > li + li::before {
  content: ""; position: absolute; top: 0; right: 0; left: 20px; height: 1px; background: var(--line);
}
.list > li:has(.avatar) + li::before { left: 70px; }
.card.flush > h2 + .list, .card.flush > h2 + ul.list { margin-top: 10px !important; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 20px; color: inherit; min-height: 60px; }
a.row { transition: background .15s; }
a.row:hover { background: #fafafc; }
a.row:active { background: var(--fill); }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { color: var(--muted); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .end { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row .chev { color: #c7c7cc; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 600; font-size: .85rem; letter-spacing: 0;
  background: linear-gradient(180deg, #a1a1a6, #8e8e93); color: #fff;
}
.empty { color: var(--muted); text-align: center; padding: 32px 20px; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .72rem; font-weight: 600; letter-spacing: 0;
  background: var(--fill); color: var(--muted); white-space: nowrap; vertical-align: middle;
}
.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.brand { background: var(--brand-soft); color: var(--brand); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.strike { text-decoration: line-through; }
.num { font-variant-numeric: tabular-nums; }
.good-text { color: var(--good); }
.bad-text { color: var(--bad); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 11px 14px; border-top: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: .78rem; border-top: 0; }
th:first-child, td:first-child { padding-left: 20px; }
th:last-child, td:last-child { padding-right: 20px; }
td.r, th.r { text-align: right; }

/* ---------- Forms ---------- */
label { display: block; font-weight: 500; font-size: .85rem; color: var(--text); margin-bottom: 6px; letter-spacing: -.01em; }
.field { margin-bottom: 16px; }
.field .help { color: var(--muted); font-size: .78rem; margin-top: 6px; }
input[type=text], input[type=tel], input[type=password], input[type=number], input[type=date], input[type=month], input[type=search], select, textarea {
  width: 100%; font: inherit; font-size: 17px; letter-spacing: -.01em; color: var(--text);
  padding: 12px 14px; border: 1px solid var(--field); border-radius: var(--radius-sm); background: #fff;
  min-height: 48px; transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none; appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%236e6e73' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 38px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px rgba(0, 113, 227, .18); }
input[type=checkbox] { accent-color: var(--brand); width: 18px; height: 18px; }
.inline { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.inline > * { flex: 1; min-width: 130px; }
.inline > .btn { flex: none; }
.form-row { display: grid; gap: 0 14px; }
@media (min-width: 600px) { .form-row { grid-template-columns: 1fr 1fr; } }

/* Pill buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font: inherit; font-weight: 500; font-size: .95rem; letter-spacing: -.01em;
  padding: 11px 22px; min-height: 46px; border-radius: 980px; cursor: pointer;
  border: 0; background: var(--fill); color: var(--text); white-space: nowrap;
  transition: background .2s, transform .1s, opacity .2s;
}
.btn:hover { background: #dedee3; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: var(--brand-hover); }
.btn.good { background: var(--brand); color: #fff; }
.btn.good:hover { background: var(--brand-hover); }
.btn.danger { background: transparent; color: var(--bad); box-shadow: inset 0 0 0 1px #f3b3b9; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.block { width: 100%; }
.btn.big { min-height: 54px; font-size: 1.05rem; }
.btn.sm { min-height: 34px; padding: 6px 14px; font-size: .82rem; }
.btn.sm .icon { width: 16px; height: 16px; }
.btn[disabled] { opacity: .5; cursor: default; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1; }

/* iOS segmented control (payment method, role) */
.segmented { display: flex; gap: 2px; background: var(--fill); padding: 3px; border-radius: 12px; }
.segmented label { flex: 1; margin: 0; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: flex; align-items: center; justify-content: center; min-height: 42px;
  border-radius: 9px; font-weight: 500; font-size: .95rem; cursor: pointer; color: var(--text);
  transition: background .2s, box-shadow .2s;
}
.segmented input:checked + span { background: #fff; box-shadow: 0 3px 8px rgba(0, 0, 0, .12), 0 1px 1px rgba(0, 0, 0, .04); font-weight: 600; }
.segmented input:focus-visible + span { outline: 2px solid var(--brand); }

.amount-input { font-size: 2.2rem !important; font-weight: 700; letter-spacing: -.03em !important; padding: 14px 16px !important; min-height: 72px !important; }
.quick-amounts { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* ---------- Flash ---------- */
.flash { padding: 13px 16px; border-radius: var(--radius-sm); margin-bottom: 18px; font-weight: 500; font-size: .95rem; }
.flash.success { 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: 13px 16px 13px 34px; border-radius: var(--radius-sm); margin: 0 0 18px; }

/* ---------- Filter chips ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 16px; border-radius: 99px; background: var(--card);
  color: var(--text); font-size: .85rem; font-weight: 400; letter-spacing: -.01em;
  box-shadow: inset 0 0 0 1px var(--field);
}
.chip.active { background: var(--ink); color: #fff; box-shadow: none; }
.search-box { position: relative; margin-bottom: 14px; }
.search-box .icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--faint); width: 18px; height: 18px; }
.search-box input { padding-left: 42px; background: var(--fill); border-color: transparent; border-radius: 12px; }
.search-box input:focus { background: #fff; }

/* ---------- Attendance ---------- */
.section-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.section-tile {
  background: var(--bg); border-radius: 14px;
  padding: 14px 6px; text-align: center; color: var(--text);
  transition: transform .15s, background .15s;
}
.section-tile:active { transform: scale(.97); }
.section-tile .name { font-size: 1.35rem; font-weight: 700; letter-spacing: -.02em; }
.section-tile .info { font-size: .72rem; color: var(--muted); margin-top: 2px; letter-spacing: 0; }
.section-tile.done { background: var(--good-soft); }
.section-tile.done .name, .section-tile.done .info { color: var(--good); }

.mark-list { list-style: none; margin: 0; padding: 0; }
.mark-list li { position: relative; }
.mark-list li + li::before { content: ""; position: absolute; top: 0; right: 0; left: 70px; height: 1px; background: var(--line); }
.mark-list label {
  display: flex; align-items: center; gap: 12px; margin: 0; padding: 12px 20px; min-height: 62px;
  font-weight: 400; font-size: 1.05rem; cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
}
.mark-list label:active { background: #fafafc; }
.mark-list input { position: absolute; opacity: 0; pointer-events: none; }
.mark-list .name { flex: 1; }
.mark-list .state {
  width: 92px; text-align: center; padding: 6px 0; border-radius: 99px; font-weight: 600; font-size: .82rem; letter-spacing: 0;
  background: var(--good-soft); color: var(--good); transition: background .15s, color .15s;
}
.mark-list .state::after { content: "Present"; }
.mark-list input:checked ~ .state { background: var(--bad); color: #fff; }
.mark-list input:checked ~ .state::after { content: "Absent"; }
.mark-list input:checked ~ .name { color: var(--bad); }
.mark-list input:checked ~ .avatar { background: var(--bad); }
.mark-list input:focus-visible ~ .state { outline: 2px solid var(--brand); }
.sticky-save {
  position: sticky; bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom)); z-index: 5;
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-radius: var(--radius); box-shadow: 0 8px 30px rgba(0, 0, 0, .12);
  padding: 10px 10px 10px 18px; display: flex; align-items: center; gap: 12px;
}
.sticky-save .summary { flex: 1; font-size: .9rem; font-weight: 500; }
@media (min-width: 900px) { .sticky-save { bottom: 20px; } }

/* ---------- Profile ---------- */
.profile-head { display: flex; gap: 16px; align-items: center; }
.profile-head .avatar { width: 64px; height: 64px; font-size: 1.35rem; }
.profile-head h1 { font-size: 1.6rem !important; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 18px; font-size: .95rem; margin: 18px 0 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.pending-box { border-radius: 14px; padding: 16px 18px; margin-top: 18px; background: var(--good-soft); color: var(--good); }
.pending-box.due { background: var(--bad-soft); color: var(--bad); }
.pending-box .big { font-size: 2rem; font-weight: 700; letter-spacing: -.03em; line-height: 1.2; }
.month-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.month-cell { border-radius: 12px; padding: 9px 8px; font-size: .78rem; text-align: center; background: var(--good-soft); color: var(--good); letter-spacing: 0; }
.month-cell b { display: block; font-size: .85rem; font-weight: 600; }
.month-cell.partial { background: var(--warn-soft); color: var(--warn); }
.month-cell.unpaid { background: var(--bad-soft); color: var(--bad); }

/* ---------- Receipt page ---------- */
.receipt-card { text-align: center; padding-top: 28px; }
.receipt-card .tick {
  width: 60px; height: 60px; border-radius: 50%; margin: 0 auto 10px; display: grid; place-items: center;
  background: var(--good); color: #fff;
}
.receipt-card .tick .icon { width: 30px; height: 30px; }
.receipt-card .amount { font-size: 3rem; font-weight: 700; letter-spacing: -.04em; line-height: 1.15; }
.receipt-card .kv { text-align: left; max-width: 420px; margin: 22px auto 0; }
.void-banner { background: var(--bad-soft); color: var(--bad); border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 14px; font-weight: 600; }

/* ---------- Sign in ---------- */
.auth { max-width: 400px; margin: 10vh auto 0; padding: 20px; }
.auth h1 { text-align: center; font-size: 2.2rem; margin-bottom: 6px; }
.auth .sub { text-align: center; color: var(--muted); font-size: 1.1rem; margin-bottom: 28px; }
.auth .card { padding: 26px; }

details summary { cursor: pointer; font-weight: 500; color: var(--link); padding: 4px 0; list-style-position: inside; }
details[open] summary { margin-bottom: 12px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

@media (max-width: 600px) {
  main { padding: 16px; }
  h1 { font-size: 1.85rem; }
  .card { padding: 18px; }
  .card.flush > h2 { padding: 18px 18px 0; }
  .row { padding: 12px 18px; }
  .stat .value { font-size: 1.4rem; }
}

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