/*
 * Broadtech Live Search: suggestions list and the header category select.
 * Colours come from the active theme's custom properties, with fallbacks.
 */

.btls-form,
.btls-has-cat {
	--btls-ink: var(--wp--preset--color--contrast, #16212c);
	--btls-muted: var(--bt-muted, var(--wp--preset--color--slate, #5a6573));
	--btls-line: var(--bt-rule, var(--bt-line, #dce1e6));
	--btls-tint: var(--bt-tint, var(--bt-mist, #eef4fa));
	--btls-accent: var(--bt-blue, var(--wp--preset--color--accent-1, #0a6fb3));
	--btls-ok: var(--bt-success, var(--btls-ink));
	/* Stock dots: green in stock, amber lead time (on backorder), red out of stock. */
	--btls-dot: #1f9d55;
	--btls-dot-late: #e3a008;
	--btls-dot-out: #d64545;
	--btls-late: var(--bt-warning, var(--btls-ink));
	--btls-radius: var(--bt-radius, 4px);
	--btls-mono: var(--bt-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
}

.btls-form {
	position: relative;
}

/* ---------- Category select, inside the search bar on the left ---------- */

/*
 * The bar is a size container: the select, text field and button fit the room
 * the header row really leaves, which depends on the menu, the account label
 * and the cart total as much as on the screen width (see "Narrow bar" below).
 * Only the bar's own children are sized by it; the suggestions panel hangs off
 * the form, outside it.
 */
.btls-has-cat .wp-block-search__inside-wrapper {
	container: btls-bar / inline-size;
}

.btls-has-cat .btls-cat {
	/* Gives way before the text field does (shrinks 4x faster). */
	flex: 0 4 11.5rem;
	align-self: stretch;
	box-sizing: border-box;
	width: auto;
	min-width: 5rem;
	max-width: 36%;
	height: auto;
	min-height: 0;
	margin: 0;
	padding: 0 32px 0 14px;
	border: 0;
	border-radius: 0;
	box-shadow: inset -1px 0 0 var(--btls-line);
	background: var(--btls-tint) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235a6573' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center / 12px 12px;
	color: var(--btls-ink);
	font-family: inherit;
	font-size: 14px;
	font-weight: 600;
	line-height: 1.2;
	white-space: nowrap;
	text-overflow: ellipsis;
	overflow: hidden;
	cursor: pointer;
	-webkit-appearance: none;
	-moz-appearance: none;
	appearance: none;
}

.btls-has-cat .btls-cat::-ms-expand {
	display: none;
}

.btls-has-cat .btls-cat:focus {
	outline: none;
}

.btls-has-cat .btls-cat:focus-visible {
	box-shadow: inset 0 0 0 2px var(--btls-accent);
}

.btls-has-cat .btls-cat option {
	color: var(--btls-ink);
	background: #fff;
	font-weight: 400;
}

/* "split": the text field carries the border (broadtech-toolkit), so the select takes it over on the left. */
.btls-has-cat.btls-skin-split .btls-cat {
	border: 2px solid var(--bt-navy, var(--btls-ink));
	border-right: 0;
	border-radius: 4px 0 0 4px;
}

.btls-has-cat.btls-skin-split .btls-cat + .wp-block-search__input {
	border-left: 0;
	border-radius: 0;
}

/* ---------- Suggestions ---------- */

.btls-panel {
	position: absolute;
	z-index: 1000;
	top: calc(100% + 6px);
	left: 0;
	right: 0;
	box-sizing: border-box;
	border: 1px solid var(--btls-line);
	border-radius: var(--btls-radius);
	background: #fff;
	box-shadow: 0 18px 40px rgba(17, 26, 35, 0.16);
	color: var(--btls-ink);
	font-size: 14px;
	line-height: 1.35;
	text-align: left;
	overflow: hidden;
}

.btls-panel[hidden] {
	display: none !important;
}

.btls-panel .btls-list {
	position: relative;
	max-height: 480px;
	overflow-x: hidden;
	overflow-y: auto;
	overscroll-behavior: contain;
	-webkit-overflow-scrolling: touch;
}

.btls-panel .btls-list:empty {
	display: none;
}

.btls-panel .btls-item {
	display: grid;
	grid-template-columns: 48px minmax(0, 1fr) auto;
	align-items: center;
	gap: 12px;
	padding: 9px 14px;
	border-bottom: 1px solid var(--btls-line);
	color: var(--btls-ink);
	text-decoration: none;
	cursor: pointer;
}

.btls-panel .btls-item:hover,
.btls-panel .btls-item:focus,
.btls-panel .btls-item.is-active {
	background: var(--btls-tint);
	color: var(--btls-ink);
	text-decoration: none;
	outline: none;
}

.btls-panel .btls-item.is-active {
	box-shadow: inset 3px 0 0 var(--btls-accent);
}

.btls-panel .btls-thumb {
	display: flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	width: 48px;
	height: 48px;
	border: 1px solid var(--btls-line);
	border-radius: 3px;
	background: #fff;
	overflow: hidden;
}

.btls-panel .btls-thumb img {
	display: block;
	width: auto;
	height: auto;
	max-width: 100%;
	max-height: 100%;
	object-fit: contain;
}

.btls-panel .btls-body {
	display: flex;
	flex-direction: column;
	gap: 2px;
	min-width: 0;
}

.btls-panel .btls-name {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	overflow: hidden;
	overflow-wrap: anywhere;
	font-weight: 600;
}

.btls-panel .btls-sku {
	overflow: hidden;
	color: var(--btls-muted);
	font-family: var(--btls-mono);
	font-size: 12px;
	white-space: nowrap;
	text-overflow: ellipsis;
}

.btls-panel .btls-hl {
	padding: 0;
	border-radius: 2px;
	background: #fdf0b8;
	color: inherit;
	font: inherit;
}

.btls-panel .btls-stock {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	color: var(--btls-muted);
	font-size: 12px;
	font-weight: 600;
	white-space: nowrap;
}

.btls-panel .btls-stock::before {
	content: "";
	flex: none;
	box-sizing: border-box;
	width: 8px;
	height: 8px;
	border: 1.5px solid currentColor;
	border-radius: 50%;
}

.btls-panel .btls-stock--instock {
	color: var(--btls-ok);
}

.btls-panel .btls-stock--instock::before {
	border-color: var(--btls-dot);
	background: var(--btls-dot);
}

.btls-panel .btls-stock--onbackorder {
	color: var(--btls-late);
}

.btls-panel .btls-stock--onbackorder::before {
	border-color: var(--btls-dot-late);
	background: var(--btls-dot-late);
}

.btls-panel .btls-stock--outofstock::before {
	border-color: var(--btls-dot-out);
	background: var(--btls-dot-out);
}

/* "View all results": stays at the bottom while the list scrolls. */
.btls-panel .btls-more {
	position: sticky;
	bottom: 0;
	display: block;
	box-sizing: border-box;
	width: 100%;
	margin: 0;
	padding: 12px 14px;
	border: 0;
	border-radius: 0;
	background: #fff;
	box-shadow: 0 -6px 14px rgba(17, 26, 35, 0.06);
	color: var(--btls-accent);
	font: inherit;
	font-weight: 700;
	text-align: center;
	text-decoration: none;
	cursor: pointer;
}

.btls-panel .btls-more:hover,
.btls-panel .btls-more:focus,
.btls-panel .btls-more.is-active {
	background: var(--btls-tint);
	outline: none;
	text-decoration: underline;
}

.btls-panel .btls-msg {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 14px 16px;
	color: var(--btls-muted);
}

.btls-panel .btls-msg:empty {
	display: none;
}

.btls-panel .btls-msg.is-loading::before {
	content: "";
	flex: none;
	box-sizing: border-box;
	width: 14px;
	height: 14px;
	border: 2px solid var(--btls-line);
	border-top-color: var(--btls-accent);
	border-radius: 50%;
	animation: btls-spin 0.7s linear infinite;
}

/* Loading while older results are still shown: a thin bar along the top. */
.btls-panel.is-busy::before {
	content: "";
	position: absolute;
	z-index: 2;
	top: 0;
	left: 0;
	width: 40%;
	height: 2px;
	background: var(--btls-accent);
	animation: btls-bar 1s ease-in-out infinite;
}

.btls-sr {
	position: absolute !important;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	border: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	white-space: nowrap;
}

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

@keyframes btls-bar {
	from {
		transform: translateX(-100%);
	}
	to {
		transform: translateX(250%);
	}
}

@media (prefers-reduced-motion: reduce) {
	.btls-panel .btls-msg.is-loading::before,
	.btls-panel.is-busy::before {
		animation: none;
	}
}

/* ---------- Tablets and phones ---------- */

@media (max-width: 781px) {
	.btls-has-cat .btls-cat {
		/* 16px stops iOS zooming the page when the select gets focus. */
		font-size: 16px;
		font-weight: 500;
	}
}

/*
 * Narrow bar (below 460px inside): phones, and tablets or small laptops where
 * the header row is busy (broadtech-trade from 782px up to about 1000px).
 * The select takes a third, never less than 4.5rem; the text field gets the
 * rest; the button shows only its icon (its text stays for screen readers).
 * Browsers without container queries keep the rules above, where the select
 * still shrinks before the text field.
 */
@container btls-bar (max-width: 459px) {
	.btls-has-cat .btls-cat {
		flex: 0 0 32%;
		min-width: 4.5rem;
		max-width: 10rem;
		padding: 0 24px 0 10px;
		background-position: right 8px center;
	}

	.btls-has-cat .wp-block-search__inside-wrapper .wp-block-search__input {
		padding-left: 12px;
		padding-right: 12px;
	}

	.btls-has-cat .wp-block-search__inside-wrapper .wp-block-search__button {
		flex: none;
		justify-content: center;
		width: 52px;
		padding: 0;
		gap: 0;
		font-size: 0;
	}
}

@media (max-width: 600px) {
	.btls-panel {
		top: calc(100% + 4px);
		box-shadow: 0 14px 30px rgba(17, 26, 35, 0.18);
	}

	.btls-panel .btls-item {
		grid-template-columns: 44px minmax(0, 1fr);
		grid-template-areas:
			"thumb body"
			"thumb stock";
		column-gap: 10px;
		row-gap: 2px;
		padding: 10px 12px;
	}

	.btls-panel .btls-thumb {
		grid-area: thumb;
		width: 44px;
		height: 44px;
	}

	.btls-panel .btls-body {
		grid-area: body;
	}

	.btls-panel .btls-stock {
		grid-area: stock;
	}

	.btls-panel .btls-more {
		padding: 14px 12px;
	}
}
