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

/* ===== 藏起顶部的颜色装饰条 ===== */
[class*="bg-[#F1CBCB]"], 
[class*="bg-[#c9e1e9]"] {
    display: none !important;
}

/* ===== 统一聊天框（气泡） ===== */
.is-user > .border.border-muted,
.is-assistant > .border.border-muted {
    background: #f7f3ed !important;          /* 温润米白，类手工纸 */
    border-radius: 14px !important;
    box-shadow: 0 2px 12px rgba(0,0,0,0.05) !important;
    border: 1px solid #e8e0d5 !important;
}

/* 输入框微调（比回复框略亮，形成轻柔层次） */
.is-user > .border.border-muted {
    background: #faf7f2 !important;
}

/* ===== 核心文本内容 ===== */
.rili-markdown-renderer {
    color: #3e362e !important;                /* 深棕，高对比 */
    font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif !important;
    font-size: 15px !important;
    line-height: 1.7 !important;
    font-weight: 400 !important;
}

/* ===== 底部操作按钮（复制、编辑等） ===== */
.bg-muted.rounded.flex.p-0\.5 > button.rounded-full.size-7{
    color: #6b5e53 !important;               /* 柔化棕灰 */
}

/* ===== 模型名称文本 ===== */
.flex.items-center.gap-2.text-xs.font-mono.text-muted-foreground {
    color: #8c8074 !important;
}

/* ===== Token 消耗文本 ===== */
/* [Token消耗hover逻辑转换未启用]
.text-orange-500 {
    color: #8c8074 !important;               /* 去橙，融入整体色调 */
}
*/
/* ===== 基础容器与配色变量 ===== */
ai {
  --bg-page: #faf8f5;
  --bg-card: #ffffff;
  --text-main: #3a322e;
  --text-sub: #6b5e55;
  --accent-deep: #2c3a5e;
  --accent-wine: #8b5e6b;
  --accent-green: #4a7c59;
  --border-pale: #e0d9cf;
  --shadow-card: 0 1px 4px rgba(0,0,0,0.04), 0 2px 8px rgba(0,0,0,0.03);
  --shadow-hover: 0 2px 8px rgba(0,0,0,0.06), 0 4px 16px rgba(0,0,0,0.04);
  --radius: 6px;
  --font-serif: "Noto Serif SC", "Source Han Serif SC", "STSong", "Songti SC", Georgia, serif;
  --font-sans: "Noto Sans SC", "Source Han Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  display: block;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text-main);
  background: var(--bg-page);
  padding: 12px 10px;
  margin: 0;
  max-width: 100%;
  box-sizing: border-box;
  line-height: 1.6;
}

/* ===== 主卡片 ===== */
.main-card {
  background: var(--bg-card);
  margin: 0 0 10px 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  border-left: 3px solid transparent;
  transition: box-shadow 0.3s ease, border-left-color 0.3s ease;
  padding: 0;
}
.main-card[open] {
  border-left-color: var(--accent-deep);
}
.main-card:hover {
  box-shadow: var(--shadow-hover);
}

/* ===== 卡片标题 ===== */
.card-title {
  display: block;
  padding: 10px 14px;
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--accent-deep);
  background: linear-gradient(135deg, #f4f1eb 0%, #faf8f5 100%);
  border-bottom: 1px solid var(--border-pale);
  cursor: pointer;
  user-select: none;
  position: relative;
  border-radius: var(--radius) var(--radius) 0 0;
  list-style: none;
}
.card-title::-webkit-details-marker {
  display: none;
}
.card-title::before {
  content: "▸";
  display: inline-block;
  margin-right: 8px;
  font-size: 12px;
  transition: transform 0.3s ease;
  color: var(--accent-deep);
}
.main-card[open] > .card-title::before {
  transform: rotate(90deg);
}

/* 闭合时标题保留圆角 */
.main-card:not([open]) > .card-title {
  border-radius: var(--radius);
  border-bottom: none;
}

