/* Site header + mega menus (partials/site-header.php, inc/nav-menu.php, assets/js/header.js).
   Figma: Event Structures menus 6927:35066 (header), 6927:35074 (image cards), 6927:36175 (link columns);
   mobile Headers & Footers 7343:32594 (bar) + Menu 6927:11027 (open menu). No mobile submenu frame exists: open
   submenus are plain link lists.
   Type: style-guide sizes only (Figma 18px → text-10, 17px → text-11, 21px → text-9; mobile 24px → text-7,
   21px → text-8).
   ponytail: one layout switch at 1200px: below it the six links + Contact don't fit next to the logo, so the menu
   button takes over. Not a WP viewport: needs the user's OK (D16). */

.fews-header {
	--fews-header-line: #d1d5dc; /* Figma color/greyscale/300 */
	position: sticky;
	top: var(--wp-admin--admin-bar--height, 0px);
	z-index: 99999;
	font-family: var(--wp--preset--font-family--body);
	color: var(--wp--preset--color--ink);
	text-align: start;
}

.fews-header :where(ul, li, p) {
	margin: 0;
	padding: 0;
	list-style: none;
}

.fews-header a {
	color: inherit;
}

.fews-header :is(a, button):focus-visible {
	outline: 2px solid currentcolor;
	outline-offset: 2px;
}

.fews-header button {
	margin: 0;
	padding: 0;
	border: 0;
	font: inherit;
	color: inherit;
	background: none;
	cursor: pointer;
}

/* Top bar: Fews site tabs + hours / phone. Desktop only; on mobile both are in the open menu. */
.fews-header__bar {
	display: flex;
	justify-content: space-between;
	align-items: center;
	block-size: 2.8125rem;
	padding-inline-end: 1.125rem;
	color: var(--wp--preset--color--base);
	background: var(--wp--preset--color--contrast);
}

/* Tabs = 45px-slanted parallelograms overlapping by 42px, so the orange behind shows as 3px diagonal lines.
   ::before / ::after = the navy triangles that close the row at both ends (Figma Rectangle 2 / 5). */
.fews-header__bar .fews-header__sites {
	--fews-slant: 2.8125rem;
	display: flex;
	align-self: stretch;
	/* no orange under the closing triangle (::after), so none shows at the row's end */
	background: linear-gradient(to left, transparent calc(var(--fews-slant) + 1px), var(--wp--preset--color--primary) 0);
	font-family: var(--wp--preset--font-family--heading);
	font-size: var(--wp--preset--font-size--text-11);
	font-weight: 600;
}

.fews-header__bar .fews-header__sites::before,
.fews-header__bar .fews-header__sites::after,
.fews-header__bar .fews-header__sites li {
	margin-inline-start: calc(3px - var(--fews-slant));
	background: var(--wp--preset--color--contrast);
}

.fews-header__bar .fews-header__sites::before,
.fews-header__bar .fews-header__sites::after {
	content: "";
	flex: none;
	inline-size: var(--fews-slant);
	clip-path: polygon(0 0, 100% 0, 0 100%);
}

.fews-header__bar .fews-header__sites::before {
	margin-inline-start: 0;
}

/* closes the row flush with the last tab: no orange line after it */
.fews-header__bar .fews-header__sites::after {
	margin-inline-start: calc(-1px - var(--fews-slant));
	clip-path: polygon(100% 0, 100% 100%, 0 100%);
}

.fews-header__bar .fews-header__sites li {
	display: flex;
	clip-path: polygon(var(--fews-slant) 0, 100% 0, calc(100% - var(--fews-slant)) 100%, 0 100%);
}

.fews-header__bar .fews-header__sites a {
	display: flex;
	align-items: center;
	padding-inline: calc(var(--fews-slant) + 0.625rem);
	white-space: nowrap;
}

.fews-header__bar .fews-header__sites .is-current {
	color: #000;
	background: var(--wp--preset--color--base);
}

.fews-header__bar .fews-header__sites li:not(.is-current) a:hover {
	color: var(--wp--preset--color--primary-light);
}

.fews-header__contact {
	display: flex;
	align-items: center;
	gap: 1.3125rem;
	font-size: var(--wp--preset--font-size--text-11);
	line-height: 1.45;
	white-space: nowrap;
}

.fews-header__contact strong {
	font-size: var(--wp--preset--font-size--text-10);
	font-weight: 600;
}

.fews-header__bar .fews-header__contact span + strong::before {
	content: "|";
	margin-inline-end: 1.3125rem;
	font-weight: 400;
	opacity: 0.3;
}

