/* EAI Labs – Chat en Vivo · widget del visitante
 * Móvil primero: en pantallas ≤ 600 px la ventana ocupa toda la pantalla.
 * Todas las clases empiezan por "eai-chat" para no chocar con Houzez/Bootstrap.
 */
.eai-chat {
	--eai-c: var(--eai-chat-color, #00aeff);
	--eai-bg: #fff;
	--eai-ink: #1f2933;
	--eai-mute: #6b7280;
	--eai-line: #e5e7eb;
	position: fixed;
	z-index: 99990; /* por encima de la cabecera fija de Houzez (1000) y por debajo del lightbox (99999) */
	bottom: calc(16px + env(safe-area-inset-bottom, 0px));
	right: 16px;
	font-family: inherit;
	font-size: 15px;
	line-height: 1.45;
	color: var(--eai-ink);
}
.eai-chat[data-position="left"] { right: auto; left: 16px; }
.eai-chat [hidden] { display: none !important; }
.eai-chat *, .eai-chat *::before, .eai-chat *::after { box-sizing: border-box; }
.eai-chat svg { width: 22px; height: 22px; fill: currentColor; stroke: currentColor; stroke-width: 0; }

/* Etiqueta de quién habla (Armando · Asistente virtual / nombre del consultor) */
.eai-chat__who { font-size: 11px; color: var(--eai-mute); padding: 0 4px 2px; font-weight: 600; }
/* Opciones (botones de Armando e inicio rápido) */
.eai-chat__options { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 4px; }
.eai-chat__opt {
	border: 1.5px solid var(--eai-c); background: #fff; color: var(--eai-c);
	border-radius: 999px; padding: 8px 12px; min-height: 40px; font: inherit; font-size: 14px; font-weight: 600;
	cursor: pointer; text-align: left; line-height: 1.2;
}
.eai-chat__opt:hover, .eai-chat__opt:focus-visible { background: var(--eai-c); color: #fff; }
.eai-chat__intro .eai-chat__options { margin-top: 10px; }
.eai-chat__msg--bot { align-self: flex-start; }
.eai-chat__msg--bot p { background: #fff; border: 1px solid var(--eai-line); border-bottom-left-radius: 4px; }
.eai-chat__msg--bot.eai-chat__msg--handoff p { background: #fefce8; border-color: #fde68a; }
.eai-chat__msg--bot.eai-chat__msg--property { align-self: stretch; max-width: 100%; }
.eai-chat__consent.is-error { color: #b91c1c; }
.eai-chat__consent.is-error input { outline: 2px solid #b91c1c; outline-offset: 1px; }

/* Burbuja */
.eai-chat__launcher {
	position: relative;
	width: 58px; height: 58px;
	border: 0; border-radius: 50%;
	background: var(--eai-c); color: #fff;
	display: flex; align-items: center; justify-content: center;
	box-shadow: 0 6px 20px rgba(0,0,0,.2);
	cursor: pointer;
	transition: transform .15s ease;
	margin-left: auto;
}
.eai-chat[data-position="left"] .eai-chat__launcher { margin-left: 0; }
.eai-chat__launcher:hover { transform: scale(1.05); }
.eai-chat__launcher:focus-visible, .eai-chat button:focus-visible, .eai-chat a:focus-visible { outline: 3px solid rgba(0,0,0,.35); outline-offset: 2px; }
.eai-chat__launcher svg { width: 28px; height: 28px; }
.eai-chat.has-online .eai-chat__launcher::after {
	content: ""; position: absolute; right: 4px; top: 4px;
	width: 12px; height: 12px; border-radius: 50%; background: #22c55e; border: 2px solid #fff;
}
.eai-chat__badge {
	position: absolute; top: -4px; left: -4px;
	min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px;
	background: #ef4444; color: #fff; font-size: 12px; font-weight: 700; line-height: 22px; text-align: center;
}
.eai-chat__teaser {
	position: relative; display: flex; align-items: flex-start; gap: 4px;
	max-width: min(290px, calc(100vw - 32px)); margin: 0 0 10px auto;
	background: #fff; border-radius: 14px 14px 4px 14px; box-shadow: 0 6px 22px rgba(0,0,0,.18);
	animation: eaiChatPop .35s ease-out;
}
.eai-chat[data-position="left"] .eai-chat__teaser { margin: 0 auto 10px 0; border-radius: 14px 14px 14px 4px; }
.eai-chat__teasertext {
	flex: 1; border: 0; background: none; text-align: left; cursor: pointer;
	padding: 12px 4px 12px 14px; font: inherit; font-size: 14px; font-weight: 600; color: var(--eai-ink); line-height: 1.35;
}
.eai-chat__teaserx { border: 0; background: none; color: var(--eai-mute); font-size: 20px; line-height: 1; padding: 8px 10px; cursor: pointer; min-width: 36px; min-height: 36px; }
@keyframes eaiChatPop { from { opacity: 0; transform: translateY(8px) scale(.97); } to { opacity: 1; transform: none; } }

/* Ventana */
.eai-chat__panel {
	position: fixed; inset: 0;
	display: flex; flex-direction: column;
	background: var(--eai-bg);
	padding-bottom: env(safe-area-inset-bottom, 0px);
}
html.eai-chat-lock, html.eai-chat-lock body { overflow: hidden; }

@media (min-width: 601px) {
	.eai-chat__panel {
		position: absolute; inset: auto 0 72px auto;
		width: 370px; height: min(600px, calc(100vh - 110px));
		border-radius: 14px; overflow: hidden;
		box-shadow: 0 12px 40px rgba(0,0,0,.22);
		padding-bottom: 0;
	}
	.eai-chat[data-position="left"] .eai-chat__panel { inset: auto auto 72px 0; }
	.eai-chat.is-open .eai-chat__teaser { display: none; }
}

.eai-chat__head {
	display: flex; align-items: center; gap: 10px;
	padding: 12px 12px 12px 14px;
	padding-top: calc(12px + env(safe-area-inset-top, 0px));
	background: var(--eai-c); color: #fff;
}
.eai-chat__avatar {
	position: relative; flex: 0 0 40px; width: 40px; height: 40px; border-radius: 50%;
	background: rgba(255,255,255,.2); display: flex; align-items: center; justify-content: center;
}
.eai-chat__avatar img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; }
.eai-chat__avatar.is-online::after {
	content: ""; position: absolute; right: -1px; bottom: -1px;
	width: 11px; height: 11px; border-radius: 50%; background: #22c55e; border: 2px solid var(--eai-c);
}
.eai-chat__headtext { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.eai-chat__headtext strong { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.eai-chat__sub { font-size: 12px; opacity: .9; }
.eai-chat__wa, .eai-chat__close {
	flex: 0 0 40px; width: 40px; height: 40px; border: 0; border-radius: 50%;
	display: flex; align-items: center; justify-content: center;
	background: rgba(255,255,255,.15); color: #fff; cursor: pointer; text-decoration: none;
}
.eai-chat__wa:hover, .eai-chat__close:hover { background: rgba(255,255,255,.28); color: #fff; }
.eai-chat__close svg { stroke-width: 2.4; fill: none; }

.eai-chat__intro { padding: 14px 16px 0; color: var(--eai-mute); }
.eai-chat__intro p { margin: 0 0 8px; }
.eai-chat__chip { display: inline-block; padding: 6px 10px; border-radius: 8px; background: #f3f4f6; color: var(--eai-ink); font-size: 13px; }

/* Mensajes */
.eai-chat__list {
	flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
	padding: 12px 12px 4px; display: flex; flex-direction: column; gap: 8px;
	background: #f8fafc;
}
.eai-chat__msg { max-width: 85%; display: flex; flex-direction: column; }
.eai-chat__msg p { margin: 0; padding: 9px 12px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; }
.eai-chat__msg time { font-size: 11px; color: var(--eai-mute); margin-top: 2px; padding: 0 4px; }
.eai-chat__msg--visitor { align-self: flex-end; align-items: flex-end; }
.eai-chat__msg--visitor p { background: var(--eai-c); color: #fff; border-bottom-right-radius: 4px; }
.eai-chat__msg--visitor p a { color: #fff; text-decoration: underline; }
.eai-chat__msg--agent { align-self: flex-start; }
.eai-chat__msg--agent p { background: #fff; border: 1px solid var(--eai-line); border-bottom-left-radius: 4px; }
.eai-chat__msg--system { align-self: center; max-width: 92%; text-align: center; }
.eai-chat__msg--system p { background: transparent; color: var(--eai-mute); font-size: 13px; padding: 4px 8px; }
.eai-chat__msg--system.eai-chat__msg--property { align-self: stretch; max-width: 100%; }

/* Tarjeta de propiedad */
.eai-chat__card {
	display: flex; gap: 10px; margin-top: 4px;
	background: #fff; border: 1px solid var(--eai-line); border-radius: 12px; overflow: hidden;
	color: var(--eai-ink); text-decoration: none; text-align: left;
}
.eai-chat__card:hover { border-color: var(--eai-c); color: var(--eai-ink); }
.eai-chat__card img { flex: 0 0 96px; width: 96px; height: 96px; object-fit: cover; }
.eai-chat__cardbody { padding: 8px 10px 8px 0; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.eai-chat__cardbody strong { font-size: 14px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.eai-chat__price { font-weight: 700; color: var(--eai-c); }
.eai-chat__cardbody small { color: var(--eai-mute); font-size: 12px; }
.eai-chat__sold { font-style: normal; font-size: 11px; font-weight: 700; color: #b91c1c; text-transform: uppercase; }
.eai-chat__cta { font-size: 12px; font-weight: 600; color: var(--eai-c); }

.eai-chat__typing { padding: 2px 16px 6px; font-size: 12px; color: var(--eai-mute); font-style: italic; background: #f8fafc; }

/* Formulario de contacto dentro del chat */
.eai-chat__contact { background: #fff; border: 1px solid var(--eai-line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.eai-chat__contact strong { font-size: 14px; }
.eai-chat__contact p { margin: 0; color: #15803d; }
.eai-chat__actions { display: flex; gap: 10px; align-items: center; }
.eai-chat__btn { border: 0; border-radius: 8px; padding: 10px 14px; min-height: 44px; background: var(--eai-c); color: #fff; font-weight: 600; cursor: pointer; }
.eai-chat__btn:disabled { opacity: .6; }
.eai-chat__link { border: 0; background: none; color: var(--eai-mute); text-decoration: underline; cursor: pointer; min-height: 44px; }

/* Barra de escritura */
.eai-chat__form { border-top: 1px solid var(--eai-line); padding: 8px 10px 10px; background: #fff; display: flex; flex-direction: column; gap: 6px; }
.eai-chat__pre { display: grid; grid-template-columns: 1fr; gap: 6px; }
.eai-chat__field, .eai-chat__input {
	width: 100%; border: 1px solid var(--eai-line); border-radius: 10px; padding: 10px 12px;
	font: inherit; font-size: 16px; /* 16 px evita el zoom automático del iPhone */
	color: var(--eai-ink); background: #fff; margin: 0;
}
.eai-chat__field:focus, .eai-chat__input:focus { outline: none; border-color: var(--eai-c); box-shadow: 0 0 0 3px rgba(0,0,0,.06); }
.eai-chat__consent { display: flex; gap: 8px; align-items: flex-start; font-size: 12px; color: var(--eai-mute); margin: 0; font-weight: 400; }
.eai-chat__consent input { margin-top: 2px; width: 18px; height: 18px; flex: 0 0 18px; }
.eai-chat__consent a { color: var(--eai-c); }
.eai-chat__hp { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; opacity: 0; }
.eai-chat__error { font-size: 13px; color: #b91c1c; }
.eai-chat__row { display: flex; gap: 8px; align-items: flex-end; }
.eai-chat__input { resize: none; max-height: 120px; line-height: 1.35; }
.eai-chat__send {
	flex: 0 0 44px; width: 44px; height: 44px; border: 0; border-radius: 50%;
	background: var(--eai-c); color: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.eai-chat__send:disabled { opacity: .5; }

@media (prefers-reduced-motion: reduce) { .eai-chat__launcher { transition: none; } }

/* En el móvil, cuando está abierto, la burbuja no tapa el campo de escribir */
@media (max-width: 600px) {
	.eai-chat.is-open .eai-chat__launcher, .eai-chat.is-open .eai-chat__teaser { display: none; }
}

/* Tarjeta sin foto: margen izquierdo */
.eai-chat__card > .eai-chat__cardbody:first-child { padding-left: 12px; }


/* ================= 0.3 · Marca EAI: azul marino, dorado y crema ================= */
.eai-chat { --eai-gold: var(--eai-chat-accent, #c9a64a); --eai-cream: #fbf8f1; --eai-line: #ece4d2; --eai-ink: #14213a; }
.eai-chat__launcher { box-shadow: 0 8px 24px rgba(10,35,71,.32); border: 3px solid var(--eai-gold); }
.eai-chat__launcher img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.eai-chat__head { background: var(--eai-c); border-bottom: 3px solid var(--eai-gold); }
.eai-chat__avatar { flex-basis: 46px; width: 46px; height: 46px; border: 2px solid var(--eai-gold); background: #fff; }
.eai-chat__avatar img { width: 42px; height: 42px; }
.eai-chat__avatar.is-online::after { background: #22c55e; }
.eai-chat__sub { color: #f3e7c4; opacity: 1; }
.eai-chat__list, .eai-chat__typing { background: var(--eai-cream); }
.eai-chat__msg p { border-radius: 18px; line-height: 1.45; }
.eai-chat__msg--bot p { border: 1px solid var(--eai-line); box-shadow: 0 1px 2px rgba(20,33,58,.05); }
.eai-chat__msg--bot.eai-chat__msg--handoff p { background: #fff8e6; border-color: var(--eai-gold); }
.eai-chat__msg--agent p { border-color: var(--eai-line); box-shadow: 0 1px 2px rgba(20,33,58,.05); }
.eai-chat__who { color: #8a6d1f; }
.eai-chat__opt { border-color: var(--eai-gold); color: var(--eai-c); background: #fff; }
.eai-chat__opt:hover, .eai-chat__opt:focus-visible { background: var(--eai-gold); color: var(--eai-c); border-color: var(--eai-gold); }
.eai-chat__send, .eai-chat__btn { background: var(--eai-gold); color: var(--eai-c); }
.eai-chat__price, .eai-chat__cta { color: #8a6d1f; }
.eai-chat__card:hover { border-color: var(--eai-gold); }
.eai-chat__field:focus, .eai-chat__input:focus { border-color: var(--eai-gold); box-shadow: 0 0 0 3px rgba(201,166,74,.18); }
.eai-chat__chip { background: #fff; border: 1px solid var(--eai-line); }
.eai-chat__teaser { border: 1px solid var(--eai-gold) !important; }

/* ================= 0.3.1 · Más vida en el chat ================= */
.eai-chat__msg { animation: eai-chat-in .25s ease-out; }
.eai-chat__typing { display: flex; align-items: center; gap: 8px; font-style: normal; padding: 4px 16px 8px; }
.eai-chat__dots { display: inline-flex; gap: 4px; background: #fff; border: 1px solid var(--eai-line); border-radius: 999px; padding: 8px 11px; box-shadow: 0 1px 2px rgba(20,33,58,.06); }
.eai-chat__dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--eai-gold); animation: eai-chat-dot 1.2s infinite ease-in-out; }
.eai-chat__dots i:nth-child(2) { animation-delay: .15s; }
.eai-chat__dots i:nth-child(3) { animation-delay: .3s; }
.eai-chat__head { background: linear-gradient(120deg, var(--eai-c) 0%, #163a6e 100%); }
.eai-chat__launcher::before { content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 2px solid var(--eai-gold); opacity: 0; animation: eai-chat-ring 2.8s ease-out 2s 3; pointer-events: none; }
.eai-chat__opt { transition: transform .12s ease, background .12s ease; }
.eai-chat__opt:active { transform: scale(.97); }
@keyframes eai-chat-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes eai-chat-dot { 0%, 80%, 100% { transform: scale(.6); opacity: .5; } 40% { transform: scale(1); opacity: 1; } }
@keyframes eai-chat-ring { 0% { transform: scale(.9); opacity: .9; } 100% { transform: scale(1.35); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .eai-chat__msg, .eai-chat__dots i, .eai-chat__launcher::before { animation: none; } }

/* ===== 0.4: lectura cómoda, «mensajes nuevos» y micrófono ===== */
.eai-chat__listwrap { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.eai-chat__listwrap .eai-chat__list { flex: 1; min-height: 0; }
.eai-chat__list, .eai-chat__list * { -webkit-user-select: text; user-select: text; }
.eai-chat__list button { -webkit-user-select: none; user-select: none; }
.eai-chat__newpill { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); border: 0; border-radius: 999px; padding: 8px 14px; min-height: 36px; background: var(--eai-c); color: #fff; font-size: 13px; font-weight: 600; box-shadow: 0 6px 18px rgba(0,0,0,.2); cursor: pointer; animation: eaiPill .25s ease-out; z-index: 2; }
@keyframes eaiPill { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
.eai-chat__mic { flex: 0 0 44px; width: 44px; height: 44px; border: 1px solid rgba(0,0,0,.12); border-radius: 50%; background: #fff; color: var(--eai-c); display: flex; align-items: center; justify-content: center; cursor: pointer; position: relative; }
.eai-chat__mic svg, .eai-chat__send svg { width: 22px; height: 22px; fill: currentColor; }
.eai-chat__mic.is-on { background: #e11d48; border-color: #e11d48; color: #fff; }
.eai-chat__mic.is-on::after { content: ""; position: absolute; inset: -5px; border-radius: 50%; border: 2px solid #e11d48; animation: eaiMic 1.2s ease-out infinite; }
@keyframes eaiMic { from { transform: scale(.9); opacity: .9; } to { transform: scale(1.35); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .eai-chat__mic.is-on::after, .eai-chat__newpill { animation: none; } }
