@import url('https://fonts.googleapis.com/css2?family=Söhne:wght@400;500;600&family=Inter:wght@400;500;600&display=swap');

/* Theme Variables */
:root {
    /* Dark Theme (Default) */
    --bg-color: #212121;
    --sidebar-bg: #171717;
    --text-color: #ececec;
    --text-muted: #8e8ea0;
    --border-color: #2f2f2f;
    --user-bubble-bg: #343541;
    --input-bg: #2f2f2f;
    --input-border: #3f3f3f;
    --accent-color: #10a37f;
    --accent-hover: #0d8c6d;
    --agent-math-bg: rgba(16, 163, 127, 0.15);
    --agent-math-border: #10a37f;
    --agent-math-text: #10a37f;
    --agent-rag-bg: rgba(25, 118, 210, 0.15);
    --agent-rag-border: #1976d2;
    --agent-rag-text: #42a5f5;
    --agent-memory-bg: rgba(156, 39, 176, 0.15);
    --agent-memory-border: #9c27b0;
    --agent-memory-text: #ce93d8;
    --agent-general-bg: rgba(245, 124, 0, 0.15);
    --agent-general-border: #f57c00;
    --agent-general-text: #ffb74d;
    --agent-search-bg: rgba(0, 188, 212, 0.15);
    --agent-search-border: #00bcd4;
    --agent-search-text: #80deea;
    --shadow-color: rgba(0, 0, 0, 0.3);
}

.light-theme {
    --bg-color: #ffffff;
    --sidebar-bg: #f9f9f9;
    --text-color: #0d0d0d;
    --text-muted: #888888;
    --border-color: #e5e5e5;
    --user-bubble-bg: #f0f2f6;
    --input-bg: #ffffff;
    --input-border: #e5e5e5;
    --shadow-color: rgba(0, 0, 0, 0.08);
}

/* Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', 'Söhne', -apple-system, system-ui, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    height: 100vh; /* Fallback for older browsers */
    height: 100dvh;
    overflow: hidden;
    transition: background-color 0.3s, color 0.3s;
}
a{
    color: var(--accent-color);
    text-decoration: none;
    transition: color 0.2s;
}
/* Sidebar */
.sidebar {
    width: 260px;
    min-width: 260px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 1rem;
    z-index: 100;
    transition: margin-left 0.3s ease;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar.collapsed {
    margin-left: -260px;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.sidebar-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

#theme-toggle {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: color 0.2s;
}

#theme-toggle:hover {
    color: var(--text-color);
}

.sidebar-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-color);
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    margin-bottom: 0.5rem;
}

.sidebar-btn:hover {
    background: var(--border-color);
}

.sidebar-btn.secondary {
    opacity: 0.6;
}

.sidebar-btn.secondary:not(:disabled):hover {
    opacity: 1;
}

.sidebar-btn:disabled {
    cursor: not-allowed;
    opacity: 0.4;
}

.sidebar-btn i {
    width: 16px;
    height: 16px;
}

.sidebar-stats {
    display: flex;
    gap: 8px;
    margin: 1.5rem 0;
}

.stat-item {
    flex: 1;
    background: var(--border-color);
    padding: 10px;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.stat-value {
    font-size: 1.1rem;
    font-weight: 600;
}

.sidebar-section {
    margin-bottom: 2rem;
}

.section-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.8rem;
    letter-spacing: 0.05em;
}

/* File Upload */
.drop-zone {
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    padding: 1.5rem 1rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}

.drop-zone:hover {
    border-color: var(--accent-color);
    background: rgba(16, 163, 127, 0.05);
}

.drop-zone i {
    width: 32px;
    height: 32px;
    color: var(--text-muted);
}

