/* ============ 主题变量 ============ */
:root {
  --bg: #ffffff;
  --sb-bg: #f7f8fa;
  --sb-item-hover: #ececf1;
  --sb-item-active: #e4eafe;
  --text: #262a32;
  --text-2: #7b8088;
  --border: #e4e7ec;
  --border-2: #d4d8e0;
  --blue: #4d6bfe;
  --blue-hover: #3d5bf5;
  --blue-weak: #eef2ff;
  --user-bubble: #e8f1ff;
  --input-bg: #ffffff;
  --input-border: #e3e6ec;
  --hover-bg: #f2f4f7;
  --code-bg: #f6f8fa;
  --code-head: #edf0f4;
  --code-text: #24292f;
  --code-inline: #c7254e;
  --quote: #6b7280;
  --danger: #d93036;
  --think-text: #8a8f99;
  --think-bg: #f7f8fa;
  --shadow: 0 4px 18px rgba(30, 41, 59, .07);
  --menu-shadow: 0 12px 40px rgba(30, 41, 59, .16);
  --syn-kw: #cf222e;
  --syn-str: #0a7d34;
  --syn-com: #6e7781;
  --syn-num: #0550ae;
  --syn-fn: #8250df;
}
html[data-theme="dark"] {
  --bg: #1d1e23;
  --sb-bg: #15161a;
  --sb-item-hover: #26272d;
  --sb-item-active: #2a3a6e;
  --text: #e8eaed;
  --text-2: #9aa0a8;
  --border: #2b2d34;
  --border-2: #3a3d45;
  --blue: #4d6bfe;
  --blue-hover: #6a83ff;
  --blue-weak: #232a4d;
  --user-bubble: #33363e;
  --input-bg: #24262b;
  --input-border: #33363d;
  --hover-bg: #2a2c32;
  --code-bg: #16181c;
  --code-head: #1f2126;
  --code-text: #d5d9de;
  --code-inline: #f0a6c0;
  --quote: #9aa0a8;
  --danger: #f27073;
  --think-text: #8f949d;
  --think-bg: #1f2126;
  --shadow: 0 4px 18px rgba(0, 0, 0, .35);
  --menu-shadow: 0 12px 40px rgba(0, 0, 0, .5);
  --syn-kw: #ff7b72;
  --syn-str: #7ee787;
  --syn-com: #8b949e;
  --syn-num: #79c0ff;
  --syn-fn: #d2a8ff;
}

/* ============ 基础 ============ */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  overflow: hidden;
}
button { font-family: inherit; background: none; border: 0; color: inherit; cursor: pointer; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-2); }
::-webkit-scrollbar-track { background: transparent; }

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

/* ============ 侧栏 ============ */
#sidebar {
  width: 264px;
  background: var(--sb-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: width .18s ease, transform .22s ease;
  border-right: 1px solid var(--border);
}
#sidebar .sb-inner { display: flex; flex-direction: column; height: 100%; min-width: 264px; }
.sb-head { padding: 12px 14px 4px; display: flex; justify-content: flex-end; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2); transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--hover-bg); color: var(--text); }
.icon-btn svg { width: 19px; height: 19px; }

#newChatBtn {
  margin: 6px 14px 12px;
  padding: 10px 14px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--blue);
  color: #fff;
  border-radius: 13px;
  font-size: 14.5px;
  font-weight: 500;
  transition: background .15s, transform .06s;
}
#newChatBtn:hover { background: var(--blue-hover); }
#newChatBtn:active { transform: scale(.98); }
#newChatBtn svg { width: 17px; height: 17px; }

#chatList { flex: 1; overflow-y: auto; padding: 2px 10px 10px; }
.list-label {
  font-size: 12px; color: var(--text-2);
  padding: 10px 8px 6px; letter-spacing: .3px;
}
.chat-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; margin: 1px 0;
  border-radius: 10px; cursor: pointer;
  color: var(--text); font-size: 14px;
  transition: background .12s;
}
.chat-item:hover { background: var(--sb-item-hover); }
.chat-item.active { background: var(--sb-item-active); }
.chat-item > .ci-icon { color: var(--text-2); display: flex; flex-shrink: 0; }
.chat-item > .ci-icon svg { width: 16px; height: 16px; }
.chat-item .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .ops { display: none; gap: 2px; flex-shrink: 0; }
.chat-item:hover .ops { display: flex; }
.chat-item .ops button {
  width: 26px; height: 26px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2);
}
.chat-item .ops button:hover { background: var(--border-2); color: var(--text); }
.chat-item .ops svg { width: 14px; height: 14px; }
.empty-list { color: var(--text-2); font-size: 13px; text-align: center; padding: 18px 0; }

