/**
 * LM Search — Estilos del buscador premium.
 * Todas las variables con prefijo --lm-search- pueden ser sobreescritas
 * por los controles de estilo de Elementor (ver includes/class-widget.php).
 */

.lm-search {
	--lm-search-width: 320px;
	--lm-search-height: 46px;
	--lm-search-radius: 30px;

	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: flex-end;
}

/* Reseteo defensivo: neutraliza estilos que el tema aplique por defecto
   a inputs y botones (bordes, sombras, fondos, radios heredados). Solo
   .lm-search__form queda 100% editable desde el panel de Elementor. */
.lm-search,
.lm-search * {
	box-sizing: border-box;
}

.lm-search__toggle,
.lm-search__close,
.lm-search__input {
	-webkit-appearance: none;
	-moz-appearance: none;
	appearance: none;
	border: 0 !important;
	box-shadow: none !important;
	background-color: transparent !important;
	background-image: none !important;
	outline: none !important;
	font-family: inherit;
}

.lm-search__input {
	border-radius: 0 !important;
}

/* Botón inicial: solo la lupa */
.lm-search__toggle {
	display: flex;
	align-items: center;
	justify-content: center;
	width: var(--lm-search-height);
	height: var(--lm-search-height);
	padding: 0;
	background: transparent;
	border: none;
	border-radius: 50%;
	cursor: pointer;
	transition: background-color 200ms ease, transform 200ms ease;
	flex-shrink: 0;
}

.lm-search__toggle:hover {
	transform: scale(1.05);
}

.lm-search__toggle:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

.lm-search.is-open .lm-search__toggle {
	opacity: 0;
	pointer-events: none;
	position: absolute;
}

.lm-search__icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	line-height: 0;
	color: #166534;
	pointer-events: none;
}

.lm-search__icon svg {
	width: 20px;
	height: 20px;
	stroke: currentColor;
}

/* Formulario expandible */
.lm-search__form {
	position: absolute;
	top: 50%;
	right: 0;
	transform: translateY(-50%);
	display: flex;
	align-items: center;
	width: 0;
	min-width: 0;
	height: var(--lm-search-height);
	background: #ffffff;
	border: 1px solid transparent;
	border-radius: var(--lm-search-radius);
	overflow: hidden;
	opacity: 0;
	box-shadow: none;
	transition: width 300ms ease, opacity 300ms ease, border-color 300ms ease, box-shadow 300ms ease;
	z-index: 999;
}

.lm-search.is-open .lm-search__form {
	width: var(--lm-search-width);
	opacity: 1;
	/* Sin sombra por defecto: actívala desde Elementor > Estilo > Caja del buscador > "Sombra al abrir". */
}

.lm-search__icon--inline {
	flex-shrink: 0;
	padding-left: 16px;
	color: #166534;
}

.lm-search__input {
	flex: 1 1 auto;
	width: 100%;
	min-width: 0;
	height: 100%;
	padding: 0 8px 0 10px;
	border: none;
	outline: none;
	background: transparent;
	font-size: 14px;
	color: #1f2937;
	font-family: inherit;
}

.lm-search__input::placeholder {
	color: #9ca3af;
}

.lm-search__close {
	flex-shrink: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	margin-right: 8px;
	padding: 0;
	background: transparent;
	border: none;
	border-radius: 50%;
	cursor: pointer;
	color: #9ca3af;
	opacity: 0;
	transform: scale(0.8);
	transition: opacity 200ms ease 100ms, transform 200ms ease 100ms, background-color 150ms ease, color 150ms ease;
}

.lm-search.is-open .lm-search__close {
	opacity: 1;
	transform: scale(1);
}

.lm-search__close:hover {
	background-color: #f3f4f6 !important;
	color: #374151;
}

.lm-search__close svg {
	width: 14px;
	height: 14px;
	stroke: currentColor;
}

/* Panel desplegable de resultados / categorías */
.lm-search__panel {
	position: absolute;
	top: calc(100% + 10px);
	right: 0;
	width: var(--lm-search-width);
	max-width: 100%;
	max-height: 420px;
	overflow-y: auto;
	background: #ffffff;
	border-radius: 16px;
	box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transform: translateY(-6px);
	transition: opacity 220ms ease, transform 220ms ease, visibility 220ms;
	padding: 10px;
	z-index: 1000;
}

.lm-search.is-open .lm-search__panel.has-content {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
	transform: translateY(0);
}

/* Categorías populares */
.lm-search__categories-title {
	margin: 4px 8px 8px;
	font-size: 12px;
	font-weight: 600;
	letter-spacing: 0.03em;
	text-transform: uppercase;
	color: #6b7280;
}

.lm-search__categories-list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	padding: 0 8px 8px;
}

.lm-search__category-link {
	display: inline-flex;
	align-items: center;
	padding: 6px 14px;
	background: #f3f4f6;
	border-radius: 999px;
	font-size: 13px;
	color: #1f2937;
	text-decoration: none;
	transition: background-color 150ms ease, color 150ms ease;
}

.lm-search__category-link:hover {
	background: #166534;
	color: #ffffff;
}

/* Resultados */
.lm-search__results {
	display: flex;
	flex-direction: column;
}

.lm-search__item {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 8px;
	border-bottom: 1px solid #e5e7eb;
	border-radius: 10px;
	text-decoration: none;
	transition: background-color 150ms ease;
	margin-bottom: 8px;
}

.lm-search__item:last-child {
	border-bottom: none;
	margin-bottom: 0;
}

.lm-search__item:hover {
	background-color: #f9fafb;
}

.lm-search__item-image {
	flex-shrink: 0;
	width: 48px;
	height: 48px;
	border-radius: 8px;
	object-fit: cover;
	background: #f3f4f6;
}

.lm-search__item-info {
	flex: 1 1 auto;
	min-width: 0;
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.lm-search__item-name {
	font-size: 14px;
	font-weight: 500;
	color: #1f2937;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	transition: color 150ms ease;
}

.lm-search__item-sku {
	font-size: 11px;
	color: #9ca3af;
}

.lm-search__item-price {
	flex-shrink: 0;
	font-size: 14px;
	font-weight: 600;
	color: #166534;
	white-space: nowrap;
}

.lm-search__item-price del {
	color: #9ca3af;
	font-weight: 400;
	margin-right: 4px;
}

.lm-search__item-price ins {
	text-decoration: none;
}

/* Estados: cargando / vacío */
.lm-search__state {
	padding: 24px 12px;
	text-align: center;
	font-size: 13px;
	color: #9ca3af;
}

.lm-search__state--loading {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
}

.lm-search__spinner {
	width: 14px;
	height: 14px;
	border: 2px solid #e5e7eb;
	border-top-color: #166534;
	border-radius: 50%;
	animation: lm-search-spin 700ms linear infinite;
}

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

/* Responsive: valores por defecto (pueden sobreescribirse desde Elementor) */
@media (max-width: 1024px) and (min-width: 768px) {
	.lm-search {
		--lm-search-width: 260px;
	}
}

@media (max-width: 767px) {
	.lm-search {
		--lm-search-width: 100%;
	}

	.lm-search.is-open {
		position: fixed;
		top: 12px;
		left: 12px;
		right: 12px;
		z-index: 99999;
	}

	.lm-search.is-open .lm-search__form {
		width: 100%;
		position: relative;
	}

	.lm-search__panel {
		max-height: 60vh;
	}
}

/* Accesibilidad: reduce motion */
@media (prefers-reduced-motion: reduce) {
	.lm-search__form,
	.lm-search__panel,
	.lm-search__close,
	.lm-search__toggle {
		transition: none !important;
	}
}
