/*
 * Sign-in surface: login, signup, forgot-password, reset-password.
 *
 * Loaded after app.css and foundation.css by templates/_auth_layout.html and by
 * nothing else. It points app.css's tokens at foundation.css, the palette the
 * dashboard and the operator console share, in its light theme: the landing
 * page is light and so is the dashboard, so clicking "Sign in" there, and then
 * signing in, never lands anywhere that looks like a different product. The
 * buttons, fields and language switch are app.css's own components; this
 * sheet sizes and colours them.
 *
 * Laid out like the landing page's hero: the form left under the logo, and
 * right a violet panel in the style of the landing's closing call to action,
 * carrying its three setup steps. Behind both, a faint violet wash so the page
 * is not a blank sheet. The form itself stays still. The only motion is the
 * steps arriving once, in order, on load, and nothing moves at all under
 * reduced motion.
 *
 * Corner radii follow foundation.css: controls (buttons, fields, alerts) 8px,
 * containers (the panel and its icon tiles) 12px, the language switch fully
 * round.
 *
 * Light always (the layout stamps data-theme="light"), even for someone whose
 * system is set to dark: the landing page and the dashboard on either side
 * are light, and a dark sign-in page between them would be the one room in
 * the house with the lights off.
 */

:root {
  /* app.css's components (buttons, fields, the language switch) read these
     names. They are pointed at foundation.css rather than given values of
     their own, so this page cannot drift from the dashboard's palette. */
  --canvas: var(--bg);
  --muted: var(--surface-2);
  --success: var(--good);
  --success-soft: var(--good-soft);
  --danger: var(--bad);
  --danger-soft: var(--bad-soft);
  /* Controls are --radius-sm everywhere in the product (foundation.css). */
  --radius: var(--radius-sm);

  /* --- auth-only ----------------------------------------------------------- */
  /* foundation.css's container radius, which --radius above no longer is. */
  --radius-box: 12px;
  /* A field's edge at 3.3:1 on white and 3:1 on the page: the hairline the
     rest of the product uses is 1.5:1, too faint to find an empty field by. */
  --field-line: #8b8c9e;
  --field-hover: var(--ink-faint);
  --wrap: 1200px;
  --header-h: 64px;
}

/* The page ground with two faint violet washes, top left behind the form and
   low on the left: enough that the page is not blank white, never enough to
   pull the eye off the form. The accent at 6-7%, no second hue. Fixed, so
   the wash stays put while a tall form scrolls. */
body.auth-page {
  background:
    radial-gradient(70% 60% at 0% 0%, color-mix(in srgb, var(--accent) 7%, transparent), transparent 70%),
    radial-gradient(60% 55% at 15% 100%, color-mix(in srgb, var(--accent) 5%, transparent), transparent 70%),
    var(--canvas);
  background-attachment: fixed;
  color: var(--ink);
}

.auth-page ::selection {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}

/* --- Frame ------------------------------------------------------------------ */

.auth-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* The landing page's navigation bar, minus its section links: the same
   width, height and side padding, so the logo does not jump on arrival. */
.auth-header {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  max-width: var(--wrap);
  height: var(--header-h);
  margin: 0 auto;
  padding: 0 32px;
}

.auth-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
  border-radius: 8px;
}

/* The hint that the logo leads back to the landing page: a thin grey house
   beside the wordmark, part of the same link rather than a button of its own. */
.auth-home {
  display: inline-flex;
  margin-left: 4px;
  padding-left: 12px;
  border-left: 1px solid var(--border-strong);
  color: var(--ink-faint);
  font-size: 20px;
  transition: color 0.2s ease, transform 0.2s ease;
}

.auth-home svg {
  stroke-width: 1.7;
}

.auth-brand:hover .auth-home {
  color: var(--ink);
}

@media (prefers-reduced-motion: no-preference) {
  .auth-brand:hover .auth-home {
    transform: translateX(-2px);
  }
}

.auth-main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  align-items: center;
  gap: 64px;
  width: 100%;
  max-width: var(--wrap);
  margin: 0 auto;
  padding: 24px 32px 48px;
}

.auth-column {
  width: 100%;
  max-width: 400px;
  /* A little above the optical centre of its cell: a form centred exactly
     reads as sitting low, because the eye weighs the heading, not the box. */
  margin-bottom: 32px;
}

/* --- Heading ---------------------------------------------------------------- */

