/*
  Page styles: the shell around the stage, the scaffold every page shares, the sign-in pages and
  Settings. Page tasks add their own blocks below these.
*/

/* ---- Shell ---------------------------------------------------------------------------------- */

/* The rail eases between its widths instead of snapping (no motion under reduced motion). */
body {
  transition: grid-template-columns var(--t-med) var(--ease);
}

/* Bare: the sign-in pages and the boot error take the window, without the rail or the operations column. */
body[data-shell="bare"] {
  --ops-w: 0px;
  grid-template-columns: minmax(0, 1fr);
}

body[data-shell="bare"] :is(#rail, #ops) {
  display: none;
}

/* Out of sight until it has keyboard focus, then over the top of the stage. */
.skip-link {
  position: absolute;
  top: var(--s-2);
  left: var(--s-2);
  z-index: 3;
  padding: var(--s-2) var(--s-4);
  border-radius: var(--r-2);
  background-color: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  translate: 0 calc(-100% - var(--s-4));
}

.skip-link:focus {
  translate: 0 0;
}

/* A <button> sizes to its content; rail buttons fill the rail like its links, so hover and focus match. */
.rail-foot button.rail-link {
  width: calc(100% - 2 * var(--s-3));
}

/* The level at the foot of the rail: the number in a ring where the other links have an icon.
   Slightly tighter than a link, so a title such as Probationary ICT Officer fits the open rail. */
.rail-level {
  gap: var(--s-3);
  padding-right: var(--s-2);
}

.rail-level-badge {
  display: grid;
  flex: none;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background-color: color-mix(in srgb, var(--accent) 16%, transparent);
  box-shadow: inset 0 0 0 1.5px var(--accent);
  color: var(--fg-0);
  font-size: var(--fs-0);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  line-height: 1;
}

.rail-level .rail-label {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.rail-level-name,
.rail-level-title {
  overflow: hidden;
  text-overflow: ellipsis;
}

.rail-level-title {
  font-size: var(--fs-0);
  font-weight: 500;
}

/* The operations column: a small heading over the panels Task 15 puts in .ops-slot. */
.ops-title {
  color: var(--fg-2);
  font-size: var(--fs-0);
  font-weight: 600;
  letter-spacing: 0.06em;
  line-height: var(--lh-ui);
  text-transform: uppercase;
}

.ops-slot {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  margin-top: var(--s-3);
}

/* A page that takes a moment to arrive dims the one it replaces, after a beat, so quick moves do not flicker. */
#stage[aria-busy="true"] > * {
  opacity: 0.6;
  transition: opacity var(--t-fast) var(--ease) 150ms;
}

/* The router focuses each new page's heading so a screen reader announces it. It is not a control, so no ring. */
#stage h1[tabindex="-1"]:focus-visible,
#stage[tabindex="-1"]:focus-visible {
  outline: none;
}

/* ---- Page scaffold -------------------------------------------------------------------------- */

.page {
  display: flex;
  flex-direction: column;
  gap: var(--s-6);
  min-width: 0;
}

.page-head {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}

.page-lede {
  max-width: var(--measure);
  color: var(--fg-1);
  font-size: var(--fs-2);
  line-height: var(--lh-read);
}

/* A page still to be built: its empty state sits in a dashed frame. */
.placeholder {
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-3);
}

/* ---- Sign-in and confirm pages ---------------------------------------------------------------- */

.auth {
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
  width: min(100%, 440px);
  margin: max(var(--s-7), 12vh) auto var(--s-7);
}

.auth-lede {
  color: var(--fg-1);
  font-size: var(--fs-2);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding: var(--s-5);
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  background-color: var(--bg-1);
  box-shadow: var(--shadow-1);
}

.auth-form h2 {
  font-size: var(--fs-3);
}

.auth-form p {
  color: var(--fg-1);
}

/* A label sits close to its input. */
.auth-form label {
  margin-bottom: calc(var(--s-1) - var(--s-3));
  color: var(--fg-0);
  font-weight: 600;
}

.auth-form input {
  width: 100%;
}

/* The enrolled address is shown, not edited. */
.auth-form input[readonly] {
  background-color: var(--bg-2);
  color: var(--fg-1);
  cursor: default;
}

.auth .btn {
  align-self: flex-start;
}

/* Scoped to .auth so it outranks .auth-form p. */
.auth .auth-error {
  color: var(--danger);
}

