/* ═══ B平台加载动画适配（自动注入）═══ */
.flex.items-center.justify-center.size-6 { opacity: 1 !important; }
.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平台按钮组保护（自动注入 — 防止按钮消失）═══
   原理：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> 内部）
   完整版，覆盖记忆区表格、进度条、QQ 聊天、深色模式等
   ============================================================ */

/* ---- 1. 聊天框美化 ---- */
[class*="bg-gray-100"]:where(.relative.inline-block) {
  background: linear-gradient(135deg, #FDFBF7 0%, #F7F3EF 100%) !important;
  box-shadow: 0 2px 12px rgba(139, 119, 90, 0.08) !important;
  border: 1px solid rgba(200, 180, 155, 0.3) !important;
  border-radius: 20px !important;
  padding: 16px 20px !important;
  isolation: isolate !important;
}

.rili-markdown-renderer {
  color: #3A2E2A !important;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif !important;
  font-size: 15px !important;
  line-height: 1.75 !important;
}

.rili-markdown-renderer strong { color: #1A1A1A !important; font-weight: 700 !important; }
.rili-markdown-renderer a { color: #8B6B4E !important; text-decoration: underline !important; }

.bg-muted.rounded.flex.p-0\.5 > button.rounded-full.size-7{
  color: #6B5C54 !important;
  font-size: 12px !important;
  font-weight: 500 !important;
  opacity: 0.75;
}
.bg-muted.rounded.flex.p-0\.5 > button.rounded-full.size-7{ opacity: 1; }
.flex.items-center.gap-2.text-xs.font-mono.text-muted-foreground { color: #8B7A70 !important; font-size: 11px !important; }
/* [Token消耗hover逻辑转换未启用]
.text-orange-500 { color: #C09A7B !important; font-size: 11px !important; background: rgba(200,180,155,0.15); padding: 2px 8px; border-radius: 12px; }
*/

/* 加载动画替换（圆点→跳跃星星） */
.flex.items-center.justify-center.size-6 { position: relative !important; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; }
.style-module__AtdJSq__dot-flashing.style-module__AtdJSq__text { display: none !important; }
.flex.items-center.justify-center.size-6::before {
  content: ''; display: block; width: 24px; height: 24px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='6' r='2.5' fill='%238B6B4E'%3E%Canimate attributeName='cy' values='6;16;6' dur='1.2s' repeatCount='indefinite' /%3E%Canimate attributeName='opacity' values='1;0.3;1' dur='1.2s' repeatCount='indefinite' /%3E%3C/circle%3E%3Ccircle cx='12' cy='6' r='2.5' fill='%23C09A7B'%3E%Canimate attributeName='cy' values='6;16;6' dur='1.2s' begin='0.4s' repeatCount='indefinite' /%3E%Canimate attributeName='opacity' values='1;0.3;1' dur='1.2s' begin='0.4s' repeatCount='indefinite' /%3E%3C/circle%3E%3C/svg%3E") !important;
  background-size: contain; background-repeat: no-repeat; background-position: center;
}

@media (prefers-reduced-motion: reduce) {
  .flex.items-center.justify-center.size-6::before { animation: none; opacity: 0.6; }
}

/* ---- 2. 状态栏美化（<ai> 内部） ---- */
ai {
  display: block;
  max-width: 560px;
  margin: 0 auto;
  padding: 8px 12px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  color: #3a2e2a;
  --card-bg: #fffffffa;
  --card-shadow: 0 2px 12px rgba(0,0,0,0.05), 0 0 0 1px rgba(0,0,0,0.02);
  --border-subtle: #e8ddd1;
  --text-muted: #8a7a6a;
  --accent: #b08968;
}

/* 头部 */
ai hd {
  display: block;
  padding: 14px 18px;
  margin-bottom: 12px;
  font-size: 16px;
  font-weight: 600;
  color: #4a3728;
  background: linear-gradient(135deg, #f5e6d3 0%, #fff 100%);
  border-radius: 16px;
}

/* 卡片容器 */
ai details {
  display: block;
  margin: 10px 0;
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: var(--card-shadow);
  overflow: hidden;
}

/* 摘要标题 */
ai details > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 550;
  color: #3d2c1e;
  cursor: pointer;
  list-style: none;
  border-left: 4px solid var(--ac, var(--accent));
  background: linear-gradient(to right, color-mix(in srgb, var(--ac, var(--accent)) 8%, #fff) 0%, transparent 60%);
  transition: background 0.2s;
  user-select: none;
}
ai details > summary::-webkit-details-marker { display: none; }
ai details > summary:hover {
  background: linear-gradient(to right, color-mix(in srgb, var(--ac, var(--accent)) 14%, #fff) 0%, transparent 60%);
}

/* 卡片内容区（通用） */
ai details > .card-body,
ai details > .msg-thread,
ai details > .diary {
  padding: 12px 18px 18px;
  border-top: 1px solid var(--border-subtle);
  animation: cardIn 0.25s ease-out;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 嵌套 details */
ai details details {
  margin: 8px 0 4px;
  border-radius: 12px;
  background: #f9f4ed;
  border: 1px solid var(--border-subtle);
}
ai details details > summary {
  padding: 8px 14px;
  font-size: 13px;
  background: #f5ede4;
}
ai details details > ul {
  padding: 8px 14px 12px;
  font-size: 13px;
}

/* 两列网格 */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 18px;
}
.grid-2 p { margin: 3px 0; }
.grid-2 p b { display: inline-block; min-width: 3.5em; color: #6b5b4a; }

/* 状态网格 */
.sg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 14px;
  margin-bottom: 10px;
  padding: 10px 14px;
  background: #f9f4ed;
  border-radius: 12px;
  font-size: 13px;
}
.sg div { display: flex; align-items: center; gap: 6px; }
.sg div b { color: #5a4a3a; font-weight: 550; min-width: 3.5em; }

/* meter 条 */
meter {
  width: 70px; height: 8px; border: none; border-radius: 4px;
  background: #e8ddd1; vertical-align: middle;
}
meter::-webkit-meter-bar { background: #e8ddd1; border-radius: 4px; }
meter::-webkit-meter-optimum-value { background: linear-gradient(90deg, #f3c98b, #f0a050); border-radius: 4px; }
meter::-webkit-meter-suboptimum-value { background: linear-gradient(90deg, #f0a050, #d08040); }
meter::-webkit-meter-even-less-good-value { background: linear-gradient(90deg, #d08040, #b06030); }

/* 内心引用 */
.inner-quote {
  margin: 8px 0; padding: 10px 16px;
  background: #f3ede7; border-left: 3px solid var(--ac, var(--accent));
  border-radius: 0 12px 12px 0;
}
.ti { padding: 2px 0; font-size: 13px; color: #5a4a3a; }

/* 聊天线程（QQ风格） */
.msg-thread { display: flex; flex-direction: column; gap: 6px; padding: 6px 0; }
.msg {
  padding: 8px 16px; border-radius: 18px; font-size: 14px; line-height: 1.6;
  max-width: 85%; background: #f0e9e2; align-self: flex-start;
  color: #2c2c2c; border-bottom-left-radius: 6px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.msg b { display: block; font-size: 12px; font-weight: 600; color: var(--accent); margin-bottom: 2px; }
.msg[dn="林雁秋"] b { color: hsl(30, 70%, 45%); }
.msg[dn="苏白芷"] b { color: hsl(350, 70%, 50%); }
.msg[dn="你"] b { color: #6b5b4a; }
.msg[dn="你"] { align-self: flex-end; background: linear-gradient(135deg, #e8ddd1, #f5ede4); border-bottom-right-radius: 6px; border-bottom-left-radius: 18px; }
.msg-d { padding: 4px 16px; font-size: 12px; color: var(--text-muted); font-style: italic; align-self: flex-start; opacity: 0.7; }

/* 日记 */
.diary {
  padding: 10px 16px; font-family: Georgia, serif;
  background: #faf5ed; border-radius: 12px; border: 1px solid #e8ddd1;
}
.diary p { margin: 4px 0; text-indent: 1em; line-height: 1.8; font-style: italic; opacity: 0.9; }

/* 关系进度 */
.rel { margin: 12px 0; padding: 10px 14px; background: #f9f4ed; border-radius: 12px; }
.rel > div:first-child { font-size: 14px; font-weight: 600; color: #3d2c1e; margin-bottom: 6px; }
.prog { position: relative; height: 22px; background: #e8ddd1; border-radius: 11px; margin: 6px 0; overflow: hidden; }
.prog::after { content: ''; position: absolute; left: 0; top: 0; height: 100%; width: clamp(5%, var(--p, 0), 95%); background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 70%, #fff)); border-radius: 11px; transition: width 0.5s ease; }
.prog span { position: relative; z-index: 1; display: block; padding: 0 12px; font-size: 12px; line-height: 22px; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.2); white-space: nowrap; }

/* 关系温度 */
.temp { margin: 12px 0 4px; }
.temp b { display: block; margin-bottom: 6px; font-size: 14px; color: #3d2c1e; }
.tb { height: 16px; background: linear-gradient(90deg, #d5e8d4, #fce4d6, #f8cbad, #f4a460); border-radius: 8px; overflow: hidden; }
.tb span { display: block; height: 100%; background: #e74c3c; border-radius: 8px; text-align: center; line-height: 16px; font-size: 10px; }
.tbl { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* 表格（记忆区） */
ai table {
  width: 100%; border-collapse: collapse; font-size: 13px; margin: 8px 0;
}
ai th {
  padding: 8px 10px; background: #f0e9e2; color: #3d2c1e;
  font-weight: 600; text-align: left; border-bottom: 2px solid var(--border-subtle);
}
ai td {
  padding: 6px 10px; border-bottom: 1px solid var(--border-subtle); color: #4a3a2e;
}
ai tr:hover td { background: #f7f0e9; }

/* 告警 */
.alert { padding: 10px 16px; margin: 8px 0; font-size: 14px; background: #faf5ed; border-left: 4px solid var(--ac, var(--accent)); border-radius: 0 12px 12px 0; }
.alert b { color: #3d2c1e; }

/* 列表 */
ul, ol { margin: 6px 0; padding-left: 1.5em; }
li { margin: 3px 0; font-size: 14px; line-height: 1.6; }

/* ---- 移动端微调 ---- */
@media (max-width: 480px) {
  ai { padding: 4px 8px; }
  ai hd { padding: 12px 14px; font-size: 15px; }
  ai details > summary { padding: 10px 14px; font-size: 13px; }
  .grid-2 { grid-template-columns: 1fr; }
  .sg { grid-template-columns: 1fr; font-size: 13px; }
  .msg { max-width: 92%; font-size: 13px; }
  ai table { font-size: 12px; }
  ai th, ai td { padding: 5px 6px; }
}

/* ---- 深色模式 ---- */
@media (prefers-color-scheme: dark) {
  [class*="bg-gray-100"]:where(.relative.inline-block) {
    background: #2a2520 !important;
    border-color: #4a3a2e !important;
  }
  .rili-markdown-renderer { color: #e0d6cc !important; }
  .rili-markdown-renderer strong { color: #f0e6dc !important; }

  ai { color: #e0d6cc; }
  ai hd { color: #e8ddd1; background: linear-gradient(135deg, #3d2c1e, #2a2520); }
  ai details { background: #332e28; }
  ai details > summary { color: #e0d6cc; background: linear-gradient(to right, color-mix(in srgb, var(--ac, var(--accent)) 12%, #2a2520) 0%, transparent 60%); }
  .card-body, .inner-quote, .sg, .rel, .diary, .alert { background: #2f2a24; }
  .msg { background: #3a342e; color: #e0d6cc; }
  .msg[dn="你"] { background: linear-gradient(135deg, #4a3a2e, #3a342e); }
  .prog { background: #4a3a2e; }
  meter { background: #4a3a2e; }
  meter::-webkit-meter-bar { background: #4a3a2e; }
  ai th { background: #3a342e; color: #d0c6bc; }
  ai td { color: #c4b5a3; border-bottom-color: #4a3a2e; }
  ai tr:hover td { background: #3a342e; }
}