/* ═══════════════════════════════════════════════════════════════════
   RAG System — UI Styles
   Design system: UI_V4_1  (white cards, hairline borders, #1a73e8)
   Layout: 3-column  sidebar | chat | knowledge-panel
   ═══════════════════════════════════════════════════════════════════ */

:root {
  --bg:            #f5f5f7;
  --surface:       #ffffff;
  --border:        #dde1e7;
  --hairline:      #eaecef;
  --text:          #1d1d1f;
  --muted:         #6e7680;
  --accent:        #1a73e8;
  --accent-h:      #1558b0;
  --accent-bg:     #e8f0fe;
  --accent-glow:   rgba(26,115,232,.18);
  --danger:        #d93025;
  --danger-bg:     #fce8e6;
  --success:       #1e8e3e;
  --success-bg:    #e6f4ea;
  --warn:          #f29900;
  --warn-bg:       #fef3e2;
  --user-bubble:   #1a73e8;
  --ai-bubble:     #ffffff;
  --sidebar-w:     280px;
  --kb-w:          300px;
  --radius:        14px;
  --radius-sm:     9px;
  --radius-xs:     6px;
  --shadow-sm:     0 1px 4px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  --shadow:        0 2px 10px rgba(0,0,0,.08), 0 1px 3px rgba(0,0,0,.05);
  --shadow-md:     0 6px 20px rgba(0,0,0,.12), 0 2px 6px rgba(0,0,0,.07);
  --shadow-lift:   0 10px 28px rgba(0,0,0,.14), 0 4px 10px rgba(0,0,0,.08);
  --font:          -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono:     "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
  --ease:          cubic-bezier(.25,.46,.45,.94);
  --ease-spring:   cubic-bezier(.34,1.56,.64,1);
  --transition:    .2s var(--ease);
}

/* ── Reset ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ── Layout shell ────────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ═══════════════════════════════════════════════════════════════════
   SIDEBAR — Chat history
   ═══════════════════════════════════════════════════════════════════ */

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  transition: width var(--transition), min-width var(--transition), transform var(--transition);
  z-index: 20;
  overflow: hidden;
}

.sidebar.collapsed {
  width: 0;
  min-width: 0;
  border-right: none;
}

.sidebar-header {
  padding: 16px 14px 12px;
  border-bottom: 1px solid var(--hairline);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.sidebar-logo {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, #dbeafe, var(--accent-bg));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  box-shadow: 0 1px 4px var(--accent-glow);
}

.sidebar-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -.2px;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-title span {
  color: var(--accent);
}

.new-chat-btn {
  width: 100%;
  padding: 9px 12px;
  margin: 10px 14px 6px;
  width: calc(100% - 28px);
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background var(--transition), box-shadow var(--transition), transform .12s var(--ease-spring);
  box-shadow: 0 2px 8px var(--accent-glow);
  flex-shrink: 0;
}

.new-chat-btn:hover {
  background: var(--accent-h);
  box-shadow: 0 4px 14px rgba(26,115,232,.35);
  transform: translateY(-1px);
}
.new-chat-btn:active { transform: scale(.97); }

/* ── Search bar ──────────────────────────────────────────────────── */
.sidebar-search {
  padding: 6px 14px 8px;
  flex-shrink: 0;
}

.sidebar-search-input {
  width: 100%;
  padding: 7px 10px 7px 30px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 12.5px;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236e7680' stroke-width='2.2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 9px center;
}

.sidebar-search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background-color: #fff;
}

/* ── Session list ────────────────────────────────────────────────── */
.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 12px;
}

.session-group-label {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .6px;
  padding: 10px 6px 4px;
}

.session-item {
  position: relative;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  transition: background var(--transition);
  group: true;
}

.session-item:hover { background: var(--bg); }
.session-item.active { background: var(--accent-bg); }

.session-icon {
  font-size: 15px;
  margin-top: 1px;
  flex-shrink: 0;
  opacity: .75;
}

