/**
 * Mega Menu Block Styles
 * 
 * A full-width navigation bar with expandable catalogue dropdown
 */

/* CSS Custom Properties */
.ims-mega-menu-wrapper {
    --mega-menu-bg: var(--color-primary, #f9c457);
    --mega-menu-text: var(--color-dark, #333333);
    --mega-menu-dropdown-bg: #ffffff;
    --mega-menu-hover: rgba(0, 0, 0, 0.1);
    --mega-menu-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    --mega-menu-border: var(--color-border, #e5e7eb);
    --mega-menu-link-hover: var(--color-primary, #f9c457);
}

/* Main Navigation Bar */
.ims-mega-menu-wrapper {
    background-color: var(--mega-menu-bg);
    position: relative;
    z-index: 1100;
    width: 100%;
}

.mega-menu-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Navigation List */
.mega-menu-nav {
    display: flex;
    align-items: center;
    gap: 0;
    list-style: none;
    margin: 0;
    padding: 0;
}

/* Menu Items */
.mega-menu-item {
    position: relative;
}

.mega-menu-link,
.mega-menu-trigger,
a.mega-menu-trigger {
    display: flex !important;
    align-items: center;
    gap: 0.5rem;
    padding: 0.875rem 1.25rem;
    color: var(--mega-menu-text) !important;
    text-decoration: none !important;
    font-size: 0.9375rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
    white-space: nowrap;
}

/* Ensure catalogue trigger is visible */
.mega-menu-item.has-dropdown .mega-menu-trigger {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.mega-menu-link:hover,
.mega-menu-trigger:hover,
.mega-menu-trigger[aria-expanded="true"] {
    background-color: var(--mega-menu-hover);
    color: var(--mega-menu-text);
    text-decoration: none;
}

/* Dropdown Arrow */
.dropdown-arrow {
    transition: transform 0.25s ease;
    flex-shrink: 0;
}

.mega-menu-trigger[aria-expanded="true"] .dropdown-arrow {
    transform: rotate(180deg);
}

/* Right Side Links */
.mega-menu-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.mega-menu-right .mega-menu-link {
    font-weight: 500;
    text-transform: none;
}

/* ============================================
   MEGA DROPDOWN PANEL
   ============================================ */

.mega-dropdown {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    width: 100vw;
    background: var(--mega-menu-dropdown-bg);
    box-shadow: var(--mega-menu-shadow);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s;
    z-index: 9999;
    /* Fixed height - content flows in columns */
    height: 70vh;
    max-height: 600px;
    min-height: 400px;
    overflow: hidden;
}

.mega-dropdown[aria-hidden="false"] {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.mega-dropdown-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem 2rem 2rem;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Dropdown Header */
.mega-dropdown-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 1.25rem;
    margin-bottom: 1.25rem;
    border-bottom: 1px solid var(--mega-menu-border);
}

.catalogue-title {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--mega-menu-text);
    margin: 0;
}

.browse-all-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    background: var(--mega-menu-bg);
    color: var(--mega-menu-text);
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    border-radius: 4px;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.browse-all-link:hover {
    background: var(--color-gold-accent);
    color: var(--mega-menu-text);
    text-decoration: none;
    transform: translateX(3px);
}

.browse-all-link svg {
    transition: transform 0.2s ease;
}

.browse-all-link:hover svg {
    transform: translateX(3px);
}

/* Close Button */
.mega-dropdown-close {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: transparent;
    border: 1px solid var(--mega-menu-border);
    border-radius: 4px;
    color: #666;
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mega-dropdown-close:hover {
    background: #f3f4f6;
    color: #dc2626;
    border-color: #dc2626;
}

.mega-dropdown-close svg {
    color: #dc2626;
}

/* ============================================
   CATEGORY GROUPS
   ============================================ */

.mega-dropdown-content {
    padding-top: 0.5rem;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* CSS columns for natural flow */
.category-groups {
    column-count: 3;
    column-gap: 2rem;
    column-fill: auto;
    height: 100%;
}

.category-group {
    margin-bottom: 1.25rem;
    break-inside: auto;
    transition: margin 0.3s ease-out;
}

.category-group-heading {
    margin: 0 0 0.5rem 0;
    font-size: 0.9375rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    break-after: avoid;
}

.category-group-heading a {
    display: inline-block;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--mega-menu-bg);
    color: var(--color-dark);
    text-decoration: none;
    transition: color 0.15s ease;
}

.category-group-heading a:hover {
    color: var(--mega-menu-bg);
}

.category-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.category-item {
    margin: 0;
    padding: 0;
}

.category-item a {
    display: block;
    padding: 0.375rem 0;
    color: #374151;
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.3;
    margin: 0;
    transition: color 0.15s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.category-item a:hover {
    color: var(--mega-menu-bg);
    text-decoration: none;
}

/* All levels with expandable children - consistent layout */
.category-item.has-children {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    position: relative;
}

.category-item--level-2:not(.has-children) > a {
    font-weight: 500;
    color: #374151;
}

/* Toggle button for expandable categories - all levels */
.category-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    flex: 1;
    padding: 0.25rem 0;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
    text-align: left;
    line-height: 1.3;
    margin: 0;
    transition: color 0.15s ease;
}

.category-toggle:hover {
    color: var(--mega-menu-bg);
}

.category-toggle > span:not(.toggle-plus-icon) {
    flex: 1;
}

/* Plus/minus icon - matches category accordion style */
.toggle-plus-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    padding: 0;
    border-radius: 3px;
    background-color: var(--color-dark, #333333);
    color: #ffffff;
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1;
    flex-shrink: 0;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.category-toggle:hover .toggle-plus-icon {
    background-color: var(--color-dark-charcoal, #2c3e50);
}

.category-toggle[aria-expanded="true"] .toggle-plus-icon {
    background: linear-gradient(to bottom, var(--color-cta, var(--mega-menu-bg)), var(--color-cta-hover, #e5b04e));
    color: var(--color-dark, #333333);
}

.category-toggle:focus-visible .toggle-plus-icon {
    outline: 2px solid var(--color-cta, var(--mega-menu-bg));
    outline-offset: 2px;
}

/* Arrow link to view category - hidden by request */
.category-link-icon {
    display: none !important;
}

/* Level-3+ smaller plus icon */
.category-item--level-3 .toggle-plus-icon,
.category-item--level-4 .toggle-plus-icon,
.category-item--level-5 .toggle-plus-icon,
.category-item--level-6 .toggle-plus-icon {
    width: 18px;
    height: 18px;
    font-size: 0.95rem;
}

/* Collapsible children container - uses display for column reflow */
.category-children {
    list-style: none;
    margin: 0;
    padding: 0;
    padding-left: 0.4rem;
    width: 100%;
    display: none;
}

.category-children[aria-hidden="false"] {
    display: block;
    animation: fadeInChildren 0.3s ease-out forwards;
}

@keyframes fadeInChildren {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Level 3+ categories (nested children) - staggered fade in */
.category-children[aria-hidden="false"] > .category-item {
    animation: fadeSlideIn 0.25s ease-out forwards;
    opacity: 0;
}

.category-children[aria-hidden="false"] > .category-item:nth-child(1) { animation-delay: 0.05s; }
.category-children[aria-hidden="false"] > .category-item:nth-child(2) { animation-delay: 0.1s; }
.category-children[aria-hidden="false"] > .category-item:nth-child(3) { animation-delay: 0.15s; }
.category-children[aria-hidden="false"] > .category-item:nth-child(4) { animation-delay: 0.2s; }
.category-children[aria-hidden="false"] > .category-item:nth-child(5) { animation-delay: 0.25s; }
.category-children[aria-hidden="false"] > .category-item:nth-child(n+6) { animation-delay: 0.3s; }

@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateX(-8px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Level 3+ styling - match level 2 */
.category-item--level-3 > a,
.category-item--level-3 > .category-toggle,
.category-item--level-4 > a,
.category-item--level-4 > .category-toggle,
.category-item--level-5 > a,
.category-item--level-5 > .category-toggle,
.category-item--level-6 > a,
.category-item--level-6 > .category-toggle {
    font-weight: 500;
    font-size: 0.875rem;
    color: #374151;
    padding: 0.375rem 0;
}

/* Nested category-children get more indentation */
.category-children .category-children {
    padding-left: 0.5rem;
}

.no-categories {
    color: #6b7280;
    font-style: italic;
    padding: 2rem;
    text-align: center;
}

/* ============================================
   OVERLAY WHEN DROPDOWN IS OPEN
   ============================================ */

.mega-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s;
    z-index: 998;
}

.mega-menu-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Body class when mega menu is open */
body.mega-menu-open {
    overflow: hidden;
}

/* ============================================
   RESPONSIVE STYLES
   ============================================ */

@media (max-width: 1200px) {
    .category-groups {
        column-gap: 1.5rem;
    }
}

@media (max-width: 992px) {
    .mega-menu-container {
        padding: 0 1rem;
    }
    
    .mega-menu-link,
    .mega-menu-trigger {
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
    }
    
    .category-groups {
        column-count: 2;
        column-gap: 1.5rem;
    }
    
    .mega-dropdown-inner {
        padding: 1.25rem 1.5rem 1.5rem;
    }
    
    .catalogue-title {
        font-size: 1.25rem;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
    
    .mega-menu-right {
        display: none;
    }
}

@media (max-width: 768px) {
    .mega-menu-nav {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    
    .mega-menu-nav::-webkit-scrollbar {
        display: none;
    }
    
    .mega-menu-link,
    .mega-menu-trigger {
        padding: 0.625rem 0.875rem;
        font-size: 0.8125rem;
    }
    
    .mega-dropdown {
        height: auto;
        max-height: calc(100vh - 150px);
        min-height: auto;
        overflow-y: auto;
    }
    
    .mega-dropdown-inner {
        padding: 1rem;
        height: auto;
    }
    
    .mega-dropdown-content {
        overflow: visible;
    }
    
    .category-groups {
        column-count: 1;
        height: auto;
    }
    
    .mega-dropdown-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    
    .catalogue-title {
        font-size: 1.125rem;
        width: 100%;
    }
    
    .browse-all-link {
        width: 100%;
        justify-content: center;
    }
    
    .mega-dropdown-close {
        position: absolute;
        top: 1rem;
        right: 1rem;
        padding: 0.375rem 0.625rem;
        font-size: 0.75rem;
    }
    
    .category-group {
        border-bottom: 1px solid var(--mega-menu-border);
        padding-bottom: 1rem;
        margin-bottom: 1rem;
    }
    
    .category-group:last-child {
        border-bottom: none;
        padding-bottom: 0;
        margin-bottom: 0;
    }
    
    .category-item a {
        padding: 0.5rem 0;
        font-size: 0.875rem;
    }
}

/* ============================================
   ANIMATION EFFECTS
   ============================================ */

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

.mega-dropdown[aria-hidden="false"] .category-groups {
    animation: fadeInDown 0.3s ease forwards;
}

/* ============================================
   ACCESSIBILITY FOCUS STATES
   ============================================ */

.mega-menu-link:focus,
.mega-menu-trigger:focus,
.browse-all-link:focus,
.mega-dropdown-close:focus,
.category-item a:focus {
    outline: none;
    box-shadow: none;
    background-color: rgba(0, 0, 0, 0.06);
}

/* Visible focus for keyboard users */
.mega-menu-link:focus-visible,
.mega-menu-trigger:focus-visible,
.browse-all-link:focus-visible,
.mega-dropdown-close:focus-visible,
.category-item a:focus-visible {
    outline: none;
    background-color: rgba(0, 0, 0, 0.06);
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.25);
    border-radius: 4px;
}

