/**
 * itm/mega-nav — primary nav: desktop .mainnav + .mega panels, mobile .drawer
 * + .acc accordion (front-end + editor).
 *
 * Ported from design/atomic-components/organisms/header.css (the nav half),
 * tokens → Token Contract presets per token-map; brand-locked weights / z-index
 * inlined as literals. Knobs (--hdr-h / --mega-* / --wrap-* / --lead-accent)
 * are referenced with var() fallbacks so the block is self-sufficient; the
 * header chrome (.hdr / .hdr__wrap / .xstrip / .ftr) lives in the theme's
 * chrome.css. Scrim tints use color-mix off --contrast (were raw rgba). The
 * block wrapper is display:contents so .hdr__nav is a direct .hdr__wrap child.
 */

.itm-mega-nav { display: contents; }

/* ---- Desktop primary nav ---------------------------------------------- */
/* The nav stretches to the full height of the header BAR and passes that height
   down to the <li> and its control, so the hover/click target is the whole menu
   item block. It used to be `align-items: center` here and a fixed 40px control:
   the hit box was a 40px band inside a 76px bar, leaving an 18px dead strip
   above and below every item. view.js already listens on the <li>, so the panel
   opened on entering that band and started its close timer on leaving it —
   ordinary vertical drift while sliding across a label crossed the edge
   repeatedly and flickered the panel. Same 18px also swallowed clicks aimed at
   the top or bottom of a plain nav link. */
.hdr__nav { flex: 1 1 auto; align-self: stretch; display: flex; }
.mainnav > ul { flex: 1 1 auto; list-style: none; margin: 0; padding: 0; display: flex; align-items: stretch; justify-content: flex-end; gap: var(--wp--preset--spacing--10); }
/* static, NOT relative: the mega-panel below is `left:0;right:0`, so a relative
   <li> made the TRIGGER BUTTON its containing block and the panel rendered at
   the button's width. The panel's containing block must be the header bar. */
.mainnav__item { position: static; display: flex; }
.mainnav__link, .mainnav__trigger {
	font-family: var(--wp--preset--font-family--heading);
	font-weight: 500;
	font-size: var(--hdr-nav-fs, 0.9375rem);   /* 15px header nav text */
	display: inline-flex; align-items: center; gap: 6px;
	/* Fills the bar when the header gives it a height; min-height keeps the old
	   40px floor wherever it does not (editor preview, standalone render). */
	min-height: 40px; height: 100%; padding: 0 var(--wp--preset--spacing--30);
	color: var(--wp--preset--color--contrast); background: none; border: none; cursor: pointer;
	border-radius: var(--wp--custom--radius--default); white-space: nowrap; text-decoration: none; position: relative;
}
/* Offset from the CENTRE (half of the old 40px box, less the old 4px inset), so
   the underline stays pixel-identical now that the control is bar-height: it
   resolves to 4px on a 40px control and 22px on a 76px one. */
.mainnav__link::after, .mainnav__trigger::after {
	content: ""; position: absolute; left: var(--wp--preset--spacing--30); right: var(--wp--preset--spacing--30); bottom: calc(50% - 16px); height: 2px;
	background: var(--lead-accent, var(--wp--preset--color--secondary));
	transform: scaleX(0); transform-origin: left; transition: transform var(--wp--custom--transition--fast);
}
.mainnav__link:hover, .mainnav__trigger:hover { color: var(--wp--preset--color--primary); text-decoration: none; }
.mainnav__link:hover::after, .mainnav__trigger:hover::after,
.mainnav__item--active > .mainnav__link::after,
.mainnav__trigger[aria-expanded="true"]::after { transform: scaleX(1); }
.mainnav__chev { width: 14px; height: 14px; opacity: 0.6; transition: transform var(--wp--custom--transition--fast); display: inline-flex; }
.mainnav__chev svg { width: 100%; height: 100%; display: block; }
.mainnav__trigger[aria-expanded="true"] .mainnav__chev { transform: rotate(180deg); }
.mainnav__link:focus-visible, .mainnav__trigger:focus-visible { outline: none; box-shadow: var(--wp--custom--focus--ring); }

