/**
 * MegaMenu Styles
 * Navigation dropdown and megamenu styles
 */

/* MegaMenu Base Styles */
.main-navigation {
    position: relative;
}

.main-navigation ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.main-navigation li {
    position: relative;
    margin: 0;
}

.main-navigation a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    text-decoration: none;
    color: #000;
    background-color: transparent;
    font-weight: 500;
    font-size: 1rem;
    transition: all 0.3s ease;
    border-radius: 6px;
}

.main-navigation a:hover {
    color: #fff;
    background-color: rgba(159, 192, 69, 0.75);
}

/* Menu Icons */
.menu-icon {
    font-size: 1.2rem;
    line-height: 1;
}

/* Dropdown Indicator */
.dropdown-indicator {
    margin-left: 0.25rem;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 4px solid currentColor;
    transition: transform 0.3s ease;
}

.menu-item-has-children:hover > a .dropdown-indicator {
    transform: rotate(180deg);
}

/* Menu Description (shows in megamenu) */
.menu-description {
    display: block;
    font-size: 0.875rem;
    color: var(--neutral-gray);
    margin-top: 0.25rem;
    line-height: 1.4;
}

/* Sub-menu Base (Regular Dropdown) */
.sub-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 240px;
    background: var(--background-pure-white);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    border-radius: 8px;
    padding: 1.5rem 0;
    z-index: 1000;
    margin-top: 0.5rem;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s ease;
}

.menu-item-has-children:hover > .sub-menu {
    display: block;
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.sub-menu li {
    display: block;
}

.sub-menu a {
    display: block;
    padding: 1rem 1.75rem;
    border-radius: 0;
    white-space: nowrap;
    font-size: 1rem;
    line-height: 1.5;
    color: #000;
    background-color: transparent;
}

.sub-menu a:hover {
    background-color: rgba(159, 192, 69, 0.75);
    color: #fff;
}

/* MegaMenu Dropdown Styles */
.megamenu-enabled > .megamenu-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    width: 100vw;
    max-width: 100vw;
    background: var(--background-pure-white);
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.15);
    border-radius: 0;
    padding: 2rem 1rem;
    z-index: 1000;
    margin-top: 0;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    justify-content: center;
}

.megamenu-enabled:hover > .megamenu-dropdown {
    display: grid;
    opacity: 1;
    visibility: visible;
}

/* MegaMenu Column Layouts */
.megamenu-cols-2 > .megamenu-dropdown {
    grid-template-columns: repeat(2, minmax(200px, 350px));
    gap: 2rem;
    align-items: start;
}

.megamenu-cols-3 > .megamenu-dropdown {
    grid-template-columns: repeat(3, minmax(200px, 300px));
    gap: 2rem;
    align-items: start;
}

.megamenu-cols-4 > .megamenu-dropdown {
    grid-template-columns: repeat(4, minmax(180px, 250px));
    gap: 2rem;
    align-items: start;
}

/* MegaMenu Items */
.megamenu-dropdown > li {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    border-bottom: 1px solid var(--background-light-gray);
    width: 100%;
    position: relative;
}

.megamenu-dropdown > li:last-child {
    border-bottom: none;
}

.megamenu-dropdown > li > a {
    font-weight: 600;
    font-size: 1.1rem;
    padding: 1rem 1.75rem;
    margin-bottom: 0;
    border-radius: 0;
    width: 100%;
}

.megamenu-dropdown > li > a:hover {
    background-color: rgba(159, 192, 69, 0.75);
    color: #fff;
}

/* Nested items in megamenu - Flyout style */
.megamenu-dropdown .sub-menu {
    position: absolute;
    display: none;
    opacity: 0;
    visibility: hidden;
    transform: translateX(-10px);
    transition: all 0.25s ease;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    padding: 0.75rem 0;
    margin: 0;
    min-width: 220px;
    background: var(--background-pure-white);
    border-radius: 8px;
    left: 100%;
    top: 0;
    z-index: 1001;
}

/* Show flyout on hover */
.megamenu-dropdown > li:hover > .sub-menu {
    display: block;
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
}

/* Hide dropdown indicator on flyout items, use right arrow instead */
.megamenu-dropdown > li.menu-item-has-children > a .dropdown-indicator {
    display: none;
}

/* Right arrow for flyout items */
.megamenu-dropdown > li.menu-item-has-children > a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.megamenu-dropdown > li.menu-item-has-children > a::after {
    content: '';
    display: inline-block;
    width: 0;
    height: 0;
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    border-left: 5px solid currentColor;
    flex-shrink: 0;
    opacity: 0.5;
}

