/* 消息区：用户气泡、助手正文、Markdown 排版、附件、输入中 */

.msg { display: flex; padding: 12px 0; animation: rise .2s ease both; }
.msg.user { justify-content: flex-end; }
.msg .body { min-width: 0; max-width: 100%; }
.msg.user .body { max-width: 78%; display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .content {
  background: var(--user-bubble); border-radius: var(--radius-lg); padding: 10px 16px;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.assistant .content { overflow-wrap: anywhere; }
.msg .content > *:first-child { margin-top: 0; }
.msg .content > *:last-child { margin-bottom: 0; }

.actions { display: flex; align-items: center; gap: 6px; margin-top: 4px; opacity: 0; transition: opacity .12s; }
.msg:hover .actions, .actions:focus-within { opacity: 1; }
.actions .time { font-size: 11.5px; color: var(--text-3); }
.act {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 8px; border: 0;
  background: none; border-radius: var(--radius-sm); color: var(--text-3); font-size: 12px;
}
.act:hover { background: var(--surface-hover); color: var(--text); }
.act .i { width: 14px; height: 14px; }

.content p { margin: 10px 0; }
.content h2, .content h3, .content h4 { margin: 16px 0 6px; font-weight: 600; letter-spacing: -.01em; }
.content h2 { font-size: 19px; } .content h3 { font-size: 17px; } .content h4 { font-size: 15.5px; }
.content ul, .content ol { margin: 8px 0; padding-left: 24px; }
.content li { margin: 3px 0; }
.content blockquote { margin: 10px 0; padding: 2px 0 2px 14px; border-left: 3px solid var(--border-2); color: var(--text-2); }
.content hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.content table { border-collapse: collapse; margin: 8px 0; font-size: 14px; }
.content th, .content td { border: 1px solid var(--border); padding: 6px 12px; text-align: left; }
.content th { background: var(--sidebar); font-weight: 600; }
/* 代码框：复制按钮/语言标签浮在块内右上角（ChatGPT 那种） */
.codeblock {
  position: relative; margin: 12px 0; border: 1px solid var(--border);
  border-radius: var(--radius-md); overflow: hidden; background: var(--code-bg);
}
.content pre {
  position: relative; background: var(--code-bg); border: 0;
  padding: 12px 14px; overflow-x: auto; font-size: 13.5px; margin: 0;
}
.content .codeblock pre code { background: none; padding: 0; }
.codetools {
  position: absolute; top: 6px; right: 8px; display: flex; align-items: center; gap: 8px;
  opacity: 0; transition: opacity .14s;
  /* 消息区有 overflow-wrap:anywhere（继承），会干扰收缩宽度计算，这里重置并显式按内容撑开 */
  white-space: nowrap; overflow-wrap: normal; word-break: normal; width: max-content;
}
.codetools > * { flex: none; }
.codeblock:hover .codetools, .codeblock:focus-within .codetools { opacity: 1; }
@media (pointer: coarse) { .codetools { opacity: 1; } }
.codelang {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px;
  color: var(--text-3); letter-spacing: .02em; user-select: none;
}
.codecopy {
  display: inline-flex; align-items: center; gap: 4px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 6px; background: var(--surface);
  color: var(--text-2); font-size: 11px; padding: 3px 8px;
}
.codecopy:hover { background: var(--control-hover); color: var(--text); }
.codecopy .i, .codecopy svg { width: 12px; height: 12px; }

/* 块级元素工具条（导出图片） */
.blockwrap { position: relative; }
.blocktools {
  position: absolute; top: 4px; right: 4px; z-index: 2; opacity: 0; transition: opacity .12s;
}
.blockwrap:hover .blocktools { opacity: 1; }
.blockimg {
  display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text-2); font-size: 11px; padding: 3px 8px; white-space: nowrap;
}
.blockimg:hover { background: var(--control-hover); color: var(--text); }
.tablewrap { display: block; overflow-x: auto; max-width: 100%; }

/* 导出用的离屏舞台 */
.export-stage {
  position: fixed; left: -20000px; top: 0; padding: 18px; color: var(--text);
  font: 15.5px/1.75 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
}

/* 公式 */
.math-display { display: block; overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.math-display .katex-display { margin: 6px 0; }
.math-inline { white-space: nowrap; }

/* 图片 / 删除线 / 任务列表 */
.mdimg { max-width: 100%; border-radius: var(--radius-md); border: 1px solid var(--border); margin: 6px 0; }
.content del { color: var(--text-3); }
.content ul li.task { list-style: none; margin-left: -18px; }
.content .taskbox {
  display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px;
  border: 1px solid var(--border-2); border-radius: 4px; margin-right: 7px;
  font-size: 11px; color: var(--ok); vertical-align: -2px;
}
.content li.task.done { color: var(--text-3); text-decoration: line-through; }
.content code {
  background: var(--code-inline); padding: 1.5px 5px; border-radius: 5px; font-size: 13.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.content pre code { background: none; padding: 0; }
.content a { color: var(--link); text-decoration: underline; text-underline-offset: 2px; word-break: break-all; }

.files { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.imgbox { position: relative; max-width: 340px; }
.imgbox img { width: 100%; border-radius: var(--radius-md); border: 1px solid var(--border); display: block; cursor: zoom-in; }
.imgtools { position: absolute; top: 8px; right: 8px; display: flex; gap: 6px; opacity: 0; transition: opacity .12s; }
.imgbox:hover .imgtools { opacity: 1; }
.itool {
  width: 30px; height: 30px; border-radius: var(--radius-sm); border: 1px solid rgba(255,255,255,.2);
  display: flex; align-items: center; justify-content: center; background: rgba(20,20,20,.7);
  color: #fff; text-decoration: none; padding: 0;
}
.itool:hover { background: rgba(20,20,20,.9); }
.filecard {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: var(--radius-md);
  border: 1px solid var(--border); background: var(--surface); color: inherit; text-decoration: none;
  font-size: 14px; max-width: 360px;
}
.filecard:hover { background: var(--surface-hover); }
.ext {
  width: 36px; height: 36px; border-radius: var(--radius-sm); display: flex; align-items: center;
  justify-content: center; flex: none; font-size: 9px; font-weight: 700; letter-spacing: .04em;
  color: #fff; background: #6b7280;
}
.ext.pdf { background: #b42318; } .ext.doc { background: #175cd3; } .ext.xls { background: #067647; }
.ext.ppt { background: #b54708; } .ext.zip { background: #7a5af8; } .ext.img { background: #7f56d9; }
.ext.audio { background: #c11574; } .ext.video { background: #3538cd; } .ext.code { background: #0e7090; }
.ext.txt { background: #667085; }
.filecard .fmeta { min-width: 0; flex: 1; }
.filecard .fname { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.filecard .fsize { color: var(--text-3); font-size: 12px; }
.filecard .fdl { color: var(--text-3); flex: none; display: flex; }
.filecard:hover .fdl { color: var(--text); }

.typing { color: var(--text-3); font-size: 13.5px; padding: 4px 0 8px; }
.typing .dots span {
  display: inline-block; width: 5px; height: 5px; margin-right: 3px; border-radius: 50%;
  background: var(--text-3); animation: blink 1.2s infinite both;
}
.typing .dots span:nth-child(2) { animation-delay: .2s; }
.typing .dots span:nth-child(3) { animation-delay: .4s; }

/* Review: keep dense data readable and expose touch actions. */
.msg.assistant .body { width: 100%; }
.content { line-height: 1.7; }
.content li > ul, .content li > ol { margin: 4px 0; padding-left: 24px; }
.tablewrap table { min-width: max-content; max-width: none; }
.tablewrap th, .tablewrap td { min-width: 7em; max-width: 28em; overflow-wrap: normal; word-break: normal; }
.tablewrap th { white-space: nowrap; }
.codeblock .codetools { position: static; opacity: 1; width: auto; justify-content: space-between; padding: 6px 12px; border-bottom: 1px solid var(--border); }
.content pre { white-space: pre; overflow-wrap: normal; word-break: normal; }
.actions { opacity: 1; flex-wrap: wrap; }
.blocktools:focus-within { opacity: 1; }
@media (hover: none), (max-width: 600px) { .blocktools { opacity: 1; position: static; text-align: right; } .act { min-height: 40px; } }
.msg.search-hit { outline: 2px solid var(--brand, #2563eb); outline-offset: 4px; border-radius: 8px; }

.export-stage { width: max-content; max-width: none; }
.export-stage .tablewrap { overflow: visible; }

.msg { animation: none; }
.msg.assistant .body { width: 100%; }
.content :is(.math-inline, .katex-display, .tablewrap) { max-width: 100%; overflow-x: auto; }
.content .math-inline { display: inline-block; vertical-align: middle; }
.content .blockwrap { min-width: 0; max-width: 100%; overflow-x: auto; }
.typing { display: flex; align-items: flex-start; flex-wrap: wrap; gap: 10px; padding: 12px 0; font-size: 13px; color: var(--text-2); }
.task-state { font-weight: 600; color: var(--text); white-space: nowrap; }
.typing-text { min-width: 0; overflow-wrap: anywhere; }
.run-events { border: 0; border-block: 1px solid var(--border); border-radius: 0; padding: 16px 0; }
.run-events summary { min-height: 36px; font-weight: 500; }
.run-event-list { margin: 8px 0 0; padding-left: 24px; }
.run-event-list li { padding: 8px 0; overflow-wrap: anywhere; line-height: 1.6; }
@media (hover: none), (max-width: 640px) { .actions { opacity: 1; } .act { min-height: 44px; } .codecopy, .blockimg { min-height: 36px; } }
