/**
 * AI Search Box block styles.
 *
 * Two rules govern this file:
 *
 * 1. Colour comes from the theme. Every visible colour is either the
 *    theme's own custom property or a translucent grey that adapts to
 *    whatever sits behind it, so the box never looks imported from
 *    another site - and dark themes work without a media query.
 * 2. Only structure and state live here. No decorative flourishes that
 *    would fight the theme's own visual language.
 */

/* Tokens: one place to retune the whole block, and the fallbacks keep
   classic (non block) themes looking deliberate rather than unstyled. */
.ai-search-box,
.ai-search-overlay {
	--ais-surface: var( --wp--preset--color--base, #fff );
	--ais-ink: var( --wp--preset--color--contrast, #1e1e1e );
	--ais-line: rgba( 127, 127, 127, 0.22 );
	--ais-hover: rgba( 127, 127, 127, 0.1 );
	--ais-accent: var( --wp--preset--color--primary, var( --wp--preset--color--contrast, #1e1e1e ) );
	--ais-radius: var( --wp--custom--radius, 6px );
}

.ai-search-box {
	position: relative;
	display: flex;
	flex-direction: column;
	max-width: 100%;
}

.ai-search-box__form {
	position: relative;
	display: flex;
	gap: 8px;
}

.ai-search-box__input {
	flex: 1;
	min-width: 0;
	padding: 0.7em 1em;
	font-family: inherit;
	font-size: inherit;
	line-height: 1.4;
	color: var( --ais-ink );
	background: var( --ais-surface );
	border: 1px solid rgba( 127, 127, 127, 0.45 );
	border-radius: var( --ais-radius );
}

.ai-search-box__input:focus {
	outline: 2px solid var( --ais-accent );
	outline-offset: 1px;
}

.ai-search-box__submit {
	padding: 0.7em 1.4em;
	font-family: inherit;
	font-size: inherit;
	font-weight: 500;
	color: var( --ais-surface );
	background: var( --ais-ink );
	border: none;
	border-radius: var( --ais-radius );
	cursor: pointer;
}

.ai-search-box__submit:hover {
	opacity: 0.85;
}

/* ---------------------------------------------------------------- *
 * Dropdown
 * ---------------------------------------------------------------- */

/* Anchored to the form row, not the block, so it lines up with the
   input instead of stretching under the submit button. */
.ai-search-box__results {
	position: absolute;
	z-index: 50;
	top: calc( 100% + 6px );
	left: 0;
	right: 0;
	max-height: min( 60vh, 420px );
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 4px;
	color: var( --ais-ink );
	background: var( --ais-surface );
	border: 1px solid var( --ais-line );
	border-radius: var( --ais-radius );
	box-shadow: 0 12px 32px rgba( 0, 0, 0, 0.14 );
	animation: ai-search-box-in 120ms ease-out;
}

@keyframes ai-search-box-in {
	from {
		opacity: 0;
		transform: translateY( -4px );
	}
}

@media ( prefers-reduced-motion: reduce ) {
	.ai-search-box__results {
		animation: none;
	}
}

/* ---------------------------------------------------------------- *
 * Result rows - one line per product
 * ---------------------------------------------------------------- */

.ai-search-box__item {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 8px 10px;
	line-height: 1.35;
	color: inherit;
	text-decoration: none;
	border-radius: calc( var( --ais-radius ) - 2px );
	transition: background-color 100ms ease;
}

/* Hairlines between rows read as a list. Not on the first row, and not
   on one that follows a group label - the label draws its own rule, and
   two lines a few pixels apart look like a mistake. */
.ai-search-box__item + .ai-search-box__item {
	box-shadow: inset 0 1px 0 var( --ais-line );
}

.ai-search-box__group + .ai-search-box__item {
	box-shadow: none;
}

.ai-search-box__item:hover,
.ai-search-box__item.is-active {
	background: var( --ais-hover );
	box-shadow: none;
	text-decoration: none;
}

/* A row is never focused directly (focus stays in the input, per the
   combobox pattern) but keyboard users still need the active row to be
   unmistakable, not just slightly tinted. */
.ai-search-box__item.is-active {
	outline: 2px solid var( --ais-accent );
	outline-offset: -2px;
}

.ai-search-box__thumb {
	width: 40px;
	height: 40px;
	flex-shrink: 0;
	object-fit: cover;
	border-radius: 4px;
	background: var( --ais-hover );
	box-shadow: inset 0 0 0 1px var( --ais-line );
}

.ai-search-box__title {
	flex: 1;
	min-width: 0;
	overflow: hidden;
	font-weight: 500;
	white-space: nowrap;
	text-overflow: ellipsis;
}

.ai-search-box__meta {
	display: flex;
	flex-shrink: 0;
	align-items: center;
	gap: 8px;
}

.ai-search-box__price {
	font-size: 0.92em;
	opacity: 0.75;
	white-space: nowrap;
}

/* Woo wraps sale prices in <del>/<ins>; keep them on the one line. */
.ai-search-box__price del {
	margin-right: 4px;
	opacity: 0.6;
}

.ai-search-box__price ins {
	text-decoration: none;
}

/* ---------------------------------------------------------------- *
 * Section label + tier badges (editors only)
 * ---------------------------------------------------------------- */

.ai-search-box__group {
	margin: 6px 0 2px;
	padding: 4px 10px 0;
	font-size: 0.68rem;
	font-weight: 600;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	opacity: 0.55;
	border-top: 1px solid var( --ais-line );
}

.ai-search-box__group:first-child {
	border-top: none;
	margin-top: 0;
}

.ai-search-box__tier {
	padding: 0.12rem 0.45rem;
	font-size: 0.62rem;
	font-weight: 700;
	letter-spacing: 0.05em;
	text-transform: uppercase;
	color: #fff;
	border-radius: 999px;
}

.ai-search-box__tier--exact {
	background: #157a52;
}

.ai-search-box__tier--keyword {
	background: #0a4b78;
}

.ai-search-box__tier--ai {
	background: #372696;
}

/* ---------------------------------------------------------------- *
 * Footer + empty state
 * ---------------------------------------------------------------- */

.ai-search-box__all {
	display: block;
	margin-top: 4px;
	padding: 11px 10px;
	font-size: 0.9em;
	font-weight: 600;
	text-align: center;
	color: inherit;
	border-top: 1px solid var( --ais-line );
	border-radius: 0 0 calc( var( --ais-radius ) - 2px ) calc( var( --ais-radius ) - 2px );
}

.ai-search-box__all:hover {
	background: var( --ais-hover );
}

.ai-search-box__empty {
	margin: 0;
	padding: 18px 14px;
	font-size: 0.95em;
	text-align: center;
	opacity: 0.65;
}
