/* ==========================================================================
   EduPort design language, "Chalk": components

   Tokens live in ds-tokens.css, which loads before this file. Every rule here
   is either an `.ek-*` component or a restyle of an existing `.portal-*` /
   `.sb-*` / `.tb` class.
   No @layer: Tailwind's runtime utilities would be silently reprioritised.
   ========================================================================== */

/* ---- Base ---------------------------------------------------------------- */
body {
  font-family: var(--font-body);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 {
  line-height: var(--leading-tight);
  letter-spacing: -0.015em;
}

a { text-underline-offset: 2px; }

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--r-sm);
}

.ek-skip {
  position: fixed;
  top: -100px;
  left: var(--sp-4);
  z-index: var(--z-toast);
  padding: var(--sp-2) var(--sp-4);
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-primary);
  border-radius: var(--r-sm);
  transition: top var(--dur-fast) var(--ease-out);
}
.ek-skip:focus { top: var(--sp-4); }

/* ---- Shell skin ---------------------------------------------------------- */
.portal-topbar {
  background: color-mix(in srgb, var(--color-surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--color-border-inner);
  box-shadow: none;
  gap: var(--sp-2);
  padding: 0 var(--sp-4);
}

.tb-school {
  font-size: var(--text-base);
  font-weight: 650;
  letter-spacing: -0.01em;
}

.tb-title { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
/* The session and term chips say which school day every figure on the page belongs
   to, so they hold their width and the search pill gives way instead. Allowing them
   to shrink clipped "2026/2027" to "2026/" at 1366. */
.tb-scope { display: inline-flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.tb-scope .ek-pill {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 0 1 auto;
}
.tb-scope a.ek-pill:hover { text-decoration: none; filter: brightness(1.08); }
/* Below 1500 the row cannot hold the history buttons, the session and term chips, the
   center switcher, the search pill, six quick links and the account menu all at once.
   The quick links repeat destinations the sidebar already names, and the key hint is
   decoration on a control that is still labelled, so those give way first. Without
   this the title block was squeezed to 86px and its 148px of chips painted over the
   switcher. The links carry .tb-hide-sm, which pins them to inline-flex !important
   from 640px up, so this has to answer at the same weight. */
@media (max-width: 1499px) {
  .portal-topbar .tb-quick { display: none !important; }
}
.tb-history { display: inline-flex; align-items: center; gap: 2px; flex: 0 0 auto; }
.tb-history .tb-btn { width: 32px; height: 32px; }
.ek-center-switch { display: none; }
.ek-back { display: none; }
@media (max-width: 1023px) {
  .tb-history { display: none; }
  .ek-back { display: inline-flex; }
  .tb-search-kbd { display: none; }
  .tb-quick { display: none !important; }
  .tb-user-text { display: none; }
  .tb-school { display: none; }
  .tb-scope .ek-pill:first-child { display: none; }
}
@media (max-width: 767px) {
  .tb-search-trigger { display: none; }
  .tb-btn.tb-search-mobile { display: inline-flex; }
  .tb-scope { display: none; }
  .tb-school { display: block; }
}

.tb-search-trigger {
  border: 1px solid var(--color-border-inner);
  background: var(--color-surface-2);
  border-radius: var(--r-pill);
  color: var(--color-text-faint);
  height: 34px;
  transition: border-color var(--dur-fast), color var(--dur-fast);
}
.tb-search-trigger:hover {
  border-color: var(--color-primary);
  color: var(--color-text);
}

.tb-btn {
  border-radius: var(--r-sm);
  color: var(--color-text-muted);
  transition: background var(--dur-fast), color var(--dur-fast);
}
.tb-btn:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

.sb-panel {
  background: color-mix(in srgb, var(--color-surface) 96%, var(--color-bg));
  border-right: 1px solid var(--color-border-inner);
  box-shadow: none;
}

.sb-brand {
  border-bottom: 1px solid var(--color-border-inner);
}

.sb-brand-name {
  font-weight: 650;
  letter-spacing: -0.01em;
}

.sb-section-label {
  font-size: var(--text-2xs);
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--color-text-faint);
  padding: var(--sp-4) var(--sp-4) var(--sp-2);
}

.sb-link {
  border-radius: var(--r-sm);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-muted);
  transition: background var(--dur-fast), color var(--dur-fast);
}
.sb-link:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}
.sb-link.active {
  background: color-mix(in srgb, var(--color-primary) 16%, transparent);
  color: var(--color-text);
  font-weight: 600;
}
.sb-link.active::before {
  background: var(--color-primary);
  width: 3px;
  border-radius: 0 3px 3px 0;
}

.sb-child-link {
  font-size: var(--text-sm);
  color: var(--color-text-faint);
  border-radius: var(--r-sm);
}
.sb-child-link.active {
  color: var(--color-text);
  background: color-mix(in srgb, var(--color-primary) 12%, transparent);
}

.sb-lock { opacity: 0.6; }

.sb-footer {
  border-top: 1px solid var(--color-border-inner);
  background: transparent;
}

.portal-main-area {
  padding: var(--sp-4) var(--sp-6);
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  background:
    radial-gradient(900px 420px at 88% -8%, color-mix(in srgb, var(--color-primary) 8%, transparent), transparent 70%),
    var(--color-bg);
}

.page-report-broadsheet .portal-main-area {
  padding: var(--sp-3) var(--sp-4);
}
.page-report-broadsheet .ek-page {
  max-width: 100% !important;
  width: 100% !important;
  margin: 0 !important;
}

.portal-bottom-nav {
  background: color-mix(in srgb, var(--color-surface) 94%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--color-border-inner);
}

.portal-bottom-nav-item {
  font-size: var(--text-2xs);
  letter-spacing: 0.01em;
}

/* ---- Buttons ------------------------------------------------------------- */
.portal-btn-primary,
.portal-btn-secondary,
.portal-btn-danger,
.portal-btn-success,
.portal-btn-warning,
.portal-btn-accent,
.ek-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 36px;
  padding: 0 var(--sp-4);
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  transition: filter var(--dur-fast), background var(--dur-fast), border-color var(--dur-fast);
}
.portal-btn-primary:hover,
.portal-btn-danger:hover,
.portal-btn-success:hover,
.portal-btn-warning:hover,
.portal-btn-accent:hover,
.ek-btn:hover { filter: brightness(1.08); }
.portal-btn-primary:active,
.ek-btn:active { transform: translateY(1px); }

/* The kit's default button is the primary action; ghost and quiet are the
   secondary surfaces. A plain .ek-btn must never render as bare text. */
.ek-btn,
.ek-btn--primary {
  background: var(--brand);
  color: var(--on-brand);
  border-color: var(--brand);
}

.portal-btn-secondary,
.ek-btn--ghost {
  background: var(--color-surface-2);
  color: var(--color-text);
  border-color: var(--color-border-inner);
}

.ek-btn--quiet {
  background: transparent;
  color: var(--color-text-muted);
  border-color: transparent;
  padding: 0 var(--sp-2);
}
.ek-btn--quiet:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

.ek-btn--warning {
  background: var(--color-warning, #f59e0b);
  color: var(--warning-ink, #78350f);
  border-color: var(--color-warning, #f59e0b);
  font-weight: 600;
}
.ek-btn--warning:hover {
  filter: brightness(0.95);
}

.ek-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--r-sm);
  color: var(--color-text-muted);
  border: 1px solid transparent;
  transition: background var(--dur-fast), color var(--dur-fast);
}
.ek-icon-btn:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

/* ---- Inputs -------------------------------------------------------------- */
.portal-input,
.portal-form input[type="text"],
.portal-form input[type="email"],
.portal-form input[type="number"],
.portal-form input[type="date"],
.portal-form input[type="tel"],
.portal-form input[type="password"],
.portal-form select,
.portal-form textarea,
.ek-input {
  width: 100%;
  min-height: 38px;
  padding: 0 var(--sp-3);
  border-radius: var(--r-sm);
  border: 1px solid var(--color-border-input);
  background: var(--color-surface-2);
  color: var(--color-text);
  font: inherit;
  font-size: var(--text-sm);
  transition: border-color var(--dur-fast), background var(--dur-fast);
}
.portal-form textarea, textarea.ek-input {
  padding: var(--sp-2) var(--sp-3);
  min-height: 92px;
  line-height: var(--leading-normal);
}
.portal-input:focus,
.portal-form input:focus,
.portal-form select:focus,
.portal-form textarea:focus,
.ek-input:focus {
  border-color: var(--color-primary);
  background: var(--color-surface);
  outline: none;
}
.portal-form-label,
.ek-label {
  font-size: var(--text-2xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-faint);
}
.ek-select { max-width: 100%; text-overflow: ellipsis; }

.ek-check {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 32px;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}
.ek-check input { width: 16px; height: 16px; accent-color: var(--color-primary); }

/* ---- Page furniture ------------------------------------------------------ */
.ek-page {
  width: 100%;
  max-width: var(--mw-page, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--flow);
}
.ek-page--fluid {
  max-width: 100% !important;
  width: 100% !important;
  margin: 0 !important;
}
.ek-page--doc {
  max-width: var(--mw-doc, 1280px);
  width: 100%;
}
.ek-page--fluid.ek-page--doc,
.ek-page--doc.ek-page--fluid {
  max-width: 100% !important;
  width: 100% !important;
  margin: 0 !important;
}

.ek-pagehead {
  position: sticky;
  /* The shell topbar is fixed at 60px; a header at top: 0 hides behind it. */
  top: 60px;
  z-index: var(--z-dock);
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-2) 0 var(--sp-3);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border-inner);
}
.ek-pagehead__main { min-width: 0; flex: 1 1 320px; }
.ek-page-title {
  margin: 0;
  font-size: var(--text-xl);
  font-weight: 680;
  color: var(--color-text);
}
.ek-page-sub {
  margin: var(--sp-1) 0 0;
  font-size: var(--text-sm);
  color: var(--color-text-faint);
  max-width: 78ch;
}
.ek-pagehead__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
}
/* A sheet's filters live in the frozen page head, not in a second bar below it. */
.ek-headform {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  margin: 0;
}
.ek-headform .ek-label { margin: 0; }
.ek-headform .ek-input { width: auto; min-width: 132px; max-width: 260px; }
.ek-headform .ek-btn,
.ek-headform .portal-btn-secondary { white-space: nowrap; }

