/* ===== Mega Menu Simple & Stable ===== */

/* Define navbar height variable */
:root {
    --navbar-height: 80px;
}

/* Prevent horizontal scroll globally when mega menu is open */
html {
    overflow-x: hidden;
}

body {
    overflow-x: hidden;
    max-width: 100vw;
    box-sizing: border-box;
}

.navbar {
    height: var(--navbar-height);
}

.navbar-nav {
    overflow: visible;
}

.navbar .container {
    max-width: 100%;
    overflow-x: hidden;
    position: relative;
    overflow: visible;
}

/* Mega Dropdown Container */
.mega-dropdown {
    position: static !important;
}

/* Mega Menu - بهینه سازی شده */
.mega-menu {
    position: fixed !important;
    top: calc(var(--navbar-height, 80px) - 2px) !important;
    left: 0 !important;
    right: 0 !important;
    transform: none !important;
    background: #fff;
    border: none;
    border-radius: 0 0 16px 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
    padding: 20px 0 15px 0; /* کاهش padding */
    width: 100vw;
    max-width: 100vw;
    max-height: 70vh; /* محدود کردن ارتفاع */
    overflow-y: auto; /* اضافه کردن scroll */
    z-index: 1050;
    
    /* Initially hidden */
    display: none;
    
    /* Prevent horizontal scroll */
    overflow-x: hidden;
    box-sizing: border-box;
    margin: 0;
    
    /* اطمینان از عدم وجود gap */
    margin-top: 0 !important;
}

/* Show on hover - JavaScript کنترل می‌کنه */
.mega-menu {
    pointer-events: auto;
    opacity: 0;
    transition: opacity 0.2s ease;
}

/* فقط برای fallback اگر JavaScript کار نکرد */
@media (hover: hover) {
    .mega-dropdown:hover .mega-menu {
        display: block !important;
        opacity: 1 !important;
    }
}

/* Bridge gap between navbar and menu - حل مشکل فاصله */
.mega-dropdown .dropdown-toggle {
    position: relative;
    padding-bottom: 5px !important; /* فضای اضافی برای bridge */
}

.mega-dropdown .dropdown-toggle::after {
    content: '';
    position: absolute;
    bottom: -10px; /* کاهش فاصله */
    left: -20px; /* گسترش به چپ و راست */
    right: -20px;
    height: 20px; /* افزایش ارتفاع bridge */
    background: transparent;
    z-index: 1049;
}

/* پیشگیری از بسته شدن منو با hover بر روی کل منطقه */
.mega-dropdown {
    position: static !important;
}

.mega-dropdown::before {
    content: '';
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    height: 5px; /* bridge اضافی */
    background: transparent;
    z-index: 1048;
}

/* Container */
.mega-menu .container {
    max-width: min(1200px, calc(100vw - 40px));
    margin: 0 auto;
    padding: 0 20px;
    width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
}

/* Menu Section - کامپکت‌تر */
.mega-menu-section {
    background: #fff;
    border-radius: 8px;
    padding: 15px; /* کاهش padding */
    border: 1px solid #e9ecef;
    transition: box-shadow 0.3s ease;
    margin-bottom: 15px; /* کاهش margin */
}

.mega-menu-section:hover {
    box-shadow: 0 4px 15px rgba(46, 125, 50, 0.1);
}

/* Menu Title - کوچک‌تر */
.mega-menu-title {
    font-weight: 700;
    font-size: 15px; /* کاهش فونت */
    color: #2E7D32;
    margin-bottom: 10px; /* کاهش margin */
    padding-bottom: 8px; /* کاهش padding */
    border-bottom: 2px solid #e9ecef;
    display: flex;
    align-items: center;
}

.mega-menu-title a {
    color: inherit;
    text-decoration: none;
    flex: 1;
}

.mega-menu-title a:hover {
    color: #1B5E20;
}

.mega-menu-title i {
    color: #4CAF50;
    font-size: 16px; /* کاهش اندازه آیکون */
}

.mega-menu-title .product-count {
    font-size: 11px; /* کاهش فونت */
    font-weight: 500;
    color: #6c757d;
    background: #f8f9fa;
    padding: 2px 6px; /* کاهش padding */
    border-radius: 12px;
    margin-right: 8px;
}

/* Menu List */
.mega-menu-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.mega-menu-list li {
    margin-bottom: 5px; /* کاهش margin */
}

