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

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

	/* superficies dark (default) */
	--i2mc-surface-0: #0b0f17;
	--i2mc-surface-1: #111722;
	--i2mc-surface-2: #182030;
	--i2mc-surface-3: #1f2937;
	--i2mc-border: rgba(255, 255, 255, 0.10);
	--i2mc-text: #e8edf4;
	--i2mc-text-muted: #9aa7b8;
	--i2mc-text-dim: #6b7889;
	--i2mc-panel-bg: rgba(17, 23, 34, 0.82);
	--i2mc-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. */
#i2magents-chat-root[data-theme="light"] {
	--i2mc-surface-0: #ffffff;
	--i2mc-surface-1: #ffffff;
	--i2mc-surface-2: #f4f6f9;
	--i2mc-surface-3: #eef1f6;
	--i2mc-border: rgba(15, 23, 42, 0.12);
	--i2mc-text: #131b27;
	--i2mc-text-muted: #5a6675;
	--i2mc-text-dim: #8a96a5;
	--i2mc-panel-bg: rgba(255, 255, 255, 0.86);
	--i2mc-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
}

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

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

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

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

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

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

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

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

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

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

@keyframes i2mc-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) {
	.i2mc-panel {
		bottom: 80px;
		right: 20px;
		width: min(92vw, 390px);
		height: min(72vh, 580px);
		border-radius: 14px;
	}
}

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

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

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

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

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

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

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

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

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

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

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

.i2mc-min-btn:hover { color: var(--i2mc-text); }
.i2mc-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) {
	.i2mc-min-btn {
		background: var(--i2mc-accent);
		color: #fff;
		padding: 6px;
	}
	.i2mc-min-btn svg { width: 20px; height: 20px; }
	.i2mc-min-icon-min { display: none; }
}
@media (min-width: 768px) {
	.i2mc-min-icon-close { display: none; }
}

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

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

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

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

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

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

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

.i2mc-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;
}

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

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

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

.i2mc-bubble {
	max-width: 82%;
	padding: 8px 12px;
	border: 1px solid var(--i2mc-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;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

.i2mc-gate-btn {
	margin-top: 4px;
	width: 100%;
	border: none;
	cursor: pointer;
	background: linear-gradient(135deg, var(--i2mc-accent) 0%, var(--i2mc-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;
}

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

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

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

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

.i2mc-send {
	border: none;
	cursor: pointer;
	background: var(--i2mc-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;
}

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

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


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