/* Mega Menu Container */
.ba-mega-menu-container {
    width: 100%;
    max-width: 900px;
    background: #ffffff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.12);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    overflow: hidden;
    display: block;
}

.ba-mega-menu-wrapper {
    display: flex !important;
    flex-direction: row !important;
    min-height: 450px;
    width: 100%;
    overflow: hidden;
}

/* Left Categories */
.ba-left-categories {
    width: 280px;
    min-width: 280px;
    max-width: 280px;
    background: #f8f9fa;
    border-right: 1px solid #e0e0e0;
    padding: 8px 0;
    max-height: 500px;
    overflow-y: auto;
    flex-shrink: 0;
    display: block;
    position: relative;
    z-index: 1;
}

/* Custom scrollbar for left categories */
.ba-left-categories::-webkit-scrollbar {
    width: 4px;
}

.ba-left-categories::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.ba-left-categories::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.ba-left-categories::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

.ba-category-item {
    cursor: pointer;
    padding: 12px 15px;
    transition: all 0.25s ease;
    border-left: 3px solid transparent;
    position: relative;
    margin-bottom: 2px;
}

.ba-m-group:last-child > .ba-category-item {
    margin-bottom: 0;
}

.ba-category-item:hover {
    background-color: #e8edf2;
    border-left-color: #0073aa;
}

.ba-category-item.active {
    background-color: #ffffff;
    border-left-color: #0073aa;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.05);
}

.ba-category-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #333333;
    font-size: 14px;
    font-weight: 500;
}

/* SVG Icon Styling */
.ba-category-content .ba-svg-icon,
.ba-mega-item .ba-svg-icon {
    width: 16px;
    height: 16px;
    margin-right: 12px;
    flex-shrink: 0;
    fill: currentColor;
}

.ba-mega-item .ba-svg-icon {
    width: 14px;
    height: 14px;
    margin-right: 10px;
}

/* Category Icon */
.ba-category-content i:first-child {
    margin-right: 12px;
    color: #0073aa;
    font-size: 16px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
    transition: all 0.25s ease;
}

.ba-category-item:hover .ba-category-content i:first-child {
    transform: scale(1.1);
}

.ba-category-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ba-arrow-icon {
    color: #999999;
    font-size: 12px;
    transition: all 0.3s ease;
    margin-left: 8px;
    flex-shrink: 0;
}

.ba-category-item:hover .ba-arrow-icon {
    transform: translateX(5px);
    color: #0073aa;
}

/* Right Mega Menu */
.ba-right-mega-menu {
    flex: 1;
    padding: 25px 30px;
    background: #ffffff;
    min-height: 400px;
    display: block;
    position: relative;
    overflow: visible;
    width: calc(100% - 280px);
    max-width: calc(100% - 280px);
    box-sizing: border-box;
}

.ba-mega-content {
    animation: fadeIn 0.3s ease;
    height: 100%;
    display: block;
    width: 100%;
    max-width: 100%;
    overflow: visible;
}

.ba-mega-content:not(:first-child) {
    display: none !important;
}

.ba-mega-content[style*="display: block"],
.ba-mega-content[style*="display:block"] {
    display: block !important;
}

.ba-no-content {
    display: flex !important;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 16px;
    height: 100%;
}

.ba-no-sub-menu {
    padding: 40px 20px;
    text-align: center;
    color: #999;
    font-style: italic;
}

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