/* Menu Item - کامپکت‌تر */
.mega-menu-item {
    display: flex;
    align-items: center;
    padding: 8px 10px; /* کاهش padding */
    color: #495057;
    text-decoration: none;
    border-radius: 6px;
    transition: all 0.2s ease;
    font-size: 13px; /* کاهش فونت */
    font-weight: 500;
}

.mega-menu-item:hover {
    background: rgba(46, 125, 50, 0.08);
    color: #2E7D32;
    text-decoration: none;
}

.mega-menu-item i {
    color: #4CAF50;
    font-size: 14px; /* کاهش اندازه آیکون */
    width: 18px; /* کاهش عرض */
    text-align: center;
}

.mega-menu-item:hover i {
    color: #2E7D32;
}

.mega-menu-item .product-count {
    font-size: 10px; /* کاهش فونت */
    font-weight: 500;
    color: #6c757d;
    background: #f8f9fa;
    padding: 1px 5px; /* کاهش padding */
    border-radius: 10px;
    margin-right: 8px;
}

.mega-menu-item:hover .product-count {
    background: rgba(46, 125, 50, 0.1);
    color: #2E7D32;
}

/* مشاهده بیشتر لینک */
.more-categories {
    border-top: 1px solid #e9ecef;
    padding-top: 8px;
    margin-top: 8px;
}

.mega-menu-item.more-link {
    color: #6c757d;
    font-style: italic;
    font-size: 12px;
    font-weight: 400;
}

.mega-menu-item.more-link:hover {
    color: #495057;
    background: rgba(108, 117, 125, 0.1);
}

.mega-menu-item.more-link i {
    color: #6c757d;
    font-size: 12px;
}

.mega-menu-item.more-link:hover i {
    color: #495057;
}

/* Menu Footer - کامپکت‌تر */
.mega-menu-footer {
    margin-top: 10px; /* کاهش margin */
    padding-top: 10px; /* کاهش padding */
    border-top: 1px solid #e9ecef;
}

.mega-menu-footer .btn {
    font-size: 12px; /* کاهش فونت */
    padding: 6px 12px; /* کاهش padding */
    border-radius: 6px;
}

/* Menu Bottom - کامپکت‌تر */
.mega-menu-bottom {
    margin-top: 15px; /* کاهش margin */
    padding-top: 15px; /* کاهش padding */
    border-top: 2px solid #e9ecef;
}

/* Menu Banner - کامپکت‌تر */
.mega-menu-banner {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 12px;
    padding: 15px; /* کاهش padding */
    margin-bottom: 10px; /* کاهش margin */
    position: relative;
    overflow: hidden;
    border: 1px solid #e9ecef;
    transition: all 0.3s ease;
}

/* Animated gradient border effect */
.mega-menu-banner::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 16px;
    padding: 2px;
    background: linear-gradient(135deg, 
        rgba(46, 125, 50, 0.2), 
        rgba(76, 175, 80, 0.3), 
        rgba(129, 199, 132, 0.2), 
        rgba(46, 125, 50, 0.2)
    );
    background-size: 400% 400%;
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask-composite: xor;
    z-index: -1;
    opacity: 0;
    transition: opacity 0.4s ease;
    animation: gradientBorder 3s ease infinite;
}

@keyframes gradientBorder {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.mega-menu-banner:hover::before {
    opacity: 1;
}

/* Floating particles effect */
.mega-menu-banner::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: 
        radial-gradient(circle at 20% 20%, rgba(46, 125, 50, 0.1) 2px, transparent 2px),
        radial-gradient(circle at 80% 80%, rgba(76, 175, 80, 0.08) 1px, transparent 1px),
        radial-gradient(circle at 40% 60%, rgba(129, 199, 132, 0.06) 1.5px, transparent 1.5px);
    background-size: 50px 50px, 30px 30px, 70px 70px;
    opacity: 0;
    transition: opacity 0.4s ease;
    animation: floatingParticles 20s linear infinite;
    pointer-events: none;
}

@keyframes floatingParticles {
    from { transform: translate(-10px, -10px) rotate(0deg); }
    to { transform: translate(10px, 10px) rotate(360deg); }
}

.mega-menu-banner:hover::after {
    opacity: 0.6;
}

.mega-menu-banner:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: 
        0 12px 40px rgba(46, 125, 50, 0.15),
        0 4px 12px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    border-color: rgba(46, 125, 50, 0.2);
}

/* Banner content styling - کامپکت‌تر */
.banner-content {
    position: relative;
    z-index: 2;
}