/* Main row: logo + tagline, menu, Contact */
.fews-header__main {
	position: relative; /* the mega panels span this row's width */
	display: flex;
	align-items: center;
	block-size: 5.4375rem;
	padding-inline: 1.375rem 1rem;
	background: var(--wp--preset--color--base);
	box-shadow: inset 0 -1px var(--fews-header-line);
}

/* Logo + tagline. The tagline drops out when the menu needs its room (no breakpoint): the brand box shrinks first,
   the tagline wraps to a second line and that line is clipped. */
.fews-header__brand {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	flex: 0 1 auto;
	min-inline-size: 7.8125rem;
	block-size: 3.5625rem;
	overflow: hidden;
}

.fews-header__logo {
	flex: none;
	inline-size: 7.8125rem;
}

.fews-header__logo img {
	display: block;
	inline-size: 100%;
	block-size: auto;
}

.fews-header__tagline {
	margin-block: 0.53125rem; /* centred on the 57px logo row */
	margin-inline-start: 0.9375rem;
	padding-inline-start: 0.9375rem;
	font-family: var(--wp--preset--font-family--heading);
	font-size: var(--wp--preset--font-size--text-11);
	font-weight: 600;
	line-height: 2.5rem; /* the 40px divider */
	letter-spacing: 0.01em;
	white-space: nowrap;
	box-shadow: inset 1px 0 var(--fews-header-line);
}

/* ◣ after a top-level label (Figma 10 × 8.8) */
.fews-nav__toggle::after {
	content: "";
	display: inline-block;
	inline-size: 0.625rem;
	block-size: 0.55rem;
	background: currentcolor;
	clip-path: polygon(0 0, 0 100%, 100% 100%);
}

.fews-nav__link.fews-nav__toggle::after {
	margin-inline-start: 0.375rem;
}

