/**
 * Megamenu Block - Frontend Styles
 *
 * Desktop (>768px): Cascading dropdown with L0 > L1 > L2 submenus
 * Mobile (<=768px): Sidebar + panel (burger button)
 */

/* ===========================
   Shared Trigger Button
   =========================== */

.megamenu-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 18px;
    font-weight: 600;
    color: inherit;
    transition: background-color 0.2s ease;
}

.megamenu-trigger:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.megamenu-trigger svg {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.megamenu-label {
    white-space: nowrap;
}

/* ===========================
   DESKTOP: Cascading Dropdown
   =========================== */

/* Hide mobile on desktop, show desktop nav */
.megamenu-mobile {
    display: none;
}

.dropdown-nav {
    position: relative;
    display: inline-block;
}

/* L0 dropdown - hidden by default */
.dropdown-menu-l0 {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 1000;
    min-width: 280px;
    margin: 0;
    padding: 4px 0;
    list-style: none;
    background-color: #ffffff;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    border-radius: 0 0 4px 4px;
}

/* Show L0 on trigger hover or when nav has .open class (touch) */
.dropdown-nav:hover .dropdown-menu-l0,
.dropdown-nav.open .dropdown-menu-l0 {
    display: block;
}

/* L0 items — static so L1 positions relative to the L0 <ul> */
.dropdown-menu-l0 > li {
    position: static;
}

.dropdown-menu-l0 > li > a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    text-decoration: none;
    color: #111;
    font-size: 14px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    transition: background-color 0.15s ease, color 0.15s ease;
    white-space: nowrap;
}

