/**
 * Header Styles
 *
 * Desktop: mega menu panel, hover-triggered, CSS transitions.
 * Mobile: right-side drawer, hamburger toggle, accordion submenus.
 * All colors via CSS custom properties from theme.json.
 * Dynamic content via MEGA_NAV and HEADER_CTA token replacement.
 */

/* -----------------------------------------------
   Variables
   ----------------------------------------------- */

.ad-header {
	--ad-header-height: 5rem;
	--ad-header-bg: var(--wp--preset--color--base);
	--ad-header-text: var(--wp--preset--color--primary);
	--ad-header-accent: var(--wp--preset--color--accent);
	--ad-header-muted: var(--wp--preset--color--muted);
	--ad-header-radius: 0.25rem;
	--ad-header-transition: 0.25s ease;
	--ad-header-padding-x: clamp(1rem, 4vw, 4rem);
}

/* Sticky header — applied to the wp-block-template-part wrapper
   because sticky only works relative to the nearest scrolling ancestor.
   The .ad-header itself is inside a same-height wrapper, so sticky
   must go on the wrapper which is a direct child of .wp-site-blocks. */
.wp-block-template-part:has(.ad-header) {
	position: sticky;
	top: 0;
	z-index: 1000;
}

/* -----------------------------------------------
   Bar
   ----------------------------------------------- */

.ad-header__bar {
	position: relative;
	height: var(--ad-header-height);
}

.ad-header__buttons {
	display: none;
	align-items: center;
	gap: 0.5rem;
}

@media (min-width: 1200px) {
	.ad-header__buttons {
		display: flex;
	}
}

/*
 * Desktop CTA buttons inherit from .ad-btn (global.css).
 * Header-specific overrides only.
 */
.ad-header__buttons .ad-btn {
	padding: 0.75rem 1rem;
	font-size: var(--wp--preset--font-size--xs);
}

.ad-header__drawer-buttons {
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
	margin-top: 1.5rem;
	padding-top: 1.5rem;
	border-top: 1px solid var(--ad-header-muted);
}

/*
 * Drawer CTA buttons inherit from .ad-btn (global.css).
 * Drawer-specific overrides: full-width, larger padding.
 */
.ad-header__drawer-buttons .ad-btn {
	display: flex;
	justify-content: center;
	padding: 0.75rem 1.5rem;
	font-size: var(--wp--preset--font-size--md);
}

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

.ad-header__logo a {
	display: flex;
	align-items: center;
	text-decoration: none;
}

.ad-header__logo a:focus-visible {
	outline: 2px solid var(--ad-header-accent);
	outline-offset: 2px;
}

.ad-header__logo img {
	display: block;
	width: 280px;
	height: auto;
}

/* -----------------------------------------------
   Desktop Nav
   ----------------------------------------------- */

.ad-header__nav-desktop {
	display: none;
}

@media (min-width: 1200px) {
	.ad-header__nav-desktop {
		display: block;
	}
}

.ad-header__menu {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	list-style: none;
	margin: 0;
	padding: 0;
}

.ad-header__menu-item {
	display: flex;
	align-items: center;
}

.ad-header__menu-link {
	display: inline-flex;
	align-items: center;
	gap: 0.25rem;
	padding: 0.5rem 0.75rem;
	border: none;
	border-radius: var(--ad-header-radius);
	background: none;
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--md);
	font-weight: 400;
	line-height: 1;
	color: var(--ad-header-text);
	text-decoration: none;
	cursor: pointer;
	transition: color var(--ad-header-transition);
}

.ad-header__menu-link:hover,
.ad-header__menu-link:focus-visible {
	color: var(--ad-header-accent);
}

.ad-header__menu-link:focus-visible {
	outline: 2px solid var(--ad-header-accent);
	outline-offset: 2px;
}

.ad-header__chevron {
	transition: transform var(--ad-header-transition);
}

.ad-header__menu-link--trigger[aria-expanded="true"] .ad-header__chevron {
	transform: rotate(180deg);
}

/* -----------------------------------------------
   Secondary Nav (desktop)
   ----------------------------------------------- */

.ad-header__nav-secondary {
	display: none;
}

@media (min-width: 1200px) {
	.ad-header__nav-secondary {
		display: block;
	}
}

.ad-header__secondary-menu {
	display: flex;
	align-items: center;
	gap: 0.25rem;
	list-style: none;
	margin: 0;
	padding: 0;
}

.ad-header__secondary-link {
	display: inline-flex;
	align-items: center;
	padding: 0.5rem 0.75rem;
	border-radius: var(--ad-header-radius);
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--sm);
	font-weight: 400;
	line-height: 1;
	color: var(--wp--preset--color--gray-dark);
	text-decoration: none;
	transition: color var(--ad-header-transition);
}

.ad-header__secondary-link:hover,
.ad-header__secondary-link:focus-visible {
	color: var(--ad-header-accent);
}

