/**
 * AI Chat Widget — estructura base común a todos los diseños.
 * Cada skin sobreescribe las variables --acw-* y añade su personalidad.
 */

:root {
	--acw-primary: #2563eb;
}

.acw,
.acw * {
	box-sizing: border-box;
}

.acw {
	position: fixed;
	bottom: 24px;
	right: 24px;
	z-index: 999999;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	font-size: 15px;
	line-height: 1.45;
	-webkit-font-smoothing: antialiased;

	/* Valores por defecto que cada skin redefine */
	--acw-surface: #ffffff;
	--acw-text: #1c1c1e;
	--acw-muted: #8a8a8e;
	--acw-border: #e6e6e4;
	--acw-header-bg: #ffffff;
	--acw-header-text: #1c1c1e;
	--acw-bot-bg: #f2f2f0;
	--acw-bot-text: #1c1c1e;
	--acw-user-bg: var(--acw-primary);
	--acw-user-text: #ffffff;
	--acw-input-bg: #ffffff;
	--acw-field-bg: transparent;
	--acw-radius-panel: 16px;
	--acw-radius-bubble: 14px;
	--acw-launcher-size: 60px;
	--acw-launcher-bg: var(--acw-primary);
	--acw-launcher-color: #ffffff;
	--acw-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
	--acw-ease: cubic-bezier(0.22, 1, 0.36, 1);
}

.acw--left {
	right: auto;
	left: 24px;
}

/* ------------------------------------------------------------------ */
/* Botón flotante                                                      */
/* ------------------------------------------------------------------ */

.acw-launcher {
	position: relative;
	display: grid;
	place-items: center;
	width: var(--acw-launcher-size);
	height: var(--acw-launcher-size);
	margin-left: auto;
	padding: 0;
	border: none;
	border-radius: 50%;
	background: var(--acw-launcher-bg);
	color: var(--acw-launcher-color);
	cursor: pointer;
	box-shadow: var(--acw-shadow);
	transition: transform 0.25s var(--acw-ease), box-shadow 0.25s var(--acw-ease);
}

.acw--left .acw-launcher {
	margin-left: 0;
	margin-right: auto;
}

.acw-launcher:hover {
	transform: scale(1.06);
}

.acw-launcher:active {
	transform: scale(0.96);
}

.acw-ico {
	position: absolute;
	width: 26px;
	height: 26px;
	transition: opacity 0.2s var(--acw-ease), transform 0.25s var(--acw-ease);
}

.acw-ico--close {
	opacity: 0;
	transform: rotate(-90deg) scale(0.6);
}

.acw--open .acw-ico--chat {
	opacity: 0;
	transform: rotate(90deg) scale(0.6);
}

.acw--open .acw-ico--close {
	opacity: 1;
	transform: rotate(0) scale(1);
}

/* ------------------------------------------------------------------ */
/* Panel                                                               */
/* ------------------------------------------------------------------ */

.acw-panel {
	position: absolute;
	bottom: calc(var(--acw-launcher-size) + 16px);
	right: 0;
	display: flex;
	flex-direction: column;
	width: min(380px, calc(100vw - 32px));
	height: min(600px, calc(100dvh - 120px));
	overflow: hidden;
	background: var(--acw-surface);
	color: var(--acw-text);
	border-radius: var(--acw-radius-panel);
	box-shadow: var(--acw-shadow);
	opacity: 0;
	transform: translateY(14px) scale(0.97);
	transform-origin: bottom right;
	pointer-events: none;
	transition: opacity 0.25s var(--acw-ease), transform 0.3s var(--acw-ease);
}

.acw--left .acw-panel {
	right: auto;
	left: 0;
	transform-origin: bottom left;
}

.acw--open .acw-panel {
	opacity: 1;
	transform: translateY(0) scale(1);
	pointer-events: auto;
}

/* ------------------------------------------------------------------ */
/* Cabecera                                                            */
/* ------------------------------------------------------------------ */

.acw-header {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 14px 16px;
	background: var(--acw-header-bg);
	color: var(--acw-header-text);
	flex-shrink: 0;
}

.acw-avatar {
	display: grid;
	place-items: center;
	width: 38px;
	height: 38px;
	font-size: 20px;
	border-radius: 50%;
	background: var(--acw-bot-bg);
	flex-shrink: 0;
	overflow: hidden;
}

