/* DG Ajax Search for WooCommerce — frontend */

.dgas {
	--dgas-height: 46px;
	--dgas-radius: 8px;
	--dgas-border: #d6dae1;
	--dgas-accent: #2563eb;
	--dgas-bg: #fff;
	--dgas-text: #1f2937;
	--dgas-muted: #6b7280;
	--dgas-divider: #eef0f3;
	--dgas-active: #f4f6f9;
	--dgas-img: 48px;
	--dgas-offset: 6px;
	position: relative;
	width: 100%;
	box-sizing: border-box;
}

.dgas *,
.dgas *::before,
.dgas *::after {
	box-sizing: border-box;
}

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

/* Formulario */
.dgas__form {
	display: flex;
	align-items: stretch;
	gap: 0;
	margin: 0;
	width: 100%;
}

.dgas__field {
	position: relative;
	display: flex;
	align-items: center;
	flex: 1 1 auto;
	min-width: 0;
	height: var(--dgas-height);
	background-color: var(--dgas-bg);
	border: 1px solid var(--dgas-border);
	border-radius: var(--dgas-radius);
	transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.dgas--has-button .dgas__field {
	border-top-right-radius: 0;
	border-bottom-right-radius: 0;
}

.dgas__field:focus-within {
	border-color: var(--dgas-accent);
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--dgas-accent) 18%, transparent);
}

.dgas__icon {
	display: inline-flex;
	align-items: center;
	flex: 0 0 auto;
	padding-left: 14px;
	color: var(--dgas-muted);
	font-size: 18px;
	line-height: 1;
}

.dgas__icon svg,
.dgas__button-icon svg {
	width: 1em;
	height: 1em;
	fill: currentColor;
}

.dgas .dgas__input {
	flex: 1 1 auto;
	min-width: 0;
	width: 100%;
	height: 100%;
	margin: 0;
	padding: 0 14px;
	border: 0;
	border-radius: 0;
	background: transparent;
	box-shadow: none;
	outline: 0;
	font: inherit;
	font-size: 15px;
	color: var(--dgas-text);
	-webkit-appearance: none;
	appearance: none;
}

.dgas .dgas__input:focus {
	border: 0;
	box-shadow: none;
	outline: 0;
}

.dgas__input::placeholder {
	color: var(--dgas-muted);
	opacity: 1;
}

.dgas__input::-webkit-search-cancel-button,
.dgas__input::-webkit-search-decoration {
	-webkit-appearance: none;
	display: none;
}

/* Limpiar y spinner */
.dgas .dgas__clear {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	width: 28px;
	height: 28px;
	margin-right: 8px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: var(--dgas-muted);
	cursor: pointer;
	line-height: 1;
}

.dgas .dgas__clear:hover,
.dgas .dgas__clear:focus-visible {
	background: var(--dgas-active);
	color: var(--dgas-text);
}

.dgas .dgas__clear[hidden],
.dgas.is-loading .dgas__clear {
	display: none;
}

.dgas__spinner {
	display: none;
	flex: 0 0 auto;
	width: 18px;
	height: 18px;
	margin-right: 12px;
	border: 2px solid var(--dgas-divider);
	border-top-color: var(--dgas-accent);
	border-radius: 50%;
	animation: dgas-spin 0.7s linear infinite;
}

.dgas.is-loading .dgas__spinner {
	display: inline-block;
}

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

/* Botón */
.dgas .dgas__button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	flex: 0 0 auto;
	height: var(--dgas-height);
	min-width: var(--dgas-height);
	margin: 0;
	padding: 0 18px;
	border: 1px solid var(--dgas-accent);
	border-radius: 0 var(--dgas-radius) var(--dgas-radius) 0;
	background-color: var(--dgas-accent);
	color: #fff;
	font: inherit;
	font-size: 15px;
	font-weight: 600;
	line-height: 1;
	cursor: pointer;
	transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.dgas .dgas__button:hover,
