/* 全局重置 + 主题语义变量 + 少量 Chat 布局兜底。
   组件外观一律走 AntD（ConfigProvider algorithm + token）；这里只保留
   Chat 页气泡/会话列表等无法用现成组件表达的自定义布局类。 */

:root {
  /* 让原生表单控件（date input / 滚动条 / 复选框）随主题自动取色，避免暗色下渲染浅色系统控件 */
  color-scheme: dark;
  --bg: #0f1216;
  --panel: #171b21;
  --panel-2: #1e232b;
  --text: #e6e9ee;
  --muted: #8b95a3;
  --accent: #4f8cff;
  --accent-2: #3ddc97;
  --border: #2a3038;
  --danger: #ff5c5c;
  /* 动效与圆角的统一刻度：页面不再各写各的 0.2s/6px */
  --dur-fast: 120ms;
  --dur-base: 200ms;
  --radius-sm: 6px;
  --radius-md: 8px;
  --focus-ring: 2px solid var(--accent);
}

/* 明色主题：随 <html data-theme="light"> 覆盖语义变量，让残余自定义 CSS 与 AntD 算法同步 */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --text: #1f2329;
  --muted: #6b7785;
  --accent: #4f8cff;
  --accent-2: #34c77b;
  --border: #e3e6eb;
  --danger: #d9363e;
  --focus-ring: 2px solid var(--accent);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* Phase 12: 会话列表 + 消息区双栏布局。
   外层 Layout 已固定为 100vh 视口、Content 内部滚动，这里撑满 Content 内容盒即可，
   不再用 calc(100vh - 固定值) 硬编高度（顶栏/内边距一变就溢出、整页滚动）。 */
.chat-wrap {
  display: flex;
  gap: 16px;
  height: 100%;
  min-height: 0;
}

.conv-list {
  width: 240px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 0;
  min-height: 0;
}

/* 会话列表与主区之间的可拖拽分隔条：默认细线，悬停/拖动时高亮加粗 */
.conv-resizer {
  flex-shrink: 0;
  align-self: stretch;
  width: 16px;
  margin-left: -8px;
  margin-right: -8px;
  cursor: col-resize;
  position: relative;
  background: transparent;
  z-index: 1;
}

.conv-resizer::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 1px;
  background: var(--border);
  transition: width 0.15s ease, background 0.15s ease;
}

.conv-resizer:hover::after,
.conv-resizer:active::after {
  width: 3px;
  background: var(--accent);
}

/* 拖拽期间全局光标与禁选，避免选中列表文字 */
body.conv-resizing {
  cursor: col-resize;
  user-select: none;
}

.conv-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.conv-group-label {
  font-size: 11px;
  color: var(--muted);
  padding: 10px 6px 4px;
  letter-spacing: 0.02em;
}

.conv-list .conv-item {
  position: relative;
  display: flex;
  align-items: center;
  padding: 8px 6px;
  border-radius: 8px;
  cursor: pointer;
  outline: none;
}

.conv-list .conv-item:hover,
.conv-list .conv-item:focus-visible {
  background: var(--panel-2);
}

.conv-list .conv-item.active {
  background: var(--panel-2);
}

/* 选中态左侧强调条，一眼定位当前会话 */
.conv-list .conv-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 3px;
  background: var(--accent);
}

.conv-item-body {
  flex: 1;
  min-width: 0;
}

