/**
 * wearseraiah/header-search
 *
 * Icon in header actions; expands a themed search panel with live product hits.
 */

.wsr-header-search,
.wp-block-wearseraiah-header-search {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	/* Do NOT set line-height:0 on the root — it collapses typed input text
	   on some mobile WebKits once the panel opens as a child. */
	line-height: normal;
	color: inherit;
}

/* Match account / mini-cart icon chrome */
.wsr-header-search__toggle {
	appearance: none;
	-webkit-appearance: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	margin: 0;
	padding-block: 0.15rem;
	padding-inline: 0;
	border: 0;
	background: transparent;
	color: inherit;
	cursor: pointer;
	line-height: 0;
	border-radius: 0;
}

.wsr-header-search__toggle:hover,
.wsr-header-search__toggle:focus-visible {
	color: var(--wp--preset--color--bronze, #a08f6e);
	outline: none;
}

.wsr-header-search__toggle:focus-visible {
	box-shadow: 0 0 0 1px currentColor;
}

.wsr-header-search__icon,
.wsr-header-search__icon svg {
	display: block;
	width: 1.5rem;
	height: 1.5rem;
}

.wsr-header-search__icon svg {
	stroke: currentColor;
}

/* Panel — light elevated card, no nested box chrome */
.wsr-header-search__panel {
	position: absolute;
	top: calc(100% + 0.65rem);
	right: 0;
	z-index: 100050;
	box-sizing: border-box;
	width: min(24rem, calc(100vw - 1.5rem));
	padding: 0.85rem 1rem 0.75rem;
	background: var(--wp--preset--color--base, #f7f3eb);
	color: var(--wp--preset--color--ink, #3a3228);
	border: 0;
	box-shadow:
		0 1px 0 color-mix(in srgb, var(--wp--preset--color--sand, #ddd2be) 70%, transparent),
		0 18px 40px rgba(58, 50, 40, 0.12);
	line-height: 1.4;
}

/* Suggestions (status + hits + view-all) hang off the panel edge on
   desktop and overlay content on mobile; never part of the strip flow. */
.wsr-header-search__dropdown {
	position: absolute;
	top: 100%;
	left: 0;
	right: 0;
	z-index: 100050;
	background: var(--wp--preset--color--base, #f7f3eb);
	color: var(--wp--preset--color--ink, #3a3228);
	box-shadow:
		0 1px 0 color-mix(in srgb, var(--wp--preset--color--sand, #ddd2be) 70%, transparent),
		0 18px 40px rgba(58, 50, 40, 0.12);
}

/* Idle (all children hidden) → no stray shadow line. */
.wsr-header-search__dropdown:not(:has(*:not([hidden]))) {
	display: none;
}

/* Respect native hidden on every collapsible piece */
.wsr-header-search__panel[hidden],
.wsr-header-search__backdrop[hidden],
.wsr-header-search__status[hidden],
.wsr-header-search__results[hidden],
.wsr-header-search__view-all[hidden],
.wsr-header-search__clear[hidden] {
	display: none !important;
}

.wsr-header-search__close {
	position: absolute;
	top: 0.45rem;
	right: 0.4rem;
	appearance: none;
	-webkit-appearance: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 1.75rem;
	height: 1.75rem;
	margin: 0;
	padding: 0;
	border: 0;
	background: transparent;
	color: var(--wp--preset--color--muted, #756b58);
	font-size: 1.35rem;
	line-height: 1;
	cursor: pointer;
}

.wsr-header-search__close:hover,
.wsr-header-search__close:focus-visible {
	color: var(--wp--preset--color--ink, #3a3228);
	outline: none;
}

.wsr-header-search__form {
	margin: 0;
	padding-right: 1.35rem;
}

/*
 * Single control — underline only. No fill/border box inside the panel
 * (that was the nested-box look).
 */
.wsr-header-search__field {
	display: grid;
	grid-template-columns: auto minmax(0, 1fr) auto auto;
	align-items: center;
	gap: 0.45rem;
	min-height: 2.5rem;
	padding: 0.15rem 0 0.55rem;
	background: transparent;
	border: 0;
	border-bottom: 1px solid var(--wp--preset--color--sand, #ddd2be);
	box-shadow: none;
	transition: border-color 0.15s ease;
}

.wsr-header-search__field:focus-within {
	border-bottom-color: var(--wp--preset--color--ink, #3a3228);
	box-shadow: none;
}

.wsr-header-search__field-icon {
	display: inline-flex;
	align-items: center;
	color: var(--wp--preset--color--muted, #756b58);
	line-height: 0;
}

.wsr-header-search__field-icon svg {
	display: block;
	width: 1.05rem;
	height: 1.05rem;
}

.wsr-header-search__input {
	width: 100%;
	min-width: 0;
	margin: 0;
	padding: 0.4rem 0.1rem;
	border: 0 !important;
	background: transparent !important;
	box-shadow: none !important;
	color: var(--wp--preset--color--ink, #3a3228) !important;
	-webkit-text-fill-color: var(--wp--preset--color--ink, #3a3228);
	caret-color: var(--wp--preset--color--ink, #3a3228);
	font-family: var(--wp--preset--font-family--body, Jost, sans-serif);
	/* 16px floor avoids iOS focus-zoom and keeps glyphs paintable. */
	font-size: 1rem;
	font-weight: 400;
	letter-spacing: 0.02em;
	line-height: 1.4;
	outline: none !important;
	outline-offset: 0 !important;
	-webkit-appearance: none;
	appearance: none;
	opacity: 1;
}

/* Theme-wide :focus-visible gold box looks nested here — field underline is the focus cue. */
.wsr-header-search__input:focus,
.wsr-header-search__input:focus-visible {
	outline: none !important;
	outline-offset: 0 !important;
	box-shadow: none !important;
	border: 0 !important;
	color: var(--wp--preset--color--ink, #3a3228) !important;
	-webkit-text-fill-color: var(--wp--preset--color--ink, #3a3228);
}

.wsr-header-search__input::placeholder {
	color: var(--wp--preset--color--muted, #756b58);
	-webkit-text-fill-color: var(--wp--preset--color--muted, #756b58);
	opacity: 1;
}

/* Kill native search clear on WebKit — we ship our own. */
.wsr-header-search__input::-webkit-search-decoration,
.wsr-header-search__input::-webkit-search-cancel-button,
.wsr-header-search__input::-webkit-search-results-button,
.wsr-header-search__input::-webkit-search-results-decoration {
	-webkit-appearance: none;
	appearance: none;
	display: none;
}

.wsr-header-search__clear {
	appearance: none;
	-webkit-appearance: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 1.35rem;
	height: 1.35rem;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 999px;
	background: transparent;
	color: var(--wp--preset--color--muted, #756b58);
	font-size: 1.05rem;
	line-height: 1;
	cursor: pointer;
}

.wsr-header-search__clear:hover,
.wsr-header-search__clear:focus-visible {
	color: var(--wp--preset--color--ink, #3a3228);
	outline: none;
}

/* Text CTA — not a chunky pill inside another box */
.wsr-header-search__submit {
	appearance: none;
	-webkit-appearance: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	margin: 0;
	padding: 0.35rem 0.15rem 0.35rem 0.55rem;
	border: 0;
	border-left: 1px solid var(--wp--preset--color--sand, #ddd2be);
	background: transparent;
	color: var(--wp--preset--color--ink, #3a3228);
	font-family: var(--wp--preset--font-family--body, Jost, sans-serif);
	font-size: 0.625rem;
	font-weight: 500;
	letter-spacing: 0.16em;
	text-transform: uppercase;
	line-height: 1;
	cursor: pointer;
	white-space: nowrap;
}

.wsr-header-search__submit:hover,
.wsr-header-search__submit:focus-visible {
	color: var(--wp--preset--color--bronze, #a08f6e);
	background: transparent;
	outline: none;
}

.wsr-header-search__status {
	margin: 0.75rem 0 0;
	padding: 0 0.05rem;
	color: var(--wp--preset--color--muted, #756b58);
	font-family: var(--wp--preset--font-family--body, Jost, sans-serif);
	font-size: 0.75rem;
	letter-spacing: 0.04em;
}

.wsr-header-search__status[data-kind='error'] {
	color: var(--wp--preset--color--ink, #3a3228);
}

.wsr-header-search__status[data-kind='loading'] {
	font-style: italic;
}

.wsr-header-search__results {
	list-style: none;
	margin: 0.35rem 0 0;
	padding: 0;
	max-height: min(22rem, 55vh);
	overflow-x: hidden;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
	border-top: 0;
}

.wsr-header-search.has-results .wsr-header-search__results {
	margin-top: 0.55rem;
	padding-top: 0.15rem;
	border-top: 1px solid color-mix(in srgb, var(--wp--preset--color--sand, #ddd2be) 75%, transparent);
}

.wsr-header-search__result {
	margin: 0;
	padding: 0;
	border-bottom: 1px solid color-mix(in srgb, var(--wp--preset--color--sand, #ddd2be) 55%, transparent);
}

.wsr-header-search__result:last-child {
	border-bottom: 0;
}

.wsr-header-search__result-link {
	display: grid;
	grid-template-columns: 3rem minmax(0, 1fr);
	gap: 0.85rem;
	align-items: center;
	padding: 0.7rem 0.1rem;
	color: inherit;
	text-decoration: none;
}

.wsr-header-search__result-link:hover,
.wsr-header-search__result-link:focus-visible {
	background: color-mix(in srgb, var(--wp--preset--color--surface, #efe8db) 70%, transparent);
	outline: none;
}

.wsr-header-search__thumb {
	display: block;
	width: 3rem;
	height: 3rem;
	object-fit: cover;
	object-position: center;
	background: var(--wp--preset--color--surface, #efe8db);
}

.wsr-header-search__thumb.is-empty {
	border: 1px solid var(--wp--preset--color--sand, #ddd2be);
}

.wsr-header-search__result-meta {
	display: flex;
	flex-direction: column;
	gap: 0.2rem;
	min-width: 0;
}

.wsr-header-search__result-name {
	font-family: var(--wp--preset--font-family--display, "Cormorant Garamond", serif);
	font-size: 1.05rem;
	font-weight: 500;
	font-style: italic;
	line-height: 1.25;
	color: var(--wp--preset--color--ink, #3a3228);
	overflow: hidden;
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
}

.wsr-header-search__result-price {
	font-family: var(--wp--preset--font-family--body, Jost, sans-serif);
	font-size: 0.6875rem;
	font-weight: 500;
	letter-spacing: 0.1em;
	text-transform: uppercase;
	color: var(--wp--preset--color--gold, #c9bda4);
}

.wsr-header-search__view-all {
	display: block;
	margin: 0.1rem 0 0;
	padding: 0.8rem 0.1rem 0.25rem;
	border-top: 1px solid color-mix(in srgb, var(--wp--preset--color--sand, #ddd2be) 75%, transparent);
	color: var(--wp--preset--color--ink, #3a3228);
	font-family: var(--wp--preset--font-family--body, Jost, sans-serif);
	font-size: 0.6875rem;
	font-weight: 500;
	letter-spacing: 0.16em;
	text-align: center;
	text-decoration: none;
	text-transform: uppercase;
}

.wsr-header-search__view-all:hover,
.wsr-header-search__view-all:focus-visible {
	color: var(--wp--preset--color--bronze, #a08f6e);
	outline: none;
}

/* Soft page dim while open on larger screens */
.wsr-header-search__backdrop {
	display: none;
}

body.wsr-search-open {
	/* reserved — mobile locks scroll */
}

/* Loading: underline ticks gold */
.wsr-header-search.is-loading .wsr-header-search__field {
	border-bottom-color: var(--wp--preset--color--gold, #c9bda4);
}

/* ------------------------------------------------------------------ */
/* Mobile — always-visible search bar under the header row             */
/* ------------------------------------------------------------------ */
@media (max-width: 781px) {
	/*
	 * The toggle icon is desktop-only. On mobile the search form is a
	 * permanent full-width strip pinned below the header row, so the
	 * panel ignores the hidden attribute the desktop toggle relies on.
	 */
	.wsr-header-search__toggle {
		display: none !important;
	}

	/*
	 * Drop the wrapper out of the actions row entirely. The header grid
	 * restructure (actions → contents, account/cart promoted, 5-col
	 * template) lives in base.css with !important so it beats the stale
	 * 3-col template; the panel then becomes an in-flow second row.
	 */
	.wsr-header-search {
		display: contents;
	}

	/* Full-width strip — in-flow second row of the header grid. Negative
	   margin cancels the header's half-rail pad so the strip is full-bleed. */
	.wsr-header-search__panel {
		position: relative;
		top: auto;
		left: 0;
		right: 0;
		grid-column: 1 / -1;
		grid-row: 2;
		margin-inline: -0.75rem;
		width: auto;
		max-width: none;
		max-height: none;
		display: block;
		padding:
			0.1rem
			max(0.75rem, env(safe-area-inset-right, 0px))
			0.35rem
			max(0.75rem, env(safe-area-inset-left, 0px));
		border: 0;
		background: var(--wp--preset--color--base, #f7f3eb);
		box-shadow: none;
		overflow: visible;
	}

	/* Suggestions overlay the page instead of stretching the strip. */
	.wsr-header-search__dropdown {
		box-shadow:
			0 1px 0 color-mix(in srgb, var(--wp--preset--color--sand, #ddd2be) 70%, transparent),
			0 18px 40px rgba(58, 50, 40, 0.12);
		padding-inline: max(0.75rem, env(safe-area-inset-left, 0px));
	}

	/* Compact single-line control inside the strip — full hairline box. */
	.wsr-header-search__field {
		min-height: 2.05rem;
		padding: 0.15rem 0.6rem;
		border: 1px solid color-mix(in srgb, var(--wp--preset--color--sand, #ddd2be) 85%, transparent);
		box-shadow: none;
	}

	.wsr-header-search__field:focus-within {
		border-color: var(--wp--preset--color--ink, #3a3228);
	}

	.wsr-header-search.is-loading .wsr-header-search__field {
		border-color: var(--wp--preset--color--gold, #c9bda4);
	}

	.wsr-header-search__field-icon svg {
		width: 0.95rem;
		height: 0.95rem;
	}

	.wsr-header-search__input {
		padding: 0.15rem 0.1rem;
	}

	.wsr-header-search__clear {
		width: 1.5rem;
		height: 1.8rem;
	}

	.wsr-header-search__submit {
		padding: 0.2rem 0.1rem 0.2rem 0.5rem;
	}

	/* The strip is always open on mobile — override hidden. */
	.wsr-header-search__panel[hidden] {
		display: block !important;
	}

	/* No toggle to dismiss and no page dim — nothing to close. */
	.wsr-header-search__close,
	.wsr-header-search__backdrop {
		display: none !important;
	}

	.wsr-header-search__form {
		margin: 0;
		padding: 0;
	}

	/* Suggestions drop below the strip; cap height so the list scrolls. */
	.wsr-header-search__results {
		max-height: min(16rem, 50vh);
	}

	/* Tuck the bar away while the fullscreen mobile menu is open. */
	.wsr-site-header:has(.wp-block-navigation__responsive-container.is-menu-open) .wsr-header-search__panel,
	.wp-block-wearseraiah-site-header:has(.wp-block-navigation__responsive-container.is-menu-open) .wsr-header-search__panel {
		visibility: hidden;
		pointer-events: none;
	}
}

/* Keep actions row icons aligned when search sits beside account/cart */
.wsr-site-header .wsr-header-search__toggle,
.wsr-site-header .wc-block-mini-cart__button,
.wsr-site-header .wc-block-customer-account__link {
	padding-block: 0.15rem !important;
}

/* Overlay header (landing): ink icon on frosted gold — matches account/cart */
.wp-block-wearseraiah-site-header.is-overlay:not(.is-scrolled) .wsr-header-search__toggle,
header.wsr-header--overlay:not(.is-scrolled) .wp-block-wearseraiah-site-header .wsr-header-search__toggle {
	color: var(--wp--preset--color--ink, #3a3228) !important;
}

.wp-block-wearseraiah-site-header.is-overlay:not(.is-scrolled) .wsr-header-search__icon svg,
header.wsr-header--overlay:not(.is-scrolled) .wp-block-wearseraiah-site-header .wsr-header-search__icon svg {
	stroke: currentColor;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
	.wsr-header-search__panel,
	.wsr-header-search__backdrop {
		transition: none !important;
	}
}
