/* ============================================================
   AUTH PAGES — Shared Stylesheet
   Modern SaaS auth: centered card, subtle background, clean form.
   ============================================================ */

/* --- Background --- */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px 16px;
  background: #f0f2f5;
  position: relative;
  overflow: hidden;
}

.auth-page::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 50% at 20% 0%, rgba(67,97,238,.06) 0%, transparent 70%),
    radial-gradient(ellipse 50% 60% at 80% 100%, rgba(118,75,162,.05) 0%, transparent 70%);
  pointer-events: none;
}

/* --- Card --- */
.auth-card {
  position: relative;
  width: 100%;
  max-width: 440px;
  background: #fff;
  border-radius: 16px;
  box-shadow:
    0 1px 3px rgba(0,0,0,.04),
    0 6px 24px rgba(0,0,0,.06);
  padding: 40px 36px;
  z-index: 1;
}

.auth-card-register {
  max-width: 760px;
  padding: 30px 32px;
}

/* --- Logo / Brand --- */
.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 32px;
}

.auth-brand-logo {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  object-fit: contain;
  margin-bottom: 20px;
}

.auth-brand h1 {
  font-size: 20px;
  font-weight: 700;
  color: #111827;
  letter-spacing: -.02em;
  margin: 0 0 4px;
}

.auth-brand p {
  font-size: 14px;
  color: #6b7280;
  margin: 0;
}

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

.auth-form .auth-fields {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.auth-form-register .auth-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 18px;
}

.auth-form-register .auth-field-full {
  grid-column: 1 / -1;
}

.auth-form-register .auth-btn-primary {
  width: auto;
  min-width: 180px;
  height: 42px;
  margin: 18px 0 0 auto;
}

[dir="rtl"] .auth-form-register .auth-btn-primary {
  margin-right: auto;
  margin-left: 0;
}

/* --- Field --- */
.auth-field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 6px;
}

.auth-field .auth-input-wrap {
  position: relative;
}

.auth-field input[type="text"],
.auth-field input[type="email"],
.auth-field input[type="password"],
.auth-field input[type="tel"] {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  font-size: 14px;
  color: #111827;
  background: #f9fafb;
  transition: border-color .15s, box-shadow .15s, background .15s;
  outline: none;
}

.auth-field input:focus {
  border-color: #4361ee;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(67,97,238,.1);
}

.auth-field input.auth-input-error {
  border-color: #ef4444;
  background: #fef2f2;
}

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

/* Error text */
.auth-error {
  display: block;
  font-size: 12px;
  color: #ef4444;
  margin-top: 4px;
  line-height: 1.4;
}

/* Password toggle */
.auth-pw-toggle {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: 4px;
  color: #9ca3af;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: color .15s;
  line-height: 1;
}

.auth-pw-toggle:hover {
  color: #4b5563;
}

.auth-pw-toggle:focus-visible {
  outline: 2px solid #4361ee;
  outline-offset: 2px;
}

/* RTL: toggle on left */
[dir="rtl"] .auth-pw-toggle {
  right: auto;
  left: 12px;
}

/* --- Row (remember me + forgot) --- */
.auth-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 2px;
}

.auth-remember {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #6b7280;
  cursor: pointer;
  user-select: none;
}

.auth-remember input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: #4361ee;
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
}

.auth-forgot {
  font-size: 13px;
  color: #4361ee;
  text-decoration: none;
  font-weight: 500;
  transition: color .15s;
  white-space: nowrap;
}

.auth-forgot:hover {
  color: #3451d1;
  text-decoration: underline;
}

/* --- Primary button --- */
.auth-btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 46px;
  margin-top: 6px;
  padding: 0 20px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: #4361ee;
  cursor: pointer;
  transition: background .15s, box-shadow .15s, transform .1s;
}

.auth-btn-primary:hover:not(:disabled) {
  background: #3451d1;
  box-shadow: 0 4px 14px rgba(67,97,238,.35);
  transform: translateY(-1px);
}

.auth-btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.auth-btn-primary:disabled {
  opacity: .6;
  cursor: not-allowed;
}

.auth-btn-primary:focus-visible {
  outline: 2px solid #4361ee;
  outline-offset: 2px;
}

.auth-btn-primary .auth-spinner {
  display: none;
}

.auth-btn-primary.is-loading .auth-btn-text {
  display: none;
}

.auth-btn-primary.is-loading .auth-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: auth-spin .6s linear infinite;
}

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

/* --- Secondary button (SMS OTP) --- */
.auth-btn-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 44px;
  margin-top: 10px;
  padding: 0 20px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  color: #374151;
  background: #fff;
  cursor: pointer;
  text-decoration: none;
  transition: border-color .15s, background .15s;
}

.auth-btn-secondary:hover {
  border-color: #4361ee;
  background: #f0f4ff;
}

.auth-btn-secondary:focus-visible {
  outline: 2px solid #4361ee;
  outline-offset: 2px;
}

/* --- Divider --- */
.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 24px 0 20px;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #e5e7eb;
}

.auth-divider span {
  font-size: 12px;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
}

/* --- Social login (placeholder) --- */
.auth-social {
  display: flex;
  gap: 10px;
}

.auth-social-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: #fff;
  font-size: 13px;
  font-weight: 500;
  color: #374151;
  text-decoration: none;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.auth-social-btn:hover {
  border-color: #d1d5db;
  background: #f9fafb;
}

.auth-social-btn:focus-visible {
  outline: 2px solid #4361ee;
  outline-offset: 2px;
}

