:root {
  --bg: #f5f6f8;
  --activity: #f0f1f3;
  --sidebar: #fafafa;
  --panel: #ffffff;
  --border: #e6e8eb;
  --border-strong: #dfe2e7;
  --text: #1f2329;
  --text-soft: #4e5969;
  --muted: #8a8f99;
  --primary: #2f6bff;
  --primary-hover: #1f5bff;
  --primary-weak: #e8efff;
  --danger: #cf1322;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font-family: inherit; }

.app { display: flex; height: 100vh; }

/* ---------- 活动栏 ---------- */
.activity-bar {
  width: 52px;
  flex: 0 0 52px;
  background: var(--activity);
  border-right: 1px solid #e3e5e8;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 6px;
}
.activity-logo {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, #4b7dff, #2f6bff);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
  user-select: none;
}
.activity-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: #6b7280;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s, color .12s;
}
.activity-btn svg { width: 19px; height: 19px; }
.activity-btn:hover { background: #e7e9ec; color: var(--text); }
.activity-btn.active { background: var(--primary-weak); color: var(--primary); }
.activity-spacer { flex: 1; }

/* ---------- 侧栏 ---------- */
.sidebar {
  width: 258px;
  flex: 0 0 258px;
  background: var(--sidebar);
  border-right: 1px solid #e8eaed;
  display: flex;
  flex-direction: column;
  padding: 14px 12px 12px;
  min-height: 0;
}
.brand { display: flex; align-items: center; gap: 9px; padding: 2px 4px 14px; }
.brand-logo {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, #4b7dff, #2f6bff);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 15px;
}
.brand-name { font-size: 14px; font-weight: 600; }
.brand-sub { font-size: 11px; color: var(--muted); margin-top: 1px; }

.new-chat {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  padding: 0 12px;
  transition: background .12s, border-color .12s;
}
.new-chat:hover { background: #f3f4f6; border-color: #d3d7dd; }
.new-chat .plus { font-size: 16px; color: var(--muted); line-height: 1; }

.section-label { font-size: 11px; color: var(--muted); padding: 16px 4px 6px; }
.session-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-right: 2px;
}
.session-item {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 8px;
  border-radius: 6px;
  color: var(--text-soft);
  cursor: pointer;
  font-size: 13px;
  user-select: none;
}
.session-item:hover { background: #eef0f3; }
.session-item.active { background: #e8ecf5; color: var(--text); }
.session-item .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-item .del {
  opacity: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0 2px;
}
.session-item:hover .del { opacity: 1; }
.session-item .del:hover { color: var(--danger); }
.session-empty { color: var(--muted); font-size: 12px; padding: 8px 6px; }

.sidebar-footer { border-top: 1px solid var(--border); padding-top: 10px; margin-top: 8px; }
.workspace-btn {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 6px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-soft);
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.workspace-btn:hover { background: #eef0f3; }
.ws-title { font-size: 11px; color: var(--muted); }
.ws-path { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 主区 ---------- */
.main { flex: 1; min-width: 0; display: flex; background: var(--panel); }
.view { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.view-page { background: var(--bg); overflow-y: auto; padding: 28px 40px 40px; }

/* ---------- 顶栏 ---------- */
.topbar {
  height: 56px;
  flex: 0 0 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid #ebedf0;
  background: #fff;
}
.topbar-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
#chatTitle {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 420px;
}
.status-dot { width: 5px; height: 5px; border-radius: 50%; background: #c9cdd4; flex: 0 0 5px; }
#statusLabel { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 消息 ---------- */
.messages { flex: 1; overflow-y: auto; background: #fff; }
.messages-inner {
  max-width: 780px;
  margin: 0 auto;
  padding: 26px 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.msg { display: flex; gap: 12px; }
.msg.user { justify-content: flex-end; }
.bubble {
  background: #f2f3f5;
  border-radius: 10px;
  padding: 10px 14px;
  max-width: 78%;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.65;
}
.msg.assistant { align-items: flex-start; }
.avatar {
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  border-radius: 50%;
  background: #e3ecff;
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  margin-top: 2px;
}
.avatar.error { background: #fff2f0; color: var(--danger); }
.content { flex: 1; min-width: 0; }
.speaker { font-size: 11px; color: var(--muted); margin-bottom: 5px; }
.answer { white-space: pre-wrap; word-break: break-word; line-height: 1.72; }
.answer:empty::after { content: "…"; color: #c9cdd4; }

.error-box {
  background: #fff2f0;
  border: 1px solid #ffd8d3;
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--danger);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
  margin-top: 8px;
}

/* ---------- 工具卡片 ---------- */
.tool-card {
  border: 1px solid var(--border);
  background: #f7f8fa;
  border-radius: 8px;
  padding: 10px 12px;
}
.tool-head { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); }
.tool-icon { font-size: 12px; }
.tool-name { font-weight: 600; color: #5f6672; }
.tool-phase { margin-left: auto; }
.tool-phase.ok { color: #1a7f37; }
.tool-phase.denied { color: var(--danger); }
.tool-body {
  margin: 8px 0 0;
  font-family: "Cascadia Mono", Consolas, "Courier New", monospace;
  font-size: 12px;
  color: #5f6672;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 240px;
  overflow-y: auto;
}

/* ---------- 欢迎 ---------- */
.welcome { padding: 16vh 0 0; text-align: center; }
.welcome-title { font-size: 22px; font-weight: 600; margin-bottom: 8px; }
.welcome-sub { color: var(--muted); font-size: 12px; line-height: 1.8; max-width: 460px; margin: 0 auto; }

/* ---------- 输入区 ---------- */
.composer-wrap { padding: 10px 24px 16px; background: #fff; }
.composer {
  max-width: 780px;
  margin: 0 auto;
  background: #fff;
  border: 1px solid #e0e3e8;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(31, 35, 41, .04);
  transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47, 107, 255, .10); }
.composer textarea {
  display: block;
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  padding: 13px 14px 4px;
  font-size: 13px;
  line-height: 1.65;
  color: var(--text);
  min-height: 42px;
  max-height: 110px;
  overflow-y: auto;
}
.composer textarea:disabled { color: #9aa0a8; }
.composer-bar { display: flex; align-items: center; gap: 10px; padding: 8px 10px 10px 12px; }
.mode-select {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--border);
  background-color: #f4f5f7;
  color: var(--text-soft);
  font-size: 11px;
  border-radius: 6px;
  padding: 4px 22px 4px 9px;
  cursor: pointer;
  outline: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' fill='none' stroke='%238a8f99' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 7px center;
}
.token-hint {
  flex: 1;
  min-width: 0;
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.send-btn {
  border: none;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  padding: 7px 18px;
  border-radius: 7px;
  cursor: pointer;
  transition: background .12s;
}
.send-btn:hover { background: var(--primary-hover); }
.send-btn:disabled { background: #b9c9f5; cursor: default; }
.composer-note { max-width: 780px; margin: 6px auto 0; text-align: right; font-size: 11px; color: #b0b5bd; }

/* ---------- 按钮 ---------- */
.ghost-btn {
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--text-soft);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: background .12s;
}
.ghost-btn:hover { background: #f3f4f6; }
.primary-btn {
  border: none;
  background: var(--primary);
  color: #fff;
  border-radius: 7px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.primary-btn:hover { background: var(--primary-hover); }
.primary-btn:disabled { background: #b9c9f5; cursor: default; }
.link-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 5px;
}
.link-btn:hover { color: var(--danger); background: #f4f5f7; }

/* ---------- 知识库 / 设置 ---------- */
.page-head {
  max-width: 860px;
  margin: 0 auto 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.page-head h2 { margin: 0 0 6px; font-size: 18px; font-weight: 600; }
.page-head p { margin: 0; color: var(--muted); font-size: 12px; }

.source-list { max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.source-item {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.source-main { flex: 1; min-width: 0; }
.source-title { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.source-path { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-meta { font-size: 11px; color: var(--muted); white-space: nowrap; }
.empty-state { max-width: 860px; margin: 0 auto; padding: 48px 0; text-align: center; color: var(--muted); font-size: 12px; }

.settings-grid {
  max-width: 860px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 18px;
}
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--text-soft); }
.field-full { grid-column: 1 / -1; }
.field input {
  height: 34px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  padding: 0 10px;
  font-size: 13px;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47, 107, 255, .10); }
.settings-meta { max-width: 860px; margin: 18px auto 0; font-size: 11px; color: var(--muted); line-height: 1.8; }

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .30);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}
.modal-card {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  width: 100%;
  max-width: 560px;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 48px rgba(15, 23, 42, .18);
}
.modal-wide { max-width: 820px; }
.modal-card h3 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }
.modal-pre {
  flex: 1;
  overflow: auto;
  margin: 0;
  background: #f7f8fa;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-family: "Cascadia Mono", Consolas, "Courier New", monospace;
  font-size: 12px;
  color: #5f6672;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
  min-height: 80px;
}
.modal-json { max-height: 60vh; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* ---------- 提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: #1f2329;
  color: #fff;
  font-size: 12px;
  padding: 9px 16px;
  border-radius: 8px;
  z-index: 60;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}

/* ---------- 滚动条 ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #d3d6db; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #c2c6cd; }
::-webkit-scrollbar-track { background: transparent; }
