:root {
    --primary-color: #eb0b90; /* Magenta del frontend_ci3 */
    --primary-hover: #d30a82; /* Color hover magenta */
    --secondary-color: #6c757d;
    --light-bg: #f8f9fa;
    --dark-text: #343a40;
    --sidebar-bg: #ffffff;
    --button-active-bg: #eb0b90; /* Cambiado a magenta */
    --button-active-color: #fff;
    --hover-bg-color: #e9ecef; /* Gris claro para hover */
    --toolbar-padding: 5px 10px;
    --button-group-gap: 10px; /* Espacio entre grupos de botones */
    --mode-button-gap: 5px; /* Espacio entre botones de modo */
    --action-button-gap: 8px; /* Espacio entre botones de acción */
    --border-color: #dee2e6;
    --bg-light: #f8f9fa;
    --text-muted: #6c757d;
    --text-color: #212529;
}

/* --- ESTILOS SIDEBAR --- */
#sidebar {
    width: 100%;
    background-color: var(--sidebar-bg);
    padding: 20px;
    display: flex;
    flex-direction: column;
    overflow-y: auto; /* Permitir scroll si hay muchas conversaciones */
    margin-bottom: 25px;
    border-radius: 10px;
}

#sidebar h3 {
    margin-top: 0;
    margin-bottom: 20px;
    font-size: 1.2em;
    color: #333;
    border-bottom: 1px solid #ccc;
    padding-bottom: 10px;
}

#sidebar ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

#sidebar li a {
    display: block;
    padding: 8px 10px;
    text-decoration: none;
    color: #333;
    border-radius: 4px;
    margin-bottom: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.9em;
    transition: background-color 0.2s ease-in-out;
}

#sidebar li a:hover {
    background-color: var(--hover-bg-color);
    color: var(--primary-color);
}

#sidebar li a.active {
    background-color: var(--button-active-bg);
    color: var(--button-active-color);
}

/* Estilos para la sidebar y el icono de borrar */
#sidebar ul li {
    position: relative; /* Necesario para posicionar el icono de borrar */
    padding-right: 30px; /* Espacio para el icono de borrar */
}

#sidebar ul li .delete-icon {
    display: none; /* Oculto por defecto */
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    color: #dc3545; /* Color rojo para borrar */
    opacity: 0.7;
    transition: opacity 0.2s;
}

#sidebar ul li:hover .delete-icon {
    display: inline-block; /* Mostrar al hacer hover sobre el li */
}

#sidebar ul li .delete-icon:hover {
    opacity: 1;
}

/* --- CONTENIDO PRINCIPAL --- */
#main-content { 
    overflow: hidden; /* Evita que el contenido principal cause scroll en body */
    width: 100%;
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto; /* Añadir scrollbar horizontal cuando sea necesario */
    padding: 20px;
    border: 1px solid #ccc;
    border-radius: 5px;
    margin-bottom: 20px;
    background-color: #fff;
    height: 620px;
}

.message {
    margin-bottom: 15px;
    padding: 10px;
    border-radius: 5px;
    max-width: 80%;
    word-wrap: break-word;
}

.message.user-message {
    background-color: #f0f0f0;
    margin-left: auto;
    border-right: 3px solid var(--primary-color);
}

.message.bot-message {
    background-color: #ffffff;
    margin-right: auto;
    border-left: 3px solid var(--primary-color);
}

.message.error-message {
    background-color: #ffe6e6;
    color: #ff0000;
    margin-right: auto;
}

/* --- BARRA DE HERRAMIENTAS --- */
#chat-toolbar {
    display: flex;
    justify-content: space-between; /* Separar grupos */
    align-items: center;
    padding: 5px 10px; /* Valor fijo */
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-light);
    width: 100%; /* Asegurar ancho completo */
    box-sizing: border-box; /* Incluir padding/border en el ancho */
    margin-bottom: 10px;
}

/* Contenedores para los grupos de botones */
.button-group {
    display: flex;
    align-items: center;
}

.left-buttons {
     display: flex; /* Asegurar flex */
     align-items: center; /* Asegurar alineación vertical */
}

/* Espaciado entre botones G, R, T */
.left-buttons .mode-button:not(:last-child) { 
    margin-right: 5px; /* Margen entre botones de modo */
}

/* Separar el toggle-short del resto de modos */
#btn-toggle-short {
    margin-left: 10px; /* Espacio antes del toggle */
}

.action-buttons {
    display: flex; /* Asegurar flex */
    align-items: center; /* Asegurar alineación vertical */
}

/* Espaciado entre botones de acción */
.action-buttons .toolbar-button:not(:first-child) {
    margin-left: 8px; /* Margen entre botones de acción */
}

