/**
 * Pinterest First Editorial - Header, navigation & search.
 *
 * Premium editorial header: brand, desktop primary navigation, search access
 * and the mobile navigation drawer / search overlay.
 *
 * All shared values come from tokens.css. The few component-specific values
 * that have no token are declared as local custom properties on
 * .pfe-site-header below (Docs/ARCHITECTURE.md, CSS Rules).
 *
 * @package Pinterest_First_Editorial
 */

/* -------------------------------------------------------------------------
 * Component-specific values
 * ---------------------------------------------------------------------- */

.pfe-site-header {
	--pfe-header-min-height: var(--pfe-space-10); /* 64px bar height */
	--pfe-header-logo-max-height: var(--pfe-space-8); /* 40px logo cap */
	--pfe-header-border-width: 1px;
	--pfe-header-underline-width: 2px;
	--pfe-header-backdrop-color: rgba(28, 27, 26, 0.45); /* from --pfe-color-text */
	--pfe-header-drawer-width: min(86vw, 22rem);
	--pfe-header-search-max-width: 40rem;
}

/* -------------------------------------------------------------------------
 * Shared utilities
 * ---------------------------------------------------------------------- */

.pfe-visually-hidden {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.pfe-scroll-locked,
.pfe-scroll-locked body {
	overflow: hidden;
}

/* -------------------------------------------------------------------------
 * Skip link - off-screen until focused, then visible above the header.
 * ---------------------------------------------------------------------- */

.pfe-skip-link {
	--pfe-skip-border-width: 1px; /* skip link is outside the header subtree */

	position: absolute;
	inset-inline-start: var(--pfe-space-4);
	inset-block-start: 0;
	z-index: var(--pfe-z-skip-link);
	transform: translateY(-120%);
	padding: var(--pfe-space-3) var(--pfe-space-5);
	background-color: var(--pfe-color-surface);
	color: var(--pfe-color-text);
	border: var(--pfe-skip-border-width) solid var(--pfe-color-border);
	border-radius: var(--pfe-radius-sm);
	box-shadow: var(--pfe-shadow-md);
	font-size: var(--pfe-font-size-sm);
	font-weight: var(--pfe-font-weight-semibold);
	text-decoration: none;
	transition: transform var(--pfe-transition-fast);
}

.pfe-skip-link:focus {
	transform: translateY(var(--pfe-space-3));
}

/* -------------------------------------------------------------------------
 * Header shell
 * ---------------------------------------------------------------------- */

.pfe-site-header {
	position: relative;
	z-index: var(--pfe-z-header);
	background-color: var(--pfe-color-surface);
	border-block-end: var(--pfe-header-border-width) solid var(--pfe-color-border);
}

.pfe-site-header__inner {
	display: flex;
	align-items: center;
	gap: var(--pfe-space-4);
	min-height: var(--pfe-header-min-height);
	padding-block: var(--pfe-space-2);
}

/* -------------------------------------------------------------------------
 * Brand - custom logo or site-title fallback.
 * ---------------------------------------------------------------------- */

.pfe-brand {
	display: flex;
	align-items: center;
	min-width: 0;
}

.pfe-brand__link {
	display: inline-flex;
	align-items: center;
	min-height: var(--pfe-tap-target);
	color: var(--pfe-color-text);
	text-decoration: none;
}

.pfe-brand__link:hover {
	color: var(--pfe-color-accent-strong);
}

.pfe-brand__name {
	font-size: var(--pfe-font-size-xl);
	font-weight: var(--pfe-font-weight-bold);
	letter-spacing: var(--pfe-tracking-tight);
	line-height: var(--pfe-leading-tight);
}

.pfe-brand .custom-logo-link {
	display: inline-flex;
	align-items: center;
}

.pfe-brand .custom-logo {
	display: block;
	width: auto;
	max-height: var(--pfe-header-logo-max-height);
}

/* -------------------------------------------------------------------------
 * Header actions - search always; menu toggle on mobile only.
 * ---------------------------------------------------------------------- */

.pfe-site-header__actions {
	display: flex;
	align-items: center;
	gap: var(--pfe-space-2);
	margin-inline-start: auto;
}

.pfe-icon-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: var(--pfe-tap-target);
	height: var(--pfe-tap-target);
	padding: 0;
	border: var(--pfe-header-border-width) solid transparent;
	border-radius: var(--pfe-radius-sm);
	background-color: transparent;
	color: var(--pfe-color-text);
	cursor: pointer;
	transition: color var(--pfe-transition-fast),
		background-color var(--pfe-transition-fast),
		border-color var(--pfe-transition-fast);
}

.pfe-icon-button:hover {
	background-color: var(--pfe-color-surface-muted);
	color: var(--pfe-color-accent-strong);
}

.pfe-icon {
	display: block;
}

/* -------------------------------------------------------------------------
 * Desktop primary navigation
 * ---------------------------------------------------------------------- */

.pfe-desktop-nav {
	display: none;
}

.pfe-menu {
	display: flex;
	align-items: center;
	gap: var(--pfe-space-5);
	margin: 0;
	padding: 0;
	list-style: none;
}

/* The desktop menu wraps its items onto a second line rather than forcing the
 * header row wider than the container when a publisher menu has more entries
 * than a tablet-width header can hold. Short menus keep the documented single,
 * compact row (Docs/DESIGN_SYSTEM.md #15; Docs/IMPLEMENTATION_PLAN.md,
 * Phase 12). */
.pfe-menu--primary {
	flex-wrap: wrap;
}

.pfe-menu a {
	position: relative;
	display: inline-flex;
	align-items: center;
	min-height: var(--pfe-tap-target);
	color: var(--pfe-color-text);
	font-size: var(--pfe-font-size-sm);
	font-weight: var(--pfe-font-weight-medium);
	line-height: var(--pfe-leading-normal);
	text-decoration: none;
}

