/*
 * Product Search - "Pirx" search bar.
 *
 * Colours and radii come from CSS custom properties printed by
 * MPS_Settings::style_vars_css().
 *
 * Specificity note: the active theme (hello-elementor) ships a control reset
 * like `[type=button],[type=submit],button { border:1px solid #c36 }` at
 * (0,1,0) and loads AFTER this file. Every rule that targets a control is
 * therefore prefixed with `.mps-search` so it reaches at least (0,2,0);
 * hover/focus states reach (0,3,0).
 */

.mps-search {
	--mps-accent: #8b684d;
	--mps-input-bg: #eeeeee;
	--mps-input-border: #eeeeee;
	--mps-input-hover-bg: #dfdfdf;
	--mps-input-focus-bg: #ffffff;
	--mps-input-focus-border: #333333;
	--mps-input-text: #000000;
	--mps-button-bg: #ffffff;
	--mps-button-hover-bg: #e4e4e4;
	--mps-dropdown-bg: #ffffff;
	--mps-dropdown-hover: #fef3ee;
	--mps-dropdown-border: #e6e1de;
	--mps-dropdown-text: #000000;
	--mps-dropdown-price: #8a8a8a;
	--mps-dropdown-price-sale: #8b684d;
	--mps-text: #000000;
	--mps-muted: #8a8a8a;
	--mps-box-radius: 10px;
	--mps-input-radius: 30px;
	--mps-dropdown-radius: 5px;

	position: relative;
	box-sizing: border-box;
	width: 100%;
	max-width: 520px;
	color: var(--mps-text);
	font-size: 15px;
	line-height: 1.4;
}

.mps-search *,
.mps-search *::before,
.mps-search *::after {
	box-sizing: inherit;
}

.mps-search__form {
	position: relative;
	margin: 0;
}

/* White padded container. */
.mps-search .mps-search__box {
	position: relative;
	border-radius: var(--mps-box-radius);
	background: #ffffff;
}

/* Shared control reset. Specificity (0,2,0). */
.mps-search .mps-search__input,
.mps-search .mps-search__submit {
	appearance: none;
	-webkit-appearance: none;
	background-image: none;
	box-shadow: none;
	text-shadow: none;
	text-decoration: none;
	font-family: inherit;
}

/* The grey pill. Specificity (0,2,0). */
.mps-search .mps-search__input {
	display: block;
	width: 100%;
	height: auto;
	margin: 0;
	padding: 7px 24px 7px 48px;
	border: 2px solid var(--mps-input-border);
	border-radius: var(--mps-input-radius);
	background: var(--mps-input-bg);
	color: var(--mps-input-text);
	font-size: 17px;
	line-height: 24px;
	transition: background-color 0.15s ease, border-color 0.15s ease, padding 0.15s ease;
}

.mps-search .mps-search__input::placeholder {
	color: var(--mps-muted);
	opacity: 1;
}

.mps-search .mps-search__input::-webkit-search-cancel-button {
	-webkit-appearance: none;
	appearance: none;
}

/* Hover state. Specificity (0,3,0). */
.mps-search .mps-search__input:hover {
	background: var(--mps-input-hover-bg);
}

/* Focus state. Specificity (0,3,0). Placed after :hover so it wins. */
.mps-search.is-focused .mps-search__input {
	background: var(--mps-input-focus-bg);
	border-color: var(--mps-input-focus-border);
	outline: none;
}

/* Icon submit button, absolutely positioned. Specificity (0,2,0).
   The box has no padding now, so top/left are measured from the box edge and
   must line the 33px button up with the 42px input (centre at 21px). */