/* ---------- Desktop ---------- */
@media (width >= 1200px) {
	.fews-header__actions,
	.fews-header__menu-button,
	.fews-nav__extra,
	.fews-nav__menu > .menu-item-home { /* the logo links home; Home is a mobile-menu item (Figma) */
		display: none;
	}

	/* The <nav> is a popover for mobile only: undo the UA popover box (author rules beat the UA display: none). */
	.fews-nav {
		position: static;
		display: block;
		inset: auto;
		inline-size: auto;
		block-size: 100%;
		margin: 0 0 0 auto;
		padding: 0;
		overflow: visible;
		border: 0;
		color: inherit;
		background: none;
		flex: none;
	}

	/* Figma 40px apart at 1920, down to 20px at ~1430 */
	.fews-nav__menu {
		display: flex;
		align-items: stretch;
		gap: clamp(1.25rem, 4.17vw - 2.5rem, 2.5rem);
		block-size: 100%;
	}

	.fews-nav__menu > li {
		display: flex;
		align-items: center;
		gap: 0.375rem;
		font-family: var(--wp--preset--font-family--heading);
		font-size: var(--wp--preset--font-size--text-10);
		font-weight: 600;
		line-height: 1.45;
		white-space: nowrap;
		box-shadow: inset 0 -4px transparent;
		transition: color 0.2s, box-shadow 0.2s;
	}

	/* Figma: the current section is orange; the underline only shows on the open panel */
	.fews-nav__menu > li:not(.is-button):is(:hover, .is-open, .current-menu-item, .current-menu-ancestor, .current-page-ancestor) {
		color: var(--wp--preset--color--primary);
	}

	.fews-nav__menu > li:not(.is-button):is(:hover, .is-open) {
		box-shadow: inset 0 -4px var(--wp--preset--color--primary);
	}

	.fews-nav__menu > li > .fews-nav__toggle:not(.fews-nav__link) {
		align-self: stretch;
		margin-inline: -0.375rem; /* the 6px label gap stays, the click target grows */
		padding-inline: 0.375rem;
	}

	/* Contact (Figma 19px, 15/30 padding, ~58px tall) */
	.fews-nav__menu > .is-button {
		margin-inline-start: 0;
		box-shadow: none;
	}

	.fews-nav__menu > .is-button > .wp-block-button__link {
		block-size: auto; /* core: height 100% */
		font-size: var(--wp--preset--font-size--text-10);
		line-height: 1.5;
	}

	/* Mega panel: full header width under the main row, content 1335px wide (Figma x 292.5 at 1920), orange
	   triangle bottom right (Figma "Left" 116 × 102). Shown by header.js (li.is-open). */
	.fews-nav__menu > li > .sub-menu {
		position: absolute;
		inset-block-start: 100%;
		inset-inline: 0;
		display: none;
		flex-wrap: wrap;
		align-items: flex-start;
		gap: 1.25rem;
		padding: 1.5625rem max(1.25rem, (100% - 83.4375rem) / 2) 1.875rem;
		font-family: var(--wp--preset--font-family--body);
		font-weight: 400;
		white-space: normal;
		color: var(--wp--preset--color--ink);
		background: var(--wp--preset--color--base);
		box-shadow: inset 0 -1px var(--fews-header-line);
		clip-path: inset(0);
		transition: clip-path 0.3s cubic-bezier(0.4, 0, 0.2, 1);
	}

	.fews-nav__menu > li.is-open > .sub-menu {
		display: flex;
	}

	/* the page under an open panel: 30% black tint, below the header */
	body::after {
		content: "";
		position: fixed;
		inset: 0;
		z-index: 99998;
		background: rgb(0 0 0 / 30%);
		opacity: 0;
		pointer-events: none;
		transition: opacity 0.3s;
	}

	body:has(.fews-nav__menu > li.is-open > .sub-menu)::after {
		opacity: 1;
	}

	.fews-nav__menu > li > .sub-menu::after {
		content: "";
		position: absolute;
		inset-inline-end: 0;
		inset-block-end: 0;
		inline-size: 7.25rem;
		block-size: 6.375rem;
		background: var(--wp--preset--color--primary);
		clip-path: polygon(100% 0, 100% 100%, 0 100%);
		pointer-events: none;
	}

	.fews-nav__menu > li > .sub-menu > li {
		transition: opacity 0.25s 0.15s;
	}

	/* Opening: the panel unrolls (Figma's empty middle frame), then its content fades in. Moving from one open panel
	   to the next swaps instantly (header.js sets .is-switching). */
	@starting-style {
		.fews-nav__menu > li.is-open > .sub-menu {
			clip-path: inset(0 0 100% 0);
		}

		.fews-nav__menu > li.is-open > .sub-menu > li {
			opacity: 0;
		}
	}

	.fews-header.is-switching .sub-menu,
	.fews-header.is-switching .sub-menu > li {
		transition: none;
	}

	/* Buttons: own row under a divider (Figma Line 20 + "Festival Projects" / "Commercial") */
	.fews-nav__menu > li > .sub-menu:has(> .is-button)::before {
		content: "";
		order: 1;
		flex-basis: 100%;
		block-size: 1px;
		background: var(--fews-header-line);
	}

	.fews-nav__menu > li > .sub-menu > .is-button {
		order: 2;
	}

	.fews-nav__menu .sub-menu .is-button > .wp-block-button__link {
		padding-inline: 1.25rem;
		font-size: var(--wp--preset--font-size--text-11);
	}

	/* outline = ink text, line and corner on the white panel (the default button text is white) */
	.fews-nav__menu .sub-menu .is-style-outline > .wp-block-button__link {
		color: var(--wp--preset--color--ink);
	}

	/* Image cards: 4 a row (Figma Commercial, Corporate, Festivals, Private), 5 when there are more than 8 (Structures) */
	.is-mega-cards > .sub-menu {
		--fews-cards: 4;
	}

	.is-mega-cards > .sub-menu:has(> :nth-child(9 of .is-card)) {
		--fews-cards: 5;
	}

	.is-card {
		flex: 0 0 calc((100% - (var(--fews-cards) - 1) * 1.25rem) / var(--fews-cards));
	}

	.is-card > a,
	.is-card > .fews-nav__link {
		display: grid;
		gap: 0.5rem;
		font-size: var(--wp--preset--font-size--text-10);
		font-weight: 600;
		line-height: 1.5;
	}

	.is-card .sub-menu {
		display: none;
	}

	/* 350:197 photo, grey until the image loads */
	.fews-nav__image {
		display: block;
		aspect-ratio: 350 / 197;
		overflow: hidden;
		background: var(--wp--preset--color--surface);
	}

	.fews-nav__image img {
		display: block;
		inline-size: 100%;
		block-size: 100%;
		object-fit: cover;
		transition: transform 0.6s ease;
	}

	.is-card > a:is(:hover, :focus-visible) img {
		transform: scale(1.05);
	}

	.is-card > a:is(:hover, :focus-visible) .fews-nav__label {
		color: var(--wp--preset--color--primary);
	}

	/* Link columns: 310px columns 100px apart, centred (Figma About). A 2nd-level item without children is a link. */
	.fews-nav__menu > .is-mega-links > .sub-menu {
		justify-content: center;
		column-gap: 6.25rem;
	}

	.is-mega-links > .sub-menu > li:not(.is-button) {
		flex: 0 0 19.375rem;
	}

	.is-mega-links > .sub-menu > .menu-item-has-children > :is(a, .fews-nav__link) {
		font-family: var(--wp--preset--font-family--heading);
		font-size: var(--wp--preset--font-size--text-11);
		font-weight: 600;
		line-height: 1.5;
		letter-spacing: 0.1875em;
		text-transform: uppercase;
		color: var(--wp--preset--color--primary);
	}

	/* Figma: 28px lines 43px apart */
	.is-mega-links .sub-menu .sub-menu {
		display: grid;
		justify-items: start;
		gap: 0.875rem;
		margin-block-start: 1.25rem;
	}

	.is-mega-links .sub-menu .sub-menu a,
	.is-mega-links > .sub-menu > li:not(.menu-item-has-children, .is-button) > a {
		font-size: var(--wp--preset--font-size--text-9);
		line-height: 1.3;
		color: var(--wp--preset--color--contrast);
		background: linear-gradient(currentcolor, currentcolor) 0 100% / 0 1px no-repeat;
		transition: background-size 0.3s, color 0.3s;
	}

	.is-mega-links .sub-menu .sub-menu a:is(:hover, :focus-visible),
	.is-mega-links > .sub-menu > li:not(.menu-item-has-children, .is-button) > a:is(:hover, :focus-visible) {
		color: var(--wp--preset--color--primary);
		background-size: 100% 1px;
	}
}