.megamenu-dropdown > li.menu-item-has-children:hover > a::after {
    opacity: 1;
}

.megamenu-dropdown .sub-menu a {
    padding: 0.75rem 1.5rem;
    font-size: 0.95rem;
    font-weight: 400;
    color: #000;
    white-space: nowrap;
}

.megamenu-dropdown .sub-menu a:hover {
    background-color: rgba(159, 192, 69, 0.75);
    color: #fff;
}

/* Featured Items */
.megamenu-featured > a {
    background-color: var(--background-light-green);
    color: var(--secondary-forest-green) !important;
    font-weight: 700;
}

.megamenu-featured:hover > a {
    background-color: var(--primary-green);
    color: var(--primary-white) !important;
}

/* Menu Icons in MegaMenu */
.megamenu-dropdown .menu-icon {
    font-size: 1.5rem;
}

/* Current Menu Item Styling - Top level only */
.main-navigation > ul > li.current-menu-item > a,
.main-navigation > ul > li.current-menu-parent > a,
.main-navigation > ul > li.current-menu-ancestor > a {
    color: #fff;
    background-color: var(--primary-green);
}

/* Reset current item styling in dropdowns */
.sub-menu .current-menu-item > a,
.megamenu-dropdown .current-menu-item > a {
    color: #000;
    background-color: transparent;
}

.sub-menu .current-menu-item > a:hover,
.megamenu-dropdown .current-menu-item > a:hover {
    color: #fff;
    background-color: rgba(159, 192, 69, 0.75);
}

/* MegaMenu Mobile Adjustments */
@media (max-width: 1023px) {
    /* Mobile - Disable MegaMenu, use standard dropdown */
    .megamenu-enabled > .megamenu-dropdown {
        position: static;
        transform: none;
        min-width: 100%;
        max-width: 100%;
        grid-template-columns: 1fr !important;
        gap: 0;
        padding: 0;
        box-shadow: none;
        border-radius: 0;
        margin-top: 0;
    }

    .megamenu-enabled:hover > .megamenu-dropdown {
        display: block;
    }

    .megamenu-dropdown > li {
        border-bottom: 1px solid var(--background-light-gray);
    }

    .megamenu-dropdown > li:last-child {
        border-bottom: none;
    }

    .megamenu-dropdown > li > a {
        border-bottom: none;
        padding: 0.75rem 1.5rem;
        margin-bottom: 0;
    }

    .megamenu-dropdown .sub-menu {
        position: static;
        display: none;
        opacity: 1;
        visibility: visible;
        transform: none;
        box-shadow: none;
        padding: 0;
        padding-left: 1rem;
        min-width: 0;
        background: transparent;
        border-radius: 0;
    }

    /* Show dropdown indicator on mobile, hide the right arrow */
    .megamenu-dropdown > li.menu-item-has-children > a .dropdown-indicator {
        display: block;
    }

    .megamenu-dropdown > li.menu-item-has-children > a::after {
        display: none;
    }

    .megamenu-dropdown > li.menu-open > a .dropdown-indicator {
        transform: rotate(180deg);
    }

    .megamenu-dropdown > li.menu-open > .sub-menu {
        display: block;
    }

    .dropdown-indicator {
        margin-left: auto;
    }

    /* Mobile dropdown toggle */
    .menu-item-has-children > a {
        position: relative;
    }

    .menu-item-has-children > .sub-menu,
    .megamenu-enabled > .megamenu-dropdown {
        display: none;
    }

    .menu-item-has-children.menu-open > .sub-menu,
    .megamenu-enabled.menu-open > .megamenu-dropdown {
        display: block;
    }
}

/* Tablet Adjustments */
@media (max-width: 1200px) and (min-width: 1024px) {
    .megamenu-cols-4 > .megamenu-dropdown {
        grid-template-columns: repeat(2, 1fr);
    }

    .megamenu-enabled > .megamenu-dropdown {
        max-width: 800px;
    }
}

/* Accessibility Improvements */
.main-navigation a:focus-visible {
    outline: 2px solid var(--primary-green);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Animation for menu items */
@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.menu-item-has-children:hover > .sub-menu,
.megamenu-enabled:hover > .megamenu-dropdown {
    animation: slideDown 0.3s ease;
}

/* Ensure dropdowns don't overflow viewport */
@media (min-width: 1024px) {
    .main-navigation li:nth-last-child(-n+2) .sub-menu:not(.megamenu-dropdown) {
        left: auto;
        right: 0;
    }
}