.pfe-menu a::after {
	content: "";
	position: absolute;
	inset-inline: 0;
	inset-block-end: var(--pfe-space-2);
	height: var(--pfe-header-underline-width);
	background-color: currentColor;
	transform: scaleX(0);
	transform-origin: left center;
	transition: transform var(--pfe-transition-fast);
}

.pfe-menu a:hover {
	color: var(--pfe-color-accent-strong);
}

.pfe-menu a:hover::after,
.pfe-menu .current-menu-item > a::after,
.pfe-menu .current-menu-ancestor > a::after {
	transform: scaleX(1);
}

.pfe-menu .current-menu-item > a,
.pfe-menu .current-menu-ancestor > a {
	color: var(--pfe-color-accent-strong);
}

/* -------------------------------------------------------------------------
 * Mobile navigation drawer - hidden until opened by navigation.js.
 * ---------------------------------------------------------------------- */

.pfe-mobile-nav {
	display: none;
	position: fixed;
	inset: 0;
	z-index: var(--pfe-z-overlay);
}

.pfe-mobile-nav.is-open {
	display: block;
}

.pfe-mobile-nav__backdrop {
	position: absolute;
	inset: 0;
	background-color: var(--pfe-header-backdrop-color);
}

.pfe-mobile-nav__panel {
	position: absolute;
	inset-block: 0;
	inset-inline-end: 0;
	display: flex;
	flex-direction: column;
	gap: var(--pfe-space-4);
	width: var(--pfe-header-drawer-width);
	max-width: 100%;
	padding: var(--pfe-space-5);
	background-color: var(--pfe-color-surface);
	border-inline-start: var(--pfe-header-border-width) solid var(--pfe-color-border);
	box-shadow: var(--pfe-shadow-md);
	overflow-y: auto;
}

.pfe-mobile-nav__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.pfe-mobile-nav__title {
	font-size: var(--pfe-font-size-xs);
	font-weight: var(--pfe-font-weight-semibold);
	letter-spacing: var(--pfe-tracking-wide);
	text-transform: uppercase;
	color: var(--pfe-color-text-secondary);
}

.pfe-menu--mobile {
	flex-direction: column;
	align-items: stretch;
	gap: 0;
}

.pfe-menu--mobile li {
	border-block-end: var(--pfe-header-border-width) solid var(--pfe-color-border);
}

.pfe-menu--mobile a {
	width: 100%;
	min-height: var(--pfe-tap-target);
	font-size: var(--pfe-font-size-md);
}

.pfe-menu--mobile a::after {
	content: none;
}

/* -------------------------------------------------------------------------
 * Search overlay - hidden until opened by search.js.
 * ---------------------------------------------------------------------- */

.pfe-search-overlay {
	display: none;
	position: fixed;
	inset: 0;
	z-index: var(--pfe-z-overlay);
}

.pfe-search-overlay.is-open {
	display: block;
}

.pfe-search-overlay__backdrop {
	position: absolute;
	inset: 0;
	background-color: var(--pfe-header-backdrop-color);
}

.pfe-search-overlay__panel {
	position: relative;
	width: min(
		calc(100% - (var(--pfe-gutter) * 2)),
		var(--pfe-header-search-max-width)
	);
	margin-inline: auto;
	margin-block-start: var(--pfe-space-8);
	padding: var(--pfe-space-5);
	background-color: var(--pfe-color-surface);
	border-radius: var(--pfe-radius-md);
	box-shadow: var(--pfe-shadow-md);
}

.pfe-search-form {
	display: flex;
	align-items: center;
	gap: var(--pfe-space-3);
}

.pfe-search-form__field {
	flex: 1 1 auto;
	min-width: 0;
	min-height: var(--pfe-tap-target);
	padding-inline: var(--pfe-space-4);
	border: var(--pfe-header-border-width) solid var(--pfe-color-border);
	border-radius: var(--pfe-radius-sm);
	background-color: var(--pfe-color-bg);
	color: var(--pfe-color-text);
	font-family: inherit;
	font-size: var(--pfe-font-size-md);
}

.pfe-search-form__field:focus {
	border-color: var(--pfe-color-accent);
}

.pfe-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: var(--pfe-tap-target);
	padding-inline: var(--pfe-space-5);
	border: var(--pfe-header-border-width) solid var(--pfe-color-accent-strong);
	border-radius: var(--pfe-radius-sm);
	background-color: var(--pfe-color-accent-strong);
	color: var(--pfe-color-on-accent);
	font-family: inherit;
	font-size: var(--pfe-font-size-sm);
	font-weight: var(--pfe-font-weight-semibold);
	text-decoration: none;
	cursor: pointer;
	transition: background-color var(--pfe-transition-fast),
		border-color var(--pfe-transition-fast);
}

.pfe-button:hover {
	background-color: var(--pfe-color-accent-hover);
	border-color: var(--pfe-color-accent-hover);
}

/* -------------------------------------------------------------------------
 * Tablet and up - desktop navigation replaces the mobile toggle, and the
 * header becomes sticky only when enabled in Theme Settings. The body class
 * is server-rendered (no JavaScript), and the rule stays inside this media
 * query so mobile is never sticky (Docs/DECISIONS.md #19).
 * ---------------------------------------------------------------------- */

@media (min-width: 768px) {

	.pfe-sticky-header-enabled .pfe-site-header {
		position: sticky;
		inset-block-start: 0;
	}

	.pfe-desktop-nav {
		display: block;
		margin-inline-start: var(--pfe-space-6);
	}

	.pfe-menu-toggle,
	.pfe-mobile-nav,
	.pfe-mobile-nav.is-open {
		display: none;
	}
}