.conv-item-title {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-item-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

/* 操作按钮：默认隐藏的右侧浮层，悬停/聚焦/选中时淡入并覆盖在标题之上 */
.conv-item-actions {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 2px;
  border-radius: 6px;
  background: var(--panel-2);
  opacity: 0;
  pointer-events: none;
  z-index: 2;
  transition: opacity 0.15s ease;
}

.conv-list .conv-item:hover .conv-item-actions,
.conv-list .conv-item:focus-within .conv-item-actions,
.conv-list .conv-item.active .conv-item-actions {
  opacity: 1;
  pointer-events: auto;
}

/* 对话内的关联目标卡：回复下方直达目标的运行/规划/产物，不再只是一枚按钮 */
.chat-goal-refs {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
}

.chat-goal-ref {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  font-size: 12px;
}

.chat-goal-ref-title {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.chat-goal-ref-jumps {
  display: inline-flex;
  align-items: center;
}

.chat-goal-ref-jumps .ant-btn {
  padding-inline: 4px;
  font-size: 12px;
  height: 20px;
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  position: relative;
}

.chat-log {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 8px 4px;
}

/* Phase 325 运行状态常驻头：贴顶一条细栏，与消息滚动同层。 */
.chat-run-header {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 8px;
  margin: -8px -4px 0;
  background: var(--ant-color-bg-container, #fff);
  border-bottom: 1px solid var(--border, #eee);
}

/* Phase 324 右侧「结果 / 计算机」可开合面板（.chat-wrap 已是 flex row，本栏占固定宽）。 */
.chat-result-pane {
  width: 360px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-left: 1px solid var(--border, #eee);
  padding-left: 12px;
}
.chat-result-pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border, #eee);
}
.chat-result-pane-body {
  flex: 1;
  overflow: auto;
  padding-top: 10px;
  min-height: 0;
}
.chat-result-brief {
  font-size: 13px;
  line-height: 1.55;
}
/* 收起态下右下角浮开的开启按钮（.chat 已 position: relative）。 */
.pane-open-fab {
  position: absolute;
  right: 28px;
  bottom: 150px;
  z-index: 5;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}

.msg {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
}

.msg.assistant {
  align-self: flex-start;
  background: var(--panel-2);
}

.chat-input {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.muted {
  color: var(--muted);
}

/* 助理气泡 Markdown 渲染：容器继承 pre-wrap 会把渲染结果里的空白重复算一次，必须归正 */
.md-body {
  white-space: normal;
  overflow-wrap: anywhere;
}

.md-body > :first-child {
  margin-top: 0;
}

.md-body > :last-child {
  margin-bottom: 0;
}

.md-body p,
.md-body ul,
.md-body ol {
  margin: 0.4em 0;
}

.md-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92em;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.5px 5px;
}

.md-body pre {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 30px 12px 10px;
  overflow: auto;
  position: relative;
}

/* Phase 335：代码块右上角复制钮（贴 .md-body pre 的相对定位）；走语义变量，明/暗一致。
   Phase 340：复制/下载合并为右上角工具条，另加左上角语言标签；配色沿用同一组语义变量。 */
.chat-code-actions {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 1;
  display: inline-flex;
  gap: 6px;
}
.chat-code-lang {
  position: absolute;
  top: 6px;
  left: 8px;
  z-index: 1;
  font-size: 11px;
  line-height: 1;
  font-family: ui-monospace, Menlo, monospace;
  color: var(--muted);
  opacity: 0.75;
  pointer-events: none;
}
.chat-code-copy {
  font-size: 11px;
  line-height: 1;
  padding: 3px 8px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
}
.chat-code-dl {
  font-size: 11px;
  line-height: 1;
  padding: 3px 8px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
}
.chat-code-copy:hover,
.chat-code-dl:hover {
  color: var(--text);
  opacity: 0.9;
}

.md-body pre code {
  background: none;
  border: none;
  padding: 0;
}

.md-body table {
  border-collapse: collapse;
  margin: 0.5em 0;
  display: block;
  overflow-x: auto;
}

/* Wave 4 Phase 348：块级表格横滚容器 + 右上角导出 CSV（滚动交给容器，表体回归 table 正常排版）。 */
.chat-table-wrap {
  position: relative;
  margin: 0.5em 0;
}
.chat-table-scroll {
  overflow-x: auto;
}
.chat-table-scroll table {
  display: table;
  margin: 0;
}
.chat-table-csv {
  position: absolute;
  top: 2px;
  right: 2px;
  z-index: 2;
  font-size: 11px;
  line-height: 1;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.chat-table-wrap:hover .chat-table-csv {
  opacity: 1;
}
.chat-mermaid {
  margin: 0.5em 0;
  text-align: center;
  overflow-x: auto;
}
.chat-mermaid svg {
  max-width: 100%;
  height: auto;
}

.md-body th,
.md-body td {
  border: 1px solid var(--border);
  padding: 4px 10px;
}

.md-body blockquote {
  margin: 0.4em 0;
  padding-left: 10px;
  border-left: 3px solid var(--border);
  color: var(--muted);
}

/* 阶段二十二 D：Markdown 链接与图片（走语义变量，随主题；图片限宽不溢出气泡）。 */
.md-body a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.md-body a:hover {
  opacity: 0.8;
}
.md-body img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
}

/* 气泡时间戳：不抢注意力，只供定位单条消息 */
.msg-time {
  display: block;
  font-size: 10px;
  line-height: 1;
  margin-top: 6px;
  color: var(--muted);
  white-space: normal;
}

.msg.user .msg-time {
  color: rgba(255, 255, 255, 0.75);
}

/* 引用重发：hover/聚焦气泡才浮现，不常驻占位 */
.msg-quote-actions {
  display: block;
  opacity: 0;
  transition: opacity 0.15s;
  white-space: normal;
}

.msg.user .msg-quote-actions .ant-btn {
  color: rgba(255, 255, 255, 0.85);
}

.msg:hover .msg-quote-actions,
.msg:focus-within .msg-quote-actions {
  opacity: 1;
}

/* 回到底部：浮在输入区右上角，列表滚动时不遮挡正文 */
.jump-bottom {
  position: absolute;
  right: 28px;
  bottom: 96px;
  z-index: 5;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}

/* 目标卡内联产物预览 */
.chat-goal-ref-wrap {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  max-width: 100%;
}

.chat-goal-artifacts {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--panel);
  font-size: 12px;
}

.chat-goal-artifact-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}

/* 空会话引导示例 */
.chat-suggest {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-self: center;
  margin-top: 16px;
  max-width: 80%;
  justify-content: center;
}

/* ---------------- 键盘可达与全局观感 ---------------- */
/* 只在键盘导航时显示焦点环：鼠标点击不出蓝框，Tab 遍历时必须有清晰落点。 */
:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* AntD 已自带焦点态的组件不重复描边，避免双框。 */
.ant-btn:focus-visible,
.ant-input:focus-visible,
.ant-select:focus-visible,
.ant-tabs-tab-btn:focus-visible {
  outline: none;
}

/* 可点击的非原生元素（会话项、通知行等）用同类交互态。 */
.ca-clickable {
  cursor: pointer;
  transition: background var(--dur-fast) ease;
}
.ca-clickable:hover {
  background: var(--panel-2);
}

/* 滚动条：跟随语义变量，明暗两主题都保持可见但不抢眼。 */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
*::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
  background-clip: content-box;
}
*::-webkit-scrollbar-track {
  background: transparent;
}

/* 尊重系统的「减少动效」偏好：仅收动效，不改布局与可读性。 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Markdown 正文里的代码块/表格：走语义变量，明暗两主题都可读，长行横向滚动。 */
.chat-md pre {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  overflow-x: auto;
  font-size: 12px;
  line-height: 1.6;
}
.chat-md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92em;
}
.chat-md p > code,
.chat-md li > code {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}
.chat-md table {
  border-collapse: collapse;
  display: block;
  overflow-x: auto;
  max-width: 100%;
  margin: 8px 0;
}
.chat-md th,
.chat-md td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
.chat-md th {
  background: var(--panel-2);
}
.chat-md blockquote {
  margin: 8px 0;
  padding: 2px 12px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}
