{"error":"\u0644\u0637\u0641\u0627\u064b \u0648\u0627\u0631\u062f \u062d\u0633\u0627\u0628 \u06a9\u0627\u0631\u0628\u0631\u06cc \u062e\u0648\u062f \u0634\u0648\u06cc\u062f"}<!-- ===== REAUTH MODAL NEW ===== -->
<style>
/* === RESET === */
#reauth-root * { box-sizing: border-box; font-family: 'Vazir', Tahoma, Arial, sans-serif !important; }
#reauth-root { direction: rtl; }

/* === OVERLAY === */
.reauth-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2147483647;
    padding: 20px;
    animation: reauth-fade-in 0.3s ease forwards;
}
@keyframes reauth-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* === CARD === */
.reauth-card {
    background: #ffffff;
    border-radius: 28px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    animation: reauth-slide-up 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    position: relative;
}
@keyframes reauth-slide-up {
    from { opacity: 0; transform: translateY(40px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* === HEADER WITH GOLD GRADIENT === */
.reauth-header {
    background: linear-gradient(145deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    padding: 32px 28px 28px;
    text-align: center;
    position: relative;
    overflow: hidden;
}
.reauth-header::before {
    content: '';
    position: absolute;
    top: -60px;
    right: -60px;
    width: 200px;
    height: 200px;
    background: radial-gradient(circle, rgba(201, 144, 43, 0.15) 0%, transparent 70%);
    border-radius: 50%;
}
.reauth-header::after {
    content: '';
    position: absolute;
    bottom: -80px;
    left: -40px;
    width: 180px;
    height: 180px;
    background: radial-gradient(circle, rgba(201, 144, 43, 0.08) 0%, transparent 70%);
    border-radius: 50%;
}
.reauth-gold-line {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #C9902B, #F5C842, #C9902B);
    background-size: 200% 100%;
    animation: gold-shimmer 3s ease-in-out infinite;
}
@keyframes gold-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.reauth-icon-wrap {
    width: 72px;
    height: 72px;
    background: linear-gradient(135deg, rgba(201, 144, 43, 0.25), rgba(245, 200, 66, 0.15));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    position: relative;
    z-index: 1;
    border: 2px solid rgba(201, 144, 43, 0.4);
    box-shadow: 0 8px 32px rgba(201, 144, 43, 0.2);
}
.reauth-icon-wrap i {
    font-size: 30px;
    color: #F5C842;
    filter: drop-shadow(0 2px 8px rgba(201, 144, 43, 0.3));
}
.reauth-title {
    font-size: 22px;
    font-weight: 800;
    color: #ffffff;
    margin: 0 0 4px;
    position: relative;
    z-index: 1;
    letter-spacing: -0.5px;
}
.reauth-subtitle {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.6);
    margin: 0;
    position: relative;
    z-index: 1;
    line-height: 1.7;
}

/* === BODY === */
.reauth-body {
    padding: 28px 28px 20px;
}

.reauth-field {
    margin-bottom: 18px;
}
.reauth-field label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: #1e293b;
    margin-bottom: 8px;
}
.reauth-field label i {
    color: #C9902B;
    font-size: 14px;
    width: 18px;
    text-align: center;
}
.reauth-field input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid #e2e8f0;
    border-radius: 16px;
    font-size: 15px;
    font-weight: 500;
    color: #0f172a;
    background: #f8fafc;
    transition: all 0.25s ease;
    outline: none;
    direction: ltr;
    text-align: left;
    font-family: 'Vazir', Tahoma, Arial, sans-serif;
}
.reauth-field input:focus {
    border-color: #C9902B;
    background: #ffffff;
    box-shadow: 0 0 0 4px rgba(201, 144, 43, 0.12);
}
.reauth-field input::placeholder {
    color: #94a3b8;
    font-weight: 400;
}

/* === ALERT === */
.reauth-alert {
    display: none;
    align-items: center;
    gap: 10px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #dc2626;
    padding: 12px 16px;
    border-radius: 14px;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 18px;
}
.reauth-alert i {
    font-size: 16px;
    flex-shrink: 0;
}
.reauth-alert.show {
    display: flex;
}

/* === BUTTON === */
.reauth-btn {
    width: 100%;
    padding: 16px;
    background: linear-gradient(135deg, #C9902B, #e8a832);
    color: #ffffff;
    border: none;
    border-radius: 16px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.2s ease;
    box-shadow: 0 4px 20px rgba(201, 144, 43, 0.4);
    font-family: 'Vazir', Tahoma, Arial, sans-serif;
}
.reauth-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(201, 144, 43, 0.5);
}
.reauth-btn:active:not(:disabled) {
    transform: translateY(0);
}
.reauth-btn:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}
.reauth-btn i {
    font-size: 18px;
}

