/* Layout base para ocupar la pantalla sin hacer scroll en el body */
.chat-layout {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
    position: relative;
}

/* Área donde viven los mensajes */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    scroll-behavior: smooth;
}

/* Scrollbar estilizado para dark mode */
.chat-container::-webkit-scrollbar { width: 8px; }
.chat-container::-webkit-scrollbar-track { background: transparent; }
.chat-container::-webkit-scrollbar-thumb { background-color: #333; border-radius: 4px; }

/* Burbujas de Mensaje */
.message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: fadeIn 0.3s ease-in-out;
}

.msg-content {
    padding: 1rem 1.25rem;
    font-size: 1.05rem;
    line-height: 1.6;
    border-radius: 8px;
    white-space: pre-wrap; /* Respeta los saltos de línea del LLM */
}

/* Mensaje del Usuario */
.user-msg {
    align-self: flex-end;
}
.user-msg .msg-content {
    background-color: #2d2d2d;
    color: #ffffff;
    border-bottom-right-radius: 2px;
}

/* Mensaje de Norma (IA) */
.assistant-msg {
    align-self: flex-start;
}
.assistant-msg .msg-content {
    background-color: transparent;
    color: #e0e0e0;
    border: 1px solid #333;
    border-bottom-left-radius: 2px;
}

/* Chips de Citas (¡La ventaja del DOM nativo!) */
.citations-container {
    margin-top: 0.8rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.citation-chip {
    font-size: 0.75rem;
    font-family: monospace;
    padding: 0.3rem 0.6rem;
    background-color: rgba(138, 180, 248, 0.1);
    color: #8ab4f8;
    border: 1px solid rgba(138, 180, 248, 0.3);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.citation-chip:hover {
    background-color: rgba(138, 180, 248, 0.2);
    transform: translateY(-1px);
}

/* Área del Input */
.input-area {
    padding: 1rem 1rem 2rem 1rem;
    background: linear-gradient(180deg, rgba(26,26,26,0) 0%, rgba(26,26,26,1) 20%);
}

.input-container {
    display: flex;
    gap: 0.8rem;
    background-color: #262626;
    border: 1px solid #404040;
    border-radius: 12px;
    padding: 0.5rem 0.8rem;
    align-items: flex-end;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.input-container:focus-within {
    border-color: #5e5e62;
}

textarea#user-input {
    flex: 1;
    background: transparent;
    border: none;
    color: #fff;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.5;
    resize: none;
    padding: 0.5rem 0;
    max-height: 150px;
    overflow-y: auto;
    outline: none;
}

#send-btn {
    background-color: #ffffff;
    color: #1a1a1a;
    border: none;
    border-radius: 8px;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin-bottom: 2px;
    transition: opacity 0.2s;
}

#send-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.legal-warning {
    text-align: center;
    font-size: 0.75rem;
    color: #666;
    margin-top: 0.8rem;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- Modal de Autenticación --- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background-color: #1e1e1e;
    border: 1px solid #333;
    border-radius: 12px;
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.modal-header {
    text-align: center;
    margin-bottom: 2rem;
}

.modal-header h2 { font-size: 1.5rem; font-weight: 600; margin-bottom: 0.5rem; }
.modal-header p { color: #999; font-size: 0.9rem; }

.modal-tabs {
    display: flex;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid #333;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: #666;
    padding: 0.8rem;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
}

.tab-btn.active {
    color: #fff;
    border-bottom-color: #8ab4f8;
}

#auth-form input {
    width: 100%;
    background-color: #2d2d2d;
    border: 1px solid #444;
    color: #fff;
    padding: 0.8rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

#auth-form input:focus { border-color: #8ab4f8; }

.auth-error {
    color: #ff6b6b;
    font-size: 0.85rem;
    text-align: center;
    margin-top: 1rem;
    min-height: 20px;
}

/* --- Panel Lateral de Citas --- */
.citation-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 400px;
    background-color: #1a1a1a;
    border-left: 1px solid #333;
    box-shadow: -10px 0 30px rgba(0,0,0,0.6);
    z-index: 500;
    display: flex;
    flex-direction: column;
    transform: translateX(0);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.citation-panel.hidden {
    transform: translateX(100%);
}

.panel-header {
    padding: 1.5rem;
    border-bottom: 1px solid #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #1e1e1e;
}

.panel-header h3 {
    font-size: 1.1rem;
    color: #fff;
    font-weight: 600;
}

.close-btn {
    background: transparent;
    border: none;
    color: #999;
    font-size: 1.8rem;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.close-btn:hover { color: #ff6b6b; }

.panel-content {
    padding: 1.5rem;
    overflow-y: auto;
    color: #cccccc;
    font-size: 0.95rem;
    line-height: 1.7;
}

/* Ajuste responsivo para móviles */
@media (max-width: 768px) {
    .citation-panel { width: 100%; }
}

/* --- Estructura Global --- */
.app-layout {
    display: flex;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

/* --- Barra Lateral --- */
.sidebar {
    width: 260px;
    background-color: #171717;
    border-right: 1px solid #2d2d2d;
    display: flex;
    flex-direction: column;
    padding: 0.75rem;
    z-index: 400;
}

.new-chat-btn {
    width: 100%;
    text-align: left;
    padding: 0.6rem 0.8rem;
    font-size: 0.9rem;
    border: 1px solid #444;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    background: transparent;
    transition: background 0.2s;
}
.new-chat-btn:hover { background-color: #262626; }

.history-section {
    flex: 1;
    margin-top: 1.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.history-label {
    font-size: 0.75rem;
    color: #666;
    font-weight: 600;
    padding-left: 0.5rem;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.history-item {
    padding: 0.6rem 0.5rem;
    font-size: 0.9rem;
    color: #ececef;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis; /* Pone los tres puntos (...) si el título es largo */
    transition: background 0.2s;
}
.history-item:hover, .history-item.active {
    background-color: #212121;
}

/* --- Footer de la Barra Lateral --- */
.sidebar-footer {
    border-top: 1px solid #2d2d2d;
    padding-top: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.user-display {
    font-size: 0.85rem;
    color: #8ab4f8;
    padding-left: 0.5rem;
    font-family: monospace;
}

.logout-btn {
    background: transparent;
    border: none;
    color: #999;
    font-size: 0.9rem;
    padding: 0.5rem;
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    border-radius: 6px;
    transition: all 0.2s;
}
.logout-btn:hover {
    color: #ff6b6b;
    background-color: rgba(255, 107, 107, 0.1);
}

/* Modificación de la zona central para que se comporte de forma elástica */
.chat-layout {
    flex: 1;
    min-width: 0; /* Evita que el contenedor desborde con el texto del LLM */
}