* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body {
    display: flex;
    height: 100vh;
    background-color: #f5f5f5;
}

/* 左侧导航栏 */
.sidebar {
    width: 240px;
    background-color: #fff;
    border-right: 1px solid #e5e5e5;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.sidebar-header {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 18px;
    font-weight: 600;
}

.logo-icon {
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
}

.sidebar-actions {
    padding: 0 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.new-chat-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background-color: #f5f5f5;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    color: #333;
}

.new-chat-btn:hover {
    background-color: #eee;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    color: #333;
}

.menu-item:hover {
    background-color: #f5f5f5;
}

.vip-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    background-color: #fff7ed;
    border: 1px solid #fed7aa;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    color: #ea580c;
    margin: 8px 12px;
}

.vip-btn:hover {
    background-color: #ffedd5;
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
}

.history-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    color: #333;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.history-item:hover {
    background-color: #f5f5f5;
}

.history-item.active {
    background-color: #333;
    color: #fff;
}

.history-item-title {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item-delete {
    display: none;
    flex-shrink: 0;
    background: none;
    border: none;
    color: #aaa;
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    padding: 0 2px;
    border-radius: 3px;
}

.history-item:hover .history-item-delete,
.history-item.active .history-item-delete {
    display: block;
}

.history-item-delete:hover {
    color: #f55;
    background: rgba(0, 0, 0, 0.06);
}

.history-item.active .history-item-delete {
    color: #bbb;
}

.history-item.active .history-item-delete:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
}

/* ── 探讨存档区 ── */
#subChatStorageArea {
    flex-shrink: 0;
    margin: 0;
    border-top: 1px solid #e5e5e5;
    background: transparent;
    padding: 0 0 8px;
    min-height: 400px;
    max-height: 400px;
    overflow-y: auto;
    transition: border-color 0.18s, background 0.18s, transform 0.15s, box-shadow 0.18s;
}

/* 移动端汉堡按钮（默认隐藏，仅移动端显示） */
.mobile-menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: none;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    color: #555;
    flex-shrink: 0;
    padding: 0;
    margin-left: 8px;
}

.mobile-menu-btn:hover {
    background: #f0f0f0;
}

/* 拖曳中：整个区域变为投放区样式 */
#subChatStorageArea.dragging {
    margin: 6px 10px 10px;
    border: 1.5px dashed #d8dce2;
    border-radius: 10px;
    background: #f9faff;
    padding: 8px 8px 6px;
}

/* 鼠标悬停于投放区上方 */
#subChatStorageArea.drag-over {
    border: 2px dashed #667eea;
    background: #eef1ff;
    transform: scale(1.025);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.subchat-storage-header {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    font-weight: 600;
    color: #aaa;
    padding: 8px 12px 6px;
    user-select: none;
}

#showMindmapBtn {
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 1px 4px;
    border-radius: 4px;
    line-height: 1;
    opacity: 0.55;
    transition: opacity 0.15s, background 0.15s;
}

#showMindmapBtn:hover {
    opacity: 1;
    background: #eef1ff;
}

#showMindmapBtn.active {
    opacity: 1;
    background: #e0e7ff;
}

/* 拖曳中缩小内边距（外层已有 padding） */
#subChatStorageArea.dragging .subchat-storage-header {
    padding: 0 2px 6px;
    border-bottom: 1px solid #eee;
    margin-bottom: 5px;
}

/* 投放提示：仅在拖曳进行时显示 */
.subchat-storage-hint {
    display: none;
    font-size: 11px;
    color: #ccc;
    text-align: center;
    padding: 6px 0 2px;
    user-select: none;
}

#subChatSavedList {
    display: flex;
    flex-direction: column;
}

/* 条目样式与 .history-item 一致 */
.subchat-saved-item {
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    color: #333;
    margin: 0 12px 2px;
    transition: background 0.12s;
    display: flex;
    align-items: center;
    gap: 4px;
    /* --- 新增：锁定高度的关键 --- */
    height: 54px;
    /* 1. 强制所有方框高度固定为 54px（可根据需要微调） */
    box-sizing: border-box;
    /* 2. 确保 padding 不会额外撑大这 54px */
    overflow: hidden;
    /* 3. 物理切断任何溢出的公式部分 */
}

.subchat-saved-item:hover {
    background-color: #f5f5f5;
}

.subchat-saved-item.active {
    background-color: #333;
    color: #fff;
}

.subchat-saved-item.active .item-meta {
    color: #aaa;
}

.subchat-saved-item.child-active {
    background-color: #999;
    color: #fff;
}

.subchat-saved-item.child-active:hover {
    background-color: #888;
}

.subchat-saved-item.child-active .item-meta {
    color: #ddd;
}

.subchat-saved-item-text {
    flex: 1;
    min-width: 0;
    /* 防止长公式撑开宽度 */
    display: flex;
    flex-direction: column;
    justify-content: center;
    /* 确保文字和元数据在 54px 内垂直居中 */
    height: 100%;
}

.subchat-saved-item .item-label {
    display: flex;
    /* 改为 flex 布局 */
    align-items: center;
    /* 核心：强制所有子元素垂直居中 */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    height: 1.4em;
    /* 稍微给一点点富余高度 */
    line-height: 1.4em;
}