/* === SPINNER === */
.reauth-spinner {
    width: 20px;
    height: 20px;
    border: 2.5px solid rgba(255, 255, 255, 0.3);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: reauth-spin 0.7s linear infinite;
}
@keyframes reauth-spin {
    to { transform: rotate(360deg); }
}

/* === FOOTER === */
.reauth-footer {
    text-align: center;
    padding: 16px 28px 24px;
    border-top: 1px solid #f1f5f9;
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
}
.reauth-footer a {
    color: #64748b;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.reauth-footer a i {
    font-size: 13px;
}
.reauth-footer a:hover {
    color: #C9902B;
}

/* === RESPONSIVE === */
@media (max-width: 480px) {
    .reauth-card {
        border-radius: 20px;
    }
    .reauth-header {
        padding: 24px 20px 20px;
    }
    .reauth-header .reauth-title {
        font-size: 19px;
    }
    .reauth-header .reauth-subtitle {
        font-size: 13px;
    }
    .reauth-body {
        padding: 20px 20px 16px;
    }
    .reauth-field input {
        padding: 12px 14px;
        font-size: 14px;
    }
    .reauth-btn {
        padding: 14px;
        font-size: 15px;
    }
    .reauth-footer {
        padding: 14px 20px 20px;
        flex-direction: column;
        gap: 8px;
    }
    .reauth-icon-wrap {
        width: 60px;
        height: 60px;
    }
    .reauth-icon-wrap i {
        font-size: 24px;
    }
}
</style>

<div id="reauth-root">
    <div class="reauth-overlay" id="reauthOverlay">
        <div class="reauth-card">
            <div class="reauth-header">
                <div class="reauth-gold-line"></div>
                <div class="reauth-icon-wrap">
                    <i class="fas fa-hourglass-half"></i>
                </div>
                <h2 class="reauth-title">نشست شما منقضی شد</h2>
                <p class="reauth-subtitle">لطفاً برای ادامه، دوباره وارد حساب خود شوید</p>
            </div>
            <div class="reauth-body">
                <div class="reauth-alert" id="reauthAlert">
                    <i class="fas fa-circle-exclamation"></i>
                    <span id="reauthAlertText"></span>
                </div>
                <div class="reauth-field">
                    <label for="reauthPhone"><i class="fas fa-mobile-screen-button"></i> شماره موبایل</label>
                    <input type="tel" id="reauthPhone" placeholder="مثال: 09123456789" autocomplete="username" inputmode="numeric" maxlength="11">
                </div>
                <div class="reauth-field">
                    <label for="reauthPassword"><i class="fas fa-lock"></i> رمز عبور</label>
                    <input type="password" id="reauthPassword" placeholder="رمز عبور خود را وارد کنید" autocomplete="current-password">
                </div>
                <input type="hidden" id="reauthCsrf" value="9a740afd2957342df93302c6affe904f6f1576191939b9a5439dc31e34385bcb">
                <button type="button" class="reauth-btn" id="reauthBtn">
                    <i class="fas fa-right-to-bracket"></i> ورود مجدد
                </button>
            </div>
            <div class="reauth-footer">
                <a href="/sms/login.php"><i class="fas fa-arrow-right-to-bracket"></i> صفحه اصلی ورود</a>
                <a href="/sms/register.php"><i class="fas fa-user-plus"></i> ثبت‌نام</a>
            </div>
        </div>
    </div>