.dropdown-menu-l0 > li:hover > a {
    background-color: var(--category-color, #d4821f);
    color: #ffffff;
}

/* L0 icon */
.dropdown-icon {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    overflow: hidden;
    border-radius: 2px;
}

.dropdown-icon img {
    width: 24px;
    height: 24px;
    object-fit: contain;
    transition: filter 0.15s ease;
}

/* Make icon white on hover (matches text color) */
.dropdown-menu-l0 > li:hover > a .dropdown-icon img {
    filter: brightness(0) invert(1);
}

/* Shared label and arrow */
.dropdown-label {
    flex: 1;
    min-width: 0;
}

.dropdown-arrow {
    margin-left: auto;
    font-size: 16px;
    font-weight: 400;
    opacity: 0.5;
    flex-shrink: 0;
    padding-left: 12px;
}

.dropdown-menu-l0 > li:hover > a .dropdown-arrow {
    opacity: 1;
    color: #ffffff;
}

/* L1 sub-dropdown — top-aligned with L0, full height */
.dropdown-menu-l1 {
    display: none;
    position: absolute;
    top: 0;
    left: 100%;
    z-index: 1001;
    min-width: 280px;
    min-height: 100%;
    margin: 0;
    padding: 4px 0;
    list-style: none;
    background-color: #ffffff;
    box-shadow: 4px 4px 16px rgba(0, 0, 0, 0.10);
    border-radius: 0 4px 4px 0;
    /* Overlap to prevent gap flicker */
    margin-left: -2px;
    padding-left: 2px;
}

.dropdown-menu-l0 > li:hover > .dropdown-menu-l1 {
    display: block;
}

/* L1 items — static so L2 positions relative to the L1 <ul> */
.dropdown-menu-l1 > li {
    position: static;
}

.dropdown-menu-l1 > li > a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    text-decoration: none;
    color: #111;
    font-size: 13px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.2px;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.dropdown-menu-l1 > li:hover > a {
    background-color: var(--category-color, #d4821f);
    color: #ffffff;
}

.dropdown-menu-l1 > li:hover > a .dropdown-arrow {
    opacity: 1;
    color: #ffffff;
}

/* L1 items inherit the L0 parent's --category-color via CSS variable inheritance */

/* L2 sub-sub-dropdown — wraps to extra columns when item count exceeds viewport height */
.dropdown-menu-l2 {
    /* Grid layout */
    display: none;
    grid-auto-flow: column;
    grid-template-rows: repeat(var(--l2-max-rows, 1), minmax(min-content, max-content));
    align-content: start;
    /* Sizing */
    min-height: 100%;
    max-height: 70vh;
    width: max-content;
    /* Positioning */
    position: absolute;
    top: 0;
    left: 100%;
    z-index: 1002;
    /* Styling */
    margin: 0;
    padding: 4px 0;
    gap: 0 10px;
    list-style: none;
    background-color: #ffffff;
    box-shadow: 4px 4px 16px rgba(0, 0, 0, 0.10);
    border-radius: 0 4px 4px 0;
    margin-left: -2px;
    padding-left: 2px;
}

.dropdown-menu-l2 > li {
    width: 260px;
}

.dropdown-menu-l1 > li:hover > .dropdown-menu-l2 {
    display: grid;
}

/* L2 items */
.dropdown-menu-l2 > li > a {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    text-decoration: none;
    color: #111;
    font-size: 13px;
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 0.2px;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.dropdown-menu-l2 > li:hover > a {
    background-color: var(--category-color, #d4821f);
    color: #ffffff;
}

/* ===========================
   MOBILE/TABLET (<=1200px): Sidebar
   =========================== */

@media (max-width: 1400px) {
    /* Hide desktop dropdown, show mobile sidebar */
    .dropdown-nav {
        display: none;
    }

    .megamenu-mobile {
        display: block;
    }
}

/* Backdrop */
.megamenu-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.megamenu-backdrop.active {
    display: block;
    opacity: 1;
}

/* Sidebar */
.megamenu-sidebar {
    position: fixed;
    top: 0;
    left: -100vw;
    width: 100vw;
    max-width: 100%;
    height: 100vh;
    background-color: #ffffff;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    transition: left 0.3s ease;
    overflow-y: auto;
}

.megamenu-sidebar.active {
    left: 0;
}

.megamenu-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 20px;
    border-bottom: 1px solid #e0e0e0;
    position: sticky;
    top: 0;
    background-color: #ffffff;
    z-index: 10;
}

.megamenu-sidebar-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.megamenu-sidebar-close {
    background: transparent;
    border: none;
    font-size: 32px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #333;
    transition: color 0.2s ease;
    flex-shrink: 0;
}

.megamenu-sidebar-close:hover {
    color: #000;
}

/* Main Navigation (mobile first layer) */
.megamenu-main-nav {
    display: none;
}

.megamenu-main-nav.active {
    display: block;
}

.megamenu-main-nav-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.megamenu-main-nav-item {
    border-bottom: 1px solid #e0e0e0;
}

.megamenu-main-nav-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 16px 20px;
    text-decoration: none;
    color: #333;
    font-size: 16px;
    font-weight: 500;
    background: transparent;
    border: none;
    cursor: pointer;
    text-align: left;
}

.megamenu-main-nav-link:hover {
    background-color: rgba(0, 0, 0, 0.03);
}

.megamenu-main-nav-item--submenu .megamenu-main-nav-link {
    font-weight: 600;
    color: #22424f;
}

.megamenu-main-nav-arrow {
    font-size: 18px;
    color: #999;
    flex-shrink: 0;
}

.megamenu-main-nav-label {
    flex: 1;
    min-width: 0;
}

/* Category List (panel - second layer) */
.megamenu-category-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.megamenu-category-item {
    border-bottom: 1px solid #e0e0e0;
}

.megamenu-category-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    text-decoration: none;
    color: #333;
    font-size: 15px;
    transition: background-color 0.2s ease, border-color 0.2s ease;
    border-left: 4px solid var(--category-color, #d4821f);
}

.megamenu-category-item.active .megamenu-category-link {
    background-color: rgba(0, 0, 0, 0.03);
}

/* Category icon in mobile sidebar */
.megamenu-category-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.megamenu-category-icon img {
    width: 24px;
    height: 24px;
    object-fit: contain;
}

.megamenu-category-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.megamenu-category-arrow {
    font-size: 18px;
    color: #999;
    margin-left: 8px;
    flex-shrink: 0;
}

/* Megamenu Panel (mobile) */
.megamenu-panel {
    display: none;
    position: fixed;
    top: 100vh;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    max-width: 100%;
    background-color: #ffffff;
    z-index: 1001;
    overflow: hidden;
    padding: 0;
    transition: top 0.3s ease;
}

.megamenu-panel.active {
    display: block;
    top: 0;
}

.megamenu-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 20px;
    border-bottom: 1px solid #e0e0e0;
    position: sticky;
    top: 0;
    background-color: #ffffff;
    z-index: 10;
}

.megamenu-panel-back {
    display: flex;
    align-items: center;
    gap: 8px;
    background: transparent;
    border: none;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    padding: 8px;
    color: #333;
    flex: 1;
    min-width: 0;
}

.megamenu-panel-back:hover {
    color: #000;
}

.megamenu-back-arrow {
    font-size: 20px;
    font-weight: bold;
    flex-shrink: 0;
}

.megamenu-back-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.megamenu-panel-close {
    background: transparent;
    border: none;
    font-size: 32px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #333;
    transition: color 0.2s ease;
    flex-shrink: 0;
}

.megamenu-panel-close:hover {
    color: #000;
}

.megamenu-content {
    display: none;
    padding: 20px;
}

.megamenu-content.loaded {
    display: flex;
    flex-direction: column;
    gap: 20px;
    height: calc(100vh - 70px);
    overflow-y: auto;
}

/* Mobile panel columns */
.megamenu-columns {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    flex: 1;
}

.megamenu-column-header {
    color: #ffffff;
    padding: 12px 16px;
    margin: 0 0 12px 0;
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.megamenu-column-header a {
    color: #ffffff;
    text-decoration: none;
}

.megamenu-column-header a:hover {
    text-decoration: underline;
}

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

.megamenu-column-item a {
    display: block;
    padding: 6px 16px;
    color: #333;
    text-decoration: none;
    font-size: 14px;
    transition: background-color 0.2s ease;
    border-radius: 4px;
}

.megamenu-column-item a:hover {
    background-color: #f5f5f5;
}

/* L1 Subcategory List (panel - third layer) */
.megamenu-subcategory-list {
    margin: 0;
    padding: 0;
}

.megamenu-subcategory-item {
    border-bottom: 1px solid #e0e0e0;
}

.megamenu-subcategory-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    text-decoration: none;
    color: #333;
    font-size: 15px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.2px;
    transition: background-color 0.2s ease;
}

.megamenu-subcategory-link:hover {
    background-color: rgba(0, 0, 0, 0.03);
}

.megamenu-subcategory-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.megamenu-subcategory-arrow {
    font-size: 18px;
    color: #999;
    margin-left: 8px;
    flex-shrink: 0;
}

/* L2 Items List (panel - fourth layer) */
.megamenu-items-list {
    margin: 0;
    padding: 0;
}

.megamenu-item-entry {
    border-bottom: 1px solid #e0e0e0;
}

.megamenu-item-link {
    display: block;
    padding: 14px 20px;
    text-decoration: none;
    color: #333;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.2px;
    transition: background-color 0.2s ease;
}

.megamenu-item-link:hover {
    background-color: rgba(0, 0, 0, 0.03);
}

/* Mobile category image */
.megamenu-image-container {
    width: 100%;
    max-width: 300px;
    margin: 0 auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

.megamenu-image-container img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* ===========================
   Small Mobile (<=480px)
   =========================== */

@media (max-width: 480px) {
    .megamenu-sidebar-header {
        padding: 12px 15px;
    }

    .megamenu-sidebar-header h3 {
        font-size: 16px;
    }

    .megamenu-sidebar-close {
        font-size: 28px;
        width: 28px;
        height: 28px;
    }

    .megamenu-main-nav-link {
        padding: 12px 15px;
        font-size: 15px;
    }

    .megamenu-category-link {
        padding: 12px 15px;
        font-size: 14px;
    }

    .megamenu-panel-header {
        padding: 12px 15px;
    }

    .megamenu-panel-back {
        font-size: 15px;
        padding: 4px;
    }

    .megamenu-back-arrow {
        font-size: 18px;
    }

    .megamenu-panel-close {
        font-size: 28px;
        width: 28px;
        height: 28px;
    }

    .megamenu-content {
        padding: 15px;
    }

    .megamenu-subcategory-link {
        padding: 12px 15px;
        font-size: 14px;
    }

    .megamenu-item-link {
        padding: 12px 15px;
        font-size: 13px;
    }

    .megamenu-label {
        display: none;
    }

    .megamenu-trigger {
        padding: 10px;
    }
}

/* ===========================
   Accessibility
   =========================== */

.megamenu-trigger:focus,
.megamenu-sidebar-close:focus,
.megamenu-panel-back:focus,
.megamenu-panel-close:focus,
.megamenu-main-nav-link:focus,
.megamenu-category-link:focus,
.megamenu-subcategory-link:focus,
.megamenu-item-link:focus,
.megamenu-column-item a:focus,
.dropdown-menu-l0 a:focus,
.dropdown-menu-l1 a:focus,
.dropdown-menu-l2 a:focus {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

/* ===========================
   Print Styles
   =========================== */

@media print {
    .megamenu-block-container,
    .megamenu-backdrop,
    .megamenu-sidebar,
    .megamenu-panel,
    .dropdown-nav {
        display: none !important;
    }
}
