/* =========================================================
   Brightwood Portal — dashboards for parents, teachers, office staff and admins
   Layout: dark navy sidebar (matches the website footer) + light work surface,
   12-column widget grid. Brand tokens shared with the public website.
   ========================================================= */
:root {
  --brand: #1565c0;
  --brand-2: #1ea7e1;
  --accent: #f0563a;
  --accent-2: #f7a531;
  --grad: linear-gradient(90deg, #1ea7e1, #1565c0);

  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-2: #f6f9fd;
  --line: #e2e8f1;
  --ink: #16213a;
  --text: #46536b;
  --muted: #8791a5;
  --hover: #eef4fb;

  --side: #0e1730;
  --side-ink: #c9d2e3;
  --side-muted: #7684a0;
  --side-hover: rgba(255,255,255,.06);

  --good: #1b8a4b; --good-bg: #e7f6ed;
  --warn: #b26a00; --warn-bg: #fff3dc;
  --bad: #c62828;  --bad-bg: #fdebea;
  --info: #1565c0; --info-bg: #e8f1fc;

  --sk: #e7edf5;
  --sk-hi: #f4f7fb;

  --font-head: "Poppins", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 30, 60, .04), 0 6px 20px rgba(16, 30, 60, .05);
  --sb-w: 252px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1222; --surface: #121b30; --surface-2: #17213a; --line: #24304a;
    --ink: #edf2fb; --text: #b4bfd3; --muted: #7d8aa5; --hover: #1a2541;
    --side: #080e1c; --side-hover: rgba(255,255,255,.05);
    --good: #4cc887; --good-bg: rgba(76,200,135,.14);
    --warn: #f5b74f; --warn-bg: rgba(245,183,79,.14);
    --bad: #ff7a70;  --bad-bg: rgba(255,122,112,.14);
    --info: #6cb8ff; --info-bg: rgba(108,184,255,.14);
    --sk: #1b263f; --sk-hi: #24314f;
    --brand: #4c9dff;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1222; --surface: #121b30; --surface-2: #17213a; --line: #24304a;
  --ink: #edf2fb; --text: #b4bfd3; --muted: #7d8aa5; --hover: #1a2541;
  --side: #080e1c; --side-hover: rgba(255,255,255,.05);
  --good: #4cc887; --good-bg: rgba(76,200,135,.14);
  --warn: #f5b74f; --warn-bg: rgba(245,183,79,.14);
  --bad: #ff7a70;  --bad-bg: rgba(255,122,112,.14);
  --info: #6cb8ff; --info-bg: rgba(108,184,255,.14);
  --sk: #1b263f; --sk-hi: #24314f;
  --brand: #4c9dff;
  --shadow: 0 1px 2px rgba(0,0,0,.3);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.55 var(--font-body); -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4 { font-family: var(--font-head); color: var(--ink); margin: 0; line-height: 1.25; text-wrap: balance; }
a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--brand-2); outline-offset: 2px; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: var(--sb-w) minmax(0, 1fr); min-height: 100%; }
.sb { position: sticky; top: 0; height: 100vh; background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; padding: 20px 14px calc(16px + env(safe-area-inset-bottom, 0px)) max(14px, env(safe-area-inset-left, 0px)); overflow-y: auto; z-index: 40; }
.sb-logo { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: #fff; font: 600 1.25rem var(--font-head); }
.sb-logo svg { width: 32px; height: 32px; flex: none; }
.sb-logo small { display: block; font: 500 .68rem var(--font-body); letter-spacing: .14em; text-transform: uppercase; color: var(--side-muted); }
.sb-role { margin: 0 6px 18px; padding: 10px 12px; border-radius: 12px; background: rgba(255,255,255,.05); display: flex; gap: 10px; align-items: center; }
.sb-role .av { width: 34px; height: 34px; font-size: .8rem; }
.sb-role div strong { display: block; color: #fff; font-size: .86rem; font-weight: 600; }
.sb-role div span { font-size: .74rem; color: var(--side-muted); }
.sb-label { font: 600 .68rem var(--font-body); letter-spacing: .14em; text-transform: uppercase; color: var(--side-muted); padding: 10px 12px 6px; }
.sb nav { display: grid; gap: 2px; }
.sb-link { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--side-ink); font-weight: 500; border: 0; background: none; width: 100%; text-align: left; transition: background .15s, color .15s; }
.sb-link svg { width: 18px; height: 18px; flex: none; opacity: .8; }
.sb-link:hover { background: var(--side-hover); color: #fff; }
.sb-link.active { background: var(--grad); color: #fff; box-shadow: 0 6px 16px rgba(21,101,192,.35); }
.sb-link.active svg { opacity: 1; }
.sb-link .badge { margin-left: auto; min-width: 22px; height: 20px; padding: 0 7px; border-radius: 999px; background: var(--accent); color: #fff; font: 600 .7rem/20px var(--font-body); text-align: center; }
.sb-foot { margin-top: auto; padding-top: 18px; display: grid; gap: 2px; border-top: 1px solid rgba(255,255,255,.07); }

.main { min-width: 0; display: flex; flex-direction: column; }
.tb { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 30; display: flex; align-items: center; gap: 12px; height: 68px; padding-left: max(24px, env(safe-area-inset-left, 0px)); padding-right: max(24px, env(safe-area-inset-right, 0px)); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 50; background: var(--bg); }
.tb-menu { display: none; }
.tb-search { flex: 1; max-width: 420px; position: relative; }
.tb-search input { width: 100%; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); padding: 0 14px 0 38px; }
.tb-search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); }
.tb-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.icon-btn { position: relative; width: 40px; height: 40px; border-radius: 10px; border: 1px solid transparent; background: none; display: grid; place-items: center; color: var(--text); }
.icon-btn:hover { background: var(--surface); border-color: var(--line); }
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn .dot { position: absolute; top: 8px; right: 9px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg); }
.icon-btn.spin svg { animation: spin .8s linear; }
@keyframes spin { to { transform: rotate(360deg); } }
.me { display: flex; align-items: center; gap: 10px; padding: 4px 8px 4px 4px; border-radius: 12px; border: 1px solid transparent; background: none; }
.me:hover { background: var(--surface); border-color: var(--line); }
.me div strong { display: block; color: var(--ink); font-size: .86rem; text-align: left; }
.me div span { display: block; font-size: .74rem; color: var(--muted); text-align: left; }

