/* Estilos para el chat flotante */
#chat-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 350px; /* Ajustado para mejor diseño */
    height: 450px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    font-family: Arial, sans-serif;
    display: flex;
    flex-direction: column;
    resize: both; /* Permite redimensionar en ambas direcciones */
    overflow: hidden;
    min-width: 250px;
    min-height: 300px;
    max-width: 90vw; /* Limita el tamaño para que no se salga de la pantalla */
    max-height: 90vh;
    z-index: 10000;
}

#chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #333;
    color: white;
    padding: 10px;
    font-weight: bold;
    user-select: none;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    cursor: grab;
}


#chat-messages {
    scroll-behavior: smooth;
    flex: 1;
    padding: 10px;
    overflow-y: auto;
    word-wrap: break-word;
    display: flex;
    flex-direction: column;
}

#chat-input-container {
    display: flex;
    padding: 10px;
    border-top: 1px solid #ddd;
    background: #f9f9f9;
    align-items: center;
}

#chat-input {
    flex: 1;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 5px;
    outline: none;
    width: 100%;
    max-width: calc(100% - 60px); /* Ajuste para que no se solape con el botón */
}

/* Botón de enviar */
#chat-send {
    background: #4689eb;
    color: white;
    border: none;
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 5px;
    margin-left: 5px;
    min-width: 50px;
}

#chat-send:hover {
    background: #356ac3;
}

/* Ajustar los mensajes dentro del chat */
.chat-message {
    padding: 4px 8px; /* Reducir el padding */
    margin: 3px 0; /* Reducir margen entre mensajes */
    border-radius: 5px;
    max-width: 85%;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
    font-size: 14px; /* Reducir un poco el tamaño del texto */
    line-height: 1.2; /* Reducir el espacio entre líneas */
}

/* Mensaje del usuario */
.chat-message.user {
    background: #e1f5fe;
    align-self: flex-end;
}

/* Mensaje del bot */
.chat-message.bot {
    background: #f1f1f1;
    align-self: flex-start;
}

.chat-message.bot .chat-html-content {
    font-family: Arial, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    color: #000;

    /* 🎬 Animación suave de entrada en cada fragmento recibido */
    animation: fadeInSmooth 0.25s ease-in-out;
    transition: opacity 0.2s ease-in-out;
    opacity: 0.97;
}


.chat-message.bot .chat-html-content h1,
.chat-message.bot .chat-html-content h2,
.chat-message.bot .chat-html-content h3,
.chat-message.bot .chat-html-content h4 {
    margin: 10px 0;
    font-weight: bold;
    font-size: 15px;
}

.chat-message.bot .chat-html-content p {
    margin: 8px 0;
}

.chat-message.bot .chat-html-content ul {
    margin: 8px 0;
    padding-left: 18px;
    list-style-type: disc;
}

.chat-message.bot .chat-html-content li {
    margin-bottom: 8px;
}
/* Icono de estado WebSocket */
.status-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 8px;
    vertical-align: middle;
    transition: background 0.3s ease;
}

.status-dot.connecting { background: #f0ad4e; }  /* Amber */
.status-dot.connected { background: #5cb85c; }   /* Green */
.status-dot.disconnected { background: #d9534f; } /* Red */

#chat-header .title-text {
    font-size: 14px; /* o 16px, 18px, etc. */
    vertical-align: middle;
    font-weight: bold;
}


/* 🌟 Estilo elegante para tablas en el chat del bot */
.chat-message.bot .chat-html-content table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: 10px 0;
    font-size: 13px;
    border: 1px solid #dcdcdc;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
    background: #fff;
}

.chat-message.bot .chat-html-content thead th {
    background-color: #2e2e2e; /* gris oscuro profesional */
    color: #ffffff;            /* texto blanco puro */
    font-weight: bold;
}

.chat-message.bot .chat-html-content th,
.chat-message.bot .chat-html-content td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid #e0e0e0;
}

.chat-message.bot .chat-html-content th:first-child,
.chat-message.bot .chat-html-content td:first-child {
    border-left: none;
}

.chat-message.bot .chat-html-content tr:last-child td {
    border-bottom: none;
}

.chat-message.bot .chat-html-content tr:hover {
    background-color: #f9f9f9;
    transition: background 0.2s ease;
}

/* Opcional: redondear bordes */
.chat-message.bot .chat-html-content table tr:first-child th:first-child {
    border-top-left-radius: 8px;
}
.chat-message.bot .chat-html-content table tr:first-child th:last-child {
    border-top-right-radius: 8px;
}
.chat-message.bot .chat-html-content table tr:last-child td:first-child {
    border-bottom-left-radius: 8px;
}
.chat-message.bot .chat-html-content table tr:last-child td:last-child {
    border-bottom-right-radius: 8px;
}

/* === Estilo para código en línea y bloques === */
.chat-message.bot .chat-html-content code {
    background: #f5f5f5;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    padding: 2px 4px;
    border-radius: 4px;
    color: #c7254e;
}

.chat-message.bot .chat-html-content pre {
    background: #f5f5f5;
    padding: 10px;
    border-radius: 5px;
    overflow-x: auto;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.5;
    border: 1px solid #ddd;
}

/* === Estilo para bloques destacados === */
.chat-message.bot .chat-html-content blockquote {
    margin: 10px 0;
    padding: 10px 16px;
    background: #f9f9f9;
    border-left: 4px solid #ccc;
    font-style: italic;
    color: #555;
}

/* === Estilo para enlaces en respuestas === */
.chat-message.bot .chat-html-content a {
    color: #1a73e8;
    text-decoration: none;
}

.chat-message.bot .chat-html-content a:hover {
    text-decoration: underline;
}


@media (max-width: 600px) {
    #chat-container {
        width: 90vw;
        height: 80vh;
        bottom: 10px;
        right: 10px;
        border-radius: 8px;
        max-width: 95vw;
        max-height: 90vh;
    }

    #chat-header {
        font-size: 16px;
        padding: 8px;
    }

    #chat-input {
        font-size: 14px;
    }

    .chat-message {
        font-size: 13px;
    }

    .chat-message.bot .chat-html-content table {
        font-size: 12px;
    }

    #chat-send {
        padding: 6px 10px;
        font-size: 13px;
        min-width: 44px;
    }
}

/* Botón de minimizar, a la derecha */
#chat-minimize {
    background: transparent;
    border: none;
    color: white;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    margin-left: auto; /* 🔁 Empuja el botón a la derecha */
    padding: 0 10px;
    line-height: 1;
}

#chat-minimize:hover {
    color: #ccc;
}

#chat-container.minimized {
    height: 42px !important;
    width: auto !important;
    min-width: unset !important;
    min-height: unset !important;
    max-width: unset !important;
    max-height: unset !important;
    overflow: hidden !important;
    bottom: 20px !important;
    right: 20px !important;
    top: auto !important;
    left: auto !important;
    resize: none !important;
    transition: all 0.3s ease;
}


/* Ocultar secciones al minimizar */
#chat-container.minimized #chat-input-container,
#chat-container.minimized #chat-messages {
    display: none;
}


@keyframes fadeInSmooth {
    from {
        opacity: 0.6;
        transform: translateY(2px);
    }
    to {
        opacity: 0.97;
        transform: translateY(0);
    }
}