.dgas .dgas__button:focus-visible {
	background-color: color-mix(in srgb, var(--dgas-accent) 85%, #000);
	border-color: color-mix(in srgb, var(--dgas-accent) 85%, #000);
	color: #fff;
}

.dgas__button-icon {
	display: inline-flex;
	font-size: 18px;
	line-height: 1;
}

/* Desplegable */
.dgas__results {
	position: absolute;
	top: calc(100% + var(--dgas-offset));
	left: 0;
	right: 0;
	z-index: 9999;
	max-height: min(70vh, 560px);
	overflow-y: auto;
	overscroll-behavior: contain;
	background-color: var(--dgas-bg);
	border: 1px solid var(--dgas-border);
	border-radius: var(--dgas-radius);
	box-shadow: 0 12px 32px rgba(17, 24, 39, 0.12);
	color: var(--dgas-text);
	text-align: left;
}

.dgas__results[hidden] {
	display: none;
}

.dgas__group + .dgas__group {
	border-top: 1px solid var(--dgas-divider);
}

.dgas__group-title {
	padding: 10px 14px 4px;
	font-size: 11px;
	font-weight: 700;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var(--dgas-muted);
}

.dgas .dgas__item {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 10px 14px;
	color: inherit;
	text-decoration: none;
	border-bottom: 1px solid var(--dgas-divider);
	transition: background-color 0.12s ease;
}

.dgas .dgas__group .dgas__item:last-child {
	border-bottom: 0;
}

.dgas .dgas__item.is-active {
	background-color: var(--dgas-active);
	color: inherit;
	text-decoration: none;
}

.dgas .dgas__item--term {
	padding-top: 8px;
	padding-bottom: 8px;
}

.dgas__item-img {
	flex: 0 0 var(--dgas-img);
	width: var(--dgas-img);
	height: var(--dgas-img);
}

.dgas .dgas__item-img img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	border-radius: 6px;
	margin: 0;
	max-width: none;
}

.dgas__item-body {
	display: flex;
	flex-direction: column;
	gap: 2px;
	flex: 1 1 auto;
	min-width: 0;
}

.dgas__item-title {
	flex: 1 1 auto;
	min-width: 0;
	font-size: 14px;
	font-weight: 500;
	line-height: 1.35;
	color: var(--dgas-text);
	overflow: hidden;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
}

.dgas__item-sku,
.dgas__item-count {
	font-size: 12px;
	color: var(--dgas-muted);
}

.dgas__item-stock {
	font-size: 12px;
	font-weight: 600;
	color: #b91c1c;
}

.dgas .is-out-of-stock .dgas__item-img img {
	opacity: 0.55;
}

.dgas__item-price {
	flex: 0 0 auto;
	margin-left: auto;
	font-size: 14px;
	font-weight: 600;
	white-space: nowrap;
	text-align: right;
	color: var(--dgas-text);
}

.dgas__item-price del {
	display: block;
	font-size: 12px;
	font-weight: 400;
	color: var(--dgas-muted);
	opacity: 1;
}

.dgas__item-price ins {
	text-decoration: none;
	background: none;
}

.dgas__results mark {
	padding: 0;
	background: transparent;
	color: var(--dgas-accent);
	font-weight: 700;
}

.dgas__empty {
	padding: 16px 14px;
	font-size: 14px;
	color: var(--dgas-muted);
}

.dgas .dgas__view-all {
	justify-content: center;
	gap: 6px;
	font-size: 14px;
	font-weight: 600;
	color: var(--dgas-accent);
	border-top: 1px solid var(--dgas-divider);
	border-bottom: 0;
}

@media (max-width: 480px) {
	.dgas__item-price del {
		display: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	.dgas__spinner {
		animation-duration: 1.5s;
	}
}

/* Textos accesibles del precio de WooCommerce aunque el tema no defina .screen-reader-text */
.dgas .screen-reader-text {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* ===================================================================
 * 2.0 — Experiencia
 * ================================================================= */

.dgas {
	--dgas-cols: 3;
	--dgas-overlay: rgba(17, 24, 39, 0.45);
	--dgas-z: 9999;
}

.dgas__results {
	z-index: var(--dgas-z);
}

/* Fondo oscurecido */
.dgas__overlay {
	position: fixed;
	inset: 0;
	z-index: calc(var(--dgas-z) - 2);
	background: var(--dgas-overlay);
	animation: dgas-fade 0.15s ease;
}

.dgas__overlay[hidden] {
	display: none;
}

.dgas.is-open .dgas__form {
	position: relative;
	z-index: calc(var(--dgas-z) - 1);
}

@keyframes dgas-fade {
	from {
		opacity: 0;
	}
}

/* Avisos y corrección */
.dgas__notice {
	padding: 10px 14px;
	font-size: 13px;
	color: var(--dgas-muted);
	background: var(--dgas-active);
	border-bottom: 1px solid var(--dgas-divider);
}

.dgas .dgas__dym {
	padding: 0;
	border: 0;
	background: none;
	color: var(--dgas-accent);
	font: inherit;
	font-weight: 700;
	text-decoration: underline;
	cursor: pointer;
}

.dgas-correction {
	margin: 0 0 1em;
}

/* Redirección y banner */
.dgas .dgas__item--redirect {
	justify-content: space-between;
	font-size: 14px;
	color: var(--dgas-accent);
	background: color-mix(in srgb, var(--dgas-accent) 6%, transparent);
}

.dgas__banner {
	display: block;
	padding: 10px 14px;
	border-bottom: 1px solid var(--dgas-divider);
	text-decoration: none;
	color: inherit;
}

.dgas .dgas__banner img {
	display: block;
	width: 100%;
	height: auto;
	border-radius: 6px;
	margin: 0;
}

/* Chips: populares e historial */
.dgas__group--chips {
	padding-bottom: 10px;
}

.dgas__group--chips .dgas__group-title {
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.dgas .dgas__history-clear {
	padding: 0;
	border: 0;
	background: none;
	color: var(--dgas-muted);
	font-size: 11px;
	font-weight: 600;
	text-transform: none;
	letter-spacing: 0;
	cursor: pointer;
	text-decoration: underline;
}

.dgas__chips {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	padding: 4px 14px 2px;
}

.dgas .dgas__chip {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	margin: 0;
	padding: 6px 12px;
	border: 1px solid var(--dgas-border);
	border-radius: 999px;
	background: var(--dgas-bg);
	color: var(--dgas-text);
	font: inherit;
	font-size: 13px;
	line-height: 1.2;
	cursor: pointer;
	transition: border-color 0.15s, color 0.15s;
}

.dgas .dgas__chip:hover,
.dgas .dgas__chip:focus-visible {
	border-color: var(--dgas-accent);
	color: var(--dgas-accent);
}

.dgas .dgas__chip--history::before {
	content: "↺";
	color: var(--dgas-muted);
}

/* Datos extra del producto */
.dgas__item-cat {
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: var(--dgas-muted);
}

.dgas .dgas__item.is-pinned .dgas__item-title::after {
	content: "★";
	margin-left: 6px;
	font-size: 11px;
	color: #f59e0b;
}

/* Botón agregar al carrito */
.dgas .dgas__add {
	flex: 0 0 auto;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 6px 10px;
	border-radius: 6px;
	background: var(--dgas-accent);
	color: #fff;
	font-size: 12px;
	font-weight: 600;
	line-height: 1;
	white-space: nowrap;
	cursor: pointer;
	transition: opacity 0.15s;
}

.dgas .dgas__add:hover {
	opacity: 0.9;
}

.dgas .dgas__add.is-busy {
	opacity: 0.6;
	pointer-events: none;
}

.dgas .dgas__add.is-added {
	background: #15803d;
}

/* Grilla */
.dgas--grid .dgas__products {
	display: grid;
	grid-template-columns: repeat(var(--dgas-cols), minmax(0, 1fr));
	gap: 8px;
	padding: 8px;
}

.dgas--grid .dgas__item--product {
	flex-direction: column;
	align-items: stretch;
	gap: 6px;
	padding: 10px;
	border: 1px solid var(--dgas-divider);
	border-radius: 8px;
}

.dgas--grid .dgas__group .dgas__item--product:last-child {
	border-bottom: 1px solid var(--dgas-divider);
}

.dgas--grid .dgas__item-img {
	flex: 0 0 auto;
	width: 100%;
	height: auto;
	aspect-ratio: 1 / 1;
}

.dgas--grid .dgas__item-price {
	margin-left: 0;
	text-align: left;
}

.dgas--grid .dgas__add {
	align-self: stretch;
}

@media (max-width: 600px) {
	.dgas--grid .dgas__products {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
}

/* Voz */
.dgas .dgas__voice {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	width: 32px;
	height: 32px;
	margin-right: 6px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: var(--dgas-muted);
	cursor: pointer;
}

.dgas .dgas__voice[hidden] {
	display: none;
}

.dgas .dgas__voice:hover {
	background: var(--dgas-active);
	color: var(--dgas-text);
}

.dgas.is-listening .dgas__voice {
	color: #dc2626;
	animation: dgas-pulse 1s ease-in-out infinite;
}

@keyframes dgas-pulse {
	50% {
		transform: scale(1.15);
	}
}

/* Pantalla completa en celular */
.dgas .dgas__back {
	display: none;
}

html.dgas-lock,
html.dgas-lock body {
	overflow: hidden;
}

@media (max-width: 767px) {
	.dgas.is-fullscreen {
		position: fixed;
		inset: 0;
		z-index: 999999;
		display: flex;
		flex-direction: column;
		padding: 10px;
		background: var(--dgas-bg);
	}

	.dgas.is-fullscreen .dgas__back {
		display: inline-flex;
		align-items: center;
		justify-content: center;
		flex: 0 0 auto;
		width: 40px;
		height: var(--dgas-height);
		margin-right: 6px;
		padding: 0;
		border: 0;
		background: transparent;
		color: var(--dgas-text);
		cursor: pointer;
	}

	.dgas.is-fullscreen .dgas__results {
		position: static;
		flex: 1 1 auto;
		max-height: none;
		margin-top: 10px;
		border: 0;
		box-shadow: none;
		min-width: 0 !important;
	}

	.dgas.is-fullscreen .dgas__overlay {
		display: none;
	}
}

/* Celular: precio y botón debajo del nombre para no comprimir el texto */
@media (max-width: 480px) {
	.dgas--list .dgas__item--product {
		flex-wrap: wrap;
		row-gap: 6px;
	}

	.dgas--list .dgas__item--product .dgas__item-body {
		flex: 1 1 calc(100% - var(--dgas-img) - 12px);
	}

	.dgas--list .dgas__item--product .dgas__item-price {
		margin-left: calc(var(--dgas-img) + 12px);
		text-align: left;
	}

	.dgas--list .dgas__item--product .dgas__add {
		margin-left: auto;
	}
}

.dgas__banner img[alt] {
	font-size: 13px;
	color: var(--dgas-muted);
}

/* ===================================================================
 * 2.1 — Modo ícono
 * ================================================================= */

.dgas.dgas--display-icon {
	--dgas-panel-w: 440px;
	--dgas-backdrop: rgba(17, 24, 39, 0.55);
	--dgas-trigger-size: 22px;
	display: inline-block;
	width: auto;
	vertical-align: middle;
}

.dgas .dgas__trigger {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	margin: 0;
	padding: 8px;
	border: 0;
	border-radius: 999px;
	background: transparent;
	color: var(--dgas-text);
	font: inherit;
	line-height: 1;
	cursor: pointer;
	transition: background-color 0.15s, color 0.15s;
}

.dgas .dgas__trigger:hover,
.dgas .dgas__trigger:focus-visible,
.dgas.is-panel-open .dgas__trigger {
	background: var(--dgas-active);
	color: var(--dgas-accent);
}

.dgas__trigger-icon {
	display: inline-flex;
	font-size: var(--dgas-trigger-size);
	line-height: 1;
}

.dgas__trigger-icon svg {
	width: 1em;
	height: 1em;
	fill: currentColor;
}

.dgas__panel {
	box-sizing: border-box;
	z-index: calc(var(--dgas-z) + 1);
	padding: 14px;
	background: var(--dgas-bg);
	border-radius: 12px;
	box-shadow: 0 18px 48px rgba(17, 24, 39, 0.2);
	text-align: left;
}

.dgas__panel[hidden],
.dgas__backdrop[hidden] {
	display: none;
}

.dgas .dgas__panel-close {
	display: none;
	align-items: center;
	justify-content: center;
	position: absolute;
	top: 10px;
	right: 10px;
	width: 34px;
	height: 34px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: var(--dgas-muted);
	cursor: pointer;
}

.dgas .dgas__panel-close:hover {
	background: var(--dgas-active);
	color: var(--dgas-text);
}

/* Dentro del panel los resultados fluyen debajo del campo */
.dgas--display-icon .dgas__results {
	position: static;
	min-width: 0 !important;
	max-height: min(60vh, 520px);
	margin-top: 10px;
	box-shadow: none;
}

/* Desplegable */
.dgas--open-dropdown {
	position: relative;
}

.dgas--open-dropdown .dgas__panel {
	position: absolute;
	top: calc(100% + 8px);
	width: var(--dgas-panel-w);
	max-width: calc(100vw - 20px);
}

.dgas--panel-right .dgas__panel {
	right: 0;
}

.dgas--panel-left .dgas__panel {
	left: 0;
}

/* Ventana centrada */
.dgas__backdrop {
	position: fixed;
	inset: 0;
	z-index: var(--dgas-z);
	background: var(--dgas-backdrop);
	animation: dgas-fade 0.15s ease;
}

.dgas--open-modal .dgas__panel {
	position: fixed;
	top: 10vh;
	left: 50%;
	width: min(var(--dgas-panel-w), calc(100vw - 24px));
	max-height: 80vh;
	overflow: auto;
	padding-top: 52px;
	transform: translateX(-50%);
	animation: dgas-pop 0.18s ease;
}

.dgas--open-modal .dgas__panel-close {
	display: inline-flex;
}

.dgas--open-modal .dgas__results {
	max-height: none;
}

@keyframes dgas-pop {
	from {
		opacity: 0;
		transform: translate(-50%, -8px);
	}
}

/* Celular: el panel ocupa toda la pantalla en ambos modos */
@media (max-width: 767px) {
	.dgas--display-icon .dgas__panel {
		position: fixed;
		inset: 0;
		top: 0;
		left: 0;
		width: auto;
		max-width: none;
		max-height: none;
		padding: 56px 12px 12px;
		border-radius: 0;
		overflow: auto;
		transform: none;
		animation: none;
		z-index: 999999;
	}

	.dgas--display-icon .dgas__panel-close {
		display: inline-flex;
	}

	.dgas--display-icon .dgas__results {
		max-height: none;
		border: 0;
	}
}

@media (prefers-reduced-motion: reduce) {
	.dgas__panel,
	.dgas__backdrop {
		animation: none !important;
	}
}

.dgas__notice--voice {
	border-bottom: 0;
	color: var(--dgas-text);
}

.dgas .dgas__voice[aria-pressed="true"] {
	background: color-mix(in srgb, #dc2626 12%, transparent);
}
