/**
 * Header search (markup: al_header_search_html() in inc/al-header.php).
 *
 * From 1025px the field stands in the bar itself, in the middle of the
 * desktop header's first row. Up to 1024px the field and the AI link stand
 * in a row under the bar, which scrolls away with the page; the bar's icon
 * shows once it has, and opens a panel under the bar with the field
 * focused. al-search anchors its live results under the field.
 * Loads after al-header.css and uses its --al-hdr-* surface tokens.
 */

/* Up to 1024px: the icon opens a panel under the bar, the field focused. */
.al-hsearch .al-hsearch__drop {
	position: absolute;
	inset-inline: 0;
	inset-block-start: 100%;
	display: none;
	padding: var(--al-s-5) var(--al-s-6) var(--al-s-6);
}

/* Surface on a pseudo-element: a backdrop-filter on the panel itself would
   become the containing block of al-search's position:fixed phone results
   and push them 56px down. */
.al-hsearch .al-hsearch__drop::before {
	content: "";
	position: absolute;
	inset: 0;
	z-index: -1;
	border-block-end: 1px solid var(--al-line);
	background: var(--al-hdr-glass-panel);
	-webkit-backdrop-filter: var(--al-hdr-blur);
	backdrop-filter: var(--al-hdr-blur);
	box-shadow: var(--al-sh-2);
}

.al-hsearch.is-open .al-hsearch__drop {
	display: block;
}

.al-hsearch__row {
	display: flex;
	align-items: center;
	gap: var(--al-s-2);
	max-inline-size: 720px;
	margin-inline: auto;
}

/* al-search appends its results panel here, under the field. */
.al-hsearch__field {
	position: relative;
	flex: 1 1 auto;
	min-inline-size: 0;
}

.al-hsearch__form {
	position: relative;
	display: block;
	margin: 0;
}

.al-hsearch__input.al-hsearch__input {
	box-sizing: border-box;
	inline-size: 100%;
	block-size: 48px;
	padding-block: 0;
	padding-inline: var(--al-s-4) 52px;
	border: 1px solid var(--al-line);
	border-radius: var(--al-r-md);
	background: var(--al-surface);
	color: var(--al-ink);
	font-size: var(--al-fs-body); /* 16px: no iOS zoom on focus */
	box-shadow: none;
	transition: border-color var(--al-t) var(--al-ease), background-color var(--al-t) var(--al-ease);
}

.al-hsearch__input.al-hsearch__input::placeholder {
	color: var(--al-ink-3);
	opacity: 1;
}

.al-hsearch__input.al-hsearch__input:focus {
	border-color: var(--al-ink);
	background: var(--al-bg);
	outline: none;
}

.al-hsearch__submit.al-hsearch__submit {
	position: absolute;
	inset-block-start: 6px;
	inset-inline-end: 6px;
	display: grid;
	place-items: center;
	inline-size: 36px;
	block-size: 36px;
	min-block-size: 0;
	padding: 0;
	border: 0;
	border-radius: var(--al-r-sm);
	background: var(--al-ink);
	color: var(--al-bg);
	cursor: pointer;
}

.al-hsearch__submit .al-ico.al-ico {
	inline-size: 20px;
	block-size: 20px;
}

/* The AI assistant beside the field, in the phone row and the phone
   panel (from 1025px the bar has its own button). */
:is(.al-hdr, .al-srow) .al-hsearch__ai {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	flex: none;
	min-block-size: 48px;
	padding-inline: var(--al-s-3) var(--al-s-4);
	border: 1px solid var(--al-orange-tint-brd);
	border-radius: var(--al-r-md);
	background: var(--al-orange-tint);
	color: var(--al-orange-tint-ink);
	font-size: var(--al-fs-sm);
	font-weight: 700;
	white-space: nowrap;
}

.al-hsearch__ai .al-ico.al-ico {
	inline-size: 18px;
	block-size: 18px;
	color: var(--al-orange-strong);
	fill: currentColor;
}

:is(.al-hdr, .al-srow) .al-hsearch__ai:hover {
	background: var(--al-orange-tint-brd);
}

@media (min-width: 1025px) {
	.al-hsearch__ai.al-hsearch__ai {
		display: none;
	}
}

/* From 1025px: the field in the bar, 48px like the AI button in the same
   row; its width is the header grid's middle column (al-header.css, up to
   640px). The icon and the panel's surface go; the submit is a quiet icon. */
