/* ==========================================================================
   School & College System — design system
   Board (deep brand) sidebar, marigold accent tab, paper content area.
   Type: Bricolage Grotesque (headings) + Atkinson Hyperlegible (body, built for legibility).
   ========================================================================== */

@font-face { font-family: "Bricolage"; src: url("../fonts/bricolage-grotesque-latin-wght-normal.woff2") format("woff2"); font-weight: 200 800; font-display: swap; }
@font-face { font-family: "Atkinson"; src: url("../fonts/atkinson-hyperlegible-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Atkinson"; src: url("../fonts/atkinson-hyperlegible-latin-700-normal.woff2") format("woff2"); font-weight: 700; font-display: swap; }

:root {
  --brand: #1F6F5C; --brand-ink: #fff; --accent: #E9A825; --accent-ink: #14211F;
  --paper: #F3F5F2; --surface: #FFFFFF; --surface-2: #F8F9F7; --ink: #18252C; --muted: #5B6970; --faint: #8A979C;
  --line: #DCE2DD; --line-strong: #C5CEC8;
  --ok: #24764A; --ok-bg: #E5F3EA; --warn: #9A6100; --warn-bg: #FCF1DA; --bad: #B3361F; --bad-bg: #FBE7E2; --info: #2B5D9B; --info-bg: #E5EEF9;
  --board: color-mix(in oklab, var(--brand) 42%, #08120F);
  --board-2: color-mix(in oklab, var(--brand) 30%, #08120F);
  --brand-soft: color-mix(in oklab, var(--brand) 12%, var(--surface));
  --focus: color-mix(in oklab, var(--accent) 85%, #000);
  --r-sm: 6px; --r: 10px; --r-lg: 16px;
  --shadow-pop: 0 18px 50px -12px rgb(10 25 22 / .35), 0 2px 6px rgb(10 25 22 / .08);
  --f-head: "Bricolage", "Segoe UI", system-ui, sans-serif;
  --f-body: "Atkinson", "Segoe UI", system-ui, -apple-system, "Noto Sans Devanagari", sans-serif;
  --sb-w: 264px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0D1413; --surface: #141D1C; --ink: #E4EBE8; --muted: #9DABA6; --faint: #74827D;
    --line: #25312F; --line-strong: #34423F; --surface-2: #182220;
    --ok: #6CCB94; --ok-bg: #12291D; --warn: #E7B24E; --warn-bg: #2B2210; --bad: #F08B74; --bad-bg: #2E1712; --info: #86B2EC; --info-bg: #13213A;
    --brand-soft: color-mix(in oklab, var(--brand) 22%, var(--surface));
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0D1413; --surface: #141D1C; --surface-2: #182220; --ink: #E4EBE8; --muted: #9DABA6; --faint: #74827D;
  --line: #25312F; --line-strong: #34423F;
  --ok: #6CCB94; --ok-bg: #12291D; --warn: #E7B24E; --warn-bg: #2B2210; --bad: #F08B74; --bad-bg: #2E1712; --info: #86B2EC; --info-bg: #13213A;
  --brand-soft: color-mix(in oklab, var(--brand) 22%, var(--surface));
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 400 15px/1.55 var(--f-body); color: var(--ink); background: var(--paper); }
h1, h2, h3, h4 { font-family: var(--f-head); line-height: 1.2; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 1.75rem; font-weight: 700; }
h2 { font-size: 1.2rem; font-weight: 650; }
h3 { font-size: 1.02rem; font-weight: 650; }
p { margin: 0 0 .8em; }
a { color: color-mix(in oklab, var(--brand) 80%, var(--ink)); text-underline-offset: 2px; }
img { max-width: 100%; height: auto; }
code, kbd { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .86em; }
kbd { border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 5px; padding: 1px 5px; color: var(--muted); background: var(--surface); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.i { width: 18px; height: 18px; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: 12px; top: -60px; z-index: 100; background: var(--accent); color: var(--accent-ink); padding: 8px 14px; border-radius: var(--r-sm); font-weight: 700; }
.skip-link:focus { top: 12px; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- Shell ---------- */
.shell { min-height: 100vh; display: grid; grid-template-columns: var(--sb-w) minmax(0, 1fr); }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  background: var(--board); color: #E8EFEC; overflow: hidden;
}
.sb-brand { display: flex; align-items: center; gap: 12px; padding: 20px 18px 18px; border-bottom: 1px solid rgb(255 255 255 / .08); }
.sb-logo { width: 40px; height: 40px; object-fit: contain; border-radius: 8px; background: #fff; padding: 3px; }
.sb-mark { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); font: 700 1rem var(--f-head); }
.sb-school { display: flex; flex-direction: column; min-width: 0; }
.sb-school strong { font: 650 .98rem/1.25 var(--f-head); color: #fff; overflow-wrap: anywhere; }
.sb-school small { color: rgb(232 239 236 / .62); font-size: .78rem; }
.sb-brand .sb-close { display: none; margin-left: auto; color: #fff; }
.sb-nav { flex: 1; overflow-y: auto; padding: 10px 0 16px; scrollbar-width: thin; scrollbar-color: rgb(255 255 255 / .2) transparent; }
.sb-section + .sb-section { margin-top: 10px; }
.sb-heading { padding: 10px 22px 6px; font-size: .78rem; color: rgb(232 239 236 / .5); }
.sb-nav ul { list-style: none; margin: 0; padding: 0 10px 0 0; }
.sb-nav a {
  position: relative; display: flex; align-items: center; gap: 12px; padding: 9px 14px 9px 22px; margin: 1px 0;
  color: rgb(232 239 236 / .82); text-decoration: none; border-radius: 0 var(--r) var(--r) 0; font-size: .95rem;
}
.sb-nav a:hover { background: rgb(255 255 255 / .06); color: #fff; }
.sb-nav a.active { background: rgb(255 255 255 / .1); color: #fff; font-weight: 700; }
/* The index tab: a marigold marker like the tab on an exercise-book divider */
.sb-nav a.active::before { content: ""; position: absolute; left: 0; top: 6px; bottom: 6px; width: 5px; border-radius: 0 4px 4px 0; background: var(--accent); }
.sb-nav a .i { opacity: .85; }
.sb-user { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-top: 1px solid rgb(255 255 255 / .08); color: #fff; text-decoration: none; background: var(--board-2); }
.sb-user span:last-child { display: flex; flex-direction: column; min-width: 0; }
.sb-user strong { font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-user small { color: rgb(232 239 236 / .6); font-size: .78rem; }
.sb-scrim { display: none; }

.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 10px 28px;
  background: color-mix(in oklab, var(--paper) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.topbar .menu-btn { display: none; }
.crumbs { min-width: 0; flex: 1; }
.crumbs ol { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: .9rem; color: var(--muted); }
.crumbs li + li::before { content: "/"; margin-right: 4px; color: var(--faint); }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--ink); text-decoration: underline; }
.crumbs [aria-current] { color: var(--ink); font-weight: 700; }
.topbar-tools { display: flex; align-items: center; gap: 8px; }
.find-btn { display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 8px 0 12px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); color: var(--muted); font: inherit; font-size: .9rem; cursor: pointer; }
.find-btn:hover { border-color: var(--line-strong); color: var(--ink); }
.icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border: 0; border-radius: var(--r); background: transparent; color: var(--muted); cursor: pointer; text-decoration: none; }
.icon-btn:hover { background: color-mix(in oklab, var(--ink) 7%, transparent); color: var(--ink); }
.icon-btn.is-disabled { opacity: .35; pointer-events: none; }
.theme-sun { display: none; }
:root[data-theme="dark"] .theme-moon { display: none; } :root[data-theme="dark"] .theme-sun { display: block; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .theme-moon { display: none; } :root:not([data-theme="light"]) .theme-sun { display: block; } }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: inline-grid; place-items: center; flex: none; background: var(--accent); color: var(--accent-ink); font: 700 .8rem var(--f-head); }
.user-btn { display: inline-flex; align-items: center; gap: 4px; padding: 2px 6px 2px 2px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--muted); cursor: pointer; }

.content { flex: 1; width: 100%; max-width: 1240px; padding: 26px 28px 40px; outline: none; }
.app-footer { display: flex; flex-wrap: wrap; gap: 6px 18px; justify-content: space-between; padding: 16px 28px 22px; color: var(--faint); font-size: .82rem; }

/* Dropdown menu */
.menu-wrap { position: relative; }
.dropdown { position: absolute; right: 0; top: calc(100% + 8px); min-width: 230px; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-pop); display: none; z-index: 40; }
.menu-wrap.open .dropdown { display: block; }
.dropdown a, .dropdown button { display: flex; width: 100%; align-items: center; gap: 10px; padding: 9px 10px; border: 0; border-radius: var(--r-sm); background: none; color: var(--ink); font: inherit; font-size: .93rem; text-decoration: none; cursor: pointer; text-align: left; }
.dropdown a:hover, .dropdown button:hover { background: var(--surface-2); }
.dropdown form { margin: 0; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 4px; }
.dd-head { padding: 8px 10px 10px; display: flex; flex-direction: column; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.dd-head small { color: var(--muted); overflow-wrap: anywhere; }

/* ---------- Page header ---------- */
.page-head { display: flex; flex-wrap: wrap; gap: 14px 24px; align-items: flex-end; justify-content: space-between; margin-bottom: 22px; }
.page-head p { margin: 6px 0 0; color: var(--muted); max-width: 70ch; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 16px;
  border: 1px solid transparent; border-radius: var(--r); font: 700 .93rem var(--f-body); text-decoration: none; cursor: pointer;
  transition: background-color .15s, border-color .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.is-loading { opacity: .6; pointer-events: none; }
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: color-mix(in oklab, var(--brand) 86%, #000); }
.btn-accent { background: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-danger-ghost { background: transparent; color: var(--bad); border-color: color-mix(in oklab, var(--bad) 40%, transparent); }
.btn-danger-ghost:hover { background: var(--bad-bg); }
.btn-sm { min-height: 32px; padding: 0 11px; font-size: .85rem; border-radius: var(--r-sm); }
.btn-block { width: 100%; }
.btn .spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Panels ---------- */
.panel { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); margin-bottom: 20px; min-width: 0; }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.panel-head p { margin: 2px 0 0; color: var(--muted); font-size: .9rem; }
.panel-body { padding: 20px; }
.panel-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.split { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 20px; align-items: start; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 18px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-weight: 700; font-size: .9rem; }
.field .hint { color: var(--muted); font-size: .84rem; margin: 0; }
.req::after { content: " *"; color: var(--bad); }
.input, select.input, textarea.input {
  width: 100%; min-height: 42px; padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: var(--r);
  background: var(--surface); color: var(--ink); font: inherit; transition: border-color .15s, box-shadow .15s;
}
textarea.input { min-height: 96px; resize: vertical; }
.input:hover { border-color: color-mix(in oklab, var(--ink) 30%, var(--line-strong)); }
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in oklab, var(--brand) 22%, transparent); }
.input[aria-invalid="true"] { border-color: var(--bad); }
.field-error { color: var(--bad); font-size: .85rem; margin: 0; }
.input-group { display: flex; }
.input-group .input { border-radius: var(--r) 0 0 var(--r); }
.input-group .ig-btn { border: 1px solid var(--line-strong); border-left: 0; border-radius: 0 var(--r) var(--r) 0; background: var(--surface-2); padding: 0 12px; color: var(--muted); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font: inherit; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--brand); flex: none; }
.check small { display: block; color: var(--muted); }
/* Switch */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { appearance: none; width: 42px; height: 24px; margin: 0; border-radius: 999px; background: var(--line-strong); position: relative; cursor: pointer; transition: background .15s; flex: none; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgb(0 0 0 / .25); transition: transform .15s; }
.switch input:checked { background: var(--brand); }
.switch input:checked::after { transform: translateX(18px); }
.switch input:disabled { opacity: .5; cursor: not-allowed; }
/* Colour field */
.color-field { display: flex; align-items: center; gap: 10px; }
.color-field input[type="color"] { width: 46px; height: 42px; padding: 3px; border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--surface); cursor: pointer; }
.color-field .input { max-width: 130px; font-family: ui-monospace, monospace; }
/* Upload */
.upload-box { display: flex; align-items: center; gap: 16px; padding: 14px; border: 1px dashed var(--line-strong); border-radius: var(--r); background: var(--surface-2); }
.upload-preview { width: 72px; height: 72px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface) center/contain no-repeat; display: grid; place-items: center; color: var(--faint); flex: none; overflow: hidden; }
.upload-preview img { width: 100%; height: 100%; object-fit: contain; }

/* ---------- Tabs ---------- */
.tabs { position: relative; display: flex; gap: 2px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 22px; scrollbar-width: none; }
.tabs a { display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; white-space: nowrap; color: var(--muted); text-decoration: none; border-bottom: 3px solid transparent; margin-bottom: -1px; font-weight: 700; font-size: .93rem; }
.tabs a:hover { color: var(--ink); }
.tabs a.active { color: var(--ink); border-bottom-color: var(--accent); }
.tabs.subtabs { border-bottom: 0; margin-bottom: 12px; gap: 6px; }
.tabs.subtabs a { border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; margin: 0; font-size: .88rem; }
.tabs.subtabs a.active { background: var(--brand-soft); border-color: transparent; }

/* ---------- Tables (register style) ---------- */
.table-wrap { position: relative; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .93rem; }
.table th { text-align: left; font-weight: 700; color: var(--muted); font-size: .82rem; padding: 10px 16px; background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: color-mix(in oklab, var(--brand) 4%, var(--surface)); }
.table .t-actions { text-align: right; white-space: nowrap; }
.table .t-actions > * + * { margin-left: 4px; }
.cell-user { display: flex; align-items: center; gap: 10px; min-width: 200px; }
.cell-user small { display: block; color: var(--muted); }

/* Toolbar (filters above a table) */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.toolbar .search { position: relative; flex: 1 1 220px; max-width: 360px; }
.toolbar .search .i { position: absolute; left: 11px; top: 12px; color: var(--faint); }
.toolbar .search .input { padding-left: 36px; }
.toolbar select.input { width: auto; min-width: 150px; }

/* ---------- Badges, chips ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.badge-neutral { background: color-mix(in oklab, var(--ink) 8%, transparent); color: var(--muted); }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-brand { background: var(--brand-soft); color: color-mix(in oklab, var(--brand) 75%, var(--ink)); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 8px; border: 1px solid var(--line); border-radius: 999px; font-size: .82rem; font-weight: 700; background: var(--surface); white-space: nowrap; }
.chip i { width: 9px; height: 9px; border-radius: 50%; }
.swatch { position: relative; width: 30px; height: 30px; border-radius: 50%; background: var(--sw); cursor: pointer; box-shadow: inset 0 0 0 2px rgb(255 255 255 / .35); }
.swatch input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.swatch:has(input:checked) { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--sw); }
.swatch:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- Alerts and toasts ---------- */
.alert { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r); margin-bottom: 18px; border: 1px solid transparent; }
.alert > div { flex: 1; }
.alert-success { background: var(--ok-bg); color: var(--ok); border-color: color-mix(in oklab, var(--ok) 25%, transparent); }
.alert-error { background: var(--bad-bg); color: var(--bad); border-color: color-mix(in oklab, var(--bad) 25%, transparent); }
.alert-warning { background: var(--warn-bg); color: var(--warn); border-color: color-mix(in oklab, var(--warn) 25%, transparent); }
.alert-info { background: var(--info-bg); color: var(--info); border-color: color-mix(in oklab, var(--info) 25%, transparent); }
.alert-x { border: 0; background: none; color: inherit; cursor: pointer; padding: 0; opacity: .7; }
.note { padding: 12px 14px; border-left: 4px solid var(--accent); background: color-mix(in oklab, var(--accent) 10%, var(--surface)); border-radius: 0 var(--r) var(--r) 0; font-size: .92rem; }
.toasts { position: fixed; z-index: 90; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 10px; max-width: min(380px, calc(100vw - 36px)); }
.toast { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r); background: var(--ink); color: var(--paper); box-shadow: var(--shadow-pop); animation: toast-in .2s ease-out; font-size: .93rem; }
.toast.ok .i { color: #6CCB94; } .toast.bad .i { color: #F08B74; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty > .i { width: 40px; height: 40px; color: var(--faint); margin-bottom: 10px; }
.empty h3 { color: var(--ink); margin-bottom: 6px; }
.empty p { max-width: 46ch; margin: 0 auto 16px; }

/* ---------- Pager ---------- */
.pager { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 20px; border-top: 1px solid var(--line); }
.pager-info { color: var(--muted); font-size: .88rem; }
.pager-links { display: flex; align-items: center; gap: 2px; }
.pg { min-width: 34px; height: 34px; display: grid; place-items: center; border-radius: var(--r-sm); text-decoration: none; color: var(--ink); font-size: .9rem; }
.pg:hover { background: var(--surface-2); }
.pg.is-current { background: var(--brand); color: var(--brand-ink); font-weight: 700; }

/* ---------- Modals ---------- */
dialog.modal { padding: 0; border: 0; background: transparent; max-width: min(640px, calc(100vw - 24px)); width: 100%; color: var(--ink); }
dialog.modal.wide { max-width: min(860px, calc(100vw - 24px)); }
dialog::backdrop { background: rgb(8 18 15 / .55); backdrop-filter: blur(2px); }
.modal-card { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-pop); max-height: calc(100vh - 40px); display: flex; flex-direction: column; margin: 0; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-body h2 { margin-bottom: 8px; }
.modal-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); }
dialog[open] .modal-card { animation: pop .16s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.99); } }

