/* ⚠ 转换警告 ════════════════════════════════════════
   1 处游离 .bg-gray-100\/90 已按通用气泡处理
═══════════════════════════════════════════════════ */

/* ═══ 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平台按钮组保护（自动注入 — 防止按钮消失）═══ */
.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;
}
.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;
}

/* ========================================
   动画定义
   ======================================== */
@keyframes subtleShift {
    0% { background-position: 0% 0%; }
    100% { background-position: 100% 100%; }
}

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

/* ========================================
   全局重置（隐藏规则已注释，避免误伤）
   ======================================== */
/*
[class*="bg-[#F1CBCB]"],
[class*="bg-[#c9e1e9]"] {
    display: none !important;
}
*/

.flex.items-center.justify-center.size-6 > .flex.gap-2 {
    display: none !important;
}

/* ========================================
   聊天框基础样式（修复+性能优化）
   ======================================== */
.is-user > .border.border-muted,
.is-assistant > .border.border-muted {
    background: hsl(30, 20%, 98%) !important;
    border: 1px solid hsl(210, 15%, 80%) !important;
    border-radius: 12px !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08) !important;
    padding: 16px !important;
    position: relative !important;
    overflow: hidden !important;
    isolation: isolate !important;
    transition: box-shadow 0.3s ease-in-out, border-color 0.3s ease-in-out !important;
    /* ✅ 独立容器，防止内部变化影响外部布局 */
    contain: layout style !important;
}

