/* =============================================================================
   School portal styles, on top of the shared design tokens (variables.css,
   kept byte-identical with manage's).

   Two audiences: a parent on a phone, once a week — one column, large type,
   the attendance rate first — and a teacher between lessons. Neither is the
   admin shell. Targets are at least 44px; nothing depends on hover.
   ============================================================================= */

[hidden] { display: none !important; }

/* variables.css is light-only. The portal remaps the SEMANTIC tokens for dark
   mode, so everything below that uses them follows automatically. */
@media (prefers-color-scheme: dark) {
  :root {
    --surface-canvas: var(--gray-950);
    --surface-raised: var(--gray-900);
    --surface-sunken: var(--gray-800);
    --text-primary: var(--gray-50);
    --text-secondary: var(--gray-200);
    --text-muted: var(--gray-400);
    --text-subtle: var(--gray-500);
    --text-brand: var(--navy-200);
    --text-link: var(--navy-200);
    --border-subtle: var(--gray-800);
    --border-default: var(--gray-700);
    --border-strong: var(--gray-600);
    --success-fg: var(--green-100);
    --success-bg: oklch(0.34 0.06 150);
    --danger-fg: var(--red-100);
    --danger-bg: oklch(0.34 0.09 25);
    --warning-fg: var(--amber-100);
    --warning-bg: oklch(0.36 0.07 75);
    --info-fg: var(--navy-100);
    --info-bg: var(--navy-800);
    --focus-ring: 0 0 0 2px var(--surface-canvas), 0 0 0 4px var(--navy-300);
  }
}

body {
  min-height: 100vh;
  background: var(--surface-canvas);
  color: var(--text-primary);
  font-size: var(--text-base);
  line-height: 1.5;
}

.lucide { width: 1.25em; height: 1.25em; flex-shrink: 0; }

/* --- top bar --------------------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  background: var(--surface-raised);
  border-bottom: 1px solid var(--border-subtle);
}
.brand {
  display: flex; align-items: center; gap: var(--space-2);
  font-weight: var(--weight-bold); font-size: var(--text-lg);
  color: var(--text-brand);
}
.brand-sub { font-weight: var(--weight-normal); color: var(--text-muted); font-size: var(--text-sm); }
.account { display: flex; align-items: center; gap: var(--space-1); min-width: 0; }
.whoami {
  color: var(--text-secondary); font-size: var(--text-sm);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 14rem;
  margin-right: var(--space-1);
}

/* --- layout ---------------------------------------------------------------- */

.wrap { max-width: 760px; margin: 0 auto; padding: var(--space-5) var(--space-4) var(--space-12); }
.center { text-align: center; }

.card {
  background: var(--surface-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--elev-1);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
}
.card h2 {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-lg); font-weight: var(--weight-semibold);
  margin-bottom: var(--space-3);
}
.card h2 .lucide { color: var(--text-brand); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; }
.card-head h2 { margin-bottom: var(--space-3); }

h1 { font-size: var(--text-2xl); font-weight: var(--weight-bold); letter-spacing: var(--tracking-tight); }

.muted { color: var(--text-muted); font-size: var(--text-sm); }
.small { font-size: var(--text-xs); }
.hint { color: var(--text-muted); font-size: var(--text-xs); margin-top: var(--space-1); }
.nowrap { white-space: nowrap; }
.mono { font-family: var(--font-mono); font-size: var(--text-sm); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* --- forms ----------------------------------------------------------------- */

.login { max-width: 400px; margin: 8vh auto 0; }
.login h1 { margin-bottom: var(--space-1); }

label { display: block; font-weight: var(--weight-medium); font-size: var(--text-sm); margin: var(--space-4) 0 var(--space-1); }
input:not([type=checkbox]), select {
  width: 100%; min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-default); border-radius: var(--radius-md);
  background: var(--surface-raised); color: var(--text-primary);
  font: inherit;
}
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: none; box-shadow: var(--focus-ring); border-color: var(--border-focus);
}
.form-error { color: var(--danger-fg); font-size: var(--text-sm); min-height: 1.5em; margin: var(--space-3) 0; }
.card > .form-error:only-child { margin: 0; }

