/* ==========================================================================
   NellyBot — Widget de chat flotante
   Ajusta los colores de marca aquí en :root
   ========================================================================== */

#nellybot {
	/* --nellybot-primary lo inyecta PHP desde el setting "color principal".
	   Si no está, cae al azul de marca. */
	--nb-primary: var(--nellybot-primary, #0a4d8c);
	--nb-primary-dark: color-mix(in srgb, var(--nb-primary) 80%, black);
	--nb-accent: #f5a623;           /* Acento (botón enviar / detalles) */
	--nb-bg: #ffffff;               /* Fondo del panel */
	--nb-bot-bubble: #eef2f7;       /* Burbuja del bot */
	--nb-user-bubble: var(--nb-primary);
	--nb-text: #1f2937;             /* Texto principal */
	--nb-muted: #6b7280;            /* Texto secundario */
	--nb-radius: 18px;
	--nb-shadow: 0 12px 38px rgba(7, 58, 107, 0.28);

	position: fixed;
	right: 24px;
	bottom: 24px;
	z-index: 99999;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-size: 15px;
	line-height: 1.4;
}

#nellybot *,
#nellybot *::before,
#nellybot *::after {
	box-sizing: border-box;
}

/* --------------------------------------------------------------------------
   Botón flotante (launcher)
   -------------------------------------------------------------------------- */
.nellybot__launcher {
	position: relative;
	width: 62px;
	height: 62px;
	border: none;
	border-radius: 50%;
	background: var(--nb-primary);
	color: #fff;
	cursor: pointer;
	box-shadow: var(--nb-shadow);
	display: flex;
	align-items: center;
	justify-content: center;
	margin-left: auto;
	transition: transform 0.2s ease, background 0.2s ease;
}

.nellybot__launcher:hover {
	background: var(--nb-primary-dark);
	transform: translateY(-2px);
}

.nellybot__launcher:focus-visible {
	outline: 3px solid var(--nb-accent);
	outline-offset: 2px;
}

.nellybot__launcher .nellybot__icon-close {
	display: none;
}

/* Estado abierto: el launcher muestra la X */
#nellybot.is-open .nellybot__launcher .nellybot__icon-open {
	display: none;
}

#nellybot.is-open .nellybot__launcher .nellybot__icon-close {
	display: block;
}

/* --------------------------------------------------------------------------
   Panel del chat
   -------------------------------------------------------------------------- */
.nellybot__panel {
	position: absolute;
	right: 0;
	bottom: 78px;
	width: 360px;
	max-width: calc(100vw - 32px);
	height: 540px;
	max-height: calc(100vh - 120px);
	background: var(--nb-bg);
	border-radius: var(--nb-radius);
	box-shadow: var(--nb-shadow);
	display: flex;
	flex-direction: column;
	overflow: hidden;

	/* Oculto por defecto */
	opacity: 0;
	visibility: hidden;
	transform: translateY(16px) scale(0.98);
	transform-origin: bottom right;
	transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s;
}

#nellybot.is-open .nellybot__panel {
	opacity: 1;
	visibility: visible;
	transform: translateY(0) scale(1);
}

/* --------------------------------------------------------------------------
   Encabezado
   -------------------------------------------------------------------------- */
.nellybot__header {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 14px 16px;
	background: var(--nb-primary);
	color: #fff;
}

.nellybot__avatar {
	width: 40px;
	height: 40px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.18);
	display: flex;
	align-items: center;
	justify-content: center;
	font-weight: 700;
	font-size: 18px;
	flex-shrink: 0;
}

.nellybot__heading {
	display: flex;
	flex-direction: column;
	line-height: 1.2;
	flex: 1; /* empuja botones de acción (WhatsApp, cerrar) a la derecha */
	min-width: 0;
}

.nellybot__heading strong {
	font-size: 15px;
}

.nellybot__status {
	font-size: 12px;
	opacity: 0.85;
	display: flex;
	align-items: center;
	gap: 6px;
}

.nellybot__status::before {
	content: "";
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: #3ddc84;
	display: inline-block;
}

/* Botón WhatsApp en el header — siempre visible si hay número configurado */
.nellybot__wa {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	border-radius: 50%;
	background: #25D366;
	color: #fff;
	text-decoration: none;
	transition: transform 0.15s ease, background 0.15s ease;
	flex-shrink: 0;
}

.nellybot__wa:hover {
	background: #1ebe57;
	transform: scale(1.06);
	color: #fff;
}

.nellybot__wa:focus-visible {
	outline: 3px solid rgba(255, 255, 255, 0.6);
	outline-offset: 2px;
}

.nellybot__close {
	background: transparent;
	border: none;
	color: #fff;
	cursor: pointer;
	padding: 4px;
	border-radius: 8px;
	display: flex;
	opacity: 0.85;
	transition: opacity 0.2s ease, background 0.2s ease;
	flex-shrink: 0;
}

.nellybot__close:hover {
	opacity: 1;
	background: rgba(255, 255, 255, 0.15);
}

