/*! Chatnegocio widget v0.1.0 — mobile-first 320px+, tema claro.
 * Prefijo .chn- para evitar colisiones con Listeo y resto de plugins.
 * Tokens en --chn-* dentro de .chn-root para que cada listing pueda override
 * --chn-primary desde el inline style del contenedor.
 */

.chn-root {
	/* Tokens. Defaults para tema claro canarias. */
	--chn-primary: #F5C518;
	--chn-primary-ink: #0D1A2E;
	--chn-ink: #0D1A2E;
	--chn-ink-soft: #1F2937;
	--chn-cream: #F9F5EC;
	--chn-white: #FFFFFF;
	--chn-g50: #F9FAFB;
	--chn-g100: #F3F4F6;
	--chn-g200: #E5E7EB;
	--chn-g300: #D1D5DB;
	--chn-g400: #9CA3AF;
	--chn-g500: #6B7280;
	--chn-g600: #4B5563;
	--chn-g700: #374151;
	--chn-success: #15803D;
	--chn-success-bg: #DCFCE7;
	--chn-danger: #B91C1C;
	--chn-danger-bg: #FEE2E2;
	--chn-whatsapp: #25D366;
	--chn-radius: 14px;
	--chn-radius-sm: 10px;
	--chn-shadow-launcher: 0 8px 24px rgba(13, 26, 46, 0.18);
	--chn-shadow-panel: 0 18px 48px rgba(13, 26, 46, 0.22);
	--chn-z-launcher: 99998;
	--chn-z-panel: 99999;
	--chn-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

	font-family: var(--chn-font);
}

/* Anti-collisions Listeo: aislar tipografía/box-sizing en todo lo .chn-* */
.chn-root *,
.chn-root *::before,
.chn-root *::after {
	box-sizing: border-box;
}

.chn-mount {
	position: static;
}

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

.chn-hp {
	position: absolute !important;
	left: -9999px !important;
	width: 1px !important;
	height: 1px !important;
	opacity: 0 !important;
	pointer-events: none !important;
}

.chn-no-scroll {
	overflow: hidden !important;
}

/* ============================================================
   Launcher (botón flotante)
   ============================================================ */
.chn-launcher {
	position: fixed;
	/* Chatnegocio en BOTTOM-RIGHT (posición esperada para chat principal).
	   Cuando Chatnegocio está activo en una ficha, class-frontend.php
	   inyecta CSS que mueve a Pío a la izquierda para evitar solape. */
	right: 16px;
	left: auto;
	bottom: 16px;
	width: 60px;
	height: 60px;
	border-radius: 50%;
	border: 0;
	background: var(--chn-primary);
	color: var(--chn-primary-ink);
	cursor: pointer;
	box-shadow: var(--chn-shadow-launcher);
	z-index: var(--chn-z-launcher);
	display: flex;
	align-items: center;
	justify-content: center;
	font-family: var(--chn-font);
	font-weight: 700;
	font-size: 20px;
	letter-spacing: -0.02em;
	transition: transform 0.18s ease, box-shadow 0.18s ease;
	overflow: hidden;
}

.chn-launcher:hover {
	transform: translateY(-2px);
	box-shadow: 0 12px 28px rgba(13, 26, 46, 0.24);
}

/* Cuando el panel está abierto, ocultamos el launcher para no ver el botón
   asomando detrás del panel. Patrón estándar (Intercom, Drift, Crisp). */
.chn-is-open .chn-launcher {
	transform: scale(0);
	opacity: 0;
	pointer-events: none;
	transition: transform 0.18s ease, opacity 0.18s ease;
}

.chn-launcher:focus-visible {
	outline: 3px solid var(--chn-primary);
	outline-offset: 3px;
}

.chn-launcher-initials {
	font-size: 20px;
	font-weight: 800;
	line-height: 1;
	letter-spacing: -0.02em;
}

.chn-launcher-img {
	display: flex;
	width: 100%;
	height: 100%;
	align-items: center;
	justify-content: center;
}

.chn-launcher-img img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.chn-launcher-dot {
	position: absolute;
	top: 6px;
	right: 6px;
	width: 12px;
	height: 12px;
	border-radius: 50%;
	background: var(--chn-success);
	border: 2px solid var(--chn-white);
	box-shadow: 0 0 0 0 rgba(21, 128, 61, 0.4);
	animation: chn-pulse 2.4s ease-out infinite;
}

@keyframes chn-pulse {
	0%   { box-shadow: 0 0 0 0 rgba(21, 128, 61, 0.5); }
	60%  { box-shadow: 0 0 0 10px rgba(21, 128, 61, 0); }
	100% { box-shadow: 0 0 0 0 rgba(21, 128, 61, 0); }
}