.check { display: inline-flex; align-items: center; gap: var(--space-2); margin: 0 0 var(--space-3); font-weight: var(--weight-normal); cursor: pointer; min-height: 44px; }
.check input { width: 1.1rem; height: 1.1rem; accent-color: var(--brand-500); }

/* --- buttons --------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 44px; padding: var(--space-2) var(--space-4);
  border: 1px solid transparent; border-radius: var(--radius-md);
  font: inherit; font-weight: var(--weight-semibold);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-standard);
}
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn-primary { background: var(--brand-500); color: var(--text-inverse); }
.btn-primary:hover:not(:disabled) { background: var(--brand-600); }
.btn-ghost { background: transparent; color: var(--text-brand); padding-inline: var(--space-2); margin-bottom: var(--space-2); }
.btn-ghost:hover { background: var(--surface-sunken); }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border: none; border-radius: var(--radius-md);
  background: transparent; color: var(--text-secondary); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-sunken); color: var(--text-primary); }

/* --- tabs (view switch and children) --------------------------------------- */

.tabs { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-4); }
.tabs [role=tab] {
  display: inline-flex; align-items: center; gap: var(--space-2);
  min-height: 44px; padding: var(--space-2) var(--space-4);
  border: 1px solid var(--border-default); border-radius: var(--radius-pill);
  background: var(--surface-raised); color: var(--text-primary);
  font: inherit; cursor: pointer;
}
.tabs [role=tab][aria-selected=true] { background: var(--brand-500); border-color: transparent; color: var(--text-inverse); }

/* --- lists ----------------------------------------------------------------- */

.list { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border-subtle);
}
.row:last-child { border-bottom: none; }
.row-main { flex: 1; min-width: 0; }
.row-title { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2); font-weight: var(--weight-medium); }
.row.unread .row-title { font-weight: var(--weight-bold); }
.row-button {
  width: 100%; min-height: 56px; text-align: left;
  background: transparent; border-left: none; border-right: none; border-top: none;
  color: inherit; font: inherit; cursor: pointer;
  padding-inline: var(--space-2); border-radius: var(--radius-md);
}
.row-button:hover { background: var(--surface-sunken); }
.row-button > .lucide { color: var(--text-subtle); }

/* --- attendance ------------------------------------------------------------ */

.rate { font-size: var(--text-4xl); font-weight: var(--weight-bold); font-variant-numeric: tabular-nums; line-height: 1.1; }
.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: var(--space-3) 0; }
.pill {
  display: inline-block; padding: 0 var(--space-2);
  border-radius: var(--radius-sm); font-size: var(--text-sm); white-space: nowrap;
  background: var(--surface-sunken); color: var(--text-secondary);
}
.m-present { background: var(--success-bg); color: var(--success-fg); }
.m-late    { background: var(--warning-bg); color: var(--warning-fg); }
.m-absent  { background: var(--danger-bg);  color: var(--danger-fg); }
.m-excused, .m-sick { background: var(--info-bg); color: var(--info-fg); }

.score { font-variant-numeric: tabular-nums; font-weight: var(--weight-semibold); white-space: nowrap; }

/* --- staff ----------------------------------------------------------------- */

.school-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-4); }
.school-switch { margin: 0; min-width: 12rem; }

.lesson {
  display: flex; gap: var(--space-4); align-items: flex-start;
  padding: var(--space-3) 0; border-bottom: 1px solid var(--border-subtle);
}
.lesson:last-child { border-bottom: none; }
.lesson.is-covered .row-title { color: var(--text-muted); text-decoration: line-through; }
.period { width: 4.5rem; flex-shrink: 0; text-align: center; }
.period-no { font-size: var(--text-2xl); font-weight: var(--weight-bold); font-variant-numeric: tabular-nums; line-height: 1.1; }