</div>

<script>
(function() {
    const phoneInput = document.getElementById('reauthPhone');
    const passInput = document.getElementById('reauthPassword');
    const submitBtn = document.getElementById('reauthBtn');
    const alertBox = document.getElementById('reauthAlert');
    const alertText = document.getElementById('reauthAlertText');
    const csrfToken = document.getElementById('reauthCsrf').value;

    function toEnDigit(str) {
        return str.replace(/[۰-۹]/g, d => d.charCodeAt(0) - 1776)
                  .replace(/[٠-٩]/g, d => d.charCodeAt(0) - 1632);
    }

    phoneInput.addEventListener('input', function() {
        const pos = this.selectionStart;
        this.value = toEnDigit(this.value);
        this.setSelectionRange(pos, pos);
    });

    function showError(msg) {
        alertText.textContent = msg;
        alertBox.classList.add('show');
    }

    function clearError() {
        alertBox.classList.remove('show');
    }

    function setLoading(on) {
        submitBtn.disabled = on;
        submitBtn.innerHTML = on
            ? '<span class="reauth-spinner"></span> در حال ورود...'
            : '<i class="fas fa-right-to-bracket"></i> ورود مجدد';
    }

    async function doLogin() {
        clearError();
        const phone = phoneInput.value.trim();
        const password = passInput.value;

        if (!phone) { showError('شماره موبایل را وارد کنید'); phoneInput.focus(); return; }
        if (!password) { showError('رمز عبور را وارد کنید'); passInput.focus(); return; }
        if (!/^09[0-9]{9}$/.test(phone)) {
            showError('شماره موبایل باید ۱۱ رقم و با ۰۹ شروع شود');
            phoneInput.focus();
            return;
        }

        setLoading(true);

        try {
            const res = await fetch(window.location.pathname + '?ajax_reauth=1', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                    'X-Requested-With': 'XMLHttpRequest',
                },
                credentials: 'same-origin',
                body: JSON.stringify({
                    phone: phone,
                    password: password,
                    csrf_token: csrfToken,
                }),
            });

            if (!res.ok) throw new Error('HTTP ' + res.status);
            const data = await res.json();

            if (data.success) {
                submitBtn.innerHTML = '<i class="fas fa-check-circle"></i> ورود موفق — در حال بارگذاری...';
                submitBtn.style.background = 'linear-gradient(135deg, #16a34a, #22c55e)';
                submitBtn.style.boxShadow = '0 4px 20px rgba(22, 163, 74, 0.4)';
                setTimeout(() => window.location.reload(), 800);
            } else {
                showError(data.message || 'ورود ناموفق، دوباره تلاش کنید');
                setLoading(false);
                passInput.value = '';
                passInput.focus();
            }
        } catch (err) {
            console.error('reauth error:', err);
            showError('خطا در ارتباط با سرور، اینترنت خود را بررسی کنید');
            setLoading(false);
        }
    }

    submitBtn.addEventListener('click', doLogin);
    [phoneInput, passInput].forEach(el => {
        el.addEventListener('keydown', e => { if (e.key === 'Enter') doLogin(); });
    });

    document.getElementById('reauthOverlay').addEventListener('click', function(e) {
        if (e.target === this) {
            // فقط در صورت کلیک روی پس‌زمینه، کارت را لرزان نشان بده
            const card = this.querySelector('.reauth-card');
            card.style.animation = 'none';
            card.style.transform = 'scale(0.98)';
            setTimeout(() => {
                card.style.transform = '';
                card.style.animation = 'reauth-slide-up 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards';
            }, 150);
        }
    });

    setTimeout(() => phoneInput.focus(), 400);
})();
</script>