/* Estilos base para todos los botones de la toolbar */
#chat-toolbar .toolbar-button {
    background: none;
    border: none;
    padding: 6px 8px;
    cursor: pointer;
    color: var(--text-muted); /* Color grisáceo por defecto */
    border-radius: 4px;
    transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out;
    display: inline-flex; /* Para alinear icono y posible texto */
    align-items: center; /* Centrar icono verticalmente */
    justify-content: center; /* Centrar icono horizontalmente */
}

#chat-toolbar .toolbar-button:hover {
    background-color: var(--hover-bg-color);
    color: var(--text-color); /* Color de texto normal al hacer hover */
}

/* Estilo específico para botones activos (modo y toggle) */
#chat-toolbar .toolbar-button.active {
    background-color: var(--button-active-bg);
    color: var(--button-active-color);
}

/* Estilos para los iconos SVG */
#chat-toolbar .toolbar-button svg {
    width: 18px; /* Tamaño consistente */
    height: 18px;
    vertical-align: middle;
}

/* --- ÁREA DE ENTRADA --- */
#input-container {
    display: flex;
    gap: 10px;
}

#messageInput {
    flex: 1;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 16px;
}

#sendButton {
    padding: 10px 20px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s;
}

#sendButton:hover {
    background-color: var(--primary-hover);
}

#sendButton:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
}

/* --- INDICADOR DE ESCRITURA --- */
.typing-indicator {
    display: none; /* Oculto por defecto */
    padding: 10px 20px;
    color: #555;
    text-align: left;
    margin-right: auto;
    font-style: italic;
}

.typing-indicator span {
    display: inline-block;
    width: 8px;
    height: 8px;
    background-color: #555;
    border-radius: 50%;
    margin-right: 5px;
    animation: typing 1s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
    margin-right: 0;
}

@keyframes typing {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-5px);
    }
}

/* --- ESTILOS DE CÓDIGO --- */
pre {
    background-color: #f6f8fa;
    padding: 16px;
    border-radius: 6px;
    overflow-x: auto;
}

code {
    font-family: 'Courier New', Courier, monospace;
}

/* --- POPUP DE AYUDA --- */
#help-popup {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80%;
    max-width: 600px;
    max-height: 80vh;
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    overflow-y: auto;
    padding: 20px;
}

#help-popup h3 {
    color: var(--primary-color);
    margin-top: 0;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
    margin-bottom: 15px;
}

#help-popup .close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #999;
}

#help-popup .close-btn:hover {
    color: #333;
}

#help-popup .section {
    margin-bottom: 20px;
}

#help-popup .section h4 {
    color: var(--primary-color);
    margin-bottom: 10px;
}

#help-popup .help-item {
    display: flex;
    align-items: flex-start;
    margin-bottom: 12px;
}

#help-popup .help-icon {
    width: 24px;
    height: 24px;
    margin-right: 10px;
    color: var(--primary-color);
    flex-shrink: 0;
}

#help-popup .help-text {
    flex: 1;
}

#help-popup .help-text strong {
    display: block;
    margin-bottom: 2px;
}

#help-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

/* --- ESTILOS PARA CONTENIDO DE MENSAJES --- */
.message-content {
    line-height: 1.5;
}

.message-content p {
    margin-bottom: 1em;
}

.message-content h1, 
.message-content h2, 
.message-content h3, 
.message-content h4, 
.message-content h5, 
.message-content h6 {
    margin-top: 1.5em;
    margin-bottom: 0.5em;
}

.message-content ul, 
.message-content ol {
    margin-bottom: 1em;
    padding-left: 2em;
}

.message-content li {
    margin-bottom: 0.5em;
}

.message-content pre {
    background-color: #f5f5f5;
    padding: 1em;
    border-radius: 5px;
    overflow-x: auto;
    margin-bottom: 1em;
}

.message-content code {
    font-family: 'Courier New', Courier, monospace;
    background-color: #f5f5f5;
    padding: 0.2em 0.4em;
    border-radius: 3px;
}

.message-content pre code {
    padding: 0;
    background-color: transparent;
}

.message-content blockquote {
    border-left: 4px solid var(--primary-color);
    padding-left: 1em;
    margin-left: 0;
    margin-bottom: 1em;
    color: #666;
}

.message-content img {
    max-width: 256px;
    height: auto;
    cursor: pointer;
    margin-bottom: 1em;
}

.message-content a {
    color: var(--primary-color);
    text-decoration: none;
}

.message-content a:hover {
    text-decoration: underline;
}

/* --- RESPONSIVE --- */
@media (max-width: 768px) {
    body {
        flex-direction: column;
    }
    
    #sidebar {
        width: 100%;
        height: 50px;
        overflow: hidden;
        transition: height 0.3s;
    }
    
    #sidebar.expanded {
        height: 300px;
    }
    
    #main-content {
        height: calc(100vh - 50px);
    }
    
    .message {
        max-width: 90%;
    }
    
    #chat-toolbar {
        flex-wrap: wrap;
    }
    
    .button-group {
        margin: 5px 0;
    }
}