/* 针对存档列表中的公式进行精准缩放 */
.subchat-saved-item .item-label .katex {
    display: inline-flex !important;
    /* 强制 inline-flex */
    align-items: center !important;
    /* 让公式内部也垂直居中 */
    font-size: 0.61em !important;
    line-height: 0 !important;
    /* 消除 KaTeX 默认的行高干扰 */
    vertical-align: middle;
    /* 兜底对齐 */
    position: relative;
    top: -1px;
}

/* 如果公式里有下标或复杂的堆叠，微调垂直对齐 */
.subchat-saved-item .item-label .katex-html {
    display: inline-flex !important;
    align-items: center !important;
    height: auto !important;
    /* 让它自适应，由外层 .item-label 统一切断 */
    overflow: visible !important;
    /* 内部不要切，让外层切 */
}

.subchat-saved-item .item-meta {
    color: #bbb;
    font-size: 10px;
    margin-top: 1px;
}

.subchat-saved-item-delete {
    display: none;
    flex-shrink: 0;
    background: none;
    border: none;
    color: #aaa;
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    padding: 0 2px;
    border-radius: 3px;
}

.subchat-saved-item:hover .subchat-saved-item-delete,
.subchat-saved-item.active .subchat-saved-item-delete {
    display: block;
}

.subchat-saved-item-delete:hover {
    color: #f55;
    background: rgba(0, 0, 0, 0.06);
}

.subchat-saved-item.active .subchat-saved-item-delete {
    color: #bbb;
}

.subchat-saved-item.active .subchat-saved-item-delete:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
}

/* 浮窗拖入存档时的消失动画 */
#subChatPopup.saving {
    transform: scale(0.12);
    opacity: 0;
    transition: transform 0.3s ease-in, opacity 0.28s ease-in;
    pointer-events: none;
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid #e5e5e5;
}

.download-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    color: #3b82f6;
    font-size: 14px;
    cursor: pointer;
}

.footer-icons {
    display: flex;
    gap: 16px;
    padding: 8px 16px;
    color: #666;
}

/* 右侧主内容区 */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: #fff;
    position: relative;
    height: 100vh;
    overflow: hidden;
}

.main-header {
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #f0f0f0;
}

.model-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background-color: #f5f5f5;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    position: relative;
    user-select: none;
}

.model-selector:hover {
    background-color: #eee;
}

.model-arrow {
    font-size: 10px;
    color: #666;
    transition: transform 0.2s;
}

.model-selector.open .model-arrow {
    transform: rotate(180deg);
}

.model-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 4px;
    background-color: #fff;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    min-width: 160px;
    z-index: 100;
    overflow: visible;
}

.model-selector.open .model-dropdown {
    display: block;
}

/* 一级菜单：提供商 */
.provider-item {
    position: relative;
    padding: 10px 16px;
    cursor: pointer;
    font-size: 14px;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: #fff;
}

.provider-item:hover {
    background-color: #f5f5f5;
}

/* 包含当前选中模型的提供商 */
.provider-item.has-selected {
    background-color: #e8f4ff;
    color: #3b82f6;
}

.provider-item .provider-arrow {
    font-size: 10px;
    color: #999;
    transition: transform 0.15s;
}

.provider-item.has-selected .provider-arrow {
    color: #3b82f6;
}

/* 二级菜单：具体模型 */
.model-submenu {
    position: absolute;
    left: 100%;
    top: 0;
    margin-left: 4px;
    background-color: #fff;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    min-width: 150px;
    overflow: hidden;
    /* 滑出/滑回动画 */
    opacity: 0;
    transform: translateX(-8px);
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.15s ease-out, transform 0.15s ease-out, visibility 0.15s;
}

/* 展开状态 */
.provider-item.submenu-open .model-submenu {
    opacity: 1;
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
}

.model-option {
    padding: 10px 16px;
    cursor: pointer;
    font-size: 14px;
    color: #333;
    white-space: nowrap;
}

.model-option:hover {
    background-color: #f5f5f5;
}

.model-option.selected {
    background-color: #e8f4ff;
    color: #3b82f6;
}

.model-icon {
    width: 20px;
    height: 20px;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    border-radius: 4px;
}

/* ========== 首页样式 ========== */
.homepage {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px;
}

.homepage.hidden {
    display: none;
}

.homepage-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 48px;
}

.homepage-icon {
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    box-shadow: 0 8px 32px rgba(102, 126, 234, 0.3);
}

.homepage-title {
    font-size: 28px;
    font-weight: 600;
    color: #333;
}

.homepage-input-container {
    width: 100%;
    max-width: 800px;
    border: 1px solid #e5e5e5;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    transition: border-color 0.3s;
}

.homepage-input-container.drag-over {
    border-color: #3b82f6;
    border-style: dashed;
    background-color: #f0f7ff;
}

.homepage-input {
    width: 100%;
    padding: 20px 24px;
    border: none;
    outline: none;
    font-size: 16px;
    resize: none;
    min-height: 60px;
}

.homepage-input::placeholder {
    color: #999;
}

/* 附件预览区域 */
.attachment-preview {
    display: none;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 16px;
    background-color: #fafafa;
    border-top: 1px solid #f0f0f0;
}

