/* =====================================================================
   صفحات حساب کاربری (ورود، ثبت‌نام، فراموشی رمز، تأیید ایمیل، ...)

   رویکرد: موبایل‌اول، با سه چیدمان مجزا
     - موبایل  (< 600px)   : سربرگ کوچک برند + «صفحه»‌ی تمام‌عرض سفید که تا پایین صفحه ادامه دارد،
                              فیلدهای ۴۸px و فونت ۱۶px (جلوگیری از زوم iOS)، مودال به‌شکل Bottom Sheet،
                              دکمه‌های ورود با حساب خارجی به‌صورت یک ردیف آیکن.
     - تبلت    (≥ 600px)   : کارت سفیدِ وسط‌چین روی پس‌زمینه‌ی گرادیانی.
     - دسکتاپ  (≥ 992px)   : صفحه‌ی دوبخشی؛ پنل برند (ثابت هنگام اسکرول) + ناحیه‌ی فرم.
   جهت (RTL/LTR) فقط با ویژگی‌های منطقی CSS و dir صفحه کنترل می‌شود.
   ===================================================================== */

.auth-shell {
    --auth-ink: #1f2937;
    --auth-muted: #6b7280;
    --auth-border: #d1d5db;
    --auth-primary: #842564;
    --auth-primary-dark: #4a1238;
    --auth-primary-soft: #fbf1f7;
    --auth-danger: #dc2626;
    --auth-radius: 12px;

    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    background: linear-gradient(135deg, #2a0b21 0%, #5a1745 100%);
    font-family: var(--font-main);
    color: var(--auth-ink);
    box-sizing: border-box;
    -webkit-text-size-adjust: 100%;
}

.auth-shell *, .auth-shell *::before, .auth-shell *::after { box-sizing: border-box; }

/* ---------- پنل برند ---------- */
.auth-brand {
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.1rem 1rem 2.6rem;
}

.auth-brand-link {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    gap: .7rem;
    color: #fff;
    text-decoration: none;
    border-radius: var(--auth-radius);
}

.auth-brand-link:focus-visible { outline: 3px solid rgba(255, 255, 255, .7); outline-offset: 4px; }

.auth-brand-logo-wrap {
    display: inline-flex;
    padding: .3rem;
    border-radius: 14px;
    background: rgba(255, 255, 255, .12);
    border: 1px solid rgba(232, 190, 216, .35);
}

.auth-brand-logo { display: block; height: 38px; width: auto; object-fit: contain; }

.auth-brand-name { font-size: 1.05rem; font-weight: 700; line-height: 1.4; color: #fff; }

/* درخششِ تزئینی فقط در پنل برند دسکتاپ نمایش داده می‌شود (در سربرگ کوچک موبایل/تبلت لبه‌ی مستطیلی دیده می‌شود) */
.auth-brand-glow { display: none; position: absolute; border-radius: 50%; pointer-events: none; filter: blur(2px); }
.auth-brand-glow-a { inline-size: 22rem; block-size: 22rem; inset-block-start: -11rem; inset-inline-end: -8rem; background: radial-gradient(circle, rgba(214, 150, 190, .26), transparent 65%); }
.auth-brand-glow-b { inline-size: 20rem; block-size: 20rem; inset-block-end: -12rem; inset-inline-start: -8rem; background: radial-gradient(circle, rgba(160, 88, 136, .34), transparent 65%); }

/* ---------- ناحیه‌ی فرم (موبایل: صفحه‌ی سفید تمام‌عرض) ---------- */
.auth-main {
    position: relative;
    z-index: 1;
    display: block;
    margin-block-start: -1.5rem;
    padding: 1.75rem 1.25rem calc(2rem + env(safe-area-inset-bottom, 0px));
    background: #fff;
    border-radius: 24px 24px 0 0;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, .18);
}

.auth-shell-inner { width: 100%; max-width: 440px; margin-inline: auto; }

.auth-card { color: var(--auth-ink); }

/* ---------- سربرگ کارت ---------- */
.auth-head { margin-block-end: 1.25rem; text-align: center; }

.auth-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    inline-size: 3.25rem;
    block-size: 3.25rem;
    margin-block-end: .8rem;
    border-radius: 50%;
    background: var(--auth-primary-soft);
    color: var(--auth-primary);
}

