/* Contenedor que posiciona todo el widget en la esquina inferior derecha. */
.chat-widget-wrapper {
    position: fixed; /* Fijo en la pantalla, no se mueve con el scroll. */
    bottom: 20px;
    right: 20px;
    z-index: 1000; /* Asegura que esté por encima de otros elementos de la página. */
}

/* La "burbuja" o botón inicial para abrir el chat. */
.chat-bubble {
    background-image: linear-gradient(to right, #6366f1, #3b82f6); /* Degradado de colores. */
    color: white;
    border-radius: 9999px; /* Totalmente redondeado. */
    width: 200px !important;
    height: 50px !important;
    padding: 0.5rem 1.25rem !important;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2); /* Sombra para darle profundidad. */
    transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out; /* Animación suave al pasar el cursor. */
    border: none;
    outline: none;
    font-size: 1rem !important;
    font-weight: 800;
    text-align: center;
    line-height: 1.2;
    white-space: nowrap; /* Evita que el texto se parta en dos líneas. */
}
.chat-bubble:hover {
    transform: scale(1.05); /* Agranda ligeramente el botón al pasar el cursor. */
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

/* Estilos del contenedor del chat (estado expandido) */
.chat-container {
    width: 100%;
    max-width: 420px; /* Ancho ajustado para parecer un chat de soporte */
    height: 600px; /* Altura ajustada */
    background-color: #ffffff;
    border-radius: 1rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Inicia oculto, se muestra con JS */
    opacity: 0;
    visibility: hidden;
    transform: scale(0.8);
    /* Importante: el origen de la transformación para que se abra desde la esquina INFERIOR DERECHA */
    transform-origin: bottom right; /* ¡Se expandirá desde abajo a la derecha! */
    transition: opacity 0.3s ease-out, transform 0.3s ease-out, visibility 0.3s ease-out;
    /* Posición explícita de la ventana de chat cuando está abierta */
    position: fixed;
    bottom: 20px;
    right: 20px;
    left: auto;
    top: auto;
    z-index: 1000; /* Aseguramos que esté por encima de otros elementos */
}

/* Clase para mostrar el chat */
.chat-container.open {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
}

/* Cabecera del chat con logo y nombre */
.chat-header {
    background-color: #3b82f6;
    color: white;
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-top-left-radius: 1rem;
    border-top-right-radius: 1rem;
    position: relative;
}

.chat-logo {
    width: 60px;
    height: 60px;
    border-radius: 9999px;
    margin-right: 0.75rem;
    border: 2px solid white; /* Pequeño borde para el logo */
}

.chat-agent-name {
    font-weight: 600;
    font-size: 1.0rem; /* text-lg */
    flex-grow: 1;
}

.close-chat-button {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 0.5rem;
    transition: transform 0.2s ease-in-out;
}

.close-chat-button:hover {
    transform: rotate(90deg);
}

.chat-messages {
    flex-grow: 1;
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background-color: #f9fafb;
}
.message-bubble {
    max-width: 80%;
    padding: 0.6rem 0.9rem;
    border-radius: 1.2rem;
    word-wrap: break-word;
    font-size: 0.9rem;
}
/* Nuevo estilo para los iframes dentro de las burbujas */
.message-bubble iframe {
    border-radius: 0.75rem; /* Aplica bordes redondeados al iframe */
    width: 100%; /* Asegura que ocupe todo el ancho de la burbuja */
    height: 215px; /* Altura ajustada para el video */
    display: block; /* Asegura que se comporte como un bloque */
    margin: 10px 0 0 0;
}
 /* Estilo para los botones de WhatsApp y pago */
.whatsapp-button {
    display: inline-block;
    padding: 6px 12px;
    background-color: #25D366; /* Color por defecto de WhatsApp */
    color: #fff !important;
    font-weight: bold;
    border-radius: 6px;
    text-decoration: none;
    font-family: Arial, sans-serif;
    font-size: 12.5px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
    text-align: center;
    transition: all 0.2s ease;
    text-shadow: 0 0 1px rgba(0, 0, 0, 0.3);
    white-space: nowrap; /* Evita que el texto del botón se rompa */
}
.whatsapp-button:hover {
    background-color: #1DA851;
}

/* Estilos para los botones de pago específicos */
.payment-button {
    display: inline-block;
    width: 250px;
    padding: 12px;
    background-color: #5eb3f0;
    color: #fff !important;
    font-weight: bold;
    border-radius: 8px;
    text-decoration: none;
    font-family: Arial, sans-serif;
    font-size: 14px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
    text-align: center;
    transition: all 0.2s ease;
    text-shadow: 0 0 1px rgba(0, 0, 0, 0.3);
}
.payment-button:hover {
    background-color: #4097d1;
}

.user-message {
    align-self: flex-end;
    background-color: #3b82f6;
    color: white;
    border-bottom-right-radius: 0.4rem;
}
.agent-message {
    align-self: flex-start;
    background-color: #e5e7eb;
    color: #374151;
    border-bottom-left-radius: 0.4rem;
}
/* Estilo para el indicador de escritura */
.typing-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 1.2em; /* Altura para que los puntos "reboten" */
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    margin: 0 2px;
    background-color: #374151; /* Color de los puntos */
    border-radius: 50%;
    display: inline-block;
    animation: bounce 0.8s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}