.attachment-preview.has-files {
    display: flex;
}

.attachment-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background-color: #fff;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    font-size: 13px;
    max-width: 200px;
}

.attachment-item img {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 4px;
}

.attachment-item .file-icon {
    font-size: 24px;
}

.attachment-item .file-info {
    flex: 1;
    overflow: hidden;
}

.attachment-item .file-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.attachment-item .file-size {
    font-size: 11px;
    color: #999;
}

.attachment-item .remove-btn {
    cursor: pointer;
    color: #999;
    font-size: 16px;
}

.attachment-item .remove-btn:hover {
    color: #f00;
}

.homepage-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background-color: #fafafa;
}

.homepage-left-actions {
    display: flex;
    gap: 8px;
}

.homepage-right-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    border: 1px solid #e5e5e5;
    border-radius: 16px;
    background-color: #fff;
    font-size: 13px;
    color: #666;
    cursor: pointer;
}

.action-btn:hover {
    background-color: #f5f5f5;
}

.action-btn.active {
    border-color: #3b82f6;
    color: #3b82f6;
}

.icon-btn {
    color: #999;
    cursor: pointer;
    font-size: 18px;
    padding: 4px;
}

.icon-btn:hover {
    color: #666;
}

.send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.send-btn:hover {
    opacity: 0.9;
}

.send-btn.explore-locked {
    background: #c0c0c0 !important;
    cursor: not-allowed !important;
    opacity: 0.5 !important;
}

/* ========== 聊天页样式 ========== */
.chatpage {
    flex: 1;
    display: none;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.chatpage.active {
    display: flex;
}

.chat-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    min-height: 0;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
}

/* 消息行容器 */
.chat-message {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 16px;
}

.chat-message.user {
    flex-direction: row-reverse;
}

.chat-message.ai {
    flex-direction: row;
}

/* 头像样式 */
.chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    overflow: hidden;
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-avatar.user {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.chat-avatar.ai {
    background-color: #f0f0f0;
    /* 强制开启高质量缩放算法 */
    image-rendering: -webkit-optimize-contrast;
    image-rendering: high-quality;
    /* 硬件加速，辅助子像素对齐 */
    transform: translateZ(0);
    /* 保持背景图不失真 */
    background-size: cover;
    background-position: center;
}

.chat-bubble {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.6;
    font-size: 15px;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.chat-bubble.user {
    background-color: #e8f4ff;
    color: #333;
    border-bottom-right-radius: 4px;
}

.chat-bubble.ai {
    background-color: #f5f5f5;
    color: #333;
    border-bottom-left-radius: 4px;
}

/* Markdown 渲染样式 */
.chat-bubble .bubble-text p {
    margin: 0 0 8px 0;
}

.chat-bubble .bubble-text p:last-child {
    margin-bottom: 0;
}

.chat-bubble .bubble-text strong {
    font-weight: 600;
}

.chat-bubble .bubble-text em {
    font-style: italic;
}

.chat-bubble .bubble-text code {
    background-color: rgba(0, 0, 0, 0.06);
    padding: 2px 5px;
    border-radius: 3px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
}

.chat-bubble .bubble-text pre {
    background-color: #1e1e1e;
    color: #d4d4d4;
    padding: 12px 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}

.chat-bubble .bubble-text pre code {
    background: none;
    padding: 0;
    color: inherit;
    font-size: 13px;
}

.chat-bubble .bubble-text ul,
.chat-bubble .bubble-text ol {
    margin: 8px 0;
    padding-left: 20px;
}

.chat-bubble .bubble-text li {
    margin: 4px 0;
}

.chat-bubble .bubble-text h1,
.chat-bubble .bubble-text h2,
.chat-bubble .bubble-text h3 {
    margin: 12px 0 6px 0;
    font-weight: 600;
}

.chat-bubble .bubble-text h1 {
    font-size: 1.3em;
}

.chat-bubble .bubble-text h2 {
    font-size: 1.15em;
}

.chat-bubble .bubble-text h3 {
    font-size: 1.05em;
}

.chat-bubble .bubble-text blockquote {
    border-left: 3px solid #ddd;
    margin: 8px 0;
    padding: 4px 12px;
    color: #666;
}

.chat-bubble .bubble-text a {
    color: #3b82f6;
    text-decoration: none;
}

.chat-bubble .bubble-text a:hover {
    text-decoration: underline;
}

.chat-bubble .bubble-text table {
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 14px;
}

.chat-bubble .bubble-text th,
.chat-bubble .bubble-text td {
    border: 1px solid #ddd;
    padding: 6px 10px;
}

.chat-bubble .bubble-text th {
    background-color: #f5f5f5;
    font-weight: 600;
}

/* 数学公式样式 */
.chat-bubble .bubble-text .math-block {
    display: block;
    text-align: center;
    margin: 12px 0;
    overflow-x: auto;
}

.chat-bubble .bubble-text .katex {
    font-size: 1.1em;
}

.chat-bubble .bubble-text {
    margin-bottom: 8px;
}

.chat-bubble .bubble-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chat-bubble .bubble-attachment {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background-color: rgba(255, 255, 255, 0.8);
    border-radius: 8px;
    font-size: 13px;
}

.chat-bubble.ai .bubble-attachment {
    background-color: rgba(255, 255, 255, 0.9);
}

.chat-bubble .bubble-attachment img {
    max-width: 200px;
    max-height: 150px;
    border-radius: 4px;
}

.chat-bubble .bubble-attachment .file-icon {
    font-size: 32px;
}

.input-area {
    padding: 16px 24px 24px;
    border-top: 1px solid #f0f0f0;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
}

.input-container {
    display: flex;
    flex-direction: column;
    border: 1px solid #e5e5e5;
    border-radius: 12px;
    overflow: hidden;
    transition: border-color 0.3s;
}

.input-container.drag-over {
    border-color: #3b82f6;
    border-style: dashed;
    background-color: #f0f7ff;
}

.input-box {
    padding: 16px;
    border: none;
    outline: none;
    font-size: 15px;
    resize: none;
    min-height: 50px;
}

.input-box::placeholder {
    color: #999;
}

.input-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background-color: #fafafa;
}

.input-left-actions {
    display: flex;
    gap: 8px;
}

.input-right-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.ai-notice {
    text-align: center;
    font-size: 12px;
    color: #999;
    padding: 8px;
}

/* 隐藏的文件输入 */
.hidden-input {
    display: none;
}

/* ========== 思维导图 ========== */
#mindmapCanvas {
    display: none;
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background: #ffffff;
    z-index: 1000;
}

