/*
 * Authentication UI Styles
 * Centered card layout with tab toggle
 * Design spec: BRE-121
 */

/* ================================================================
   Page Layout
   ================================================================ */

.auth-page {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 3rem 1rem;
  animation: authFadeIn 0.5s ease-out;
}

.auth-outer {
  width: 100%;
  max-width: 700px;
}

@keyframes authFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ================================================================
   Brand (Logo + Name + Tagline)
   ================================================================ */

.auth-brand {
  text-align: center;
  margin-bottom: 2rem;
}

.auth-brand-logo {
  display: inline-block;
  font-size: 2.5rem;
  text-decoration: none;
  line-height: 1;
}

.auth-brand-name {
  font-family: 'Instrument Sans', sans-serif;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0.5rem 0 0.25rem;
}

.auth-brand-tagline {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin: 0;
}

/* ================================================================
   Card
   ================================================================ */

.auth-card {
  max-width: 480px;
  margin: 0 auto;
  background: var(--card-bg);
  border-radius: 12px;
  border: 1px solid var(--border-input);
  padding: 36px;
}

.auth-card-header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.auth-card-header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 0.5rem;
}

.auth-card-header p {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  margin: 0;
}

/* ================================================================
   Tab Toggle
   ================================================================ */

.auth-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 1.5rem;
}

.auth-tab {
  flex: 1;
  padding: 0 0 0.75rem;
  font-size: 0.9375rem;
  font-weight: 400;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
  font-family: inherit;
}

.auth-tab:hover:not(.active) {
  color: var(--text-secondary);
}

.auth-tab.active {
  color: var(--text-primary);
  font-weight: 600;
  border-bottom-color: var(--accent-hover);
}

.auth-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: 4px 4px 0 0;
}

/* ================================================================
   Tab Panels
   ================================================================ */

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

/* ================================================================
   Form Styles
   ================================================================ */

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Form Fields */
.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.form-field label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
}

.form-field input {
  width: 100%;
  height: 48px;
  padding: 0 1rem;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text-primary);
  background: transparent;
  border: 1px solid var(--border-input);
  border-radius: 8px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  box-sizing: border-box;
}

.form-field input::placeholder {
  color: var(--text-muted);
}

.form-field input:hover {
  border-color: var(--text-muted);
}

.form-field input:focus {
  outline: none;
  border-color: var(--accent-hover);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Error State */
.form-field.has-error input {
  border-color: #EF4444;
}

.form-field.has-error input:focus {
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.form-error {
  font-size: 0.8125rem;
  color: #EF4444;
  display: none;
}

.form-field.has-error .form-error {
  display: block;
}

/* Success State */
.form-field.has-success input {
  border-color: var(--status-success);
}

/* ================================================================
   Forgot Password Link
   ================================================================ */

.form-help {
  text-align: right;
  margin-top: -0.5rem;
}

.forgot-password-link {
  font-size: 0.8125rem;
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s ease;
}

.forgot-password-link:hover {
  color: var(--accent-hover);
}

/* ================================================================
   Form Button
   ================================================================ */

.form-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  height: 48px;
  font-size: 0.9375rem;
  font-weight: 600;
  font-family: inherit;
  color: white;
  background: var(--accent-hover);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.1s ease;
  margin-top: 0.25rem;
}

.form-button:hover {
  opacity: 0.9;
}

.form-button:active {
  transform: scale(0.98);
}

.form-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.form-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ================================================================
   Loading Spinner
   ================================================================ */

.spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: none;
}

.form-button.is-loading .spinner {
  display: block;
}

.form-button.is-loading .button-text {
  display: none;
}

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

/* Large spinner (reset password loading state) */
.spinner-large {
  width: 2rem;
  height: 2rem;
  border: 2px solid var(--border-default);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin: 0 auto 1rem;
}

/* ================================================================
   Alert Messages
   ================================================================ */

.alert {
  padding: 0.875rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1.5;
  display: none;
  margin-bottom: 1rem;
}

.alert.is-visible {
  display: block;
}

.alert-success {
  background: rgba(16, 185, 129, 0.06);
  color: var(--status-success-text);
  border: 1px solid rgba(16, 185, 129, 0.15);
}

.alert-error {
  background: rgba(239, 68, 68, 0.04);
  color: #B91C1C;
  border: none;
  border-left: 3px solid #EF4444;
}

.alert-error.is-visible {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
}

