/* Uppingham Cairo PE Assessment - prototype styling.
   Mirrors the intended canvas-app design: minimal, high-contrast, large touch
   targets for pitch-side use, and never colour-only signalling. */

:root {
  --uc-navy: #12233f;
  --uc-navy-soft: #1d3557;
  --uc-ink: #16202e;
  --uc-muted: #5b6878;
  --uc-line: #d9e0e8;
  --uc-bg: #f4f6f9;
  --uc-surface: #ffffff;
  --uc-accent: #8a6a1f;

  --hands: #0b6e5f;
  --head: #2f4d9b;
  --heart: #8f3b6b;

  /* Five-point mastery scale. Colour is reinforcement only - every control also
     carries a label and a symbol from a filling sequence. */
  --band-ENT: #6d28d9;
  --band-DEV: #b45309;
  --band-SEC: #0f766e;
  --band-CON: #1d4ed8;
  --band-MAS: #166534;

  --ok: #14664f;
  --warn: #8a5a00;
  --err: #a52121;

  --radius: 10px;
  --tap: 60px;
  --shadow: 0 1px 2px rgba(18, 35, 63, .08), 0 4px 16px rgba(18, 35, 63, .06);
  --focus: 3px solid #1a73e8;
}

* { box-sizing: border-box; }

