:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-hover: #22262f;
  --border: #2d3142;
  --text: #e4e6eb;
  --text-muted: #8b8fa3;
  --primary: #6366f1;
  --primary-hover: #5558e3;
  --primary-dim: rgba(99, 102, 241, 0.15);
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
  --radius-sm: 6px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

#app { display: flex; min-height: 100vh; }

/* ── 侧边栏 ──────────────────────────── */

.sidebar {
  width: 220px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}

.logo {
  width: 32px;
  height: 32px;
  background: var(--primary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.sidebar-header .title { font-weight: 600; font-size: 15px; }

.sidebar-nav { flex: 1; padding: 12px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  transition: all 0.15s;
  cursor: pointer;
  margin-bottom: 4px;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--primary-dim); color: var(--primary); }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
  transition: background 0.3s;
}

.status-dot.online { background: var(--success); }
.status-dot.offline { background: var(--danger); }

/* ── 主区域 ──────────────────────────── */

.main {
  flex: 1;
  padding: 32px 40px;
  overflow-y: auto;
  max-width: 100%;
}

.view { display: none; }
.view.active { display: block; }

.view-header { margin-bottom: 24px; }
.view-header h1 { font-size: 22px; font-weight: 600; }
.view-header .subtitle { color: var(--text-muted); margin-top: 4px; font-size: 13px; }

.header-actions { display: flex; gap: 8px; align-items: center; }

/* ── 表单 ────────────────────────────── */

.upload-options {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
}

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 12px; color: var(--text-muted); font-weight: 500; }

select, input[type="text"] {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

select:focus, input[type="text"]:focus { border-color: var(--primary); }
select { min-width: 140px; cursor: pointer; }
.select-sm { padding: 6px 10px; font-size: 12px; min-width: auto; }

/* ── 拖拽区 ──────────────────────────── */

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-muted);
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-dim);
  color: var(--primary);
}

.dropzone-content svg { margin-bottom: 12px; }
.dropzone-title { font-size: 15px; margin-bottom: 4px; }
.dropzone-title .link { color: var(--primary); text-decoration: underline; }
.dropzone-hint { font-size: 12px; }

/* ── 上传队列 ────────────────────────── */

.upload-queue { margin-top: 24px; }

.queue-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.queue-header h2 { font-size: 16px; }

.queue-list { display: flex; flex-direction: column; gap: 8px; }

.queue-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.queue-item .file-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  flex-shrink: 0;
}