.alert-error.is-visible::before {
  content: '';
  width: 1.125rem;
  height: 1.125rem;
  flex-shrink: 0;
  margin-top: 1px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23EF4444' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z'/%3E%3Cline x1='12' y1='9' x2='12' y2='13'/%3E%3Cline x1='12' y1='17' x2='12.01' y2='17'/%3E%3C/svg%3E") center/contain no-repeat;
}

.error-action-link {
  display: block;
  margin-top: 0.5rem;
  font-size: 0.8125rem;
  color: #B91C1C;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.error-action-link:hover {
  color: #991B1B;
}

.alert-info {
  background: var(--surface-subtle);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
}

/* ================================================================
   Password Requirements
   ================================================================ */

.password-requirements {
  margin-top: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--surface-subtle);
  border: 1px solid var(--border-input);
  border-radius: 8px;
  font-size: 0.8125rem;
}

.password-requirements p {
  margin: 0 0 0.5rem 0;
  color: var(--text-secondary);
  font-weight: 500;
}

.password-requirements ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.password-requirements li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
  transition: color 0.2s ease;
}

.password-requirements li.is-valid {
  color: var(--status-success-text);
}

.password-requirements li .check-icon {
  width: 0.875rem;
  height: 0.875rem;
  flex-shrink: 0;
}

.password-requirements li .check-icon svg {
  width: 100%;
  height: 100%;
}

/* ================================================================
   Auth Terms
   ================================================================ */

.auth-terms {
  text-align: center;
  margin-top: 1.25rem;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.auth-terms a {
  color: var(--text-secondary);
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color 0.2s ease;
}

.auth-terms a:hover {
  color: var(--text-primary);
}

/* ================================================================
   Auth Back Link
   ================================================================ */

.auth-back {
  text-align: center;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border-subtle);
}

.auth-back a {
  font-size: 0.875rem;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.2s ease;
}

.auth-back a:hover {
  color: var(--text-primary);
}

/* ================================================================
   Reset Password States
   ================================================================ */

.auth-loading {
  text-align: center;
  padding: 2rem 0;
}

.auth-loading p {
  color: var(--text-secondary);
  font-size: 0.9375rem;
}

.auth-error-state {
  text-align: center;
}

.reset-email-info {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9375rem;
  margin-bottom: 1.5rem;
}

/* ================================================================
   Header Auth Links (used on non-auth pages)
   ================================================================ */

.nav-auth {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.nav-auth .nav-link-login {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.3s ease;
}

.nav-auth .nav-link-login:hover {
  color: var(--text-primary);
}

.nav-auth .nav-link-logout {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
  transition: color 0.3s ease;
}

.nav-auth .nav-link-logout:hover {
  color: var(--text-primary);
}

/* ================================================================
   Auth Visibility Classes (global — used by auth.js)
   ================================================================ */

.auth-only {
  display: none;
}

.guest-only {
  display: flex;
}

body.is-authenticated .auth-only {
  display: flex;
}

body.is-authenticated .guest-only {
  display: none;
}

/* ================================================================
   Dark Mode
   ================================================================ */

[data-theme="dark"] .auth-card {
  border-color: var(--border-default);
}

[data-theme="dark"] .alert-error {
  background: rgba(239, 68, 68, 0.08);
  color: #FCA5A5;
  border-left-color: #F87171;
}

[data-theme="dark"] .alert-error.is-visible::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23F87171' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z'/%3E%3Cline x1='12' y1='9' x2='12' y2='13'/%3E%3Cline x1='12' y1='17' x2='12.01' y2='17'/%3E%3C/svg%3E");
}

[data-theme="dark"] .form-field.has-error input {
  border-color: #F87171;
}

[data-theme="dark"] .form-field.has-error input:focus {
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.15);
}

[data-theme="dark"] .form-error {
  color: #FCA5A5;
}

[data-theme="dark"] .error-action-link {
  color: #FCA5A5;
}

[data-theme="dark"] .error-action-link:hover {
  color: #FECACA;
}

[data-theme="dark"] .form-button {
  background: var(--accent);
}

[data-theme="dark"] .password-requirements {
  border-radius: 8px;
}

/* ================================================================
   Responsive
   ================================================================ */

@media (max-width: 540px) {
  .auth-page {
    padding: 2rem 1rem;
  }

  .auth-card {
    padding: 24px;
    border-radius: 8px;
  }

  .auth-brand-logo {
    font-size: 2rem;
  }

  .auth-brand-name {
    font-size: 1.125rem;
  }

  .auth-card-header h1 {
    font-size: 1.25rem;
  }

  .form-field input {
    height: 44px;
  }

  .form-button {
    height: 44px;
  }
}