/* 超长助理气泡折叠：默认限行，点开看全部。 */
.chat-md.chat-md-clamped {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 12;
  overflow: hidden;
}

/* 阶段二十一 B：流式打字指示（脉冲点 + 尾部光标，全走语义变量，随主题切换；受上方 prefers-reduced-motion 全局降级）。 */
.copilot-typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 2px 0;
}
.copilot-typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text);
  opacity: 0.35;
  animation: copilotPulse 1.2s infinite ease-in-out;
}
.copilot-typing i:nth-child(2) {
  animation-delay: 0.2s;
}
.copilot-typing i:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes copilotPulse {
  0%,
  80%,
  100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  40% {
    opacity: 0.9;
    transform: translateY(-2px);
  }
}
.copilot-caret {
  display: inline-block;
  width: 7px;
  height: 14px;
  margin-left: 2px;
  vertical-align: -2px;
  background: var(--accent);
  animation: copilotBlink 1s steps(2, start) infinite;
}
@keyframes copilotBlink {
  50% {
    opacity: 0;
  }
}

/* 阶段二十一 C：围栏代码块右上角语言角标（无语法高亮依赖）。 */
.md-code-lang {
  position: absolute;
  top: 6px;
  left: 10px;
  font-size: 11px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text);
  opacity: 0.5;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  pointer-events: none;
}

/* 阶段二十一 D：气泡动作按钮 hover/focus 收敛（DOM 常驻，仅透明度；键盘 focus 亦显）。 */
.copilot-msg-actions {
  opacity: 0;
  transition: opacity 0.15s ease;
}
.copilot-bubble:hover .copilot-msg-actions,
.copilot-bubble:focus-within .copilot-msg-actions {
  opacity: 1;
}