.typing-indicator span:nth-child(2) {
    animation-delay: -0.16s;
}
.typing-indicator span:nth-child(3) {
    animation-delay: 0s;
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-5px);
    }
}

.chat-input-area {
    display: flex;
    padding: 1rem;
    border-top: 1px solid #e5e7eb;
    background-color: #ffffff;
    border-bottom-left-radius: 1rem;
    border-bottom-right-radius: 1rem;
    align-items: center;
    justify-content: center;
}
.chat-input {
    flex-grow: 1;
    padding: 0.6rem 0.9rem;
    border: 1px solid #d1d5db;
    border-radius: 0.75rem;
    outline: none;
    font-size: 0.9rem;
    transition: border-color 0.2s ease-in-out;
}
.chat-input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}
.send-button {
    background-color: #3b82f6;
    color: white;
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 0.75rem;
    margin-left: 0.75rem;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: background-color 0.2s ease-in-out, transform 0.1s ease-in-out;
}
.send-button:hover {
    background-color: #2563eb;
    transform: translateY(-1px);
}
.send-button:active {
    transform: translateY(0);
}

.new-conversation-button {
     background-color: #16a34a; /* green-600 */
     color: white;
     padding: 0.75rem 1.5rem;
     border: none;
     border-radius: 0.75rem;
     cursor: pointer;
     font-size: 0.9rem;
     font-weight: 600;
     transition: background-color 0.2s ease-in-out, transform 0.1s ease-in-out;
     width: 100%;
}

.new-conversation-button:hover {
    background-color: #15803d; /* green-700 */
    transform: translateY(-1px);
}

/* Estilos responsivos para pantallas más pequeñas */
@media (max-width: 640px) {
    .chat-widget-wrapper {
        bottom: 10px; /* Ajuste para móvil en la parte inferior derecha */
        right: 10px; /* Ajuste para móvil en la parte inferior derecha */
    }
    .chat-bubble {
        width: 180px !important; /* Añadido !important */
        height: 50px !important; /* Añadido !important */
        font-size: 0.9rem !important; /* Añadido !important */
        padding: 0.5rem 1rem !important; /* Añadido !important */
    }
    .chat-container {
        max-width: 90vw; /* Ocupa casi todo el ancho en móviles */
        height: 80vh; /* Ocupa casi toda la altura en móviles */
        border-radius: 0.5rem; /* Bordes un poco menos redondeados en móvil */
        bottom: 10px; /* Posición del chat para móvil */
        right: 10px; /* Posición del chat para móvil */
    }
    .chat-header {
        padding: 0.75rem;
        border-top-left-radius: 0.5rem;
        border-top-right-radius: 0.5rem;
    }
    .chat-logo {
        width: 35px;
        height: 35px;
    }
    .chat-agent-name {
        font-size: 1rem;
    }
    .chat-messages {
        padding: 0.75rem;
        gap: 0.6rem;
    }
    .message-bubble {
        font-size: 0.9rem; /* Letra ajustada para móvil */
        padding: 0.75rem 1rem;
        max-width: 90%; /* Mayor ancho para mensajes en móvil */
    }
    .chat-input-area {
        padding: 0.75rem;
        border-bottom-left-radius: 0.5rem;
        border-bottom-right-radius: 0.5rem;
    }
    .chat-input, .send-button {
        padding: 0.75rem 1rem;
        font-size: 0.9rem; /* Letra ajustada para input en móvil */
    }
     .message-bubble iframe {
        height: 180px;
    }
}
