/**
 * Authentication Domain Stylesheet
 *
 * Purpose: Styles specific to authentication pages and flows
 * Usage: Login, signup, password reset, social authentication
 * Dependencies: main.css (must be loaded first)
 *
 * BOOTSTRAP 5 BEST PRACTICES:
 * - Use --bs-primary for primary actions (login buttons)
 * - Use --bs-secondary for secondary actions
 * - Leverage Bootstrap form utilities (.form-control, .btn-primary)
 * - Use Bootstrap's validation classes (.is-valid, .is-invalid)
 *
 * Key Features:
 * - Professional authentication layouts
 * - Desktop-optimized forms with mobile compatibility
 * - Social authentication button styling
 * - Error messaging and validation feedback
 */

/* Native MFA enrollment and account management, also loaded with app.css. */
.mfa-panel {
  max-width: 40rem;
  margin-block: var(--space-8);
  padding: var(--space-8);
  background: var(--surface-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  overflow-wrap: anywhere;
}

.mfa-panel .btn,
.mfa-panel summary,
.mfa-panel .form-check-label {
  min-height: 44px;
}

.mfa-panel .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.mfa-panel .form-check {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding-left: 0;
}

.mfa-panel .form-check-input {
  flex-shrink: 0;
  margin: 0;
}

.mfa-panel .form-check-label {
  display: flex;
  align-items: center;
}

.mfa-panel summary {
  padding-block: var(--space-3);
  color: var(--primary-slate);
  cursor: pointer;
}

.mfa-panel summary:focus-visible {
  outline: 2px solid var(--secondary-indigo);
  outline-offset: 2px;
}

.mfa-qr {
  width: 200px;
  max-width: 100%;
}

.mfa-panel .webauthn-not-supported {
  display: none;
}

.mfa-recovery-codes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--surface-secondary);
  border-radius: var(--radius-md);
  text-align: center;
  user-select: all;
}

@media (max-width: 575.98px) {
  .mfa-panel {
    margin-block: var(--space-4);
    padding: var(--space-4);
  }

  .mfa-panel .btn {
    width: 100%;
  }
}

/* ============================================================================
   AUTHENTICATION CONTAINER LAYOUTS
   ============================================================================ */

.auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--surface-primary) 0%, var(--surface-accent) 100%);
  padding: var(--space-4);
}

