/* ============================================================
   Site header / primary navigation
   Design ref: designs/Navbar Desktop.png
   Solid teal sticky bar: logo left, menu + CTA right.
   Mobile (< 1024px): hamburger opens slide-down panel.
   ============================================================ */

/* Fixed header. On the homepage it starts transparent over the hero's teal
   pattern (per the Figma design, where TopNavBar sits inside the hero frame)
   and fades to solid teal + soft shadow once scrolled (.is-scrolled via JS).
   Other pages: solid from the start; body:not(.home) gets padding-top to
   compensate for the fixed positioning (see main.css). */
.site-header {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	z-index: 100;
	background: var(--color-teal);
	transition: background-color 0.35s ease, box-shadow 0.35s ease;
}

body.home .site-header:not(.is-scrolled) {
	background: transparent;
}

/* Solid whenever the mobile panel is open, even at the top of the page */
body.nav-open .site-header {
	background: var(--color-teal);
}

.site-header.is-scrolled {
	box-shadow: 0 2px 16px rgb(0 31 38 / 0.18);
}

/* Logged-in WordPress admin bar sits above the fixed header */
body.admin-bar .site-header {
	top: 32px;
}

@media (max-width: 782px) {
	body.admin-bar .site-header {
		top: 46px;
	}
}

.site-header .container {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--space-md);
	min-height: var(--header-height);
}

/* ---- Logo ---- */

.site-header__logo {
	flex-shrink: 0;
}

.site-header__logo a {
	display: flex;
	flex-direction: column;
	text-decoration: none;
}

/* Explicit height + max-width:none - the base img { max-width:100% } inside a
   shrink-to-fit flex anchor otherwise collapses the SVG to 0x0.
   Mobile stays 44px to match the 44px hamburger beside it. Desktop was the
   Figma navbar spec of 51px, bumped to 55px (client request) so the logo is
   the same height as the "Get Help Today" CTA button and no longer sits with
   more top/bottom space than it (both now clear ~12.5px above and below in
   the 80px bar). */
.site-header__logo img {
	height: 44px;
	width: auto;
	max-width: none;
}

@media (min-width: 1024px) {
	.site-header__logo img {
		height: 55px;
	}
}

.site-header__name {
	font-family: var(--font-heading);
	font-size: 1.375rem;
	line-height: 1.2;
	color: var(--color-text-on-dark);
}

.site-header__tagline {
	font-family: var(--font-body);
	font-size: 0.5625rem;
	font-weight: 600;
	letter-spacing: 0.18em;
	text-transform: uppercase;
	color: var(--color-caramel-light);
}

/* ---- Hamburger (mobile only) ---- */

.site-header__hamburger {
	display: inline-flex;
	flex-direction: column;
	justify-content: center;
	gap: 5px;
	width: 44px;
	height: 44px;
	padding: 10px;
	background: transparent;
	border: 0;
	cursor: pointer;
}

.site-header__hamburger-line {
	display: block;
	width: 24px;
	height: 2px;
	background: var(--color-text-on-dark);
	border-radius: 1px;
	transition: transform var(--transition), opacity var(--transition);
}

.site-header__hamburger.is-active .site-header__hamburger-line:nth-child(1) {
	transform: translateY(7px) rotate(45deg);
}

.site-header__hamburger.is-active .site-header__hamburger-line:nth-child(2) {
	opacity: 0;
}

.site-header__hamburger.is-active .site-header__hamburger-line:nth-child(3) {
	transform: translateY(-7px) rotate(-45deg);
}

/* ---- Navigation panel (mobile-first: full-height sheet) ---- */

/* Fills the screen from under the bar to the bottom edge. It used to size to
   its content, which showed a strip of page underneath - and collapsing the
   sub-menus (below) makes the content shorter still, so a fixed height is what
   makes the accordion possible. dvh tracks the mobile address bar showing and
   hiding; the vh line above it is the fallback for browsers without dvh. */
