/**
 * Header, mega menu and menu drawer — 2026 skin.
 *
 * Markup: parts/header.html (bar) and parts/navigation.html (drawer, opened
 * by The Framework Core's menu button). Mega panels are navigation submenus
 * with the class `pw-mega`; inc/theme-setup.php adds their intro and quote
 * card. Loaded after theme.css, whose older header rules this file overrides.
 *
 *   ≥1024px  logo · menu with mega panels · Log in · country · Get a quote
 *   <1024px  logo · account icon · Get a quote · menu button (the rest is in
 *            the drawer, where the menu groups open as an accordion)
 */

/* Shorter bar: 72px (64px once scrolled), 64px / 56px below 1024px. The
   tokens also set the drawer top and the sticky offsets in theme.css. */
:root:root {
	--wp--custom--header--height: 72px;
	--wp--custom--header--height-compact: 64px;

	@media (max-width: 1023px) {
		--wp--custom--header--height: 64px;
		--wp--custom--header--height-compact: 56px;
	}
}

.pw-site-header,
.is-scrolled .pw-site-header {
	padding-block: 0 !important;
}

.pw-site-header__inner {
	position: relative;
}

/* One type style for every item in the bar: menu, account, country. */
.pw-site-header :is(
	.pw-header-nav .wp-block-navigation-item__content,
	.pw-account-link__link,
	.pw-site-switcher__button
) {
	color: var(--wp--preset--color--text-primary);
	font-family: inherit;
	font-size: var(--wp--preset--font-size--body);
	font-weight: 600;
	line-height: 1.5;
	letter-spacing: 0;
}

/* Account link and country button: the same hover box as the menu items. */
.pw-site-header :is(.pw-account-link__link, .pw-site-switcher__button):not(.pw-drawer *) {
	box-sizing: border-box;
	min-height: 40px;
	padding: 8px 12px;
	border-radius: var(--wp--custom--radius--sm);
	transition: background-color 0.15s;

	&:hover,
	&:focus-visible,
	&[aria-expanded="true"] {
		background-color: var(--wp--preset--color--surface-natural);
		opacity: 1;
	}
}

@media (min-width: 1024px) {
	/* Items carry their own padding now, so the gaps between them shrink. */
	.pw-site-header .pw-site-header__actions {
		gap: 8px;
	}

	.pw-site-header .pw-header-cta {
		margin-inline-start: 8px;
	}

	/* theme.css hides the "Log in" label below 1280px; it fits now. */
	.pw-site-header .pw-account-link__label:not(.pw-drawer *) {
		position: static;
		width: auto;
		height: auto;
		margin: 0;
		overflow: visible;
		clip: auto;
	}
}

/* Core prints a submenu's description inside its top-level link too; it
   belongs in the panel intro only. */
.pw-site-header .wp-block-navigation__container > .wp-block-navigation-item > :is(a, button) > .wp-block-navigation-item__description {
	display: none;
}

/* -------------------------------------------------------------------------
 * Menu bar (≥1024px)
 * ---------------------------------------------------------------------- */
.pw-site-header .pw-header-nav {
	gap: 4px;

	/* Items as tall as the account link's hover box (40px), not stretched
	   to the bar. */
	& > .wp-block-navigation__container {
		align-items: center;
		gap: 4px;
	}

	& > .wp-block-navigation__container > .wp-block-navigation-item {
		align-self: center;
	}

	/* 12px either side, as the account link and the country button. */
	& > .wp-block-navigation__container > .wp-block-navigation-item > .wp-block-navigation-item__content {
		box-sizing: border-box;
		min-height: 40px;
		padding: 8px 4px 8px 12px;
		border-radius: var(--wp--custom--radius--sm);
		transition: background-color 0.15s;
	}

	& > .wp-block-navigation__container > .wp-block-navigation-item:not(.has-child) > .wp-block-navigation-item__content {
		padding-inline-end: 12px;
	}

	/* The chevron toggle sits inside the pill. */
	/* Hover: a rounded rectangle behind the label and its chevron. */
	& > .wp-block-navigation__container > .has-child {
		border-radius: var(--wp--custom--radius--sm);
		transition: background-color 0.15s;

		& > .wp-block-navigation-submenu__toggle {
			margin-inline-start: -4px;
			padding-inline-end: 12px;
		}

		&:is(:hover, :focus-within) {
			background-color: var(--wp--preset--color--surface-natural);
		}
	}

	& .wp-block-navigation-item__content:hover {
		opacity: 1;
	}

	& .wp-block-navigation-item__content {
		text-decoration: none;
	}
}

