/* ═══ 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平台按钮组保护（自动注入 — 防止按钮消失）═══
   原理：B平台消息操作按钮结构为：
   .flex.items-center.gap-1.ml-auto (hover显隐包装)
     └── .bg-muted.rounded.flex.p-0.5 (按钮组容器)
           └── button.rounded-full.size-7 (单个按钮)
   以下规则使用高specificity + !important确保按钮
   不被任何转换后/透传的CSS规则意外隐藏
   ═══════════════════════════════════════════════ */
/* 按钮组容器保护 */
.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显隐包装层保护 — 仅保留B平台原生的opacity过渡 */
.flex.items-center.gap-1.ml-auto.md\:opacity-0.group-hover\:opacity-100 {
  visibility: visible !important;
  display: flex !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;
}

/* ========== 全局容器与主题变量 ========== */
ai {
  --pink: #FF6B6B;
  --blue: #48C9B0;
  --blue-dark: #2E8B7F;
  --gray-bg: #F5F5F8;
  --gray-border: #E8E8ED;
  --gray-text: #8E8E9A;
  --dark-text: #2C2C3A;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --radius: 12px;
  --radius-sm: 8px;
  display: block;
  max-width: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", sans-serif;
  color: var(--dark-text);
  line-height: 1.6;
  font-size: 15px;
  padding: 8px 0;
  background: transparent; /* 继承平台背景 */
}

/* ========== 场景头 ========== */
ai > hd {
  display: block;
  background: linear-gradient(135deg, var(--pink), #FF8E8E);
  color: #fff;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.3px;
  margin-bottom: 12px;
  box-shadow: 0 2px 6px rgba(255,107,107,0.25);
}

/* ========== 正文段落 ========== */
ai > article p {
  margin: 0 0 10px 0;
  padding: 0 4px;
  font-size: 15px;
  color: var(--dark-text);
}

/* ========== 可折叠状态栏（details） ========== */
details {
  display: block;
  margin: 8px 0;
  background: #fff;
  border: 1px solid var(--gray-border);
  border-radius: var(--radius);
  padding: 0;
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow 0.2s;
}
details:hover {
  box-shadow: 0 4px 14px rgba(0,0,0,0.08);
}
details[open] {
  padding-bottom: 6px;
}

/* — 折叠标题行 — */
details > summary {
  display: block;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 14px;
  color: var(--dark-text);
  background: var(--gray-bg);
  cursor: pointer;
  border-bottom: 1px solid transparent;
  list-style: none;
  user-select: none;
  transition: background 0.2s, color 0.2s;
  position: relative;
}
details > summary:hover {
  background: #EDEDF2;
}
details[open] > summary {
  border-bottom-color: var(--gray-border);
  color: var(--blue-dark);
}
/* 自定义折叠箭头（纯CSS） */
details > summary::after {
  content: "▶";
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  color: var(--gray-text);
  transition: transform 0.25s ease;
}
details[open] > summary::after {
  transform: translateY(-50%) rotate(90deg);
}

/* ========== 状态区内联信息块（使用 <t> 标签） ========== */
ai t {
  display: block;
  padding: 8px 14px 4px;
}
ai t > d {
  display: block;
  padding: 3px 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--dark-text);
}
ai t > d + d {
  border-top: 1px dashed #F0F0F5;
  margin-top: 2px;
  padding-top: 5px;
}

/* — 字段内重要数字/数值高亮 — */
details b, details strong {
  color: var(--pink);
  font-weight: 600;
}

/* ========== 表格样式（主角/NPC/记忆区） ========== */
details table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  margin: 6px 0;
}
details table th {
  background: var(--gray-bg);
  text-align: left;
  padding: 6px 10px;
  font-weight: 600;
  color: var(--dark-text);
  border-bottom: 2px solid var(--blue);
  font-size: 13px;
}
details table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--gray-border);
  vertical-align: top;
}
details table tr:last-child td {
  border-bottom: none;
}
details table tr:nth-child(even) td {
  background: #FAFAFC;
}
details table td:first-child {
  font-weight: 500;
  color: var(--gray-text);
  width: 28%;
  white-space: nowrap;
}

/* ========== QQ聊天消息区（chatbox） ========== */
chatbox {
  display: block;
  padding: 6px 14px 10px;
}
chatbox > hr {
  border: none;
  border-top: 1px solid var(--gray-border);
  margin: 12px 0;
}
chatbox > time {
  display: block;
  text-align: center;
  font-size: 12px;
  color: var(--gray-text);
  padding: 6px 0 8px;
  font-weight: 500;
}

/* — 单条消息 — */
chatbox > msg {
  display: block;
  margin: 5px 0;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  line-height: 1.5;
  max-width: 88%;
  position: relative;
  word-break: break-word;
}

/* 夏沫消息（粉色·右对齐） */
chatbox > msg[from="夏沫"] {
  background: #FFE8E8;
  color: #5C3A3A;
  margin-left: auto;
  border-bottom-right-radius: 2px;
}
chatbox > msg[from="夏沫"]::before {
  content: "夏沫";
  display: block;
  font-size: 12px;
  color: var(--pink);
  font-weight: 600;
  margin-bottom: 2px;
}

/* 顾清词消息（蓝绿色·左对齐） */
chatbox > msg[from="顾清词"] {
  background: #E4F5F1;
  color: #1A5C52;
  margin-right: auto;
  border-bottom-left-radius: 2px;
}
chatbox > msg[from="顾清词"]::before {
  content: "顾清词";
  display: block;
  font-size: 12px;
  color: var(--blue);
  font-weight: 600;
  margin-bottom: 2px;
}

/* 陈檬消息（灰色·左对齐） */
chatbox > msg[from="陈檬"] {
  background: #F0F0F5;
  color: #3A3A4A;
  margin-right: auto;
  border-bottom-left-radius: 2px;
}
chatbox > msg[from="陈檬"]::before {
  content: "陈檬";
  display: block;
  font-size: 12px;
  color: #8A8A9A;
  font-weight: 600;
  margin-bottom: 2px;
}

/* ========== 行动推荐计数器 ========== */
ai t {
  counter-reset: action;
}
ai t > d {
  counter-increment: action;
}
ai t > d::before {
  content: counter(action) ". ";
  font-weight: 600;
  color: var(--blue);
  margin-right: 4px;
}

/* ========== 移动端适配 ========== */
@media (max-width: 640px) {
  ai {
    font-size: 14px;
    padding: 4px 0;
  }
  details > summary {
    font-size: 13px;
    padding: 9px 12px;
  }
  ai t {
    padding: 6px 12px 2px;
  }
  ai t > d {
    font-size: 13px;
  }
  chatbox > msg {
    font-size: 13px;
    padding: 5px 10px;
    max-width: 92%;
  }
  details table {
    font-size: 13px;
  }
  details table td:first-child {
    width: 24%;
  }
}

/* ========== 打印支持 ========== */
@media print {
  details > summary::after {
    display: none;
  }
  details {
    box-shadow: none;
    border-color: #ccc;
  }
}

/* ========== 兼容性备用：确保自定义标签显示为块级 ========== */
hd, t, chatbox, msg, time {
  display: block;
}