.ek-pagehead--sheet {
  align-items: center;
  padding: var(--sp-2) 0;
  gap: var(--sp-2);
}
.ek-pagehead--sheet form.ek-headform {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
}
.ek-pagehead--sheet .ek-page-title {
  font-size: var(--text-lg);
  font-weight: 700;
  margin: 0;
  white-space: nowrap;
}
.ek-pagehead--sheet .ek-label {
  margin: 0;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-faint);
}
.ek-meta { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-top: var(--sp-2); }

.ek-section-title {
  margin: 0 0 var(--sp-3);
  font-size: var(--text-md);
  font-weight: 650;
}
.ek-card-title { margin: 0; font-size: var(--text-md); font-weight: 650; }

.ek-grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(12, minmax(0, 1fr)); }
/* Selector pages lay out one card per class or subject, so the row holds as many as
   fit rather than a fixed twelve columns. A class, because the v2 screens carry no
   inline style attributes. */
.ek-grid--auto { grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr)); }
.ek-grid--auto-wide { grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr)); }
.ek-grid > * { min-width: 0; }
.ek-col-3 { grid-column: span 3; }
.ek-col-4 { grid-column: span 4; }
.ek-col-6 { grid-column: span 6; }
.ek-col-8 { grid-column: span 8; }
.ek-col-12 { grid-column: span 12; }
/* A KPI band is four across on a desktop and one across on a phone. Declared
   here because the band is a plain .ek-grid with .ek-kpi children. */
.ek-grid > .ek-kpi { grid-column: span 3; }
.ek-split { display: grid; gap: var(--sp-4); grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.ek-split--rev { display: grid; gap: var(--sp-4); grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
.ek-split--even { display: grid; gap: var(--sp-4); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.ek-split > *,
.ek-split--rev > *,
.ek-split--even > * { min-width: 0; }
.ek-split:has(> :only-child),
.ek-split--rev:has(> :only-child),
.ek-split--even:has(> :only-child) { grid-template-columns: minmax(0, 1fr); }
.ek-stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.ek-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.ek-spacer { flex: 1 1 auto; }

/* ---- Cards --------------------------------------------------------------- */
.portal-card,
.ek-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border-inner);
  border-radius: var(--r-md);
  box-shadow: none;
  padding: var(--sp-5);
}
.portal-card:hover { box-shadow: none; }
.ek-card--flush { padding: 0; overflow: hidden; }
/* A stored JSON payload, as an auditor reads it: monospaced, scrollable inside its own
   box, and never wider than the card that holds it. */
.ek-code {
  margin: 0;
  padding: var(--sp-3);
  border: 1px solid var(--color-border-inner);
  border-radius: var(--r-sm);
  background: var(--color-surface-2);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: var(--text-xs);
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 340px;
  overflow: auto;
}
.ek-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--color-border-inner);
}
.ek-card__body { padding: var(--sp-5); }
.ek-card__foot {
  padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--color-border-inner);
  font-size: var(--text-2xs);
  color: var(--color-text-faint);
}

/* ---- KPI ----------------------------------------------------------------- */
.ek-kpi {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  min-height: 116px;
  padding: var(--sp-4) var(--sp-5);
  background: var(--color-surface);
  border: 1px solid var(--color-border-inner);
  border-radius: var(--r-md);
  color: inherit;
  text-decoration: none;
  transition: border-color var(--dur-fast), background var(--dur-fast);
}
a.ek-kpi:hover {
  border-color: color-mix(in srgb, var(--color-primary) 55%, var(--color-border-inner));
  background: color-mix(in srgb, var(--color-primary) 5%, var(--color-surface));
  text-decoration: none;
}
.ek-kpi__top { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.ek-kpi__icon {
  width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--color-primary) 14%, transparent);
  color: var(--color-primary-text);
}
/* Same reason as the empty-state icon: a bare svg measures 300 by 150 and only the
   glyph looks right by accident, because the symbol centres itself in the box. */
.ek-kpi__icon svg { width: 18px; height: 18px; }
.ek-figure {
  font-family: var(--font-num);
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: var(--tracking-num);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  color: var(--color-text);
}
.ek-figure--hero { font-size: var(--text-3xl); }
.ek-unit { font-size: var(--text-sm); color: var(--color-text-faint); margin-left: var(--sp-1); }
.ek-kpi__caption { font-size: var(--text-2xs); color: var(--color-text-faint); }
.ek-kpi__foot { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.ek-spark { display: block; width: 100%; height: 26px; overflow: visible; }
.ek-spark path { fill: none; stroke: var(--color-primary); stroke-width: 1.6; }

.ek-delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: var(--text-2xs);
  font-weight: 600;
  padding: 2px 7px;
  border-radius: var(--r-pill);
  background: var(--color-surface-2);
  color: var(--color-text-muted);
}
.ek-delta--good { background: var(--color-success-bg); color: var(--color-success); }
.ek-delta--bad { background: var(--color-danger-bg); color: var(--color-danger); }

/* ---- Chart card ---------------------------------------------------------- */
.ek-chartcard {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-5);
  background: var(--color-surface);
  border: 1px solid var(--color-border-inner);
  border-radius: var(--r-md);
  min-width: 0;
}
.ek-chartcard__head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-2); }
.ek-chartcard__canvas { position: relative; width: 100%; min-width: 0; }
.ek-chartcard__canvas canvas { display: block; width: 100% !important; }
.ek-chartcard__foot {
  font-size: var(--text-2xs);
  color: var(--color-text-faint);
  border-top: 1px solid var(--color-border-inner);
  padding-top: var(--sp-2);
}

/* ---- Table --------------------------------------------------------------- */
.ek-tablewrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--color-border-inner);
  border-radius: var(--r-md);
  background: var(--color-surface);
}
.ek-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 0;
  background: transparent;
  border-radius: 0;
  box-shadow: none;
  font-size: var(--text-sm);
}
.ek-table caption {
  caption-side: top;
  text-align: left;
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--text-2xs);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-text-faint);
}
.ek-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--color-surface-2);
  font-size: var(--text-2xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-faint);
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--color-border-inner);
  white-space: nowrap;
}
.ek-table tbody td {
  height: var(--row-h);
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--color-border-inner);
  vertical-align: middle;
  color: var(--color-text-muted);
}
.ek-table tbody tr:last-child td { border-bottom: 0; }
.ek-table tbody tr:hover td { background: var(--color-surface-2); }
.ek-table .num,
.ek-num {
  text-align: right;
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--tracking-num);
}
.ek-table .ek-actions {
  width: 1%;
  white-space: nowrap;
  text-align: right;
}
.ek-actions .ek-icon-btn { opacity: 0; transition: opacity var(--dur-fast); }
.ek-table tr:hover .ek-actions .ek-icon-btn,
.ek-actions .ek-icon-btn:focus-visible { opacity: 1; }
@media (hover: none) { .ek-actions .ek-icon-btn { opacity: 1; } }

.ek-th-sort {
  color: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.ek-th-sort:hover { color: var(--color-text); text-decoration: none; }
.ek-th-sort[aria-current="true"] { color: var(--color-primary-text); }

/* ---- Toolbar ------------------------------------------------------------- */
.ek-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border-inner);
  border-radius: var(--r-md);
}
.ek-toolbar form { display: contents; }
.ek-toolbar .ek-search { flex: 1 1 240px; min-width: 0; }
.ek-toolbar select.ek-input,
.ek-toolbar input.ek-input { width: auto; min-width: 132px; max-width: 260px; }
.ek-toolbar__count {
  margin-left: auto;
  font-size: var(--text-2xs);
  color: var(--color-text-faint);
  white-space: nowrap;
}
.ek-toolbar--sticky {
  position: sticky;
  top: 60px;
  z-index: var(--z-dock);
  backdrop-filter: blur(8px);
}

/* ---- Quick-action tiles -------------------------------------------------- */
.ek-tilegrid {
  display: grid;
  gap: var(--sp-2);
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr));
}
.ek-tile {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  min-width: 0;
  padding: var(--sp-3);
  border: 1px solid var(--color-border-inner);
  border-radius: var(--r-md);
  background: var(--color-surface);
  color: inherit;
  text-decoration: none;
  transition: border-color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}
.ek-tile:hover {
  border-color: var(--color-primary);
  background: var(--color-surface-2);
  text-decoration: none;
}
.ek-tile__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--color-primary) 12%, transparent);
  color: var(--color-primary-text);
}
.ek-tile__icon .gi,
.ek-tile__icon svg { width: 18px; height: 18px; }
.ek-tile__body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ek-tile__title { font-size: var(--text-sm); font-weight: 650; color: var(--color-text); }
.ek-tile__sub { font-size: var(--text-2xs); color: var(--color-text-faint); }