/* Quick find */
.find-dialog { padding: 0; border: 0; width: min(560px, calc(100vw - 24px)); margin-top: 12vh; border-radius: var(--r-lg); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-pop); }
.find-box { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); color: var(--faint); }
.find-box input { flex: 1; border: 0; outline: none; background: none; font: inherit; font-size: 1.05rem; color: var(--ink); }
.find-list { list-style: none; margin: 0; padding: 6px; max-height: 50vh; overflow-y: auto; }
.find-list a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--r-sm); color: var(--ink); text-decoration: none; }
.find-list a small { margin-left: auto; color: var(--muted); font-size: .8rem; }
.find-list a[aria-selected="true"], .find-list a:hover { background: var(--brand-soft); }
.find-list .none { padding: 16px; color: var(--muted); text-align: center; }

/* ---------- Dashboard ---------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); margin-bottom: 20px; overflow: hidden; }
.stat { padding: 18px 20px; }
.stat .label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 400; font-size: .88rem; }
.stat .value { font: 700 1.9rem/1.1 var(--f-head); margin-top: 8px; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--muted); font-size: .84rem; margin-top: 4px; }
.welcome { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; align-items: flex-end; margin-bottom: 22px; }
.welcome h1 { font-size: 2rem; }
.welcome p { color: var(--muted); margin: 6px 0 0; }
.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { display: flex; gap: 14px; align-items: flex-start; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.checklist li:last-child { border-bottom: 0; }
.checklist .tick { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line-strong); display: grid; place-items: center; flex: none; color: transparent; }
.checklist .done .tick { background: var(--ok); border-color: var(--ok); color: #fff; }
.checklist .done strong { color: var(--muted); }
.checklist .grow { flex: 1; min-width: 0; }
.checklist p { margin: 2px 0 0; color: var(--muted); font-size: .88rem; }
.progress { height: 8px; border-radius: 999px; background: color-mix(in oklab, var(--ink) 9%, transparent); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line); font-size: .92rem; }
.feed li:last-child { border-bottom: 0; }
.feed .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); margin-top: 8px; flex: none; }
.feed time { color: var(--faint); font-size: .82rem; white-space: nowrap; margin-left: auto; padding-left: 10px; }

/* ---------- Access matrix ---------- */
.matrix-module { border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 14px; overflow: hidden; }
.matrix-module-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.matrix-module-head h3 { font-size: .98rem; }
.matrix-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.matrix-table th { font-size: .78rem; color: var(--muted); font-weight: 700; padding: 8px 6px; text-align: center; white-space: nowrap; }
.matrix-table th:first-child, .matrix-table td:first-child { text-align: left; padding-left: 14px; }
.matrix-table td { padding: 8px 6px; border-top: 1px solid var(--line); text-align: center; }
.matrix-table td:first-child { min-width: 190px; }
.matrix-table .page-cell { display: flex; align-items: center; gap: 10px; }
.matrix-table .page-cell .i { color: var(--muted); }
.matrix-table input[type="checkbox"] { width: 19px; height: 19px; accent-color: var(--brand); cursor: pointer; }
.matrix-table input:disabled { cursor: not-allowed; opacity: .35; }
.matrix-table .na { color: var(--line-strong); }
.matrix-table .row-all { font-size: .8rem; }
.matrix-table tr.is-on td:first-child { font-weight: 700; }
.locked-note { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: .88rem; }

