/**
 * Advanced Mega Menu Styles
 * Glassmorphism, Modern Grids, and Animations
 */

/* Container for Mega Menu */
.menu-item-has-mega-menu {
    position: relative;
}

/* Ensure site sections are not forcing static context */
.site-topbar .container,
.site-header .container,
.site-header-bottom .container {
    position: relative;
}

/* Ensure Header has high z-index but is relative for full-width support fallback */
.site-header {
    position: relative;
}

.abr-mega-menu-content {
    position: absolute;
    inset-inline: 0;
    top: 100%;
    z-index: var(--z-mega-menu);
    padding: 30px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 0 0 20px 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    display: none;
    /* Prevents ghost overflow and document expansion */
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.4s ease, transform 0.4s ease;
    pointer-events: none;
}

.abr-mega-menu-content::-webkit-scrollbar {
    width: 6px;
}

.abr-mega-menu-content::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}


/* Hover State */
#page .menu-item-has-mega-menu:hover>.abr-mega-menu-content,
#page .menu-item-has-mega-menu.is-hovered>.abr-mega-menu-content {
    display: block;
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

/* Ensure display: block doesn't break grids */
.abr-mega-menu-content[class*="abr-grid-"] {
    display: none;
}

#page .menu-item-has-mega-menu:hover>.abr-mega-menu-content[class*="abr-grid-"],
#page .menu-item-has-mega-menu.is-hovered>.abr-mega-menu-content[class*="abr-grid-"] {
    display: grid;
}

/* Width Variants & Alignment - Unified Variable System */
.abr-mega-menu-content {
    inset-inline-start: var(--abr-mega-left, 0);
    inset-inline-end: var(--abr-mega-right, auto);
    width: var(--abr-mega-width, 600px);
    max-width: calc(100vw - 40px);
    text-align: start;
}

/* Full Width Handling */
.menu-item-has-mega-menu.mega-menu-full {
    position: static;
}

#page .site-header .menu-item-has-mega-menu.mega-menu-full .abr-mega-menu-content,
#page .site-topbar .menu-item-has-mega-menu.mega-menu-full .abr-mega-menu-content {
    left: 50%;
    right: auto;
    width: 100vw;
    margin-inline: -50vw;
    transform: translateX(calc(var(--abr-mega-translate, -50%) * 1)) translateY(20px);
    border-radius: 0;
}

#page .site-header .menu-item-has-mega-menu.mega-menu-full:hover>.abr-mega-menu-content,
#page .site-topbar .menu-item-has-mega-menu.mega-menu-full:hover>.abr-mega-menu-content,
#page .site-header .menu-item-has-mega-menu.mega-menu-full.is-hovered>.abr-mega-menu-content,
#page .site-topbar .menu-item-has-mega-menu.mega-menu-full.is-hovered>.abr-mega-menu-content {
    transform: translateX(calc(var(--abr-mega-translate, -50%) * 1)) translateY(0);
}

/* Responsive Grid Logic - Unified CSS Variable System */
/* Defined globally to work on both .abr-mega-menu-content AND its children like .abr-mega-dynamic-posts */
.abr-grid-1 {
    --abr-mega-cols: 1;
}

.abr-grid-2 {
    --abr-mega-cols: 2;
}

.abr-grid-3 {
    --abr-mega-cols: 3;
}

.abr-grid-4 {
    --abr-mega-cols: 4;
}

.abr-grid-5 {
    --abr-mega-cols: 5;
}

.abr-grid-6 {
    --abr-mega-cols: 6;
}

/* Desktop Scaling Down - Prevents overcrowding before mobile breakpoint */
@media (min-width: 1025px) {
    @media (max-width: 1400px) {
        .abr-grid-4 {
            --abr-mega-cols: 3;
        }

        .abr-grid-5,
        .abr-grid-6 {
            --abr-mega-cols: 4;
        }
    }

    @media (max-width: 1200px) {

        .abr-grid-3,
        .abr-grid-4 {
            --abr-mega-cols: 2;
        }

        .abr-grid-5,
        .abr-grid-6 {
            --abr-mega-cols: 3;
        }
    }
}