.auth-icon svg { inline-size: 1.6rem; block-size: 1.6rem; }
.auth-icon-danger { background: #fef2f2; color: #b91c1c; }

.auth-title { margin: 0 0 .35rem; font-size: 1.45rem; line-height: 1.5; text-align: center; color: var(--auth-primary-dark); font-weight: 700; }
.auth-title:focus { outline: none; }
.auth-subtitle { margin: 0; text-align: center; color: var(--auth-muted); font-size: .92rem; line-height: 1.9; }

/* ---------- تب‌ها ---------- */
.auth-tabs { display: flex; gap: .25rem; padding: .25rem; margin-block-end: 1.25rem; background: #f3f4f6; border-radius: var(--auth-radius); }
.auth-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-block-size: 2.75rem;
    padding: .4rem .5rem;
    border-radius: 9px;
    color: var(--auth-muted);
    text-decoration: none;
    font-weight: 600;
    transition: background .15s, color .15s, box-shadow .15s;
}
.auth-tab:hover { color: var(--auth-primary); }
.auth-tab.active { background: #fff; color: var(--auth-primary); box-shadow: 0 1px 4px rgba(0, 0, 0, .12); }
.auth-tab:focus-visible { outline: 3px solid rgba(132, 37, 100, .35); outline-offset: 1px; }

/* ---------- فرم ---------- */
.auth-form { display: flex; flex-direction: column; gap: 1rem; }
.form-row { display: flex; gap: .75rem; }
.form-row .form-group { flex: 1; min-inline-size: 0; }
.form-group { display: flex; flex-direction: column; gap: .35rem; }
.auth-shell .form-group label { font-size: .88rem; font-weight: 600; color: #374151; }

.auth-shell .form-control {
    width: 100%;
    min-block-size: 3rem;
    padding: .65rem .85rem;
    font: inherit;
    font-size: 1rem; /* ≥16px: جلوگیری از زوم خودکار iOS */
    line-height: 1.5;
    border: 1px solid var(--auth-border);
    border-radius: var(--auth-radius);
    background: #fff;
    color: #111827;
    box-shadow: none;
    transition: border-color .15s, box-shadow .15s;
}
.auth-shell .form-control::placeholder { color: #9ca3af; }
.auth-shell .form-control:hover { border-color: #9ca3af; }
.auth-shell .form-control:focus { outline: none; border-color: var(--auth-primary); box-shadow: 0 0 0 3px rgba(132, 37, 100, .18); }
.auth-shell .form-control.invalid { border-color: var(--auth-danger); outline: none; }
.auth-shell .form-control.invalid:focus { box-shadow: 0 0 0 3px rgba(220, 38, 38, .15); }
.auth-shell .form-control.valid.modified { outline: none; }
.auth-shell input:-webkit-autofill { -webkit-box-shadow: 0 0 0 1000px #fff inset; -webkit-text-fill-color: #111827; }

/* فیلد رمز عبور (کامپوننت مشترک PasswordField؛ فقط داخل صفحات حساب شخصی‌سازی می‌شود) */
.auth-shell .password-field > input.form-control { padding-right: 3.1rem; padding-left: .85rem; }
.auth-shell .password-toggle { inline-size: 2.5rem; block-size: 2.5rem; right: .35rem; }

/* کد تأیید */
.auth-shell .form-control.auth-code-input {
    text-align: center;
    font-size: clamp(1.25rem, 6vw, 1.6rem);
    letter-spacing: .4em;
    padding-inline-start: calc(.85rem + .4em); /* جبران فاصله‌ی انتهای letter-spacing تا کد دقیقاً وسط بماند */
    font-variant-numeric: tabular-nums;
    min-block-size: 3.5rem;
}

.form-hint { color: var(--auth-muted); font-size: .8rem; line-height: 1.7; }
.auth-shell .validation-message { color: var(--auth-danger); font-size: .82rem; line-height: 1.6; }

.auth-check {
    display: flex;
    align-items: center;
    gap: .6rem;
    min-block-size: 2.75rem;
    font-size: .9rem;
    color: #374151;
    cursor: pointer;
    user-select: none;
}
.auth-check input { inline-size: 1.2rem; block-size: 1.2rem; margin: 0; accent-color: var(--auth-primary); cursor: pointer; flex: none; }

/* ---------- دکمه‌ها ---------- */
.btn-gradient, .btn-outline {
    display: flex;
    align-items: center;
    justify-content: center;
    min-block-size: 2.9rem;
    border-radius: var(--auth-radius);
    padding: .7rem 1rem;
    font: inherit;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: filter .15s, transform .05s, background .15s;
}
.btn-gradient { border: 0; font-weight: 700; color: #fff; background: linear-gradient(135deg, #9b2f78, #5a1745); }
.btn-gradient:hover { filter: brightness(1.1); color: #fff; }
.btn-gradient:active { transform: translateY(1px); }
.btn-outline { border: 1px solid var(--auth-primary); font-weight: 600; color: var(--auth-primary); background: #fff; }
.btn-outline:hover { background: var(--auth-primary-soft); }
.btn-gradient:focus-visible, .btn-outline:focus-visible { outline: 3px solid rgba(132, 37, 100, .4); outline-offset: 2px; }
.btn-block { width: 100%; }
.btn-lg { min-block-size: 3.1rem; font-size: 1rem; }
a.btn-block { margin-block-start: 0; }

.auth-actions { display: flex; flex-direction: column; gap: .65rem; }
.auth-form > .auth-actions { margin-block-start: .15rem; }

/* ---------- لینک‌ها ---------- */
.auth-links { display: flex; justify-content: space-between; flex-wrap: wrap; gap: .25rem 1rem; font-size: .88rem; }
.auth-links a, .auth-back-link { color: var(--auth-primary); text-decoration: none; border-radius: 6px; }
.auth-links a { padding-block: .4rem; }
.auth-links a:hover, .auth-back-link:hover { text-decoration: underline; }
.auth-links a:focus-visible, .auth-back-link:focus-visible { outline: 3px solid rgba(132, 37, 100, .35); outline-offset: 2px; }

.auth-back-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    min-block-size: 2.75rem;
    margin-block-start: 1rem;
    font-size: .9rem;
}
/* فلش بازگشت: در RTL به راست، در LTR به چپ */
.auth-back-link::before {
    content: "";
    inline-size: 1rem;
    block-size: 1rem;
    background-color: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12h14M13 6l6 6-6 6'/%3E%3C/svg%3E") center / contain no-repeat;
            mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12h14M13 6l6 6-6 6'/%3E%3C/svg%3E") center / contain no-repeat;
}
.auth-shell[dir="ltr"] .auth-back-link::before { transform: scaleX(-1); }

/* ---------- پیام‌ها ---------- */
.auth-alert { padding: .75rem .95rem; margin-block-end: 1rem; border-radius: var(--auth-radius); font-size: .9rem; line-height: 1.8; border-inline-start-width: 4px; }
.auth-alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; border-inline-start: 4px solid #10b981; }
.auth-alert-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; border-inline-start: 4px solid #3b82f6; }
.auth-alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; border-inline-start: 4px solid #ef4444; }

/* ---------- مودال خطا (بدون JavaScript) — موبایل: Bottom Sheet ---------- */
.auth-modal-toggle { display: none; }
.auth-modal-toggle:checked + .auth-modal-backdrop { display: none; }
.auth-modal-backdrop { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: flex-end; justify-content: center; padding: 0; }
.auth-modal-scrim { position: absolute; inset: 0; background: rgba(17, 24, 39, .55); cursor: pointer; }
.auth-modal-box {
    position: relative;
    width: 100%;
    max-width: none;
    max-height: 85vh;
    max-height: 85dvh;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 20px 20px 0 0;
    overflow: hidden;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, .3);
    padding-block-end: env(safe-area-inset-bottom, 0px);
    animation: auth-sheet-in .22s ease-out;
}
.auth-modal-header { display: flex; align-items: center; justify-content: space-between; padding: .6rem; padding-inline: 1.1rem .6rem; background: #f9fafb; border-block-end: 1px solid #e5e7eb; }
.auth-modal-header h5 { margin: 0; font-size: 1.02rem; color: #991b1b; }
.auth-modal-x { display: inline-flex; align-items: center; justify-content: center; inline-size: 2.5rem; block-size: 2.5rem; border-radius: 50%; cursor: pointer; color: var(--auth-muted); }
.auth-modal-x:hover { background: #e5e7eb; }
.auth-modal-body { padding: 1.1rem; overflow-y: auto; white-space: pre-line; line-height: 1.9; font-size: .95rem; color: var(--auth-ink); }
.auth-modal-footer { padding: 0 1.1rem 1.1rem; }
.auth-modal-ok { cursor: pointer; width: 100%; }
@keyframes auth-sheet-in { from { transform: translateY(100%); } to { transform: none; } }
@keyframes auth-modal-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---------- ورود با حساب خارجی ---------- */
.auth-divider { display: flex; align-items: center; gap: .75rem; margin: 1.4rem 0 1rem; color: var(--auth-muted); font-size: .84rem; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: #e5e7eb; }

/* موبایل: یک ردیف آیکن (نام سرویس همچنان برای صفحه‌خوان و tooltip موجود است) */
.auth-external { display: flex; flex-wrap: wrap; gap: .5rem; }
.auth-external-btn {
    flex: 1 1 3.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .6rem;
    min-block-size: 3rem;
    padding: .6rem;
    border: 1px solid var(--auth-border);
    border-radius: var(--auth-radius);
    background: #fff;
    color: #111827;
    font: inherit;
    font-size: .92rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}
.auth-external-btn:hover { background: #f9fafb; border-color: #9ca3af; }
.auth-external-btn:focus-visible { outline: 3px solid rgba(132, 37, 100, .35); outline-offset: 2px; }
.auth-external-icon { display: inline-flex; inline-size: 1.25rem; block-size: 1.25rem; flex: none; }
.auth-external-icon svg { inline-size: 100%; block-size: 100%; }
.auth-external-label {
    position: absolute; inline-size: 1px; block-size: 1px; margin: -1px; padding: 0; overflow: hidden;
    clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* دسترسی غیرمجاز داخل سایت (Routes و AdminLayout) */
.auth-denied-inline { max-width: 480px; margin: 3rem auto; padding: 1.5rem; text-align: center; background: #fff; border-radius: 14px; box-shadow: 0 4px 20px rgba(0, 0, 0, .1); }

/* فرم خروج در نوار بالا و پنل مدیریت */
.navbar-logout-form { display: inline; margin: 0; }
.navbar-logout-form button, .admin-logout-button {
    background: none; border: 0; padding: 0; margin: 0; font: inherit; color: inherit; cursor: pointer;
}
.admin-top-actions { display: flex; align-items: center; gap: 1.25rem; }
.admin-logout-form { margin: 0; }
.admin-logout-button { color: #b91c1c; font-weight: 600; }
.admin-logout-button:hover { text-decoration: underline; }

/* ---------- موبایل خیلی کوچک ---------- */
@media (max-width: 380px) {
    .auth-main { padding-inline: 1rem; }
    .auth-title { font-size: 1.3rem; }
}

@media (max-width: 480px) {
    .form-row { flex-direction: column; gap: 1rem; }
    .auth-links { flex-direction: column; align-items: center; text-align: center; }
}

/* =====================================================================
   تبلت و بالاتر (≥ 600px): کارت سفید وسط‌چین
   ===================================================================== */
@media (min-width: 600px) {
    .auth-shell { grid-template-rows: auto auto; align-content: center; padding: 2rem 1rem; }

    .auth-brand { padding: 0 0 1.25rem; }
    .auth-brand-logo { height: 44px; }
    .auth-brand-name { font-size: 1.15rem; }

    .auth-main {
        margin-block-start: 0;
        padding: 2.25rem 2.25rem 2rem;
        background: #fff;
        border-radius: 20px;
        box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
        inline-size: 100%;
        max-inline-size: 520px;
        justify-self: center;
    }

    .auth-title { font-size: 1.55rem; }

    /* دکمه‌ها و فیلدها کمی جمع‌وجورتر از موبایل */
    .auth-shell .form-control { min-block-size: 2.9rem; font-size: .95rem; }
    .btn-lg { min-block-size: 3rem; }

    /* ورود با حساب خارجی: دکمه‌های برچسب‌دار، دو ستونه */
    .auth-external { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
    .auth-external-btn { flex: initial; padding: .6rem 1rem; }
    .auth-external-btn:last-of-type:nth-of-type(odd) { grid-column: 1 / -1; }
    .auth-external-label { position: static; inline-size: auto; block-size: auto; margin: 0; overflow: visible; clip: auto; clip-path: none; white-space: normal; }

    /* مودال: وسط صفحه */
    .auth-modal-backdrop { align-items: center; padding: 1rem; }
    .auth-modal-box { max-width: 400px; border-radius: 16px; padding-block-end: 0; box-shadow: 0 20px 50px rgba(0, 0, 0, .35); animation: auth-modal-in .18s ease-out; }
}

/* =====================================================================
   دسکتاپ (≥ 992px): صفحه‌ی دوبخشی
   ===================================================================== */
@media (min-width: 992px) {
    .auth-shell {
        grid-template-columns: minmax(340px, 5fr) minmax(0, 7fr);
        grid-template-rows: minmax(100dvh, auto);
        align-content: stretch;
        padding: 0;
        background: #fff;
    }

    .auth-brand {
        position: sticky;
        top: 0;
        align-self: start;
        block-size: 100vh;
        block-size: 100dvh;
        padding: 3rem 2.5rem;
        flex-direction: column;
        background: linear-gradient(160deg, #220a1b 0%, #431033 45%, #6b1d52 100%);
    }

    .auth-brand-link { flex-direction: column; gap: 1.4rem; text-align: center; }
    .auth-brand-logo-wrap { padding: 1.5rem; border-radius: 32px; background: rgba(255, 255, 255, .1); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
    .auth-brand-logo { height: auto; width: clamp(150px, 16vw, 240px); }
    .auth-brand-name { font-size: 1.6rem; }

    .auth-brand-glow { display: block; }
    .auth-brand-glow-a { inline-size: 32rem; block-size: 32rem; inset-block-start: -14rem; inset-inline-end: -10rem; }
    .auth-brand-glow-b { inline-size: 30rem; block-size: 30rem; inset-block-end: -16rem; inset-inline-start: -10rem; }

    .auth-main {
        display: flex;
        align-items: center;
        justify-content: center;
        justify-self: stretch;
        max-inline-size: none;
        padding: 3rem 2rem;
        border-radius: 0;
        box-shadow: none;
        background: #fff;
    }

    .auth-shell-inner { max-width: 440px; }

    .auth-title { font-size: 1.75rem; }
    .auth-subtitle { font-size: .95rem; }
    .auth-head { margin-block-end: 1.5rem; }
}

@media (min-width: 1400px) {
    .auth-shell { grid-template-columns: minmax(420px, 1fr) minmax(0, 1fr); }
    .auth-shell-inner { max-width: 460px; }
}

/* دسکتاپ کم‌ارتفاع (مثلاً لپ‌تاپ‌های کوچک یا موبایل افقی) */
@media (min-width: 992px) and (max-height: 640px) {
    .auth-brand { padding-block: 1.5rem; }
    .auth-brand-logo { width: 120px; }
    .auth-main { align-items: flex-start; padding-block: 1.5rem; }
}

@media (max-height: 480px) and (max-width: 991px) {
    .auth-brand { padding-block-end: 2.2rem; }
}

@media (prefers-reduced-motion: reduce) {
    .auth-shell *, .auth-shell *::before, .auth-shell *::after { animation: none !important; transition: none !important; }
}
