/* AI 助手 Markdown 样式 */
.message-bubble.markdown-content {
    padding: 1rem 1.25rem !important;
    line-height: 1.8 !important;
    overflow-wrap: break-word;
    word-wrap: break-word;
    display: block !important;
    position: relative;
    isolation: isolate;
}

.message-bubble.markdown-content h1, 
.message-bubble.markdown-content h2, 
.message-bubble.markdown-content h3 {
    margin-top: 1.2em;
    margin-bottom: 0.8em;
    font-weight: 600;
    line-height: 1.5;
    padding-top: 0.2em;
}

.message-bubble.markdown-content h1 { 
    font-size: 1.2em; 
}

.message-bubble.markdown-content h2 { 
    font-size: 1.1em; 
}

.message-bubble.markdown-content h3 { 
    font-size: 1em; 
}

.message-bubble.markdown-content p { 
    margin: 0.9em 0 !important; 
    line-height: 1.7 !important;
    padding: 0 !important;
    display: block !important;
}

.message-bubble.markdown-content ul, 
.message-bubble.markdown-content ol {
    margin: 1em 0 !important;
    padding-left: 1.5em !important;
    line-height: 1.7 !important;
    display: block !important;
    list-style-position: outside !important;
}

.message-bubble.markdown-content li { 
    margin: 0.5em 0 !important;
    line-height: 1.6 !important;
    display: list-item !important;
    list-style-type: disc !important;
}

.message-bubble.markdown-content ol > li {
    list-style-type: decimal !important;
}

.message-bubble.markdown-content code {
    background: rgba(0,0,0,0.2);
    padding: 0.1em 0.3em;
    border-radius: 3px;
    font-size: 0.9em;
}

.message-bubble.markdown-content pre {
    background: rgba(0,0,0,0.3);
    padding: 1em;
    border-radius: 6px;
    overflow-x: auto;
    margin: 1em 0;
    line-height: 1.5;
}

.message-bubble.markdown-content pre code {
    background: none;
    padding: 0;
}

.message-bubble.markdown-content strong { 
    font-weight: 600; 
}

.message-bubble.markdown-content blockquote {
    border-left: 3px solid var(--primary);
    margin: 1em 0;
    padding: 0.5em 0 0.5em 1em;
    opacity: 0.9;
    line-height: 1.7;
}

/* 深色主题适配 */
[data-theme="dark"] .message-bubble.markdown-content code {
    background: rgba(0, 0, 0, 0.3);
    color: var(--text-primary);
}

[data-theme="dark"] .message-bubble.markdown-content pre {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--glass-border);
}

[data-theme="dark"] .message-bubble.markdown-content pre code {
    background: none;
    color: var(--text-primary);
}

[data-theme="dark"] .message-bubble.markdown-content blockquote {
    border-left-color: var(--primary);
    background: rgba(99, 102, 241, 0.05);
    padding-left: 1em;
}

/* 浅色主题适配 */
[data-theme="light"] .message-bubble.markdown-content code {
    background: rgba(99, 102, 241, 0.12);
    color: var(--primary);
}

[data-theme="light"] .message-bubble.markdown-content pre {
    background: #f1f5f9;
    border: 1px solid rgba(99, 102, 241, 0.15);
}

[data-theme="light"] .message-bubble.markdown-content pre code {
    color: #334155;
}

[data-theme="light"] .message-bubble.markdown-content blockquote {
    border-left-color: var(--primary);
    background: rgba(99, 102, 241, 0.05);
}

/* 确保消息气泡内容不重叠 */
.message-bubble.markdown-content * {
    box-sizing: border-box;
}

/* 移除可能的重叠样式 */
.message-bubble.markdown-content * {
    position: static !important;
    z-index: auto !important;
}

/* 第一个元素 */
.message-bubble.markdown-content > *:first-child {
    margin-top: 0 !important;
    padding-top: 0 !important;
}