.ad-header__secondary-link:focus-visible {
	outline: 2px solid var(--ad-header-accent);
	outline-offset: 2px;
}

/* Donate link styled as a filled button */
.ad-header__secondary-link--donate {
	padding: 0.625rem 0.875rem;
	font-size: var(--wp--preset--font-size--xs);
	border: 1px solid var(--wp--preset--color--primary);
	background-color: var(--wp--preset--color--primary);
	color: var(--wp--preset--color--secondary);
	font-weight: 500;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	transition: opacity var(--ad-header-transition);
}

.ad-header__secondary-link--donate:hover {
	color: var(--wp--preset--color--secondary);
	opacity: 0.85;
}

.ad-header__secondary-link--donate:focus-visible {
	color: var(--wp--preset--color--secondary);
}

/* Mobile drawer: Donate as full-width button */
.ad-header__drawer-item--donate {
	border-bottom: none;
	padding: 0.75rem var(--ad-header-padding-x);
	margin-top: 0.75rem;
}

.ad-header__drawer-item--donate .ad-header__drawer-link {
	display: flex;
	justify-content: center;
	padding: 0.75rem 1.5rem;
	border: 1px solid var(--wp--preset--color--primary);
	border-radius: var(--ad-header-radius);
	background-color: var(--wp--preset--color--primary);
	color: var(--wp--preset--color--secondary);
	font-size: var(--wp--preset--font-size--md);
	font-weight: 500;
	text-transform: uppercase;
	letter-spacing: 0.04em;
}

.ad-header__drawer-item--donate .ad-header__drawer-link:hover {
	color: var(--wp--preset--color--secondary);
	opacity: 0.85;
}

/* -----------------------------------------------
   Mega Panel
   ----------------------------------------------- */

.ad-header__menu-item--has-children {
	position: relative;
}

.ad-header__mega-panel {
	position: absolute;
	top: 100%;
	left: 0;
	z-index: 999;
	width: max-content;
	max-width: 40rem;
	background-color: var(--ad-header-bg);
	border: 1px solid var(--ad-header-muted);
	border-radius: var(--ad-header-radius);
	box-shadow: var(--ad-shadow-md);
	opacity: 0;
	visibility: hidden;
	transition:
		opacity var(--ad-header-transition),
		visibility var(--ad-header-transition);
}

.ad-header__mega-panel.is-open {
	opacity: 1;
	visibility: visible;
}

.ad-header__mega-panel-inner {
	display: flex;
	gap: 0;
	padding: 1.5rem;
}

/* Left column: parent title + description */
.ad-header__mega-panel-info {
	flex: 0 0 45%;
	padding-right: 1.5rem;
	border-right: 1px solid var(--ad-header-muted);
}

.ad-header__mega-panel-title {
	margin: 0 0 0.75rem;
	font-family: var(--wp--preset--font-family--heading);
	font-size: var(--wp--preset--font-size--lg);
	font-weight: 500;
	line-height: 1.3;
	color: var(--ad-header-text);
}

.ad-header__mega-panel-desc {
	margin: 0;
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--sm);
	font-weight: 400;
	line-height: 1.6;
	color: var(--wp--preset--color--gray-dark);
}

/* Right column: child links */
.ad-header__mega-panel-links {
	list-style: none;
	margin: 0;
	padding: 0 0 0 1.5rem;
	display: flex;
	flex: 1;
	flex-direction: column;
	gap: 0.25rem;
}

.ad-header__mega-link {
	display: block;
	padding: 0.5rem 0.75rem;
	border-radius: var(--ad-header-radius);
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--md);
	font-weight: 500;
	color: var(--ad-header-text);
	text-decoration: none;
	transition: background-color var(--ad-header-transition);
}

.ad-header__mega-link:hover,
.ad-header__mega-link:focus-visible {
	background-color: var(--ad-header-muted);
}

.ad-header__mega-link:focus-visible {
	outline: 2px solid var(--ad-header-accent);
	outline-offset: 2px;
}

.ad-header__mega-link-label {
	font-size: inherit;
	font-weight: inherit;
	line-height: 1.4;
}

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

.ad-header__drawer-toggle {
	position: relative;
	z-index: 1002;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	margin-left: auto;
	padding: 0;
	border: none;
	background: none;
	cursor: pointer;
}

.ad-header__drawer-toggle:focus-visible {
	outline: 2px solid var(--ad-header-accent);
	outline-offset: 2px;
}

@media (min-width: 1200px) {
	.ad-header__drawer-toggle {
		display: none;
	}
}

.ad-header__hamburger {
	display: flex;
	flex-direction: column;
	justify-content: center;
	gap: 7px;
	width: 32px;
	height: 32px;
}

.ad-header__hamburger span {
	display: block;
	width: 100%;
	height: 2px;
	background-color: var(--ad-header-text);
	border-radius: 1px;
	transition: transform var(--ad-header-transition), opacity var(--ad-header-transition);
}