/* Group cards */
.group-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.group-card { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.group-card .gc-top { display: flex; gap: 12px; align-items: flex-start; padding: 16px 16px 12px; border-top: 5px solid var(--gc, var(--brand)); }
.group-card .gc-icon { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: color-mix(in oklab, var(--gc, var(--brand)) 14%, var(--surface)); color: var(--gc, var(--brand)); flex: none; }
.group-card h3 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.group-card p { color: var(--muted); font-size: .88rem; margin: 4px 0 0; }
.group-card .gc-meta { display: flex; gap: 16px; padding: 0 16px 14px; color: var(--muted); font-size: .86rem; }
.group-card .gc-meta strong { color: var(--ink); }
.group-card .gc-actions { margin-top: auto; display: flex; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--line); background: var(--surface-2); }

/* E-mail accounts */
.acct-list { display: grid; gap: 14px; }
.acct { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 16px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
.acct.is-off { opacity: .65; }
.acct-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); }
.acct h3 { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.acct .meta { color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; margin-top: 2px; }
.acct .status { display: flex; gap: 6px; align-items: center; font-size: .85rem; margin-top: 6px; }
.acct .status.ok { color: var(--ok); } .acct .status.bad { color: var(--bad); } .acct .status.none { color: var(--faint); }
.acct-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.route-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(200px, 280px); gap: 14px; align-items: center; padding: 12px 20px; border-bottom: 1px solid var(--line); }
.route-row:last-child { border-bottom: 0; }
.route-row strong { display: block; }
.route-row small { color: var(--muted); }
.preset-row { display: flex; flex-wrap: wrap; gap: 8px; }
.preset-row button { border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: .85rem; cursor: pointer; }
.preset-row button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.transcript { margin-top: 12px; max-height: 220px; overflow: auto; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); font: .78rem/1.5 ui-monospace, monospace; white-space: pre-wrap; color: var(--muted); }
.test-result { margin-top: 14px; }
details.more summary { cursor: pointer; color: var(--muted); font-size: .88rem; }

/* Audit */
.audit-meta { font: .8rem/1.5 ui-monospace, monospace; color: var(--muted); white-space: pre-wrap; max-width: 520px; overflow-wrap: anywhere; }

/* ---------- Auth pages ---------- */
body.auth { background: var(--surface); }
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
.auth-board {
  position: relative; display: flex; flex-direction: column; justify-content: space-between; padding: 44px 52px; overflow: hidden;
  background: var(--board); color: #F1F5F3;
}
/* Faint ruled lines, like a classroom board after it has been wiped */
.board-lines { position: absolute; inset: 0; pointer-events: none; opacity: .5;
  background-image: repeating-linear-gradient(180deg, transparent 0 46px, rgb(255 255 255 / .05) 46px 47px),
                    radial-gradient(120% 80% at 10% 100%, rgb(255 255 255 / .06), transparent 60%); }