.badges { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }
.badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 0 var(--space-2); border-radius: var(--radius-pill);
  font-size: var(--text-xs); font-weight: var(--weight-medium); white-space: nowrap;
}
.badge .lucide { width: 1em; height: 1em; }
.badge-success { background: var(--success-bg); color: var(--success-fg); }
.badge-warning { background: var(--warning-bg); color: var(--warning-fg); }
.badge-info    { background: var(--info-bg);    color: var(--info-fg); }
.badge-muted   { background: var(--surface-sunken); color: var(--text-muted); }

.table { width: 100%; border-collapse: collapse; margin-top: var(--space-3); }
.table th { text-align: left; font-size: var(--text-xs); font-weight: var(--weight-semibold); color: var(--text-muted); padding: var(--space-2); border-bottom: 1px solid var(--border-default); }
.table td { padding: var(--space-2); border-bottom: 1px solid var(--border-subtle); vertical-align: top; }
.table tr:last-child td { border-bottom: none; }
.table .num { font-variant-numeric: tabular-nums; color: var(--text-muted); width: 3rem; }

/* --- banners, dialog, toast ------------------------------------------------ */

.banner {
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-md);
  background: var(--info-bg); color: var(--info-fg); margin-bottom: var(--space-4);
}

dialog {
  width: calc(100% - 2 * var(--space-4)); max-width: 420px;
  margin: auto; padding: var(--space-5);
  border: 1px solid var(--border-subtle); border-radius: var(--radius-lg);
  background: var(--surface-raised); color: var(--text-primary);
  box-shadow: var(--elev-4);
}
dialog::backdrop { background: var(--surface-overlay); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.dialog-head h2 { font-size: var(--text-lg); font-weight: var(--weight-semibold); }

.toast {
  position: fixed; left: 50%; bottom: var(--space-6); transform: translateX(-50%);
  max-width: calc(100% - 2 * var(--space-4));
  padding: var(--space-3) var(--space-5); border-radius: var(--radius-pill);
  background: var(--surface-inverse); color: var(--text-inverse);
  box-shadow: var(--elev-3); z-index: 20;
}

/* --- school OS: shared pieces --------------------------------------------- */

.tabs-scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: var(--space-1); scrollbar-width: thin; }
.tabs-scroll [role=tab] { flex-shrink: 0; }

.actions { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2); }
.btn-sm { min-height: 36px; padding: var(--space-1) var(--space-3); font-size: var(--text-sm); margin-bottom: 0; }
.card-head .check { margin: 0; }

.controls { display: flex; flex-wrap: wrap; gap: var(--space-3); margin-bottom: var(--space-4); }
.control { flex: 1 1 10rem; min-width: 0; }
.control label { margin-top: 0; }
.card-head .control { flex: 0 1 14rem; margin-bottom: var(--space-3); }