.acw-logo {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.acw-header-text {
	display: flex;
	flex-direction: column;
	min-width: 0;
}

.acw-name {
	font-weight: 600;
	font-size: 15px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.acw-status {
	font-size: 12px;
	color: var(--acw-muted);
	display: flex;
	align-items: center;
	gap: 6px;
}

.acw-status::before {
	content: "";
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #22c55e;
}

.acw-close {
	margin-left: auto;
	display: grid;
	place-items: center;
	width: 34px;
	height: 34px;
	padding: 0;
	border: none;
	border-radius: 10px;
	background: transparent;
	color: inherit;
	cursor: pointer;
	opacity: 0.7;
	transition: opacity 0.15s ease, background 0.15s ease;
}

.acw-close:hover {
	opacity: 1;
	background: rgba(0, 0, 0, 0.06);
}

.acw-close svg {
	width: 18px;
	height: 18px;
}

/* ------------------------------------------------------------------ */
/* Mensajes                                                            */
/* ------------------------------------------------------------------ */

.acw-messages {
	flex: 1;
	display: flex;
	flex-direction: column;
	gap: 10px;
	padding: 16px;
	overflow-y: auto;
	overscroll-behavior: contain;
	scroll-behavior: smooth;
}

.acw-msg {
	max-width: 82%;
	padding: 10px 14px;
	border-radius: var(--acw-radius-bubble);
	white-space: pre-wrap;
	overflow-wrap: break-word;
	animation: acw-in 0.25s var(--acw-ease);
}

.acw-msg--bot {
	align-self: flex-start;
	background: var(--acw-bot-bg);
	color: var(--acw-bot-text);
	border-bottom-left-radius: 4px;
}

.acw-msg--user {
	align-self: flex-end;
	background: var(--acw-user-bg);
	color: var(--acw-user-text);
	border-bottom-right-radius: 4px;
}

@keyframes acw-in {
	from {
		opacity: 0;
		transform: translateY(6px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* Indicador de "escribiendo…" */

.acw-typing {
	display: flex;
	align-items: center;
	gap: 5px;
	min-height: 38px;
}

.acw-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--acw-muted);
	animation: acw-blink 1.2s infinite ease-in-out;
}

.acw-typing span:nth-child(2) {
	animation-delay: 0.15s;
}

.acw-typing span:nth-child(3) {
	animation-delay: 0.3s;
}

@keyframes acw-blink {
	0%,
	60%,
	100% {
		opacity: 0.3;
		transform: translateY(0);
	}
	30% {
		opacity: 1;
		transform: translateY(-3px);
	}
}

/* ------------------------------------------------------------------ */
/* Formulario                                                          */
/* ------------------------------------------------------------------ */

.acw-form {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px;
	border-top: 1px solid var(--acw-border);
	background: var(--acw-input-bg);
	flex-shrink: 0;
}

.acw-input {
	flex: 1;
	max-height: 110px;
	padding: 10px 12px;
	border: 1px solid var(--acw-border);
	border-radius: 12px;
	background: transparent;
	color: var(--acw-text);
	font: inherit;
	resize: none;
	outline: none;
	transition: border-color 0.15s ease;
}

.acw-input::placeholder {
	color: var(--acw-muted);
}

.acw-input:focus {
	border-color: var(--acw-primary);
}

.acw-send {
	display: grid;
	place-items: center;
	width: 42px;
	height: 42px;
	padding: 0;
	border: none;
	border-radius: 12px;
	background: var(--acw-primary);
	color: #fff;
	cursor: pointer;
	flex-shrink: 0;
	transition: transform 0.15s var(--acw-ease), opacity 0.15s ease;
}

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

.acw-send svg {
	width: 20px;
	height: 20px;
}

.acw--sending .acw-send {
	opacity: 0.5;
	pointer-events: none;
}

/* ------------------------------------------------------------------ */
/* Accesibilidad y responsive                                          */
/* ------------------------------------------------------------------ */

.acw button:focus-visible,
.acw .acw-input:focus-visible {
	outline: 2px solid var(--acw-primary);
	outline-offset: 2px;
}

@media (max-width: 480px) {
	.acw--open .acw-panel {
		position: fixed;
		inset: 0;
		width: 100%;
		height: 100dvh;
		border-radius: 0;
	}

	/* Con el chat a pantalla completa, el botón flotante sobra:
	   se cierra con la X de la cabecera. */
	.acw--open .acw-launcher {
		display: none;
	}
}

/* Mientras el chat está abierto en móvil, la página de fondo no se mueve.
   La clase la pone y la quita el propio widget. */
html.acw-lock,
html.acw-lock body {
	overflow: hidden !important;
	overscroll-behavior: none;
}

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

/* ------------------------------------------------------------------ */
/* Blindaje frente al CSS del tema                                     */
/* Los temas (Astra, Elementor, etc.) aplican estilos globales a       */
/* input/textarea/button que se cuelan en el widget. Estas reglas con  */
/* el id #acw-root ganan a las del tema, y usan variables para que los */
/* skins y el CSS personalizado del admin sigan mandando.              */
/* ------------------------------------------------------------------ */

#acw-root .acw-input {
	color: var(--acw-text);
	-webkit-text-fill-color: var(--acw-text);
	caret-color: var(--acw-primary);
	background: var(--acw-field-bg);
	font-family: inherit;
	/* 16px como mínimo: con menos, iOS hace zoom automático al enfocar el campo */
	font-size: 16px;
	margin: 0;
	box-shadow: none;
	text-transform: none;
}

#acw-root .acw-input:focus {
	border-color: var(--acw-primary);
	background: var(--acw-field-bg);
}

#acw-root .acw-input::placeholder {
	color: var(--acw-muted);
	opacity: 1;
}

#acw-root .acw-send {
	background: var(--acw-send-bg, var(--acw-primary));
	color: #ffffff;
	margin: 0;
	text-transform: none;
}

#acw-root .acw-launcher {
	background: var(--acw-launcher-bg);
	color: var(--acw-launcher-color);
	margin: 0;
	text-transform: none;
}

#acw-root .acw-close {
	background: transparent;
	/* margen izquierdo en auto: es lo que empuja la X al extremo derecho */
	margin: 0 0 0 auto;
}

#acw-root .acw-close:hover {
	background: rgba(128, 128, 128, 0.18);
}
