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

:root {
  --bg-body: #f5f7fa;
  --bg-app: #ffffff;
  --bg-sidebar: #f0f2f5;
  --bg-chat: #fafbfc;
  --bg-input: #ffffff;
  --bg-user-msg: #4f46e5;
  --bg-ai-msg: #ffffff;
  --bg-hover: #e2e8f0;
  --bg-active: #dbeafe;
  --bg-code: #1e293b;
  --bg-switch-off: #cbd5e1;
  --bg-modal: #ffffff;
  --text-primary: #1a1e24;
  --text-secondary: #334155;
  --text-muted: #94a3b8;
  --text-user-msg: #ffffff;
  --text-ai-msg: #1f2937;
  --border-color: #e0e4e8;
  --border-light: #d9dee3;
  --border-input: #d1d5db;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --code-toolbar-bg: rgba(15, 23, 42, 0.95);
  --code-border: #334155;
  --code-text: #e2e8f0;
}

body[data-code-theme="dark"] {
  --bg-code: #1e293b;
  --code-toolbar-bg: rgba(15, 23, 42, 0.95);
  --code-border: #334155;
  --code-text: #e2e8f0;
}
body[data-code-theme="light"] {
  --bg-code: #f8fafc;
  --code-toolbar-bg: rgba(241, 245, 249, 0.95);
  --code-border: #e2e8f0;
  --code-text: #1e293b;
}

body.dark-mode {
  --bg-body: #0f172a;
  --bg-app: #1e293b;
  --bg-sidebar: #1a2332;
  --bg-chat: #0f172a;
  --bg-input: #1e293b;
  --bg-user-msg: #4f46e5;
  --bg-ai-msg: #1e293b;
  --bg-hover: #334155;
  --bg-active: #1e3a8a;
  --bg-switch-off: #475569;
  --bg-modal: #1e293b;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --text-user-msg: #ffffff;
  --text-ai-msg: #e2e8f0;
  --border-color: #334155;
  --border-light: #334155;
  --border-input: #475569;
  --accent: #6366f1;
  --accent-hover: #818cf8;
}

html, body {
  height: 100%;
}
body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg-body);
  height: 100vh;
  height: 100dvh;
  display: flex; flex-direction: column; justify-content: center; align-items: center; overflow: hidden;
  color: var(--text-primary);
  transition: background 0.3s, color 0.3s;
}
.app-container {
  display: flex; width: 100%; height: 100%; max-width: 1400px;
  background: var(--bg-app); box-shadow: 0 0 40px rgba(0,0,0,0.08); position: relative;
  overflow: hidden;
}

/* ===== 侧边栏 ===== */
.sidebar {
  background: var(--bg-sidebar); width: 300px; min-width: 300px; height: 100%;
  display: flex; flex-direction: column; border-right: 1px solid var(--border-color);
  transition: transform 0.3s ease, width 0.3s ease, min-width 0.3s ease, background 0.3s;
  z-index: 20; position: relative;
  user-select: none; -webkit-user-select: none;
  overflow: visible;
}
.sidebar.collapsed { width: 0; min-width: 0; overflow: hidden; border-right: none; }