.subhead { font-size: var(--text-base); font-weight: var(--weight-semibold); margin: var(--space-5) 0 var(--space-2); }
.subhead-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; }
.subhead-row .subhead { margin-bottom: var(--space-2); }
.roster-meta { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.cell-actions { white-space: nowrap; text-align: right; width: 1%; }
.cell-actions .icon-btn { width: 40px; height: 40px; }

.table-scroll { overflow-x: auto; margin: 0 calc(-1 * var(--space-2)); padding: 0 var(--space-2); }

.lesson-action { align-self: center; margin-bottom: 0; }

/* --- timetable --------------------------------------------------------------- */

.grid { table-layout: fixed; min-width: 34rem; }
.grid th, .grid td { border: 1px solid var(--border-subtle); text-align: center; }
.grid thead th { text-align: center; }
.grid-period { width: 4rem; background: var(--surface-sunken); }
.grid-cell { height: 4.5rem; padding: var(--space-1); vertical-align: top; }
.slot {
  position: relative; text-align: left;
  padding: var(--space-1) var(--space-2); border-radius: var(--radius-sm);
  background: var(--info-bg); color: var(--info-fg);
}
.slot + .slot { margin-top: var(--space-1); }
.slot-title { font-weight: var(--weight-semibold); font-size: var(--text-sm); padding-right: 1.5rem; }
.slot-remove {
  position: absolute; top: 0; right: 0; width: 32px; height: 32px;
  border: none; background: transparent; color: inherit; cursor: pointer; opacity: 0.7;
}
.slot-remove:hover { opacity: 1; }
.slot-add {
  width: 100%; height: 100%; min-height: 44px;
  border: 1px dashed var(--border-default); border-radius: var(--radius-sm);
  background: transparent; color: var(--text-subtle); cursor: pointer;
}
.slot-add:hover { background: var(--surface-sunken); color: var(--text-primary); }
.day-short { display: none; }

/* --- register ---------------------------------------------------------------- */

.register-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-2); }
.register-bar .btn { margin-bottom: 0; }
.register-row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap;
  padding: var(--space-3) 0; border-bottom: 1px solid var(--border-subtle);
}
.marks { display: flex; gap: var(--space-1); flex-wrap: wrap; }
.mark-btn {
  min-width: 44px; min-height: 44px; padding: 0 var(--space-2);
  border: 1px solid var(--border-default); border-radius: var(--radius-md);
  background: var(--surface-raised); color: var(--text-secondary);
  font: inherit; font-size: var(--text-sm); cursor: pointer;
}
.mark-btn:disabled { cursor: not-allowed; opacity: 0.55; }
.mark-btn[aria-pressed=true] { border-color: transparent; font-weight: var(--weight-semibold); }
.mark-btn.m-present[aria-pressed=true] { background: var(--success-bg); color: var(--success-fg); }
.mark-btn.m-late[aria-pressed=true]    { background: var(--warning-bg); color: var(--warning-fg); }
.mark-btn.m-absent[aria-pressed=true]  { background: var(--danger-bg);  color: var(--danger-fg); }
.mark-btn.m-excused[aria-pressed=true], .mark-btn.m-sick[aria-pressed=true] { background: var(--info-bg); color: var(--info-fg); }
.mark-short { display: none; }
.register-save { display: flex; justify-content: flex-end; margin-top: var(--space-4); }

/* --- gradebook --------------------------------------------------------------- */

.gradebook { min-width: 30rem; }
.gradebook th, .gradebook td { vertical-align: middle; }
.gradebook thead th { min-width: 7rem; }
.gradebook thead th.draft { background: var(--warning-bg); }
.gradebook .pupil-col { position: sticky; left: 0; background: var(--surface-raised); min-width: 9rem; font-weight: var(--weight-medium); }
.gb-title { font-weight: var(--weight-semibold); color: var(--text-primary); }
.score-in { width: 4.5rem; min-height: 40px; text-align: center; font-variant-numeric: tabular-nums; }
.score-in.invalid { border-color: var(--danger-default); background: var(--danger-bg); }
.term { white-space: nowrap; }
.band { margin-left: var(--space-2); padding: 0 var(--space-2); border-radius: var(--radius-sm); font-size: var(--text-sm); font-weight: var(--weight-semibold); }
.band.pass { background: var(--success-bg); color: var(--success-fg); }
.band.fail { background: var(--danger-bg); color: var(--danger-fg); }

/* --- small screens --------------------------------------------------------- */

@media (max-width: 480px) {
  .brand-sub, .whoami { display: none; }
  .day-long, .mark-long { display: none; }
  .day-short, .mark-short { display: inline; }
  .register-row .marks { width: 100%; justify-content: space-between; }
  .wrap { padding-top: var(--space-4); }
  .card { padding: var(--space-4); }
  .period { width: 3.25rem; }
  .table th:nth-child(3), .table td:nth-child(3) { display: none; }
}
