:root {
    --primary: #7e57c2;
    --primary-dark: #673ab7;
    --secondary: #ff5722;
    --bg: #f5f7fb;
    --white: #ffffff;
    --text: #333333;
    --text-light: #6c757d;
    --border: #e0e0e0;
    --user-bg: #7e57c2;
    --bot-bg: #f5f5f5;
    --online: #4caf50;
    --sidebar-width: 280px;
    --radius: 12px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background: var(--bg);
    color: var(--text);
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    padding: 20px;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.logo i {
    font-size: 28px;
}

.logo h1 {
    font-size: 22px;
    font-weight: 600;
}

/* Perfil de usuario */
.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius);
    margin-bottom: 20px;
    transition: all 0.3s;
}

.user-profile:hover {
    background: rgba(255, 255, 255, 0.15);
}

.avatar {
    width: 48px;
    height: 48px;
    min-width: 48px;
    border-radius: 50%;
    background: var(--secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 20px;
    color: white;
    text-transform: uppercase;
}

.user-info {
    flex: 1;
    overflow: hidden;
}

.user-name {
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-status {
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    opacity: 0.8;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--online);
}

.logout-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.3s;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.logout-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

/* Menú */
.menu {
    margin: 20px 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.3s;
    background: rgba(255, 255, 255, 0.05);
}

.menu-item:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateX(5px);
}

.menu-item.active {
    background: rgba(255, 255, 255, 0.2);
    border-left: 3px solid white;
}

.menu-item i {
    width: 24px;
    text-align: center;
}

/* Conversaciones recientes */
.section-title {
    font-size: 12px;
    text-transform: uppercase;
    opacity: 0.7;
    margin: 15px 0 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-conversation-item {
    padding: 10px;
    margin: 5px 0;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-conversation-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.sidebar-conversation-delete {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    display: none;
}

.sidebar-conversation-item:hover .sidebar-conversation-delete {
    display: block;
}

.sidebar-conversation-delete:hover {
    color: #ff4444;
}

.export-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    width: 100%;
    margin-top: 10px;
}

.favorite-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
}

.favorite-btn.active {
    color: #ffc107;
}

/* Guest warning */
.guest-warning {
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius);
    padding: 15px;
    margin-top: auto;
    font-size: 13px;
}

.guest-warning p {
    margin-bottom: 12px;
    line-height: 1.5;
}

.auth-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.auth-btn {
    padding: 10px;
    border-radius: var(--radius);
    border: none;
    background: white;
    color: var(--primary);
    font-weight: 600;
    cursor: pointer;
    text-align: center;
}

.auth-btn:hover {
    background: #f0f0f0;
}

.auth-btn.register {
    background: var(--secondary);
    color: white;
}

.auth-btn.register:hover {
    background: #e64a19;
}

/* Main content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.header {
    padding: 15px 25px;
    background: var(--white);
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--primary);
}

.header-btn {
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    padding: 8px 12px;
    border-radius: var(--radius);
}

.header-btn:hover {
    background: var(--bg);
    color: var(--primary);
}

/* Chat */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Mensajes */
.message {
    max-width: 75%;
    padding: 12px 18px;
    border-radius: 18px;
    animation: fadeIn 0.3s ease;
    line-height: 1.5;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.user-message {
    background: var(--user-bg);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 5px;
}

.bot-message {
    background: var(--bot-bg);
    align-self: flex-start;
    border-bottom-left-radius: 5px;
}

.message-info {
    font-size: 11px;
    color: var(--text-light);
    margin-top: 8px;
    text-align: right;
}

.bot-message .message-info {
    text-align: left;
}

.message strong {
    font-weight: 600;
}

.user-message strong {
    color: white;
}

.bot-message strong {
    color: var(--primary);
}

.message em {
    font-style: italic;
    opacity: 0.9;
}

.message code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}

.message p {
    margin: 8px 0;
}

.message p:first-child {
    margin-top: 0;
}

.message p:last-child {
    margin-bottom: 0;
}

/* Listas en mensajes */
.message ol,
.message ul {
    margin: 10px 0;
    padding-left: 25px;
}

.message li {
    margin: 8px 0;
    line-height: 1.5;
}