.drop-zone span {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.browse-btn {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-top: 4px;
    cursor: pointer;
}

/* Clear DB Button */
.upload-actions {
    margin-top: 1rem;
    display: flex;
    justify-content: flex-end;
}

.clear-btn {
    background: transparent;
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.2);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.clear-btn:hover:not(:disabled) {
    background: rgba(239, 68, 68, 0.1);
    border-color: #ef4444;
}

.clear-btn:disabled {
    opacity: 0.5;
    cursor: default;
}

.clear-btn i {
    width: 14px;
    height: 14px;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.spin {
    animation: spin 1s linear infinite;
}

.file-list {
    margin-top: 10px;
    max-height: 200px;
    overflow-y: auto;
    padding-right: 5px;
}

.file-list::-webkit-scrollbar {
    width: 4px;
}
.file-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.file-item {
    font-size: 0.8rem;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    color: var(--text-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
    transition: background 0.2s;
}

.file-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.file-info {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow: hidden;
    white-space: nowrap;
}

.file-info i {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    color: var(--accent-color);
}

.file-info span {
    overflow: hidden;
    text-overflow: ellipsis;
}

.delete-file-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.delete-file-btn:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

.delete-file-btn i {
    width: 14px;
    height: 14px;
}

.empty-list {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    padding: 1rem 0;
    font-style: italic;
}

/* Agent Legend */
.agent-legend {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.agent-item {
    font-size: 0.82rem;
    font-weight: 500;
    padding: 3px 0 3px 8px;
    border-left: 3px solid transparent;
}

.math-agent { border-color: var(--agent-math-border); color: var(--agent-math-text); }
.rag-agent { border-color: var(--agent-rag-border); color: var(--agent-rag-text); }
.memory-agent { border-color: var(--agent-memory-border); color: var(--agent-memory-text); }
.general-agent { border-color: var(--agent-general-border); color: var(--agent-general-text); }
.search-agent { border-color: var(--agent-search-border); color: var(--agent-search-text); }

/* Main Chat Area */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    max-width: 100%;
}

/* Desktop Sidebar Toggle */
.desktop-sidebar-toggle {
    position: absolute;
    top: 12px;
    left: 12px;
    background: var(--sidebar-bg); /* Use sidebar bg to stand out */
    border: 1px solid var(--border-color);
    color: var(--text-color);
    cursor: pointer;
    z-index: 200; /* Higher than sidebar */
    width: 40px;
    height: 40px;
    border-radius: 8px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.desktop-sidebar-toggle:hover {
    background: var(--input-bg);
    border-color: var(--accent-color);
    transform: scale(1.05);
}

.welcome-screen {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    pointer-events: none;
    transition: opacity 0.4s ease, visibility 0.4s;
}

.welcome-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    transform: translateY(-80px);
}

.welcome-avatar {
    width: 110px;
    height: 110px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 15px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.welcome-name {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 8px;
    font-family: 'Outfit', sans-serif;
}

.welcome-screen h1 {
    font-size: 2.2rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    opacity: 0.9;
    font-family: 'Outfit', sans-serif;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 4rem 2rem 10rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
}

/* Input Container */
.input-container-wrapper {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0 2rem 2.5rem 2rem;
    background: linear-gradient(to top, var(--bg-color) 70%, transparent);
    z-index: 20;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.input-container-wrapper.welcome-mode {
    top: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    transform: translateY(20px);
}

.chat-input-container {
    max-width: 768px;
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 1.5rem;
    display: flex;
    margin:auto;
    margin-bottom: 40px;
    align-items: flex-end;
    padding: 10px 14px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.dark-theme .chat-input-container {
    box-shadow: 0 0 0 1px rgba(255,255,255,0.05);
}

.chat-input-container:focus-within {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.15);
}

.chat-input-container textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-color);
    font-size: 1rem;
    resize: none;
    padding: 10px 4px;
    max-height: 200px;
}

.chat-input-container textarea:focus {
    outline: none;
}

#send-btn {
    background: var(--accent-color);
    color: white;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 4px;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
}

#send-btn:disabled {
    opacity: 0.2;
    cursor: default;
    background: var(--text-muted);
}

#send-btn:not(:disabled):hover {
    background: var(--accent-hover);
}

/* Chat Messages */
.message {
    display: flex;
    gap: 1.2rem;
    max-width: 100%;
    animation: fadeIn 0.3s ease;
}

.message.user {
    flex-direction: row-reverse;
}

