/* Search overlay.
 *
 * One panel over the current page: field, filter row, scrolling product rows
 * and a pager. Tokens are scoped to `#hbg-search` and carry a light and a dark
 * set, the same pair the storefront uses (body.dark is set by theme-init.js
 * before first paint, so a dark session never flashes light).
 *
 * Geometry is fixed: 672px wide, 16px corners, capped at min(80vh, 720px),
 * opened 8vh from the top. Everything inside is flex so the list is the only
 * part that scrolls and the field and pager stay put.
 */

#hbg-search {
	--hs-bg: #ffffff;
	--hs-panel-line: rgba(15, 18, 24, 0.1);
	--hs-ink: #16181d;
	--hs-muted: rgba(22, 24, 29, 0.6);
	--hs-faint: rgba(22, 24, 29, 0.62);
	--hs-badge: rgba(22, 24, 29, 0.72);
	--hs-input: #f6f7f9;
	--hs-input-line: rgba(15, 18, 24, 0.1);
	--hs-row: rgba(15, 18, 24, 0.04);
	--hs-thumb: #eceded;
	--hs-step: #ffffff;
	--hs-step-line: rgba(15, 18, 24, 0.12);
	--hs-step-next: #f1f2f4;
	--hs-step-next-line: rgba(15, 18, 24, 0.16);
	--hs-accent: var(--accent, #6571ff);
	--hs-accent-soft: rgba(101, 113, 255, 0.12);

	position: fixed;
	inset: 0;
	z-index: 2147482900;
	display: flex;
	align-items: flex-start;
	justify-content: center;
	padding: 8vh 16px 16px;
	font-family: "Proxima Nova", "proximaNova", -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
}

body.dark #hbg-search {
	--hs-bg: #151515;
	--hs-panel-line: rgba(255, 255, 255, 0.1);
	--hs-ink: #f2f2f2;
	--hs-muted: rgba(255, 255, 255, 0.64);
	--hs-faint: rgba(255, 255, 255, 0.5);
	--hs-badge: rgba(255, 255, 255, 0.72);
	--hs-input: #1a1a1a;
	--hs-input-line: rgba(255, 255, 255, 0.1);
	--hs-row: rgba(255, 255, 255, 0.04);
	--hs-thumb: #0d0d0d;
	--hs-step: #1f1f1f;
	--hs-step-line: rgba(255, 255, 255, 0.12);
	--hs-step-next: #262626;
	--hs-step-next-line: rgba(255, 255, 255, 0.16);
	--hs-accent-soft: rgba(101, 113, 255, 0.18);
}

#hbg-search[hidden] {
	display: none;
}

#hbg-search,
#hbg-search *,
#hbg-search *::before,
#hbg-search *::after {
	box-sizing: border-box;
}

html.hbg-search-open {
	overflow: hidden;
}

/* ------------------------------------------------------------------ scrim */

.hbg-search-scrim {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, 0.7);
	-webkit-backdrop-filter: blur(2px);
	backdrop-filter: blur(2px);
	opacity: 0;
	transition: opacity 0.18s ease;
}

#hbg-search.is-open .hbg-search-scrim {
	opacity: 1;
}

/* ------------------------------------------------------------------ panel */

.hbg-search-panel {
	position: relative;
	z-index: 10;
	display: flex;
	flex-direction: column;
	width: min(672px, 100%);
	max-height: min(80vh, 720px);
	overflow: hidden;
	border: 1px solid var(--hs-panel-line);
	border-radius: 16px;
	background: var(--hs-bg);
	box-shadow: 0 30px 80px rgba(0, 0, 0, 0.65);
	opacity: 0;
	transform: translateY(-8px) scale(0.995);
	transition: opacity 0.18s ease, transform 0.18s ease;
}

#hbg-search.is-open .hbg-search-panel {
	opacity: 1;
	transform: none;
}

/* ------------------------------------------------------------------ field */

.hbg-search-field {
	display: flex;
	flex: none;
	align-items: center;
	gap: 8px;
	padding: 12px;
	border-bottom: 1px solid var(--hs-panel-line);
}

.hbg-search-inputwrap {
	position: relative;
	flex: 1 1 auto;
	min-width: 0;
}

.hbg-search-glyph {
	position: absolute;
	left: 14px;
	top: 50%;
	transform: translateY(-50%);
	display: grid;
	place-items: center;
	color: var(--hs-faint);
	pointer-events: none;
}

.hbg-search-glyph svg {
	width: 18px;
	height: 18px;
	display: block;
}

