/* ============================================================================
   COMPONENTS — buttons, cards, tables, badges, toasts, empty states.
   ============================================================================ */

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--touch);          /* a finger must always hit it */
  padding: var(--space-3) var(--space-5);
  font-family: inherit;
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  line-height: 1;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease),
              box-shadow var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; transform: none; }

/* Electric blue into cyan on the dark theme, with a soft glow; plain indigo
   on the light one. The tokens decide — see the premium layer in tokens.css. */
.btn-primary {
  background-color: var(--primary-solid);
  background-image: var(--primary-fill);
  color: var(--on-primary);
  box-shadow: var(--primary-glow);
  border-color: transparent;
}
.btn-primary:hover:not(:disabled) { background-image: var(--primary-fill-hover); }

.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--secondary-edge); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-sunk); border-color: var(--primary); }

.btn-ghost { background: transparent; color: var(--primary); }
.btn-ghost:hover:not(:disabled) { background: var(--primary-soft); }

.btn-danger { background: var(--danger); color: var(--ink-invert); }
.btn-danger:hover:not(:disabled) { background: var(--danger-ink); }

.btn-sm { min-height: 36px; padding: var(--space-2) var(--space-3); font-size: var(--text-sm); }
.btn-lg { min-height: 52px; padding: var(--space-4) var(--space-8); font-size: var(--text-md); }
.btn-block { width: 100%; }

/* A button that is working. The label stays, so the user still knows what it does. */
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 18px; height: 18px;
  border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%;
  color: var(--ink-invert);
  animation: spin 0.6s linear infinite;
}
.btn-secondary.is-loading::after, .btn-ghost.is-loading::after { color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------- password reveal */

/*
  Typing a password blind is where signing in most often fails — a parent on a
  phone keyboard has no way to see they hit the wrong key. So every password
  box carries a Show/Hide control.

  It starts hidden, so opening a page never exposes anything, and it is a real
  44px target rather than a small eye glyph.  [KICKOFF 6.1, 6.4]
*/
/* Wraps the input and its button only, so the button never covers the label
   above it or the error message below. */
.password-field { position: relative; display: grid; }

.password-field input { padding-right: 5.5rem; }

.password-reveal {
  position: absolute;
  right: 1px;
  top: 1px;
  bottom: 1px;
  min-width: 5rem;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  background: transparent;
  color: var(--primary);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
}
.password-reveal:hover { background: var(--primary-soft); }
.password-reveal:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

/* ---------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--card-edge);
  border-radius: var(--radius-lg);
  box-shadow: var(--card-shadow);
}
/* The card that matters more on a page — a dashboard's figures, the thing to
   do next — carries the accent edge and the glow. Sparingly. */
.card.is-featured { box-shadow: var(--card-glow); }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  /* A heading and its buttons sit side by side while they fit and drop onto a
     second line when they do not. Without this the lock button on the
     examinations page hung 37px off the side of a 360px screen. */
  flex-wrap: wrap;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--line);
}
.card-title { font-size: var(--text-md); font-weight: var(--weight-semi); }

/* A second group of fields inside one form — the parent, after the student.
   A rule above it rather than a second card, because it is still one save. */
.form-section {
  font-size: var(--text-md); font-weight: var(--weight-semi);
  margin-top: var(--space-6); padding-top: var(--space-5);
  border-top: 1px solid var(--line);
}
.form-section + p { margin: var(--space-2, .5rem) 0 var(--space-4); }
.card-body { padding: var(--space-6); }
.card-body.tight { padding: var(--space-4); }
.card-foot {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--line);
  background: var(--surface-alt);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* One number that matters. Used sparingly — not every figure is a headline. */
.stat { padding: var(--space-5) var(--space-6); }
.stat-label {
  font-size: var(--text-sm); color: var(--ink-muted);
  margin-bottom: var(--space-1);
}
.stat-value {
  font-size: var(--text-2xl); font-weight: var(--weight-bold);
  line-height: 1.1; font-variant-numeric: tabular-nums;
  color: var(--figure);
}
.stat-note { font-size: var(--text-sm); color: var(--ink-soft); margin-top: var(--space-2); }
.stat-value.is-good { color: var(--success); }
.stat-value.is-warn { color: var(--warning); }
.stat-value.is-bad  { color: var(--danger); }

