:root {
    /* -- Theme Variables -- */
    --bg-color: #f0f2f5; /* Un gris muy claro para el fondo principal */
    --sidebar-bg: #ffffff;
    --chat-bg: #ffffff;
    --text-primary: #1e293b; /* Gris oscuro para texto principal */
    --text-secondary: #64748b; /* Gris medio para texto secundario */
    --accent-color: #3b82f6; /* Azul más profesional */
    --border-color: #e2e8f0; /* Gris claro para bordes */
    --user-msg-bg: #e5e7eb; /* Gris claro para mensajes de usuario */
    --bot-msg-bg: #f8fafc; /* Blanco roto para mensajes del bot */
    --code-bg: #1f2937; /* Gris oscuro para bloques de código */
    --code-text: #f9fafb; /* Blanco para texto de código */
    --shadow-light: 0 1px 3px 0 rgba(0, 0, 0, 0.08), 0 1px 2px -1px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);

    /* -- Layout Variables -- */
    --vh: 1vh;
    --composer-min-height: 72px;
}

/* --- Global & Reset Styles --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
}

/* --- Main App Layout --- */
.app-container {
    display: flex;
    height: calc(var(--vh, 1vh) * 100);
    position: relative;
    overflow: hidden;
}

/* --- Sidebar --- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100%;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-md);
}
.sidebar-open .sidebar { transform: translateX(0); }
.sidebar-header { margin-bottom: 32px; }
.sidebar-button {
    width: 100%;
    padding: 14px;
    background-color: var(--accent-color);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: background-color 0.2s;
    box-shadow: var(--shadow-light);
}
.sidebar-button:hover { background-color: #2563eb; }

.history-nav { margin-bottom: 20px; }
.history-nav h2 { font-size: 0.8rem; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 12px; }
.history-list { list-style: none; overflow-y: auto; flex-grow: 1; }
.history-list li {
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background-color 0.2s, color 0.2s;
    margin-bottom: 6px;
}
.history-list li:hover { background-color: var(--bg-color); }
.history-list li.active { background-color: var(--accent-color); color: white; font-weight: 600; }
.history-list li.active:hover { background-color: var(--accent-color); }

/* --- Overlay for Mobile Sidebar --- */
.overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.4); z-index: 999; opacity: 0; visibility: hidden; transition: opacity 0.3s ease, visibility 0.3s ease; }
.sidebar-open .overlay { opacity: 1; visibility: visible; }

/* --- Chat Area --- */
.chat-area { flex-grow: 1; display: flex; flex-direction: column; background-color: var(--chat-bg); height: 100%; width: 100%; position: relative; }
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    background-color: var(--sidebar-bg);
}
.menu-btn { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-secondary); padding: 8px; margin-left: -8px; }
.chat-title { font-size: 1.25rem; font-weight: 700; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 8px; }
.model-selector { display: flex; align-items: center; gap: 8px; }
#model-select {
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    font-size: 0.875rem;
    background-color: var(--bg-color);
    color: var(--text-primary);
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* --- Messages Container --- */
.messages-container { flex-grow: 1; overflow-y: auto; overscroll-behavior: contain; padding: 24px; padding-bottom: calc(var(--composer-min-height) + 24px); }

.message { display: flex; max-width: 85%; line-height: 1.6; animation: fadeIn 0.4s ease-out; margin-bottom: 24px; }
.message .content {
    padding: 14px 20px;
    border-radius: 20px;
    word-wrap: break-word;
    overflow: hidden;
    width: 100%;
    box-shadow: var(--shadow-light);
}

.user-message { margin-left: auto; flex-direction: row-reverse; }
.user-message .content { background-color: var(--user-msg-bg); border-bottom-right-radius: 8px; }
.bot-message { margin-right: auto; }
.bot-message .content { background-color: var(--bot-msg-bg); border-bottom-left-radius: 8px; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* --- Composer (Input Area) --- */
.composer {
    position: absolute;
    bottom: 0;
    width: 100%;
    display: flex;
    align-items: flex-end;
    gap: 16px;
    padding: 16px 24px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    background-color: var(--sidebar-bg);
    border-top: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
}
#message-input {
    flex-grow: 1;
    padding: 14px 20px;
    border-radius: 26px;
    border: 1px solid var(--border-color);
    font-size: 1rem;
    line-height: 1.5;
    outline: none;
    resize: none;
    max-height: 200px;
    font-family: 'Inter', sans-serif;
    transition: border-color 0.2s, box-shadow 0.2s;
    background-color: var(--bg-color);
    color: var(--text-primary);
}
#message-input:focus { border-color: var(--accent-color); box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2); }
#send-btn {
    height: 48px;
    width: 48px;
    border: none;
    background-color: var(--accent-color);
    color: white;
    border-radius: 50%;
    font-size: 1.25rem;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, transform 0.1s;
    box-shadow: var(--shadow-light);
}
#send-btn:hover { background-color: #2563eb; }
#send-btn:active { transform: scale(0.95); }

/* --- Code Block Styles --- */
pre {
    position: relative;
    background-color: var(--code-bg);
    border-radius: 10px;
    padding: 16px;
    margin: 16px 0;
    color: var(--code-text);
    font-size: 0.9rem;
    overflow-x: auto;
    max-width: 100%;
}
pre code.hljs {
    padding: 0;
    background: transparent;
    color: inherit;
    white-space: pre;
}
.copy-button { position: absolute; top: 12px; right: 12px; background-color: rgba(255, 255, 255, 0.15); color: white; border: none; padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 0.8rem; font-weight: 500; opacity: 0; transition: opacity 0.2s, background-color 0.2s; }
pre:hover .copy-button { opacity: 1; }
.copy-button:hover { background-color: rgba(255, 255, 255, 0.25); }
.copy-button.copied { background-color: #28a745; opacity: 1; }

/* --- Responsive Styles for Desktop --- */
@media (min-width: 768px) {
    .sidebar {
        position: static;
        height: auto;
        transform: translateX(0);
        box-shadow: none;
        flex-shrink: 0;
        border-right: 1px solid var(--border-color);
    }
    .menu-btn, .overlay { display: none; }
    .chat-header { justify-content: space-between; padding: 16px 24px; border-bottom: none; box-shadow: var(--shadow-light); z-index: 10; }
    .chat-title { font-size: 1.25rem; }
    .model-selector { position: static; }
    .messages-container { padding: 32px; }
    .message { max-width: 75%; }
    .composer {
        position: static;
        padding: 24px;
        padding-bottom: calc(24px + env(safe-area-inset-bottom));
        border-top: none;
        box-shadow: none;
        background-color: transparent;
    }
    .composer-wrapper {
        position: fixed;
        bottom: 0;
        left: 280px; /* Ancho del sidebar */
        right: 0;
        background-color: var(--chat-bg);
        border-top: 1px solid var(--border-color);
        box-shadow: var(--shadow-md);
        padding-top: 16px;
    }
}
