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

/* ===== 圣战预言·暗夜圣匣 聊天框美化方案 ===== */
/* 设计理念：以「圣剑沉睡于暗夜」为意象，深色基底搭配微光金线，
   营造5000年等待的神秘与庄重。绝对可读性为第一铁则。 */

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

/* 2. 统一聊天框样式 — 暗夜圣匣 */
.is-user > .border.border-muted,
.is-assistant > .border.border-muted {
    background: linear-gradient(145deg, #0F0E1A 0%, #1A1833 100%) !important;
    border: 1px solid rgba(180, 160, 100, 0.25) !important;
    border-radius: 12px !important;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(210, 190, 140, 0.08) !important;
    padding: 16px 20px !important;
    transition: box-shadow 0.3s ease, border-color 0.3s ease !important;
    position: relative !important;
    isolation: isolate !important;
    backdrop-filter: blur(2px) !important;
}

/* 3. 聊天气泡微光呼吸（伪元素装饰 — 金线纹章） */
.is-user > .border.border-muted,
.is-assistant > .border.border-muted::before {
    content: '' !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: 2px !important;
    background: linear-gradient(90deg, transparent, #C4A86A, #E8D5A0, #C4A86A, transparent) !important;
    opacity: 0.6 !important;
    z-index: 0 !important;
    pointer-events: none !important;
}

.is-user > .border.border-muted,
.is-assistant > .border.border-muted::after {
    content: '' !important;
    position: absolute !important;
    bottom: 0 !important;
    right: 0 !important;
    width: 48px !important;
    height: 48px !important;
    background: radial-gradient(circle at 100% 100%, rgba(196, 168, 106, 0.08), transparent 70%) !important;
    z-index: 0 !important;
    pointer-events: none !important;
}

/* 4. 主要文本内容 — 绝对清晰 */
.rili-markdown-renderer {
    color: #E8E0D4 !important;
    font-family: 'Inter', 'Segoe UI', 'Roboto', -apple-system, BlinkMacSystemFont, sans-serif !important;
    font-size: 15px !important;
    line-height: 1.75 !important;
    letter-spacing: 0.01em !important;
    font-weight: 400 !important;
    text-shadow: 0 0 0 transparent !important;
    /* 禁用任何光晕阴影 */;
    background: transparent !important;
    z-index: 1 !important;
    position: relative !important;
}

/* 强调文本 — 用加粗代替光晕 */
.rili-markdown-renderer strong {
    color: #F0E8D0 !important;
    font-weight: 700 !important;
    text-shadow: 0 0 0 transparent !important;
}

.rili-markdown-renderer em {
    color: #D4C8B0 !important;
    font-style: italic !important;
}

.rili-markdown-renderer a {
    color: #B8C8E8 !important;
    text-decoration: underline !important;
    text-underline-offset: 2px !important;
}

.rili-markdown-renderer code,
.rili-markdown-renderer pre {
    background: rgba(255, 255, 255, 0.06) !important;
    color: #E8E0D4 !important;
    border: 1px solid rgba(180, 160, 100, 0.15) !important;
    border-radius: 6px !important;
}

/* 5. 底部附加元素 — 浅色高对比 */
/* 操作按钮 */
.bg-muted.rounded.flex.p-0\.5 > button.rounded-full.size-7{
    color: #C8C0B0 !important;
    font-weight: 500 !important;
    letter-spacing: 0.02em !important;
    transition: color 0.2s ease !important;
}

.bg-muted.rounded.flex.p-0\.5 > button.rounded-full.size-7{
    color: #E8E0D4 !important;
    background: rgba(255, 255, 255, 0.05) !important;
}

/* 模型名称文本 */
.flex.items-center.gap-2.text-xs.font-mono.text-muted-foreground {
    color: #B0A898 !important;
    font-size: 13px !important;
    font-weight: 400 !important;
    letter-spacing: 0.02em !important;
}

/* Token消耗文本 */
/* [Token消耗hover逻辑转换未启用]
.text-orange-500 {
    color: #D4B88C !important;
    font-weight: 500 !important;
}
*/

/* 6. 输入框内文本（若存在） */
/* 覆盖平台默认输入区样式，保证深色背景下的可读性 */
.is-user > .border.border-muted,
.is-assistant > .border.border-muted input,
.is-user > .border.border-muted,
.is-assistant > .border.border-muted textarea,
.is-user > .border.border-muted,
.is-assistant > .border.border-muted [contenteditable="true"] {
    color: #E8E0D4 !important;
    background: transparent !important;
    caret-color: #C4A86A !important;
}

/* 7. 滚动条适配（深色） */
.is-user > .border.border-muted,
.is-assistant > .border.border-muted ::-webkit-scrollbar {
    width: 6px !important;
    height: 6px !important;
}

.is-user > .border.border-muted,
.is-assistant > .border.border-muted ::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.03) !important;
    border-radius: 3px !important;
}