/* Grid Application */
#page .site-header .abr-mega-menu-content .abr-mega-grid,
#page .site-topbar .abr-mega-menu-content .abr-mega-grid,
#page .abr-mega-dynamic-posts,
#page .abr-mega-dynamic-products,
#page .abr-mega-dynamic-categories {
    display: grid;
    gap: 20px;
    grid-template-columns: repeat(var(--abr-mega-cols, 1), minmax(0, 1fr));
}

/* Dynamic Responsive Columns Override for Nested Panes */
#page .abr-nested-pane .abr-mega-grid,
#page .abr-nested-pane .abr-mega-dynamic-posts,
#page .abr-nested-pane .abr-mega-dynamic-products,
#page .abr-nested-pane .abr-mega-dynamic-categories {
    gap: 10px;
    /* Smaller gap for nested content */
    grid-template-columns: repeat(min(var(--abr-responsive-cols, 6), var(--abr-mega-cols, 1)), minmax(0, 1fr));
}

/* Specific Gap for sub-items grid */
.site-header .abr-mega-menu-content .abr-mega-grid,
.site-topbar .abr-mega-menu-content .abr-mega-grid {
    gap: 15px;
}

/* Sub-menu Styles in Mega Menu - Increased specificity to remove !important */
.site-header .abr-mega-menu-content .sub-menu,
.site-topbar .abr-mega-menu-content .sub-menu {
    position: static;
    opacity: 1;
    visibility: visible;
    transform: none;
    display: block;
    box-shadow: none;
    background: transparent;
    padding: 0;
    border: none;
    margin: 0;
    backdrop-filter: none;
    width: 100%;
    /* Ensure it takes full width of container */
}

/* On mobile, reset standard display to allow accordion logic */
@media (max-width: 1024px) {

    .site-header .abr-mega-menu-content .sub-menu,
    .site-topbar .abr-mega-menu-content .sub-menu {
        display: none;
    }

    .site-header .abr-mega-menu-content .sub-menu.is-open,
    .site-topbar .abr-mega-menu-content .sub-menu.is-open {
        display: block;
    }
}

/* Override block/flex display for grid - Base maintained by unified system above */
.site-header .abr-mega-menu-content .abr-mega-grid,
.site-topbar .abr-mega-menu-content .abr-mega-grid {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: stretch;
    align-items: stretch;
}

.site-header .abr-mega-menu-content .abr-mega-grid>li,
.site-topbar .abr-mega-menu-content .abr-mega-grid>li {
    display: block;
    width: 100%;
    margin: 0;
    position: relative;
    /* Anchor point for nested flyout */
    transition: z-index 0s;
    /* Instant z-index switch */
}

/* Bring the hovered item to the front so its flyout isn't covered by next items */
.site-header .abr-mega-menu-content .abr-mega-grid>li:hover,
.site-header .abr-mega-menu-content .abr-mega-grid>li.is-hovered,
.site-topbar .abr-mega-menu-content .abr-mega-grid>li:hover,
.site-topbar .abr-mega-menu-content .abr-mega-grid>li.is-hovered {
    z-index: 100;
}

/* Nested Mega Menu - Side-by-Side Dashboard Pane (Works inside Mega OR Standard Dropdowns) */
.abr-mega-menu-content .abr-mega-menu-content,
.sub-menu .abr-mega-menu-content {
    position: absolute;
    /* top and left are calculated by JS for perfect Dashboard alignment */
    width: var(--abr-mega-width, 600px);
    max-width: calc(100vw - 40px);
    display: none;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    background: #ffffff;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.15);
    border-radius: 20px;
    z-index: 1100;
    /* Higher than standard sub-menu (usually 1000) */
    padding: 25px;
    border: 1px solid rgba(0, 0, 0, 0.05);
    transition: opacity 0.4s ease, transform 0.4s ease;
    pointer-events: none;
}

