:root {
    --bg-color: #f8fafc;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(0, 0, 0, 0.05);
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #059669;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* Layout */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.sidebar {
    width: 260px;
    background: #f1f5f9;
    border-right: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1rem;
    flex-shrink: 0;
}

.sidebar-header h2 { margin-bottom: 0.2rem; font-size: 1.25rem; }
.sidebar-header p { color: var(--text-muted); font-size: 0.8rem; margin-bottom: 2rem; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }

.sidebar-nav { display: flex; flex-direction: column; gap: 0.5rem; }
.nav-btn {
    background: transparent; border: none; text-align: left; padding: 0.75rem 1rem;
    border-radius: 0.5rem; cursor: pointer; color: var(--text-muted); font-weight: 500;
    font-size: 0.95rem; font-family: inherit; transition: all 0.2s;
}
.nav-btn:hover { background: #e2e8f0; color: var(--text-main); }
.nav-btn.active { background: #e0e7ff; color: var(--primary-hover); font-weight: 600; }

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    position: relative;
}

.view-panel { display: none; padding: 2rem; max-width: 900px; margin: 0 auto; width: 100%; }
.view-panel.active { display: block; }
#chat-view { display: none; height: 100%; padding: 0; max-width: none; }
#chat-view.active { display: flex; flex-direction: column; }

/* Knowledge View Specifics */
.page-header { margin-bottom: 1rem; }
.page-header h1 { font-size: 1.5rem; font-weight: 600; color: var(--text-main); }
.page-header p { color: var(--text-muted); font-size: 0.9rem; margin-top: 0.2rem; }

/* Knowledge Base UI */
.glass-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.glass-card h2 {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 1rem;
}

.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 0.5rem;
}

.tab-btn {
    background: transparent;
    border: none;
    font-size: 0.9rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.4rem 0.8rem;
    border-radius: 0.25rem;
}

.tab-btn:hover {
    background: #f1f5f9;
}

.tab-btn.active {
    color: var(--text-main);
    font-weight: 600;
    background: #f1f5f9;
}

.tab-content { display: none; }
.tab-content.active { display: flex; flex-direction: column; gap: 0.5rem; }

.tab-content input[type="text"] {
    width: 100%;
    padding: 0.6rem;
    border-radius: 0.25rem;
    border: 1px solid #cbd5e1;
    font-size: 0.9rem;
}

.primary-btn {
    background: #334155;
    color: white;
    border: none;
    padding: 0.6rem 1rem;
    border-radius: 0.25rem;
    font-size: 0.9rem;
    cursor: pointer;
    align-self: flex-start;
}