.auth-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 2.25rem;
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: -0.032em;
  text-wrap: balance;
}

.auth-lede {
  margin: 12px 0 0;
  max-width: 42ch;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--ink-soft);
  text-wrap: pretty;
}

/* Everything after the heading block starts one step further down. */
.auth-title + .auth-lede + *,
.auth-title + :not(.auth-lede) {
  margin-top: 32px;
}

/* --- Alerts ----------------------------------------------------------------- */

.auth-alert {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 24px;
  padding: 12px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--ink);
}

.auth-alert p {
  margin: 0;
}

.auth-alert svg {
  flex: none;
  width: 18px;
  height: 18px;
  /* Centres the icon on the first line of text (21px line box). */
  margin-top: 1.5px;
}

.auth-alert p {
  flex: 1;
}

.auth-alert-close {
  flex: none;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  margin: -1.5px -4px 0 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius-tag);
  background: transparent;
  color: var(--ink-faint);
  cursor: pointer;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}

.auth-alert-close[hidden] {
  display: none;
}

.auth-alert .auth-alert-close svg {
  width: 16px;
  height: 16px;
  margin: 0;
  color: inherit;
}

.auth-alert-close:hover {
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  color: var(--ink);
}

.auth-alert-close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* The text stays ink for reading; the tint, the edge and the icon carry the
   kind of message. */
.auth-alert.is-error {
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 26%, transparent);
}

.auth-alert.is-error svg {
  color: var(--danger);
}

.auth-alert.is-ok {
  background: var(--success-soft);
  border-color: color-mix(in srgb, var(--success) 26%, transparent);
}

.auth-alert.is-ok svg {
  color: var(--success);
}

/* --- Buttons ---------------------------------------------------------------- */

.auth-column .btn {
  width: 100%;
  height: 46px;
  padding: 0 18px;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 600;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease),
    transform 0.1s var(--ease);
}

.auth-column .btn:hover {
  background: var(--accent-hover);
}

.auth-column .btn:active {
  transform: translateY(1px);
}

.auth-column .btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* The Google button: the landing page's quieter button, a white face and a
   visible edge, so it reads as the second way in rather than the first. */
.auth-column .btn-secondary {
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.auth-column .btn-secondary:hover {
  background: var(--surface-2);
  border-color: var(--field-line);
}

/*
 * Google's mark keeps its own four colours (their branding terms require it),
 * and `flex: none` stops it squashing when the label is long, which is every
 * language but English.
 */
.auth-column .google-mark {
  width: 18px;
  height: 18px;
  flex: none;
}

/* While the form is on its way: still readable, visibly not clickable. */
.auth-column .btn[aria-disabled="true"] {
  background: var(--accent-hover);
  color: rgba(255, 255, 255, 0.86);
  cursor: progress;
  transform: none;
}

/* --- Divider ---------------------------------------------------------------- */

.auth-divider {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 24px 0;
  font-size: 0.8125rem;
  color: var(--ink-faint);
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border-strong);
}

/* --- Fields ----------------------------------------------------------------- */

.auth-column .form {
  max-width: none;
  gap: 20px;
}

.auth-column .field {
  gap: 8px;
}

.auth-column .form .btn {
  margin-top: 4px;
}

.field-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.auth-column label {
  font-size: 0.875rem;
  font-weight: 550;
  color: var(--ink);
}

.auth-column input[type="email"],
.auth-column input[type="password"],
.auth-column input[type="text"] {
  height: 46px;
  padding: 0 14px;
  border-radius: var(--radius);
  background: var(--field);
  border: 1px solid var(--field-line);
  color: var(--ink);
  font-size: 0.9375rem;
  caret-color: var(--accent);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.auth-column input:hover {
  border-color: var(--field-hover);
}

/*
 * The ring replaces app.css's outline. `outline` stays as a transparent shape
 * rather than being removed, so Windows high-contrast mode, which ignores
 * box-shadow, still marks the focused field.
 */
.auth-column input:focus {
  outline: 2px solid transparent;
  outline-offset: 2px;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}

/*
 * Chrome paints autofilled fields pale blue, which clashes with the violet
 * ring. An inset shadow is the only way to repaint it; the long transition
 * keeps Chrome's own colour from flashing back on blur.
 */
.auth-column input:-webkit-autofill,
.auth-column input:-webkit-autofill:hover,
.auth-column input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--ink);
  -webkit-box-shadow: 0 0 0 1000px var(--accent-soft) inset;
  box-shadow: 0 0 0 1000px var(--accent-soft) inset;
  caret-color: var(--ink);
  transition: background-color 100000s ease-in-out 0s;
}

