/* ═══════════════════════════════════════════════════════════════
   login-modal.css — جریان ورود/ثبت‌نام (AJAX)
     • auth-page-* : فرم درون‌صفحه‌ای صفحهٔ /accounts/
     • auth-modal-* : مودال روی سایر صفحات + کنترل‌های مشترک فرم
   کنترل‌های auth-modal__* عمداً مشترک‌اند تا هر دو حالت یکسان دیده شوند.
   ═══════════════════════════════════════════════════════════════ */

/* ── صفحهٔ /accounts/ ──
   مقصد LOGIN_URL و صفحهٔ فرود لینک‌های بدون جاوااسکریپت. فرم در
   وسط صفحه و بدون لایهٔ مودال رندر می‌شود.

   چیدمان عمودی بر پایهٔ سه چیز است و باید با هم هماهنگ بمانند:
     ۱) هدر fixed است و در جریان صفحه جایی نمی‌گیرد ⇒ padding-top دقیقاً
        به اندازهٔ ارتفاع هدر است (نه بیشتر، وگرنه کارت پایین می‌افتد).
     ۲) در موبایل نوار پایین هم fixed است ⇒ از ارتفاع مفید کم می‌شود.
     ۳) padding بالا و پایین برابر است ⇒ مرکز کارت دقیقاً روی مرکز
        ناحیهٔ قابل دید می‌افتد.
   وسط‌چینی با margin:auto انجام می‌شود، نه align-items:center؛ چون
   margin خودکار در حالت سرریز صفر می‌شود و برخلاف center، لبهٔ کارت
   را زیر هدر یا نوار پایین برش نمی‌دهد. */
.auth-page {
  /* هدر در موبایل ۶۰px است ولی متغیر سراسری ۷۰px می‌ماند؛ اینجا هم‌تراز می‌شود */
  --auth-header: var(--header-height);
  /* حداقل فاصلهٔ تنفس بین کارت و هدر/فوتر. clamp یعنی روی صفحه‌های
     بلند فاصله بیشتر می‌شود و روی صفحه‌های کوتاه به ۲۴px جمع می‌شود؛
     بالا و پایین همیشه دقیقاً برابرند چون از یک متغیر مشترک می‌آیند. */
  --auth-gap: clamp(var(--space-lg), 6vh, 72px);

  display: flex;

  /* .site-main یک padding-top سراسری دارد که ارتفاع هدر را دوباره به آن
     اضافه می‌کند؛ اینجا با مقدار متقارن جایگزین می‌شود. */
  padding-top: calc(var(--auth-header) + var(--auth-gap));
  padding-bottom: var(--auth-gap);

  /* .site-main به‌صورت پیش‌فرض flex:1 0 auto دارد، یعنی فضای باقیماندهٔ
     بدنه را می‌گیرد و دقیقاً بین هدر و فوتر/نوار پایین می‌نشیند.
     برای همین کافی است min-height را صفر کنیم تا flex خودش ارتفاع درست
     را بدهد؛ این کار هم padding-bottom بدنه (نوار پایین موبایل) و هم
     فوتر را درست در محاسبهٔ مرکزیت لحاظ می‌کند. */
  min-height: 0;

  background:
    radial-gradient(ellipse 60% 45% at 50% 0%, var(--gold-glow), transparent 70%);
}

/* .container حلقهٔ میانی است و باید کل ارتفاع را بگیرد تا فرزندش
   بتواند در راستای عمودی خودکار وسط بنشیند. */
.auth-page > .container {
  display: flex;
  flex: 1;
}

.auth-page__wrap {
  width: 100%;
  max-width: 27rem;
  /* auto در هر دو محور: افقی و عمودی. در نبود فضای آزاد صفر می‌شود. */
  margin: auto;
}

/* در موبایل هدر ۶۰px است (main.css ارتفاع را عوض می‌کند ولی متغیر را نه) */
@media (max-width: 767px) {
  .auth-page { --auth-header: 60px; }
}

.auth-page__wrap {
  width: 100%;
  max-width: 27rem;
  /* auto در هر دو محور: افقی و عمودی. در نبود فضای آزاد صفر می‌شود. */
  margin: auto;
}

.auth-page__card {
  position: relative;
  overflow: hidden;
  padding: clamp(var(--space-lg), 4vw, var(--space-xl)) clamp(var(--space-md), 4vw, var(--space-xl)) var(--space-lg);
  background: var(--bg-card, #fff);
  border: 2px solid var(--border-gold);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  animation: authPageIn 0.4s var(--transition-bounce);
}

@keyframes authPageIn {
  from { opacity: 0; transform: translateY(18px) scale(0.985); }
  to   { opacity: 1; transform: none; }
}

/* نوار طلایی بالای کارت */
.auth-page__glow {
  position: absolute;
  top: 0;
  inset-inline: 0;
  height: 4px;
  background: linear-gradient(90deg, transparent, var(--gold-500), transparent);
}

.auth-page__head {
  text-align: center;
  margin-bottom: var(--space-lg);
}

.auth-page__logo {
  display: flex;
  justify-content: center;
  margin-bottom: var(--space-md);
}

.auth-page__title {
  font-size: clamp(1.2rem, 3.4vw, 1.4rem);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-2xs);
}

