/**
 * Header search: the live search dropdown (G8; template-parts/header/search.php,
 * js/header-search.js). Loaded with the header when Site Manager "Header
 * search" is on.
 *
 * Measured from design/search/required-active-state.png at 1920 (TODO: verify
 * in Figma):
 * - The box: 340 x 40 at the container's end edge, a 1px orange border, a
 *   ~16px search icon ~16px from the start, the text (17px), a ~10px × at the
 *   end. It covers the CTAs and the toggle (hidden, so nothing moves). It never
 *   covers a nav item: the script measures the room from the last nav item
 *   (plus the nav's gap) to the box's end edge into --hs-box-width, on open and
 *   on resize; the box is 340px at most and shrinks when the room is narrower
 *   (325px at 1280). 340px when unmeasured.
 * - The panel: 644px wide, end-aligned, overlapping the bar's bottom by ~9px,
 *   at most ~535px tall (and the viewport), white with the panel shadow, a
 *   thin scrollbar, a bottom fade while more is below; padding ~28px top,
 *   ~41px start, ~32px end.
 * - Group header: the label (17px Roboto 500) and "Found N results" (14px
 *   #666666) over a 1px #ebebeb hairline. Result: a title (17px/24px) over a
 *   two-line snippet (14px/20px #666666); matches orange and bold (2.79:1
 *   with bold, the orange-text decision).
 * - Not in the frame (TODO): the highlighted result (a light tint), the
 *   sticky "See all N results" link, the loading, empty and error messages.
 * Mobile and tablet (a PROPOSAL, no frame): the field at the top of the
 * drawer, the results in a full-width panel under it inside the drawer,
 * "See all" sticky, rows of 48px or more.
 * Tokens are local to the component. Logical properties only.
 *
 * @package cartrack
 */

.header-search {
	--hs-box-max: 21.25rem;               /* ~340px. */
	--hs-box-height: 2.5rem;              /* ~40px. */
	--hs-border: var(--color-primary);
	--hs-panel-width: 40.25rem;           /* ~644px. */
	--hs-panel-max: 33.4rem;              /* ~535px. */
	--hs-overlap: 0.5625rem;              /* ~9px over the bar's bottom edge. */
	--hs-pad-block: 1.75rem;              /* ~28px. */
	--hs-pad-start: 2.5625rem;            /* ~41px. */
	--hs-pad-end: 2rem;                   /* ~32px. */
	--hs-muted: #666666;                  /* Sampled ("Found N", snippets). */
	--hs-rule: #ebebeb;
	--hs-active: #f3f6f9;                 /* TODO: the highlighted result (not in the frame). */
	--hs-mark: var(--color-text-accent);
	--hs-fade: 3rem;
	--hs-icon: 1rem;
}

/* ---------- The toggle: a link without JS, a button with it; the same box ---------- */

.site-header__search-toggle {
	box-sizing: border-box;
	margin: 0;
	font-family: inherit;
	line-height: 1;
	text-decoration: none;
	appearance: none;
}

.site-header__search-toggle:focus-visible {
	outline: 2px solid var(--color-focus-dark);
	outline-offset: 2px;
}

/* While the search is open, the CTAs and the toggle keep their space under the box. */
.site-header.is-search-open .site-nav__ctas,
.site-header.is-search-open .site-header__search-toggle {
	visibility: hidden;
}

/* ---------- The box ---------- */

.header-search[hidden] {
	display: none;
}

.header-search__form {
	position: relative;
	margin: 0;
}

.header-search__box {
	display: flex;
	align-items: center;
	gap: 0.6875rem;                       /* ~11px icon to text. */
	block-size: var(--hs-box-height);
	padding-inline-start: var(--space-sm);
	border: 1px solid var(--hs-border);
	background-color: var(--color-bg);
	color: var(--color-text);
}

.header-search__box > .icon {
	flex: none;
	inline-size: var(--hs-icon);
	block-size: var(--hs-icon);
}

.header-search__input {
	flex: 1 1 auto;
	min-inline-size: 0;
	block-size: 100%;
	margin: 0;
	padding: 0;
	border: 0;
	background: transparent;
	color: inherit;
	font-family: var(--t-body-family);
	font-size: max(1rem, var(--t-body-size)); /* 16px or more: no zoom on phones. */
	line-height: 1.2;
	appearance: none;
}

