/* ── Theme variables ────────────────────────────────────────────────── */
:root {
  --bg: #0f0f0f;
  --sidebar-bg: #1a1a1a;
  --msg-user: #2563eb;
  --msg-ai: #1e1e1e;
  --border: #2a2a2a;
  --text: #e5e5e5;
  --text-muted: #888;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --citation-bg: #1a2332;
  --citation-border: #2a4a6b;
}
[data-theme="light"] {
  --bg: #f5f5f5;
  --sidebar-bg: #ffffff;
  --msg-user: #2563eb;
  --msg-ai: #ffffff;
  --border: #e0e0e0;
  --text: #1a1a1a;
  --text-muted: #666;
  --citation-bg: #e8f0fe;
  --citation-border: #b4d0fe;
}
[data-theme="ocean"] {
  --bg: #0a1929;
  --sidebar-bg: #0d2137;
  --msg-user: #0288d1;
  --msg-ai: #0d2137;
  --border: #1a3a5c;
  --text: #b3d4f0;
  --text-muted: #6b8fa8;
  --accent: #0288d1;
  --accent-hover: #0277bd;
  --citation-bg: #0d2a3f;
  --citation-border: #1a4a6b;
}
[data-theme="forest"] {
  --bg: #0d1f0d;
  --sidebar-bg: #122612;
  --msg-user: #2e7d32;
  --msg-ai: #122612;
  --border: #1f3a1f;
  --text: #c8e6c8;
  --text-muted: #6b9a6b;
  --accent: #4caf50;
  --accent-hover: #388e3c;
  --citation-bg: #0d2a0d;
  --citation-border: #2a5a2a;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; transition: background 0.3s, color 0.3s; }
.app { display: flex; height: 100vh; }
.sidebar { width: 280px; background: var(--sidebar-bg); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; transition: background 0.3s; }
.sidebar-header { padding: 16px; border-bottom: 1px solid var(--border); }
.logo { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.kb-badge { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 12px; background: #1e3a5f; color: #60a5fa; font-weight: 600; }
.new-chat-btn { margin: 12px 16px; padding: 10px; background: transparent; border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 14px; cursor: pointer; transition: background 0.2s; }
.new-chat-btn:hover { background: var(--border); }
.chat-list { flex: 1; overflow-y: auto; padding: 0 8px; }
.chat-item { padding: 10px 12px; border-radius: 8px; font-size: 13px; color: var(--text-muted); cursor: pointer; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: background 0.15s; }
.chat-item:hover, .chat-item.active { background: var(--border); color: var(--text); }
.model-selector { padding: 8px 16px; border-top: 1px solid var(--border); }
.model-selector label { font-size: 11px; color: var(--text-muted); display: block; margin-bottom: 4px; }
.model-selector select { width: 100%; padding: 6px 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 13px; cursor: pointer; font-family: inherit; }
.settings-panel { border-top: 1px solid var(--border); }
.settings-toggle { width: 100%; padding: 12px 16px; background: transparent; border: none; color: var(--text-muted); font-size: 13px; cursor: pointer; text-align: left; transition: background 0.2s; }
.settings-toggle:hover { background: var(--border); }
.settings-content { padding: 12px 16px; display: flex; flex-direction: column; gap: 14px; }
.setting-row label { font-size: 11px; color: var(--text-muted); display: block; margin-bottom: 6px; font-weight: 600; }
.setting-row textarea { width: 100%; padding: 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 13px; resize: vertical; font-family: inherit; }
.theme-options, .accent-options { display: flex; gap: 6px; flex-wrap: wrap; }
.theme-btn { padding: 6px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 12px; cursor: pointer; transition: all 0.2s; }
.theme-btn.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 15%, transparent); }
.accent-btn { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; transition: transform 0.15s; }
.accent-btn:hover { transform: scale(1.15); }
.accent-btn.active { border-color: var(--text); }
.chat-area { flex: 1; display: flex; flex-direction: column; background: var(--bg); }
.chat-header { padding: 14px 24px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.chat-header h2 { font-size: 14px; font-weight: 500; color: var(--text-muted); }
.kb-status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.kb-dot { width: 8px; height: 8px; border-radius: 50%; background: #f59e0b; }
.kb-dot.connected { background: #10b981; }
.kb-dot.error { background: #ef4444; }
.messages { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.welcome-msg { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; height: 100%; gap: 12px; }
.welcome-icon { font-size: 48px; }
.welcome-msg h3 { font-size: 22px; font-weight: 600; }
.welcome-msg p { color: var(--text-muted); font-size: 14px; max-width: 400px; }
.suggestions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; justify-content: center; }
.suggestion-chip { padding: 8px 16px; background: var(--msg-ai); border: 1px solid var(--border); border-radius: 20px; color: var(--text); font-size: 13px; cursor: pointer; transition: all 0.2s; }
.suggestion-chip:hover { border-color: var(--accent); }
.message { max-width: 760px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 6px; }
.message-role { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.message-bubble { padding: 14px 18px; border-radius: 12px; font-size: 15px; line-height: 1.6; white-space: pre-wrap; word-wrap: break-word; }
.message.user .message-bubble { background: var(--msg-user); color: #fff; border-radius: 12px 12px 4px 12px; }
.message.ai .message-bubble { background: var(--msg-ai); border: 1px solid var(--border); border-radius: 12px 12px 12px 4px; }
.citations { max-width: 760px; width: 100%; margin: 0 auto; margin-top: 4px; }
.citations-title { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; font-weight: 600; }
.citation-list { display: flex; flex-direction: column; gap: 6px; }
.citation { display: flex; align-items: flex-start; gap: 8px; padding: 8px 12px; background: var(--citation-bg); border: 1px solid var(--citation-border); border-radius: 8px; font-size: 13px; }
.citation-num { background: var(--citation-border); color: var(--text); border-radius: 50%; width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; flex-shrink: 0; }
.citation-source { font-weight: 600; color: var(--accent); }
.citation-snippet { color: var(--text-muted); margin-top: 2px; }
.citation-score { font-size: 11px; color: #4a7a4a; margin-top: 2px; }
.typing { display: flex; gap: 4px; padding: 14px 18px; }
.typing span { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); animation: bounce 1.4s infinite; }
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-8px); opacity: 1; } }
.input-area { padding: 16px 24px 20px; border-top: 1px solid var(--border); }
.input-form { max-width: 760px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; background: var(--sidebar-bg); border: 1px solid var(--border); border-radius: 12px; padding: 8px; transition: border-color 0.2s; }
.input-form:focus-within { border-color: var(--accent); }
#userInput { flex: 1; background: transparent; border: none; color: var(--text); font-size: 15px; resize: none; outline: none; padding: 8px; max-height: 200px; font-family: inherit; line-height: 1.5; }
.send-btn { background: var(--accent); border: none; border-radius: 8px; width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; cursor: pointer; color: #fff; flex-shrink: 0; transition: background 0.2s; }
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.mobile-menu { display: none; }
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
@media (max-width: 768px) {
  .sidebar { position: fixed; left: -280px; top: 0; height: 100vh; z-index: 100; transition: left 0.3s; }
  .sidebar.open { left: 0; }
  .mobile-menu { display: flex; position: fixed; top: 12px; left: 12px; z-index: 101; background: var(--sidebar-bg); border: 1px solid var(--border); border-radius: 8px; width: 40px; height: 40px; align-items: center; justify-content: center; font-size: 18px; color: var(--text); cursor: pointer; }
  .messages { padding: 16px; padding-top: 60px; }
  .input-area { padding: 12px 16px 16px; }
  .chat-header { padding-left: 60px; }
}
