/*
 * Megamenu panel system — base stylesheet
 *
 * Customise via CSS custom properties in your theme:
 *
 *   --mm-max-width   Max content width inside the panel   (default: 1200px)
 *   --mm-padding-x   Horizontal padding inside the panel  (default: 1.5rem)
 *   --mm-accent      Chevron + link hover colour           (default: currentColor)
 *   --mm-text        Link text colour                      (default: inherit)
 *   --mm-bg          Panel background                      (default: #fff)
 *   --mm-bg-mobile   Mobile accordion background           (default: #f9fafb)
 *
 * The promo slot background has no default — set it via:
 *   .megamenu-promo { background-color: var(--color-primary); }
 *
 * Some link-reset rules use .megamenu-panel a selectors to undo common
 * parent-theme nav styles. Add more specific overrides in your theme if needed.
 */

/* ── Panel container ────────────────────────────────────────────────────────
   left/width are set by megamenu.js (alignPanels) so the panel spans the
   full nav bar width regardless of where the <li> sits.               */

.megamenu-panel {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 200;
    background: var(--mm-bg, #fff);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.10);
    text-align: left;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.2s ease, visibility 0s linear 0.2s;
    pointer-events: none;
}

li.has-megamenu:hover .megamenu-panel,
li.has-megamenu.is-open .megamenu-panel {
    visibility: visible;
    opacity: 1;
    transition: opacity 0.2s ease, visibility 0s linear;
    pointer-events: auto;
}

/* ── Dim overlay ─────────────────────────────────────────────────────────── */

main {
    position: relative;
}

.megamenu-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.2);
    z-index: 9;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

@media (max-width: 767px) {
    .megamenu-overlay {
        display: none;
    }
}

body.megamenu-open .megamenu-overlay {
    opacity: 1;
    pointer-events: auto;
}

/* ── Inner layout ────────────────────────────────────────────────────────── */

.megamenu-inner {
    display: flex;
    align-items: flex-start;
    gap: 2rem;
    max-width: var(--mm-max-width, 1200px);
    margin: 0 auto;
    padding: 1.75rem var(--mm-padding-x, 1.5rem);
}

/* ── Columns area ────────────────────────────────────────────────────────── */

.megamenu-columns {
    display: grid;
    grid-template-columns: repeat(var(--mm-cols, 2), minmax(0, 1fr));
    gap: 0 2.5rem;
    align-items: start;
    justify-content: center;
    margin: 0 auto;
}