/* ---- Three-series coverage ----------------------------------------------- */
.ek-covlist { display: flex; flex-direction: column; gap: 4px; }
.ek-cov { display: flex; align-items: center; gap: 6px; }
.ek-cov__label {
  flex: 0 0 58px;
  font-size: var(--text-2xs);
  color: var(--color-text-faint);
}
.ek-cov__track {
  flex: 1 1 auto;
  height: 5px;
  min-width: 48px;
  border-radius: var(--r-pill);
  background: var(--color-surface-2);
  overflow: hidden;
}
.ek-cov__fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--color-success);
}
.ek-cov__fill--warn { background: var(--color-warning); }
.ek-cov__fill--bad { background: var(--color-danger); }
.ek-cov__value {
  flex: 0 0 32px;
  text-align: right;
  font-size: var(--text-2xs);
  font-variant-numeric: tabular-nums;
  color: var(--color-text-faint);
}

.ek-search { position: relative; display: flex; align-items: center; }
.ek-search input { padding-left: 2.1rem; }
.ek-search .ek-search__icon {
  position: absolute; left: 10px; width: 15px; height: 15px;
  color: var(--color-text-faint); pointer-events: none;
}

.ek-segment {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  border-radius: var(--r-sm);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border-inner);
  overflow-x: auto;
  max-width: 100%;
}
.ek-segment > a,
.ek-segment > button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  /* The strip scrolls on a phone, so each label keeps its full width and the user
     scrolls to it. Without this the flex items shrink below their nowrap text and
     every label loses its first word. */
  flex: 0 0 auto;
  padding: 0 var(--sp-3);
  border-radius: 4px;
  font-size: var(--text-2xs);
  font-weight: 600;
  color: var(--color-text-faint);
  white-space: nowrap;
  text-decoration: none;
}
.ek-segment > a:hover,
.ek-segment > button:hover { color: var(--color-text); background: color-mix(in srgb, var(--color-surface) 60%, transparent); }
.ek-segment > a[aria-current="true"],
.ek-segment > button[aria-selected="true"],
.ek-segment > .is-active {
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--elev-1);
}

/* ---- Pills --------------------------------------------------------------- */
.portal-badge,
.ek-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 22px;
  padding: 1px 9px;
  border-radius: var(--r-pill);
  font-size: var(--text-2xs);
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  border: 1px solid transparent;
}
.ek-pill--success { background: var(--color-success-bg); color: var(--success-ink); }
.ek-pill--warning { background: var(--color-warning-bg); color: var(--warning-ink); }
.ek-pill--danger { background: var(--color-danger-bg); color: var(--danger-ink); }
.ek-pill--info { background: var(--color-info-bg); color: var(--info-ink); }
.ek-pill--primary { background: var(--color-primary-bg); color: var(--color-primary-text); }
.ek-pill--stale { background: color-mix(in srgb, var(--color-stale) 18%, var(--color-surface)); color: var(--color-text-muted); font-style: italic; }
.ek-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
  flex: 0 0 6px;
}
.ek-live-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor; flex: 0 0 7px;
  box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 18%, transparent);
}
.ek-duty-actions { display: inline-flex; flex-wrap: wrap; gap: 4px; margin-left: 6px; }
.ek-duty-actions form { display: inline-flex; }

/* ---- Meter, scorebar, rank ----------------------------------------------- */
.ek-meter { display: flex; flex-direction: column; gap: 6px; }
.ek-meter__top { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-2); }
.ek-meter__label { font-size: var(--text-2xs); font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--color-text-faint); }
.ek-meter__value { font: 600 var(--text-xs) var(--font-num); font-variant-numeric: tabular-nums; color: var(--color-text-muted); }
.ek-meter__track {
  position: relative;
  height: 8px;
  border-radius: 4px;
  background: var(--color-surface-2);
  overflow: hidden;
}
.ek-meter__fill {
  display: block;
  height: 100%;
  border-radius: 4px;
  background: var(--color-primary);
  transition: width var(--dur-base) var(--ease-out);
}
.ek-meter--good .ek-meter__fill { background: var(--color-success); }
.ek-meter--warn .ek-meter__fill { background: var(--color-warning); }
.ek-meter--bad .ek-meter__fill { background: var(--color-danger); }
.ek-meter__caption { font-size: var(--text-2xs); color: var(--color-text-faint); }

.ek-scorebar { display: flex; flex-direction: column; gap: var(--sp-2); }
.ek-scorebar__track {
  display: flex;
  height: 10px;
  border-radius: 5px;
  overflow: hidden;
  background: var(--color-surface-2);
}
.ek-scorebar__seg { height: 100%; }
.ek-scorebar__legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  font-size: var(--text-2xs);
  color: var(--color-text-faint);
}
.ek-scorebar__legend span { display: inline-flex; align-items: center; gap: 5px; }
.ek-scorebar__swatch { width: 8px; height: 8px; border-radius: 2px; }
.ek-band-a { background: var(--band-a); }
.ek-band-b { background: var(--band-b); }
.ek-band-c { background: var(--band-c); }
.ek-band-d { background: var(--band-d); }
.ek-band-e { background: var(--band-e); }
.ek-band-none { background: var(--color-border-strong); }
.ek-rank {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.ek-rank small { font-size: 0.75em; color: var(--color-text-faint); font-weight: 500; }

/* ---- States -------------------------------------------------------------- */
.ek-empty {
  display: grid;
  justify-items: center;
  gap: var(--sp-2);
  text-align: center;
  padding: var(--sp-10) var(--sp-4);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--color-surface) 55%, transparent);
  color: var(--color-text-faint);
}
.ek-empty__icon {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--color-surface-2);
  color: var(--color-text-muted);
}
/* The icon helper emits a bare <svg> when a call site passes no class, and a bare svg
   with no width defaults to 300 by 150 whatever box it sits in. Inside this 44px circle
   that painted a clipboard across the empty-state title. Size the element here so every
   call site is safe, including the ones that never pass a class. */
.ek-empty__icon svg { width: 22px; height: 22px; }
.ek-empty__title { color: var(--color-text); font-weight: 650; font-size: var(--text-base); }
.ek-empty__text { max-width: 46ch; font-size: var(--text-sm); }
.ek-empty__actions { margin-top: var(--sp-2); display: flex; gap: var(--sp-2); flex-wrap: wrap; }

.ek-skeleton {
  position: relative;
  overflow: hidden;
  border-radius: var(--r-sm);
  background: var(--color-surface-2);
  min-height: 12px;
}
.ek-skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.06), transparent);
  animation: ek-shimmer 1.4s infinite;
}
@keyframes ek-shimmer { to { transform: translateX(100%); } }
@media (prefers-reduced-motion: reduce) { .ek-skeleton::after { animation: none; } }

.ek-error {
  border-left: 3px solid var(--color-danger);
  background: var(--color-danger-bg);
  color: var(--color-text);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-sm);
  font-size: var(--text-sm);
}
.ek-stale-note {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---- Alerts and banners -------------------------------------------------- */
.portal-alert,
.ek-banner {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-sm);
  border: 1px solid var(--color-border-inner);
  border-left-width: 3px;
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-sm);
}
.ek-banner--info { border-left-color: var(--color-info); background: var(--color-info-bg); }
.ek-banner--success { border-left-color: var(--color-success); background: var(--color-success-bg); }
.ek-banner--warning { border-left-color: var(--color-warning); background: var(--color-warning-bg); }
.ek-banner--danger { border-left-color: var(--color-danger); background: var(--color-danger-bg); }
.ek-banner__body { flex: 1 1 auto; min-width: 0; }
.ek-banner__title { font-weight: 650; }

.sub-warn-banner { margin-bottom: var(--sp-4); }
.sub-warn-banner > div {
  border-radius: var(--r-sm);
  border-width: 1px;
  border-left-width: 3px;
}

/* ---- Toasts and modal ---------------------------------------------------- */
#flash-messages {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  width: min(560px, 92vw);
  pointer-events: none;
}
.portal-toast {
  border-radius: var(--r-sm);
  box-shadow: var(--elev-2);
  border: 1px solid var(--color-border-inner);
}
.portal-modal {
  border-radius: var(--r-lg);
  border: 1px solid var(--color-border-inner);
  background: var(--color-surface);
  box-shadow: var(--elev-3);
}
.portal-modal-overlay { background: rgba(2, 6, 23, 0.62); backdrop-filter: blur(3px); }

/* ---- Misc ---------------------------------------------------------------- */
.ek-timeline { display: flex; flex-direction: column; gap: 0; }
.ek-timeline__item {
  position: relative;
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: var(--sp-3);
  padding-bottom: var(--sp-4);
}
.ek-timeline__rail { display: flex; flex-direction: column; align-items: center; }
.ek-timeline__dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--color-primary);
  margin-top: 5px;
}
.ek-timeline__line { flex: 1 1 auto; width: 1px; background: var(--color-border-inner); margin-top: 4px; }
.ek-timeline__body { min-width: 0; font-size: var(--text-sm); }
.ek-timeline__time { font-size: var(--text-2xs); color: var(--color-text-faint); }

.ek-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  flex: 0 0 32px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  font-size: var(--text-2xs);
  font-weight: 700;
  letter-spacing: 0.02em;
}
.ek-avatar img { width: 100%; height: 100%; object-fit: cover; }
.ek-avatar--sm { width: 24px; height: 24px; flex-basis: 24px; }
.ek-avatar--lg { width: 48px; height: 48px; flex-basis: 48px; font-size: var(--text-sm); }