.site-header__nav {
	position: absolute;
	top: 100%;
	left: 0;
	right: 0;
	display: flex;
	flex-direction: column;
	height: calc(100vh - var(--header-height));
	height: calc(100dvh - var(--header-height));
	padding-bottom: env(safe-area-inset-bottom);
	background: var(--color-teal-dark);
	overflow-y: auto;
	overscroll-behavior: contain; /* don't scroll the page behind at the ends */
	opacity: 0;
	visibility: hidden;
	transform: translateY(-6px);
	transition: opacity 0.28s ease, transform 0.28s ease, visibility 0s linear 0.28s;
}

.site-header__nav.is-open {
	opacity: 1;
	visibility: visible;
	transform: translateY(0);
	transition: opacity 0.28s ease, transform 0.28s ease;
}

/* The admin bar pushes the header down, so the panel must lose that height too */
@media (max-width: 782px) {
	body.admin-bar .site-header__nav {
		height: calc(100vh - var(--header-height) - 46px);
		height: calc(100dvh - var(--header-height) - 46px);
	}
}

@media (prefers-reduced-motion: reduce) {
	.site-header__nav {
		transform: none;
		transition: opacity 0.01s linear, visibility 0.01s linear;
	}
}

.site-header__menu {
	list-style: none;
	margin: 0;
	padding: var(--space-xs) var(--container-pad);
	flex-shrink: 0; /* long menus scroll the panel, they never squash */
}

/* Top-level row: label on the left, its expand button on the right, hairline
   between rows. The sub-menu is the third child and wraps onto its own line. */
.site-header__menu > li {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	border-bottom: 1px solid var(--color-footer-line);
}

/* Figma spec: Onest Medium 16px / line-height 24px / letter-spacing 0 / #FFFFFF */
.site-header__menu a {
	display: block;
	padding: 0.75rem 0;
	font-size: 1rem;
	font-weight: 500;
	line-height: 1.5;
	text-decoration: none;
	color: var(--color-white);
}

/* Rows with no chevron: the whole row navigates */
.site-header__menu > li > a {
	flex: 1;
}

/* Rows WITH a chevron: only the label itself navigates. Everything to its
   right - the empty span and the chevron - belongs to the toggle button
   below, so tapping the gap opens the branch instead of loading the page. */
.site-header__menu > li.menu-item-has-children > a {
	flex: 0 1 auto;
}

/* Current page, so the auto-opened branch is obvious. Mobile only - the
   desktop bar is screenshot-matched to the design, which has no current state. */
@media (max-width: 1023.98px) {
	.site-header__menu .current-menu-item > a {
		color: var(--color-caramel-light);
	}
}

.site-header__menu a:hover,
.site-header__menu a:focus-visible {
	color: var(--color-caramel-light);
}

/* Chevron on items with children (.has-chevron = placeholder items without real submenus yet).
   Figma spec: wide shallow vector, 7x3 path with 1.5 stroke - drawn via mask so it
   follows currentColor on hover. */
.site-header__menu .menu-item-has-children > a::after,
.site-header__menu .has-chevron > a::after {
	content: "";
	display: inline-block;
	width: 10px;
	height: 6px;
	margin-left: 0.625rem;
	background-color: currentColor;
	-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6' fill='none'%3E%3Cpath d='M1.5 1.25 L5 4.25 L8.5 1.25' stroke='%23000' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat center / contain;
	mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6' fill='none'%3E%3Cpath d='M1.5 1.25 L5 4.25 L8.5 1.25' stroke='%23000' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat center / contain;
	vertical-align: 0.125em;
}

/* On mobile the chevron belongs to the toggle BUTTON, not the link: every
   dropdown parent is a real page (About Us > 49, Treatment > 97, Admissions >
   109), so tapping the label must navigate and only the chevron expands. */
@media (max-width: 1023.98px) {
	.site-header__menu .menu-item-has-children > a::after,
	.site-header__menu .has-chevron > a::after {
		display: none;
	}
}

