:root {
  --bg: #0e0f13;
  --panel: #16181f;
  --panel-2: #1e2129;
  --border: #2a2e39;
  --text: #e6e8ee;
  --muted: #9aa0ac;
  --accent: #6c8cff;
  --accent-2: #8a6cff;
  --green: #5fcf80;
  --red: #ff6c7a;
  --user-bubble: linear-gradient(135deg, #6c8cff, #8a6cff);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: radial-gradient(1200px 600px at 70% -10%, #1a1d29 0%, var(--bg) 55%);
  color: var(--text);
  display: flex;
  flex-direction: row;
  height: 100vh;
  overflow: hidden;
}

/* 侧边栏 */
aside.sidebar {
  width: 264px; flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: rgba(14, 15, 19, 0.7);
  display: flex; flex-direction: column;
  backdrop-filter: blur(8px);
}
.sidebar-head {
  padding: 16px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--border);
}
.sidebar-head .logo {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: white; font-size: 14px;
}
.sidebar-head .name { font-weight: 600; font-size: 14px; }
.new-btn {
  margin: 12px;
  border: 1px solid var(--border); background: var(--panel);
  color: var(--text); border-radius: 10px; padding: 10px 12px;
  font-size: 13px; cursor: pointer; text-align: center;
  transition: border-color 0.15s, background 0.15s;
}
.new-btn:hover { border-color: var(--accent); background: var(--panel-2); }
.session-list { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.session-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; border-radius: 9px; cursor: pointer;
  color: var(--muted); font-size: 13px; margin-bottom: 2px;
  transition: background 0.12s, color 0.12s;
}
.session-item:hover { background: var(--panel); color: var(--text); }
.session-item.active { background: var(--panel-2); 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: 14px; padding: 0 4px; border-radius: 4px;
}
.session-item:hover .del { opacity: 1; }
.session-item .del:hover { color: #ff8a8a; background: rgba(255,138,138,0.1); }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}
.mcp-entry-btn {
  width: 100%; border: 1px solid var(--border); background: var(--panel);
  color: var(--text); border-radius: 9px; padding: 9px 12px; font-size: 13px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.mcp-entry-btn:hover { border-color: var(--accent); background: var(--panel-2); }
.mcp-icon { font-size: 14px; color: var(--accent); }
.mcp-count-badge {
  background: rgba(108,140,255,0.2); color: var(--accent);
  border: 1px solid rgba(108,140,255,0.4); border-radius: 10px;
  padding: 1px 7px; font-size: 11px; font-weight: 600;
}

/* 主区 */
main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(20, 22, 29, 0.6);
  backdrop-filter: blur(8px);
}
header h1 { font-size: 15px; margin: 0; font-weight: 600; letter-spacing: 0.3px; }
header .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

.mode-picker, .model-picker {
  display: flex; align-items: center; gap: 8px;
}
.mode-picker { margin-left: auto; }
.mode-picker label, .model-picker label { color: var(--muted); font-size: 12px; }
.mode-picker select, .model-picker select {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 9px;
  padding: 7px 30px 7px 12px; font-size: 13px; cursor: pointer;
  outline: none; appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2 4l4 4 4-4' stroke='%239aa0ac' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center;
  transition: border-color 0.15s;
}
.mode-picker select:hover, .model-picker select:hover { border-color: var(--accent); }
.mode-picker select:focus, .model-picker select:focus { border-color: var(--accent); }

#chat { flex: 1; overflow-y: auto; padding: 28px 0; }
.container { max-width: 820px; margin: 0 auto; padding: 0 20px; }

.msg { display: flex; gap: 14px; margin-bottom: 22px; align-items: flex-start; }
.msg .avatar {
  width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
}
.msg.user { flex-direction: row-reverse; }
.msg.user .avatar { background: var(--user-bubble); color: white; }
.msg.bot .avatar { background: var(--panel-2); border: 1px solid var(--border); color: var(--accent); }

.bubble {
  padding: 12px 16px; border-radius: 14px; line-height: 1.65;
  font-size: 15px; white-space: pre-wrap; word-break: break-word;
  max-width: 78%;
}
.msg.user .bubble { background: var(--user-bubble); color: white; border-bottom-right-radius: 4px; }
.msg.bot .bubble { background: var(--panel); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble.error { border-color: #5a2a33; color: #ff9aa8; }

.cursor-blink::after {
  content: "▋"; color: var(--accent); animation: blink 1s steps(2) infinite; margin-left: 1px;
}
@keyframes blink { 50% { opacity: 0; } }

footer {
  border-top: 1px solid var(--border);
  background: rgba(20, 22, 29, 0.6);
  backdrop-filter: blur(8px);
  padding: 14px 0 20px;
}
.input-wrap {
  max-width: 820px; margin: 0 auto; padding: 0 20px;
  display: flex; gap: 10px; align-items: flex-end;
}
textarea {
  flex: 1; resize: none; border: 1px solid var(--border); background: var(--panel);
  color: var(--text); border-radius: 14px; padding: 13px 16px; font-size: 15px;
  line-height: 1.5; max-height: 180px; outline: none; font-family: inherit;
}
textarea:focus { border-color: var(--accent); }
button.send {
  border: none; border-radius: 12px; padding: 0 18px; height: 46px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white; font-weight: 600; font-size: 14px; cursor: pointer;
  transition: opacity 0.15s;
}
button.send:disabled { opacity: 0.5; cursor: not-allowed; }
button.send.stop { background: linear-gradient(135deg, #ff6c7a, #ff8a5c); }
.hint { max-width: 820px; margin: 8px auto 0; padding: 0 20px; color: var(--muted); font-size: 12px; }

.meta { margin-top: 6px; font-size: 11px; color: var(--muted); }
.meta.stopped { color: #ffb86c; }

/* 工具调用透明化提示条 */
.tool-trace {
  display: flex; flex-wrap: wrap; gap: 5px;
  margin-bottom: 6px; max-width: 78%;
  margin-left: 44px; /* 与 bot 气泡对齐(avatar 30px + gap 14px) */
}
.tool-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 20px; font-size: 11.5px;
  border: 1px solid rgba(108,140,255,0.35);
  background: rgba(108,140,255,0.1); color: var(--accent);
  white-space: nowrap;
}
.tool-badge.calling { animation: tool-pulse 1.2s ease-in-out infinite; }
.tool-badge.done {
  border-color: rgba(95,207,128,0.35);
  background: rgba(95,207,128,0.08); color: var(--green);
}
.tool-badge.error {
  border-color: rgba(255,108,122,0.35);
  background: rgba(255,108,122,0.08); color: var(--red);
}
.tool-badge .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; flex-shrink: 0;
}
.tool-badge.calling .dot {
  animation: tool-dot-blink 1.2s ease-in-out infinite;
}
@keyframes tool-pulse { 0%,100%{opacity:1} 50%{opacity:0.6} }
@keyframes tool-dot-blink { 0%,100%{opacity:1} 50%{opacity:0.2} }

/* 思考过程折叠展示 */
.thinking {
  max-width: 78%;
  margin: 0 0 10px 44px; /* 与 bot 气泡对齐(avatar 30px + gap 14px) */
  border: 1px solid rgba(108,140,255,0.25);
  background: rgba(108,140,255,0.06);
  border-radius: 10px;
  padding: 8px 12px;
}
.thinking summary {
  cursor: pointer;
  list-style: none;
  display: flex; align-items: center; gap: 6px;
  user-select: none;
  color: var(--text);
  font-size: 12.5px;
}
.thinking summary::-webkit-details-marker { display: none; }
.thinking .thinking-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); flex-shrink: 0;
}
.thinking:not(.done) .thinking-dot {
  animation: tool-dot-blink 1.2s ease-in-out infinite;
}
.thinking .thinking-hint { color: var(--muted); font-size: 11px; }
.thinking-body {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed rgba(108,140,255,0.2);
  white-space: pre-wrap; word-break: break-word;
  line-height: 1.6; color: var(--muted);
  font-size: 12.5px;
  max-height: 240px; overflow-y: auto;
}

.empty { text-align: center; color: var(--muted); margin-top: 12vh; }
.empty h2 { color: var(--text); font-weight: 600; margin-bottom: 8px; }

/* 弹窗 Styles */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px); z-index: 100;
  display: flex; align-items: center; justify-content: center;
}
.modal-dialog {
  width: 90%; max-width: 680px; max-height: 85vh;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 16px; display: flex; flex-direction: column;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5); overflow: hidden;
}
.modal-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  background: var(--panel);
}
.modal-title h3 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-subtitle { color: var(--muted); font-size: 12px; margin-top: 2px; }
.modal-close {
  background: transparent; border: none; color: var(--muted);
  font-size: 16px; cursor: pointer; border-radius: 6px; padding: 4px 8px;
}
.modal-close:hover { color: var(--text); background: var(--panel-2); }