.session-item.active .session-icon { opacity: 1; }

.session-info { flex: 1; min-width: 0; }

.session-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

.session-item.active .session-name {
  color: var(--accent);
  font-weight: 600;
}

.session-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-actions {
  display: none;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.session-item:hover .session-actions { display: flex; }

.session-action-btn {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  transition: background var(--transition), color var(--transition);
}

.session-action-btn:hover { background: var(--hairline); color: var(--text); }
.session-action-btn.danger:hover { background: var(--danger-bg); color: var(--danger); }

/* Inline rename input */
.session-rename-input {
  width: 100%;
  border: 1.5px solid var(--accent);
  border-radius: 5px;
  padding: 3px 6px;
  font-family: var(--font);
  font-size: 13px;
  outline: none;
  background: #fff;
}

/* ── Sidebar footer ──────────────────────────────────────────────── */
.sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--hairline);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ccc;
  flex-shrink: 0;
  transition: background var(--transition);
}
.status-dot.ok      { background: var(--success); box-shadow: 0 0 0 2px var(--success-bg); }
.status-dot.warn    { background: var(--warn); }
.status-dot.error   { background: var(--danger); }

.status-label {
  font-size: 11.5px;
  color: var(--muted);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ═══════════════════════════════════════════════════════════════════
   MAIN CHAT AREA
   ═══════════════════════════════════════════════════════════════════ */

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Top bar ─────────────────────────────────────────────────────── */
.chat-topbar {
  height: 56px;
  padding: 0 16px;
  border-bottom: 1px solid var(--hairline);
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.topbar-toggle-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  color: var(--muted);
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}
.topbar-toggle-btn:hover { background: var(--bg); color: var(--text); }

.topbar-session-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -.1px;
}

.topbar-model-badge {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-bg);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  border: 1px solid #c5d8fb;
  letter-spacing: .3px;
  white-space: nowrap;
}

.topbar-kb-btn {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: #fff;
  color: var(--muted);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: border-color var(--transition), color var(--transition), background var(--transition);
  white-space: nowrap;
}
.topbar-kb-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }
.topbar-kb-btn.active { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }

/* ── Messages area ───────────────────────────────────────────────── */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 0 8px;
}

/* ── Empty / welcome state ───────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 32px 24px;
  text-align: center;
  animation: fadeSlideUp .3s var(--ease) both;
}

.empty-logo {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: linear-gradient(135deg, #dbeafe, var(--accent-bg));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-md);
}

.empty-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.3px;
  margin-bottom: 8px;
}

.empty-sub {
  font-size: 14px;
  color: var(--muted);
  max-width: 360px;
  line-height: 1.65;
  margin-bottom: 28px;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 520px;
}

.quick-action-card {
  padding: 13px 14px;
  background: var(--surface);
  border: 1.5px solid var(--hairline);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  transition: border-color var(--transition), box-shadow var(--transition), transform .12s var(--ease-spring);
  animation: fadeSlideUp .3s var(--ease) both;
}

.quick-action-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  transform: translateY(-1px);
}

.quick-action-icon {
  font-size: 18px;
  margin-bottom: 6px;
}

.quick-action-text {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
}

/* ── Message bubble ──────────────────────────────────────────────── */
.message-row {
  display: flex;
  padding: 6px 20px;
  gap: 10px;
  animation: fadeSlideUp .22s var(--ease) both;
}

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

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
  margin-top: 2px;
}