.message ol {
    list-style-type: decimal;
}

.message ul {
    list-style-type: disc;
}

/* Gráficas */
.chart-container {
    margin: 15px 0;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 10px;
    border: 1px solid var(--border);
}

.chart-wrapper {
    position: relative;
    height: 250px;
    width: 100%;
}

.response-chart {
    width: 100% !important;
    height: 100% !important;
}

.chart-caption {
    text-align: center;
    margin-top: 10px;
    font-size: 12px;
    color: var(--text-light);
}

/* Sugerencias */
.suggestions-container {
    margin-top: 15px;
    padding: 12px;
    background: rgba(126, 87, 194, 0.05);
    border-radius: 12px;
    border: 1px solid rgba(126, 87, 194, 0.2);
}

.suggestions-title {
    font-size: 13px;
    color: var(--primary);
    margin-bottom: 10px;
    font-weight: 600;
}

.suggestion-btn {
    display: block;
    width: 100%;
    padding: 8px 12px;
    margin: 5px 0;
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
    font-size: 13px;
    transition: all 0.2s;
}

.suggestion-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Typing indicator */
.typing-indicator {
    display: inline-flex;
    background: var(--bot-bg);
    padding: 12px 18px;
    border-radius: 18px;
    border-bottom-left-radius: 5px;
    align-self: flex-start;
    gap: 4px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-light);
    border-radius: 50%;
    animation: typing 1.5s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%,
    100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-5px);
    }
}

/* Input */
.input-area {
    display: flex;
    padding: 15px;
    border-radius: var(--radius);
    background: var(--white);
    box-shadow: var(--shadow);
    gap: 12px;
}

.attach-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px 16px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 16px;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.attach-btn:hover {
    background: var(--primary-dark);
    transform: scale(1.02);
}

#user-input {
    flex: 1;
    padding: 12px 15px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    resize: none;
    font-size: 15px;
    outline: none;
    max-height: 150px;
}

#user-input:focus {
    border-color: var(--primary);
}

#send-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 16px;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

#send-btn:hover {
    background: var(--primary-dark);
    transform: scale(1.02);
}

#send-btn:disabled {
    background: var(--text-light);
    cursor: not-allowed;
    transform: none;
}

/* File badge */
.file-badge {
    background: var(--primary);
    color: white;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    margin: 5px 0;
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.file-badge i {
    cursor: pointer;
    font-size: 12px;
}

.file-badge i:hover {
    color: #ff4444;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.3s;
}

.modal-content {
    background: var(--white);
    margin: 10% auto;
    padding: 30px;
    border-radius: var(--radius);
    width: 90%;
    max-width: 450px;
    position: relative;
    box-shadow: var(--shadow);
    animation: slideIn 0.3s;
}

.modal-content.large {
    max-width: 800px;
}

@keyframes slideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.close {
    position: absolute;
    right: 15px;
    top: 10px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    color: var(--text-light);
}

.close:hover {
    color: var(--text);
}

.modal-title {
    font-size: 24px;
    margin-bottom: 20px;
    color: var(--primary);
    text-align: center;
}

/* Auth form */
#auth-form input {
    width: 100%;
    padding: 12px;
    margin: 10px 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 15px;
    outline: none;
}

#auth-form input:focus {
    border-color: var(--primary);
}

#auth-form button {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    margin-top: 15px;
    font-size: 16px;
    font-weight: 600;
}

#auth-form button:hover {
    background: var(--primary-dark);
}

.auth-message {
    padding: 10px;
    border-radius: var(--radius);
    margin: 10px 0;
    text-align: center;
    display: none;
}

.auth-message.error {
    background: rgba(244, 67, 54, 0.1);
    color: #f44336;
    display: block;
}

.auth-message.success {
    background: rgba(76, 175, 80, 0.1);
    color: #4caf50;
    display: block;
}

/* Historial */
.conversation-item {
    padding: 15px;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 10px;
    cursor: pointer;
}

.conversation-item:hover {
    background: #f5f5f5;
}

.conversation-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
}

.conversation-date {
    font-size: 12px;
    color: #999;
}