.ad-header__drawer-toggle[aria-expanded="true"] .ad-header__hamburger span:nth-child(1) {
	transform: translateY(9px) rotate(45deg);
}

.ad-header__drawer-toggle[aria-expanded="true"] .ad-header__hamburger span:nth-child(2) {
	opacity: 0;
}

.ad-header__drawer-toggle[aria-expanded="true"] .ad-header__hamburger span:nth-child(3) {
	transform: translateY(-9px) rotate(-45deg);
}

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

.ad-header__drawer {
	position: fixed;
	inset: 0;
	z-index: 1001;
	width: 100vw;
	height: 100vh;
	background-color: var(--ad-header-bg);
	opacity: 0;
	visibility: hidden;
	transition: opacity var(--ad-header-transition), visibility var(--ad-header-transition);
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
}

.admin-bar .ad-header__drawer {
	top: 32px;
	height: calc(100vh - 32px);
}

@media (max-width: 782px) {
	.admin-bar .ad-header__drawer {
		top: 46px;
		height: calc(100vh - 46px);
	}
}

.ad-header__drawer.is-open {
	opacity: 1;
	visibility: visible;
}

.ad-header__drawer-inner {
	padding: 1rem 0 2rem;
}

.ad-header__drawer-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 0;
	padding: 0 var(--ad-header-padding-x) 1rem;
	border-bottom: 1px solid var(--ad-header-muted);
}

.ad-header__drawer-logo {
	display: flex;
	align-items: center;
}

.ad-header__drawer-logo:focus-visible {
	outline: 2px solid var(--ad-header-accent);
	outline-offset: 2px;
}

.ad-header__drawer-logo img {
	display: block;
	width: 220px;
	height: auto;
}

.ad-header__drawer-close {
	display: none;
}

.ad-header__drawer-close:focus-visible {
	outline: 2px solid var(--ad-header-accent);
	outline-offset: 2px;
}

.ad-header__drawer-menu {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 0;
}

.ad-header__drawer-item {
	border-bottom: 1px solid var(--ad-header-muted);
}

.ad-header__drawer-link {
	display: flex;
	align-items: center;
	justify-content: space-between;
	width: 100%;
	padding: 1.25rem var(--ad-header-padding-x);
	border: none;
	background: none;
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--lg);
	font-weight: 500;
	color: var(--ad-header-text);
	text-decoration: none;
	text-align: left;
	cursor: pointer;
}

.ad-header__drawer-link:hover,
.ad-header__drawer-link:focus-visible {
	color: var(--ad-header-text);
}

.ad-header__drawer-link:focus-visible {
	outline: 2px solid var(--ad-header-accent);
	outline-offset: 2px;
}

.ad-header__drawer-accordion-trigger .ad-header__chevron {
	width: 20px;
	height: 20px;
	flex-shrink: 0;
	margin-right: 0.25rem;
	transition: transform var(--ad-header-transition);
}

.ad-header__drawer-accordion-trigger[aria-expanded="true"] .ad-header__chevron {
	transform: rotate(180deg);
}

/* Accordion submenu */

.ad-header__drawer-submenu {
	list-style: none;
	margin: 0;
	padding: 0;
	max-height: 0;
	overflow: hidden;
	background-color: var(--wp--preset--color--secondary);
	transition: max-height var(--ad-header-transition);
}

.ad-header__drawer-submenu.is-open {
	max-height: 40rem;
	padding-bottom: 1rem;
}

.ad-header__drawer-submenu a {
	display: block;
	padding: 1.125rem var(--ad-header-padding-x) 1.125rem calc(var(--ad-header-padding-x) + 1rem);
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--md);
	font-weight: 400;
	color: var(--ad-header-text);
	text-decoration: none;
	border-bottom: 1px solid var(--ad-header-muted);
}

.ad-header__drawer-submenu li:last-child a {
	border-bottom: none;
}

.ad-header__drawer-submenu a:hover,
.ad-header__drawer-submenu a:focus-visible {
	color: var(--ad-header-text);
}

.ad-header__drawer-submenu a:focus-visible {
	outline: 2px solid var(--ad-header-accent);
	outline-offset: 2px;
}

/* -----------------------------------------------
   Overlay
   ----------------------------------------------- */

.ad-header__overlay {
	position: fixed;
	inset: 0;
	z-index: 1000;
	background-color: var(--ad-header-text);
	opacity: 0;
	visibility: hidden;
	transition: opacity var(--ad-header-transition), visibility var(--ad-header-transition);
}

.ad-header__overlay.is-active {
	opacity: 0.5;
	visibility: visible;
}

/* -----------------------------------------------
   Reduced Motion
   ----------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
	.ad-header__mega-panel,
	.ad-header__drawer,
	.ad-header__drawer-submenu,
	.ad-header__overlay,
	.ad-header__hamburger span,
	.ad-header__chevron,
	.ad-header__menu-link,
	.ad-header__mega-link,
	.ad-header__drawer-link,
	.ad-btn {
		transition: none;
	}
}
