/* ══════════════ 主题变量（便于统一调整） ══════════════ */
:root {
  --clinic-red: #c0392b;
  --clinic-brown: #7a6b5a;
  --bg-paper: #f0eadc;
  --card-bg: #faf8f4;
  --border-color: #ddd8cc;
  --summary-bg: #f5f0e6;
  --summary-hover: #ede7db;
  --text-dark: #2c2c2c;
  --text-light: #3a3a3a;
  --dash-color: #e8e2d4;
  --muted-text: #9a8c7a;
}

/* ═══ B平台加载动画适配（自动注入） ═══ */
.flex.items-center.justify-center.size-6 {
  opacity: 1 !important;
  position: relative;
  width: 24px;
  height: 24px;
}
.flex.items-center.justify-center.size-6 > .flex.gap-2 {
  display: none !important;
}

.is-assistant.w-fit {
  width: 100% !important;
}
.is-assistant > .border.border-muted:has(.flex.items-center.justify-center.size-6) {
  width: 100% !important;
  background: transparent !important;
  border: none !important;
  padding: 0 !important;
}
.is-assistant .space-y-3:has(.flex.items-center.justify-center.size-6) {
  display: flex;
  justify-content: center;
  width: 100%;
}

/* ═══ B平台表格修正 ═══ */
.rili-markdown-renderer table {
  display: table !important;
  table-layout: auto !important;
  width: 100% !important;
  border-collapse: collapse !important;
}
.rili-markdown-renderer table caption {
  display: table-caption !important;
  caption-side: top !important;
  text-align: center !important;
  padding: 8px !important;
}
.rili-markdown-renderer thead { display: table-header-group !important; }
.rili-markdown-renderer tbody { display: table-row-group !important; }
.rili-markdown-renderer tr    { display: table-row !important; }
.rili-markdown-renderer th,
.rili-markdown-renderer td   { display: table-cell !important; }

/* ═══ B平台按钮组保护（合并上下文，统一防御） ═══ */
.w-full.h-full.flex.group .bg-muted.rounded.flex.p-0\.5,
.is-user .bg-muted.rounded.flex.p-0\.5,
.is-assistant .bg-muted.rounded.flex.p-0\.5 {
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  overflow: visible !important;
  position: relative !important;
  width: auto !important;
  height: auto !important;
  max-height: none !important;
  pointer-events: auto !important;
  clip: auto !important;
  clip-path: none !important;
}

.w-full.h-full.flex.group .bg-muted.rounded.flex.p-0\.5 > button,
.is-user .bg-muted.rounded.flex.p-0\.5 > button,
.is-assistant .bg-muted.rounded.flex.p-0\.5 > button {
  display: inline-flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
  position: relative !important;
  clip: auto !important;
  clip-path: none !important;
}

/* hover 显隐包装层 */
.flex.items-center.gap-1.ml-auto.md\:opacity-0.group-hover\:opacity-100 {
  display: flex !important;
  visibility: visible !important;
  pointer-events: auto !important;
  overflow: visible !important;
}

/* 操作行 */
.flex.w-full.items-center.justify-between.gap-2.px-2 {
  display: flex !important;
  visibility: visible !important;
  overflow: visible !important;
}

/* ═══ 全局装饰条隐藏 ═══ */
[class*="bg-[#F1CBCB]"],
[class*="bg-[#c9e1e9]"] {
  display: none !important;
}

/* ═══ 全局背景 — 病历档案室质感 ═══ */
body,
html,
#__next,
[class*="bg-gray"] {
  background-color: var(--bg-paper) !important;
}

/* ═══ 聊天框 — 病历单卡片 ═══ */
.is-user > .border.border-muted,
.is-assistant > .border.border-muted {
  background: var(--card-bg) !important;
  border: 1px solid var(--border-color);
  border-radius: 4px !important;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  padding: 16px 18px;
  position: relative;
}

/* 病历抬头红线（修复伪元素选择器错误） */
.is-user > .border.border-muted::before,
.is-assistant > .border.border-muted::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--clinic-red);
  border-radius: 4px 4px 0 0;
}

/* ═══ 文本区域 ═══ */
.rili-markdown-renderer {
  color: var(--text-dark) !important;
  font-family: 'Noto Serif SC', 'Source Han Serif SC', 'Georgia', 'Times New Roman', serif;
  line-height: 1.8;
  font-size: 0.95em;
  background: transparent !important;
}

.rili-markdown-renderer p {
  border-bottom: 1px dashed var(--dash-color);
  padding-bottom: 8px;
  margin-bottom: 8px;
}
.rili-markdown-renderer p:last-child {
  border-bottom: none;
}