/* ✅ 背景装饰伪元素 */
.is-user > .border.border-muted::before,
.is-assistant > .border.border-muted::before {
    content: "" !important;
    position: absolute !important;
    inset: 0 !important;
    z-index: 0 !important;
    opacity: 0.2 !important;
    background:
        radial-gradient(circle at 10% 20%, hsla(330, 50%, 70%, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 90% 80%, hsla(210, 20%, 50%, 0.1) 0%, transparent 50%) !important;
    background-size: 200% 200% !important;
    animation: subtleShift 30s ease-in-out infinite alternate !important;
    pointer-events: none !important;
    will-change: background-position !important;
}

/* ========================================
   Markdown 内容区
   ======================================== */
.rili-markdown-renderer {
    color: hsl(40, 10%, 20%) !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol" !important;
    line-height: 1.6 !important;
    font-size: 1rem !important;
    z-index: 1 !important;
    position: relative !important;
    background: transparent !important;
    word-break: break-word !important;
}

.rili-markdown-renderer h1, .rili-markdown-renderer h2, .rili-markdown-renderer h3,
.rili-markdown-renderer h4, .rili-markdown-renderer h5, .rili-markdown-renderer h6,
.rili-markdown-renderer strong {
    color: hsl(40, 10%, 20%) !important;
    font-weight: bold !important;
}

.rili-markdown-renderer a {
    color: hsl(330, 60%, 60%) !important;
    text-decoration: underline !important;
}

.rili-markdown-renderer pre, .rili-markdown-renderer code {
    background-color: hsl(210, 15%, 12%) !important;
    color: hsl(30, 15%, 88%) !important;
    border-radius: 6px !important;
    border: 1px solid hsl(210, 15%, 22%) !important;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace !important;
}

.rili-markdown-renderer pre {
    padding: 0.75rem 1rem !important;
    overflow-x: auto !important;
}

.rili-markdown-renderer code {
    padding: 0.2em 0.4em !important;
    font-size: 85% !important;
}

.rili-markdown-renderer pre > code {
    padding: 0 !important;
    background: none !important;
    border: none !important;
}

/* ========================================
   底部操作按钮
   ======================================== */
.bg-muted.rounded.flex.p-0\.5 > button.rounded-full.size-7 {
    color: hsl(210, 20%, 50%) !important;
    font-weight: 500 !important;
    text-transform: capitalize !important;
    border-radius: 6px !important;
    padding: 6px 12px !important;
    font-size: 0.875rem !important;
    min-width: unset !important;
    transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out !important;
    background-color: hsla(330, 50%, 70%, 0.15) !important;
    color: hsl(330, 60%, 60%) !important;
}

/* ========================================
   状态栏（模型名称、Token）—— 完全静态，消除打字闪烁
   ======================================== */
.flex.items-center.gap-2.text-xs.font-mono.text-muted-foreground,
.flex.items-center.gap-2.text-xs.font-mono.text-muted-foreground * {
    transition: none !important;
    animation: none !important;
    will-change: auto !important;
    transform: none !important;
    backface-visibility: visible !important;
    color: hsl(210, 20%, 50%) !important;
    font-size: 0.85rem !important;
    margin-left: 8px !important;
    opacity: 0.8 !important;
}

/* 如存在单独的 Token 消耗元素，同样静态化 */
.text-orange-500,
.text-orange-500 * {
    transition: none !important;
    animation: none !important;
    will-change: auto !important;
}

/* ========================================
   加载动画（三点跳跃）
   ======================================== */
.flex.items-center.justify-center.size-6 {
    position: relative !important;
    width: 24px !important;
    height: 20px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.flex.items-center.justify-center.size-6::before {
    content: "" !important;
    position: absolute !important;
    width: 100% !important;
    height: 100% !important;
    background-image: url("data:image/svg+xml,%3Csvg width='24' height='20' viewBox='0 0 24 20' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='4' cy='10' r='3' fill='hsl(330, 60%25, 60%25)'%3E%3Canimate attributeName='cy' values='10;7;10;13;10' dur='1.2s' repeatCount='indefinite' calcMode='spline' keySplines='0.4 0 0.2 1;0.4 0 0.2 1;0.4 0 0.2 1;0.4 0 0.2 1'/%3E%3C/circle%3E%3Ccircle cx='12' cy='10' r='3' fill='hsl(330, 60%25, 60%25)'%3E%3Canimate attributeName='cy' values='10;13;10;7;10' dur='1.2s' begin='0.2s' repeatCount='indefinite' calcMode='spline' keySplines='0.4 0 0.2 1;0.4 0 0.2 1;0.4 0 0.2 1;0.4 0 0.2 1'/%3E%3C/circle%3E%3Ccircle cx='20' cy='10' r='3' fill='hsl(330, 60%25, 60%25)'%3E%3Canimate attributeName='cy' values='10;7;10;13;10' dur='1.2s' begin='0.4s' repeatCount='indefinite' calcMode='spline' keySplines='0.4 0 0.2 1;0.4 0 0.2 1;0.4 0 0.2 1;0.4 0 0.2 1'/%3E%3C/circle%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: center !important;
    background-size: contain !important;
    will-change: transform !important;
}

/* ========================================
   Details / Summary 折叠面板
   ======================================== */
details {
    background: hsl(30, 20%, 98%) !important;
    border: 1px solid hsl(210, 15%, 80%) !important;
    border-radius: 12px !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08) !important;
    padding: 0 !important;
    margin-bottom: 12px !important;
    position: relative !important;
    overflow: hidden !important;
    isolation: isolate !important;
    transition: box-shadow 0.3s ease-in-out, border-color 0.3s ease-in-out !important;
    contain: layout style !important;
}

details::before {
    content: "" !important;
    position: absolute !important;
    inset: 0 !important;
    z-index: 0 !important;
    opacity: 0.2 !important;
    background:
        radial-gradient(circle at 10% 20%, hsla(330, 50%, 70%, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 90% 80%, hsla(210, 20%, 50%, 0.1) 0%, transparent 50%) !important;
    background-size: 200% 200% !important;
    animation: subtleShift 30s ease-in-out infinite alternate !important;
    pointer-events: none !important;
    will-change: background-position !important;
}

summary {
    display: flex !important;
    align-items: center !important;
    padding: 14px 18px !important;
    color: hsl(40, 10%, 20%) !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
    font-size: 1rem !important;
    font-weight: 600 !important;
    line-height: 1.5 !important;
    cursor: pointer !important;
    list-style: none !important;
    position: relative !important;
    z-index: 1 !important;
    border-bottom: 1px solid transparent !important;
    transition: border-color 0.2s ease !important;
    user-select: none !important;
    -webkit-tap-highlight-color: transparent !important;
}

summary::-webkit-details-marker {
    display: none !important;
}

summary::after {
    content: '▼' !important;
    font-size: 0.75em !important;
    color: hsl(210, 20%, 50%) !important;
    transition: transform 0.25s ease, color 0.25s ease !important;
    margin-left: auto !important;
    flex-shrink: 0 !important;
}

details[open] summary::after {
    transform: rotate(180deg) !important;
    color: hsl(330, 60%, 60%) !important;
}

details[open] summary {
    border-bottom-color: hsl(210, 15%, 80%) !important;
}

details > .rili-markdown-renderer,
details > *:not(summary) {
    position: relative !important;
    z-index: 1 !important;
    padding: 16px 18px !important;
    color: hsl(40, 10%, 20%) !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
    line-height: 1.6 !important;
    font-size: 1rem !important;
    background: transparent !important;
}

details[open] > *:not(summary) {
    animation: detailFadeIn 0.2s ease-in forwards !important;
}

/* ========================================
   减少动画偏好
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    .is-user > .border.border-muted::before,
    .is-assistant > .border.border-muted::before,
    details::before {
        animation: none !important;
        background-size: 100% 100% !important;
        background-position: center !important;
        will-change: auto !important;
    }

    details[open] > *:not(summary) {
        animation: none !important;
    }

    /* 确保所有元素回归普通流，释放合成层 */
    .is-user > .border.border-muted,
    .is-assistant > .border.border-muted,
    details,
    summary,
    summary::after,
    .bg-muted.rounded.flex.p-0\.5 > button.rounded-full.size-7,
    .flex.items-center.justify-center.size-6,
    .flex.items-center.justify-center.size-6::before {
        will-change: auto !important;
        transform: none !important;
        backface-visibility: visible !important;
        transition: none !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: 0.9rem !important;
    }

    details {
        border-radius: 8px !important;
        margin-bottom: 10px !important;
    }

    summary {
        padding: 12px 14px !important;
        font-size: 0.95rem !important;
    }

    details > .rili-markdown-renderer,
    details > *:not(summary) {
        padding: 12px 14px !important;
        font-size: 0.9rem !important;
    }

    .bg-muted.rounded.flex.p-0\.5 > button.rounded-full.size-7 {
        font-size: 0.75rem !important;
        padding: 4px 8px !important;
    }

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

    .flex.items-center.justify-center.size-6 {
        width: 20px !important;
        height: 16px !important;
    }

    .flex.items-center.justify-center.size-6::before {
        background-size: 100% auto !important;
    }
}