/**
 * Mega Menu Native Kadence Styling
 * Integrates with Kadence's native submenu system
 */

/* Mega Menu Shortcode - Native Kadence Submenu Approach */
:is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger).menu-item-has-children>.sub-menu {
    /* Override Kadence defaults for mega menu */
    position: fixed !important;
    left: 0 !important;
    top: var(--header-height, 80px) !important;
    transform: none !important;
    width: 100vw !important;
    background: #fff !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15) !important;
    padding: 0 !important;
    margin: 0;
    z-index: 9999;
    height: auto !important;
    max-height: calc(100vh - var(--header-height, 80px) - 40px) !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    transition: min-height 0.4s ease-out, opacity 0.3s ease, visibility 0.3s ease !important;
    /* Hidden by default - show when menu is open */
    display: block !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

/* Show submenu when parent has 'menu-open' class (click-activated) */
@media (min-width: 1025px) {
    :is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger).menu-item-has-children.menu-open>.sub-menu {
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto !important;
    }
}

/* Different minimal heights per trigger */
.mega-menu-shortcode-trigger.menu-item-has-children>.sub-menu {
    min-height: 500px !important;
}

/* Collections tray should fit content; no forced minimum here */

/* Loading and Error States */
.mega-menu-loading,
.mega-menu-error {
    text-align: center;
    padding: 40px 20px;
    color: #666;
    font-size: 16px;
}

.mega-menu-error {
    color: #d63638;
}

/* Ensure error/empty messages are visible in trays */
:is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger) .sub-menu .mega-menu-error {
    padding: 24px;
    color: #333;
}

/* Style the shortcode content within submenu */
:is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger) .sub-menu .merida-mega-menu-container {
    display: flex;
    gap: 0;
    min-height: 0;
    max-width: var(--global-content-width, 1200px);
    margin: 0 auto;
    padding: 20px;
}

/* Only the shortcode mega menu uses a tall container by default */
.mega-menu-shortcode-trigger .sub-menu .merida-mega-menu-container {
    min-height: 500px;
    padding: 0;
}

/* Collections and solutions use simplified single-column layout */
:is(.mega-menu-collections-trigger, .mega-menu-solutions-trigger) .sub-menu .merida-mega-menu-container {
    display: block;
    padding: 30px;
}

:is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger) .sub-menu .merida-mega-menu-left-column {
    width: 300px;
    min-width: 300px;
    background: #fff;
    border-radius: 0;
    padding: 0;
}

:is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger) .sub-menu .merida-mega-menu-left-column ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

:is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger) .sub-menu .merida-mega-menu-left-column li {
    margin: 0;
    padding: 0;
}

:is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger) .sub-menu .merida-mega-menu-left-column li:last-child {
    border-bottom: none;
}

.mega-menu-shortcode-trigger .sub-menu .merida-mega-menu-left-column a {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    text-decoration: none;
    color: #333;
    font-weight: 500;
    transition: all 0.3s ease;
    border-radius: 0;
    background: #fff;
    cursor: pointer;
}

.mega-menu-shortcode-trigger .sub-menu .merida-mega-menu-left-column a:hover {
    background: #f8f9fa;
    color: #333;
}

.mega-menu-shortcode-trigger .sub-menu .merida-mega-menu-left-column li.active a {
    background: #f8f9fa;
    color: #333;
    font-weight: 600;
}

:is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger) .sub-menu .merida-category-icon {
    width: 25px;
    height: 25px;
    margin-right: 15px;
    object-fit: cover;
    border-radius: 0;
    flex-shrink: 0;
}

/* Right Column Grid - only for shortcode mega menu (categories) */
.mega-menu-shortcode-trigger .sub-menu .merida-mega-menu-right-column {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.mega-menu-shortcode-trigger .sub-menu .merida-mega-menu-sub-categories {
    display: none;
    padding: 20px;
    background: #fff;
    border-radius: 6px;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 460px;
}

.mega-menu-shortcode-trigger .sub-menu .merida-mega-menu-sub-categories.active {
    display: flex;
    flex-direction: column;
    flex: 1;
}

:is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger) .sub-menu .merida-mega-menu-sub-categories h3 {
    margin: 0 0 20px 0;
    font-size: 24px;
    font-weight: 600;
}

:is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger) .sub-menu .mega-menu-category-title a {
    color: #333;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    transition: all 0.3s ease;
}

:is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger) .sub-menu .mega-menu-category-title .category-text {
    transition: all 0.3s ease;
}

:is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger) .sub-menu .mega-menu-category-title a:hover .category-text {
    text-decoration: underline;
}

:is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger) .sub-menu .mega-menu-category-title .arrow-right {
    font-size: 20px;
    line-height: 1;
    transition: transform 0.3s ease;
    text-decoration: none;
}