#mindmapCanvas.active {
    display: block;
}

#mindmapCanvas svg {
    width: 100%;
    height: 100%;
}

/* 连接线 */
.mindmap-link {
    fill: none;
    stroke: #ccc;
    stroke-width: 1.5px;
}

/* 节点圆圈 */
.mindmap-node circle {
    fill: #667eea;
    stroke: #fff;
    stroke-width: 2px;
    cursor: pointer;
}

.mindmap-node.leaf circle {
    fill: #ffffff;
    stroke: #667eea;
    stroke-width: 2px;
}

.mindmap-node:hover circle {
    filter: brightness(0.88);
}

/* 节点文字 */
.mindmap-node text {
    font-size: 12px;
    fill: #333;
    pointer-events: none;
    user-select: none;
}

/* 返回按钮 */
#mindmapBackBtn {
    position: absolute;
    top: 14px;
    left: 16px;
    z-index: 10;
    background: #fff;
    border: 1px solid #e0e7ff;
    border-radius: 8px;
    padding: 5px 14px;
    font-size: 13px;
    color: #667eea;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(102, 126, 234, 0.10);
    transition: background 0.15s;
}

#mindmapBackBtn:hover {
    background: #eef1ff;
}

/* 拖拽提示遮罩 */
.drop-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(59, 130, 246, 0.1);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.drop-overlay.active {
    display: flex;
}

.drop-overlay-content {
    padding: 32px 48px;
    background-color: #fff;
    border: 2px dashed #3b82f6;
    border-radius: 16px;
    text-align: center;
    font-size: 18px;
    color: #3b82f6;
}

/* 图片预览模态框 */
.preview-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
}

.preview-modal.active {
    display: flex;
}

.preview-modal img {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.preview-modal .close-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    background-color: rgba(0, 0, 0, 0.1);
    border: none;
    border-radius: 50%;
    color: #333;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-modal .close-btn:hover {
    background-color: rgba(0, 0, 0, 0.2);
}

.preview-modal .file-name-display {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: #333;
    font-size: 14px;
    background-color: rgba(0, 0, 0, 0.08);
    padding: 8px 16px;
    border-radius: 8px;
}