.ek-help { color: var(--color-text-faint); }
.ek-help:hover { color: var(--color-primary-text); }

.ek-divide { height: 1px; background: var(--color-border-inner); border: 0; margin: var(--sp-2) 0; }

.ek-bulkbar {
  position: sticky;
  bottom: var(--sp-4);
  z-index: var(--z-dock);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  background: var(--color-surface);
  border: 1px solid var(--color-primary);
  border-radius: var(--r-md);
  box-shadow: var(--elev-2);
  font-size: var(--text-sm);
}

/* ---- List rows, suggestions and inline detail ---------------------------- */
.ek-listrow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  padding: 7px var(--sp-2);
  border-radius: var(--r-sm);
  color: inherit;
  font-size: var(--text-sm);
  text-decoration: none;
}
.ek-listrow:hover { background: var(--color-surface-2); text-decoration: none; }
.ek-listrow > span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* A debtor row in the narrow follow-up card: name and balance, then the class,
   age pill and the action on a second line. */
.ek-followup {
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--color-border-inner);
}
.ek-followup:first-child { border-top: 0; }
.ek-followup__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-2);
}
.ek-followup__meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-top: 2px;
}
.ek-followup__meta .ek-btn {
  margin-left: auto;
  min-height: 30px;
  padding: 0 var(--sp-3);
}
.ek-ink--bad { color: var(--color-danger); }
.ek-ink--good { color: var(--color-success); }

.ek-suggest {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: var(--z-dock);
  max-height: 16rem;
  overflow-y: auto;
  padding: 4px;
  background: var(--color-surface);
  border: 1px solid var(--color-border-inner);
  border-radius: var(--r-md);
  box-shadow: var(--elev-2);
}
.ek-suggest__row {
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: 100%;
  padding: 7px var(--sp-2);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--color-text);
  text-align: left;
  cursor: pointer;
}
.ek-suggest__row:hover { background: var(--color-surface-2); }
.ek-suggest__name { font-size: var(--text-sm); font-weight: 600; }
.ek-suggest__meta { font-size: var(--text-2xs); color: var(--color-text-faint); }
.ek-search { position: relative; }

.ek-details { border-top: 1px solid var(--color-border-inner); padding-top: var(--sp-2); }
.ek-details > summary {
  cursor: pointer;
  font-size: var(--text-2xs);
  color: var(--color-text-faint);
}
.ek-details > summary:hover { color: var(--color-text); }

.ek-proofrow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--color-border-inner);
}
.ek-proofrow__main { flex: 1 1 240px; min-width: 0; }

/* ---- Item rows (circulars, notices, announcements) ----------------------- */
.ek-itemrow,
.ek-circular-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3) var(--sp-4);
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--color-border-inner);
  transition: background var(--dur-fast);
}
.ek-itemrow:first-child,
.ek-circular-row:first-child {
  border-top: 0;
}
.ek-itemrow:hover,
.ek-circular-row:hover {
  background: color-mix(in srgb, var(--color-surface-2) 65%, transparent);
}
.ek-itemrow__main,
.ek-circular-row__main {
  flex: 1 1 280px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ek-itemrow__actions,
.ek-circular-row__actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-left: auto;
  flex-shrink: 0;
}
.ek-itemrow__actions form,
.ek-circular-row__actions form {
  display: inline-flex;
  margin: 0;
}
.ek-itemrow__actions .ek-danger-btn,
.ek-circular-row__actions .ek-danger-btn {
  color: var(--color-danger);
}
.ek-itemrow__actions .ek-danger-btn:hover,
.ek-circular-row__actions .ek-danger-btn:hover {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}
.ek-row--gap-sm {
  gap: var(--sp-2);
  align-items: center;
}

/* ---- Arrears aging ------------------------------------------------------- */
.ek-aging {
  display: flex;
  height: 12px;
  margin-top: 6px;
  border-radius: var(--r-pill);
  overflow: hidden;
  background: var(--color-surface-2);
}
.ek-aging__seg { display: block; height: 100%; }
.ek-aging__seg + .ek-aging__seg { border-left: 1px solid var(--color-surface); }
.ek-aging__legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2) var(--sp-4);
  margin-top: var(--sp-2);
  font-size: var(--text-2xs);
  color: var(--color-text-muted);
}
.ek-aging__legend > span { display: inline-flex; align-items: center; gap: 5px; }

/* ---- Error state --------------------------------------------------------- */
.ek-error {
  max-width: 34rem;
  margin: clamp(2rem, 8vh, 5rem) auto;
  padding: var(--sp-6);
  text-align: center;
  background: var(--color-surface);
  border: 1px solid var(--color-border-inner);
  border-radius: var(--r-md);
}
.ek-error__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  margin-bottom: var(--sp-3);
  border-radius: 50%;
}
.ek-error__icon .gi { width: 26px; height: 26px; }
.ek-error--danger .ek-error__icon { background: var(--color-danger-bg); color: var(--color-danger); }
.ek-error--warning .ek-error__icon { background: var(--color-warning-bg); color: var(--color-warning); }
.ek-error--info .ek-error__icon { background: var(--color-primary-bg); color: var(--color-primary-text); }
.ek-error .ek-page-title { font-size: var(--text-xl); margin: 2px 0 var(--sp-2); }
.ek-error .ek-page-sub { margin: 0 auto var(--sp-2); }

/* ---- Stale polled values ------------------------------------------------- */
/* A failed poll keeps the last known value and fades it. The read time is
   carried in the title and in a visually hidden note, never as an overlaid
   line that could cover the bar it belongs to. */
.ek-stale { opacity: 0.72; }

/* ---- Sidebar rail dots --------------------------------------------------- */.sb-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  margin-left: auto;
  border-radius: 50%;
  background: var(--color-danger);
  box-shadow: 0 0 0 2px var(--color-surface);
}
.sb.collapsed .sb-link .sb-dot,
.sb.collapsed .sb-group-header .sb-dot {
  position: absolute;
  top: 7px;
  left: 35px;
  margin: 0;
}

/* ---- Responsive ---------------------------------------------------------- */
@media (max-width: 1024px) {
  .ek-col-8, .ek-col-6, .ek-col-4, .ek-col-3 { grid-column: span 12; }
  .ek-grid > .ek-kpi { grid-column: span 6; }
  .ek-split,
  .ek-split--rev,
  .ek-split--even { grid-template-columns: minmax(0, 1fr); }
  .ek-card__head { flex-wrap: wrap; }
  .ek-card__head > .ek-page-sub { flex-basis: 100%; }
  /* A five-column row of actions does not fit beside the rail on a tablet,
     so the row becomes one card. This is shared by the phone width below. */
  .ek-table--cards thead { display: none; }
  .ek-table--cards,
  .ek-table--cards tbody { display: block; }
  .ek-table--cards tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--sp-2) var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    border-top: 1px solid var(--color-border-inner);
  }
  .ek-table--cards td {
    display: block;
    padding: 0;
    border: 0;
    height: auto;
  }
  .ek-table--cards td.num { text-align: right; }
  .ek-table--cards td.num::before {
    content: attr(data-label);
    display: block;
    font-size: var(--text-2xs);
    color: var(--color-text-faint);
  }
  .ek-table--cards td:nth-child(3),
  .ek-table--cards td.ek-actions { grid-column: 1 / -1; }
  .ek-table--cards td.ek-actions {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: var(--sp-1);
    width: auto;
    white-space: normal;
    text-align: left;
  }
  .ek-table--cards td.ek-actions .ek-btn { min-height: 32px; }
  /* The invoice rows carry seven columns. Below the rail they become a
     receipt-style card: student and status, class and invoice, then the three
     money figures, with the due date across the last line. */
  .ek-table--invoice thead { display: none; }
  .ek-table--invoice,
  .ek-table--invoice tbody { display: block; }
  .ek-table--invoice tr {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--sp-2) var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    border-top: 1px solid var(--color-border-inner);
  }
  .ek-table--invoice td {
    display: block;
    min-width: 0;
    padding: 0;
    border: 0;
    height: auto;
  }
  .ek-table--invoice td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: var(--text-2xs);
    color: var(--color-text-faint);
  }
  .ek-table--invoice td:nth-child(1) { grid-column: 1 / 3; grid-row: 1; }
  .ek-table--invoice td:nth-child(7) { grid-column: 3; grid-row: 1; justify-self: end; }
  .ek-table--invoice td:nth-child(2) { grid-column: 1; grid-row: 2; }
  .ek-table--invoice td:nth-child(3) { grid-column: 2 / 4; grid-row: 2; text-align: right; }
  .ek-table--invoice td:nth-child(4) { grid-column: 1; grid-row: 3; }
  .ek-table--invoice td:nth-child(5) { grid-column: 2; grid-row: 3; }
  .ek-table--invoice td:nth-child(6) { grid-column: 3; grid-row: 3; }
  .ek-table--invoice td[colspan] { grid-column: 1 / -1; text-align: center; }
  /* Recent payments is a five-column ledger on a desktop and a small receipt
     line on a phone. The amount, method and date keep their own labelled
     columns so a figure is never read against the wrong heading. */
  .ek-table--payments thead { display: none; }
  .ek-table--payments,
  .ek-table--payments tbody { display: block; }
  .ek-table--payments tr {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--sp-2) var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    border-top: 1px solid var(--color-border-inner);
  }
  .ek-table--payments td {
    display: block;
    min-width: 0;
    width: auto;
    padding: 0;
    border: 0;
    height: auto;
    white-space: normal;
  }
  .ek-table--payments td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: var(--text-2xs);
    color: var(--color-text-faint);
  }
  .ek-table--payments td:nth-child(1) { grid-column: 1 / 3; grid-row: 1; }
  .ek-table--payments td:nth-child(5) {
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
    width: auto;
    text-align: right;
  }
  .ek-table--payments td:nth-child(2) { grid-column: 1; grid-row: 2; }
  .ek-table--payments td:nth-child(3) { grid-column: 2; grid-row: 2; }
  .ek-table--payments td:nth-child(4) { grid-column: 3; grid-row: 2; }
  .ek-table--payments td[colspan] { grid-column: 1 / -1; text-align: center; }
  /* Directories read as a card below the rail: the person and the edit control
     on the first line, then department and roles, then contact on a tablet. */
  .ek-table--staff thead,
  .ek-table--parents thead { display: none; }
  .ek-table--staff,
  .ek-table--staff tbody,
  .ek-table--parents,
  .ek-table--parents tbody { display: block; }
  .ek-table--staff tr,
  .ek-table--parents tr {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--sp-2) var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    border-top: 1px solid var(--color-border-inner);
  }
  .ek-table--staff td,
  .ek-table--parents td {
    display: block;
    min-width: 0;
    width: auto;
    padding: 0;
    border: 0;
    height: auto;
    white-space: normal;
  }
  .ek-table--staff td[data-label]::before,
  .ek-table--parents td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: var(--text-2xs);
    color: var(--color-text-faint);
  }
  .ek-table--staff td.ek-actions,
  .ek-table--parents td.ek-actions {
    width: auto;
    text-align: right;
  }
  .ek-table--staff td:nth-child(1) { grid-column: 1 / 3; grid-row: 1; }
  .ek-table--staff td:nth-child(6) { grid-column: 3; grid-row: 1; justify-self: end; }
  .ek-table--staff td:nth-child(3) { grid-column: 1; grid-row: 2; }
  .ek-table--staff td:nth-child(4) { grid-column: 2 / 4; grid-row: 2; }
  .ek-table--staff td:nth-child(2) { grid-column: 1 / 3; grid-row: 3; }
  .ek-table--staff td:nth-child(5) { grid-column: 3; grid-row: 3; }
  .ek-table--parents td:nth-child(1) { grid-column: 1 / 3; grid-row: 1; }
  .ek-table--parents td:nth-child(4) { grid-column: 3; grid-row: 1; justify-self: end; }
  .ek-table--parents td:nth-child(3) { grid-column: 1 / -1; grid-row: 2; }
  .ek-table--parents td:nth-child(2) { grid-column: 1 / -1; grid-row: 3; }
  .ek-table--staff td[colspan],
  .ek-table--parents td[colspan] { grid-column: 1 / -1; text-align: center; }
}