.sidebar-header {
  padding: 16px; display: flex; flex-direction: column; gap: 10px;
  border-bottom: 1px solid var(--border-light);
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
}
.sidebar-brand-icon {
  width: 40px; height: 40px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.sidebar-brand-icon a { display: block; width: 100%; height: 100%; }
.sidebar-brand-icon img {
  width: 100%; height: 100%; object-fit: cover;
  display: block;
}
.sidebar-brand h2 {
  font-size: 1.2rem; font-weight: 700; color: var(--text-primary); flex: 1;
}
.homepage-link {
  color: #16a34a;
  text-decoration: none;
}
.homepage-link:hover { text-decoration: underline; }

.new-chat-btn {
  background: var(--accent); color: white; border: none; padding: 8px 12px;
  border-radius: 8px; font-weight: 500; cursor: pointer; font-size: 0.85rem;
  width: 100%;
}
.new-chat-btn:hover { background: var(--accent-hover); }

.explore-agents-btn {
  background: linear-gradient(135deg, #8b5cf6, #6366f1);
  color: white; border: none; padding: 8px 12px;
  border-radius: 8px; font-weight: 500; cursor: pointer; font-size: 0.85rem;
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: opacity 0.2s;
}
.explore-agents-btn:hover { opacity: 0.9; }
.explore-agents-btn svg { width: 16px; height: 16px; }

.ai-credit {
  font-size: 0.7rem; color: var(--text-muted); text-align: center;
  padding: 0 4px; line-height: 1.5;
}
.ai-credit b { font-weight: 600; }

.history-list {
  flex: 1; overflow-y: auto; padding: 12px 8px;
  display: flex; flex-direction: column; gap: 4px;
}
.history-item {
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
  background: transparent; transition: background 0.15s;
  display: flex; align-items: center; justify-content: space-between;
  color: var(--text-secondary); font-size: 0.9rem; position: relative;
}
.history-item:hover { background: var(--bg-hover); }
.history-item.active { background: var(--bg-active); font-weight: 500; }
.history-title { overflow: hidden; text-overflow: ellipsis; flex: 1; white-space: nowrap; }

.more-btn {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 1.1rem; padding: 2px 6px;
  border-radius: 6px; visibility: hidden; transition: 0.15s; line-height: 1;
}
.history-item:hover .more-btn { visibility: visible; }
.more-btn:hover { background: var(--bg-hover); color: var(--text-secondary); }

.dropdown-menu {
  display: none; position: absolute; right: 0; top: 100%;
  background: var(--bg-modal);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  z-index: 100;
  min-width: 140px; padding: 6px; margin-top: 4px;
}
.dropdown-menu.show { display: block; }
.dropdown-item {
  padding: 8px 12px; border-radius: 8px; cursor: pointer;
  font-size: 0.85rem; display: flex; align-items: center; gap: 8px;
  transition: background 0.15s; border: none; background: none;
  width: 100%; text-align: left; color: var(--text-secondary);
}
.dropdown-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.dropdown-item.danger { color: var(--danger); }
.dropdown-item.danger:hover { background: rgba(239, 68, 68, 0.15); color: var(--danger); }

/* ===== 侧边栏底部设置 ===== */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-light);
  position: relative;
}
.settings-btn {
  background: none; border: none; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: 8px;
  color: var(--text-secondary); font-size: 0.9rem;
  transition: 0.15s;
  width: 100%;
}
.settings-btn:hover { background: var(--bg-hover); }
.settings-btn svg { width: 18px; height: 18px; }

.settings-quick-panel {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 12px;
  right: 12px;
  margin-bottom: 8px;
  background: var(--bg-modal);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  padding: 8px;
  z-index: 100;
  flex-direction: column;
  gap: 4px;
}
.settings-quick-panel.show { display: flex; }
.quick-panel-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  border: none; background: none;
  color: var(--text-secondary); font-size: 0.9rem;
  cursor: pointer; text-align: left;
  transition: 0.15s;
  width: 100%;
}
.quick-panel-btn:hover { background: var(--bg-hover); }
.quick-panel-btn svg { width: 18px; height: 18px; flex-shrink: 0; }

/* ===== 收起/展开按钮 ===== */
.sidebar-collapse-btn {
  position: absolute; top: 12px; right: -36px;
  background: var(--bg-modal); border: 1px solid var(--border-input);
  border-radius: 8px; width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 1rem; color: var(--text-muted);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08); z-index: 30;
}
.sidebar-collapse-btn:hover { background: var(--bg-hover); }