/* ---- Mega-panel ------------------------------------------------------- */
/* Anchored to .hdr__wrap (position:relative in chrome.css), not to .hdr: the
   panel belongs to the BAR, so `top:100%` puts it flush under the bar whatever
   the cross-strip above is doing — including being hidden below 1040px. The old
   `top: var(--hdr-h)` was measured from the trigger button and left a ~27px gap
   the 12px hover bridge could not span. */
.mega {
	position: absolute; left: 0; right: 0; top: 100%;
	background: var(--wp--preset--color--base);
	border-top: 1px solid var(--wp--custom--border--soft); border-bottom: 1px solid var(--wp--custom--border--muted);
	z-index: 1000;
	opacity: 0; visibility: hidden; transform: translateY(-6px);
	transition: opacity var(--wp--custom--transition--fast), transform var(--wp--custom--transition--fast), visibility var(--wp--custom--transition--fast);
}
.mega[data-open="true"] { opacity: 1; visibility: visible; transform: translateY(0); }
.mega::before { content: ""; position: absolute; left: 0; right: 0; top: -12px; height: 12px; }
/* box-sizing matters here and there is no global reset on this site (chrome.css
   sets it explicitly on .hdr__wrap / .xstrip__wrap / .ftr__inner for the same
   reason). As content-box, `width: min(100%, …)` plus the gutter padding made
   the wrap 115px wider than the panel — invisible while the panel was 145px
   wide, but a real horizontal page overflow once it spans the header. */
.mega__wrap {
	box-sizing: border-box;
	width: min(100%, var(--wrap-max, 1440px)); margin-inline: auto;
	padding: var(--mega-pad, var(--wp--preset--spacing--60)) var(--wrap-gutter, clamp(16px, 4vw, 64px));
	display: grid; grid-template-columns: repeat(var(--mega-cols, 4), 1fr); gap: var(--wp--preset--spacing--60); align-items: start;
}
.mega__col { display: flex; flex-direction: column; gap: 2px; }
.mega__head { font-family: var(--wp--preset--font-family--heading); font-weight: 700; font-size: var(--wp--preset--font-size--xs); letter-spacing: 0.08em; text-transform: uppercase; color: var(--wp--preset--color--contrast-2); padding-bottom: var(--wp--preset--spacing--20); border-bottom: 1px solid var(--wp--custom--border--soft); margin: 0 0 var(--wp--preset--spacing--20); }
.mega__link { font-size: var(--wp--preset--font-size--sm); color: var(--wp--preset--color--contrast); padding: 7px 0; text-decoration: none; display: inline-flex; align-items: center; gap: var(--wp--preset--spacing--20); }
.mega__link:hover { color: var(--wp--preset--color--primary); text-decoration: none; }
.mega__feature { background: var(--wp--preset--color--surface-1); border: 1px solid var(--wp--custom--border--soft); border-radius: var(--wp--custom--radius--default); padding: var(--wp--preset--spacing--50); display: flex; flex-direction: column; gap: var(--wp--preset--spacing--30); }
.mega__feature .eyebrow { font-family: var(--wp--preset--font-family--heading); font-size: var(--wp--preset--font-size--xs); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--lead-accent, var(--wp--preset--color--secondary)); margin: 0; }
.mega__feature h4 { margin: 0; font-size: var(--wp--preset--font-size--lead); font-family: var(--wp--preset--font-family--heading); font-weight: 500; }
.mega__feature p { margin: 0; font-size: var(--wp--preset--font-size--sm); color: var(--wp--preset--color--contrast-2); }
/* The section's own archive link. The trigger is a <button> (a disclosure), so
   without this the section landing page is unreachable. Spans the whole row. */
