/**
 * Mega navigation.
 *
 * Loaded front-end and editor (block.json "style"). Values come straight from
 * the design; tokens come from theme.json.
 *
 * The flyout positions against .tma-site-header -- the sticky template-part
 * wrapper is the nearest positioned ancestor and it spans the full viewport,
 * so `position:absolute; top:100%; left:0; right:0` gives an edge-to-edge
 * panel without any transform or width hackery.
 */

.tma-meganav {
	--tma-nav-rail: var( --wp--custom--nav--rail-width, 306px );
	--tma-nav-h: var( --wp--custom--nav--header-height, 58px );

	display: flex;
	align-items: center;
	font-family: var( --wp--preset--font-family--open-sans );
}

/* ---------- Top level ---------------------------------------------------- */

.tma-meganav__top {
	display: flex;
	align-items: center;
	gap: 4px;
	list-style: none;
	margin: 0;
	padding: 0;
}

.tma-meganav__top-item {
	margin: 0;
}

.tma-meganav__trigger {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	appearance: none;
	border: 0;
	background: transparent;
	cursor: pointer;
	font-family: inherit;
	font-size: var( --wp--preset--font-size--small );
	font-weight: 600;
	line-height: 1.2;
	color: var( --wp--preset--color--neutral-300 );
	padding: 10px 14px;
	border-radius: 8px;
	white-space: nowrap;
}

.tma-meganav__trigger:hover {
	color: var( --wp--preset--color--neutral-000 );
}

/* The open trigger becomes the tab connected to the white flyout. */
.tma-meganav__trigger[ aria-expanded="true" ] {
	color: var( --wp--preset--color--neutral-900 );
	background: var( --wp--preset--color--neutral-000 );
}

.tma-meganav__chevron {
	display: none;
}

/* ---------- Burger (mobile only) ---------------------------------------- */

.tma-meganav__burger {
	display: none;
	align-items: center;
	gap: 10px;
	appearance: none;
	border: 1px solid var( --wp--preset--color--neutral-800 );
	background: transparent;
	border-radius: 8px;
	color: var( --wp--preset--color--neutral-000 );
	font-family: inherit;
	font-size: var( --wp--preset--font-size--small );
	font-weight: 600;
	padding: 9px 14px;
	min-height: 44px;
	cursor: pointer;
}

.tma-meganav__bars {
	position: relative;
	width: 16px;
	height: 2px;
	background: currentColor;
	border-radius: 2px;
}

.tma-meganav__bars::before,
.tma-meganav__bars::after {
	content: "";
	position: absolute;
	left: 0;
	width: 16px;
	height: 2px;
	background: currentColor;
	border-radius: 2px;
}

.tma-meganav__bars::before { top: -5px; }
.tma-meganav__bars::after { top: 5px; }

.tma-meganav__burger[ aria-expanded="true" ] .tma-meganav__bars {
	background: transparent;
}

.tma-meganav__burger[ aria-expanded="true" ] .tma-meganav__bars::before {
	top: 0;
	transform: rotate( 45deg );
}

.tma-meganav__burger[ aria-expanded="true" ] .tma-meganav__bars::after {
	top: 0;
	transform: rotate( -45deg );
}

/* ---------- Flyout panel ------------------------------------------------ */

.tma-meganav__panel {
	position: absolute;
	top: 100%;
	left: 0;
	right: 0;
	background: var( --wp--preset--color--neutral-000 );
	border-bottom: 1px solid var( --wp--preset--color--neutral-200 );
	box-shadow: var( --wp--preset--shadow--flyout );
	z-index: 1;
}

.tma-meganav__panel[ hidden ] {
	display: none;
}

.tma-meganav__shell {
	max-width: 1240px;
	margin: 0 auto;
	display: grid;
	grid-template-columns: var( --tma-nav-rail ) minmax( 0, 1fr );
}

/* ---------- Rail -------------------------------------------------------- */

.tma-meganav__rail {
	background: var( --wp--preset--color--neutral-050 );
	border-right: 1px solid var( --wp--preset--color--neutral-200 );
	padding: 22px 0 26px;
	display: flex;
	flex-direction: column;
}