.auth-page__subtitle {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.auth-page__note {
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px dashed var(--border-gold);
  font-size: 0.6875rem;
  line-height: 1.9;
  color: var(--text-muted);
  text-align: center;
}

/* ── موبایل ──
   فقط فاصلهٔ افقی و تراکم داخلی کم می‌شود؛ ارتفاع و وسط‌چینی دست‌نخورده
   می‌ماند تا فاصلهٔ بالا و پایین برابر بماند. */
@media (max-width: 480px) {
  .auth-page__card {
    padding: var(--space-lg) var(--space-md) var(--space-md);
    border-radius: var(--radius-lg);
  }

  .auth-page__head { margin-bottom: var(--space-md); }
  .auth-page__note { font-size: 0.625rem; margin-top: var(--space-sm); padding-top: var(--space-sm); }
}

/* ── فضای عمودی کوتاه (چرخش گوشی، لپ‌تاپ کم‌ارتفاع) ──
   اینجا کارت در یک صفحه جا نمی‌شود، پس وسط‌چینی معنا ندارد؛ تراکم
   کم می‌شود و صفحه اسکرول می‌خورد. margin:auto خودکار در نبود فضای
   آزاد صفر می‌شود، پس لبهٔ کارت زیر هدر یا نوار پایین برش نمی‌خورد. */
@media (max-height: 640px) {
  .auth-page { --auth-gap: var(--space-md); }

  .auth-page__head { margin-bottom: var(--space-md); }
  .auth-page__logo { display: none; }
  .auth-page__note { display: none; }
}

/* حالت افقیِ موبایل: هدر و نوار پایین فضای زیادی می‌گیرند */
@media (max-height: 500px) and (orientation: landscape) {
  .auth-page { --auth-gap: var(--space-sm); }
  .auth-page__card { padding: var(--space-md); }
  .auth-page__title { font-size: 1.05rem; }
}

.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
  visibility: hidden;
  pointer-events: none;
}

.auth-modal.is-open {
  visibility: visible;
  pointer-events: auto;
}

/* ── Overlay ── */
.auth-modal__overlay {
  position: absolute;
  inset: 0;
  background: var(--bg-overlay, rgba(0, 0, 0, 0.6));
  backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 0.25s ease;
}

.auth-modal.is-open .auth-modal__overlay { opacity: 1; }

/* ── Dialog ── */
.auth-modal__dialog {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: calc(100vh - 2 * var(--space-md));
  overflow-y: auto;
  background: var(--bg-card, #fff);
  border: 2px solid var(--border-gold);
  border-radius: var(--radius-xl);
  padding: var(--space-xl) var(--space-lg) var(--space-lg);
  box-shadow: var(--shadow-xl);
  opacity: 0;
  transform: translateY(24px) scale(0.97);
  transition: opacity 0.25s ease, transform 0.3s var(--transition-bounce);
}

.auth-modal.is-open .auth-modal__dialog {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.auth-modal__dialog::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(to right, transparent, var(--gold-500), transparent);
}

.auth-modal__close {
  position: absolute;
  top: var(--space-md);
  left: var(--space-md);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  background: var(--bg-inset);
  border: 1px solid var(--border-light);
  transition: var(--transition);
}

.auth-modal__close:hover {
  color: var(--gold-600);
  border-color: var(--border-gold);
  transform: rotate(90deg);
}

/* ── Head ── */
.auth-modal__head {
  text-align: center;
  margin-bottom: var(--space-lg);
}

.auth-modal__title {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.auth-modal__subtitle {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* ── Body / step ── */
.auth-modal__body { width: 100%; }

/* ── Phone field ── */
.auth-modal__label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 0.375rem;
}

.auth-modal__input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.auth-modal__input-icon {
  position: absolute;
  right: 1rem;
  display: flex;
  pointer-events: none;
  color: var(--gold-500);
  transition: color 0.2s;
}

.auth-modal__input-wrap:focus-within .auth-modal__input-icon { color: var(--gold-600); }

.auth-modal__input {
  width: 100%;
  padding: 0.875rem 3rem 0.875rem 1rem;
  border: 2px solid var(--border-input);
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-family: var(--font-body);
  background: var(--bg-input);
  color: var(--text-primary);
  transition: all 0.2s;
}

.auth-modal__input::placeholder { color: var(--text-placeholder); }

.auth-modal__input:focus {
  outline: none;
  border-color: var(--gold-500);
  box-shadow: 0 0 0 3px var(--gold-glow);
}

/* ── Error ── */
.auth-modal__error {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: var(--danger);
  margin-top: 0.5rem;
  animation: authErrorIn 0.25s ease both;
}

@keyframes authErrorIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Submit ── */
.auth-modal__submit {
  position: relative;
  overflow: hidden;
  width: 100%;
  margin-top: var(--space-md);
  padding: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: linear-gradient(135deg, var(--dark-jade), var(--light-jade));
  color: var(--text-light);
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 15px var(--gold-glow);
  transition: all 0.2s;
}

.auth-modal__submit::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.12), transparent);
  transition: left 0.5s ease;
}