.sidebar-expand-btn {
  display: none; position: fixed; top: 16px; left: 16px;
  z-index: 50; background: var(--bg-modal); border: 1px solid var(--border-input);
  border-radius: 8px; width: 36px; height: 36px;
  align-items: center; justify-content: center;
  cursor: pointer; font-size: 1.2rem; color: var(--text-secondary);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.sidebar-expand-btn:hover { background: var(--bg-hover); }

.sidebar:not(.collapsed) .sidebar-collapse-btn { display: flex; }
.sidebar:not(.collapsed) ~ .sidebar-expand-btn { display: none; }
.sidebar.collapsed .sidebar-collapse-btn { display: none; }
.sidebar.collapsed ~ .sidebar-expand-btn { display: flex; }

/* ===== 主聊天区 ===== */
.chat-main {
  flex: 1; display: flex; flex-direction: column;
  height: 100%; background: var(--bg-input); position: relative; min-width: 0;
  overflow: hidden;
}

.chat-messages {
  flex: 1; overflow-y: auto; padding: 20px 16px;
  display: flex; flex-direction: column; gap: 12px; background: var(--bg-chat);
  min-height: 0;
}
.message { display: flex; flex-direction: column; max-width: 85%; position: relative; }
.message.user {
  align-self: flex-end; background: var(--bg-user-msg); color: var(--text-user-msg);
  border-radius: 18px 18px 4px 18px; padding: 10px 16px;
}
.message.assistant {
  align-self: flex-start; background: var(--bg-ai-msg); border: 1px solid var(--border-color);
  border-radius: 18px 18px 18px 4px; padding: 12px 16px;
  color: var(--text-ai-msg); box-shadow: 0 2px 6px rgba(0,0,0,0.02);
}
.message-content { word-wrap: break-word; line-height: 1.6; white-space: pre-wrap; }
.message-content p { margin-bottom: 8px; }
.message-content code { font-family: 'Fira Code', monospace; font-size: 0.9rem; }
.message-content ul, .message-content ol { margin-left: 20px; }
.message-content img { max-width: 100%; border-radius: 8px; margin: 6px 0; }

.message-actions {
  display: flex; gap: 4px; margin-top: 6px;
  opacity: 0; transition: opacity 0.15s;
}
.message:hover .message-actions { opacity: 1; }
.message-actions button {
  background: none; border: none; cursor: pointer;
  padding: 6px; border-radius: 6px; color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  transition: 0.15s;
}
.message-actions button:hover { background: var(--bg-hover); color: var(--text-secondary); }
.message-actions svg { width: 16px; height: 16px; pointer-events: none; }
.message.user .message-actions { justify-content: flex-end; }
.message.user .message-actions button { color: rgba(255,255,255,0.7); }
.message.user .message-actions button:hover { background: rgba(255,255,255,0.15); color: white; }

.message-attachments {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px;
}
.message-attachments .att-chip {
  background: rgba(255,255,255,0.2); border-radius: 6px;
  padding: 2px 8px; font-size: 0.75rem;
}

.attachments-area {
  display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 0;
  min-height: 0; max-height: 120px; overflow-y: auto;
}
.attachment-item {
  display: flex; align-items: center; gap: 6px;
  background: #eef2ff; border: 1px solid #c7d2fe;
  border-radius: 8px; padding: 4px 10px; font-size: 0.8rem; color: #3730a3;
}
.attachment-item .file-name { max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
.attachment-item .file-size { color: #6366f1; font-size: 0.7rem; }
.attachment-item .remove-file {
  background: none; border: none; color: var(--danger);
  cursor: pointer; font-size: 1rem; padding: 0 2px; line-height: 1;
}

.input-area {
  border-top: 1px solid var(--border-color); padding: 16px 20px 20px;
  background: var(--bg-input); display: flex; flex-direction: column; gap: 12px;
  flex-shrink: 0;
  position: relative;
}

/* ===== 当前智能体提示条 ===== */
.current-agent-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: linear-gradient(135deg, rgba(139,92,246,0.1), rgba(99,102,241,0.1));
  border: 1px solid var(--border-color);
  border-radius: 10px;
  font-size: 0.85rem; color: var(--text-secondary);
  flex-shrink: 0;
}
.current-agent-icon {
  display: flex; align-items: center; justify-content: center;
  width: 20px; height: 20px;
}
.current-agent-icon svg {
  width: 18px; height: 18px;
  stroke: var(--accent);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.current-agent-name { font-weight: 600; color: var(--accent); flex: 1; }

/* ===== 智能体自定义参数栏 ===== */
.agent-extra-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  padding: 8px 0;
}
.agent-extra-bar .agent-extra-label {
  font-size: 0.8rem; font-weight: 600; color: var(--text-muted);
  flex-shrink: 0;
}
.agent-extra-bar input,
.agent-extra-bar select {
  padding: 6px 10px; border: 1px solid var(--border-input);
  border-radius: 8px; font-size: 0.85rem; outline: none;
  background: var(--bg-sidebar); color: var(--text-primary);
  max-width: 180px;
}
.agent-extra-bar input:focus,
.agent-extra-bar select:focus { border-color: var(--accent); }

/* ===== 右下角悬浮按钮组 ===== */
.float-buttons {
  position: absolute;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 40;
  transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.4s ease;
  opacity: 1;
}
.float-buttons.float-collapsed {
  right: -22px;
  opacity: 0.5;
}
.float-buttons.float-collapsed:hover {
  right: 20px;
  opacity: 1;
}
.float-btn {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--bg-modal); border: 1px solid var(--border-color);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, background 0.15s;
}
.float-btn:hover {
  box-shadow: 0 6px 20px rgba(0,0,0,0.18);
  transform: translateY(-2px);
  background: var(--bg-hover);
}
.float-btn svg {
  width: 20px; height: 20px;
  stroke: var(--accent);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.float-btn.locked svg { stroke: var(--danger); }
.float-btn.hidden { display: none; }

/* ===== 思考强度区域 ===== */
.think-strength-row {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; position: relative;
}
.think-strength-label {
  font-size: 0.8rem; font-weight: 600; color: var(--text-muted);
  letter-spacing: 0.02em;
}
.strength-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; font-size: 0.85rem; color: var(--text-secondary);
  background: var(--bg-sidebar); border: 1px solid var(--border-input);
  border-radius: 8px; cursor: pointer;
  transition: 0.15s;
}
.strength-btn:hover { border-color: #9ca3af; background: var(--bg-hover); }
.strength-btn .chevron {
  width: 12px; height: 12px; transition: transform 0.2s;
}
.strength-btn.open .chevron { transform: rotate(180deg); }

.strength-panel {
  display: none; position: absolute;
  top: 100%; left: 0; margin-top: 8px;
  background: var(--bg-modal); border: 1px solid var(--border-color);
  border-radius: 12px; padding: 14px 18px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  z-index: 60; min-width: 240px;
}
.strength-panel.show { display: block; }
.strength-panel-title {
  font-size: 0.75rem; color: var(--text-muted); margin-bottom: 10px;
  display: flex; justify-content: space-between;
}
.strength-slider {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 6px; border-radius: 3px;
  background: linear-gradient(to right, #c7d2fe, var(--accent));
  outline: none; cursor: pointer;
}
.strength-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 20px; height: 20px; border-radius: 50%;
  background: white; border: 3px solid var(--accent);
  cursor: pointer; box-shadow: 0 2px 6px rgba(79,70,229,0.3);
}
.strength-slider::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%;
  background: white; border: 3px solid var(--accent);
  cursor: pointer; box-shadow: 0 2px 6px rgba(79,70,229,0.3);
}
.strength-marks {
  display: flex; justify-content: space-between;
  margin-top: 8px; font-size: 0.7rem; color: var(--text-muted);
}
.strength-hint {
  font-size: 0.68rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--border-color);
}
.strength-marks span { flex: 1; text-align: center; }
.strength-marks span:first-child { text-align: left; }
.strength-marks span:last-child { text-align: right; }

