/**
 * Product search bar - shared between both themes
 * Industrial Kinetic (DESIGN.md).
 *
 * Sits in the white header band. Everything here is tokenised: an earlier
 * version carried 29 literal hex values, most of which are now on the
 * do-not-use list in DESIGN.md 12.
 *
 * @package lkelec
 */

/* ============================================
   THE BAR

   The wrapper is the input, per the form-control spec: white, 1px
   --border-strong, 4px radius. Hover darkens the border to --outline; focus
   takes a 2px --primary outline at 1px offset AND a --primary border.
   ============================================ */

.lk-search {
	position: relative;                   /* anchors the autocomplete panel */
	display: flex;
	align-items: stretch;
	box-sizing: border-box;
	width: 100%;
	max-width: 560px;
	min-height: 44px;
	border: 1px solid var(--border-strong);
	border-radius: var(--radius);
	background: var(--surface-container-lowest);
	transition: border-color var(--transition);
}

/* NB: no overflow:hidden here, tempting though it is for tucking the button
   into the corner radius - it clips the autocomplete panel out of existence.
   The button rounds its own two corners instead. */

.lk-search:hover { border-color: var(--outline); }

.lk-search:focus-within {
	border-color: var(--primary);
	outline: 2px solid var(--primary);
	outline-offset: 1px;
}

.lk-search__input {
	flex: 1 1 auto;
	min-width: 0;                         /* lets the input shrink inside flex */
	border: 0;
	outline: 0;
	background: transparent;
	padding: 10px 12px;
	font-family: var(--font-body);
	font-size: 15px;
	font-weight: 500;
	color: var(--on-surface);
	/* Safari rounds search inputs and adds its own inner shadow. */
	-webkit-appearance: none;
	appearance: none;
}

.lk-search__input::placeholder {
	color: var(--on-surface-variant);
	opacity: 1;                           /* Firefox dims placeholders by default */
}

/* The browser's own clear "x" sits awkwardly next to our button. */
.lk-search__input::-webkit-search-decoration,
.lk-search__input::-webkit-search-cancel-button {
	-webkit-appearance: none;
}

.lk-search__btn {
	flex: 0 0 auto;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 48px;
	border: 0;
	/* Slightly inside the wrapper's radius so the corners nest cleanly. */
	border-radius: 0 3px 3px 0;
	cursor: pointer;
	background: var(--primary);
	color: var(--on-primary);
	transition: background var(--transition);
}

.lk-search__btn:hover,
.lk-search__btn:focus-visible {
	background: var(--primary-container);
}

.lk-search__btn svg {
	display: block;
}


/* ============================================
   AUTOCOMPLETE PANEL

   Genuinely floating UI, so this is one of the few things allowed a shadow -
   and it is the tight, low-blur technical one, not a glow.
   ============================================ */

.lk-search__panel {
	position: absolute;
	top: calc(100% + 5px);
	left: -1px;                           /* line up with the border, not the box */
	right: -1px;
	z-index: 999;
	max-height: min(70vh, 460px);
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
	background: var(--surface-container-lowest);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow-technical);
	text-align: left;
}

.lk-search__panel[hidden] {
	display: none;                        /* [hidden] loses to display:flex etc. */
}

.lk-search__group {
	margin: 0;
	padding: 10px 12px 4px;
	background: var(--surface-container-low);
	font-size: 11px;
	font-weight: 700;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--on-surface-variant);
}

.lk-search__item {
	display: flex;
	align-items: center;
	gap: var(--stack-sm);
	padding: var(--stack-sm) 12px;
	text-decoration: none;
	color: var(--on-surface);
	border-top: 1px solid var(--border);
}

.lk-search__group + .lk-search__item {
	border-top: 0;
}

/* One highlight state for both hover and keyboard - the JS keeps them in sync
   so the mouse and the arrow keys never disagree. --secondary-container is the
   information tint: "this is the row you're on". */
