/*
 * Header mega menu.
 *
 * Two presentations of one DOM. On a pointer screen the categories are a tab
 * strip in the bar and the panels drop below it full width; below 900px the
 * same markup becomes a drawer whose panels slide in as a second level with a
 * back button. Sharing the markup keeps one source of truth for the links and
 * means the product pictures are never downloaded twice.
 *
 * The panel strip is measured and animated in JavaScript (height), so nothing
 * here sets a fixed panel height.
 */

.mega,
.mega *,
.mega *::before,
.mega *::after,
.mega__overlay {
	box-sizing: border-box;
}

.mega {
	flex-grow: 1;
	min-width: 0;
}

/*
 * WordPress's core/shortcode block runs its raw content through wpautop()
 * before expanding the shortcode (render_block_core_shortcode() literally
 * returns wpautop( $content )), and since the saved block content is just
 * the bare tag `[ecoflow_mega_menu]` with no block-level markup around it,
 * wpautop wraps it as `<p>[ecoflow_mega_menu]</p>` first. Once do_shortcode()
 * then expands that tag into this nav's markup, the browser's own HTML
 * parser auto-closes the `<p>` the moment it hits the block-level `<nav>`
 * inside it - which leaves a stray empty `<p></p>` as this nav's first
 * child. Its default 1em top/bottom margin was tall enough to inflate the
 * nav's own box past the header's fixed height, which is what pushed the
 * whole tab strip down past the bar's bottom edge. Zeroing the margin (it
 * has no content and no visual role) removes the extra height entirely.
 */
.mega > p {
	margin: 0;
}

/* --- Tab strip ---------------------------------------------------------- */

.mega__tabs {
	display: flex;
	justify-content: center;
	align-items: center;
	gap: 0;
	margin: 0;
	padding: 0;
	list-style: none;
}

.mega__tab {
	appearance: none;
	background: none;
	border: 0;
	margin: 0;
	padding: 0 12px;
	height: var(--ef-header-h);
	display: inline-flex;
	align-items: center;
	gap: 4px;
	cursor: pointer;
	font-family: inherit;
	font-size: var(--wp--preset--font-size--sm);
	font-weight: 500;
	line-height: 1;
	white-space: nowrap;
	color: var(--ef-header-fg);
	transition: opacity var(--wp--custom--duration--fast) var(--wp--custom--ease--out);
}

.mega__tab:hover,
.mega__tab[aria-expanded="true"] {
	opacity: 0.65;
}

/*
 * Flat tab = plain <a>, no dropdown chevron, no panel. Kept on the same
 * `.mega__tab` base class so it lines up pixel-for-pixel with the button
 * tabs when both forms coexist in the strip; `text-decoration:none` is
 * added here because the base rule assumes a <button>.
 */
.mega__tab--flat {
	text-decoration: none;
	color: var(--ef-header-fg);
}

.mega__tab--flat:hover {
	color: var(--ef-header-fg);
	opacity: 0.65;
}

.mega__tab-chevron {
	width: 8px;
	height: 8px;
	border-right: 1.5px solid currentColor;
	border-bottom: 1.5px solid currentColor;
	transform: translateY(-2px) rotate(45deg);
	transition: transform var(--wp--custom--duration--fast) var(--wp--custom--ease--out);
}

.mega__tab[aria-expanded="true"] .mega__tab-chevron {
	transform: translateY(1px) rotate(-135deg);
}

/* --- Panel strip --------------------------------------------------------- */

/*
 * Anchored to the header, not to the tab, so the panel spans the window the way
 * the reference does. height is written by the script - 0 when closed, the
 * active panel's own height when open - which is what lets one category grow
 * or shrink into the next without the strip jumping.
 */