.sb-foot {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.sb-foot-note { flex: 1; text-align: right; font-size: 11.5px; color: var(--text-2); }

/* 折叠状态 */
body.sb-collapsed #sidebar { width: 0; border-right: 0; }
#expandBtn {
  position: fixed; left: 14px; top: 14px; z-index: 40;
  background: var(--bg);
  box-shadow: var(--shadow);
  display: flex;
}
body:not(.sb-collapsed) #expandBtn { display: none !important; }

/* ============ 主区域 ============ */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.mobile-bar {
  display: none;
  align-items: center; gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.mobile-title { flex: 1; text-align: center; font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#chatScroll { flex: 1; overflow-y: auto; overflow-x: hidden; }
#messages { max-width: 758px; margin: 0 auto; padding: 20px 18px 6px; }

/* 欢迎页 */
#chatScroll.home { display: flex; }
#chatScroll.home #messages {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; padding-bottom: 8vh;
}
.welcome h1 { font-size: 27px; font-weight: 700; margin: 18px 0 10px; }
.welcome p { color: var(--text-2); font-size: 16.5px; line-height: 1.7; }
.welcome-logo {
  width: 62px; height: 62px; border-radius: 19px;
  background: var(--blue);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 26px rgba(77, 107, 254, .35);
  overflow: hidden;
}
.welcome-logo img, .welcome-logo svg { width: 100%; height: 100%; display: block; object-fit: contain; border-bottom: none !important; }
/* 移除所有图标元素可能继承的蓝色底部边框 */
svg { border-bottom: none !important; }
.pill svg, .icon-btn svg, .welcome-logo svg, .avatar svg { border-bottom: none !important; }
.conn-error {
  margin-top: 22px; max-width: 420px;
  border: 1px solid rgba(217, 48, 54, .4); background: rgba(217, 48, 54, .06);
  color: var(--danger); border-radius: 13px; padding: 13px 17px;
  font-size: 13.5px; line-height: 1.6; text-align: left;
}

/* ============ 消息 ============ */
.msg { margin: 16px 0; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble {
  background: var(--user-bubble);
  padding: 11px 17px;
  border-radius: 18px;
  max-width: 82%;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.65;
  font-size: 15px;
}
.msg.assistant { display: flex; gap: 13px; }
.avatar {
  width: 33px; height: 33px; border-radius: 50%;
  background: var(--blue); color: #fff;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  margin-top: 2px;
}
.avatar svg { width: 21px; height: 21px; }
.msg .body { flex: 1; min-width: 0; }
.content { line-height: 1.78; font-size: 15.5px; word-break: break-word; }

/* 流式光标 */
.cursor {
  display: inline-block;
  width: 7px; height: 17px;
  border-radius: 2px;
  background: var(--text-2);
  vertical-align: -2px;
  margin-left: 2px;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

/* 正在思考 */
.status { color: var(--text-2); font-size: 14px; display: flex; align-items: center; gap: 9px; padding: 4px 0; }
.dots { display: inline-flex; gap: 4px; }
.dots i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-2);
  animation: bounce 1.2s infinite ease-in-out;
}
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

/* 深度思考折叠块 */
details.thinking {
  margin: 2px 0 10px;
  border-radius: 13px;
  background: var(--think-bg);
  padding: 0 15px;
}details.thinking summary {
  list-style: none;
  cursor: pointer;
  color: var(--text-2);
  font-size: 13.5px;
  padding: 10px 0;
  display: flex; align-items: center; gap: 6px;
  user-select: none;
}
details.thinking summary::-webkit-details-marker { display: none; }
details.thinking summary svg { width: 14px; height: 14px; flex-shrink: 0; }
details.thinking summary .chev { transition: transform .15s; }
details.thinking[open] summary .chev { transform: rotate(180deg); }
details.thinking .think-body {
  color: var(--think-text);
  font-size: 13.5px;
  line-height: 1.7;
  white-space: pre-wrap;
  border-top: 1px dashed var(--border-2);
  padding: 9px 0 12px;
  max-height: 340px;
  overflow-y: auto;
}

/* 联网搜索来源折叠块 */
details.sources {
  margin: 2px 0 10px;
  border-radius: 13px;
  background: var(--think-bg);
  padding: 0 15px;
}
details.sources summary {
  list-style: none;
  cursor: pointer;
  color: var(--text-2);
  font-size: 13.5px;
  padding: 10px 0;
  display: flex; align-items: center; gap: 6px;
  user-select: none;
}
details.sources summary::-webkit-details-marker { display: none; }
details.sources summary svg { width: 14px; height: 14px; flex-shrink: 0; }
details.sources summary .chev { transition: transform .15s; }
details.sources[open] summary .chev { transform: rotate(180deg); }
details.sources .src-list {
  list-style: none;
  border-top: 1px dashed var(--border-2);
  padding: 4px 0 10px;
  margin: 0;
  max-height: 320px;
  overflow-y: auto;
}
.src-list li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.src-list li:last-child { border-bottom: 0; padding-bottom: 2px; }
.src-list .src-none { color: var(--text-2); font-size: 12.5px; border: 0; }
.src-title { font-size: 13.5px; line-height: 1.5; }
.src-title a { color: var(--blue); text-decoration: none; word-break: break-all; }
.src-title a:hover { text-decoration: underline; }
.src-meta { color: var(--text-2); font-size: 11.5px; margin-top: 2px; }
.src-snip { color: var(--text-2); font-size: 12.5px; line-height: 1.55; margin-top: 3px; }
.search-note { color: var(--text-2); font-size: 12.5px; margin: 4px 0 10px; }

/* 错误提示 */
.errbox {
  border: 1px solid rgba(217, 48, 54, .45);
  background: rgba(217, 48, 54, .06);
  color: var(--danger);
  border-radius: 13px;
  padding: 11px 15px;
  font-size: 13.5px;
  line-height: 1.6;
  margin: 6px 0;
}

/* 消息操作 */
.actions { display: flex; gap: 4px; margin-top: 6px; opacity: 0; transition: opacity .15s; }
.msg.assistant:hover .actions { opacity: 1; }
.actions button {
  width: 29px; height: 29px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2);
}
.actions button:hover { background: var(--hover-bg); color: var(--text); }
.actions svg { width: 15.5px; height: 15.5px; }