/* ---------- Mobile + tablet: bar with logo, Contact and the menu button; the menu opens full screen ---------- */
@media (width < 1200px) {
	.fews-header__bar,
	.fews-header__tagline {
		display: none;
	}

	/* Figma: white 75% → 38%, 5px blur. The blur sits on ::before: backdrop-filter on the header itself would make it
	   the containing block of the fixed (popover) menu. */
	.fews-header__main {
		block-size: 4.0625rem;
		padding-inline: 0.8125rem;
		background: none;
	}

	.fews-header__main::before {
		content: "";
		position: absolute;
		inset: 0;
		z-index: -1;
		background: linear-gradient(90deg, rgb(255 255 255 / 0.75) 30.937%, rgb(255 255 255 / 0.38));
		backdrop-filter: blur(5px);
	}

	.fews-header__logo {
		inline-size: 6.8125rem;
	}

	.fews-header__actions {
		display: flex;
		gap: 0.625rem;
		margin-inline-start: auto;
	}

	.fews-header__actions .wp-block-button__link {
		display: grid;
		place-items: center;
		inline-size: 6.25rem;
		block-size: 2.8125rem;
		padding: 0;
	}

	/* Menu / close button: 45px box, 30% navy line; 3 lines (Figma Hamburger) or an X (Close) */
	.fews-header__menu-button {
		position: relative;
		flex: none;
		inline-size: 2.8125rem;
		block-size: 2.8125rem;
		box-shadow: inset 0 0 0 1px rgb(54 65 83 / 0.3);
	}

	.fews-header__menu-button span,
	.fews-header__menu-button span::before,
	.fews-header__menu-button span::after {
		position: absolute;
		inset-inline-start: 50%;
		inline-size: 1rem;
		block-size: 1px;
		margin-inline-start: -0.5rem;
		background: var(--wp--preset--color--contrast);
	}

	.fews-header__menu-button span {
		inset-block-start: 50%;
	}

	.fews-header__menu-button span::before,
	.fews-header__menu-button span::after {
		content: "";
		inset-inline-start: 0;
		margin: 0;
	}

	.fews-header__menu-button span::before {
		inset-block-start: -0.40625rem;
	}

	.fews-header__menu-button span::after {
		inset-block-start: 0.40625rem;
	}

	.fews-header__menu-button.is-close {
		position: absolute;
		inset-block-start: 0.625rem;
		inset-inline-end: 0.8125rem;
	}

	.fews-header__menu-button.is-close span {
		background: none;
	}

	.fews-header__menu-button.is-close span::before,
	.fews-header__menu-button.is-close span::after {
		inset-block-start: 0;
		inset-inline-start: -0.3rem;
		inline-size: 1.625rem;
		transform: rotate(45deg);
	}

	.fews-header__menu-button.is-close span::after {
		transform: rotate(-45deg);
	}

	/* The open menu: full screen, white, content 25px in, from 72px down (Figma Menu 6927:11027) */
	.fews-nav {
		box-sizing: border-box;
		inset: 0;
		inline-size: 100%;
		max-inline-size: none;
		block-size: 100%;
		max-block-size: none;
		margin: 0;
		padding: 4.5rem 1.5625rem 2.5rem;
		overflow-y: auto;
		overscroll-behavior: contain;
		border: 0;
		color: var(--wp--preset--color--ink);
		background: var(--wp--preset--color--base);
		text-align: start;
	}

	.fews-nav::backdrop {
		background: none;
	}

	html:has(.fews-nav:popover-open) {
		overflow: hidden;
	}

	.fews-nav__menu {
		display: flex;
		flex-direction: column;
		box-shadow: inset 0 1px var(--wp--preset--color--border);
	}

	.fews-nav__menu > li {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		padding-block: 0.9375rem;
		font-size: var(--wp--preset--font-size--text-7);
		font-weight: 600;
		line-height: 1.875rem;
		box-shadow: inset 0 -1px var(--wp--preset--color--border);
	}

	/* the rest of the row toggles the submenu; the label stays a link */
	.fews-nav__menu > li > .fews-nav__toggle:not(.fews-nav__link) {
		flex: 1;
		align-self: stretch;
		padding-inline-start: 0.375rem;
		text-align: start;
	}

	.fews-nav__menu > li.is-open > .fews-nav__toggle,
	.fews-nav__menu > li:is(.current-menu-item, .current-menu-ancestor, .current-page-ancestor) > a {
		color: var(--wp--preset--color--primary);
	}

	/* Contact: full width, 60px, navy */
	.fews-nav__menu > .is-button {
		margin-block-start: 0.9375rem;
		padding: 0;
		box-shadow: none;
	}

	.fews-nav__menu > .is-button > .wp-block-button__link {
		display: grid;
		place-items: center;
		flex: 1;
		block-size: 3.75rem;
		font-family: var(--wp--preset--font-family--body);
		font-size: var(--wp--preset--font-size--text-8);
		line-height: 1.75rem;
	}

	/* Submenus: a plain list under the row; card images and button styling are desktop only */
	.fews-nav__menu .sub-menu {
		display: none;
		flex-basis: 100%;
		padding-block-start: 0.625rem;
		font-size: var(--wp--preset--font-size--text-10);
		font-weight: 400;
		line-height: 1.5;
	}

	.fews-nav__menu > li.is-open > .sub-menu,
	.fews-nav__menu .sub-menu .sub-menu {
		display: grid;
		gap: 0.3125rem;
	}

	.fews-nav__menu .sub-menu .sub-menu {
		padding-block-start: 0.3125rem;
	}

	.fews-nav__image {
		display: none;
	}

	.is-mega-links > .sub-menu > .menu-item-has-children > :is(a, .fews-nav__link) {
		font-family: var(--wp--preset--font-family--heading);
		font-size: var(--wp--preset--font-size--text-12);
		font-weight: 600;
		letter-spacing: 0.1875em;
		text-transform: uppercase;
		color: var(--wp--preset--color--primary);
	}

	.is-mega-links > .sub-menu > .menu-item-has-children:not(:first-child) {
		margin-block-start: 0.625rem;
	}

	.fews-nav__menu .sub-menu .is-button > .wp-block-button__link {
		display: block;
		padding: 0;
		font: inherit;
		color: inherit;
		background: none;
		box-shadow: none;
		filter: none;
	}

	.fews-nav__menu .sub-menu .is-button > .wp-block-button__link::before {
		content: none;
	}

	/* Hours + phone, then the Fews sites (Figma: below Contact) */
	.fews-nav__extra {
		display: grid;
		gap: 0.9375rem;
		margin-block-start: 0.9375rem;
		font-size: var(--wp--preset--font-size--text-10);
		line-height: 1.5;
	}

	.fews-nav__extra .fews-header__contact {
		flex-direction: column;
		align-items: flex-start;
		gap: 0.3125rem;
		padding-block-end: 0.9375rem;
		font-size: inherit;
		color: var(--wp--preset--color--contrast);
		box-shadow: inset 0 -1px var(--wp--preset--color--border);
	}

	.fews-nav__extra .fews-header__contact strong {
		font-size: inherit;
	}

	.fews-nav__extra .fews-header__sites {
		display: grid;
		justify-items: start;
		gap: 0.625rem;
	}
}

@media (prefers-reduced-motion: reduce) {
	.fews-header *,
	.fews-header *::before,
	.fews-header *::after {
		transition: none;
	}
}
