/* The provisioning console.
 *
 * WHY THIS FILE NAMES NO COLOUR. Every value here is an `--app-*` token from
 * tokens.css, which is the College's own derived theme: four base colours in, a
 * whole accessible palette out, every value's contrast computed. The console is
 * the first thing a citizen coder sees, and it should look like the product it
 * provisions rather than a form that happens to share an address.
 *
 * It previously carried about twenty hand-written hexes. "Colour and contrast
 * are derived, never chosen" is the rule this platform states most loudly, and
 * this file escaped it only because `color-guard` scans `apps/`, not
 * `services/`.
 *
 * ONE STEP AT A TIME. The page is a wizard: a compact stepper (numbers, short
 * labels, a tick on a finished step) and one step panel below it. Help lives
 * behind `?` tips, never in sub-text, and no surface carries a coloured bar on
 * one edge: states are tinted pills with an even border.
 */

* {
  box-sizing: border-box;
}

/* `hidden` always wins. Without this a class that sets `display` (the stepper's
   grid, a flex row) silently shows an element the script hid, which is how the
   stepper appeared before sign-in. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--app-color-surface-page);
  color: var(--app-color-text-primary);
  font-family: var(--app-font-body);
  font-size: var(--app-font-size-body-control);
  line-height: 1.55;
}

main {
  max-width: 40rem;
  margin: 0 auto;
  padding: var(--app-space-lg) var(--app-space-md) 5rem;
}

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

/* --------------------------------------------------------------- masthead */

.masthead {
  margin-bottom: var(--app-space-md);
}

/* The one place the platform names itself. Letter-spaced caps rather than a
   logo file: the gateway serves no images. */
.masthead__eyebrow {
  font-size: var(--app-font-size-overline);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--app-color-text-secondary);
  margin: 0 0 var(--app-space-xs);
}

.masthead__row,
.label-row {
  display: flex;
  align-items: center;
  gap: var(--app-space-sm);
  position: relative;
}

h1 {
  font-family: var(--app-font-heading);
  font-size: var(--app-font-size-heading-sm);
  font-weight: 600;
  color: var(--app-color-heading);
  line-height: 1.2;
  margin: 0;
}

.identity {
  font-size: var(--app-font-size-caption);
  color: var(--app-color-text-secondary);
  margin: var(--app-space-xs) 0 0;
}

/* ---------------------------------------------------------------- help tip */

/* A `?` that opens its explanation in place. A native <details>, so it is
   keyboard reachable and needs no script under the page's CSP. */
.help {
  position: static;
}

.help > summary {
  list-style: none;
  cursor: pointer;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: var(--app-radius-full);
  border: 1px solid var(--app-color-border);
  color: var(--app-color-text-secondary);
  font-size: var(--app-font-size-caption);
  font-weight: 600;
  display: grid;
  place-items: center;
}

.help > summary::-webkit-details-marker {
  display: none;
}

.help > summary:hover {
  border-color: var(--app-color-primary);
  color: var(--app-color-primary);
}

.help > summary:focus-visible {
  outline: 2px solid var(--app-color-focus-ring);
  outline-offset: 2px;
}

.help[open] > summary {
  border-color: var(--app-color-primary);
  color: var(--app-color-primary);
}

.help > p {
  position: absolute;
  z-index: 2;
  left: 0;
  right: 0;
  top: calc(100% + var(--app-space-xs));
  margin: 0;
  padding: var(--app-space-sm) var(--app-space-md);
  font-size: var(--app-font-size-body-sm);
  color: var(--app-color-text-primary);
  background: var(--app-color-surface-elevated);
  border: 1px solid var(--app-color-border);
  border-radius: var(--app-radius-sm);
  box-shadow: 0 6px 20px var(--app-color-hover-overlay);
}

/* ---------------------------------------------------------------- stepper */

.stepper {
  list-style: none;
  margin: 0 0 var(--app-space-md);
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--app-space-xs);
}