/* 可点击的附件样式 */
.attachment-item.clickable,
.bubble-attachment.clickable {
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.attachment-item.clickable:hover,
.bubble-attachment.clickable:hover {
    transform: scale(1.02);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.bubble-attachment.clickable img {
    cursor: zoom-in;
}

/* 思考过程样式 */
.thinking-block {
    background-color: #f8f9fa;
    border-left: 3px solid #667eea;
    padding: 12px 16px;
    margin-bottom: 12px;
    border-radius: 0 8px 8px 0;
    font-size: 14px;
    color: #666;
    line-height: 1.6;
    white-space: pre-wrap;
}

.thinking-block-header {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    color: #667eea;
    margin-bottom: 8px;
    font-size: 13px;
}

.thinking-block-content {
    max-height: 300px;
    overflow-y: auto;
}

.thinking-block.collapsed .thinking-block-content {
    max-height: 100px;
    overflow: hidden;
}

.thinking-toggle {
    cursor: pointer;
    color: #667eea;
    font-size: 12px;
    margin-top: 8px;
}

.thinking-toggle:hover {
    text-decoration: underline;
}

/* 搜索结果样式 */
.search-status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background-color: #f0f9ff;
    border: 1px solid #bfdbfe;
    border-radius: 16px;
    font-size: 13px;
    color: #3b82f6;
    margin-bottom: 8px;
}

.search-status .spinner {
    width: 14px;
    height: 14px;
    border: 2px solid #bfdbfe;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.search-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background-color: #f0f9ff;
    border: 1px solid #bfdbfe;
    border-radius: 16px;
    font-size: 13px;
    color: #3b82f6;
    cursor: pointer;
    transition: background-color 0.2s;
    margin-bottom: 8px;
}

.search-toggle-btn:hover {
    background-color: #dbeafe;
}

.search-toggle-btn .arrow {
    font-size: 10px;
    transition: transform 0.2s;
}

.search-toggle-btn.expanded .arrow {
    transform: rotate(180deg);
}

.search-results-panel {
    display: none;
    background-color: #f0f9ff;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
    max-height: 200px;
    overflow-y: auto;
}

.search-results-panel.show {
    display: block;
    animation: slideDown 0.2s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.search-results-panel a {
    display: block;
    padding: 6px 8px;
    color: #2563eb;
    text-decoration: none;
    font-size: 13px;
    border-radius: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-results-panel a:hover {
    background-color: #dbeafe;
}

.search-results-block {
    background-color: #f0f9ff;
    border-left: 3px solid #3b82f6;
    padding: 12px 16px;
    margin-bottom: 12px;
    border-radius: 0 8px 8px 0;
    font-size: 14px;
}

.search-results-header {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    color: #3b82f6;
    margin-bottom: 10px;
    font-size: 13px;
}

.search-results-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.search-result-item {
    background: white;
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid #e0e7ff;
}

.search-result-title {
    color: #2563eb;
    text-decoration: none;
    font-weight: 500;
    font-size: 13px;
    display: block;
    margin-bottom: 4px;
}

.search-result-title:hover {
    text-decoration: underline;
}

.search-result-snippet {
    font-size: 12px;
    color: #666;
    line-height: 1.4;
    max-height: 2.8em;
    /* 2行 × 1.4行高 */
    overflow: hidden;
}

/* 响应式布局 */
@media (max-width: 900px) {
    .sidebar {
        width: 200px;
    }
}

@media (max-width: 700px) {
    .sidebar {
        width: 180px;
    }

    .chat-content {
        padding: 16px;
    }

    .input-area {
        padding: 12px 16px 16px;
    }

    .chat-bubble {
        max-width: 90%;
        font-size: 14px;
    }

    .chat-avatar {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }

    .homepage {
        padding: 24px 16px;
    }

    .homepage-input-container {
        max-width: 100%;
    }
}

@media (max-width: 550px) {
    .sidebar {
        display: none;
    }

    .chat-bubble {
        max-width: 95%;
    }

    .chat-avatar {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }

    .chat-message {
        gap: 8px;
    }

    .action-btn span:last-child {
        display: none;
    }

    .homepage-title {
        font-size: 22px;
    }
}

/* ========== 深度探讨浮窗 ========== */

#subChatPopup {
    display: none;
    position: absolute;
    width: 320px;
    max-height: 70vh;
    min-width: 280px;
    min-height: 200px;
    background: #fff;
    border: 1px solid #e5e5e5;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    flex-direction: column;
    z-index: 2000;
    overflow: hidden;
}

#subChatPopup.open {
    display: flex;
}

.sub-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid #f0f0f0;
    font-weight: 600;
    font-size: 14px;
    color: #333;
    flex-shrink: 0;
    cursor: move;
    user-select: none;
}

/* ── 缩放手柄（桌面端专用）── */
.resizer {
    position: absolute;
    background: transparent;
    z-index: 10;
    transition: background 0.15s;
}

.resizer:hover {
    background: rgba(102, 126, 234, 0.12);
}

.resizer.r {
    top: 0;
    right: 0;
    width: 6px;
    height: 100%;
    cursor: e-resize;
}

.resizer.l {
    top: 0;
    left: 0;
    width: 6px;
    height: 100%;
    cursor: w-resize;
}

.resizer.b {
    bottom: 0;
    left: 0;
    width: 100%;
    height: 6px;
    cursor: s-resize;
}

.resizer.rb {
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    cursor: se-resize;
    z-index: 11;
}

.resizer.lb {
    bottom: 0;
    left: 0;
    width: 12px;
    height: 12px;
    cursor: sw-resize;
    z-index: 11;
}

@media (max-width: 600px) {
    .resizer {
        display: none;
    }

    .sub-popup-header {
        cursor: default;
    }
}

.sub-popup-close {
    background: none;
    border: none;
    font-size: 16px;
    color: #999;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    line-height: 1;
}

.sub-popup-close:hover {
    color: #333;
    background: #f5f5f5;
}

/* ── header 右侧按钮组 ── */
.sub-popup-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* ── 移动端拖拽手柄（桌面端隐藏）── */
.mobile-drag-handle {
    display: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #f0f0f0;
    align-items: center;
    justify-content: center;
    cursor: grab;
    color: #666;
    flex-shrink: 0;
    touch-action: none;
    transition: transform 0.2s ease-out, background 0.15s;
}

.mobile-drag-handle.is-active {
    transform: scale(1.3);
    background: #e8f0ff;
    color: #667eea;
    cursor: grabbing;
}

@media (max-width: 600px) {
    .mobile-drag-handle {
        display: flex;
    }
}

/* ── 移动端缩放按钮（桌面端隐藏）── */
.mobile-resize-btn {
    display: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #f0f0f0;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #666;
    flex-shrink: 0;
    touch-action: manipulation;
    transition: background 0.15s, color 0.15s;
}