/* 最后一个元素 */
.message-bubble.markdown-content > *:last-child {
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
}

/* 重置继承问题，确保行高正确 */
.message-bubble.markdown-content {
    line-height: 1.8 !important;
    vertical-align: baseline !important;
}

.message-bubble.markdown-content p {
    line-height: 1.7 !important;
    margin: 0.9em 0 !important;
    display: block !important;
}

.message-bubble.markdown-content li {
    line-height: 1.6 !important;
    display: list-item !important;
}

.message-bubble.markdown-content div {
    line-height: 1.7 !important;
}

/* 确保代码块不会与周围内容重叠 */
.message-bubble.markdown-content pre {
    margin-top: 1.2em !important;
    margin-bottom: 1.2em !important;
    display: block !important;
    clear: both !important;
    min-height: 2em !important;
}

/* 确保列表项之间有足够间距 */
.message-bubble.markdown-content li + li {
    margin-top: 0.5em !important;
}

/* 确保列表容器不会重叠 */
.message-bubble.markdown-content ul,
.message-bubble.markdown-content ol {
    margin-top: 1em !important;
    margin-bottom: 1em !important;
    display: block !important;
    clear: both !important;
}

/* 确保引用块不会重叠 */
.message-bubble.markdown-content blockquote {
    margin-top: 1em !important;
    margin-bottom: 1em !important;
    display: block !important;
    clear: both !important;
}

/* 确保所有文本内容容器正确显示 */
.message-bubble.markdown-content {
    min-height: 1.8em !important;
    overflow: visible !important;
}

/* 修复可能的行高问题 */
.message-bubble.markdown-content {
    min-height: 1.8em;
}

/* br 标签不需要特殊样式，保持默认行为 */
.message-bubble.markdown-content br {
    line-height: inherit;
}

/* 确保聊天历史区域有正确的间距 */
.chat-history {
    gap: 1rem !important;
    padding: 1.25rem 1.5rem !important;
}

/* 欢迎文本样式 */
.chat-welcome {
    padding: 2rem 1rem !important;
    margin: 0 !important;
    display: block !important;
    width: 100% !important;
    flex-shrink: 0 !important;
}

.chat-welcome h5 {
    margin-top: 1rem !important;
    margin-bottom: 0.75rem !important;
    padding: 0 !important;
    line-height: 1.5 !important;
    display: block !important;
}

.chat-welcome p {
    margin: 0.5rem 0 !important;
    padding: 0 !important;
    line-height: 1.6 !important;
    display: block !important;
}

.chat-welcome .small {
    font-size: 0.875rem !important;
    line-height: 1.5 !important;
}

.chat-welcome i {
    margin-bottom: 1rem !important;
    display: block !important;
}

/* 确保消息之间有足够间距 */
.chat-history .chat-message {
    margin-bottom: 1.5rem !important;
    margin-top: 0 !important;
    padding: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    clear: both !important;
    width: 100% !important;
}

.chat-history .chat-message:last-child {
    margin-bottom: 1rem !important;
}

.chat-history .chat-message.user {
    align-items: flex-end !important;
}

.chat-history .chat-message.assistant {
    align-items: flex-start !important;
}

/* 确保消息气泡内容正确显示 */
.chat-history .message-bubble {
    display: block !important;
    position: relative !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    white-space: normal !important;
    margin: 0 !important;
    padding: 0.75rem 1rem !important;
    box-sizing: border-box !important;
}

/* 确保所有文本元素都有正确的显示方式 */
.message-bubble.markdown-content {
    display: block !important;
    position: static !important;
}

.message-bubble.markdown-content * {
    position: static !important;
    z-index: auto !important;
}

/* 内联元素应该保持内联 */
.message-bubble.markdown-content code,
.message-bubble.markdown-content strong,
.message-bubble.markdown-content em,
.message-bubble.markdown-content a,
.message-bubble.markdown-content span {
    display: inline !important;
}

/* 列表项应该保持列表项显示 */
.message-bubble.markdown-content li {
    display: list-item !important;
}

