/**
 * Header Main navigation + mobile overlay (Figma "Header - Mobile" /
 * "Design - Nav - mobile v2").
 *
 * Breakpoint (theme override of core’s 600px overlayMenu “mobile” cutover):
 * - ≥1200px: horizontal one-line menu (nowrap + fluid type/gap).
 * - ≤1199px: hamburger + full-viewport Mid Green overlay.
 *
 * Overlay extras (contact + booking) come from Theme::filter_main_navigation_markup().
 * Footer nav grid breakpoints stay at 600px (below).
 */

/*
 * Desktop horizontal menu (≥1200px): one line, modest fluid shrink so items still
 * fit inside the 1280px header frame as the viewport approaches 1200.
 */
@media (min-width: 1200px) {
	header.wp-block-template-part .wp-block-navigation__container > .aps-nav-mobile-only,
	.aps-mobile-nav-extras,
	.aps-mobile-nav-rule {
		display: none;
	}

	header.wp-block-template-part .wp-block-navigation {
		--navigation-layout-wrap: nowrap;
	}

	header.wp-block-template-part .wp-block-navigation__container {
		flex-wrap: nowrap;
		/* 1.5625rem gap at wide; trims toward ~0.875rem near 1200. */
		gap: clamp(0.875rem, 1.1vw, 1.5625rem);
	}

	header.wp-block-template-part .wp-block-navigation-item,
	header.wp-block-template-part .wp-block-navigation-item__content {
		white-space: nowrap;
	}

	/*
	 * Nav preset max is 1.1875rem (~19px). Fluid vw keeps a one-line fit down to 1200
	 * without dropping below 1rem (nav fluid min).
	 */
	header.wp-block-template-part .wp-block-navigation .wp-block-navigation-item__content {
		font-size: clamp(1rem, 0.5vw + 0.6rem, var(--wp--preset--font-size--nav, 1.1875rem));
	}
}

/*
 * Hamburger range (≤1199px): beat core’s min-width:600px rules that would show the
 * horizontal menu and hide the open button.
 */
