/* =============================================================================
   SEARCH OVERLAY — desktop (279:27586) + mobile (180:8184)
   Triggered by [data-action="search"] in header.
   <dialog> + showModal() → focus trap, Escape, inert backdrop are free.
   Dissolve: opacity 300ms ease-out. BUG-26: no scrim, scroll lock on html.
   ============================================================================= */

/* ── Scroll lock ─────────────────────────────────────────────────────────── */

html.search-open { overflow: hidden; }

/* ── Dialog shell ─────────────────────────────────────────────────────────── */

.search-overlay {
	/* Override browser default centering; drop from header bottom downward */
	position: fixed;
	inset: var(--header-h, 165px) 0 auto 0;
	margin: 0;
	padding: 0;
	border: 0;
	width: 100%;
	max-width: 100%;
	max-height: calc(100vh - var(--header-h, 165px));   /* fallback: Safari <16 */
	max-height: calc(100dvh - var(--header-h, 165px));
	overflow-y: auto;
	background: transparent;
	z-index: 250;

	/* Closed state */
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transition:
		opacity var(--dur-base) ease-out,
		visibility 0s var(--dur-base),
		overlay var(--dur-base) allow-discrete,
		display var(--dur-base) allow-discrete;
	transition-behavior: allow-discrete; /* belt-and-suspenders for Safari */
}

.search-overlay[open] {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
	transition:
		opacity var(--dur-base) ease-out,
		visibility 0s 0s,
		overlay var(--dur-base) allow-discrete,
		display var(--dur-base) allow-discrete;
	transition-behavior: allow-discrete; /* repeated: [open] overrides the transition shorthand */
}

@starting-style {
	.search-overlay[open] { opacity: 0; }
}

.search-overlay::backdrop { background: transparent; }

@media (prefers-reduced-motion: reduce) {
	.search-overlay,
	.search-overlay[open] { transition: none !important; }
}

/* Desktop: close button to the RIGHT of the search form.
 * DOM order has close first (correct for mobile top-right); order:2 flips it on row layout. */
@media (min-width: 768px) {
	.search-overlay__close { order: 2; }
}

/* ── White panel ──────────────────────────────────────────────────────────── */

.search-overlay__panel {
	/* border-box, and it matters most on mobile: the rule below sets width
	   100% with 20px of padding, and in content-box that is 375 + 40 = 415 in
	   a 375 viewport. That one line is why the search bar drew wrong on a
	   phone AND why the results ran off the side - everything inside
	   inherited the overflow. Both reported separately; one cause. */
	box-sizing: border-box;
	/* 16px gutters each side — panel is 32px narrower than viewport, max 1408px */
	width: calc(100% - 32px);
	max-width: 1342px;
	margin-inline: auto;
	background: #fff;
	border: 1px solid #e6e7e7;
	border-radius: var(--r-sm);
	box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
	padding: 32px;
	display: flex;
	flex-direction: column;
	gap: 32px;
}

/* ── Top row: input form + close button ───────────────────────────────────── */
/*
 * Desktop: [form (flex 1 → ~850px)]  [close (20px)]  side by side, space-between.
 * Mobile:  close button above form via absolute positioning; form full-width.
 */

.search-overlay__top {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
}

/* ── Close button ─────────────────────────────────────────────────────────── */

.search-overlay__close {
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	width: 44px;
	height: 44px;
	background: none;
	border: 0;
	padding: 12px;
	cursor: pointer;
	color: var(--fig-siegel-black);
}

.search-overlay__close svg { display: block; }

.search-overlay__close:focus-visible {
	outline: 2px solid var(--fig-siegel-black);
	outline-offset: 2px;
	border-radius: var(--r-sm);
}

/* ── Search form ──────────────────────────────────────────────────────────── */

.search-overlay__form {
	flex: 1;
	min-width: 0;
}

.search-overlay__input-wrap {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	height: 45px;
	padding: 0 12px;
	background: #f5f6f6;
	border-radius: var(--r-sm);
	overflow: hidden;
}

.search-overlay__input {
	flex: 1;
	min-width: 0;
	background: transparent;
	border: 0;
	outline: none;
	/* Aktiv Grotesk Medium 16px/20px, tracking --ls-title (-0.1504px) */
	font: var(--fw-medium) 1rem/1.25rem var(--font-heading);
	letter-spacing: var(--ls-title);
	color: var(--fig-siegel-black);
}