/* 列表容器 */
.message-bubble.markdown-content ul,
.message-bubble.markdown-content ol {
    display: block !important;
}

/* 块级元素应该保持块级显示 */
.message-bubble.markdown-content div {
    display: block !important;
}

/* 确保段落不会重叠 */
.message-bubble.markdown-content p {
    display: block !important;
    margin: 0.9em 0 !important;
    padding: 0 !important;
    clear: both !important;
    min-height: 1.5em !important;
}

.message-bubble.markdown-content p:first-child {
    margin-top: 0 !important;
}

.message-bubble.markdown-content p:last-child {
    margin-bottom: 0 !important;
}

/* 确保标题不会重叠 */
.message-bubble.markdown-content h1,
.message-bubble.markdown-content h2,
.message-bubble.markdown-content h3,
.message-bubble.markdown-content h4,
.message-bubble.markdown-content h5,
.message-bubble.markdown-content h6 {
    display: block !important;
    margin-top: 1.2em !important;
    margin-bottom: 0.8em !important;
    padding: 0 !important;
    clear: both !important;
    min-height: 1.2em !important;
}

.message-bubble.markdown-content > h1:first-child,
.message-bubble.markdown-content > h2:first-child,
.message-bubble.markdown-content > h3:first-child,
.message-bubble.markdown-content > h4:first-child,
.message-bubble.markdown-content > h5:first-child,
.message-bubble.markdown-content > h6:first-child {
    margin-top: 0 !important;
}

/* ============================================
   深色主题适配 - 强制覆盖所有 .text-muted 样式
   使用最高优先级选择器确保覆盖 enhanced.css 和 Bootstrap
   注意：深色主题时 data-theme 属性会被移除，所以使用 :not([data-theme="light"])
   ============================================ */

/* 覆盖 enhanced.css 中所有在聊天区域的 .text-muted 样式 - 最高优先级 */
:not([data-theme="light"]) .chat-box .text-muted,
:not([data-theme="light"]) .chat-box div.text-muted,
:not([data-theme="light"]) .chat-box span.text-muted,
:not([data-theme="light"]) .chat-box p.text-muted,
:not([data-theme="light"]) .chat-history .text-muted,
:not([data-theme="light"]) .chat-history div.text-muted,
:not([data-theme="light"]) .chat-history span.text-muted,
:not([data-theme="light"]) .chat-history p.text-muted,
:not([data-theme="light"]) .chat-input-area .text-muted,
:not([data-theme="light"]) .chat-input-area div.text-muted,
:not([data-theme="light"]) .chat-input-area span.text-muted,
:not([data-theme="light"]) .chat-input-area p.text-muted {
    color: var(--text-muted) !important;
    background-color: transparent !important;
    background: transparent !important;
    padding: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    font-weight: normal !important;
    display: block !important;
    align-items: unset !important;
    flex-direction: unset !important;
    font-size: inherit !important;
}

/* 覆盖 enhanced.css 中的 .text-muted i 样式 */
:not([data-theme="light"]) .chat-box .text-muted i,
:not([data-theme="light"]) .chat-box div.text-muted i,
:not([data-theme="light"]) .chat-box span.text-muted i,
:not([data-theme="light"]) .chat-box p.text-muted i,
:not([data-theme="light"]) .chat-history .text-muted i,
:not([data-theme="light"]) .chat-history div.text-muted i,
:not([data-theme="light"]) .chat-history span.text-muted i,
:not([data-theme="light"]) .chat-history p.text-muted i,
:not([data-theme="light"]) .chat-input-area .text-muted i,
:not([data-theme="light"]) .chat-input-area div.text-muted i,
:not([data-theme="light"]) .chat-input-area span.text-muted i,
:not([data-theme="light"]) .chat-input-area p.text-muted i {
    background: transparent !important;
    -webkit-background-clip: unset !important;
    background-clip: unset !important;
    -webkit-text-fill-color: var(--text-muted) !important;
    color: var(--text-muted) !important;
    margin-right: 0.25rem !important;
    font-size: inherit !important;
}