.tma-meganav__rail-label {
	font-size: var( --wp--preset--font-size--eyebrow );
	font-weight: 700;
	letter-spacing: 0.12em;
	text-transform: uppercase;
	color: var( --wp--preset--color--neutral-700 );
	padding: 0 26px 14px;
	margin: 0;
}

.tma-meganav__rail-list {
	list-style: none;
	margin: 0;
	padding: 0;
}

.tma-meganav__rail-line {
	display: block;
	width: 100%;
	text-align: left;
	appearance: none;
	background: transparent;
	border: 0;
	border-left: 3px solid transparent;
	padding: 13px 26px;
	cursor: pointer;
	font-family: inherit;
}

.tma-meganav__rail-line.is-selected {
	border-left-color: var( --tma-line, var( --wp--preset--color--blue-500 ) );
	background: var( --wp--preset--color--neutral-000 );
}

/* Gate hover on a real pointer: on touch, :hover latches after a tap and the
   line stays highlighted long after the finger has gone. */
@media ( hover: hover ) {
	.tma-meganav__rail-line:hover .tma-meganav__rail-title {
		color: var( --wp--preset--color--blue-700 );
	}
}

.tma-meganav__rail-title {
	display: block;
	font-family: var( --wp--preset--font-family--poppins );
	font-weight: 600;
	font-size: var( --wp--preset--font-size--medium );
	color: var( --wp--preset--color--neutral-900 );
	line-height: 1.3;
}

.tma-meganav__rail-count {
	display: block;
	font-size: 0.75rem;
	color: var( --wp--preset--color--neutral-600 );
	margin-top: 3px;
	line-height: 1.4;
}

.tma-meganav__rail-footer {
	border-top: 1px solid var( --wp--preset--color--neutral-200 );
	margin: 20px 0 0;
	padding: 20px 26px 0;
	font-size: var( --wp--preset--font-size--caption );
	font-weight: 700;
}

.tma-meganav__rail-footer a {
	text-decoration: none;
}

.tma-meganav__rail-footer a:hover {
	text-decoration: underline;
}

/* ---------- Panes ------------------------------------------------------- */

.tma-meganav__panes {
	padding: 34px 40px 38px;
}

.tma-meganav__pane[ hidden ] {
	display: none;
}

.tma-meganav__pane-head {
	display: flex;
	align-items: center;
	gap: 11px;
	font-family: var( --wp--preset--font-family--poppins );
	font-weight: 600;
	font-size: 1.375rem;
	line-height: 1.2;
	color: var( --wp--preset--color--neutral-900 );
	margin: 0 0 8px;
}

.tma-meganav__dot {
	flex: 0 0 auto;
	width: 10px;
	height: 10px;
	border-radius: var( --wp--custom--radius--pill );
}

.tma-meganav__pane-note {
	font-size: var( --wp--preset--font-size--medium );
	line-height: 1.6;
	color: var( --wp--preset--color--neutral-700 );
	margin: 0 0 26px;
	max-width: 62ch;
}

.tma-meganav__cards {
	display: grid;
	grid-template-columns: repeat( auto-fit, minmax( 268px, 1fr ) );
	gap: 10px;
	list-style: none;
	margin: 0;
	padding: 0;
}

/* Equal-height cards via flex, not height:100%. A percentage height on a grid
   item's child does not contribute to intrinsic row sizing, so with four cards
   in a three-column grid the second row was laid out against a too-short first
   row and overlapped it. */
.tma-meganav__cards > li {
	display: flex;
	margin: 0;
}

.tma-meganav__card {
	display: block;
	flex: 1 1 auto;
	border: 1px solid var( --wp--preset--color--neutral-200 );
	border-radius: var( --wp--custom--radius--nav-card );
	padding: 16px 18px;
	text-decoration: none;
}

.tma-meganav__card:hover,
.tma-meganav__card:focus-visible {
	border-color: var( --wp--preset--color--neutral-400 );
	background: var( --wp--preset--color--neutral-050 );
	text-decoration: none;
}

.tma-meganav__card-name {
	display: block;
	font-size: var( --wp--preset--font-size--medium );
	font-weight: 700;
	color: var( --wp--preset--color--neutral-900 );
	line-height: 1.3;
	margin-bottom: 4px;
}