.msg-avatar.ai {
  background: linear-gradient(135deg, #dbeafe, var(--accent-bg));
  box-shadow: 0 1px 4px var(--accent-glow);
}

.msg-avatar.user {
  background: var(--user-bubble);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.msg-body { max-width: 72%; display: flex; flex-direction: column; gap: 4px; }
.message-row.user .msg-body { align-items: flex-end; }

.msg-bubble {
  padding: 11px 14px;
  border-radius: 16px;
  line-height: 1.65;
  font-size: 14px;
  word-break: break-word;
  position: relative;
}

/* User bubble */
.message-row.user .msg-bubble {
  background: var(--user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(26,115,232,.25);
}

/* AI bubble */
.message-row.ai .msg-bubble {
  background: var(--ai-bubble);
  border: 1px solid var(--hairline);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}

/* Streaming cursor */
.msg-bubble.streaming::after {
  content: "▋";
  display: inline-block;
  animation: blink .9s step-end infinite;
  color: var(--accent);
  margin-left: 2px;
}

@keyframes blink { 50% { opacity: 0; } }

/* ── Markdown inside AI bubble ───────────────────────────────────── */
.msg-bubble p { margin: 0 0 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3,
.msg-bubble h4, .msg-bubble h5, .msg-bubble h6 {
  margin: 12px 0 6px;
  font-weight: 700;
  line-height: 1.3;
}
.msg-bubble h1 { font-size: 18px; }
.msg-bubble h2 { font-size: 16px; }
.msg-bubble h3 { font-size: 14.5px; }
.msg-bubble ul, .msg-bubble ol {
  margin: 6px 0;
  padding-left: 22px;
}
.msg-bubble li { margin-bottom: 3px; }
.msg-bubble blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  color: var(--muted);
  margin: 8px 0;
}
.msg-bubble strong { font-weight: 700; }
.msg-bubble em { font-style: italic; }
.msg-bubble a { color: var(--accent); text-decoration: underline; }
.msg-bubble hr { border: none; border-top: 1px solid var(--hairline); margin: 12px 0; }
.msg-bubble table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 8px 0; }
.msg-bubble th { background: var(--bg); font-weight: 700; }
.msg-bubble th, .msg-bubble td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }

/* Code blocks */
.msg-bubble code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: var(--bg);
  border: 1px solid var(--hairline);
  border-radius: 4px;
  padding: 1px 5px;
}
.msg-bubble pre {
  background: #1e1e2e;
  border-radius: var(--radius-sm);
  padding: 14px;
  overflow-x: auto;
  margin: 8px 0;
  position: relative;
}
.msg-bubble pre code {
  background: transparent;
  border: none;
  padding: 0;
  color: #cdd6f4;
  font-size: 12.5px;
}

/* Copy code btn */
.code-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 3px 9px;
  border-radius: 5px;
  border: 1px solid rgba(255,255,255,.15);
  background: rgba(255,255,255,.08);
  color: rgba(255,255,255,.7);
  font-size: 11px;
  cursor: pointer;
  font-family: var(--font);
  transition: background var(--transition);
}
.code-copy-btn:hover { background: rgba(255,255,255,.18); color: #fff; }

/* ── Message meta row ────────────────────────────────────────────── */
.msg-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 2px;
}

.msg-time {
  font-size: 10.5px;
  color: var(--muted);
}

.msg-action-btn {
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: background var(--transition), color var(--transition);
  opacity: 0;
  transition: opacity var(--transition), background var(--transition), color var(--transition);
}
.message-row:hover .msg-action-btn { opacity: 1; }
.msg-action-btn:hover { background: var(--bg); color: var(--text); }

/* ── Sources accordion ───────────────────────────────────────────── */
.sources-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 11.5px;
  color: var(--muted);
  cursor: pointer;
  font-family: var(--font);
  transition: border-color var(--transition), color var(--transition), background var(--transition);
  margin-top: 4px;
}
.sources-toggle:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }

.sources-panel {
  margin-top: 8px;
  background: var(--bg);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  animation: fadeSlideUp .18s var(--ease) both;
}

.source-chip {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-xs);
  font-size: 12px;
  transition: border-color var(--transition);
}
.source-chip:hover { border-color: var(--accent); }