/* Hover State for Nested Panes (Works inside Mega OR Standard Dropdowns) */
.abr-mega-menu-content .menu-item-has-mega-menu:hover>.abr-mega-menu-content,
.abr-mega-menu-content .menu-item-has-mega-menu.is-hovered>.abr-mega-menu-content,
.sub-menu .menu-item-has-mega-menu:hover>.abr-mega-menu-content,
.sub-menu .menu-item-has-mega-menu.is-hovered>.abr-mega-menu-content {
    display: block;
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

.abr-mega-menu-content .sub-menu>li>a {
    font-weight: 600;
    font-size: 12px;
    /* Further reduced to 12px */
    color: #1e293b;
    margin-bottom: 3px;
    /* Tighter */
    display: block;
    padding-bottom: 2px;
    padding-inline-start: 5px;
    text-align: start;
    /* Tighter */
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.site-header .abr-mega-menu-content .sub-menu .sub-menu,
.site-topbar .abr-mega-menu-content .sub-menu .sub-menu {
    border-top: none;
    margin-top: 0;
}

.abr-mega-menu-content .sub-menu .sub-menu li a {
    font-weight: 400;
    font-size: 11px;
    /* Tiny microscopic font */
    color: #64748b;
    padding: 1px 0;
    padding-inline-start: 5px;
    text-align: start;
    /* Minimal padding */
    text-transform: none;
    letter-spacing: normal;
    transition: color 0.3s ease;
}

.abr-mega-menu-content .sub-menu .sub-menu li a:hover {
    color: #2271b1;
    padding-inline-start: 10px;
}

/* Block & Dynamic Content */
.abr-mega-block-content,
.abr-mega-dynamic-mode {
    width: 100%;
}

/* Categories already handled by unified system */

/* Targeted Scroll for specific modes on Desktop - Avoids clipping nested Dashboard panes */
@media (min-width: 1025px) {

    .site-header .abr-mega-menu-content.abr-mega-block-mode,
    .site-header .abr-mega-menu-content.abr-mega-posts-mode,
    .site-header .abr-mega-menu-content.abr-mega-products-mode,
    .site-header .abr-mega-menu-content.abr-mega-categories-mode,
    .site-topbar .abr-mega-menu-content.abr-mega-block-mode,
    .site-topbar .abr-mega-menu-content.abr-mega-posts-mode,
    .site-topbar .abr-mega-menu-content.abr-mega-products-mode,
    .site-topbar .abr-mega-menu-content.abr-mega-categories-mode {
        max-height: calc(100vh - 150px);
        overflow-y: auto;
        overflow-x: hidden;
    }
}

/* Common Card Styles */
.abr-mega-post-card,
.abr-mega-cat-card,
.abr-mega-product-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 12px;
    padding: 8px;
    transition: transform 0.3s ease, background 0.3s ease;
    border: 1px solid rgba(255, 255, 255, 0.2);
    min-width: 0;
    /* Allows the card to shrink below its content size */
    width: 100%;
    box-sizing: border-box;
}

.post-content,
.product-content,
.cat-content {
    width: 100%;
    min-width: 0;
    /* Prevents flex items from overflowing their parent */
}

.abr-mega-post-card:hover,
.abr-mega-cat-card:hover,
.abr-mega-product-card:hover {
    transform: translateY(-5px);
    background: rgba(255, 255, 255, 0.8);
    border-color: rgba(99, 102, 241, 0.3);
}

.post-thumb img,
.cat-thumb img,
.product-thumb img,
.post-thumb > a,
.product-thumb > a {
    width: 100%;
    height: 160px;
    object-fit: cover;
    border-radius: 8px;
    display: block;
}

.cat-thumb,
.cat-thumb > a {
    display: block;
    width: 100%;
}

.cat-thumb > a {
    overflow: hidden;
    border-radius: 10px;
}

.post-thumb > a,
.product-thumb > a {
    overflow: hidden;
    border-radius: 8px;
}

.abr-mega-media-placeholder,
.abr-mega-category-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 160px;
    background: var(--global-color-primary, var(--wp--preset--color--primary, #6366f1));
    color: #fff;
    font-size: 40px;
    font-weight: 700;
}

body.dark-mode .abr-mega-media-placeholder,
body.dark-mode .abr-mega-category-placeholder {
    background: var(--global-color-primary, var(--wp--preset--color--primary, #6366f1));
    color: #fff;
}

.abr-mega-post-card h4,
.abr-mega-cat-card h4,
.abr-mega-product-card h4 {
    margin: 0;
    font-size: 15px;
    line-height: 1.4;
    overflow-wrap: break-word;
    /* Prevents long words/titles from overflowing */
    word-break: break-word;
    hyphens: auto;
    white-space: normal;
    /* Force text to wrap instead of staying on one line */
}

.abr-mega-post-card h4 a,
.abr-mega-cat-card h4 a,
.abr-mega-product-card h4 a {
    color: #1e293b;
    text-decoration: none;
    transition: color 0.3s;
    display: inline-block;
    /* Ensure it follows wrapping rules */
    max-width: 100%;
    /* Prevent it from pushing outside its container */
    white-space: normal !important;
    /* Critical override for navigation menu defaults */
}

.abr-mega-post-card h4 a:hover,
.abr-mega-cat-card h4 a:hover,
.abr-mega-product-card h4 a:hover {
    color: #6366f1;
}

.post-date,
.cat-count,
.price {
    font-size: 12px;
    color: #64748b;
}

.price ins {
    text-decoration: none;
    color: #10b981;
    font-weight: 600;
}

/* Animation on items */
.abr-mega-menu-content .sub-menu>li {
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
}

.menu-item-has-mega-menu:hover .abr-mega-menu-content .sub-menu>li,
.menu-item-has-mega-menu.is-hovered .abr-mega-menu-content .sub-menu>li {
    opacity: 1;
    transform: translateY(0);
}

/* Staggered delay for grid items - Scalable approach */
.abr-mega-menu-content .sub-menu>li {
    transition-delay: calc(var(--item-index, 0) * 0.05s);
}

/* Fallback for the first few items if index is missing */
.abr-mega-menu-content .sub-menu>li:nth-child(1) {
    --item-index: 1;
}

.abr-mega-menu-content .sub-menu>li:nth-child(2) {
    --item-index: 2;
}

.abr-mega-menu-content .sub-menu>li:nth-child(3) {
    --item-index: 3;
}

.abr-mega-menu-content .sub-menu>li:nth-child(4) {
    --item-index: 4;
}

.abr-mega-menu-content .sub-menu>li:nth-child(5) {
    --item-index: 5;
}

.abr-mega-menu-content .sub-menu>li:nth-child(6) {
    --item-index: 6;
}

.abr-mega-menu-content .sub-menu>li:nth-child(7) {
    --item-index: 7;
}

.abr-mega-menu-content .sub-menu>li:nth-child(8) {
    --item-index: 8;
}

/* Dark Mode Support (if theme has a dark class) */
body.dark-mode .abr-mega-menu-content {
    background: rgba(15, 23, 42, 0.85);
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

body.dark-mode .abr-mega-menu-content .sub-menu>li>a {
    color: #f8fafc;
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

body.dark-mode .abr-mega-menu-content .sub-menu .sub-menu li a {
    color: #94a3b8;
}

body.dark-mode .abr-mega-menu-content .sub-menu .sub-menu li a:hover {
    color: #38bdf8;
}

body.dark-mode .abr-mega-post-card,
body.dark-mode .abr-mega-cat-card,
body.dark-mode .abr-mega-product-card {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
}

body.dark-mode .abr-mega-post-card:hover,
body.dark-mode .abr-mega-cat-card:hover,
body.dark-mode .abr-mega-product-card:hover {
    background: rgba(255, 255, 255, 0.1);
}

body.dark-mode .abr-mega-post-card h4 a,
body.dark-mode .abr-mega-cat-card h4 a,
body.dark-mode .abr-mega-product-card h4 a {
    color: var(--abr-dark-text);
}

body.dark-mode .post-date,
body.dark-mode .cat-count,
body.dark-mode .price {
    color: rgba(248, 250, 252, 0.6);
}

/* Navigation Arrow - Pure CSS (No font dependency) */
.menu-item-has-mega-menu>a::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    margin-inline-start: 6px;
    margin-bottom: 2px;
    vertical-align: middle;
    transition: transform 0.3s ease;
}

.menu-item-has-mega-menu:hover>a::after,
.menu-item-has-mega-menu.is-hovered>a::after {
    transform: rotate(-135deg);
}

/* Fullscreen Mobile Mega Menu Overlay */
@media (max-width: 1024px) {

    /* The Overlay Container */
    /* Increased specificity to avoid !important */
    /* The Mobile Mega Menu Content - Inline Accordion Style */
    #page .abr-mega-menu-content {
        position: static;
        /* No longer fixed fullscreen */
        width: 100%;
        height: auto;
        padding: 0;
        overflow: hidden;
        display: none;
        /* Controlled by .is-open class */
        opacity: 1;
        visibility: visible;
        transform: none;
        border: none;
        border-radius: 0;
        box-shadow: none;
        backdrop-filter: none;
        pointer-events: auto;
    }

    #page .abr-mega-menu-content.is-active-mobile,
    #page .abr-mega-menu-content.is-open {
        display: block !important;
    }

    /* Grid Layout - Mobile Fluidity */
    #page .abr-mega-menu-content[class*="abr-grid-"],
    #page .abr-grid-1,
    #page .abr-grid-2,
    #page .abr-grid-3,
    #page .abr-grid-4,
    #page .abr-grid-5,
    #page .abr-grid-6 {
        --abr-mega-cols: 2;
    }

    @media (max-width: 639px) {

        #page .abr-grid-1,
        #page .abr-grid-2,
        #page .abr-grid-3,
        #page .abr-grid-4,
        #page .abr-grid-5,
        #page .abr-grid-6 {
            --abr-mega-cols: 1;
        }
    }

    #page .abr-mega-menu-content[class*="abr-grid-"] .abr-mega-grid {
        width: 100%;
    }

    /* Reset Nested menus inside full-screen overlay */
    body #page .abr-mega-menu-content .abr-mega-menu-content,
    body #page .sub-menu .abr-mega-menu-content {
        position: static;
        width: 100%;
        height: auto;
        padding: 0;
        background: transparent;
        display: none;
        /* Initially hidden on mobile */
        opacity: 1;
        visibility: visible;
        transform: none;
        box-shadow: none;
        border: none;
    }

    body #page .abr-mega-menu-content .abr-mega-menu-content.is-open,
    body #page .sub-menu .abr-mega-menu-content.is-open {
        display: block;
    }

    /* Accordion Trigger Styles */
    .abr-mega-menu-content .menu-item-has-children>a,
    .abr-mega-menu-content .menu-item-has-mega-menu>a {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 15px 20px;
        /* Horizontal padding moved to links */
        border-bottom: 1px solid rgba(0, 0, 0, 0.05);
        width: 100%;
        box-sizing: border-box;
    }

    /* Full width sub-containers */
    .site-header .abr-mega-menu-content .sub-menu,
    .site-topbar .abr-mega-menu-content .sub-menu,
    body #page .abr-mega-menu-content .abr-mega-menu-content,
    body #page .sub-menu .abr-mega-menu-content {
        padding: 0;
        margin: 0;
        width: 100% !important;
        max-width: 100% !important;
        position: static;
        display: none;
    }

    body #page .abr-mega-menu-content .abr-mega-menu-content.is-open,
    body #page .sub-menu .abr-mega-menu-content.is-open,
    .site-header .abr-mega-menu-content .sub-menu.is-open,
    .site-topbar .abr-mega-menu-content .sub-menu.is-open,
    #page .abr-mega-menu-content.is-open {
        display: block !important;
    }

    #page .abr-mega-grid {
        display: block !important;
    }

    /* Nested link padding for visual hierarchy */
    .abr-mega-menu-content .sub-menu li a {
        padding-inline-start: 40px !important;
        padding-top: 12px;
        padding-bottom: 12px;
        border-bottom: 1px solid rgba(0, 0, 0, 0.03);
    }

    .abr-mega-menu-content .menu-item-has-children>a::after,
    .abr-mega-menu-content .menu-item-has-mega-menu>a::after {
        content: '+';
        font-size: 1.2rem;
        transition: transform 0.3s ease;
    }

    .abr-mega-menu-content .menu-item-has-children.is-open>a::after,
    .abr-mega-menu-content .menu-item-has-mega-menu.is-open>a::after {
        content: '−';
        transform: rotate(180deg);
    }

    /* Dynamic Content maintained by unified variable system above */
    body #page .abr-mega-dynamic-posts,
    body #page .abr-mega-dynamic-categories,
    body #page .abr-mega-dynamic-products {
        gap: 15px;
    }

    body #page .abr-mega-post-card h4 {
        font-size: 13px;
    }

    body #page .post-thumb img,
    body #page .product-thumb img {
        height: 120px;
    }
}

/* Touch Device Support */
@media (hover: none) {
    .menu-item-has-mega-menu:hover>.abr-mega-menu-content {
        display: none;
        /* Prevents ghost hovers on touch */
    }

    .menu-item-has-mega-menu.is-active-mobile>.abr-mega-menu-content {
        display: block;
    }
}
