/* Sign-in and forgot-password pages (templates/auth/*.html).
 *
 * One centred card on the shared dark palette (theme-dark.css): the company
 * name above it, the copyright line below, and a soft violet glow with a
 * fading dot grid behind it. The same layout serves phones and desktops; only
 * the card padding changes. There is no logo and no descriptive text.
 *
 * Every colour, space and radius comes from tokens.css / theme-dark.css. The
 * only motion is the card's short entrance and the button arrow;
 * prefers-reduced-motion switches both off.
 */

.auth-body {
  --auth-accent: var(--color-brand);
  --auth-accent-hover: var(--color-brand-hover);
  --auth-accent-soft: var(--color-brand-soft);
  --auth-gap: var(--space-md);
  --auth-fs-small: var(--font-size-sm);
  --auth-control-height: 46px;
  --auth-card-width: 420px;

  background-color: var(--color-background);
  background-image: radial-gradient(ellipse 70% 45% at 50% -10%, var(--auth-accent-soft), transparent 70%);
  background-repeat: no-repeat;
}

/* ----------------------------------------------------------------- Layout */

.auth-layout {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--space-xl) var(--space-md);
  isolation: isolate;
}

/* A dot grid that fades out towards the bottom of the window. */
.auth-layout::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background-image: radial-gradient(var(--color-border) 1px, transparent 1px);
  background-size: 24px 24px;
  -webkit-mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 30%, transparent 75%);
  mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 30%, transparent 75%);
  pointer-events: none;
}

.auth-shell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-lg);
  width: 100%;
  max-width: var(--auth-card-width);
}

.auth-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  max-width: 100%;
  margin: 0;
}

.auth-brand__name {
  font-size: var(--font-size-xl);
}

.auth-brand__tag {
  flex: 0 0 auto;
  padding: var(--space-3xs) var(--space-xs);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-pill);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.auth-card {
  width: 100%;
  padding: var(--space-lg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  background-color: var(--color-surface);
  box-shadow: var(--shadow-lg);
  animation: auth-enter 320ms cubic-bezier(0.4, 0, 0.2, 1) both;
}

@media (min-width: 480px) {
  .auth-card {
    padding: var(--space-xl) calc(var(--space-xl) + var(--space-2xs));
  }
}

.auth-foot {
  font-size: var(--font-size-xs);
  color: var(--color-text-subtle);
}

@keyframes auth-enter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* ------------------------------------------------------------ Card header */

.auth-card__header {
  margin-bottom: var(--space-lg);
  text-align: center;
}

.auth-card__badge {
  display: inline-grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  margin-bottom: var(--space-md);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-lg);
  background-color: var(--auth-accent-soft);
  color: var(--auth-accent);
}

.auth-card__badge svg {
  width: 1.375rem;
  height: 1.375rem;
}

.auth-card__title {
  font-family: var(--font-brand);
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-bold);
  letter-spacing: -0.02em;
}

.auth-card__subtitle {
  margin-top: var(--space-2xs);
  font-size: var(--font-size-base);
  color: var(--color-text-muted);
}

.auth-card__email {
  color: var(--color-text);
  font-weight: var(--font-weight-semibold);
  overflow-wrap: anywhere;
}

.auth-card__alert {
  margin-bottom: var(--space-md);
}

.auth-card__switch {
  margin-top: var(--space-lg);
  font-size: var(--auth-fs-small);
  color: var(--color-text-muted);
  text-align: center;
}

.auth-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  justify-content: space-between;
  margin-top: var(--space-md);
}

.auth-card__actions form {
  margin: 0;
}

.auth-card__fineprint {
  margin-top: var(--space-xs);
  font-size: var(--font-size-xs);
  color: var(--color-text-subtle);
}

/* ------------------------------------------------------------------- Form */

.auth-form {
  display: grid;
  gap: var(--auth-gap);
}

.auth-form__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0 var(--space-sm);
  margin-block: calc(var(--space-xs) * -1);
}

.auth-link {
  font-weight: var(--font-weight-semibold);
  color: var(--auth-accent);
}

.auth-link:hover {
  color: var(--auth-accent-hover);
}

.auth-link:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ----------------------------------------------------------------- Fields */

.auth-field {
  display: grid;
  gap: var(--space-2xs);
}

.auth-field__label {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text);
}

.auth-field__required {
  color: var(--color-error);
}