.options-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 16px;
  position: relative;
}

/* ===== 温度帮助图标 ===== */
.temp-help-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.temp-help-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid var(--text-muted);
  color: var(--text-muted);
  font-size: 0.65rem;
  font-weight: 700;
  cursor: help;
  user-select: none;
  transition: 0.15s;
  line-height: 1;
}
.temp-help-icon:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.temp-help-tip {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: 260px;
  max-width: 80vw;
  padding: 10px 12px;
  background: var(--bg-modal);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--text-secondary);
  line-height: 1.5;
  z-index: 200;
  white-space: normal;
  text-align: left;
}
.temp-help-tip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--bg-modal);
}
.temp-help-wrap:hover .temp-help-tip {
  display: block;
}

/* ===== 深度思考开关 ===== */
.switch-label {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.9rem; color: var(--text-secondary);
  cursor: pointer; user-select: none;
}
.switch-track {
  position: relative;
  width: 40px; height: 22px; border-radius: 11px;
  background: var(--bg-switch-off); transition: background 0.2s;
  flex-shrink: 0;
}
.switch-thumb {
  position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: white; box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 0.2s;
}
.switch-label input[type="checkbox"] { display: none; }
.switch-label input[type="checkbox"]:checked + .switch-track { background: var(--accent); }
.switch-label input[type="checkbox"]:checked + .switch-track .switch-thumb { transform: translateX(18px); }

.model-select {
  padding: 6px 28px 6px 12px;
  font-size: 0.85rem; color: var(--text-secondary);
  background: var(--bg-sidebar);
  border: 1px solid var(--border-input);
  border-radius: 8px;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 14px;
  transition: border-color 0.15s;
}
.model-select:hover { border-color: #9ca3af; }
.model-select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(79,70,229,0.1); }