/* An empty message line takes no room; it stays in place as a live region for when it fills. */
.auth-form > p:empty {
  margin-top: calc(-1 * var(--s-3));
}

.auth > p:empty {
  margin-top: calc(-1 * var(--s-5));
}

.boot-error {
  align-items: flex-start;
  max-width: 560px;
  margin: max(var(--s-7), 12vh) auto 0;
}

/* ---- Form kit (/js/components/form.js) ------------------------------------------------------ */

/* A section is a card; a data-tone (the danger zone's) draws its coloured edge. */
.form-section {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  min-width: 0;
  padding: var(--s-5);
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  background-color: var(--bg-1);
  box-shadow: inset 3px 0 0 var(--tone, transparent), var(--shadow-1);
  scroll-margin-top: var(--s-5);
}

.form-section-title {
  font-size: var(--fs-3);
}

.form-intro {
  max-width: var(--measure);
  color: var(--fg-1);
}

.form-fields {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  min-width: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  min-width: 0;
}

.field-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--s-1) var(--s-2);
}

.field-label {
  color: var(--fg-0);
  font-weight: 600;
}

.field input:not([type="checkbox"], [type="radio"]) {
  width: 100%;
  max-width: 28rem;
}

.field input:is([type="time"], [type="date"], [type="number"]) {
  max-width: 12rem;
}

/* 24-hour times, HH:MM. */
.field input.input-time {
  max-width: 7rem;
  font-variant-numeric: tabular-nums;
}

.field-row {
  display: flex;
  gap: var(--s-2);
  max-width: 28rem;
}

.field-row input:not([type="checkbox"], [type="radio"]) {
  flex: 1 1 auto;
  min-width: 0;
}

.field-hint {
  max-width: var(--measure);
  color: var(--fg-2);
  font-size: var(--fs-0);
}

.field-error {
  color: var(--danger);
  font-size: var(--fs-0);
  font-weight: 600;
}

.field-error:empty {
  display: none;
}

.field-check {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
}

/* 16px boxes centred on the first 15px line. */
.field-check input {
  flex: none;
  margin-top: 3px;
}

.field-check-text {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2) var(--s-3);
}

.form-status {
  display: inline-flex;
  align-items: flex-start;
  gap: var(--s-2);
  color: var(--fg-1);
}

.form-notice {
  display: flex;
  align-items: flex-start;
  gap: var(--s-2);
  max-width: var(--measure);
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-2);
  background-color: var(--bg-2);
  color: var(--fg-1);
}

/* Status and notice text stays neutral; the tone is in the icon. */
:is(.form-status, .form-notice) .icon {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  color: var(--tone, var(--fg-2));
}

/* ---- Settings ------------------------------------------------------------------------------- */

.settings {
  max-width: calc(200px + var(--s-7) + 800px);
}

.settings-head {
  gap: var(--s-4);
}

.settings-head-text {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}

.settings-account {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-3) var(--s-4);
  color: var(--fg-1);
}

.settings-layout {
  display: grid;
  grid-template-columns: 200px minmax(0, 800px);
  align-items: start;
  gap: var(--s-7);
}

.settings-toc {
  position: sticky;
  top: var(--s-5);
}

.settings-toc ul {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  margin: 0;
  padding: 0;
  list-style: none;
}

.settings-toc a {
  display: block;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-2);
  color: var(--fg-1);
  font-weight: 500;
  text-decoration: none;
  transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}

.settings-toc a:hover {
  background-color: var(--bg-2);
  color: var(--fg-0);
}

.settings-sections {
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
  min-width: 0;
}

.settings-current {
  color: var(--fg-1);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr));
  gap: var(--s-4);
}

.settings-choice legend {
  margin-bottom: var(--s-2);
}

.settings-options {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2) var(--s-5);
}

.settings-options label {
  color: var(--fg-0);
}

.settings-integration {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding: var(--s-4);
  border: 1px solid var(--line);
  border-radius: var(--r-2);
}

.settings-integration-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2) var(--s-4);
}

.settings-integration-title {
  font-size: var(--fs-2);
}

.settings-integration-state {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2) var(--s-3);
}

.settings-updated {
  color: var(--fg-2);
  font-size: var(--fs-0);
}

/* ---- Today ---------------------------------------------------------------------------------- */

/* Today keeps its learning flow together, with one supporting column when the stage has room. */
.today {
  container-type: inline-size;
}