.hbg-search-field input {
	width: 100%;
	height: 46px;
	margin: 0;
	padding: 0 12px 0 44px;
	border: 1px solid var(--hs-input-line);
	border-radius: 12px;
	background: var(--hs-input);
	color: var(--hs-ink);
	font: inherit;
	font-size: 14px;
	line-height: 1;
	outline: none;
	-webkit-appearance: none;
	appearance: none;
	transition: border-color 0.15s ease;
}

.hbg-search-field input:focus {
	border-color: var(--hs-accent);
}

.hbg-search-field input::placeholder {
	color: var(--hs-faint);
}

.hbg-search-field input::-webkit-search-cancel-button {
	display: none;
}

.hbg-search-close {
	display: grid;
	place-items: center;
	flex: none;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 1px solid var(--hs-input-line);
	border-radius: 12px;
	background: var(--hs-input);
	color: var(--hs-faint);
	cursor: pointer;
	transition: background-color 0.15s ease, color 0.15s ease;
}

.hbg-search-close:hover {
	background: var(--hs-row);
	color: var(--hs-ink);
}

/* ---------------------------------------------------------------- filters */

.hbg-search-filters {
	display: flex;
	flex: none;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
	padding: 12px;
	border-bottom: 1px solid var(--hs-panel-line);
}

.hbg-search-dd {
	position: relative;
	flex: none;
}

.hbg-search-select {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	height: 36px;
	margin: 0;
	padding: 0 11px 0 12px;
	border: 1px solid var(--hs-input-line);
	border-radius: 12px;
	background: var(--hs-input);
	color: var(--hs-ink);
	font: inherit;
	font-size: 14px;
	font-weight: 500;
	line-height: 1;
	cursor: pointer;
	outline: none;
	white-space: nowrap;
	transition: border-color 0.15s ease, background-color 0.15s ease;
}

.hbg-search-select:hover {
	border-color: var(--hs-step-line);
}

.hbg-search-select:focus-visible,
.hbg-search-dd.is-open .hbg-search-select {
	border-color: var(--hs-accent);
}

.hbg-search-dd.is-open .hbg-search-select {
	background: var(--hs-step);
}

.hbg-search-chevron {
	flex: none;
	opacity: 0.5;
	transition: transform 0.16s ease;
}

.hbg-search-dd.is-open .hbg-search-chevron {
	transform: rotate(180deg);
	opacity: 0.8;
}

/* The menu is a real listbox: 6px of padding, 8px-ish rows, one check on the
   current value. It drops from the trigger and stays inside the panel, which
   is the only scrolling ancestor it has to worry about. */
.hbg-search-menu {
	position: absolute;
	top: calc(100% + 6px);
	left: 0;
	z-index: 20;
	min-width: 100%;
	max-width: 280px;
	max-height: 264px;
	padding: 6px;
	overflow-y: auto;
	overflow-x: hidden;
	border: 1px solid var(--hs-input-line);
	border-radius: 12px;
	background: var(--hs-bg);
	box-shadow: 0 18px 40px rgba(0, 0, 0, 0.42), 0 2px 6px rgba(0, 0, 0, 0.16);
	overscroll-behavior: contain;
	scrollbar-width: thin;
}

.hbg-search-menu[hidden] {
	display: none;
}

.hbg-search-menu::-webkit-scrollbar {
	width: 8px;
}

.hbg-search-menu::-webkit-scrollbar-thumb {
	border: 2px solid transparent;
	border-radius: 8px;
	background: var(--hs-faint);
	background-clip: content-box;
}

.hbg-search-option {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	width: 100%;
	padding: 8px 10px;
	border: 0;
	border-radius: 8px;
	background: transparent;
	color: var(--hs-ink);
	font: inherit;
	font-size: 13.5px;
	line-height: 1.25;
	text-align: left;
	cursor: pointer;
	outline: none;
	opacity: 0.78;
	transition: background-color 0.1s ease, opacity 0.1s ease;
}

.hbg-search-option:hover,
.hbg-search-option:focus-visible,
.hbg-search-option:focus {
	background: var(--hs-row);
	opacity: 1;
}

.hbg-search-option[aria-selected="true"] {
	color: var(--hs-accent);
	font-weight: 600;
	opacity: 1;
}