/* chatWelcome 元素本身 - 最高优先级覆盖 enhanced.css */
:not([data-theme="light"]) #chatWelcome,
:not([data-theme="light"]) #chatWelcome.text-center,
:not([data-theme="light"]) #chatWelcome.text-center.text-muted,
:not([data-theme="light"]) #chatWelcome.py-4.text-muted,
:not([data-theme="light"]) #chatWelcome.text-center.py-4.text-muted,
:not([data-theme="light"]) .chat-welcome,
:not([data-theme="light"]) .chat-welcome.text-center,
:not([data-theme="light"]) .chat-welcome.text-center.text-muted,
:not([data-theme="light"]) .chat-welcome.py-4.text-muted {
    color: var(--text-primary) !important;
    background: transparent !important;
    background-color: transparent !important;
    /* 覆盖 enhanced.css 中的 .text-muted 样式 */
    display: block !important;
    align-items: unset !important;
    flex-direction: unset !important;
    padding: 2rem 1rem !important;
    margin: 0 !important;
    width: 100% !important;
    flex-shrink: 0 !important;
    font-weight: normal !important;
    border-radius: 0 !important;
    box-shadow: none !important;
}

/* chatWelcome 内的标题 */
:not([data-theme="light"]) #chatWelcome h5,
:not([data-theme="light"]) .chat-welcome h5 {
    color: var(--text-primary) !important;
}

/* chatWelcome 内的段落 */
:not([data-theme="light"]) #chatWelcome p,
:not([data-theme="light"]) .chat-welcome p {
    color: var(--text-secondary) !important;
}

/* chatWelcome 内的 .text-muted 元素 - 使用 ID 选择器提高优先级 */
:not([data-theme="light"]) #chatWelcome.text-muted,
:not([data-theme="light"]) #chatWelcome .text-muted,
:not([data-theme="light"]) #chatWelcome.text-center.text-muted,
:not([data-theme="light"]) #chatWelcome.text-center .text-muted,
:not([data-theme="light"]) #chatWelcome.py-4.text-muted,
:not([data-theme="light"]) #chatWelcome.py-4 .text-muted,
:not([data-theme="light"]) #chatWelcome.text-center.py-4.text-muted,
:not([data-theme="light"]) #chatWelcome.text-center.py-4 .text-muted,
:not([data-theme="light"]) .chat-welcome.text-muted,
:not([data-theme="light"]) .chat-welcome .text-muted,
:not([data-theme="light"]) .chat-welcome.text-center.text-muted,
:not([data-theme="light"]) .chat-welcome.text-center .text-muted {
    color: var(--text-muted) !important;
    background-color: transparent !important;
    background: transparent !important;
    padding: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    display: block !important;
    font-weight: normal !important;
    align-items: unset !important;
    flex-direction: unset !important;
    font-size: inherit !important;
}

/* chatWelcome 内的图标 */
:not([data-theme="light"]) #chatWelcome i,
:not([data-theme="light"]) .chat-welcome i {
    color: var(--primary) !important;
}

:not([data-theme="light"]) #chatWelcome .text-muted i,
:not([data-theme="light"]) .chat-welcome .text-muted i {
    color: var(--text-muted) !important;
    background: transparent !important;
    -webkit-background-clip: unset !important;
    background-clip: unset !important;
    -webkit-text-fill-color: var(--text-muted) !important;
}

/* 深色主题适配 - 输入区域底部提示栏 */
:not([data-theme="light"]) .chat-input-area .d-flex.justify-content-between.align-items-center.mt-2 {
    color: var(--text-primary) !important;
    background: transparent !important;
    background-color: transparent !important;
}