.modal-body {
  flex: 1; overflow-y: auto; padding: 20px;
}
.mcp-tabs {
  display: flex; gap: 8px; border-bottom: 1px solid var(--border); padding-bottom: 12px; margin-bottom: 16px;
}
.mcp-tab {
  background: transparent; border: none; color: var(--muted);
  padding: 6px 12px; border-radius: 8px; font-size: 13px; cursor: pointer;
  font-weight: 500; transition: all 0.12s;
}
.mcp-tab:hover { color: var(--text); background: var(--panel); }
.mcp-tab.active { color: white; background: var(--accent); }

.mcp-server-list { display: flex; flex-direction: column; gap: 12px; }
.mcp-empty-tip { text-align: center; color: var(--muted); padding: 40px 0; font-size: 13px; }

.mcp-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 8px;
}
.mcp-card-head {
  display: flex; align-items: center; justify-content: space-between;
}
.mcp-card-title {
  display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px;
}
.mcp-type-tag {
  font-size: 10px; padding: 2px 6px; border-radius: 4px;
  background: rgba(108,140,255,0.15); color: var(--accent);
  border: 1px solid rgba(108,140,255,0.3); text-transform: uppercase;
}
.mcp-card-actions {
  display: flex; align-items: center; gap: 8px;
}
.mcp-card-cmd {
  font-family: monospace; font-size: 12px; color: var(--muted);
  background: var(--panel-2); padding: 6px 10px; border-radius: 6px;
  word-break: break-all;
}
.mcp-card-tools {
  font-size: 12px; color: var(--muted); margin-top: 4px;
  display: flex; flex-wrap: wrap; gap: 6px;
}
.mcp-tool-pill {
  background: rgba(95,207,128,0.12); color: var(--green);
  border: 1px solid rgba(95,207,128,0.25); border-radius: 4px;
  padding: 1px 6px; font-size: 11px;
}

