/* =========================================
   RAG CHAT WIDGET - PBTechnologies
   ========================================= */

:root {
    --pbt-dark: #222222;       
    --pbt-dark-sec: #333333;   
    --pbt-red: #da291c;        
    --pbt-red-hover: #b52217;  
    --pbt-light: #f8fafc;      
}

#rag-chat-widget {
    position: fixed;
    bottom: 20px;
    left: 20px; 
    right: auto; 
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

/* ----- BOTÓN FLOTANTE ----- */
#rag-chat-button {
    width: 65px;
    height: 65px;
    border-radius: 50%;
    background: var(--pbt-dark);
    background-image: url('https://pbt.com.bo/wp-content/uploads/2026/03/icono-pbt.png');
    background-size: 60%; 
    background-position: center;
    background-repeat: no-repeat;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
    border: 2px solid var(--pbt-red);
}

#rag-chat-button:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(218, 41, 28, 0.4); 
}

/* ----- VENTANA DEL CHAT ----- */
#rag-chat-window {
    position: absolute;
    bottom: 85px;
    left: 0;
    width: 380px;
    height: 550px;
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
}

/* ----- HEADER DEL CHAT ----- */
#rag-chat-header {
    padding: 0 16px;
    height: 65px;
    background: var(--pbt-dark);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 2px solid var(--pbt-red);
}

/* Contenedor del título */
#rag-chat-header span {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

/* Ajuste del ícono */
#rag-chat-header span::before {
    content: "⚙️";
    font-size: 16px;
    display: flex;
    align-items: center;
}

/* Botón cerrar mejor alineado */
#rag-chat-close {
    background: transparent;
    border: none;
    outline: none;
    color: white;
    font-size: 20px;
    cursor: pointer;

    width: 32px;
    height: 32px;

    display: flex;
    align-items: center;
    justify-content: center;

    border-radius: 6px; /* opcional */
    transition: all 0.2s ease;
}

#rag-chat-close:hover {
    background: rgba(255,255,255,0.1);
    color: var(--pbt-red);
}

/* ----- ÁREA DE MENSAJES ----- */
#rag-chat-messages {
    flex: 1 1 auto;
    padding: 20px 15px;
    overflow-y: auto;
    background: var(--pbt-light);
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
}

.rag-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    line-height: 1.5;
    font-size: 14px;
    word-wrap: break-word;
    animation: messageAppear 0.3s ease;
    position: relative;
}

@keyframes messageAppear {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.rag-message.user {
    background: var(--pbt-red);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 5px rgba(218, 41, 28, 0.2);
}

.rag-message.bot {
    line-height: 1.6;
    letter-spacing: 0.2px;
    color: #333;
    border-left: 3px solid var(--pbt-red); /* Cambiado de Dark a Red para coherencia */
    background: #ffffff;
}

.message-time {
    font-size: 10px;
    opacity: 0.6;
    margin-top: 5px;
    text-align: right;
}

/* ----- ÁREA DE ENTRADA ----- */
#rag-chat-input-area {
    padding: 16px 15px 18px;
    background: #ffffff;
    border-top: 1px solid #eee; /* Borde más fino */
    display: flex;
    gap: 12px;
    align-items: center; /* Centrado vertical perfecto */
    flex-shrink: 0;
    min-height: 75px;
    box-sizing: border-box;
}

#rag-chat-input {
    flex: 1;
    padding: 12px 20px;
    border: 1px solid #e0e0e0; /* Menos grueso */
    border-radius: 24px;
    outline: none;
    font-size: 14px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: #f9f9f9;
}

#rag-chat-input:focus {
    border-color: var(--pbt-red);
    background: white;
    box-shadow: 0 0 0 3px rgba(218, 41, 28, 0.1); /* Efecto de foco moderno */
}

#rag-chat-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--pbt-red);
    border: none;

    display: flex;
    align-items: center;
    justify-content: center;

    cursor: pointer;
}

#rag-chat-send svg {
    width: 20px;
    height: 20px;
    fill: white;
    display: block;
    transform: translateX(1px);
}

#rag-chat-send:hover {
    background: var(--pbt-red-hover);
    transform: scale(1.08);
}

/* ----- INDICADOR DE ESCRITURA ----- */
#rag-chat-typing {
    padding: 10px 15px;
    background: white;
    border-top: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--pbt-dark);
    opacity: 0.6;
    animation: typingAnimation 1.4s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingAnimation {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.6; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* ----- FORMATO DE RESPUESTAS ----- */
.rag-message.bot strong {
    color: var(--pbt-red);
    font-weight: 600;
}
.rag-message.bot ul {
    margin: 8px 0;
    padding-left: 20px;
}
.rag-message.bot li {
    margin: 4px 0;
}

/* ----- TOOLTIP ----- */
.rag-chat-tooltip {
    position: absolute;
    left: 85px;
    bottom: 12px;
    background: white;
    padding: 12px 18px;
    border-radius: 15px 15px 15px 0;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    font-size: 14px;
    color: var(--pbt-dark);
    font-weight: 500;
    white-space: nowrap;
    border: 1px solid #e2e8f0;
    cursor: pointer;
    animation: bounceInTooltip 0.6s ease;
    z-index: 1000000;
}

.rag-chat-tooltip::after {
    content: '';
    position: absolute;
    left: -8px;
    bottom: 0;
    border-width: 0 10px 12px 0;
    border-style: solid;
    border-color: transparent white transparent transparent;
}

@keyframes bounceInTooltip {
    0% { opacity: 0; transform: scale(0.5); }
    100% { opacity: 1; transform: scale(1); }
}

/* ----- SCROLL PERSONALIZADO ----- */
#rag-chat-messages::-webkit-scrollbar {
    width: 6px;
}
#rag-chat-messages::-webkit-scrollbar-track {
    background: #e2e8f0;
    border-radius: 10px;
}
#rag-chat-messages::-webkit-scrollbar-thumb {
    background: var(--pbt-dark-sec);
    border-radius: 10px;
}