.header-search__input::-webkit-search-cancel-button,
.header-search__input::-webkit-search-decoration {
	appearance: none;
}

.header-search__input:focus {
	outline: none;
}

/*
 * The frame shows the focused box with its orange border only (the box appears
 * on focus, with the caret in it), so the field adds no outer ring; the × and
 * "See all" have rings. In the drawer, where the field is always shown, the
 * focused field gets the dark ring (TODO designer).
 */
.header-search--drawer .header-search__box:focus-within {
	outline: 2px solid var(--color-focus-dark);
	outline-offset: 2px;
}

.header-search__clear {
	display: inline-flex;
	flex: none;
	align-items: center;
	justify-content: center;
	inline-size: var(--hs-box-height);
	block-size: 100%;
	padding: 0;
	border: 0;
	background: none;
	color: var(--color-text);
	cursor: pointer;
}

.header-search__clear[hidden] {
	display: none;
}

.header-search__clear .icon {
	inline-size: 0.875rem;
	block-size: 0.875rem;
}

.header-search__clear:focus-visible {
	outline: 2px solid var(--color-focus-dark);
	outline-offset: -4px;
}

/* ---------- The panel ---------- */

.header-search__panel {
	position: absolute;
	z-index: 5;
	display: flex;
	flex-direction: column;
	max-block-size: min(var(--hs-panel-max), var(--hs-panel-room, var(--hs-panel-max)));
	background-color: var(--color-bg);
	box-shadow: var(--nav-panel-shadow);
	animation: header-search-in var(--transition-fast);
}

.header-search__panel[hidden] {
	display: none;
}

@keyframes header-search-in {
	from {
		opacity: 0;
	}
}

.header-search__body {
	position: relative;
	display: flex;
	flex: 1 1 auto;
	flex-direction: column;
	min-block-size: 0;
}

.header-search__scroll {
	flex: 1 1 auto;
	min-block-size: 0;
	padding-block: var(--hs-pad-block) var(--space-md);
	padding-inline: var(--hs-pad-start) var(--hs-pad-end);
	overflow-y: auto;
	overscroll-behavior: contain;
	scrollbar-color: #8a8a8a transparent;
	scrollbar-width: thin;
}

.header-search__fade {
	position: absolute;
	inset-inline: 0;
	inset-block-end: 0;
	block-size: var(--hs-fade);
	background: linear-gradient(to bottom, rgba(255, 255, 255, 0), var(--color-bg));
	opacity: 0;
	pointer-events: none;
	transition: opacity var(--transition-fast);
}

.header-search__panel.has-more .header-search__fade {
	opacity: 1;
}

/* ---------- Groups and results ---------- */

.header-search__group + .header-search__group {
	margin-block-start: 1.25rem;          /* ~20px. */
}

.header-search__group-head {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	justify-content: space-between;
	gap: 0 var(--space-sm);
	margin-block-end: var(--space-xs);
	padding-block-end: 0.4375rem;         /* ~7px to the hairline. */
	border-block-end: 1px solid var(--hs-rule);
}

.header-search__group-label {
	min-inline-size: 0;
	color: var(--color-text);
	font-family: var(--t-body-bold-family);
	font-size: var(--t-body-bold-size);
	font-weight: var(--t-body-bold-weight);
	line-height: var(--t-body-bold-line-height);
	overflow-wrap: anywhere;
}

.header-search__found {
	color: var(--hs-muted);
	font-family: var(--t-small-family);
	font-size: var(--t-small-size);
	line-height: var(--t-small-line-height);
}

.header-search__option {
	display: flex;
	flex-direction: column;
	gap: var(--space-xs);                 /* ~8px title to snippet. */
	margin-inline: calc(-1 * var(--space-xs));
	padding: 0.375rem var(--space-xs);    /* ~12px between results with the next one's padding. */
	color: var(--color-text);
	text-decoration: none;
	scroll-margin-block: var(--space-sm);
}

.header-search__option.is-active {
	background-color: var(--hs-active);
}