.is-user > .border.border-muted,
.is-assistant > .border.border-muted ::-webkit-scrollbar-thumb {
    background: rgba(196, 168, 106, 0.3) !important;
    border-radius: 3px !important;
}

.is-user > .border.border-muted,
.is-assistant > .border.border-muted ::-webkit-scrollbar-thumb:hover {
    background: rgba(196, 168, 106, 0.5) !important;
}

/* 8. 移动端适配 — 保证小屏可读 */
@media (max-width: 480px) {
    .is-user > .border.border-muted,
.is-assistant > .border.border-muted {
        padding: 12px 14px !important;
        border-radius: 10px !important;
    }

    .rili-markdown-renderer {
        font-size: 14px !important;
        line-height: 1.65 !important;
    }

    .flex.items-center.gap-2.text-xs.font-mono.text-muted-foreground {
        font-size: 12px !important;
    }
}

/* 9. 低动效模式 — 保留微光但降低闪烁 */
@media (prefers-reduced-motion: reduce) {
    .is-user > .border.border-muted,
.is-assistant > .border.border-muted {
        transition: none !important;
    }

    .is-user > .border.border-muted,
.is-assistant > .border.border-muted::before {
        opacity: 0.4 !important;
    }
}

/* 10. 加载动画占位 — 默认隐藏并替换为SVG静默动画 */
.flex.items-center.justify-center.size-6 > .flex.gap-2 {
    display: none !important;
}

.flex.items-center.justify-center.size-6 {
    position: relative !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-height: 28px !important;
}