/* ═══ details / summary — 折叠病历夹 ═══ */
.rili-markdown-renderer details {
  margin: 12px 0;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: #fcfaf6;
  box-shadow: inset 0 1px 3px rgba(0,0,0,.04);
}

.rili-markdown-renderer details summary {
  cursor: pointer;
  padding: 8px 14px;
  font-family: 'Noto Serif SC', 'Source Han Serif SC', serif;
  font-size: 0.95em;
  font-weight: bold;
  color: var(--clinic-brown);
  background: var(--summary-bg);
  border-bottom: 1px solid var(--border-color);
  border-radius: 3px 3px 0 0;
  user-select: none;
  transition: background .2s;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* 自定义折叠指示器 */
.rili-markdown-renderer details summary::before {
  content: '+';
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  font-family: 'Courier New', monospace;
  font-size: 1em;
  font-weight: bold;
  color: var(--clinic-red);
  border: 1px solid var(--clinic-red);
  border-radius: 3px;
  line-height: 1;
  flex-shrink: 0;
  transition: transform .2s;
}
.rili-markdown-renderer details[open] summary::before {
  content: '−';
}

.rili-markdown-renderer details summary:hover {
  background: var(--summary-hover);
}

.rili-markdown-renderer details[open] {
  padding-bottom: 10px;
}
.rili-markdown-renderer details[open] > :not(summary) {
  padding: 8px 14px 4px;
  font-size: 0.93em;
  color: var(--text-light);
}

.rili-markdown-renderer details[open] p {
  border-bottom: 1px dashed var(--summary-hover);
  padding-bottom: 6px;
  margin-bottom: 6px;
}

/* ═══ 操作按钮 ═══ */
.bg-muted.rounded.flex.p-0\.5 > button.rounded-full.size-7 {
  color: var(--clinic-red) !important;
  font-weight: normal;
  text-transform: none;
  padding: 4px 10px;
  border-radius: 3px;
  font-size: 0.85em;
  background-color: rgba(192, 57, 43, 0.06);
}

/* ═══ 模型名称 / Token ═══ */
.flex.items-center.gap-2.text-xs.font-mono.text-muted-foreground {
  color: var(--muted-text);
  font-size: 0.82em;
  font-family: 'Courier New', monospace;
}

/* ═══ 加载动画（整合到前面的容器上） ═══ */
.flex.items-center.justify-center.size-6::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24'%3E%3Ccircle cx='6' cy='12' r='3' fill='%23c0392b'%3E%3Canimate attributeName='r' values='3;5;3' dur='1.2s' repeatCount='indefinite' begin='0s'/%3E%3Canimate attributeName='opacity' values='1;0.6;1' dur='1.2s' repeatCount='indefinite' begin='0s'/%3E%3C/circle%3E%3Ccircle cx='12' cy='12' r='3' fill='%23c0392b'%3E%3Canimate attributeName='r' values='3;5;3' dur='1.2s' repeatCount='indefinite' begin='0.4s'/%3E%3Canimate attributeName='opacity' values='1;0.6;1' dur='1.2s' repeatCount='indefinite' begin='0.4s'/%3E%3C/circle%3E%3Ccircle cx='18' cy='12' r='3' fill='%23c0392b'%3E%3Canimate attributeName='r' values='3;5;3' dur='1.2s' repeatCount='indefinite' begin='0.8s'/%3E%3Canimate attributeName='opacity' values='1;0.6;1' dur='1.2s' repeatCount='indefinite' begin='0.8s'/%3E%3C/circle%3E%3C/svg%3E") no-repeat center;
  background-size: contain;
}

/* ═══ 移动端 ═══ */
@media (max-width: 768px) {
  .is-user > .border.border-muted,
  .is-assistant > .border.border-muted {
    padding: 12px 14px;
  }
  .rili-markdown-renderer {
    font-size: 0.9em;
    line-height: 1.65;
  }
  .rili-markdown-renderer details summary {
    padding: 6px 10px;
    font-size: 0.9em;
  }
  .bg-muted.rounded.flex.p-0\.5 > button.rounded-full.size-7 {
    padding: 3px 6px;
    font-size: 0.8em;
  }
  .flex.items-center.gap-2.text-xs.font-mono.text-muted-foreground {
    font-size: 0.78em;
  }
}

/* ═══ 低动效模式 ═══ */
@media (prefers-reduced-motion: reduce) {
  .flex.items-center.justify-center.size-6::before {
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24'%3E%3Ccircle cx='6' cy='12' r='3' fill='%23c0392b'/%3E%3Ccircle cx='12' cy='12' r='3' fill='%23c0392b'/%3E%3Ccircle cx='18' cy='12' r='3' fill='%23c0392b'/%3E%3C/svg%3E") no-repeat center;
    background-size: contain;
  }
}