:is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger) .sub-menu .mega-menu-category-title a:hover .arrow-right {
    transform: translateX(5px);
}

:is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger) .sub-menu .merida-sub-category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 4px;
    align-content: start;
    flex: 1;
    align-items: start;
}

:is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger) .sub-menu .merida-sub-category-item {
    background: transparent;
    border: none;
    border-radius: 0;
    overflow: visible;
    box-shadow: none;
    transition: all 0.3s ease;
    padding: 15px;
    text-align: center;
}

:is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger) .sub-menu .merida-sub-category-item:hover {
    transform: none;
    box-shadow: none;
}

:is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger) .sub-menu .merida-sub-category-item a {
    text-decoration: none;
    color: #333;
    display: flex;
    flex-direction: column;
    align-items: center;
}

:is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger) .sub-menu .merida-sub-category-item a:hover {
    color: #007cba;
}

:is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger) .sub-menu .merida-category-image {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 0;
    margin-bottom: 10px;
    border: none;
    transition: none;
}

/* "More" tile for collections */
:is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger) .sub-menu .merida-grid-more-tile {
    width: 72px;
    height: 72px;
    background: #f3f4f6;
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 10px;
}

:is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger) .sub-menu .merida-sub-category-item:hover .merida-category-image {
    border: none;
}

:is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger) .sub-menu .merida-sub-category-item span {
    font-size: 14px;
    font-weight: 500;
    line-height: 1.3;
    margin-top: 10px;
    text-align: center;
}

/* Responsive */
:is(.mega-menu-collections-trigger, .mega-menu-solutions-trigger).menu-item-has-children>.sub-menu {
    min-height: 190px;
}

/* Compact spacing for collections grid */
:is(.mega-menu-collections-trigger, .mega-menu-solutions-trigger) .sub-menu .merida-sub-category-grid {
    gap: 16px;
}

:is(.mega-menu-collections-trigger, .mega-menu-solutions-trigger) .sub-menu .merida-sub-category-item {
    padding: 10px;
}

/* Keyboard focus */
:is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger) .sub-menu .merida-sub-category-item a:focus-visible {
    outline: 2px solid #0ea5e9;
    outline-offset: 2px;
}

/* Icons for parent menu items */
.mega-menu-shortcode-trigger>a,
.mega-menu-collections-trigger>a,
.mega-menu-solutions-trigger>a {
    display: inline-flex !important; /* ensure flex even if Kadence overrides */
    align-items: center;
    gap: 0.6em; /* space between icon and text */
    white-space: nowrap; /* keep icon and label on the same line */
}

.mega-menu-shortcode-trigger>a::before,
.mega-menu-collections-trigger>a::before,
.mega-menu-solutions-trigger>a::before {
    content: '';
    display: inline-block;
    width: 18px;
    height: 18px;
    flex: 0 0 18px; /* prevent shrinking and keep consistent width */
    margin: 0;
    margin-inline-end: 0; /* fallback margin added below for browsers without flex gap */
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    opacity: 0.95;
    vertical-align: middle;
}

/* Fallback for browsers that don't support flex gap on inline-flex */
@supports not (gap: 0.6em) {
    .mega-menu-shortcode-trigger>a::before,
    .mega-menu-collections-trigger>a::before,
    .mega-menu-solutions-trigger>a::before {
        margin-inline-end: 0.6em;
    }
}

.mega-menu-shortcode-trigger>a::before {
    background-image: url('../../../../assets/icons/k/list.svg');
}

.mega-menu-collections-trigger>a::before {
    background-image: url('../../../../assets/icons/Merida-signet.svg');
}

.mega-menu-solutions-trigger>a::before {
    background-image: url('../../../../assets/icons/k/9grid.svg');
}

/* Make sure the single <li> wrapper for mega menu content behaves like a block container */
:is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger) > .sub-menu > li.mega-menu-content {
    list-style: none;
    display: block;
    width: 100%;
    padding: 0;
    margin: 0;
}

@media (max-width: 1024px) {
    :is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger).menu-item-has-children>.sub-menu {
        width: 95vw !important;
    }

    :is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger) .sub-menu .merida-mega-menu-container {
        flex-direction: column;
    }

    :is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger) .sub-menu .merida-mega-menu-left-column {
        width: 100%;
    }

    :is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger) .sub-menu .merida-sub-category-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 15px;
    }
}

@media (max-width: 768px) {
    :is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger).menu-item-has-children>.sub-menu {
        width: 100vw !important;
        left: 0 !important;
        transform: none !important;
    }

    :is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger) .sub-menu .merida-sub-category-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 12px;
    }

    :is(.mega-menu-shortcode-trigger, .mega-menu-collections-trigger, .mega-menu-solutions-trigger) .sub-menu .merida-category-image {
        width: 60px;
        height: 60px;
    }
}
