/* Mercado Bot — asistente de compras */

#mb-root {
	--mb-accent: #3f9c35;
	--mb-accent-2: #8cc63f;
	--mb-orange: #f5842d;
	--mb-ink: #17241a;
	--mb-muted: #64766a;
	--mb-line: #e3e9e2;
	--mb-soft: #f4f8f2;
	--mb-white: #fff;
	--mb-shadow: 0 20px 50px -20px rgba(16, 45, 22, .5);
	position: fixed;
	z-index: 999990;
	inset: auto 0 0 0;
	pointer-events: none;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

#mb-root *, #mb-root *::before, #mb-root *::after { box-sizing: border-box; }
#mb-root > * { pointer-events: auto; }

/* ============ Botón flotante ============ */

.mb-launcher-wrap {
	position: fixed;
	bottom: calc(22px + env(safe-area-inset-bottom, 0px));
	display: flex;
	align-items: center;
	gap: 10px;
}

.mb-right .mb-launcher-wrap { right: 22px; flex-direction: row-reverse; }
.mb-left  .mb-launcher-wrap { left: 22px; }

.mb-launcher {
	position: relative;
	width: 68px;
	height: 68px;
	flex: none;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	cursor: pointer;
	isolation: isolate;
	transition: transform .2s ease;
}

.mb-launcher:hover { transform: scale(1.06); }
.mb-launcher:active { transform: scale(.97); }
.mb-launcher:focus-visible { outline: 3px solid var(--mb-accent); outline-offset: 4px; }

/* Anillo de destello girando */
.mb-launcher::before {
	content: "";
	position: absolute;
	inset: -3px;
	border-radius: 50%;
	background: conic-gradient(
		from 0deg,
		rgba(255, 255, 255, 0) 0deg,
		rgba(140, 198, 63, .25) 40deg,
		var(--mb-accent-2) 95deg,
		#ffe9a8 120deg,
		var(--mb-orange) 145deg,
		rgba(140, 198, 63, .25) 200deg,
		rgba(255, 255, 255, 0) 300deg
	);
	z-index: 0;
}

.mb-glow .mb-launcher::before { animation: mb-spin 2.8s linear infinite; }

/* Halo que respira */
.mb-launcher::after {
	content: "";
	position: absolute;
	inset: 2px;
	border-radius: 50%;
	background: var(--mb-white);
	box-shadow: 0 8px 24px -6px rgba(20, 60, 25, .55);
	z-index: 1;
}

.mb-launcher img {
	position: relative;
	z-index: 2;
	width: 50px;
	height: 50px;
	margin: 9px;
	object-fit: contain;
	display: block;
}

.mb-pulse {
	position: absolute;
	inset: 0;
	border-radius: 50%;
	border: 2px solid var(--mb-accent-2);
	z-index: 0;
	opacity: 0;
}

.mb-glow .mb-pulse { animation: mb-pulse 2.8s ease-out infinite; }

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

@keyframes mb-pulse {
	0%   { transform: scale(1);   opacity: .65; }
	70%  { transform: scale(1.5); opacity: 0; }
	100% { transform: scale(1.5); opacity: 0; }
}

/* Globito de invitación */
.mb-bubble {
	max-width: 210px;
	padding: 9px 14px;
	border-radius: 16px;
	background: var(--mb-white);
	border: 1px solid var(--mb-line);
	box-shadow: 0 10px 26px -14px rgba(16, 45, 22, .6);
	font-size: 13.5px;
	line-height: 1.35;
	color: var(--mb-ink);
	cursor: pointer;
	animation: mb-in .35s ease both;
}

.mb-bubble-out {
	opacity: 0;
	transform: translateY(6px);
	pointer-events: none;
	transition: opacity .4s ease, transform .4s ease;
}

@keyframes mb-in {
	from { opacity: 0; transform: translateY(8px); }
	to   { opacity: 1; transform: none; }
}

/* ============ Panel ============ */

.mb-panel {
	position: fixed;
	bottom: 22px;
	width: 390px;
	max-width: calc(100vw - 28px);
	height: 600px;
	max-height: calc(100vh - 44px);
	display: none;
	flex-direction: column;
	overflow: hidden;
	background: var(--mb-white);
	border: 1px solid var(--mb-line);
	border-radius: 20px;
	box-shadow: var(--mb-shadow);
	opacity: 0;
	transform: translateY(14px) scale(.98);
	transition: opacity .2s ease, transform .2s ease;
}

.mb-right .mb-panel { right: 22px; }
.mb-left  .mb-panel { left: 22px; }