.stepper__btn {
  width: 100%;
  margin: 0;
  display: flex;
  align-items: center;
  gap: var(--app-space-sm);
  padding: var(--app-space-xs) var(--app-space-sm);
  font-weight: 500;
  color: var(--app-color-text-secondary);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--app-radius-sm);
  text-align: left;
}

.stepper__btn:hover:not(:disabled) {
  background: var(--app-color-neutral-on-surface-bg);
  border-color: transparent;
}

.stepper__btn:disabled {
  opacity: 0.5;
}

.stepper__marker {
  flex: none;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: var(--app-radius-full);
  display: grid;
  place-items: center;
  font-size: var(--app-font-size-caption);
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--app-color-border);
  background: var(--app-color-surface-page);
  color: var(--app-color-text-muted);
}

.stepper__label {
  font-size: var(--app-font-size-body-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stepper__step[data-state="current"] .stepper__btn {
  color: var(--app-color-text-primary);
  font-weight: 600;
  background: var(--app-color-primary-on-surface-bg);
  border-color: var(--app-color-primary-on-surface-border);
}

.stepper__step[data-state="current"] .stepper__marker {
  border-color: var(--app-color-primary);
  background: var(--app-color-primary);
  color: var(--app-color-primary-contrast);
}

.stepper__step[data-state="done"] .stepper__marker {
  background: var(--app-color-success);
  border-color: var(--app-color-success);
  color: var(--app-color-success-contrast);
}

/* ------------------------------------------------------------------ steps */

.card {
  background: var(--app-color-surface-card);
  border: 1px solid var(--app-color-border-subtle);
  border-radius: var(--app-radius-md);
  padding: var(--app-space-md);
}

.step h2 {
  font-family: var(--app-font-heading);
  font-size: var(--app-font-size-subheading);
  font-weight: 600;
  color: var(--app-color-heading);
  margin: 0;
}

/* Focus lands on the heading when the step changes, so a screen reader reads
   where it now is. A heading is not a control, so it draws no ring. */
.step h2:focus,
.step h2:focus-visible {
  outline: none;
}

.step__meta {
  margin: var(--app-space-sm) 0 0;
}

.step__nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--app-space-sm);
  margin-top: var(--app-space-md);
}

.step__nav button {
  margin: 0;
}

.step__links {
  margin: var(--app-space-md) 0 0;
}

/* A part of the summary, divided from what is above it by a neutral rule rather
   than drawn as a card inside a card. */
.subpanel {
  border-top: 1px solid var(--app-color-border-subtle);
  margin-top: var(--app-space-md);
  padding-top: var(--app-space-xs);
}

/* --------------------------------------------------------------- controls */

label {
  display: block;
  font-size: var(--app-font-size-label);
  font-weight: 600;
  margin: var(--app-space-md) 0 var(--app-space-xs);
}

.label-row label {
  margin-bottom: var(--app-space-xs);
}

input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 0.6rem 0.7rem;
  font: inherit;
  color: var(--app-color-field-text);
  background: var(--app-color-field-bg);
  border: 1px solid var(--app-color-field-border);
  border-radius: var(--app-radius-sm);
}

input::placeholder {
  color: var(--app-color-field-placeholder);
}

input:hover:not(:disabled) {
  background: var(--app-color-field-bg-hover);
}

input:disabled {
  background: var(--app-color-field-bg-disabled);
}

/* A visible focus ring is not decoration here. The audience is often on a
   school iPad with a keyboard, and this page holds a credential paste. */
input:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--app-color-focus-ring);
  outline-offset: 2px;
}

