/* =============================================================================
   megamenu.css — Communities vertical megamenu (desktop flyout + mobile accordion)
   Uses per-community --community-accent / --community-primary (injected by layout)
   and the fixed --text-primary:#1f2937 / --text-secondary:#4B5563 (WCAG AA).
   ============================================================================= */

/* ---------- Desktop sidebar megamenu ---------- */
/* The whole trigger list sits in ONE white card, matching a standard menu block (.event-pages-nav). */
.megamenu {
    width: 100%;
    background: var(--bg-white, #ffffff);
    border: 1px solid var(--glass-border, rgba(0, 0, 0, 0.1));
    border-radius: 1rem;
    box-shadow: 0 4px 20px 0 rgba(209, 209, 209, 0.15);
    padding: 0.75rem;
    box-sizing: border-box;
}

.megamenu-triggers {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.megamenu-trigger {
    position: relative; /* anchor for the absolutely-positioned flyout */
}

/* Trigger row: link, disclosure button, or static label — all share the look */
/* Trigger rows mirror the standard-menu link rows (.event-page-link). */
.megamenu-trigger-link,
.megamenu-trigger-button,
.megamenu-trigger-static {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    min-height: 52px; /* WCAG touch target */
    padding: 1rem 1.25rem;
    box-sizing: border-box;
    color: var(--text-primary, #1f2937);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 0.75rem;
    font: inherit;
    font-weight: 500;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: color 0.2s ease, border-color 0.2s ease;
}

.megamenu-trigger-static {
    cursor: default;
}

.megamenu-trigger-link:hover,
.megamenu-trigger-button:hover,
.megamenu-trigger.open > .megamenu-trigger-link,
.megamenu-trigger.open > .megamenu-trigger-button {
    color: var(--community-primary, #6A4A9E);
    border-color: color-mix(in srgb, var(--community-primary, #6A4A9E) 15%, transparent);
}

.megamenu-trigger-label {
    flex: 1 1 auto;
}

.megamenu-caret {
    margin-left: auto;
    font-size: 0.75rem;
    color: var(--text-secondary, #4B5563);
    transition: transform 0.15s ease;
}

.megamenu-trigger.open .megamenu-caret {
    transform: rotate(90deg);
}

/* Separate disclosure toggle next to a navigating link (link+flyout trigger) */
.megamenu-trigger-toggle {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-secondary, #4B5563);
    cursor: pointer;
}

/* ---------- Flyout panel (two columns: groups left, blurbs right) ---------- */
.megamenu-flyout {
    position: absolute;
    top: 0;
    left: 100%;
    z-index: 1000;
    display: flex;
    align-items: flex-start; /* don't stretch the short menu column to the tall blurb */
    gap: 1.5rem;
    min-width: 320px;
    width: max-content;
    max-width: 720px;
    max-height: 80vh;
    overflow-y: auto;
    padding: 1.5rem;
    background: var(--bg-white, #ffffff);
    border: 1px solid var(--glass-border, rgba(0, 0, 0, 0.1));
    border-radius: 1rem;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
    /* hidden by default */
    visibility: hidden;
    opacity: 0;
    transform: translateX(-6px);
    transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
}

/* Both columns share identical flex → always equal halves (50/50). */
.megamenu-flyout-main {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.megamenu-flyout-aside {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Reveal: hover, keyboard focus-within, or JS-toggled .open */
.megamenu-trigger:hover > .megamenu-flyout,
.megamenu-trigger:focus-within > .megamenu-flyout,
.megamenu-trigger.open > .megamenu-flyout {
    visibility: visible;
    opacity: 1;
    transform: translateX(0);
}

/* Right-sidebar megamenu: flyout opens to the LEFT so it doesn't run off-screen. */
.megamenu--fly-left .megamenu-flyout {
    left: auto;
    right: 100%;
    transform: translateX(6px);
}

.megamenu--fly-left .megamenu-trigger:hover > .megamenu-flyout,
.megamenu--fly-left .megamenu-trigger:focus-within > .megamenu-flyout,
.megamenu--fly-left .megamenu-trigger.open > .megamenu-flyout {
    transform: translateX(0);
}

/* ---------- Group (L2) ---------- */
/* Groups are spaced by the flex `gap` on .megamenu-flyout-main — no divider lines (matches ECS). */
.megamenu-group {
    display: flex;
    flex-direction: column;
    gap: 0.45rem; /* item-to-item rhythm (~30% more than the initial tight 0.35rem) */
}

.megamenu-group-heading {
    margin: 0 0 0.3rem 0; /* heading keeps its own breathing room despite the tight item gap */
    font-size: var(--font-size-lg, 1.125rem); /* ~18px — a touch larger than items, much lighter than before */
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: -0.01em;
    text-transform: none;
    color: var(--community-primary, #6A4A9E);
}

/* ---------- Item (L3) — plain text rows, not buttons ---------- */
.megamenu-item {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 0;
    border-radius: 0;
    /* Override the global WCAG touch-target floor (community-accessibility.css sets
       a, button { min-height/min-width: 44px }), which otherwise pads single-line items
       with ~22px of empty space below the label — the "phantom description slot". The desktop
       flyout is pointer/keyboard-driven; the mobile accordion keeps its larger targets. */
    min-height: 0;
    min-width: 0;
    color: var(--text-primary, #1f2937);
    text-decoration: none;
}

/* Hover: icon + title + description turn primary; no background highlight. */
.megamenu-item:hover .megamenu-item-label,
.megamenu-item:hover .megamenu-item-desc,
.megamenu-item:hover .megamenu-item-icon {
    color: var(--community-primary, #6A4A9E);
}

.megamenu-item-static {
    cursor: default;
}

.megamenu-item-icon {
    flex: 0 0 auto;
    margin-top: 0.2rem;
    width: 1rem;
    text-align: center;
    font-size: 0.95rem;
    color: var(--text-secondary, #4B5563);
}

.megamenu-item-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.megamenu-item-label {
    font-size: var(--font-size-base, 1rem); /* 16px — matches the sidebar trigger title */
    font-weight: 500;
    line-height: 1.4;
    color: var(--text-primary, #1f2937);
}

.megamenu-item-desc {
    font-size: var(--font-size-sm, 0.875rem); /* 14px */
    line-height: 1.45;
    color: var(--text-secondary, #4B5563);
    margin-top: 0.1rem;
}

/* Markdown wraps the description in <p>; strip its UA margins so it sits tight under the label. */
.megamenu-item-desc p {
    margin: 0;
}

/* ---------- Blurb ---------- */
/* Background + text color are set inline (BlurbStyle) so text inverts to stay readable on any
   background. Title/body/icon inherit that color. */
.megamenu-blurb {
    display: block;
    padding: 1.25rem;
    border-radius: 12px;
    background: var(--community-accent, var(--community-primary, #6366F1));
    text-decoration: none;
}

a.megamenu-blurb-link {
    display: block;
}

a.megamenu-blurb-link:hover {
    filter: brightness(0.95);
}

/* Icon only renders when the blurb has one (conditional in markup), so a no-icon blurb reserves
   no space. When present, show it at 2x. */
.megamenu-blurb-icon {
    display: block;
    font-size: 2.5rem;
    line-height: 1;
    margin-bottom: 0.6rem;
    color: inherit;
}

.megamenu-blurb-title {
    margin: 0 0 0.35rem 0;
    font-size: var(--font-size-lg, 1.125rem); /* ~18px */
    font-weight: 700;
    color: inherit;
}

.megamenu-blurb-body {
    font-size: var(--font-size-sm, 0.875rem); /* 14px */
    color: inherit;
    opacity: 0.95;
}

.megamenu-blurb-body p {
    margin: 0 0 0.5rem;
}

.megamenu-blurb-body p:last-child {
    margin-bottom: 0;
}

/* ---------- Focus visibility (WCAG) ---------- */
.megamenu-trigger-link:focus-visible,
.megamenu-trigger-button:focus-visible,
.megamenu-trigger-toggle:focus-visible,
.megamenu-item:focus-visible,
.megamenu-blurb-link:focus-visible,
.mobile-nav-accordion-trigger:focus-visible {
    outline: 2px solid var(--community-primary, #2563eb);
    outline-offset: 2px;
}

/* ---------- Mobile accordion (drawer) ---------- */
.mobile-megamenu {
    display: flex;
    flex-direction: column;
}

.mobile-nav-accordion-trigger {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    min-height: 48px;
    padding: 0.75rem 1rem;
    box-sizing: border-box;
    background: transparent;
    border: none;
    border-bottom: 1px solid #f0f0f0;
    color: var(--text-primary, #1f2937);
    font: inherit;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
}

.mobile-nav-accordion-trigger .megamenu-caret {
    transition: transform 0.15s ease;
}

.mobile-nav-accordion-trigger[aria-expanded="true"] .megamenu-caret {
    transform: rotate(90deg);
}

.mobile-nav-accordion-panel {
    padding: 0.25rem 0 0.5rem 0.75rem;
}

.mobile-megamenu .megamenu-flyout {
    /* the accordion reuses item/blurb styles but not the absolute 2-column desktop flyout */
    position: static;
    display: block;        /* collapse the desktop 2-column flex to a single stacked column */
    width: auto;
    gap: 0;
    visibility: visible;
    opacity: 1;
    transform: none;
    min-width: 0;
    max-width: none;
    max-height: none;
    overflow: visible;
    padding: 0;
    border: none;
    border-radius: 0;
    box-shadow: none;
}

/* Stack the columns and give the blurb column breathing room when collapsed. */
.mobile-megamenu .megamenu-flyout-aside {
    flex: none;
    margin-top: 0.75rem;
}

.mobile-nav-megamenu-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 48px;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #f0f0f0;
    color: var(--text-primary, #1f2937);
    text-decoration: none;
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    .megamenu-flyout,
    .megamenu-caret,
    .mobile-nav-accordion-trigger .megamenu-caret {
        transition: none;
    }
}