.input-row {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--bg-sidebar); border: 1px solid var(--border-input);
  border-radius: 16px; padding: 6px 8px;
}
.input-row-left {
  display: flex; align-items: flex-end; gap: 4px; flex: 1;
}
.attach-btn {
  background: none; border: none;
  cursor: pointer; padding: 8px 10px; border-radius: 8px;
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  min-width: 36px; min-height: 36px;
  transition: 0.15s;
}
.attach-btn:hover { background: var(--bg-hover); color: var(--text-secondary); }
.attach-btn svg { width: 20px; height: 20px; }
.message-textarea {
  flex: 1; border: none; background: transparent;
  resize: none; font-size: 0.95rem; font-family: inherit;
  line-height: 1.5; outline: none; max-height: 150px;
  min-height: 24px; padding: 4px 0;
  color: var(--text-primary);
}
.newline-btn {
  display: none; background: none; border: none;
  cursor: pointer; padding: 6px; border-radius: 8px;
  color: var(--text-muted); transition: 0.15s;
  align-items: center; justify-content: center;
}
.newline-btn:hover { background: var(--bg-hover); color: var(--text-secondary); }
.newline-btn svg { width: 18px; height: 18px; }

.send-btn {
  background: var(--accent); border: none; color: white;
  padding: 8px 14px; border-radius: 20px;
  cursor: pointer; display: flex; align-items: center;
  justify-content: center; min-width: 44px; min-height: 36px;
  transition: background 0.2s;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn.stop { background: var(--danger); }
.send-btn.stop:hover { background: var(--danger-hover); }
.send-btn svg { width: 18px; height: 18px; fill: white; }

.empty-chat {
  flex: 1; display: flex; align-items: center;
  justify-content: center; color: var(--text-muted); font-size: 1.2rem;
}
.reasoning-badge {
  display: inline-block; background: #fef3c7; color: #92400e;
  padding: 2px 8px; border-radius: 12px; font-size: 0.75rem;
  margin-bottom: 6px; font-weight: 500;
}

.modal-overlay {
  display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.4); z-index: 200;
  justify-content: center; align-items: center;
}
.modal-overlay.show { display: flex; }
.modal-box {
  background: var(--bg-modal); border-radius: 16px; padding: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2); max-width: 400px; width: 90%;
  display: flex; flex-direction: column; gap: 16px;
  max-height: 90vh; overflow-y: auto;
}
.modal-box h3 { font-size: 1.1rem; color: var(--text-primary); }
.modal-box input, .modal-box select {
  padding: 10px 14px; border: 1px solid var(--border-input); border-radius: 10px;
  font-size: 0.95rem; outline: none;
  background: var(--bg-input); color: var(--text-primary);
}
.modal-box input:focus, .modal-box select:focus { border-color: var(--accent); }
.modal-buttons { display: flex; gap: 10px; justify-content: flex-end; }
.modal-btn {
  padding: 8px 18px; border-radius: 10px; border: none;
  font-size: 0.9rem; cursor: pointer; font-weight: 500;
}
.modal-btn.cancel { background: var(--bg-sidebar); color: var(--text-secondary); }
.modal-btn.cancel:hover { background: var(--bg-hover); }
.modal-btn.confirm { background: var(--accent); color: white; }
.modal-btn.confirm:hover { background: var(--accent-hover); }
.modal-btn.danger { background: var(--danger); color: white; }
.modal-btn.danger:hover { background: var(--danger-hover); }

/* ===== 设置面板 ===== */
.settings-tabs {
  display: flex; gap: 4px; padding: 4px;
  background: var(--bg-sidebar); border-radius: 10px;
  margin-bottom: 16px;
}
.settings-tab {
  flex: 1; padding: 8px 12px; border-radius: 8px;
  border: none; background: transparent; cursor: pointer;
  font-size: 0.9rem; color: var(--text-muted);
  transition: 0.15s; font-weight: 500;
}
.settings-tab.active {
  background: var(--bg-modal); color: var(--text-primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.settings-panel { display: none; }
.settings-panel.active { display: block; }

.settings-section {
  display: flex; flex-direction: column; gap: 12px;
  margin-bottom: 20px;
}
.settings-section-title {
  font-size: 0.85rem; font-weight: 600; color: var(--text-muted);
  margin-bottom: 4px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-color);
}
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.settings-row label {
  font-size: 0.9rem; color: var(--text-secondary);
  flex-shrink: 0;
}
.settings-row select,
.settings-row input[type="text"] {
  flex: 1; max-width: 220px;
  padding: 6px 10px; border: 1px solid var(--border-input);
  border-radius: 8px; font-size: 0.85rem; outline: none;
  background: var(--bg-input); color: var(--text-primary);
}
.settings-row select:focus,
.settings-row input:focus { border-color: var(--accent); }

.settings-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.5;
  padding: 6px 0 0 0;
}