/* --------------------------------------------------------------------------
   Mensajes
   -------------------------------------------------------------------------- */
.nellybot__messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	background: #f7f9fb;
}

.nellybot__msg {
	max-width: 80%;
	padding: 10px 14px;
	border-radius: 16px;
	word-wrap: break-word;
	white-space: pre-wrap;
	animation: nb-pop 0.18s ease;
}

.nellybot__msg--bot {
	align-self: flex-start;
	background: var(--nb-bot-bubble);
	color: var(--nb-text);
	border-bottom-left-radius: 4px;
}

.nellybot__msg--user {
	align-self: flex-end;
	background: var(--nb-user-bubble);
	color: #fff;
	border-bottom-right-radius: 4px;
}

/* Texto del mensaje (envuelto en span para que el timestamp quede abajo) */
.nellybot__msg-text {
	display: block;
	white-space: pre-wrap;
	word-wrap: break-word;
}

/* Links dentro de las burbujas (reseñas, WhatsApp, etc.) */
.nellybot__link {
	color: inherit;
	text-decoration: underline;
	text-underline-offset: 2px;
	word-break: break-all; /* URLs largas no rompen el layout */
	font-weight: 600;
	transition: opacity 0.15s ease;
}

.nellybot__link:hover {
	opacity: 0.75;
}

/* En burbuja del bot el link va en el color principal de la marca */
.nellybot__msg--bot .nellybot__link {
	color: var(--nb-primary);
}

/* En burbuja del usuario (fondo color), el link queda en blanco visible */
.nellybot__msg--user .nellybot__link {
	color: #fff;
	text-decoration-color: rgba(255, 255, 255, 0.6);
}

/* Hora del mensaje (estilo discreto, alineado a la derecha) */
.nellybot__time {
	display: block;
	font-size: 10.5px;
	margin-top: 4px;
	text-align: right;
	line-height: 1;
	letter-spacing: 0.02em;
}

.nellybot__msg--bot .nellybot__time {
	color: var(--nb-muted);
	opacity: 0.85;
}

.nellybot__msg--user .nellybot__time {
	color: rgba(255, 255, 255, 0.85);
}

/* Enlaces dentro de las burbujas (reseñas Google, etc.) */
.nellybot__msg-text a {
	text-decoration: underline;
	font-weight: 600;
	word-break: break-word;
}

.nellybot__msg--bot .nellybot__msg-text a {
	color: var(--nb-primary);
}

.nellybot__msg--user .nellybot__msg-text a {
	color: #fff;
}

.nellybot__msg-text a:hover {
	opacity: 0.85;
}

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

/* Indicador de escritura */
.nellybot__typing {
	align-self: flex-start;
	background: var(--nb-bot-bubble);
	padding: 12px 16px;
	border-radius: 16px;
	border-bottom-left-radius: 4px;
	display: flex;
	gap: 4px;
}

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

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

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

/* --------------------------------------------------------------------------
   Respuestas rápidas (quick replies)
   -------------------------------------------------------------------------- */
.nellybot__quick {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	padding: 0 16px 8px;
	background: #f7f9fb;
}

.nellybot__quick:empty {
	display: none;
}

.nellybot__chip {
	border: 1px solid var(--nb-primary);
	background: #fff;
	color: var(--nb-primary);
	padding: 7px 14px;
	border-radius: 999px;
	font-size: 13px;
	cursor: pointer;
	transition: background 0.2s ease, color 0.2s ease;
}

.nellybot__chip:hover {
	background: var(--nb-primary);
	color: #fff;
}

/* --------------------------------------------------------------------------
   Formulario de entrada
   -------------------------------------------------------------------------- */
.nellybot__form {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 12px;
	border-top: 1px solid #e5e9ef;
	background: var(--nb-bg);
}

.nellybot__input {
	flex: 1;
	border: 1px solid #d7dde5;
	border-radius: 999px;
	padding: 11px 16px;
	font-size: 14px;
	outline: none;
	color: var(--nb-text);
	transition: border-color 0.2s ease;
}

.nellybot__input:focus {
	border-color: var(--nb-primary);
}

.nellybot__send {
	width: 44px;
	height: 44px;
	flex-shrink: 0;
	border: none;
	border-radius: 50%;
	background: var(--nb-accent);
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: filter 0.2s ease, transform 0.2s ease;
}

.nellybot__send:hover {
	filter: brightness(0.93);
	transform: scale(1.05);
}

.nellybot__send:disabled {
	opacity: 0.5;
	cursor: not-allowed;
	transform: none;
}

/* --------------------------------------------------------------------------
   Responsive (móvil)
   -------------------------------------------------------------------------- */
@media (max-width: 480px) {
	#nellybot {
		right: 16px;
		bottom: 16px;
	}

	.nellybot__panel {
		width: calc(100vw - 24px);
		height: calc(100vh - 100px);
		right: -4px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.nellybot__panel,
	.nellybot__launcher,
	.nellybot__msg,
	.nellybot__send {
		transition: none;
		animation: none;
	}
}