.mega__panels {
	position: absolute;
	top: 100%;
	left: 0;
	right: 0;
	height: 0;
	overflow: hidden;
	/*
	 * The dimming layer is a sibling inside the header, so the panel has to
	 * out-rank it locally or the panel gets dimmed along with the page.
	 */
	z-index: 2;
	background: var(--wp--preset--color--base);
	color: var(--wp--preset--color--contrast);
	border-top: 1px solid var(--wp--preset--color--border);
	box-shadow: var(--wp--custom--shadow--lg);
	opacity: 0;
	visibility: hidden;
	transition:
		height 260ms var(--wp--custom--ease--out),
		opacity 200ms var(--wp--custom--ease--out),
		visibility 0s linear 260ms;
}

.mega.is-open .mega__panels {
	opacity: 1;
	visibility: visible;
	transition:
		height 260ms var(--wp--custom--ease--out),
		opacity 200ms var(--wp--custom--ease--out),
		visibility 0s linear 0s;
}

.mega__panel {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
}

.mega__inner {
	max-width: 1440px;
	margin-inline: auto;
	padding: 40px var(--wp--preset--spacing--5) 48px;
}

/* The small lift the brief asks for, on the content rather than the panel. */
@keyframes ef-mega-in {
	from {
		opacity: 0;
		transform: translateY(-8px);
	}
}

.mega__panel:not([hidden]) .mega__inner {
	animation: ef-mega-in 240ms var(--wp--custom--ease--out) backwards;
}

.mega__panel-title {
	margin: 0 0 28px;
	font-size: var(--wp--preset--font-size--xl-2);
	font-weight: 700;
	letter-spacing: -0.02em;
	color: var(--wp--preset--color--contrast);
}

.mega__cols {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
	gap: var(--wp--preset--spacing--6);
	align-items: start;
}

.mega__col-title {
	margin: 0 0 16px;
	font-size: var(--wp--preset--font-size--xs);
	font-weight: 700;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--wp--preset--color--contrast-muted, rgba(17, 17, 17, 0.55));
}

/* --- Cards ---------------------------------------------------------------- */

.mega__cards {
	display: grid;
	gap: var(--wp--preset--spacing--3);
	margin: 0;
	padding: 0;
	list-style: none;
}

.mega-card {
	display: flex;
	gap: 12px;
	align-items: center;
	padding: 8px;
	margin: -8px;
	border-radius: var(--wp--custom--radius--md);
	text-decoration: none;
	color: inherit;
	transition:
		transform var(--wp--custom--duration--fast) var(--wp--custom--ease--out),
		background-color var(--wp--custom--duration--fast) var(--wp--custom--ease--out);
}

.mega-card:hover {
	transform: translateY(-2px);
	background: var(--wp--preset--color--base-subtle);
	color: inherit;
}

.mega-card__body {
	display: flex;
	flex-direction: column;
	gap: 2px;
	min-width: 0;
}

.mega-card__media {
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 52px;
	height: 52px;
	border-radius: var(--wp--custom--radius--sm);
	background: var(--wp--preset--color--base-subtle);
	overflow: hidden;
}

.mega-card__img {
	width: 100%;
	height: 100%;
	object-fit: contain;
	transition: transform var(--wp--custom--duration--base) var(--wp--custom--ease--out);
}

.mega-card:hover .mega-card__img {
	transform: scale(1.03);
}

.mega-card__name {
	font-size: var(--wp--preset--font-size--sm);
	font-weight: 600;
	line-height: 1.25;
	color: var(--wp--preset--color--contrast);
}