/* Switch 开关 */
.switch { position: relative; display: inline-block; width: 34px; height: 20px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0;
  background-color: var(--panel-2); border: 1px solid var(--border);
  transition: .2s; border-radius: 20px;
}
.slider:before {
  position: absolute; content: ""; height: 14px; width: 14px;
  left: 2px; bottom: 2px; background-color: var(--muted);
  transition: .2s; border-radius: 50%;
}
input:checked + .slider { background-color: var(--accent); border-color: var(--accent); }
input:checked + .slider:before { transform: translateX(14px); background-color: white; }

.btn-icon {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  border-radius: 6px; padding: 4px 8px; cursor: pointer; font-size: 12px;
}
.btn-icon:hover { color: var(--text); border-color: var(--accent); }
.btn-icon.del:hover { color: var(--red); border-color: var(--red); }

/* 表单 Styles */
.mcp-form { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: flex; flex-direction: column; gap: 6px; }
.form-row label { font-size: 13px; color: var(--text); font-weight: 500; }
.form-row label .req { color: var(--red); }
.form-row input, .form-row select, .form-row textarea, .json-textarea {
  background: var(--panel); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 9px 12px; font-size: 13px;
  font-family: inherit; outline: none;
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus, .json-textarea:focus {
  border-color: var(--accent);
}
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 10px; }
.btn {
  padding: 8px 16px; border-radius: 8px; font-size: 13px; font-weight: 600;
  cursor: pointer; border: none; transition: opacity 0.15s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: white; }
.btn-secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); }

.test-result-box {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px; font-size: 12px; line-height: 1.5;
  margin-top: 12px; max-height: 180px; overflow-y: auto;
}
.test-result-box.success { border-color: rgba(95,207,128,0.4); color: var(--green); }
.test-result-box.error { border-color: rgba(255,108,122,0.4); color: var(--red); }

.import-intro { font-size: 13px; color: var(--muted); margin-bottom: 10px; line-height: 1.5; }
.import-intro code { background: var(--panel-2); padding: 2px 6px; border-radius: 4px; color: var(--accent); }
.json-textarea { width: 100%; font-family: monospace; resize: vertical; }