.source-type-badge {
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .3px;
  flex-shrink: 0;
}
.source-type-badge.text  { background: var(--accent-bg); color: var(--accent); }
.source-type-badge.image { background: #fce8ff; color: #8430c8; }

.source-content { flex: 1; min-width: 0; }
.source-file { font-weight: 600; color: var(--text); margin-bottom: 2px; }
.source-snippet { color: var(--muted); line-height: 1.4; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.source-score { font-size: 10.5px; color: var(--success); font-weight: 700; flex-shrink: 0; margin-top: 1px; }

/* Source image thumb */
.source-thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 5px;
  border: 1px solid var(--hairline);
  flex-shrink: 0;
}

/* ── Typing indicator ────────────────────────────────────────────── */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 14px;
  align-items: center;
}
.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: typingBounce 1.2s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

/* ── Error message ───────────────────────────────────────────────── */
.msg-error {
  background: var(--danger-bg);
  border: 1px solid #f5c6c2;
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 7px;
}

/* ═══════════════════════════════════════════════════════════════════
   CHAT INPUT BAR
   ═══════════════════════════════════════════════════════════════════ */

.chat-input-area {
  flex-shrink: 0;
  padding: 12px 20px 16px;
  background: var(--surface);
  border-top: 1px solid var(--hairline);
  box-shadow: 0 -2px 12px rgba(0,0,0,.04);
}

/* Collections selector strip */
.collections-strip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 0 8px;
  flex-wrap: wrap;
}

.collections-strip-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  flex-shrink: 0;
}

.collection-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: #fff;
  font-size: 11.5px;
  color: var(--muted);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--font);
}
.collection-chip:hover { border-color: var(--accent); color: var(--accent); }
.collection-chip.selected {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.collection-chip-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.no-collections-hint {
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
}

/* ── Input row ───────────────────────────────────────────────────── */
.input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 16px;
  padding: 8px 8px 8px 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.input-row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3.5px var(--accent-glow);
  background: #fff;
}

.chat-textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  outline: none;
  line-height: 1.6;
  max-height: 180px;
  min-height: 24px;
  overflow-y: auto;
  padding: 0;
}
.chat-textarea::placeholder { color: #c2c8d0; }

.input-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: background var(--transition), box-shadow var(--transition), transform .12s var(--ease-spring);
  box-shadow: 0 2px 8px var(--accent-glow);
}
.input-send-btn:hover:not(:disabled) {
  background: var(--accent-h);
  box-shadow: 0 4px 14px rgba(26,115,232,.40);
  transform: scale(1.08);
}
.input-send-btn:active:not(:disabled) { transform: scale(.93); }
.input-send-btn:disabled { background: #c5cdd8; box-shadow: none; cursor: not-allowed; }

.input-stop-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--danger);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  transition: background var(--transition), transform .12s var(--ease-spring);
}
.input-stop-btn:hover { background: #b71c1c; transform: scale(1.08); }

.input-hint {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  margin-top: 8px;
}

/* ═══════════════════════════════════════════════════════════════════
   KNOWLEDGE BASE PANEL (right)
   ═══════════════════════════════════════════════════════════════════ */

.kb-panel {
  width: var(--kb-w);
  min-width: var(--kb-w);
  background: var(--surface);
  border-left: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  transition: width var(--transition), min-width var(--transition), transform var(--transition);
  overflow: hidden;
  z-index: 15;
}

.kb-panel.collapsed {
  width: 0;
  min-width: 0;
  border-left: none;
}

.kb-header {
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--hairline);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.kb-header-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--accent-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}

.kb-header-title {
  font-size: 14px;
  font-weight: 700;
  flex: 1;
}

.kb-close-btn {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition: background var(--transition), color var(--transition);
}
.kb-close-btn:hover { background: var(--bg); color: var(--text); }

/* ── Upload zone ─────────────────────────────────────────────────── */
.kb-upload-section {
  padding: 12px;
  border-bottom: 1px solid var(--hairline);
  flex-shrink: 0;
}

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 12px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), transform .15s var(--ease);
  background: var(--bg);
  position: relative;
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-bg);
  transform: translateY(-1px);
}
.upload-zone.drag-over { box-shadow: 0 0 0 3px var(--accent-glow); }