.mega__all { grid-column: 1 / -1; justify-self: start; font-family: var(--wp--preset--font-family--heading); font-weight: 500; font-size: var(--wp--preset--font-size--sm); color: var(--wp--preset--color--secondary); text-decoration: none; }
.mega__all:hover { color: var(--wp--preset--color--primary); text-decoration: underline; }

/* ---- Scrim under an open panel ----------------------------------------
   Full-viewport and z-999. It used to start at `--hdr-h` from the top, which is
   the BAR's height, not the header's — the strip sits above it and wraps, so no
   constant is safe here.
   ⚠ It still PAINTS over the header bar. Task 3 lifted `.hdr > *` to z-1000
   meaning to keep the bar undimmed, but this scrim sits INSIDE .hdr__wrap's
   stacking context (see the display:contents note below), so lifting the wrap
   lifted the scrim with it. Measured 2026-08-12: the bar's pixels change when a
   panel opens. Left as-is here — pointer-events below fixes the interaction
   bug; the paint order is a separate visual fix wanting its own pass. */
/* pointer-events: none is load-bearing, not a tidy-up. `display: contents` on
   the block wrapper makes this scrim a BOX-TREE SIBLING of .hdr__nav inside
   .hdr__wrap, and fixed+inset:0 then puts it over the header bar itself — so
   while a panel was open, elementFromPoint on the trigger returned .nav-scrim.
   The first pointer move fired mouseleave on the <li>, the 140ms timer closed
   the panel, the scrim went visibility:hidden, the next move re-entered the
   <li> and reopened it: a flicker loop that ran only while the mouse moved.
   The scrim has no interaction role of its own — view.js closes on a document
   click — so it must not hit-test. */
.nav-scrim { position: fixed; inset: 0; background: color-mix(in srgb, var(--wp--preset--color--contrast) 18%, transparent); opacity: 0; visibility: hidden; pointer-events: none; transition: opacity var(--wp--custom--transition--fast), visibility var(--wp--custom--transition--fast); z-index: 999; }
.nav-scrim[data-open="true"] { opacity: 1; visibility: visible; }

/* ---- Burger (chrome part toggles this block's drawer) ----------------- */
.hdr__icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border: none; background: none; cursor: pointer; color: var(--wp--preset--color--contrast); border-radius: var(--wp--custom--radius--default); position: relative; flex: 0 0 auto; }
.hdr__icon-btn:hover { background: var(--wp--preset--color--surface-1); color: var(--wp--preset--color--primary); }
.hdr__icon-btn .icon { width: 22px; height: 22px; display: inline-flex; }
.hdr__icon-btn .icon svg { width: 100%; height: 100%; display: block; }

/* ---- Collapse to burger + drawer at 1040px ---------------------------- */
@media (max-width: 1040px) {
	.hdr__nav { display: none; }
	.mega, .nav-scrim { display: none; }
}

/* ---- Mobile off-canvas drawer ----------------------------------------- */
/* visibility:hidden (plus the `inert` attribute toggled in view.js) is what
   takes the ~11 drawer controls out of the tab order while it is closed. It was
   only translated off-screen before, so every viewport — desktop included —
   tabbed through focusable content inside an aria-hidden element. */
