.source-document { display: block; font-weight: 600; overflow-wrap: anywhere; }
.chatpdf-selection-context { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .5rem; border: 1px solid currentColor; border-radius: .5rem; overflow-wrap: anywhere; }
.chatpdf-selection-context button, #chatpdfRestoreStatus button { min-height: 32px; padding: .25rem .5rem; text-decoration: underline; }
#chatpdfRestoreStatus { flex-basis: 100%; }
/* Chat With PDF Page-Specific Styles
 * Extracted from templates/chat_with_pdf_react.html so page CSS can be cached
 * and the HTML payload stays small. Core PDF styles remain in tailwind.css.
 */

    /* 页面特定样式 - 仅包含复杂布局和此页面独有的样式 */

    /* ===== 以下样式已迁移到 tailwind.css ===== */
    /* .pdf-btn, .pdf-btn-primary, .chat-message, .typing-indicator, */
    /* .textLayer, .pdf-paragraph, .pdf-page-*, .text-selection-menu */
    /* 等核心样式已在 tailwind.css 中定义 */

    /* PDF 按钮图标尺寸 */
    .pdf-btn-icon {
        width: 36px;
        height: 36px;
        padding: 0;
        justify-content: center;
    }

    .pdf-btn-icon .heroicon {
        width: 18px;
        height: 18px;
        stroke: currentColor;
        stroke-width: 2;
        fill: none;
        stroke-linecap: round;
        stroke-linejoin: round;
        pointer-events: none;
    }

    /* PDF 容器状态 */
    #pdfContainer {
        position: relative;
        display: flex;
        align-items: flex-start;
        justify-content: center;
    }


    /* Chat PDF history area: smooth first paint and content replacement */
    .pdf-history-section {
        opacity: 0;
        transform: translateY(10px);
        animation: chatPdfHistorySectionIn 360ms cubic-bezier(0.22, 1, 0.36, 1) 120ms forwards;
    }

    .pdf-history-title {
        transition: color 180ms ease, opacity 180ms ease;
    }

    #historyDocsList {
        min-height: 64px;
        transition: opacity 180ms ease, transform 180ms ease;
        will-change: opacity, transform;
    }

    #historyDocsList.history-swap-out {
        opacity: 0;
        transform: translateY(6px);
    }

    #historyDocsList.history-swap-in {
        animation: chatPdfHistoryContentIn 260ms cubic-bezier(0.22, 1, 0.36, 1) both;
    }

    .history-loading,
    .history-empty {
        color: rgba(115, 115, 115, 0.92);
        font-size: 15px;
        line-height: 1.6;
        text-align: center;
    }

    .history-loading .ph-spinner {
        display: inline-block;
        margin-right: 8px;
        animation: chatPdfHistorySpin 800ms linear infinite;
    }

    @keyframes chatPdfHistorySectionIn {
        from {
            opacity: 0;
            transform: translateY(10px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    @keyframes chatPdfHistoryContentIn {
        from {
            opacity: 0;
            transform: translateY(6px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    @keyframes chatPdfHistorySpin {
        to {
            transform: rotate(360deg);
        }
    }

    @media (prefers-reduced-motion: reduce) {
        .pdf-history-section,
        #historyDocsList,
        #historyDocsList.history-swap-in,
        #historyDocsList.history-swap-out,
        .history-loading .ph-spinner {
            animation: none !important;
            transition: none !important;
            transform: none !important;
            opacity: 1 !important;
        }
    }

    /* Chat PDF 选中文本弹层：限制宽度，避免长预览撑宽后贴到/伸入左侧 sidebar */
    .text-selection-menu {
        min-width: min(280px, calc(100vw - 24px));
        width: min(360px, calc(100vw - 24px));
        max-width: calc(100vw - 24px);
        box-sizing: border-box;
    }

    #pdfContainer.has-pdf {
        display: block !important;
        overflow-y: auto;
        overflow-x: hidden;
    }

    /* PDF 页面容器 */
    #pdfPagesContainer {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 16px;
        padding: 16px 0;
    }

    /* 页面特定的固定布局样式 */
    .selected-text-indicator {
        position: fixed;
        bottom: 20px;
        right: 20px;
        background: rgba(0, 0, 0, 0.8);
        color: white;
        padding: 8px 16px;
        border-radius: 8px;
        display: none;
        align-items: center;
        gap: 8px;
        font-size: 14px;
        z-index: 1000;
        max-width: 300px;
    }
    
    .selected-text-indicator.show {
        display: flex;
    }
    
    /* 通知动画 */
    @keyframes slideIn {
        from {
            transform: translateX(100%);
            opacity: 0;
        }
        to {
            transform: translateX(0);
            opacity: 1;
        }
    }
    
    @keyframes slideOut {
        from {
            transform: translateX(0);
            opacity: 1;
        }
        to {
            transform: translateX(100%);
            opacity: 0;
        }
    }
    
    /* 卡片折叠动画 */
    .citation-header-card {
        transition: all 0.3s ease;
        overflow: hidden;
        max-height: 200px;
    }
    
    .citation-header-card.hidden {
        max-height: 0;
        margin-bottom: 0;
        opacity: 0;
        transform: translateY(-10px);
    }
    
    /* 切换按钮样式 */
    .toggle-header-btn {
        transition: transform 0.3s ease;
    }
    
    .toggle-header-btn.rotated {
        transform: rotate(180deg);
    }
    
    /* 文本选择弹出菜单样式 */
    .text-selection-menu {
        position: fixed;
        background: white;
        border-radius: 8px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        border: 1px solid #e5e5e5;
        z-index: 10000;
        display: none;
        opacity: 0;
        transform: translateY(-10px);
        transition: all 0.2s ease;
        min-width: min(280px, calc(100vw - 24px));
        width: min(360px, calc(100vw - 24px));
        max-width: calc(100vw - 24px);
        box-sizing: border-box;
    }
    
    .text-selection-menu.show {
        opacity: 1;
        transform: translateY(0);
    }
    
    .selection-menu-content {
        padding: 12px;
    }
    
    .selection-menu-header {
        padding: 8px 12px;
        background: #F8F8F7;
        border-radius: 6px;
        margin-bottom: 12px;
        max-height: 60px;
        overflow: hidden;
    }
    
    .selection-text-preview {
        font-size: 13px;
        color: #666;
        line-height: 1.4;
        display: -webkit-box;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .selection-menu-actions {
        display: flex;
        flex-direction: column;
        gap: 4px;
    }
    
    .selection-action-btn {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 10px 12px;
        background: white;
        border: 1px solid transparent;
        border-radius: 6px;
        cursor: pointer;
        transition: all 0.15s ease;
        font-size: 14px;
        text-align: left;
        width: 100%;
        color: #333;
    }
    
    .selection-action-btn:hover {
        background: #F8F8F7;
        border-color: #e5e5e5;
        transform: translateX(2px);
    }
    
    .selection-action-btn i {
        width: 20px;
        text-align: center;
        color: #666;
    }
    
    .selection-action-btn:hover i {
        color: #000;
    }
    
    /* 消息气泡标题样式 */
    .message-title {
        font-size: 11px;
        color: #999;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        margin-bottom: 4px;
        font-weight: 500;
    }
    
    .chat-message.user .message-title {
        color: rgba(51, 51, 51, 0.7);
    }
    
    .message-text {
        font-size: 14px;
        line-height: 1.5;
    }
    
    .message-time {
        font-size: 11px;
        color: #999;
        margin-top: 4px;
    }
    
    .chat-message.user .message-time {
        color: rgba(51, 51, 51, 0.6);
    }
    
    /* 示例文档链接样式 */
    #samplePdfBtn:hover {
        text-decoration: underline !important;
    }
    
    /* 搜索高亮样式 - 亮黄色,不影响文本选择 */
    .search-highlight {
        background-color: rgba(255, 255, 0, 0.6) !important;
        /* 不使用padding和border-radius,避免破坏文本层布局 */
    }
    
    /* PDF查看器容器样式 */
    #pdfViewerContainer {
        position: relative;
        width: 100%;
        height: 100%;
    }
    
    #pdfTextLayer {
        user-select: text;
        cursor: text;
    }
    
    /* PDF搜索框样式 */
    #pdfSearchBox {
        animation: slideInFromRight 0.3s ease-out;
    }
    
    @keyframes slideInFromRight {
        from {
            opacity: 0;
            transform: translateX(20px);
        }
        to {
            opacity: 1;
            transform: translateX(0);
        }
    }
    
    /* 隐藏 footer 和聊天悬浮按钮 */
    #chatWidget {
        display: none !important;
    }

    footer,
    .footer,
    .site-footer,
    #site-footer {
        display: none !important;
    }

    /* 确保支付模态框的按钮区域正常显示 */
    .payment-option-footer {
        display: block !important;
    }
    .payment-option-footer.compact {
        display: block !important;
    }
    
    /* 优化页面布局 - 占满整个视口 */
    .citation-workspace-vertical {
        height: 100vh;
        display: flex;
        flex-direction: column;
        padding: 0;
        margin: 0;
        overflow: hidden;
        background: #F8F8F7;
    }
    
    /* PDF卡片占满剩余空间 */
    .citation-workspace-vertical > .pdf-card {
        flex: 1;
        height: auto !important;
        min-height: 0 !important;
        margin: 0;
        overflow: hidden;
        display: flex;
        padding: 0;
    }
    
    /* 主容器布局 - 固定高度 */
    .citation-workspace-vertical > .pdf-card > div[style*="display: flex"] {
        height: 100% !important;
    }
    
    /* PDF查看器卡片 - 固定定位，参考视口高度，响应sidebar状态 */
    /* 固定间距变量 */
    :root {
        --pdf-chat-gap: 16px; /* 左右卡片之间的固定间距 */
        --card-margin: 8px; /* 卡片与边缘的间距 */
    }
    
    .citation-workspace-vertical .pdf-viewer-card {
        position: fixed !important;
        left: var(--sidebar-width, 240px) !important; /* 默认sidebar展开宽度 */
        top: 60px !important;
        height: calc(100vh - 60px - 16px) !important; /* 减去顶部和底部的边距 */
        /* 宽度 = 视口宽度 - sidebar宽度 - 右侧聊天卡片宽度 - 固定间距 - 左右边距 */
        width: calc(100vw - var(--sidebar-width, 240px) - 520px - var(--pdf-chat-gap) - var(--card-margin) * 2) !important;
        max-width: calc(100vw - var(--sidebar-width, 240px) - 380px - var(--pdf-chat-gap) - var(--card-margin) * 2) !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        background: white !important;
        border-radius: 12px !important;
        box-shadow: 2px 0 8px 0 rgba(0, 0, 0, 0.1) !important;
        border: 1px solid #e5e5e5 !important;
        margin: var(--card-margin) !important;
        margin-right: calc(var(--pdf-chat-gap) / 2) !important; /* 间距的一半给左侧卡片 */
        z-index: 99 !important;
        transition: left 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                    width 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                    top 0.3s ease,
                    height 0.3s ease !important;
    }
    
    /* 当标题卡片显示时，PDF卡片向下移动 */
    body.header-card-visible .citation-workspace-vertical .pdf-viewer-card {
        top: 180px !important; /* 60px header + 120px 标题卡片区域 */
        height: calc(100vh - 180px - 16px) !important; /* 减去顶部和底部的边距 */
    }
    
    /* Sidebar收缩状态 - PDF卡片调整 */
    .sidebar-collapsed .citation-workspace-vertical .pdf-viewer-card,
    body.sidebar-collapsed .citation-workspace-vertical .pdf-viewer-card,
    [data-sidebar-collapsed="true"] .citation-workspace-vertical .pdf-viewer-card {
        left: var(--sidebar-collapsed-width, 60px) !important;
        width: calc(100vw - var(--sidebar-collapsed-width, 60px) - 520px - var(--pdf-chat-gap) - var(--card-margin) * 2) !important;
        max-width: calc(100vw - var(--sidebar-collapsed-width, 60px) - 380px - var(--pdf-chat-gap) - var(--card-margin) * 2) !important;
    }
    
    /* 大屏幕 - PDF卡片固定最大宽度 */
    @media (min-width: 1486px) {
        .citation-workspace-vertical .pdf-viewer-card {
            width: calc(100vw - var(--sidebar-width, 240px) - 520px - var(--pdf-chat-gap) - var(--card-margin) * 2) !important;
            max-width: calc(100vw - var(--sidebar-width, 240px) - 520px - var(--pdf-chat-gap) - var(--card-margin) * 2) !important;
        }
        
        .sidebar-collapsed .citation-workspace-vertical .pdf-viewer-card,
        body.sidebar-collapsed .citation-workspace-vertical .pdf-viewer-card,
        [data-sidebar-collapsed="true"] .citation-workspace-vertical .pdf-viewer-card {
            width: calc(100vw - var(--sidebar-collapsed-width, 60px) - 520px - var(--pdf-chat-gap) - var(--card-margin) * 2) !important;
            max-width: calc(100vw - var(--sidebar-collapsed-width, 60px) - 520px - var(--pdf-chat-gap) - var(--card-margin) * 2) !important;
        }
    }
    
    /* PDF工具栏 - 卡片顶部，圆角效果，固定在顶部 */
    .pdf-viewer-card > .pdf-toolbar {
        position: sticky;
        top: 0;
        border-radius: 12px 12px 0 0;
        flex-shrink: 0;
        z-index: 100;
        background: white;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }
    
    /* PDF内容区域 - 卡片内可滚动 */
    .pdf-viewer-card > div[id="pdfContainer"] {
        flex: 1;
        overflow: auto;
        min-height: 0;
    }
    
    /* Chat区域卡片 - 固定在右侧，带卡片样式，固定宽度 */
    .chat-section-card {
        position: fixed !important;
        right: 0 !important;
        top: 60px !important;
        height: calc(100vh - 60px - 16px) !important; /* 减去顶部和底部的边距 */
        width: 520px !important; /* 固定宽度 */
        min-width: 380px !important;
        max-width: 520px !important;
        display: flex !important;
        flex-direction: column !important;
        z-index: 100 !important;
        background: white !important;
        border-radius: 12px 0 0 12px !important;
        box-shadow: -2px 0 8px 0 rgba(0, 0, 0, 0.1) !important;
        border: 1px solid #e5e5e5 !important;
        border-right: none !important;
        overflow: hidden !important;
        margin: var(--card-margin) 0 var(--card-margin) calc(var(--pdf-chat-gap) / 2) !important; /* 间距的一半给右侧卡片 */
        transition: top 0.3s ease, height 0.3s ease, width 0.25s ease !important;
    }
    
    /* 当标题卡片显示时，聊天卡片也向下移动 */
    body.header-card-visible .chat-section-card {
        top: 180px !important; /* 60px header + 120px 标题卡片区域 */
        height: calc(100vh - 180px - 16px) !important; /* 减去顶部和底部的边距 */
    }
    
    /* 确保聊天消息区域可滚动 */
    .chat-section-card #pdfChatMessages {
        flex: 1 !important;
        overflow-y: auto !important;
    }
    
    /* PDF查看器卡片工具栏顶部圆角 */
    .pdf-viewer-card > .pdf-toolbar {
        border-radius: 12px 12px 0 0 !important;
    }
    
    /* 响应式设计 - 中等屏幕 (1200px - 1400px) */
    @media (max-width: 1400px) and (min-width: 1200px) {
        .chat-section-card {
            width: 480px !important; /* 稍微缩小右侧卡片 */
        }
        
        .citation-workspace-vertical .pdf-viewer-card {
            width: calc(100vw - var(--sidebar-width, 240px) - 480px - var(--pdf-chat-gap) - var(--card-margin) * 2) !important;
            max-width: calc(100vw - var(--sidebar-width, 240px) - 480px - var(--pdf-chat-gap) - var(--card-margin) * 2) !important;
        }
        
        .sidebar-collapsed .citation-workspace-vertical .pdf-viewer-card,
        body.sidebar-collapsed .citation-workspace-vertical .pdf-viewer-card,
        [data-sidebar-collapsed="true"] .citation-workspace-vertical .pdf-viewer-card {
            width: calc(100vw - var(--sidebar-collapsed-width, 60px) - 480px - var(--pdf-chat-gap) - var(--card-margin) * 2) !important;
            max-width: calc(100vw - var(--sidebar-collapsed-width, 60px) - 480px - var(--pdf-chat-gap) - var(--card-margin) * 2) !important;
        }
    }
    
    /* 响应式设计 - 较小屏幕 (1000px - 1200px) */
    @media (max-width: 1200px) and (min-width: 1000px) {
        .chat-section-card {
            width: 420px !important; /* 进一步缩小右侧卡片 */
            min-width: 350px !important;
        }
        
        .citation-workspace-vertical .pdf-viewer-card {
            width: calc(100vw - var(--sidebar-width, 240px) - 420px - var(--pdf-chat-gap) - var(--card-margin) * 2) !important;
            max-width: calc(100vw - var(--sidebar-width, 240px) - 420px - var(--pdf-chat-gap) - var(--card-margin) * 2) !important;
        }
        
        .sidebar-collapsed .citation-workspace-vertical .pdf-viewer-card,
        body.sidebar-collapsed .citation-workspace-vertical .pdf-viewer-card,
        [data-sidebar-collapsed="true"] .citation-workspace-vertical .pdf-viewer-card {
            width: calc(100vw - var(--sidebar-collapsed-width, 60px) - 420px - var(--pdf-chat-gap) - var(--card-margin) * 2) !important;
            max-width: calc(100vw - var(--sidebar-collapsed-width, 60px) - 420px - var(--pdf-chat-gap) - var(--card-margin) * 2) !important;
        }
    }
    
    /* 响应式设计 - 小屏幕 (768px - 1000px) 允许重叠 */
    @media (max-width: 1000px) and (min-width: 768px) {
        .chat-section-card {
            width: 380px !important;
            min-width: 320px !important;
        }
        
        .citation-workspace-vertical .pdf-viewer-card {
            left: 0 !important;
            width: calc(100vw - var(--card-margin) * 2) !important;
            max-width: calc(100vw - var(--card-margin) * 2) !important;
            margin-right: var(--card-margin) !important;
        }
        
        .sidebar-collapsed .citation-workspace-vertical .pdf-viewer-card,
        body.sidebar-collapsed .citation-workspace-vertical .pdf-viewer-card,
        [data-sidebar-collapsed="true"] .citation-workspace-vertical .pdf-viewer-card {
            left: 0 !important;
            width: calc(100vw - var(--card-margin) * 2) !important;
            max-width: calc(100vw - var(--card-margin) * 2) !important;
        }
    }
    
    /* 移动端顶部选择器样式 - 默认隐藏 */
    .mobile-top-tabs {
        display: none;
    }

    /* 响应式设计 - 移动端 (小于768px) Tab切换布局 */
    @media (max-width: 768px) {
        /* 隐藏底部tab栏（使用顶部选择器代替） */
        .mobile-tab-bar {
            display: none !important;
        }

        /* 顶部选择器样式 */
        .mobile-top-tabs {
            display: flex !important;
            position: fixed !important;
            top: 56px !important; /* header高度 */
            left: 0 !important;
            right: 0 !important;
            height: 44px !important;
            background: white !important;
            border-bottom: 1px solid #e5e5e5 !important;
            z-index: 100 !important;
            padding: 0 16px !important;
            gap: 8px !important;
            align-items: center !important;
            justify-content: center !important;
        }

        .mobile-top-tab {
            flex: 1 !important;
            max-width: 160px !important;
            display: flex !important;
            align-items: center !important;
            justify-content: center !important;
            gap: 6px !important;
            padding: 8px 16px !important;
            border: none !important;
            background: #f5f5f5 !important;
            border-radius: 8px !important;
            font-size: 14px !important;
            font-weight: 500 !important;
            color: #666 !important;
            cursor: pointer !important;
            transition: all 0.2s ease !important;
        }

        .mobile-top-tab i {
            font-size: 14px !important;
        }

        .mobile-top-tab.active {
            background: var(--color-primary, #F5A623) !important;
            color: white !important;
        }

        .mobile-top-tab:not(.active):hover {
            background: #eee !important;
        }

        /* 移动端父容器需要相对定位和正确的高度 */
        .citation-workspace-vertical {
            position: fixed !important;
            top: 100px !important; /* header(56px) + 顶部选择器(44px) */
            left: 0 !important;
            right: 0 !important;
            bottom: 0 !important;
            height: auto !important;
            padding: 0 !important;
            margin: 0 !important;
            overflow: hidden !important;
        }

        .citation-workspace-vertical > .pdf-card {
            position: relative !important;
            width: 100% !important;
            height: 100% !important;
            margin: 0 !important;
            padding: 0 !important;
            overflow: hidden !important;
        }

        /* 两个卡片使用固定定位，全屏显示 */
        .pdf-viewer-card,
        .chat-section-card {
            position: fixed !important;
            top: 100px !important; /* header(56px) + 顶部选择器(44px) */
            left: 0 !important;
            right: 0 !important;
            bottom: 0 !important;
            width: 100% !important;
            height: auto !important;
            max-width: none !important;
            margin: 0 !important;
            border-radius: 0 !important;
            border: none !important;
            box-shadow: none !important;
            background: white !important;
            z-index: 10 !important;
            display: none !important;
            flex-direction: column !important;
            overflow: hidden !important;
        }

        /* 激活状态显示 */
        .pdf-viewer-card.mobile-tab-content-active,
        .chat-section-card.mobile-tab-content-active {
            display: flex !important;
            z-index: 20 !important;
        }

        /* PDF工具栏移动端样式 */
        .pdf-viewer-card .pdf-toolbar {
            flex-shrink: 0 !important;
            border-radius: 0 !important;
        }

        /* PDF内容区域填满剩余空间 */
        .pdf-viewer-card #pdfContainer {
            flex: 1 !important;
            overflow: auto !important;
            min-height: 0 !important;
        }

        /* 聊天消息区域填满剩余空间 */
        .chat-section-card #pdfChatMessages {
            flex: 1 !important;
            overflow-y: auto !important;
            min-height: 0 !important;
        }

        /* 移动端历史文档文件名折行 */
        .history-filename-cell {
            max-width: calc(100vw - 140px) !important; /* 留出时间和聊天数的空间 */
            white-space: normal !important;
            word-wrap: break-word !important;
            word-break: break-all !important;
            overflow-wrap: anywhere !important;
            line-height: 1.3 !important;
            font-size: 13px !important;
        }

        .history-docs-table {
            table-layout: fixed !important;
            width: 100% !important;
        }

        .history-docs-table th:first-child,
        .history-docs-table td:first-child {
            width: auto !important;
        }

        .history-docs-table th:nth-child(2),
        .history-docs-table td:nth-child(2) {
            width: 80px !important;
            white-space: nowrap !important;
        }

        .history-docs-table th:nth-child(3),
        .history-docs-table td:nth-child(3) {
            width: 50px !important;
            text-align: center !important;
        }
    }
    
    /* 历史文档表格样式 */
    .history-docs-table {
        width: 100%;
        max-width: 900px;
        border-collapse: collapse;
        font-size: 13px;
        background: transparent;
        border-radius: 8px;
        overflow: hidden;
        box-shadow: none;
    }
    
    .history-docs-table thead {
        background: transparent;
        border-bottom: 1px solid #e5e7eb;
    }
    
    .history-docs-table th {
        padding: 6px 12px;
        text-align: left;
        font-weight: 600;
        color: #6b7280;
        font-size: 12px;
        white-space: nowrap;
    }
    
    .history-docs-table td {
        padding: 6px 12px;
        border-bottom: 1px solid #f3f4f6;
        color: #374151;
    }
    
    .history-docs-table tbody tr {
        cursor: pointer;
        transition: background 0.2s ease;
        background: transparent;
    }
    
    .history-docs-table tbody tr:hover {
        background: rgba(0, 0, 0, 0.03);
    }
    
    .history-docs-table tbody tr:last-child td {
        border-bottom: none;
    }
    
    .history-filename-cell {
        max-width: 500px;
        white-space: normal;
        word-wrap: break-word;
        word-break: break-word;
        font-weight: 500;
        color: #111827;
        text-align: left;
        line-height: 1.4;
    }
    
    .history-time-cell {
        color: #6b7280;
        font-size: 12px;
    }
    
    .history-count-cell {
        text-align: center;
        color: #059669;
        font-weight: 500;
    }
    
    .history-view-more {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 10px;
        margin-top: 12px;
        color: #666;
        font-size: 13px;
        cursor: pointer;
        transition: all 0.2s ease;
        border-radius: 6px;
    }
    
    .history-view-more:hover {
        background: #f3f4f6;
        color: #000;
    }
    
    .history-empty {
        text-align: center;
        padding: 24px;
        color: #9ca3af;
        font-size: 13px;
    }

    /* ==================== 新增元素默认样式 ==================== */
    .pdf-page-indicator {
        color: #666;
    }

    .pdf-toolbar-divider {
        background: #e5e5e5;
    }

    .pdf-toolbar select {
        background: white;
        border-color: #e5e5e5;
        color: inherit;
    }

    #pdfContainer {
        background: #F8F8F7;
    }

    .pdf-placeholder-icon {
        color: #ccc;
    }

    .pdf-placeholder-text {
        color: #666;
    }

    .pdf-placeholder-hint {
        color: #ccc;
    }

    .pdf-sample-link {
        color: #666;
    }

    .pdf-history-section {
        border-top: 1px solid #e5e5e5;
    }

    .pdf-history-title {
        color: #666;
    }

    .history-loading {
        color: #999;
    }

    #pdfSearchBox {
        background: white;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }

    #pdfSearchInput {
        border-color: #e5e5e5;
        background: white;
    }

    .pdf-search-results {
        color: #666;
    }

    #pdfChatMessages {
        background: #f9fafb;
    }

    .pdf-chat-welcome-container {
        text-align: center;
        padding: 48px 24px;
    }

    .pdf-chat-welcome-icon-wrapper {
        width: 64px;
        height: 64px;
        border-radius: 16px;
        background: linear-gradient(135deg, rgba(79, 70, 229, 0.1) 0%, rgba(99, 102, 241, 0.06) 100%);
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 0 auto 20px;
    }

    .pdf-chat-welcome-svg {
        width: 32px;
        height: 32px;
        color: var(--color-primary, #4f46e5);
        opacity: 0.85;
    }

    .pdf-chat-welcome-title {
        font-size: 17px;
        font-weight: 600;
        color: #111827;
        margin-bottom: 6px;
    }

    .pdf-chat-welcome-desc {
        font-size: 13px;
        color: #9ca3af;
        margin-bottom: 20px;
    }

    .pdf-chat-welcome-features {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        max-width: 340px;
        margin: 0 auto;
    }

    .pdf-chat-feature-card {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 10px 14px;
        border-radius: 10px;
        background: #ffffff;
        border: 1px solid #f3f4f6;
        font-size: 13px;
        color: #4b5563;
        text-align: left;
    }

    .pdf-chat-feature-card svg {
        flex-shrink: 0;
        color: var(--color-primary, #4f46e5);
        opacity: 0.7;
    }

    .pdf-chat-input-wrapper {
        border-top: 1px solid #e5e5e5;
        background: white;
    }

    #pdfChatInput {
        border-color: #e5e5e5;
        background: white;
    }

    .pdf-char-count {
        color: #ccc;
    }

    .pdf-toolbar {
        background: white;
        border-bottom-color: #e5e5e5;
    }

    /* ==================== Dark Mode ==================== */
    html.dark .text-selection-menu {
        background: #1e1e1e;
        border-color: #404040;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    }

    html.dark .selection-menu-header {
        background: #2a2a2a;
    }

    html.dark .selection-text-preview {
        color: #a3a3a3;
    }

    html.dark .selection-action-btn {
        background: #1e1e1e;
        color: #d4d4d4;
    }

    html.dark .selection-action-btn:hover {
        background: #2a2a2a;
        border-color: #404040;
    }

    html.dark .selection-action-btn i {
        color: #a3a3a3;
    }

    html.dark .selection-action-btn:hover i {
        color: #e5e5e5;
    }

    html.dark .message-title {
        color: #737373;
    }

    html.dark .chat-message.user .message-title {
        color: rgba(217, 217, 217, 0.7);
    }

    html.dark .message-time {
        color: #737373;
    }

    html.dark .chat-message.user .message-time {
        color: rgba(217, 217, 217, 0.6);
    }

    html.dark .search-highlight {
        background-color: rgba(184, 134, 11, 0.5) !important;
    }

    html.dark .citation-workspace-vertical {
        background: #0f0f0f;
    }

    html.dark .citation-workspace-vertical .pdf-viewer-card {
        background: #1e1e1e !important;
        border-color: #2a2a2a !important;
        box-shadow: 2px 0 8px 0 rgba(0, 0, 0, 0.3) !important;
    }

    html.dark .pdf-viewer-card > .pdf-toolbar {
        background: #1e1e1e;
    }

    html.dark .chat-section-card {
        background: #1e1e1e !important;
        border-color: #2a2a2a !important;
        box-shadow: -2px 0 8px 0 rgba(0, 0, 0, 0.3) !important;
    }

    html.dark .mobile-top-tabs {
        background: #171717 !important;
        border-bottom-color: #2a2a2a !important;
    }

    html.dark .mobile-top-tab {
        background: #262626 !important;
        color: #a3a3a3 !important;
    }

    html.dark .mobile-top-tab:not(.active):hover {
        background: #333333 !important;
    }

    html.dark .history-docs-table thead {
        border-bottom-color: #2a2a2a;
    }

    html.dark .history-docs-table th {
        color: #a3a3a3;
    }

    html.dark .history-docs-table td {
        border-bottom-color: #262626;
        color: #d4d4d4;
    }

    html.dark .history-docs-table tbody tr:hover {
        background: rgba(255, 255, 255, 0.05);
    }

    html.dark .history-filename-cell {
        color: #e5e5e5;
    }

    html.dark .history-time-cell {
        color: #a3a3a3;
    }

    html.dark .history-view-more {
        color: #a3a3a3;
    }

    html.dark .history-view-more:hover {
        background: #262626;
        color: #e5e5e5;
    }

    html.dark .history-empty {
        color: #525252;
    }

    /* PDF 工具栏 */
    html.dark .pdf-toolbar {
        background: #1e1e1e !important;
        border-bottom-color: #2a2a2a !important;
    }

    html.dark .pdf-page-indicator {
        color: #a3a3a3;
    }

    html.dark .pdf-toolbar-divider {
        background: #404040;
    }

    html.dark .pdf-toolbar select {
        background: #262626 !important;
        border-color: #404040 !important;
        color: #d4d4d4 !important;
    }

    /* PDF 容器 */
    html.dark #pdfContainer {
        background: #171717 !important;
    }

    html.dark .pdf-placeholder-icon {
        color: #525252;
    }

    html.dark .pdf-placeholder-text {
        color: #a3a3a3;
    }

    html.dark .pdf-placeholder-hint {
        color: #525252;
    }

    html.dark .pdf-sample-link {
        color: #a3a3a3;
    }

    html.dark .pdf-history-section {
        border-top-color: #2a2a2a;
    }

    html.dark .pdf-history-title {
        color: #a3a3a3;
    }

    html.dark .history-loading {
        color: #525252;
    }

    /* PDF 搜索框 */
    html.dark #pdfSearchBox {
        background: #1e1e1e !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4) !important;
    }

    html.dark #pdfSearchInput {
        background: #262626 !important;
        border-color: #404040 !important;
        color: #d4d4d4 !important;
    }

    html.dark .pdf-search-results {
        color: #a3a3a3;
    }

    /* 聊天消息区域 */
    html.dark #pdfChatMessages {
        background: #171717 !important;
    }

    html.dark .pdf-chat-welcome-icon-wrapper {
        background: linear-gradient(135deg, rgba(129, 140, 248, 0.15) 0%, rgba(99, 102, 241, 0.08) 100%);
    }

    html.dark .pdf-chat-welcome-title {
        color: #e5e5e5;
    }

    html.dark .pdf-chat-welcome-desc {
        color: #737373;
    }

    html.dark .pdf-chat-feature-card {
        background: #262626;
        border-color: #333333;
        color: #d4d4d4;
    }

    html.dark .pdf-chat-feature-card svg {
        opacity: 0.8;
    }

    /* 聊天输入区域 */
    html.dark .pdf-chat-input-wrapper {
        background: #1e1e1e !important;
        border-top-color: #2a2a2a !important;
    }

    html.dark #pdfChatInput {
        background: #262626 !important;
        border-color: #404040 !important;
        color: #d4d4d4 !important;
    }

    html.dark #pdfChatInput::placeholder {
        color: #525252 !important;
    }

    html.dark .pdf-char-count {
        color: #525252;
    }

    /* 移动端两卡片 dark mode */
    @media (max-width: 768px) {
        html.dark .pdf-viewer-card,
        html.dark .chat-section-card {
            background: #1e1e1e !important;
        }
    }


