/* The sign-in pages (views/layouts/auth.php and views/auth/): sign in, create account, forgot and new password.
   No header or footer: one white card in the middle of a stone background with soft dots,
   the logo in a chip on the card's top edge, then a few links under the card.
   Grouped by part, top to bottom. */

/* --- The page: stone with soft dots, the card in the middle. --- */
.auth {
  position: relative;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: var(--sp-6);
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--sp-16) var(--sp-4) var(--sp-10);
  background-color: var(--c-surface);
}

/* The dots: the same soft dot as the trust bar on the home page. */
.auth::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle, var(--c-texture-dot), transparent calc(var(--border-1) * 3));
  background-size: var(--sp-2) var(--sp-2);
  pointer-events: none;
}

/* --- The card. --- */
.auth__card {
  position: relative; /* above the dots, and holds the chip */
  width: 100%;
  max-width: calc(var(--auth-w) + 2 * var(--sp-10));
  padding: var(--sp-12) var(--sp-6) var(--sp-8);
  background-color: var(--c-page);
  border: var(--border-1) solid var(--c-line);
  border-radius: var(--radius-2);
  box-shadow: var(--shadow-1);
}

.auth__card--wide {
  max-width: calc(var(--auth-w-wide) + 2 * var(--sp-10));
}

@media (min-width: 576px) {
  .auth__card {
    padding-inline: var(--sp-10);
  }
}

/* --- The logo chip: a white pill centred on the card's top border. --- */
.auth__chip {
  position: absolute;
  top: 0;
  left: 50%;
  display: flex;
  align-items: center;
  height: var(--sp-10);
  padding-inline: var(--sp-10);
  color: var(--c-dark);
  background-color: var(--c-page);
  border: var(--border-1) solid var(--c-line);
  border-radius: var(--radius-pill);
  transform: translate(-50%, -50%);
}

.auth__chip .logo {
  display: block;
  height: var(--sp-5); /* 20px */
  width: auto;
}

.auth__chip:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* --- The heading: eyebrow, title and a line of text, centred. --- */
.auth__intro {
  justify-items: center;
  margin-bottom: var(--sp-8);
  text-align: center;
}

.auth__intro .intro__title {
  font-size: var(--fs-h2);
}

.auth__intro .intro__text {
  font-size: var(--fs-body);
  text-wrap: pretty; /* no single word alone on the last line */
}

/* --- Inside the form. --- */

/* First and last name side by side from 576px. */
.auth__pair {
  display: grid;
  gap: var(--sp-4);
}

@media (min-width: 576px) {
  .auth__pair {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.auth__hint {
  margin-top: calc(-1 * var(--sp-2));
  font-size: var(--fs-small);
  color: var(--c-text-muted);
}

.auth__forgot {
  justify-self: end;
  font-size: var(--fs-small);
}

.auth__submit {
  width: 100%;
}

/* Back and Create account: side by side, the same width. */
.auth__buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-3);
}

.auth__buttons .button {
  padding-inline: var(--sp-3);
  white-space: nowrap;
}

.auth__buttons .button--secondary {
  border-color: var(--c-line); /* grey, not the blue outline of the main buttons */
}

/* On phones the icons go, so "Create account" fits on one line. */
@media (max-width: 575.98px) {
  .auth__buttons .bi {
    display: none;
  }
}

/* The lock line under the Sign in button. */
.auth__secure {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-small);
  color: var(--c-text-muted);
}

/* --- Links. --- */
.auth__link {
  color: var(--c-accent-text);
  text-decoration: none;
}

.auth__link:hover {
  text-decoration: underline;
}

/* Keyboard focus on these text links is an underline, not the boxy site ring
   (Chrome also shows that ring on a link after coming back from the tab it opened). */
.auth__link:focus-visible {
  box-shadow: none;
  text-decoration: underline;
}

