:root {
  --bg: #f6f2ec;
  --surface: #ffffff;
  --surface-2: #faf7f2;
  --text: #2a2024;
  --muted: #6b5f63;
  --line: #e6ddd0;
  --brand: #7a2e3b;
  --brand-strong: #5e1f2b;
  --brand-soft: #f6e6e8;
  --on-brand: #ffffff;
  --good: #1f6f4a;
  --good-soft: #e1f2e8;
  --warn: #9a5b00;
  --warn-soft: #fdf0d8;
  --bad: #b42318;
  --bad-soft: #fde5e2;
  --shadow: 0 1px 2px rgba(42, 32, 36, .06), 0 4px 14px rgba(42, 32, 36, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141016;
    --surface: #1f1a21;
    --surface-2: #19151b;
    --text: #f2ecee;
    --muted: #b3a7ac;
    --line: #362d33;
    --brand: #e3909c;
    --brand-strong: #f0aeb8;
    --brand-soft: #3a242b;
    --on-brand: #2a1218;
    --good: #7fd4a6;
    --good-soft: #16301f;
    --warn: #f4c95d;
    --warn-soft: #3a2e12;
    --bad: #ff8a80;
    --bad-soft: #3d1a17;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  font-size: 16px; line-height: 1.45;
  background: var(--bg); color: var(--text);
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: var(--brand); }
h2 { font-size: 1.05rem; margin: 0 0 .4em; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pad { padding: 14px 16px; margin: 0; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

/* Top bar & tab bar */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px; background: var(--brand); color: var(--on-brand);
}
.topbar h1 { font-size: 1.2rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: rgba(255, 255, 255, .18); color: inherit; border: 0; border-radius: 999px; padding: 6px 14px; font: inherit; font-weight: 600; }
#view { max-width: 640px; margin: 0 auto; padding: 14px 12px; outline: none; }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 10px; min-height: 60px;
  font-size: .72rem; font-weight: 600; color: var(--muted); text-decoration: none;
}
.tabbar a span { font-size: 1.25rem; line-height: 1.2; }
.tabbar a.active { color: var(--brand); }
.tabbar .tab-pay span {
  display: grid; place-items: center; width: 38px; height: 38px; margin-top: -16px; border-radius: 50%;
  background: var(--brand); color: var(--on-brand); font-size: 1.5rem; box-shadow: 0 4px 12px rgba(122, 46, 59, .35);
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 10px 18px;
  border-radius: 12px; border: 2px solid var(--brand); background: var(--brand); color: var(--on-brand);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn-ghost { background: transparent; color: var(--brand); }
.btn-small { min-height: 36px; padding: 6px 12px; font-size: .9rem; border-radius: 10px; }
.link-danger { background: none; border: 0; color: var(--bad); font: inherit; font-weight: 600; padding: 10px 0; cursor: pointer; text-decoration: underline; }

/* Cards & rows */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); margin-bottom: 14px; overflow: hidden; }
.pad-card { padding: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; padding: 14px 16px 6px; }
.card-head h2 { margin: 0; }
.card-head a { font-weight: 600; font-size: .9rem; text-decoration: none; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line);
  color: var(--text); text-decoration: none; flex-wrap: wrap;
}
.card-head + .row, .day + .row { border-top: 0; }
#s-list .row:first-child { border-top: 0; }
a.row:active { background: var(--surface-2); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-main strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-main small { color: var(--muted); }
.row-icon { font-size: 1.3rem; }
.row-amt { font-weight: 700; font-variant-numeric: tabular-nums; }
.row-amt.warn { color: var(--warn); }
.row-actions { display: flex; gap: 8px; width: 100%; justify-content: flex-end; }
.avatar {
  display: grid; place-items: center; width: 40px; height: 40px; flex: none; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand); font-weight: 700;
}
.avatar.big { width: 56px; height: 56px; font-size: 1.4rem; }
.day { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0; padding: 12px 16px 4px; }