button {
  font: inherit;
  font-weight: 600;
  margin-top: var(--app-space-md);
  padding: 0.55rem 1.1rem;
  color: var(--app-color-primary-contrast);
  background: var(--app-color-primary);
  border: 1px solid var(--app-color-primary);
  border-radius: var(--app-radius-sm);
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: var(--app-color-primary-shade);
  border-color: var(--app-color-primary-shade);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button.secondary {
  color: var(--app-color-text-primary);
  background: var(--app-color-surface-page);
  border-color: var(--app-color-border);
}

button.secondary:hover:not(:disabled) {
  background: var(--app-color-neutral-on-surface-bg);
  border-color: var(--app-color-border);
}

button.link {
  margin: 0;
  padding: 0;
  font-weight: 600;
  color: var(--app-color-primary);
  background: none;
  border: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}

button.link:hover:not(:disabled) {
  background: none;
  color: var(--app-color-primary-shade);
}

a {
  color: var(--app-color-primary);
  text-underline-offset: 2px;
  overflow-wrap: anywhere;
}

.field-hint {
  margin: 0 0 var(--app-space-xs);
  font-size: var(--app-font-size-body-control);
  color: var(--app-color-text-secondary);
}

/* ---------------------------------------------------------- app selection */

.app-list {
  list-style: none;
  margin: var(--app-space-sm) 0 0;
  padding: 0;
  display: grid;
  gap: var(--app-space-xs);
}

/* A list of things to pick, not the page's actions: quiet rows, and the picked
   one tinted with an even border. */
.app-list button {
  margin: 0;
  width: 100%;
  text-align: left;
  font-weight: 500;
  color: var(--app-color-text-primary);
  background: var(--app-color-surface-page);
  border-color: var(--app-color-border);
}

.app-list button:hover:not(:disabled) {
  background: var(--app-color-surface-elevated);
  border-color: var(--app-color-primary);
}

.app-list button[aria-pressed="true"] {
  background: var(--app-color-primary-on-surface-bg);
  border-color: var(--app-color-primary);
  color: var(--app-color-primary-on-surface-text);
}

.app-list__new {
  font-weight: 600;
}

/* An app and its Manage action on one row: the name takes the width, Manage its
   own. */
.app-list__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--app-space-xs);
}

.app-list .app-list__manage {
  width: auto;
  text-align: center;
}

/* ------------------------------------------------------------ the question */

/* A Yes/No question with its ? tip on the answers' row. A fieldset for the
   grouping a screen reader announces, with none of its default frame. */
.question {
  border: 0;
  margin: var(--app-space-md) 0 0;
  padding: 0;
  min-width: 0;
}

.question legend {
  padding: 0;
  font-size: var(--app-font-size-label);
  font-weight: 600;
  color: var(--app-color-text-primary);
}

.question__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--app-space-md);
  margin-top: var(--app-space-xs);
  position: relative;
}

label.choice {
  display: inline-flex;
  align-items: center;
  gap: var(--app-space-xs);
  margin: 0;
  font-weight: 500;
  min-height: 2.75rem; /* a touch target, not just the radio dot */
}

label.choice input {
  width: 1.1rem;
  height: 1.1rem;
  margin: 0;
  accent-color: var(--app-color-primary);
}

/* ------------------------------------------------------------- manage view */

.subpanel h3 {
  font-size: var(--app-font-size-label);
  font-weight: 600;
  color: var(--app-color-heading);
  margin: var(--app-space-sm) 0 0;
}

/* Breaks at the slash (a <wbr> after it), and inside a name only if one part is
   wider than the row on its own. */
#summary-repo {
  overflow-wrap: break-word;
}

/* An Azure address is one long word with no slash to break at. */
#summary-address {
  overflow-wrap: anywhere;
}

.owners-list {
  list-style: none;
  margin: var(--app-space-sm) 0 0;
  padding: 0;
  display: grid;
  gap: var(--app-space-xs);
}

.owners-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--app-space-sm);
  overflow-wrap: anywhere;
}

.subpanel .label-row button.link {
  margin-top: var(--app-space-sm);
}

/* ------------------------------------------------------------ the summary */

/* Short label and value pairs: the repository, Cloudflare and the database as
   one word each. Two columns so the values line up; the labels are short enough
   that it never needs to stack at phone width. */
.facts {
  display: grid;
  gap: var(--app-space-sm);
  margin: var(--app-space-md) 0 0;
}

.facts__row {
  display: grid;
  grid-template-columns: 6.5rem minmax(0, 1fr);
  gap: var(--app-space-sm);
  align-items: center;
}

