/* ===== EasyRAG 样式 ===== */
:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --sidebar-bg: #1f2430;
  --sidebar-text: #d7dbe3;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --border: #e5e7eb;
  --text: #1f2937;
  --text-dim: #6b7280;
  --user-bubble: #2563eb;
  --danger: #dc2626;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ===== 侧栏 ===== */
#sidebar {
  width: 280px;
  min-width: 240px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
}

#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 10px 18px;
}

.logo { font-size: 18px; font-weight: 700; letter-spacing: .5px; color: #fff; }

.icon-btn {
  width: 30px; height: 30px;
  border: none; border-radius: 8px;
  background: rgba(255, 255, 255, .1);
  color: #fff; font-size: 16px; line-height: 1;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(255, 255, 255, .2); }
.icon-btn:disabled { opacity: .5; cursor: not-allowed; }

#session-list { flex: 1; overflow-y: auto; padding: 4px 8px; }

.session-item {
  display: flex; flex-direction: column; gap: 2px;
  padding: 9px 10px; margin-bottom: 4px;
  border-radius: 10px; cursor: pointer;
  position: relative;
}
.session-item:hover { background: rgba(255, 255, 255, .08); }
.session-item.active { background: var(--accent); color: #fff; }

.session-title {
  font-size: 14px; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 210px;
}
.session-meta { font-size: 11px; color: #8b93a5; }
.session-item.active .session-meta { color: rgba(255, 255, 255, .8); }

.btn-del {
  position: absolute; top: 6px; right: 6px;
  width: 22px; height: 22px; border: none; border-radius: 6px;
  background: transparent; color: #8b93a5; font-size: 14px; cursor: pointer;
  opacity: 0;
}
.session-item:hover .btn-del, .doc-item:hover .btn-del { opacity: 1; }
.btn-del:hover { background: rgba(220, 38, 38, .25); color: #f87171; }

/* ===== 文档管理区 ===== */
#docs-panel {
  border-top: 1px solid rgba(255, 255, 255, .08);
  max-height: 45%;
  min-height: 120px;
  display: flex; flex-direction: column;
}
.docs-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px 6px;
  font-size: 13px; color: #b7bdc9;
}
#docs-list { overflow-y: auto; padding: 2px 8px 10px; }

.doc-item {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: 7px 10px; border-radius: 8px; position: relative;
}
.doc-item:hover { background: rgba(255, 255, 255, .08); }
.doc-info { min-width: 0; }
.doc-name {
  font-size: 13px; color: #e5e7eb;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 180px;
}
.doc-meta { font-size: 11px; color: #8b93a5; }

.empty-hint { padding: 8px 10px; font-size: 12px; color: #6b7280; }

#docs-drop-hint {
  text-align: center; padding: 10px; margin: 4px 8px;
  font-size: 12px; color: #93c5fd;
  border: 1px dashed #3b82f6; border-radius: 8px;
}

/* ===== 主区 ===== */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#topbar {
  height: 56px; flex-shrink: 0;
  display: flex; align-items: center;
  padding: 0 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  font-size: 15px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

#messages { flex: 1; overflow-y: auto; padding: 20px 0; }

#welcome {
  height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; color: var(--text-dim);
}
#welcome h2 { font-size: 20px; margin-bottom: 8px; color: var(--text); }

.message { display: flex; padding: 6px 24px; }
.message.user { flex-direction: row; justify-content: flex-end; }
.message.assistant { flex-direction: column; align-items: flex-start; }

.bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px; line-height: 1.7;
  word-break: break-word; overflow-wrap: break-word;
}
.message.user .bubble {
  background: var(--user-bubble); color: #fff;
  border-top-right-radius: 4px;
}
.message.assistant .bubble {
  background: var(--panel);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
}

/* Markdown 内容样式 */
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble pre {
  background: #f6f8fa; padding: 12px; border-radius: 8px;
  overflow-x: auto; margin: 8px 0;
}
.bubble code { font-family: Consolas, "Courier New", monospace; font-size: 13px; }
.bubble :not(pre) > code { background: #f1f3f5; padding: 2px 5px; border-radius: 4px; }
.bubble ul, .bubble ol { padding-left: 20px; margin: 6px 0; }
.bubble h1, .bubble h2, .bubble h3 { margin: 10px 0 6px; }
.bubble table { border-collapse: collapse; margin: 8px 0; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 6px 10px; }
.bubble blockquote { border-left: 3px solid var(--border); padding-left: 12px; color: var(--text-dim); margin: 8px 0; }
.bubble a { color: var(--accent); }
.bubble hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }

/* ===== 思考 / 加载状态 ===== */
.thinking {
  display: flex; align-items: center; gap: 8px;
  padding: 2px 2px;
  color: var(--text-dim);
  font-size: 13px;
}
.spinner {
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 参考来源折叠区 ===== */
.sources { margin-top: 8px; font-size: 12px; width: fit-content; max-width: 78%; }
.sources-head {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 6px;
  background: #eef1f5;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.sources-head:hover { background: #e2e6ec; color: var(--text); }
.sources-body {
  margin-top: 8px;
  padding: 8px 12px;
  border-left: 3px solid #cbd5e1;
  background: #fafbfc;
  border-radius: 0 8px 8px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.source-item { color: var(--text-dim); line-height: 1.6; }
.source-idx { color: var(--accent); font-weight: 600; }
.source-meta { font-size: 11px; }
.source-text {
  margin-top: 2px;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ===== 输入区 ===== */
#input-bar {
  flex-shrink: 0;
  display: flex; align-items: flex-end; gap: 10px;
  padding: 12px 24px 16px;
  background: var(--panel);
  border-top: 1px solid var(--border);
}

#chat-input {
  flex: 1; resize: none;
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; font-size: 14px; line-height: 1.5;
  max-height: 200px; min-height: 42px;
  font-family: inherit; outline: none;
}
#chat-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
#chat-input:disabled { background: #f3f4f6; }

#btn-send {
  height: 42px; padding: 0 22px;
  border: none; border-radius: 10px;
  background: var(--accent); color: #fff;
  font-size: 14px; font-weight: 600; cursor: pointer;
}
#btn-send:hover:not(:disabled) { background: var(--accent-hover); }
#btn-send:disabled { background: #9db6f5; cursor: not-allowed; }

/* ===== Toast ===== */
#toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(17, 24, 39, .92); color: #fff;
  padding: 10px 18px; border-radius: 10px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: all .25s;
  z-index: 999; max-width: 80%;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== 滚动条 ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, .15); border-radius: 4px; }
#sidebar ::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .15); }

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  #sidebar { width: 200px; min-width: 200px; }
  .message { padding: 6px 12px; }
  .bubble { max-width: 88%; }
}