@media (max-width: 1199px) {
	header.wp-block-template-part .wp-block-navigation__responsive-container:not(.hidden-by-default):not(.is-menu-open) {
		display: none !important;
	}

	header.wp-block-template-part .wp-block-navigation__responsive-container-open:not(.always-shown) {
		display: flex !important;
	}

	/*
	 * Closed header chrome for the whole hamburger range (Figma 117px phone bar,
	 * also used at tablet so overlay close / mask stay aligned).
	 */
	.wp-site-blocks > header.wp-block-template-part > .wp-block-group.alignfull {
		position: relative;
		overflow: visible;
		padding-top: 3.5625rem !important;
		min-height: 7.3125rem;
		box-sizing: border-box;
	}

	.wp-site-blocks > header.wp-block-template-part .custom-logo {
		width: 13.3125rem;
		height: auto;
	}

	/* Hamburger: Figma 34×34 hit target, three-line icon. */
	header.wp-block-template-part .wp-block-navigation__responsive-container-open {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 2.125rem;
		height: 2.125rem;
		color: var(--wp--preset--color--page);
	}

	header.wp-block-template-part .wp-block-navigation__responsive-container-open svg {
		width: 2rem;
		height: 1.5625rem;
		fill: none;
		overflow: visible;
	}

	/*
	 * Open overlay: full-viewport Mid Green, calm fade (reveal token).
	 * Logo + Crisis stay above the overlay; close sits where the hamburger was.
	 * Overflow stays on the content pane so the fixed top chrome does not scroll away.
	 */
	header.wp-block-template-part .wp-block-navigation__responsive-container.is-menu-open {
		--aps-mobile-nav-chrome-height: calc(
			var(--wp-admin--admin-bar--height, 0px) + 7.3125rem
		);
		background-color: var(--wp--preset--color--mid-green) !important;
		color: var(--wp--preset--color--page);
		padding: 0;
		justify-content: stretch;
		overflow: hidden;
	}

	header.wp-block-template-part .wp-block-navigation__responsive-container.is-menu-open {
		animation-name: aps-mobile-nav-reveal;
		animation-duration: var(--wp--custom--motion--duration--reveal);
		animation-timing-function: var(--wp--custom--motion--easing--out);
		animation-fill-mode: forwards;
	}

	@keyframes aps-mobile-nav-reveal {
		from {
			opacity: 0;
		}

		to {
			opacity: 1;
		}
	}

	/*
	 * Keep logo + Crisis above the fixed overlay (core z-index 100000). Elevate only
	 * those nodes — not the whole logo row — or the overlay (a descendant of the nav)
	 * still paints over the logo inside the same stacking context.
	 */
	html.has-modal-open .wp-site-blocks > header.wp-block-template-part .custom-logo-link {
		position: relative;
		z-index: 100001;
	}

	html.has-modal-open .wp-site-blocks > header.wp-block-template-part .wp-block-buttons:has(.is-style-crisis-tab) {
		z-index: 100002;
	}

	html.has-modal-open .wp-site-blocks > header.wp-block-template-part .wp-block-navigation__responsive-container-open {
		visibility: hidden;
	}

	header.wp-block-template-part .wp-block-navigation__responsive-container.is-menu-open .wp-block-navigation__responsive-close,
	header.wp-block-template-part .wp-block-navigation__responsive-container.is-menu-open .wp-block-navigation__responsive-dialog {
		display: flex;
		flex-direction: column;
		flex: 1 1 auto;
		width: 100%;
		max-width: none;
		min-height: 100%;
		height: 100%;
		margin: 0;
	}

	/*
	 * Solid Mid Green top chrome (full width, down through the header HR). Sits above
	 * the scrolling nav (z-index 1) so links pass behind logo / Crisis / close / HR.
	 */
	header.wp-block-template-part .wp-block-navigation__responsive-container.is-menu-open .wp-block-navigation__responsive-dialog::before {
		content: "";
		position: absolute;
		top: 0;
		right: 0;
		left: 0;
		z-index: 1;
		height: calc(var(--aps-mobile-nav-chrome-height) + 1px);
		background-color: var(--wp--preset--color--mid-green);
		pointer-events: none;
	}

	/* Top fade rule pinned on the chrome (no longer a scrolling flex item). */
	header.wp-block-template-part .wp-block-navigation__responsive-container.is-menu-open .wp-block-navigation__responsive-dialog::after {
		content: "";
		position: absolute;
		top: var(--aps-mobile-nav-chrome-height);
		left: 50%;
		z-index: 1;
		box-sizing: border-box;
		width: min( calc( 100% - 3.25rem ), 21.875rem );
		height: 1px;
		transform: translateX( -50% );
		background-image: linear-gradient(
			90deg,
			transparent 0%,
			color-mix(in srgb, var(--wp--preset--color--page) 50%, transparent) 20%,
			color-mix(in srgb, var(--wp--preset--color--page) 50%, transparent) 80%,
			transparent 100%
		);
		pointer-events: none;
	}

	header.wp-block-template-part .wp-block-navigation__responsive-container.is-menu-open .wp-block-navigation__responsive-container-content {
		position: relative;
		z-index: 0;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: flex-start;
		flex: 1 1 auto;
		width: 100%;
		padding: calc( var(--aps-mobile-nav-chrome-height) + 1px ) 1.625rem 1.5rem;
		box-sizing: border-box;
		overflow: auto;
		-webkit-overflow-scrolling: touch;
	}

	/* Close (X) on the same root-gutter right edge as the closed hamburger / Crisis. */
	header.wp-block-template-part .wp-block-navigation__responsive-container-close {
		top: calc(var(--wp-admin--admin-bar--height, 0px) + 3.625rem);
		right: var(--wp--style--root--padding-right, 0px);
		z-index: 2;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 2.125rem;
		height: 2.125rem;
		color: var(--wp--preset--color--page);
	}

	header.wp-block-template-part .wp-block-navigation__responsive-container-close svg {
		width: 1.5625rem;
		height: 1.5rem;
		fill: none;
	}

	header.wp-block-template-part .wp-block-navigation__responsive-container.is-menu-open .wp-block-navigation__container {
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 100%;
		max-width: 21.875rem;
		margin: 0;
		gap: 0.8125rem;
		padding-block: 1.25rem;
	}

	header.wp-block-template-part .wp-block-navigation__responsive-container.is-menu-open .wp-block-navigation-item {
		display: flex;
		justify-content: center;
		width: 100%;
	}

	header.wp-block-template-part .wp-block-navigation__responsive-container.is-menu-open .wp-block-navigation-item__content {
		width: 100%;
		text-align: center;
		font-size: 1.6875rem;
		font-weight: var(--wp--custom--font-weight--regular);
		letter-spacing: 0.01em;
		line-height: var(--wp--custom--line-height--body);
		color: var(--wp--preset--color--page);
		text-decoration-color: transparent;
		white-space: normal;
	}

	header.wp-block-template-part .wp-block-navigation__responsive-container.is-menu-open .wp-block-navigation-item__content:is(:hover, :focus-visible) {
		text-decoration-color: currentColor;
	}

	header.wp-block-template-part .wp-block-navigation__responsive-container.is-menu-open :is(.current-menu-item > .wp-block-navigation-item__content, .wp-block-navigation-item__content[aria-current="page"]) {
		text-decoration-color: currentColor;
	}

	/* Fade rules (same recipe as separator.css Light). */
	.aps-mobile-nav-rule {
		display: block;
		flex-shrink: 0;
		border: 0;
		height: 1px;
		min-height: 1px;
		width: 100%;
		max-width: 21.875rem;
		margin: 0 auto;
		background-image: linear-gradient(
			90deg,
			transparent 0%,
			color-mix(in srgb, var(--wp--preset--color--page) 50%, transparent) 20%,
			color-mix(in srgb, var(--wp--preset--color--page) 50%, transparent) 80%,
			transparent 100%
		);
	}

	.aps-mobile-nav-extras {
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 100%;
		max-width: 21.875rem;
		margin-top: auto;
		padding-bottom: 0.5rem;
		gap: 0;
	}

	.aps-mobile-nav-extras > .aps-mobile-nav-rule:first-child {
		margin-bottom: 1.5rem;
	}

	.aps-mobile-nav-contact {
		display: flex;
		flex-direction: column;
		align-items: center;
		gap: 0.9375rem;
		width: 100%;
		margin-bottom: 1.5rem;
		text-align: center;
	}

	.aps-mobile-nav-contact a {
		font-size: 1.4375rem;
		font-weight: var(--wp--custom--font-weight--medium);
		letter-spacing: 0.01em;
		line-height: var(--wp--custom--line-height--body);
		color: var(--wp--preset--color--page);
		text-decoration: underline;
		text-decoration-thickness: 1px;
		text-underline-offset: 0.2em;
	}

	.aps-mobile-nav-extras > .aps-mobile-nav-rule:nth-of-type(2) {
		margin-bottom: 1.5rem;
	}

	/* Cream CTA on Mid Green (inverted from the default button). */
	.aps-mobile-nav-book {
		display: inline-flex;
		align-items: center;
		justify-content: center;
		box-sizing: border-box;
		width: min(100%, 17.5625rem);
		padding: 0.8125rem 1.25rem;
		border: 0;
		border-radius: 0.625rem;
		background-color: var(--wp--preset--color--page) !important;
		color: var(--wp--preset--color--mid-green) !important;
		font-family: var(--wp--preset--font-family--season-sans);
		font-size: var(--wp--preset--font-size--body);
		font-weight: var(--wp--custom--font-weight--medium);
		letter-spacing: var(--wp--custom--letter-spacing--body);
		line-height: var(--wp--custom--line-height--none);
		text-decoration: none !important;
		text-align: center;
		transition:
			background-color var(--wp--custom--motion--duration--quick) var(--wp--custom--motion--easing--out),
			color var(--wp--custom--motion--duration--quick) var(--wp--custom--motion--easing--out);
	}

	.aps-mobile-nav-book:is(:hover, :focus-visible) {
		background-color: #ffffff !important;
		color: var(--wp--preset--color--mid-green) !important;
	}

	/* Programmatic focus on open should not draw a box; keyboard :focus-visible still does. */
	header.wp-block-template-part .wp-block-navigation__responsive-container.is-menu-open :is(.wp-block-navigation-item, .wp-block-navigation-item__content):focus {
		outline: none;
		box-shadow: none;
	}

	header.wp-block-template-part .wp-block-navigation__responsive-container.is-menu-open .wp-block-navigation-item__content:focus-visible {
		outline: 2px solid var(--wp--preset--color--page);
		outline-offset: 0.25rem;
	}
}