.mps-search .mps-search__submit {
	position: absolute;
	top: 5px;
	left: 10px;
	z-index: 2;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 33px;
	height: 33px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 100%;
	background: transparent;
	color: #000000;
	cursor: pointer;
	pointer-events: none;
	transition: left 0.15s ease, right 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.mps-search .mps-search__submit svg {
	display: block;
	width: 18px;
	height: 18px;
}

/* Hover state. Specificity (0,3,0). */
.mps-search .mps-search__submit:hover {
	background: var(--mps-button-hover-bg);
	box-shadow: 0 0 0 2px var(--mps-button-hover-bg);
}

/* Filled state: the button moves to the right and becomes clickable. */
.mps-search.is-filled .mps-search__submit {
	left: auto;
	right: 10px;
	pointer-events: auto;
}

.mps-search.is-filled .mps-search__input {
	padding-left: 24px;
	padding-right: 48px;
}

/* Dropdown, tucked flush under the box padding. */
.mps-search .mps-search__results {
	position: absolute;
	z-index: 40;
	top: calc(100% - 10px);
	right: 0;
	left: 0;
	max-height: 360px;
	overflow-y: auto;
	margin: 0;
	padding: 6px;
	border: 1px solid var(--mps-dropdown-border);
	border-radius: 0 0 var(--mps-dropdown-radius) var(--mps-dropdown-radius);
	background: var(--mps-dropdown-bg);
	box-shadow: 0 12px 30px rgba(0, 0, 0, 0.12);
}

.mps-search .mps-search__results[hidden] {
	display: none;
}

/* Result row is an anchor. Specificity (0,2,0). */
.mps-search .mps-search__item {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 8px 10px;
	border-radius: calc(var(--mps-dropdown-radius) - 1px);
	color: var(--mps-dropdown-text);
	text-decoration: none;
}

/* Hover/active state. Specificity (0,3,0). */
.mps-search .mps-search__item:hover,
.mps-search .mps-search__item:focus,
.mps-search .mps-search__item.is-active,
.mps-search .mps-search__item[aria-selected="true"] {
	background: var(--mps-dropdown-hover);
	outline: none;
}

.mps-search .mps-search__thumb {
	flex: 0 0 40px;
	width: 40px;
	height: 40px;
	border-radius: 10px;
	background: var(--mps-input-bg);
	object-fit: cover;
}

.mps-search .mps-search__thumb--empty {
	display: inline-block;
	border: 1px solid var(--mps-dropdown-border);
}

.mps-search .mps-search__body {
	display: flex;
	flex-direction: column;
	min-width: 0;
}

.mps-search .mps-search__title {
	overflow: hidden;
	color: var(--mps-dropdown-text);
	font-size: 14px;
	font-weight: 600;
	white-space: nowrap;
	text-overflow: ellipsis;
}

.mps-search .mps-search__price {
	display: inline-flex;
	align-items: baseline;
	gap: 6px;
	color: var(--mps-dropdown-price);
	font-size: 13px;
}

/* WooCommerce places a <br> between <del> and <ins>. As a flex item it is
   zero-width but still earns a second gap, so it is taken out of the flow. */
.mps-search .mps-search__price br {
	display: none;
}

/* Base price: secondary. Struck through and lighter than the offer.
   The preview root also carries `.mps-search`, so these rules reach it. */
.mps-search .mps-search__price del {
	color: var(--mps-dropdown-price);
	font-weight: 400;
	opacity: 0.75;
	text-decoration: line-through;
}

/* Offer price: stands out. WooCommerce themes underline `ins`; undo it here. */
.mps-search .mps-search__price ins {
	color: var(--mps-dropdown-price-sale);
	font-weight: 700;
	text-decoration: none;
}

.mps-search .mps-search__message,
.mps-search .mps-search__empty {
	padding: 12px 10px;
	color: var(--mps-muted);
	font-size: 14px;
	text-align: center;
}

/* Admin live preview. */
.mps-preview {
	max-width: 520px;
	padding: 24px;
	border-radius: 16px;
	background: #f0f0f1;
}

.mps-search--preview .mps-search__results {
	position: static;
	display: block;
	margin-top: 8px;
	box-shadow: none;
}

/* Preview controls are decorative. Specificity (0,2,0). */
.mps-search--preview .mps-search__input {
	cursor: default;
}

.mps-search--preview .mps-search__submit {
	pointer-events: none;
}

@media screen and (max-width: 600px) {
	.mps-search {
		max-width: 100%;
	}
}

/* Mini cargador mientras se consulta el buscador. */
.mps-search .mps-search__spinner {
	display: none;
	width: 16px;
	height: 16px;
	border: 2px solid currentColor;
	border-top-color: transparent;
	border-radius: 50%;
	animation: mps-spin 0.7s linear infinite;
}
.mps-search.is-loading .mps-search__submit svg {
	display: none;
}
.mps-search.is-loading .mps-search__spinner {
	display: block;
}
@keyframes mps-spin {
	to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
	.mps-search .mps-search__spinner { animation-duration: 1.8s; }
}
