/**
 * Site header: template-parts/header/header.php and primary-nav.php.
 * Mobile first (Mobile 2286:3402, header 2288:1058), desktop from 1280
 * (Homepage 2060:18). Sticky; the top bar above it scrolls away.
 * Hover, current and sticky states are not designed: docs/designer-questions.md item 8.
 */

.site-header {
	position: sticky;
	top: var(--wp-admin--admin-bar--height, 0px);
	z-index: 50;
	background: var(--color-white);
	transition: box-shadow 0.2s ease, margin-bottom 0.2s ease;
}

/* Stuck (navigation.js): a shadow separates the white bar from white sections.
 * On the full-width bar, not on .site-header__inner, which stops at 1660px. */
.site-header.is-stuck {
	box-shadow: var(--shadow-header);
}

.site-header__inner {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--space-sm);
	box-sizing: content-box;
	max-width: var(--container-max);
	margin: 0 auto;
	padding: 4px var(--container-gutter);
	transition: padding 0.2s ease;
}

/* Stuck: a little less padding. The bottom margin gives the same height back
 * to the page flow (a sticky header keeps its flow place up where it started,
 * out of view), so nothing below shifts. Without it the browser's scroll
 * anchoring moved the page back over the threshold and the header flickered
 * between the two states. */
.site-header.is-stuck {
	margin-bottom: 4px;
}

.site-header.is-stuck .site-header__inner {
	padding-block: 2px;
}

.site-header__start {
	display: flex;
	flex: none;
	align-items: center;
	gap: 10px;
}

.site-header__logo {
	display: block;
	flex: none;
	line-height: 0;
}

.site-header__logo-img {
	display: block;
	width: 110px;
	height: 40px;
	transform-origin: left center;
	transition: transform 0.2s ease;
}

/* The logo shrinks while the header is stuck (transform, so it does not
 * change the layout by itself). */
.site-header.is-stuck .site-header__logo-img {
	transform: scale(0.9);
}

@media (prefers-reduced-motion: reduce) {
	.site-header,
	.site-header__inner,
	.site-header__logo-img {
		transition: none;
	}
}

/* Menu button (mobile only): list icon, x while the menu is open. */

.site-header__menu-btn {
	display: inline-flex;
	flex: none;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--color-cream);
	color: var(--color-ink);
	cursor: pointer;
}

.site-header__menu-close,
.site-header__menu-btn[aria-expanded="true"] .site-header__menu-open {
	display: none;
}

.site-header__menu-btn[aria-expanded="true"] .site-header__menu-close {
	display: block;
}

/* Utilities: search, account, cart. */

.site-header__utilities {
	display: flex;
	flex: none;
	align-items: center;
	gap: 5px;
}

.site-header__utilities .icon-btn {
	width: 32px;
	height: 32px;
}

.site-header__utilities .icon-btn svg {
	width: 16px;
	height: 16px;
}

/* A button that opens the mini cart. */
.cart-pill {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	margin: 0;
	padding: 6px 6px 6px 10px;
	border: 0;
	font-family: inherit;
	cursor: pointer;
	border-radius: var(--radius-pill);
	background: var(--color-green-dark);
	color: var(--color-cream);
	font-size: var(--text-label-m);
	font-weight: var(--weight-semibold);
	line-height: var(--leading-label-m);
	text-decoration: none;
}

.cart-pill__icon {
	width: 16px;
	height: 16px;
}

.cart-pill:hover {
	background: var(--color-green);
}

/* The label is hidden on mobile but stays the link's accessible name. */
.cart-pill__label {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
}

.cart-pill__count {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 20px;
	height: 20px;
	box-sizing: border-box;
	padding: 0 4px;
	border-radius: var(--radius-pill);
	background: var(--color-orange);
	color: var(--color-cream);
	font-size: 10px;
	letter-spacing: var(--tracking-label-s);
	line-height: var(--leading-label-s);
}

/* Primary navigation: desktop only. */

.primary-nav {
	display: none;
}

.primary-nav__list {
	display: flex;
	align-items: center;
	gap: 6px;
	margin: 0;
	padding: 6px 6px 6px 14px;
	border-radius: var(--radius-pill);
	background: var(--color-cream);
	list-style: none;
}

.primary-nav__link {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 12px 14px;
	border-radius: var(--radius-pill);
	color: var(--color-ink);
	font-size: var(--text-label-m);
	font-weight: var(--weight-semibold);
	line-height: var(--leading-label-m);
	text-decoration: none;
	white-space: nowrap;
}

.primary-nav__item--category .primary-nav__link {
	min-height: 48px;
	box-sizing: border-box;
	padding: 6px 14px 6px 6px;
}

.primary-nav__link:hover,
.primary-nav__link[aria-current="page"] {
	background: var(--color-white);
}

/* Sized by its width and height attributes (no auto size), so the nav has its
 * final width before the image loads; the max values cap uploaded thumbnails. */
.primary-nav__thumb {
	display: block;
	flex: none;
	max-width: 36px;
	max-height: 36px;
	object-fit: contain;
}

.primary-nav__chevron {
	flex: none;
}

/* Desktop. The container gutter (tokens.css) leaves room for the header. */
@media (min-width: 1280px) {
	.site-header__inner {
		gap: var(--space-md);
		padding: 22px var(--container-gutter);
	}

	.site-header__menu-btn {
		display: none;
	}

	.site-header__logo-img {
		width: 173px;
		height: 63px;
	}

	.site-header.is-stuck {
		margin-bottom: 20px;
	}

	.site-header.is-stuck .site-header__inner {
		padding-block: 12px;
	}

	.site-header.is-stuck .site-header__logo-img {
		transform: scale(0.8);
	}

	.primary-nav {
		display: block;
	}

	.site-header__utilities {
		gap: 8px;
	}

	.site-header__utilities .icon-btn {
		width: var(--icon-button-size);
		height: var(--icon-button-size);
	}

	.site-header__utilities .icon-btn svg,
	.cart-pill__icon {
		width: 20px;
		height: 20px;
	}

	.cart-pill {
		gap: 8px;
		padding: 8px 8px 8px 16px;
	}

	.cart-pill__label {
		position: static;
		width: auto;
		height: auto;
		overflow: visible;
		clip: auto;
	}

	.cart-pill__count {
		min-width: 30px;
		height: 30px;
		padding: 0 6px;
		font-size: var(--text-label-s);
	}
}

/* A short bounce when an item is added (motion.js). */
.cart-pill__count.is-bumped {
	animation: cart-bump 0.5s ease;
}

@keyframes cart-bump {
	30% {
		transform: scale(1.3);
	}

	60% {
		transform: scale(0.9);
	}

	80% {
		transform: scale(1.05);
	}
}

@media (prefers-reduced-motion: reduce) {
	.primary-nav__link,
	.cart-pill {
		transition: none;
	}

	.cart-pill__count.is-bumped {
		animation: none;
	}
}
