/**
 * Divi Mega Menu - Frontend Styles
 * Modern, responsive mega menu design
 */

/* Reset and base styles */
.divi-mega-menu-container {
    position: relative !important; /* Positioning context for absolute dropdowns */
    width: 100% !important;
    z-index: 9999 !important;
    background: white !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1) !important;
    margin: 0 !important;
    padding: 0 20px !important;
    /* Explicitly ensure natural flow positioning - no fixed positioning */
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    top: auto !important;
}

.divi-mega-menu {
    position: relative;
    z-index: 9999;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
}

.divi-mega-menu * {
    box-sizing: border-box;
}

/* Main navigation */
.divi-mega-menu-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    list-style: none;
    margin: 0;
    padding: 0;
    background: var(--mega-menu-bg, #ffffff);
    min-height: 59px;
    flex-wrap: nowrap;
    position: relative; /* Needed for dropdown positioning */
    width: 100%;
    overflow: hidden; /* Prevent any content from going off screen */
}

/* Menu items container - dynamic width allocation */
.mega-menu-items {
    display: flex;
    align-items: center;
    flex: 1;
    gap: clamp(0px, 0.5vw, 10px);
    min-width: 0; /* Allow shrinking */
}

/* Buy Now button */
.mega-menu-buy-now {
    background: #5DB737 !important;
    color: white !important;
    padding: 7px 22px !important;
    border-radius: 22px !important;
    text-decoration: none !important;
    font-weight: 600 !important;
    font-size: 14px !important;
    border: none !important;
    cursor: pointer !important;
    transition: all 0.3s ease !important;
    margin-left: 20px !important;
}

.mega-menu-buy-now:hover {
    background: #4ca82e !important;
    color: white !important;
}

.divi-mega-menu-item {
    position: relative;
    margin: 0;
    flex: 0 1 auto; /* Size based on content, allow shrinking */
    min-width: 0; /* Allow shrinking */
}

a.divi-mega-menu-link {
    display: flex;
    align-items: center;
    padding: clamp(6px, 1vw, 15px) clamp(8px, 1.5vw, 20px);
    color: #272727;
    text-decoration: none;
    font-weight: 400;
    font-size: clamp(10px, 1.4vw, 16px);
    line-height: clamp(1.1, 1.2, 1.4);
    transition: all 0.3s ease;
    white-space: nowrap;
    text-align: center;
}

.divi-mega-menu-link:hover,
.divi-mega-menu-item:hover > .divi-mega-menu-link {
    color: #5DB737;
}