.auth-field__control-wrap {
  position: relative;
}

.auth-field__icon {
  position: absolute;
  top: 50%;
  inset-inline-start: var(--space-sm);
  display: inline-grid;
  place-items: center;
  width: 1.125rem;
  height: 1.125rem;
  color: var(--color-text-subtle);
  pointer-events: none;
  transform: translateY(-50%);
  transition: color var(--transition-fast);
}

.auth-field__icon svg {
  width: 100%;
  height: 100%;
}

.auth-field__control {
  width: 100%;
  min-height: var(--auth-control-height);
  padding: 0 var(--space-sm);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background-color: var(--color-surface-muted);
  font: inherit;
  font-size: var(--font-size-md);
  color: var(--color-text);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast),
    background-color var(--transition-fast);
}

.auth-field__control::placeholder {
  color: var(--color-text-subtle);
}

.auth-field__control:hover {
  border-color: var(--color-text-subtle);
}

.auth-field__control:focus {
  outline: none;
  border-color: var(--auth-accent);
  background-color: var(--color-surface);
  box-shadow: 0 0 0 3px var(--auth-accent-soft);
}

.auth-field__control-wrap:focus-within .auth-field__icon {
  color: var(--auth-accent);
}

.auth-field__control-wrap--icon .auth-field__control {
  padding-inline-start: calc(var(--space-sm) + 1.125rem + var(--space-xs));
}

.auth-field__control-wrap--toggle .auth-field__control {
  padding-inline-end: calc(var(--auth-control-height) + var(--space-2xs));
}

.auth-field__select {
  appearance: none;
  padding-inline-end: calc(var(--space-sm) + 1.5rem);
}

.auth-field__chevron {
  position: absolute;
  top: 50%;
  inset-inline-end: var(--space-sm);
  width: 1rem;
  height: 1rem;
  color: var(--color-text-subtle);
  pointer-events: none;
  transform: translateY(-50%);
}

/* Show / hide password: a full-height, 44px-wide touch target. */
.auth-field__toggle {
  position: absolute;
  inset-block: 1px;
  inset-inline-end: 1px;
  display: inline-grid;
  place-items: center;
  width: var(--auth-control-height);
  padding: 0;
  border: 0;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  background: transparent;
  color: var(--color-text-subtle);
  cursor: pointer;
  transition: color var(--transition-fast);
}

.auth-field__toggle[hidden] {
  display: none;
}

.auth-field__toggle:hover {
  color: var(--color-text);
}

.auth-field__toggle:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: -4px;
  border-radius: var(--radius-md);
}

.auth-field__toggle svg {
  width: 1.125rem;
  height: 1.125rem;
}

.auth-field__toggle-hide,
.auth-field__toggle[aria-pressed="true"] .auth-field__toggle-show {
  display: none;
}

.auth-field__toggle[aria-pressed="true"] .auth-field__toggle-hide,
.auth-field__toggle-show {
  display: inline-grid;
}

.auth-field__hint {
  font-size: var(--font-size-xs);
  color: var(--color-text-subtle);
}

.auth-field__error {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2xs);
  font-size: var(--font-size-xs);
  color: var(--color-error);
}

.auth-field__error-icon {
  flex: 0 0 auto;
  width: 0.9rem;
  height: 0.9rem;
  margin-top: 0.1rem;
}

.auth-field--invalid .auth-field__control {
  border-color: var(--color-error);
}

.auth-field--invalid .auth-field__control:focus {
  box-shadow: 0 0 0 3px var(--color-error-soft);
}

/* The 6-digit code: large, spaced digits. */
.auth-otp {
  min-height: 56px;
  font-family: var(--font-mono);
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-semibold);
  letter-spacing: 0.5em;
  text-align: center;
  text-indent: 0.5em;
}

[data-countdown].is-expired {
  color: var(--color-warning);
}

/* --------------------------------------------------------------- Checkbox */

.auth-check {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  min-height: 44px;
  cursor: pointer;
  font-size: var(--font-size-sm);
  color: var(--color-text);
}

.auth-check__input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
}