.grid { display: grid; gap: var(--space-4); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

/* ---------------------------------------------------------------- badges */

.badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 3px var(--space-3);
  font-size: var(--text-xs); font-weight: var(--weight-semi);
  letter-spacing: 0.02em;
  border-radius: var(--radius-full);
  white-space: nowrap;
}
.badge-neutral { background: var(--surface-sunk); color: var(--ink-soft); }
.badge-info    { background: var(--info-bg);    color: var(--info-ink); }
.badge-success { background: var(--success-bg); color: var(--success-ink); }
.badge-warning { background: var(--warning-bg); color: var(--warning-ink); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger-ink); }

/* A dot before the label makes status readable without relying on colour alone. */
.badge::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor;
  opacity: 0.75;
}
.badge.no-dot::before { display: none; }

/*
  The "×" that takes a chip away.

  The glyph itself is tiny, so the button is given a real hit area around it
  and pulled back with negative margin, which keeps the chip the size it looks
  without leaving an 8px target nobody can hit. Under a thumb it grows to the
  full 44px and the chip grows with it.  [KICKOFF 6.4]
*/
.chip-remove {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  min-height: 24px;
  margin: -4px -6px -4px var(--space-1);
  border-radius: var(--radius-full);
  color: inherit;
  opacity: 0.7;
  font-size: var(--text-sm);
  line-height: 1;
}
.chip-remove:hover { opacity: 1; background: rgba(19, 28, 40, 0.1); }
.chip-remove:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; opacity: 1; }

@media (pointer: coarse), (max-width: 860px) {
  .badge:has(.chip-remove) { min-height: var(--touch); }
  .chip-remove {
    min-width: var(--touch);
    min-height: var(--touch);
    margin: 0 calc(var(--space-2) * -1) 0 var(--space-1);
  }
}

/* ---------------------------------------------------------------- tables */

/* Wide tables scroll inside their own container, never the page. [KICKOFF 6.4] */
.table-wrap {
  /* Positioned so that this box is the containing block for anything absolute
     inside it. Without it, the .sr-only labels on the attendance radios — which
     are absolutely positioned — were laid out against the page instead, escaped
     the clip below, and dragged the whole document 91px sideways on a phone
     while the table itself scrolled correctly. */
  position: relative;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  -webkit-overflow-scrolling: touch;
}

table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }

thead th {
  position: sticky; top: 0; z-index: 1;
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-size: var(--text-xs);
  font-weight: var(--weight-semi);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-muted);
  background: var(--surface-sunk);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

tbody td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-alt); }

th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* On a phone, the student's name stays put while marks scroll.  [KICKOFF 6.4] */
.table-sticky-first th:first-child,
.table-sticky-first td:first-child {
  position: sticky; left: 0; z-index: 2;
  background: var(--surface);
  box-shadow: 1px 0 0 var(--line);
}
.table-sticky-first thead th:first-child { z-index: 3; background: var(--surface-sunk); }

/* ---------------------------------------------------------------- toasts */

/*
  Every save, failure and refusal raises one of these. It closes itself after
  5 seconds, can be dismissed sooner, is announced to screen readers, and never
  blocks the page.  [KICKOFF 6.3]
*/
.toast-region {
  position: fixed;
  right: var(--space-5);
  bottom: var(--space-5);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column-reverse;   /* newest nearest the thumb */
  gap: var(--space-3);
  pointer-events: none;
  max-width: min(400px, calc(100vw - var(--space-8)));
}

.toast {
  pointer-events: auto;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: var(--space-3);
  align-items: start;
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--ink-muted);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  animation: toast-in var(--normal) var(--ease);
}
.toast.is-leaving { animation: toast-out var(--fast) var(--ease) forwards; }

.toast-success { border-left-color: var(--success); }
.toast-error   { border-left-color: var(--danger); }
.toast-warning { border-left-color: var(--warning); }
.toast-info    { border-left-color: var(--info); }

.toast-icon {
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 13px; font-weight: var(--weight-bold); color: var(--ink-invert);
  flex-shrink: 0;
}
.toast-success .toast-icon { background: var(--success); }
.toast-error   .toast-icon { background: var(--danger); }
.toast-warning .toast-icon { background: var(--warning); }
.toast-info    .toast-icon { background: var(--info); }

.toast-title { font-weight: var(--weight-semi); font-size: var(--text-sm); }
.toast-body  { font-size: var(--text-sm); color: var(--ink-soft); margin-top: 2px; }

