/* ============================================
   GangDan - Styles with Theme Support
   ============================================ */

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

/* ============================================
   Theme Variables
   ============================================ */

/* Dark Theme (Default) */
[data-theme="dark"] {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #16213e;
    --bg-card: rgba(255, 255, 255, 0.04);
    --bg-card-hover: rgba(255, 255, 255, 0.08);
    --bg-input: rgba(255, 255, 255, 0.04);
    
    --text-primary: #e0e0e0;
    --text-secondary: #90a4ae;
    --text-muted: #6b7280;
    
    --accent: #4fc3f7;
    --accent-hover: #29b6f6;
    --accent-soft: rgba(79, 195, 247, 0.1);
    --accent-border: rgba(79, 195, 247, 0.2);
    
    --success: #66bb6a;
    --success-soft: rgba(102, 187, 106, 0.1);
    --danger: #ef5350;
    --warning: #ff9800;
    
    --border: rgba(255, 255, 255, 0.1);
    --border-accent: rgba(79, 195, 247, 0.3);
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    
    --code-bg: rgba(0, 0, 0, 0.4);
    --code-block-bg: #0a0a0a;
    --terminal-bg: #0d0d0d;
    --terminal-input-bg: #080808;
    
    --scrollbar-track: rgba(0, 0, 0, 0.2);
    --scrollbar-thumb: rgba(79, 195, 247, 0.3);
    --scrollbar-thumb-hover: rgba(79, 195, 247, 0.5);
}

/* Light Theme */
[data-theme="light"] {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --bg-card: rgba(0, 0, 0, 0.02);
    --bg-card-hover: rgba(0, 0, 0, 0.05);
    --bg-input: #ffffff;
    
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    
    --accent: #0ea5e9;
    --accent-hover: #0284c7;
    --accent-soft: rgba(14, 165, 233, 0.1);
    --accent-border: rgba(14, 165, 233, 0.3);
    
    --success: #22c55e;
    --success-soft: rgba(34, 197, 94, 0.1);
    --danger: #ef4444;
    --warning: #f59e0b;
    
    --border: rgba(0, 0, 0, 0.08);
    --border-accent: rgba(14, 165, 233, 0.3);
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    
    --code-bg: #f1f5f9;
    --code-block-bg: #e2e8f0;
    --terminal-bg: #1e293b;
    --terminal-input-bg: #0f172a;
    
    --scrollbar-track: rgba(0, 0, 0, 0.05);
    --scrollbar-thumb: rgba(14, 165, 233, 0.3);
    --scrollbar-thumb-hover: rgba(14, 165, 233, 0.5);
}

/* Default to dark theme */
:root {
    color-scheme: dark;
}

[data-theme="light"] {
    color-scheme: light;
}

/* ============================================
   Base Styles
   ============================================ */

body { 
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
}

[data-theme="dark"] body {
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 50%, var(--bg-tertiary) 100%);
}

.container { max-width: 1400px; margin: 0 auto; padding: 15px 20px; }

/* ============================================
   Header
   ============================================ */

.header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 20px; background: var(--bg-card);
    border-radius: 12px; margin-bottom: 15px;
    backdrop-filter: blur(10px); border: 1px solid var(--border);
}
.header h1 { font-size: 1.4em; color: var(--accent); font-weight: 600; }
.header p { color: var(--text-secondary); font-size: 0.85em; margin-top: 2px; }

/* Theme Toggle Button */
.theme-toggle {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 1.1em;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.theme-toggle:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent);
}
.theme-toggle .theme-icon { transition: transform 0.3s; }
.theme-toggle:hover .theme-icon { transform: scale(1.1); }

/* Show/hide icons based on theme */
[data-theme="dark"] .theme-icon-light { display: none; }
[data-theme="light"] .theme-icon-dark { display: none; }

.lang-select {
    padding: 6px 12px; border-radius: 6px; border: 1px solid var(--accent);
    background: transparent; color: var(--accent); cursor: pointer;
    font-size: 0.9em; transition: all 0.2s;
}
.lang-select:hover { background: var(--accent-soft); }

/* ============================================
   Tabs
   ============================================ */

