/* @layer ui — 助手回复的安全 Markdown / 数学排版。
 *
 * 用户消息不使用本文件：用户说过的话保持原样。助手的长回复沿用 Chat 的编辑式排版，
 * 不再用一堵气泡包住；浮窗仅在短回复上保留一层轻纸面。
 */

.rich-text {
  min-width: 0;
  display: grid;
  gap: 0.78em;
  color: var(--text);
  font-size: var(--fs-body);
  line-height: 1.72;
  overflow-wrap: anywhere;
}

.rich-text > :first-child { margin-top: 0; }
.rich-text > :last-child { margin-bottom: 0; }
.rich-text p { margin: 0; color: var(--text); }
.rich-text strong { font-weight: 650; color: var(--text); }
.rich-text em { font-style: italic; }

.rich-heading {
  margin: 0.38em 0 0;
  color: var(--text);
  font-family: var(--font-display);
  font-weight: 640;
  letter-spacing: var(--tracking-title);
  line-height: 1.36;
}
.rich-heading--1 { font-size: var(--fs-title); }
.rich-heading--2 { font-size: var(--fs-lead); }
.rich-heading--3,
.rich-heading--4,
.rich-heading--5,
.rich-heading--6 { font-size: var(--fs-body); }

.rich-text ul,
.rich-text ol {
  margin: 0;
  padding-left: 1.45em;
  display: grid;
  gap: 0.34em;
}
.rich-text li { padding-left: 0.12em; }
.rich-text li::marker { color: var(--text-faint); font-variant-numeric: tabular-nums; }

/* 0.6.0：嵌套列表。子列表紧贴它的父项（不另起一段的间距），换一种点，一眼看得出层级。 */
.rich-text li > ul,
.rich-text li > ol { margin-top: 0.3em; gap: 0.26em; }
.rich-text li > ul { list-style-type: circle; }
.rich-text li > ul ul { list-style-type: square; }

/* 0.6.0：任务清单。只读的勾选框——这是回答里的「清单」写法，点它不会改任何记录，所以不做成控件、不给指针手势。 */
.rich-text .rich-tasks { list-style: none; padding-left: 0.1em; }
.rich-task { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.6em; padding-left: 0; }
.rich-task > ul,
.rich-task > ol { flex-basis: 100%; }
.rich-task__box {
  flex: none;
  position: relative;
  width: 0.92em;
  height: 0.92em;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-xs);
  transform: translateY(0.12em);
}
.rich-task.is-done .rich-task__box { border-color: var(--accent); background: var(--accent); }
.rich-task.is-done .rich-task__box::after {
  content: "";
  position: absolute;
  left: 0.27em;
  top: 0.08em;
  width: 0.24em;
  height: 0.48em;
  border: solid var(--accent-text);
  border-width: 0 0.12em 0.12em 0;
  transform: rotate(45deg);
}
.rich-task__text { min-width: 0; flex: 1; }
.rich-task.is-done .rich-task__text { color: var(--text-faint); text-decoration: line-through; text-decoration-color: var(--border-strong); }

/* 0.6.0：分隔线。发丝线，与表格、代码块同一支笔。 */
.rich-rule { margin: 0.35em 0; border: 0; border-top: 1px solid var(--hairline); }

.rich-text blockquote {
  margin: 0.15em 0;
  padding: 0.2em 0 0.2em 0.95em;
  border-left: 2px solid var(--accent-line);
  color: var(--text-muted);
}
.rich-text blockquote .rich-text { color: inherit; gap: 0.52em; }
.rich-text blockquote p { color: inherit; }

.rich-text a {
  color: var(--accent-ink);
  text-decoration-line: underline;
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.18em;
}
/* 悬停原来换成 --accent-hover。那是"面"的那一支（--accent-l − 6%），深色下它是 58%，
   而链接常态用的 --accent-ink 在深色下是 78% —— 指上去墨色反而往背景方向跑，
   对比度从 5.10:1 掉到 3 出头。链接本来就带下划线，加重下划线就够了：
   墨一个字不动，反馈仍然看得见。 */
.rich-text a:hover { text-decoration-thickness: 0.14em; }
.rich-text a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: 0 0 0 3.5px var(--accent-soft);
  border-radius: var(--radius-xs);
}
.rich-link-unsafe { color: var(--text-faint); }

/* 等宽栈原来在这里又写了一遍，而且和 themes.css 的 --mono 不是同一份
   （那份第二顺位是 "SF Mono"，这份是 "SFMono-Regular"）：在装了 SF Mono 的 Mac 上，
   助手回复里的代码和 kbd / 账号 ID / 上下文预览用的是两款不同的字。走令牌。
   圆角同理：4px 不在字阶之外的任何一张表上，components.css 早就为同一枚内联代码芯片
   写过"圆角走 --radius-xs 而不是自己发明的 4px"，这里是漏网的那一处。 */
