@layer auth-layout, auth-components, auth-responsive;

@layer auth-layout {
  .auth-page {
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--vs-warm-porcelain);
    color: var(--vs-deep-ink);
  }

  .auth-shell {
    display: grid;
    grid-template-columns: minmax(20rem, 0.92fr) minmax(28rem, 1.08fr);
    min-height: 100vh;
    min-height: 100dvh;
  }

  .auth-brand-panel {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 100vh;
    min-height: 100dvh;
    padding: clamp(2rem, 5vw, 5rem);
    overflow-x: hidden;
    overflow-y: auto;
    background: var(--vs-deep-ink);
    color: var(--vs-color-text-inverse);
  }

  .auth-brand-panel::after {
    position: absolute;
    right: clamp(-5rem, -7vw, -2rem);
    bottom: clamp(-7rem, -9vw, -3rem);
    width: clamp(16rem, 32vw, 33rem);
    aspect-ratio: 1;
    border: clamp(1.5rem, 4vw, 4rem) solid rgba(var(--vs-mineral-lime-rgb), 0.12);
    border-radius: 50%;
    content: "";
    pointer-events: none;
  }

  .auth-brand {
    position: relative;
    z-index: 1;
    display: inline-flex;
    width: fit-content;
    align-items: center;
    gap: 0.8rem;
    min-height: var(--vs-touch-target);
    color: inherit;
    text-decoration: none;
  }

  .auth-brand img {
    width: 2rem;
    height: 2.5rem;
  }

  .auth-brand strong {
    font-size: 1.25rem;
    letter-spacing: -0.03em;
  }

  .auth-brand-copy {
    position: relative;
    z-index: 1;
    max-width: 37rem;
    margin-block: auto;
    padding-block: 4rem;
  }

  .auth-brand-copy h1 {
    max-width: 12ch;
    margin: 0;
    color: inherit;
    font-size: clamp(2.6rem, 5.8vw, 5.4rem);
    line-height: 0.98;
    letter-spacing: -0.055em;
  }

  .auth-brand-copy p {
    max-width: 34rem;
    margin: 1.7rem 0 0;
    color: var(--vs-soft-sage);
    font-size: clamp(1rem, 1.4vw, 1.2rem);
    line-height: 1.65;
  }

  .auth-brand-copy .auth-accent {
    color: var(--vs-mineral-lime);
  }

  .auth-trust {
    position: relative;
    z-index: 1;
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .auth-trust li {
    display: inline-flex;
    align-items: center;
    min-height: 2rem;
    padding: 0.35rem 0.75rem;
    border: 1px solid rgba(var(--vs-soft-sage-rgb), 0.45);
    border-radius: var(--vs-radius-pill);
    color: var(--vs-soft-sage);
    font-size: 0.75rem;
  }

  .auth-trust li::before {
    width: 0.45rem;
    height: 0.45rem;
    margin-right: 0.45rem;
    border-radius: 50%;
    background: var(--vs-mineral-lime);
    content: "";
  }

  .auth-form-panel {
    display: grid;
    min-height: 100vh;
    min-height: 100dvh;
    place-items: center;
    padding: clamp(1.25rem, 5vw, 5rem);
  }

  .auth-card {
    width: min(100%, 30rem);
  }
}