.conversation-preview {
    font-size: 14px;
    color: #666;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Botón de modo oscuro */
.theme-toggle {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 50%;
    transition: all 0.3s;
    color: var(--text-light);
}

.theme-toggle:hover {
    background: var(--bg);
    transform: scale(1.1);
}

/* ==================== MODO OSCURO ==================== */
body.dark-mode {
    --bg: #1a1a2e;
    --white: #16213e;
    --text: #eeeeee;
    --text-light: #aaaaaa;
    --border: #2c3e50;
    --bot-bg: #0f3460;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

body.dark-mode .sidebar {
    background: linear-gradient(135deg, #1a1a2e, #0f0f23);
}

body.dark-mode .user-profile {
    background: rgba(255, 255, 255, 0.08);
}

body.dark-mode .menu-item {
    background: rgba(255, 255, 255, 0.05);
}

body.dark-mode .menu-item:hover {
    background: rgba(255, 255, 255, 0.12);
}

body.dark-mode .menu-item.active {
    background: rgba(255, 255, 255, 0.15);
}

body.dark-mode .guest-warning {
    background: rgba(255, 255, 255, 0.08);
}

body.dark-mode .header,
body.dark-mode .chat-messages,
body.dark-mode .input-area,
body.dark-mode .modal-content {
    background: #16213e;
    color: #eeeeee;
}

body.dark-mode .message.bot-message {
    background: #0f3460;
    color: #eeeeee;
}

body.dark-mode .message.user-message {
    background: #7e57c2;
}

body.dark-mode .message-info {
    color: #aaaaaa;
}

body.dark-mode .suggestion-btn {
    background: #0f3460;
    color: #eeeeee;
    border-color: #2c3e50;
}

body.dark-mode .suggestion-btn:hover {
    background: #7e57c2;
}

body.dark-mode #user-input {
    background: #0f3460;
    border-color: #2c3e50;
    color: #eeeeee;
}

body.dark-mode #user-input:focus {
    border-color: #7e57c2;
}

body.dark-mode #send-btn {
    background: #7e57c2;
}

body.dark-mode #send-btn:hover {
    background: #673ab7;
}

body.dark-mode .attach-btn {
    background: #7e57c2;
}

body.dark-mode .attach-btn:hover {
    background: #673ab7;
}

body.dark-mode .conversation-item {
    background: #0f3460;
    border-color: #2c3e50;
    color: #eeeeee;
}

body.dark-mode .conversation-item:hover {
    background: #1a4a7a;
}

body.dark-mode .auth-btn {
    background: #0f3460;
    color: white;
}

body.dark-mode .auth-btn:hover {
    background: #1a4a7a;
}

body.dark-mode .auth-btn.register {
    background: #ff5722;
}

body.dark-mode .close {
    color: #aaaaaa;
}

body.dark-mode .close:hover {
    color: #ffffff;
}

body.dark-mode .section-title {
    color: #aaaaaa;
}

body.dark-mode .sidebar-conversation-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

body.dark-mode .logo h1,
body.dark-mode .logo i,
body.dark-mode .menu-item span,
body.dark-mode .menu-item i,
body.dark-mode .user-name,
body.dark-mode .user-status {
    color: white;
}

body.dark-mode .theme-toggle {
    color: #ffd700;
}

body.dark-mode .theme-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Responsive */
@media (max-width: 768px) {
    body {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        padding: 15px;
    }

    .message {
        max-width: 85%;
    }

    .header-title {
        font-size: 18px;
    }
}

@media (max-width: 480px) {
    .chat-container {
        padding: 10px;
    }

    .chat-messages {
        padding: 12px;
    }

    .message {
        max-width: 90%;
        padding: 10px 14px;
        font-size: 14px;
    }

    .input-area {
        padding: 10px;
    }

    .attach-btn {
        padding: 10px 12px;
    }

    #send-btn {
        padding: 10px 16px;
    }

    .message p + p {
        margin-top: 12px;
    }

    #recent-conversations-container {
        margin-top: 20px;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        padding-top: 10px;
    }

    .section-title {
        font-size: 11px;
        letter-spacing: 1.5px;
        opacity: 0.6;
        margin-bottom: 12px;
    }
}