/* --- Password field --------------------------------------------------------- */

.password-input {
  position: relative;
}

/* Room for the toggle, so a long password never runs under it. */
.password-input input {
  padding-right: 48px;
}

.password-toggle {
  position: absolute;
  top: 5px;
  right: 5px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-faint);
  font-size: 18px;
  cursor: pointer;
  transition: color 0.15s var(--ease), background-color 0.15s var(--ease);
}

.password-toggle[hidden] {
  display: none;
}

.password-toggle:hover {
  color: var(--ink);
  background: var(--muted);
}

.password-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}

/* One icon at a time: the open eye while the password is hidden, the struck
   eye while it is shown, matching what a click will do next. */
.password-toggle > span {
  display: contents;
}

.password-toggle .when-shown,
.password-toggle[aria-pressed="true"] .when-hidden {
  display: none;
}

.password-toggle[aria-pressed="true"] .when-shown {
  display: contents;
}

/*
 * The rule, as a checklist. Every rule starts as a faint cross: a requirement
 * not yet met, not an achievement. Once met, the cross becomes a green tick and
 * the text darkens. If someone submits with a rule still unmet the page marks
 * the ones that are (`.was-tried` on the list, set by auth.js) by turning their
 * crosses red. The state is carried by the icon's shape and the text colour,
 * not colour alone.
 */
.password-rules {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin: 2px 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--ink-faint);
}

.password-rules li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: color 0.15s var(--ease);
}

.rule-mark {
  display: inline-flex;
  flex: none;
}

.password-rules svg {
  flex: none;
  width: 14px;
  height: 14px;
  opacity: 0.45;
  transition: color 0.15s var(--ease), opacity 0.15s var(--ease);
}

/* Unmet shows the cross, met shows the tick. */
.password-rules .rule-mark svg:nth-child(2),
.password-rules li.is-met .rule-mark svg:nth-child(1) {
  display: none;
}

.password-rules li.is-met .rule-mark svg:nth-child(2) {
  display: block;
}

.password-rules li.is-met {
  color: var(--ink);
}

.password-rules li.is-met svg {
  color: var(--success);
  opacity: 1;
}

.password-rules.was-tried li:not(.is-met) {
  color: var(--danger);
}

.password-rules.was-tried li:not(.is-met) svg {
  color: var(--danger);
  opacity: 1;
}

/* --- Links ------------------------------------------------------------------ */

.field-link,
.auth-foot a {
  color: var(--accent-ink);
  font-weight: 550;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 3px;
  transition: text-decoration-color 0.15s var(--ease);
}

.field-link:hover,
.auth-foot a:hover {
  text-decoration-color: currentColor;
}

.field-link {
  font-size: 0.8125rem;
  white-space: nowrap;
}

.auth-brand:focus-visible,
.field-link:focus-visible,
.auth-foot a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

/* The page's other way through, below a rule so it is not read as part of
   the form it follows. */
.auth-foot {
  margin: 32px 0 0;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
  color: var(--ink-soft);
}

.auth-back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.auth-back svg {
  width: 16px;
  height: 16px;
  transition: transform 0.15s var(--ease);
}

.auth-back:hover svg {
  transform: translateX(-2px);
}

/* --- Setup panel ------------------------------------------------------------ */

/*
 * The landing page's closing panel (landing.css .lp-final): solid violet,
 * white type. It carries the landing's "how it works" steps, the same three
 * in the same words, so the page says what the account is for without a mock
 * of the product. The rule between the icons carries the order, as it does on
 * the landing page, so there are no step numbers.
 *
 * White on --accent is 7.7:1; the step text at 86% white stays above 6:1.
 */