.upload-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}
.upload-icon { font-size: 22px; display: block; margin-bottom: 4px; }
.upload-text { font-size: 12.5px; color: var(--muted); }
.upload-text strong { color: var(--accent); }
.upload-text .exts { font-size: 11px; color: #aaa; margin-top: 2px; }

/* ── Collection name input & ingest btn ──────────────────────────── */
.kb-col-name-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.kb-col-name-input {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-family: var(--font);
  font-size: 12.5px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.kb-col-name-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

.kb-ingest-btn {
  padding: 6px 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), box-shadow var(--transition), transform .12s var(--ease-spring);
}
.kb-ingest-btn:hover:not(:disabled) { background: var(--accent-h); transform: translateY(-1px); }
.kb-ingest-btn:disabled { background: #b0b8c4; cursor: not-allowed; }

/* ── Progress bar ────────────────────────────────────────────────── */
.ingest-progress {
  margin-top: 8px;
  background: var(--hairline);
  border-radius: 999px;
  height: 4px;
  overflow: hidden;
}
.ingest-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #2979ff);
  border-radius: 999px;
  transition: width .3s var(--ease);
}

.ingest-status {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 5px;
  min-height: 16px;
}
.ingest-status.ok    { color: var(--success); }
.ingest-status.error { color: var(--danger); }

/* ── Collection list ─────────────────────────────────────────────── */
.kb-collections-label {
  padding: 10px 14px 6px;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .6px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--hairline);
}

.kb-collections-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 10px 12px;
}

.kb-empty {
  padding: 20px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
  font-style: italic;
}

.collection-card {
  padding: 10px 11px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--hairline);
  margin-bottom: 6px;
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  cursor: default;
}
.collection-card:hover { border-color: var(--border); box-shadow: var(--shadow-sm); }
.collection-card.selected { border-color: var(--accent); background: #f0f5ff; }

.collection-card-top {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 5px;
}

.col-checkbox {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 2px;
}

.col-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.col-delete-btn {
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}
.col-delete-btn:hover { background: var(--danger-bg); color: var(--danger); }

.col-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  font-size: 11px;
  color: var(--muted);
  padding-left: 24px;
}
.col-meta-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

/* ── Select all / none ───────────────────────────────────────────── */
.kb-select-row {
  padding: 6px 14px;
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--hairline);
  flex-shrink: 0;
}

.kb-select-btn {
  font-size: 11.5px;
  color: var(--accent);
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  padding: 2px 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.kb-select-btn:hover { color: var(--accent-h); }

/* ═══════════════════════════════════════════════════════════════════
   ANIMATIONS
   ═══════════════════════════════════════════════════════════════════ */

@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Spinner ─────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(26,115,232,.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .65s linear infinite;
  vertical-align: middle;
}
.spinner.white {
  border-color: rgba(255,255,255,.35);
  border-top-color: #fff;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ───────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: #1d1d1f;
  color: #fff;
  font-size: 13px;
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  animation: fadeSlideUp .22s var(--ease) both;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 320px;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
.toast.warn    { background: var(--warn); color: #1d1d1f; }

/* ── Scrollbar ───────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-thumb { background: #d0d5dd; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #b0b8c6; }
::-webkit-scrollbar-track { background: transparent; }

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 900px) {
  :root { --sidebar-w: 260px; --kb-w: 270px; }
  .quick-actions { grid-template-columns: 1fr; max-width: 320px; }
}

@media (max-width: 640px) {
  .sidebar, .kb-panel { position: fixed; top: 0; bottom: 0; box-shadow: var(--shadow-lift); }
  .sidebar { left: 0; }
  .kb-panel { right: 0; }
  .sidebar.collapsed  { transform: translateX(-100%); width: var(--sidebar-w); min-width: var(--sidebar-w); }
  .kb-panel.collapsed { transform: translateX(100%);  width: var(--kb-w);      min-width: var(--kb-w); }
  .msg-body { max-width: 88%; }
}

/* ── Reduced motion ──────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