.toast-close {
  background: none; border: 0; cursor: pointer;
  width: 28px; height: 28px; border-radius: var(--radius-sm);
  color: var(--ink-muted); font-size: 18px; line-height: 1;
  display: grid; place-items: center;
}
.toast-close:hover { background: var(--surface-sunk); color: var(--ink); }

/* A thin bar showing the 5 seconds running out, so the dismissal isn't a surprise. */
.toast-timer {
  grid-column: 1 / -1;
  height: 2px; margin-top: var(--space-2);
  background: var(--line); border-radius: var(--radius-full); overflow: hidden;
}
.toast-timer span {
  display: block; height: 100%; background: currentColor; opacity: 0.5;
  transform-origin: left;
  animation: toast-countdown linear forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(6px) scale(0.98); }
}
@keyframes toast-countdown {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}

@media (max-width: 600px) {
  .toast-region {
    left: var(--space-4); right: var(--space-4); bottom: var(--space-4);
    max-width: none;
  }
}

/* ---------------------------------------------------------------- empty & alert */

/* An empty screen must say what to do next, never just "no data".  [KICKOFF 6.1] */
.empty {
  text-align: center;
  padding: var(--space-12) var(--space-6);
  color: var(--ink-soft);
}
.empty-icon {
  width: 52px; height: 52px; margin: 0 auto var(--space-4);
  border-radius: var(--radius-full);
  background: var(--primary-soft); color: var(--primary);
  display: grid; place-items: center; font-size: 24px;
}
/* The bell is an SVG rather than a glyph, so it needs its own size in the
   circle — font-size does nothing to it. */
.empty-icon .bell-icon { width: 26px; height: 26px; }
.empty-title { font-weight: var(--weight-semi); color: var(--ink); margin-bottom: var(--space-2); }
.empty-text { font-size: var(--text-sm); max-width: 42ch; margin: 0 auto var(--space-5); }

.alert {
  display: flex; gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: var(--text-sm);
}
.alert-info    { background: var(--info-bg);    border-color: var(--info-line);    color: var(--info-ink); }
.alert-success { background: var(--success-bg); border-color: var(--success-line); color: var(--success-ink); }
.alert-warning { background: var(--warning-bg); border-color: var(--warning-line); color: var(--warning-ink); }
.alert-danger  { background: var(--danger-bg);  border-color: var(--danger-line);  color: var(--danger-ink); }

/* ---------------------------------------------------------------- misc */

.divider { height: 1px; background: var(--line); border: 0; margin: var(--space-6) 0; }

.avatar {
  width: 38px; height: 38px; border-radius: var(--radius-full);
  background: var(--avatar-bg); color: var(--avatar-ink);
  display: grid; place-items: center;
  font-weight: var(--weight-semi); font-size: var(--text-sm);
  flex-shrink: 0;
  overflow: hidden;
}
/* A profile photo fills the circle; the initials are what shows without one. */
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.has-photo { background: var(--surface-sunk); }
.avatar-sm { width: 32px; height: 32px; font-size: var(--text-xs); }
.avatar-md { width: 44px; height: 44px; }
.avatar-photo { width: 72px; height: 72px; background: var(--surface-sunk); color: var(--ink-muted); }

/* A name with its photo in front, like a chat list. */
.person { display: inline-flex; align-items: center; gap: var(--space-3); min-width: 0; vertical-align: middle; }
.person-text { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }

.photo-picker { display: flex; align-items: center; gap: var(--space-4); margin-bottom: var(--space-4); }
.photo-picker-body { min-width: 0; }

.pill-tabs { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.pill-tab {
  min-height: 40px;
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--ink-soft);
  font-size: var(--text-sm); font-weight: var(--weight-medium);
  cursor: pointer;
  transition: all var(--fast) var(--ease);
}
.pill-tab:hover { border-color: var(--soft-edge-hover); color: var(--primary); }
.pill-tab[aria-selected="true"] {
  background: var(--primary); border-color: var(--primary); color: var(--ink-invert);
}

.progress { height: 8px; background: var(--surface-sunk); border-radius: var(--radius-full); overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--primary); border-radius: var(--radius-full);
                 transition: width var(--slow) var(--ease); }
.progress.is-good span { background: var(--success); }
.progress.is-warn span { background: var(--warning); }
.progress.is-bad  span { background: var(--danger); }