/* Chevrons: 16px, in the bar and the drawer. */
.pw-site-header .wp-block-navigation__submenu-icon {
	display: grid;
	place-items: center;
	width: 20px;
	height: 20px;

	&::after {
		width: 16px !important;
		height: 16px !important;
	}
}

/* -------------------------------------------------------------------------
 * Mega panel (≥1024px): full width of the header row, below the bar
 * ---------------------------------------------------------------------- */
@media (min-width: 1024px) {
	.pw-site-header .pw-header-nav,
	.pw-site-header .pw-header-nav .wp-block-navigation__container,
	.pw-site-header .pw-header-nav .pw-mega {
		position: static;
	}

	.pw-site-header .pw-header-nav .pw-mega > .wp-block-navigation__submenu-container {
		--pw-mega-gap: var(--wp--preset--spacing--lg);

		position: absolute !important;
		top: calc(100% + 10px) !important;
		right: 0 !important;
		left: 0 !important;
		z-index: 60;
		box-sizing: border-box;
		width: auto !important;
		min-width: 0 !important;
		padding: var(--pw-mega-gap) !important;
		border: 1px solid light-dark(rgb(12 31 107 / 0.08), rgb(233 228 222 / 0.22)) !important;
		border-radius: var(--wp--custom--radius--xl);
		background-color: var(--wp--preset--color--surface-raised);
		color: var(--wp--preset--color--text-primary);
		box-shadow: light-dark(0 24px 60px rgb(12 31 107 / 0.16), 0 24px 60px rgb(0 0 0 / 0.4));

		/* Hover bridge across the gap between the bar and the panel. */
		&::before {
			inset: -2.5rem 0 auto;
			height: 2.5rem;
		}
	}

	/* Shown (core's hover / focus / open states): lay it out as a grid. */
	.pw-site-header .pw-header-nav .pw-mega:is(:hover, :focus-within) > .wp-block-navigation__submenu-container,
	.pw-site-header .pw-header-nav .pw-mega > .wp-block-navigation-submenu__toggle[aria-expanded="true"] ~ .wp-block-navigation__submenu-container {
		display: grid;
		grid-template-columns: minmax(12rem, 16rem) repeat(2, minmax(0, 1fr)) minmax(14rem, 18rem);
		grid-template-rows: repeat(var(--pw-mega-rows, 2), auto);
		grid-auto-flow: column;
		align-content: start;
		gap: 4px var(--pw-mega-gap);
	}

	/* Core resets the padding of list items in a submenu. */
	.pw-site-header .pw-header-nav .pw-mega .pw-mega__intro {
		grid-column: 1;
		grid-row: 1 / span var(--pw-mega-rows, 2);
		align-self: start;
		padding: 12px 0 !important;
	}

	.pw-site-header .pw-header-nav .pw-mega .pw-mega__card {
		grid-column: 4;
		grid-row: 1 / span var(--pw-mega-rows, 2);
		padding: var(--wp--preset--spacing--lg) !important;
	}

	.pw-site-header .pw-header-nav .pw-mega .wp-block-navigation-item {
		align-self: stretch;
		align-items: stretch;
	}

	.pw-site-header .pw-header-nav .pw-mega .wp-block-navigation__submenu-container .wp-block-navigation-item__content {
		display: flex;
		flex-direction: column;
		align-items: flex-start;
		gap: 2px;
		box-sizing: border-box;
		width: 100%;
		height: 100%;
		padding: 12px 14px !important;
		text-align: start;
		border-radius: var(--wp--custom--radius--md);
		white-space: normal;
		transition: background-color 0.15s;

		&:hover,
		&:focus-visible {
			background-color: var(--wp--preset--color--surface);
		}
	}
}

