/**
 * Shared mega-menu base — the flyout shell + link-row primitives every module
 * reuses.
 *
 * Ships in its own file (`build/mega.css`) enqueued only when at least one mega
 * module is enabled, so the always-loaded frontend sheet stays lean (Layer 6:
 * on-page CSS scales with what's turned on). Owns positioning, card chrome, the
 * hidden/reveal state, and the shared link row (list, item, link, icon tile,
 * title, description) that every variant emits — reusing the same `--aureon-*`
 * tokens and hover/click triggers as `.sub-menu`. Each module's own stylesheet
 * supplies only its container layout (column grid, full-bleed sizing, footer
 * bar); module sheets depend on this one for cascade order.
 */

.aureon-header .aureon-nav {

	/* Mega panels replace a parent's .sub-menu when it resolves to a module. */
	.aureon-mega {
		position: absolute;

		/* `100%` is the bottom of the trigger <li>, which is only as tall as its
		   link — on a header row taller than that (logo, row padding) the panel
		   would start inside the header and overlap it. `--aureon-mega-drop` is the
		   leftover distance down to the row's bottom edge, measured in
		   `mega-drop.js` (CSS can't reach an ancestor's height) and published on
		   the <li>. Absent JS, or on panels that already anchor to the row, it
		   falls back to 0 and the old trigger-relative drop applies. */
		top: calc(100% + var(--aureon-mega-drop, 0px));
		left: 50%;

		/* Never wider than the screen, whatever width a style or its Panel Style
		   override asks for (the full-width shell lifts this). */
		max-width: calc(100vw - 2rem);
		z-index: 100;

		/* The gap between the trigger row and the panel. A variable rather than a
		   flat value so a panel can be set flush (0) or pushed further down
		   without the hover bridge below losing track of the distance it has to
		   span — both read the same custom property. Named for the *drop* to keep
		   it clear of `--aureon-mega-gap`, which is the gap between link rows
		   inside a panel; the two are unrelated and a panel that set one would
		   otherwise inherit it into the other. */
		margin-top: var(--aureon-mega-drop-gap, var(--aureon-space-sm));

		/* Centred on the trigger, then nudged by `--aureon-mega-shift` (measured
		   in `mega-drop.js`) so a wide panel under an item near either end of the
		   nav stays inside the header's content area instead of overhanging it. */
		transform: translate(calc(-50% + var(--aureon-mega-shift, 0px)), 6px);
		background: var(--aureon-submenu-bg, var(--aureon-color-background));
		border: 1px solid color-mix(in srgb, var(--aureon-color-border) 60%, transparent);

		/* Radius + shadow are overridable per style from Mega Menu → Panel Style
		   (emitted by Mega_Menu_Bootstrap::enqueue_dimensions()). */
		border-radius: var(--aureon-mega-radius, var(--aureon-radius-lg));
		box-shadow: var(--aureon-mega-shadow, 0 16px 40px -8px rgba(15, 23, 42, 0.18));
		opacity: 0;
		visibility: hidden;
		transition:
			opacity 0.18s ease,
			transform 0.18s ease,
			visibility 0.18s ease;

		/* Transparent bridge so the cursor can cross the gap to the trigger
		   without dropping :hover and closing the panel. Spans the whole gap —
		   the margin plus the drop down from the trigger to the row's edge. */
		&::before {
			content: "";
			position: absolute;
			bottom: 100%;
			left: 0;
			width: 100%;
			height: calc(var(--aureon-mega-drop-gap, var(--aureon-space-sm)) + var(--aureon-mega-drop, 0px));
		}
	}

	/* Reveal on click for click-triggered menus (JS toggles `.is-open`). Mega
	   panels keep their horizontal centering (translate -50%) on reveal,
	   unlike .sub-menu. */
	li.is-open > .aureon-mega {
		opacity: 1;
		visibility: visible;
		transform: translate(calc(-50% + var(--aureon-mega-shift, 0px)), 0);
	}
}