@media (max-width: 767px) {
  .portal-main-area { padding: var(--sp-4); }
  .hide-sm { display: none !important; }
  .ek-pagehead { position: static; padding-top: 0; }
  .ek-pagehead__actions { width: 100%; }
  .ek-pagehead__actions .ek-btn,
  .ek-pagehead__actions .portal-btn-primary,
  .ek-pagehead__actions .portal-btn-secondary { flex: 1 1 auto; }
  .ek-grid { grid-template-columns: minmax(0, 1fr); }
  /* A KPI band is two cards across on a phone. One card per row turns four
     short figures into a page of empty space. */
  .ek-grid:has(> .ek-kpi) { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); }
  .ek-grid > .ek-kpi { grid-column: auto; min-height: 88px; padding: var(--sp-3) var(--sp-4); }
  .ek-kpi__icon { width: 26px; height: 26px; }
  .ek-figure { font-size: var(--text-xl); }
  .ek-toolbar { padding: var(--sp-2); }
  .ek-toolbar form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: var(--sp-1) var(--sp-2);
    width: 100%;
  }
  .ek-toolbar form > .ek-label { grid-column: 1 / -1; }
  .ek-toolbar select.ek-input,
  .ek-toolbar input.ek-input {
    grid-column: 1;
    width: 100%;
    min-width: 0;
    max-width: none;
  }
  .ek-toolbar form > button { grid-column: 2; }
  .ek-toolbar__count { margin-left: 0; width: 100%; }
  .portal-card, .ek-card, .ek-chartcard { padding: var(--sp-4); }
  .ek-table thead th { position: static; }
  .ek-table tbody td { height: auto; padding: var(--sp-2); }
  /* Two money columns fit a 360px phone; three do not. The due date takes the
     last full line because a lateness pill needs the width. */
  .ek-table--invoice tr { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ek-table--invoice td:nth-child(1) { grid-column: 1; grid-row: 1; }
  .ek-table--invoice td:nth-child(7) { grid-column: 2; grid-row: 1; }
  .ek-table--invoice td:nth-child(2) { grid-column: 1; grid-row: 2; }
  .ek-table--invoice td:nth-child(3) { grid-column: 2; grid-row: 2; text-align: left; }
  .ek-table--invoice td:nth-child(4) { grid-column: 1; grid-row: 3; }
  .ek-table--invoice td:nth-child(5) { grid-column: 2; grid-row: 3; text-align: left; }
  .ek-table--invoice td:nth-child(6) { grid-column: 1 / -1; grid-row: 4; }
  .ek-table--invoice td[colspan] { grid-column: 1 / -1; }
  /* Confirm and reject are two different decisions; on a phone they stack so
     the rejection reason gets the full width instead of a sliver. */
  .ek-proof-actions { align-items: stretch; }
  .ek-proof-actions > form,
  .ek-proof-actions > form.ek-row { flex: 1 1 100%; width: 100%; }
  .ek-proof-actions .ek-btn { width: 100%; }
}

/* ---- Print --------------------------------------------------------------- */
.net-diag-item {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-4);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border-inner);
  border-radius: var(--r-md);
}
.net-diag-head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}
.net-diag-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-primary);
  flex-shrink: 0;
}
.net-diag-title-wrap {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  flex: 1 1 auto;
}
.net-diag-title {
  margin: 0;
  font-size: var(--text-sm);
  font-weight: 680;
  color: var(--color-text);
}
.net-diag-desc {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.5;
}
.net-diag-steps {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  margin-top: 2px;
}
.net-path-crumb {
  margin: 0;
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-text);
  background: var(--color-surface);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm);
  border: 1px solid var(--color-border-inner);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow-x: auto;
}
.net-code-box {
  margin-top: var(--sp-1);
}

@media print {
  .ek-chartcard, .ek-toolbar, .ek-toolbar__count,
  .ek-pagehead__actions, .ek-bulkbar, .ek-skeleton { display: none !important; }
  .portal-main-area { padding: 0; background: none; }
  .portal-card, .ek-card, .ek-chartcard, .ek-tablewrap { border-color: #cbd5e1; }
}


/* ---- Attendance mark list ------------------------------------------------ */
.ek-mark-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.ek-mark-row {
  display: grid;
  grid-template-columns: 32px minmax(120px, 1fr) auto;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-4);
  border-bottom: 1px solid var(--color-border-inner);
  min-width: 0;
}
.ek-mark-row:last-child { border-bottom: 0; }
.ek-mark-row:hover { background: var(--color-surface-2); }
.ek-mark-name { min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.ek-mark-name strong { font-size: var(--text-sm); font-weight: 600; overflow-wrap: break-word; }
.ek-mark-name small { font-size: var(--text-2xs); color: var(--color-text-faint); font-family: var(--font-num); }
.ek-mark-options {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  width: min(360px, 100%);
  justify-self: end;
}
.ek-mark-form { margin: 0; }
.ek-mark-btn {
  width: 100%;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0 8px;
  border-radius: var(--r-sm);
  border: 1px solid var(--color-border-inner);
  background: var(--color-surface-2);
  color: var(--color-text-faint);
  font-size: var(--text-2xs);
  font-weight: 700;
  transition: background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast);
}
.ek-mark-btn:hover:not(:disabled) { color: var(--color-text); border-color: var(--color-border-strong); }
.ek-mark-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.ek-mark-btn svg { width: 14px; height: 14px; }
.ek-mark-btn.is-selected { border-color: currentColor; box-shadow: inset 0 -3px currentColor; }
.ek-mark-btn--present.is-selected { background: var(--success); color: var(--on-success); }
.ek-mark-btn--absent.is-selected { background: var(--danger); color: var(--on-danger); }
.ek-mark-btn--late.is-selected { background: var(--warning-bg); color: var(--warning-ink); }
.ek-mark-btn--excused.is-selected { background: var(--info); color: var(--on-info); }
@media (max-width: 640px) {
  .ek-mark-row { grid-template-columns: 28px minmax(0, 1fr); row-gap: 8px; }
  .ek-mark-options { grid-column: 1 / -1; width: 100%; justify-self: stretch; }
  .ek-mark-btn { min-height: 44px; }
  .ek-mark-btn__label { font-size: var(--text-2xs); }
}

/* ---- Numeric and table alignment ---------------------------------------- */
.ek-num {
  text-align: right;
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--tracking-num);
  white-space: nowrap;
}
.ek-center { text-align: center; }
.ek-nowrap { white-space: nowrap; }