.skeleton {
  background: linear-gradient(90deg, var(--grey-100) 25%, var(--grey-200) 37%, var(--grey-100) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* ============================================================================
   ASK — in-page confirmations and questions
   Never alert(), confirm() or prompt(): those look like a browser warning
   rather than part of the school's software, and they freeze the page.
   [UI-GUIDE 7, 9]
   ============================================================================ */

.ask {
  width: min(30rem, calc(100vw - var(--space-8)));
  padding: 0;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.ask::backdrop {
  background: rgba(19, 28, 40, 0.45);
}
.ask[open] {
  animation: ask-in var(--normal) var(--ease);
}
@keyframes ask-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

.ask-body { padding: var(--space-6); }

.ask-title {
  margin: 0 0 var(--space-2);
  font-size: var(--text-md);
  font-weight: var(--weight-semi);
  line-height: var(--leading-tight);
}
.ask-text {
  margin: 0 0 var(--space-5);
  color: var(--ink-soft);
  line-height: var(--leading-normal);
}
/* What a yes will do, one line each — below the question's own words. */
.ask-list {
  margin: calc(var(--space-5) * -0.5) 0 var(--space-5);
  padding-left: 1.2em;
  color: var(--ink);
  line-height: var(--leading-normal);
}
.ask-list li + li { margin-top: var(--space-1); }

.ask-actions {
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: var(--space-5);
}
/* On a phone the buttons stack and go full width — a 44px target every time. */
@media (max-width: 30rem) {
  .ask-actions { flex-direction: column-reverse; }
  .ask-actions .btn { width: 100%; }
}

/* ============================================================================
   CHART — the term-wise progress plot on the student and parent result pages.
   Plain SVG, drawn by assets/js/progress.js. Colours come from the tokens, so
   a dot on the chart is the same green, amber or red as the figure beside it.
   ============================================================================ */

.chart-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}
.chart-pick { display: grid; gap: var(--space-2); min-width: 13rem; }
.chart-pick select { min-height: 40px; padding-block: var(--space-2); }

.chart-svg { width: 100%; height: auto; overflow: visible; }

.chart-grid { stroke: var(--line); stroke-width: 1; }

.chart-line {
  fill: none;
  stroke: var(--primary);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.chart-area { fill: var(--primary); opacity: 0.07; }

.chart-dot { stroke: var(--surface); stroke-width: 2; fill: var(--primary); }
.chart-dot.is-good { fill: var(--success); }
.chart-dot.is-warn { fill: var(--warning); }
.chart-dot.is-bad  { fill: var(--danger); }

.chart-value {
  fill: var(--ink);
  font-size: 13px;
  font-weight: var(--weight-semi);
  font-family: var(--font);
}
.chart-axis {
  fill: var(--ink-muted);
  font-size: 12px;
  font-family: var(--font);
}
/* An examination with no marks for this subject still keeps its place on the
   axis, but says so quietly. */
.chart-axis.is-empty { fill: var(--grey-400); }

.chart-note { margin: var(--space-4) 0 0; color: var(--ink-soft); }

/* The chart sits inside the child card on a parent's overview, between the
   figures above it and the marks below. */
.progress-slot { margin: var(--space-6) 0; }
.progress-slot .chart-note { margin-bottom: var(--space-6); }

/* The plot is one drawing that scales with the column it sits in, so on a
   narrow screen everything in it shrinks — including the writing. These steps
   grow the type inside the SVG as the drawing shrinks, which keeps the labels
   at roughly the same real size on a phone as on a laptop. */
@media (max-width: 64rem) {
  .chart-value { font-size: 16px; }
  .chart-axis  { font-size: 15px; }
  .chart-dot   { r: 6px; stroke-width: 2.5; }
  .chart-line  { stroke-width: 3; }
}
@media (max-width: 48rem) {
  .chart-value { font-size: 21px; }
  .chart-axis  { font-size: 20px; }
  .chart-dot   { r: 8px; stroke-width: 3; }
  .chart-line  { stroke-width: 4; }
}
@media (max-width: 34rem) {
  .chart-pick  { min-width: 100%; }
  .chart-value { font-size: 27px; }
  .chart-axis  { font-size: 25px; }
  .chart-dot   { r: 10px; stroke-width: 4; }
  .chart-line  { stroke-width: 5; }
}

/* ------------------------------------------------------------------- houses
   A house badge, in its own colour, wherever a student is shown.

   The colour comes from `data-house` rather than from a class per house, so
   the markup carries the house's key — the same key the database stores and
   the same one utils/constants.js names — and nothing has to remember to keep
   a class list in step with it. */
.house {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 2px var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: var(--weight-semi);
  border: 1px solid currentColor;
}
.house::before {
  content: "";
  width: 9px; height: 9px;
  border-radius: var(--radius-full);
  background: currentColor;
}
.house[data-house="GREEN"]  { color: var(--house-green);  background: var(--house-green-soft); }
.house[data-house="RED"]    { color: var(--house-red);    background: var(--house-red-soft); }
.house[data-house="YELLOW"] { color: var(--house-yellow); background: var(--house-yellow-soft); }
.house[data-house="ORANGE"] { color: var(--house-orange); background: var(--house-orange-soft); }
.house[data-house="BLUE"]   { color: var(--house-blue);   background: var(--house-blue-soft); }
.house[data-house="PURPLE"] { color: var(--house-purple); background: var(--house-purple-soft); }
.house[data-house="MAROON"] { color: var(--house-maroon); background: var(--house-maroon-soft); }
.house[data-house="SKY"]    { color: var(--house-sky);    background: var(--house-sky-soft); }
.house[data-house="PINK"]   { color: var(--house-pink);   background: var(--house-pink-soft); }

/* No house yet is a real state, and says so rather than showing an empty pill. */
.house[data-house=""] { color: var(--ink-muted); background: var(--surface-sunk); border-color: var(--line); }

/* ============================================================================
   School IDs and first passwords.

   An ID is read out over a phone and copied off a card, so it is set in a
   typeface where 0 and O, 1 and I cannot be mistaken, and it never wraps
   halfway through. */
.id-chip {
  display: inline-block;
  padding: 1px var(--space-2);
  border-radius: var(--radius);
  background: var(--surface-sunk);
  border: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 0.92em;
  letter-spacing: 0.02em;
  white-space: nowrap;
  color: var(--ink);
}

/* The date of birth, and the box for when there is none. */
.dob-field .choice { margin-top: var(--space-2); min-height: 36px; padding-block: var(--space-1); }
.field-help { display: block; margin-top: var(--space-1); font-size: var(--text-sm); color: var(--ink-muted); }
.credential-note { display: inline-block; line-height: var(--leading-normal); }

/* The sign-in panel for one person. */
.ask.ask-wide { width: min(36rem, calc(100vw - var(--space-8))); }
.person-facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: var(--space-4);
  margin-top: var(--space-4);
}
.ask-actions-wrap { justify-content: flex-start; }
.ask-actions-wrap .btn-primary { margin-left: auto; }
@media (max-width: 30rem) {
  .ask-actions-wrap .btn-primary { margin-left: 0; }
}

/* The first sign-in: why this page, and why now. */
.first-signin { margin-bottom: var(--space-5); }

/* ============================================================================
   A student's details, and their family's — the office's View details panel.
   Label above value, two columns on a desk, one on a phone. The panel scrolls
   inside itself so its buttons stay reachable with two parents on it. */
.details-dialog[open] { max-height: calc(100vh - var(--space-8)); display: flex; }
.details-dialog .ask-body { overflow-y: auto; width: 100%; }
.details-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: var(--space-3) var(--space-5);
  margin: var(--space-3) 0 var(--space-4);
}
.details-grid dt { font-size: var(--text-sm); color: var(--ink-muted); }
.details-grid dd { margin: 2px 0 0; font-weight: var(--weight-medium); overflow-wrap: anywhere; }
.details-grid .span-2, .details-dialog .span-2 { grid-column: 1 / -1; }
.family-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
  background: var(--surface);
}
.family-card .details-grid { margin-bottom: 0; }
.details-dialog textarea { width: 100%; resize: vertical; }
.choice.choice-tight { min-height: 36px; margin-top: var(--space-2); padding-block: var(--space-1); }