/* Reveal on hover / keyboard focus for hover-triggered menus. */
.aureon-header .aureon-menu-el--trigger-hover .aureon-nav {

	li:hover > .aureon-mega,
	li:focus-within > .aureon-mega {
		opacity: 1;
		visibility: visible;
		transform: translate(calc(-50% + var(--aureon-mega-shift, 0px)), 0);
	}
}

/**
 * Shared link-row primitive.
 *
 * Every variant renders its links as this same row (icon tile + title +
 * optional description), so the styles live here in the base sheet rather than
 * being duplicated per module. A module sheet only positions the row's
 * container (a single column, a grid cell, a footer bar).
 *
 * Scoped under `.aureon-mega` on purpose: the panel sits inside
 * `.aureon-menu`, whose `.aureon-menu a { display: inline-block }` rule
 * (specificity 0,1,1) would beat a bare `.aureon-mega__link` (0,1,0) and
 * collapse the flex row — stacking the icon above the title. `.aureon-mega
 * .aureon-mega__link` (0,2,0) wins cleanly.
 */
.aureon-mega {

	.aureon-mega__list {
		display: flex;
		flex-direction: column;

		/* Item gap defaults to 2px; a per-variant override sets --aureon-mega-gap. */
		gap: var(--aureon-mega-gap, 2px);
		margin: 0;
		padding: 0;
		list-style: none;
	}

	.aureon-mega__item {
		display: block;
		margin: 0;
	}

	.aureon-mega__link {
		display: flex;
		gap: 0.875rem;
		align-items: flex-start;
		padding: 0.75rem;
		border-radius: var(--aureon-radius-md, 8px);
		color: var(--aureon-submenu-text, var(--aureon-color-text));
		text-decoration: none;
		transition:
			background-color 0.15s ease,
			color 0.15s ease;

		&:hover,
		&:focus-visible {
			background: var(--aureon-submenu-hover-bg, color-mix(in srgb, var(--aureon-submenu-text, var(--aureon-color-text)) 6%, transparent));

			.aureon-mega__title {
				color: var(--aureon-menu-link-hover, var(--aureon-color-link));
			}

			.aureon-mega__icon {
				color: var(--aureon-menu-link-hover, var(--aureon-color-link));
			}
		}
	}

	/* A read-only row (Link type → "Read-only label") keeps the row's layout but
	   drops every affordance of a link: no hover tint, no pointer, no focus. */
	.aureon-mega__link--readonly {
		cursor: default;
		color: var(--aureon-submenu-text, var(--aureon-color-text));

		&:hover {
			background: none;
		}
	}

	/* Icon tile — square, subtly recessed, colors to the primary on hover. */
	.aureon-mega__icon {
		display: grid;
		flex: 0 0 auto;
		place-items: center;
		width: 2.5rem;
		height: 2.5rem;
		border-radius: var(--aureon-radius-md, 8px);
		background: color-mix(in srgb, var(--aureon-color-border) 35%, transparent);
		color: var(--aureon-color-text);
		font-size: 1.375rem;
		line-height: 1;
		transition: color 0.15s ease;

		/* Phosphor glyph (font `<i>`) sizes off font-size; SVGs kept in step. */
		svg {
			width: 1.375rem;
			height: 1.375rem;
		}
	}

	.aureon-mega__text {
		display: flex;
		min-width: 0;
		flex-direction: column;
		gap: 0.15rem;
	}

	.aureon-mega__title {
		font-size: var(--aureon-submenu-font-size, 0.9375rem);
		font-weight: 600;
		line-height: 1.3;
		color: inherit;
		transition: color 0.15s ease;
	}

	.aureon-mega__desc {
		font-size: 0.8125rem;
		line-height: 1.4;
		color: color-mix(in srgb, var(--aureon-submenu-text, var(--aureon-color-text)) 65%, transparent);
	}
}