.search-overlay__input::placeholder {
	color: #8b8d8e;
}

/* Clear button that browsers inject into [type="search"] */
.search-overlay__input::-webkit-search-cancel-button { display: none; }

.search-overlay__submit {
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	width: 20px;
	height: 20px;
	background: none;
	border: 0;
	padding: 0;
	cursor: pointer;
	color: var(--fig-siegel-black);
}

.search-overlay__submit:focus-visible {
	outline: 2px solid var(--fig-siegel-black);
	outline-offset: 4px;
	border-radius: var(--r-sm);
}

/* ── Results area ─────────────────────────────────────────────────────────── */

.search-overlay__results {
	display: block;
	min-height: 0;
}

.search-overlay__results:empty { display: none; }

/* ── Categories column (desktop left, mobile top) ─────────────────────────── */

.search-overlay__cats {
	flex-shrink: 0;
	width: 288px;
}

.search-overlay__cats-inner {
	background: #fff;
	border: 1px solid #f5f6f6;
	border-radius: var(--r-md);
	padding: 25px;
	display: flex;
	flex-direction: column;
	gap: 24px;
}

.search-overlay__cat-group {
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.search-overlay__cat-group-label {
	/* .t-caption applied in PHP */
	display: block;
	margin-bottom: 4px;
}

.search-overlay__cat-links {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 0;
}

.search-overlay__cat-link {
	display: block;
	padding: 2px 0 2px 8px;
	text-decoration: none;
	/* .t-link-2: Lato Regular 14/20 tracking --ls-tight */
	color: #3c3d3d;
}

.search-overlay__cat-link:focus-visible {
	outline: 2px solid var(--fig-siegel-black);
	outline-offset: 2px;
	border-radius: var(--r-sm);
}

@media (hover: hover) and (pointer: fine) {
	.search-overlay__cat-link:hover { text-decoration: underline; }
}

/* ── Products column ──────────────────────────────────────────────────────── */

.search-overlay__prods {
	flex: 1;
	min-width: 0;
	padding-top: 25px;
	display: flex;
	flex-direction: column;
	gap: 24px;
}

/* 3-per-row grid on desktop */
.search-overlay__prod-list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 32px;
}

.search-overlay__prod-row {
	display: flex;
	gap: 32px;
	align-items: flex-start;
}

/* ── Single product result item ───────────────────────────────────────────── */

.search-overlay__prod {
	display: flex;
	gap: 10px;
	align-items: flex-start;
	width: 258px;
	flex-shrink: 0;
	text-decoration: none;
	color: inherit;
}

.search-overlay__prod-img {
	flex-shrink: 0;
	width: 78px;
	align-self: stretch;
	overflow: hidden;
	background: #f5f6f6;
}