/* ============================================================================
   Checked as it is typed (assets/js/forms.js).

   A field that is right gets a quiet green edge and a tick; one that is wrong
   keeps the red edge and its message underneath. A note under a field is good
   news (the bank branch an IFSC belongs to) or worth a second look ("Did you
   mean gmail.com?") — never a refusal, which is always the red message. */
input.is-valid, select.is-valid, textarea.is-valid {
  border-color: var(--success);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3 8.5l3 3 7-7' fill='none' stroke='%23059669' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  background-size: 14px;
  padding-right: 2rem;
}
input[type="date"].is-valid { background-image: none; padding-right: revert; }
.field-note { display: block; min-height: 0; font-size: var(--text-sm); color: var(--ink-muted); }
.field-note:empty { display: none; }
.field-note.is-ok { color: var(--success-ink); }
.field-note.is-warning { color: var(--warning-ink); }

/* The address, as a group: Country → State → District → Locality → PIN → address. */
.address-block { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-3) var(--space-4) var(--space-2); margin: var(--space-3) 0; }
.address-legend { padding: 0 var(--space-2); font-weight: var(--weight-semi); color: var(--ink); }
.address-block textarea { width: 100%; resize: vertical; }

/* ---------------------------------------------------------------- the Aa text size control
   (assets/js/textSize.js) — on the sign-in page and every signed-in page. */