.auth-card {
  width: 100%;
  max-width: 600px;
  background: var(--surface-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
}

.auth-card-header {
  background: var(--surface-accent);
  padding: var(--space-6);
  text-align: center;
  border-bottom: 1px solid var(--border-light);
}

.auth-card-body {
  padding: var(--space-6);
}

/* The entrance card owns page width; invitation content uses its full body. */
.auth-invitation {
  overflow-wrap: anywhere;
}

.auth-invitation .btn {
  min-height: 44px;
  max-width: 100%;
  white-space: normal;
}

.auth-card-footer {
  background: var(--surface-accent);
  padding: var(--space-4);
  text-align: center;
  border-top: 1px solid var(--border-light);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

/* Brand Integration */
.auth-brand {
  margin-bottom: var(--space-4);
}

.auth-brand-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto var(--space-4);
  display: block;
}

.auth-brand-title {
  font-size: var(--text-2xl);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  margin: 0;
}

.auth-brand-subtitle {
  font-size: var(--text-base);
  color: var(--text-secondary);
  margin: var(--space-2) 0 0;
}

/* ============================================================================
   SOCIAL AUTHENTICATION BUTTONS
   ============================================================================ */

.social-auth-section {
  margin-bottom: var(--space-6);
}

.social-auth-button {
  width: 100%;
  padding: var(--space-4);
  margin-bottom: var(--space-3);
  border: 2px solid var(--border-light);
  border-radius: var(--radius-md);
  background: var(--surface-secondary);
  color: var(--text-primary);
  text-decoration: none;
  font-size: var(--text-base);
  font-weight: var(--font-weight-medium);
  transition: all var(--transition-base);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.social-auth-button:hover {
  border-color: var(--bs-primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-base);
  color: var(--text-primary);
  text-decoration: none;
}

.social-auth-button:focus {
  outline: none;
  border-color: var(--bs-primary);
  box-shadow: 0 0 0 0.25rem rgba(var(--bs-primary-rgb), 0.25);
}

.social-auth-button.auth-required-provider {
  border-width: 3px;
  box-shadow: 0 0 0 0.25rem rgba(var(--bs-primary-rgb), 0.15);
}

/* Google OAuth Button */
.social-auth-button.google {
  border-color: #4285F4;
}

.social-auth-button.google:hover {
  border-color: #3367D6;
  background-color: rgba(66, 133, 244, 0.05);
}

/* Microsoft OAuth Button */
.social-auth-button.microsoft {
  border-color: #0078D4;
}

.social-auth-button.microsoft:hover {
  border-color: #106EBE;
  background-color: rgba(0, 120, 212, 0.05);
}

/* Social Button Icons */
.social-auth-icon {
  width: 20px;
  height: 20px;
  margin-right: var(--space-3);
  flex-shrink: 0;
}

/* Social Button Text Container */
.auth-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
}

.auth-primary {
  font-size: var(--text-base);
  font-weight: var(--font-weight-medium);
  line-height: 1.2;
}

/* Social Button Hint Text */
.auth-hint {
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-weight: var(--font-weight-regular);
  margin-top: 2px;
  line-height: 1.2;
  opacity: 0.75;
}

/* ============================================================================
   AUTHENTICATION FORMS
   ============================================================================ */

.auth-form {
  margin-bottom: var(--space-4);
  width: 100%;
}

.auth-step {
  margin-bottom: var(--space-2);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--font-weight-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.auth-email {
  overflow-wrap: anywhere;
  font-weight: var(--font-weight-semibold);
}

.auth-quiet {
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

.auth-pill {
  display: inline-block;
  padding: 0.25rem 0.55rem;
  border-radius: var(--radius-sm);
  background: var(--surface-accent);
  color: var(--secondary-teal);
  font-size: var(--text-sm);
  font-weight: var(--font-weight-semibold);
}

.passkey-form {
  width: 100%;
}

.passkey-options {
  margin-top: var(--space-5);
  border-top: 1px solid var(--border-light);
  padding-top: var(--space-3);
}

.passkey-options summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  color: var(--text-secondary);
  cursor: pointer;
}

.passkey-stage .webauthn-not-supported[hidden] {
  display: none;
}

.auth-form form {
  width: 100%;
}

.auth-form .form-group {
  margin-bottom: var(--space-4);
}

.auth-form .form-label {
  font-weight: var(--font-weight-medium);
  color: var(--text-primary);
  display: block;
  margin-bottom: var(--space-2);
}

.auth-form .form-control {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: 2px solid var(--border-light);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
  background-color: var(--surface-primary);
}

.auth-form .form-control:focus {
  outline: none;
  border-color: var(--bs-primary);
  box-shadow: 0 0 0 0.25rem rgba(var(--bs-primary-rgb), 0.25);
}

.auth-form .form-control.is-invalid {
  border-color: var(--status-error);
}

.auth-form .form-control.is-valid {
  border-color: var(--status-success);
}

/* Password Pair */
.password-input-row {
  position: relative;
}

.password-toggle {
  position: absolute;
  right: 2px;
  top: 2px;
  min-width: 4rem;
  min-height: 44px;
  background: none;
  border: none;
  color: var(--primary-slate);
  cursor: pointer;
  font-size: var(--text-sm);
}

.password-toggle:focus-visible {
  outline: 2px solid var(--secondary-indigo);
  outline-offset: -2px;
}

.password-input-row .form-control {
  min-height: 48px;
  padding-right: 5rem;
  background-image: none;
}

.password-pair .invalid-feedback {
  font-size: var(--text-sm);
  line-height: 1.4;
}

.password-pair [data-password-confirm-error] {
  display: block;
  min-height: 2.8em;
  visibility: hidden;
}

.password-pair [data-password-confirm-error].d-block {
  visibility: visible;
}

form:has(.password-pair) button[type="submit"] {
  min-height: 44px;
}

.password-match-feedback {
  color: var(--secondary-teal);
  font-size: var(--text-sm);
  margin-bottom: var(--space-4);
}

@keyframes password-shake {
  25%, 75% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
}

/* ============================================================================
   FORM VALIDATION AND FEEDBACK
   ============================================================================ */

.form-error {
  color: var(--status-error);
  font-size: var(--text-sm);
  margin-top: var(--space-1);
  display: block;
}

.form-help {
  color: var(--text-hint);
  font-size: var(--text-sm);
  margin-top: var(--space-1);
  display: block;
}

.form-success {
  color: var(--status-success);
  font-size: var(--text-sm);
  margin-top: var(--space-1);
  display: block;
}

.password-shake {
  animation: password-shake 0.3s ease-in-out;
}

.password-requirements-title {
  margin: var(--space-1) 0 0;
  font-size: var(--text-sm);
  font-weight: var(--font-weight-semibold);
}

.password-requirements {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 var(--space-3);
  margin: var(--space-1) 0 var(--space-4);
  padding-left: 0;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  list-style: none;
}

.password-requirements li:last-child {
  grid-column: 1 / -1;
}

.password-requirement {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  line-height: 1.7;
}

.password-requirement.requirement-met {
  color: var(--secondary-teal);
}

.password-requirement.requirement-unmet {
  color: var(--password-rule-unmet);
  font-weight: var(--font-weight-bold);
}

.requirement-icon {
  width: 1rem;
  flex: 0 0 1rem;
  text-align: center;
}

.password-strength-feedback {
  margin-top: var(--space-1);
}

/* Password validation errors */
.password-validation-errors {
  margin-top: var(--space-2);
}

.password-validation-errors .form-error {
  margin-bottom: var(--space-1);
}

@media (max-width: 420px) {
  .password-requirements {
    grid-template-columns: 1fr;
  }

  .password-requirements li:last-child {
    grid-column: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .password-shake {
    animation: none;
  }
}

/* Validation States */
.field-valid {
  border-color: var(--status-success);
}

.field-invalid {
  border-color: var(--status-error);
}

.field-warning {
  border-color: var(--status-warning);
}

/* ============================================================================
   AUTH SPECIFIC BUTTONS
   ============================================================================ */

.auth-submit-btn {
  width: 100%;
  padding: var(--space-4);
  font-size: var(--text-base);
  font-weight: var(--font-weight-medium);
  border-radius: var(--radius-md);
  transition: all var(--transition-base);
  margin-bottom: var(--space-4);
}

.auth-submit-btn:hover {
  transform: translateY(-1px);
}

.auth-submit-btn:active {
  transform: translateY(0);
}

/* Secondary Auth Actions */
.auth-link {
  color: var(--bs-primary);
  text-decoration: none;
  font-size: var(--text-sm);
  transition: color var(--transition-base);
}

.auth-link:hover {
  color: var(--secondary-indigo);
  text-decoration: underline;
}

/* Form-wide elements */
.auth-form .form-full-width {
  width: 100%;
}

.auth-divider {
  text-align: center;
  margin: var(--space-5) 0;
  position: relative;
  color: var(--text-hint);
  font-size: var(--text-sm);
}

.auth-divider::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background-color: var(--border-light);
  z-index: 1;
}

.auth-divider span {
  background-color: var(--surface-secondary);
  padding: 0 var(--space-4);
  position: relative;
  z-index: 2;
}

/* ============================================================================
   LOADING AND DISABLED STATES
   ============================================================================ */

.auth-loading {
  opacity: 0.6;
  pointer-events: none;
  position: relative;
}

.auth-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid var(--border-light);
  border-top-color: var(--bs-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================================================
   RESPONSIVE DESIGN
   ============================================================================ */

@media (max-width: 768px) {
  .auth-container {
    padding: var(--space-2);
  }

  .auth-card {
    max-width: 100%;
  }

  .auth-card-header,
  .auth-card-body {
    padding: var(--space-4);
  }

  .auth-brand-title {
    font-size: var(--text-xl);
  }

  .social-auth-button {
    padding: var(--space-3);
    font-size: var(--text-base);
  }

  .auth-form .form-control {
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-base);
  }

  .auth-submit-btn {
    padding: var(--space-3);
    font-size: var(--text-base);
  }
}

/* ============================================================================
   HIGH CONTRAST MODE SUPPORT
   ============================================================================ */

@media (prefers-contrast: high) {
  .auth-card {
    border: 2px solid var(--text-primary);
  }

  .social-auth-button {
    border-width: 2px;
  }

  .form-control {
    border-width: 2px;
  }
}

/* ============================================================================
   PRINT STYLES
   ============================================================================ */

@media print {
  .auth-container {
    background: white;
    min-height: auto;
  }

  .auth-card {
    box-shadow: none;
    border: 1px solid #000;
  }

  .social-auth-button,
  .auth-submit-btn {
    border: 1px solid #000;
    background: white;
    color: black;
  }
}