.drawer {
	position: fixed; inset: 0 0 0 auto; width: min(92vw, 380px);
	background: var(--wp--preset--color--base); z-index: 1300;
	display: flex; flex-direction: column;
	transform: translateX(100%); visibility: hidden;
	transition: transform var(--wp--custom--transition--base), visibility var(--wp--custom--transition--base);
	border-inline-start: 1px solid var(--wp--custom--border--soft);
}
.drawer[data-open="true"] { transform: translateX(0); visibility: visible; }
.drawer__scrim { position: fixed; inset: 0; background: color-mix(in srgb, var(--wp--preset--color--contrast) 40%, transparent); opacity: 0; visibility: hidden; transition: opacity var(--wp--custom--transition--base), visibility var(--wp--custom--transition--base); z-index: 1299; }
.drawer__scrim[data-open="true"] { opacity: 1; visibility: visible; }
.drawer__head { display: flex; align-items: center; justify-content: space-between; gap: var(--wp--preset--spacing--40); padding: 0 var(--wp--preset--spacing--40) 0 var(--wp--preset--spacing--50); border-bottom: 1px solid var(--wp--custom--border--soft); height: var(--hdr-h, 76px); flex: 0 0 auto; }
.drawer__title { font-family: var(--wp--preset--font-family--heading); font-weight: 500; }
.drawer__body { overflow-y: auto; padding: var(--wp--preset--spacing--20) 0 var(--wp--preset--spacing--50); flex: 1 1 auto; }
.drawer__foot { border-top: 1px solid var(--wp--custom--border--soft); padding: var(--wp--preset--spacing--40) var(--wp--preset--spacing--50); display: flex; flex-direction: column; gap: var(--wp--preset--spacing--30); flex: 0 0 auto; }

.acc { border-bottom: 1px solid var(--wp--custom--border--soft); }
.acc__summary { display: flex; align-items: center; justify-content: space-between; gap: var(--wp--preset--spacing--30); width: 100%; padding: var(--wp--preset--spacing--40) var(--wp--preset--spacing--50); background: none; border: none; cursor: pointer; font-family: var(--wp--preset--font-family--heading); font-weight: 500; font-size: var(--wp--preset--font-size--md); color: var(--wp--preset--color--contrast); text-align: left; }
.acc__summary .icon { width: 18px; height: 18px; opacity: 0.6; transition: transform var(--wp--custom--transition--fast); flex: 0 0 auto; display: inline-flex; }
.acc__summary .icon svg { width: 100%; height: 100%; display: block; }
.acc__summary[aria-expanded="true"] .icon { transform: rotate(180deg); }
.acc__summary[aria-expanded="true"] { color: var(--wp--preset--color--primary); }
.acc__summary:focus-visible { outline: none; box-shadow: var(--wp--custom--focus--ring); }
.acc__panel { display: none; padding: 0 var(--wp--preset--spacing--50) var(--wp--preset--spacing--30); flex-direction: column; }
.acc__panel[data-open="true"] { display: flex; }
.acc__cat { font-family: var(--wp--preset--font-family--heading); font-weight: 700; font-size: var(--wp--preset--font-size--xs); letter-spacing: 0.08em; text-transform: uppercase; color: var(--wp--preset--color--contrast-2); margin: var(--wp--preset--spacing--30) 0 2px; }
.acc__leaf { display: block; padding: 8px 0 8px var(--wp--preset--spacing--30); font-size: var(--wp--preset--font-size--sm); color: var(--wp--preset--color--contrast); text-decoration: none; }
.acc__leaf:hover { color: var(--wp--preset--color--primary); }
.drawer__plain { display: block; padding: var(--wp--preset--spacing--40) var(--wp--preset--spacing--50); font-family: var(--wp--preset--font-family--heading); font-weight: 500; font-size: var(--wp--preset--font-size--md); color: var(--wp--preset--color--contrast); text-decoration: none; border-bottom: 1px solid var(--wp--custom--border--soft); }
.drawer__plain:hover { color: var(--wp--preset--color--primary); }
/* The cross-strip is desktop-only, so its Kaugabi action leads the drawer and
   its site links close it. */
.drawer__lead { padding: var(--wp--preset--spacing--30) var(--wp--preset--spacing--50) var(--wp--preset--spacing--40); border-bottom: 1px solid var(--wp--custom--border--soft); }
.drawer__also { padding: 0 var(--wp--preset--spacing--50) var(--wp--preset--spacing--30); display: flex; flex-direction: column; }

@media (prefers-reduced-motion: reduce) {
	.mega, .drawer, .drawer__scrim, .nav-scrim,
	.mainnav__link::after, .mainnav__trigger::after, .mainnav__chev, .acc__summary .icon { transition: none; }
}