/* The text size control. Measured in px on purpose: it keeps its own size
   while everything it controls grows and shrinks. */
.textsize {
  position: fixed;
  z-index: 60;
  left: 0;
  top: 0;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 12px 32px -10px rgba(0, 0, 0, 0.45);
  font-size: 16px;
  line-height: 1;
}
.textsize.is-dragging { cursor: grabbing; box-shadow: 0 18px 40px -10px rgba(0, 0, 0, 0.55); }

.textsize-grip {
  display: grid;
  place-items: center;
  width: 44px;       /* a finger's width, like every control on the site */
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-muted);
  cursor: grab;
  touch-action: none;
}
.textsize-grip:focus-visible,
.textsize-open:focus-visible,
.textsize-step:focus-visible,
.textsize-close:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.textsize-open {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background-color: var(--primary-solid);
  background-image: var(--primary-fill);
  color: var(--on-primary);
  font: 700 17px/1 var(--font);
  cursor: pointer;
}

.textsize-panel {
  position: absolute;
  left: 0;
  width: 264px;
  max-width: calc(100vw - 32px);
  padding: 14px 16px 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 20px 48px -14px rgba(0, 0, 0, 0.55);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.4;
}
.textsize-panel.is-below { top: calc(100% + 10px); }
.textsize-panel.is-above { bottom: calc(100% + 10px); }

.textsize-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: -4px -6px 12px 0;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.textsize-head small { font-weight: 400; color: var(--ink-muted); font-size: 12px; }
.textsize-close {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin: -6px -4px -6px 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 20px;
  cursor: pointer;
}
.textsize-close:hover { background: var(--surface-alt); }

.textsize-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 10px;
}
.textsize-step {
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-alt);
  color: var(--ink);
  font: 700 15px/1 var(--font);
  cursor: pointer;
}
.textsize-step:disabled { opacity: 0.4; cursor: default; }
.textsize-step:not(:disabled):hover { border-color: var(--primary); color: var(--primary); }
.textsize-value {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.textsize-range { width: 100%; margin: 12px 0 14px; accent-color: var(--primary); }
.textsize-reset { width: 100%; }
.textsize-note { margin: 8px 0 0; font-size: 12px; color: var(--ink-muted); }

@media print { .textsize { display: none; } }

/* Larger text, chosen with the Aa button. Words and boxes grow, so a few
   things that are fixed at the normal size must give way on a narrow screen:
   a long button label wraps, a box shrinks to the space it has, a column with
   a minimum width narrows. These apply only while the text is enlarged
   (data-text-size="larger", set by textSize.js and theme.js), so every layout
   at the normal size is exactly as it was. */
:root[data-text-size="larger"] .btn {
  white-space: normal;
  max-width: 100%;
  line-height: 1.2;
  text-align: center;
}
:root[data-text-size="larger"] :is(.field, .card, .cal-card, .cal-nav > *) { min-width: 0; }
:root[data-text-size="larger"] :is(input, select, textarea) { min-width: 0; max-width: 100%; }
:root[data-text-size="larger"] .person-facts { grid-template-columns: repeat(auto-fit, minmax(min(13rem, 100%), 1fr)); }
:root[data-text-size="larger"] .details-grid { grid-template-columns: repeat(auto-fit, minmax(min(12rem, 100%), 1fr)); }
:root[data-text-size="larger"] .row { flex-wrap: wrap; }