/* World-class PDF chat answer grounding */
.reference-sources {
    margin-top: 12px;
    padding: 12px;
    border: 1px solid #e5e5e5;
    border-radius: 14px;
    background: #f5f5f5;
}

.sources-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 700;
    color: #171717;
    margin-bottom: 10px;
    letter-spacing: -0.01em;
}

.sources-list {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(240px, 320px);
    gap: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0 2px 4px;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
    scrollbar-color: #d4d4d4 transparent;
}

.sources-list::-webkit-scrollbar {
    height: 6px;
}

.sources-list::-webkit-scrollbar-track {
    background: transparent;
}

.sources-list::-webkit-scrollbar-thumb {
    background: #d4d4d4;
    border-radius: 999px;
}

.source-card {
    width: min(320px, 78vw);
    min-height: 118px;
    display: grid;
    grid-template-columns: auto auto;
    grid-template-rows: auto 1fr;
    column-gap: 8px;
    row-gap: 8px;
    align-items: start;
    align-content: start;
    padding: 12px 13px;
    border: 1px solid #e5e5e5;
    border-radius: 12px;
    background: #ffffff;
    color: #171717;
    text-align: left;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(23, 23, 23, 0.04);
    transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease, background 0.16s ease;
}

.source-card:hover,
.source-card:focus-visible {
    border-color: #a3a3a3;
    background: #fafafa;
    box-shadow: 0 8px 22px rgba(23, 23, 23, 0.08);
    transform: translateY(-1px);
    outline: none;
}