.theme-toggle { display: flex; gap: 8px; }
.theme-btn {
  padding: 6px 14px; border-radius: 8px;
  border: 1px solid var(--border-input);
  background: var(--bg-sidebar);
  color: var(--text-secondary);
  cursor: pointer; font-size: 0.85rem;
  transition: 0.15s;
}
.theme-btn.active {
  background: var(--accent); color: white;
  border-color: var(--accent);
}

.danger-btn {
  background: var(--danger); color: white; border: none;
  padding: 10px 16px; border-radius: 8px;
  cursor: pointer; font-size: 0.9rem; font-weight: 500;
  width: 100%;
}
.danger-btn:hover { background: var(--danger-hover); }

/* ===== 智能体弹窗 ===== */
.agents-tabs {
  display: flex; gap: 4px; padding: 4px;
  background: var(--bg-sidebar); border-radius: 10px;
  margin-bottom: 16px;
}
.agents-tab {
  flex: 1; padding: 8px 12px; border-radius: 8px;
  border: none; background: transparent; cursor: pointer;
  font-size: 0.85rem; color: var(--text-muted);
  transition: 0.15s; font-weight: 500;
}
.agents-tab.active {
  background: var(--bg-modal); color: var(--text-primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.agents-panel { display: none; }
.agents-panel.active { display: block; }

.agents-list {
  display: flex; flex-direction: column; gap: 8px;
  max-height: 50vh; overflow-y: auto;
}
.agent-card {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--border-color);
  background: var(--bg-sidebar);
  cursor: pointer; transition: 0.15s;
}
.agent-card:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}
.agent-card-icon {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  background: #eef2ff;
}
.agent-card-icon svg {
  width: 22px; height: 22px;
  stroke: var(--accent);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.agent-card-info { flex: 1; min-width: 0; }
.agent-card-name {
  font-size: 0.95rem; font-weight: 600; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.agent-card-desc {
  font-size: 0.75rem; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 2px;
}
.agent-card-actions {
  display: flex; gap: 4px; flex-shrink: 0;
}
.agent-card-action {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 1rem; padding: 4px 6px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
}
.agent-card-action svg { width: 16px; height: 16px; }
.agent-card-action:hover { background: var(--bg-hover); color: var(--text-secondary); }
.agent-card-action.danger:hover { background: rgba(239,68,68,0.15); color: var(--danger); }

.agents-empty {
  padding: 24px; text-align: center;
  color: var(--text-muted); font-size: 0.9rem;
}

.agent-prompt-textarea {
  flex: 1; max-width: 320px;
  padding: 10px 14px; border: 1px solid var(--border-input);
  border-radius: 10px; font-size: 0.9rem; outline: none;
  background: var(--bg-input); color: var(--text-primary);
  font-family: inherit; resize: vertical;
  min-height: 100px;
}
.agent-prompt-textarea:focus { border-color: var(--accent); }

/* ===== 对话列表内智能体小图标 ===== */
.history-title .agent-mini-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  margin-right: 6px;
  flex-shrink: 0;
  vertical-align: -2px;
}
.history-title .agent-mini-icon svg {
  width: 14px;
  height: 14px;
  stroke: var(--accent);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ===== Markdown 表格 ===== */
.table-wrapper {
  position: relative;
  margin: 10px 0;
  border-radius: 8px;
  border: 1px solid var(--border-input);
  background: var(--bg-input);
  overflow: hidden;
}
.table-toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  padding: 4px 8px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-input);
  position: sticky;
  left: 0;
  z-index: 2;
}
.table-scroll { overflow-x: auto; width: 100%; }
.table-toolbar .code-btn {
  padding: 4px 8px;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 6px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: 0.15s;
}
.table-toolbar .code-btn:hover { background: var(--bg-hover); color: var(--text-secondary); }
.table-toolbar .code-btn svg { width: 14px; height: 14px; }
.table-toolbar .code-btn.success { color: var(--success); }

