/* --- Botón flotante (como Foto 2: naranja) --- */
#inan-chat-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background-color: var(--inan-chat-color, #f07c00);
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* --- Botón flotante (como Foto 2: naranja) --- */
#inan-chat-button {
    position: fixed; /* Mantenemos esto */
    position: relative; /* ¡AÑADIDO! - Para anclar el pseudo-elemento */
    overflow: visible;  /* ¡AÑADIDO! - Para que se vea el brillo */
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background-color: var(--inan-chat-color, #f07c00);
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#inan-chat-button svg {
    width: 32px;
    height: 32px;
    color: white;
    fill: white;
}

/* --- Contenedor de la Ventana de Chat (como Foto 1: oscura) --- */
#inan-chat-window {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 350px;
    height: 500px;
    max-height: calc(100vh - 110px);
    max-width: calc(100vw - 40px);
    background-color: #0F172A; /* Fondo oscuro (azul-negro) */
    color: #E2E8F0; /* Texto claro (casi blanco) */
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, sans-serif;
    transform-origin: bottom right;
    
    /* Oculto por defecto */
    visibility: hidden;
    opacity: 0;
    transform: scale(0.9) translateY(10px);
    transition: all 0.2s ease-in-out;
}

#inan-chat-window.inan-visible {
    visibility: visible;
    opacity: 1;
    transform: scale(1) translateY(0);
}

/* --- Cabecera del Chat (como Foto 1: con rayo) --- */
#inan-chat-header {
    padding: 16px;
    background-color: #1E293B; /* Un poco más claro que el fondo */
    display: flex;
    align-items: center;
    border-bottom: 1px solid #334155;
    position: relative;
}

#inan-chat-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    /* Efecto de borde brillante (como Foto 1) */
    border: 2px solid transparent;
    background-image: linear-gradient(#000, #000), 
                      radial-gradient(circle at top left, #8B5CF6, #EC4899, #F59E0B);
    background-origin: border-box;
    background-clip: content-box, border-box;
    flex-shrink: 0;
}

#inan-chat-icon svg {
    width: 20px;
    height: 20px;
    color: white;
    fill: white;
}

#inan-chat-header-title {
    flex-grow: 1;
}

#inan-chat-header-title strong {
    display: block;
    font-size: 16px;
    font-weight: 600;
    color: #F8FAFC;
}
#inan-chat-header-title span {
    font-size: 13px;
    color: #94A3B8;
}

#inan-chat-close-btn {
    background: none;
    border: none;
    color: #94A3B8;
    cursor: pointer;
    font-size: 24px;
    line-height: 1;
    padding: 4px;
}
#inan-chat-close-btn:hover {
    color: #F8FAFC;
}

/* --- Log de Mensajes --- */
#inan-chat-log {
    flex-grow: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.inan-chat-message {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.inan-chat-message.inan-user {
    background-color: var(--inan-chat-color, #f07c00);
    color: #FFFFFF;
    border-bottom-right-radius: 4px;
    align-self: flex-end;
}

.inan-chat-message.inan-bot {
    background-color: #334155; /* Gris-azul para el bot */
    color: #E2E8F0;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
}

.inan-chat-message.inan-bot.inan-loading {
    padding: 14px 14px 12px;
}

/* Animación de "escribiendo..." */
.inan-loading span {
    display: inline-block;
    width: 7px;
    height: 7px;
    background-color: #94A3B8;
    border-radius: 50%;
    margin: 0 1px;
    animation: inan-dot-blink 1.4s infinite both;
}
.inan-loading span:nth-child(2) { animation-delay: 0.2s; }
.inan-loading span:nth-child(3) { animation-delay: 0.4s; }

@keyframes inan-dot-blink {
    0% { opacity: 0.2; }
    20% { opacity: 1; }
    100% { opacity: 0.2; }
}

/* --- Formulario de Input --- */
#inan-chat-form {
    display: flex;
    padding: 16px;
    border-top: 1px solid #334155;
    background-color: #1E293B;
}

#inan-chat-input {
    flex-grow: 1;
    border: 1px solid #475569;
    background-color: #0F172A;
    color: #E2E8F0;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

#inan-chat-input::placeholder {
    color: #64748B;
}

#inan-chat-input:focus {
    border-color: var(--inan-chat-color, #f07c00);
}

#inan-chat-form button {
    background-color: var(--inan-chat-color, #f07c00);
    border: none;
    color: white;
    padding: 0 16px;
    margin-left: 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

#inan-chat-form button:hover {
    filter: brightness(1.1);
}

#inan-chat-form button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ... (todo el CSS anterior) ... */

/* --- NUEVO: Estilos para el Popup Emergente --- */
#inan-chat-popup {
    position: fixed;
    bottom: 90px; /* Justo encima del botón flotante */
    right: 20px;
    background-color: #FFFFFF;
    color: #1E293B;
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.15);
    z-index: 9997;
    font-size: 14px;
    font-weight: 500;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, sans-serif;
    cursor: pointer;
    
    /* Oculto por defecto */
    visibility: hidden;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease-in-out;
}

#inan-chat-popup.inan-visible {
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
}

/* Pequeña flecha/triángulo en la parte inferior */
#inan-chat-popup::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 22px; /* Alineado con el centro del botón */
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid #FFFFFF;
}

/* --- NUEVO: Borde animado para el botón de chat --- */

#inan-chat-button::before {
    content: '';
    position: absolute;
    /* Lo hacemos 4px más grande que el botón (60px -> 68px) */
    top: -4px;
    left: -4px;
    right: -4px;
    bottom: -4px;
    
    /* El gradiente de colores que rotará */
    background: conic-gradient(
        from 180deg at 50% 50%,
        #f07c00,  /* Naranja INAN */
        #8B5CF6,  /* Púrpura */
        #3B82F6,  /* Azul */
        #f07c00   /* Naranja INAN de nuevo para un ciclo suave */
    );
    
    /* Lo ponemos detrás del botón naranja (z-index -1) */
    z-index: -1;
    border-radius: 50%; /* Debe ser un círculo */
    
    /* La animación */
    animation: inan-spin 3s linear infinite;
    
    /* Opcional: un suave desenfoque para un efecto "glow" */
    filter: blur(2px);
}

/* Definición de la animación de rotación */
@keyframes inan-spin {
    100% {
        transform: rotate(360deg);
    }
}

/* Detenemos la animación y el blur cuando el chat está abierto (opcional) */
#inan-chat-window.inan-visible + #inan-chat-button::before {
    animation: none;
    filter: none;
}