.tma-meganav__card-desc {
	display: block;
	font-size: var( --wp--preset--font-size--caption );
	line-height: 1.5;
	color: var( --wp--preset--color--neutral-600 );
}

.tma-meganav__pane-foot {
	margin: 26px 0 0;
	border-top: 1px solid var( --wp--preset--color--neutral-100 );
	padding-top: 20px;
	display: flex;
	gap: 24px;
	align-items: center;
	flex-wrap: wrap;
	font-size: var( --wp--preset--font-size--small );
}

.tma-meganav__pane-cta {
	font-weight: 700;
	color: var( --wp--preset--color--blue-700 );
	text-decoration: none;
}

.tma-meganav__pane-demo {
	font-weight: 600;
	color: var( --wp--preset--color--neutral-700 );
	text-decoration: none;
}

.tma-meganav__pane-cta:hover,
.tma-meganav__pane-demo:hover {
	text-decoration: underline;
}

/* ==========================================================================
   Mobile -- full-screen accordion.
   The 306px + 1fr shell cannot work narrow, so top-level menus become rows;
   opening one reveals its rail categories; opening a category reveals its
   cards. Same markup, same ARIA -- only the layout changes.
   ========================================================================== */

@media ( max-width: 1079px ) {

	/* Specificity: core emits .is-layout-flex > :is(*, div){margin:0} at (0,1,1),
	   so a bare .tma-meganav auto margin loses. The header stylesheet owns this
	   with .tma-header-row > .tma-meganav; nothing needed here. */

	.tma-meganav__burger {
		display: inline-flex;
	}

	.tma-meganav__drawer {
		position: absolute;
		top: 100%;
		left: 0;
		right: 0;
		max-height: calc( 100dvh - var( --tma-nav-h ) );
		overflow-y: auto;
		overscroll-behavior: contain;
		background: var( --wp--preset--color--neutral-950 );
		border-top: 1px solid var( --wp--preset--color--neutral-800 );
		padding: 8px 0 40px;
		box-shadow: var( --wp--preset--shadow--flyout );
	}

	.tma-meganav__drawer[ hidden ] {
		display: none;
	}

	.tma-meganav__top {
		display: block;
		gap: 0;
	}

	.tma-meganav__top-item + .tma-meganav__top-item {
		border-top: 1px solid var( --wp--preset--color--neutral-800 );
	}

	.tma-meganav__trigger {
		display: flex;
		justify-content: space-between;
		width: 100%;
		border-radius: 0;
		padding: 17px var( --wp--custom--gutter );
		font-size: var( --wp--preset--font-size--large );
		color: var( --wp--preset--color--neutral-000 );
		min-height: 44px;
	}

	.tma-meganav__trigger[ aria-expanded="true" ] {
		background: transparent;
		color: var( --wp--preset--color--lime-500 );
	}

	.tma-meganav__chevron {
		display: block;
		flex: 0 0 auto;
		width: 9px;
		height: 9px;
		border-right: 2px solid currentColor;
		border-bottom: 2px solid currentColor;
		transform: rotate( 45deg ) translateY( -25% );
	}

	.tma-meganav__trigger[ aria-expanded="true" ] .tma-meganav__chevron {
		transform: rotate( -135deg ) translateY( -25% );
	}

	/* The flyout stops being a flyout. */
	.tma-meganav__panel {
		position: static;
		background: transparent;
		border: 0;
		box-shadow: none;
	}

	.tma-meganav__shell {
		display: block;
		max-width: none;
	}

	.tma-meganav__rail {
		background: transparent;
		border-right: 0;
		padding: 0 0 10px;
		display: block;
	}

	.tma-meganav__rail-label {
		padding: 4px var( --wp--custom--gutter ) 10px;
		color: var( --wp--preset--color--neutral-500 );
	}

	.tma-meganav__rail-line {
		padding: 13px var( --wp--custom--gutter );
		border-left-width: 3px;
		min-height: 44px;
	}

	.tma-meganav__rail-line.is-selected {
		background: transparent;
	}

	.tma-meganav__rail-title {
		color: var( --wp--preset--color--neutral-000 );
	}

	/* Expanded, not hovered -- see the note above. */
	.tma-meganav__rail-line[ aria-expanded="true" ] .tma-meganav__rail-title {
		color: var( --wp--preset--color--lime-500 );
	}

	.tma-meganav__rail-count {
		color: var( --wp--preset--color--neutral-500 );
	}

	.tma-meganav__rail-footer {
		border-color: var( --wp--preset--color--neutral-800 );
		padding: 16px var( --wp--custom--gutter ) 0;
		margin-top: 14px;
	}

	/* On mobile each pane is rendered inline, immediately after its own rail
	   line -- view.js moves the pane node into the rail list item so the
	   accordion reads in the right order for screen readers and for the eye. */
	.tma-meganav__panes {
		padding: 0;
	}

	.tma-meganav__pane {
		padding: 4px var( --wp--custom--gutter ) 20px;
	}

	.tma-meganav__pane-head {
		display: none;
	}

	.tma-meganav__pane-note {
		display: none;
	}

	.tma-meganav__cards {
		grid-template-columns: 1fr;
		gap: 8px;
	}

	.tma-meganav__card {
		border-color: var( --wp--preset--color--neutral-800 );
		background: var( --wp--preset--color--neutral-900 );
	}

	.tma-meganav__card:hover,
	.tma-meganav__card:focus-visible {
		border-color: var( --wp--preset--color--neutral-700 );
		background: var( --wp--preset--color--neutral-900 );
	}

	.tma-meganav__card-name {
		color: var( --wp--preset--color--neutral-000 );
	}

	.tma-meganav__card-desc {
		color: var( --wp--preset--color--neutral-300 );
	}

	.tma-meganav__pane-foot {
		border-color: var( --wp--preset--color--neutral-800 );
		margin-top: 16px;
	}

	.tma-meganav__pane-cta {
		color: var( --wp--preset--color--lime-500 );
	}

	.tma-meganav__pane-demo {
		color: var( --wp--preset--color--neutral-300 );
	}
}

