/**
 * IANAgents Chat — widget flotante. Vanilla CSS, replicando el copiloto del
 * dashboard de IANAgents. Todo namespaceado bajo #solingua-chat-root y .iac-*
 * para no chocar con los estilos del theme.
 *
 * Variables de color: --iac-accent / --iac-accent-dim las inyecta el JS
 * (desde la config). Las superficies/bordes/texto cambian según data-theme.
 */

#solingua-chat-root {
	/* defaults; el JS pisa accent/accent-dim con la config */
	--iac-accent: #1c80fa;
	--iac-accent-dim: #1769d1;

	/* superficies dark (default) */
	--iac-surface-0: #0b0f17;
	--iac-surface-1: #111722;
	--iac-surface-2: #182030;
	--iac-surface-3: #1f2937;
	--iac-border: rgba(255, 255, 255, 0.10);
	--iac-text: #e8edf4;
	--iac-text-muted: #9aa7b8;
	--iac-text-dim: #6b7889;
	--iac-panel-bg: rgba(17, 23, 34, 0.96);
	--iac-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);

	position: fixed;
	z-index: 2147483000;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	line-height: 1.4;
}

/* Tema claro: explícito (data-theme="light") o auto sin preferencia oscura. */
#solingua-chat-root[data-theme="light"] {
	--iac-surface-0: #ffffff;
	--iac-surface-1: #ffffff;
	--iac-surface-2: #f4f6f9;
	--iac-surface-3: #eef1f6;
	--iac-border: rgba(15, 23, 42, 0.12);
	--iac-text: #131b27;
	--iac-text-muted: #5a6675;
	--iac-text-dim: #8a96a5;
	--iac-panel-bg: rgba(255, 255, 255, 0.97);
	--iac-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
}

@media (prefers-color-scheme: light) {
	#solingua-chat-root[data-theme="auto"] {
		--iac-surface-0: #ffffff;
		--iac-surface-1: #ffffff;
		--iac-surface-2: #f4f6f9;
		--iac-surface-3: #eef1f6;
		--iac-border: rgba(15, 23, 42, 0.12);
		--iac-text: #131b27;
		--iac-text-muted: #5a6675;
		--iac-text-dim: #8a96a5;
		--iac-panel-bg: rgba(255, 255, 255, 0.97);
		--iac-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
	}
}

#solingua-chat-root *,
#solingua-chat-root *::before,
#solingua-chat-root *::after {
	box-sizing: border-box;
}

/* ── Botón flotante ─────────────────────────────────────────────────────── */
.iac-launcher {
	position: fixed;
	bottom: 20px;
	right: 25px;
	width: 48px;
	height: 48px;
	z-index: 2147483001;
}

.iac-launcher-btn {
	position: relative;
	width: 48px;
	height: 48px;
	border-radius: 9999px;
	border: none;
	cursor: pointer;
	background: var(--iac-accent);
	color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 0 16px 2px var(--iac-accent), 0 4px 14px rgba(0, 0, 0, 0.35);
	transition: transform 0.15s ease;
	-webkit-appearance: none;
	appearance: none;
	padding: 0;
}

.iac-launcher-btn:hover {
	transform: scale(1.1);
}

.iac-launcher-btn:active {
	transform: scale(0.95);
}

.iac-launcher-btn svg {
	width: 22px;
	height: 22px;
	display: block;
}

/* anillo pulsante cuando está cerrado */
.iac-ping {
	position: absolute;
	inset: 0;
	border-radius: 9999px;
	background: var(--iac-accent);
	opacity: 0.4;
	animation: iac-ping 1.6s cubic-bezier(0, 0, 0.2, 1) infinite;
	pointer-events: none;
}

@keyframes iac-ping {
	75%, 100% {
		transform: scale(1.9);
		opacity: 0;
	}
}

/* ── Panel ──────────────────────────────────────────────────────────────── */
.iac-panel {
	position: fixed;
	z-index: 2147483001;
	display: flex;
	flex-direction: column;
	overflow: hidden;
	color: var(--iac-text);
	background: var(--iac-panel-bg);
	-webkit-backdrop-filter: blur(18px);
	backdrop-filter: blur(18px);
	border: 1px solid var(--iac-border);
	box-shadow: var(--iac-shadow);
	animation: iac-pop 0.18s ease;
}

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

/* Desktop: ventana abajo-derecha, ~390px. */
@media (min-width: 768px) {
	.iac-panel {
		bottom: 80px;
		right: 20px;
		width: min(92vw, 390px);
		height: min(72vh, 580px);
		border-radius: 14px;
	}
}

/* Mobile: pantalla completa. */
@media (max-width: 767px) {
	.iac-panel {
		inset: 0;
		width: 100%;
		height: 100dvh;
		border-radius: 0;
		border: 0;
	}
}

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

/* ── Header ─────────────────────────────────────────────────────────────── */
.iac-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding: 12px;
	border-bottom: 1px solid var(--iac-border);
	background: var(--iac-surface-2);
	cursor: pointer;
	user-select: none;
	flex-shrink: 0;
}

@media (min-width: 768px) {
	.iac-header { padding: 10px 12px; }
}