@layer auth-components {
  .auth-kicker {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0 0 1rem;
    color: var(--vs-color-text-secondary);
    font-size: 0.75rem;
    font-weight: var(--vs-font-weight-bold);
    letter-spacing: 0.1em;
    text-transform: uppercase;
  }

  .auth-kicker::before {
    width: 1.8rem;
    height: 0.2rem;
    border-radius: var(--vs-radius-pill);
    background: var(--vs-coral);
    content: "";
  }

  .auth-card h2 {
    margin: 0;
    font-size: clamp(2rem, 4vw, 3rem);
    line-height: 1.05;
    letter-spacing: -0.045em;
  }

  .auth-lead {
    margin: 0.85rem 0 2rem;
    color: var(--vs-color-text-secondary);
    line-height: 1.62;
  }

  .auth-form {
    display: grid;
    gap: 1.1rem;
  }

  .auth-field {
    display: grid;
    gap: 0.45rem;
  }

  .auth-field > span:not(.auth-password),
  .auth-field > label,
  .auth-field__label,
  .auth-fieldset legend {
    color: var(--vs-deep-ink);
    font-size: 0.84rem;
    font-weight: var(--vs-font-weight-semibold);
  }

  .auth-field input {
    width: 100%;
    min-height: 3.25rem;
    padding: 0.75rem 0.95rem;
    border: 1px solid var(--vs-color-border-strong);
    border-radius: var(--vs-radius-md);
    outline: 0;
    background: var(--vs-color-surface);
    color: var(--vs-color-text);
    font: inherit;
    transition: border-color var(--vs-duration-base), box-shadow var(--vs-duration-base);
  }

  .auth-field input:hover {
    border-color: var(--vs-deep-ink);
  }

  .auth-field input:focus-visible {
    border-color: var(--vs-deep-ink);
    outline: 2px solid var(--vs-deep-ink);
    outline-offset: 2px;
    box-shadow: var(--vs-shadow-focus);
  }

  .auth-field small {
    color: var(--vs-color-text-secondary);
    line-height: 1.45;
  }

  .auth-password {
    position: relative;
  }

  .auth-password input {
    padding-right: 4.4rem;
  }

  .auth-password button {
    position: absolute;
    top: 50%;
    right: 0.45rem;
    min-width: 3.5rem;
    min-height: var(--vs-touch-target);
    padding: 0.25rem 0.55rem;
    border: 0;
    border-radius: var(--vs-radius-sm);
    background: transparent;
    color: var(--vs-color-text-secondary);
    font: inherit;
    font-size: 0.78rem;
    font-weight: var(--vs-font-weight-semibold);
    cursor: pointer;
    transform: translateY(-50%);
  }

  .auth-password button:hover,
  .auth-password button:focus-visible {
    background: var(--vs-color-surface-subtle);
    color: var(--vs-deep-ink);
  }

  .auth-password button:focus-visible {
    outline: 3px solid var(--vs-deep-ink);
    outline-offset: 2px;
  }

  .auth-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    font-size: 0.88rem;
  }

  .auth-check {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    min-height: var(--vs-touch-target);
    cursor: pointer;
  }

  .auth-check input {
    width: 1.15rem;
    height: 1.15rem;
    accent-color: var(--vs-deep-ink);
  }

  .auth-link {
    color: var(--vs-deep-ink);
    font-weight: var(--vs-font-weight-semibold);
    text-underline-offset: 0.2em;
  }

  .auth-submit,
  .auth-secondary {
    display: inline-flex;
    min-height: 3.25rem;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.1rem;
    border: 1px solid var(--vs-deep-ink);
    border-radius: var(--vs-radius-md);
    font: inherit;
    font-weight: var(--vs-font-weight-bold);
    text-decoration: none;
    cursor: pointer;
    transition: background var(--vs-duration-base), color var(--vs-duration-base), transform var(--vs-duration-fast);
  }

  .auth-submit {
    background: var(--vs-deep-ink);
    color: var(--vs-mineral-lime);
  }

  .auth-submit:hover:not(:disabled) {
    background: var(--vs-color-interactive-hover);
  }

  .auth-secondary {
    background: transparent;
    color: var(--vs-deep-ink);
  }

  .auth-submit:active:not(:disabled),
  .auth-secondary:active:not(:disabled) {
    transform: translateY(1px);
  }

  .auth-submit:focus-visible,
  .auth-secondary:focus-visible {
    outline: 3px solid var(--vs-color-focus);
    outline-offset: 3px;
    box-shadow: var(--vs-shadow-focus);
  }

  .auth-submit:disabled,
  .auth-secondary:disabled {
    cursor: wait;
    opacity: 0.62;
  }

  .auth-message {
    min-height: 1.4rem;
    margin: 0;
    color: var(--vs-color-danger);
    font-size: 0.88rem;
    line-height: 1.45;
  }

  .auth-message[data-kind="success"] {
    color: var(--vs-color-success-ink);
  }

  .auth-message[data-kind="info"] {
    color: var(--vs-color-text-secondary);
  }

  .auth-footnote {
    margin: 1.7rem 0 0;
    color: var(--vs-color-text-secondary);
    text-align: center;
    font-size: 0.9rem;
  }

  .auth-stage[hidden] {
    display: none;
  }

  .auth-stage-note {
    display: flex;
    gap: 0.75rem;
    margin: 0 0 1.25rem;
    padding: 0.9rem;
    border: 1px solid var(--vs-color-border);
    border-radius: var(--vs-radius-md);
    background: var(--vs-color-highlight-soft);
    color: var(--vs-color-text-secondary);
    font-size: 0.86rem;
    line-height: 1.45;
  }

  .auth-stage-note::before {
    flex: 0 0 auto;
    width: 0.62rem;
    height: 0.62rem;
    margin-top: 0.28rem;
    border-radius: 50%;
    background: var(--vs-mineral-lime);
    box-shadow: 0 0 0 3px var(--vs-deep-ink);
    content: "";
  }

  .auth-fieldset {
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
  }

  .auth-fieldset legend {
    margin-bottom: 0.65rem;
  }

  .auth-factor-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.35rem;
    padding: 0.3rem;
    border: 1px solid var(--vs-color-border);
    border-radius: var(--vs-radius-md);
    background: var(--vs-color-surface-subtle);
  }

  .auth-factor-switch label {
    position: relative;
    display: grid;
    min-height: var(--vs-touch-target);
    place-items: center;
    border-radius: var(--vs-radius-sm);
    color: var(--vs-color-text-secondary);
    font-size: 0.8rem;
    font-weight: var(--vs-font-weight-semibold);
    cursor: pointer;
  }

  .auth-factor-switch input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
  }

  .auth-factor-switch label:has(input:checked) {
    background: var(--vs-color-surface);
    color: var(--vs-deep-ink);
    box-shadow: var(--vs-shadow-1);
  }

  .auth-factor-switch label:has(input:focus-visible) {
    outline: 3px solid var(--vs-deep-ink);
    outline-offset: 2px;
    box-shadow: var(--vs-shadow-focus);
  }

  .auth-tenant-list {
    display: grid;
    gap: 0.65rem;
  }

  .auth-tenant-option {
    position: relative;
    display: flex;
    min-height: 3.8rem;
    align-items: center;
    gap: 0.85rem;
    padding: 0.8rem 0.95rem;
    border: 1px solid var(--vs-color-border-strong);
    border-radius: var(--vs-radius-md);
    background: var(--vs-color-surface);
    cursor: pointer;
  }

  .auth-tenant-option input {
    width: 1.15rem;
    height: 1.15rem;
    margin: 0;
    accent-color: var(--vs-deep-ink);
  }

  .auth-tenant-option span {
    display: grid;
    gap: 0.15rem;
    min-width: 0;
  }

  .auth-tenant-option strong,
  .auth-tenant-option small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .auth-tenant-option small {
    color: var(--vs-color-text-muted);
  }

  .auth-tenant-option:has(input:checked) {
    border-color: var(--vs-deep-ink);
    background: var(--vs-color-highlight-soft);
    box-shadow: 0 0 0 1px var(--vs-deep-ink);
  }

  .auth-tenant-option:has(input:focus-visible) {
    outline: 3px solid var(--vs-deep-ink);
    outline-offset: 2px;
    box-shadow: var(--vs-shadow-focus);
  }

  .auth-success-mark {
    display: grid;
    width: 3.5rem;
    height: 3.5rem;
    margin-bottom: 1.4rem;
    place-items: center;
    border-radius: 50%;
    background: var(--vs-mineral-lime);
    color: var(--vs-deep-ink);
    font-size: 1.4rem;
    font-weight: var(--vs-font-weight-bold);
  }

  .auth-actions {
    display: grid;
    gap: 0.75rem;
    margin-top: 1.5rem;
  }

  .auth-expiry {
    margin: -0.35rem 0 0;
    color: var(--vs-color-text-secondary);
    font-size: 0.78rem;
  }

  .auth-skip-link {
    position: fixed;
    z-index: 10;
    top: 0.75rem;
    left: 0.75rem;
    padding: 0.65rem 0.9rem;
    border-radius: var(--vs-radius-sm);
    background: var(--vs-mineral-lime);
    color: var(--vs-deep-ink);
    font-weight: var(--vs-font-weight-bold);
    transform: translateY(-180%);
  }

  .auth-skip-link:focus {
    transform: translateY(0);
  }

  .auth-mfa-details .auth-fieldset {
    margin-top: 1rem;
  }

  .auth-mfa-details .auth-field {
    margin-top: 0.85rem;
  }

  .auth-page :where(a, button, summary):focus-visible {
    outline: 3px solid var(--vs-color-focus);
    outline-offset: 3px;
  }

  .auth-link:focus-visible {
    outline-color: var(--vs-deep-ink);
  }
}