.source-page {
    font-size: 12px;
    font-weight: 800;
    color: #171717;
    white-space: nowrap;
}

.source-score {
    font-size: 11px;
    color: #737373;
    white-space: nowrap;
}

.source-snippet {
    grid-column: 1 / -1;
    max-height: 5.8em;
    overflow: hidden;
    font-size: 12px;
    line-height: 1.45;
    color: #404040;
}

.message-actions,
.suggested-questions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.copy-answer-btn,
.suggested-question-chip {
    border: 1px solid #d4d4d4;
    border-radius: 999px;
    background: #fafafa;
    color: #404040;
    font-size: 12px;
    padding: 6px 10px;
    cursor: pointer;
    transition: border-color 0.16s ease, background 0.16s ease, color 0.16s ease;
}

.copy-answer-btn:hover,
.suggested-question-chip:hover {
    background: #f5f5f5;
    border-color: #a3a3a3;
    color: #171717;
}

html.dark .reference-sources,
body.dark .reference-sources,
html[data-theme="dark"] .reference-sources,
body[data-theme="dark"] .reference-sources {
    background: #171717;
    border-color: #2a2a2a;
}

html.dark .sources-title,
body.dark .sources-title,
html[data-theme="dark"] .sources-title,
body[data-theme="dark"] .sources-title,
html.dark .source-page,
body.dark .source-page,
html[data-theme="dark"] .source-page,
body[data-theme="dark"] .source-page {
    color: #f5f5f5;
}