.today-layout,
.today-main,
.today-side {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  gap: var(--s-5);
  min-width: 0;
}

.today-prep .card-body {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
}

/* Items side by side where the prep has the room, under the card. */
.prep-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(380px, 100%), 1fr));
  gap: var(--s-4) var(--s-5);
  margin: 0;
  padding: 0;
  list-style: none;
}

.prep-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: var(--s-3);
}

.prep-item:focus-visible {
  border-radius: var(--r-1);
  outline-offset: 4px;
}

.prep-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--r-2);
  background-color: var(--bg-2);
  color: var(--fg-1);
}

.prep-icon .icon {
  width: 18px;
  height: 18px;
}

.prep-item[data-state="ready"] .prep-icon {
  color: var(--ok);
}

.prep-item[data-state="attention"] .prep-icon {
  color: var(--warn);
}

.prep-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.prep-text {
  color: var(--fg-0);
}

.prep-meta {
  color: var(--fg-2);
  font-size: var(--fs-0);
}

.prep-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin-top: var(--s-1);
}

.prep-actions:empty {
  display: none;
}

.prep-state {
  padding-top: 5px;
}

.momentum {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
}

.momentum-level {
  display: flex;
  align-items: center;
  gap: var(--s-4);
}

.momentum-level .ring {
  flex: none;
}

.momentum-level-text {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  min-width: 0;
}

.momentum-title {
  display: flex;
  flex-direction: column;
  color: var(--fg-0);
  font-size: var(--fs-2);
  font-weight: 600;
  line-height: var(--lh-tight);
}

.momentum-title span {
  margin-top: 2px;
  color: var(--fg-1);
  font-size: var(--fs-1);
  font-weight: 500;
}

.momentum-xp {
  color: var(--fg-1);
  font-variant-numeric: tabular-nums;
}

.momentum-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s-4);
  margin: 0;
}

.momentum-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.momentum-stat dt {
  color: var(--fg-2);
  font-size: var(--fs-0);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.momentum-stat dd {
  display: flex;
  flex-direction: column;
  margin: 0;
  color: var(--fg-0);
  font-size: var(--fs-2);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  line-height: var(--lh-tight);
}

.momentum-hint {
  margin-top: 2px;
  color: var(--fg-2);
  font-size: var(--fs-0);
  font-weight: 400;
  line-height: var(--lh-ui);
}

/* Room for a statement of three lines, so selecting a cell does not move the card's foot. */
.today-cell {
  min-height: calc(3em * var(--lh-ui));
  margin-top: var(--s-3);
  color: var(--fg-1);
  font-size: var(--fs-0);
}

.today-cell strong {
  color: var(--fg-0);
}

.today-grid-link {
  margin-top: var(--s-2);
  font-size: var(--fs-0);
}

/* ---- Program -------------------------------------------------------------------------------- */

.program {
  container-type: inline-size;
}

.program-map,
.program-grid {
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
  min-width: 0;
}

.program-legend {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}

.program-legend-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2) var(--s-3);
}

.program-legend-title {
  flex: 0 0 9.5rem;
  color: var(--fg-2);
  font-size: var(--fs-0);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.program-legend-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2) var(--s-3);
  margin: 0;
  padding: 0;
  list-style: none;
}

.program-legend-state {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  color: var(--fg-1);
  font-size: var(--fs-0);
}

.program-legend-state .icon {
  width: 16px;
  height: 16px;
  color: var(--ok);
}

/* Phases stack, two abreast from 2500px of stage. */
.program-phases {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--s-5);
}

@container (min-width: 2500px) {
  .program-phases {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.phase-band {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  min-width: 0;
  padding: var(--s-5);
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  background-color: var(--bg-1);
  box-shadow: var(--shadow-1);
}

.phase-band:only-child {
  grid-column: 1 / -1;
}

.phase-band[data-published="false"] {
  border-style: dashed;
  background-color: transparent;
  box-shadow: none;
}

.phase-band-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: var(--s-2) var(--s-4);
}

.phase-band-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--s-1) var(--s-3);
  font-size: var(--fs-3);
}

