:root {
    --sidebar-width: 258px;
    --config-width: 258px;
    --chat-line-height: 1.1;
    --chat-paragraph-margin: 0.1rem;
    --primary: #2563eb;
    --primary-hover: #3b82f6;
    --danger: #ef4444;
    color-scheme: light; /* 阻止浏览器自动跟随系统暗色模式 */
}

/* ===== 滚动条 ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: #d2dceb; border-radius: 10px; }
.dark ::-webkit-scrollbar-thumb { background: #3a4a62; }

/* ===== 侧边栏与配置面板过渡 ===== */
.sidebar, .config-panel { transition: all 0.3s ease; }
.sidebar.collapsed { width: 0 !important; opacity: 0; transform: translateX(-20px); padding: 0; margin: 0; border: none; }
.config-panel.hidden-panel { width: 0 !important; opacity: 0; transform: translateX(20px); padding: 0; margin: 0; border: none; }

/* ===== 全局基础样式 ===== */
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
}
body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: #f9fafb;
    line-height: 1.6;
    color: #1f2937;
}
.dark body { background: #111827; color: #e5e7eb; }
*:focus { outline: none; }

/* ===== 主容器确保全屏 ===== */
.h-screen {
    height: 100vh;
    height: 100dvh; /* 动态视口高度，移动端更好 */
    display: flex;
    overflow: hidden; /* 防止子元素溢出 */
}

/* ===== 聊天区域 ===== */
#chatBox {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
    min-height: 0; /* 防止 flex 溢出 */
}
.chat-messages-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 0 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    flex: 1;
}

/* ===== 消息行 ===== */
.message-row { display: flex; gap: 1rem; align-items: flex-start; }
.message-row.user { flex-direction: row-reverse; }
.message-row.assistant { justify-content: center; }
.message-row.user { justify-content: flex-end; }

/* ===== 消息内容包装器 ===== */
.message-content-wrapper {
    display: flex;
    flex-direction: column;
    flex: 1;
    max-width: calc(100% - 50px);
}
.message-row.user .message-content-wrapper { align-items: flex-end; }
.message-row.assistant .message-content-wrapper { max-width: 90%; margin: 0 auto; }