.facts__row[hidden] {
  display: none;
}

.facts dt {
  font-size: var(--app-font-size-label);
  color: var(--app-color-text-secondary);
}

.facts dd {
  margin: 0;
  font-size: var(--app-font-size-body-sm);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--app-space-sm);
  min-width: 0;
}

/* A state, not an action: a tinted pill with an even border, toned by what the
   state means (good, in motion, needs attention, neutral). */
.pill {
  display: inline-block;
  padding: 0.1rem 0.6rem;
  border-radius: var(--app-radius-full);
  border: 1px solid var(--app-color-neutral-on-surface-border);
  background: var(--app-color-neutral-on-surface-bg);
  color: var(--app-color-neutral-on-surface-text);
  font-size: var(--app-font-size-caption);
  font-weight: 600;
}

.pill:empty {
  display: none;
}

.pill[data-tone="success"] {
  border-color: var(--app-color-success-on-surface-border);
  background: var(--app-color-success-on-surface-bg);
  color: var(--app-color-success-on-surface-text);
}

.pill[data-tone="primary"] {
  border-color: var(--app-color-primary-on-surface-border);
  background: var(--app-color-primary-on-surface-bg);
  color: var(--app-color-primary-on-surface-text);
}

.pill[data-tone="warning"] {
  border-color: var(--app-color-warning-on-surface-border);
  background: var(--app-color-warning-on-surface-bg);
  color: var(--app-color-warning-on-surface-text);
}

.pill[data-tone="danger"] {
  border-color: var(--app-color-danger-on-surface-border);
  background: var(--app-color-danger-on-surface-bg);
  color: var(--app-color-danger-on-surface-text);
}

/* The route's own refusal, shown beside the action it refused. */
.field-error {
  font-size: var(--app-font-size-body-sm);
  color: var(--app-color-text-error);
  margin: var(--app-space-sm) 0 0;
}

/* -------------------------------------------------------------- messaging */

#status {
  font-size: var(--app-font-size-body-sm);
  color: var(--app-color-text-secondary);
  margin: 0 0 var(--app-space-sm);
}

#status:empty {
  display: none;
}

/* Semantic tones, even borders. `.error` / `.success` / `.info` match what
   console.js writes (`className = "notice " + kind`). */
.notice {
  padding: var(--app-space-sm) var(--app-space-md);
  border-radius: var(--app-radius-sm);
  border: 1px solid var(--app-color-border);
  background: var(--app-color-surface-card);
  font-size: var(--app-font-size-body-sm);
  margin-bottom: var(--app-space-md);
  white-space: pre-line;
}

.notice.error {
  border-color: var(--app-color-danger-on-surface-border);
  background: var(--app-color-danger-on-surface-bg);
  color: var(--app-color-text-error);
}

.notice.success {
  border-color: var(--app-color-success-on-surface-border);
  background: var(--app-color-success-on-surface-bg);
  color: var(--app-color-text-primary);
}

.notice.info {
  border-color: var(--app-color-primary-on-surface-border);
  background: var(--app-color-primary-on-surface-bg);
  color: var(--app-color-text-primary);
}

/* ----------------------------------------------------------------- motion */

@media (prefers-reduced-motion: no-preference) {
  .stepper__btn,
  .stepper__marker,
  button,
  input {
    transition:
      background-color 120ms ease,
      border-color 120ms ease,
      box-shadow 120ms ease;
  }
}

/* -------------------------------------------------------------- the phone */

/* The phone is the outer edge: the step loses its card chrome so nothing is a
   card inside a card, and the stepper keeps its numbers with shorter gaps. */
@media (max-width: 30rem) {
  main {
    padding: var(--app-space-md) var(--app-space-md) 4rem;
  }

  .step.card {
    background: transparent;
    border: 0;
    border-radius: 0;
    padding: 0;
  }

  .stepper__btn {
    padding: var(--app-space-xs);
    gap: var(--app-space-xs);
  }

  .step__nav button {
    flex: 1 1 auto;
  }
}