.mega-card__desc {
	font-size: var(--wp--preset--font-size--xs);
	line-height: 1.4;
	color: var(--wp--preset--color--contrast-muted, rgba(17, 17, 17, 0.6));
	/* Two lines is enough to describe; more turns the panel into a wall. */
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.mega-card__cta {
	font-size: var(--wp--preset--font-size--xs);
	font-weight: 600;
	color: var(--wp--preset--color--contrast);
	opacity: 0;
	transition: opacity var(--wp--custom--duration--fast) var(--wp--custom--ease--out);
}

.mega-card:hover .mega-card__cta,
.mega-card:focus-visible .mega-card__cta {
	opacity: 1;
}

/* --- Lifestyle tiles ------------------------------------------------------- */

/*
 * The scenario column leads with the photograph rather than a thumbnail, so it
 * gets a wider share of the panel and its cards stack picture over label.
 */
.mega__col--tiles {
	grid-column: span 2;
}

.mega__col--tiles .mega__cards {
	grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
	gap: var(--wp--preset--spacing--4);
}

.mega__col--tiles .mega-card {
	flex-direction: column;
	align-items: stretch;
	gap: 10px;
}

.mega__col--tiles .mega-card__media {
	width: 100%;
	height: auto;
	aspect-ratio: 16 / 10;
	border-radius: var(--wp--custom--radius--md);
}

.mega__col--tiles .mega-card__img {
	object-fit: cover;
}

.mega__col--tiles .mega-card__name {
	font-size: var(--wp--preset--font-size--base);
}

@media (max-width: 899px) {
	.mega__col--tiles {
		grid-column: auto;
	}

	.mega__col--tiles .mega__cards {
		grid-template-columns: 1fr;
	}
}

/* --- Link lists ------------------------------------------------------------ */

.mega__links {
	display: grid;
	gap: 2px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.mega__link {
	display: block;
	padding: 8px 10px;
	margin-inline: -10px;
	border-radius: var(--wp--custom--radius--sm);
	font-size: var(--wp--preset--font-size--sm);
	line-height: 1.35;
	text-decoration: none;
	color: var(--wp--preset--color--contrast);
	transition: background-color var(--wp--custom--duration--fast) var(--wp--custom--ease--out);
}

.mega__link:hover {
	background: var(--wp--preset--color--base-subtle);
	color: var(--wp--preset--color--contrast);
}

/* --- Page dimming ---------------------------------------------------------- */

/*
 * Light enough to separate the panel from the page without darkening the hero
 * into mud. It sits below the header and above everything else.
 */
.mega__overlay {
	position: fixed;
	inset: var(--ef-header-h) 0 0;
	z-index: 1;
	background: rgba(0, 0, 0, 0.15);
	opacity: 0;
	transition: opacity 200ms var(--wp--custom--ease--out);
}

.mega__overlay.is-visible {
	opacity: 1;
}

/* --- Drawer chrome, hidden on desktop -------------------------------------- */

.mega__toggle,
.mega__back {
	display: none;
}

/* --- Mobile ---------------------------------------------------------------- */

@media (max-width: 899px) {
	.mega {
		flex-grow: 0;
		order: 1;
	}

	.mega__toggle {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 44px;
		height: 44px;
		padding: 0;
		appearance: none;
		background: none;
		border: 0;
		cursor: pointer;
		color: var(--ef-header-fg);
	}

	/* Three bars that fold into a cross when the drawer is open. */
	.mega__toggle-bars,
	.mega__toggle-bars::before,
	.mega__toggle-bars::after {
		content: "";
		display: block;
		width: 20px;
		height: 1.5px;
		background: currentColor;
		transition: transform 200ms var(--wp--custom--ease--out), opacity 120ms linear;
	}

	.mega__toggle-bars {
		position: relative;
	}

	.mega__toggle-bars::before {
		position: absolute;
		top: -6px;
	}

	.mega__toggle-bars::after {
		position: absolute;
		top: 6px;
	}

	.mega__toggle[aria-expanded="true"] .mega__toggle-bars {
		background: transparent;
	}

	.mega__toggle[aria-expanded="true"] .mega__toggle-bars::before {
		transform: translateY(6px) rotate(45deg);
	}

	.mega__toggle[aria-expanded="true"] .mega__toggle-bars::after {
		transform: translateY(-6px) rotate(-45deg);
	}

	/*
	 * The drawer is the whole screen below the bar. Two levels live inside it
	 * side by side; opening a category slides the strip across rather than
	 * reflowing anything, so the transition cannot jump.
	 */
	.mega__drawer {
		position: fixed;
		top: var(--ef-header-h);
		left: 0;
		right: 0;
		bottom: 0;
		z-index: 95;
		background: var(--wp--preset--color--base-darker);
		color: var(--wp--preset--color--base);
		overflow: hidden;
		transform: translateX(-100%);
		visibility: hidden;
		transition: transform 260ms var(--wp--custom--ease--out), visibility 0s linear 260ms;
	}

	.mega.is-drawer-open .mega__drawer {
		transform: translateX(0);
		visibility: visible;
		transition: transform 260ms var(--wp--custom--ease--out), visibility 0s linear 0s;
	}

	.mega__tabs {
		flex-direction: column;
		align-items: stretch;
		/* The base rule centres the row; in a column that would float the list. */
		justify-content: flex-start;
		height: 100%;
		overflow-y: auto;
		padding: var(--wp--preset--spacing--4) var(--wp--preset--spacing--5);
		transition: transform 260ms var(--wp--custom--ease--out);
	}

	.mega.is-level-2 .mega__tabs {
		transform: translateX(-30%);
	}

	.mega__tab {
		width: 100%;
		height: auto;
		justify-content: space-between;
		padding: 18px 0;
		font-size: var(--wp--preset--font-size--xl-2);
		font-weight: 600;
		letter-spacing: -0.02em;
		border-bottom: 1px solid var(--wp--custom--border--on-dark);
		color: var(--wp--preset--color--base);
		opacity: 1;
	}

	.mega__tab:hover,
	.mega__tab[aria-expanded="true"] {
		opacity: 1;
	}

	/* Points right on the drawer list: it opens a level, it does not drop down. */
	.mega__tab-chevron {
		transform: rotate(-45deg);
		width: 9px;
		height: 9px;
	}

	.mega__tab[aria-expanded="true"] .mega__tab-chevron {
		transform: rotate(-45deg);
	}

	/* Level two: a full-height sheet over the category list. */
	.mega__panels {
		position: absolute;
		inset: 0;
		height: auto;
		overflow-y: auto;
		background: var(--wp--preset--color--base-darker);
		color: var(--wp--preset--color--base);
		border: 0;
		box-shadow: none;
		opacity: 1;
		visibility: hidden;
		transform: translateX(100%);
		transition: transform 260ms var(--wp--custom--ease--out), visibility 0s linear 260ms;
	}

	.mega.is-level-2 .mega__panels {
		visibility: visible;
		transform: translateX(0);
		transition: transform 260ms var(--wp--custom--ease--out), visibility 0s linear 0s;
	}

	/* Desktop uses is-open for the drop-down; on mobile the level does the work. */
	.mega.is-open .mega__panels {
		opacity: 1;
	}

	.mega__panel {
		position: static;
	}

	.mega__inner {
		padding: var(--wp--preset--spacing--4) var(--wp--preset--spacing--5) var(--wp--preset--spacing--10);
	}

	.mega__back {
		display: inline-flex;
		align-items: center;
		min-height: 44px;
		margin: 0 0 8px -8px;
		padding: 0 8px;
		appearance: none;
		background: none;
		border: 0;
		cursor: pointer;
		font-family: inherit;
		font-size: var(--wp--preset--font-size--sm);
		font-weight: 600;
		color: rgba(255, 255, 255, 0.75);
	}

	.mega__panel-title,
	.mega__col-title,
	.mega-card__name,
	.mega__link {
		color: var(--wp--preset--color--base);
	}

	.mega__col-title {
		color: rgba(255, 255, 255, 0.55);
	}

	.mega-card__desc {
		color: rgba(255, 255, 255, 0.6);
	}

	.mega__cols {
		grid-template-columns: 1fr;
		gap: var(--wp--preset--spacing--6);
	}

	.mega-card:hover,
	.mega__link:hover {
		background: rgba(255, 255, 255, 0.08);
		color: var(--wp--preset--color--base);
	}

	.mega-card__media {
		background: rgba(255, 255, 255, 0.08);
	}

	/* The card link is a touch target, so it gets a comfortable one. */
	.mega-card,
	.mega__link {
		min-height: 44px;
	}

	.mega-card__cta {
		display: none;
	}

	/* The dimming belongs to the desktop drop-down only. */
	.mega__overlay {
		display: none;
	}
}