/* Panel parts (also used in the drawer). */
.pw-mega__title {
	margin: 0 0 6px;
	color: var(--wp--preset--color--text-primary);
	font-size: var(--wp--preset--font-size--headline-5);
	font-weight: 800;
	line-height: 1.2;
}

.pw-mega__text {
	margin: 0;
	color: var(--wp--preset--color--text-secondary);
	font-size: var(--wp--preset--font-size--small);
	font-weight: 400;
	line-height: 1.5;
	white-space: normal;
}

.pw-site-header .pw-mega .wp-block-navigation-item__label {
	font-weight: 700;
}

.pw-site-header .pw-mega .wp-block-navigation-item__description {
	margin: 0;
	color: var(--wp--preset--color--text-secondary);
	font-size: var(--wp--preset--font-size--small);
	font-weight: 400;
	line-height: 1.45;
}

/* Quote card: navy in both modes (dark scheme inside, like section-navy). */
.pw-mega__card {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 8px;
	padding: var(--wp--preset--spacing--lg);
	border: 1px solid light-dark(transparent, rgb(233 228 222 / 0.22));
	border-radius: var(--wp--custom--radius--lg);
	background-color: var(--wp--preset--color--brand-navy);
	color-scheme: dark;
	color: var(--wp--preset--color--text-secondary);

	& .wp-block-button {
		margin-block-start: auto;
		padding-block-start: 8px;
	}
}

.pw-mega__card-title {
	margin: 0;
	color: var(--wp--preset--color--text-primary);
	font-size: var(--wp--preset--font-size--headline-6);
	font-weight: 800;
	line-height: 1.3;
}

.pw-mega__card-text {
	margin: 0;
	font-size: var(--wp--preset--font-size--small);
	line-height: 1.5;
	white-space: normal;
}

/* -------------------------------------------------------------------------
 * Compact bar (<1024px): logo · account icon · Get a quote · menu button
 * ---------------------------------------------------------------------- */
@media (max-width: 1023px) {
	.pw-site-header .pw-site-header__actions {
		gap: var(--wp--preset--spacing--md);
	}

	.pw-site-header .pw-account-link__link:not(.pw-drawer *) {
		display: inline-grid;
		place-items: center;
		min-width: 44px;
		min-height: 44px;
		padding: 6px;
	}

	.pw-site-header .wp-block-the-framework-menu {
		margin-inline-end: -10px;
		color: var(--wp--preset--color--text-primary);
	}
}

/* Phones: a slightly smaller logo, tighter gaps and a "Get a quote" pill
   without its arrow, so all four fit from 320px. */
@media (max-width: 479px) {
	.pw-site-header__inner,
	.pw-site-header .pw-site-header__actions {
		gap: 8px;
	}

	/* The block sets its width inline; the scrolled star keeps its own. */
	header:not(.is-scrolled) > .pw-site-header .wp-block-palletways-logo {
		width: 108px !important;
	}

	.pw-site-header .pw-account-link__link:not(.pw-drawer *) {
		min-width: 36px;
	}

	.pw-site-header .pw-header-cta .wp-block-button .wp-block-button__link {
		padding-inline: 12px;

		&::before,
		&::after {
			display: none;
		}
	}
}

@media (max-width: 359px) {
	header:not(.is-scrolled) > .pw-site-header .wp-block-palletways-logo {
		width: 92px !important;
	}
}

/* -------------------------------------------------------------------------
 * Drawer — parts/navigation.html
 * ---------------------------------------------------------------------- */
/* While the drawer is open the header (and the drawer in it) sits above the
   floating colour switcher and other fixed widgets. */
header.wp-block-template-part:has(.menu-content.is-visible) {
	z-index: 100000;
}

.menu-content .wp-block-the-framework-navigation-drawer {
	box-shadow: -24px 0 60px rgb(12 31 107 / 0.18);
}

/* A fixed width. The panel is shrink-to-fit, so without one an opened group's
   one-line descriptions stretched it to the full window. Below 30rem
   theme.css stretches it edge to edge. */
@media (min-width: 30rem) {
	.menu-content .wp-block-the-framework-navigation-drawer {
		box-sizing: border-box;
		width: min(var(--drawer-width, 26rem), 100vw);
	}
}

