/* ============ 基础 ============ */
:root {
  --bg: #f2f5fa;
  --bg-sidebar: #eef2f9;
  --card: #ffffff;
  --line: #e3e9f2;
  --text: #26303e;
  --text-sub: #7a8595;
  --accent: #3b82f6;
  --accent-hover: #2f6fe0;
  --accent-soft: #e3effd;
  --bubble-user: #d8e9fd;
  --bubble-user-text: #1d3a5f;
  --danger: #e5484d;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(30, 60, 110, 0.08), 0 8px 24px rgba(30, 60, 110, 0.06);
  --shadow-sm: 0 1px 2px rgba(30, 60, 110, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}
button { font-family: inherit; cursor: pointer; }
textarea { font-family: inherit; }

.hidden { display: none !important; }

/* ============ 布局 ============ */
#app { display: flex; height: 100vh; overflow: hidden; }

#sidebar {
  width: 288px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 14px 12px 10px;
  gap: 12px;
}

.brand {
  display: flex; align-items: center; gap: 8px;
  padding: 2px 6px 10px;
  border-bottom: 1px solid var(--line);
}
.brand-icon { font-size: 22px; }
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: 0.5px; }
.brand-admin { margin-left: auto; text-decoration: none; font-size: 15px; opacity: 0.55; transition: 0.15s; }
.brand-admin:hover { opacity: 1; }

.sec { display: flex; flex-direction: column; min-height: 0; }
.sec.grow { flex: 1; }
.sec-title {
  font-size: 12px; color: var(--text-sub);
  padding: 0 6px 8px; font-weight: 600; letter-spacing: 1px;
}
.sec-title.row { display: flex; align-items: center; justify-content: space-between; }
.btn-mini {
  border: 1px solid var(--line); background: var(--card);
  border-radius: 6px; font-size: 12px; padding: 2px 8px; color: var(--accent);
  transition: 0.15s;
}
.btn-mini:hover { background: var(--accent-soft); border-color: var(--accent); }

.agent-list, .session-list { overflow-y: auto; min-height: 0; }
.agent-list::-webkit-scrollbar, .session-list::-webkit-scrollbar, .messages::-webkit-scrollbar { width: 6px; }
.agent-list::-webkit-scrollbar-thumb, .session-list::-webkit-scrollbar-thumb, .messages::-webkit-scrollbar-thumb {
  background: #c9d4e4; border-radius: 3px;
}

