/* =========================================================================
   school.css — the school-specific components.
   `styles.css` carries the design system (tokens, materials, type, motion
   prefs) unchanged from `personal`; this file is everything Term adds.

   A subject's colour derives from ONE number — `--hue` set on the element —
   so adding a subject needs no new CSS anywhere.
   ========================================================================= */

/* ------------------------------------------------------------------ tabs */

.tabs {
  display: flex;
  gap: 0.125rem;
  margin-left: auto;
  padding: 0.25rem;
  border-radius: 11px;
  background: var(--separator);
}
.tabs button {
  padding: 0.3125rem 0.875rem;
  border-radius: 8px;
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: -0.003em;
  color: var(--text-secondary);
  transition: color 140ms ease-out, background-color 140ms ease-out;
}
.tabs button[aria-selected="true"] {
  color: var(--text);
  font-weight: 600;
  background: var(--bg-elevated);
  box-shadow: var(--shadow-sm);
}

/* ------------------------------------------------------------- page body */

.page {
  position: absolute;
  inset: var(--header-h) 0 0 0;
  overflow-y: auto;
  scrollbar-width: thin;
  padding: 1.25rem 1.5rem 4rem;
}

.stack { display: flex; flex-direction: column; gap: 1.5rem; max-width: 58rem; }
/* The timetable is a table, not prose — the reading-width cap squashes it. */
.stack--wide { max-width: none; }