.hbg-search-option-label {
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.hbg-search-tick {
	flex: none;
	opacity: 0;
}

.hbg-search-option[aria-selected="true"] .hbg-search-tick {
	opacity: 1;
}

.hbg-search-count {
	margin-left: auto;
	color: var(--hs-faint);
	font-size: 14px;
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
}

/* -------------------------------------------------------------------- rows */

.hbg-search-body {
	flex: 1 1 auto;
	min-height: 0;
	padding: 8px;
	overflow-y: auto;
	overscroll-behavior: contain;
	scrollbar-width: thin;
}

.hbg-search-body::-webkit-scrollbar {
	width: 8px;
}

.hbg-search-body::-webkit-scrollbar-thumb {
	border: 2px solid transparent;
	border-radius: 8px;
	background: var(--hs-faint);
	background-clip: content-box;
}

.hbg-search-body::-webkit-scrollbar-track {
	background: transparent;
}

.hbg-search-row {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 10px 8px;
	border-radius: 12px;
	color: inherit;
	text-decoration: none;
	outline: none;
	transition: background-color 0.12s ease;
}

.hbg-search-row:hover,
.hbg-search-row.is-active {
	background: var(--hs-row);
}

.hbg-search-row:focus-visible {
	box-shadow: inset 0 0 0 1px var(--hs-accent);
}

.hbg-search-thumb {
	position: relative;
	flex: none;
	width: 72px;
	height: 56px;
	overflow: hidden;
	border-radius: 8px;
	background: var(--hs-thumb);
}

.hbg-search-thumb img {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.hbg-search-thumb--page {
	display: grid;
	place-items: center;
	color: var(--hs-faint);
}

.hbg-search-meta {
	min-width: 0;
	flex: 1 1 auto;
}

.hbg-search-head {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
}

.hbg-search-title {
	min-width: 0;
	max-width: 100%;
	overflow: hidden;
	color: var(--hs-ink);
	font-size: 14px;
	font-weight: 700;
	line-height: 1.35;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.hbg-search-badge {
	flex: none;
	padding: 2px 6px;
	border-radius: 6px;
	background: var(--hs-row);
	color: var(--hs-badge);
	font-size: 10px;
	font-weight: 700;
	letter-spacing: 0.04em;
	text-transform: uppercase;
}

.hbg-search-price {
	margin: 4px 0 0;
	color: var(--hs-muted);
	font-size: 14px;
	font-variant-numeric: tabular-nums;
}

.hbg-search-price--quiet {
	color: var(--hs-faint);
	font-size: 12.5px;
}

.hbg-search-body mark {
	padding: 0 1px;
	border-radius: 3px;
	background: var(--hs-accent-soft);
	color: inherit;
}

/* ------------------------------------------------------------ empty + foot */

.hbg-search-empty {
	display: grid;
	flex: none;
	gap: 4px;
	padding: 26px 20px 30px;
	text-align: center;
	color: var(--hs-muted);
	font-size: 13px;
}

.hbg-search-empty[hidden] {
	display: none;
}

.hbg-search-empty strong {
	color: var(--hs-ink);
	font-size: 14.5px;
	font-weight: 600;
}

.hbg-search-foot {
	display: flex;
	flex: none;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 12px;
	border-top: 1px solid var(--hs-panel-line);
}

.hbg-search-page {
	color: var(--hs-faint);
	font-size: 14px;
	font-variant-numeric: tabular-nums;
}

.hbg-search-pager {
	display: flex;
	align-items: center;
	gap: 8px;
}

.hbg-search-step {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 8px 12px;
	border: 1px solid var(--hs-step-line);
	border-radius: 12px;
	background: var(--hs-step);
	color: var(--hs-ink);
	font: inherit;
	font-size: 14px;
	line-height: 1.2;
	cursor: pointer;
	transition: background-color 0.15s ease, opacity 0.15s ease;
}

.hbg-search-step--next {
	border-color: var(--hs-step-next-line);
	background: var(--hs-step-next);
}

.hbg-search-step:hover:not(:disabled) {
	filter: brightness(1.12);
}

.hbg-search-step:disabled {
	opacity: 0.35;
	cursor: not-allowed;
}

/* ---------------------------------------------------------------- responsive */

@media (min-width: 640px) {
	.hbg-search-field,
	.hbg-search-filters,
	.hbg-search-foot {
		padding: 16px;
	}

	.hbg-search-body {
		padding: 8px 12px;
	}

	.hbg-search-row {
		gap: 16px;
		padding: 10px 12px;
	}

	.hbg-search-thumb {
		width: 96px;
		height: 64px;
	}

	.hbg-search-title {
		font-size: 16px;
	}
}

@media (max-width: 560px) {
	#hbg-search {
		padding: 12px;
	}

	.hbg-search-panel {
		max-height: calc(100vh - 24px);
	}

	.hbg-search-count {
		order: 3;
		width: 100%;
		margin-left: 0;
	}

	.hbg-search-page {
		font-size: 13px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.hbg-search-scrim,
	.hbg-search-panel,
	.hbg-search-row,
	.hbg-search-step {
		transition: none;
	}
}