.ek-table--compact td,
.ek-table--compact th { padding-top: 6px; padding-bottom: 6px; }
.ek-table td,
.ek-table th { height: var(--row-h); }
.ek-table--sticky thead th:first-child {
  position: sticky;
  left: 0;
  z-index: 3;
  background: var(--color-surface-2);
}
/* The pupil anchor is a th[scope=row] in every sheet, not a td. Without it the
   name column scrolled away on a phone while the numbers kept moving. */
.ek-table--sticky tbody th:first-child,
.ek-table--sticky tbody td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--color-surface);
}
.ek-table--sticky tbody tr:hover th:first-child,
.ek-table--sticky tbody tr:hover td:first-child { background: var(--color-surface-hover); }
.ek-table tbody tr.is-selected td { background: var(--color-primary-bg); }

.ek-table-toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--color-border-inner);
}
.ek-table-toolbar input[type="search"] {
  min-width: 180px;
  flex: 1 1 220px;
  max-width: 320px;
}
.ek-table-sort {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}
.ek-table-sort:hover { color: var(--text); }
.ek-table-sort::after {
  content: "";
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  opacity: 0.35;
}
.ek-table-sort[data-dir="asc"]::after { transform: rotate(180deg); opacity: 0.9; }
.ek-table-sort[data-dir="desc"]::after { opacity: 0.9; }
.ek-table-pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  border-top: 1px solid var(--color-border-inner);
  color: var(--faint);
  font-size: var(--text-xs);
}

/* ---- Live badge ---------------------------------------------------------- */
.ek-live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border: 1px solid var(--color-border-inner);
  border-radius: var(--r-pill);
  background: var(--color-surface-2);
  color: var(--muted);
  font-size: var(--text-2xs);
  font-weight: 650;
  line-height: 1.5;
  white-space: nowrap;
}
.ek-live__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--faint);
  flex: 0 0 auto;
}
.ek-live__count {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
}
.ek-live--success .ek-live__dot { background: var(--success-ink); }
.ek-live--warning .ek-live__dot { background: var(--warning-ink); }
.ek-live--danger .ek-live__dot { background: var(--danger-ink); }
.ek-live--info .ek-live__dot { background: var(--info-ink); }
.ek-live--pulse .ek-live__dot { animation: ek-live-pulse 2.2s ease-out infinite; }
.ek-live.is-stale { color: var(--faint); }
.ek-live.is-stale .ek-live__dot { animation: none; background: var(--faint); }

@keyframes ek-live-pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--success-ink) 55%, transparent); }
  70% { box-shadow: 0 0 0 5px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.ek-stale-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 7px;
  border-radius: var(--r-pill);
  background: var(--warning-bg);
  color: var(--warning-ink);
  font-size: var(--text-2xs);
  font-weight: 650;
  white-space: nowrap;
}

/* ---- Timeline strip ------------------------------------------------------ */
.ek-timeline {
  list-style: none;
  margin: 0;
  padding: 0;
}
.ek-timeline__item {
  position: relative;
  display: grid;
  grid-template-columns: 64px 14px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  padding: 9px 0;
}
.ek-timeline__time {
  padding-top: 1px;
  color: var(--faint);
  font-family: var(--font-num);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
}
.ek-timeline__rail {
  position: relative;
  align-self: stretch;
  display: flex;
  justify-content: center;
}
.ek-timeline__rail::before {
  content: "";
  position: absolute;
  top: 14px;
  bottom: -18px;
  width: 1px;
  background: var(--color-border-inner);
}
.ek-timeline__item:last-child .ek-timeline__rail::before { display: none; }
.ek-timeline__dot {
  position: relative;
  top: 4px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 0 0 3px var(--color-surface);
}
.ek-timeline__dot--success { background: var(--success-ink); }
.ek-timeline__dot--warning { background: var(--warning-ink); }
.ek-timeline__dot--danger { background: var(--danger-ink); }
.ek-timeline__dot--info { background: var(--info-ink); }
.ek-timeline__dot--muted { background: var(--faint); }
.ek-timeline__title {
  display: block;
  color: var(--text);
  font-weight: 600;
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
}
.ek-timeline__meta {
  display: block;
  color: var(--faint);
  font-size: var(--text-xs);
  margin-top: 1px;
}
.ek-timeline__body { min-width: 0; }

/* ---- FactBox ------------------------------------------------------------- */
.ek-factbox {
  position: sticky;
  top: 72px;
  align-self: start;
  border: 1px solid var(--color-border-inner);
  border-radius: var(--r-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
.ek-factbox__head {
  padding: var(--sp-4);
  border-bottom: 1px solid var(--color-border-inner);
  background: var(--color-surface-2);
}
.ek-factbox__title {
  margin: 0;
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text);
}
.ek-factbox__sub {
  margin: 2px 0 0;
  font-size: var(--text-xs);
  color: var(--faint);
}
.ek-factbox__rows { padding: 0 var(--sp-4); }
.ek-factbox__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: 8px 0;
  border-bottom: 1px solid var(--color-border-inner);
  font-size: var(--text-xs);
}
.ek-factbox__row:last-child { border-bottom: 0; }
.ek-factbox__label { color: var(--faint); }
.ek-factbox__value {
  color: var(--text);
  font-weight: 650;
  text-align: right;
  min-width: 0;
}
.ek-factbox__value .ek-num { font-weight: 700; }
.ek-factbox__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4) var(--sp-4);
  border-top: 1px solid var(--color-border-inner);
}
@media (max-width: 1023px) {
  .ek-factbox { position: static; }
}