/* Injected by main.js - progressive enhancement, so with JS off the sub-menus
   simply stay open (see .sub-menu default below) rather than being unreachable. */
.site-header__submenu-toggle {
	display: inline-flex;
	align-items: center;
	justify-content: flex-end; /* chevron stays pinned to the right edge */
	flex: 1; /* claims the rest of the row, so the gap toggles too */
	min-width: 44px;
	height: 44px; /* full 44px touch height */
	padding: 0 1rem 0 0; /* puts the chevron where a 44px centred one sat */
	background: transparent;
	border: 0;
	color: var(--color-white);
	cursor: pointer;
	transition: color var(--transition);
}

.site-header__submenu-toggle::after {
	content: "";
	width: 12px;
	height: 7px;
	background-color: currentColor;
	-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6' fill='none'%3E%3Cpath d='M1.5 1.25 L5 4.25 L8.5 1.25' stroke='%23000' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat center / contain;
	mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6' fill='none'%3E%3Cpath d='M1.5 1.25 L5 4.25 L8.5 1.25' stroke='%23000' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat center / contain;
	transition: transform 0.25s ease;
}

/* Open: chevron flips up and warms to caramel */
.site-header__submenu-toggle[aria-expanded="true"] {
	color: var(--color-caramel-light);
}

.site-header__submenu-toggle[aria-expanded="true"]::after {
	transform: rotate(180deg);
}

@media (prefers-reduced-motion: reduce) {
	.site-header__submenu-toggle::after {
		transition: none;
	}
}

.site-header__menu .sub-menu {
	list-style: none;
	margin: 0;
	padding: 0 0 0 var(--space-sm);
}

.site-header__menu .sub-menu a {
	font-weight: 400;
	font-size: 0.9375rem;
}

/* Mobile accordion. Scoped to a max-width query on purpose: these rules carry
   more specificity than the desktop .sub-menu block below, so unscoped they
   would collapse the desktop dropdown to max-height:0. */
@media (max-width: 1023.98px) {
	.site-header__menu .sub-menu {
		flex-basis: 100%;
		padding-bottom: var(--space-xs);
	}

	/* Collapsed only once JS marks the panel as enhanced, so with JS off the
	   sub-menus stay open and every link is still reachable. */
	.site-header__nav--accordion .sub-menu {
		max-height: 0;
		padding-block: 0;
		overflow: hidden;
		opacity: 0;
		transition: max-height 0.3s ease, opacity 0.25s ease, padding 0.3s ease;
	}

	.site-header__nav--accordion > .site-header__menu > li.is-expanded > .sub-menu {
		max-height: 22rem;
		padding-bottom: var(--space-xs);
		opacity: 1;
	}

	.site-header__menu .sub-menu a {
		padding: 0.5rem 0;
		color: rgb(255 255 255 / 0.78);
	}

	.site-header__menu .sub-menu a:hover,
	.site-header__menu .sub-menu a:focus-visible {
		color: var(--color-caramel-light);
	}

	@media (prefers-reduced-motion: reduce) {
		.site-header__nav--accordion .sub-menu {
			transition: none;
		}
	}
}

/* CTA inside the nav so mobile panel and desktop row share one source.
   Navbar CTA is more compact than section buttons (Figma: 164px wide).
   Doubled selector so it beats the later-in-source global .btn padding.
   margin-top:auto anchors it to the bottom of the full-height panel. */
.site-header__nav .site-header__cta {
	margin: var(--space-lg) var(--container-pad) var(--space-md);
	margin-top: auto;
	padding-inline: 1.75rem;
	flex-shrink: 0;
}

/* ---- Desktop (>= 1024px) ---- */