/* --- Footer link --- */
.auth-footer {
  text-align: center;
  margin-top: 28px;
  font-size: 14px;
  color: #6b7280;
}

.auth-footer a {
  color: #4361ee;
  text-decoration: none;
  font-weight: 600;
}

.auth-footer a:hover {
  text-decoration: underline;
}

.auth-footer a:focus-visible {
  outline: 2px solid #4361ee;
  outline-offset: 2px;
  border-radius: 4px;
}

/* --- Non-field errors --- */
.auth-nonfield-errors {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 10px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  font-size: 13px;
  margin-bottom: 20px;
  line-height: 1.5;
}

.auth-nonfield-errors i {
  margin-top: 2px;
  flex-shrink: 0;
}

/* --- Checkbox row (terms) --- */
.auth-check-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  color: #6b7280;
  line-height: 1.5;
}

.auth-check-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: #4361ee;
  border-radius: 4px;
  cursor: pointer;
  margin-top: 2px;
  flex-shrink: 0;
}

.auth-check-row a {
  color: #4361ee;
  text-decoration: none;
  font-weight: 500;
}

.auth-check-row a:hover {
  text-decoration: underline;
}

body.auth-modal-open {
  overflow: hidden;
}

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

.auth-terms-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, .62);
  backdrop-filter: blur(3px);
}

.auth-terms-dialog {
  width: min(720px, 100%);
  max-height: min(82vh, 760px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: #1f2937;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  box-shadow: 0 24px 64px rgba(15, 23, 42, .28);
}

.auth-terms-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid #e5e7eb;
}

.auth-terms-header h2 {
  margin: 0 0 4px;
  font-size: 17px;
  line-height: 1.5;
}

.auth-terms-header p {
  margin: 0;
  color: #6b7280;
  font-size: 12px;
}

.auth-terms-close {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  padding: 0;
  display: grid;
  place-items: center;
  color: #6b7280;
  background: #f3f4f6;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.auth-terms-content {
  overflow-y: auto;
  padding: 18px 22px;
  text-align: right;
  line-height: 1.9;
  scrollbar-gutter: stable;
}

.auth-terms-content h3 {
  margin: 20px 0 5px;
  font-size: 14px;
  color: #111827;
}

.auth-terms-content h3:first-of-type {
  margin-top: 14px;
}

.auth-terms-content p {
  margin: 0 0 8px;
  color: #4b5563;
  font-size: 13px;
}

.auth-terms-intro {
  padding: 10px 12px;
  background: #f5f7ff;
  border-right: 3px solid #4361ee;
  border-radius: 8px;
}

.auth-terms-footer {
  padding: 12px 20px;
  border-top: 1px solid #e5e7eb;
}

.auth-terms-done {
  min-width: 110px;
  height: 38px;
  padding: 0 16px;
  color: #fff;
  background: #4361ee;
  border: 0;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

/* --- Optional field hint --- */
.auth-optional {
  font-size: 11px;
  color: #9ca3af;
  font-weight: 400;
  margin-left: 4px;
}

[dir="rtl"] .auth-optional {
  margin-left: 0;
  margin-right: 4px;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 480px) {
  .auth-card {
    padding: 32px 20px;
    border-radius: 12px;
  }

  .auth-brand {
    margin-bottom: 28px;
  }

  .auth-brand h1 {
    font-size: 18px;
  }

  .auth-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .auth-social {
    flex-direction: column;
  }
}

@media (max-width: 720px) {
  .auth-card-register {
    max-width: 440px;
  }

  .auth-form-register .auth-fields {
    grid-template-columns: 1fr;
  }

  .auth-form-register .auth-field-full {
    grid-column: auto;
  }

  .auth-form-register .auth-btn-primary {
    width: 100%;
  }
}

/* ============================================================
   RTL SUPPORT
   ============================================================ */
[dir="rtl"] .auth-field input {
  text-align: right;
}

[dir="rtl"] .auth-error {
  text-align: right;
}

/* ============================================================
   DARK MODE SAFEGUARD (prefers-color-scheme)
   ============================================================ */
@media (prefers-color-scheme: dark) {
  .auth-page {
    background: #111827;
  }

  .auth-card {
    background: #1f2937;
    box-shadow:
      0 1px 3px rgba(0,0,0,.2),
      0 6px 24px rgba(0,0,0,.3);
  }

  .auth-brand h1 {
    color: #f9fafb;
  }

  .auth-brand p {
    color: #9ca3af;
  }

  .auth-field label {
    color: #e5e7eb;
  }

  .auth-field input {
    border-color: #374151;
    background: #111827;
    color: #f9fafb;
  }

  .auth-field input:focus {
    background: #1f2937;
  }

  .auth-remember,
  .auth-check-row {
    color: #9ca3af;
  }

  .auth-btn-secondary {
    border-color: #37451;
    background: #111827;
    color: #e5e7eb;
  }

  .auth-divider::before,
  .auth-divider::after {
    background: #374151;
  }

  .auth-nonfield-errors {
    background: #450a0a;
    border-color: #7f1d1d;
    color: #fca5a5;
  }

  .auth-terms-dialog {
    color: #e5e7eb;
    background: #1f2937;
    border-color: #374151;
  }

  .auth-terms-header,
  .auth-terms-footer {
    border-color: #374151;
  }

  .auth-terms-header h2,
  .auth-terms-content h3 {
    color: #f9fafb;
  }

  .auth-terms-header p,
  .auth-terms-content p {
    color: #cbd5e1;
  }

  .auth-terms-close {
    color: #cbd5e1;
    background: #374151;
  }

  .auth-terms-intro {
    background: #111827;
  }
}