/* ---- Teacher deployment matrix ------------------------------------------ */
.ek-matrix {
  overflow: auto;
  border: 1px solid var(--color-border-inner);
  border-radius: var(--r-lg);
  background: var(--color-surface);
}
.ek-matrix table {
  width: 100%;
  min-width: 760px;
  border-collapse: separate;
  border-spacing: 0;
}
.ek-matrix th,
.ek-matrix td {
  padding: 5px 7px;
  border-right: 1px solid var(--color-border-inner);
  border-bottom: 1px solid var(--color-border-inner);
  font-size: var(--text-xs);
}
.ek-matrix tr:last-child td { border-bottom: 0; }
.ek-matrix th:last-child,
.ek-matrix td:last-child { border-right: 0; }
.ek-matrix thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--color-surface-2);
  color: var(--muted);
  font-weight: 650;
  text-align: center;
  white-space: nowrap;
}
.ek-matrix thead th small { display: block; color: var(--faint); font-weight: 500; }
.ek-matrix__who {
  position: sticky;
  left: 0;
  z-index: 3;
  min-width: 168px;
  max-width: 220px;
  background: var(--color-surface);
  text-align: left;
}
.ek-matrix thead .ek-matrix__who { z-index: 4; background: var(--color-surface-2); }
.ek-matrix__name {
  display: block;
  color: var(--text);
  font-weight: 650;
  font-size: var(--text-xs);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ek-matrix__dept { display: block; color: var(--faint); font-size: 10px; }
.ek-matrix__cell {
  height: 34px;
  text-align: center;
  vertical-align: middle;
  min-width: 62px;
}
.ek-matrix__cell strong {
  display: block;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 88px;
  margin: 0 auto;
}
.ek-matrix__cell span {
  display: block;
  font-size: 9px;
  line-height: 1.25;
  color: var(--faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 88px;
  margin: 0 auto;
}
.ek-matrix__cell--answered { background: color-mix(in srgb, var(--success) 16%, transparent); }
.ek-matrix__cell--answered strong { color: var(--success-ink); }
.ek-matrix__cell--due { background: color-mix(in srgb, var(--warning) 16%, transparent); }
.ek-matrix__cell--due strong { color: var(--warning-ink); }
.ek-matrix__cell--missed { background: color-mix(in srgb, var(--danger) 16%, transparent); }
.ek-matrix__cell--missed strong { color: var(--danger-ink); }
.ek-matrix__cell--free { background: var(--color-surface-2); }
.ek-matrix__cell--none { background: transparent; }
.ek-matrix__cell--none strong { color: var(--faint); font-weight: 500; }
.ek-matrix__legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  color: var(--faint);
  font-size: var(--text-xs);
}
.ek-matrix__legend span { display: inline-flex; align-items: center; gap: 5px; }
.ek-matrix__swatch {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: var(--color-surface-2);
}
.ek-matrix__swatch--answered { background: color-mix(in srgb, var(--success) 60%, transparent); }
.ek-matrix__swatch--due { background: color-mix(in srgb, var(--warning) 60%, transparent); }
.ek-matrix__swatch--missed { background: color-mix(in srgb, var(--danger) 60%, transparent); }
.ek-matrix__swatch--free { background: var(--color-surface-3); }

/* ---- Attendance pulse ---------------------------------------------------- */
.ek-pulse { display: grid; gap: var(--sp-4); }
.ek-pulse__top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
}
.ek-pulse__figure {
  font-family: var(--font-num);
  font-size: var(--text-3xl);
  font-weight: 750;
  line-height: 1;
  letter-spacing: var(--tracking-num);
  color: var(--text);
}
.ek-pulse__figure small {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--faint);
  letter-spacing: 0;
  margin-left: 4px;
}
.ek-pulse__bar {
  display: flex;
  height: 10px;
  border-radius: var(--r-pill);
  overflow: hidden;
  background: var(--color-surface-2);
}
.ek-pulse__seg { height: 100%; min-width: 0; }
.ek-pulse__seg--present { background: var(--success); }
.ek-pulse__seg--late { background: var(--warning); }
.ek-pulse__seg--absent { background: var(--danger); }
.ek-pulse__seg--excused { background: var(--info); }
.ek-pulse__stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--sp-2);
}
.ek-pulse__stat {
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--color-border-inner);
  border-radius: var(--r-md);
  background: var(--color-surface-2);
}
.ek-pulse__stat b {
  display: block;
  font-family: var(--font-num);
  font-size: var(--text-md);
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.ek-pulse__stat span { color: var(--faint); font-size: var(--text-2xs); overflow-wrap: break-word; }
.ek-pulse__stat--present b { color: var(--success-ink); }
.ek-pulse__stat--late b { color: var(--warning-ink); }
.ek-pulse__stat--absent b { color: var(--danger-ink); }
.ek-pulse__stat--excused b { color: var(--info-ink); }
@media (max-width: 640px) {
  .ek-pulse__stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---- Chart skeleton and empty state ------------------------------------- */
.ek-chartcard__canvas { position: relative; min-height: 120px; }
.ek-chart-skeleton {
  height: 100%;
  min-height: 120px;
  border-radius: var(--r-md);
  background: linear-gradient(
    90deg,
    var(--color-surface-2) 25%,
    var(--color-surface-3) 37%,
    var(--color-surface-2) 63%
  );
  background-size: 400% 100%;
  animation: ek-shimmer 1.5s ease infinite;
}
.ek-chart-empty,
.ek-chart-error {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 120px;
  padding: var(--sp-4);
  text-align: center;
  color: var(--faint);
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
}
.ek-chart-error { color: var(--warning-ink); }

@keyframes ek-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

/* ---- Role center shell --------------------------------------------------- */
.ek-center-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
}
.ek-center-head__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.ek-center-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: var(--flow);
  align-items: start;
}
.ek-center-grid__main { min-width: 0; display: grid; gap: var(--flow); }
.ek-center-grid__side { min-width: 0; display: grid; gap: var(--flow); }
.ek-page[data-live-url].ek-stale { opacity: 1; }
.ek-ops-chart { height: 240px; }
.ek-matrix__cell .ek-ops-duty span {
  display: inline;
  max-width: none;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  font-size: var(--text-xs);
}
.ek-ops-duty + .ek-ops-duty { margin-top: var(--sp-2); border-top: 1px solid var(--line); padding-top: var(--sp-2); }
.ek-ops-duty-details { margin-top: var(--sp-1); font-size: var(--text-2xs); }
.ek-ops-duty-details summary { cursor: pointer; color: var(--muted); }
.ek-ops-duty-details[open] { min-width: 140px; text-align: left; }
@media (min-width: 641px) and (max-width: 1024px) {
  .ek-ops-kpis > .ek-col-3 { grid-column: span 6; }
}
@media (max-width: 1180px) {
  .ek-center-grid { grid-template-columns: minmax(0, 1fr); }
  .ek-center-grid__side { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  .ek-live--pulse .ek-live__dot,
  .ek-chart-skeleton { animation: none; }
}

/* ---- Report generation queue --------------------------------------------- */
/* The bar is a real <progress> element, so the percentage is announced and the
   fill width comes from the value attribute instead of a written style. */
.rq-task { display: flex; flex-direction: column; gap: var(--sp-2); }
.rq-label { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.rq-progress {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 8px;
  border: 0;
  border-radius: 4px;
  background: var(--color-surface-2);
  overflow: hidden;
}
.rq-progress::-webkit-progress-bar {
  background: var(--color-surface-2);
  border-radius: 4px;
}
.rq-progress::-webkit-progress-value {
  background: var(--color-primary);
  border-radius: 4px;
}
.rq-progress::-moz-progress-bar {
  background: var(--color-primary);
  border-radius: 4px;
}
.rq-task[data-task-status='paused'] .rq-progress::-webkit-progress-value { background: var(--color-warning); }
.rq-task[data-task-status='paused'] .rq-progress::-moz-progress-bar { background: var(--color-warning); }
.rq-task[data-task-status='completed'] .rq-progress::-webkit-progress-value { background: var(--color-success); }
.rq-task[data-task-status='completed'] .rq-progress::-moz-progress-bar { background: var(--color-success); }
.rq-task[data-task-status='failed'] .rq-progress::-webkit-progress-value,
.rq-task[data-task-status='stopped'] .rq-progress::-webkit-progress-value { background: var(--color-danger); }
.rq-task[data-task-status='failed'] .rq-progress::-moz-progress-bar,
.rq-task[data-task-status='stopped'] .rq-progress::-moz-progress-bar { background: var(--color-danger); }
.rq-line,
.rq-started { margin: 0; }
.rq-started { color: var(--color-text-faint); }
.rq-actions { margin-top: var(--sp-1); }

/* ---- Auth screens -------------------------------------------------------- */
/* Login, signup, recovery and the school finder. Nobody is signed in here, so
   there is no shell: the card is the page. */
.ek-auth {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-5);
  padding: var(--sp-5);
  background: var(--color-bg);
}
.ek-auth__card {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  padding: var(--sp-6);
}
.ek-auth__card--wide { max-width: 640px; }
.ek-auth__brand { display: flex; justify-content: center; }
.ek-auth__logo {
  width: 56px;
  height: 56px;
  object-fit: contain;
  border-radius: var(--r-md);
}
.ek-auth__title {
  margin: 0;
  text-align: center;
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-text);
  overflow-wrap: anywhere;
}
.ek-auth__sub {
  margin: 0;
  text-align: center;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}
.ek-auth__form { display: flex; flex-direction: column; gap: var(--sp-4); }
.ek-auth__field { display: flex; flex-direction: column; gap: 6px; }
.ek-auth__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-2);
}
.ek-auth__hint {
  margin: 0;
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}
.ek-auth__foot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-align: center;
}
.ek-auth__actions { display: flex; flex-wrap: wrap; gap: var(--sp-3); justify-content: center; }
/* The reveal control sits inside the input's box, so the field keeps its full
   width and the password text never runs under the button. */
.ek-auth__pw { position: relative; display: flex; flex-direction: column; gap: 6px; }
.ek-auth__pw .ek-input { padding-inline-end: 40px; }
.ek-pw-toggle {
  position: absolute;
  inset-inline-end: 6px;
  top: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--color-text-faint);
  cursor: pointer;
}
.ek-pw-toggle:hover { color: var(--color-text); background: var(--color-surface-2); }
.ek-pw-toggle .gi { width: 17px; height: 17px; }
.ek-auth__list { display: flex; flex-direction: column; gap: var(--sp-3); }
.ek-auth__result { display: flex; flex-direction: column; gap: 2px; text-align: start; }
.ek-auth__result strong { color: var(--color-text); font-size: var(--text-base); }
.ek-auth__steps { display: flex; flex-direction: column; gap: var(--sp-4); }
.ek-auth__step {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-4);
  border: 1px solid var(--color-border-inner);
  border-radius: var(--r-md);
  background: var(--color-surface-2);
}
.ek-auth__submit { width: 100%; justify-content: center; }
.ek-auth__link { color: var(--color-primary-text); font-weight: 600; }
.ek-auth__note { margin: 0; font-size: var(--text-sm); color: var(--color-text-muted); }

/* ---- Score sheets --------------------------------------------------------
   The subject grid and the class matrix. A sheet is a table the teacher types
   into: the pupil column stays put, the header stays put, and each cell says
   whether its value is on its way to the server (amber), saved (green) or
   refused (red). The phone view below turns the same rows into one card at a
   time, so no markup is duplicated for the small screen. */

.ek-sheet {
  width: 100%;
  min-width: max-content;
  overflow: visible;
}
.ek-sheet caption {
  white-space: normal;
}
.ek-sheet thead th {
  top: 0;
}
.ek-sheet td,
.ek-sheet th {
  padding: 8px 12px;
}
/* A subject sheet is nine columns wide, not a class matrix. `max-content` here
   feeds the 100%-wide inputs back into the table width and every column grows to
   ~1,800px on a desktop. A definite minimum keeps the grid on screen. */
.ek-sheet--subject {
  min-width: 760px;
  width: 100%;
}
.ek-sheet .sheet-pupil-col {
  position: sticky;
  left: 0;
  min-width: 220px;
  max-width: 320px;
  text-align: start;
  background: var(--color-surface);
  z-index: 2;
  white-space: nowrap;
}
.ek-sheet thead .sheet-pupil-col {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 4;
  background: var(--color-surface-2);
}
.ek-sheet .sheet-subject-col {
  min-width: 96px;
  text-align: center;
}
.ek-sheet .sheet-sum-col {
  min-width: 76px;
  text-align: center;
}
.ek-sheet td.ek-num {
  text-align: center;
  font-size: var(--text-sm);
}
.ek-sheet .sheet-pupil__idx {
  display: inline-block;
  min-width: 1.5em;
  margin-inline-end: 6px;
  color: var(--color-text-faint);
  font-size: var(--text-2xs);
  font-variant-numeric: tabular-nums;
}
.ek-sheet .sheet-pupil__name {
  color: var(--color-text);
  font-weight: 600;
  white-space: normal;
}
.ek-sheet .sheet-pupil__adm {
  display: block;
  color: var(--color-text-faint);
  font-size: var(--text-2xs);
  font-weight: 400;
  letter-spacing: 0.04em;
}
.ek-sheet .sheet-cell-td {
  padding: 2px 4px;
}
.ek-sheet .sheet-value {
  display: block;
  padding-inline: var(--sp-2);
  text-align: right;
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
}

/* A numeric input with no chrome until it is focused, so a filled sheet reads
   as a table and an empty cell looks like a place to type. 44px tall is the
   touch target the rest of the kit uses. */
