/* ============================================================
   TAGHAT — Glass App Layer (v4.7)
   لایهٔ نهایی ظاهر «اپ‌گونه» برای موبایل / WebView:
   هدر و منوی پایین شیشه‌ای، انیمیشن نرم، ریپل نارنجی.
   این فایل باید آخرین CSS بارگذاری‌شده باشد (در functions.php تنظیم شده).
   فقط ≤ 991.98px را تغییر می‌دهد؛ دسکتاپ دست‌نخورده می‌ماند.
   ============================================================ */

:root {
    --tgg-blur-top: 18px;
    --tgg-blur-nav: 22px;
    --tgg-saturate: 165%;
    --tgg-ripple: rgba(242, 163, 61, 0.50);          /* نارنجی برند */

    /* روشن — هدر موبایل همیشه سرمه‌ای است (مثل طراحی فعلی) */
    --tgg-top-bg: rgba(16, 35, 65, 0.56);
    --tgg-top-bg-scrolled: rgba(16, 35, 65, 0.76);
    --tgg-top-line: rgba(255, 255, 255, 0.10);
    --tgg-top-shadow: 0 8px 28px rgba(8, 18, 40, 0.28);

    /* منوی پایین: در حالت روشن کدری بیشتر، چون روی هیرو سرمه‌ای هم باید خوانا بماند */
    --tgg-nav-bg: rgba(255, 255, 255, 0.78);
    --tgg-nav-line: rgba(255, 255, 255, 0.70);
    --tgg-nav-shadow: 0 18px 44px rgba(19, 41, 75, 0.30), inset 0 1px 0 rgba(255, 255, 255, 0.65);
    --tgg-nav-text: #3A4866;
    --tgg-nav-text-active: var(--green-dark, #0E9C86);
    --tgg-ind-bg: var(--accent, #DFF9F5);
    --tgg-ind-ring: var(--green-glow, rgba(22, 168, 122, 0.35));

    --tgg-fab-bg: linear-gradient(135deg, rgba(242, 163, 61, 0.95), rgba(216, 132, 32, 0.95));
    --tgg-fab-shadow: 0 10px 28px rgba(216, 132, 32, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

@media (prefers-color-scheme: dark){
:root:not([data-theme="light"]){
        --tgg-top-bg: rgba(10, 15, 30, 0.52);
        --tgg-top-bg-scrolled: rgba(10, 15, 30, 0.76);
        --tgg-top-line: rgba(91, 155, 255, 0.16);
        --tgg-top-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);

        --tgg-nav-bg: rgba(14, 22, 42, 0.60);
        --tgg-nav-line: rgba(130, 170, 255, 0.20);
        --tgg-nav-shadow: 0 18px 44px rgba(0, 0, 0, 0.60), inset 0 1px 0 rgba(255, 255, 255, 0.08);
        --tgg-nav-text: #B4C1DC;
        --tgg-nav-text-active: var(--green, #4ADE80);
        --tgg-ind-bg: rgba(74, 222, 128, 0.20);
        --tgg-ind-ring: rgba(74, 222, 128, 0.22);

        --tgg-ripple: rgba(255, 184, 77, 0.38);
        --tgg-fab-bg: linear-gradient(135deg, rgba(255, 184, 77, 0.92), rgba(224, 144, 48, 0.92));
        --tgg-fab-shadow: 0 10px 28px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.25);
    }
}
/* forced dark (data-theme="dark") */
:root[data-theme="dark"]{
        --tgg-top-bg: rgba(10, 15, 30, 0.52);
        --tgg-top-bg-scrolled: rgba(10, 15, 30, 0.76);
        --tgg-top-line: rgba(91, 155, 255, 0.16);
        --tgg-top-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);

        --tgg-nav-bg: rgba(14, 22, 42, 0.60);
        --tgg-nav-line: rgba(130, 170, 255, 0.20);
        --tgg-nav-shadow: 0 18px 44px rgba(0, 0, 0, 0.60), inset 0 1px 0 rgba(255, 255, 255, 0.08);
        --tgg-nav-text: #B4C1DC;
        --tgg-nav-text-active: var(--green, #4ADE80);
        --tgg-ind-bg: rgba(74, 222, 128, 0.20);
        --tgg-ind-ring: rgba(74, 222, 128, 0.22);

        --tgg-ripple: rgba(255, 184, 77, 0.38);
        --tgg-fab-bg: linear-gradient(135deg, rgba(255, 184, 77, 0.92), rgba(224, 144, 48, 0.92));
        --tgg-fab-shadow: 0 10px 28px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.25);
    }


/* ------------------------------------------------------------
   ۱) ریپل نارنجی (عنصرها را JS در taghat-glass-app.js می‌سازد)
   ------------------------------------------------------------ */
.tg-bottom-nav-item,
.tg-mobile-burger,
.tg-icon-btn,
.taghat-float-btn,
.tg-profile-trigger {
    position: relative;
    -webkit-tap-highlight-color: transparent;
}
.tg-ripple-layer {
    position: absolute;
    inset: 0;
    border-radius: inherit;
    overflow: hidden;
    pointer-events: none;
    z-index: 0;
}
.tg-ripple {
    position: absolute;
    border-radius: 50%;
    background: var(--tgg-ripple);
    transform: scale(0);
    opacity: 1;
    animation: tgRipple 620ms cubic-bezier(.22, .7, .3, 1) forwards;
    will-change: transform, opacity;
}
@keyframes tgRipple {
    to { transform: scale(1); opacity: 0; }
}

/* ------------------------------------------------------------
   ۲) فقط موبایل / WebView
   ------------------------------------------------------------ */
@media (max-width: 991.98px) {

    /* --- هدر: پوستهٔ بیرونی شفاف و بدون blur ---
       (blur والد، blur فرزند را از کار می‌اندازد؛ dark-mode.css روی
       .main-header پس‌زمینهٔ !important و blur می‌گذارد، پس باید بشکنیم) */
    .main-header,
    .main-header.scrolled {
        background: transparent !important;
        -webkit-backdrop-filter: none !important;
        backdrop-filter: none !important;
        box-shadow: none !important;
    }

    .main-header .tg-mobile-topbar {
        background: var(--tgg-top-bg);
        -webkit-backdrop-filter: blur(var(--tgg-blur-top)) saturate(var(--tgg-saturate));
        backdrop-filter: blur(var(--tgg-blur-top)) saturate(var(--tgg-saturate));
        border-bottom: 1px solid var(--tgg-top-line);
        transition: background-color 320ms ease, box-shadow 320ms ease;
        transform: translateZ(0);
    }
    .main-header.scrolled .tg-mobile-topbar {
        background: var(--tgg-top-bg-scrolled);
        box-shadow: var(--tgg-top-shadow);
    }

    /* دکمه‌های گردِ هدر: شیشه‌ای‌تر */
    .tg-mobile-burger,
    .tg-mobile-topbar .tg-icon-btn {
        background: rgba(255, 255, 255, 0.14);
        border: 1px solid rgba(255, 255, 255, 0.18);
        box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
        overflow: visible;
    }
    .tg-mobile-burger:active,
    .tg-mobile-topbar .tg-icon-btn:active { transform: scale(0.92); }

    /* --- منوی پایین --- */
    .tg-bottom-nav {
        bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        background: var(--tgg-nav-bg);
        -webkit-backdrop-filter: blur(var(--tgg-blur-nav)) saturate(var(--tgg-saturate));
        backdrop-filter: blur(var(--tgg-blur-nav)) saturate(var(--tgg-saturate));
        border: 1px solid var(--tgg-nav-line);
        box-shadow: var(--tgg-nav-shadow);
        transform: translateZ(0);
        isolation: isolate;
    }
    .tg-bottom-nav-item {
        color: var(--tgg-nav-text);
        font-family: 'Vazirmatn', sans-serif;
        transition: color 260ms ease, transform 160ms ease;
    }
    .tg-bottom-nav-item:active { transform: scale(0.94); }
    .tg-bottom-nav-label { font-size: 11px; font-weight: 700; position: relative; z-index: 1; }
    .tg-bottom-nav-icon { position: relative; z-index: 1; }
    .tg-bottom-nav-item.is-active { color: var(--tgg-nav-text-active); }

    /* وقتی JS فعال است، دایرهٔ فعال یک عنصر مستقل است که بین تب‌ها می‌لغزد */
    .tg-bottom-nav.tg-nav-enhanced .tg-bottom-nav-icon {
        width: 38px;
        height: 38px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 0;
        background: none;
        box-shadow: none;
        border-radius: 50%;
        transition: transform 360ms cubic-bezier(.34, 1.4, .64, 1);
    }
    .tg-bottom-nav.tg-nav-enhanced .tg-bottom-nav-item.is-active .tg-bottom-nav-icon {
        background: none;
        box-shadow: none;
        padding: 0;
        transform: translateY(-3px);
    }
    .tg-nav-indicator {
        position: absolute;
        top: 0;
        left: 0;
        width: 38px;
        height: 38px;
        border-radius: 50%;
        background: var(--tgg-ind-bg);
        box-shadow: 0 0 0 5px var(--tgg-ind-ring);
        pointer-events: none;
        z-index: 0;
        will-change: transform;
    }
    .tg-nav-indicator.is-anim {
        transition: transform 520ms cubic-bezier(.34, 1.36, .64, 1);
    }

    /* --- دکمهٔ تماس شناور: کوچک‌تر، شیشه‌ای-کهربایی، و هنگام اسکرول رو به پایین جمع می‌شود --- */
    .taghat-float-contact {
        left: 16px;
        bottom: calc(96px + env(safe-area-inset-bottom, 0px));
        transition: transform 280ms cubic-bezier(.4, 0, .2, 1), opacity 220ms ease;
    }
    .taghat-float-contact.is-hidden {
        transform: translateY(18px) scale(0.88);
        opacity: 0;
        pointer-events: none;
    }
    .taghat-float-btn {
        width: 48px;
        height: 48px;
        background: var(--tgg-fab-bg);
        box-shadow: var(--tgg-fab-shadow);
        border: 1px solid rgba(255, 255, 255, 0.28);
    }
    .taghat-float-btn:hover { transform: none; }
    .taghat-float-btn:active { transform: scale(0.92); }
    .taghat-float-btn > svg,
    .taghat-float-btn > span:not(.float-tooltip):not(.tg-ripple-layer) { position: relative; z-index: 1; }
    .float-tooltip { display: none !important; } /* روی لمس معنی ندارد */
}

/* مرورگر بدون backdrop-filter: کدری بیشتر تا متن خوانا بماند */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    :root {
        --tgg-top-bg: rgba(16, 35, 65, 0.92);
        --tgg-top-bg-scrolled: rgba(16, 35, 65, 0.97);
        --tgg-nav-bg: rgba(255, 255, 255, 0.96);
    }
    @media (prefers-color-scheme: dark) {
        :root {
            --tgg-top-bg: rgba(10, 15, 30, 0.93);
            --tgg-top-bg-scrolled: rgba(10, 15, 30, 0.97);
            --tgg-nav-bg: rgba(14, 22, 42, 0.95);
        }
    }
}

/* ------------------------------------------------------------
   ۳) ورود نرم محتوای هر صفحه (fade + کمی بالا آمدن)
   هدر، منو، دکمه شناور و drawer عمداً جدا هستند.
   ------------------------------------------------------------ */
@media (prefers-reduced-motion: no-preference) {
    body > *:not(.main-header):not(.tg-bottom-nav):not(.taghat-float-contact):not(.offcanvas):not(.offcanvas-backdrop):not(.modal):not(.modal-backdrop):not(#wpadminbar):not(script):not(style):not(link) {
        animation: tgPageIn 380ms cubic-bezier(.22, .7, .3, 1) backwards;
    }
}
@keyframes tgPageIn {
    from { opacity: 0; transform: translateY(12px); }
}

/* کاهش حرکت: همه‌چیز ساکن */
@media (prefers-reduced-motion: reduce) {
    .tg-ripple { display: none; }
    .tg-nav-indicator.is-anim { transition: none; }
    .taghat-float-contact { transition: none; }
}


/* ============================================================
   v4.7.1 — اصلاح لایه‌بندی (z-index) و ظاهر شدن نرم
   ------------------------------------------------------------
   علت باگ «افتادن روی هم» هنگام باز شدن منوی همبرگری:
   هدر = 9999، منوی پایین = 9995، دکمهٔ تماس = 9990،
   ولی منوی کشویی و پس‌زمینهٔ بوت‌استرپ فقط 1045 / 1040 بودند؛
   یعنی همه‌چیز روی منو می‌افتاد. حالا ترتیب یک‌جا و صریح است:
   دکمه شناور < منوی پایین < هدر < پس‌زمینهٔ منو < منو < مودال.
   ============================================================ */
:root {
    /* مقادیر اصلی در tokens.css تعریف شده‌اند؛ اینجا فقط تکرار امن (اگر کش tokens قدیمی بود) */
    --tg-z-fab: 940;
    --tg-z-nav: 950;
    --tg-z-header: 1030;
    --tg-z-backdrop: 1040;
    --tg-z-drawer: 1045;
    --tg-z-modal-backdrop: 1050;
    --tg-z-modal: 1055;
}

.taghat-float-contact { z-index: var(--tg-z-fab); }
.tg-bottom-nav        { z-index: var(--tg-z-nav); }
.main-header          { z-index: var(--tg-z-header); }

.offcanvas-backdrop { z-index: var(--tg-z-backdrop); }
.modal-backdrop     { z-index: var(--tg-z-modal-backdrop); }
.modal              { z-index: var(--tg-z-modal); }

/* منوی کشویی: قواعد ضروری آن در خود قالب هم هست تا اگر CSS بوت‌استرپ
   (از CDN) دیر برسد یا نرسد، منو باز هم درست جا بگیرد و روی بقیه بیاید. */
.taghat-offcanvas.offcanvas {
    position: fixed;
    top: 0;
    bottom: 0;
    z-index: var(--tg-z-drawer);
    display: flex;
    flex-direction: column;
    max-width: 100%;
    visibility: hidden;
}
.taghat-offcanvas.offcanvas.offcanvas-end {
    inset-inline-end: 0;
    transform: translateX(100%);
}
[dir="rtl"] .taghat-offcanvas.offcanvas.offcanvas-end {
    transform: translateX(-100%);
}
.taghat-offcanvas.offcanvas.showing,
.taghat-offcanvas.offcanvas.show,
.taghat-offcanvas.offcanvas.hiding {
    visibility: visible;
}
.taghat-offcanvas.offcanvas.offcanvas-end.show:not(.hiding),
.taghat-offcanvas.offcanvas.offcanvas-end.showing {
    transform: none;
}

/* وقتی منو باز است، منوی پایین و دکمهٔ تماس کنار می‌روند (JS کلاس را می‌گذارد) */
.tg-bottom-nav,
.taghat-float-contact {
    transition: opacity 220ms ease, transform 280ms cubic-bezier(.4, 0, .2, 1);
}
html.tg-drawer-open .tg-bottom-nav,
html.tg-drawer-open .taghat-float-contact {
    opacity: 0;
    pointer-events: none;
}

/* ------------------------------------------------------------
   ظاهر شدن نرم هدر / منوی پایین / دکمهٔ تماس (ضد پرش اولیه)
   کلاس tg-preload را یک اسکریپت کوچک در <head> می‌گذارد و بعد از آماده شدن
   صفحه برمی‌دارد (حداکثر ۲ ثانیه). اگر JS اجرا نشود کلاس هرگز نمی‌آید و
   همه‌چیز عادی دیده می‌شود. فقط opacity عوض می‌شود، پس اندازه‌گیری‌های JS
   (مثل دایرهٔ فعال منو) به‌هم نمی‌خورد.
   ------------------------------------------------------------ */
/* v4.7.2 — برای همهٔ عرض‌ها (قبلاً فقط موبایل بود) */
.main-header {
    transition: opacity 320ms ease, box-shadow var(--duration-base, 0.3s) var(--ease, ease);
}
html.tg-preload .main-header,
html.tg-preload .tg-bottom-nav,
html.tg-preload .taghat-float-contact {
    opacity: 0;
    pointer-events: none;
    transition: none;
}
@media (prefers-reduced-motion: reduce) {
    .main-header,
    .tg-bottom-nav,
    .taghat-float-contact { transition: none; }
}


/* ============================================================
   v4.7.2 — دکمهٔ تغییر تم (خودکار / روشن / تاریک)
   html[data-tg-pref] حالت انتخاب‌شدهٔ کاربر است (auto | light | dark)
   ============================================================ */

/* دکمهٔ چرخشی هدر دسکتاپ: فقط آیکون حالت فعلی دیده می‌شود */
.tg-theme-toggle .tg-ti { display: none; }
html:not([data-tg-pref]) .tg-theme-toggle .tg-ti-auto,
html[data-tg-pref="auto"]  .tg-theme-toggle .tg-ti-auto,
html[data-tg-pref="light"] .tg-theme-toggle .tg-ti-light,
html[data-tg-pref="dark"]  .tg-theme-toggle .tg-ti-dark { display: block; }
.tg-theme-toggle svg { transition: transform 360ms cubic-bezier(.34, 1.4, .64, 1); }
.tg-theme-toggle:active svg { transform: rotate(40deg) scale(.9); }

/* کنترل سه‌حالته در منوی موبایل */
.tg-theme-seg {
    margin: 4px 20px 0;
    padding: 4px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    border-radius: 999px;
    background: rgba(128, 138, 160, 0.14);
    border: 1px solid var(--taghat-border, rgba(128, 138, 160, 0.25));
}
.tg-theme-seg-title {
    margin: 14px 20px 8px;
    font-size: 12.5px;
    font-weight: 700;
    color: var(--taghat-text-muted, #6b7a95);
}
.tg-theme-seg button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 40px;
    padding: 0 6px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--taghat-text-muted, #6b7a95);
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 220ms ease, color 220ms ease, box-shadow 220ms ease;
}
.tg-theme-seg button svg { flex: none; }
.tg-theme-seg button[aria-pressed="true"] {
    background: var(--amber, #F6A52C);
    color: #1b1405;
    box-shadow: 0 4px 14px rgba(216, 132, 32, 0.35);
}
.tg-theme-seg button:focus-visible,
.tg-theme-toggle:focus-visible { outline: 2px solid var(--amber, #F6A52C); outline-offset: 2px; }