.pw-drawer {
	& .pw-drawer__top {
		position: sticky;
		top: 0;
		z-index: 2;
		min-height: var(--wp--custom--header--height);
		margin-inline: calc(-1 * var(--wp--preset--spacing--lg));
		padding-inline: var(--wp--preset--spacing--lg);
		border-bottom: 1px solid var(--wp--preset--color--border-subtle);
		background-color: var(--wp--preset--color--surface);
	}

	& .wp-block-the-framework-close {
		display: grid;
		place-items: center;
		width: 44px;
		height: 44px;
		margin-inline-end: -10px;
		color: var(--wp--preset--color--text-primary);
	}

	/* Menu groups: full-width rows that open one at a time. */
	& .pw-drawer__nav {
		width: 100%;
		padding-block: var(--wp--preset--spacing--sm);

		& > .wp-block-navigation__container {
			width: 100%;
			gap: 0;
		}

		& > .wp-block-navigation__container > .wp-block-navigation-item {
			width: 100%;
			border-bottom: 1px solid var(--wp--preset--color--border-subtle);
		}

		& .wp-block-navigation-submenu__toggle {
			display: flex;
			justify-content: space-between;
			align-items: center;
			width: 100%;
			min-height: 56px;
			padding: 0 !important;
			color: var(--wp--preset--color--text-primary);
			font-size: var(--wp--preset--font-size--headline-6);
			font-weight: 700;
			text-align: start;
		}

		/* theme.css hides the chevron in the drawer; here it marks a group
		   that opens. Core puts it after the toggle button, not inside. */
		& > .wp-block-navigation__container > .has-child {
			position: relative;

			& > .wp-block-navigation__submenu-icon {
				display: grid !important;
				position: absolute;
				top: 18px;
				right: 0;
				margin: 0;
				pointer-events: none;
			}
		}

		& .wp-block-navigation-submenu__toggle {
			padding-inline-end: 32px !important;
		}

		/* Closed groups are hidden; header-menu.js animates the height on
		   the way in and, with .is-closing, on the way out. */
		& .wp-block-navigation-submenu__toggle[aria-expanded="false"] ~ .wp-block-navigation__submenu-container:not(.is-closing) {
			display: none !important;
		}

		& .wp-block-navigation__submenu-container {
			box-sizing: border-box;
			overflow: hidden !important;
			gap: 2px !important;
			width: 100% !important;
			padding: 0 0 var(--wp--preset--spacing--md) !important;

			& .wp-block-navigation-item {
				width: 100%;
			}

			& .wp-block-navigation-item__content {
				display: flex;
				flex-direction: column;
				align-items: flex-start;
				gap: 2px;
				box-sizing: border-box;
				width: 100%;
				padding: 10px 12px !important;
				text-align: start;
				text-decoration: none;
				border-radius: var(--wp--custom--radius--md);
				color: var(--wp--preset--color--text-primary);
				white-space: normal;

				&:hover,
				&:focus-visible {
					background-color: var(--wp--preset--color--surface-natural);
				}
			}
		}

		& .pw-mega__intro {
			padding: 0 12px 8px !important;

			& .pw-mega__title {
				display: none;
			}
		}

		& .pw-mega__card {
			display: none;
		}
	}

	& .pw-drawer__functions {
		width: 100%;
		margin-block-start: auto;
		padding-block: var(--wp--preset--spacing--lg);
		border-top: 0;
	}

	/* "Get a quote" stays in reach at the bottom of the sheet. */
	& .pw-drawer__cta {
		position: sticky;
		bottom: 0;
		margin-inline: calc(-1 * var(--wp--preset--spacing--lg));
		padding: var(--wp--preset--spacing--md) var(--wp--preset--spacing--lg) max(var(--wp--preset--spacing--md), env(safe-area-inset-bottom));
		border-top: 1px solid var(--wp--preset--color--border-subtle);
		background-color: var(--wp--preset--color--surface);
	}
}

/* The drawer's account link keeps its label. */
.pw-drawer .pw-account-link__label {
	position: static !important;
	width: auto !important;
	height: auto !important;
	margin: 0 !important;
	overflow: visible !important;
	clip: auto !important;
}