.ek-sheet .sheet-cell {
  width: 100%;
  min-width: 64px;
  height: 44px;
  /* The topbar is fixed at 60px and scrollIntoView aligns to the viewport edge. */
  scroll-margin-block-start: 68px;
  padding: 0 var(--sp-2);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--color-text);
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: var(--text-sm);
  text-align: right;
  transition: background var(--dur-fast), border-color var(--dur-fast);
}
.ek-sheet .sheet-cell::placeholder { color: var(--color-text-faint); }
.ek-sheet .sheet-cell:hover { border-color: var(--color-border-inner); }
.ek-sheet .sheet-cell:focus {
  outline: none;
  border-color: var(--color-primary);
  background: var(--color-surface);
  box-shadow: 0 0 0 2px var(--color-primary-bg);
}
.ek-sheet .sheet-cell.is-pending {
  background-color: var(--color-warning-bg);
  background-image: linear-gradient(225deg, var(--color-warning) 7px, transparent 7px);
  background-repeat: no-repeat;
  background-position: top right;
  box-shadow: inset 0 -2px 0 var(--color-warning);
}
.ek-sheet .sheet-cell.is-saving {
  opacity: 0.75;
  background-color: var(--color-surface-2);
  border-color: var(--color-warning);
  animation: ekSheetPulse 0.9s ease-in-out infinite alternate;
}
@keyframes ekSheetPulse {
  0% { opacity: 0.5; }
  100% { opacity: 0.9; }
}
.ek-sheet .sheet-cell.is-saved {
  background-color: var(--color-success-bg);
  border-color: var(--color-success);
  box-shadow: 0 0 0 1px var(--color-success);
  transition: background-color 0.4s ease, border-color 0.4s ease;
}
.ek-sheet .sheet-cell.is-error {
  background-color: var(--color-danger-bg) !important;
  border-color: var(--color-danger) !important;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.25) !important;
}

/* Progress line above the sheet. */
.sheet-progress {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
}
.sheet-progress progress {
  width: 110px;
  height: 8px;
  border: 0;
  border-radius: 999px;
  overflow: hidden;
  background: var(--color-surface-3);
  accent-color: var(--color-primary);
}
.sheet-progress progress::-webkit-progress-bar { background: var(--color-surface-3); border-radius: 999px; }
.sheet-progress progress::-webkit-progress-value { background: var(--color-primary); border-radius: 999px; }
.sheet-progress progress::-moz-progress-bar { background: var(--color-primary); border-radius: 999px; }

/* The phone view bottom bar. */
.sheet-focus-bar {
  position: sticky;
  bottom: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-top: 1px solid var(--color-border-inner);
  background: var(--color-surface-2);
}
.sheet-focus-bar[hidden] { display: none; }
.sheet-focus-bar__who {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  flex-direction: column;
  text-align: center;
}
.sheet-focus-bar__who strong {
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* The on-screen keypad, for a phone whose keyboard is alphanumeric. */
.sheet-keypad {
  position: fixed;
  inset-inline-end: var(--sp-3);
  inset-block-end: var(--sp-3);
  z-index: 60;
  width: min(320px, calc(100vw - 2 * var(--sp-3)));
  padding: var(--sp-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--r-md);
  background: var(--color-surface);
  box-shadow: var(--shadow-3);
}
.sheet-keypad[hidden] { display: none; }
.sheet-keypad__head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-2);
}
.sheet-keypad__head .ek-kpi__caption {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sheet-keypad__grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--sp-2);
}
.sheet-keypad__key {
  min-height: 44px;
  border: 1px solid var(--color-border-inner);
  border-radius: var(--r-sm);
  background: var(--color-surface-2);
  color: var(--color-text);
  font-family: var(--font-num);
  font-size: var(--text-base);
  font-weight: 600;
  cursor: pointer;
}
.sheet-keypad__key:hover { background: var(--color-surface-hover); }
.sheet-keypad__key:active { background: var(--color-primary-bg); }
.sheet-keypad__key--wide { grid-column: span 2; }
.sheet-keypad__key--go {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-on-primary);
}

/* On a phone the pupil column must leave a subject column on screen; the
   table's auto layout otherwise gives it half the viewport. */
@media (max-width: 767px) {
  .ek-sheet .sheet-pupil-col {
    width: 128px;
    min-width: 128px;
    max-width: 128px;
  }
  .ek-sheet .sheet-pupil__name,
  .ek-sheet .sheet-pupil__adm {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .ek-sheet thead th,
  .ek-sheet tbody td {
    min-width: 84px;
  }
  .ek-sheet thead th.sheet-subject-col,
  .ek-sheet tbody td.sheet-cell-td {
    width: 150px;
    min-width: 150px;
    max-width: 150px;
  }
  .ek-sheet thead th {
    white-space: normal;
    overflow-wrap: anywhere;
  }
}

/* Focus view: one pupil per card on a phone. The cells keep their inputs, so
   autosave and keyboard movement work exactly as they do in the grid. */
@media (max-width: 767px) {
  .sheet-focus .ek-tablewrap {
    overflow: visible;
    border: 0;
    background: transparent;
  }
  .sheet-focus .ek-sheet {
    min-width: 0;
    width: 100%;
    display: block;
  }
  /* A table-caption shrink-wraps to min-content once the table is blockified,
     which turns the one-line caption into a narrow column beside the card. */
  .sheet-focus .ek-sheet caption {
    display: block;
    width: auto;
    padding-bottom: var(--sp-2);
    text-align: start;
  }
  .sheet-focus .ek-sheet thead,
  .sheet-focus .ek-sheet tfoot {
    display: none;
  }
  .sheet-focus .ek-sheet tbody {
    display: block;
  }
  .sheet-focus .ek-sheet tbody tr {
    display: none;
  }
  .sheet-focus .ek-sheet tbody tr.is-active {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 2px;
    margin-bottom: var(--sp-3);
    padding: var(--sp-3);
    scroll-margin-block-start: 68px;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--r-md);
    background: var(--color-surface);
  }
  .sheet-focus .ek-sheet tbody tr.is-active > th,
  .sheet-focus .ek-sheet tbody tr.is-active > td {
    position: static;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    min-height: 44px;
    height: auto;
    padding: 2px 0;
    border: 0;
    background: transparent;
    text-align: right;
  }
  .sheet-focus .ek-sheet tbody tr.is-active > th::before,
  .sheet-focus .ek-sheet tbody tr.is-active > td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    color: var(--color-text-faint);
    font-size: var(--text-2xs);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    text-align: left;
  }
  .sheet-focus .ek-sheet tbody tr.is-active > th.sheet-pupil-col {
    display: block;
    padding-bottom: var(--sp-2);
    border-bottom: 1px solid var(--color-border-inner);
    text-align: left;
  }
  .sheet-focus .ek-sheet tbody tr.is-active > th.sheet-pupil-col::before {
    display: none;
  }
  .sheet-focus .ek-sheet tbody tr.is-active .sheet-cell-td {
    padding: 0;
  }
  .sheet-focus .ek-sheet tbody tr.is-active .sheet-cell {
    width: 120px;
    min-width: 88px;
  }
  .sheet-focus .ek-sheet tbody tr.is-active .sheet-value {
    padding-inline: 0;
  }
}

/* The printed sheet is a document, not a control surface. */
@media print {
  .sheet-keypad,
  .sheet-focus-bar,
  .sheet-progress,
  .no-print {
    display: none !important;
  }
  .ek-tablewrap {
    overflow: visible !important;
    border: 0 !important;
    border-radius: 0 !important;
  }
  .ek-sheet {
    min-width: 0 !important;
    width: 100% !important;
  }
  .ek-sheet thead th,
  .ek-sheet tbody th:first-child,
  .ek-sheet tbody td:first-child {
    position: static !important;
  }
  .ek-sheet .sheet-cell {
    height: auto !important;
    min-width: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    background: transparent !important;
    color: #111 !important;
    box-shadow: none !important;
  }
  .ek-sheet tr {
    break-inside: avoid;
  }
  .ek-sheet caption {
    color: #111;
  }
}


/* ---- Network connectivity guide ----------------------------------------- */
.net-hero {
  display: grid;
  gap: var(--sp-4);
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
}
@media (max-width: 900px) {
  .net-hero { grid-template-columns: minmax(0, 1fr); }
}
.net-qr-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--sp-5);
  background: var(--color-surface);
  border: 1px solid var(--color-border-inner);
  border-radius: var(--r-md);
}
.net-qr-wrap {
  display: inline-flex;
  padding: var(--sp-3);
  background: #ffffff;
  border: 1px solid var(--color-border);
  border-radius: var(--r-md);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.06);
}
.net-qr-img {
  display: block;
  width: 192px;
  height: 192px;
  image-rendering: pixelated;
}
.net-url-display {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--r-md);
}
.net-url-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-primary);
  word-break: break-all;
}
.net-step-card {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border-inner);
  border-radius: var(--r-md);
}
.net-step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--r-full);
  background: var(--color-primary);
  color: var(--color-on-primary, #ffffff);
  font-size: var(--text-xs);
  font-weight: 700;
}
.net-step-title {
  font-size: var(--text-base);
  font-weight: 680;
  color: var(--color-text);
  margin: 0;
}
.net-step-desc {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.5;
  margin: 0;
}
@media print {
  .tb-bar,
  .sb-bar,
  .portal-bottom-nav,
  .ek-pagehead__actions,
  .net-hide-print {
    display: none !important;
  }
  .ek-page {
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }
}