/* 覆盖 enhanced.css 中的 .text-muted 样式 - 使用更具体的选择器 */
:not([data-theme="light"]) .chat-input-area .d-flex.justify-content-between.align-items-center.mt-2 .text-muted,
:not([data-theme="light"]) .chat-input-area .d-flex.justify-content-between.align-items-center.mt-2 span.text-muted,
:not([data-theme="light"]) .chat-input-area .d-flex.justify-content-between.align-items-center.mt-2 .small.text-muted,
:not([data-theme="light"]) .chat-input-area .d-flex.justify-content-between.align-items-center.mt-2 span.small.text-muted {
    color: var(--text-muted) !important;
    background-color: transparent !important;
    background: transparent !important;
    padding: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    display: inline !important;
    font-weight: normal !important;
    align-items: unset !important;
    font-size: inherit !important;
}

:not([data-theme="light"]) .chat-input-area .d-flex.justify-content-between.align-items-center.mt-2 .text-muted i,
:not([data-theme="light"]) .chat-input-area .d-flex.justify-content-between.align-items-center.mt-2 span.text-muted i,
:not([data-theme="light"]) .chat-input-area .d-flex.justify-content-between.align-items-center.mt-2 .small.text-muted i,
:not([data-theme="light"]) .chat-input-area .d-flex.justify-content-between.align-items-center.mt-2 span.small.text-muted i {
    color: var(--text-muted) !important;
    background: transparent !important;
    -webkit-background-clip: unset !important;
    background-clip: unset !important;
    -webkit-text-fill-color: var(--text-muted) !important;
    margin-right: 0.25rem !important;
    font-size: inherit !important;
}

:not([data-theme="light"]) .chat-input-area .d-flex.justify-content-between.align-items-center.mt-2 .small {
    color: var(--text-muted) !important;
}

:not([data-theme="light"]) .chat-input-area .d-flex.justify-content-between.align-items-center.mt-2 i {
    color: var(--text-muted) !important;
}

:not([data-theme="light"]) .chat-input-area .d-flex.justify-content-between.align-items-center.mt-2 .btn {
    color: var(--text-primary) !important;
    border-color: var(--glass-border) !important;
    background: rgba(255, 255, 255, 0.05) !important;
}

:not([data-theme="light"]) .chat-input-area .d-flex.justify-content-between.align-items-center.mt-2 .btn:hover {
    background: rgba(99, 102, 241, 0.2) !important;
    border-color: var(--primary) !important;
    color: var(--primary-light) !important;
}

:not([data-theme="light"]) .chat-input-area .d-flex.justify-content-between.align-items-center.mt-2 .btn-outline-secondary {
    color: var(--text-secondary) !important;
    border-color: var(--glass-border) !important;
}

:not([data-theme="light"]) .chat-input-area .d-flex.justify-content-between.align-items-center.mt-2 .btn-outline-danger {
    color: #f87171 !important;
    border-color: rgba(248, 113, 113, 0.5) !important;
}

:not([data-theme="light"]) .chat-input-area .d-flex.justify-content-between.align-items-center.mt-2 .btn-outline-danger:hover {
    background: rgba(248, 113, 113, 0.2) !important;
    border-color: #f87171 !important;
    color: #fca5a5 !important;
}

/* 浅色主题适配 - chatWelcome */
[data-theme="light"] #chatWelcome,
[data-theme="light"] .chat-welcome {
    color: var(--text-primary) !important;
}

[data-theme="light"] #chatWelcome .text-muted,
[data-theme="light"] .chat-welcome .text-muted {
    color: var(--text-muted) !important;
}

/* 浅色主题适配 - 输入区域底部提示栏 */
[data-theme="light"] .chat-input-area .d-flex.justify-content-between.align-items-center.mt-2 .text-muted {
    color: var(--text-muted) !important;
}

/* 响应式调整 */
@media (max-width: 768px) {
    .chat-box {
        height: 500px;
        min-height: 500px;
    }
    
    .message-bubble {
        max-width: 90% !important;
        font-size: 0.85rem;
    }
}