/* ============================================================
   Panel
   ============================================================ */
.chn-panel {
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	top: auto;
	max-height: 85vh;
	max-height: 85dvh;
	height: 85vh;
	height: 85dvh;
	background: var(--chn-white);
	border-radius: 18px 18px 0 0;
	box-shadow: var(--chn-shadow-panel);
	z-index: var(--chn-z-panel);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	color: var(--chn-ink);
	font-family: var(--chn-font);
	font-size: 15px;
	line-height: 1.5;
	animation: chn-slide-up 0.22s ease-out;
}

.chn-panel[hidden] {
	display: none;
}

@keyframes chn-slide-up {
	from { transform: translateY(20px); opacity: 0; }
	to   { transform: translateY(0);     opacity: 1; }
}

/* Tablet / desktop ≥768px: floating box bottom-right (alineado con launcher).
   Hasta 768px el panel ocupa todo el ancho (mobile + tablet vertical). */
@media (min-width: 768px) {
	.chn-panel {
		right: 16px;
		left: auto;
		bottom: 88px;
		width: 400px;
		max-width: calc(100vw - 32px);
		height: 620px;
		max-height: calc(100vh - 110px);
		border-radius: 16px;
		animation: chn-fade-in 0.22s ease-out;
	}
}

@keyframes chn-fade-in {
	from { transform: translateY(8px) scale(0.98); opacity: 0; }
	to   { transform: translateY(0)    scale(1);    opacity: 1; }
}

/* ============================================================
   Header
   ============================================================ */
.chn-head {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 12px 14px;
	background: linear-gradient(180deg, var(--chn-cream) 0%, var(--chn-white) 100%);
	border-bottom: 1px solid var(--chn-g200);
	min-height: 60px;
}

.chn-head-avatar,
.chn-head-initials {
	width: 36px;
	height: 36px;
	border-radius: 50%;
	background: var(--chn-primary);
	color: var(--chn-primary-ink);
	display: flex;
	align-items: center;
	justify-content: center;
	font-weight: 800;
	font-size: 14px;
	letter-spacing: -0.02em;
	flex-shrink: 0;
	overflow: hidden;
}

.chn-head-avatar { object-fit: cover; }

.chn-head-logo {
	max-height: 36px;
	max-width: 140px;
	width: auto;
	height: auto;
	object-fit: contain;
}

.chn-head-text {
	flex: 1 1 auto;
	min-width: 0;
}