.rich-code-inline,
.rich-code-block code {
  font-family: var(--mono);
  font-variant-ligatures: none;
}
.rich-code-inline {
  padding: 0.08em 0.32em;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-xs);
  background: var(--surface-sunken);
  color: var(--text);
  font-size: 0.92em;
  white-space: break-spaces;
}
.rich-code-block {
  min-width: 0;
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  box-shadow: var(--shadow-inset);
}
.rich-code-block__label {
  display: block;
  padding: 7px 11px 0;
  color: var(--text-faint);
  font-size: var(--fs-micro);
  font-weight: 620;
  letter-spacing: var(--tracking-caps);
}
.rich-code-block pre {
  margin: 0;
  padding: 11px 13px;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  tab-size: 2;
}
.rich-code-block code {
  color: var(--text);
  font-size: var(--fs-small);
  line-height: 1.62;
  white-space: pre;
}

/**
 * 0.4.1 必修三（1）：表格。
 *
 * 与代码块同一条规矩：**宽内容自己横向滚，绝不把气泡撑破**（外层 wrap 负责滚动，
 * 表格本身不设最小宽度以外的约束）。线只用发丝线，表头只靠字重与底色分出来——
 * 这套视觉里没有「粗边框表格」这个角色。
 */
.rich-table-wrap {
  min-width: 0;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
}
.rich-table {
  border-collapse: collapse;
  width: 100%;
  font-size: var(--fs-small);
  line-height: 1.55;
}
.rich-table th,
.rich-table td {
  padding: 7px 11px;
  border-bottom: 1px solid var(--hairline);
  text-align: left;
  vertical-align: top;
  white-space: normal;
}
.rich-table thead th {
  background: var(--surface-sunken);
  color: var(--text);
  font-weight: 620;
  white-space: nowrap;
}
.rich-table tbody tr:last-child td { border-bottom: 0; }
/* 0.6.0：数字列对齐（时间、金额、次数竖着读要对得上位），第一列是行名，用令牌表的 medium（500，强调短语）。 */
.rich-table td { font-variant-numeric: tabular-nums; }
.rich-table tbody td:first-child { color: var(--text); font-weight: 500; }

.rich-math {
  color: var(--text);
  font-family: "New York", "Times New Roman", STSong, serif;
  font-variant-numeric: lining-nums tabular-nums;
  letter-spacing: 0.012em;
}
.rich-math--inline {
  display: inline-flex;
  align-items: baseline;
  max-width: 100%;
  padding: 0 0.12em;
  white-space: nowrap;
  vertical-align: -0.06em;
}
.rich-math--block {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  padding: 12px 14px;
  border-block: 1px solid var(--hairline);
  background: color-mix(in srgb, var(--surface-2) 74%, transparent);
  text-align: center;
  font-size: var(--fs-lead);
  white-space: nowrap;
}
.rich-math sup,
.rich-math sub { font-size: 0.72em; line-height: 0; }
.rich-math__frac {
  display: inline-flex;
  flex-direction: column;
  align-items: stretch;
  vertical-align: -0.48em;
  margin: 0 0.16em;
  text-align: center;
  line-height: 1.05;
}
.rich-math__frac > span:first-child { padding: 0 0.2em 0.1em; border-bottom: 1px solid currentColor; }
.rich-math__frac > span:last-child { padding: 0.1em 0.2em 0; }
.rich-math__sqrt { display: inline-flex; align-items: stretch; }
.rich-math__sqrt > span:first-child { font-size: 1.18em; line-height: 1; }
.rich-math__sqrt > span:last-child { border-top: 1px solid currentColor; padding: 0.02em 0.16em 0; }
.rich-math__text { font-family: inherit; font-style: normal; }

/* 主工作区：助手回复本身就是一段文稿，不再额外套纸。 */
.chat-message.is-assistant .rich-text { color: var(--text-muted); }
.chat-message.is-assistant .rich-text p { color: var(--text-muted); }

/* 浮窗：短句保留轻气泡，长回复仍走编辑式排版。 */
.wg__rich {
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs) var(--radius) var(--radius) var(--radius);
  background: var(--wg-lift-grad);
  box-shadow: var(--shadow-inset);
  user-select: text;
}
.wg__rich .rich-text { gap: 0.58em; line-height: 1.55; }
.wg__rich .rich-heading--1 { font-size: var(--fs-lead); }
.wg__rich .rich-heading--2 { font-size: var(--fs-body); }
.wg__message.is-assistant.is-editorial .wg__rich {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
}
.wg__rich .rich-code-block pre { padding: 8px 9px; }
.wg__rich .rich-code-block code { font-size: var(--fs-tiny); }
.wg__rich .rich-math--block { padding: 9px 8px; font-size: var(--fs-body); }
/* 0.6.0：浮窗只有三百多像素宽，表格收紧一档：字小一号、格子内边距收一半，仍横向滑动，不撑破窗。 */
.wg__rich .rich-table { font-size: var(--fs-tiny); }
.wg__rich .rich-table th,
.wg__rich .rich-table td { padding: 6px 8px; }
.wg__rich .rich-text ul,
.wg__rich .rich-text ol { padding-left: 1.25em; }

@media (max-width: 820px) {
  .rich-text { line-height: 1.66; }
  .rich-code-block pre { padding: 10px 11px; }
  .rich-math--block { text-align: left; }
}
