/* =========================================================
   پاپ‌آپ ورود/ثبت‌نام با شماره موبایل — هم‌زبان طراحی سایت
   از تگ بومی <dialog> استفاده می‌کنه: فوکوس‌تراپ و بستن با Esc
   رایگان از خود مرورگر میاد، رنگ‌ها از متغیرهای قالب می‌خونه
   تا با تغییر پالت رنگ سایت خودکار هماهنگ بمونه.
   ========================================================= */

html body dialog#sg-otp-dialog {
    /* ریست کامل استایل پیش‌فرض مرورگر برای dialog — بدون این، رنگ متن و پس‌زمینه‌ی
       پیش‌فرض مرورگر (که تیره‌ست) روی متن ما می‌افته و متن خوانا نمی‌مونه */
    border: none;
    padding: 0;
    background: transparent;
    color: #1A1A1A;
    max-width: none;
    max-height: none;
    width: auto;
    overflow: visible;
    box-shadow: none;
}
html body dialog#sg-otp-dialog::backdrop {
    background: rgba(26, 20, 15, 0.55);
}

html body dialog#sg-otp-dialog.sg-otp-modal {
    /* باید fixed بمونه.
       مرورگر برای dialog باز‌شده با showModal() خودش position: fixed می‌ذاره و
       با inset:0 + margin:auto وسط پنجره‌ی دید نگهش می‌داره. قبلاً اینجا
       position: relative بود که اون رفتار رو خنثی می‌کرد و پاپ‌آپ می‌رفت
       بالای سند — یعنی اگه کاربر پایین صفحه بود اصلاً نمی‌دیدش. */
    position: fixed;
    inset: 0;
    margin: auto;
    height: fit-content;
    max-height: min(90vh, 90dvh);
    overflow-y: auto;
    width: min(400px, calc(100vw - 2rem));
    background: #FFFFFF;
    background-color: #FFFFFF;
    border-top: 3px solid var(--sg-gold, #C5A059);
    border-radius: 16px;
    padding: 2rem 1.6rem 1.5rem;
    box-sizing: border-box;
    box-shadow: 0 24px 60px rgba(26, 20, 15, 0.3);
    text-align: center;
    font-family: var(--sg-font-body, 'Kalameh', 'Vazirmatn', sans-serif);
    color: #1A1A1A;
    direction: rtl;
    margin: auto;
}

/* -------- دکمه بستن -------- */
html body #sg-otp-dialog .sg-otp-close {
    position: absolute;
    top: 12px;
    left: 14px;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    border-radius: 8px;
    font-size: 1.5rem;
    line-height: 1;
    color: #999;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease;
}
html body #sg-otp-dialog .sg-otp-close:hover {
    background: var(--sg-champagne, #F2EEE9);
    color: var(--sg-black, #1A1A1A);
}

/* -------- لوگوی سایت بالای پاپ‌آپ -------- */
html body #sg-otp-dialog .sg-otp-logo {
    display: flex;
    justify-content: center;
    margin: 0 0 0.9rem;
}
html body #sg-otp-dialog .sg-otp-logo img {
    width: 48px;
    height: 48px;
    object-fit: contain;
}

/* -------- نشانگر مرحله (۳ نقطه) -------- */
html body #sg-otp-dialog .sg-otp-steps-indicator {
    display: flex;
    justify-content: center;
    gap: 0.45rem;
    margin: 0 0 1.1rem;
}
html body #sg-otp-dialog .sg-otp-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--sg-champagne, #E8DFCE);
    transition: background-color 0.25s ease, transform 0.25s ease;
}
html body #sg-otp-dialog .sg-otp-dot.is-active {
    background: var(--sg-gold, #C5A059);
    transform: scale(1.35);
}

/* -------- عناوین و توضیح -------- */
html body #sg-otp-dialog h3 {
    margin: 0 0 0.5rem;
    font-size: 1.2rem;
    font-weight: 600;
    color: #1A1A1A;
    font-family: var(--sg-font-body, 'Kalameh', 'Vazirmatn', sans-serif);
}
html body #sg-otp-dialog .sg-otp-sub {
    margin: 0 0 1.2rem;
    font-size: 0.85rem;
    color: #6b6258;
    line-height: 1.8;
}

/* -------- فرم هر مرحله -------- */
html body #sg-otp-dialog .sg-otp-step {
    display: block;
}
/* لیبل فقط برای صفحه‌خوان — بصری حذف شده چون متن هر مرحله خودش گویاست
   و باکس رو شلوغ می‌کرد، ولی برای دسترسی‌پذیری باید توی DOM بمونه */
html body #sg-otp-dialog .sg-otp-sronly {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* -------- ورودی‌ها -------- */
html body #sg-otp-dialog .sg-otp-input {
    display: block;
    width: 100%;
    box-sizing: border-box;
    height: 46px;
    border: 1px solid var(--sg-champagne, #E8DFCE);
    border-radius: 8px;
    padding: 0 14px;
    font-size: 0.95rem;
    font-family: var(--sg-font-body, 'Vazirmatn', sans-serif);
    color: #1A1A1A;
    background: #FFFFFF;
    margin-bottom: 0.75rem;
    outline: none;
    text-align: center;
    transition: border-color 0.2s ease;
}
html body #sg-otp-dialog .sg-otp-input:focus-visible {
    border-color: var(--sg-gold, #C5A059);
    outline: 2px solid var(--sg-gold, #C5A059);
    outline-offset: 1px;
}
html body #sg-otp-dialog .sg-otp-input--code {
    letter-spacing: 0.55em;
    font-size: 1.3rem;
    font-weight: 700;
    /* برای اینکه letter-spacing جای خالی راست‌چین اضافه نکنه بعد از آخرین رقم */
    text-indent: 0.55em;
}