.auth-check__box {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 1.125rem;
  height: 1.125rem;
  border: 1px solid var(--color-text-subtle);
  border-radius: var(--radius-sm);
  background-color: var(--color-surface-muted);
  color: transparent;
  transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

.auth-check__box svg {
  width: 0.8rem;
  height: 0.8rem;
}

.auth-check:hover .auth-check__box {
  border-color: var(--color-text-muted);
}

.auth-check__input:checked + .auth-check__box {
  border-color: var(--auth-accent);
  background-color: var(--auth-accent);
  color: var(--color-brand-contrast);
}

.auth-check__input:focus-visible + .auth-check__box {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 2px;
}

/* ---------------------------------------------------- Password strength */

.auth-meter {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.auth-meter[hidden] {
  display: none;
}

.auth-meter__bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  flex: 1 1 auto;
  gap: var(--space-2xs);
}

.auth-meter__bar span {
  height: 4px;
  border-radius: var(--radius-pill);
  background-color: var(--color-border-strong);
  transition: background-color var(--transition-normal);
}

.auth-meter__label {
  min-width: 3.5rem;
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  text-align: end;
}

.auth-meter[data-level="1"] .auth-meter__bar span:nth-child(-n + 1) { background-color: var(--color-error); }
.auth-meter[data-level="2"] .auth-meter__bar span:nth-child(-n + 2) { background-color: var(--color-warning); }
.auth-meter[data-level="3"] .auth-meter__bar span:nth-child(-n + 3) { background-color: var(--auth-accent); }
.auth-meter[data-level="4"] .auth-meter__bar span { background-color: var(--color-success); }

/* ------------------------------------------------------------------ Steps */

.auth-steps {
  display: flex;
  gap: var(--space-xs);
  margin: 0 0 var(--space-lg);
  padding: 0;
  list-style: none;
}

.auth-steps__item {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  gap: var(--space-2xs);
  min-width: 0;
  padding-top: var(--space-xs);
  border-top: 3px solid var(--color-border-strong);
  font-size: var(--font-size-xs);
  color: var(--color-text-subtle);
}

.auth-steps__item.is-done,
.auth-steps__item.is-current {
  border-top-color: var(--auth-accent);
}

.auth-steps__item.is-current {
  color: var(--color-text);
  font-weight: var(--font-weight-semibold);
}

/* The number (or tick) stays for screen readers; the bar shows progress. */
.auth-steps__dot {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------------------------------------------------------------- Buttons */

.auth-submit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  width: 100%;
  min-height: var(--auth-control-height);
  margin-top: var(--space-2xs);
  padding: 0 var(--space-md);
  border: 0;
  border-radius: var(--radius-md);
  background-color: var(--auth-accent);
  font: inherit;
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
  color: var(--color-brand-contrast);
  cursor: pointer;
  transition: background-color var(--transition-fast), transform var(--transition-fast);
}

.auth-submit:hover:not([disabled]) {
  background-color: var(--auth-accent-hover);
}

.auth-submit:active:not([disabled]) {
  transform: translateY(1px);
}

.auth-submit:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 3px;
}

.auth-submit[disabled],
.auth-submit.is-loading {
  cursor: progress;
  opacity: 0.8;
}

.auth-submit__arrow {
  width: 1.05rem;
  height: 1.05rem;
  transition: transform var(--transition-normal);
}

.auth-submit:hover:not([disabled]) .auth-submit__arrow {
  transform: translateX(3px);
}

.auth-submit:not(.is-loading) .button__spinner,
.auth-ghost:not(.is-loading) .button__spinner,
.auth-submit.is-loading .auth-submit__arrow,
.auth-ghost.is-loading .auth-ghost__icon {
  display: none;
}

.auth-ghost {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  min-height: 44px;
  padding: 0 var(--space-sm);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background-color: transparent;
  font: inherit;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text);
  cursor: pointer;
  transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

.auth-ghost:hover:not([disabled]) {
  border-color: var(--color-text-subtle);
  background-color: var(--color-surface);
}

.auth-ghost:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 2px;
}

.auth-ghost[disabled] {
  cursor: not-allowed;
  opacity: 0.6;
}

.auth-ghost--quiet {
  border-color: transparent;
  color: var(--color-text-muted);
}

.auth-ghost__icon {
  width: 1rem;
  height: 1rem;
}

/* ---------------------------------------------------------------- Motion */

@media (prefers-reduced-motion: reduce) {
  .auth-card {
    animation: none;
  }

  .auth-submit,
  .auth-submit__arrow,
  .auth-field__control {
    transition: none;
  }
}