.tabs { display: flex; gap: 8px; margin-bottom: 15px; flex-wrap: wrap; }
.tab {
    padding: 10px 20px; border-radius: 8px; border: none;
    background: var(--bg-card); color: var(--text-primary);
    cursor: pointer; transition: all 0.2s; font-size: 0.9em;
    border: 1px solid transparent;
}
.tab:hover { background: var(--bg-card-hover); border-color: var(--border); }
.tab.active { background: var(--accent); color: #0f0f1a; font-weight: 500; }
[data-theme="light"] .tab.active { color: #ffffff; }

.tab-divider {
    width: 1px; height: 24px;
    background: var(--border); align-self: center;
    margin: 0 4px;
}
.tab.tab-learning {
    padding: 8px 14px; font-size: 0.84em;
}

/* ============================================
   Panels
   ============================================ */

.panel { display: none; animation: fadeIn 0.3s ease; }
.panel.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ============================================
   Chat Container
   ============================================ */

.chat-container {
    background: var(--bg-card); border-radius: 12px;
    padding: 15px; height: calc(100vh - 200px); min-height: 500px;
    display: flex; flex-direction: column;
    border: 1px solid var(--border);
}

.chat-messages {
    flex: 1; overflow-y: auto; padding: 10px;
    display: flex; flex-direction: column; gap: 12px;
    scroll-behavior: smooth;
}

.message { padding: 10px 14px; border-radius: 12px; max-width: 85%; }
.message.user { 
    background: var(--accent); color: #0f0f1a; 
    align-self: flex-end; margin-left: auto;
}
[data-theme="light"] .message.user { color: #ffffff; }

.message.assistant { 
    background: var(--bg-card-hover); 
    align-self: flex-start;
}
.message pre { 
    background: var(--code-bg); padding: 10px; 
    border-radius: 6px; overflow-x: auto; margin: 8px 0;
    font-size: 0.9em;
}
.message code { font-family: 'Fira Code', 'Consolas', monospace; font-size: 0.9em; }

/* ============================================
   Code Blocks
   ============================================ */

.code-block { position: relative; margin: 8px 0; }
.code-block-header {
    display: flex; justify-content: space-between; align-items: center;
    background: var(--code-block-bg); padding: 4px 10px;
    border-radius: 6px 6px 0 0; font-size: 0.8em;
}
.code-block-header .lang { color: var(--accent); font-weight: 500; }
.code-block-header .actions { display: flex; gap: 4px; }
.code-block-header button {
    padding: 2px 8px; font-size: 0.75em; border: none; border-radius: 3px; cursor: pointer;
}
.code-block-header .btn-run { background: var(--success); color: white; }
.code-block-header .btn-copy { background: rgba(255,255,255,0.2); color: var(--text-primary); }
[data-theme="light"] .code-block-header .btn-copy { background: rgba(0,0,0,0.1); color: var(--text-primary); }
.code-block pre { margin: 0; border-radius: 0 0 6px 6px; }

.code-output {
    background: var(--code-block-bg); border: 1px solid #333; border-radius: 0 0 6px 6px;
    padding: 8px; margin-top: -1px; font-family: monospace; font-size: 0.85em;
    max-height: 200px; overflow: auto; white-space: pre-wrap;
}
.code-output.error { border-color: var(--danger); color: var(--danger); }
.code-output.success { border-color: var(--success); }

/* ============================================
   Markdown Tables
   ============================================ */

.message table, .ai-message-content table {
    border-collapse: collapse; margin: 8px 0; width: 100%;
    background: var(--bg-card); border-radius: 6px; overflow: hidden;
    font-size: 0.9em;
}
.message th, .message td, .ai-message-content th, .ai-message-content td {
    border: 1px solid var(--border); padding: 6px 10px; text-align: left;
}
.message th, .ai-message-content th {
    background: var(--accent-soft); color: var(--accent); font-weight: 500;
}

/* ============================================
   Math & Blockquotes
   ============================================ */

.math-block { display: block; padding: 10px; margin: 8px 0; background: var(--bg-card-hover); border-radius: 6px; text-align: center; }
.message blockquote, .ai-message-content blockquote {
    border-left: 3px solid var(--accent); padding-left: 12px;
    margin: 8px 0; color: var(--text-secondary); font-style: italic;
}

/* ============================================
   Chat Input
   ============================================ */

.chat-input-area { display: flex; gap: 8px; margin-top: 12px; align-items: flex-end; flex-wrap: wrap; }
.chat-input {
    flex: 1; padding: 10px; border-radius: 8px; border: 1px solid var(--border);
    background: var(--bg-input); color: var(--text-primary);
    resize: none; min-height: 44px; font-size: 0.95em;
    transition: border-color 0.2s; min-width: 200px;
}
.chat-input:focus { border-color: var(--accent); outline: none; }
.chat-options { display: flex; gap: 15px; margin-bottom: 8px; font-size: 0.9em; flex-wrap: wrap; align-items: center; }
.chat-options label { display: flex; align-items: center; gap: 5px; cursor: pointer; color: var(--text-secondary); }
.chat-options input:checked + span { color: var(--accent); }

/* ============================================
   Buttons
   ============================================ */

.btn {
    padding: 8px 16px; border-radius: 6px; border: none;
    cursor: pointer; transition: all 0.2s; font-weight: 500; font-size: 0.9em;
}
.btn-primary { background: var(--accent); color: #0f0f1a; }
[data-theme="light"] .btn-primary { color: #ffffff; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-danger { background: var(--danger); color: white; }
.btn-secondary { background: var(--bg-card-hover); color: var(--text-primary); }
.btn-secondary:hover { background: var(--bg-card-hover); }
[data-theme="light"] .btn-secondary { background: var(--bg-tertiary); }
.btn-sm { padding: 5px 10px; font-size: 0.8em; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============================================
   Settings & Docs
   ============================================ */

.settings-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 15px;
}
.settings-card {
    background: var(--bg-card); border-radius: 10px; padding: 16px;
    border: 1px solid var(--border); transition: all 0.2s;
}
.settings-card:hover { border-color: var(--border-accent); }
.settings-card h3 { color: var(--accent); margin-bottom: 12px; font-size: 1em; font-weight: 500; }
.settings-card.highlight { background: var(--accent-soft); border-color: var(--border-accent); }

.form-group { margin-bottom: 12px; }
.form-group label { display: block; margin-bottom: 4px; color: var(--text-secondary); font-size: 0.85em; }
.form-group select, .form-group input {
    width: 100%; padding: 8px 10px; border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-input); color: var(--text-primary); font-size: 0.9em;
    transition: border-color 0.2s;
}
.form-group select:focus, .form-group input:focus { border-color: var(--accent); outline: none; }
[data-theme="light"] .form-group select { background: var(--bg-secondary); }
.form-group select option { background: var(--bg-secondary); color: var(--text-primary); }

/* ============================================
   Docs List
   ============================================ */

.docs-list { display: flex; flex-direction: column; gap: 6px; max-height: 200px; overflow-y: auto; }
.doc-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 10px; background: var(--bg-card-hover); border-radius: 6px; font-size: 0.9em;
}
.doc-item .name { font-weight: 500; }
.doc-item .status { color: var(--text-secondary); font-size: 0.8em; }

/* ============================================
   Batch Sources
   ============================================ */

.batch-sources {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 4px; max-height: 180px; overflow-y: auto; padding: 5px;
    background: var(--bg-card-hover); border-radius: 6px;
}
.batch-sources label {
    display: flex; align-items: center; gap: 5px; padding: 4px 6px;
    cursor: pointer; font-size: 0.85em; border-radius: 4px;
    transition: background 0.2s;
}
.batch-sources label:hover { background: var(--bg-card-hover); }

/* ============================================
   Status Indicator
   ============================================ */

.status-dot { 
    width: 8px; height: 8px; border-radius: 50%; 
    display: inline-block; margin-right: 6px;
}
.status-dot.online { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-dot.offline { background: var(--danger); }

/* ============================================
   Loading
   ============================================ */

.loading { display: inline-block; }
.loading::after {
    content: ''; display: inline-block; width: 14px; height: 14px;
    border: 2px solid var(--accent); border-radius: 50%;
    border-top-color: transparent; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================
   Toast
   ============================================ */

.toast {
    position: fixed; bottom: 20px; right: 20px; padding: 12px 20px;
    border-radius: 8px; background: #323232; color: white;
    transform: translateY(100px); opacity: 0; transition: all 0.3s;
    font-size: 0.9em; box-shadow: var(--shadow); z-index: 10000;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* ============================================
   Terminal Panel
   ============================================ */

.terminal-panel-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 15px;
    height: calc(100vh - 200px); min-height: 450px;
}
.terminal-container {
    background: var(--terminal-bg); border-radius: 10px;
    padding: 12px; display: flex; flex-direction: column;
    border: 1px solid var(--border);
}
.terminal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding-bottom: 8px; border-bottom: 1px solid var(--border); margin-bottom: 8px;
}
.terminal-header h4 { font-size: 0.95em; font-weight: 500; }
.terminal-output {
    flex: 1; overflow-y: auto; font-family: 'Fira Code', monospace;
    font-size: 0.85em; white-space: pre-wrap; padding: 8px;
    background: var(--terminal-input-bg); border-radius: 6px; margin-bottom: 8px;
    color: var(--text-primary);
}
.terminal-output .cmd { color: var(--accent); display: block; }
.terminal-output .stdout { color: var(--text-primary); }
.terminal-output .stderr { color: var(--danger); }
.terminal-input-area { display: flex; gap: 6px; align-items: center; }
.terminal-input {
    flex: 1; padding: 8px 10px; border-radius: 6px; border: 1px solid #333;
    background: var(--terminal-input-bg); color: var(--accent); font-family: 'Fira Code', monospace;
    font-size: 0.9em; transition: all 0.2s;
}
.terminal-input:focus { border-color: var(--accent); outline: none; }
.terminal-input.drag-over { border-color: var(--success); box-shadow: 0 0 10px rgba(102,187,106,0.4); }
.terminal-prompt { color: var(--success); font-size: 0.9em; }

/* ============================================
   AI Chat Messages
   ============================================ */

.ai-chat-messages {
    flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px;
    padding: 8px; background: var(--terminal-input-bg); border-radius: 6px; margin-bottom: 8px;
}
.ai-message {
    padding: 10px 12px; border-radius: 10px; max-width: 98%;
    animation: slideIn 0.2s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateY(5px); } }
.ai-message.user {
    background: var(--accent); color: #0f0f1a;
    align-self: flex-end; margin-left: auto; font-size: 0.9em;
}
[data-theme="light"] .ai-message.user { color: #ffffff; }
.ai-message.assistant {
    background: var(--bg-card-hover); align-self: flex-start;
}
.ai-message.system {
    background: var(--accent-soft); color: var(--text-secondary);
    font-size: 0.85em; border: 1px dashed var(--accent-border);
}
.ai-message-content { line-height: 1.6; font-size: 0.9em; }
.ai-message-content p { margin: 6px 0; }
.ai-message-content ul, .ai-message-content ol { margin: 6px 0; padding-left: 20px; }
.ai-message-content li { margin: 3px 0; }
.ai-message-content h1, .ai-message-content h2, .ai-message-content h3, 
.ai-message-content h4, .ai-message-content h5, .ai-message-content h6 {
    color: var(--accent); margin: 12px 0 6px 0; font-weight: 600;
}
.ai-message-content h1 { font-size: 1.3em; }
.ai-message-content h2 { font-size: 1.2em; }
.ai-message-content h3 { font-size: 1.1em; }
.ai-message-content h4, .ai-message-content h5, .ai-message-content h6 { font-size: 1em; }
.ai-message-content strong { color: var(--accent); font-weight: 600; }
.ai-message-content em { font-style: italic; }
.ai-message-content code:not(pre code) { 
    background: var(--accent-soft); padding: 2px 6px; 
    border-radius: 4px; font-family: 'Fira Code', monospace; font-size: 0.9em;
    color: var(--accent);
}
.ai-message-content a { color: var(--accent); text-decoration: underline; }
.ai-message-content hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

/* Code blocks in AI message */
.ai-message-content .code-block { position: relative; margin: 8px 0; }
.ai-message-content .code-block-header {
    display: flex; justify-content: space-between; align-items: center;
    background: var(--code-block-bg); padding: 4px 10px;
    border-radius: 6px 6px 0 0; font-size: 0.8em;
}
.ai-message-content .code-block-header .lang { color: var(--accent); font-weight: 500; }
.ai-message-content .code-block-header .actions { display: flex; gap: 4px; }
.ai-message-content .code-block-header button {
    padding: 2px 8px; font-size: 0.75em; border: none; border-radius: 3px; cursor: pointer;
}
.ai-message-content .code-block-header .btn-run { background: var(--success); color: white; }
.ai-message-content .code-block-header .btn-copy { background: rgba(255,255,255,0.2); color: var(--text-primary); }
[data-theme="light"] .ai-message-content .code-block-header .btn-copy { background: rgba(0,0,0,0.1); }
.ai-message-content .code-block pre {
    margin: 0; padding: 10px; border-radius: 0 0 6px 6px;
    background: var(--code-bg); overflow-x: auto;
}
.ai-message-content .code-block pre code {
    font-family: 'Fira Code', monospace; font-size: 0.9em;
    background: none; padding: 0; color: var(--text-primary);
}
.ai-message-content > pre, .ai-message-content > div > pre:not(.code-block pre) { 
    background: var(--code-bg); padding: 10px; 
    border-radius: 6px; overflow-x: auto; margin: 8px 0;
}
.ai-message-content .code-output {
    background: var(--code-block-bg); border: 1px solid #333; border-radius: 0 0 6px 6px;
    padding: 8px; margin-top: -1px; font-family: monospace; font-size: 0.85em;
    max-height: 150px; overflow: auto; white-space: pre-wrap;
}
.ai-message-content .code-output.error { border-color: var(--danger); color: var(--danger); }
.ai-message-content .code-output.success { border-color: var(--success); }

/* Math in AI message */
.ai-message-content .math-block {
    display: block; padding: 10px; margin: 8px 0;
    background: var(--bg-card-hover); border-radius: 6px;
    overflow-x: auto; text-align: center;
}
.ai-message-content .math-inline { padding: 0 3px; }
.ai-message-content .katex { font-size: 1.1em; }

/* ============================================
   Collapsible Content
   ============================================ */

.collapsible-content {
    position: relative; overflow: hidden;
    transition: max-height 0.3s ease;
}
.collapsible-content.collapsed { max-height: 120px; }
[data-theme="dark"] .collapsible-content.collapsed::after {
    content: ''; position: absolute; bottom: 0; left: 0; right: 0;
    height: 40px; background: linear-gradient(transparent, rgba(8,8,8,0.95));
    pointer-events: none;
}
[data-theme="light"] .collapsible-content.collapsed::after {
    content: ''; position: absolute; bottom: 0; left: 0; right: 0;
    height: 40px; background: linear-gradient(transparent, rgba(248,250,252,0.95));
    pointer-events: none;
}
.collapse-toggle {
    display: block; width: 100%; padding: 6px; margin-top: 4px;
    background: var(--accent-soft); border: 1px dashed var(--accent-border);
    border-radius: 4px; color: var(--accent); cursor: pointer;
    font-size: 0.8em; text-align: center; transition: all 0.2s;
}
.collapse-toggle:hover { background: var(--accent-soft); }

/* ============================================
   Command Execution Box
   ============================================ */

.ai-exec-command {
    background: var(--success-soft); border: 1px solid rgba(102,187,106,0.3);
    border-radius: 8px; padding: 10px; margin: 8px 0;
}
.ai-exec-command .cmd-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 6px; color: var(--success); font-size: 0.8em;
}
.ai-exec-command .cmd-code {
    background: var(--code-bg); padding: 8px; border-radius: 5px;
    font-family: 'Fira Code', monospace; font-size: 0.9em; cursor: grab;
}
.ai-exec-command .cmd-code:active { cursor: grabbing; }
.ai-exec-command .cmd-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.ai-exec-command .cmd-actions button {
    padding: 5px 12px; border: none; border-radius: 4px;
    cursor: pointer; font-size: 0.8em; transition: all 0.2s;
}
.ai-exec-command .btn-run-cmd { background: var(--success); color: #0f0f1a; }
[data-theme="light"] .ai-exec-command .btn-run-cmd { color: #ffffff; }
.ai-exec-command .btn-copy-cmd { background: rgba(255,255,255,0.1); color: var(--text-primary); }
[data-theme="light"] .ai-exec-command .btn-copy-cmd { background: rgba(0,0,0,0.1); }
.ai-exec-command .btn-auto-exec { background: var(--warning); color: #0f0f1a; }

/* Execution Result */
.ai-exec-result {
    background: var(--bg-card-hover); border-radius: 6px; padding: 10px;
    margin: 6px 0; border-left: 3px solid var(--success); font-size: 0.85em;
}
.ai-exec-result.error { border-left-color: var(--danger); }
.ai-exec-result .result-header { font-size: 0.8em; color: var(--text-secondary); margin-bottom: 6px; }
.ai-exec-result pre {
    background: var(--bg-card-hover); padding: 8px; border-radius: 4px;
    max-height: 150px; overflow: auto; white-space: pre-wrap; font-size: 0.85em;
}

/* ============================================
   Scrollbar Styling
   ============================================ */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); border-radius: 3px; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }

/* ============================================
   KB Scope Selector Dropdown
   ============================================ */

.kb-selector-wrapper { position: relative; display: inline-block; vertical-align: middle; }
.kb-dropdown-toggle {
    background: var(--bg-card); border: 1px solid var(--border);
    color: var(--text-primary); padding: 4px 10px; border-radius: 6px;
    cursor: pointer; font-size: 0.85em; white-space: nowrap;
}
.kb-dropdown-toggle:hover { border-color: var(--accent); }
.kb-dropdown-menu {
    display: none; position: absolute; top: calc(100% + 4px); left: 0; z-index: 100;
    background: var(--bg-secondary); border: 1px solid var(--border);
    border-radius: 8px; padding: 8px; min-width: 280px; max-height: 340px;
    box-shadow: var(--shadow);
}
.kb-dropdown-menu.open { display: block; }
.kb-dropdown-header {
    display: flex; gap: 6px; margin-bottom: 6px; padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}
.kb-dropdown-list {
    overflow-y: auto; max-height: 270px; display: flex;
    flex-direction: column; gap: 2px;
}
.kb-dropdown-item {
    display: flex; align-items: center; gap: 6px; padding: 5px 6px;
    border-radius: 4px; cursor: pointer; font-size: 0.85em; color: var(--text-primary);
}
.kb-dropdown-item:hover { background: var(--bg-card-hover); }
.kb-dropdown-item input[type="checkbox"] { accent-color: var(--accent); }
.kb-type-badge {
    font-size: 0.7em; padding: 1px 6px; border-radius: 3px; margin-left: auto;
    white-space: nowrap;
}
.kb-type-badge.builtin { background: var(--accent-soft); color: var(--accent); }
.kb-type-badge.user { background: var(--success-soft); color: var(--success); }

/* ============================================
   File Upload Input
   ============================================ */

.file-input {
    width: 100%; padding: 8px; border-radius: 6px;
    border: 1px solid var(--border); background: var(--bg-input);
    color: var(--text-primary); font-size: 0.85em;
}
.file-input::file-selector-button {
    background: var(--accent); color: #0f0f1a; border: none;
    padding: 4px 10px; border-radius: 4px; cursor: pointer;
    font-size: 0.85em; font-weight: 500; margin-right: 8px;
}
[data-theme="light"] .file-input::file-selector-button { color: #ffffff; }
.file-input::file-selector-button:hover { background: var(--accent-hover); }

/* ============================================
   Image Gallery Styles
   ============================================ */

.gallery-container {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 20px;
    min-height: 400px;
}

.gallery-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 10px;
}

.gallery-controls {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.gallery-stats {
    padding: 10px;
    background: var(--bg-secondary);
    border-radius: 6px;
    font-size: 0.9em;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 15px;
    margin-top: 15px;
}

.image-card {
    background: var(--bg-secondary);
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.image-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.image-card img {
    width: 100%;
    height: 150px;
    object-fit: cover;
}

.image-card p {
    margin: 0;
    padding: 10px;
}

.image-card p:first-child {
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.image-card p:last-child {
    font-size: 0.75em;
    color: var(--text-secondary);
}

.gallery-empty {
    text-align: center;
    padding: 50px;
    color: var(--text-secondary);
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
}

.modal-content {
    position: relative;
    background: transparent;
    margin: 2% auto;
    padding: 0;
    width: 90%;
    max-width: 1200px;
    max-height: 90vh;
    overflow: auto;
}

.modal-content img {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    border-radius: 8px;
}

.modal-info {
    background: var(--bg-secondary);
    padding: 15px;
    border-radius: 8px;
    margin-top: 15px;
    width: 100%;
    max-width: 800px;
}

.modal-info p {
    margin: 5px 0;
    color: var(--text-secondary);
}

/* Chat Image References */
.chat-message.images {
    background: var(--accent-soft);
    border-left: 3px solid var(--accent);
}

.chat-image-ref {
    display: inline-block;
    margin: 5px;
    padding: 5px 10px;
    background: var(--bg-secondary);
    border-radius: 4px;
    font-size: 0.85em;
    cursor: pointer;
}

.chat-image-ref:hover {
    background: var(--bg-card-hover);
}

/* ============================================
   Modal Backdrop (KB Manager)
   ============================================ */

.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow-y: auto;
    padding: 20px;
}

.kb-manager-modal {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 20px;
    max-width: 800px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    border: 1px solid var(--border);
}

.kb-manager-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    margin: 8px 0;
    background: var(--bg-card);
    border-radius: 8px;
    flex-wrap: wrap;
    gap: 10px;
}

.kb-file-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    margin: 4px 0;
    background: var(--bg-card);
    border-radius: 6px;
}