* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    height: 100vh;
    overflow: hidden;
}

.container {
    display: flex;
    height: 100vh;
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px;
    gap: 20px;
}

/* Sidebar Styles */
.sidebar {
    width: 280px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
}

.sidebar-header {
    margin-bottom: 20px;
}

.sidebar-header h2 {
    font-size: 20px;
    color: #333;
    margin-bottom: 15px;
}

.btn-new-session {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-new-session:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.sessions-list {
    flex: 1;
    overflow-y: auto;
}

.session-item {
    padding: 12px;
    margin-bottom: 8px;
    background: #f7f7f7;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.session-item:hover {
    background: #e8e8e8;
    transform: translateX(4px);
}

.session-item.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.session-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.session-time {
    font-size: 11px;
    opacity: 0.7;
    display: block;
    margin-bottom: 4px;
}

.session-preview {
    font-size: 13px;
    font-weight: 500;
}

.btn-delete-session {
    background: transparent;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
    opacity: 0.6;
}

.btn-delete-session:hover {
    opacity: 1;
    background: rgba(255, 0, 0, 0.1);
    transform: scale(1.1);
}

.session-item.active .btn-delete-session:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Header Title with Logo */
.header-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-title .logo {
    width: 100px;
    height: 70px;
    border-radius: 12px;
    object-fit: contain;
    background: white;
    padding: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Main Chat Area */
.chat-container {
    flex: 1;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    overflow: hidden;
}

.chat-header {
    padding: 20px 30px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 16px 16px 0 0;
}

.chat-header h1 {
    font-size: 24px;
    font-weight: 600;
}

.bot-selector {
    display: flex;
    align-items: center;
    gap: 10px;
}

.bot-selector label {
    font-size: 14px;
    font-weight: 500;
}

.bot-type-select {
    padding: 8px 16px;
    border: 2px solid white;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    backdrop-filter: blur(10px);
}

.bot-type-select option {
    background: #764ba2;
    color: white;
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.message {
    display: flex;
    gap: 12px;
    animation: fadeIn 0.3s ease-in;
    align-items: flex-end;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.user-message .message-avatar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.assistant-message .message-avatar {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.message-content {
    flex: 1;
    max-width: 70%;
    word-break: break-word;
}

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.message-role {
    font-weight: 600;
    font-size: 14px;
    color: #333;
}

.message-time {
    font-size: 12px;
    color: #999;
}

.message-text {
    background: transparent;
    padding: 0;
    border-radius: 0;
    line-height: 1.6;
    white-space: normal;
    word-wrap: break-word;
    overflow: visible;
}

.user-message .message-text {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: #ffffff !important;
    padding: 12px 16px;
    border-radius: 12px;
    word-break: break-word;
    overflow-wrap: break-word;
    display: inline-block;
    max-width: 100%;
}

.assistant-message .message-text {
    background: transparent;
    color: #333;
    padding: 0;
    border-radius: 0;
}

/* Styles for text content within message */
.assistant-message .message-text > br,
.assistant-message .message-text > span:not(.table-responsive-container) {
    display: block;
    padding: 12px 16px;
    background: #f7f7f7;
    border-radius: 12px;
    margin-bottom: 10px;
}

/* Wrap text nodes in proper styling */
.assistant-message .message-text::before {
    content: '';
}

/* Ensure tables display properly */
.assistant-message .message-text .table-responsive-container {
    margin: 0;
    border-radius: 12px;
    padding: 0;
    background: transparent;
}

/* Chat Input */
.chat-input-container {
    padding: 20px 30px;
    background: white;
    border-top: 1px solid #e8e8e8;
}

.input-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

#user-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e8e8e8;
    border-radius: 12px;
    font-size: 15px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    transition: border-color 0.2s;
}

#user-input:focus {
    outline: none;
    border-color: #667eea;
}

.btn-send {
    padding: 12px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.btn-send:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-send:active {
    transform: translateY(0);
}

.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.send-icon {
    font-size: 18px;
}

/* Scrollbar Styles */
.chat-messages::-webkit-scrollbar,
.sessions-list::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track,
.sessions-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb,
.sessions-list::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.sessions-list::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Loading Animation */
.loading {
    display: inline-block;
}

.loading::after {
    content: '...';
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 10px;
        gap: 10px;
    }
    
    .sidebar {
        display: none;
    }
    
    .message-content {
        max-width: 85%;
    }
}

/* Header Actions */
.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-header {
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.btn-header:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.modal-content {
    background: white;
    margin: 5% auto;
    padding: 0;
    border-radius: 16px;
    width: 90%;
    max-width: 600px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 25px;
    border-bottom: 1px solid #e0e0e0;
}

.modal-header h2 {
    font-size: 22px;
    color: #333;
}

.modal-close {
    font-size: 32px;
    color: #999;
    cursor: pointer;
    transition: color 0.2s ease;
    line-height: 1;
}

.modal-close:hover {
    color: #333;
}

.modal-body {
    padding: 25px;
    max-height: 60vh;
    overflow-y: auto;
}

/* PDF List Styles */
.pdf-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.pdf-item {
    display: flex;
    align-items: center;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.pdf-item:hover {
    background: #e9ecef;
    transform: translateX(5px);
}

.pdf-icon {
    font-size: 24px;
    margin-right: 15px;
}

.pdf-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.pdf-name {
    font-weight: 500;
    color: #333;
    font-size: 14px;
}

.pdf-size {
    font-size: 12px;
    color: #666;
}

.pdf-open {
    font-size: 20px;
    color: #667eea;
}

.no-pdfs, .error, .loading {
    text-align: center;
    padding: 30px;
    color: #666;
}

.error {
    color: #dc3545;
}

/* Upload Wizard Styles */
.upload-question {
    font-size: 16px;
    font-weight: 600;
    color: #333;
    margin-bottom: 6px;
}

.upload-hint {
    font-size: 13px;
    color: #777;
    margin-bottom: 16px;
}

.upload-choices {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}

.btn-choice {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 20px 16px;
    background: #f8f9fa;
    border: 2px solid #e9ecef;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.btn-choice:hover {
    border-color: #667eea;
    background: #f0f0ff;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.btn-choice .choice-icon {
    font-size: 28px;
}

.btn-choice .choice-label {
    font-size: 15px;
    font-weight: 600;
    color: #333;
}

.btn-choice small {
    font-size: 12px;
    color: #888;
    line-height: 1.4;
}

.upload-confirm-box {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
}

.upload-confirm-details p {
    margin-bottom: 8px;
    font-size: 14px;
    color: #333;
}

.upload-confirm-details p:last-child {
    margin-bottom: 0;
}

/* Upload Form Styles */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: #333;
}

.form-group input[type="file"] {
    width: 100%;
    padding: 12px;
    border: 2px dashed #ccc;
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.3s ease;
}

.form-group input[type="file"]:hover {
    border-color: #667eea;
}

.form-group textarea {
    width: 100%;
    padding: 12px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    min-height: 120px;
    transition: border-color 0.2s;
    color: #333;
}

.form-group textarea:focus {
    outline: none;
    border-color: #667eea;
}

.form-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.btn-primary, .btn-secondary {
    flex: 1;
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-primary:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background: #f8f9fa;
    color: #333;
}

.btn-secondary:hover {
    background: #e9ecef;
}

.upload-status {
    margin-top: 15px;
    padding: 12px;
    border-radius: 8px;
    text-align: center;
}

.upload-status .success {
    color: #28a745;
    background: #d4edda;
    padding: 10px;
    border-radius: 6px;
}

.upload-status .error {
    color: #dc3545;
    background: #f8d7da;
    padding: 10px;
    border-radius: 6px;
}

.upload-status .loading {
    color: #667eea;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: #999;
}

.empty-state-icon {
    font-size: 64px;
    margin-bottom: 20px;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 24px;
    margin-bottom: 10px;
    color: #666;
}

.empty-state p {
    font-size: 16px;
    color: #999;
}

.pdf-image-thumbnail {
    max-width: 300px;
    max-height: 200px;
    cursor: pointer;
    border: 2px solid #ccc;
    border-radius: 8px;
    transition: transform 0.2s, box-shadow 0.2s;
    object-fit: contain;
}

.pdf-image-thumbnail:hover {
    transform: scale(1.03);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

/* Fullscreen overlay modal */
.pdf-image-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.9);
    z-index: 10000;
    justify-content: center;
    align-items: center;
    cursor: zoom-out;
}

.pdf-image-overlay.active {
    display: flex;
}

.pdf-image-overlay img {
    max-width: 95vw;
    max-height: 95vh;
    object-fit: contain;
    border-radius: 4px;
}

/* Close button */
.pdf-image-overlay .close-btn {
    position: absolute;
    top: 20px;
    right: 30px;
    color: white;
    font-size: 36px;
    font-weight: bold;
    cursor: pointer;
    z-index: 10001;
    user-select: none;
}

.pdf-image-overlay .close-btn:hover {
    color: #ff6b6b;
}

/* ─────────────────────────────────────────────
   Markdown rendering
───────────────────────────────────────────── */
.markdown-body {
    padding: 12px 16px;
    border-radius: 12px;
    background: #f7f7f7;
    color: #333;
    line-height: 1.7;
    font-size: 15px;
    overflow-wrap: break-word;
    word-break: break-word;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
    margin: 14px 0 6px;
    font-weight: 700;
    line-height: 1.3;
    color: #222;
}

.markdown-body h1 { font-size: 1.4em; }
.markdown-body h2 { font-size: 1.2em; }
.markdown-body h3 { font-size: 1.05em; }

.markdown-body p {
    margin: 0 0 10px;
}

.markdown-body p:last-child {
    margin-bottom: 0;
}

.markdown-body ul,
.markdown-body ol {
    margin: 6px 0 10px 20px;
    padding: 0;
}

.markdown-body li {
    margin-bottom: 4px;
}

.markdown-body code {
    background: #e8e8e8;
    border-radius: 4px;
    padding: 2px 6px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.88em;
    color: #c7254e;
}

.markdown-body pre {
    background: #1e1e1e;
    border-radius: 8px;
    padding: 14px 16px;
    overflow-x: auto;
    margin: 10px 0;
}

.markdown-body pre code {
    background: transparent;
    color: #d4d4d4;
    padding: 0;
    font-size: 0.87em;
    line-height: 1.6;
}

.markdown-body blockquote {
    border-left: 4px solid #667eea;
    margin: 10px 0;
    padding: 8px 14px;
    background: #efefff;
    border-radius: 0 8px 8px 0;
    color: #555;
    font-style: italic;
}

.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
    font-size: 14px;
}

.markdown-body th,
.markdown-body td {
    border: 1px solid #ddd;
    padding: 8px 12px;
    text-align: left;
}

.markdown-body th {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-weight: 600;
}

.markdown-body tr:nth-child(even) {
    background: #f2f2f2;
}

.markdown-body a {
    color: #667eea;
    text-decoration: underline;
}

.markdown-body hr {
    border: none;
    border-top: 1px solid #ddd;
    margin: 14px 0;
}

.markdown-body strong { font-weight: 700; }
.markdown-body em { font-style: italic; }

/* ─────────────────────────────────────────────
   Impresión / exportar a PDF
───────────────────────────────────────────── */
@media print {
    /* Ocultar todo lo que no es el chat */
    .sidebar,
    .chat-header,
    .chat-input-container,
    .modal,
    #pdfImageOverlay {
        display: none !important;
    }

    /* Resetear layout del body y container */
    body {
        background: white !important;
        overflow: visible !important;
        height: auto !important;
    }

    .container {
        display: block !important;
        height: auto !important;
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    /* Chat container: quitar scroll, sombra y radio */
    .chat-container {
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        display: block !important;
        width: 100% !important;
    }

    /* Expandir el área de mensajes */
    .chat-messages {
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
        padding: 20px !important;
    }

    /* Encabezado de impresión */
    .chat-messages::before {
        content: "Conversación exportada — Sesión " attr(data-session-id);
        display: block;
        font-size: 9pt;
        color: #888;
        border-bottom: 1px solid #ddd;
        padding-bottom: 8px;
        margin-bottom: 16px;
    }

    /* Flujo libre — el contenido se corta naturalmente entre páginas */

    /* Quitar gradiente del fondo del user-message para que imprima bien */
    .user-message .message-text {
        background: #e8ecff !important;
        color: #1a1a2e !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* Forzar que los colores de fondo se impriman */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Plots: uno por fila, ancho completo, nunca cortados entre páginas */
    .message-text img,
    .pdf-image-thumbnail {
        display: block !important;
        width: 100% !important;
        max-height: 85vh !important;
        height: auto !important;
        margin: 12px 0 !important;
        page-break-inside: avoid;
        break-inside: avoid;
        cursor: default !important;
        border: 1px solid #ccc !important;
        box-shadow: none !important;
    }

    /* Expandir la burbuja del mensaje a ancho completo */
    .message-content {
        max-width: 100% !important;
        width: 100% !important;
    }

    /* El wrapper de cada plot también en bloque, nunca cortado */
    .plot-wrapper {
        display: block !important;
        width: 100% !important;
        page-break-inside: avoid;
        break-inside: avoid;
    }
}