@media (hover: hover) {
	.header-search__option:hover {
		background-color: var(--hs-active);
	}
}

.header-search__title {
	font-family: var(--t-body-family);
	font-size: var(--t-body-size);
	line-height: 1.4118;                  /* 24px at 17px. */
	overflow-wrap: anywhere;
}

.header-search__snippet {
	display: -webkit-box;
	overflow: hidden;
	color: var(--hs-muted);
	font-family: var(--t-small-family);
	font-size: var(--t-small-size);
	line-height: var(--t-small-line-height);
	overflow-wrap: anywhere;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	line-clamp: 2;
}

.header-search__mark {
	background: none;
	color: var(--hs-mark);
	font-weight: 600;
}

/* ---------- Messages and "See all" ---------- */

.header-search__status[hidden] {
	display: none;
}

.header-search__message {
	margin: 0;
	color: var(--hs-muted);
	font-family: var(--t-small-family);
	font-size: var(--t-small-size);
	line-height: var(--t-small-line-height);
	overflow-wrap: anywhere;
}

.header-search__message-link,
.header-search__all {
	color: var(--color-text);
	font-family: var(--t-small-family);
	font-size: var(--t-small-size);
	font-weight: 600;
	line-height: var(--t-small-line-height);
	text-decoration: underline;
	text-underline-offset: 0.2em;
	overflow-wrap: anywhere;
}

.header-search__message-link {
	display: inline-block;
	margin-block-start: var(--space-xs);
}

.header-search__all {
	display: block;
	flex: none;
	padding-block: var(--space-sm);
	padding-inline: var(--hs-pad-start) var(--hs-pad-end);
	border-block-start: 1px solid var(--hs-rule);
}

.header-search__all[hidden] {
	display: none;
}

.header-search__option:focus-visible,
.header-search__message-link:focus-visible,
.header-search__all:focus-visible {
	outline: 2px solid var(--color-focus-dark);
	outline-offset: -2px;
}

/* ---------- Desktop: the header box over the bar's end area ---------- */

.header-search--header {
	display: none;
}

@media (min-width: 80em) { /* --bp-nav */
	.header-search--header:not([hidden]) {
		position: absolute;
		inset-block-start: 0;
		inset-inline: 0;
		z-index: 3;
		display: flex;
		align-items: center;
		justify-content: flex-end;
		max-inline-size: calc(var(--container-max) + 2 * var(--container-gutter));
		block-size: var(--main-bar-height);
		margin-inline: auto;
		padding-inline: var(--container-gutter);
		pointer-events: none;
	}

	.header-search--header .header-search__form {
		inline-size: min(var(--hs-box-max), var(--hs-box-width, var(--hs-box-max)));
		pointer-events: auto;
	}

	.header-search--header .header-search__panel {
		inset-block-start: calc(100% + (var(--main-bar-height) - var(--hs-box-height)) / 2 - var(--hs-overlap));
		inset-inline-end: 0;
		inline-size: min(var(--hs-panel-width), 100vw - 2 * var(--container-gutter));
	}
}

/* ---------- Drawer (mobile and tablet, a PROPOSAL) ---------- */

.header-search--drawer {
	--hs-box-height: 3rem;                /* 48px to tap. */
	--hs-pad-block: var(--space-md);
	--hs-pad-start: var(--container-gutter);
	--hs-pad-end: var(--container-gutter);
}

.header-search--drawer .header-search__panel {
	inset-block-start: calc(100% + var(--space-md));
	inset-inline: calc(-1 * var(--container-gutter));
	max-block-size: var(--hs-panel-room, 70vh);
	box-shadow: none;
	border-block-start: 1px solid var(--hs-rule);
}

.header-search--drawer .header-search__option {
	justify-content: center;
	min-block-size: 3rem;                 /* 48px rows. */
	padding-block: var(--space-xs);
}

.header-search--drawer .header-search__all {
	min-block-size: 3rem;
	padding-block: 0.875rem;
}

/* Tablet: the drawer is full width; the text column stays readable (TODO designer). */
.header-search--drawer .header-search__scroll > * {
	max-inline-size: 40rem;
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
	.header-search__panel {
		animation: none;
	}

	.header-search__fade {
		transition: none;
	}
}
