/* ============================================================================
   Resources mega menu — desktop dropdown from the primary nav.

   Additive module. Touches no existing selector: only .has-mega / .mega-*
   classes, all new. Reuses the .profile-dropdown grammar already in nav.css
   (--bg-alt surface, --surface-border, --r-card, fade+slide .is-open) so the
   panel reads as part of the same system. Theme-invariant — every colour is a
   token, so dark default and [data-theme="light"] both resolve correctly.

   Load AFTER nav.css in the $cssModules manifest (header.php). Behaviour lives
   in /js/nav-mega.js (UI-002: no inline JS).
   ============================================================================ */

/* The <li> wrapper becomes the positioning context for the panel. */
.has-mega {
    position: relative;
}

/* --------------------------------------------------------------------------
   Trigger — a <button> styled to sit in the primary-nav link row. Matches
   .primary-nav a exactly (size, colour, animated underline), plus a caret.
   Its own accent key so the underline colour is distinct from the six links.
-------------------------------------------------------------------------- */
.mega-trigger {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1;
    color: var(--text);
    background: none;
    border: 0;
    padding: var(--space-xs) 0;
    cursor: pointer;
    transition: color var(--transition);

    /* Resources accent — theme accent so it stays legible on both grounds.
       Change this one line to give Resources a bespoke colour if wanted. */
    --nav-accent: var(--color-accent);
}
.mega-trigger::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 2px;
    background: var(--nav-accent);
    transform: scaleX(0);
    transform-origin: left center;
    transition: transform 320ms cubic-bezier(0.32, 0.72, 0, 1);
    border-radius: 1px;
    pointer-events: none;
}
.mega-trigger:hover,
.mega-trigger:focus-visible,
.has-mega.is-open .mega-trigger {
    color: var(--nav-accent);
}
.mega-trigger:hover::after,
.mega-trigger:focus-visible::after,
.has-mega.is-open .mega-trigger::after {
    transform: scaleX(1);
}

/* Caret rotates when open. */
.mega-trigger .mega-caret {
    width: 12px;
    height: 12px;
    transition: transform var(--transition);
}
.has-mega.is-open .mega-trigger .mega-caret {
    transform: rotate(180deg);
}

/* --------------------------------------------------------------------------
   Panel — mirrors .profile-dropdown: --bg-alt surface, hairline border,
   fade + slide on open. Wide, centred under the trigger.
-------------------------------------------------------------------------- */
.mega-panel {
    position: absolute;
    top: calc(100% + 12px);
    left: 50%;
    transform: translateX(-50%) translateY(-6px);
    z-index: 30;

    width: min(920px, calc(100vw - 48px));
    background: var(--bg-alt);
    border: 1px solid var(--surface-border);
    border-radius: var(--r-card);
    box-shadow:
        0 12px 32px rgba(0, 0, 0, 0.32),
        0 2px 6px rgba(0, 0, 0, 0.16);
    padding: var(--space-lg);

    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-lg);

    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    transition:
        opacity    180ms ease,
        transform  220ms cubic-bezier(0.16, 0.84, 0.44, 1),
        visibility 0s linear 220ms;
}
.has-mega.is-open .mega-panel {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
    visibility: visible;
    transition-delay: 0s;
}

.mega-col { min-width: 0; }

.mega-eyebrow {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 10px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding-bottom: var(--space-xs);
    margin: 0 0 var(--space-xs);
    border-bottom: 1px solid var(--surface-border);
}

.mega-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.mega-link {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: var(--space-sm);
    align-items: start;
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--r-card);
    text-decoration: none;
    transition: background 160ms ease;
}
.mega-link:hover,
.mega-link:focus-visible {
    background: rgba(43, 108, 176, 0.16);   /* same tint as .profile-dropdown__link */
    outline: none;
}

.mega-ico {
    width: 30px;
    height: 30px;
    border-radius: var(--r-card);
    border: 1px solid var(--surface-border);
    display: grid;
    place-items: center;
    color: var(--color-accent);
}
.mega-ico svg { width: 16px; height: 16px; }

.mega-title {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 13.5px;
    letter-spacing: -0.01em;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 6px;
}
.mega-title .mega-badge {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-accent);
    border: 1px solid var(--surface-border);
    border-radius: 3px;
    padding: 0 4px;
}
.mega-desc {
    font-family: var(--font-body);
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
    margin-top: 1px;
}

/* --------------------------------------------------------------------------
   Build & design accordion — collapses a long link column into labelled
   groups so the panel stays short. Native <details>/<summary>: no JS, keyboard
   operable, and fully usable with JS off. Groups share a name attribute so
   opening one closes the rest, bounding the panel's height. The link rows
   inside reuse .mega-link verbatim, so the open state is visually identical to
   a flat column.
-------------------------------------------------------------------------- */
.mega-acc {
    display: flex;
    flex-direction: column;
}

.mega-acc-item {
    border-bottom: 1px solid var(--surface-border);
}
.mega-acc-item:last-child {
    border-bottom: 0;
}

.mega-acc-summary {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm);
    cursor: pointer;
    list-style: none;                 /* strip default marker (Firefox) */
    border-radius: var(--r-card);
    transition: background 160ms ease, color 160ms ease;
}
.mega-acc-summary::-webkit-details-marker { display: none; }   /* Safari / Chrome */
.mega-acc-summary:hover,
.mega-acc-summary:focus-visible {
    background: rgba(43, 108, 176, 0.16);   /* same tint as .mega-link hover */
    outline: none;
}
.mega-acc-item[open] > .mega-acc-summary {
    color: var(--color-accent);
}

.mega-acc-label {
    flex: 1 1 auto;
    min-width: 0;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 13.5px;
    letter-spacing: -0.01em;
    color: inherit;
}

.mega-acc-count {
    flex: 0 0 auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 10px;
    line-height: 1.6;
    color: var(--text-muted);
    border: 1px solid var(--surface-border);
    border-radius: 3px;
    padding: 0 5px;
}

.mega-acc-caret {
    flex: 0 0 auto;
    width: 14px;
    height: 14px;
    color: var(--text-muted);
    transition: transform var(--transition);
}
.mega-acc-item[open] > .mega-acc-summary .mega-acc-caret {
    transform: rotate(180deg);
    color: var(--color-accent);
}

/* Links sit directly under their group label, with a little breathing room. */
.mega-acc .mega-list {
    padding: 2px 0 var(--space-xs);
}

/* Open content eases in — echoes the panel's own entrance. */
.mega-acc-item[open] > .mega-list {
    animation: mega-acc-in 200ms cubic-bezier(0.16, 0.84, 0.44, 1);
}
@keyframes mega-acc-in {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* --------------------------------------------------------------------------
   Reduced motion — snap in, skip the slide (matches profile-dropdown).
-------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    .mega-panel { transition: opacity 120ms ease, visibility 0s linear 120ms; transform: translateX(-50%); }
    .has-mega.is-open .mega-panel { transform: translateX(-50%); }
    .mega-trigger::after,
    .mega-trigger .mega-caret { transition: none; }
    .mega-acc-caret { transition: none; }
    .mega-acc-item[open] > .mega-list { animation: none; }
}

/* --------------------------------------------------------------------------
   Small viewports — the primary nav is already hidden below the drawer
   breakpoint, so the mega trigger + panel hide with it. Resources still
   reaches users via its normal link in the drawer (drawer variant of
   renderNav) and via the footer Resources column.
-------------------------------------------------------------------------- */
@media (max-width: 860px) {
    .has-mega { position: static; }
    .mega-panel { display: none; }
}
