/* ─────────────────────────────────────────────
   对话解疑
   沿用 style.css 里的配色变量，不引入新色板
   ───────────────────────────────────────────── */

.chat-shell {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--white);
  box-shadow: 0 12px 32px rgba(24, 43, 80, .06);
  overflow: hidden;
}

/* ── 顶部信息栏 ── */
.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: #fbfcff;
}

.chat-id { display: flex; align-items: center; gap: 9px; font-size: .92rem; }
.chat-id b { font-weight: 800; letter-spacing: -.02em; }
.chat-id span { color: #8390a4; font-size: .78rem; }
.chat-id .dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: #28c07a;
  box-shadow: 0 0 0 3px #d9f5e7;
}

.chat-actions { display: flex; align-items: center; gap: 9px; }

.think-toggle {
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: #5c6a80;
  font: inherit;
  font-size: .8rem;
  font-weight: 700;
  cursor: pointer;
  transition: .18s;
}
.think-toggle:hover { border-color: #b8c8f5; color: var(--blue); }
.think-toggle.on {
  border-color: transparent;
  background: var(--blue);
  color: #fff;
  box-shadow: 2px 2px 0 #c7d4ff;
}

.ghost-btn {
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: #5c6a80;
  font: inherit;
  font-size: .8rem;
  font-weight: 700;
  cursor: pointer;
  transition: .18s;
}
.ghost-btn:hover { border-color: #b8c8f5; color: var(--blue); }

/* ── 消息区 ── */
.chat-log {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 230px;
  max-height: min(58vh, 540px);
  padding: 20px 18px;
  overflow-y: auto;
  background: linear-gradient(#fff, #fbfcfe);
}
.chat-log::-webkit-scrollbar { width: 10px; }
.chat-log::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 99px;
  background: #dbe3f0;
  background-clip: content-box;
}
.chat-log::-webkit-scrollbar-thumb:hover { background: #c3cfe4; background-clip: content-box; }

/* ── 初始引导 ── */
.chat-hello { display: flex; flex-direction: column; gap: 14px; padding: 4px 2px 2px; }
.chat-hello[hidden] { display: none; }
.chat-hello p { margin: 0; color: var(--muted); font-size: .9rem; line-height: 1.7; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 13px;
  border: 1px dashed #c4cfe6;
  border-radius: 999px;
  background: #fff;
  color: #4d5c74;
  font: inherit;
  font-size: .8rem;
  font-weight: 650;
  cursor: pointer;
  transition: .18s;
}
.chip:hover {
  border-style: solid;
  border-color: var(--blue);
  background: #f4f7ff;
  color: var(--blue);
}

/* ── 气泡 ── */
.msg { display: flex; }
.msg-user { justify-content: flex-end; }

.msg .bubble {
  max-width: min(88%, 640px);
  padding: 13px 15px;
  border-radius: 14px;
  font-size: .9rem;
  line-height: 1.75;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.msg-user .bubble {
  background: var(--blue);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.msg-bot .bubble {
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
  background: #fff;
  box-shadow: 0 4px 14px rgba(24, 43, 80, .04);
}
.msg-failed .bubble { border-color: #f0c9c9; background: #fffafa; }

/* ── 回答正文（Markdown 渲染结果） ── */
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p { margin: 0 0 9px; }
.md p.md-h { font-weight: 800; color: var(--ink); margin-bottom: 6px; }
.md ul, .md ol { margin: 0 0 9px; padding-left: 21px; }
.md li { margin: 4px 0; }
.md li > p { margin: 0; }
.md strong { font-weight: 800; }
.md code {
  padding: 1px 5px;
  border-radius: 5px;
  background: #eef2f9;
  color: #24406f;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Courier New", monospace;
  font-size: .86em;
}
.md pre {
  margin: 10px 0;
  padding: 12px 14px;
  overflow-x: auto;
  border-radius: 11px;
  background: #172642;
  color: #e6edfa;
}
.md pre code {
  padding: 0;
  background: none;
  color: inherit;
  font-size: .82rem;
  line-height: 1.65;
}
.md .katex-display { max-width: 100%; overflow-x: auto; overflow-y: hidden; padding: .15em 0; }
.md .katex { font-size: 1.05em; }
.md a { color: var(--blue); text-decoration: underline; text-underline-offset: 2px; }
.md a:hover { color: var(--blue-dark); }

/* 用户侧气泡是蓝底，里面的强调元素要换成浅色才看得清 */
.msg-user .bubble a { color: #fff; }
.msg-user .bubble code { background: rgba(255, 255, 255, .18); color: #fff; }

/* ── 思考过程折叠块 ── */
.think {
  margin: 0 0 11px;
  border-left: 3px solid var(--yellow);
  border-radius: 0 9px 9px 0;
  background: #fffbf0;
}
.think[hidden] { display: none; }
.think summary {
  padding: 8px 12px;
  color: #8a7327;
  font-size: .78rem;
  font-weight: 750;
  cursor: pointer;
  list-style: none;
}
.think summary::-webkit-details-marker { display: none; }
.think summary::before { content: "▸ "; }
.think[open] summary::before { content: "▾ "; }
.think-body {
  max-height: 220px;
  padding: 0 12px 11px;
  overflow-y: auto;
  color: #7b6a3f;
  font-size: .79rem;
  line-height: 1.7;
  white-space: pre-wrap;
}

/* ── 复制 / 字数 ── */
.msg-tools { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.msg-tools[hidden] { display: none; }
.msg-tools .meta { color: #93a0b4; font-size: .72rem; }
.mini {
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #6b7a92;
  font: inherit;
  font-size: .72rem;
  font-weight: 700;
  cursor: pointer;
  transition: .18s;
}
.mini:hover { border-color: #b8c8f5; color: var(--blue); }
.mini:disabled { opacity:.7; cursor:default; }
.review-context { margin:0 0 18px; padding:15px 18px; border:1px solid #cbd8f6; border-radius:12px; background:#edf3ff; color:#344e86; font-size:.86rem; line-height:1.7; }
.review-context[hidden] { display:none; }
.review-context a { margin-left:12px; color:var(--blue); font-weight:750; }
.bookmark-dialog { width:min(600px,calc(100% - 24px)); max-height:90vh; border:1px solid var(--line); border-radius:17px; padding:23px; color:var(--ink); box-shadow:0 20px 65px rgba(20,32,52,.22); }
.bookmark-dialog::backdrop { background:rgba(20,32,52,.55); }
.bookmark-dialog form { display:grid; gap:13px; }
.bookmark-heading { display:flex; align-items:center; justify-content:space-between; }
.bookmark-heading h2 { margin:0; font-size:1.35rem; }
.bookmark-heading button { border:0; background:none; font-size:1.6rem; cursor:pointer; }
.bookmark-dialog p { margin:0; color:var(--muted); font-size:.82rem; line-height:1.6; }
.bookmark-dialog label { display:grid; gap:5px; font-weight:700; font-size:.84rem; }
.bookmark-dialog :is(input,select,textarea) { width:100%; padding:9px 11px; border:1px solid var(--line); border-radius:9px; background:#fff; color:var(--ink); font:inherit; font-weight:400; font-size:.88rem; }
.bookmark-dialog textarea { resize:vertical; max-height:24vh; }
.bookmark-actions { display:flex; justify-content:end; gap:10px; }
.bookmark-actions button:first-child { border:1px solid var(--line); border-radius:9px; background:#fff; padding:8px 14px; cursor:pointer; }
#bookmark-status { color:#ba3030; }

/* ── 等待中的三点动画 ── */
.typing { display: inline-flex; align-items: center; gap: 5px; height: 18px; }
.typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #b6c3d8;
  animation: dotPulse 1.15s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes dotPulse {
  0%, 60%, 100% { opacity: .32; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* ── 错误提示 ── */
.err-line {
  margin: 8px 0 0;
  padding: 9px 11px;
  border-radius: 9px;
  background: #fff3f3;
  color: #b4232c;
  font-size: .82rem;
  line-height: 1.65;
}

/* ── 输入区 ── */
.chat-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 13px 14px;
  border-top: 1px solid var(--line);
  background: #fff;
}
.chat-entry { display: flex; align-items: flex-end; gap: 10px; }
.chat-photo-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.photo-btn {
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #f7f9ff;
  color: #40567c;
  font: inherit;
  font-size: .8rem;
  cursor: pointer;
}
.photo-btn:hover:not(:disabled) { border-color: #b8c8f5; color: var(--blue); }
.photo-btn:disabled { opacity: .5; cursor: not-allowed; }
.photo-status { color: #6a7991; font-size: .76rem; line-height: 1.4; }
.chat-photo-preview { display: flex; align-items: center; gap: 10px; }
.chat-photo-preview[hidden] { display: none; }
.chat-photo-preview img { width: 58px; height: 58px; border: 1px solid var(--line); border-radius: 9px; object-fit: cover; }
.chat-photo-preview span { color: var(--muted); font-size: .8rem; }
.chat-photo-preview button {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: #b4232c;
  font: inherit;
  font-size: .8rem;
  cursor: pointer;
}
.msg-photo { display: block; max-width: min(100%, 280px); max-height: 340px; margin-bottom: 8px; border-radius: 9px; object-fit: contain; }
.chat-form textarea {
  flex: 1;
  min-width: 0; /* 没有这一行，窄屏上长文本会把按钮挤出容器 */
  min-height: 46px;
  max-height: 160px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fbfcfe;
  color: var(--ink);
  font: inherit;
  font-size: .92rem;
  line-height: 1.5;
  resize: none;
  outline: 0;
  transition: border-color .18s, box-shadow .18s, background .18s;
}
.chat-form textarea:focus {
  border-color: #b8c8f5;
  background: #fff;
  box-shadow: 0 0 0 3px #eef3ff;
}
.chat-form textarea::placeholder { color: #95a1b5; }
.chat-form textarea:disabled { opacity: .6; }

.send-btn {
  flex: none;
  height: 46px;
  padding: 0 22px;
  border: 0;
  border-radius: 13px;
  background: var(--blue);
  color: #fff;
  font: inherit;
  font-size: .9rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 3px 3px 0 #c7d4ff;
  transition: .18s;
}
.send-btn:hover:not(:disabled) { background: var(--blue-dark); }
.send-btn:disabled { opacity: .5; box-shadow: none; cursor: not-allowed; }

.stop-btn {
  flex: none;
  height: 46px;
  padding: 0 17px;
  border: 1px solid #f0c9c9;
  border-radius: 13px;
  background: #fff6f6;
  color: #b4232c;
  font: inherit;
  font-size: .85rem;
  font-weight: 750;
  cursor: pointer;
  transition: .18s;
}
.stop-btn:hover { background: #ffecec; }
.stop-btn[hidden] { display: none; }

.chat-tip {
  margin: 0;
  padding: 0 16px 14px;
  color: #93a0b4;
  font-size: .74rem;
  line-height: 1.7;
}

/* ── 窄屏 ── */
@media (max-width: 760px) {
  .chat-head { padding: 12px 14px; }
  .chat-id span { display: none; }
  .chat-log { min-height: 200px; max-height: 62vh; padding: 14px 13px; }
  .msg .bubble { max-width: 94%; }
  .chat-form { padding: 11px; gap: 8px; }
  .chat-entry { gap: 8px; }
  .send-btn { padding: 0 18px; }
  .chat-tip { padding: 0 13px 12px; }
}