/* Mega Grid Layout */
.ba-mega-grid {
    display: grid;
    gap: 10px 20px;
    height: 100%;
    align-content: start;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/* Force column layout */
.ba-mega-grid.columns-1 {
    grid-template-columns: repeat(1, 1fr) !important;
}

.ba-mega-grid.columns-2 {
    grid-template-columns: repeat(2, 1fr) !important;
}

.ba-mega-grid.columns-3 {
    grid-template-columns: repeat(3, 1fr) !important;
}

.ba-mega-grid.columns-4 {
    grid-template-columns: repeat(4, 1fr) !important;
}

.ba-mega-grid.columns-5 {
    grid-template-columns: repeat(5, 1fr) !important;
}

/* Column dividers */
.ba-mega-grid.columns-2 .ba-mega-item:not(:nth-child(2n))::after,
.ba-mega-grid.columns-3 .ba-mega-item:not(:nth-child(3n))::after,
.ba-mega-grid.columns-4 .ba-mega-item:not(:nth-child(4n))::after,
.ba-mega-grid.columns-5 .ba-mega-item:not(:nth-child(5n))::after {
    content: '';
    position: absolute;
    right: -10px;
    top: 10%;
    height: 80%;
    width: 1px;
    background-color: #e8e8e8;
}

/* Remove divider from last item in each row */
.ba-mega-grid.columns-2 .ba-mega-item:nth-child(2n)::after,
.ba-mega-grid.columns-3 .ba-mega-item:nth-child(3n)::after,
.ba-mega-grid.columns-4 .ba-mega-item:nth-child(4n)::after,
.ba-mega-grid.columns-5 .ba-mega-item:nth-child(5n)::after {
    display: none;
}

/* No dividers for single column */
.ba-mega-grid.columns-1 .ba-mega-item::after {
    display: none !important;
}

.ba-mega-item {
    position: relative;
    margin-bottom: 0;
    padding: 3px 0;
    max-width: 100%;
    box-sizing: border-box;
    overflow: visible;
}

/* Mega Items */
.ba-mega-item a {
    display: flex;
    align-items: center;
    padding: 7px 12px;
    color: #333333;
    text-decoration: none;
    border-radius: 4px;
    transition: all 0.25s ease;
    font-size: 13px;
    font-weight: 400;
    position: relative;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    word-wrap: break-word;
    word-break: break-word;
    line-height: 1.4;
}

.ba-mega-item a:hover {
    background-color: #f0f4f8;
    color: #0073aa;
    transform: translateX(5px);
}

.ba-mega-item a i {
    margin-right: 10px;
    color: #0073aa;
    font-size: 14px;
    width: 20px;
    min-width: 20px;
    text-align: center;
    flex-shrink: 0;
    transition: all 0.25s ease;
}

.ba-mega-item a:hover i {
    color: #0073aa;
    transform: scale(1.1);
}

.ba-mega-item a span {
    flex: 1;
    display: inline;
    word-wrap: break-word;
    word-break: break-word;
    white-space: normal;
    line-height: 1.4;
}

/* Active Category Text */
.ba-category-item.active .ba-category-content {
    color: #0073aa;
}

.ba-category-item.active .ba-category-content i:first-child {
    color: #0073aa;
}

/* Responsive Design */
@media (max-width: 992px) {
    .ba-right-mega-menu {
        width: calc(100% - 250px);
        max-width: calc(100% - 250px);
        padding: 20px;
    }
    
    .ba-left-categories {
        width: 250px;
        min-width: 250px;
        max-width: 250px;
    }
    
    .ba-mega-grid.columns-4,
    .ba-mega-grid.columns-5 {
        grid-template-columns: repeat(3, 1fr) !important;
    }
}

@media (max-width: 768px) {
    .ba-mega-menu-wrapper {
        flex-direction: column !important;
    }
    
    .ba-left-categories {
        width: 100% !important;
        min-width: auto !important;
        max-width: 100% !important;
        border-right: none;
        border-bottom: 1px solid #e0e0e0;
        max-height: 300px;
        flex-shrink: 1;
    }
    
    .ba-right-mega-menu {
        min-height: 250px;
        padding: 20px;
        flex: 1;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    .ba-mega-grid.columns-2,
    .ba-mega-grid.columns-3,
    .ba-mega-grid.columns-4,
    .ba-mega-grid.columns-5 {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    .ba-category-item {
        padding: 10px 12px;
    }
    
    .ba-mega-grid.columns-2 .ba-mega-item:not(:nth-child(2n))::after,
    .ba-mega-grid.columns-3 .ba-mega-item:not(:nth-child(3n))::after,
    .ba-mega-grid.columns-4 .ba-mega-item:not(:nth-child(4n))::after,
    .ba-mega-grid.columns-5 .ba-mega-item:not(:nth-child(5n))::after {
        display: none;
    }
}

@media (max-width: 480px) {
    .ba-mega-grid.columns-2,
    .ba-mega-grid.columns-3,
    .ba-mega-grid.columns-4,
    .ba-mega-grid.columns-5 {
        grid-template-columns: 1fr !important;
    }
    
    .ba-right-mega-menu {
        padding: 15px;
        min-height: 200px;
    }
    
    .ba-mega-item a {
        font-size: 12px;
        padding: 6px 10px;
    }
}
/* Mobile accordion toggle + sub list (hidden on desktop) */
.ba-m-toggle,
.ba-m-sub {
    display: none;
}

@media (max-width: 768px) {
    /* On mobile each Sub category opens its own list underneath; the right box is not used */
    .ba-right-mega-menu {
        display: none !important;
    }

    .ba-mega-menu-wrapper {
        min-height: 0 !important;
    }

    .ba-left-categories {
        max-height: none !important;
        overflow: visible;
        border-bottom: none;
    }

    .ba-category-item {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
    }

    .ba-category-item > .ba-category-link,
    .ba-category-item > .ba-category-content {
        flex: 1 1 0;
        min-width: 0;
        text-decoration: none;
    }

    .ba-category-item .ba-arrow-icon {
        display: none;
    }

    .ba-m-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 40px;
        width: 40px;
        height: 36px;
        padding: 0;
        margin: 0;
        background: transparent;
        border: 0;
        color: #666666;
        cursor: pointer;
        box-shadow: none;
    }

    .ba-m-chev {
        display: block;
        width: 8px;
        height: 8px;
        border-right: 2px solid currentColor;
        border-bottom: 2px solid currentColor;
        transform: translateY(-2px) rotate(45deg);
        transition: transform 0.25s ease;
    }

    .ba-m-group.ba-open .ba-m-chev {
        transform: translateY(2px) rotate(-135deg);
    }

    .ba-m-sub {
        flex: 0 0 100%;
        width: 100%;
        padding: 6px 0 4px 12px;
    }

    .ba-m-group.ba-open > .ba-m-sub {
        display: block;
    }
}

/* Tablet: own column count for the right box (class only added when it differs from desktop) */
@media (min-width: 769px) and (max-width: 1024px) {
    .ba-mega-grid.t-cols-1 {
        grid-template-columns: repeat(1, 1fr) !important;
    }
    .ba-mega-grid.t-cols-2 {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    .ba-mega-grid.t-cols-3 {
        grid-template-columns: repeat(3, 1fr) !important;
    }
    .ba-mega-grid.t-cols-4 {
        grid-template-columns: repeat(4, 1fr) !important;
    }
    .ba-mega-grid.t-cols-5 {
        grid-template-columns: repeat(5, 1fr) !important;
    }
    .ba-mega-grid[class*="t-cols-"] .ba-mega-item::after {
        display: none !important;
    }
}

/* Mobile: columns of the list under each Sub category */
@media (max-width: 768px) {
    .ba-m-group.ba-open > .ba-m-sub[class*="m-cols-"] {
        display: grid;
        column-gap: 8px;
    }
    .ba-m-sub.m-cols-2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .ba-m-sub.m-cols-3 {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
    .ba-m-sub.m-cols-4 {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
    .ba-m-sub.m-cols-5 {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }
}