.agent-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer;
  transition: 0.15s; margin-bottom: 2px;
}
.agent-item:hover { background: rgba(59, 130, 246, 0.07); }
.agent-item.active { background: var(--accent-soft); box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.35); }
.avatar {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #e3effd, #d3e4fb);
  font-size: 20px;
}
.avatar.lg { width: 44px; height: 44px; font-size: 24px; border-radius: 12px; }
.agent-meta { min-width: 0; flex: 1; }
.agent-name { font-weight: 600; font-size: 14px; }
.agent-desc {
  font-size: 12px; color: var(--text-sub);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.session-item {
  padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  color: var(--text); font-size: 13.5px;
  transition: 0.15s;
}
.session-item:hover { background: rgba(59, 130, 246, 0.07); }
.session-item.active { background: var(--accent-soft); }
.session-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-del {
  opacity: 0; border: none; background: none; font-size: 13px; color: var(--text-sub);
  padding: 2px 4px; border-radius: 4px;
}
.session-item:hover .session-del { opacity: 1; }
.session-del:hover { color: var(--danger); background: #fdecec; }
.sidebar-empty { font-size: 12.5px; color: var(--text-sub); padding: 6px; }

/* ============ 主区域 ============ */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 22px; background: rgba(255, 255, 255, 0.85);
  border-bottom: 1px solid var(--line); backdrop-filter: blur(6px);
}
.chat-agent { display: flex; align-items: center; gap: 12px; min-width: 0; }
.chat-agent-info { min-width: 0; }
.h-name { font-size: 15px; font-weight: 700; }
.h-desc { font-size: 12px; color: var(--text-sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 320px; }
.model-badge {
  font-size: 11px; color: var(--accent); background: var(--accent-soft);
  padding: 2px 8px; border-radius: 20px; white-space: nowrap;
}
.chat-actions { display: flex; gap: 8px; }
.btn-ghost {
  border: 1px solid var(--line); background: var(--card); color: var(--text-sub);
  border-radius: var(--radius-sm); padding: 5px 12px; font-size: 12.5px; transition: 0.15s;
}
.btn-ghost:hover { color: var(--accent); border-color: var(--accent); }
.btn-ghost.danger:hover { color: var(--danger); border-color: var(--danger); }

/* ============ 消息区 ============ */
.messages {
  flex: 1; overflow-y: auto; padding: 24px 0;
  scroll-behavior: smooth;
}
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; gap: 8px; color: var(--text-sub);
}
.empty-icon { font-size: 52px; opacity: 0.9; }
.empty-title { font-size: 17px; font-weight: 700; color: var(--text); }
.empty-sub { font-size: 13px; }

.msg {
  display: flex; gap: 12px; padding: 6px 22px 6px; max-width: 860px; margin: 0 auto 18px;
}
.msg.assistant .avatar { background: linear-gradient(135deg, #eef6ff, #dcebff); }
.msg .avatar { width: 36px; height: 36px; font-size: 19px; border-radius: 9px; }
.msg-body { min-width: 0; flex: 1; }
.msg-role { font-size: 12px; color: var(--text-sub); margin-bottom: 4px; }
.msg.user .msg-body { display: flex; flex-direction: column; align-items: flex-end; }
.bubble {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 4px var(--radius) var(--radius) var(--radius);
  padding: 10px 14px; max-width: 100%;
  word-break: break-word;
}
.msg.user .bubble {
  background: var(--bubble-user); border-color: transparent;
  color: var(--bubble-user-text); border-radius: var(--radius) 4px var(--radius) var(--radius);
}
.msg.user .msg-role { text-align: right; }

.bubble > *:first-child { margin-top: 0; }
.bubble > *:last-child { margin-bottom: 0; }
.bubble p { margin: 6px 0; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 { margin: 12px 0 6px; line-height: 1.4; }
.bubble h1 { font-size: 19px; } .bubble h2 { font-size: 17px; } .bubble h3 { font-size: 15px; }
.bubble h4 { font-size: 14px; }
.bubble ul, .bubble ol { margin: 6px 0 6px 22px; }
.bubble li { margin: 3px 0; }
.bubble blockquote {
  border-left: 3px solid var(--accent); background: var(--bg-sidebar);
  padding: 6px 12px; margin: 8px 0; border-radius: 0 6px 6px 0; color: var(--text-sub);
}
.bubble a { color: var(--accent); }
.bubble code {
  background: #eef2f8; border: 1px solid var(--line); border-radius: 4px;
  padding: 1px 5px; font-size: 12.5px; font-family: Consolas, Monaco, monospace;
}
.bubble pre {
  background: #1e2a3a; color: #e6edf5; border-radius: var(--radius-sm);
  padding: 12px 14px; margin: 8px 0; overflow-x: auto;
}
.bubble pre code { background: none; border: none; padding: 0; color: inherit; font-size: 12.5px; }
.bubble pre .lang-tag { display: block; font-size: 11px; color: #8fa3b8; margin-bottom: 6px; }
.bubble hr { border: none; border-top: 1px solid var(--line); margin: 10px 0; }
.bubble table { border-collapse: collapse; margin: 8px 0; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 5px 10px; }
.bubble th { background: var(--bg-sidebar); }

.thinking { color: var(--text-sub); font-size: 13px; }

/* 附件预览（发送前） */
.file-preview { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 14px 0; max-width: 860px; margin: 0 auto; }
.file-chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 4px 8px; font-size: 12px; max-width: 220px;
}
.file-chip img { width: 30px; height: 30px; object-fit: cover; border-radius: 5px; }
.file-chip-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }
.file-chip-x { border: none; background: none; color: var(--text-sub); font-size: 13px; padding: 0 2px; }
.file-chip-x:hover { color: var(--danger); }

/* 消息中的附件 */
.msg-files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.msg-file {
  display: flex; align-items: center; gap: 5px;
  background: rgba(59, 130, 246, 0.08); border: 1px solid rgba(59, 130, 246, 0.25);
  border-radius: 7px; padding: 3px 8px; font-size: 12px; color: var(--accent); text-decoration: none;
}
.msg-file img { width: 34px; height: 34px; object-fit: cover; border-radius: 5px; }

/* ============ 输入区 ============ */
.input-wrap {
  border-top: 1px solid var(--line);
  background: linear-gradient(to top, rgba(242, 245, 250, 0.95), rgba(242, 245, 250, 0));
  padding: 6px 0 12px;
}
.input-bar {
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; padding: 10px 14px;
  max-width: 860px; margin: 0 auto;
  box-shadow: var(--shadow-sm);
  transition: 0.2s;
}
.input-bar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12); }
.icon-btn {
  border: none; background: none; font-size: 19px; color: var(--text-sub);
  width: 34px; height: 34px; border-radius: 8px; transition: 0.15s; flex-shrink: 0;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }
#msgInput {
  flex: 1; border: none; outline: none; resize: vertical;
  font-size: 15px; line-height: 1.6;
  min-height: 40px; max-height: 60vh;
  padding: 6px 2px; background: transparent;
}
.send-btn {
  width: 36px; height: 36px; border-radius: 10px; border: none; flex-shrink: 0;
  background: var(--accent); color: #fff; font-size: 16px;
  transition: 0.15s; box-shadow: 0 2px 8px rgba(59, 130, 246, 0.35);
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { background: #b7c8e4; box-shadow: none; cursor: not-allowed; }
.send-btn.stop { background: var(--danger); }
.input-hint { text-align: center; font-size: 11px; color: #a9b4c4; margin-top: 6px; }

/* ============ 拖拽遮罩 / Toast ============ */
.drop-overlay {
  position: fixed; inset: 0; background: rgba(59, 130, 246, 0.12);
  border: 3px dashed var(--accent); border-radius: 16px; margin: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700; color: var(--accent);
  z-index: 100; pointer-events: none;
}
.toast {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%);
  background: #26303e; color: #fff; padding: 10px 20px; border-radius: 10px;
  font-size: 13px; z-index: 200; box-shadow: var(--shadow);
  animation: toastIn 0.25s ease;
}
.toast.err { background: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* 流式输出光标 */
.cursor::after { content: "▋"; color: var(--accent); animation: blink 0.9s infinite; }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

@media (max-width: 760px) {
  #sidebar { width: 220px; }
}