/* ===== NPC卡片专属 ===== */
.npc-card .card-title {
  color: var(--accent-wine);
  background: linear-gradient(135deg, #f9f3f4 0%, #fdfafb 100%);
}
.npc-card[open] {
  border-left-color: var(--accent-wine);
}

/* ===== 手机卡片 ===== */
.phone-card .card-title {
  color: #3a6b4c;
  background: linear-gradient(135deg, #f2f7f3 0%, #f8fbf9 100%);
}
.phone-card[open] {
  border-left-color: var(--accent-green);
}

/* ===== 琴心絮语卡片 ===== */
.whisper-card .card-title {
  color: #5c4a6e;
  background: linear-gradient(135deg, #f6f3f9 0%, #faf8fc 100%);
}
.whisper-card[open] {
  border-left-color: #5c4a6e;
}

/* ===== 记忆区卡片 ===== */
.memory-card .card-title {
  color: #5a4a3a;
}
.memory-card[open] {
  border-left-color: #5a4a3a;
}

/* ===== 行动卡片 ===== */
.action-card .card-title {
  color: #4a6a5a;
}
.action-card[open] {
  border-left-color: #4a6a5a;
}

/* ===== 通用信息行 ===== */
.info-line {
  padding: 6px 14px;
  margin: 0;
  font-size: 13.5px;
  border-bottom: 1px dotted var(--border-pale);
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.info-line:last-child {
  border-bottom: none;
}
.info-line t {
  font-weight: 600;
  font-size: 12px;
  color: var(--text-sub);
  flex-shrink: 0;
  min-width: 70px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ===== 文本块 ===== */
.block {
  padding: 8px 14px;
  border-bottom: 1px dotted var(--border-pale);
  font-size: 13.5px;
}
.block:last-child {
  border-bottom: none;
}
.block t {
  display: block;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-sub);
  margin-bottom: 4px;
  letter-spacing: 0.04em;
}
.block span {
  display: block;
  color: var(--text-main);
}

/* 子小节 */
.sub-section {
  background: #fdfcf9;
  margin: 0 8px;
  padding: 8px 10px;
  border-left: 2px solid var(--border-pale);
  border-bottom: 1px dotted var(--border-pale);
}
.sub-section d {
  font-weight: 600;
  font-size: 12px;
  color: var(--text-sub);
  display: inline;
}
.sub-section d::after {
  content: "";
  display: inline;
}
.sub-section span {
  display: inline;
}

/* 内心想法 */
.inner-voice {
  background: linear-gradient(135deg, #fef9fa 0%, #fdfafb 100%);
  border-left: 2px solid var(--accent-wine);
  margin: 0 8px 8px 8px;
  padding: 10px 12px;
  font-style: italic;
}

/* ===== 列表块 ===== */
.list-block {
  padding: 8px 14px;
  border-bottom: 1px dotted var(--border-pale);
  font-size: 13.5px;
}
.list-block:last-child {
  border-bottom: none;
}
.list-block t {
  display: block;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-sub);
  margin-bottom: 4px;
  letter-spacing: 0.04em;
}
.list-block li {
  margin: 2px 0 2px 16px;
  padding: 0;
  list-style-type: "· ";
  color: var(--text-main);
}

/* ===== 手机消息 ===== */
.msg {
  padding: 8px 14px;
  border-radius: 4px;
  margin: 6px 8px;
  font-size: 13.5px;
}
.msg t {
  display: block;
  font-weight: 600;
  font-size: 11px;
  margin-bottom: 3px;
  letter-spacing: 0.03em;
}
.msg span {
  display: block;
  color: var(--text-main);
}
.wechat {
  background: #f1f8f2;
  border-left: 3px solid #4a8c5c;
}
.sms {
  background: #f6f4f0;
  border-left: 3px solid #a09080;
}

/* ===== 琴心絮语条目 ===== */
.whisper {
  padding: 10px 14px;
  margin: 6px 8px;
  border-radius: 3px;
  font-size: 13.5px;
  position: relative;
}
.whisper t {
  display: block;
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 6px;
  letter-spacing: 0.05em;
}
.whisper span {
  display: block;
  font-style: italic;
  color: #4a3f3a;
  line-height: 1.7;
}
.memory {
  background: #faf7f2;
  border-left: 2px solid #c4a882;
}
.soliloquy {
  background: #f5f3f8;
  border-left: 2px solid #8b7aaa;
}
.diary {
  background: #fdf6f0;
  border-left: 2px solid #c4846a;
  position: relative;
}
.diary::after {
  content: "📜";
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 14px;
  opacity: 0.3;
}

/* ===== 记忆区表格 ===== */
.sub-title {
  padding: 8px 14px 4px 14px;
  font-weight: 700;
  font-size: 13px;
  color: var(--accent-deep);
  letter-spacing: 0.04em;
}
.table-wrap {
  overflow-x: auto;
  margin: 0 8px 8px 8px;
  -webkit-overflow-scrolling: touch;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  min-width: 400px;
}
th {
  background: #f4f1eb;
  color: var(--text-sub);
  font-weight: 600;
  padding: 6px 8px;
  text-align: left;
  border-bottom: 2px solid var(--border-pale);
  white-space: nowrap;
  font-size: 11px;
  letter-spacing: 0.03em;
}
td {
  padding: 6px 8px;
  border-bottom: 1px dotted var(--border-pale);
  vertical-align: top;
}
tr:last-child td {
  border-bottom: none;
}

/* ===== 行动列表 ===== */
.action-list {
  padding: 8px 14px;
  margin: 0;
  list-style: none;
  counter-reset: action;
}
.action-list li {
  padding: 8px 10px;
  margin: 4px 0;
  background: #f9f7f3;
  border-radius: 4px;
  font-size: 13.5px;
  cursor: pointer;
  transition: background 0.2s ease, box-shadow 0.2s ease;
  counter-increment: action;
  position: relative;
  padding-left: 36px;
}
.action-list li::before {
  content: counter(action);
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--accent-deep);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.action-list li:hover {
  background: #f0ece4;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

/* ===== 响应式微调 ===== */
@media (max-width: 480px) {
  ai {
    padding: 8px 4px;
    font-size: 13px;
  }
  .info-line {
    flex-direction: column;
    gap: 2px;
  }
  .info-line t {
    min-width: auto;
  }
  .card-title {
    font-size: 14px;
    padding: 8px 10px;
  }
  .block,
  .list-block,
  .msg,
  .whisper {
    padding: 6px 10px;
  }
}