.auth-art {
  align-self: stretch;
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 560px;
  padding: 56px;
  border-radius: var(--radius-box);
  /*
   * The brand violet, lit from the top corner, falling away into deep indigo
   * toward the bottom, with a haze where the grid floor below meets its
   * horizon. One hue family throughout: the depth comes from darkening the
   * accent, not from adding a second colour. The title and the first step sit
   * on the lit violet (still above 7:1 for white); the lower steps sit on the
   * darker indigo, where contrast only rises.
   */
  background:
    radial-gradient(80% 24% at 50% 86%, rgba(167, 139, 250, 0.28), transparent 70%),
    radial-gradient(85% 55% at 100% 0%, rgba(255, 255, 255, 0.15), transparent 62%),
    linear-gradient(
      168deg,
      var(--accent) 0%,
      color-mix(in srgb, var(--accent) 70%, #0c0624) 48%,
      color-mix(in srgb, var(--accent) 34%, #06031a) 100%
    );
  color: #fff;
}

/*
 * A perspective grid floor receding toward the horizon haze: a flat line grid
 * tipped back in 3D and faded out before it reaches the text above. Wider
 * than the panel so the tilted edges never show.
 */
.auth-art::before {
  content: "";
  position: absolute;
  left: -60%;
  right: -60%;
  bottom: 0;
  height: 46%;
  z-index: -1;
  background-image:
    linear-gradient(rgba(221, 214, 254, 0.3) 1px, transparent 1px),
    linear-gradient(90deg, rgba(221, 214, 254, 0.3) 1px, transparent 1px);
  background-size: 44px 44px;
  background-position: 50% 0;
  transform: perspective(520px) rotateX(58deg);
  transform-origin: 50% 100%;
  -webkit-mask-image: linear-gradient(to top, #000 0%, rgba(0, 0, 0, 0.6) 40%, transparent 80%);
  mask-image: linear-gradient(to top, #000 0%, rgba(0, 0, 0, 0.6) 40%, transparent 80%);
  pointer-events: none;
}

/* A faint dot matrix in the lit corner, fading out toward the text. */
.auth-art::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background-image: radial-gradient(rgba(255, 255, 255, 0.4) 1px, transparent 1.6px);
  background-size: 20px 20px;
  -webkit-mask-image: radial-gradient(55% 45% at 100% 0%, #000, transparent 75%);
  mask-image: radial-gradient(55% 45% at 100% 0%, #000, transparent 75%);
  opacity: 0.55;
  pointer-events: none;
}

.auth-art-title {
  margin: 0;
  max-width: 16ch;
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 2.4vw, 2.125rem);
  font-weight: 650;
  line-height: 1.12;
  letter-spacing: -0.03em;
}

.auth-steps {
  margin: 40px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 28px;
}

.auth-step {
  position: relative;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  column-gap: 18px;
}

/* The rule from one icon down to the next. */
.auth-step:not(:last-child)::after {
  content: "";
  position: absolute;
  top: 52px;
  bottom: -20px;
  left: 21.5px;
  width: 1px;
  background: rgba(255, 255, 255, 0.3);
}

.auth-step-ico {
  grid-row: span 2;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-box);
  background: rgba(255, 255, 255, 0.14);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.auth-step-ico svg {
  width: 20px;
  height: 20px;
}

.auth-step h3 {
  margin: 0;
  padding-top: 2px;
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 650;
  letter-spacing: -0.012em;
}

.auth-step p {
  margin: 4px 0 0;
  max-width: 44ch;
  font-size: 0.9375rem;
  line-height: 1.55;
  color: rgba(255, 255, 255, 0.86);
}

/*
 * The steps arrive once, in their order, on load: the order is the content.
 * Gated on no-preference rather than undone under reduce, so a reduced-motion
 * visitor never sees a frame of it. The form itself never moves.
 */
@keyframes auth-rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .auth-step {
    animation: auth-rise 0.55s var(--ease) var(--delay, 0s) both;
  }

  .auth-step:nth-child(1) { --delay: 0.15s; }
  .auth-step:nth-child(2) { --delay: 0.3s; }
  .auth-step:nth-child(3) { --delay: 0.45s; }
}


/* --- Smaller screens -------------------------------------------------------- */

/* One column: the form, centred, and no panel to push it down. */
@media (max-width: 1023px) {
  .auth-main {
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
    padding-bottom: 96px;
  }

  .auth-art {
    display: none;
  }
}

/*
 * The column goes to the top rather than the middle: with the keyboard open a
 * vertically centred form is pushed half off the screen.
 */
@media (max-width: 560px) {
  .auth-header {
    height: 56px;
    padding: 0 16px;
  }

  .auth-main {
    align-items: start;
    justify-items: stretch;
    padding: 28px 16px 40px;
  }

  .auth-column {
    max-width: none;
    margin-bottom: 0;
  }

  .auth-title {
    font-size: 1.75rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .auth-page *,
  .auth-page *::before,
  .auth-page *::after {
    transition: none !important;
  }
}