/* "Send a new code" is a button (it sends an email), dressed as a link. */
.auth__link--button {
  padding: 0;
  font: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

/* "New here? Create an account": under a line, centred. */
.auth__alt {
  margin-top: var(--sp-10);
  padding-top: var(--sp-6);
  border-top: var(--border-1) solid var(--c-line);
  text-align: center;
  color: var(--c-text-muted);
}

.auth__back {
  margin-top: var(--sp-3);
  text-align: center;
  font-size: var(--fs-small);
}

/* A page with no line above it (new password) gets one before "Back to the website". */
.form + .auth__back {
  margin-top: var(--sp-10);
  padding-top: var(--sp-6);
  border-top: var(--border-1) solid var(--c-line);
}

.auth__back a,
.auth__footer a {
  color: var(--c-text-muted);
  text-decoration: none;
}

.auth__back a:hover,
.auth__footer a:hover {
  color: var(--c-text);
  text-decoration: underline;
}

/* --- Under the card: contact, privacy, terms and the copyright. --- */
.auth__footer {
  position: relative; /* above the dots */
  display: grid;
  justify-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-small);
  color: var(--c-text-muted);
  text-align: center;
}

.auth__links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--sp-1) var(--sp-4);
}

/* --- The create account step bar: a circle per step, joined by a line, the label underneath. --- */
.steps-bar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: var(--sp-8);
}

.steps-bar__item {
  position: relative;
  display: grid;
  justify-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-small);
  text-align: center;
  color: var(--c-text-muted);
}

/* The line from the step before, between the two circles. */
.steps-bar__item + .steps-bar__item::before {
  content: "";
  position: absolute;
  top: calc(var(--sp-6) / 2);
  right: calc(50% + var(--sp-6) / 2 + var(--sp-2));
  left: calc(-50% + var(--sp-6) / 2 + var(--sp-2));
  border-top: var(--border-1) solid var(--c-line);
}

.steps-bar__number {
  display: grid;
  place-items: center;
  width: var(--sp-6);
  height: var(--sp-6);
  font-weight: 600;
  background-color: var(--c-page);
  border: var(--border-1) solid var(--c-line);
  border-radius: 50%;
}

.steps-bar__item--now {
  font-weight: 500;
  color: var(--c-text);
}

.steps-bar__item--now .steps-bar__number {
  color: var(--c-accent-text);
  border-color: var(--c-menu-button);
}

.steps-bar__item--done .steps-bar__number {
  color: var(--c-on-dark);
  background-color: var(--c-tick);
  border-color: var(--c-tick);
}

/* --- The 6-digit code: one real field, drawn as six boxes. --- */
.code {
  justify-items: center;
  text-align: center;
}

.code__text {
  color: var(--c-text-muted);
  text-wrap: pretty;
}

.code__text strong {
  font-weight: 500;
  color: var(--c-text);
  overflow-wrap: anywhere; /* a long email address wraps instead of widening the card */
}

.code__field {
  --box: var(--sp-10); /* 40px on phones */
  position: relative;
  width: calc(6 * var(--box) + 5 * var(--sp-2));
  margin-top: var(--sp-2);
}

@media (min-width: 576px) {
  .code__field {
    --box: var(--code-box); /* 48px */
  }
}

.code__label {
  position: absolute;
  width: var(--border-1);
  height: var(--border-1);
  overflow: hidden;
  clip-path: inset(50%);
}

/* The six boxes, drawn behind the field. */
.code__boxes {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: var(--sp-2);
  pointer-events: none;
}

.code__boxes span {
  background-color: var(--c-page);
  border: var(--border-1) solid var(--c-line);
  border-radius: var(--radius-2);
  transition: border-color var(--duration-fast) var(--ease), box-shadow var(--duration-fast) var(--ease);
}

/* The field itself: see-through, its digits spaced so each lands in a box. */
.code__input {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: calc(var(--box) + var(--sp-4));
  padding: 0 0 0 calc(var(--box) / 2 - 0.5ch);
  font-family: var(--font-body);
  font-size: var(--fs-h4);
  font-variant-numeric: tabular-nums;
  letter-spacing: calc(var(--box) + var(--sp-2) - 1ch);
  color: var(--c-text);
  background: transparent;
  border: 0;
  outline: none;
  caret-color: transparent;
}

/* Focus shows on the boxes, not as a ring round the see-through field. */
.code__input:focus-visible {
  box-shadow: none;
}

/* Only the box the next digit goes into lights up. site.js keeps data-filled at the digit count;
   without JavaScript there is no count, so all six light up instead. */
