/* ==========================================================================
   پیش‌فرض دسکتاپ (min-width: 992px): مخفی‌سازی کامل تمام المان‌ها و دراورهای موبایل
   ========================================================================== */
@media (min-width: 992px) {
    #ksnBottomNav,
    .ksn-mobile-bottom-nav,
    .ksn-search-modal,
    #ksnMenuDrawer,
    #ksnMenuOverlay,
    .ksn-account-drawer,
    .ksn-account-overlay,
    .ksn-quick-order-wrapper,
    .ksn-mobile-menu-trigger {
        display: none !important;
    }
}

/* ==========================================================================
   Mobile Header: فقط نمایش لوگوی جمع‌وجور در بالا
   ========================================================================== */
@media (max-width: 991px) {
    /* ۱. مخفی کردن تمام بخش‌های اضافی هدر در موبایل */
    .ksn-header-search,
    .ksn-fast-order-wrapper,
    .ksn-header-actions,
    .ksn-header-nav,
    .ksn-mobile-menu-trigger {
        display: none !important;
    }

    /* ۲. تنظیم بدنه هدر */
    .ksn-site-header {
        background: #ffffff;
        border-bottom: 1px solid #f1f5f9;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
        position: relative;
        z-index: 100;
    }

    .ksn-header-main {
        padding: 8px 0;
    }

    /* ۳. تراز کردن لوگو در مرکز */
    .ksn-header-row {
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        padding: 0 16px;
    }

    .ksn-header-branding {
        display: flex;
        justify-content: center;
        align-items: center;
        margin: 0 !important;
        text-align: center;
    }

    .ksn-logo-link {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* ۴. سایز بهینه و متناسب لوگو برای صفحه موبایل */
    .ksn-site-logo {
        width: auto !important;
        height: 38px !important;
        max-width: 140px !important;
        object-fit: contain;
        display: block;
    }
}

/* =======================================================
   حالت موبایل و تبلت (زیر 992px)
   ======================================================= */
@media (max-width: 991px) {
    body {
        padding-bottom: 60px;
    }

    /* ۱. نوار پایین (Bottom Bar) */
    #ksnBottomNav.ksn-mobile-bottom-nav {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: center;
        justify-content: space-around;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100vw;
        max-width: 100%;
        height: 56px;
        background: #ffffff;
        border-top: 1px solid #e5e7eb;
        box-shadow: 0 -3px 12px rgba(0, 0, 0, 0.07);
        z-index: 99990;
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }

    #ksnBottomNav .ksn-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        flex: 1 1 20%;
        max-width: 20%;
        height: 100%;
        text-decoration: none;
        color: #64748b;
        position: relative;
        padding: 4px 0;
        margin: 0;
        transition: color 0.15s ease;
        -webkit-tap-highlight-color: transparent;
    }

    #ksnBottomNav .ksn-nav-item.active,
    #ksnBottomNav .ksn-nav-item:active {
        color: #d32f2f;
    }

    #ksnBottomNav .ksn-nav-item svg {
        width: 21px;
        height: 21px;
        stroke: currentColor;
        fill: none;
        display: block;
        margin: 0 auto 3px auto;
        flex-shrink: 0;
    }

    #ksnBottomNav .ksn-nav-item span.ksn-nav-label {
        font-size: 10px;
        font-weight: 500;
        line-height: 1;
        white-space: nowrap;
        color: inherit;
        text-align: center;
    }

    .ksn-cart-icon-wrap {
        position: relative;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    #ksnBottomNav .ksn-cart-badge {
        position: absolute;
        top: -4px;
        right: -9px;
        background: #d32f2f;
        color: #ffffff;
        font-size: 9px;
        font-weight: 700;
        min-width: 15px;
        height: 15px;
        line-height: 15px;
        border-radius: 10px;
        text-align: center;
        padding: 0 3px;
        box-sizing: border-box;
        font-feature-settings: "ss01" on;
    }

    .ksn-filter-trigger-btn,
    .ksn-filter-float-btn,
    #ksn-filter-btn {
        bottom: 68px !important;
        z-index: 9980 !important;
    }

    /* ۲. مدال جستجوی فیبوسرچ */
    .ksn-search-modal {
        display: none;
    }
    .ksn-search-modal.is-active {
        display: flex;
        position: fixed;
        inset: 0;
        z-index: 99999;
        background: #ffffff;
        flex-direction: column;
    }
    .ksn-search-backdrop {
        display: none;
    }
    .ksn-search-container {
        display: flex;
        flex-direction: column;
        width: 100%;
        height: 100%;
        padding: 12px 14px;
        box-sizing: border-box;
    }
    .ksn-search-topbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 12px;
        padding-bottom: 8px;
        border-bottom: 1px solid #f1f5f9;
    }
    .ksn-search-title {
        font-size: 14px;
        font-weight: 700;
        color: #1e293b;
    }
    .ksn-search-close {
        background: #f1f5f9;
        border: none;
        width: 32px;
        height: 32px;
        border-radius: 50%;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        color: #475569;
        cursor: pointer;
    }
    .ksn-search-fibo-wrap {
        flex: 1;
        position: relative;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .ksn-search-fibo-wrap .dgwt-wcas-search-wrapp {
        width: 100%;
        max-width: 100%;
        margin: 0;
    }
    .ksn-search-fibo-wrap .dgwt-wcas-search-input {
        height: 44px;
        border-radius: 10px;
        border: 1px solid #cbd5e1;
        background: #f8fafc;
        font-size: 13px;
        padding: 0 14px;
    }
    .ksn-search-fibo-wrap .dgwt-wcas-suggestions-wrapp {
        position: static;
        box-shadow: none;
        border: none;
        margin-top: 10px;
        width: 100%;
        max-height: none;
    }

    /* ۳. دراور مینی‌کارت (موبایل) */
    #ksnCartOverlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.6);
        z-index: 99996;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease;
    }
    body.ksn-cart-open #ksnCartOverlay {
        opacity: 1;
        visibility: visible;
    }
    body.ksn-cart-open {
        overflow: hidden !important;
    }

    #ksnCartDrawer {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        right: auto;
        width: 90%;
        max-width: 90vw;
        height: 100%;
        z-index: 99997;
        background: #ffffff;
        box-shadow: 5px 0 25px rgba(0, 0, 0, 0.2);
        display: flex;
        flex-direction: column;
        box-sizing: border-box;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    }
    #ksnCartDrawer.is-open {
        transform: translateX(0);
    }
    .admin-bar #ksnCartDrawer {
        top: 46px;
        height: calc(100% - 46px);
    }

    /* حذف هدر بالا در موبایل */
    #ksnCartDrawer .ksn-cart-drawer-header {
        display: none !important;
    }

    /* لیست کالاها */
    #ksnCartDrawer .ksn-mini-cart-content,
    #ksnCartDrawer .widget_shopping_cart_content {
        flex: 1 1 auto;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        height: 100%;
    }
    #ksnCartDrawer ul.woocommerce-mini-cart {
        flex: 1 1 auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0;
        padding: 12px 14px;
    }

    /* دکمه ۱: بستن سبد (سمت راست) */
    #ksnCartDrawer .ksn-mobile-cart-close {
        flex: 1;
        background: #e2e8f0;
        color: #334155;
        border: 1px solid #cbd5e1;
        border-radius: 8px;
        font-size: 13px;
        font-weight: 700;
        text-align: center;
        padding: 11px 8px;
        text-decoration: none;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
    }
    /* مخفی کردن «جمع جزء» اضافی ووکامرس در مینی‌کارت */
    #ksnCartDrawer .woocommerce-mini-cart__total p.woocommerce-mini-cart__subtotal,
    #ksnCartDrawer .woocommerce-mini-cart__total strong {
        display: none !important;
    }

    /* کانتینر جمع کل */
    #ksnCartDrawer .woocommerce-mini-cart__total {
        margin: 0 !important;
        padding: 12px 16px !important;
        background: #f8fafc !important;
        border-top: 1px solid #e2e8f0 !important;
        border-bottom: 1px dashed #cbd5e1 !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
    }

    #ksnCartDrawer .woocommerce-mini-cart__total::before {
        content: "جمع کل سفارش:";
        font-size: 13px;
        font-weight: 700;
        color: #0f172a;
    }

    #ksnCartDrawer .woocommerce-mini-cart__total .amount {
        font-size: 14px !important;
        font-weight: 800 !important;
        color: #d32f2f !important;
    }

    /* دکمه‌های فوتر در یک ردیف (چپ: مشاهده سبد، راست: بستن) */
    #ksnCartDrawer .woocommerce-mini-cart__buttons {
        margin: 0 !important;
        display: flex !important;
        flex-direction: row-reverse !important;
        gap: 10px !important;
        padding: 12px 16px calc(14px + env(safe-area-inset-bottom, 0px)) 16px !important;
        background: #f8fafc !important;
    }

    #ksnCartDrawer .woocommerce-mini-cart__buttons a {
        flex: 1 !important;
        height: 42px !important;
        border-radius: 8px !important;
        font-size: 13px !important;
        font-weight: 700 !important;
        text-align: center !important;
        text-decoration: none !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        box-sizing: border-box !important;
        margin: 0 !important;
    }

    /* دکمه مشاهده سبد (چپ - آبی) */
    #ksnCartDrawer .woocommerce-mini-cart__buttons a.button.wc-forward,
    #ksnCartDrawer .woocommerce-mini-cart__buttons a.button:not(.checkout):not(.ksn-mobile-cart-close) {
        background: #2563eb !important;
        color: #ffffff !important;
        border: none !important;
    }

    /* دکمه بستن (راست - خاکستری) */
    #ksnCartDrawer .woocommerce-mini-cart__buttons a.ksn-mobile-cart-close,
    #ksnCartDrawer .woocommerce-mini-cart__buttons a.button.checkout {
        background: #e2e8f0 !important;
        color: #334155 !important;
        border: 1px solid #cbd5e1 !important;
        display: inline-flex !important;
    }

    /* ۴. دراور منوی ناوبری موبایل */
    #ksnMenuOverlay {
        position: fixed !important;
        inset: 0 !important;
        background: rgba(0, 0, 0, 0.6) !important;
        z-index: 99996 !important;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease;
    }
    body.ksn-menu-open #ksnMenuOverlay {
        opacity: 1 !important;
        visibility: visible !important;
    }

    #ksnMenuDrawer {
        position: fixed !important;
        top: 0 !important;
        bottom: 0 !important;
        right: 0 !important;
        left: auto !important;
        width: 85% !important;
        max-width: 360px !important;
        height: 100vh !important;
        z-index: 99997 !important;
        background: #ffffff !important;
        box-shadow: -5px 0 25px rgba(0, 0, 0, 0.2) !important;
        display: flex !important;
        flex-direction: column !important;
        box-sizing: border-box !important;
        transform: translateX(100%) !important;
        transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1) !important;
    }
    #ksnMenuDrawer.is-open {
        transform: translateX(0) !important;
    }

    .admin-bar #ksnMenuDrawer {
        top: 46px !important;
        height: calc(100vh - 46px) !important;
    }

    @media (min-width: 783px) {
        .admin-bar #ksnMenuDrawer {
            top: 32px !important;
            height: calc(100vh - 32px) !important;
        }
    }

    /* هدر دراور همراه با لوگو */
    .ksn-menu-drawer-header {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        padding: 14px 16px !important;
        background: #ffffff !important;
        border-bottom: 1px solid #e2e8f0 !important;
        flex-shrink: 0 !important;
    }
    .ksn-menu-drawer-logo img {
        max-height: 36px !important;
        width: auto !important;
    }
    .ksn-menu-drawer-close {
        background: #f1f5f9 !important;
        border: none !important;
        width: 32px !important;
        height: 32px !important;
        border-radius: 50% !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        color: #334155 !important;
        cursor: pointer !important;
    }

    /* بدنه اسکرول‌خور */
    .ksn-menu-drawer-body {
        flex: 1 1 auto !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        padding: 0 !important;
    }

    /* ساختار درختی منو */
    #ksnMenuDrawer ul.ksn-mobile-menu-ul {
        list-style: none !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    #ksnMenuDrawer li {
        border-bottom: 1px solid #f1f5f9 !important;
        position: relative;
    }

    #ksnMenuDrawer a {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        padding: 13px 16px !important;
        font-size: 13px !important;
        font-weight: 600 !important;
        color: #1e293b !important;
        text-decoration: none !important;
    }

    /* استایل فلش برای آیتم‌های دارای زیرمنو */
    #ksnMenuDrawer li.menu-item-has-children > a::after {
        content: "";
        display: inline-block;
        width: 6px;
        height: 6px;
        border-right: 2px solid #64748b;
        border-bottom: 2px solid #64748b;
        transform: rotate(-45deg);
        transition: transform 0.2s ease;
        margin-right: 8px;
    }
    #ksnMenuDrawer li.menu-item-has-children.is-active > a::after {
        transform: rotate(45deg);
    }

    /* زیرمنوها (به صورت آکاردیونی و مخفی‌پیش‌فرض) */
    #ksnMenuDrawer ul.sub-menu {
        display: none !important;
        list-style: none !important;
        margin: 0 !important;
        padding: 0 !important;
        background: #f8fafc !important;
        border-top: 1px solid #f1f5f9 !important;
    }
    #ksnMenuDrawer li.is-active > ul.sub-menu {
        display: block !important;
    }

    #ksnMenuDrawer ul.sub-menu a {
        padding: 11px 24px !important;
        font-size: 12px !important;
        font-weight: 400 !important;
        color: #475569 !important;
    }

    /* ۵. رپر دکمه خرید سریع در موبایل */
    .ksn-quick-order-wrapper {
        display: flex;
        justify-content: flex-start;
        padding: 10px 16px;
    }

    .ksn-quick-order-btn {
        display: inline-flex;
        align-items: center;
        gap: 7px;
        padding: 7px 14px;
        background-color: #f7f9fb;
        border: 1px solid #dce2e8;
        border-radius: 8px;
        font-size: 13px;
        font-weight: 700;
        color: #1e293b;
        text-decoration: none;
        line-height: 1.2;
        transition: all 0.2s ease;
    }

    .ksn-quick-order-btn:hover,
    .ksn-quick-order-btn:active {
        background-color: #edf2f7;
        border-color: #cbd5e1;
        color: #0f172a;
    }

    .ksn-quick-order-btn .ksn-grid-icon {
        flex-shrink: 0;
        color: #334155;
    }

    /* ۶. دراور و اورلی حساب کاربری (موبایل) */
    .ksn-account-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(2px);
        z-index: 99998;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    .ksn-account-overlay.is-active {
        opacity: 1;
        visibility: visible;
    }

    .ksn-account-drawer {
        position: fixed;
        top: 0;
        left: 0;
        width: 300px;
        max-width: 85vw;
        height: 100vh;
        background-color: #fff;
        z-index: 99999;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
        display: flex;
        flex-direction: column;
    }

    .ksn-account-drawer.is-open {
        transform: translateX(0);
    }

    .admin-bar .ksn-account-drawer {
        top: 46px !important;
        height: calc(100vh - 46px) !important;
    }

    @media (min-width: 783px) {
        .admin-bar .ksn-account-drawer {
            top: 32px !important;
            height: calc(100vh - 32px) !important;
        }
    }

    .ksn-account-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 14px 16px;
        border-bottom: 1px solid #f1f5f9;
    }

    .ksn-account-user-info {
        display: flex;
        align-items: center;
        gap: 10px;
    }

    .ksn-account-avatar img {
        border-radius: 50%;
        display: block;
    }

    .ksn-account-meta {
        display: flex;
        flex-direction: column;
    }

    .ksn-user-name {
        font-size: 14px;
        font-weight: 700;
        color: #1e293b;
    }

    .ksn-user-role {
        font-size: 11px;
        color: #64748b;
    }

    .ksn-account-title {
        font-size: 15px;
        font-weight: 700;
        color: #1e293b;
    }

    .ksn-account-close {
        background: none;
        border: none;
        padding: 6px;
        cursor: pointer;
        color: #64748b;
        display: flex;
        align-items: center;
    }

    .ksn-account-body {
        flex: 1;
        overflow-y: auto;
        padding: 12px 0;
    }

    .ksn-account-menu {
        list-style: none;
        margin: 0;
        padding: 0;
    }

    .ksn-account-menu li a {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 12px 20px;
        color: #334155;
        text-decoration: none;
        font-size: 13.5px;
        font-weight: 600;
        border-bottom: 1px solid #f8fafc;
        transition: background-color 0.2s ease, color 0.2s ease;
    }

    .ksn-account-menu li.is-active a,
    .ksn-account-menu li a:hover {
        background-color: #f1f5f9;
        color: #0284c7;
    }

    .ksn-account-menu li.customer-logout a {
        color: #ef4444;
    }

    .ksn-arrow-icon {
        transform: rotate(180deg);
        color: #94a3b8;
    }

    .ksn-account-guest {
        padding: 30px 20px;
        text-align: center;
    }

    .ksn-guest-icon {
        margin-bottom: 14px;
    }

    .ksn-guest-text {
        font-size: 13px;
        color: #64748b;
        line-height: 1.6;
        margin-bottom: 20px;
    }

    .ksn-btn-login {
        display: block;
        width: 100%;
        padding: 10px;
        background-color: #0284c7;
        color: #fff !important;
        text-align: center;
        text-decoration: none;
        border-radius: 8px;
        font-size: 14px;
        font-weight: 700;
    }
}

/* ==========================================================================
   قفل کردن اسکرول صفحه فقط هنگام باز بودن دراورها
   ========================================================================== */
body.ksn-menu-open,
body.ksn-cart-open,
body.ksn-account-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
}