@layer auth-responsive {
  @media (max-width: 52rem) {
    .auth-shell {
      grid-template-columns: 1fr;
    }

    .auth-brand-panel {
      min-height: auto;
      padding: 1.25rem;
    }

    .auth-brand-copy {
      padding-block: 2.5rem 1.5rem;
    }

    .auth-brand-copy h1 {
      max-width: 16ch;
      font-size: clamp(2.2rem, 10vw, 3.8rem);
    }

    .auth-brand-copy p {
      margin-top: 1rem;
    }

    .auth-trust {
      display: none;
    }

    .auth-form-panel {
      min-height: auto;
      padding-block: 2.5rem 4rem;
    }
  }

  @media (max-width: 30rem) {
    .auth-row {
      align-items: flex-start;
      flex-direction: column;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .auth-page *,
    .auth-page *::before,
    .auth-page *::after {
      scroll-behavior: auto !important;
      transition-duration: 0.01ms !important;
    }
  }

  @media (prefers-contrast: more) {
    .auth-field input,
    .auth-factor-switch,
    .auth-tenant-option,
    .auth-stage-note {
      border-width: var(--vs-border-width-strong);
      border-color: var(--vs-color-border-strong);
    }

    .auth-trust li {
      border-color: var(--vs-soft-sage);
    }
  }

  @media (forced-colors: active) {
    .auth-brand-panel::after,
    .auth-trust li,
    .auth-field input,
    .auth-factor-switch,
    .auth-tenant-option,
    .auth-stage-note,
    .auth-submit,
    .auth-secondary {
      border-color: CanvasText;
    }

    .auth-stage-note::before,
    .auth-trust li::before,
    .auth-kicker::before {
      background: Highlight;
    }

    .auth-page :where(a, button, input, summary):focus-visible,
    .auth-factor-switch label:has(input:focus-visible),
    .auth-tenant-option:has(input:focus-visible) {
      outline: 3px solid Highlight;
      outline-offset: 3px;
      box-shadow: none;
    }
  }
}