/* ----- RESPONSIVE ----- */
@media (max-width: 480px) {
    #rag-chat-widget { 
        left: 15px; 
        bottom: 15px; 
    }
    #rag-chat-window {
        width: calc(100vw - 30px);
        padding-bottom: 5px;
        height: 80vh;
        bottom: 0;
        left: 0;
        border-radius: 15px;
    }
    .rag-chat-tooltip { 
        display: none; 
    }
}

/* ----- ESTILO DE TABLAS EN EL CHAT ----- */
.rag-message.bot table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 13px;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #e2e8f0;
    display: block; /* Permite scroll horizontal en móviles */
    overflow-x: auto;
}

.rag-message.bot th {
    background-color: var(--pbt-dark);
    color: white;
    text-align: left;
    padding: 10px;
    font-weight: 600;
    border-bottom: 2px solid var(--pbt-red);
}

.rag-message.bot td {
    padding: 8px 10px;
    border-bottom: 1px solid #f1f5f9;
    color: #334155;
    min-width: 100px;
}

.rag-message.bot tr:nth-child(even) {
    background-color: #f8fafc;
}

.rag-message.bot tr:hover {
    background-color: #f1f5f9;
}

/* Mejora de enlaces (URLs de productos) */
.rag-message.bot a {
    color: var(--pbt-red);
    text-decoration: none;
    font-weight: 600;
    border-bottom: 1px dashed var(--pbt-red);
}

.rag-message.bot a:hover {
    color: var(--pbt-red-hover);
    border-bottom-style: solid;
}

/* Ajuste para que las imágenes no se salgan del mensaje */
.rag-message.bot img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin-top: 10px;
}

/* Contenedor para scroll horizontal si la tabla es grande */
.table-container {
    width: 100%;
    overflow-x: auto;
    margin: 10px 0;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.rag-message.bot table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    font-size: 12px; /* Un poco más pequeña para que quepa mejor */
}

.rag-message.bot th {
    background: #222; /* Tu color var(--pbt-dark) */
    color: white;
    padding: 8px;
    text-align: left;
}

.rag-message.bot td {
    padding: 8px;
    border-bottom: 1px solid #eee;
    color: #333;
    min-width: 80px; /* Evita que las palabras se amontonen */
}

.pbt-product-link {
    display: inline-block;
    background-color: var(--pbt-red);
    color: white !important;
    padding: 5px 12px;
    border-radius: 15px;
    text-decoration: none !important;
    font-size: 12px;
    font-weight: 600;
    margin: 5px 0;
    border: none !important;
    transition: background 0.2s;
}

.pbt-product-link:hover {
    background-color: var(--pbt-red-hover);
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
/* Estilo para los links de productos */
.product-link {
    display: inline-block;
    background: #e40611;
    color: #ffffff !important;
    padding: 8px 16px;
    margin: 5px 0;
    border-radius: 4px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.product-link:hover {
    background: #9c0324;
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    color: #ffffff !important;
}

/* Separador */
.separator {
    margin: 20px 0;
    border: none;
    height: 2px;
    background: linear-gradient(90deg, #7b1fa2, #e0e0e0, #7b1fa2);
}

/* Etiquetas de links */
.link-label {
    display: inline-block;
    margin-top: 10px;
}
/* Reducir márgenes en listas */
.rag-message.bot ol,
.rag-message.bot ul {
    margin: 0 0 5px 0;
    padding-left: 25px;
}

.rag-message.bot li {
    margin: 2px 0;
}

.rag-message.bot p {
    margin: 5px 0;
}

.rag-message.bot hr.separator {
    margin: 10px 0;
    border: none;
    height: 1px;
    background: #e2e8f0;
}

/* Eliminar márgenes del primer párrafo después de la lista */
.rag-message.bot ul + p,
.rag-message.bot ol + p {
    margin-top: 8px;
}

/* Estilo para la sección de contacto */
.rag-message.bot p:has(📞) {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid #e2e8f0;
}
/* Badge de notificación */
#rag-chat-notification-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #ff4444;
    color: white;
    border-radius: 50%;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    font-size: 11px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1001;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    animation: bounce 0.5s ease;
}

.badge-count {
    font-size: 11px;
    line-height: 1;
}

/* Animación de pulso para el botón */
.pulse-animation {
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 68, 68, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(255, 68, 68, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(255, 68, 68, 0);
    }
}

@keyframes bounce {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
}

/* Toast notification */
.rag-chat-toast {
    position: fixed;
    bottom: 100px;
    right: 20px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    padding: 12px 15px;
    min-width: 280px;
    max-width: 350px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 10000;
    cursor: pointer;
    transform: translateX(400px);
    transition: transform 0.3s ease;
    border-left: 4px solid var(--pbt-red, #ff4444);
}

.rag-chat-toast.show {
    transform: translateX(0);
}

.toast-icon {
    font-size: 24px;
    background: #f0f0f0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toast-content {
    flex: 1;
}

.toast-title {
    font-weight: bold;
    font-size: 14px;
    margin-bottom: 4px;
    color: #333;
}

.toast-message {
    font-size: 12px;
    color: #666;
    line-height: 1.4;
}

.toast-close {
    font-size: 20px;
    color: #999;
    cursor: pointer;
    padding: 0 5px;
    transition: color 0.2s;
}

.toast-close:hover {
    color: #333;
}

/* Responsive para móviles */
@media (max-width: 768px) {
    .rag-chat-toast {
        bottom: 80px;
        right: 10px;
        left: 10px;
        min-width: auto;
        max-width: none;
    }
}