/* 用SMIL内嵌SVG替换加载点 — 即使CSS动画被禁用也能动 */
.flex.items-center.justify-center.size-6::before {
    content: '' !important;
    display: block !important;
    width: 64px !important;
    height: 20px !important;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='20' viewBox='0 0 64 20'%3E%3Ccircle cx='10' cy='10' r='4' fill='%23C4A86A'%3E%3Canimate attributeName='opacity' values='0.3;1;0.3' dur='1.2s' repeatCount='indefinite' begin='0s'/%3E%3C/circle%3E%3Ccircle cx='32' cy='10' r='4' fill='%23C4A86A'%3E%3Canimate attributeName='opacity' values='0.3;1;0.3' dur='1.2s' repeatCount='indefinite' begin='0.3s'/%3E%3C/circle%3E%3Ccircle cx='54' cy='10' r='4' fill='%23C4A86A'%3E%3Canimate attributeName='opacity' values='0.3;1;0.3' dur='1.2s' repeatCount='indefinite' begin='0.6s'/%3E%3C/circle%3E%3C/svg%3E") no-repeat center center !important;
    background-size: contain !important;
    z-index: 1 !important;
}
/* ===== 全局重置与容器 ===== */
ai {
  display: block;
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 14px 24px;
  background: radial-gradient(ellipse at 50% 0%, #121a2e 0%, #0b0f1a 100%);
  color: #c8d0dc;
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  border: 1px solid rgba(212, 165, 74, 0.15);
  border-radius: 12px;
  box-shadow: inset 0 0 60px rgba(78, 127, 184, 0.04), 0 4px 32px rgba(0,0,0,0.6);
}

/* ===== 滚动条 ===== */
ai ::-webkit-scrollbar { width: 4px; height: 4px; }
ai ::-webkit-scrollbar-track { background: #0b0f1a; }
ai ::-webkit-scrollbar-thumb { background: #d4a54a; border-radius: 4px; }

/* ===== 顶部状态栏 ===== */
ai hd {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 12px;
  padding: 8px 10px 6px;
  margin-bottom: 4px;
  border-bottom: 1px solid rgba(212, 165, 74, 0.2);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.3px;
  color: #9aa8b9;
}
ai hd s { color: #d4a54a; font-weight: 600; }
ai hd l, ai hd w { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
ai hd w { color: #e6c87a; }

/* ===== 经验/行动力条 ===== */
ai bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-around;
  gap: 4px;
  padding: 6px 10px;
  margin-bottom: 8px;
  background: rgba(19, 26, 43, 0.7);
  border-radius: 8px;
  border: 1px solid rgba(78, 127, 184, 0.12);
  font-size: 13px;
  font-weight: 500;
  color: #7e8fa1;
}
ai bar d { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
ai bar v { color: #d4a54a; font-weight: 700; }

/* ===== 正文区 ===== */
ai text {
  display: block;
  padding: 10px 12px;
  margin-bottom: 10px;
  background: rgba(19, 26, 43, 0.5);
  border-left: 2px solid #4e7fb8;
  border-radius: 0 8px 8px 0;
  font-size: 15px;
  color: #dae1ec;
}
ai text p { margin: 6px 0; }
ai text p:first-child { margin-top: 0; }
ai text p:last-child { margin-bottom: 0; }

/* ===== 折叠面板 ===== */
ai details {
  margin: 8px 0;
  border: 1px solid rgba(212, 165, 74, 0.1);
  border-radius: 8px;
  background: rgba(19, 26, 43, 0.35);
  backdrop-filter: blur(4px);
  transition: border-color 0.25s, box-shadow 0.25s;
  overflow: hidden;
}
ai details[open] {
  border-color: rgba(212, 165, 74, 0.25);
  box-shadow: 0 2px 12px rgba(212, 165, 74, 0.04);
}

/* Summary 定制 */
ai details summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  min-height: 44px;
  font-size: 15px;
  font-weight: 600;
  color: #d4a54a;
  cursor: pointer;
  list-style: none;
  border-left: 3px solid transparent;
  transition: background 0.2s, border-color 0.2s;
  user-select: none;
}
ai details summary::-webkit-details-marker,
ai details summary::marker {
  display: none;
  content: '';
}
ai details summary::before {
  content: '▶';
  display: inline-block;
  font-size: 10px;
  color: #7e8fa1;
  transition: transform 0.3s ease;
  width: 14px;
  text-align: center;
}
ai details[open] > summary::before {
  transform: rotate(90deg);
  color: #d4a54a;
}
ai details summary:hover {
  background: rgba(212, 165, 74, 0.04);
  border-left-color: #d4a54a;
}

/* ===== 内部数据区 ===== */
ai details[open] > :not(summary) {
  animation: fadeSlide 0.3s ease-out;
}
@keyframes fadeSlide {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

ai details p,
ai details div[class] {
  padding: 4px 14px 6px;
  margin: 0;
  font-size: 14px;
  color: #bcc6d6;
}

/* ===== 标签系统 ===== */
ai f { color: #d4a54a; font-weight: 600; }                          /* 角色名 */
ai v { color: #e6c87a; font-weight: 700; text-shadow: 0 0 6px rgba(212,165,74,0.15); } /* 数值高亮 */
ai b { color: #4e7fb8; font-weight: 600; }                          /* 技能/关键词 */
ai d { display: block; padding: 2px 0; }                              /* 数据行 */

/* ===== 分组标题 ===== */
ai p[t="g"] {
  margin: 8px 0 2px !important;
  padding: 4px 14px 2px !important;
  border-bottom: 1px solid rgba(78, 127, 184, 0.15);
  font-size: 13px;
  font-weight: 600;
  color: #7e8fa1;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

/* 角色卡内的分组用 f 强调 */
ai p[t="n"] { padding-left: 18px; }
ai p[t="n"] d { padding-left: 4px; border-left: 1px solid rgba(212,165,74,0.08); margin: 1px 0; }

/* ===== 主角状态特殊布局 ===== */
ai p[t="id"] { font-size: 15px; padding: 6px 14px 0; }
ai p[t="attr"] {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  font-size: 13px;
  color: #9aa8b9;
}
ai p[t="attr"] v { font-size: 14px; }
ai p[t="res"] { font-size: 13px; }
ai p[t="res"] v { color: #4e7fb8; }
ai p[t="ab"] { font-size: 13px; padding: 4px 14px 2px; }
ai p[t="inv"] { font-size: 13px; color: #7e8fa1; }

/* ===== 日程/任务样式 ===== */
ai p[t="sk"] d, 
ai p[t="q"] d,
ai p[t="tl"] {
  padding: 3px 6px;
  margin: 2px 0;
  font-size: 13px;
  border-left: 2px solid transparent;
  transition: border-color 0.15s;
}
ai p[t="sk"] d:hover,
ai p[t="q"] d:hover {
  border-left-color: #d4a54a;
  background: rgba(212,165,74,0.03);
}
ai p[t="sk"] b { color: #d4a54a; font-weight: 600; }
ai p[t="tl"] { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 14px; padding: 4px 14px; }

/* ===== 记忆/秘闻 ===== */
ai p[t="mem"] d,
ai p[t="sec"] d {
  padding: 4px 8px;
  margin: 3px 0;
  font-size: 13px;
  background: rgba(78, 127, 184, 0.04);
  border-radius: 4px;
  border-left: 2px solid rgba(78, 127, 184, 0.2);
}

/* ===== 行动推荐 ===== */
ai p[t="act"] d {
  padding: 6px 8px;
  margin: 4px 0;
  font-size: 14px;
  background: rgba(19, 26, 43, 0.6);
  border-radius: 6px;
  border: 1px solid rgba(212, 165, 74, 0.08);
  transition: background 0.2s, border-color 0.2s;
  cursor: default;
}
ai p[t="act"] d:hover {
  background: rgba(212, 165, 74, 0.06);
  border-color: rgba(212, 165, 74, 0.2);
}

/* ===== 社交热点图 ===== */
ai p[t="map"] {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 8px;
  padding: 6px 14px 8px;
}
ai p[t="map"] d {
  padding: 5px 8px;
  font-size: 13px;
  background: rgba(19, 26, 43, 0.5);
  border-radius: 6px;
  border-left: 3px solid #4e7fb8;
}
ai p[t="map"] d:nth-child(1) { border-left-color: #d4a54a; } /* 佩川 */
ai p[t="map"] d:nth-child(2) { border-left-color: #4e7fb8; } /* 镜枢 */
ai p[t="map"] d:nth-child(3) { border-left-color: #7e8fa1; } /* 崇岳 */
ai p[t="map"] d:nth-child(4) { border-left-color: #c94a4a; } /* 十三月 */
ai p[t="map"] d:nth-child(5) { border-left-color: #e6c87a; } /* 琥珀 */

/* ===== 响应式 ===== */
@media (max-width: 480px) {
  ai { padding: 8px 10px 18px; font-size: 15px; }
  ai hd { font-size: 12px; gap: 3px 8px; padding: 6px 8px; }
  ai bar { font-size: 12px; padding: 4px 8px; }
  ai text { font-size: 14px; padding: 8px 10px; }
  ai details summary { font-size: 14px; padding: 8px 12px; min-height: 40px; }
  ai details p, ai details div[class] { font-size: 13px; padding: 3px 12px 5px; }
  ai p[t="map"] { grid-template-columns: 1fr; }
  ai p[t="attr"] { gap: 2px 8px; font-size: 12px; }
}
/* ===== 当前对话NPC面板 ===== */
ai .npc-current {
  display: block;
  margin: 8px 0 12px;
  padding: 12px 14px;
  background: linear-gradient(135deg, rgba(212,165,74,0.08) 0%, rgba(19,26,43,0.7) 100%);
  border: 1px solid rgba(212,165,74,0.3);
  border-radius: 10px;
  box-shadow: 0 2px 16px rgba(212,165,74,0.06), inset 0 0 30px rgba(212,165,74,0.02);
  transition: border-color 0.3s, box-shadow 0.3s;
}
ai .npc-current:hover {
  border-color: rgba(212,165,74,0.5);
  box-shadow: 0 4px 24px rgba(212,165,74,0.1);
}

ai .npc-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
ai .npc-head .npc-icon {
  font-size: 28px;
  line-height: 1;
}
ai .npc-head .npc-name {
  font-size: 20px;
  font-weight: 700;
  color: #d4a54a;
  letter-spacing: 0.5px;
  text-shadow: 0 0 8px rgba(212,165,74,0.2);
}
ai .npc-head .npc-tag {
  font-size: 12px;
  font-weight: 600;
  color: #7e8fa1;
  background: rgba(78,127,184,0.12);
  padding: 2px 8px;
  border-radius: 12px;
  border: 1px solid rgba(78,127,184,0.2);
  text-transform: uppercase;
}

ai .npc-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-bottom: 6px;
  font-size: 14px;
  color: #bcc6d6;
}
ai .npc-stats .stat {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  background: rgba(19,26,43,0.5);
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,0.04);
}
ai .npc-stats .stat:first-child { color: #d4a54a; font-weight: 600; }

ai .npc-core {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-bottom: 4px;
  font-size: 14px;
  color: #9aa8b9;
}
ai .npc-core span {
  padding: 2px 0;
}
ai .npc-core span::before {
  content: '▸ ';
  color: #4e7fb8;
  font-size: 12px;
}

ai .npc-quote {
  margin: 6px 0 4px;
  padding: 6px 10px;
  background: rgba(212,165,74,0.06);
  border-left: 3px solid #d4a54a;
  border-radius: 0 4px 4px 0;
  font-style: italic;
  font-size: 15px;
  color: #e6c87a;
  line-height: 1.5;
}

ai .npc-extra {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  font-size: 13px;
  color: #7e8fa1;
  padding-top: 4px;
  border-top: 1px solid rgba(212,165,74,0.1);
}