.avatar {
    min-width: 40px;
    width: auto;
    height: 40px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 4px;
    font-weight: 600;
    font-size: 0.8rem;
    padding: 0 10px;
    white-space: nowrap;
    letter-spacing: 0.01em;
    overflow: hidden;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.user .avatar {
    background: #5436da;
    color: white;
}

.assistant .avatar {
    background: transparent;
    padding: 0;
    width: 40px;
    min-width: 40px;
}
.message-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.user .message-content {
    align-items: flex-end;
}

.bubble {
    padding: 10px 16px;
    border-radius: 18px;
    font-size: 1rem;
    line-height: 1.6;
    max-width: 85%;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.bubble a {
    word-break: break-all;
}

.user .bubble {
    background: var(--user-bubble-bg);
    border-radius: 18px 18px 2px 18px;
    color: var(--text-color);
    box-shadow: 0 4px 12px var(--shadow-color);
}

.assistant .bubble {
    background: transparent;
    color: var(--text-color);
}

.message-meta {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 6px;
    display: flex;
    gap: 10px;
}

.agent-badge-inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 20px;
    margin-bottom: 8px;
    letter-spacing: 0.03em;
}

/* Agent Badge Colors */
.badge-math { background: var(--agent-math-bg); border: 1px solid var(--agent-math-border); color: var(--agent-math-text); }
.badge-rag  { background: var(--agent-rag-bg); border: 1px solid var(--agent-rag-border); color: var(--agent-rag-text); }
.badge-memory { background: var(--agent-memory-bg); border: 1px solid var(--agent-memory-border); color: var(--agent-memory-text); }
.badge-general { background: var(--agent-general-bg); border: 1px solid var(--agent-general-border); color: var(--agent-general-text); }
.badge-search  { background: var(--agent-search-bg); border: 1px solid var(--agent-search-border); color: var(--agent-search-text); }

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

/* Typing Indicator (Skeleton) */
.typing-bubble {
    display: flex;
    gap: 4px;
    padding: 10px 0;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Markdown Styling */
.bubble p { margin-bottom: 0.8rem; }
.bubble p:last-child { margin-bottom: 0; }
.bubble code {
    background: var(--bg-color);
    padding: 2px 4px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}
.bubble pre {
    background: #0d0d0d;
    color: #e6edf3;
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 1rem 0;
}
.bubble pre code {
    background: transparent;
    padding: 0;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Mobile Header & Overlay (Hidden by default on Desktop) */
.mobile-header {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--bg-color);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 50;
}

.mobile-title {
    font-weight: 600;
    font-size: 1.1rem;
    flex: 1;
    text-align: center;
    padding-right: 32px; /* balance out the left hamburger menu width to center perfectly */
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 90;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    body {
        flex-direction: column;
    }

    .desktop-sidebar-toggle {
        display: none;
    }

    .mobile-header {
        display: flex;
    }

    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        bottom: 0;
        width: 280px;
        z-index: 100;
        box-shadow: 2px 0 10px rgba(0,0,0,0.5);
    }

    .sidebar.open {
        transform: translateX(280px);
    }
    .message-content {
        flex: 1;
        display: flex;
        max-width: 350px;
        flex-direction: column;
        align-items: flex-start; /* Align all messages to left on mobile for better readability */
    }
   .assistant-bubble {
    display: flex
    max-width: 350px;
    

    }
    .chat-container {
        width: 100%;
        height: calc(100vh - 55px); /* Fallback */
        height: calc(100dvh - 55px); /* Subtract mobile header height natively */
    }

    .welcome-content {
        transform: translateY(-40px);
    }

    .welcome-avatar {
        width: 85px;
        height: 85px;
    }

    .welcome-screen h1 {
        font-size: 1.8rem;
        text-align: center;
        padding: 0 20px;
    }

    .chat-messages {
        padding: 1.5rem 1rem 8rem 1rem;
        gap: 1.5rem;
    }

    .message {
        gap: 0.8rem;
    }

    .avatar {
        width: 32px;
        min-width: 32px;
        height: 32px;
        font-size: 0.7rem;
    }

    .assistant .avatar {
        width: 32px;
        min-width: 32px;
    }

    .bubble {
        padding: 8px 14px;
        font-size: 0.95rem;
        max-width: 90%;
    }

    .input-container-wrapper {
        padding: 0 1rem 1.5rem 1rem;
    }

    .chat-input-container {
        padding: 8px 10px;
        border-radius: 1.2rem;
        margin-bottom: 25px;
    }

    .chat-input-container textarea {
        font-size: 0.95rem;
    }
}