/* 阶段二十三 A：历史会话抽屉行内动作悬停/聚焦收敛（键盘可达） */
.thread-list .ant-list-item-action {
  opacity: 0;
  transition: opacity 0.15s ease;
}
.thread-list .ant-list-item:hover .ant-list-item-action,
.thread-list .ant-list-item:focus-within .ant-list-item-action {
  opacity: 1;
}

/* 编码 diff 审批 UX：unified diff 逐行着色（全用主题语义变量，随明/暗切换） */
.copilot-diff-add {
  color: var(--accent-2);
  background: color-mix(in srgb, var(--accent-2) 16%, transparent);
  display: inline-block;
  width: 100%;
}
.copilot-diff-del {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  display: inline-block;
  width: 100%;
}
.copilot-diff-hunk {
  color: var(--accent);
  opacity: 0.85;
}
.copilot-diff-ctx {
  color: var(--text);
}

/* 编码二期 WS-B：逐 hunk 审批视图（多块勾选 + Prism 语法着色），全用主题语义变量随明/暗切换 */
.copilot-diff-pre {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  background: var(--bg);
  color: var(--text);
  padding: 8px;
  margin: 0;
  overflow-x: auto;
  max-height: 300px;
  font-size: 12px;
  line-height: 1.5;
}
.copilot-diff-line {
  display: flex;
  align-items: flex-start;
  width: 100%;
  white-space: pre-wrap;
  word-break: break-word;
}
.copilot-diff-line.copilot-diff-add {
  background: color-mix(in srgb, var(--accent-2) 16%, transparent);
}
.copilot-diff-line.copilot-diff-del {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
}
.copilot-diff-sign {
  flex: 0 0 auto;
  width: 14px;
  user-select: none;
  opacity: 0.7;
}
.copilot-diff-code {
  flex: 1 1 auto;
  font-family: inherit;
  background: transparent;
  white-space: pre-wrap;
  word-break: break-word;
}
.copilot-diff-hunkbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
/* Prism token 着色：映射到主题语义变量，去掉 prism 默认背景，保证明/暗一致 */
.copilot-diff-code .token.comment,
.copilot-diff-code .token.prolog,
.copilot-diff-code .token.doctype,
.copilot-diff-code .token.cdata {
  color: var(--text);
  opacity: 0.5;
}
.copilot-diff-code .token.punctuation {
  opacity: 0.7;
}
.copilot-diff-code .token.keyword,
.copilot-diff-code .token.boolean,
.copilot-diff-code .token.number,
.copilot-diff-code .token.constant,
.copilot-diff-code .token.symbol {
  color: var(--accent);
}
.copilot-diff-code .token.string,
.copilot-diff-code .token.char,
.copilot-diff-code .token.attr-value,
.copilot-diff-code .token.template-string {
  color: var(--accent-2);
}
.copilot-diff-code .token.function,
.copilot-diff-code .token.class-name,
.copilot-diff-code .token.builtin {
  color: var(--accent);
}
.copilot-diff-code .token.property,
.copilot-diff-code .token.tag,
.copilot-diff-code .token.attr-name,
.copilot-diff-code .token.selector {
  color: var(--danger);
}

/* Phase 335：助理气泡代码块 token 着色，与 copilot diff 同色系、同语义变量（明/暗一致）。 */
.chat-code .token.comment,
.chat-code .token.prolog,
.chat-code .token.doctype,
.chat-code .token.cdata {
  color: var(--text);
  opacity: 0.5;
}
.chat-code .token.punctuation {
  opacity: 0.7;
}
.chat-code .token.keyword,
.chat-code .token.boolean,
.chat-code .token.number,
.chat-code .token.constant,
.chat-code .token.symbol {
  color: var(--accent);
}
.chat-code .token.string,
.chat-code .token.char,
.chat-code .token.attr-value,
.chat-code .token.template-string {
  color: var(--accent-2);
}
.chat-code .token.function,
.chat-code .token.class-name,
.chat-code .token.builtin {
  color: var(--accent);
}
.chat-code .token.property,
.chat-code .token.tag,
.chat-code .token.attr-name,
.chat-code .token.selector {
  color: var(--danger);
}

/* Wave 5 Phase 349 引用接地角标：正文里 [N] 渲染成可点小上标，主题感知色 + 键盘落点。 */
.chat-cite {
  color: var(--ant-primary-color, #1677ff);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.75em;
  padding: 0 2px;
  margin: 0 1px;
  border-radius: 3px;
  line-height: 1;
}
.chat-cite:hover {
  text-decoration: underline;
}
.chat-cite:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 1px;
}