.board-top { position: relative; z-index: 1; }
.board-logo { width: 64px; height: 64px; object-fit: contain; border-radius: 14px; background: #fff; padding: 5px; }
.board-mark { width: 60px; height: 60px; border-radius: 14px; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); font: 700 1.4rem var(--f-head); }
.board-copy { position: relative; z-index: 1; max-width: 18ch; }
.board-school { font: 700 clamp(2.2rem, 4.4vw, 3.6rem)/1.02 var(--f-head); letter-spacing: -.025em; margin: 0; color: #fff; }
.board-school::after { content: ""; display: block; width: 72px; height: 6px; border-radius: 3px; background: var(--accent); margin-top: 22px; }
.board-tag { margin: 18px 0 0; color: rgb(241 245 243 / .75); font-size: 1.05rem; max-width: 34ch; }
.auth-panel { display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 40px 24px; background: var(--paper); }
.auth-card { width: 100%; max-width: 410px; }
.auth-title { font-size: 1.85rem; margin-bottom: 6px; }
.auth-sub { color: var(--muted); margin-bottom: 26px; }
.auth-card form { display: grid; gap: 16px; }
.auth-row label { font-weight: 700; font-size: .9rem; }
.auth-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; font-size: .92rem; }
.auth-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.auth-help { margin-top: 30px; max-width: 410px; color: var(--muted); font-size: .86rem; text-align: center; }
.error-code { font: 800 4.5rem/1 var(--f-head); color: var(--accent); margin-bottom: 10px; letter-spacing: -.04em; }
.pw-meter { height: 6px; border-radius: 999px; background: color-mix(in oklab, var(--ink) 9%, transparent); overflow: hidden; }
.pw-meter span { display: block; height: 100%; width: 0; transition: width .2s, background .2s; }
.pw-rules { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: .85rem; color: var(--muted); }
.pw-rules li.ok { color: var(--ok); }
.pw-rules li::before { content: "\25CB  "; } .pw-rules li.ok::before { content: "\2713  "; }

/* Portal placeholder */
.placeholder { max-width: 640px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .split { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: min(300px, 86vw); height: auto; z-index: 60; transform: translateX(-102%); transition: transform .22s ease; }
  body.sb-open .sidebar { transform: none; box-shadow: var(--shadow-pop); }
  body.sb-open .sb-scrim { display: block; position: fixed; inset: 0; z-index: 55; background: rgb(8 18 15 / .5); }
  .sb-brand .sb-close, .topbar .menu-btn { display: inline-grid; }
  .topbar { padding: 8px 14px; }
  .content { padding: 18px 14px 32px; }
  .app-footer { padding: 14px; }
  .find-btn span, .find-btn kbd { display: none; }
  .find-btn { width: 38px; padding: 0; justify-content: center; }
  .grid-2, .grid-3, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .auth-wrap { grid-template-columns: minmax(0, 1fr); }
  .auth-board { padding: 26px 22px 30px; min-height: 0; gap: 22px; }
  .board-school { font-size: 1.9rem; }
  .board-school::after { margin-top: 14px; height: 5px; width: 56px; }
  .board-tag { display: none; }
  .auth-panel { justify-content: flex-start; padding: 28px 18px 40px; }
  .acct { grid-template-columns: auto minmax(0, 1fr); }
  .acct-actions { grid-column: 1 / -1; justify-content: flex-start; }
  .route-row { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  h1 { font-size: 1.45rem; } .welcome h1 { font-size: 1.6rem; }
}
@media (max-width: 560px) {
  .stats { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .stat { padding: 14px; } .stat .value { font-size: 1.5rem; } .stat .sub { font-size: .78rem; }
  .page-actions { width: 100%; } .page-actions .btn { flex: 1; }
  .panel-body { padding: 16px; } .panel-head, .toolbar, .pager { padding-left: 16px; padding-right: 16px; }
  .toolbar .search { max-width: none; flex: 1 1 100%; }
  .toolbar select.input, .toolbar input[type="date"].input { flex: 1 1 40%; min-width: 0; width: auto; }
  .modal-foot .btn { flex: 1; }
}
@media print { .sidebar, .topbar, .app-footer, .page-actions, .toolbar, .pager { display: none !important; } .shell { display: block; } body { background: #fff; } }

/* ==========================================================================
   Phase 2: people screens + app-like phone experience
   ========================================================================== */
/* Avatars */
.avatar { object-fit: cover; }
.avatar-sm { width: 30px; height: 30px; font-size: .72rem; }
.avatar-md { width: 40px; height: 40px; font-size: .85rem; }
.avatar-lg { width: 64px; height: 64px; font-size: 1.2rem; border-radius: 18px; }
.avatar-xl { width: 96px; height: 96px; font-size: 1.7rem; border-radius: 24px; }
img.avatar { background: var(--surface-2); }

/* Stats as a flexible grid */
.stats { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.stat { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); margin: 0 -1px -1px 0; }
.stat:hover { background: var(--surface-2); }

/* Filter chips (status filters) */
.chip-filters { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 14px; scrollbar-width: none; }
.chip-filters::-webkit-scrollbar { display: none; }
.chip-filters a { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none; font-size: .88rem; font-weight: 700; }
.chip-filters a .n { font-weight: 400; color: var(--muted); }
.chip-filters a.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chip-filters a.active .n { color: inherit; opacity: .75; }

/* Clickable rows */
.table tr[data-href] { cursor: pointer; }
.cell-sub { display: block; color: var(--muted); font-size: .84rem; }

/* Profile header */
.profile-head { display: flex; gap: 20px; align-items: center; padding: 22px; }
.profile-head h1 { font-size: 1.6rem; }
.profile-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--muted); margin-top: 6px; font-size: .93rem; }
.profile-meta span { display: inline-flex; align-items: center; gap: 6px; }
.profile-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; align-self: flex-start; }
.ptabs { display: flex; gap: 2px; border-top: 1px solid var(--line); padding: 0 12px; overflow-x: auto; scrollbar-width: none; }
.ptabs button { border: 0; background: none; padding: 12px 14px; font: inherit; font-weight: 700; color: var(--muted); border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap; display: inline-flex; gap: 8px; align-items: center; }
.ptabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.ptab-panel[hidden] { display: none; }
.kv-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 28px; }
.kv { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px dashed var(--line); font-size: .94rem; }
.kv > span:first-child { color: var(--muted); }
.kv > strong, .kv > span:last-child { text-align: right; overflow-wrap: anywhere; }
.form-section { grid-column: 1 / -1; font: 650 .98rem var(--f-head); padding-top: 8px; margin-top: 4px; border-top: 1px solid var(--line); }
.form-section:first-child { border-top: 0; padding-top: 0; margin-top: 0; }

/* Person cards (guardians, linked records) */
.person-list { display: grid; gap: 10px; }
.person { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
.person .grow { flex: 1; min-width: 0; }
.person strong { display: block; }
.person small { color: var(--muted); display: block; overflow-wrap: anywhere; }
.person .acts { display: flex; gap: 4px; }

/* Documents */
.doc-list { display: grid; gap: 8px; margin-bottom: 18px; }
.doc { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r); }
.doc-ext { width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); font: 700 .72rem var(--f-head); flex: none; }
.doc-main { flex: 1; min-width: 0; } .doc-main a { font-weight: 700; overflow-wrap: anywhere; } .doc-main small { display: block; color: var(--muted); }
.doc-upload { display: grid; grid-template-columns: 1fr 1fr auto; gap: 12px; align-items: end; padding-top: 14px; border-top: 1px solid var(--line); }