/* 设置（模型服务 ApiKey） */
.sidebar-footer .mcp-entry-btn + .mcp-entry-btn { margin-top: 8px; }
.settings-status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted); flex-shrink: 0;
}
.settings-status-dot.on { background: var(--green); box-shadow: 0 0 6px rgba(95, 207, 128, 0.6); }
.modal-dialog-sm { max-width: 460px; }
.settings-form { display: flex; flex-direction: column; gap: 14px; }
.key-input-wrap { display: flex; gap: 8px; align-items: stretch; }
.key-input-wrap input {
  flex: 1; background: var(--panel); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 9px 12px; font-size: 13px;
  font-family: monospace; outline: none;
}
.key-input-wrap input:focus { border-color: var(--accent); }
.key-input-wrap .btn-icon { flex-shrink: 0; padding: 0 12px; }
.field-hint { font-size: 12px; color: var(--muted); line-height: 1.5; }
.settings-reset { display: flex; justify-content: flex-end; }
.settings-note {
  font-size: 12px; color: var(--muted); line-height: 1.6;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px;
}

/* 用户信息行与退出 */
.user-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 0 2px 10px;
}
.user-name { font-size: 13px; color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 无 ApiKey 拦截条 */
.gate-banner {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 10px 20px; margin: 0 24px 8px;
  background: rgba(255, 180, 90, 0.12); border: 1px solid rgba(255, 180, 90, 0.4);
  border-radius: 10px; color: #ffc98a; font-size: 13px;
}

/* 登录 / 注册遮罩 */
.auth-overlay {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: #0b0c10;
  overflow: hidden;
}
.auth-overlay::before,
.auth-overlay::after {
  content: ""; position: absolute; border-radius: 50%;
  filter: blur(90px); opacity: 0.5; pointer-events: none;
}
.auth-overlay::before {
  width: 460px; height: 460px; top: -120px; right: -80px;
  background: radial-gradient(circle, rgba(108, 140, 255, 0.55), transparent 65%);
}
.auth-overlay::after {
  width: 520px; height: 520px; bottom: -160px; left: -120px;
  background: radial-gradient(circle, rgba(138, 108, 255, 0.45), transparent 65%);
}

.auth-card {
  position: relative; z-index: 1;
  width: 100%; max-width: 400px;
  background: rgba(22, 24, 31, 0.82);
  border: 1px solid rgba(108, 140, 255, 0.18);
  border-radius: 20px;
  padding: 34px 30px 26px;
  display: flex; flex-direction: column;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(14px);
  animation: auth-in 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes auth-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.auth-logo {
  width: 52px; height: 52px; border-radius: 15px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: white; font-size: 23px; margin: 0 auto 14px;
  box-shadow: 0 8px 24px rgba(108, 140, 255, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.auth-card h2 { margin: 0; text-align: center; font-size: 20px; font-weight: 700; letter-spacing: 0.3px; }
.auth-sub { text-align: center; color: var(--muted); font-size: 13px; margin: 6px 0 22px; }

.auth-tabs {
  display: flex; gap: 4px; padding: 4px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 12px; margin-bottom: 20px;
}
.auth-tab {
  flex: 1; background: transparent; border: none; color: var(--muted);
  padding: 9px 0; border-radius: 9px; font-size: 13.5px; cursor: pointer; font-weight: 600;
  transition: color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}
.auth-tab:hover { color: var(--text); }
.auth-tab.active {
  color: white; background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 4px 12px rgba(108, 140, 255, 0.35);
}

#authForm { display: flex; flex-direction: column; gap: 14px; }
.auth-card .form-row { gap: 7px; }
.auth-card .form-row label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.auth-card .form-row input {
  background: rgba(14, 15, 19, 0.7); border: 1px solid var(--border);
  color: var(--text); border-radius: 10px; padding: 12px 14px; font-size: 14px;
  font-family: inherit; outline: none; width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.auth-card .form-row input::placeholder { color: #5c6270; }
.auth-card .form-row input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108, 140, 255, 0.18);
}

.auth-submit {
  width: 100%; padding: 12px; font-size: 14.5px; font-weight: 700;
  border-radius: 11px; margin-top: 4px;
  box-shadow: 0 8px 20px rgba(108, 140, 255, 0.35);
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.15s;
}
.auth-submit:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(108, 140, 255, 0.45); }
.auth-submit:active:not(:disabled) { transform: translateY(0); }

.auth-error {
  background: rgba(255, 108, 122, 0.1); border: 1px solid rgba(255, 108, 122, 0.4);
  color: var(--red); border-radius: 10px; padding: 10px 12px; font-size: 12.5px; line-height: 1.5;
}
.auth-note { color: var(--muted); font-size: 11.5px; line-height: 1.6; text-align: center; margin-top: 18px; }