.chip { display: inline-block; font-size: .75rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.chip-paid { background: var(--good-soft); color: var(--good); }
.chip-partial { background: var(--warn-soft); color: var(--warn); }
.chip-due { background: var(--bad-soft); color: var(--bad); }
.chip-nofee, .chip-off { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }

/* Home */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.stat { border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 2px; border: 1px solid var(--line); }
.stat small { font-size: .8rem; color: var(--muted); font-weight: 600; }
.stat strong { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: .85rem; color: var(--muted); }
.stat-good { background: var(--good-soft); } .stat-good strong { color: var(--good); }
.stat-warn { background: var(--warn-soft); } .stat-warn strong { color: var(--warn); }
.all-paid { padding: 10px 16px 16px; margin: 0; font-weight: 600; color: var(--good); }
.tip { padding: 16px; background: var(--brand-soft); border-color: transparent; }
.hello { text-align: center; padding: 40px 20px; }
.hello h2 { font-size: 1.5rem; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty-icon { font-size: 2.6rem; margin-bottom: 8px; }

/* Lists & filters */
.toolbar, .filters { display: flex; gap: 10px; margin-bottom: 14px; }
.filters { flex-wrap: wrap; }
.filters select { flex: 1 1 45%; }
.filters input { flex: 1 1 100%; }
.toolbar input { flex: 1; }
.summary {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--brand); color: var(--on-brand); border-radius: 16px; padding: 14px 16px; margin-bottom: 14px;
}
.summary small { display: block; opacity: .85; font-weight: 600; }
.summary strong { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.split { display: flex; gap: 12px; font-size: .85rem; font-weight: 600; flex-wrap: wrap; }

/* Student profile */
.profile { padding: 16px; }
.profile-head { display: flex; gap: 14px; align-items: center; margin-bottom: 12px; }
.profile-head h2 { font-size: 1.3rem; margin: 0; }
.profile-head p { margin: 0; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin: 0 0 12px; }
.facts dt { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.facts dd { margin: 0; font-weight: 600; }
.notes { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.months { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; padding: 6px 16px 16px; }
.month { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; padding: 10px; border: 1px solid var(--line); border-radius: 12px; }
.month span { font-size: .85rem; font-weight: 600; }
.month small { color: var(--muted); }

/* Forms */
.form { padding: 16px; display: grid; gap: 14px; }
.form h2 { margin: 0; }
.field { display: grid; gap: 6px; border: 0; padding: 0; margin: 0; min-width: 0; }
.field > span, legend { font-weight: 600; font-size: .9rem; padding: 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface-2); width: 100%; min-height: 46px;
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: flex; align-items: center; justify-content: center; min-height: 46px; padding: 6px; text-align: center;
  border: 1px solid var(--line); border-radius: 12px; font-weight: 600; font-size: .9rem; background: var(--surface-2); cursor: pointer;
}
.seg input:checked + span { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.seg input:focus-visible + span { outline: 3px solid var(--brand); outline-offset: 2px; }
.switch { display: flex; gap: 10px; align-items: center; font-weight: 500; }
.switch input { width: 22px; height: 22px; min-height: 0; accent-color: var(--brand); }
.hint { margin: 0; font-size: .9rem; color: var(--muted); }
.hint:empty { display: none; }
.form-error { color: var(--bad); font-weight: 600; margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.form .actions .btn { flex: 1; }

/* Toast */
.toast {
  position: fixed; left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 20; max-width: 560px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--text); color: var(--bg); border-radius: 12px; padding: 12px 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); font-weight: 500;
}
.toast button { background: none; border: 0; color: var(--brand-soft); font: inherit; font-weight: 700; text-decoration: underline; white-space: nowrap; cursor: pointer; }

@media (max-width: 360px) {
  .two, .stats { grid-template-columns: 1fr; }
}

/* Top bar actions */
.top-actions { display: flex; gap: 8px; align-items: center; }
.top-actions a.icon-btn { text-decoration: none; padding: 6px 10px; }

/* PIN lock */
body.locked .topbar, body.locked .tabbar, body.locked #view, body.locked .toast { display: none !important; }
.lock { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.lock-box { width: 100%; max-width: 320px; display: grid; gap: 12px; text-align: center; justify-items: center; }
.lock-box img { border-radius: 18px; }
.lock-box h2 { font-size: 1.4rem; margin: 6px 0 0; }
.lock-box p { margin: 0; }
.lock-box input { text-align: center; font-size: 1.6rem; letter-spacing: .5em; }
.lock-box input::placeholder { letter-spacing: normal; font-size: 1.1rem; }
.lock-box .btn { width: 100%; }
.link-muted { background: none; border: 0; color: var(--muted); font: inherit; text-decoration: underline; padding: 8px; cursor: pointer; }

/* Attendance */
.att-tabs { margin-bottom: 14px; }
.seg-2 { grid-template-columns: 1fr 1fr; }
.seg-2 a {
  display: flex; align-items: center; justify-content: center; min-height: 44px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--text); font-weight: 600; text-decoration: none;
}
.seg-2 a.on { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.daybar { display: grid; grid-template-columns: 48px 1fr 48px; gap: 8px; align-items: center; margin-bottom: 12px; }
.daybar .btn { font-size: 1.4rem; padding: 0; min-height: 46px; }
.daybar input { text-align: center; font-weight: 600; }
.btn-spacer { display: block; }
.att-summary { display: flex; gap: 16px; flex-wrap: wrap; font-size: .9rem; color: var(--muted); margin-bottom: 10px; }
.att-summary strong { color: var(--text); font-size: 1.05rem; }
.att-summary .warn strong { color: var(--warn); }
.att-bulk { margin-bottom: 12px; }
.att-row { flex-wrap: nowrap; }
.pa { display: flex; gap: 6px; flex: none; }
.pa button {
  min-height: 40px; min-width: 76px; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--muted); font: inherit; font-size: .85rem; font-weight: 700; cursor: pointer;
}
.pa .pa-p.on { background: var(--good); border-color: var(--good); color: #fff; }
.pa .pa-a.on { background: var(--bad); border-color: var(--bad); color: #fff; }
@media (prefers-color-scheme: dark) { .pa .pa-p.on, .pa .pa-a.on { color: #141016; } }
.att-line { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; padding-top: 4px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; padding: 4px 16px 0; text-align: center; }
.cal-h { font-size: .7rem; font-weight: 700; color: var(--muted); }
.cal-d {
  display: grid; place-items: center; aspect-ratio: 1; border-radius: 8px; font-size: .85rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted); text-decoration: none;
}
.cal-p { background: var(--good-soft); color: var(--good); }
.cal-a { background: var(--bad-soft); color: var(--bad); }
.cal-today { outline: 2px solid var(--brand); outline-offset: -2px; }
.cal-key { display: flex; gap: 6px; align-items: center; padding-top: 10px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.dot-p { background: var(--good); } .dot-a { background: var(--bad); margin-left: 8px; }
.bar { flex: 0 0 70px; height: 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--good); }
.top-gap { margin-top: 10px; }
@media (max-width: 380px) { .pa button { min-width: 64px; padding: 6px; } }