@media (min-width: 1025px) {
	.al-hsearch__toggle.al-hsearch__toggle {
		display: none;
	}

	.al-hsearch .al-hsearch__drop {
		position: static;
		display: block;
		padding: 0;
	}

	.al-hsearch .al-hsearch__drop::before {
		content: none;
	}

	.al-hsearch__row {
		max-inline-size: none;
	}

	.al-hsearch__input.al-hsearch__input {
		padding-inline-end: 48px;
		text-overflow: ellipsis;
	}

	.al-hsearch__submit.al-hsearch__submit {
		background: none;
		color: var(--al-ink-2);
	}

	.al-hsearch__submit.al-hsearch__submit:hover {
		background: color-mix(in srgb, var(--al-ink) 6%, transparent);
		color: var(--al-ink);
	}

	/* At least 480px wide: they open from the field's end edge (the left),
	   never off the screen. */
	.al-hdr .al-hsearch__field .als-results {
		inset-inline-start: auto;
		inline-size: max(100%, 480px);
	}
}

/* al-search's live results. Its highlight is a <mark>, which Woodmart pads
   as a label (5px 8px, inline-block): a match inside a word split it. */
mark.als-hl {
	display: inline;
	padding: 0;
	line-height: inherit;
}

/* Its add-to-cart is the site's primary button, not a black pill (its
   accent is Woodmart's primary colour, which the tokens map to ink). The
   "choose options" outline and the "added" state keep their own look. */
html .als-results .als-atc {
	border-radius: var(--al-r-md) !important;
}
html .als-results .als-atc:not(.als-atc-opts, .als-added) {
	background: var(--btn-accented-bgcolor) !important;
	color: var(--btn-accented-color) !important;
}
html .als-results .als-atc:not(.als-atc-opts, .als-added):hover {
	background: var(--btn-accented-bgcolor-hover) !important;
}

@media (max-width: 1024px) {
	.al-hsearch .al-hsearch__drop {
		padding: var(--al-s-3);
	}
}

/* ---- Phones and tablets: the search row under the bar ---------------- */

/* Printed after the header, outside it (al-header.php), so it scrolls away
   while the bar sticks: the same field and AI link as the panel, a little
   lower. Its live results float over the page, under the header (390) and
   the dim it lays over the page. */
.al-srow {
	display: none;
}

@media (max-width: 1024px) {
	.al-srow {
		position: relative;
		z-index: 380;
		display: block;
		padding: var(--al-s-1) var(--al-s-3) var(--al-s-3);
		border-block-end: 1px solid var(--al-line);
		background: var(--al-hdr-glass);
	}

	.al-srow .al-hsearch__row {
		max-inline-size: none;
	}

	.al-srow .al-hsearch__input.al-hsearch__input {
		block-size: 44px;
		text-overflow: ellipsis;
	}

	.al-srow .al-hsearch__submit.al-hsearch__submit {
		inset-block-start: 4px;
		inset-inline-end: 4px;
	}

	.al-srow .al-hsearch__ai.al-hsearch__ai {
		min-block-size: 44px;
	}

	/* Bar and row read as one surface until the page moves. */
	.elementor-location-header:has(+ .al-srow):not(.is-stuck) .al-hdr__main::before {
		border-block-end-color: transparent;
	}

	/* The bar's search icon keeps its place but shows only once the bar
	   covers the row (is-srow-out, al-header.js), so search stays one tap
	   away. */
	.al-hsearch__toggle.al-hsearch__toggle {
		transition: background-color var(--al-t-fast) var(--al-ease), opacity var(--al-t) var(--al-ease), visibility 0s;
	}

	.elementor-location-header:has(+ .al-srow):not(.is-srow-out) .al-hsearch__toggle.al-hsearch__toggle {
		visibility: hidden;
		opacity: 0;
		transition-delay: 0s, 0s, var(--al-t);
	}

	/* The accessibility plugin's button (fixed on the left edge, 100px from
	   the top in its own settings) sat on the row's "עוזר AI": it starts
	   under the row instead, and under the announcement strip too. */
	body:has(.al-srow) #vplugin #vplugin-toggler {
		margin-block-start: calc(var(--al-hdr-h) + 72px);
	}

	body:has(.al-strip):has(.al-srow) #vplugin #vplugin-toggler {
		margin-block-start: calc(var(--al-hdr-h) + 72px + var(--al-strip-h));
	}

	/* There it would sit on the row's live results: it steps aside while
	   they are open, as it does for the header's panels. */
	body:has(.al-srow .als-results:not([hidden])) #vplugin._vp_open_false #vplugin-toggler {
		visibility: hidden;
	}
}

/* Tablets: the row's sides line up with the bar's. */
@media (min-width: 768px) and (max-width: 1024px) {
	.al-srow {
		padding-inline: var(--al-s-6);
	}
}

@media (prefers-reduced-motion: reduce) {
	.al-hsearch__input.al-hsearch__input,
	.al-hsearch__toggle.al-hsearch__toggle {
		transition: none;
	}
}