/* Dropdown arrow */
a.divi-mega-menu-link::after {
    content: url(/wp-content/uploads/2025/08/menu-arrow-down.svg);
    width: 1em;
    height: 1em;
    transition: transform 0.3s ease;
    position: absolute;
    top:auto;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.divi-mega-menu-item:hover .divi-mega-menu-link::after {
    transform: rotate(180deg);
}

/* Hide arrow for items without mega menu */
.divi-mega-menu-item:not([data-has-mega]) .divi-mega-menu-link::after {
    display: none;
}

/* Mega menu dropdown - viewport-centered positioning */
.mega-menu-dropdown {
    position: fixed; /* Fixed positioning relative to viewport */
    top: var(--dropdown-top, 100px); /* Will be set dynamically */
    left: 2.5vw; /* 2.5vw from left edge (centers 95vw width) */
    right: auto;
    width: 95vw; /* 95vw as requested */
    max-width: 95vw; /* Maximum 95vw width */
    min-width: 800px; /* Minimum width for desktop */
    background: var(--mega-menu-dropdown-bg, #ffffff);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    border-radius: 12px;
    border: 1px solid var(--mega-menu-border, #e5e7eb);
    opacity: 0;
    visibility: hidden;
    transition: all var(--mega-menu-animation-speed, 300ms) ease;
    z-index: 10000;
    transform: translateY(-10px); /* Only Y transform for smooth animation */
    box-sizing: border-box;
    margin-top: 0; /* No extra margin */
}

/* Dropdown visibility now controlled by JavaScript with delay */
/* Removed CSS hover rule to prevent immediate dropdown appearance */

/* Show dropdown only when JavaScript adds 'active' class */
.mega-menu-dropdown.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.mega-menu-content {
    padding: clamp(1.5rem, 3vw, 3rem); /* Dynamic padding */
    display: flex;
    flex-direction: row;
    gap: clamp(1rem, 2.5vw, 2.5rem); /* Dynamic gap */
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: nowrap;
    width: 100%;
    min-width: 100%; /* Ensure full width coverage */
    min-height: clamp(20rem, 25vh, 25rem); /* Dynamic height */
    box-sizing: border-box; /* Include padding in width calculation */
}

/* Columns layout - inherits flex from content */
.mega-menu-columns {
    display: contents; /* Use parent flex context */
}

/* Regular menu columns - responsive flex basis */
.mega-menu-column {
    flex: 1 1 0; /* Equal distribution of available space */
    min-width: clamp(12rem, 15vw, 18rem); /* Dynamic minimum width */
    max-width: none;
    height: 100%; /* Full height coverage */
}

/* Product column - responsive right-aligned */
.mega-menu-column[data-type="products"] {
    flex: 0 0 clamp(18rem, 22vw, 25rem); /* Dynamic product column width */
    order: 999; /* Always last (right side) */
    margin-left: auto; /* Push to right */
    height: 100%; /* Full height coverage */
}

/* When there's a product column, other columns share remaining space dynamically */
.mega-menu-content:has(.mega-menu-column[data-type="products"]) .mega-menu-column:not([data-type="products"]) {
    flex: 1 1 0; /* Equal sharing of remaining space */
    min-width: clamp(10rem, 12vw, 15rem); /* Dynamic minimum */
    max-width: clamp(16rem, 20vw, 22rem); /* Dynamic maximum */
}

/* Categories and links */
.mega-menu-category {
    margin-bottom: 24px;
}

.mega-menu-category:last-child {
    margin-bottom: 0;
}

.mega-menu-category-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--mega-menu-title, #1f2937);
    margin: 0 0 12px 0;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--mega-menu-hover, #10b981);
}

.mega-menu-category-title-link {
    color: inherit;
    text-decoration: none;
    transition: color 0.2s ease;
}

.mega-menu-category-title-link:hover {
    color: var(--mega-menu-hover, #10b981);
    text-decoration: none;
}

.divi-mega-menu ul.mega-menu-links {
    list-style: none;
    margin: 0;
    padding: 0;
}
.divi-mega-menu .mega-menu-links li::marker {
    display: none;
    opacity: 0;
    color: transparent;
}
.mega-menu-links li {
    margin-bottom: 8px;
}

.mega-menu-links a {
    display: block;
    padding: 8px 0;
    color: var(--mega-menu-link, #6b7280);
    text-decoration: none;
    font-size: 15px;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    padding-left: 12px;
}

.mega-menu-links a:hover {
    color: var(--mega-menu-hover, #10b981);
    border-left-color: var(--mega-menu-hover, #10b981);
    padding-left: 16px;
}

/* Products */
.mega-menu-products {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0;
	justify-content: center;
    margin-left: 2em;
    margin-top: 1em;
}

.mega-menu-product {
    background: #f8fafc;
    border-radius: 12px;
    overflow: hidden;
    transition: all 0.3s ease;
    border: 1px solid #e2e8f0;
}

.mega-menu-product:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.mega-menu-product-link {
    display: block;
    text-decoration: none;
    color: inherit;
}

.mega-menu-product-image {
    aspect-ratio: 1;
    overflow: hidden;
    background: #f1f5f9;
}

.mega-menu-product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.mega-menu-product:hover .mega-menu-product-image img {
    transform: scale(1.05);
}

.mega-menu-product-info {
    padding: 16px;
}

.mega-menu-product-title {
    font-size: 16px;
    font-weight: 600;
    color: #1f2937;
    margin: 0 0 8px 0;
    line-height: 1.4;
}

.mega-menu-product-price {
    font-size: 18px;
    font-weight: 700;
    color: var(--mega-menu-hover, #10b981);
    margin-bottom: 12px;
}

/* Product actions */
.mega-menu-product-actions {
    padding: 0 16px 16px 16px;
}

.mega-menu-product-buy {
    display: inline-block;
    background: #5DB737;
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    text-align: center;
    transition: all 0.3s ease;
    width: 100%;
    box-sizing: border-box;
}

.mega-menu-product-buy:hover {
    background: #4ca82e;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(93, 183, 55, 0.3);
    color: white;
    text-decoration: none;
}

/* Custom content */
.mega-menu-column-custom {
    padding: 20px;
    background: #f8fafc;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
}

/* Tablet responsive - adjust proportions */
@media (max-width: 1024px) {
    .mega-menu-dropdown {
        width: 92vw; /* Slightly more conservative on tablets */
        min-width: 600px;
        max-width: 92vw;
    }
    
    .mega-menu-content {
        padding: clamp(1rem, 2.5vw, 2rem);
        gap: clamp(0.75rem, 2vw, 1.5rem);
    }
    
    .mega-menu-column {
        min-width: clamp(10rem, 12vw, 14rem);
    }
    
    .mega-menu-column[data-type="products"] {
        flex: 0 0 clamp(16rem, 20vw, 20rem);
    }
}

/* Product buy buttons - customizable styles */
.mega-menu-product-buy {
    background: #ACFF89;
    border-radius: 8px;
    padding: 8px 18px;
    font-family: 'Poppins', sans-serif;
    font-weight: 400;
    font-size: 14px;
    line-height: 17px;
    letter-spacing: -0.3px;
    color: #323232;
    height: 32px;
    min-width: 61px;
    transition: all 0.3s ease;
}

.mega-menu-product-buy:hover {
    background: #9AE577;
    color: #323232;
    transform: translateY(-1px);
}

/* Add-to-cart buttons - customizable styles */
.add-to-cart-btn {
    background: transparent;
    color: var(--mega-menu-hover, #10b981);
    border: 2px solid var(--mega-menu-hover, #10b981);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all 0.3s ease;
}

.add-to-cart-btn:hover {
    background: var(--mega-menu-hover, #10b981);
    color: white;
    transform: translateY(-1px);
}

/* Mega menu titles - customizable styles */
.mega-menu-title {
    font-family: 'Barlow Condensed', sans-serif;
    font-weight: 500;
    font-size: 22px;
    line-height: 1.2;
    color: #272727;
    margin-bottom: 12px;
    padding: 12px 40px 0 40px;
    margin-left: -40px;
    margin-right: -40px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 8px 8px 0 0;
}

/* Category titles - customizable styles */
.mega-menu-category-title {
    font-family: 'Poppins', sans-serif;
    font-weight: 600;
    font-size: 14px;
    line-height: 24px;
}

/* Search dropdown z-index fix */
.search-results-dropdown {
    z-index: 10000 !important;
    position: absolute !important;
}

/* Hide redundant search button for AJAX search */
.mega-menu-search-form button[type="submit"] {
    display: none;
}

/* Custom button responsive improvements */
.custom-button-container {
    flex-shrink: 0;
    margin-left: auto;
    max-width: clamp(80px, 20vw, 200px);
    min-width: 60px;
}

.custom-button {
    white-space: nowrap;
    width: 100%;
    font-size: clamp(8px, 1.1vw, 14px);
    line-height: clamp(1, 1.1, 1.3);
    padding: clamp(4px, 0.8vw, 12px) clamp(6px, 1.2vw, 16px);
    border-radius: clamp(15px, 2vw, 20px);
    text-align: center;
    display: block;
}

/* Dropdown scrolling improvements */
.mega-menu-dropdown {
    overscroll-behavior: contain; /* Prevent scroll chaining to page */
}

/* Complete body scroll lock when hovering dropdowns */
body.mega-menu-scroll-locked {
    overflow: hidden !important;
    overscroll-behavior: none !important;
}

/* Responsive breakpoints with proper scaling */
@media (max-width: 1200px) {
    .mega-menu-dropdown {
        max-height: 80vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
    
    .mega-menu-title {
        font-size: 20px;
        padding: 10px 20px 0 20px;
        margin-left: -20px;
        margin-right: -20px;
    }
    
    .mega-menu-category-title {
        font-size: 13px;
        line-height: 20px;
    }
    
    .divi-mega-menu-link {
        font-size: clamp(12px, 1.5vw, 16px);
        padding: clamp(8px, 1vw, 12px) clamp(12px, 2vw, 20px);
    }
    
    .custom-button {
        font-size: clamp(11px, 1.3vw, 14px);
        padding: clamp(6px, 0.8vw, 10px) clamp(10px, 1.5vw, 16px);
        white-space: nowrap;
        min-width: auto;
    }
}

@media (max-width: 960px) {
    .mega-menu-dropdown {
        max-height: 70vh;
    }
    
    .mega-menu-title {
        font-size: 18px;
        padding: 8px 16px 0 16px;
        margin-left: -16px;
        margin-right: -16px;
    }
    
    .mega-menu-category-title {
        font-size: 12px;
        line-height: 18px;
    }
    
    .divi-mega-menu-nav {
        padding: 0 10px;
    }
    
    .divi-mega-menu-link {
        font-size: clamp(11px, 1.8vw, 14px);
        padding: clamp(6px, 1vw, 10px) clamp(8px, 1.5vw, 16px);
    }
    
    .custom-button {
        font-size: clamp(10px, 1.5vw, 12px);
        padding: clamp(5px, 0.8vw, 8px) clamp(8px, 1.3vw, 12px);
    }
}

/* Mobile responsive - stack everything */
@media (max-width: 768px) {
    .divi-mega-menu-nav {
        flex-direction: column;
        align-items: stretch;
        padding: 0 8px;
    }
    
    .divi-mega-menu-item {
        width: 100%;
        border-bottom: 1px solid #e5e7eb;
    }
    
    .divi-mega-menu-link {
        font-size: 14px;
        padding: 10px 12px;
        text-align: center;
    }
    
    .custom-button {
        font-size: 12px;
        padding: 8px 12px;
        margin: 5px 0;
        text-align: center;
        white-space: normal;
        line-height: 1.3;
    }
    
    .mega-menu-dropdown {
        position: static;
        min-width: auto;
        width: 100%;
        max-height: 60vh;
        box-shadow: none;
        border: none;
        border-radius: 0;
        opacity: 1;
        visibility: visible;
        transform: none;
        display: none;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .mega-menu-title {
        font-size: 16px;
        padding: 8px 12px 0 12px;
        margin-left: -12px;
        margin-right: -12px;
    }
    
    .mega-menu-category-title {
        font-size: 11px;
        line-height: 16px;
    }
    
    .divi-mega-menu-item.mobile-open .mega-menu-dropdown {
        display: block;
    }
    
    .mega-menu-dropdown {
        width: 95vw;
        min-width: 20rem;
        max-width: 95vw;
    }
    
    .mega-menu-content {
        padding: clamp(1rem, 4vw, 1.5rem);
        flex-direction: column;
        gap: clamp(1rem, 3vw, 1.5rem);
        min-height: auto;
    }
    
    .mega-menu-columns {
        display: contents;
    }
    
    .mega-menu-column {
        min-width: auto;
        max-width: none;
        flex: 1 1 auto !important; /* Reset all columns to equal on mobile */
        order: initial !important;
        margin-left: 0 !important;
    }
    
    /* Product column loses special treatment on mobile */
    .mega-menu-column[data-type="products"] {
        flex: 1 1 auto !important;
        order: initial !important;
        margin-left: 0 !important;
    }
    
    .mega-menu-products {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        gap: 16px;
    }
}

/* Hide Divi navigation when mega menu is active */
#et-top-navigation,
.et_mobile_menu,
#main-header .et_mobile_menu,
.mobile_menu_bar,
.et_pb_menu,
.et_pb_menu__menu,
.et-main-menu-container {
    /* display: none !important; */
}

/* Ensure proper spacing - don't cover logo */
#main-header {
    position: relative;
}

/* Accessibility */
.mega-menu-dropdown[aria-hidden="true"] {
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
}

.mega-menu-dropdown[aria-hidden="false"] {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
.scroll-down .announcement-bar {
    display: none;
}
.scroll-down .divi-mega-menu-logo-bar {
    display: none;
}
#divi-mega-menu-header-system.scroll-down.is-sticky .divi-mega-menu-link {
    padding-top: 0em !important;
    padding-bottom: 0 !important;
}
.scroll-down .mega-menu-buy-now {
    padding-top: 0.3em !important;
    padding-bottom: 0.3em !important;
}
.scroll-down ul.divi-mega-menu-nav {
    min-height: 0;
    padding: 0.7em 0;
}
.scroll-down .mega-menu-buy-now:before {
    bottom: 0.9em;
}
/* Focus styles for accessibility */
.divi-mega-menu-link:focus,
.mega-menu-links a:focus,
.mega-menu-product-link:focus {
    outline: 2px solid var(--mega-menu-hover, #10b981);
    outline-offset: 2px;
}

/* Animation classes */
.mega-menu-fade-in {
    animation: megaMenuFadeIn var(--mega-menu-animation-speed, 300ms) ease;
}

.mega-menu-fade-out {
    animation: megaMenuFadeOut var(--mega-menu-animation-speed, 300ms) ease;
}

@keyframes megaMenuFadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes megaMenuFadeOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

/* Loading states */
.mega-menu-loading {
    opacity: 0.6;
    pointer-events: none;
}

.mega-menu-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #e5e7eb;
    border-top-color: var(--mega-menu-hover, #10b981);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .divi-mega-menu-nav {
        border: 2px solid;
    }
    
    .mega-menu-dropdown {
        border: 2px solid;
    }
    
    .mega-menu-product {
        border: 2px solid;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .divi-mega-menu-link,
    .mega-menu-dropdown,
    .mega-menu-links a,
    .mega-menu-product,
    .mega-menu-product-image img {
        transition: none;
    }
    
    .mega-menu-fade-in,
    .mega-menu-fade-out {
        animation: none;
    }
}