.mobile-resize-btn.is-active {
    background: #e8f0ff;
    color: #667eea;
}

@media (max-width: 600px) {
    .mobile-resize-btn {
        display: flex;
    }
}

/* ── 移动端缩放箭头 ── */
.popup-resize-arrow {
    display: none;
    position: absolute;
    background: #667eea;
    color: #fff;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    z-index: 20;
    touch-action: none;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.35);
    user-select: none;
}

/* 右箭头：垂直居中，紧贴右边外侧 */
.popup-resize-arrow-r {
    right: -18px;
    top: 50%;
    transform: translateY(-50%);
}

/* 下箭头：水平居中，紧贴底边外侧 */
.popup-resize-arrow-b {
    bottom: -18px;
    left: 50%;
    transform: translateX(-50%);
}

/* 缩放模式：允许子元素溢出（显示边缘箭头），并显示箭头 */
#subChatPopup.resize-mode {
    overflow: visible;
}

#subChatPopup.resize-mode .popup-resize-arrow {
    display: flex;
}

#subPopupMessages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
}

.sub-bubble-wrap {
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

.sub-bubble-wrap.user {
    flex-direction: row-reverse;
}

.sub-bubble {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
}

.sub-bubble.user {
    background: #e8f4ff;
    color: #333;
    border-bottom-right-radius: 4px;
}

.sub-bubble.ai {
    background: #f5f5f5;
    color: #333;
    border-bottom-left-radius: 4px;
}

.sub-bubble .bubble-text {
    margin: 0;
    white-space: pre-wrap;
}

/* 子窗口 Markdown 样式继承 */
.sub-bubble .bubble-text p {
    margin: 0 0 6px 0;
}

.sub-bubble .bubble-text p:last-child {
    margin-bottom: 0;
}

.sub-bubble .bubble-text code {
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 4px;
    border-radius: 3px;
    font-size: 0.9em;
}

.sub-bubble .bubble-text pre {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 10px 14px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 6px 0;
}

.sub-bubble .bubble-text pre code {
    background: none;
    padding: 0;
    font-size: 13px;
}

.sub-popup-footer {
    border-top: 1px solid #f0f0f0;
    padding: 10px 12px;
    flex-shrink: 0;
    background: #fafafa;
}

.sub-popup-slider-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 12px;
    color: #555;
}

.sub-popup-slider-row input[type="range"] {
    flex: 1;
    accent-color: #667eea;
    cursor: pointer;
}

.sub-popup-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

#subChatInputBox {
    flex: 1;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 13px;
    resize: none;
    outline: none;
    min-height: 38px;
    max-height: 100px;
    font-family: inherit;
    background: #fff;
}

#subChatInputBox:focus {
    border-color: #667eea;
}

#subChatSendBtn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    border: none;
    color: white;
    cursor: pointer;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#subChatSendBtn:hover {
    opacity: 0.9;
}

@media (max-width: 600px) {
    #subChatPopup {
        width: min(94vw, 340px);
    }

    /* 确认框跟随气泡：宽度适配移动端，Top/Left 由 JS 动态写入
    #selectionConfirmBox {
        width: min(94vw, 360px) !important;
        max-width: none !important;
    }

    彻底禁用原生选词视觉干扰
    .chat-bubble.ai.selecting-highlight {
        user-select: none !important;
        -webkit-user-select: none !important;
        -webkit-touch-callout: none !important;
    } */

    /* 5. 信标容器：手柄在下，尖端在上，避免手指遮挡文字 */
    /* .marker-handle {
        position: absolute;
        width: 44px;
        height: 90px;
        z-index: 10000;
        display: flex;
        flex-direction: column;
        align-items: center;
        pointer-events: none;
        will-change: transform;
        transform: translate(-50%, -75px);
    } */

    /* 向上指的蓝色三角 */
    /* .marker-tip {
        width: 0;
        height: 0;
        border-left: 9px solid transparent;
        border-right: 9px solid transparent;
        border-bottom: 14px solid #3b82f6;
    }

    .marker-line {
        width: 2px;
        height: 25px;
        background: #3b82f6;
    } */

    /* 供手指拖拽的圆形手柄（仅 knob 接收触摸，handle 整体穿透）
    .marker-knob {
        width: 30px;
        height: 30px;
        background: #3b82f6;
        border-radius: 50%;
        box-shadow: 0 3px 12px rgba(0, 0, 0, 0.4);
        border: 2px solid #fff;
        pointer-events: auto;
        touch-action: none;
    } */





}

/* ── Pick Mode：消息可点击基础样式 ── */
.chat-content.pick-mode .chat-message.ai .chat-bubble.ai {
    cursor: pointer;
}

/* ── Phase 1 呼吸灯动画（仅用 GPU 加速属性）── */
@keyframes breathe-glow {
    0% {
        box-shadow: 0 0 0 0 rgba(191, 219, 254, 0.7);
        background-color: rgba(239, 246, 255, 0.4);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(191, 219, 254, 0);
        background-color: rgba(239, 246, 255, 0.1);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(191, 219, 254, 0);
        background-color: transparent;
    }
}

.picking-active {
    animation: breathe-glow 2s infinite ease-out;
    will-change: box-shadow, background-color;
    transition: transform 0.15s ease;
}