.av { width: 38px; height: 38px; border-radius: 50%; background: var(--grad); color: #fff; display: grid; place-items: center; font: 600 .82rem var(--font-head); flex: none; }
.av.warm { background: linear-gradient(135deg, var(--accent-2), var(--accent)); }
.av.green { background: linear-gradient(135deg, #43a047, #1ea7e1); }
.av.sm { width: 30px; height: 30px; font-size: .7rem; }

/* Dropdowns */
.pop { position: absolute; right: 0; top: calc(100% + 8px); width: 340px; max-width: calc(100vw - 32px); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 18px 50px rgba(10,20,40,.18); padding: 8px; z-index: 60; }
.pop h4 { font-size: .9rem; padding: 8px 10px; display: flex; justify-content: space-between; align-items: center; }
.pop h4 button { border: 0; background: none; color: var(--brand); font-size: .78rem; font-weight: 600; }
.pop-item { display: flex; gap: 10px; padding: 10px; border-radius: 10px; color: var(--text); width: 100%; border: 0; background: none; text-align: left; align-items: flex-start; }
.pop-item:hover { background: var(--hover); }
.pop-item strong { display: block; color: var(--ink); font-size: .86rem; font-weight: 600; }
.pop-item span { font-size: .78rem; color: var(--muted); }
.pop-item .unread { width: 8px; height: 8px; border-radius: 50%; background: var(--brand-2); margin-top: 6px; flex: none; }
.pop-item .read { width: 8px; flex: none; }
.rel { position: relative; }

/* ---------- Content ---------- */
.content { padding-block: 26px 48px; padding-left: max(24px, env(safe-area-inset-left, 0px)); padding-right: max(24px, env(safe-area-inset-right, 0px)); width: 100%; max-width: 1440px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head .crumbs { font-size: .78rem; color: var(--muted); margin-bottom: 4px; letter-spacing: .02em; }
.page-head h1 { font-size: 1.6rem; font-weight: 600; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.ph-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 18px; align-items: start; }
.s-2 { grid-column: span 2; } .s-3 { grid-column: span 3; } .s-4 { grid-column: span 4; } .s-5 { grid-column: span 5; }
.s-6 { grid-column: span 6; } .s-7 { grid-column: span 7; } .s-8 { grid-column: span 8; } .s-12 { grid-column: span 12; }

.w { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; min-width: 0; box-shadow: var(--shadow); }
.w.flush { padding: 0; overflow: hidden; }
.w.flush .w-h { padding: 18px 20px 0; }
.w-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; min-height: 24px; }
.w-h h3 { font-size: .98rem; font-weight: 600; }
.w-h .sub { font-size: .78rem; color: var(--muted); font-weight: 400; margin-left: 6px; font-family: var(--font-body); }
.link-btn { border: 0; background: none; color: var(--brand); font-weight: 600; font-size: .82rem; padding: 4px 0; white-space: nowrap; }
.link-btn:hover { text-decoration: underline; }
.loaded { animation: fadeIn .35s ease; }
@keyframes fadeIn { from { opacity: .35; } to { opacity: 1; } }

/* Context bar (child switcher etc.) */
.ctx { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.ctx-btn { display: flex; align-items: center; gap: 10px; padding: 8px 14px 8px 8px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); text-align: left; min-width: 0; }
.ctx-btn div strong { display: block; color: var(--ink); font-size: .9rem; }
.ctx-btn div span { font-size: .76rem; color: var(--muted); }
.ctx-btn.active { border-color: var(--brand-2); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-2) 22%, transparent); }

/* ---------- Buttons, pills, inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 600; font-size: .84rem; white-space: nowrap; transition: .15s; }
.btn:hover { border-color: var(--brand-2); color: var(--brand); }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--grad); color: #fff; border-color: transparent; box-shadow: 0 6px 16px rgba(21,101,192,.25); }
.btn.primary:hover { color: #fff; filter: brightness(1.05); }
.btn.sm { height: 30px; padding: 0 11px; font-size: .76rem; border-radius: 8px; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.pill { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px; border-radius: 999px; font-size: .72rem; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.pill.plain::before { display: none; }
.pill.good { background: var(--good-bg); color: var(--good); border-color: transparent; }
.pill.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.pill.info { background: var(--info-bg); color: var(--info); border-color: transparent; }

.field { display: grid; gap: 6px; }
.field label { font-size: .78rem; font-weight: 600; color: var(--ink); }
.input, .field input, .field select, .field textarea { width: 100%; min-height: 40px; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); }
.field textarea { resize: vertical; min-height: 90px; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { outline: 0; border-color: var(--brand-2); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-2) 20%, transparent); background: var(--surface); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }

/* Segmented control */
.seg { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); gap: 2px; }
.seg button { border: 0; background: none; height: 30px; padding: 0 12px; border-radius: 8px; font-weight: 600; font-size: .78rem; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* ---------- KPI ---------- */
.kpi { display: grid; gap: 4px; position: relative; }
.kpi-l { font-size: .78rem; font-weight: 500; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.kpi-l .ic { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--info-bg); color: var(--info); }
.kpi-l .ic svg { width: 15px; height: 15px; }
.kpi-l .ic.warn { background: var(--warn-bg); color: var(--warn); }
.kpi-l .ic.bad { background: var(--bad-bg); color: var(--bad); }
.kpi-l .ic.good { background: var(--good-bg); color: var(--good); }
.kpi-v { font: 600 1.7rem/1.15 var(--font-head); color: var(--ink); font-variant-numeric: tabular-nums; margin-top: 6px; letter-spacing: -.01em; }
.kpi-v small { font: 500 .85rem var(--font-body); color: var(--muted); margin-left: 4px; }
.kpi-f { display: flex; align-items: center; gap: 8px; font-size: .76rem; color: var(--muted); flex-wrap: wrap; }
.delta { font-weight: 600; font-variant-numeric: tabular-nums; }
.delta.good { color: var(--good); } .delta.bad { color: var(--bad); } .delta.flat { color: var(--muted); }
.kpi .spark { position: absolute; right: 0; top: 2px; width: 84px; height: 34px; }

/* ---------- Charts ---------- */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid-l { stroke: var(--line); stroke-width: 1; }
.chart .axis-t { fill: var(--muted); font: 500 11px var(--font-body); }
.chart .val-t { fill: var(--ink); font: 600 11px var(--font-body); }
.c1 { fill: var(--brand-2); stroke: var(--brand-2); }
.c2 { fill: var(--line); stroke: var(--muted); }
.c3 { fill: var(--accent-2); stroke: var(--accent-2); }
.c4 { fill: var(--accent); stroke: var(--accent); }
.c5 { fill: var(--good); stroke: var(--good); }
.chart .bar { stroke: none; transition: opacity .15s; }
.chart .bar:hover { opacity: .8; }
.chart .line { fill: none; stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.dash { stroke-dasharray: 5 5; stroke-width: 1.6; }
.chart .area { stroke: none; opacity: .14; }
.chart .dot { stroke: var(--surface); stroke-width: 2.5; }
.chart .target { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 4 4; fill: none; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: .76rem; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend i.c1 { background: var(--brand-2); } .legend i.c2 { background: var(--line); border: 1px solid var(--muted); }
.legend i.c3 { background: var(--accent-2); } .legend i.c4 { background: var(--accent); } .legend i.c5 { background: var(--good); }
.legend i.dash { height: 0; border-top: 2px dashed var(--accent); border-radius: 0; background: none; }
.chart-wrap { overflow-x: auto; }

.donut { display: grid; grid-template-columns: 140px 1fr; gap: 20px; align-items: center; }
.donut svg { width: 140px; height: 140px; }
.donut .ring-bg { fill: none; stroke: var(--surface-2); }
.donut .center-v { fill: var(--ink); font: 600 22px var(--font-head); }
.donut .center-l { fill: var(--muted); font: 500 11px var(--font-body); }
.donut-legend { display: grid; gap: 10px; }
.donut-legend div { display: flex; justify-content: space-between; gap: 12px; font-size: .84rem; }
.donut-legend span { display: flex; align-items: center; gap: 8px; }
.donut-legend i { width: 10px; height: 10px; border-radius: 3px; }
.donut-legend strong { color: var(--ink); font-variant-numeric: tabular-nums; }

/* ---------- Table ---------- */
.tbl-tools { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.tbl-tools .input { height: 36px; min-height: 36px; max-width: 260px; }
.tbl-wrap { overflow-x: auto; margin: 0 -20px; }
.w.flush .tbl-wrap { margin: 0; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th { text-align: left; font: 600 .7rem var(--font-body); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
td { padding: 12px 14px; border-bottom: 1px solid var(--line); color: var(--text); vertical-align: middle; }
th:first-child, td:first-child { padding-left: 20px; }
th:last-child, td:last-child { padding-right: 20px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--hover); }
tr.clickable { cursor: pointer; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
td.c, th.c { text-align: center; }
td strong { color: var(--ink); font-weight: 600; }
.cell-user { display: flex; align-items: center; gap: 10px; min-width: 160px; }
.cell-user small { display: block; color: var(--muted); font-size: .76rem; }
.empty-row td { text-align: center; color: var(--muted); padding: 28px; }
.ok { color: var(--good); } .no { color: var(--bad); opacity: .8; }

/* ---------- Lists ---------- */
.list { display: grid; }
.li { display: flex; gap: 12px; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line); min-width: 0; }
.li:last-child { border-bottom: 0; padding-bottom: 0; }
.li:first-child { padding-top: 0; }
.li-body { flex: 1; min-width: 0; }
.li-body strong { display: block; color: var(--ink); font-weight: 600; font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li-body span { display: block; font-size: .78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li-right { text-align: right; flex: none; display: grid; gap: 4px; justify-items: end; font-size: .78rem; color: var(--muted); }
.li-ic { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--info-bg); color: var(--info); flex: none; }
.li-ic svg { width: 18px; height: 18px; }
.li-ic.warn { background: var(--warn-bg); color: var(--warn); } .li-ic.bad { background: var(--bad-bg); color: var(--bad); } .li-ic.good { background: var(--good-bg); color: var(--good); }
.date-chip { width: 44px; flex: none; text-align: center; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); padding: 5px 0; font: 600 1rem/1.1 var(--font-head); color: var(--ink); }
.date-chip small { display: block; font: 600 .62rem var(--font-body); color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }
.progress { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.progress i { display: block; height: 100%; border-radius: inherit; background: var(--grad); }
.progress.warn i { background: var(--accent-2); } .progress.bad i { background: var(--accent); }

/* ---------- Timetable ---------- */
.tt { display: grid; gap: 8px; }
.tt-row { display: grid; grid-template-columns: 92px 1fr auto; gap: 14px; align-items: center; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); }
.tt-row .time { font: 600 .8rem var(--font-body); color: var(--muted); font-variant-numeric: tabular-nums; }
.tt-row strong { display: block; color: var(--ink); }
.tt-row span { font-size: .78rem; color: var(--muted); }
.tt-row.now { border-color: var(--brand-2); background: var(--info-bg); }
.tt-row.done { opacity: .6; }
.tt-row.free { border-style: dashed; background: none; }

/* ---------- Register ---------- */
.reg-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.reg-count { display: flex; gap: 8px; flex-wrap: wrap; }
.reg-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.reg-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.reg-item .nm { flex: 1; min-width: 0; font-weight: 600; color: var(--ink); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reg-item .nm small { display: block; font-weight: 400; color: var(--muted); font-size: .72rem; }
.pal { display: inline-flex; gap: 3px; }
.pal button { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); font: 700 .74rem var(--font-body); color: var(--muted); }
.pal button.on.p { background: var(--good-bg); color: var(--good); border-color: var(--good); }
.pal button.on.a { background: var(--bad-bg); color: var(--bad); border-color: var(--bad); }
.pal button.on.l { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.locked .pal button { pointer-events: none; }

/* Markbook */
.mark-in { width: 70px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); text-align: right; padding: 0 8px; font-variant-numeric: tabular-nums; color: var(--ink); }
.mark-in:focus { outline: 0; border-color: var(--brand-2); background: var(--surface); }
.mark-in.bad { border-color: var(--bad); }
.lvl { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; font: 700 .76rem var(--font-body); background: var(--surface-2); color: var(--ink); }
.lvl.l7, .lvl.l6 { background: var(--good-bg); color: var(--good); }
.lvl.l5, .lvl.l4 { background: var(--info-bg); color: var(--info); }
.lvl.l3 { background: var(--warn-bg); color: var(--warn); }
.lvl.l2, .lvl.l1 { background: var(--bad-bg); color: var(--bad); }
.stat-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.mini-stat { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--surface-2); }
.mini-stat span { font-size: .72rem; color: var(--muted); display: block; }
.mini-stat strong { font: 600 1.15rem var(--font-head); color: var(--ink); font-variant-numeric: tabular-nums; }

/* Attendance heat grid */
.heat { display: grid; grid-template-columns: 70px repeat(5, minmax(0, 1fr)); gap: 6px; align-items: center; font-size: .74rem; }
.heat .hd { color: var(--muted); text-align: center; font-weight: 600; }
.heat .wk { color: var(--muted); }
.heat .d { height: 30px; border-radius: 7px; background: var(--good-bg); border: 1px solid transparent; display: grid; place-items: center; font-weight: 600; color: var(--good); }
.heat .d.a { background: var(--bad-bg); color: var(--bad); }
.heat .d.l { background: var(--warn-bg); color: var(--warn); }
.heat .d.h { background: var(--surface-2); color: var(--muted); }
.heat .d.f { background: none; border: 1px dashed var(--line); color: var(--muted); }

/* Inbox */
.inbox { display: grid; grid-template-columns: 320px minmax(0, 1fr); min-height: 460px; }
.inbox-list { border-right: 1px solid var(--line); overflow-y: auto; max-height: 560px; }
.msg { display: flex; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); width: 100%; border-left: 3px solid transparent; background: none; border-top: 0; border-right: 0; text-align: left; }
.msg:hover { background: var(--hover); }
.msg.on { background: var(--hover); border-left-color: var(--brand-2); }
.msg .li-body strong { font-weight: 500; }
.msg.unread .li-body strong { font-weight: 700; }
.msg time { font-size: .72rem; color: var(--muted); flex: none; }
.reader { padding: 22px 24px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.reader-h { display: flex; gap: 12px; align-items: center; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.reader-h h3 { font-size: 1.05rem; }
.reader-h span { font-size: .78rem; color: var(--muted); }
.reader-body { line-height: 1.7; max-width: 68ch; }
.reader-body p { margin: 0 0 10px; }
.reply { margin-top: auto; display: grid; gap: 8px; }
.reply textarea { min-height: 80px; }
.back-btn { display: none; }

/* Notice preview (admin) */
.np { border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
.np-bar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; color: #fff; font-size: .84rem; background: linear-gradient(90deg, #c62828, #f0563a); }
.np-bar.info { background: linear-gradient(90deg, #1ea7e1, #1565c0); }
.np-bar b { white-space: nowrap; }
.np-bar .x { margin-left: auto; opacity: .8; }
.np-site { height: 70px; background: linear-gradient(135deg, #0d47a1, #1ea7e1); display: flex; align-items: center; padding: 0 16px; color: #fff; font: 600 .95rem var(--font-head); gap: 8px; }
.switch { position: relative; width: 42px; height: 24px; flex: none; display: inline-block; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch i { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: .2s; cursor: pointer; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + i { background: var(--brand); }
.switch input:checked + i::after { transform: translateX(18px); }
.switch input:focus-visible + i { outline: 2px solid var(--brand-2); outline-offset: 2px; }
.toggle-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* Permission matrix */
.perm td.c input { width: 17px; height: 17px; accent-color: var(--brand); }
.perm td.c input:disabled { opacity: .6; }

/* Quick actions */
.qa { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.qa button { display: grid; gap: 8px; justify-items: start; text-align: left; padding: 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); font-weight: 600; font-size: .84rem; transition: .15s; }
.qa button:hover { border-color: var(--brand-2); background: var(--hover); }
.qa button span { font-weight: 400; font-size: .74rem; color: var(--muted); }
.qa .li-ic { width: 34px; height: 34px; }

/* Pay card */
.pay { display: grid; gap: 10px; }
.pay-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.pay-row:last-of-type { border-bottom: 0; }
.pay-row span { color: var(--muted); font-size: .8rem; }
.pay-row strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.pay-ref { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--side); color: #fff; border-radius: 12px; padding: 12px 14px; }
.pay-ref strong { font: 600 1.05rem var(--font-head); letter-spacing: .06em; }
.pay-ref .btn { background: transparent; color: #fff; border-color: rgba(255,255,255,.25); }
.copy-ok { color: var(--good) !important; border-color: var(--good) !important; }

/* Drawer */
.scrim { position: fixed; inset: 0; background: rgba(8,14,28,.45); z-index: 70; opacity: 0; transition: opacity .2s; }
.scrim.on { opacity: 1; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100%); background: var(--surface); z-index: 71; box-shadow: -20px 0 50px rgba(0,0,0,.2); transform: translateX(100%); transition: transform .25s ease; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); padding-right: env(safe-area-inset-right, 0px); }
.drawer.on { transform: none; }
.drawer-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.drawer-b { padding: 20px 22px; overflow-y: auto; display: grid; gap: 14px; align-content: start; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; font-size: .86rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; color: var(--ink); font-weight: 500; }

/* Toast */
.toasts { position: fixed; right: max(20px, env(safe-area-inset-right, 0px)); bottom: calc(20px + env(safe-area-inset-bottom, 0px)); z-index: 90; display: grid; gap: 8px; }
.toast { display: flex; align-items: center; gap: 10px; background: var(--side); color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: 0 12px 30px rgba(0,0,0,.25); font-size: .86rem; max-width: 360px; animation: toastIn .25s ease; }
.toast svg { width: 18px; height: 18px; color: #4cc887; flex: none; }
@keyframes toastIn { from { transform: translateY(10px); opacity: 0; } }

/* ---------- Skeleton loader ---------- */
.sk { display: block; border-radius: 6px; background: linear-gradient(90deg, var(--sk) 25%, var(--sk-hi) 37%, var(--sk) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.sk-line { height: 11px; }
.sk-line.lg { height: 16px; } .sk-line.xl { height: 30px; border-radius: 8px; }
.sk-circle { border-radius: 50%; flex: none; }
.sk-box { border-radius: 10px; flex: none; }
.sk-stack { display: grid; gap: 9px; }
.sk-row { display: flex; gap: 12px; align-items: center; }
.sk-chart { display: flex; align-items: flex-end; gap: 4%; height: 190px; padding: 10px 4px 0; border-bottom: 1px solid var(--line); }
.sk-chart .sk { flex: 1; border-radius: 6px 6px 0 0; }
.sk-table { display: grid; }
.sk-table .sk-row { padding: 13px 20px; border-bottom: 1px solid var(--line); }
.sk-table .sk-row:first-child { background: var(--surface-2); padding-block: 12px; }
.w.is-loading { pointer-events: none; }
.w.is-loading .w-h h3, .w.is-loading .w-h .link-btn { display: none; }
[aria-busy="true"] .sr-loading { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

@media (prefers-reduced-motion: reduce) {
  .sk { animation: none; }
  .loaded, .toast { animation: none; }
  .drawer, .scrim { transition: none; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1280px) {
  .s-2 { grid-column: span 4; }
}
@media (max-width: 1100px) {
  .s-2, .s-3 { grid-column: span 6; }
  .s-4, .s-5 { grid-column: span 6; }
  .s-7, .s-8 { grid-column: span 12; }
  .s-6 { grid-column: span 12; }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sb { position: fixed; inset: 0 auto 0 0; width: min(280px, 86vw); height: 100%; transform: translateX(-100%); transition: transform .25s ease; padding-top: calc(20px + env(safe-area-inset-top, 0px)); }
  .sb.open { transform: none; box-shadow: 20px 0 50px rgba(0,0,0,.35); }
  .tb-menu { display: grid; }
  .tb-search { display: none; }
  .me div { display: none; }
  .tb { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .content { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-block: 20px 40px; }
  .inbox { grid-template-columns: 1fr; }
  .inbox.reading .inbox-list { display: none; }
  .inbox:not(.reading) .reader { display: none; }
  .inbox-list { border-right: 0; max-height: none; }
  .back-btn { display: inline-flex; align-self: flex-start; }
}
@media (max-width: 640px) {
  .s-2, .s-3, .s-4, .s-5, .s-6 { grid-column: span 12; }
  .grid { gap: 14px; }
  .form-grid { grid-template-columns: 1fr; }
  .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .donut { grid-template-columns: 1fr; justify-items: center; }
  .donut-legend { width: 100%; }
  .page-head h1 { font-size: 1.3rem; }
  .tt-row { grid-template-columns: 70px 1fr; }
  .tt-row > :last-child { grid-column: 2; justify-self: start; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .heat { grid-template-columns: 52px repeat(5, minmax(0, 1fr)); }
}
@media (min-width: 641px) and (max-width: 1100px) {
  .s-2 { grid-column: span 6; }
}
.donut-legend i.c1 { background: var(--brand-2); } .donut-legend i.c2 { background: var(--line); }
.donut-legend i.c3 { background: var(--accent-2); } .donut-legend i.c4 { background: var(--accent); } .donut-legend i.c5 { background: var(--good); }
.w.flush .tbl-tools { padding: 0 20px; }
.w.flush > .list, .w.flush > .tt { padding: 0 20px 18px; }

/* Sidebar colour fills the full page height on desktop */
@media (min-width: 901px) { .shell { background: linear-gradient(90deg, var(--side) var(--sb-w), transparent var(--sb-w)); } }
/* KPI sparkline: keep clear of the label, hide on narrow tiles */
.w { container-type: inline-size; }
.kpi:has(.spark) .kpi-l { padding-right: 92px; }
@container (max-width: 250px) { .kpi .spark { display: none; } .kpi:has(.spark) .kpi-l { padding-right: 0; } }
@container (max-width: 210px) { .kpi-v { font-size: 1.35rem; } .kpi-l .ic { display: none; } }
@media (max-width: 640px) {
  .w.kpi-w { grid-column: span 6; padding: 14px; }
  .ctx { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; margin-inline: -2px; }
  .ctx-btn { flex: none; }
}

/* ---------- Photo consent + admissions emails ---------- */
.pc-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.pc-row:first-child { padding-top: 2px; }
.pc-row strong { display: block; color: var(--ink); font-weight: 600; font-size: .92rem; }
.pc-row span.d { display: block; font-size: .82rem; color: var(--muted); margin-top: 2px; }
.pc-foot { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 16px; }
.pc-dots { display: inline-flex; gap: 5px; }
.pc-dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line); background: var(--surface); display: inline-block; }
.pc-dots i.on { background: var(--good); border-color: var(--good); }
.pc-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 10px 0 0; padding: 0; list-style: none; font-size: .8rem; color: var(--muted); }
.pc-legend b { color: var(--ink); font-weight: 600; margin-right: 4px; }
.rule-box { border-left: 4px solid var(--warn); background: var(--warn-bg); border-radius: 10px; padding: 12px 16px; font-size: .88rem; color: var(--ink); }
.rule-box p { margin: 0; }
.check-inline { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--ink); }
.check-inline input { width: 16px; height: 16px; accent-color: var(--brand); }
.email-box { border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); padding: 12px 14px; font-size: .82rem; color: var(--text); }
.email-box strong { color: var(--ink); }
.email-box p { margin: 0 0 .6em; }
.email-box ul { margin: 0 0 .6em; padding-left: 18px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.set-row:last-child { border-bottom: 0; }
.set-row strong { color: var(--ink); font-weight: 600; font-size: .86rem; display: block; }
.set-row span.d { font-size: .76rem; color: var(--muted); display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- Mobile: no horizontal scrolling anywhere in the portals ---------- */
html { overflow-x: hidden; max-width: 100%; }
body { overflow-x: clip; max-width: 100%; overflow-wrap: anywhere; }
@media (max-width: 640px) {
  .tbl-wrap { overflow: visible; margin: 0; padding: 0 12px 12px; }
  .tbl-wrap table, .tbl-wrap tbody, .tbl-wrap tr, .tbl-wrap td { display: block; width: 100%; }
  .tbl-wrap thead { display: none; }
  .tbl-wrap tr { border: 1px solid var(--line); border-radius: 12px; margin: 10px 0 0; padding: 6px 12px; background: var(--surface); }
  .tbl-wrap td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 7px 0; border: 0; text-align: right; }
  .tbl-wrap td::before { content: attr(data-label); font-weight: 600; font-size: .75rem; color: var(--muted); text-align: left; flex: none; max-width: 42%; }
  .tbl-wrap td[data-label=""]::before { content: none; }
  .tbl-wrap td.r, .tbl-wrap td.right { text-align: right; }
  .tbl-wrap tr[hidden], .tbl-wrap tr.empty-row[hidden] { display: none; }
  .ctx { flex-wrap: wrap; overflow: visible; margin-inline: 0; }
  .ctx-btn { flex: 1 1 100%; }
}