html.dark .sources-list,
body.dark .sources-list,
html[data-theme="dark"] .sources-list,
body[data-theme="dark"] .sources-list {
    scrollbar-color: #525252 transparent;
}

html.dark .sources-list::-webkit-scrollbar-thumb,
body.dark .sources-list::-webkit-scrollbar-thumb,
html[data-theme="dark"] .sources-list::-webkit-scrollbar-thumb,
body[data-theme="dark"] .sources-list::-webkit-scrollbar-thumb {
    background: #525252;
}

html.dark .source-card,
body.dark .source-card,
html[data-theme="dark"] .source-card,
body[data-theme="dark"] .source-card {
    background: #1e1e1e;
    border-color: #333333;
    color: #e5e5e5;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
}

html.dark .source-card:hover,
html.dark .source-card:focus-visible,
body.dark .source-card:hover,
body.dark .source-card:focus-visible,
html[data-theme="dark"] .source-card:hover,
html[data-theme="dark"] .source-card:focus-visible,
body[data-theme="dark"] .source-card:hover,
body[data-theme="dark"] .source-card:focus-visible {
    background: #262626;
    border-color: #525252;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.24);
}

html.dark .source-score,
body.dark .source-score,
html[data-theme="dark"] .source-score,
body[data-theme="dark"] .source-score {
    color: #a3a3a3;
}