.banner-content h6 {
    font-weight: 700;
    margin-bottom: 8px; /* کاهش margin */
    color: #2E7D32;
    font-size: 14px; /* کاهش فونت */
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px; /* کاهش gap */
    line-height: 1.3;
}

.banner-content h6 i {
    font-size: 16px; /* کاهش اندازه آیکون */
    background: linear-gradient(135deg, #2E7D32, #4CAF50);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 1px 2px rgba(46, 125, 50, 0.3));
}

.banner-content p {
    color: #558B2F;
    margin-bottom: 12px; /* کاهش margin */
    font-size: 12px; /* کاهش فونت */
    line-height: 1.4;
    font-weight: 500;
    opacity: 0.9;
}

.banner-content .btn {
    font-weight: 600;
    border-radius: 20px; /* کاهش radius */
    padding: 8px 16px; /* کاهش padding */
    font-size: 11px; /* کاهش فونت */
    text-transform: none;
    letter-spacing: 0.3px;
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    border: 2px solid transparent;
    background: linear-gradient(135deg, #2E7D32, #4CAF50);
    color: white;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px; /* کاهش gap */
    box-shadow: 0 4px 15px rgba(46, 125, 50, 0.3);
    position: relative;
    overflow: hidden;
}

.banner-content .btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.6s ease;
}

.banner-content .btn:hover::before {
    left: 100%;
}

.banner-content .btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(46, 125, 50, 0.4);
    background: linear-gradient(135deg, #1B5E20, #2E7D32);
}

.banner-content .btn i {
    transition: transform 0.3s ease;
}

.banner-content .btn:hover i {
    transform: scale(1.1) rotate(5deg);
}

/* Special styling for different banner types */
.mega-menu-banner:first-child {
    background: linear-gradient(135deg, #fff5f5 0%, #fef7f7 50%, #fff0f3 100%);
}

.mega-menu-banner:first-child .banner-content h6 i {
    background: linear-gradient(135deg, #1976D2, #2196F3);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.mega-menu-banner:first-child .banner-content .btn {
    background: linear-gradient(135deg, #1976D2, #2196F3);
    box-shadow: 0 4px 15px rgba(25, 118, 210, 0.3);
}

.mega-menu-banner:first-child .banner-content .btn:hover {
    background: linear-gradient(135deg, #0D47A1, #1976D2);
    box-shadow: 0 8px 25px rgba(25, 118, 210, 0.4);
}

.mega-menu-banner:last-child {
    background: linear-gradient(135deg, #f0f8ff 0%, #f5f9ff 50%, #fafcff 100%);
}

.mega-menu-banner:last-child .banner-content h6 i {
    background: linear-gradient(135deg, #0288D1, #03A9F4);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.mega-menu-banner:last-child .banner-content .btn {
    background: linear-gradient(135deg, #0288D1, #03A9F4);
    box-shadow: 0 4px 15px rgba(2, 136, 209, 0.3);
}

.mega-menu-banner:last-child .banner-content .btn:hover {
    background: linear-gradient(135deg, #01579B, #0288D1);
    box-shadow: 0 8px 25px rgba(2, 136, 209, 0.4);
}

/* Wrapper for better positioning */
.navbar .container {
    position: relative;
    overflow: visible;
}

.mega-dropdown .dropdown-menu {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 100vw;
    max-width: calc(100vw - 30px);
    margin-left: calc(-50vw + 50%);
    margin-right: calc(-50vw + 50%);
}

/* Mobile Responsive - بهینه سازی شده */
@media (max-width: 991.98px) {
    .mega-menu {
        position: relative !important;
        left: auto !important;
        transform: none !important;
        min-width: auto !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: 50vh !important; /* کاهش ارتفاع برای موبایل */
        box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        padding: 12px; /* کاهش padding */
        border-radius: 8px;
        margin-top: 8px;
        display: block !important;
        overflow-y: auto; /* اضافه کردن scroll */
    }
    
    .mega-menu-section {
        margin-bottom: 12px; /* کاهش margin */
        padding: 12px; /* کاهش padding */
    }
    
    .mega-menu-bottom {
        margin-top: 12px;
        padding-top: 12px;
    }
    
    .mega-menu-banner {
        margin-bottom: 10px;
        padding: 15px; /* کاهش padding */
        border-radius: 10px;
    }
    
    .banner-content h6 {
        font-size: 13px; /* کاهش فونت */
        margin-bottom: 8px;
    }
    
    .banner-content .btn {
        padding: 6px 14px; /* کاهش padding */
        font-size: 10px; /* کاهش فونت */
    }
    
    /* مخفی کردن banner در موبایل برای صرفه‌جویی در فضا */
    .mega-menu-bottom {
        display: none;
    }
}

@media (max-width: 767.98px) {
    .mega-menu {
        padding: 8px; /* کاهش padding */
        border-radius: 6px;
        max-height: 40vh; /* کاهش بیشتر ارتفاع */
    }
    
    .mega-menu-section {
        padding: 10px; /* کاهش padding */
        border-radius: 6px;
        margin-bottom: 10px;
    }
    
    .mega-menu-title {
        font-size: 13px; /* کاهش فونت */
        margin-bottom: 8px;
        padding-bottom: 6px;
    }
    
    .mega-menu-item {
        padding: 6px 8px; /* کاهش padding */
        font-size: 12px; /* کاهش فونت */
    }
    
    .mega-menu-item i {
        font-size: 12px; /* کاهش آیکون */
        width: 16px;
    }
    
    .mega-menu-item .product-count {
        font-size: 9px; /* کاهش فونت */
        padding: 1px 4px;
    }
    
    /* مخفی کردن بخش‌های اضافی در موبایل کوچک */
    .mega-menu-banner {
        display: none;
    }
    
    .mega-menu-footer {
        margin-top: 8px;
        padding-top: 8px;
    }
    
    .mega-menu-footer .btn {
        padding: 5px 10px;
        font-size: 10px;
    }
    
    /* کاهش animations برای بهبود performance */
    .mega-menu-banner::before,
    .mega-menu-banner::after {
        display: none;
    }
    
    .mega-menu-banner:hover {
        transform: none; /* حذف transform */
    }
    
    .mega-menu-item:hover {
        transform: none; /* حذف transform */
    }
    
    /* بهبود scroll */
    .mega-menu {
        scrollbar-width: thin;
        scrollbar-color: #ccc #f0f0f0;
    }
    
    .mega-menu::-webkit-scrollbar {
        width: 4px;
    }
    
    .mega-menu::-webkit-scrollbar-track {
        background: #f0f0f0;
        border-radius: 2px;
    }
    
    .mega-menu::-webkit-scrollbar-thumb {
        background: #ccc;
        border-radius: 2px;
    }
    
    .mega-menu::-webkit-scrollbar-thumb:hover {
        background: #999;
    }
}

/* ==== User Dropdown Fix - حل مشکل gap برای dropdown حساب کاربری ==== */
.user-dropdown {
    position: relative;
}

.user-dropdown .dropdown-toggle {
    position: relative;
    padding-bottom: 10px !important;
}

.user-dropdown .dropdown-toggle::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: -10px;
    right: -10px;
    height: 15px;
    background: transparent;
    z-index: 1049;
}

.user-dropdown .dropdown-menu {
    margin-top: -5px !important; /* کاهش فاصله */
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    border: 1px solid #dee2e6;
    padding: 8px 0;
    min-width: 200px;
}

.user-dropdown .dropdown-item {
    padding: 10px 20px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
}

.user-dropdown .dropdown-item:hover {
    background-color: rgba(40, 167, 69, 0.1);
    color: #2E7D32;
    transform: translateX(3px);
}

.user-dropdown .dropdown-item i {
    width: 20px;
    color: #6c757d;
    transition: color 0.2s ease;
}

.user-dropdown .dropdown-item:hover i {
    color: #2E7D32;
}

.user-dropdown .dropdown-divider {
    margin: 8px 0;
    border-color: #e9ecef;
}

/* انیمیشن برای dropdown */
.user-dropdown .dropdown-menu {
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    pointer-events: none;
}

.user-dropdown .show .dropdown-menu {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

/* === Categories Modal Specific === */
#categoriesModal .mega-menu-section {
    display: flex;
    flex-direction: column;
    height: 100%;
}

#categoriesModal .mega-menu-title {
    margin-bottom: 12px;
}

#categoriesModal .mega-menu-list {
    flex-grow: 1;
    overflow: hidden;
    padding-bottom: 4px;
}

#categoriesModal .mega-menu-footer {
    margin-top: auto; /* push footer to bottom */
}

#categoriesModal .mega-menu-section:hover {
    box-shadow: 0 3px 12px rgba(63, 112, 77, 0.15);
}

#categoriesModal .col {
    padding: 0 !important;
}

#categoriesModal .row.g-3 > .col {
    padding: 0 12px 12px 12px !important;
}