/* The `hidden` attribute must always win.
 *
 * Browsers hide [hidden] elements with a user-agent rule of `display: none`,
 * but ANY author rule that sets display beats it on specificity - so
 * `.gate { display: flex }` silently un-hid every element the app tried to
 * hide with `el.hidden = true`. The gate stayed on screen covering the whole
 * viewport while the app loaded perfectly behind it, which looked exactly like
 * a hang. Affects .gate, .app and .field, and would quietly affect any future
 * class that sets display.
 *
 * !important is warranted here: this rule must be unbeatable, which is the
 * whole point of it. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--uc-bg);
  color: var(--uc-ink);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

:focus-visible { outline: var(--focus); outline-offset: 2px; border-radius: 4px; }

.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;
}

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--uc-navy); color: #fff; padding: 12px 18px;
}
.skip-link:focus { left: 8px; top: 8px; }

/* ---------------------------------------------------------------- chrome */
.app { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  background: var(--uc-navy);
  color: #fff;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px;
  position: sticky; top: 0; z-index: 20;
}
.topbar img { height: 38px; width: auto; background: #fff; border-radius: 6px; padding: 3px; }
.topbar .title { font-weight: 600; font-size: 1.02rem; line-height: 1.25; }
.topbar .title small { display: block; font-weight: 400; opacity: .8; font-size: .78rem; }
.topbar .spacer { flex: 1; }

.who {
  display: flex; align-items: center; gap: 10px;
  background: rgba(255, 255, 255, .1);
  border-radius: 999px; padding: 5px 6px 5px 14px;
}
.who .role { font-size: .8rem; opacity: .9; }
.who select {
  font: inherit; font-size: .82rem; border: 0; border-radius: 999px;
  padding: 6px 10px; background: #fff; color: var(--uc-ink); max-width: 190px;
}

.banner {
  background: #fff6e0; border-bottom: 1px solid #e6d1a0; color: #5b4300;
  padding: 8px 16px; font-size: .84rem; display: flex; gap: 10px; align-items: baseline;
}
.banner strong { white-space: nowrap; }

.nav {
  display: flex; gap: 2px; background: var(--uc-navy-soft);
  padding: 0 8px; overflow-x: auto; position: sticky; top: 58px; z-index: 19;
}
.nav button {
  font: inherit; font-size: .9rem; color: #e8eef7; background: transparent;
  border: 0; border-bottom: 3px solid transparent; padding: 12px 16px;
  cursor: pointer; white-space: nowrap; min-height: 46px;
}
.nav button:hover { background: rgba(255, 255, 255, .07); }
.nav button[aria-current="page"] {
  color: #fff; border-bottom-color: #f0c14b; font-weight: 600;
}

main { flex: 1; padding: 18px 16px 64px; max-width: 1180px; width: 100%; margin: 0 auto; }

h1 { font-size: 1.4rem; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 1.08rem; margin: 26px 0 10px; }
h3 { font-size: .95rem; margin: 0 0 6px; }
.lede { color: var(--uc-muted); margin: 0 0 18px; font-size: .92rem; }

/* ----------------------------------------------------------------- cards */
.card {
  background: var(--uc-surface); border: 1px solid var(--uc-line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }

.grid { display: grid; gap: 14px; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }

.tile { text-align: left; }
.tile .n { font-size: 2rem; font-weight: 700; line-height: 1.1; }
.tile .lbl { font-size: .84rem; color: var(--uc-muted); }
.tile .sub { font-size: .78rem; color: var(--uc-muted); margin-top: 6px; }
.tile.attention { border-left: 5px solid var(--warn); }
.tile.good { border-left: 5px solid var(--ok); }

/* ----------------------------------------------------------- form controls */
.controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 170px; flex: 1 1 170px; }
.field label { font-size: .78rem; font-weight: 600; color: var(--uc-muted); }
.field select, .field input[type="text"], .field input[type="search"] {
  font: inherit; padding: 11px 10px; border: 1px solid var(--uc-line);
  border-radius: 8px; background: #fff; min-height: 44px;
}

.btn {
  font: inherit; font-weight: 600; border-radius: 8px; padding: 11px 16px;
  min-height: 44px; border: 1px solid var(--uc-navy); background: var(--uc-navy);
  color: #fff; cursor: pointer;
}
.btn:hover { background: #0d1b31; }
.btn.secondary { background: #fff; color: var(--uc-navy); }
.btn.secondary:hover { background: #eef2f7; }
.btn.danger { background: #fff; color: var(--err); border-color: var(--err); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn.small { padding: 7px 11px; min-height: 36px; font-size: .84rem; }

/* --------------------------------------------------------------- assessing */
.classlist { display: flex; flex-direction: column; gap: 10px; }

.pupil {
  border: 1px solid var(--uc-line); border-radius: var(--radius);
  background: #fff; padding: 12px 14px;
}
.pupil.incomplete { border-left: 5px solid var(--warn); }
.pupil.complete { border-left: 5px solid var(--ok); }

.pupil-head {
  display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 10px;
}
.pupil-head .nm { font-weight: 600; font-size: 1.02rem; }
.pupil-head .meta { font-size: .78rem; color: var(--uc-muted); }
.pupil-head .spacer { flex: 1; }

/* Five rating controls per outcome need the full width of the card to stay large
   enough for pitch-side use, so the three strands stack rather than sitting in
   three columns. The strand grouping stays obvious through the coloured top
   border, the icon and the heading. */
.strandrow { display: flex; flex-direction: column; gap: 12px; }

.strand {
  border: 1px solid var(--uc-line); border-radius: 8px; padding: 10px; background: #fbfcfe;
}
.strand > .hdr {
  display: flex; align-items: center; gap: 7px; margin-bottom: 8px;
  font-weight: 700; font-size: .82rem; text-transform: uppercase; letter-spacing: .05em;
}
.strand[data-strand="Hands"] { border-top: 4px solid var(--hands); }
.strand[data-strand="Head"]  { border-top: 4px solid var(--head); }
.strand[data-strand="Heart"] { border-top: 4px solid var(--heart); }
.strand[data-strand="Hands"] > .hdr { color: var(--hands); }
.strand[data-strand="Head"]  > .hdr { color: var(--head); }
.strand[data-strand="Heart"] > .hdr { color: var(--heart); }
.strand .glyph { font-size: 1.1rem; }
.strand .kind { font-weight: 400; text-transform: none; letter-spacing: 0; opacity: .75; }

.outcome { margin-bottom: 12px; }
.outcome:last-child { margin-bottom: 0; }
.outcome .txt { font-size: .84rem; margin-bottom: 6px; }
.outcome .txt .code { color: var(--uc-muted); font-size: .74rem; display: block; }

.rating-group { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }

.rate {
  font: inherit; font-size: .8rem; font-weight: 600; cursor: pointer;
  min-height: var(--tap); border: 2px solid var(--uc-line); background: #fff;
  border-radius: 8px; color: var(--uc-ink); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; padding: 4px 2px;
}
.rate .sym { font-size: 1.15rem; line-height: 1; }
.rate .lbl { font-size: .74rem; line-height: 1.15; }
.rate:hover { border-color: var(--uc-muted); }
.rate[aria-pressed="true"] { color: #fff; border-width: 2px; }
.rate[aria-pressed="true"][data-band="ENT"] { background: var(--band-ENT); border-color: var(--band-ENT); }
.rate[aria-pressed="true"][data-band="DEV"] { background: var(--band-DEV); border-color: var(--band-DEV); }
.rate[aria-pressed="true"][data-band="SEC"] { background: var(--band-SEC); border-color: var(--band-SEC); }
.rate[aria-pressed="true"][data-band="CON"] { background: var(--band-CON); border-color: var(--band-CON); }
.rate[aria-pressed="true"][data-band="MAS"] { background: var(--band-MAS); border-color: var(--band-MAS); }
.rate[aria-pressed="true"]::after { content: " \2713"; font-size: .8rem; }

.pupil-foot {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--uc-line);
  font-size: .84rem;
}

.progress { flex: 1; min-width: 140px; }
.bar { height: 9px; background: #e8edf3; border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--uc-navy); border-radius: 99px; }
.bar.done > i { background: var(--ok); }

/* ---------------------------------------------------------------- badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: .76rem;
  font-weight: 700; padding: 3px 9px; border-radius: 999px;
  border: 1.5px solid currentColor; white-space: nowrap;
}
.badge[data-band="ENT"] { color: var(--band-ENT); }
.badge[data-band="DEV"] { color: var(--band-DEV); }
.badge[data-band="SEC"] { color: var(--band-SEC); }
.badge[data-band="CON"] { color: var(--band-CON); }
.badge[data-band="MAS"] { color: var(--band-MAS); }
.badge.g-Incomplete { color: var(--uc-muted); }
.badge.s-approved { color: var(--ok); }
.badge.s-awaiting { color: var(--warn); }
.badge.s-draft { color: var(--uc-muted); }
.badge.s-none { color: var(--uc-muted); }

/* Outcome + rating row on the pupil detail screen. align-items must be set:
   the default `stretch` makes the pill-shaped badge grow to the height of a
   wrapped outcome sentence, turning it into a large circle. */
.outcome-line {
  display: flex; gap: 10px; justify-content: space-between;
  align-items: flex-start; margin: 6px 0;
}
.outcome-line-text { font-size: .84rem; min-width: 0; }
.outcome-line .badge { flex: 0 0 auto; }

/* ----------------------------------------------------------------- tables */
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--uc-line); vertical-align: top; }
th { font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--uc-muted); }
tbody tr:hover { background: #f7f9fc; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ----------------------------------------------------------------- states */
.state {
  text-align: center; padding: 42px 20px; color: var(--uc-muted);
  border: 1px dashed var(--uc-line); border-radius: var(--radius); background: #fff;
}
.state .ico { font-size: 2rem; display: block; margin-bottom: 8px; }
.state h3 { color: var(--uc-ink); margin-bottom: 4px; }
.state.error { border-color: #e8b4b4; background: #fdf6f6; color: #6c2020; }
.state.denied { border-color: #cfd8e3; background: #f7f9fc; }

.spinner {
  width: 26px; height: 26px; border: 3px solid var(--uc-line);
  border-top-color: var(--uc-navy); border-radius: 50%;
  animation: spin .8s linear infinite; margin: 0 auto 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
  * { transition: none !important; }
}

.toast {
  position: fixed; right: 16px; bottom: 16px; z-index: 60;
  background: var(--uc-ink); color: #fff; padding: 11px 15px; border-radius: 8px;
  box-shadow: var(--shadow); font-size: .88rem; max-width: 340px;
}
.toast.err { background: var(--err); }

/* ---------------------------------------------------------------- reports */
.reporttext {
  font-size: .95rem; line-height: 1.65; background: #fbfcfe;
  border: 1px solid var(--uc-line); border-left: 4px solid var(--uc-navy);
  border-radius: 8px; padding: 13px 15px; white-space: pre-wrap;
}
textarea.reportedit {
  width: 100%; min-height: 160px; font: inherit; font-size: .95rem; line-height: 1.6;
  padding: 12px; border: 1px solid var(--uc-line); border-radius: 8px; resize: vertical;
}
.wordcount { font-size: .78rem; color: var(--uc-muted); }
.wordcount.out { color: var(--warn); font-weight: 600; }

.why {
  font-size: .82rem; background: #f2f6fb; border: 1px solid #d6e2f2;
  border-radius: 8px; padding: 9px 11px; color: #23405f;
}

details.explain { margin-top: 8px; }
details.explain summary { cursor: pointer; font-size: .82rem; color: var(--uc-navy); font-weight: 600; }

/* ---------------------------------------------------------------- dialogs */
dialog {
  border: 0; border-radius: var(--radius); padding: 0; max-width: 620px; width: calc(100% - 32px);
  box-shadow: 0 12px 48px rgba(0, 0, 0, .28);
}
dialog::backdrop { background: rgba(10, 20, 35, .5); }
.dlg-head { padding: 15px 18px; border-bottom: 1px solid var(--uc-line); font-weight: 600; }
.dlg-body { padding: 18px; }
.dlg-foot {
  padding: 13px 18px; border-top: 1px solid var(--uc-line);
  display: flex; gap: 10px; justify-content: flex-end; background: #fafbfd;
}
.dlg-body textarea {
  width: 100%; min-height: 92px; font: inherit; padding: 10px;
  border: 1px solid var(--uc-line); border-radius: 8px;
}
.errmsg { color: var(--err); font-size: .84rem; margin-top: 6px; }

/* ------------------------------------------------------------- bulk mode */
.bulk-outcome {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  padding: 10px 12px; border: 1px solid var(--uc-line); border-radius: 8px;
  background: #fbfcfe; margin-bottom: 12px;
}
.bulk-row {
  display: grid; grid-template-columns: minmax(150px, 1fr) minmax(240px, 340px);
  gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--uc-line);
}
.bulk-row:last-child { border-bottom: 0; }
.bulk-row .nm { font-weight: 600; font-size: .92rem; }
.bulk-row .nm span { display: block; font-weight: 400; font-size: .76rem; color: var(--uc-muted); }

/* -------------------------------------------------------------- settings */
.rule-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.rule-row .field { min-width: 0; }
.mono { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: .82rem; }

/* ------------------------------------------------------------ responsive */
@media (max-width: 980px) {
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .strandrow { grid-template-columns: 1fr; }
}
/* Below about 560px five controls in a row become too small to hit reliably, so
   they wrap to 3 + 2 rather than shrinking further. */
@media (max-width: 560px) {
  .rating-group { grid-template-columns: repeat(3, 1fr); }
  .rate .lbl { font-size: .78rem; }
}

@media (max-width: 640px) {
  main { padding: 14px 10px 60px; }
  .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
  .topbar .title small { display: none; }
  .topbar .title { font-size: .95rem; }
  .topbar img { height: 32px; }
  /* The header wraps on a phone, so its height is no longer predictable. Stop
     pinning it and let the nav own the sticky position instead. */
  .topbar { position: static; }
  .nav { top: 0; }
  .who { padding-left: 10px; }
  .who .role { display: none; }
  .rate { min-height: 66px; font-size: .84rem; }
  .bulk-row { grid-template-columns: 1fr; }
  .who select { max-width: 130px; }
}

@media (prefers-contrast: more) {
  .card, .pupil, .strand { border-width: 2px; }
  .rate { border-width: 3px; }
}

@media print {
  .topbar, .nav, .banner, .btn, .toast { display: none !important; }
  .card { box-shadow: none; border: 1px solid #999; break-inside: avoid; }
}

/* ===========================================================================
   WEB APP ADDITIONS — sign-in gate, connection state, save queue.
   Everything above this line is shared with the offline prototype.
   =========================================================================== */

/* The gate covers the whole viewport until Identity confirms who this is.
   Nothing behind it is rendered, so pupil data cannot flash up before the
   check completes. */
.gate {
  position: fixed; inset: 0; z-index: 200;
  background: var(--uc-bg);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.gate-card {
  background: var(--uc-surface); border: 1px solid var(--uc-line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 28px; max-width: 460px; width: 100%; text-align: center;
}
.gate-card img { height: 56px; width: auto; margin-bottom: 14px; }
.gate-card h1 { font-size: 1.25rem; margin-bottom: 6px; }
.gate-card p { color: var(--uc-muted); font-size: .9rem; margin: 0 0 18px; }
.gate-card .btn { width: 100%; }
.gate-card .errmsg { margin-top: 14px; }

/* Sync indicator. Deliberately quiet when everything is fine and loud when it
   is not: a coach mid-lesson should only look up if something needs them. */
.syncstate { font-size: .78rem; color: var(--uc-muted); white-space: nowrap; }
.syncstate.pending { color: var(--warn); font-weight: 600; }
.syncstate.failed  { color: var(--err); font-weight: 600; }

.offline-banner {
  background: #fff2f2; border-bottom: 1px solid #e6b8b8; color: #7a1f1f;
  padding: 8px 16px; font-size: .84rem;
}

/* A rating that has not yet reached the server. The tick still appears, so the
   coach can keep moving, but the dotted edge shows it is not confirmed. */
.rate[data-pending="true"] { border-style: dashed; }

.rowbusy { opacity: .55; pointer-events: none; }

/* --------------------------------------------------------- password reveal */
/* Typing a password you cannot see, on a phone, at the side of a pitch, is
   where sign-ins go to die. The toggle is a plain button rather than an icon so
   it reads the same to a screen reader and to someone in a hurry. */
.pw-wrap { position: relative; display: flex; }
.pw-wrap input { flex: 1; padding-right: 68px; }
.pw-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  font: inherit; font-size: .78rem; font-weight: 600;
  background: transparent; border: 0; color: var(--uc-navy);
  cursor: pointer; padding: 8px 10px; border-radius: 6px;
  min-height: 36px;              /* still a real tap target */
}
.pw-toggle:hover { background: #eef2f7; }
.pw-toggle[aria-pressed="true"] { color: var(--err); }