.picking-active:hover {
    transform: scale(1.01);
}

/* ── 提示栏 ── */
#pickModeHint {
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 20px;
    background: rgba(240, 238, 255, 0.97);
    border-bottom: 1px solid rgba(102, 126, 234, 0.25);
    font-size: 13px;
    color: #555;
    flex-shrink: 0;
}

#pickModeHint.active {
    display: flex;
}

#pickHintText {
    flex: 1;
}

.pick-hint-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

#pickConfirmWholeBtn {
    display: none;
    padding: 5px 12px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
}

#pickConfirmWholeBtn:hover {
    opacity: 0.88;
}

#pickCancelBtn {
    padding: 5px 10px;
    background: #f0f0f0;
    color: #666;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
}

#pickCancelBtn:hover {
    background: #e5e5e5;
}

/* ── Phase 2：目标气泡高亮框 ── */
.chat-bubble.ai.selecting-highlight {
    outline: 2px solid #667eea;
    outline-offset: 3px;
    cursor: text;
    user-select: text;
}

/* ── 划选确认气泡 ── */
#selectionConfirmBox {
    display: none;
    position: fixed;
    z-index: 10001;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.16);
    padding: 12px 14px;
    width: 300px;
    font-size: 13px;
    /* 1. 提高背景白度的亮度（使用 0.9 或者 0.92） */
    background: rgba(255, 255, 255, 0.92) !important;
    /* 2. 增加模糊强度，苹果原生的模糊感非常重 */
    backdrop-filter: blur(25px) saturate(180%) !important;
    -webkit-backdrop-filter: blur(25px) saturate(180%) !important;
    /* 3. 苹果菜单的描边其实是带有亮度的，不是纯黑 */
    border: 0.5px solid rgba(255, 255, 255, 0.4) !important;
    /* 4. 阴影要深一些但范围要广，这样能反衬出盒子的“白” */
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2) !important;
    /* 5. 确保内部没有任何深色背景遮挡 */

    /* ── 核心修改：彻底禁止选中 ── */
    user-select: none !important;
    -webkit-user-select: none !important;
    /* iOS 必须 */
    -webkit-touch-callout: none !important;
    /* 禁用 iOS 长按弹出系统菜单 */

    /* 限制最大宽度，防止在极小屏手机上溢出 */
    max-width: 92vw;

    /* 增加平滑过渡动画，弹出时更自然 */
    transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);

    /* 确保内部元素也无法被选中 */
    pointer-events: auto;
    /* 确保按钮依然可以点击 */
}

/* 针对确认框内部所有文字和按钮的额外保护 */
#selectionConfirmBox * {
    user-select: none !important;
    -webkit-user-select: none !important;
    -webkit-tap-highlight-color: transparent;
    /* 移除移动端点击高亮蓝框 */
}

/* 预览文本区域：防止其成为选词干扰项 */
#confirmQuotePreview {
    /* 基础样式保持不变 */
    display: block;
    /* 下方会被 -webkit-box 覆盖，但保留作为兜底 */
    color: #666;
    background: #f8f9fa;
    padding: 8px;
    border-radius: 6px;
    margin-bottom: 8px;
    border-left: 3px solid #667eea;
    pointer-events: none;

    /* --- 新增：5行截断核心逻辑 --- */
    display: -webkit-box;
    /* 必须使用盒子模型 */
    -webkit-box-orient: vertical;
    /* 设置垂直方向 */
    /* -webkit-line-clamp: 5;          限制显示 5 行 */
    overflow: hidden;
    /* 隐藏超出部分 */

    /* 额外保护：解决公式或长英文不换行的问题 */
    line-height: 1.5;
    /* 固定的行高便于计算 */
    max-height: 7.5em;
    /* 物理高度兜底 (1.5 * 5) */
    word-break: break-all;
    /* 强制换行防止撑破宽度 */
}

.confirm-quote {
    color: #555;
    line-height: 1.55;
    margin-bottom: 10px;
    word-break: break-all;
}

.confirm-quote-text {
    color: #667eea;
    background: #f0eeff;
    padding: 1px 5px;
    border-radius: 4px;
    font-style: normal;
}

.confirm-actions {
    display: flex;
    gap: 8px;
}

.confirm-yes {
    flex: 1;
    padding: 7px 0;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
}

.confirm-yes:hover {
    opacity: 0.88;
}

.confirm-no {
    padding: 7px 12px;
    background: #f5f5f5;
    color: #666;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
}

.confirm-no:hover {
    background: #eee;
}


/* ── 子对话内的引用片段提示条 ── */
.sub-quote-chip {
    /* 1. 核心修改：使用 inline-flex，这能让容器既像行内元素一样不占整行，
          又能像 Flexbox 一样让子元素（图标、文字、公式）横向排列 */
    display: inline-flex !important;
    align-items: center;
    /* 核心：垂直居中对齐，解决公式偏上或偏下的问题 */
    flex-wrap: wrap;
    /* 允许长文本在必要时换行，但不会强行切断公式 */
    gap: 6px;
    /* 图标和文字之间的间距 */
    /* 2. 基础样式保持不变 */
    margin: 4px 0 !important;
    /* 给点垂直外边距防止引用块互相挤压 */
    padding: 8px 12px;
    background: #f0eeff;
    border-left: 3px solid #667eea;
    border-radius: 0 8px 8px 0;
    font-size: 12px;
    color: #555;
    line-height: 1.5;
    max-width: 100%;
    /* 宽度保护 */
    word-break: break-all;
    /* 防止长公式源码撑爆容器 */
}