.message-content table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9rem;
  white-space: normal;
}
.message-content table th,
.message-content table td {
  border: 1px solid var(--border-input);
  padding: 6px 12px;
  text-align: left;
}
.message-content table th { background: var(--bg-sidebar); font-weight: 600; }
.message-content table tr:nth-child(even) { background: var(--bg-chat); }
.message.user .message-content table th,
.message.user .message-content table td { border-color: rgba(255,255,255,0.3); }
.message.user .message-content table th { background: rgba(255,255,255,0.15); }

/* ===== LaTeX ===== */
.katex { font-size: 1em; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 6px 0; }
.message.user .katex { color: white; }

/* ===== 代码块 ===== */
.message-content pre {
  background: var(--bg-code);
  color: var(--code-text);
  padding: 0;
  border-radius: 10px;
  overflow: hidden;
  margin: 8px 0;
  position: relative;
  transition: background 0.3s, color 0.3s;
}
.message-content pre code {
  display: block;
  padding: 40px 12px 12px 12px;
  overflow-x: auto;
  font-family: 'Fira Code', monospace;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--code-text);
}
.code-toolbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 32px;
  background: var(--code-toolbar-bg);
  border-bottom: 1px solid var(--code-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  z-index: 2;
  transition: background 0.3s;
}
.code-lang {
  font-size: 0.7rem;
  color: #94a3b8;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.code-btn-group { display: flex; gap: 4px; }
.code-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  color: #94a3b8;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: 0.15s;
}
.code-btn:hover { background: rgba(148, 163, 184, 0.15); color: #e2e8f0; }
body[data-code-theme="light"] .code-btn { color: #64748b; }
body[data-code-theme="light"] .code-btn:hover { background: rgba(100, 116, 139, 0.1); color: #1e293b; }
body[data-code-theme="light"] .code-lang { color: #64748b; }
.code-btn.success { color: var(--success) !important; }
.code-btn svg { width: 14px; height: 14px; pointer-events: none; }

/* ===== 运行弹窗 ===== */
.run-modal-box {
  max-width: 90vw;
  width: 900px;
  height: 80vh;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  overflow: hidden;
}
.run-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-sidebar);
}
.run-modal-header h3 { font-size: 1rem; color: var(--text-primary); }
.run-modal-close {
  background: none; border: none; cursor: pointer;
  font-size: 1.3rem; color: var(--text-muted);
  padding: 4px 8px; border-radius: 6px;
}
.run-modal-close:hover { background: var(--bg-hover); color: var(--text-secondary); }
.run-modal-body { flex: 1; background: white; position: relative; overflow: hidden; }
.run-modal-body iframe { width: 100%; height: 100%; border: none; background: white; }

.hidden { display: none !important; }

@media (max-width: 768px) {
  .sidebar {
    position: fixed; left: 0; top: 0; height: 100%;
    width: 280px; min-width: 280px; transform: translateX(-100%);
    box-shadow: 8px 0 24px rgba(0,0,0,0.15);
  }
  .sidebar.mobile-visible { transform: translateX(0); }
  .sidebar.collapsed { transform: translateX(-100%); width: 280px; min-width: 280px; }

  .sidebar:not(.mobile-visible) .sidebar-collapse-btn { display: none; }
  .sidebar:not(.mobile-visible) ~ .sidebar-expand-btn { display: flex; }
  .sidebar.mobile-visible .sidebar-collapse-btn { display: flex; }
  .sidebar.mobile-visible ~ .sidebar-expand-btn { display: none; }

  .sidebar-collapse-btn {
    position: absolute; top: 12px; right: -36px;
    background: var(--bg-modal); border: 1px solid var(--border-input);
    border-radius: 8px; width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; font-size: 1rem; color: var(--text-muted);
    box-shadow: 0 2px 8px rgba(0,0,0,0.08); z-index: 30;
  }

  .newline-btn { display: flex; }
  .message { max-width: 92%; }
  .float-buttons { right: 16px; bottom: 140px; }
  .run-modal-box { width: 95vw; height: 75vh; }
  .agent-prompt-textarea { max-width: 100%; }
}