/* 4 → 2+2 */
@media (max-width: 1023px) {
    .megamenu-columns {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* 2+2 → single column */
@media (max-width: 899px) {
    .megamenu-columns {
        grid-template-columns: repeat(1, 1fr);
    }

    .megamenu-column + .megamenu-column {
        border-top: 1px solid #e5e7eb;
        padding-top: 0.75rem;
    }
}

.megamenu-column {
    display: flex;
    flex-direction: column;
    max-width: 350px;
}

@media (max-width: 767px) {
    .megamenu-column {
        max-width: none;
    }
}

/* ── Items within a column ───────────────────────────────────────────────── */

.megamenu-item {
    padding: 0.75rem 0;
}

.megamenu-item:first-child {
    padding-top: 0;
}

.megamenu-item + .megamenu-item {
    border-top: 1px solid #e5e7eb;
}

.megamenu-item-title {
    font-size: 16px;
    font-weight: 600;
    margin-top: 0;
    margin-bottom: 0.4rem;
}

.megamenu-item-title a {
    color: inherit;
    text-decoration: underline;
    font-weight: 600;
}

.megamenu-item-title a:hover {
    color: var(--mm-accent, currentColor);
    text-decoration: underline;
}

.megamenu-item-ingress {
    font-size: 0.8125rem;
    color: #6b7280;
    margin-top: 0;
    margin-bottom: 0.5rem;
    line-height: 1.4;
}

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

.megamenu-item-links li {
    margin-bottom: 0.3rem;
}

.megamenu-item-links a {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--mm-text, inherit);
    text-decoration: none;
}

.megamenu-item-links a:hover {
    color: var(--mm-accent, currentColor);
    text-decoration: underline;
}

/* ── Promo slot ──────────────────────────────────────────────────────────── */

.megamenu-promo {
    flex-shrink: 0;
    width: 260px;
    border-radius: 1rem;
    padding: 1.25rem;
    color: #fff;
    /* background-color: set per panel inline, or provide a fallback:
       .megamenu-promo { background-color: var(--color-primary); } */
}

.megamenu-promo-image {
    margin-bottom: 0.75rem;
    background: #fff;
    border-radius: 1rem;
}

.megamenu-promo-image img {
    width: 100%;
    height: 130px;
    object-fit: cover;
    display: block;
    border-radius: 0.5rem;
}

.megamenu-promo-heading {
    font-size: 1rem;
    font-weight: 700;
    margin-top: 0;
    margin-bottom: 0.4rem;
    color: #fff;
}

.megamenu-promo-heading a {
    color: #fff;
    text-decoration: underline;
    font-weight: 600;
}

.megamenu-promo-heading a:hover {
    color: #fff;
    text-decoration: underline;
}

.megamenu-promo-text {
    font-size: 0.8125rem;
    line-height: 1.45;
    margin-top: 0;
    margin-bottom: 0.75rem;
    opacity: 0.9;
}

.megamenu-promo-link {
    font-size: 0.8125rem;
    font-weight: 500;
    color: #fff;
    text-decoration: underline;
    transition: opacity 0.15s;
}

.megamenu-promo-link:hover {
    color: #fff;
    opacity: 0.75;
    text-decoration: underline;
}

/* ── Chevron on megamenu trigger link ────────────────────────────────────── */

/* Hide parent-theme arrow elements if injected into our items */
.has-megamenu > a > .arrow {
    display: none !important;
}

.has-megamenu > a::after {
    content: '';
    display: inline-block;
    width: 5px;
    height: 5px;
    border-right: 2px solid var(--mm-accent, currentColor);
    border-bottom: 2px solid var(--mm-accent, currentColor);
    transform: rotate(45deg) translateY(-2px);
    margin-left: 6px;
    transition: transform 0.2s ease;
    vertical-align: middle;
    flex-shrink: 0;
}

li.has-megamenu:hover > a::after,
li.has-megamenu.is-open > a::after {
    transform: rotate(-135deg) translateY(2px);
}

/* ── Responsive: sub-desktop (768–1023px) ────────────────────────────────── */

@media (min-width: 768px) and (max-width: 1023px) {
    .megamenu-inner {
        flex-direction: row;
    }

    .megamenu-promo {
        width: min-content;
        min-width: 280px;
    }
}

/* ── Mobile (<768px): accordion ──────────────────────────────────────────── */

@media (max-width: 767px) {

    .megamenu-panel {
        position: static !important;
        width: auto !important;
        left: auto !important;
        box-shadow: none;
        border-top: none;
        background: var(--mm-bg-mobile, #f9fafb);
        visibility: visible !important;
        opacity: 1 !important;
        transform: none !important;
        pointer-events: auto !important;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.35s ease !important;
    }

    li.has-megamenu.is-open .megamenu-panel {
        max-height: 2000px;
    }

    .megamenu-inner {
        flex-direction: column;
        padding: 0.75rem 1rem 1rem;
        gap: 1rem;
        max-width: none;
    }

    .megamenu-columns {
        grid-template-columns: 1fr !important;
        gap: 0;
    }

    .megamenu-promo {
        width: 100%;
        min-width: 0;
    }

    /* Chevron: push to far right of trigger link.
       This selector may need adjusting to match your theme's mobile nav markup. */
    li.has-megamenu > a {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
    }

    li.has-megamenu > a::after {
        margin-left: auto;
        width: 8px;
        height: 8px;
    }
}