.phase-band-n,
.week-n {
  color: var(--fg-2);
  font-size: var(--fs-0);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.phase-band-count {
  color: var(--fg-1);
  font-size: var(--fs-0);
  font-variant-numeric: tabular-nums;
}

.phase-band-meter {
  grid-column: 1 / -1;
  height: 4px;
  border-radius: 2px;
  background-image: linear-gradient(to right, var(--accent) calc(var(--share, 0) * 100%), var(--bg-3) 0);
}

/* The weeks share their title row (subgrid), so a two-line title does not push its days out of line. */
.phase-weeks {
  display: grid;
  grid-template-columns: repeat(var(--week-columns, 4), minmax(0, 1fr));
  grid-template-rows: auto auto;
  gap: var(--s-2) var(--s-4);
  margin: 0;
  padding: 0;
  list-style: none;
}

/* minmax(0, 1fr): an auto column would grow to the day titles' full, unwrapped width. */
.week {
  display: grid;
  grid-row: span 2;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: subgrid;
  align-content: start;
  min-width: 0;
}

.week-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: var(--fs-1);
}

.week-name {
  color: var(--fg-0);
}

.day-chips {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

/* A day: its number, its state and its two work orders, the primary domain as the left edge. */
.day-chip {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--s-2) var(--s-3) var(--s-2) var(--s-4);
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  background-color: var(--bg-2);
  box-shadow: inset 3px 0 0 var(--tone, transparent);
  color: var(--fg-1);
  font-size: var(--fs-0);
  line-height: 1.35;
  text-decoration: none;
  transition: border-color var(--t-fast) var(--ease);
}

a.day-chip:hover {
  border-color: var(--line-strong);
}

.day-chip[aria-current="step"] {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--tone, transparent), 0 0 0 1px var(--accent);
}

.day-chip[data-state="unpublished"] {
  border-style: dashed;
  background-color: transparent;
}

.day-chip-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  min-height: 20px;
}

.day-chip-day {
  color: var(--fg-0);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.day-chip[data-state="unpublished"] .day-chip-day {
  color: var(--fg-2);
  font-weight: 500;
}

.day-chip-state {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  color: var(--fg-0);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.day-chip-state .icon {
  width: 16px;
  height: 16px;
  color: var(--ok);
}

.day-chip-flag {
  padding: 0 var(--s-1);
  border-radius: var(--r-1);
  background-color: color-mix(in srgb, var(--info) 16%, transparent);
  color: var(--fg-0);
  font-size: var(--fs-0);
  font-weight: 600;
  white-space: nowrap;
}

.day-chip-flag[data-flag="next"] {
  background-color: color-mix(in srgb, var(--accent) 18%, transparent);
}

.day-chip-order {
  display: flex;
  align-items: baseline;
  gap: var(--s-2);
  min-width: 0;
}

/* Each work order's letter, underlined in its own domain's colour. */
.day-chip-letter {
  flex: none;
  min-width: 1.1em;
  color: var(--fg-1);
  font-weight: 600;
  text-align: center;
  box-shadow: inset 0 -2px 0 var(--tone, transparent);
}

.day-chip-letter:not([data-domain]) {
  --tone: var(--line-strong);
}

.day-chip-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.program-intro {
  max-width: var(--measure);
  color: var(--fg-1);
}

.cell-detail {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  max-width: calc(var(--measure) + 24ch);
  padding: var(--s-5);
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  background-color: var(--bg-1);
}

.cell-detail-title {
  font-size: var(--fs-3);
}

.cell-detail-pct {
  color: var(--fg-1);
  font-variant-numeric: tabular-nums;
}

.cell-detail-statement {
  max-width: var(--measure);
  color: var(--fg-0);
  font-size: var(--fs-2);
  line-height: var(--lh-read);
}

.cell-detail-prompt {
  color: var(--fg-2);
}

.cell-sessions,
.milestones {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.cell-sessions {
  margin-top: var(--s-2);
}

.cell-session,
.milestone {
  display: grid;
  grid-template-columns: 11rem minmax(0, 1fr) auto;
  align-items: baseline;
  gap: var(--s-3);
}

.cell-session-title,
.milestone-title {
  min-width: 0;
  color: var(--fg-1);
}

.projects {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(560px, 100%), 1fr));
  align-items: start;
  gap: var(--s-5);
}

.project-group {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  min-width: 0;
  padding: var(--s-5);
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  background-color: var(--bg-1);
  box-shadow: inset 3px 0 0 var(--tone, transparent), var(--shadow-1);
}

.project-head {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
}

.project-title {
  font-size: var(--fs-2);
}

.project-count {
  color: var(--fg-1);
  font-size: var(--fs-0);
}