/* ============ Markdown ============ */
.content p { margin: .55em 0; }
.content > :first-child { margin-top: 0; }
.content > :last-child { margin-bottom: 0; }
.content h1, .content h2, .content h3, .content h4 { margin: 1em 0 .45em; line-height: 1.4; }
.content h1 { font-size: 1.42em; }
.content h2 { font-size: 1.25em; }
.content h3 { font-size: 1.12em; }
.content h4 { font-size: 1em; }
.content ul, .content ol { padding-left: 1.5em; margin: .55em 0; }
.content li { margin: .28em 0; }
.content li.task { list-style: none; display: flex; gap: 8px; align-items: baseline; margin-left: -1.3em; }
.content li.task input { accent-color: var(--blue); }
.content a { color: var(--blue); text-decoration: none; }
.content a:hover { text-decoration: underline; }
.content blockquote { border-left: 3px solid var(--border-2); color: var(--quote); padding: 2px 14px; margin: .7em 0; }
.content hr { border: 0; border-top: 1px solid var(--border); margin: 1em 0; }
.content img { max-width: 100%; border-radius: 10px; }
.content code.ic {
  background: rgba(77, 107, 254, .09);
  color: var(--code-inline);
  padding: 2px 6px;
  border-radius: 6px;
  font-family: Consolas, "Courier New", "SF Mono", monospace;
  font-size: .88em;
}
.content table { border-collapse: collapse; margin: .8em 0; display: block; overflow-x: auto; max-width: 100%; }
.content th, .content td { border: 1px solid var(--border); padding: 7px 13px; font-size: 14px; text-align: left; }
.content th { background: var(--think-bg); }

/* 代码块 */
.codeblock { border-radius: 13px; overflow: hidden; margin: .8em 0; border: 1px solid var(--border); }
.cb-head {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--code-head);
  padding: 7px 8px 7px 15px;
  font-size: 12.5px; color: var(--text-2);
  font-family: Consolas, "Courier New", monospace;
}
.cb-copy {
  display: flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 7px;
  color: var(--text-2); font-size: 12.5px;
  transition: background .12s, color .12s;
}
.cb-copy:hover { background: var(--border); color: var(--text); }
.cb-copy svg { width: 13.5px; height: 13.5px; }
.codeblock pre {
  margin: 0; padding: 14px 16px;
  overflow-x: auto;
  background: var(--code-bg);
  line-height: 1.62;
  font-size: 13.2px;
  font-family: Consolas, "Courier New", "SF Mono", monospace;
  color: var(--code-text);
}
.tok-kw { color: var(--syn-kw); }
.tok-str { color: var(--syn-str); }
.tok-com { color: var(--syn-com); }
.tok-num { color: var(--syn-num); }
.tok-fn { color: var(--syn-fn); }

/* ============ 输入区 ============ */
#inputPanel { padding: 0 16px 14px; background: linear-gradient(to bottom, transparent, var(--bg) 26px); }
#inputWrap { max-width: 758px; margin: 0 auto; }
#inputBox {
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 13px 16px 10px;
  transition: border-color .15s;
}
#inputBox:focus-within { border-color: rgba(77, 107, 254, .55); }
#input {
  width: 100%;
  border: 0; outline: 0; resize: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  line-height: 1.6;
  max-height: 220px;
  padding: 2px 4px;
}
#input::placeholder { color: var(--text-2); }
.ctl-row { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; padding: 0 2px; }
.ctl-left { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 13px;
  border-radius: 999px;
  border: 1px solid var(--border-2);
  color: var(--text-2);
  font-size: 13px;
  transition: all .15s;
  background: transparent;
}
.pill:hover { color: var(--text); border-color: var(--text-2); }
.pill svg { width: 15px; height: 15px; }
.pill.on { color: var(--blue); border-color: rgba(77, 107, 254, .5); background: rgba(77, 107, 254, .08); }
.pill .chev { width: 13px; height: 13px; transition: transform .15s; }

