:root {
  --bg: #5b3a24;
  --on-bg: #f7ecdb;
  --on-bg-muted: #dcc6a6;
  --bar: #3a2113;
  --surface: #fffaf2;
  --surface-2: #f5eadb;
  --text: #2b1b10;
  --muted: #7d6551;
  --border: #e8d9c4;
  --primary: #e9a73a;
  --primary-ink: #2b1b10;
  --primary-soft: #fbe7c2;
  --danger: #b8382c;
  --danger-soft: #fbe1dd;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(43, 27, 16, .10), 0 6px 18px rgba(43, 27, 16, .18);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #22150c;
    --on-bg: #f2e4cd;
    --on-bg-muted: #bba486;
    --bar: #160d07;
    --surface: #2e1f14;
    --surface-2: #3a291b;
    --text: #f3e9dc;
    --muted: #b8a48e;
    --border: #4b3726;
    --primary: #f0b24a;
    --primary-ink: #22150c;
    --primary-soft: #4a3519;
    --danger: #f06b60;
    --danger-soft: #4a1f1a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 6px 18px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #22150c;
  --on-bg: #f2e4cd;
  --on-bg-muted: #bba486;
  --bar: #160d07;
  --surface: #2e1f14;
  --surface-2: #3a291b;
  --text: #f3e9dc;
  --muted: #b8a48e;
  --border: #4b3726;
  --primary: #f0b24a;
  --primary-ink: #22150c;
  --primary-soft: #4a3519;
  --danger: #f06b60;
  --danger-soft: #4a1f1a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 6px 18px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; line-height: 1.25; }
h2 { font-size: 17px; }
a { color: inherit; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.center { text-align: center; }
.err { color: var(--danger); font-size: 13px; margin: 6px 0 0; min-height: 0; }
.err:empty { display: none; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 999px; padding: 11px 20px;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  min-height: 44px;
}
.btn-sm { padding: 6px 14px; min-height: 34px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-ghost { background: var(--surface-2); color: var(--text); }
.btn-ghost-bar { background: rgba(255, 255, 255, .12); color: var(--on-bg); }
.btn-danger { background: var(--danger); color: #fff; }
.btn:disabled { opacity: .6; cursor: default; }
.icon-btn {
  border: 0; background: transparent; color: inherit; cursor: pointer;
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-size: 18px;
}
.icon-btn.small { width: 34px; height: 34px; font-size: 15px; }
.icon-btn:active { background: rgba(255, 255, 255, .12); }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Welcome */
.welcome {
  min-height: 100vh; padding: calc(32px + env(safe-area-inset-top)) 16px 32px;
  display: flex; flex-direction: column; align-items: center; color: var(--on-bg); text-align: center;
}
.welcome-logo { width: 120px; height: 120px; margin-bottom: 12px; }
.welcome h1 { font-size: 26px; color: var(--primary); }
.welcome-sub { margin: 6px 0 22px; color: var(--on-bg-muted); max-width: 320px; }
.card {
  background: var(--surface); color: var(--text); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.welcome-card { width: 100%; max-width: 420px; text-align: left; }
fieldset { border: 0; margin: 0 0 18px; padding: 0; }
legend { font-weight: 700; margin-bottom: 8px; padding: 0; }
.choice-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice { position: relative; cursor: pointer; }
.choice input { position: absolute; opacity: 0; inset: 0; }
.choice span {
  display: block; text-align: center; padding: 12px 8px; border-radius: 12px;
  border: 2px solid var(--border); background: var(--surface-2); font-weight: 600;
}
.choice input:checked + span { border-color: var(--primary); background: var(--primary-soft); }
.choice input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px 16px;
  background: var(--bar); color: var(--on-bg);
}
.topbar-logo { width: 36px; height: 36px; flex: none; }
.topbar-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.topbar-title strong { color: var(--primary); font-size: 16px; }
.on-bar-muted { color: var(--on-bg-muted); }
.link-chip {
  align-self: flex-start; border: 0; background: none; padding: 2px 0; font: inherit; font-size: 12px;
  color: var(--on-bg-muted); cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
}

.install-bar {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px 10px 16px;
  background: var(--primary-soft); color: var(--text); font-size: 13px;
}
.install-bar span { flex: 1; }

/* Feed */
.feed-wrap { max-width: 680px; margin: 0 auto; padding: 14px 16px 24px; }
.toolbar { display: grid; gap: 10px; margin-bottom: 6px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; width: 100%;
}
textarea { resize: vertical; }
#search { border-radius: 999px; padding-left: 16px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid rgba(255, 255, 255, .2); background: rgba(255, 255, 255, .08);
  color: var(--on-bg); border-radius: 999px; padding: 6px 14px; font: inherit; font-size: 13px; cursor: pointer;
}
.chip[aria-selected="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }
.status { color: var(--on-bg-muted); font-size: 12px; margin: 4px 2px 10px; min-height: 18px; }

.feed { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.post {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; cursor: pointer; border-left: 5px solid transparent; position: relative;
}
.post:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.post.unread { border-left-color: var(--primary); }
.post.urgent { border-left-color: var(--danger); }
.post-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.post h3 { margin: 0 0 4px; font-size: 16px; line-height: 1.3; }
.post .excerpt {
  margin: 0; color: var(--muted); font-size: 14px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.meta { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.cat {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted);
}
.cat.urgent { background: var(--danger-soft); color: var(--danger); }
.cat.events, .cat.academics { background: var(--primary-soft); color: var(--text); }
.badge {
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  background: var(--primary); color: var(--primary-ink);
}
.pin { font-size: 12px; color: var(--muted); }
.empty { text-align: center; color: var(--on-bg-muted); padding: 40px 10px; }
.empty p { margin: 4px 0; }
.foot {
  text-align: center; font-size: 12px; color: var(--on-bg-muted);
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
}

/* Sheets (dialogs) */
dialog.sheet {
  border: 0; padding: 0; border-radius: 18px; width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - 48px); background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
dialog.sheet::backdrop { background: rgba(20, 10, 4, .6); }
dialog.sheet > article, dialog.sheet > form { padding: 18px 18px 20px; display: grid; gap: 12px; }
.small-sheet { width: min(380px, calc(100vw - 24px)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sheet h2 { font-size: 20px; }
.sheet .meta { margin: -6px 0 0; }
.body-text { white-space: pre-wrap; word-wrap: break-word; font-size: 15px; }
.body-text a { color: var(--primary); }
@media (prefers-color-scheme: light) { .body-text a { color: #8a5a10; } }
#dLinkWrap { margin: 0; }

/* Forms */
.field { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.field > input, .field > select, .field > textarea { font-weight: 400; color: var(--text); }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 420px) { .grid-2 { grid-template-columns: 1fr; } }
.row-btns { display: flex; gap: 10px; flex-wrap: wrap; }
#postForm, #loginForm { display: grid; gap: 12px; margin-bottom: 16px; }
.narrow { max-width: 400px; margin: 24px auto; }
.admin-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
.admin-list li {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--border);
}
.admin-list .info { flex: 1; min-width: 0; }
.admin-list .info strong { display: block; overflow-wrap: anywhere; }
.admin-list .actions { display: flex; gap: 6px; flex: none; }
.expired { opacity: .6; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--bar); color: var(--on-bg); padding: 10px 18px; border-radius: 999px;
  box-shadow: var(--shadow); font-size: 14px; z-index: 20; max-width: calc(100vw - 32px);
}

/* Registration */
.welcome-card h2 { margin-bottom: 14px; }
#welcomeForm { display: grid; gap: 4px; }
#regFields { display: grid; gap: 12px; margin-bottom: 8px; }
#regFields fieldset { margin: 0; }
.reg-group { display: grid; gap: 12px; }
.consent { align-items: flex-start; font-size: 13px; color: var(--muted); }
.consent input { flex: none; margin-top: 2px; }
.install-card { margin-bottom: 14px; display: grid; gap: 6px; justify-items: start; }
.install-card p { margin: 0; color: var(--muted); }
.info-list { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
.info-list dt { color: var(--muted); font-size: 13px; }
.info-list dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.reg-card { margin-top: 16px; display: grid; gap: 10px; }
.reg-card h2 { margin: 0; }

/* Bilingual install instructions: Tagalog line under the English one */
.tl { display: block; font-style: italic; font-weight: 400; color: var(--muted); margin-top: 1px; }
.install-title .tl { font-size: 13px; }
.install-bar .tl { color: var(--muted); }
.install-steps { margin: 4px 0 2px; padding-left: 20px; display: grid; gap: 8px; font-size: 13px; }
.install-note { margin: 2px 0 0; color: var(--muted); }

/* Enrollment check */
.reg-intro { margin: -8px 0 10px; }
.notice {
  margin: 0 0 12px; padding: 10px 12px; border-radius: 10px; font-size: 13px;
  background: var(--primary-soft); color: var(--text);
}
.hint { font-weight: 400; color: var(--muted); }
.farewell-card { text-align: center; display: grid; gap: 10px; }
.farewell-card p { margin: 0; }
.farewell-icon { font-size: 44px; line-height: 1; }
.pill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; vertical-align: middle; }
.pill-grad { background: var(--primary-soft); color: var(--text); }
.pill-old { background: var(--surface-2); color: var(--muted); }
#syInfo { margin: 0; }
#syLive { margin: 0; }

/* Approvals */
.row-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.row-head h2 { display: flex; align-items: center; gap: 8px; }
.pending-card { margin: 0 0 16px; border-top: 4px solid var(--primary); }
.pending-card > p { margin: 0; }
.pill-ok { background: #dff3e0; color: #1e6b22; }
.pill-warn { background: var(--danger-soft); color: var(--danger); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .pill-ok { background: #1f3a21; color: #8fe093; } }
:root[data-theme="dark"] .pill-ok { background: #1f3a21; color: #8fe093; }
.admin-list .info .tiny { display: block; }
.wait-details { text-align: left; background: var(--surface-2); padding: 10px 12px; border-radius: 10px; font-size: 13px; }
@media (max-width: 420px) { .admin-list li { flex-wrap: wrap; } .admin-list .actions { width: 100%; } }

.name-note { margin: 2px 0 -6px; font-weight: 600; }

/* Locked fields when a parent edits their registration */
.identity-locked input:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }
.identity-locked .choice input:disabled + span { opacity: .55; cursor: not-allowed; }
.identity-locked .choice input:disabled:checked + span { opacity: 1; }

#adminMode:not(:empty)::before { content: "· "; }
#adminWho:empty + #adminMode::before { content: ""; }
select:disabled { background: var(--surface-2); color: var(--muted); }

/* Admin tabs */
.admin-tabs-wrap { display: flex; align-items: center; gap: 8px; margin: 0 0 14px; }
.admin-tabs { display: flex; gap: 6px; overflow-x: auto; flex: 1; scrollbar-width: none; padding-bottom: 2px; }
.admin-tabs::-webkit-scrollbar { display: none; }
.admin-tabs button {
  flex: none; border: 1px solid rgba(255, 255, 255, .2); background: rgba(255, 255, 255, .08); color: var(--on-bg);
  border-radius: 999px; padding: 8px 14px; font: inherit; font-size: 14px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px;
}
.admin-tabs button[aria-selected="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 700; }
.admin-tabs button[aria-selected="true"] .badge { background: var(--primary-ink); color: var(--primary); }
#adminPanel [data-panel] > .card + .card, #adminPanel [data-panel] > form + .card { margin-top: 16px; }

/* Dashboard */
.dash-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
@media (max-width: 700px) { .dash-cards { grid-template-columns: 1fr 1fr; } }
.dash-stat {
  background: var(--surface); color: var(--text); border: 0; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; text-align: left; font: inherit; display: grid; gap: 2px;
}
.dash-stat.clickable { cursor: pointer; }
.dash-stat.clickable:hover { outline: 2px solid var(--primary); }
.dash-num { font-size: 28px; font-weight: 800; line-height: 1.1; color: var(--text); }
.dash-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.dash-card-wide h2 { margin-bottom: 10px; }
.table-scroll { overflow-x: auto; }
.dash-table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.dash-table th, .dash-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
.dash-table th:first-child { text-align: left; }
.dash-table thead th { font-size: 12px; font-weight: 600; color: var(--muted); }
.dash-table tbody th { font-weight: 600; }
.dash-total th, .dash-total td { font-weight: 700; border-bottom: 0; }
.dash-pending { color: var(--danger); }
#dashNote { margin: 10px 0 0; }
#dashActivity li { padding: 8px 0; }
#dashActivity .info span:first-child { font-size: 14px; }

.admin-link { margin-top: 18px; font-size: 13px; color: var(--on-bg-muted); text-underline-offset: 3px; }

/* Board: a filter is hiding some posts */
.filter-note {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  background: var(--primary-soft); color: var(--text); border-radius: 12px; padding: 8px 8px 8px 14px;
  margin: 0 0 12px; font-size: 13px; font-weight: 600;
}
/* Admin: who will see this post */
.post-who { margin: 0; }
.post-who.warn { background: var(--danger-soft); color: var(--danger); }

.reach { display: block; font-weight: 600; color: var(--text); }
.reach-none { color: var(--danger); }

/* Main admin: campus menu above the announcement list */
.campus-menu { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 6px; }
.campus-menu button {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; min-height: 34px;
}
.campus-menu button[aria-selected="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 700; }
.campus-menu .count { font-size: 11px; font-weight: 700; opacity: .75; font-variant-numeric: tabular-nums; }
.link-btn {
  border: 0; background: none; padding: 2px 6px; font: inherit; color: inherit; cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px; font-variant-numeric: tabular-nums;
}

.audience-menu { padding-top: 6px; border-top: 1px dashed var(--border); }
.audience-menu button { min-height: 30px; padding: 4px 10px; font-size: 12px; }

/* School year form, list upload, admins, passcodes */
#syForm { margin-top: 6px; align-items: end; }
#syForm .sy-help, #syForm .err, #syForm .row-btns { grid-column: 1 / -1; margin: 0; }
#enrollText { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; white-space: pre; }
.file-btn { cursor: pointer; }
.pass-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.pass-list li { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 8px 10px;
  background: var(--surface-2); border-radius: 10px; font-size: 14px; }
.pass-list code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700; font-size: 15px; user-select: all; }
#adminForm { display: grid; gap: 12px; margin-top: 16px; }

/* Photos */
.avatar {
  flex: none; width: 44px; height: 44px; border-radius: 50%; overflow: hidden; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--text); font: inherit; font-weight: 700; font-size: 14px;
  border: 2px solid var(--border); padding: 0;
}
button.avatar:not([disabled]) { cursor: zoom-in; }
button.avatar:not([disabled]):hover { border-color: var(--primary); }
button.avatar[disabled] { cursor: default; opacity: .85; }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-lg { width: 88px; height: 88px; font-size: 28px; }
#profilePhoto { justify-self: center; }
.photo-field { gap: 8px; }
.photo-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.photo-btns { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.photo-big { width: 100%; max-width: 320px; aspect-ratio: 1; object-fit: cover; border-radius: 14px; justify-self: center; }
.admin-list li { align-items: center; }

/* Users tab download buttons */
.export-btns { gap: 6px; }

/* Printable photo roster */
.roster { position: fixed; inset: 0; z-index: 30; background: var(--bg); overflow: auto; }
body.roster-open { overflow: hidden; }
.roster-bar {
  position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  flex-wrap: wrap; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--bar); color: var(--on-bg);
}
.roster-body { max-width: 1000px; margin: 0 auto; padding: 16px; display: grid; gap: 22px; }
.roster-group h2 { color: var(--on-bg); font-size: 18px; margin: 0 0 10px; display: flex; gap: 8px; align-items: baseline; }
.roster-group h2 span { font-size: 13px; font-weight: 600; opacity: .75; }
.roster-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.roster-card {
  background: var(--surface); color: var(--text); border-radius: 12px; padding: 12px 10px; text-align: center;
  display: grid; justify-items: center; gap: 2px; font-size: 12px; break-inside: avoid;
}
.roster-card strong { font-size: 13px; line-height: 1.25; margin-top: 4px; }
.roster-card span { color: var(--muted); }
.roster-photo { width: 96px; height: 96px; font-size: 30px; }
.roster-parent { font-size: 11px; }
.roster-status { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.roster-status.s-pending, .roster-status.s-rejected { color: var(--danger) !important; }

@media print {
  body.roster-open > :not(#roster) { display: none !important; }
  body.roster-open { background: #fff; overflow: visible; }
  .roster { position: static; background: #fff; overflow: visible; }
  .roster-bar .row-btns { display: none; }
  .roster-bar { position: static; background: #fff; color: #000; padding: 0 0 8px; border-bottom: 2px solid #000; }
  .roster-body { padding: 8px 0; max-width: none; }
  .roster-group { break-before: page; }
  .roster-group:first-child { break-before: auto; }
  .roster-group h2 { color: #000; }
  .roster-card { background: #fff; color: #000; border: 1px solid #bbb; }
  .roster-card span { color: #333; }
  .roster-grid { grid-template-columns: repeat(5, 1fr); }
}

/* Notifications */
.push-bar { background: var(--primary-soft); border-top: 1px solid var(--border); }
.push-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; border-radius: 10px; background: var(--surface-2); font-size: 14px; font-weight: 600; }