.primary-btn:hover { background: #1e293b; }
.primary-btn:disabled { background: #cbd5e1; cursor: not-allowed; }

.progress-container {
    margin-top: 1rem;
    padding: 1rem;
    border-radius: 0.25rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
}

.status-text { font-size: 0.85rem; color: var(--text-main); margin-bottom: 0.5rem; }

.progress-bar-bg {
    width: 100%; height: 6px; background: #e2e8f0; border-radius: 3px; overflow: hidden;
}

.progress-bar-fill {
    height: 100%; width: 0%; background: #334155; transition: width 0.3s;
}

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

.stat-badge {
    background: #e2e8f0; color: #334155; padding: 0.2rem 0.6rem; border-radius: 0.25rem; font-size: 0.85rem;
}

.table-container {
    overflow-x: auto; border: 1px solid #e2e8f0; border-radius: 0.25rem; background: #fff;
}

table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.75rem 1rem; text-align: left; border-bottom: 1px solid #e2e8f0; font-size: 0.9rem; }
th { background: #f8fafc; font-weight: 600; color: var(--text-muted); }

/* Chat UI */
.chat-container { flex: 1; display: flex; flex-direction: column; height: 100%; }
.chat-messages {
    flex: 1; overflow-y: auto; padding: 2rem; display: flex; flex-direction: column; gap: 1.5rem; scroll-behavior: smooth;
}

.welcome-msg { margin: auto; text-align: center; color: var(--text-muted); }
.welcome-msg h2 { font-size: 2rem; font-weight: 600; color: var(--text-main); margin-bottom: 0.5rem; }

.message { display: flex; gap: 1rem; max-width: 800px; margin: 0 auto; width: 100%; }
.message.user { flex-direction: row-reverse; }
.message .avatar { width: 36px; height: 36px; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 1.2rem; flex-shrink: 0; }
.message.user .avatar { background: var(--primary); color: white; }
.message.assistant .avatar { background: #10b981; color: white; }

.bubble { padding: 1rem 1.2rem; border-radius: 0.75rem; font-size: 0.95rem; line-height: 1.6; max-width: 85%; }
.message.user .bubble { background: #e0e7ff; color: #1e3a8a; border-bottom-right-radius: 0.25rem; }
.message.assistant .bubble { background: #fff; border: 1px solid #e2e8f0; box-shadow: 0 1px 2px rgba(0,0,0,0.05); border-bottom-left-radius: 0.25rem; }

.chat-input-area { padding: 1.5rem 2rem; background: #fff; border-top: 1px solid #e2e8f0; }

.chat-settings { display: flex; gap: 0.5rem; max-width: 800px; margin: 0 auto 0.5rem auto; align-items: center; flex-wrap: wrap; }
.settings-input { 
    background: #f8fafc; border: 1px solid #cbd5e1; border-radius: 0.5rem; 
    padding: 0.4rem 0.6rem; font-size: 0.8rem; color: var(--text-muted); outline: none; transition: border 0.2s;
}
.settings-input:focus { border-color: var(--primary); color: var(--text-main); }
.context-input { flex: 1; min-width: 200px; }

.rag-toggle {
    display: flex; align-items: center; gap: 0.3rem; font-size: 0.8rem; color: var(--text-muted); cursor: pointer;
    background: #f8fafc; border: 1px solid #cbd5e1; padding: 0.4rem 0.6rem; border-radius: 0.5rem;
}
.rag-toggle input { cursor: pointer; }

.chat-input-wrapper {
    max-width: 800px; margin: 0 auto; display: flex; gap: 1rem; align-items: flex-end;
    background: #fff; border: 1px solid #cbd5e1; border-radius: 0.75rem; padding: 0.5rem 0.5rem 0.5rem 1rem;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05); transition: border-color 0.2s;
}
.chat-input-wrapper:focus-within { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,0.2); }
textarea {
    flex: 1; border: none; resize: none; max-height: 200px; outline: none; padding: 0.5rem 0;
    font-family: inherit; font-size: 0.95rem; color: var(--text-main); min-height: 44px;
}
.send-btn { padding: 0.5rem 1.2rem; align-self: flex-end; margin-bottom: 0.25rem; }

.chat-footer { text-align: center; font-size: 0.75rem; color: var(--text-muted); margin-top: 0.75rem; }

/* Markdown Content */
.bubble p { margin-bottom: 0.75rem; }
.bubble p:last-child { margin-bottom: 0; }
.bubble pre { background: #1e293b; color: #f8fafc; padding: 1rem; border-radius: 0.5rem; overflow-x: auto; margin: 0.75rem 0; font-family: monospace; font-size: 0.85rem; }
.bubble code { font-family: monospace; background: rgba(0,0,0,0.05); padding: 0.2em 0.4em; border-radius: 3px; font-size: 0.9em; }
.bubble pre code { background: none; padding: 0; }
.rag-badge {
    display: inline-flex; align-items: center; gap: 0.4rem; background: #d1fae5; color: #059669;
    padding: 0.3rem 0.6rem; border-radius: 1rem; font-size: 0.75rem; font-weight: 600; margin-top: 0.5rem;
}

/* Mobile Optimization */
@media (max-width: 768px) {
    .app-layout { flex-direction: column; }
    
    .sidebar {
        width: 100%; height: auto; border-right: none; border-bottom: 1px solid #e2e8f0;
        padding: 1rem;
    }
    
    .sidebar-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.5rem; }
    .sidebar-header p { display: none; }
    
    .sidebar-nav { flex-direction: row; flex-wrap: wrap; justify-content: center; }
    .nav-btn { flex: 1; text-align: center; }
    
    .view-panel { padding: 1rem; }
    
    .chat-messages { padding: 1rem; }
    .message { max-width: 100%; }
    .bubble { max-width: 90%; }
    
    .chat-input-area { padding: 1rem; }
    .chat-settings { flex-direction: column; align-items: stretch; }
    .context-input { min-width: 0; }
    #new-chat-btn { margin-left: 0 !important; width: 100%; text-align: center; justify-content: center; }
    
    .chat-input-wrapper { flex-direction: column; align-items: stretch; }
    .send-btn { width: 100%; }
}