.auth-modal__submit:hover:not(:disabled)::before { left: 100%; }

.auth-modal__submit:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

.auth-modal__submit.is-loading .auth-modal__btn-label { opacity: 0.75; }

.auth-modal__spinner {
  width: 18px;
  height: 18px;
  animation: authSpin 0.9s linear infinite;
}

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

/* ── Hint ── */
.auth-modal__hint {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-top: 0.75rem;
}

/* ── Step 2 ── */
.auth-modal__phone {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8125rem;
  margin-bottom: var(--space-md);
}

.auth-modal__phone-number {
  direction: ltr;
  display: inline-block;
  color: var(--gold-600);
  font-weight: 700;
  background: var(--gold-glow);
  border: 1px dashed var(--gold-500);
  border-radius: var(--radius-full);
  padding: 0.125rem 0.625rem;
  letter-spacing: 0.05em;
}

/* ── OTP boxes ──
   استایل کامل و مستقل (نه وابسته به auth.css که فقط در صفحات
   login/verify لود می‌شود) تا ورودی‌ها همه‌جا افقی و یک‌شکل باشند. */
.auth-modal__otp {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, 1.8vw, 10px);
  direction: ltr;
  margin-bottom: var(--space-md);
}

.auth-modal__otp-box {
  flex: 1 1 0;
  min-width: 0;
  max-width: 56px;
  height: clamp(52px, 13vw, 64px);
  padding: 0;
  border: 2px solid var(--border-input, #e5e7eb);
  border-radius: var(--radius-md);
  background: var(--bg-input, #fff);
  color: var(--text-primary, #2d2d2d);
  font-family: var(--font-body);
  font-size: clamp(1.25rem, 4.6vw, 1.6rem);
  font-weight: 700;
  line-height: 1;
  text-align: center;
  outline: none;
  appearance: none;
  -moz-appearance: textfield;
  transition: border-color 0.2s ease, box-shadow 0.2s ease,
              transform 0.2s ease, background 0.2s ease;
}

.auth-modal__otp-box:focus {
  border-color: var(--gold-500, #cfa434);
  background: var(--bg-card, #fff);
  box-shadow: 0 0 0 4px var(--gold-glow, rgba(207, 164, 52, 0.15));
  transform: translateY(-2px);
}

.auth-modal__otp-box.filled {
  border-color: var(--gold-500, #cfa434);
  background: var(--gold-glow, rgba(207, 164, 52, 0.15));
  color: var(--gold-600, #b8962e);
  animation: authOtpPop 0.18s ease;
}

.auth-modal__otp-box:-webkit-autofill,
.auth-modal__otp-box:-webkit-autofill:hover,
.auth-modal__otp-box:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text-primary, #2d2d2d);
  -webkit-box-shadow: 0 0 0 1000px var(--bg-input, #fff) inset;
  transition: background-color 9999s ease-in-out 0s;
}

@keyframes authOtpPop {
  50% { transform: scale(1.08); }
}

/* ── Resend row ── */
.auth-modal__resend {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: 2px dashed var(--border-gold);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.auth-modal__timer strong { color: var(--gold-600); font-weight: 700; }

.auth-modal__resend-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: transparent;
  border: 1px solid var(--border-gold);
  color: var(--gold-600);
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.4rem 1rem;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.2s;
}

.auth-modal__resend-btn:hover:not(:disabled) { background: var(--gold-glow); }
.auth-modal__resend-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.auth-modal__edit-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-full);
  transition: all 0.2s;
}

.auth-modal__edit-btn:hover { color: var(--gold-600); background: var(--gold-glow); }

/* قفل موقت «ویرایش شماره» روی موبایل — جلوی تاپ تصادفی را می‌گیرد */
.auth-modal__edit-btn--locked,
.auth-modal__edit-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background: transparent;
  color: var(--text-muted);
}

.auth-modal__edit-btn--locked:hover,
.auth-modal__edit-btn:disabled:hover { color: var(--text-muted); background: transparent; }

/* ── Shake ── */
.auth-modal.is-shake .auth-modal__dialog,
.auth-page__card.is-shake { animation: authShake 0.4s ease; }

@keyframes authShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* ── Mobile ── */
@media (max-width: 576px) {
  .auth-modal { padding: var(--space-sm); align-items: flex-end; }

  .auth-modal__dialog {
    padding: var(--space-lg) var(--space-md) var(--space-md);
    border-radius: var(--radius-lg);
    max-width: 100%;
  }

  .auth-modal__title { font-size: 1.15rem; }
}