@media (min-width: 1024px) {
	.site-header__hamburger {
		display: none;
	}

	/* Undo the mobile sheet: the panel is just a row in the bar up here */
	.site-header__nav {
		position: static;
		display: flex;
		flex-direction: row;
		align-items: center;
		align-self: stretch;
		gap: var(--space-xl);
		height: auto;
		padding-bottom: 0;
		background: transparent;
		max-height: none;
		overflow: visible;
		visibility: visible;
		opacity: 1;
		transform: none;
		transition: none;
	}

	.site-header__submenu-toggle {
		display: none;
	}

	/* Menu fills the bar's full height (see .site-header__menu > li below) */
	.site-header__menu {
		display: flex;
		align-self: stretch;
		align-items: stretch;
		gap: var(--space-lg);
		padding: 0;
	}

	/* Tighter gaps on narrow desktops so the menu never wraps */
	@media (max-width: 1199.98px) {
		.site-header__nav,
		.site-header__menu {
			gap: var(--space-md);
		}
	}

	/* Items span the FULL bar height, so the panel below hangs off the header's
	   bottom edge (not the link's) and never overlaps the bar - and the whole
	   bar height is a hover target, so the pointer can't fall out of the menu. */
	.site-header__menu > li {
		position: relative;
		display: flex;
		flex-wrap: nowrap;
		align-items: center;
		border-bottom: 0; /* the mobile row hairline */
	}

	.site-header__menu a {
		padding: 0.5rem 0;
	}

	/* Chevron flips up while its panel is open */
	.site-header__menu .menu-item-has-children > a::after,
	.site-header__menu .has-chevron > a::after {
		transition: transform 0.2s ease;
	}

	.site-header__menu .menu-item-has-children:hover > a::after,
	.site-header__menu .menu-item-has-children:focus-within > a::after {
		transform: rotate(180deg);
	}

	/* Dropdown: a floating card that sits BELOW the bar with a small gap,
	   fading + easing down into place. Left-aligned so the child labels line
	   up under the parent's text. */
	.site-header__menu .sub-menu {
		position: absolute;
		top: calc(100% + 4px);
		left: calc(-1 * var(--space-md));
		min-width: 240px;
		padding: var(--space-xs) 0;
		/* Same teal as the bar so the panel reads as part of the nav; the shadow
		   + hairline separate it (it can sit over the homepage's teal hero). */
		background: var(--color-teal);
		border: 1px solid rgb(255 255 255 / 0.08);
		border-radius: var(--radius-sm);
		box-shadow: 0 18px 40px rgb(0 31 38 / 0.32);
		opacity: 0;
		visibility: hidden;
		/* Straight fade + small slide - no scale/overshoot (no bounce) */
		transform: translateY(-6px);
		transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
	}

	/* Invisible bridge across the gap so hover survives the pointer travelling
	   from the bar down onto the card */
	.site-header__menu .sub-menu::before {
		content: "";
		position: absolute;
		top: -4px;
		left: 0;
		right: 0;
		height: 4px;
	}

	.site-header__menu li:hover > .sub-menu,
	.site-header__menu li:focus-within > .sub-menu {
		opacity: 1;
		visibility: visible;
		transform: translateY(0);
	}

	.site-header__menu .sub-menu a {
		padding: 0.625rem var(--space-md);
		white-space: nowrap;
		transition: color 0.2s ease, background-color 0.2s ease;
	}

	.site-header__menu .sub-menu a:hover,
	.site-header__menu .sub-menu a:focus-visible {
		color: var(--color-caramel-light);
		background: rgb(255 255 255 / 0.07);
	}

	@media (prefers-reduced-motion: reduce) {
		.site-header__menu .sub-menu,
		.site-header__menu .sub-menu,
		.site-header__menu .menu-item-has-children > a::after {
			transition: opacity 0.01s linear, visibility 0.01s linear;
			transform: none;
		}

		.site-header__menu li:hover > .sub-menu,
		.site-header__menu li:focus-within > .sub-menu {
			transform: none;
		}
	}

	.site-header__nav .site-header__cta {
		margin: 0;
	}
}