/*
 * Footer links: one Navigation, CSS grid with column-major flow.
 * Mobile (≤599): 2 cols × 5 rows — Figma "Footer - Mobile" (5 + 4).
 * Desktop (≥600): 3 cols × 3 rows — Figma "Footer" (unchanged; not the nav overlay cutover).
 */
footer.wp-block-template-part .aps-footer-links .wp-block-navigation__container {
	display: grid;
	grid-template-columns: 1fr 1fr;
	grid-template-rows: repeat(5, auto);
	grid-auto-flow: column;
	column-gap: 1.5rem;
	row-gap: 0.75rem;
	align-items: start;
	width: 100%;
}

@media (min-width: 600px) {
	footer.wp-block-template-part .aps-footer-links .wp-block-navigation__container {
		grid-template-columns: max-content max-content max-content;
		grid-template-rows: repeat(3, auto);
		width: auto;
		column-gap: 3.5rem;
		row-gap: 0.8125rem;
	}
}

/*
 * Side by side from 782px (where core Columns stop stacking) the links column is 39.4% wide,
 * narrower than the 3-column grid until about 1200px. It keeps the grid's full width and the
 * logo column gives way instead, so the footer never overflows sideways.
 */
@media (min-width: 782px) {
	footer.wp-block-template-part .wp-block-column:has(> .aps-footer-links) {
		min-width: max-content;
	}
}
