/* ═══ 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;
}

/* ============ 聊天框美化 - 保留原样 ============ */
.is-user > .border.border-muted,
.is-assistant > .border.border-muted {
    background: #FAF8F5 !important;
    border-radius: 12px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06) !important;
    padding: 16px !important;
    margin-bottom: 12px !important;
    border: 1px solid #EAE6E0 !important;
    transition: box-shadow 0.2s ease !important;
}
.is-user > .border.border-muted,
.is-assistant > .border.border-muted:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1) !important;
}
.rili-markdown-renderer {
    color: #2C2C2C !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif !important;
    font-size: 16px !important;
    line-height: 1.7 !important;
    text-shadow: none !important;
    font-weight: 400 !important;
}
.rili-markdown-renderer strong {
    color: #1A1A1A !important;
    font-weight: 700 !important;
}
.bg-muted.rounded.flex.p-0\.5 > button.rounded-full.size-7{
    color: #555555 !important;
}
.flex.items-center.gap-2.text-xs.font-mono.text-muted-foreground {
    color: #555555 !important;
}
/* [Token消耗hover逻辑转换未启用]
.text-orange-500 {
    color: #555555 !important;
}
*/
@media (max-width: 480px) {
    .is-user > .border.border-muted,
.is-assistant > .border.border-muted {
        padding: 12px !important;
        border-radius: 8px !important;
    }
    .rili-markdown-renderer {
        font-size: 15px !important;
    }
}

/* ============ AI 容器 - 全局变量与基准 ============ */
ai {
  --bg-page: #fbf7f2;
  --bg-card: #ffffff;
  --bg-card-tint: rgba(232,228,218,0.25);
  --accent: #5b4b3a;
  --accent-soft: #8a7564;
  --gold: #b8996b;
  --gold-pale: #dcc9a3;
  --text: #3a332a;
  --text-dim: #7a6e5e;
  --text-light: #9c8f7e;
  --border: #e0d9cf;
  --table-stripe: #f7f4ed;
  --table-head: #e8e0d5;
  --radius: 8px;
  --shadow: 0 1px 4px rgba(91,75,58,0.06);
  display: block;
  font-family: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "SimSun", "KaiTi", serif;
  font-size: 15px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg-page);
  padding: 0.6rem 0.8rem 1rem;
  max-width: 100%;
  box-sizing: border-box;
}

/* ============ 头部信息条 ============ */
ai hd {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto auto;
  gap: 0.25rem 0.6rem;
  padding: 0.7rem 1rem;
  margin-bottom: 0.8rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border-left: 3px solid var(--accent);
  font-size: 0.9rem;
  color: var(--text-dim);
  align-items: center;
}
ai hd t {
  grid-column: 1 / -1;
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  display: block;
  margin-bottom: 0.15rem;
  letter-spacing: 0.03em;
  position: relative;
  padding-left: 0.3rem;
}
ai hd t::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.1em;
  bottom: 0.1em;
  width: 2px;
  background: var(--gold);
  border-radius: 1px;
}
ai hd d {
  display: flex;
  align-items: baseline;
  gap: 0.15rem;
  padding: 0.1rem 0;
}

/* ============ 折叠区核心样式（标准 details/summary） ============ */
ai details {
  display: block;
  margin-bottom: 10px;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border-left: 4px solid transparent;
  border-image: linear-gradient(to bottom, var(--accent), var(--gold-pale)) 1;
  overflow: hidden;
  transition: box-shadow 0.25s ease;
}
ai details[open] {
  box-shadow: 0 2px 8px rgba(91,75,58,0.1);
}

/* 折叠区标题 */
ai summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0.55rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  user-select: none;
  list-style: none;
  transition: background 0.2s ease;
}
ai summary:hover {
  background: rgba(91,75,58,0.03);
}
/* 移除系统默认箭头 */
ai summary::-webkit-details-marker {
  display: none;
}
ai summary::marker {
  display: none;
  content: '';
}

/* 自定义箭头（左侧三角） */
ai summary::before {
  content: '▶';
  transition: transform 0.25s ease, color 0.2s;
  font-size: 12px;
  color: var(--gold);
  flex-shrink: 0;
  opacity: 0.7;
}
ai details[open] > summary::before {
  transform: rotate(90deg);
  color: var(--accent);
  opacity: 1;
}