/* ===== 头像 ===== */
.avatar {
    width: 36px; height: 36px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.9rem; font-weight: 500; flex-shrink: 0;
}
.avatar.user { background: #e5e7eb; color: #1f2937; }
.avatar.assistant { background: var(--primary); color: white; }
.dark .avatar.user { background: #374151; color: #f3f4f6; }
.dark .avatar.assistant { background: var(--primary-hover); }

/* ===== 气泡 ===== */
.bubble {
    max-width: 90%;
    padding: 0.4rem 0.6rem;
    border-radius: 1.2rem;
    position: relative;
    word-wrap: break-word;
    font-size: 0.95rem;
    font-weight: 400;
}
.bubble.user {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 0.25rem;
}
.bubble.assistant {
    background: white;
    color: #1f2937;
    border-bottom-left-radius: 0.25rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.dark .bubble.assistant { background: #1f2937 !important; color: #f3f4f6 !important; }

/* ===== Markdown 样式 ===== */
.markdown-body {
    line-height: var(--chat-line-height);
    white-space: pre-wrap;
}
.markdown-body > * {
    margin-top: 0;
    margin-bottom: var(--chat-paragraph-margin);
}
.markdown-body > :last-child { margin-bottom: 0; }
.markdown-body li > * { margin-top: 0; margin-bottom: 0; }
.markdown-body strong { font-weight: 600; }
.markdown-body em { font-style: italic; }

/* 段落前缀 */
.paragraph-prefix-dot .markdown-body > p::before,
.paragraph-prefix-dot .markdown-body > h1::before,
.paragraph-prefix-dot .markdown-body > h2::before,
.paragraph-prefix-dot .markdown-body > h3::before,
.paragraph-prefix-dot .markdown-body > h4::before,
.paragraph-prefix-dot .markdown-body > h5::before,
.paragraph-prefix-dot .markdown-body > h6::before {
    content: "• ";
    color: #9ca3af;
    font-weight: normal;
    margin-right: 0.25rem;
}
.paragraph-prefix-dash .markdown-body > p::before,
.paragraph-prefix-dash .markdown-body > h1::before,
.paragraph-prefix-dash .markdown-body > h2::before,
.paragraph-prefix-dash .markdown-body > h3::before,
.paragraph-prefix-dash .markdown-body > h4::before,
.paragraph-prefix-dash .markdown-body > h5::before,
.paragraph-prefix-dash .markdown-body > h6::before {
    content: "- ";
    color: #9ca3af;
    font-weight: normal;
    margin-right: 0.25rem;
}

/* 代码块 */
.markdown-body pre {
    padding: 0.5rem; border-radius: 0.6rem; overflow-x: auto;
    position: relative; white-space: pre;
    background: #f3f4f6;
}
.dark .markdown-body pre { background: #2d3748; }
.markdown-body code {
    padding: 0.1rem 0.3rem; border-radius: 0.3rem; font-size: 0.9em;
    background: #e5e7eb; color: #1f2937;
}
.dark .markdown-body code { background: #4b5563; color: #f3f4f6; }
.markdown-body pre code { padding: 0; background: transparent; }
.markdown-body pre .hljs { background: transparent; }

/* 列表 */
.markdown-body ul, .markdown-body ol {
    margin: 0 0 var(--chat-paragraph-margin) 0;
    padding-left: 1.5rem;
}
.markdown-body li { margin: 0; }

/* 表格 */
.markdown-body table {
    display: block; overflow-x: auto; border-collapse: collapse;
    width: 100%; margin: 0 0 var(--chat-paragraph-margin) 0; white-space: nowrap;
}
.markdown-body th, .markdown-body td {
    border: 1px solid #d1d5db; padding: 0.4rem; text-align: left;
}
.dark .markdown-body th, .dark .markdown-body td { border-color: #4b5563; }
.markdown-body th { background: #f3f4f6; font-weight: 600; }
.dark .markdown-body th { background: #2d3748; }

/* 引用 */
.markdown-body blockquote {
    margin: 0 0 var(--chat-paragraph-margin) 0;
    padding: 0.1rem 0.8rem;
    border-left: 4px solid #e5e7eb;
}
.dark .markdown-body blockquote { border-left-color: #4b5563; }

/* ===== 代码复制按钮 ===== */
.code-copy-btn {
    position: absolute; top: 8px; right: 8px;
    background: rgba(255,255,255,0.8); backdrop-filter: blur(4px);
    border: 1px solid #e5e7eb; border-radius: 20px;
    width: 28px; height: 28px; display: flex; align-items: center;
    justify-content: center; cursor: pointer; opacity: 0;
    transition: opacity 0.2s; color: #4b5563; z-index: 5;
}
.dark .code-copy-btn {
    background: #374151; border-color: #4b5563; color: #d1d5db;
}
.markdown-body pre:hover .code-copy-btn { opacity: 1; }
.code-copy-btn svg { width: 16px; height: 16px; }

/* ===== 深度思考折叠块 ===== */
details.reasoning-details {
    cursor: pointer;
    margin-bottom: 4px;
}
details.reasoning-details summary {
    font-weight: 500;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
    user-select: none;
    font-size: 0.9rem;
}
details.reasoning-details summary::before {
    content: "▶";
    font-size: 0.8rem;
    transition: transform 0.2s ease-in-out;
}
details.reasoning-details[open] summary::before { content: "▼"; }
.reasoning-content {
    margin-top: 4px;
    padding: 4px 8px;
    border-left: 2px solid #9a8cc0;
    font-style: italic;
    white-space: pre-wrap;
    font-size: 0.85rem;
    background: rgba(200, 215, 240, 0.2);
    border-radius: 6px;
    color: #2c3e6b;
    max-height: 999999px;
    opacity: 1;
    overflow: visible;
    transition: max-height 0.3s ease-out, opacity 0.2s ease-out, margin 0.2s;
}
.dark .reasoning-content {
    background: rgba(50, 60, 90, 0.3);
    border-left-color: #b39ddb;
    color: #cfd9f0;
}

/* ===== 消息页脚 ===== */
.message-footer {
    font-size: 0.7rem; color: #9ca3af; margin-top: 0.3rem; text-align: right;
}
.dark .message-footer { color: #6b7280; }

/* ===== 欢迎容器 ===== */
.welcome-container {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; height: 100%; color: #9ca3af;
}
.dark .welcome-container { color: #6b7280; }
.welcome-container .brand { font-size: 3rem; font-weight: 300; letter-spacing: -0.02em; margin-bottom: 0.5rem; }

/* ===== 输入区域 ===== */
.input-area {
    max-width: 850px;
    margin: 0 auto 1rem;
    padding: 0 1rem;
    width: 100%;
    position: relative;
}

/* ===== 发送/停止按钮 ===== */
.send-stop-container {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    transition: top 0.2s ease;
    z-index: 10;
}
.send-btn, .stop-btn {
    position: absolute; top: 0; left: 0; width: 44px; height: 44px;
    border-radius: 50%; display: flex; align-items: center;
    justify-content: center; transition: all 0.2s; cursor: pointer;
}
.send-btn { background: var(--primary); color: white; }
.stop-btn { background: var(--danger); color: white; opacity: 0; pointer-events: none; }
.send-btn.hidden { opacity: 0; pointer-events: none; }
.stop-btn.visible { opacity: 1; pointer-events: auto; }
.send-btn:hover, .stop-btn:hover { transform: scale(1.1); }

/* ===== 文件预览 ===== */
.file-preview-container {
    display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.5rem;
}
.file-tag {
    display: inline-flex; align-items: center; gap: 0.25rem;
    background: #e5e7eb; border-radius: 20px; padding: 0.2rem 0.6rem;
    font-size: 0.75rem; color: #1f2937; max-width: 200px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dark .file-tag { background: #374151; color: #f3f4f6; }
.file-tag.error { background: #fee2e2; color: #b91c1c; }
.dark .file-tag.error { background: #7f1d1d; color: #fecaca; }
.file-tag .remove-file {
    cursor: pointer; margin-left: 0.25rem; font-weight: bold;
}
.file-tag .remove-file:hover { color: var(--danger); }
.file-tag .file-icon {
    width: 14px; height: 14px; margin-right: 4px; color: currentColor; vertical-align: middle;
}
.drop-overlay-icon { margin-right: 6px; vertical-align: middle; }

/* ===== 配置面板 ===== */
.config-panel {
    background: white; border-left: 1px solid #e5e7eb;
}
.dark .config-panel { background: #1f2937; border-left-color: #1f2937; }

/* ===== 下拉菜单选项 ===== */
select, select option { background-color: inherit; color: inherit; }
select option { background: white; color: #1f2937; }
.dark select option { background: #1f2937; color: #f3f4f6; }

/* ===== 快速到底部按钮 ===== */
#scrollToBottomBtn {
    position: absolute;
    bottom: 80px !important;
    right: 20px !important;
    top: auto !important;
    left: auto !important; /* 避免 left 固定 */
    width: 36px !important;
    height: 36px !important;
    z-index: 100 !important;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    background: white;
    border: 1px solid #e5e7eb;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    display: flex !important;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    cursor: pointer;
    color: #4b5563;
}
#scrollToBottomBtn.visible { opacity: 1 !important; visibility: visible !important; }
#scrollToBottomBtn:hover {
    transform: scale(1.1);
    background: #f9fafb;
}
.dark #scrollToBottomBtn {
    background: #1f2937;
    border-color: #374151;
    color: #d1d5db;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.dark #scrollToBottomBtn:hover { background: #374151; }
#scrollToBottomBtn svg { width: 18px; height: 18px; }

/* ===== 侧边栏折叠按钮 ===== */
.sidebar-collapse-btn {
    font-size: 1.5rem; padding: 0.75rem 1rem; line-height: 1;
    border-radius: 9999px; transition: background-color 0.2s;
}
.sidebar-collapse-btn:hover { background-color: rgba(0,0,0,0.05); }
.dark .sidebar-collapse-btn:hover { background-color: rgba(255,255,255,0.1); }

/* ===== 头部菜单按钮 ===== */
.header-menu-btn {
    padding: 0.5rem 0.75rem;
    font-size: 1.25rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 9999px;
    background: white;
    border: 1px solid #e5e7eb;
    color: #4b5563;
    transition: all 0.2s;
}
.header-menu-btn:hover { background-color: #f3f4f6; }
.dark .header-menu-btn {
    background: #1f2937;
    border-color: #374151;
    color: #d1d5db;
}
.dark .header-menu-btn:hover { background: #374151; }

/* ===== 输入框包装与拖拽层 ===== */
.input-wrapper {
    position: relative;
    background: white;
    border-radius: 9999px;
    border: 1px solid #e5e7eb;
    overflow: hidden;
}
.dark .input-wrapper {
    background: #1f2937;
    border-color: #374151;
}
.drop-overlay-input {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(37, 99, 235, 0.15); backdrop-filter: blur(3px);
    border: 3px dashed var(--primary); border-radius: 9999px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1rem; color: var(--primary); font-weight: 600; pointer-events: none;
    z-index: 30; opacity: 0; visibility: hidden; transition: opacity 0.2s;
}
.dark .drop-overlay-input {
    background: rgba(59, 130, 246, 0.2); border-color: var(--primary-hover); color: var(--primary-hover);
}
.drop-overlay-input.show { opacity: 1; visibility: visible; }

/* ===== 输入框 ===== */
#userInput {
    resize: none;
    overflow-y: auto;
    min-height: 44px;
    max-height: 150px;
    padding: 0.75rem 1rem;
    padding-right: 60px;
    line-height: 1.5;
    box-sizing: border-box;
    transition: height 0.2s ease;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    outline: none !important;
}
#userInput::-webkit-scrollbar { width: 8px; }
#userInput::-webkit-scrollbar-track { background: transparent; margin: 4px 0; }
#userInput::-webkit-scrollbar-thumb {
    background-color: rgba(156, 163, 175, 0.4);
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: padding-box;
    transition: background-color 0.2s ease;
}
#userInput::-webkit-scrollbar-thumb:hover { background-color: rgba(156, 163, 175, 0.6); }
.dark #userInput::-webkit-scrollbar-thumb { background-color: rgba(107, 114, 128, 0.4); }
.dark #userInput::-webkit-scrollbar-thumb:hover { background-color: rgba(107, 114, 128, 0.6); }

/* ===== 文件上传按钮 ===== */
.input-wrapper .flex label[for="fileInput"] {
    padding: 0.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #4b5563;
    transition: transform 0.2s ease, background 0.2s ease;
    background: transparent;
    flex-shrink: 0;
    position: relative;
}
.input-wrapper .flex label[for="fileInput"]:hover {
    background: rgba(0, 0, 0, 0.05);
    transform: scale(1.1);
}
.dark .input-wrapper .flex label[for="fileInput"] { color: #9ca3af; }
.dark .input-wrapper .flex label[for="fileInput"]:hover { background: rgba(255, 255, 255, 0.1); }
.input-wrapper .flex label[for="fileInput"] svg { width: 20px; height: 20px; }

/* 当输入框高度变化时动态调整文件上传按钮位置 */
.input-wrapper:has(#userInput:focus) .flex label[for="fileInput"],
.input-wrapper:has(#userInput:not(:empty)) .flex label[for="fileInput"],
.input-wrapper:has(.drop-overlay-input.show) .flex label[for="fileInput"] {
    transform: translateY(var(--offset, 0px));
}

/* ===== 通用隐藏 ===== */
.hidden { display: none !important; }

/* ===== Tailwind 工具类补充 ===== */
.flex { display: flex; }
.flex-1 { flex: 1 1 0%; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.h-4 { height: 1rem; }
.h-5 { height: 1.25rem; }
.w-4 { width: 1rem; }
.w-5 { width: 1.25rem; }
.w-16 { width: 4rem; }
.w-20 { width: 5rem; }
.w-\[280px\] { width: 280px; }
.min-w-0 { min-width: 0; }
.overflow-hidden { overflow: hidden; }
.overflow-y-auto { overflow-y: auto; }
.p-0 { padding: 0; }
.p-1 { padding: 0.25rem; }
.p-2 { padding: 0.5rem; }
.p-3 { padding: 0.75rem; }
.p-4 { padding: 1rem; }
.p-5 { padding: 1.25rem; }
.px-2 { padding-left: 0.5rem; padding-right: 0.5rem; }
.px-4 { padding-left: 1rem; padding-right: 1rem; }
.py-1 { padding-top: 0.25rem; padding-bottom: 0.25rem; }
.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.py-2\.5 { padding-top: 0.625rem; padding-bottom: 0.625rem; }
.py-3 { padding-top: 0.75rem; padding-bottom: 0.75rem; }
.pt-4 { padding-top: 1rem; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-6 { margin-top: 1.5rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.ml-0 { margin-left: 0; }
.mr-2 { margin-right: 0.5rem; }
.mx-auto { margin-left: auto; margin-right: auto; }
.bg-white { background-color: #ffffff; }
.bg-gray-50 { background-color: #f9fafb; }
.bg-gray-100 { background-color: #f3f4f6; }
.bg-gray-200 { background-color: #e5e7eb; }
.bg-gray-300 { background-color: #d1d5db; }
.bg-blue-600 { background-color: #2563eb; }
.bg-red-500 { background-color: #ef4444; }
.dark .bg-gray-800 { background-color: #1f2937; }
.dark .bg-gray-900 { background-color: #111827; }
.dark .bg-gray-950 { background-color: #0b1120; }
.text-gray-400 { color: #9ca3af; }
.text-gray-500 { color: #6b7280; }
.text-gray-600 { color: #4b5563; }
.text-gray-800 { color: #1f2937; }
.text-blue-500 { color: #3b82f6; }
.text-blue-600 { color: #2563eb; }
.text-red-500 { color: #ef4444; }
.text-white { color: #ffffff; }
.dark .text-gray-200 { color: #e5e7eb; }
.dark .text-gray-400 { color: #9ca3af; }
.border { border-width: 1px; border-style: solid; }
.border-r { border-right-width: 1px; }
.border-b { border-bottom-width: 1px; }
.border-t { border-top-width: 1px; }
.border-gray-200 { border-color: #e5e7eb; }
.border-gray-300 { border-color: #d1d5db; }
.border-gray-700 { border-color: #374151; }
.dark .border-gray-700 { border-color: #374151; }
.dark .border-gray-800 { border-color: #1f2937; }
.rounded-full { border-radius: 9999px; }
.rounded-2xl { border-radius: 1rem; }
.rounded-lg { border-radius: 0.5rem; }
.rounded-xl { border-radius: 0.75rem; }
.font-bold { font-weight: 700; }
.font-medium { font-weight: 500; }
.font-normal { font-weight: 400; }
.text-xs { font-size: 0.75rem; line-height: 1rem; }
.text-sm { font-size: 0.875rem; line-height: 1.25rem; }
.text-base { font-size: 1rem; line-height: 1.5rem; }
.tracking-wider { letter-spacing: 0.05em; }
.uppercase { text-transform: uppercase; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.placeholder-gray-400::placeholder { color: #9ca3af; }
.dark .placeholder-gray-500::placeholder { color: #6b7280; }
.cursor-pointer { cursor: pointer; }
.cursor-default { cursor: default; }
.outline-none { outline: 2px solid transparent; outline-offset: 2px; }
.resize-none { resize: none; }
.space-y-2 > * + * { margin-top: 0.5rem; }
.space-y-3 > * + * { margin-top: 0.75rem; }
.space-y-5 > * + * { margin-top: 1.25rem; }
.shadow-sm { box-shadow: 0 1px 2px 0 rgba(0,0,0,0.05); }
.shadow-md { box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06); }
.hover\:scale-105:hover { transform: scale(1.05); }
.hover\:bg-gray-100:hover { background-color: #f3f4f6; }
.hover\:bg-gray-200:hover { background-color: #e5e7eb; }
.hover\:text-blue-500:hover { color: #3b82f6; }
.hover\:text-red-500:hover { color: #ef4444; }
.hover\:shadow-sm:hover { box-shadow: 0 1px 2px 0 rgba(0,0,0,0.05); }
.dark .hover\:bg-gray-700:hover { background-color: #374151; }
.dark .hover\:bg-gray-800:hover { background-color: #1f2937; }
.focus-within\:shadow-md:focus-within { box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06); }
.transition { transition-property: all; transition-timing-function: cubic-bezier(0.4,0,0.2,1); transition-duration: 150ms; }
.group:hover .group-hover\:opacity-100 { opacity: 1; }
.z-10 { z-index: 10; }
.z-20 { z-index: 20; }
.z-40 { z-index: 40; }
.dark .dark\:hidden { display: none; }
.dark .dark\:block { display: block; }

/* ===== 隐藏AI头像 ===== */
.message-row:not(.user) .avatar { display: none; }

/* ===== 操作按钮容器 ===== */
.msg-actions {
    display: flex;
    gap: 4px;
    margin-top: 2px;
    opacity: 0.5;
    transition: opacity 0.2s;
    justify-content: flex-end;
}
.message-content-wrapper:hover .msg-actions { opacity: 1; }

/* ===== 操作按钮样式 ===== */
.msg-action-btn {
    width: 28px;
    height: 28px;
    border-radius: 20px;
    background: rgba(255,255,255,0.8);
    backdrop-filter: blur(4px);
    border: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #4b5563;
    transition: all 0.2s;
}
.dark .msg-action-btn { background: #374151; border-color: #4b5563; color: #d1d5db; }
.msg-action-btn:hover { transform: scale(1.1); background: white; }
.dark .msg-action-btn:hover { background: #4b5563; }
.msg-action-btn svg { width: 16px; height: 16px; }

/* ===== 文件列表样式 ===== */
.file-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}
.file-item {
    display: inline-flex;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.05);
    border-radius: 16px;
    padding: 4px 10px 4px 6px;
    font-size: 0.85rem;
    line-height: 1.2;
    max-width: 100%;
}
.dark .file-item { background-color: rgba(255, 255, 255, 0.1); }
.file-item .file-icon { width: 14px; height: 14px; margin-right: 4px; flex-shrink: 0; }
.file-item a {
    color: inherit;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}
.file-item a:hover { text-decoration: underline; text-decoration-style: dashed; }
.bubble.user .markdown-body { margin-top: 0; }

/* ===== 历史记录滚动边缘 ===== */
#chatHistoryList {
    margin-bottom: 2rem;
    position: relative;
    overflow-y: auto;
}
#chatHistoryList::before,
#chatHistoryList::after {
    content: '' !important;
    position: sticky !important;
    left: 0 !important;
    right: 0 !important;
    height: 60px !important;
    pointer-events: none !important;
    z-index: 1000 !important;
    opacity: 1 !important;
    display: block !important;
}
#chatHistoryList::before {
    top: 0 !important;
    background: linear-gradient(to bottom, rgba(255,255,255,0.9) 0%, rgba(255,255,255,0.4) 30%, transparent 80%) !important;
}
#chatHistoryList::after {
    bottom: 0 !important;
    background: linear-gradient(to top, rgba(255,255,255,0.9) 0%, rgba(255,255,255,0.4) 30%, transparent 80%) !important;
}
.dark #chatHistoryList::before { background: linear-gradient(to bottom, rgba(0,0,0,0.3) 0%, rgba(0,0,0,0.1) 30%, transparent 80%) !important; }
.dark #chatHistoryList::after { background: linear-gradient(to top, rgba(0,0,0,0.3) 0%, rgba(0,0,0,0.1) 30%, transparent 80%) !important; }

/* ===== 助手气泡透明背景 ===== */
.bubble.assistant.transparent-bg {
    background: transparent !important;
    box-shadow: none !important;
}
.dark .bubble.assistant.transparent-bg { background: transparent !important; color: #e5e7eb !important; }

/* ===== 水平分割线 ===== */
hr { border: 0; border-top: 1px solid #e5e7eb; margin: 1rem 0; }

/* ===== 对话标题 ===== */
.chat-title {
    flex: 1;
    text-align: center;
    font-weight: 600;
    font-size: 16px;
    color: #374151;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 16px;
}
.dark .chat-title { color: #e5e7eb; }

/* ===== 联网搜索状态指示器 ===== */
.search-indicator {
    background: #f3f4f6;
    border-radius: 20px;
    padding: 6px 12px;
    margin: 8px auto;
    font-size: 13px;
    display: inline-block;
    color: #4b5563;
    animation: pulse 1.5s infinite;
}
.dark .search-indicator {
    background-color: #0c4a6e;
    border-color: #0369a1;
    color: #7dd3fc;
}
.search-indicator.error {
    background: #fee2e2;
    color: #b91c1c;
    animation: none;
}
@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.7; }
    100% { opacity: 1; }
}

/* ===== 搜索配置项样式 ===== */
#searchConfigDetails { transition: all 0.3s ease; }
#searchConfigItem {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #e5e7eb;
}
.dark #searchConfigItem { border-top-color: #374151; }

/* ===== 开关样式 ===== */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #d1d5db;
    transition: .4s;
    border-radius: 24px;
}
.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}
input:checked + .slider { background-color: #2563eb; }
input:checked + .slider:before { transform: translateX(20px); }
.dark .slider { background-color: #4b5563; }
.dark input:checked + .slider { background-color: #3b82f6; }

/* ===== 配置输入框样式 ===== */
.config-input {
    width: 100%;
    padding: 0.375rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    background-color: white;
    color: #1f2937;
}
.dark .config-input {
    background-color: #374151;
    border-color: #4b5563;
    color: #f3f4f6;
}
.config-input:focus { outline: 2px solid #3b82f6; outline-offset: 2px; }
.dark .config-input:focus { outline-color: #60a5fa; }

/* ===== 侧边栏下拉框宽度限制 ===== */
.sidebar select#compressModel,
.sidebar select#titleModel {
    width: 120px;
    flex: none;
    min-width: 0;
}
.sidebar .flex.items-center.gap-2 > span { white-space: nowrap; }

/* ===== 暗色模式手动覆盖 ===== */
.dark body { background-color: #111827; color: #e5e7eb; }
.dark .sidebar { background-color: #111827; border-right-color: #1f2937; }
.dark .sidebar .text-gray-400,
.dark .sidebar .text-xs.tracking-wider { color: #9ca3af; }
.dark .sidebar button.bg-white.border-gray-200 {
    background-color: #1f2937;
    border-color: #374151;
    color: #60a5fa;
}
.dark #chatHistoryList .group .text-gray-600 { color: #9ca3af; }
.dark #chatHistoryList .group.hover\:bg-gray-100:hover { background-color: #1f2937; }
.dark #chatHistoryList .bg-white.shadow-sm.text-blue-600 {
    background-color: #1f2937 !important;
    color: #60a5fa;
    box-shadow: 0 1px 3px 0 rgba(0,0,0,0.3);
}
.dark #chatHistoryList .bg-white.shadow-sm .text-gray-600 { color: #9ca3af; }
.dark .flex-1.flex-col.bg-gray-50 { background-color: #0b1120; }
.dark header { border-bottom-color: #1f2937; }
.dark header .bg-white.border-gray-200 { background-color: #1f2937; border-color: #374151; }
.dark header .text-gray-400 { color: #d1d5db; }
.dark header .hover\:bg-gray-100:hover { background-color: #374151; }
.dark .config-panel { background-color: #1f2937; border-left-color: #374151; }
.dark .config-panel .text-gray-400 { color: #9ca3af; }
.dark .config-panel input,
.dark .config-panel select,
.dark .config-panel textarea {
    background-color: #374151;
    border-color: #4b5563;
    color: #f3f4f6;
}
.dark .config-panel .bg-gray-200 { background-color: #374151; }
.dark .config-panel .bg-gray-100 { background-color: #1f2937; }
.dark .config-panel input[type="checkbox"] { accent-color: #3b82f6; }
.dark .input-wrapper .bg-white { background-color: #1f2937; border-color: #374151; }
.dark .input-wrapper .text-gray-400 { color: #9ca3af; }
.dark #userInput { color: #f3f4f6; }
.dark #userInput::placeholder { color: #6b7280; }
.dark .scroll-to-bottom-btn { background-color: #1f2937; border-color: #374151; color: #9ca3af; }
.dark .file-tag { background-color: #374151; color: #e5e7eb; }
.dark button .text-gray-400,
.dark .msg-action-btn { color: #9ca3af; }
.dark .msg-action-btn:hover { background-color: #374151; color: #f3f4f6; }
.dark .code-copy-btn { background-color: #374151; border-color: #4b5563; color: #d1d5db; }
.dark .welcome-container { color: #6b7280; }
.dark hr { border-color: #374151; }
.dark .sidebar input[type="number"],
.dark .sidebar select {
    background-color: #1f2937;
    border-color: #374151;
    color: #f3f4f6;
}
.dark .sidebar input[type="number"]::placeholder { color: #9ca3af; }
.dark .sidebar select option { background-color: #1f2937; color: #f3f4f6; }
.dark .sidebar input[type="checkbox"] { accent-color: #3b82f6; border-color: #4b5563; }
.dark .header-menu-btn { background: #1f2937; border-color: #374151; color: #d1d5db; }
.dark .header-menu-btn:hover { background: #374151; }

/* ===== 亮色模式强制修正（去除黑色背景） ===== */
/* 移除之前可能导致黑色背景的覆盖，确保亮色下所有元素背景正确 */
html:not(.dark) body,
html:not(.dark) .sidebar,
html:not(.dark) .flex-1.flex-col,
html:not(.dark) .config-panel,
html:not(.dark) header,
html:not(.dark) .input-wrapper,
html:not(.dark) .chat-messages-container,
html:not(.dark) #chatBox,
html:not(.dark) .message-row,
html:not(.dark) .bubble.assistant,
html:not(.dark) .bubble.user,
html:not(.dark) .avatar.user,
html:not(.dark) .avatar.assistant,
html:not(.dark) .message-footer,
html:not(.dark) .file-tag,
html:not(.dark) .msg-action-btn,
html:not(.dark) #scrollToBottomBtn,
html:not(.dark) select,
html:not(.dark) input,
html:not(.dark) textarea,
html:not(.dark) .config-panel input,
html:not(.dark) .config-panel select,
html:not(.dark) .config-panel textarea,
html:not(.dark) .sidebar .mt-6.pt-4,
html:not(.dark) .sidebar .space-y-3,
html:not(.dark) .sidebar .space-y-3 *,
html:not(.dark) .sidebar input[type="number"],
html:not(.dark) .sidebar select,
html:not(.dark) .sidebar input[type="checkbox"],
html:not(.dark) .sidebar button.bg-white,
html:not(.dark) header .bg-white,
html:not(.dark) header .p-2.rounded-full,
html:not(.dark) #chatHistoryList .bg-white,
html:not(.dark) #chatHistoryList .group,
html:not(.dark) #chatHistoryList .bg-white.shadow-sm,
html:not(.dark) .config-panel .bg-gray-100,
html:not(.dark) .config-panel .bg-gray-200,
html:not(.dark) .config-panel .bg-white,
html:not(.dark) #userInput {   /* 新增 #userInput，修复输入框背景 */
    background-color: #f9fafb !important;
    color: #1f2937 !important;
    border-color: #e5e7eb !important;
}
/* 特定元素修正 */
html:not(.dark) .bubble.user {
    background-color: #2563eb !important;
    color: white !important;
}
html:not(.dark) .bubble.assistant {
    background-color: white !important;
    color: #1f2937 !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05) !important;
}
html:not(.dark) .avatar.user {
    background-color: #e5e7eb !important;
    color: #1f2937 !important;
}
html:not(.dark) .avatar.assistant {
    background-color: #2563eb !important;
    color: white !important;
}
html:not(.dark) .sidebar { border-right-color: #e5e7eb !important; }
html:not(.dark) .config-panel { border-left-color: #e5e7eb !important; }
html:not(.dark) .msg-action-btn {
    background: rgba(255,255,255,0.8) !important;
    border-color: #e5e7eb !important;
    color: #4b5563 !important;
}
html:not(.dark) .file-tag {
    background-color: #e5e7eb !important;
    color: #1f2937 !important;
}
html:not(.dark) select,
html:not(.dark) input,
html:not(.dark) textarea {
    background-color: white !important;
    border-color: #d1d5db !important;
}
html:not(.dark) .sidebar input[type="checkbox"] { accent-color: #2563eb !important; }
/* 确保主题图标正确 */
html:not(.dark) #moonPath { display: block !important; }
html:not(.dark) #sunPath { display: none !important; }
html.dark #moonPath { display: none !important; }
html.dark #sunPath { display: block !important; }

/* ===== 媒体查询 ===== */
@media (max-width: 786px) {
    /* 响应式基础 */
    .chat-messages-container { padding: 0 0.75rem; }
    .bubble { max-width: 95%; font-size: 0.9rem; }
    .avatar { width: 32px; height: 32px; font-size: 0.8rem; }
    .input-area { padding: 0 0.75rem; }
    .msg-action-btn { width: 32px; height: 32px; }
    .code-copy-btn { width: 32px; height: 32px; }
    .sidebar-collapse-btn { padding: 0.5rem 0.75rem; font-size: 1.25rem; }
    .header-menu-btn { padding: 0.6rem; font-size: 1.1rem; }

    /* 移动端侧边栏和配置面板覆盖层 */
    .sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        height: 100vh !important;
        width: 258px !important;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 1000 !important;
        box-shadow: 2px 0 8px rgba(0,0,0,0.1);
        overflow-y: auto;
        opacity: 1 !important;
        border-right: 1px solid #e5e7eb;
        border-top-right-radius: 20px;
        border-bottom-right-radius: 20px;
    }
    .sidebar.mobile-open { transform: translateX(0) !important; }

    .config-panel {
        position: fixed !important;
        top: 0 !important;
        right: 0 !important;
        height: 100vh !important;
        width: 258px !important;
        transform: translateX(100%);
        transition: transform 0.3s ease;
        z-index: 1000 !important;
        box-shadow: -2px 0 8px rgba(0,0,0,0.1);
        overflow-y: auto;
        opacity: 1 !important;
        border-left: 1px solid #e5e7eb;
        border-top-left-radius: 20px;
        border-bottom-left-radius: 20px;
    }
    .config-panel.mobile-open { transform: translateX(0) !important; }

    .sidebar-mask {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0,0,0,0.5);
        z-index: 999;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
        pointer-events: none;
    }
    .sidebar-mask.active {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    #sidebarToggle { display: block !important; }

    /* 确保可滚动 */
    .sidebar, .config-panel {
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }
    .sidebar .mt-6.pt-4 { padding-bottom: 20px; }
    .config-panel .space-y-5 { padding-bottom: 20px; }

    /* 头部布局优化 */
    header {
        flex-wrap: wrap !important;
        gap: 0.25rem;
        padding-left: max(0.5rem, env(safe-area-inset-left, 0px));
        padding-right: max(0.5rem, env(safe-area-inset-right, 0px));
        padding-top: max(0.5rem, env(safe-area-inset-top, 0px));
    }
    header .flex.items-center.gap-4 {
        flex: 1 1 auto;
        min-width: 0;
        gap: 0.25rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        justify-content: flex-start;
    }
    header .flex.items-center.gap-3 {
        flex-shrink: 0;
        gap: 0.1rem;
        justify-content: flex-end;
    }
    #modelSelect {
        max-width: 130px;
        font-size: 0.75rem;
        padding-left: 0.4rem;
        padding-right: 0.4rem;
    }
    header .p-2.rounded-full,
    header .header-menu-btn { padding: 0.5rem !important; }
    header .p-2.rounded-full svg,
    header .header-menu-btn svg { width: 1.25rem; height: 1.25rem; }

    /* 消息居中 */
    .message-row.assistant { justify-content: center; }
    .message-row.assistant .message-content-wrapper { max-width: 90%; margin: 0 auto; }
    .message-row.user { justify-content: flex-end; }

    /* 标题样式 */
    .chat-title {
        width: 100%;
        flex: 0 0 100%;
        order: -1;
        text-align: center;
        margin: 0 0 0.25rem 0;
        font-size: 0.95rem;
        font-weight: 600;
        white-space: normal;
        overflow: visible;
        word-break: break-word;
        text-overflow: clip;
        color: inherit;
        position: static;
    }

    /* 输入框相关调整 */
    .send-stop-container { right: 6px; }
    #userInput { padding-right: 55px; }

    /* 回到底部按钮 */
    #scrollToBottomBtn {
        bottom: 70px !important;
        right: 15px !important;
        width: 34px !important;
        height: 34px !important;
    }

    /* 输入框圆角修复 */
    .input-wrapper {
        border-radius: 9999px !important;
        background: white !important;
        border-color: #e5e7eb !important;
    }
    #userInput { background: transparent !important; color: #1f2937 !important; }
    .dark .input-wrapper { background: #1f2937 !important; border-color: #374151 !important; }
    .dark #userInput { background: transparent !important; color: #f3f4f6 !important; }
}

@media (max-width: 480px) {
    /* 响应式基础 */
    .message-row { gap: 0.6rem; }
    .bubble { padding: 0.4rem 0.6rem; }
    .msg-action-btn { width: 28px; height: 28px; }
    .code-copy-btn { width: 28px; height: 28px; }

    /* 输入区域窄屏修复 */
    .input-area { padding: 0 0.5rem !important; margin-bottom: 0.5rem; }
    .input-wrapper > .flex {
        border-radius: 9999px !important;
        overflow: hidden !important;
        background: white !important;
        border: 1px solid #e5e7eb !important;
        padding-right: 50px;
    }
    .dark .input-wrapper > .flex { background: #1f2937 !important; border-color: #374151 !important; }
    #userInput {
        padding: 0.75rem 0.5rem;
        padding-right: 50px;
        min-height: 44px;
        max-height: 150px;
        border: none !important;
        background: transparent !important;
    }
    .send-stop-container {
        right: 4px;
        width: 40px;
        height: 40px;
    }
    .send-btn, .stop-btn { width: 40px; height: 40px; }
    .file-preview-container {
        padding: 0 0.25rem;
        margin-bottom: 0.5rem;
        overflow-x: auto;
        flex-wrap: nowrap;
    }
    .file-tag { font-size: 0.7rem; padding: 0.2rem 0.4rem; max-width: 180px; flex-shrink: 0; }
    .drop-overlay-input { border-radius: 9999px; border-width: 2px; font-size: 0.9rem; padding: 0 1rem; }

    /* 滚动条调整 */
    #userInput::-webkit-scrollbar { width: 6px; }

    /* 回到底部按钮 */
    #scrollToBottomBtn {
        bottom: 65px !important;
        right: 10px !important;
        width: 32px !important;
        height: 32px !important;
    }

    /* 文件上传按钮 */
    .input-wrapper .flex label[for="fileInput"] { padding: 0.3rem; }
    .input-wrapper .flex label[for="fileInput"] svg { width: 16px; height: 16px; }
}

@media (max-width: 360px) {
    .input-area { padding: 0 0.25rem !important; }
    #userInput { padding: 0.75rem 0.5rem; padding-right: 45px; font-size: 0.9rem; }
    .send-stop-container { right: 2px; width: 38px; height: 38px; }
    .send-btn, .stop-btn { width: 38px; height: 38px; }
    .file-tag { max-width: 140px; font-size: 0.65rem; }
    #scrollToBottomBtn {
        bottom: 60px !important;
        right: 8px !important;
        width: 30px !important;
        height: 30px !important;
    }
}

@media (min-width: 787px) {
    /* 电脑端标题绝对居中 */
    header { position: relative; }
    .chat-title {
        position: absolute;
        left: 50%;
        transform: translateX(calc(-50% - 5px));
        max-width: 400px;
        width: auto;
        margin: 0;
        font-weight: 600;
        font-size: 1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        color: inherit;
        z-index: 1;
        pointer-events: none;
    }
    .message-row.assistant .message-content-wrapper { margin-right: 10px; }
    .dark .chat-title { color: #e5e7eb; }
    header .flex.items-center.gap-4,
    header .flex.items-center.gap-3 { position: relative; z-index: 2; }

    /* 回到底部按钮 */
    #scrollToBottomBtn { bottom: 80px !important; right: 20px !important; }
}

@media (orientation: landscape) and (min-width: 768px) {
    /* 平板横屏修复 - 确保全屏铺满 */
    .flex.h-screen {
        height: 100vh;
        height: 100dvh;
        overflow: hidden;
    }
    .flex-1.flex-col {
        min-height: 0;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }
    #chatBox {
        flex: 1 1 0%;
        min-height: 0;
        overflow-y: auto;
    }
    .input-area {
        flex-shrink: 0;
        padding-bottom: max(0.75rem, env(safe-area-inset-bottom, 0.75rem));
        margin-bottom: 0;
    }
    #scrollToBottomBtn {
        bottom: calc(75px + env(safe-area-inset-bottom, 0px)) !important;
        right: 15px !important;
    }
}

/* ========== 平板端亮色模式黑色背景逐一修复 ========== */
@media (max-width: 786px) {
    /* 强制所有主要容器背景为亮色 */
    html:not(.dark) body,
    html:not(.dark) .flex-1.flex-col.bg-gray-50,
    html:not(.dark) .sidebar,
    html:not(.dark) .config-panel,
    html:not(.dark) header,
    html:not(.dark) .input-wrapper,
    html:not(.dark) .input-wrapper .flex,
    html:not(.dark) #chatBox,
    html:not(.dark) .chat-messages-container,
    html:not(.dark) .message-row,
    html:not(.dark) .bubble.assistant,
    html:not(.dark) .bubble.user,
    html:not(.dark) .avatar.user,
    html:not(.dark) .avatar.assistant,
    html:not(.dark) .message-footer,
    html:not(.dark) .file-tag,
    html:not(.dark) .msg-action-btn,
    html:not(.dark) #scrollToBottomBtn,
    html:not(.dark) select,
    html:not(.dark) input,
    html:not(.dark) textarea,
    html:not(.dark) .config-panel input,
    html:not(.dark) .config-panel select,
    html:not(.dark) .config-panel textarea,
    html:not(.dark) .sidebar .mt-6.pt-4,
    html:not(.dark) .sidebar .space-y-3,
    html:not(.dark) .sidebar .space-y-3 *,
    html:not(.dark) .sidebar input[type="number"],
    html:not(.dark) .sidebar select,
    html:not(.dark) .sidebar input[type="checkbox"],
    html:not(.dark) .sidebar button.bg-white,
    html:not(.dark) header .bg-white,
    html:not(.dark) header .p-2.rounded-full,
    html:not(.dark) #chatHistoryList .bg-white,
    html:not(.dark) #chatHistoryList .group,
    html:not(.dark) #chatHistoryList .bg-white.shadow-sm,
    html:not(.dark) .config-panel .bg-gray-100,
    html:not(.dark) .config-panel .bg-gray-200,
    html:not(.dark) .config-panel .bg-white,
    html:not(.dark) .drop-overlay-input,
    html:not(.dark) .sidebar-mask,
    html:not(.dark) .code-copy-btn,
    html:not(.dark) .slider,
    html:not(.dark) .slider:before,
    html:not(.dark) .switch input:checked + .slider,
    html:not(.dark) .search-indicator,
    html:not(.dark) .search-indicator.error,
    html:not(.dark) #userInput {  /* 新增 #userInput 修复 */
        background-color: #f9fafb !important;
        color: #1f2937 !important;
        border-color: #e5e7eb !important;
    }

    /* 特定元素颜色修正 */
    html:not(.dark) .bubble.user {
        background-color: #2563eb !important;
        color: white !important;
    }
    html:not(.dark) .bubble.assistant {
        background-color: white !important;
        color: #1f2937 !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.05) !important;
    }
    html:not(.dark) .avatar.user {
        background-color: #e5e7eb !important;
        color: #1f2937 !important;
    }
    html:not(.dark) .avatar.assistant {
        background-color: #2563eb !important;
        color: white !important;
    }
    html:not(.dark) .msg-action-btn {
        background: rgba(255,255,255,0.8) !important;
        border-color: #e5e7eb !important;
        color: #4b5563 !important;
    }
    html:not(.dark) .file-tag {
        background-color: #e5e7eb !important;
        color: #1f2937 !important;
    }
    html:not(.dark) select,
    html:not(.dark) input,
    html:not(.dark) textarea {
        background-color: white !important;
        border-color: #d1d5db !important;
    }
    html:not(.dark) .sidebar input[type="checkbox"] {
        accent-color: #2563eb !important;
    }
    html:not(.dark) .code-copy-btn {
        background: rgba(255,255,255,0.8) !important;
        border-color: #e5e7eb !important;
        color: #4b5563 !important;
    }
    html:not(.dark) .search-indicator {
        background: #f3f4f6 !important;
        color: #4b5563 !important;
    }
    html:not(.dark) .search-indicator.error {
        background: #fee2e2 !important;
        color: #b91c1c !important;
    }
    html:not(.dark) .slider {
        background-color: #d1d5db !important;
    }
    html:not(.dark) .slider:before {
        background-color: white !important;
    }
    html:not(.dark) .switch input:checked + .slider {
        background-color: #2563eb !important;
    }
    /* 修复折叠按钮颜色 */
    html:not(.dark) .sidebar-collapse-btn {
        color: #4b5563 !important;
    }
    html:not(.dark) .sidebar-collapse-btn:hover {
        background-color: rgba(0,0,0,0.05) !important;
    }
    /* 修复下拉菜单选项背景 */
    html:not(.dark) select option {
        background: white !important;
        color: #1f2937 !important;
    }
    /* 修复遮罩层背景 */
    html:not(.dark) .sidebar-mask {
        background: rgba(0,0,0,0.5) !important; /* 遮罩保持半透明，不是纯黑 */
    }
    /* 修复拖拽覆盖层背景 */
    html:not(.dark) .drop-overlay-input {
        background: rgba(37, 99, 235, 0.15) !important;
        backdrop-filter: blur(3px) !important;
        border-color: var(--primary) !important;
        color: var(--primary) !important;
    }
}

/* ========== 触摸设备（平板/手机）亮色模式黑色背景修复（仅修复背景色，不影响图标样式） ========== */
@media (hover: none) and (pointer: coarse) {
    /* 修复主要区域背景为亮色（仅强制背景色，不强制color/border） */
    html:not(.dark) body,
    html:not(.dark) .flex-1.flex-col,
    html:not(.dark) .sidebar,
    html:not(.dark) .config-panel,
    html:not(.dark) header,
    html:not(.dark) .input-wrapper,
    html:not(.dark) .input-wrapper .flex,
    html:not(.dark) #chatBox,
    html:not(.dark) .chat-messages-container,
    html:not(.dark) .message-row,
    html:not(.dark) .bubble.assistant,
    html:not(.dark) .bubble.user,
    html:not(.dark) .avatar,
    html:not(.dark) .message-footer,
    html:not(.dark) .file-tag,
    html:not(.dark) .msg-action-btn,
    html:not(.dark) #scrollToBottomBtn,
    html:not(.dark) select,
    html:not(.dark) input,
    html:not(.dark) textarea,
    html:not(.dark) .config-panel input,
    html:not(.dark) .config-panel select,
    html:not(.dark) .config-panel textarea,
    html:not(.dark) .sidebar .mt-6.pt-4,
    html:not(.dark) .sidebar .space-y-3,
    html:not(.dark) .sidebar .space-y-3 *,
    html:not(.dark) .sidebar input[type="number"],
    html:not(.dark) .sidebar select,
    html:not(.dark) .sidebar input[type="checkbox"],
    html:not(.dark) .sidebar button,
    html:not(.dark) header .bg-white,
    html:not(.dark) header .p-2.rounded-full,
    html:not(.dark) #chatHistoryList,
    html:not(.dark) #chatHistoryList .group,
    html:not(.dark) #chatHistoryList .bg-white,
    html:not(.dark) #chatHistoryList .bg-white.shadow-sm,
    html:not(.dark) .config-panel .bg-gray-100,
    html:not(.dark) .config-panel .bg-gray-200,
    html:not(.dark) .config-panel .bg-white,
    html:not(.dark) .drop-overlay-input,
    html:not(.dark) .sidebar-mask,
    html:not(.dark) .code-copy-btn,
    html:not(.dark) .slider,
    html:not(.dark) .slider:before,
    html:not(.dark) .switch,
    html:not(.dark) .search-indicator,
    html:not(.dark) .search-indicator.error,
    html:not(.dark) .sidebar-collapse-btn,
    html:not(.dark) .header-menu-btn,
    html:not(.dark) .welcome-container,
    html:not(.dark) hr,
    html:not(.dark) #userInput {  /* 新增 #userInput 修复 */
        background-color: #f9fafb !important;
    }

    /* 确保特殊元素背景色正确（有些元素可能需要额外处理） */
    html:not(.dark) .bubble.user {
        background-color: #2563eb !important;
        color: white !important;
    }
    html:not(.dark) .bubble.assistant {
        background-color: white !important;
        color: #1f2937 !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.05) !important;
    }
    html:not(.dark) .send-btn,
    html:not(.dark) .stop-btn {
        background: var(--primary) !important;
        color: white !important;
    }
    html:not(.dark) .stop-btn {
        background: var(--danger) !important;
    }
    html:not(.dark) .sidebar-mask {
        background: rgba(0,0,0,0.5) !important;
    }
    html:not(.dark) .drop-overlay-input {
        background: rgba(37, 99, 235, 0.15) !important;
        border-color: var(--primary) !important;
        color: var(--primary) !important;
    }

    /* 特别处理：防止某些元素颜色被意外改变（恢复按钮默认颜色） */
    html:not(.dark) .msg-action-btn,
    html:not(.dark) .code-copy-btn,
    html:not(.dark) .sidebar-collapse-btn,
    html:not(.dark) .header-menu-btn {
        color: #4b5563 !important;
        border-color: #e5e7eb !important;
    }

    /* 不再对svg进行强制fill/stroke，让图标保持原有设计 */
}

/* 修复配置面板中开关按钮在亮色模式下的背景 */
@media (hover: none) and (pointer: coarse) {
    /* 开关容器本身不应有背景色，避免遮挡滑块 */
    html:not(.dark) label.switch,
    html:not(.dark) .switch {
        background-color: transparent !important;
    }

    /* 滑块背景：默认灰色，开启时蓝色 */
    html:not(.dark) .switch .slider {
        background-color: #d1d5db !important;
    }
    html:not(.dark) .switch input:checked + .slider {
        background-color: #2563eb !important;
    }

    /* 滑块内部小圆点保持白色 */
    html:not(.dark) .slider:before {
        background-color: white !important;
    }

    /* 确保配置面板内其他相关元素背景正确 */
    html:not(.dark) #searchConfigItem,
    html:not(.dark) #searchConfigDetails,
    html:not(.dark) .config-item {
        background-color: transparent !important; /* 继承父级亮色背景 */
    }
}

/* 隐藏空的段落（没有内容或仅含 <br>） */
.markdown-body p:empty,
.markdown-body p:has(> br:only-child) {
    display: none;
}

/* 更紧凑的段落边距（可选，根据喜好调整） */
.markdown-body p {
    margin: 0 0 0.1rem 0; /* 下边距压缩到最小 */
}
.markdown-body p:last-child {
    margin-bottom: 0;
}

/* ===== 助手气泡等待动画（调大三个点）===== */
.bubble.assistant.typing .markdown-body {
    min-height: 1.5em;
    position: relative;
}
.bubble.assistant.typing .markdown-body::after {
    content: '...';
    display: inline-block;
    animation: typing-dots 1.2s steps(4, end) infinite;
    width: 1.5em;
    text-align: left;
    font-size: var(--chat-font-size, 16px);       /* 使用全局字体变量 */
    line-height: var(--chat-line-height, 1.1);     /* 使用全局行高变量 */
    opacity: 0.7;
    vertical-align: bottom; /* 确保底部对齐，避免额外间隙 */
}
@keyframes typing-dots {
    0%, 20% { content: ''; }
    40% { content: '.'; }
    60% { content: '..'; }
    80%, 100% { content: '...'; }
}
.bubble.assistant {
    padding: 12px 16px;
}

/* ===== 移动端输入框可见性修复（合并优化） ===== */
@media (max-width: 786px) {
    /* 主容器改为垂直方向（侧边栏、中央区、配置面板上下排列） */
    .h-screen {
        flex-direction: column !important;
        height: 100% !important;
    }
    /* 确保中央区占满剩余空间 */
    .flex-1.flex-col {
        min-height: 0;
        flex: 1;
        display: flex;
        flex-direction: column;
    }
    #chatBox {
        flex: 1 1 auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .input-area {
        flex-shrink: 0;
        width: 100%;
        padding-bottom: max(0.75rem, env(safe-area-inset-bottom, 0.75rem));
        box-sizing: border-box;
    }

    /* 强制输入框背景为白色（亮色模式） */
    html:not(.dark) .input-wrapper,
    html:not(.dark) .input-wrapper .flex,
    html:not(.dark) #userInput {
        background-color: #ffffff !important;
        border-color: #e5e7eb !important;
        color: #1f2937 !important;
    }
    /* 移除可能导致裁剪的 overflow: hidden */
    .input-wrapper,
    .input-wrapper .flex {
        overflow: visible !important;
    }
    /* 确保发送按钮位置正确 */
    .send-stop-container {
        right: 8px !important;
    }
    /* 输入框 flex 布局修正 */
    .input-wrapper .flex {
        width: 100%;
        flex-wrap: nowrap;
        box-sizing: border-box;
    }
    #userInput {
        flex: 1 1 auto;
        min-width: 0;
        width: 100%;
        box-sizing: border-box;
    }
}

/* 极端窄屏进一步调整 */
@media (max-width: 480px) {
    .input-wrapper .flex {
        padding-right: 40px;
    }
    #userInput {
        padding-right: 40px;
    }
    .send-stop-container {
        right: 2px;
    }
}

/* 暗色模式适配（确保输入框背景正确） */
.dark .input-wrapper,
.dark .input-wrapper .flex,
.dark #userInput {
    background-color: #1f2937 !important;
    border-color: #374151 !important;
    color: #f3f4f6 !important;
}

/* ===== 强制亮色模式下输入框背景为纯白（覆盖之前的浅灰） ===== */
html:not(.dark) .input-wrapper,
html:not(.dark) .input-wrapper .flex,
html:not(.dark) #userInput {
    background-color: #ffffff !important;
}

/* 让 markdown-body 中的链接更明显 */
.markdown-body a {
    color: #0366d6;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.markdown-body a:hover {
    color: #0056b3;
    text-decoration: none;
    background-color: #f0f6ff;
}