/* Classes */
.class-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); margin-bottom: 14px; overflow: hidden; }
.class-card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: 14px 18px; }
.class-card-head h3 { font-size: 1.1rem; }
.class-card-head .grow { flex: 1; }
.section-row { display: flex; flex-wrap: wrap; gap: 10px; padding: 0 18px 16px; }
.section-pill { display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
.section-pill strong { font-family: var(--f-head); }
.section-pill small { color: var(--muted); }
.bars { display: grid; gap: 8px; padding: 16px 20px; }
.bar-row { display: grid; grid-template-columns: 110px minmax(0, 1fr) 44px; gap: 12px; align-items: center; font-size: .9rem; }
.bar-row .bar { height: 10px; border-radius: 999px; background: color-mix(in oklab, var(--ink) 7%, transparent); overflow: hidden; }
.bar-row .bar span { display: block; height: 100%; background: var(--brand); border-radius: inherit; }
.bar-row .n { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

/* Import preview */
.row-bad td { background: color-mix(in oklab, var(--bad) 6%, var(--surface)); }
.steps { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.steps span { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: .88rem; color: var(--muted); }
.steps span.on { background: var(--brand-soft); color: var(--ink); font-weight: 700; border-color: transparent; }

/* Phone: app chrome (hidden on desktop) */
.m-title, .bottom-nav, .fab { display: none; }

@media (max-width: 900px) {
  body.app { -webkit-tap-highlight-color: transparent; }
  .topbar { min-height: 58px; padding: 8px 10px 8px 14px; padding-top: max(8px, env(safe-area-inset-top)); background: color-mix(in oklab, var(--surface) 92%, transparent); }
  .crumbs, .topbar .menu-btn { display: none; }
  .m-title { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; color: var(--ink); text-decoration: none; font: 700 1.05rem var(--f-head); }
  .m-title span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .m-title img, .m-title .m-mark { width: 30px; height: 30px; border-radius: 8px; object-fit: contain; flex: none; }
  .m-title .m-mark { display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); font-size: .75rem; }
  a.m-title .i { width: 22px; height: 22px; }
  .user-btn .i { display: none; }
  .content { padding: 16px 14px calc(104px + env(safe-area-inset-bottom)); }
  .app-footer { display: none; }
  .page-head { margin-bottom: 14px; }
  .page-head p { font-size: .92rem; }
  .page-actions .btn-primary.fab-dup { display: none; }

  .bottom-nav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 45; background: color-mix(in oklab, var(--surface) 96%, transparent); backdrop-filter: blur(12px);
    border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .bottom-nav a, .bottom-nav button { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 2px 0; border: 0; background: none; color: var(--muted); text-decoration: none; font: 700 .7rem var(--f-body); cursor: pointer; }
  .bottom-nav .bn-ico { display: grid; place-items: center; width: 56px; height: 30px; border-radius: 999px; transition: background .15s; }
  .bottom-nav .bn-label { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 2px; }
  .bottom-nav .active { color: var(--ink); }
  .bottom-nav .active .bn-ico { background: var(--brand-soft); color: var(--brand); }

  .fab { display: inline-flex; align-items: center; gap: 8px; position: fixed; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 44;
    height: 54px; padding: 0 20px 0 16px; border-radius: 18px; background: var(--brand); color: var(--brand-ink); text-decoration: none; font-weight: 700; box-shadow: var(--shadow-pop); }
  .fab .i { width: 22px; height: 22px; }

  /* Inputs: 16px stops phones zooming in; bigger touch targets */
  .input, select.input, textarea.input { font-size: 16px; min-height: 46px; }
  .btn { min-height: 44px; }
  .btn-sm { min-height: 36px; }
  .icon-btn { width: 42px; height: 42px; }

  /* Tabs stick under the title bar and scroll sideways */
  .tabs { position: sticky; top: 58px; z-index: 15; background: var(--paper); margin: 0 -14px 16px; padding: 0 14px; scroll-snap-type: x proximity; }
  .tabs a { scroll-snap-align: start; padding: 12px 12px; }

  /* Modals open as bottom sheets */
  dialog.modal, dialog.modal.wide { margin: auto 0 0; max-width: 100%; width: 100%; max-height: 94vh; }
  dialog.modal .modal-card { border-radius: 22px 22px 0 0; max-height: 94vh; padding-bottom: env(safe-area-inset-bottom); }
  dialog.modal .modal-card::before { content: ""; width: 40px; height: 5px; border-radius: 3px; background: var(--line-strong); margin: 8px auto 0; flex: none; }
  dialog[open].modal .modal-card { animation: sheet .22s ease-out; }
  @keyframes sheet { from { transform: translateY(40px); opacity: .6; } }

  .profile-head { flex-wrap: wrap; padding: 18px; gap: 14px; }
  .profile-head h1 { font-size: 1.3rem; }
  .profile-actions { margin-left: 0; width: 100%; }
  .profile-actions .btn { flex: 1; }
  .kv-grid { grid-template-columns: minmax(0, 1fr); }
  .doc-upload { grid-template-columns: minmax(0, 1fr); }
  .bar-row { grid-template-columns: 80px minmax(0, 1fr) 36px; }
}

/* Phone: tables become compact cards (labels come from the table header) */
@media (max-width: 700px) {
  .table.is-cards thead { display: none; }
  .table.is-cards, .table.is-cards tbody { display: block; width: 100%; }
  .table.is-cards tr { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
  .table.is-cards tr:last-child { border-bottom: 0; }
  .table.is-cards td { display: inline-flex; align-items: center; gap: 5px; border: 0; padding: 0; font-size: .88rem; min-width: 0; max-width: 100%; }
  .table.is-cards td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; }
  .table.is-cards td:first-child { display: block; width: 100%; padding-bottom: 4px; font-size: .95rem; }
  .table.is-cards td:first-child::before, .table.is-cards td.t-actions::before, .table.is-cards td[data-label=""]::before { display: none; }
  .table.is-cards td:empty { display: none; }
  .table.is-cards td .cell-sub { display: inline; margin-left: 4px; }
  .table.is-cards td:first-child .cell-sub { display: block; margin: 0; }
  .table.is-cards td.t-actions { width: 100%; flex-wrap: wrap; padding-top: 6px; }
  .table.is-cards tbody tr:hover td { background: none; }
  .table.is-cards tr[data-href] { position: relative; padding-right: 34px; }
  .table.is-cards tr[data-href]::after { content: ""; position: absolute; right: 16px; top: 50%; width: 8px; height: 8px; border-right: 2px solid var(--faint); border-top: 2px solid var(--faint); transform: translateY(-50%) rotate(45deg); }
  .table.is-cards .cell-user { min-width: 0; }
  .table-wrap:has(.is-cards) { overflow: visible; }
  .toolbar .search { order: -1; }
}
@media print {
  .bottom-nav, .fab, .ptabs, .profile-actions, .doc-upload { display: none !important; }
  .ptab-panel[hidden] { display: block !important; }
}

/* Sidebar colour runs the full page height (long pages, printing) */
@media (min-width: 901px) {
  .shell { background: linear-gradient(to right, var(--board) var(--sb-w), transparent var(--sb-w)); }
}
.profile-actions .btn { white-space: nowrap; }
@media (max-width: 900px) {
  /* Save buttons stay in reach above the bottom bar */
  .save-bar { position: fixed; left: 0; right: 0; bottom: calc(63px + env(safe-area-inset-bottom)); z-index: 40; margin: 0; border-radius: 0; border-width: 1px 0 0; box-shadow: 0 -8px 24px -12px rgb(10 25 22 / .25); }
  .save-bar .panel-foot { padding: 10px 14px; border-radius: 0 !important; background: var(--surface); }
  .save-bar .panel-foot .btn { flex: 1; }
  body:has(.save-bar) .content { padding-bottom: calc(170px + env(safe-area-inset-bottom)); }
  body:has(.save-bar) .fab { display: none; }
  .profile-actions .btn { padding: 0 10px; }
}
@media (max-width: 900px) {
  .stats { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .stat { padding: 14px; }
  .stat .value { font-size: 1.55rem; }
}

/* ==========================================================================
   Phase 3: attendance, register, timetable
   ========================================================================== */
.att-picker { align-items: flex-end; }
.att-picker .field { min-width: 150px; }
.att-nav { display: flex; align-items: center; gap: 4px; }
.att-head { gap: 10px; }
.att-counts { display: flex; flex-wrap: wrap; gap: 6px; }
.att-counts b { font-variant-numeric: tabular-nums; }
.att-list { list-style: none; margin: 0; padding: 0; }
.att-row { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(140px, 230px); gap: 10px 16px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); transition: background-color .15s; }
.att-row:has(.att-time) { grid-template-columns: minmax(0, 1fr) auto 112px minmax(130px, 210px); }
.att-row.st-absent { background: color-mix(in oklab, var(--bad) 7%, var(--surface)); }
.att-row.st-late, .att-row.st-half_day { background: color-mix(in oklab, var(--warn) 7%, var(--surface)); }
.att-row.st-leave { background: color-mix(in oklab, var(--info) 7%, var(--surface)); }
.att-who { display: flex; gap: 10px; align-items: center; min-width: 0; }
.att-who strong { display: block; overflow-wrap: anywhere; }
.att-who small { color: var(--muted); font-size: .82rem; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 12px; overflow: hidden; background: var(--surface); }
.seg label { position: relative; cursor: pointer; }
.seg input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.seg span { display: grid; place-items: center; min-width: 44px; height: 40px; padding: 0 6px; font-weight: 700; color: var(--muted); border-left: 1px solid var(--line); transition: background-color .12s, color .12s; }
.seg label:first-child span { border-left: 0; }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: -3px; }
.seg input:disabled + span { cursor: not-allowed; }
.seg-present input:checked + span { background: var(--ok); color: #fff; }
.seg-absent input:checked + span { background: var(--bad); color: #fff; }
.seg-late input:checked + span, .seg-half_day input:checked + span { background: #B7791F; color: #fff; }
.seg-leave input:checked + span { background: var(--info); color: #fff; }
.att-remark, .att-time { min-height: 38px; padding: 6px 10px; }

/* Month register */
.reg { font-size: .85rem; }
.reg th, .reg td { padding: 6px 4px; text-align: center; border-bottom: 1px solid var(--line); }
.reg .reg-name { position: sticky; left: 0; z-index: 2; background: var(--surface); text-align: left; min-width: 170px; padding-left: 16px; font-weight: 700; box-shadow: 1px 0 0 var(--line); }
.reg thead .reg-name { background: var(--surface-2); }
.reg .reg-name small { display: block; font-weight: 400; color: var(--muted); font-size: .76rem; }
.reg th.reg-day { min-width: 28px; font-size: .78rem; }
.reg th.reg-day small { display: block; font-weight: 400; color: var(--faint); font-size: .68rem; }
.reg th.today { color: var(--brand); box-shadow: inset 0 -3px 0 var(--accent); }
.reg .off { background-image: repeating-linear-gradient(135deg, transparent 0 4px, color-mix(in oklab, var(--ink) 6%, transparent) 4px 6px); }
.reg-cell { font-weight: 700; font-size: .78rem; }
.c-present { color: var(--ok); } .c-absent { color: var(--bad); background-color: var(--bad-bg); } .c-late, .c-half_day { color: var(--warn); } .c-leave { color: var(--info); }
.reg-legend { display: flex; flex-wrap: wrap; gap: 8px 18px; padding: 12px 16px; color: var(--muted); font-size: .84rem; border-top: 1px solid var(--line); }
.reg-legend span { display: inline-flex; align-items: center; gap: 6px; }
.reg-legend i { display: inline-grid; place-items: center; width: 22px; height: 22px; border: 1px solid var(--line); border-radius: 6px; font-style: normal; font-weight: 700; font-size: .75rem; }

/* Timetable */
.tt-wrap { overflow-x: auto; }
.tt { width: 100%; border-collapse: separate; border-spacing: 6px; min-width: 760px; }
.tt th { font-size: .82rem; color: var(--muted); font-weight: 700; text-align: left; padding: 4px 6px; }
.tt th.tt-period { width: 120px; }
.tt th.tt-period small { display: block; font-weight: 400; color: var(--faint); }
.tt td { vertical-align: top; }
.tt-cell { display: flex; flex-direction: column; gap: 2px; width: 100%; min-height: 62px; padding: 8px 10px; border: 1px dashed var(--line-strong); border-radius: 10px; background: var(--surface); text-align: left; font: inherit; color: var(--ink); cursor: default; }
button.tt-cell { cursor: pointer; }
button.tt-cell:hover { border-color: var(--brand); }
.tt-cell.filled { border-style: solid; border-color: transparent; background: color-mix(in oklab, var(--tc, var(--brand)) 13%, var(--surface)); box-shadow: inset 4px 0 0 var(--tc, var(--brand)); }
.tt-cell strong { font-size: .9rem; }
.tt-cell small { color: var(--muted); font-size: .78rem; }
.tt-cell.conflict { box-shadow: inset 4px 0 0 var(--bad); background: var(--bad-bg); }
.tt-break td { padding: 2px 0; }
.tt-break .tt-cell { min-height: 0; padding: 4px 10px; border: 0; background: var(--surface-2); color: var(--muted); font-size: .8rem; text-align: center; display: block; }
.tt-day-list { display: grid; gap: 10px; }

@media (max-width: 900px) {
  .att-picker .field { flex: 1 1 140px; }
  .att-row, .att-row:has(.att-time) { grid-template-columns: minmax(0, 1fr); gap: 8px; padding: 12px 14px; }
  .seg { display: flex; width: 100%; }
  .seg label { flex: 1; }
  .seg span { min-width: 0; height: 44px; }
  .att-row.st-present .att-remark:placeholder-shown { display: none; }
  .att-time { width: 100%; }
  .att-save .panel-foot { flex-wrap: wrap; }
  .att-save .check { width: 100%; }
}
.chip-filters button { display: inline-flex; align-items: center; white-space: nowrap; padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: 700 .88rem var(--f-body); cursor: pointer; }
.chip-filters button.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.tt-mobile { display: none; }
.tt-item { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 10px; align-items: stretch; }
.tt-item .tt-time { font-size: .82rem; font-weight: 700; color: var(--muted); padding-top: 8px; }
.tt-item .tt-time small { display: block; font-weight: 400; color: var(--faint); }
.tt-item.is-break .tt-cell { min-height: 0; padding: 6px 10px; border: 0; background: var(--surface-2); color: var(--muted); text-align: center; display: block; font-size: .82rem; }
@media (max-width: 900px) {
  .tt-wrap { display: none; }
  .tt-mobile { display: block; }
}
@media print { .tt-mobile { display: none !important; } .tt-wrap { display: block !important; } }
@media (max-width: 900px) {
  .att-picker { gap: 8px; }
  .att-picker .field, .toolbar .field { min-width: 0 !important; flex: 1 1 140px !important; }
  .att-picker .att-nav { width: 100%; justify-content: center; }
}

/* ==========================================================================
   Phase 4: print documents (bills, receipts) and ID cards
   ========================================================================== */
body.print-view { background: #e9ece9; color: #111; }
.print-bar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); color: var(--ink); }
.print-bar-info { flex: 1; display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; font-size: .9rem; color: var(--muted); }
.print-area { padding: 20px 12px 60px; display: flex; flex-direction: column; align-items: center; gap: 18px; }
.doc-sheet { position: relative; background: #fff; color: #111; width: 148mm; min-height: 210mm; padding: 12mm 12mm 10mm; box-shadow: 0 4px 20px rgb(0 0 0 / .12); font: 10pt/1.45 var(--f-body); overflow: hidden; }
.doc-thermal .doc-sheet { width: 80mm; min-height: 0; padding: 5mm 4mm; font-size: 8.5pt; }
.doc-head { display: grid; grid-template-columns: auto 1fr auto; gap: 4mm; align-items: center; padding-bottom: 4mm; border-bottom: 0.6mm solid var(--brand); }
.doc-head img { width: 16mm; height: 16mm; object-fit: contain; }
.doc-head h1 { font: 700 13pt/1.15 var(--f-head); color: #111; margin: 0; }
.doc-head p { margin: 1mm 0 0; font-size: 8pt; color: #444; }
.doc-title { text-align: right; }
.doc-title strong { display: block; font: 800 12pt var(--f-head); letter-spacing: .04em; color: var(--brand); }
.doc-title span { font-size: 9pt; font-weight: 700; }
.doc-thermal .doc-head { grid-template-columns: 1fr; text-align: center; justify-items: center; gap: 1.5mm; }
.doc-thermal .doc-head h1 { font-size: 11pt; } .doc-thermal .doc-title { text-align: center; }
.doc-meta { display: grid; grid-template-columns: 1fr auto; gap: 4mm; margin: 5mm 0; }
.doc-meta > div:last-child { text-align: right; }
.doc-meta span { display: block; font-size: 8pt; color: #555; }
.doc-meta strong { display: block; font-size: 11pt; }
.doc-meta small { display: block; font-size: 8.5pt; color: #333; }
.doc-thermal .doc-meta { grid-template-columns: 1fr; } .doc-thermal .doc-meta > div:last-child { text-align: left; }
.doc-table { width: 100%; border-collapse: collapse; margin: 2mm 0; }
.doc-table th, .doc-table td { padding: 1.8mm 1mm; border-bottom: 0.2mm solid #ccc; text-align: left; vertical-align: top; }
.doc-table th:last-child, .doc-table td:last-child { text-align: right; white-space: nowrap; }
.doc-table thead th { font-size: 8pt; color: #555; border-bottom: 0.4mm solid #333; }
.doc-table tfoot th, .doc-table tfoot td { border-bottom: 0; } .doc-table tfoot tr:last-child th { font-size: 11.5pt; border-top: 0.4mm solid #333; }
.doc-table small { color: #555; }
.doc-words { margin: 3mm 0; font-style: italic; font-size: 9pt; }
.doc-sign { text-align: right; align-self: end; }
.doc-sign span { display: block; min-width: 40mm; padding-top: 10mm; border-bottom: 0.2mm solid #333; font-size: 9pt; }
.doc-foot { margin-top: 6mm; padding-top: 3mm; border-top: 0.2mm dashed #999; font-size: 8pt; color: #444; text-align: center; }
.doc-void { position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%) rotate(-24deg); font: 800 34pt var(--f-head); color: rgb(200 40 30 / .25); border: 2mm solid rgb(200 40 30 / .25); padding: 2mm 8mm; pointer-events: none; }

/* ID card sheets: everything in millimetres so it prints at the exact size */
.id-sheet { position: relative; background: #fff; box-shadow: 0 4px 20px rgb(0 0 0 / .12); overflow: hidden; }
.id-sheet .cut { position: absolute; background: #888; }
.id-slot { position: absolute; }
.id-label { font-size: .85rem; color: var(--muted); align-self: flex-start; }
.idc { position: relative; width: 100%; height: 100%; overflow: hidden; background: #fff; color: #14211F; border-radius: 3mm; box-shadow: inset 0 0 0 0.15mm #cfd6d2; font-family: var(--f-body); }
.idc-top { position: absolute; left: 0; right: 0; top: 0; height: 13.6mm; background: var(--brand); color: var(--brand-ink); display: flex; align-items: center; gap: 2mm; padding: 0 2.6mm; }
.idc-top img { width: 9mm; height: 9mm; object-fit: contain; background: #fff; border-radius: 1.6mm; padding: 0.5mm; flex: none; }
.idc-top .idc-school { min-width: 0; }
.idc-top strong { display: block; font: 700 7.2pt/1.1 var(--f-head); }
.idc-top small { display: block; font-size: 4.6pt; line-height: 1.25; opacity: .9; }
.idc-band { position: absolute; left: 0; right: 0; height: 1.2mm; background: var(--accent); }
.idc-photo { position: absolute; overflow: hidden; background: #e9eeeb; border: 0.6mm solid #fff; box-shadow: 0 0 0 0.2mm #b9c3be; border-radius: 2mm; display: grid; place-items: center; }
.idc-photo img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 28%; display: block; }
.idc-photo span { font: 700 14pt var(--f-head); color: #66736d; }
.idc-name { position: absolute; font: 700 9pt/1.12 var(--f-head); text-align: center; overflow: hidden; }
.idc-role { position: absolute; display: inline-block; padding: 0.5mm 2.4mm; border-radius: 3mm; background: var(--accent); color: var(--accent-ink); font: 700 5.2pt var(--f-body); }
.idc-fields { position: absolute; margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 0.5mm 2mm; font-size: 5.6pt; line-height: 1.25; }
.idc-fields dt { color: #5b6970; white-space: nowrap; }
.idc-fields dd { margin: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.idc-foot { position: absolute; left: 2.6mm; right: 2.6mm; bottom: 2mm; display: flex; justify-content: space-between; align-items: flex-end; font-size: 4.8pt; color: #44524b; }
.idc-sig { text-align: center; } .idc-sig img { display: block; height: 5mm; max-width: 18mm; margin: 0 auto -0.4mm; object-fit: contain; }
.idc-sig span { display: block; border-top: 0.15mm solid #44524b; padding-top: 0.4mm; min-width: 15mm; }
/* Portrait 54 x 85.6 */
.idc-p .idc-band { top: 13.6mm; }
.idc-p .idc-photo { left: 50%; transform: translateX(-50%); top: 17.4mm; width: 22mm; height: 27mm; }
.idc-p .idc-name { left: 2.5mm; right: 2.5mm; top: 45.6mm; max-height: 8.2mm; }
.idc-p .idc-role { left: 50%; transform: translateX(-50%); top: 54.2mm; }
.idc-p .idc-fields { left: 3.4mm; right: 3.4mm; top: 58.6mm; }
/* Landscape 85.6 x 54 */
.idc-l .idc-band { top: 13.6mm; }
.idc-l .idc-photo { left: 3mm; top: 17.2mm; width: 21mm; height: 26mm; }
.idc-l .idc-name { left: 27mm; right: 2.5mm; top: 17mm; text-align: left; max-height: 8.2mm; }
.idc-l .idc-role { left: 27mm; top: 25.6mm; }
.idc-l .idc-fields { left: 27mm; right: 2.5mm; top: 30mm; }
.idc-l .idc-foot { left: 27mm; }
.idc-l .idc-foot .idc-valid { position: absolute; left: -24mm; bottom: 0; }
/* Back side */
.idc-back { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 6mm 5mm; gap: 2mm; font-size: 6pt; }
.idc-back strong { font: 700 8pt var(--f-head); }
.idc-back .idc-back-box { width: 100%; border: 0.2mm solid #cfd6d2; border-radius: 2mm; padding: 2mm; display: grid; gap: 0.6mm; }
.idc-back img { width: 12mm; height: 12mm; object-fit: contain; }
.idc-back p { margin: 0; }
/* Screen preview */
.idc-preview { width: 54mm; height: 85.6mm; zoom: 1.6; }
.idc-preview.land { width: 85.6mm; height: 54mm; }
.idpick-list { list-style: none; margin: 0; padding: 0; }
.idpick-list li { display: flex; align-items: center; gap: 12px; padding: 8px 16px; border-bottom: 1px solid var(--line); }
.idpick-list li input { width: 20px; height: 20px; accent-color: var(--brand); flex: none; }

@media print {
  body.print-view { background: #fff; }
  .no-print { display: none !important; }
  .print-area { padding: 0; gap: 0; display: block; }
  .doc-sheet { box-shadow: none; margin: 0; page-break-after: always; break-after: page; }
  .doc-a5 .doc-sheet { width: 148mm; height: 210mm; }
  .id-sheet { box-shadow: none; page-break-after: always; break-after: page; }
  .id-label { display: none; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
/* Phones: show print previews smaller (printing is not affected) */
@media screen and (max-width: 700px) {
  .print-bar { flex-wrap: wrap; }
  .print-area { padding: 10px 0 40px; overflow-x: hidden; }
  .doc-a5 .doc-sheet { zoom: .62; }
  .id-sheet { zoom: .44; }
  .idcards-print .print-area { align-items: center; }
}

/* ==========================================================================
   Phase 5: marks entry, ledger, report cards
   ========================================================================== */
.marks-table td { vertical-align: middle; }
.marks-table .input { width: 90px; min-height: 40px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.marks-table .input.bad { border-color: var(--bad); background: var(--bad-bg); }
.marks-table .input.low { color: var(--bad); }
.marks-table input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--brand); }
.marks-table tr.is-absent td { background: var(--surface-2); }
.marks-table .mark-total { font-weight: 700; min-width: 60px; }
.exam-setup .input { width: 84px; min-height: 38px; text-align: center; }
.exam-setup input[type=date] { width: 150px; }
.ledger th, .ledger td { text-align: center; white-space: nowrap; padding: 8px 10px; }
.ledger .reg-name { text-align: left; }
.doc-a4 .doc-sheet { width: 210mm; min-height: 297mm; padding: 12mm 14mm 10mm; }
.ledger-print { font-size: 8pt; } .ledger-print th, .ledger-print td { text-align: center; padding: 1.2mm 1mm; border: 0.15mm solid #bbb; }
.ledger-print small { color: #555; }
.doc-signs { display: flex; justify-content: space-between; gap: 10mm; margin-top: 14mm; }
.doc-signs > span { flex: 1; text-align: center; border-top: 0.2mm solid #333; padding-top: 1.5mm; font-size: 9pt; position: relative; }
.doc-signs small { display: block; color: #555; font-size: 8pt; }
.doc-signs img { position: absolute; left: 50%; bottom: 100%; transform: translateX(-50%); height: 11mm; max-width: 40mm; object-fit: contain; }
.rc-student { display: grid; grid-template-columns: 1fr 28mm; gap: 6mm; margin: 5mm 0; align-items: start; }
.rc-info { display: grid; grid-template-columns: 1fr 1fr; gap: 2mm 6mm; }
.rc-info span, .rc-summary span, .rc-remark span { display: block; font-size: 7.5pt; color: #555; }
.rc-info strong { font-size: 10pt; }
.rc-photo { width: 28mm; height: 34mm; border: 0.3mm solid #999; border-radius: 1.5mm; overflow: hidden; display: grid; place-items: center; background: #f1f3f2; }
.rc-photo img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 28%; }
.rc-photo span { font: 700 14pt var(--f-head); color: #777; }
.rc-table th, .rc-table td { text-align: center; border: 0.15mm solid #bbb; padding: 1.6mm 1.2mm; }
.rc-table th:last-child, .rc-table td:last-child { text-align: center; }
.rc-table .rc-fail td { color: #b3361f; }
.rc-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2.5mm; margin: 4mm 0; padding: 3mm; border: 0.3mm solid var(--brand); border-radius: 2mm; }
.rc-summary strong { font-size: 10.5pt; }
.rc-remark { margin: 3mm 0; } .rc-remark p { margin: 0.5mm 0 0; font-size: 10pt; border-bottom: 0.2mm dotted #888; padding-bottom: 1mm; }
.rc-legend { width: 100%; border-collapse: collapse; margin-top: 3mm; font-size: 7pt; color: #444; }
.rc-legend td { border: 0.15mm solid #ccc; padding: 1mm; text-align: center; }
@media print { .doc-a4 .doc-sheet { width: 210mm; height: 297mm; } }
@media screen and (max-width: 700px) {
  .doc-a4 .doc-sheet { zoom: .45; }
  .doc-ledger .doc-sheet { zoom: .32; }
  .marks-table .input { width: 64px; }
}
@media (max-width: 700px) {
  .marks-table thead { display: none; }
  .marks-table, .marks-table tbody { display: block; }
  .marks-table tr { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
  .marks-table td { display: flex; align-items: center; gap: 6px; padding: 0; border: 0; }
  .marks-table td:first-child { width: 100%; }
  .marks-table td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .8rem; }
  .marks-table .input { width: 72px; min-height: 44px; font-size: 17px; }
  .marks-form .save-bar .muted { display: none; }
}
[hidden] { display: none !important; }

/* ==========================================================================
   Phase 7: certificates (A4). Award pages print landscape, letters portrait.
   ========================================================================== */
@page award { size: A4 landscape; margin: 0; }
@page letter { size: A4; margin: 0; }
.ct-sheet { position: relative; background: #fff; color: #1b1b1b; box-shadow: 0 4px 20px rgb(0 0 0 / .12); overflow: hidden; font-family: Georgia, "Times New Roman", serif; }
.ct-award { page: award; width: 297mm; height: 210mm; padding: 9mm; }
.ct-letter { page: letter; width: 210mm; height: 297mm; padding: 16mm 20mm 14mm; }
/* Award */
.ct-frame { height: 100%; padding: 2.4mm; border: 2.4mm solid var(--brand); }
.ct-inner { position: relative; height: 100%; border: 0.6mm solid var(--accent); padding: 9mm 18mm 8mm; display: flex; flex-direction: column; align-items: center; text-align: center;
  background: radial-gradient(circle at 0 0, color-mix(in oklab, var(--accent) 22%, transparent) 0 14mm, transparent 14.2mm),
              radial-gradient(circle at 100% 0, color-mix(in oklab, var(--accent) 22%, transparent) 0 14mm, transparent 14.2mm),
              radial-gradient(circle at 0 100%, color-mix(in oklab, var(--accent) 22%, transparent) 0 14mm, transparent 14.2mm),
              radial-gradient(circle at 100% 100%, color-mix(in oklab, var(--accent) 22%, transparent) 0 14mm, transparent 14.2mm); }
.ct-head img { height: 18mm; max-width: 40mm; object-fit: contain; }
.ct-head h1 { font: 700 17pt/1.15 var(--f-head); color: var(--brand); margin: 2mm 0 0; letter-spacing: .02em; }
.ct-head p { margin: 1mm 0 0; font: 8.5pt var(--f-body); color: #555; }
.ct-award .ct-title { font: italic 700 30pt/1.1 Georgia, "Times New Roman", serif; color: #1b1b1b; margin: 6mm 0 1mm; letter-spacing: .01em; }
.ct-award .ct-title::after { content: ""; display: block; width: 46mm; height: 0.8mm; margin: 3mm auto 0; background: var(--accent); }
.ct-lead { margin: 3mm 0 1mm; font-size: 11.5pt; color: #444; font-style: italic; }
.ct-name { font: 700 26pt/1.2 Georgia, "Times New Roman", serif; color: var(--brand); padding: 0 10mm 1.5mm; border-bottom: 0.3mm solid #999; min-width: 120mm; }
.ct-award .ct-body { margin-top: 4mm; max-width: 200mm; font-size: 13pt; line-height: 1.55; }
.ct-award .ct-body p { margin: 0; }
.ct-award .ct-photo.round { position: absolute; top: 9mm; right: 14mm; width: 26mm; height: 32mm; border-radius: 2mm; overflow: hidden; border: 0.6mm solid var(--brand); }
.ct-photo img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 28%; }
.ct-sigs { margin-top: auto; display: flex; justify-content: space-around; gap: 14mm; width: 100%; padding-top: 10mm; }
.ct-sig { position: relative; min-width: 48mm; text-align: center; border-top: 0.3mm solid #333; padding-top: 1.5mm; font: 10pt var(--f-body); color: #333; }
.ct-sig img { position: absolute; left: 50%; bottom: 100%; transform: translateX(-50%); height: 13mm; max-width: 44mm; object-fit: contain; }
.ct-foot { display: flex; justify-content: space-between; gap: 6mm; width: 100%; margin-top: 5mm; font: 7.5pt var(--f-body); color: #666; }
.ct-seal { position: absolute; left: 16mm; bottom: 20mm; width: 24mm; height: 24mm; border-radius: 50%; border: 0.8mm double var(--accent); display: grid; place-items: center; transform: rotate(-12deg); }
.ct-seal span { font: 700 8pt var(--f-head); color: var(--accent); text-align: center; padding: 2mm; }
/* Letter */
.ct-lh { display: grid; grid-template-columns: auto 1fr; gap: 5mm; align-items: center; padding-bottom: 4mm; border-bottom: 0.8mm solid var(--brand); }
.ct-lh img { height: 22mm; max-width: 34mm; object-fit: contain; }
.ct-lh h1 { font: 700 18pt/1.15 var(--f-head); color: var(--brand); margin: 0; }
.ct-lh p { margin: 1mm 0 0; font: 8.5pt var(--f-body); color: #555; }
.ct-ref { display: flex; justify-content: space-between; margin: 6mm 0 2mm; font: 10pt var(--f-body); }
.ct-letter .ct-photo { position: absolute; right: 20mm; top: 62mm; width: 30mm; height: 38mm; border: 0.3mm solid #888; overflow: hidden; }
.ct-letter .ct-title { text-align: center; font: 700 17pt Georgia, "Times New Roman", serif; text-decoration: underline; text-underline-offset: 2mm; margin: 14mm 0 12mm; letter-spacing: .03em; }
.ct-letter .ct-body { font-size: 12.5pt; line-height: 1.95; text-align: justify; }
.ct-letter .ct-body p { margin: 0 0 6mm; text-indent: 12mm; }
.ct-letter .ct-sigs { position: absolute; left: 20mm; right: 20mm; bottom: 30mm; width: auto; justify-content: space-between; }
.ct-letter .ct-foot { position: absolute; left: 20mm; right: 20mm; bottom: 12mm; width: auto; border-top: 0.2mm solid #ccc; padding-top: 2mm; }
.cert-preview { background: var(--surface-2); overflow: auto; display: flex; justify-content: center; }
.cert-preview .ct-sheet { zoom: .42; flex: none; }
@media print { .ct-sheet { box-shadow: none; page-break-after: always; break-after: page; } }
@media screen and (max-width: 700px) { .certs-print .ct-sheet { zoom: .34; } }
/* Award: fill the page with calmer spacing */
.ct-award .ct-title { font-size: 34pt; margin-top: 12mm; }
.ct-award .ct-lead { margin-top: 9mm; font-size: 12.5pt; }
.ct-award .ct-name { font-size: 32pt; padding-bottom: 2mm; min-width: 140mm; }
.ct-award .ct-body { margin-top: 7mm; font-size: 15pt; line-height: 1.6; }
