/* Complemento Asistente virtual: burbuja con el perrito, aviso y ventana de chat. */

.mango-ast {
	--mango-ast-accent: var(--mango-color-primary, #1e3a8a);
	--mango-ast-ink: #0f172a;
	--mango-ast-muted: #64748b;
	--mango-ast-line: #e2e8f0;
	--mango-ast-soft: #f1f5f9;
	--mango-ast-wa: #25d366;
	position: fixed;
	right: 20px;
	bottom: 20px;
	z-index: 9990;
	font-family: inherit;
	font-size: 15px;
	line-height: 1.45;
	color: var(--mango-ast-ink);
}

.mango-ast.is-left { right: auto; left: 20px; }
.mango-ast *, .mango-ast *::before, .mango-ast *::after { box-sizing: border-box; }
.mango-ast svg { display: block; }
.mango-ast button { font: inherit; letter-spacing: normal; text-transform: none; }

/* Figura (perrito u otra, con diadema) */
.mango-ast-figure { display: block; width: 100%; height: 100%; }
.mango-ast-figure.is-image { margin: 0; border-radius: 50%; object-fit: cover; }

/* Burbuja */
.mango-ast-bubble {
	position: relative;
	display: grid;
	place-items: center;
	width: 64px;
	height: 64px;
	min-width: 0 !important;
	min-height: 0 !important;
	padding: 0 !important;
	border: 3px solid #fff;
	border-radius: 50%;
	background: var(--mango-ast-accent);
	box-shadow: 0 10px 28px rgba(15, 23, 42, .28);
	cursor: pointer;
	transition: transform .2s ease, box-shadow .2s ease;
}

.mango-ast-bubble:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 14px 34px rgba(15, 23, 42, .32); }
.mango-ast-bubble:focus { outline: none; }
.mango-ast-bubble:focus-visible { outline: 3px solid var(--mango-ast-accent); outline-offset: 3px; }
.mango-ast-bubble-face { width: 54px; height: 54px; margin-top: 3px; transition: transform .25s ease, opacity .2s ease; }
.mango-ast-bubble-close { position: absolute; inset: 0; display: grid; place-items: center; opacity: 0; transform: rotate(-90deg); transition: transform .25s ease, opacity .2s ease; }
.mango-ast-bubble-close svg { width: 26px; height: 26px; fill: none; stroke: #fff; stroke-width: 2.4; stroke-linecap: round; }
.mango-ast.is-open .mango-ast-bubble-face { opacity: 0; transform: scale(.6); }
.mango-ast.is-open .mango-ast-bubble-close { opacity: 1; transform: none; }

/* Punto «en línea» */
.mango-ast-bubble::after {
	content: "";
	position: absolute;
	right: 1px;
	bottom: 3px;
	width: 14px;
	height: 14px;
	border: 2.5px solid #fff;
	border-radius: 50%;
	background: #22c55e;
}

.mango-ast.is-open .mango-ast-bubble::after { display: none; }

/* Aviso «¿Necesitas ayuda?» */
.mango-ast-teaser {
	position: absolute;
	right: 76px;
	bottom: 12px;
	display: flex;
	align-items: center;
	gap: 2px;
	padding: 4px 4px 4px 16px;
	border-radius: 999px;
	background: #fff;
	box-shadow: 0 8px 26px rgba(15, 23, 42, .18);
	white-space: nowrap;
	animation: mango-ast-pop .35s cubic-bezier(.2, .9, .3, 1.3);
}

.mango-ast.is-left .mango-ast-teaser { right: auto; left: 76px; padding: 4px 4px 4px 16px; }
.mango-ast-teaser[hidden] { display: none; }

.mango-ast-teaser-text {
	padding: 6px 2px !important;
	border: 0;
	background: none;
	color: var(--mango-ast-ink);
	font-weight: 700;
	cursor: pointer;
}

.mango-ast-teaser-close {
	display: grid;
	place-items: center;
	width: 28px;
	height: 28px;
	min-width: 0 !important;
	min-height: 0 !important;
	padding: 0 !important;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: var(--mango-ast-muted);
	font-size: 18px;
	line-height: 1;
	cursor: pointer;
}

.mango-ast-teaser-close:hover { background: var(--mango-ast-soft); color: var(--mango-ast-ink); }

@keyframes mango-ast-pop { from { opacity: 0; transform: translateY(8px) scale(.9); } }

/* Ventana */
.mango-ast-panel {
	position: absolute;
	right: 0;
	bottom: 80px;
	display: flex;
	flex-direction: column;
	width: 380px;
	height: min(600px, calc(100vh - 120px));
	height: min(600px, calc(100dvh - 120px));
	overflow: hidden;
	border-radius: 22px;
	background: #fff;
	box-shadow: 0 24px 70px rgba(15, 23, 42, .28);
	transform-origin: bottom right;
	animation: mango-ast-open .22s ease-out;
}

.mango-ast.is-left .mango-ast-panel { right: auto; left: 0; transform-origin: bottom left; }
.mango-ast-panel[hidden] { display: none; }

@keyframes mango-ast-open { from { opacity: 0; transform: translateY(12px) scale(.96); } }

.mango-ast-head {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 14px 14px 14px 16px;
	background: var(--mango-ast-accent);
	color: #fff;
}

.mango-ast-avatar { flex: none; width: 44px; height: 44px; padding: 3px; border-radius: 50%; background: rgba(255, 255, 255, .16); }
.mango-ast-who { display: flex; flex: 1; flex-direction: column; min-width: 0; }
.mango-ast-who strong { font-size: 16px; line-height: 1.2; color: #fff; }
.mango-ast-who small { display: flex; align-items: center; gap: 6px; margin-top: 2px; font-size: 12.5px; opacity: .85; }
.mango-ast-who small::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #4ade80; }

.mango-ast-close,
.mango-ast-restart {
	display: grid;
	place-items: center;
	flex: none;
	width: 34px;
	height: 34px;
	min-width: 0 !important;
	min-height: 0 !important;
	padding: 0 !important;
	border: 0;
	border-radius: 50%;
	background: rgba(255, 255, 255, .14);
	color: #fff;
	cursor: pointer;
}

.mango-ast-restart { background: transparent; }
.mango-ast-close:hover, .mango-ast-restart:hover { background: rgba(255, 255, 255, .26); }
.mango-ast-close svg, .mango-ast-restart svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.mango-ast-close:focus, .mango-ast-restart:focus { outline: none; }
.mango-ast-close:focus-visible, .mango-ast-restart:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }

/* Conversación */
.mango-ast-log {
	display: flex;
	flex: 1;
	flex-direction: column;
	gap: 10px;
	padding: 16px 14px 8px;
	overflow-y: auto;
	overscroll-behavior: contain;
	background: #f8fafc;
}

.mango-ast-msg {
	max-width: 86%;
	padding: 10px 14px;
	border-radius: 18px;
	white-space: pre-line;
	overflow-wrap: anywhere;
	animation: mango-ast-msg .2s ease-out;
}

@keyframes mango-ast-msg { from { opacity: 0; transform: translateY(6px); } }

.mango-ast-msg.is-bot { align-self: flex-start; border-bottom-left-radius: 6px; background: #fff; box-shadow: 0 1px 2px rgba(15, 23, 42, .08); }
.mango-ast-msg.is-user { align-self: flex-end; border-bottom-right-radius: 6px; background: var(--mango-ast-accent); color: #fff; }

.mango-ast-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; white-space: normal; }

.mango-ast-link {
	display: inline-flex;
	align-items: center;
	padding: 6px 12px;
	border: 1.5px solid var(--mango-ast-accent);
	border-radius: 999px;
	color: var(--mango-ast-accent);
	font-size: 13.5px;
	font-weight: 700;
	text-decoration: none !important;
}

.mango-ast-link:hover { background: var(--mango-ast-accent); color: #fff; }

.mango-ast-typing { display: inline-flex; gap: 4px; align-self: flex-start; padding: 14px 16px; border-radius: 18px 18px 18px 6px; background: #fff; box-shadow: 0 1px 2px rgba(15, 23, 42, .08); }
.mango-ast-typing i { width: 7px; height: 7px; border-radius: 50%; background: #94a3b8; animation: mango-ast-dot 1s infinite ease-in-out; }
.mango-ast-typing i:nth-child(2) { animation-delay: .15s; }
.mango-ast-typing i:nth-child(3) { animation-delay: .3s; }

@keyframes mango-ast-dot { 0%, 80%, 100% { opacity: .35; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* Productos */
.mango-ast-products { display: flex; flex-direction: column; gap: 8px; align-self: stretch; }

.mango-ast-product {
	display: grid;
	grid-template-columns: 60px minmax(0, 1fr);
	gap: 4px 12px;
	align-items: center;
	padding: 10px;
	border-radius: 16px;
	background: #fff;
	box-shadow: 0 1px 2px rgba(15, 23, 42, .08);
	animation: mango-ast-msg .2s ease-out;
}

.mango-ast-product-img { grid-row: span 2; width: 60px; height: 60px; overflow: hidden; border-radius: 12px; background: var(--mango-ast-soft); }
.mango-ast-product-img img { display: block; width: 100%; height: 100%; margin: 0; object-fit: contain; }
.mango-ast-product-name { display: -webkit-box; overflow: hidden; color: var(--mango-ast-ink) !important; font-size: 14px; font-weight: 600; line-height: 1.3; text-decoration: none !important; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.mango-ast-product-name:hover { color: var(--mango-ast-accent) !important; }
.mango-ast-product-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.mango-ast-product-price { font-weight: 800; white-space: nowrap; }
.mango-ast-product-price del { margin-right: 4px; color: var(--mango-ast-muted); font-size: 12.5px; font-weight: 500; }

.mango-ast-add {
	flex: none;
	min-width: 0 !important;
	min-height: 0 !important;
	padding: 6px 12px !important;
	border: 0;
	border-radius: 999px;
	background: var(--mango-ast-accent);
	color: #fff !important;
	font-size: 13px !important;
	font-weight: 700;
	line-height: 1.2;
	text-decoration: none !important;
	cursor: pointer;
}

.mango-ast-add:hover { filter: brightness(1.1); }
.mango-ast-add.is-loading { opacity: .6; pointer-events: none; }
.mango-ast-add.is-done { background: #16a34a; }
.mango-ast-add.is-view { border: 1.5px solid var(--mango-ast-line); background: #fff; color: var(--mango-ast-ink) !important; }

.mango-ast-more { align-self: flex-start; }

/* Asesor */
.mango-ast-advisor { align-self: flex-start; max-width: 92%; }
.mango-ast-advisor .mango-ast-msg { max-width: none; }

.mango-ast-wa {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	margin-top: 8px;
	padding: 10px 16px !important;
	min-width: 0 !important;
	min-height: 0 !important;
	border: 0;
	border-radius: 999px;
	background: var(--mango-ast-wa);
	color: #fff !important;
	font-size: 14.5px !important;
	font-weight: 800;
	line-height: 1.2;
	cursor: pointer;
	box-shadow: 0 6px 16px rgba(37, 211, 102, .32);
}

.mango-ast-wa:hover { filter: brightness(1.05); }
.mango-ast-wa svg, .mango-ast-foot svg { width: 18px; height: 18px; fill: currentColor; }

/* Sugerencias */
.mango-ast-chips {
	display: flex;
	gap: 8px;
	padding: 8px 14px;
	overflow-x: auto;
	background: #f8fafc;
	scrollbar-width: none;
}

.mango-ast-chips::-webkit-scrollbar { display: none; }
.mango-ast-chips:empty { display: none; }

.mango-ast-chip {
	flex: none;
	min-width: 0 !important;
	min-height: 0 !important;
	padding: 7px 13px !important;
	border: 1.5px solid var(--mango-ast-line);
	border-radius: 999px;
	background: #fff;
	color: var(--mango-ast-ink) !important;
	font-size: 13.5px !important;
	font-weight: 600;
	line-height: 1.2;
	white-space: nowrap;
	cursor: pointer;
}

.mango-ast-chip:hover { border-color: var(--mango-ast-accent); color: var(--mango-ast-accent) !important; }

/* Escribir */
.mango-ast-form { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--mango-ast-line); background: #fff; }

.mango-ast-form input {
	flex: 1;
	min-width: 0;
	height: 44px;
	margin: 0;
	padding: 0 16px;
	border: 1.5px solid var(--mango-ast-line);
	border-radius: 999px;
	background: #fff;
	color: var(--mango-ast-ink);
	font: inherit;
	font-size: 16px;
	box-shadow: none;
}

.mango-ast-form input:focus { outline: none; border-color: var(--mango-ast-accent); box-shadow: none !important; }

.mango-ast-form button {
	display: grid;
	place-items: center;
	flex: none;
	width: 44px;
	height: 44px;
	min-width: 0 !important;
	min-height: 0 !important;
	padding: 0 !important;
	border: 0;
	border-radius: 50%;
	background: var(--mango-ast-accent);
	color: #fff;
	cursor: pointer;
}

.mango-ast-form button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

.mango-ast-foot {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	width: 100%;
	min-height: 0 !important;
	padding: 10px !important;
	border: 0;
	border-top: 1px solid var(--mango-ast-line);
	border-radius: 0;
	background: #fff;
	color: #128c4b !important;
	font-size: 13.5px !important;
	font-weight: 700;
	cursor: pointer;
}

.mango-ast-foot:hover { background: #f0fdf4; }

/* Teléfono: hoja casi a pantalla completa y burbuja algo más chica. */
@media (max-width: 600px) {
	.mango-ast { right: 14px; bottom: calc(14px + env(safe-area-inset-bottom)); }
	.mango-ast.is-left { left: 14px; }
	.mango-ast-bubble { width: 58px; height: 58px; }
	.mango-ast-bubble-face { width: 49px; height: 49px; }
	.mango-ast-teaser { right: 68px; bottom: 10px; }
	.mango-ast.is-left .mango-ast-teaser { left: 68px; }

	.mango-ast-panel {
		position: fixed;
		inset: auto 0 0 0;
		width: 100%;
		height: 88vh;
		height: var(--mango-ast-vh, 88dvh);
		border-radius: 22px 22px 0 0;
		padding-bottom: env(safe-area-inset-bottom);
		transform-origin: bottom center;
	}

	.mango-ast.is-left .mango-ast-panel { left: 0; }
	.mango-ast.is-open .mango-ast-bubble,
	.mango-ast.is-open .mango-ast-teaser { display: none; }
	.mango-ast-msg { max-width: 90%; }
}

@media (prefers-reduced-motion: reduce) {
	.mango-ast *, .mango-ast *::before, .mango-ast *::after { animation: none !important; transition: none !important; }
}

@media print {
	.mango-ast { display: none; }
}