/* 箭头左侧装饰圆点（继承原设计） */
ai summary::after {
  content: "";
  position: absolute;
  left: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
  opacity: 0.7;
  transition: all 0.3s ease;
}
ai details[open] > summary::after {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(184,153,107,0.25);
}
/* 调整 summary 内边距给圆点留空间 */
ai summary {
  padding-left: 1.8rem;
  position: relative;
}

/* ============ 折叠区内容 ============ */
ai .con {
  display: block;
  padding: 0.5rem 1rem 0.7rem 1.2rem;
  font-size: 0.9rem;
  border-top: 1px solid var(--border);
  animation: fadeInUp 0.2s ease;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============ 数据行 ============ */
ai d {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.2rem 0.4rem;
  padding: 0.35rem 0;
  border-bottom: 1px dotted var(--border);
  transition: background 0.2s ease;
  border-radius: 2px;
  padding-left: 0.2rem;
  padding-right: 0.2rem;
  position: relative;
}
ai d:last-child {
  border-bottom: none;
}
ai d:hover {
  background: rgba(184,153,107,0.06);
}

ai l {
  display: inline;
  font-weight: 600;
  font-size: 0.88em;
  color: var(--accent);
  white-space: nowrap;
}

/* ============ 列表 ============ */
ai ul {
  margin: 0.3rem 0 0.3rem 1.2rem;
  padding: 0;
  list-style: none;
}
ai li {
  position: relative;
  padding: 0.2rem 0 0.2rem 1rem;
  font-size: 0.9em;
  color: var(--text-dim);
  line-height: 1.55;
  transition: color 0.2s ease;
}
ai li::before {
  content: "—";
  position: absolute;
  left: 0;
  color: var(--gold);
  font-weight: 300;
  opacity: 0.6;
}
ai li:hover {
  color: var(--text);
}
ai li ul {
  margin-left: 0.8rem;
}

/* ============ 表格（记忆区） ============ */
ai table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.4rem 0;
  font-size: 0.82rem;
  border-radius: 3px;
  overflow: hidden;
  box-shadow: 0 0 0 1px var(--border);
}
ai th {
  background: var(--table-head);
  color: var(--accent);
  font-weight: 600;
  padding: 0.4rem 0.5rem;
  text-align: left;
  font-size: 0.82em;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
ai td {
  padding: 0.35rem 0.5rem;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  line-height: 1.45;
  word-break: break-word;
}
ai tr:nth-child(even) td {
  background: var(--table-stripe);
}
ai tr:hover td {
  background: rgba(184,153,107,0.08);
  color: var(--text);
}

/* ============ 强调文字 & 引用 ============ */
ai em {
  font-style: normal;
  color: var(--gold);
  font-weight: 500;
}
ai strong {
  color: var(--accent);
  font-weight: 600;
}
ai blockquote {
  margin: 0.5rem 0;
  padding: 0.5rem 0.8rem;
  border-left: 3px solid var(--gold-pale);
  background: rgba(255,255,255,0.5);
  font-style: italic;
  color: var(--text-dim);
  border-radius: 0 3px 3px 0;
}

/* ============ 分隔线 ============ */
ai hr {
  border: none;
  border-top: 1px dashed var(--border);
  margin: 0.5rem 0;
  opacity: 0.6;
}

/* ============ 栀子花装饰（关键字段） ============ */
ai d[l="内心想法："]::after,
ai d[l="关系概述："]::after {
  content: "";
  position: absolute;
  right: 0.2rem;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.9) 0%, rgba(220,201,163,0.5) 40%, transparent 70%);
  border-radius: 50% 50% 50% 0;
  opacity: 0.5;
  pointer-events: none;
}

/* ============ 移动端优化 ============ */
@media (max-width: 480px) {
  ai {
    font-size: 14px;
    padding: 0.4rem 0.5rem 0.8rem;
  }
  ai hd {
    grid-template-columns: 1fr;
    font-size: 0.82rem;
    padding: 0.5rem 0.8rem;
  }
  ai hd t {
    font-size: 0.95rem;
  }
  ai summary {
    font-size: 0.9rem;
    padding: 0.45rem 0.8rem 0.45rem 1.8rem;
  }
  ai .con {
    padding: 0.4rem 0.7rem 0.6rem 1rem;
  }
  ai table {
    font-size: 0.75rem;
  }
  ai th, ai td {
    padding: 0.3rem 0.4rem;
  }
}