.mb-open .mb-panel { display: flex; opacity: 1; transform: none; }
.mb-open .mb-launcher-wrap { display: none; }

.mb-header {
	display: flex;
	align-items: center;
	gap: 11px;
	padding: 13px 14px;
	background: linear-gradient(120deg, #1f7a32 0%, var(--mb-accent) 55%, var(--mb-accent-2) 100%);
	color: #fff;
	flex: none;
	position: relative;
	z-index: 2;
}

.mb-header-logo {
	width: 42px; height: 42px; flex: none;
	padding: 5px;
	border-radius: 50%;
	background: #fff;
	object-fit: contain;
}

.mb-header-name { font-size: 15px; font-weight: 700; line-height: 1.15; }

.mb-header-sub {
	display: flex; align-items: center; gap: 5px;
	margin-top: 3px;
	font-size: 11.5px;
	opacity: .9;
}

.mb-dot {
	width: 7px; height: 7px;
	border-radius: 50%;
	background: #b6f36a;
	box-shadow: 0 0 0 3px rgba(182, 243, 106, .25);
}

.mb-header-actions { margin-left: auto; display: flex; gap: 2px; }

.mb-ico {
	width: 32px; height: 32px;
	display: grid; place-items: center;
	border: 0; border-radius: 9px;
	background: transparent; color: #fff;
	font-size: 17px; line-height: 1; cursor: pointer; opacity: .9;
}
.mb-ico:hover { background: rgba(255, 255, 255, .18); opacity: 1; }

/* ============ Conversación ============ */

.mb-log {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
	padding: 15px 14px;
	background: var(--mb-soft);
	display: flex;
	flex-direction: column;
	gap: 9px;
}

.mb-msg {
	max-width: 88%;
	padding: 10px 13px;
	border-radius: 15px;
	font-size: 14.5px;
	line-height: 1.5;
	color: var(--mb-ink);
	white-space: pre-wrap;
	word-wrap: break-word;
	animation: mb-in .22s ease both;
}

.mb-bot {
	align-self: flex-start;
	background: var(--mb-white);
	border: 1px solid var(--mb-line);
	border-bottom-left-radius: 5px;
}

.mb-user {
	align-self: flex-end;
	background: var(--mb-accent);
	color: #fff;
	border-bottom-right-radius: 5px;
}

.mb-typing { display: flex; gap: 4px; align-items: center; height: 13px; }
.mb-typing i {
	width: 6px; height: 6px; border-radius: 50%;
	background: var(--mb-muted);
	animation: mb-bounce 1.1s infinite ease-in-out;
}
.mb-typing i:nth-child(2) { animation-delay: .15s; }
.mb-typing i:nth-child(3) { animation-delay: .3s; }

@keyframes mb-bounce {
	0%, 60%, 100% { transform: translateY(0); opacity: .4; }
	30% { transform: translateY(-4px); opacity: 1; }
}

/* ============ Tarjetas de producto ============ */

.mb-products { display: flex; flex-direction: column; gap: 8px; animation: mb-in .25s ease both; }

.mb-card {
	display: flex;
	gap: 11px;
	padding: 9px;
	background: var(--mb-white);
	border: 1px solid var(--mb-line);
	border-radius: 14px;
	align-items: center;
}

.mb-card img {
	width: 56px; height: 56px; flex: none;
	border-radius: 10px;
	object-fit: cover;
	background: var(--mb-soft);
}

.mb-card-body { flex: 1; min-width: 0; }

.mb-card-name {
	display: block;
	font-size: 13.5px; font-weight: 600; line-height: 1.3;
	color: var(--mb-ink); text-decoration: none;
}
.mb-card-name:hover { color: var(--mb-accent); }

.mb-card-price { margin-top: 2px; font-size: 13.5px; font-weight: 700; color: var(--mb-accent); }
.mb-card-out   { margin-top: 2px; font-size: 12px; color: #b4463c; font-weight: 600; }
.mb-card-tip {
	font-size: 12px;
	line-height: 1.35;
	color: #2f6f2a;
	margin-top: 3px;
}

.mb-card-cat   { margin-top: 1px; font-size: 11px; color: var(--mb-muted); }

.mb-card-actions { display: flex; flex-direction: column; gap: 5px; flex: none; }

.mb-btn {
	padding: 7px 11px;
	border: 0; border-radius: 9px;
	font-size: 12px; font-weight: 700;
	text-decoration: none; text-align: center;
	cursor: pointer; white-space: nowrap;
	background: var(--mb-accent); color: #fff;
}
.mb-btn:hover { filter: brightness(1.08); color: #fff; }
.mb-btn[disabled] { opacity: .6; cursor: default; }

.mb-btn-ghost {
	background: var(--mb-soft);
	color: var(--mb-ink);
	border: 1px solid var(--mb-line);
}
.mb-btn-ghost:hover { color: var(--mb-accent); border-color: var(--mb-accent); }

/* ============ Enlaces y redes ============ */

.mb-links { display: flex; flex-wrap: wrap; gap: 7px; animation: mb-in .25s ease both; }

.mb-link {
	display: inline-flex; align-items: center; gap: 6px;
	padding: 9px 14px;
	border-radius: 11px;
	font-size: 13px; font-weight: 700;
	text-decoration: none;
	background: var(--mb-white);
	border: 1px solid var(--mb-line);
	color: var(--mb-ink);
}
.mb-link:hover { border-color: var(--mb-accent); color: var(--mb-accent); }

.mb-link-whatsapp { background: #25d366; border-color: #25d366; color: #fff; }
.mb-link-whatsapp:hover { background: #1fb855; border-color: #1fb855; color: #fff; }
.mb-link-primary { background: var(--mb-accent); border-color: var(--mb-accent); color: #fff; }
.mb-link-primary:hover { color: #fff; filter: brightness(1.08); }

/* ============ Sugerencias ============ */

.mb-chips {
	display: flex; flex-wrap: wrap; gap: 6px;
	padding: 0 14px 11px;
	background: var(--mb-soft);
}

.mb-chip {
	padding: 7px 13px;
	border: 1px solid var(--mb-line);
	border-radius: 999px;
	background: var(--mb-white);
	color: var(--mb-ink);
	font-size: 12.5px;
	font-family: inherit;
	cursor: pointer;
}
.mb-chip:hover { border-color: var(--mb-accent); color: var(--mb-accent); }

/* ============ Escritura ============ */

.mb-composer {
	flex: none;
	display: flex; align-items: flex-end; gap: 8px;
	padding: 11px 12px;
	border-top: 1px solid var(--mb-line);
	background: var(--mb-white);
}

.mb-input {
	flex: 1;
	min-height: 42px; max-height: 110px;
	padding: 11px 13px;
	border: 1px solid var(--mb-line);
	border-radius: 13px;
	background: var(--mb-soft);
	color: var(--mb-ink);
	font-family: inherit; font-size: 14.5px; line-height: 1.4;
	resize: none;
}
.mb-input:focus { outline: none; border-color: var(--mb-accent); background: #fff; }

.mb-send {
	width: 42px; height: 42px; flex: none;
	display: grid; place-items: center;
	border: 0; border-radius: 13px;
	background: var(--mb-accent); color: #fff;
	font-size: 16px; cursor: pointer;
}
.mb-send:disabled { opacity: .45; cursor: not-allowed; }

.mb-foot {
	padding: 0 12px 9px;
	background: var(--mb-white);
	font-size: 10.5px; color: var(--mb-muted); text-align: center;
}

/* Aviso flotante al agregar al carrito */
.mb-toast {
	position: absolute;
	left: 50%; bottom: 74px;
	transform: translateX(-50%);
	padding: 9px 15px;
	border-radius: 11px;
	background: var(--mb-ink);
	color: #fff;
	font-size: 12.5px; font-weight: 600;
	white-space: nowrap;
	z-index: 5;
	animation: mb-in .2s ease both;
}

/* ============ Celular ============ */

@media (max-width: 600px) {
	.mb-panel {
		right: 6px;
		left: 6px;
		bottom: 6px;
		width: auto;
		max-height: none;
		border-radius: 17px;

		/* --mb-vh lo calcula el script con la altura real visible del navegador.
		   Con 100vh el encabezado quedaba tapado por la barra de direcciones. */
		height: calc(100vh - 12px);
		height: calc(var(--mb-vh, 100vh) - 12px);
		padding-bottom: env(safe-area-inset-bottom, 0px);
	}

	/* Botones de cerrar y reiniciar más grandes para el dedo */
	.mb-ico { width: 38px; height: 38px; font-size: 20px; }
	.mb-header { padding: 12px 10px 12px 14px; }

	.mb-bubble { max-width: 160px; font-size: 12.5px; }
	.mb-launcher { width: 62px; height: 62px; }
	.mb-launcher img { width: 46px; height: 46px; margin: 8px; }

	.mb-card-actions { gap: 4px; }
	.mb-btn { padding: 8px 10px; }
}

@media (prefers-reduced-motion: reduce) {
	.mb-launcher::before, .mb-pulse, .mb-typing i { animation: none !important; }
	.mb-panel, .mb-msg, .mb-bubble { transition: none; animation: none; }
}