html.dark .source-snippet,
body.dark .source-snippet,
html[data-theme="dark"] .source-snippet,
body[data-theme="dark"] .source-snippet {
    color: #d4d4d4;
}

html.dark .copy-answer-btn,
html.dark .suggested-question-chip,
body.dark .copy-answer-btn,
body.dark .suggested-question-chip,
html[data-theme="dark"] .copy-answer-btn,
html[data-theme="dark"] .suggested-question-chip,
body[data-theme="dark"] .copy-answer-btn,
body[data-theme="dark"] .suggested-question-chip {
    background: #262626;
    border-color: #404040;
    color: #d4d4d4;
}

html.dark .copy-answer-btn:hover,
html.dark .suggested-question-chip:hover,
body.dark .copy-answer-btn:hover,
body.dark .suggested-question-chip:hover,
html[data-theme="dark"] .copy-answer-btn:hover,
html[data-theme="dark"] .suggested-question-chip:hover,
body[data-theme="dark"] .copy-answer-btn:hover,
body[data-theme="dark"] .suggested-question-chip:hover {
    background: #333333;
    border-color: #737373;
    color: #f5f5f5;
}

/* Scope-limited controls: retain the existing viewer/chat layout. */
#chatpdfTools { display:flex; flex-wrap:wrap; gap:6px; width:100%; margin:6px 0; font-size:12px; align-items:center; }
#chatpdfTools [hidden] { display:none !important; }
#chatpdfTools button, #chatpdfTools select, #chatpdfTools input, #chatpdfTools textarea { color:inherit; background:var(--bg-secondary, #f5f5f5); border:1px solid var(--border-color, #aaa); border-radius:6px; padding:5px 7px; max-width:100%; font:inherit; }
#chatpdfTools button, #chatpdfTools summary { cursor:pointer; }
#chatpdfTools input[type=number] { width:76px; }
#chatpdfTools details { max-width:100%; }
#chatpdfNotebook { flex-basis:100%; }
#chatpdfNotebook textarea { display:block; width:100%; margin:6px 0; min-height:44px; }
#chatpdfEvidenceList { max-height:280px; overflow:auto; overflow-wrap:anywhere; }
#chatpdfEvidenceList article { padding:8px 0; border-top:1px solid var(--border-color, #aaa); }
#chatpdfEvidenceList blockquote { white-space:pre-wrap; margin:6px 0; }
.chatpdf-related-list { max-height:180px; overflow:auto; }
.chatpdf-related-list label { display:block; overflow-wrap:anywhere; }
.textLayer.search-active { opacity:1 !important; }
.textLayer.search-active span, .textLayer .search-highlight { color:transparent !important; }
.textLayer .search-highlight { background:rgba(255, 210, 0, .55) !important; padding:0; }
html.dark #chatpdfTools, body.dark #chatpdfTools, html[data-theme=dark] #chatpdfTools { --bg-secondary:#262626; --border-color:#737373; color:#eee; }
/* This route's toolbar replaces only the floating launcher, not the widget. */
body.chatpdf-support-toolbar #cw-bubble-holder .woot-widget-bubble:not(.woot--close) { display:none !important; }
body.chatpdf-support-toolbar .pdf-quick-actions-bar { overflow-x:auto; }
@media(max-width:767px) { #chatpdfTools button, #chatpdfTools select, #chatpdfTools summary { min-height:36px; } #chatpdfTools { gap:4px; } }