.chn-head-name {
	font-weight: 700;
	font-size: 15px;
	color: var(--chn-ink);
	line-height: 1.25;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.chn-head-sub {
	font-size: 12px;
	color: var(--chn-g600);
	line-height: 1.25;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.chn-head-close {
	width: 36px;
	height: 36px;
	border-radius: 50%;
	border: 0;
	background: transparent;
	color: var(--chn-g600);
	font-size: 24px;
	line-height: 1;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.15s ease;
	flex-shrink: 0;
}

.chn-head-close:hover {
	background: var(--chn-g100);
	color: var(--chn-ink);
}

.chn-head-close:focus-visible {
	outline: 2px solid var(--chn-primary);
	outline-offset: 2px;
}

/* ============================================================
   Messages
   ============================================================ */
.chn-messages {
	flex: 1 1 auto;
	overflow-y: auto;
	overflow-x: hidden;
	padding: 14px 14px 8px;
	background: var(--chn-cream);
	display: flex;
	flex-direction: column;
	gap: 10px;
	overscroll-behavior: contain;
	scroll-behavior: smooth;
	-webkit-overflow-scrolling: touch;
}

.chn-msg {
	max-width: 85%;
	padding: 10px 14px;
	border-radius: var(--chn-radius);
	font-size: 15px;
	line-height: 1.45;
	word-wrap: break-word;
	overflow-wrap: anywhere;
	white-space: normal;
	animation: chn-msg-in 0.18s ease-out;
}

@keyframes chn-msg-in {
	from { transform: translateY(4px); opacity: 0; }
	to   { transform: translateY(0);    opacity: 1; }
}

.chn-msg--user {
	align-self: flex-end;
	background: var(--chn-primary);
	color: var(--chn-primary-ink);
	border-bottom-right-radius: 4px;
	font-weight: 500;
}

.chn-msg--assistant {
	align-self: flex-start;
	background: var(--chn-white);
	color: var(--chn-ink);
	border: 1px solid var(--chn-g200);
	border-left: 3px solid var(--chn-primary);
	border-bottom-left-radius: 4px;
}

.chn-msg--assistant a:not(.chn-cta) {
	color: var(--chn-ink);
	text-decoration: underline;
}

/* CTAs inline (markdown links del asistente). */
.chn-cta {
	display: inline-block;
	margin: 6px 6px 0 0;
	padding: 8px 14px;
	border-radius: 999px;
	font-size: 13px;
	font-weight: 600;
	text-decoration: none;
	border: 1px solid var(--chn-g300);
	background: var(--chn-white);
	color: var(--chn-ink);
	transition: transform 0.12s ease, background 0.15s ease;
}

.chn-cta:hover {
	transform: translateY(-1px);
}

.chn-cta--primary {
	background: var(--chn-primary);
	color: var(--chn-primary-ink);
	border-color: var(--chn-primary);
}

.chn-cta--whatsapp {
	background: var(--chn-whatsapp);
	color: #FFFFFF;
	border-color: var(--chn-whatsapp);
}

.chn-cta--whatsapp:hover {
	background: #1FB957;
}

/* Typing indicator. */
.chn-typing {
	display: inline-flex;
	gap: 4px;
	padding: 12px 14px;
}

.chn-typing-dot {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--chn-g400);
	animation: chn-bounce 1.2s ease-in-out infinite;
}

.chn-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.chn-typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes chn-bounce {
	0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
	30%           { transform: translateY(-6px); opacity: 1; }
}

/* ============================================================
   Error bar
   ============================================================ */
.chn-error {
	padding: 10px 14px;
	background: var(--chn-danger-bg);
	color: var(--chn-danger);
	font-size: 13px;
	font-weight: 500;
	border-top: 1px solid #FCA5A5;
	border-bottom: 1px solid #FCA5A5;
}

.chn-error[hidden] {
	display: none;
}

/* ============================================================
   CTA bar persistente (Reservar / WhatsApp / Lead)
   ============================================================ */
.chn-cta-bar {
	display: flex;
	flex-wrap: wrap;             /* Si no caben en 1 línea, saltan a 2 — sin scroll oculto */
	gap: 6px;
	padding: 10px 14px;
	background: var(--chn-white);
	border-top: 1px solid var(--chn-g200);
	/* Sombra sutil hacia arriba para separar visualmente del scroll de mensajes. */
	box-shadow: 0 -6px 12px -6px rgba(13, 26, 46, 0.10);
	position: relative;
	z-index: 2;
	min-width: 0;
}

.chn-cta-bar::-webkit-scrollbar { display: none; }

.chn-cta-bar-btn {
	flex: 0 0 auto;
	padding: 8px 14px;
	border-radius: 999px;
	font-size: 13px;
	font-weight: 600;
	text-decoration: none;
	border: 1px solid var(--chn-g200);
	background: var(--chn-white);
	color: var(--chn-ink);
	cursor: pointer;
	white-space: nowrap;
	font-family: var(--chn-font);
	transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}

.chn-cta-bar-btn:hover {
	transform: translateY(-1px);
	border-color: var(--chn-g400);
}

.chn-cta-bar-btn--primary {
	background: var(--chn-primary);
	color: var(--chn-primary-ink);
	border-color: var(--chn-primary);
}

.chn-cta-bar-btn--whatsapp {
	background: var(--chn-whatsapp);
	color: #FFFFFF;
	border-color: var(--chn-whatsapp);
}

.chn-cta-bar-btn--whatsapp:hover {
	background: #1FB957;
	border-color: #1FB957;
}

.chn-cta-bar-btn--lead {
	background: var(--chn-g100);
	color: var(--chn-ink);
	border-color: var(--chn-g200);
}

/* ============================================================
   Input row
   ============================================================ */
.chn-input-row {
	/* CSS Grid en vez de flex: el input ocupa 1fr, el botón send ocupa columna
	   fija de 42px. Predecible y robusto frente a reglas globales del tema que
	   pueden forzar textarea{width:100%}. */
	display: grid;
	grid-template-columns: 1fr 42px;
	grid-template-rows: auto;
	align-items: end;
	gap: 8px;
	padding: 10px 14px 12px;
	background: var(--chn-white);
	border-top: 1px solid var(--chn-g200);
	min-width: 0;
	box-sizing: border-box;
}

.chn-input {
	/* Con CSS Grid el input ocupa su columna 1fr — el tema Listeo no puede
	   empujarlo fuera porque la columna tiene tamaño calculado por el grid. */
	width: 100%;
	min-width: 0;
	min-height: 42px;
	max-height: 120px;
	padding: 10px 14px;
	border-radius: 20px;
	border: 1px solid var(--chn-g200);
	background: var(--chn-white);
	color: var(--chn-ink);
	font-family: var(--chn-font);
	font-size: 16px;          /* 16px previene zoom automático en iOS Safari */
	line-height: 1.4;
	resize: none;
	overflow-y: auto;
	box-sizing: border-box;
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

@media (min-width: 768px) {
	.chn-input {
		font-size: 15px;      /* en desktop podemos volver a 15 sin zoom issue */
	}
}

.chn-input::placeholder {
	color: var(--chn-g500);
}

.chn-input:focus-visible {
	outline: 0;
	border-color: var(--chn-primary);
	box-shadow: 0 0 0 3px rgba(245, 197, 24, 0.18);
}

.chn-input:disabled {
	background: var(--chn-g50);
	color: var(--chn-g500);
	cursor: not-allowed;
}

.chn-send {
	width: 42px;
	height: 42px;
	border-radius: 50%;
	border: 0;
	background: var(--chn-primary);
	color: var(--chn-primary-ink);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	padding: 0;
	transition: transform 0.12s ease, opacity 0.15s ease;
}

.chn-send:hover {
	transform: scale(1.05);
}

.chn-send:focus-visible {
	outline: 2px solid var(--chn-primary);
	outline-offset: 2px;
}

.chn-send:disabled,
.chn-send.is-loading {
	opacity: 0.6;
	cursor: not-allowed;
	transform: none;
}

.chn-send-icon {
	display: flex;
	align-items: center;
	justify-content: center;
}

.chn-send-icon svg {
	width: 18px;
	height: 18px;
}

/* ============================================================
   Footer (Powered by)
   ============================================================ */
.chn-foot {
	padding: 6px 14px 10px;
	background: var(--chn-white);
	text-align: center;
	border-top: 1px solid var(--chn-g100);
}

.chn-foot-text {
	font-size: 11px;
	font-weight: 500;
	color: var(--chn-g500);
	letter-spacing: 0.04em;
	text-transform: uppercase;
}

/* ============================================================
   Lead form overlay
   ============================================================ */
.chn-lead-overlay {
	position: absolute;
	inset: 0;
	background: rgba(13, 26, 46, 0.55);
	display: flex;
	align-items: flex-end;
	justify-content: center;
	z-index: 10;
	animation: chn-fade-in 0.18s ease-out;
}

@media (min-width: 600px) {
	.chn-lead-overlay {
		align-items: center;
	}
}

.chn-lead-card {
	background: var(--chn-white);
	border-radius: 16px 16px 0 0;
	width: 100%;
	max-width: 360px;
	padding: 18px;
	box-shadow: var(--chn-shadow-panel);
	animation: chn-slide-up 0.18s ease-out;
}

@media (min-width: 600px) {
	.chn-lead-card {
		border-radius: 16px;
		margin: 0 16px;
	}
}

.chn-lead-title {
	font-size: 16px;
	font-weight: 700;
	color: var(--chn-ink);
	margin-bottom: 12px;
}

.chn-lead-form {
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.chn-lead-input {
	width: 100%;
	padding: 11px 14px;
	border-radius: 10px;
	border: 1px solid var(--chn-g200);
	background: var(--chn-white);
	color: var(--chn-ink);
	font-family: var(--chn-font);
	font-size: 15px;
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.chn-lead-input::placeholder {
	color: var(--chn-g500);
}

.chn-lead-input:focus-visible {
	outline: 0;
	border-color: var(--chn-primary);
	box-shadow: 0 0 0 3px rgba(245, 197, 24, 0.18);
}

.chn-lead-textarea {
	min-height: 70px;
	resize: vertical;
	line-height: 1.4;
}

.chn-lead-err {
	font-size: 13px;
	color: var(--chn-danger);
}

.chn-lead-err[hidden] { display: none; }

.chn-lead-actions {
	display: flex;
	gap: 8px;
	justify-content: flex-end;
	margin-top: 4px;
}

.chn-lead-cancel,
.chn-lead-submit {
	padding: 10px 16px;
	border-radius: 999px;
	font-size: 14px;
	font-weight: 600;
	cursor: pointer;
	font-family: var(--chn-font);
	transition: transform 0.12s ease;
}

.chn-lead-cancel {
	background: var(--chn-white);
	color: var(--chn-ink);
	border: 1px solid var(--chn-g300);
}

.chn-lead-submit {
	background: var(--chn-primary);
	color: var(--chn-primary-ink);
	border: 1px solid var(--chn-primary);
}

.chn-lead-submit:disabled {
	opacity: 0.6;
	cursor: not-allowed;
}

.chn-lead-cancel:hover,
.chn-lead-submit:hover {
	transform: translateY(-1px);
}

/* ============================================================
   Voice overlay (ElevenLabs Conversational AI)
   ============================================================ */
.chn-cta-bar-btn--voice {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	background: var(--chn-primary-ink);
	color: var(--chn-white);
	border-color: var(--chn-primary-ink);
}

.chn-cta-bar-btn--voice:hover {
	background: #1a2a47;
	border-color: #1a2a47;
}

.chn-voice-icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
}

.chn-voice-overlay {
	position: absolute;
	inset: 0;
	background: linear-gradient(180deg, var(--chn-white) 0%, var(--chn-cream) 100%);
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 18px;
	z-index: 11;
	animation: chn-fade-in 0.2s ease-out;
}

.chn-voice-orb {
	position: relative;
	width: 120px;
	height: 120px;
	border-radius: 50%;
	background: var(--chn-primary);
	color: var(--chn-primary-ink);
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 16px 40px rgba(245, 197, 24, 0.35);
}

.chn-voice-orb-pulse {
	position: absolute;
	inset: -16px;
	border-radius: 50%;
	background: var(--chn-primary);
	opacity: 0.32;
	animation: chn-voice-pulse 1.8s ease-out infinite;
}

.chn-voice-orb-icon {
	position: relative;
	z-index: 1;
	display: inline-flex;
	align-items: center;
	justify-content: center;
}

@keyframes chn-voice-pulse {
	0%   { transform: scale(0.8);  opacity: 0.45; }
	100% { transform: scale(1.35); opacity: 0; }
}

/* Estados de la orb segun voice status */
.chn-voice-overlay[data-status="connecting"] .chn-voice-orb-pulse { animation-duration: 1s; }
.chn-voice-overlay[data-status="listening"]  .chn-voice-orb-pulse { animation-duration: 2.4s; opacity: 0.25; }
.chn-voice-overlay[data-status="speaking"]   .chn-voice-orb { animation: chn-voice-speak 0.8s ease-in-out infinite alternate; }
.chn-voice-overlay[data-status="speaking"]   .chn-voice-orb-pulse { animation: none; opacity: 0; }
.chn-voice-overlay[data-status="error"]      .chn-voice-orb { background: var(--chn-danger); color: var(--chn-white); box-shadow: 0 16px 40px rgba(185, 28, 28, 0.35); }
.chn-voice-overlay[data-status="error"]      .chn-voice-orb-pulse { animation: none; opacity: 0; }

@keyframes chn-voice-speak {
	from { transform: scale(1);    box-shadow: 0 16px 40px rgba(245, 197, 24, 0.35); }
	to   { transform: scale(1.08); box-shadow: 0 18px 52px rgba(245, 197, 24, 0.55); }
}

.chn-voice-status-label {
	font-size: 15px;
	font-weight: 600;
	color: var(--chn-ink);
	text-align: center;
	padding: 0 16px;
}

.chn-voice-hangup {
	padding: 12px 24px;
	border-radius: 999px;
	border: 0;
	background: var(--chn-danger);
	color: var(--chn-white);
	font-family: var(--chn-font);
	font-size: 14px;
	font-weight: 600;
	cursor: pointer;
	box-shadow: 0 4px 14px rgba(185, 28, 28, 0.32);
	transition: transform 0.12s ease;
}

.chn-voice-hangup:hover {
	transform: translateY(-1px);
}

.chn-voice-hangup:focus-visible {
	outline: 2px solid var(--chn-primary);
	outline-offset: 2px;
}

/* ============================================================
   No-script fallback
   ============================================================ */
.chn-noscript {
	font-size: 13px;
	color: var(--chn-g600);
	background: var(--chn-cream);
	border: 1px solid var(--chn-g200);
	padding: 12px 14px;
	border-radius: 8px;
	margin: 16px 0;
}

/* ============================================================
   Reduced motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
	.chn-launcher,
	.chn-panel,
	.chn-msg,
	.chn-cta,
	.chn-cta-bar-btn,
	.chn-launcher-dot,
	.chn-typing-dot {
		animation: none !important;
		transition: none !important;
	}
	.chn-launcher:hover,
	.chn-send:hover,
	.chn-cta:hover,
	.chn-cta-bar-btn:hover,
	.chn-lead-cancel:hover,
	.chn-lead-submit:hover {
		transform: none;
	}
}