.lk-search__item.is-active,
.lk-search__item:focus {
	background: var(--secondary-container);
	outline: 0;
	text-decoration: none;
}

.lk-search__thumb {
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	background: var(--surface-container-lowest);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	overflow: hidden;
}

.lk-search__thumb img {
	max-width: 100%;
	max-height: 100%;
	width: auto;
	height: auto;
	object-fit: contain;
}

.lk-search__body {
	min-width: 0;                         /* lets the ellipsis actually work */
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.lk-search__title {
	font-size: 14px;
	font-weight: 500;
	line-height: 1.3;
	/* Long product names should not make the panel three times taller. */
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

/* Part numbers are data, so they take the mono face. */
.lk-search__sku {
	font-family: var(--font-mono);
	font-size: 12px;
	color: var(--on-surface-variant);
}

.lk-search__item mark {
	background: transparent;
	color: var(--primary);
	font-weight: 700;
}

.lk-search__item--cat {
	justify-content: space-between;
	font-weight: 700;
}

.lk-search__count {
	flex: 0 0 auto;
	font-family: var(--font-mono);
	font-size: 11px;
	color: var(--on-surface-variant);
	background: var(--surface-container-low);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	padding: 1px 6px;
}

.lk-search__item--suggest {
	font-size: 14px;
}

.lk-search__item--suggest strong {
	color: var(--primary);
}

.lk-search__empty {
	margin: 0;
	padding: var(--stack-md) 12px;
	font-size: 14px;
	color: var(--on-surface-variant);
}


/* ============================================
   PLACEMENT IN THE HEADER

   Desktop: the search takes the space between the logo and the phone/nav.
   Mobile: it wraps onto its own full-width line underneath.
   ============================================ */

.lk-header__search {
	flex: 1 1 260px;
	display: flex;
	justify-content: center;
	min-width: 0;
}

/* The shortcode block adds a wrapper of its own between the two. */
.lk-header__search > * {
	width: 100%;
	max-width: 560px;
}

@media (max-width: 768px) {
	.lk-header__search {
		order: 3;                         /* below logo and phone, not between */
		flex-basis: 100%;
		margin-top: 12px;
	}

	.lk-header__search > *,
	.lk-search {
		max-width: none;
	}

	/* Thumbs are less accurate than a mouse. */
	.lk-search__input {
		padding: 12px;
		/* Under 16px iOS Safari zooms the whole page on focus. */
		font-size: 16px;
	}

	.lk-search__btn {
		width: 56px;
	}
}


/* ============================================
   ASTRA HEADER BAND

   Astra's header is generated from its own settings, so the form is hooked in
   underneath as its own band rather than placed inside the header row.
   ============================================ */

.lk-search-band {
	background: var(--surface-container-lowest);
	border-bottom: 1px solid var(--border);
	padding: 12px 40px;
}

.lk-search-band__inner {
	max-width: 1440px;
	margin: 0 auto;
	display: flex;
	justify-content: flex-end;
}

@media (max-width: 768px) {
	.lk-search-band { padding: 12px var(--stack-md); }
	.lk-search-band__inner .lk-search { max-width: none; }
}


/* ============================================
   RESULTS PAGE
   ============================================ */

.lk-search-summary {
	margin: 0 0 var(--stack-lg);
	color: var(--on-surface-variant);
	font-size: 15px;
}

.lk-search-summary strong {
	color: var(--on-surface);
}

.lk-search-summary--didyoumean {
	font-size: 18px;
}

.lk-search-summary--didyoumean a {
	color: var(--primary);
	text-decoration: underline;
	text-underline-offset: 3px;
}

/* Information about a dead end, so it takes the red top border. */
.lk-search-empty {
	padding: var(--gutter);
	background: var(--surface-container-lowest);
	border: 1px solid var(--border);
	border-top: 3px solid var(--primary);
	border-radius: var(--radius);
}

.lk-search-empty p {
	margin: 0 0 var(--stack-sm);
}

.lk-search-empty p:last-child {
	margin-bottom: 0;
}