.code__input:focus:not([data-filled]) + .code__boxes span,
.code__input:focus[data-filled="0"] + .code__boxes span:nth-child(1),
.code__input:focus[data-filled="1"] + .code__boxes span:nth-child(2),
.code__input:focus[data-filled="2"] + .code__boxes span:nth-child(3),
.code__input:focus[data-filled="3"] + .code__boxes span:nth-child(4),
.code__input:focus[data-filled="4"] + .code__boxes span:nth-child(5),
.code__input:focus[data-filled="5"] + .code__boxes span:nth-child(6),
.code__input:focus[data-filled="6"] + .code__boxes span:nth-child(6) {
  border-color: var(--c-focus-border);
  box-shadow: var(--focus-ring);
}

.code__input[aria-invalid="true"] + .code__boxes span {
  border-color: var(--c-error);
}

.code__help {
  font-size: var(--fs-small);
  color: var(--c-text-muted);
}

.code__resend {
  margin-top: var(--sp-6);
  font-size: var(--fs-small);
  color: var(--c-text-muted);
  text-align: center;
  text-wrap: pretty;
}

/* --- Setting up the authenticator app (views/auth/app-setup.php): three numbered steps, the QR code in the second. --- */
.app-setup {
  display: grid;
  gap: var(--sp-4);
  padding-left: var(--sp-6);
  text-align: left;
  list-style: decimal;
}

.app-setup li {
  padding-left: var(--sp-1);
}

.app-setup li > * {
  display: block;
  margin-top: var(--sp-2);
}

.app-setup__qr {
  border: var(--border-1) solid var(--c-line);
  border-radius: var(--radius-2);
}

.app-setup__key {
  font-size: var(--fs-small);
  color: var(--c-text-muted);
}

.app-setup__key strong {
  display: block; /* the whole key on a line of its own, not broken after its first group */
  font-family: var(--font-mono); /* a key is easier to copy letter by letter in a fixed-width font */
  color: var(--c-text);
  letter-spacing: var(--tracking-caps);
}

/* Only on phones, where the app is on the same device. */
@media (min-width: 768px) {
  .app-setup .app-setup__open {
    display: none;
  }
}

/* --- The welcome after the code: a tick draws itself, then the bar fills before moving on. --- */
.welcome {
  display: grid;
  justify-items: center;
  gap: var(--sp-3);
  text-align: center;
}

.welcome__tick {
  display: grid;
  place-items: center;
  width: var(--sp-16);
  height: var(--sp-16);
  background-color: var(--c-tick);
  border-radius: 50%;
  animation: welcome-pop var(--duration-slow) var(--ease-out) both;
}

.welcome__tick svg {
  width: var(--sp-8);
  height: var(--sp-8);
  fill: none;
  stroke: var(--c-on-dark);
  stroke-width: 2.4; /* in the icon's own 24-unit grid, not pixels */
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 20; /* a little longer than the tick's line, so it starts hidden and draws in */
  stroke-dashoffset: 20;
  animation: welcome-draw var(--duration-slow) var(--ease-out) var(--duration-slow) forwards;
}

.welcome__title {
  margin-top: var(--sp-2);
  font-size: var(--fs-h4);
}

.welcome__text {
  color: var(--c-text-muted);
  text-wrap: pretty;
}

.welcome__bar {
  width: 100%;
  max-width: var(--welcome-bar-w);
  height: var(--sp-1);
  margin-top: var(--sp-3);
  overflow: hidden;
  background-color: var(--c-panel);
  border-radius: var(--radius-pill);
}

/* Fills in the time the page waits before moving on (WELCOME_SECONDS in src/auth.php). */
.welcome__bar span {
  display: block;
  height: 100%;
  background-color: var(--c-tick);
  border-radius: inherit;
  transform-origin: left;
  animation: welcome-fill var(--welcome-time) linear both;
}

.welcome__link {
  font-size: var(--fs-small);
}

@keyframes welcome-pop {
  from { transform: scale(0.6); opacity: 0; }
}

@keyframes welcome-draw {
  to { stroke-dashoffset: 0; }
}

@keyframes welcome-fill {
  from { transform: scaleX(0); }
}

/* Reduced motion: the tick and a full bar, standing still. The page still moves on after the same wait. */
@media (prefers-reduced-motion: reduce) {
  .welcome__tick,
  .welcome__bar span {
    animation: none;
  }

  .welcome__tick svg {
    animation: none;
    stroke-dashoffset: 0;
  }
}