.h-sec {
  margin: 0 0 0.625rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;    /* small text opens up */
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.card {
  padding: 1rem 1.125rem;
  background: var(--bg-elevated);
  border: 1px solid var(--separator);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.empty {
  padding: 1.75rem 1.125rem;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 0.875rem;
}

/* ------------------------------------------------------------- the brief */

.brief__head {
  margin: 0 0 0.25rem;
  font-size: clamp(1.5rem, 3.2vw, 2rem);
  font-weight: 640;
  letter-spacing: -0.024em;   /* display type tightens as it grows */
  line-height: 1.12;
}
.brief__sub { font-size: 0.9375rem; color: var(--text-secondary); }

.brief__row { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 1rem; }

.stat {
  flex: 1 1 8rem;
  padding: 0.75rem 0.875rem;
  background: var(--bg-elevated);
  border: 1px solid var(--separator);
  border-radius: var(--radius);
}
.stat__n {
  font-size: 1.5rem;
  font-weight: 620;
  letter-spacing: -0.02em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.stat__l { margin-top: 0.125rem; font-size: 0.75rem; color: var(--text-secondary); }

.meter {
  height: 6px;
  margin-top: 0.5rem;
  border-radius: 3px;
  background: var(--separator);
  overflow: hidden;
}
/* width is spring-driven from JS, never transitioned here */
.meter__fill { height: 100%; border-radius: 3px; background: var(--accent); }
.meter__fill--done { background: hsl(var(--tag-health)); }

/* ----------------------------------------------------------- lesson strip */

.lessons {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
  scrollbar-width: thin;
}

.lesson {
  flex: 0 0 auto;
  min-width: 7.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  background: hsl(var(--hue) 72% 52% / 0.12);
  border-left: 2.5px solid hsl(var(--hue) 72% 52%);
}
.lesson--now {
  background: hsl(var(--hue) 72% 52% / 0.2);
  box-shadow: 0 0 0 2px hsl(var(--hue) 72% 52% / 0.35);
}
.lesson--free {
  background: var(--separator);
  border-left-color: var(--text-tertiary);
  border-left-style: dashed;
}
.lesson__p {
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: hsl(var(--hue) 72% 40%);
}
.lesson--free .lesson__p { color: var(--text-tertiary); }
.lesson__n {
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: -0.006em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lesson__m {
  font-size: 0.6875rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.lesson__flag { font-size: 0.625rem; font-weight: 600; color: hsl(var(--tag-travel)); }

/* Vibrancy: the same hue needs to lift in dark mode to stay legible. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .lesson__p { color: hsl(var(--hue) 72% 68%); }
}
:root[data-theme="dark"] .lesson__p { color: hsl(var(--hue) 72% 68%); }

/* -------------------------------------------------------------- work rows */

.rows { display: flex; flex-direction: column; gap: 1px; }

.row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius);
  text-align: left;
  transition: background-color 120ms ease-out;
}
.row:hover { background: var(--separator); }
.row__bar {
  flex: none;
  width: 3px;
  align-self: stretch;
  border-radius: 2px;
  background: hsl(var(--hue) 72% 52%);
}
.row__body { flex: 1; min-width: 0; }
.row__t {
  font-size: 0.875rem;
  font-weight: 550;
  letter-spacing: -0.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row__t--done { text-decoration: line-through; color: var(--text-tertiary); }
.row__m { font-size: 0.75rem; color: var(--text-secondary); }
.row__m--late { color: var(--now); font-weight: 550; }
.row__m--tight { color: hsl(var(--tag-travel)); font-weight: 550; }

.row__sub {
  flex: none;
  padding: 0.0625rem 0.375rem;
  border-radius: 4px;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: hsl(var(--hue) 72% 52% / 0.16);
  color: hsl(var(--hue) 72% 36%);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .row__sub { color: hsl(var(--hue) 72% 70%); }
}
:root[data-theme="dark"] .row__sub { color: hsl(var(--hue) 72% 70%); }

.tick {
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--separator-strong);
  border-radius: 50%;
  color: transparent;
  transition: background-color 120ms ease-out, border-color 120ms ease-out, color 120ms ease-out;
}
.tick:hover { border-color: var(--accent); }
.tick[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.tick svg { width: 0.75rem; height: 0.75rem; }

/* --------------------------------------------------------- timetable grid */

.tt {
  display: grid;
  grid-template-columns: 4.5rem repeat(5, minmax(0, 1fr));
  gap: 1px;
  background: var(--separator);
  border: 1px solid var(--separator);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.tt__h, .tt__p, .tt__c { background: var(--bg-elevated); padding: 0.5rem; min-height: 3.25rem; }
.tt__h {
  min-height: 0;
  padding: 0.5rem 0.25rem;
  text-align: center;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}
.tt__h--today { color: var(--now); }
.tt__p {
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  font-size: 0.625rem;
  line-height: 1.3;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}
.tt__p b { display: block; font-size: 0.75rem; font-weight: 600; color: var(--text-secondary); }
.tt__c { padding: 0.25rem; }
.tt__c--break { background: color-mix(in srgb, var(--text) 3%, var(--bg-elevated)); }

.cell {
  height: 100%;
  padding: 0.3125rem 0.4375rem;
  border-radius: var(--radius-sm);
  background: hsl(var(--hue) 72% 52% / 0.14);
  border-left: 2.5px solid hsl(var(--hue) 72% 52%);
  overflow: hidden;
}
.cell__n {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: -0.004em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cell__r { font-size: 0.6875rem; color: var(--text-secondary); }
.cell--cancelled { opacity: 0.4; text-decoration: line-through; }

.weekpill {
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------------------------------------------------------------- subjects */

.subs { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); }

.sub {
  padding: 0.875rem 1rem;
  background: var(--bg-elevated);
  border: 1px solid var(--separator);
  border-left: 3px solid hsl(var(--hue) 72% 52%);
  border-radius: var(--radius);
}
.sub__n { font-size: 0.9375rem; font-weight: 620; letter-spacing: -0.01em; }
.sub__q { font-size: 0.75rem; color: var(--text-tertiary); }
.sub__row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 0.625rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
}
.sub__pct {
  font-size: 1.25rem;
  font-weight: 620;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.chips { display: flex; gap: 0.3125rem; flex-wrap: wrap; margin-top: 0.625rem; }
.chip {
  padding: 0.125rem 0.4375rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 550;
  background: var(--separator);
  color: var(--text-secondary);
}
.chip--weak { background: hsl(var(--tag-travel) / 0.18); color: hsl(var(--tag-travel)); }

/* ------------------------------------------------------------------ sheet */

.sheet-scrim {
  position: fixed;
  inset: 0;
  z-index: 150;
  /* Dim to focus: a modal task pushes the background back. */
  background: rgba(0, 0, 0, 0.42);
  opacity: 0;
  pointer-events: none;
}
.sheet-scrim[data-open="true"] { pointer-events: auto; }

.sheet {
  position: fixed;
  z-index: 151;
  top: 50%;
  left: 50%;
  width: min(30rem, calc(100vw - 2rem));
  max-height: min(44rem, calc(100dvh - 3rem));
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-xl);
  /* Heavier than the command palette on purpose. A form full of inputs over
     a dense timetable must stay legible WITHOUT relying on backdrop blur,
     which is switched off under "reduce transparency" and absent in some
     renderers — at the thinner material the grid read straight through the
     fields. Material weight encodes hierarchy: this is the heaviest surface
     in the app because it is the one you have to read carefully. */
  background: color-mix(in srgb, var(--bg-elevated) 97%, transparent);
  backdrop-filter: blur(40px) saturate(190%);
  -webkit-backdrop-filter: blur(40px) saturate(190%);
  border: 1px solid var(--material-edge);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  will-change: transform, opacity;
}
.sheet[data-open="true"] { pointer-events: auto; }

.sheet__form { display: flex; flex-direction: column; min-height: 0; }
.sheet__head { padding: 1.125rem 1.25rem 0.25rem; }
.sheet__title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 650;
  letter-spacing: -0.016em;
}
.sheet__sub { margin: 0.125rem 0 0; font-size: 0.8125rem; color: var(--text-secondary); }
.sheet__body {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  padding: 0.875rem 1.25rem;
  overflow-y: auto;
}
.sheet__error {
  margin: 0 1.25rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  background: hsl(4 90% 58% / 0.12);
  color: var(--now);
}
.sheet__foot {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.875rem 1.25rem 1.125rem;
  border-top: 1px solid var(--separator);
}
.sheet__foot .btn { flex: none; padding: 0.4375rem 1rem; }
.sheet__spacer { flex: 1; }

/* The buttons live in styles.css for `personal`; Term needs them too. */
.btn {
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 550;
  background: var(--separator);
  transition: background-color 120ms ease-out, transform 100ms ease-out;
}
.btn:hover { background: var(--separator-strong); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; pointer-events: none; }
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn--danger { color: var(--now); }
.btn--danger[data-armed="true"] { background: var(--now); color: #fff; }

/* ------------------------------------------------------------------ fields */

.field { display: flex; flex-direction: column; gap: 0.3125rem; border: 0; margin: 0; padding: 0; min-width: 0; }
.field__label {
  padding: 0;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text-secondary);
}
.field__hint { font-size: 0.75rem; color: var(--text-tertiary); }
.field--note {
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--separator);
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.field input:not([type="radio"]),
.field select,
.field textarea {
  width: 100%;
  padding: 0.5rem 0.625rem;
  border: 1px solid var(--separator-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  font-size: 0.9375rem;     /* >= 16px-equivalent on iOS stops zoom-on-focus */
  transition: border-color 120ms ease-out, box-shadow 120ms ease-out;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field textarea { resize: vertical; min-height: 4.5rem; font-family: inherit; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

/* segmented radios */
.seg {
  display: flex;
  gap: 0.125rem;
  padding: 0.1875rem;
  border-radius: 9px;
  background: var(--separator);
}
.seg__opt { flex: 1; position: relative; }
.seg__opt input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg__opt span {
  display: block;
  padding: 0.375rem 0.5rem;
  border-radius: 7px;
  text-align: center;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: background-color 120ms ease-out, color 120ms ease-out;
}
.seg__opt input:checked + span {
  background: var(--bg-elevated);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}
.seg__opt input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

/* colour picker */
.hues { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.hue { position: relative; width: 1.75rem; height: 1.75rem; }
.hue input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.hue span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: hsl(var(--hue) 72% 52%);
  transition: transform 120ms ease-out;
}
.hue:hover span { transform: scale(1.1); }
.hue input:checked + span { box-shadow: 0 0 0 2px var(--bg-elevated), 0 0 0 4px hsl(var(--hue) 72% 52%); }
.hue input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ------------------------------------------------------------- onboarding */

.welcome {
  padding: 2rem 1.75rem;
  text-align: center;
  background: var(--bg-elevated);
  border: 1px solid var(--separator);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
}
.welcome__title {
  margin: 0 0 0.375rem;
  font-size: 1.5rem;
  font-weight: 650;
  letter-spacing: -0.022em;
}
.welcome__text { max-width: 30rem; margin: 0 auto 1.25rem; color: var(--text-secondary); font-size: 0.9375rem; }
.welcome__actions { display: flex; gap: 0.625rem; justify-content: center; flex-wrap: wrap; }
.welcome__actions .btn { padding: 0.5625rem 1.125rem; font-size: 0.875rem; }

/* ------------------------------------------------------- editable affordances */

.tt__c--editable { cursor: pointer; }
.tt__c--editable:hover { background: color-mix(in srgb, var(--accent) 6%, var(--bg-elevated)); }
.tt__c--editable:empty::after {
  content: "+";
  display: grid;
  place-items: center;
  height: 100%;
  font-size: 1rem;
  color: var(--text-tertiary);
  opacity: 0;
  transition: opacity 120ms ease-out;
}
.tt__c--editable:empty:hover::after { opacity: 1; }
.cell--cancelled .cell__n::after { content: " · off"; font-weight: 500; }
.cell--moved { border-left-style: dashed; }

.toolbar { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.toolbar .btn { padding: 0.375rem 0.75rem; }

.row--clickable { cursor: pointer; }
.row__act {
  flex: none;
  padding: 0.25rem 0.625rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
}

/* the running study timer */
.timer {
  font-size: 2.75rem;
  font-weight: 300;
  letter-spacing: -0.03em;
  line-height: 1;
  text-align: center;
  font-variant-numeric: tabular-nums;
  padding: 0.75rem 0 0.25rem;
}
.timer__label { text-align: center; font-size: 0.8125rem; color: var(--text-secondary); }

/* -------------------------------------------------------------- responsive */

@media (max-width: 60rem) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .fab { display: grid; }
}

@media (max-width: 40rem) {
  .page { padding: 1rem 0.875rem 5rem; }
  .topbar { padding: 0 0.625rem; gap: 0.375rem; }
  .topbar__title {
    font-size: 1.0625rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .tabs button { padding: 0.3125rem 0.5rem; font-size: 0.75rem; }
  /* Five columns of lessons is tight on a phone but still the clearest
     representation of a week — shrink the gutter and drop room labels
     rather than reflowing into something that is no longer a timetable. */
  .tt { grid-template-columns: 3.5rem repeat(5, minmax(0, 1fr)); }
  .tt__c { padding: 0.125rem; }
  .cell { padding: 0.25rem; border-left-width: 2px; }
  .cell__r { display: none; }

  /* On a phone the sheet is a true bottom sheet, anchored where the thumb is.
     sheet.js drops the centring transform below 640px to match. */
  .sheet {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: calc(100dvh - 2.5rem);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .row2 { grid-template-columns: 1fr; }
}