/* Mobile: panel plein écran. Padding cómodo, izquierda/derecha SIEMPRE presentes,
   + safe-area arriba (notch). Alta especificidad + !important para que ningún estilo
   del theme lo pise. */
@media (max-width: 767px) {
	#solingua-chat-root .iac-header {
		padding-top: calc(16px + env(safe-area-inset-top, 0px)) !important;
		padding-right: 18px !important;
		padding-bottom: 16px !important;
		padding-left: 18px !important;
	}
}

.iac-header-left {
	display: flex;
	align-items: center;
	gap: 8px;
	min-width: 0;
}

.iac-avatar {
	width: 26px;
	height: 26px;
	border-radius: 9999px;
	background: color-mix(in srgb, var(--iac-accent) 15%, transparent);
	border: 1px solid color-mix(in srgb, var(--iac-accent) 40%, transparent);
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	color: var(--iac-accent);
}

.iac-avatar svg { width: 14px; height: 14px; display: block; }

.iac-titles { min-width: 0; }

.iac-title {
	font-size: 14px;
	font-weight: 600;
	line-height: 1.2;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.iac-subtitle {
	font-size: 10px;
	color: var(--iac-text-muted);
	line-height: 1.2;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.iac-min-btn {
	flex-shrink: 0;
	border: none;
	cursor: pointer;
	background: transparent;
	color: var(--iac-text-muted);
	padding: 4px;
	border-radius: 9999px;
	display: flex;
	align-items: center;
	justify-content: center;
}

.iac-min-btn:hover { color: var(--iac-text); }
.iac-min-btn svg { width: 15px; height: 15px; display: block; }

/* En mobile, el botón cerrar es un círculo accent más visible. */
@media (max-width: 767px) {
	.iac-min-btn {
		background: var(--iac-accent);
		color: #fff;
		padding: 6px;
	}
	.iac-min-btn svg { width: 20px; height: 20px; }
	.iac-min-icon-min { display: none; }
}
@media (min-width: 768px) {
	.iac-min-icon-close { display: none; }
}

/* ── Lista de mensajes ──────────────────────────────────────────────────── */
.iac-messages {
	flex: 1;
	overflow-y: auto;
	padding: 12px;
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.iac-empty {
	font-size: 12px;
	color: var(--iac-text-muted);
	text-align: center;
	margin-top: 24px;
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.iac-suggests {
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.iac-suggest {
	display: block;
	width: 100%;
	text-align: left;
	font-size: 11px;
	background: var(--iac-surface-3);
	border: 1px solid var(--iac-border);
	color: var(--iac-text);
	border-radius: 6px;
	padding: 6px 8px;
	cursor: pointer;
	transition: background 0.12s ease;
}

.iac-suggest:hover { background: var(--iac-surface-2); }
.iac-suggest:disabled { opacity: 0.5; cursor: default; }

/* fila de mensaje */
.iac-row {
	display: flex;
	align-items: flex-end;
	gap: 6px;
}

.iac-row.iac-user { justify-content: flex-end; }
.iac-row.iac-bot { justify-content: flex-start; }

.iac-row-avatar {
	width: 24px;
	height: 24px;
	border-radius: 9999px;
	flex-shrink: 0;
	align-self: flex-end;
	margin-bottom: 4px;
	display: flex;
	align-items: center;
	justify-content: center;
}

.iac-row-avatar.iac-bot-avatar {
	background: color-mix(in srgb, var(--iac-accent) 15%, transparent);
	border: 1px solid color-mix(in srgb, var(--iac-accent) 40%, transparent);
	color: var(--iac-accent);
}

.iac-row-avatar.iac-bot-avatar svg { width: 13px; height: 13px; display: block; }

.iac-row-avatar.iac-user-avatar {
	background: var(--iac-accent);
	border: 1px solid var(--iac-accent);
	color: #fff;
	font-size: 10px;
	font-weight: 700;
}

.iac-bubble {
	max-width: 82%;
	padding: 8px 12px;
	border: 1px solid var(--iac-border);
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
	white-space: pre-wrap;
	overflow-wrap: anywhere;
	word-break: break-word;
	font-size: 13px;
	line-height: 1.45;
	border-radius: 16px;
}

.iac-bubble.iac-bubble-user {
	border-bottom-right-radius: 4px;
	font-weight: 500;
	color: #fff;
	border-color: var(--iac-accent);
	background: linear-gradient(135deg, var(--iac-accent) 0%, var(--iac-accent-dim) 100%);
	box-shadow: 0 2px 8px -2px rgba(0, 0, 0, 0.25);
}

.iac-bubble.iac-bubble-bot {
	border-bottom-left-radius: 4px;
	background: var(--iac-surface-3);
	border-color: var(--iac-border);
	color: var(--iac-text);
}

.iac-bubble.iac-bubble-error {
	border-bottom-left-radius: 4px;
	background: rgba(239, 68, 68, 0.10);
	color: #ef6464;
	border-color: rgba(239, 68, 68, 0.22);
}

.iac-bubble-label {
	font-size: 10px;
	color: var(--iac-text-dim);
	margin-bottom: 2px;
}

.iac-thinking {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	color: var(--iac-text-muted);
	font-style: italic;
}

/* ── Typing dots ────────────────────────────────────────────────────────── */
.iac-dots {
	display: inline-flex;
	gap: 4px;
	align-items: center;
	margin-left: 4px;
	vertical-align: middle;
}

.iac-dots span {
	width: 6px;
	height: 6px;
	border-radius: 9999px;
	background: color-mix(in srgb, var(--iac-accent) 70%, transparent);
	animation: iac-bounce 1s infinite;
}

.iac-dots span:nth-child(2) { animation-delay: 0.15s; }
.iac-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes iac-bounce {
	0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
	40% { transform: translateY(-4px); opacity: 1; }
}

/* ── Gate de identificación (nombre + email) ────────────────────────────── */
.iac-gate {
	flex: 1;
	overflow-y: auto;
	padding: 22px 18px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	justify-content: center;
}

.iac-gate[hidden] { display: none; }

.iac-gate-title {
	font-size: 15px;
	font-weight: 600;
	color: var(--iac-text);
	text-align: center;
}

.iac-gate-intro {
	font-size: 12px;
	color: var(--iac-text-muted);
	text-align: center;
	margin: 0 0 4px;
	line-height: 1.45;
}

.iac-gate-input {
	width: 100%;
	background: var(--iac-surface-0);
	border: 1px solid var(--iac-border);
	color: var(--iac-text);
	border-radius: 10px;
	padding: 11px 12px;
	font-size: 14px;
	font-family: inherit;
	outline: none;
}

.iac-gate-input:focus { border-color: var(--iac-accent); }
.iac-gate-input::placeholder { color: var(--iac-text-dim); }

.iac-gate-error {
	font-size: 12px;
	color: #ef6464;
	line-height: 1.4;
}

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

.iac-gate-btn {
	margin-top: 4px;
	width: 100%;
	border: none;
	cursor: pointer;
	background: linear-gradient(135deg, var(--iac-accent) 0%, var(--iac-accent-dim) 100%);
	color: #fff;
	border-radius: 10px;
	padding: 11px 16px;
	font-size: 14px;
	font-weight: 600;
	font-family: inherit;
	transition: filter 0.12s ease;
}

.iac-gate-btn:hover { filter: brightness(1.08); }
.iac-gate-btn:disabled { opacity: 0.6; cursor: default; }

/* ── Input ──────────────────────────────────────────────────────────────── */
.iac-inputbar {
	border-top: 1px solid var(--iac-border);
	flex-shrink: 0;
	padding: 8px;
	display: flex;
	gap: 6px;
	align-items: flex-end;
	background: var(--iac-surface-1);
}

.iac-textarea {
	flex: 1;
	background: var(--iac-surface-0);
	border: 1px solid var(--iac-border);
	color: var(--iac-text);
	border-radius: 10px;
	padding: 10px 12px;
	font-size: 14px;
	font-family: inherit;
	resize: none;
	max-height: 96px;
	line-height: 1.4;
	outline: none;
}

.iac-textarea:focus { border-color: var(--iac-accent); }
.iac-textarea::placeholder { color: var(--iac-text-dim); }
.iac-textarea:disabled { opacity: 0.6; }

.iac-send {
	border: none;
	cursor: pointer;
	background: var(--iac-accent);
	color: #fff;
	border-radius: 10px;
	padding: 0 16px;
	height: 40px;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	transition: filter 0.12s ease;
}

.iac-send:hover { filter: brightness(1.08); }
.iac-send:disabled { opacity: 0.4; cursor: default; }
.iac-send svg { width: 18px; height: 18px; display: block; }

/* scrollbar discreta */
.iac-messages::-webkit-scrollbar { width: 8px; }
.iac-messages::-webkit-scrollbar-thumb {
	background: var(--iac-border);
	border-radius: 8px;
}


/* Paso OTP del gate: botón 'reenviar código' como link discreto. */
.iac-gate-resend {
	display: block;
	margin: 10px auto 0;
	padding: 4px 6px;
	background: none;
	border: none;
	color: var(--iac-accent, #1c80fa);
	font: inherit;
	font-size: 13px;
	text-decoration: underline;
	cursor: pointer;
}
.iac-gate-resend:hover { opacity: .8; }
.iac-gate-resend:disabled { opacity: .5; cursor: default; }

/* Enlaces clicables dentro de las burbujas del bot. */
.iac-bubble a {
	color: var(--iac-accent);
	font-weight: 600;
	text-decoration: underline;
	text-underline-offset: 2px;
	overflow-wrap: anywhere;
}
.iac-bubble a:hover { filter: brightness(1.15); }
.iac-bubble.iac-bubble-user a { color: #fff; }

/* Avatar del asistente con logo PNG (header + al costado de la burbuja del bot). */
.iac-avatar.iac-has-logo,
.iac-row-avatar.iac-bot-avatar.iac-has-logo {
	background: transparent;
	border: 0;
	overflow: hidden;
}
.iac-logo {
	width: 100%;
	height: 100%;
	object-fit: contain;
	display: block;
	border-radius: 9999px;
}