.sub-quote-chip .sub-quote-icon {
    flex-shrink: 0;
}

.sub-quote-chip .sub-quote-text {
    color: #444;
    display: inline;
    /* 确保文字是行内的 */

}

.sub-quote-chip strong {
    color: #667eea;
    font-weight: 600;
}

.sub-quote-content {
    display: inline-block;
}

/* 覆盖 KaTeX 的强制换行样式 */
.sub-quote-content .katex-display {
    display: inline !important;
    margin: 0 !important;
}

.sub-quote-content .katex {
    display: inline-block !important;
    line-height: 1 !important;
    text-indent: 0 !important;
}


/* ── 移动端虚拟选区高亮层（代替系统蓝底）── */
/* .virtual-selection-layer {
    position: absolute;
    background: rgba(59, 130, 246, 0.22);
    pointer-events: none;
    z-index: 9999;
} */

/* ── KaTeX：抑制 tap 高亮与幽灵蓝底 ── */
/* .katex-display,
.katex {
    -webkit-tap-highlight-color: transparent;
}

/* 1. 消除公式选区的视觉残留 */
/* .chat-bubble.ai.selecting-highlight .katex {
    position: relative;
    isolation: isolate;
} */

/* 2. 屏蔽 KaTeX 的测量/辅助元素，不让它们被选中 */
/* .chat-bubble.ai.selecting-highlight .katex .hide-tail,
.chat-bubble.ai.selecting-highlight .katex .vlist-t,
.chat-bubble.ai.selecting-highlight .katex .strut,
.chat-bubble.ai.selecting-highlight .katex .vlist-s {
    -webkit-user-select: none !important;
    user-select: none !important;
    pointer-events: none !important;
} */

/* 3. 强制裁剪容器，防止"镜像蓝底"出现在公式下方 */
/* .chat-bubble.ai.selecting-highlight .katex-html {
    overflow: hidden !important;
    -webkit-tap-highlight-color: transparent;
} */

/* 4. 优化选区背景色，使其整洁 */
/* .chat-bubble.ai.selecting-highlight .katex *::selection { */
/* background: rgba(59, 130, 246, 0.3) !important;
} */


/* ========== 移动端侧边栏抽屉 ========== */
.mobile-drop-zone {
    display: none !important;
}

@media (max-width: 768px) {

    /* 汉堡按钮显示 */
    .mobile-menu-btn {
        display: flex;
    }

    /* 侧边栏变为固定抽屉，初始隐藏在左侧外 */
    .sidebar {
        position: fixed;
        top: 0;
        left: -280px;
        width: 260px;
        height: 100%;
        z-index: 200;
        transition: left 0.3s ease;
        box-shadow: none;
        border-radius: 0 16px 16px 0;
        overflow: hidden;
    }

    .sidebar.active {
        left: 0;
        box-shadow: 4px 0 15px rgba(0, 0, 0, 0.1);
    }

    /* 主内容占满全宽 */
    .main-content {
        width: 100%;
        flex: 1;
    }

    /* 探讨存档区在移动端可正常滚动 */
    #subChatStorageArea {
        display: flex;
        flex-direction: column;
        max-height: 45vh;
        overflow-y: auto;
    }

    #subChatSavedList {
        flex: 1;
        overflow-y: auto;
    }

    .sidebar {
        background-color: #fff !important;
        /* 防止透明 */
        z-index: 200 !important;
        /* 确保在遮罩 (150) 之上 */
        display: flex !important;
        /* 确保不是 none */
    }

    /* ── 移动端拖拽投放区 ── */
    .mobile-drop-zone {
        display: flex !important;
        height: 0;
        overflow: hidden;
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 13px;
        font-weight: 500;
        color: #667eea;
        background: linear-gradient(90deg, #eef1ff, #f5f0ff);
        border: 1.5px dashed #a5b4fc;
        border-radius: 8px;
        margin: 0 8px;
        transition: height 0.25s ease, opacity 0.25s ease;
        opacity: 0;
        pointer-events: none;
    }

    body.drag-active .mobile-drop-zone {
        height: 50px;
        opacity: 1;
        pointer-events: auto;
    }

    @keyframes dropzone-nudge {

        0%,
        100% {
            transform: scale(1);
        }

        40% {
            transform: scale(1.03);
        }

        70% {
            transform: scale(0.97);
        }
    }

    .mobile-drop-zone.hover {
        background: linear-gradient(90deg, #dde4ff, #ede8ff);
        border-color: #667eea;
        animation: dropzone-nudge 0.35s ease;
    }
}

/* 强制 foreignObject 遵循 SVG 布局 */
foreignObject {
    position: relative; /* 防止被设置为 absolute */
    margin: 0;
    padding: 0;
}

/* 确保内部 div 不会产生额外的偏移 */
foreignObject div {
    background: transparent;
    margin: 0;
}