.file-icon.pdf { background: #ef444433; color: #ef4444; }
.file-icon.word { background: #2196f333; color: #42a5f5; }
.file-icon.ppt { background: #ff980033; color: #ffa726; }
.file-icon.excel { background: #4caf5033; color: #66bb6a; }
.file-icon.image { background: #9c27b033; color: #ce93d8; }
.file-icon.video { background: #6366f133; color: #818cf8; }
.file-icon.text { background: #64748b33; color: #94a3b8; }

.queue-item .file-info { flex: 1; min-width: 0; }
.queue-item .file-name {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.queue-item .file-meta { font-size: 11px; color: var(--text-muted); }

.queue-item .file-status {
  font-size: 12px;
  font-weight: 500;
  flex-shrink: 0;
  padding: 4px 10px;
  border-radius: 4px;
}

.status-pending { background: #f59e0b22; color: var(--warning); }
.status-processing { background: #6366f122; color: var(--primary); }
.status-completed { background: #22c55e22; color: var(--success); }
.status-failed { background: #ef444422; color: var(--danger); }
.status-uploading { background: #6366f122; color: var(--primary); }

.queue-item .remove-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  flex-shrink: 0;
}

.queue-item .remove-btn:hover { background: var(--bg-hover); color: var(--danger); }

.queue-actions { margin-top: 16px; text-align: right; }

/* ── 按钮 ────────────────────────────── */

.btn {
  padding: 8px 20px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.85; }

.btn-sm { padding: 5px 12px; font-size: 12px; }

/* ── 表格 ────────────────────────────── */

.table-wrap { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 12px;
  white-space: nowrap;
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.data-table tr:hover td { background: var(--bg-hover); }

.type-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.scope-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
}

.scope-internal { background: #6366f122; color: #818cf8; }
.scope-external { background: #f59e0b22; color: var(--warning); }

.empty-row { text-align: center; color: var(--text-muted); padding: 40px; }

/* ── 分页 ────────────────────────────── */

.pagination {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-top: 20px;
}

.page-btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
}

.page-btn:hover { background: var(--bg-hover); }
.page-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── 检索测试 ────────────────────────── */

.retrieve-box { max-width: 800px; }

.retrieve-input {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.retrieve-input input[type="text"] { flex: 1; }

.retrieve-results { display: flex; flex-direction: column; gap: 12px; }

.result-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
}

.result-card .result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.result-score {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--primary-dim);
  color: var(--primary);
  font-weight: 600;
}

.result-text { font-size: 13px; color: var(--text); }
.result-meta { font-size: 11px; color: var(--text-muted); margin-top: 6px; }

.no-results { text-align: center; color: var(--text-muted); padding: 40px; }

/* ── Toast ───────────────────────────── */

.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  min-width: 280px;
  max-width: 400px;
  font-size: 13px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: slideIn 0.25s ease;
  border-left: 3px solid var(--primary);
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ── 响应式 ──────────────────────────── */

.nav-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 12px;
}

@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar-header .title { display: none; }
  .nav-item span { display: none; }
  .sidebar-footer { font-size: 0; }
  .main { padding: 16px; }
  .upload-options { flex-direction: column; }
}

/* ── Chatbox 对话界面 ──────────────────────────── */

.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 0px);
  max-width: 900px;
  margin: 0 auto;
  padding: 0;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.chat-header h1 {
  font-size: 20px;
  font-weight: 600;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.scope-badge {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}

.scope-internal {
  background: rgba(99, 102, 241, 0.15);
  color: var(--primary);
}

.scope-external {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning);
}

.chat-session-id {
  font-size: 12px;
  color: var(--text-muted);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  gap: 16px;
  color: var(--text-muted);
}

.chat-welcome-icon {
  color: var(--primary);
  opacity: 0.6;
}

.chat-msg {
  display: flex;
  gap: 12px;
  max-width: 80%;
  animation: chatMsgIn 0.3s ease;
}

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

.chat-msg-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

.chat-msg-user .chat-msg-avatar {
  background: var(--primary);
  color: white;
}

.chat-msg-assistant .chat-msg-avatar {
  background: var(--bg-hover);
  color: var(--primary);
  border: 1px solid var(--border);
}

.chat-msg-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  max-width: 100%;
}

.chat-msg-user .chat-msg-bubble {
  background: var(--primary);
  border-color: var(--primary);
}

.chat-msg-user .chat-msg-bubble .chat-msg-text {
  color: white;
}

.chat-msg-text {
  font-size: 14px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-msg-extra {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.msg-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.source-tag {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-hover);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.msg-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
}

.msg-badge-intercepted {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

.chat-msg-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  opacity: 0.7;
}

.chat-msg-user .chat-msg-time {
  color: rgba(255, 255, 255, 0.7);
}

.chat-typing {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.chat-typing span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingDot 1.4s infinite;
}

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

@keyframes typingDot {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
  30% { opacity: 1; transform: scale(1); }
}

.chat-input-area {
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
}

.chat-input-wrapper {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 8px 8px 16px;
  transition: border-color 0.2s;
}

.chat-input-wrapper:focus-within {
  border-color: var(--primary);
}

.chat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  resize: none;
  max-height: 120px;
  font-family: inherit;
}

.chat-input::placeholder {
  color: var(--text-muted);
}

.chat-send-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--primary);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, opacity 0.2s;
}

.chat-send-btn:hover:not(:disabled) {
  background: var(--primary-hover);
}

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

.chat-input-hint {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.rate-limit-hint {
  color: var(--warning);
}