/* -------- دکمه‌ی اصلی هر مرحله -------- */
html body #sg-otp-dialog .sg-otp-btn {
    display: block;
    width: 100%;
    height: 46px;
    background-color: #2B2420;
    color: #C5A059;
    border: 1px solid #2B2420;
    border-radius: 8px;
    font-size: 0.92rem;
    font-weight: 600;
    font-family: var(--sg-font-body, 'Vazirmatn', sans-serif);
    cursor: pointer;
    transition: background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease;
    margin-bottom: 0.6rem;
}
html body #sg-otp-dialog .sg-otp-btn:hover {
    background-color: #C5A059;
    color: #1A1A1A;
    border-color: #C5A059;
}
html body #sg-otp-dialog .sg-otp-btn:focus-visible {
    outline: 2px solid var(--sg-gold, #C5A059);
    outline-offset: 2px;
}
html body #sg-otp-dialog .sg-otp-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* -------- لینک ارسال دوباره -------- */
html body #sg-otp-dialog .sg-otp-link {
    background: none;
    border: none;
    color: #9E7B3B;
    font-size: 0.8rem;
    font-family: var(--sg-font-body, 'Vazirmatn', sans-serif);
    cursor: pointer;
    text-decoration: underline;
    padding: 0.4rem;
}
html body #sg-otp-dialog .sg-otp-link:focus-visible {
    outline: 2px solid var(--sg-gold, #C5A059);
    outline-offset: 1px;
}
html body #sg-otp-dialog .sg-otp-link:disabled {
    color: #ccc;
    cursor: not-allowed;
    text-decoration: none;
}

/* -------- پیام خطا -------- */
html body #sg-otp-dialog .sg-otp-error {
    color: #C0392B;
    font-size: 0.8rem;
    margin: 0.5rem 0 0;
    min-height: 1.2em;
}

/* -------- موبایل -------- */
@media only screen and (max-width: 480px) {
    html body dialog#sg-otp-dialog.sg-otp-modal {
        max-width: 100%;
        padding: 2.2rem 1.4rem 1.5rem;
    }
}

/* =========================================================
   عناصر جدید: پیام خوشامد، دکمه‌های ثانویه، صفحه‌ی موفقیت
   ========================================================= */

/* -------- نوار «خوشحالیم که برگشتید» برای کاربر قدیمی -------- */
html body #sg-otp-dialog .sg-otp-welcome {
    margin: 0 0 1rem;
    padding: 0.5rem 0.8rem;
    background: #FAF6EE;
    border-right: 2px solid #C5A059;
    border-radius: 8px;
    color: #6b5836;
    font-size: 0.8rem;
    line-height: 1.6;
    text-align: right;
}

/* -------- ردیف دکمه‌های ثانویه (تغییر شماره / ارسال دوباره) -------- */
html body #sg-otp-dialog .sg-otp-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-top: 0.15rem;
}
html body #sg-otp-dialog .sg-otp-actions .sg-otp-link {
    flex: 0 0 auto;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s ease, color 0.2s ease;
}
html body #sg-otp-dialog .sg-otp-actions .sg-otp-link:hover:not(:disabled) {
    border-bottom-color: #9E7B3B;
}

/* -------- صفحه‌ی موفقیت -------- */
html body #sg-otp-dialog .sg-otp-step--done {
    padding: 0.5rem 0 0.8rem;
}
html body #sg-otp-dialog .sg-otp-check {
    display: flex;
    justify-content: center;
    margin-bottom: 1rem;
    color: #C5A059;
}
html body #sg-otp-dialog .sg-otp-check-circle {
    stroke-dasharray: 145;
    stroke-dashoffset: 145;
    animation: sgOtpDrawCircle 0.5s ease-out forwards;
}
html body #sg-otp-dialog .sg-otp-check-mark {
    stroke-dasharray: 36;
    stroke-dashoffset: 36;
    animation: sgOtpDrawMark 0.3s ease-out 0.4s forwards;
}
@keyframes sgOtpDrawCircle {
    to { stroke-dashoffset: 0; }
}
@keyframes sgOtpDrawMark {
    to { stroke-dashoffset: 0; }
}

/* ورود نرم خود پاپ‌آپ */
html body dialog#sg-otp-dialog[open] {
    animation: sgOtpFadeIn 0.22s ease-out both;
}
@keyframes sgOtpFadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* احترام به ترجیح کاربر برای حذف انیمیشن */
@media (prefers-reduced-motion: reduce) {
    html body dialog#sg-otp-dialog[open],
    html body #sg-otp-dialog .sg-otp-check-circle,
    html body #sg-otp-dialog .sg-otp-check-mark {
        animation: none !important;
    }
    html body #sg-otp-dialog .sg-otp-check-circle,
    html body #sg-otp-dialog .sg-otp-check-mark {
        stroke-dashoffset: 0 !important;
    }
}

/* راهنمای زمان انتظار پیامک — ظریف، فقط برای اطمینان دادن به کاربر */
html body #sg-otp-dialog .sg-otp-hint {
    margin: 0.15rem 0 0;
    font-size: 0.72rem;
    color: #8a8078;
    line-height: 1.6;
}