/* Scroll lock while the mobile drawer is open. */
html.tma-nav-open,
html.tma-nav-open body {
	overflow: hidden;
}

/* ==========================================================================
   No-JS fallback
   A disclosure menu with no script is a row of dead buttons, so without
   JavaScript the whole nav renders as a plain expanded list: every panel and
   pane in flow, no burger, no flyout. Ugly on purpose, and every destination
   stays reachable. (Crawlers see the links either way -- hidden content is
   still in the DOM and still followed.)

   The rules themselves live in a <noscript> block in render.php, NOT here.
   They used to key off `:not([data-js])`, with view.js adding data-js on
   boot -- which meant the expanded state was the default and every fresh load
   flashed the entire mega menu across the screen until the footer script ran.
   Inverting it costs nothing: the markup already ships collapsed, so the
   default state is now the correct one and only genuinely script-less
   browsers ever see the fallback.
   ========================================================================== */

/* The drawer only needs hiding below the breakpoint, so above it `hidden` is
   ignored and the top-level menu paints correctly on first paint, without
   waiting for view.js to remove the attribute. Scoped to a min-width query
   rather than left unscoped: the mobile rule that hides it lives earlier in
   this file, and at equal specificity a later unscoped rule would win. */
@media ( min-width: 1080px ) {
	.tma-meganav__drawer[ hidden ] {
		display: block;
	}
}

@media ( prefers-reduced-motion: reduce ) {
	.tma-meganav *,
	.tma-meganav *::before,
	.tma-meganav *::after {
		transition-duration: 0.01ms !important;
	}
}

/* ==========================================================================
   Editor preview
   ServerSideRender drops the markup into a plain container with no sticky
   header to position against, so pin the panel in flow and show it open.
   ========================================================================== */

.editor-styles-wrapper .tma-meganav,
.block-editor-block-preview__content .tma-meganav {
	background: var( --wp--preset--color--neutral-950 );
	padding: 10px;
	border-radius: 8px;
	flex-wrap: wrap;
}

.editor-styles-wrapper .tma-meganav__panel,
.block-editor-block-preview__content .tma-meganav__panel {
	position: static;
	margin-top: 10px;
	border-radius: 8px;
}