/* ---------- 文件上传预览 ---------- */
#uploadBtn { cursor: pointer; }
#uploadBtn svg { width: 15px; height: 15px; }
#filePreview {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 6px; padding: 8px;
  border-radius: 10px;
  background: rgba(77, 107, 254, .06);
  border: 1px solid rgba(77, 107, 254, .15);
}
.fp-item {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 8px 4px 4px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
}
.fp-thumb { width: 32px; height: 32px; object-fit: cover; border-radius: 5px; background: #f0f2f5; }
.fp-info { min-width: 0; }
.fp-name { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font-weight: 500; }
.fp-size { color: var(--text-2); font-size: 11px; }
.fp-del {
  width: 20px; height: 20px; border-radius: 50%; border: none; background: transparent;
  color: var(--text-2); cursor: pointer; font-size: 14px; line-height: 1;
}
.fp-del:hover { background: rgba(0,0,0,.06); color: #ff3b30; }
@media (prefers-color-scheme: dark) {
  #filePreview { background: rgba(77, 107, 254, .12); border-color: rgba(77, 107, 254, .25); }
  .fp-item { background: #1f2128; border-color: #2d3039; }
}

#sendBtn {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, transform .06s;
  flex-shrink: 0;
}
#sendBtn svg { width: 19px; height: 19px; margin-left: -1px; }
#sendBtn:hover:not(:disabled) { background: var(--blue-hover); }
#sendBtn:active:not(:disabled) { transform: scale(.94); }
#sendBtn:disabled { background: var(--border-2); cursor: default; }
#sendBtn.stop { background: var(--text); }

.disclaimer { text-align: center; color: var(--text-2); font-size: 12px; margin-top: 10px; }

/* ============ 模型菜单 ============ */
.msel { position: relative; }
.msel-menu {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 0;
  min-width: 292px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 15px;
  box-shadow: var(--menu-shadow);
  padding: 7px;
  display: none;
  z-index: 60;
  max-height: 62vh;
  overflow-y: auto;
}
.msel-menu.open { display: block; }
.ms-group {
  font-size: 11.5px; color: var(--text-2);
  padding: 9px 10px 5px;
  letter-spacing: .3px;
}
.ms-hint {
  font-size: 11.5px; color: var(--text-2);
  padding: 4px 10px 7px;
  line-height: 1.55;
}
.ms-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text);
}
.ms-item:hover { background: var(--hover-bg); }
.ms-item .ms-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-item .check { color: var(--blue); display: flex; }
.ms-item .check svg { width: 15px; height: 15px; }
.ms-item .ms-del {
  width: 22px; height: 22px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2);
}
.ms-item .ms-del:hover { background: var(--border-2); color: var(--danger); }
.ms-item .ms-del svg { width: 12px; height: 12px; }
.ms-custom { border-top: 1px solid var(--border); margin-top: 5px; padding-top: 3px; }
.cus-row { display: flex; gap: 6px; padding: 4px 8px 8px; }
.cus-row select {
  flex-shrink: 0;
  border: 1px solid var(--border-2);
  background: var(--bg);
  color: var(--text);
  border-radius: 8px;
  font-size: 12.5px;
  padding: 0 4px;
  outline: none;
}
.cus-row input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border-2);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 12.5px;
  padding: 6px 9px;
  outline: none;
}
.cus-row input:focus { border-color: var(--blue); }
.cus-row button {
  border: 1px solid rgba(77, 107, 254, .5);
  color: var(--blue);
  border-radius: 8px;
  padding: 0 12px;
  font-size: 12.5px;
}
.cus-row button:hover { background: rgba(77, 107, 254, .08); }

/* ============ 移动端 ============ */
#overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.42); z-index: 45; }

@media (max-width: 820px) {
  #sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 50;
    transform: translateX(-102%);
    box-shadow: var(--menu-shadow);
    width: 274px;
  }
  body.sb-open #sidebar { transform: translateX(0); }
  body.sb-open #overlay { display: block; }
  body.sb-collapsed #sidebar { width: 274px; }
  .mobile-bar { display: flex; }
  #expandBtn { display: none !important; }
  .welcome h1 { font-size: 22px; }
  .welcome p { font-size: 15px; }
  #messages { padding: 14px 14px 6px; }
  .msg.user .bubble { max-width: 92%; }
}