.search-overlay__prod-img img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.search-overlay__prod-info {
	flex: 1;
	min-width: 0;
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.search-overlay__prod-title-row {
	display: flex;
	align-items: center;
	gap: 4px;
	flex-wrap: wrap;
}

.search-overlay__prod-name {
	/* .t-body-sm: Lato Regular 14.416px/17.3px */
	color: #333;
	white-space: nowrap;
}

/* Product SKU / line badge (e.g. "5000", "7000", "X10") */
.search-badge {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	padding: 4px;
	background: var(--search-badge-bg, var(--fig-siegel-red));
	color: #fff;
	/* Aktiv Grotesk SemiBold 12px/12.15px tracking -0.004em — .t-adhoc-button */
	font: var(--fw-semibold) 0.75rem/0.759375rem var(--font-heading);
	letter-spacing: var(--ls-micro);
}

.search-overlay__prod-desc {
	/* .t-body-xs: Lato Regular 12.814px/15.377px */
	color: #6b6d6f;
	margin: 0;
}

.search-overlay__prod-docs {
	display: flex;
	align-items: center;
	gap: 10px;
	flex-wrap: wrap;
}

.search-overlay__prod-doc {
	/* .t-body-h5: Lato Regular 10.125px/12.15px */
	color: #3c3d3d;
	text-decoration: underline;
}

.search-overlay__prod-doc:focus-visible {
	outline: 2px solid var(--fig-siegel-black);
	outline-offset: 2px;
	border-radius: var(--r-sm);
}

/* ── View All Products ────────────────────────────────────────────────────── */

.search-overlay__view-all {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	width: 100%;
	padding: 4px 0 5px;
	border-bottom: 1px solid #e5e7eb;
	text-decoration: none;
	/* .t-body-sm color: #8b8d8e */
	color: #8b8d8e;
}

.search-overlay__view-all svg { display: block; flex-shrink: 0; }

@media (hover: hover) and (pointer: fine) {
	.search-overlay__view-all:hover { text-decoration: underline; }
}

.search-overlay__view-all:focus-visible {
	outline: 2px solid var(--fig-siegel-black);
	outline-offset: 2px;
	border-radius: var(--r-sm);
}

/* ============================================================================
   MOBILE ≤ 767px — full-screen, single-column
   ============================================================================ */

@media (max-width: 767px) {

	/* Dialog spans full screen on mobile */
	.search-overlay {
		inset: 0;
		max-height: 100vh;   /* fallback: Safari <16 */
		max-height: 100dvh;
		/* Full height, not content height: the result list is now trimmed to
		   fit the screen, so it no longer pads the dialog out to the bottom
		   and the page behind showed through underneath it. */
		height: 100vh;
		height: 100dvh;
		background: #fff;
		box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
	}

	/* No white inner panel on mobile — dialog IS the white surface */
	.search-overlay__panel {
		width: 100%;
		max-width: 100%;
		margin-inline: 0;
		border: 0;
		border-radius: 0;
		box-shadow: none;
		padding: 20px;
		gap: 12px;
	}

	/* Everything inside the panel too. A result row with its own padding
	   would push the same 40px back out again. */
	.search-overlay__panel * {
		box-sizing: border-box;
	}

	/* The top row stacks the close button above the form and is
	   align-items:flex-end, so the form sized to its content - 227px of a
	   335px row - and the input with it. It takes the full width. */
	.search-overlay__form,
	.search-overlay__input-wrap {
		width: 100%;
	}

	/* Mobile top: X button (right-aligned) above the search form */
	.search-overlay__top {
		flex-direction: column;
		align-items: flex-end;
		gap: 8px;
		padding: 0;
		/* Remove the relative wrapper hack; column order is X then form */
	}

	/* Input shorter on mobile: 36px total (py-10 + 16px line-height) */
	.search-overlay__input-wrap {
		height: 36px;
		padding: 0 12px;
	}

	/* Mobile placeholder: body-xs size per Figma (12.814px/15.377px Lato) */
	.search-overlay__input {
		font: var(--fw-regular) 0.8009033203rem/0.9610840082rem var(--font-body);
		color: #6b6d6f;
		letter-spacing: 0;
	}

	/* Results: stacked column on mobile */
	.search-overlay__results {
		flex-direction: column;
		gap: 0;
	}

	/* Mobile categories: border-bottom, no box */
	.search-overlay__cats {
		width: 100%;
	}

	.search-overlay__cats-inner {
		border: 0;
		border-bottom: 1px solid #e6e7e7;
		border-radius: 0;
		padding: 12px;
		gap: 12px;
	}

	/* Mobile category links: gap 4px between items */
	.search-overlay__cat-group { gap: 0; }

	.search-overlay__cat-links { gap: 0; }

	.search-overlay__cat-link {
		padding: 2px 0;
		min-height: 24px;
		display: flex;
		align-items: center;
	}

	/* Mobile products: single column, gap 12px */
	.search-overlay__prods {
		padding-top: 16px;
		gap: 24px;
	}

	.search-overlay__prod-list { gap: 12px; }

	/* No 3-per-row on mobile; rows each contain ONE product */
	.search-overlay__prod-row {
		flex-direction: column;
		gap: 0;
	}

	.search-overlay__prod {
		width: 100%;
	}
}

/* ── Autocomplete suggestions — Figma 180:7574 ────────────────────────────────
   Results row sits at x=32 y=109 inside the 1408 panel, 1344 wide.
   Categories panel 288 wide with 25px padding; products column starts at
   x=320, so the gap between them is 32. The product grid is 1024 wide in three
   columns; each card is 258 with a 78x62 thumbnail and its copy at x=88.
   ---------------------------------------------------------------------------- */

.search-suggest {
	display: grid;
	grid-template-columns: 288px minmax(0, 1fr);
	gap: 32px;
	align-items: start;
}

/* A query that matches no category leaves the products block as the only
   child, and Grid places a single child in the FIRST track - the 288px one
   meant for categories. The three product columns then came out at 85px
   against a 78px thumbnail, so every card overlapped the one beside it while
   1022px sat empty to its right. One track when there is one column of
   content. (Categories without products keep the 288px track: that panel is
   drawn at 288 by design and has no reason to stretch.) */
.search-suggest--no-cats {
	grid-template-columns: minmax(0, 1fr);
}

.search-suggest__label {
	margin: 0 0 24px;
	color: var(--text-body-primary);
	text-transform: uppercase;
	letter-spacing: 0.6px;
}

/* ── Categories ──────────────────────────────────────────────────────────── */

.search-suggest__cats {
	padding: 25px;
	box-sizing: border-box;
	border: 1px solid var(--fig-neutral-50);
	border-radius: var(--r-sm, 2px);
}

.search-suggest__cat-list {
	display: flex;
	flex-direction: column;
	gap: 4px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.search-suggest__cat {
	display: block;
	min-height: 20px;
	padding: 2px 0;
	color: var(--text-heading-primary);
	font: var(--fw-regular) 0.875rem/1.25rem var(--font-heading);
	text-decoration: none;
}

/* ── Products ────────────────────────────────────────────────────────────── */

.search-suggest__grid {
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: 24px 16px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.search-suggest__item {
	display: grid;
	grid-template-columns: 78px minmax(0, 1fr);
	gap: 10px;
	align-items: start;
	padding: 4px;
	color: inherit;
	text-decoration: none;
	border-radius: var(--r-sm, 2px);
}

.search-suggest__thumb {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 78px;
	height: 62px;
	overflow: hidden;
	background: var(--fig-neutral-50);
	border-radius: var(--r-sm, 2px);
}

.search-suggest__thumb img {
	width: 100%;
	height: 100%;
	object-fit: contain;
}

.search-suggest__copy {
	display: flex;
	flex-direction: column;
	gap: 3px;
	min-width: 0;
}

.search-suggest__name {
	display: flex;
	align-items: center;
	gap: 4px;
	min-width: 0;
	color: var(--text-heading-primary);
}

.search-suggest__tagline {
	overflow: hidden;
	color: var(--text-body-primary);
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
}

.search-suggest__price {
	color: var(--text-heading-primary);
}

/* Hover and keyboard share one active state - a list you can only drive with a
   mouse is not usable from the keyboard, and two different highlights for the
   same idea reads as a bug. */
.search-suggest__item.is-active,
.search-suggest__cat.is-active {
	background: var(--fig-neutral-50);
}

.search-suggest__item:focus-visible,
.search-suggest__cat:focus-visible,
.search-suggest__all:focus-visible {
	outline: 2px solid var(--btn-stroke-focused, var(--fig-siegel-blue, #0057b8));
	outline-offset: 2px;
}

/* ── Footer ──────────────────────────────────────────────────────────────── */

.search-suggest__all {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	margin-block-start: 24px;
	padding-block-start: 24px;
	color: var(--text-body-primary);
	text-decoration: none;
	border-block-start: 1px solid var(--fig-neutral-50);
}

/* search-overlay.js hides this, and products that do not fit on a phone, with
   the hidden attribute; display:flex above would otherwise override it. */
.search-suggest__all[hidden],
.search-suggest__grid > li[hidden] { display: none; }

.search-overlay__empty {
	margin: 0;
	padding-block: 24px;
	color: var(--text-body-primary);
}

@media (hover: hover) and (pointer: fine) {
	.search-suggest__cat:hover,
	.search-suggest__all:hover { color: var(--fig-red-600, #c8102e); }
}

/* ── Mobile: one column, categories above products (180:8184) ────────────── */

@media (max-width: 767px) {
	.search-suggest {
		grid-template-columns: minmax(0, 1fr);
		gap: 24px;
	}

	.search-suggest__label { margin-block-end: 16px; }

	.search-suggest__cats { padding: 16px; }

	.search-suggest__cat-list {
		flex-direction: row;
		flex-wrap: wrap;
		gap: 8px 16px;
	}

	.search-suggest__grid {
		grid-template-columns: minmax(0, 1fr);
		gap: 16px;
	}

	.search-suggest__all {
		margin-block-start: 16px;
		padding-block-start: 16px;
	}
}

/* ── Loading feedback ─────────────────────────────────────────────────────────
   Typing into a box that does nothing for a second reads as broken, so there
   are two signals. The spinner says "working" the moment a request starts. The
   skeleton says "results are coming, and roughly this many" - it mirrors the
   real grid, so nothing jumps when the answer lands.

   Only the FIRST search of a session draws skeletons. Once results are on
   screen they stay and dim instead: replacing a list you are reading with grey
   boxes on every keystroke is worse than a moment of stale content.
   ---------------------------------------------------------------------------- */

.search-overlay__spinner {
	flex: 0 0 16px;
	width: 16px;
	height: 16px;
	margin-inline-end: 4px;
	border: 2px solid var(--fig-neutral-100, #e4e6e6);
	border-top-color: var(--fig-red-600, #c8102e);
	border-radius: 50%;
	opacity: 0;
	transition: opacity var(--dur-fast, 200ms) linear;
	pointer-events: none;
}

.search-overlay__form[data-loading] .search-overlay__spinner {
	opacity: 1;
	animation: siegel-spin 700ms linear infinite;
}

@keyframes siegel-spin { to { transform: rotate(360deg); } }

/* Results already on screen: dim rather than replace, so the reader keeps
   their place while the next answer is fetched. */
.search-overlay__results[data-loading] .search-suggest {
	opacity: 0.45;
	transition: opacity var(--dur-fast, 200ms) linear;
}

/* ── Skeleton ────────────────────────────────────────────────────────────── */

.search-skeleton {
	display: grid;
	grid-template-columns: 288px minmax(0, 1fr);
	gap: 32px;
	align-items: start;
}

.search-skeleton__cats {
	padding: 25px;
	box-sizing: border-box;
	border: 1px solid var(--fig-neutral-50);
	border-radius: var(--r-sm, 2px);
}

.search-skeleton__grid {
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: 24px 16px;
}

.search-skeleton__item {
	display: grid;
	grid-template-columns: 78px minmax(0, 1fr);
	gap: 10px;
	align-items: start;
	padding: 4px;
}

.search-skeleton__copy {
	display: flex;
	flex-direction: column;
	gap: 6px;
	padding-block-start: 2px;
}

.search-skeleton__bar {
	height: 10px;
	border-radius: 2px;
	background: var(--fig-neutral-50, #f5f6f6);
	background-image: linear-gradient(
		90deg,
		var(--fig-neutral-50, #f5f6f6) 0%,
		#eceeee 40%,
		var(--fig-neutral-50, #f5f6f6) 80%
	);
	background-size: 300% 100%;
	animation: siegel-shimmer 1200ms ease-in-out infinite;
}

.search-skeleton__bar--thumb { height: 62px; border-radius: var(--r-sm, 2px); }
.search-skeleton__bar--title { width: 62%; height: 12px; }
.search-skeleton__bar--line { width: 88%; }
.search-skeleton__bar--short { width: 44%; }

/* Background-position only - a compositor-cheap shimmer. Nothing here changes
   box size, so the skeleton occupies exactly the space the results will. */
@keyframes siegel-shimmer {
	0%   { background-position: 100% 0; }
	100% { background-position: 0 0; }
}

@media (prefers-reduced-motion: reduce) {
	.search-overlay__form[data-loading] .search-overlay__spinner,
	.search-skeleton__bar {
		animation: none;
	}
	/* Still legible as "busy" without motion. */
	.search-overlay__form[data-loading] .search-overlay__spinner {
		border-top-color: var(--fig-red-600, #c8102e);
	}
}

@media (max-width: 767px) {
	.search-skeleton { grid-template-columns: minmax(0, 1fr); gap: 24px; }
	.search-skeleton__cats { padding: 16px; }
	.search-skeleton__grid { grid-template-columns: minmax(0, 1fr); gap: 16px; }
}
