/* ==================== 容器 ==================== */
#ai-search-container {
    max-width: 900px;
    margin: 20px auto;
    font-family: 'Noto Serif SC', 'SimSun', serif;
}

/* ==================== 搜索栏 ==================== */
.ai-search-box {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

#ai-search-input {
    flex: 1;
    padding: 12px 18px;
    font-size: 16px;
    border: 2px solid #8c0000;
    border-radius: 30px;
    outline: none;
    transition: box-shadow 0.3s;
}

#ai-search-input:focus {
    box-shadow: 0 0 0 4px rgba(140, 0, 0, 0.1);
}

#ai-search-btn {
    padding: 12px 28px;
    background: linear-gradient(135deg, #8c0000, #6d0000);
    color: white;
    border: none;
    border-radius: 30px;
    font-size: 16px;
    cursor: pointer;
    font-weight: 600;
    letter-spacing: 1px;
    transition: all 0.2s;
}

#ai-search-btn:hover {
    background: linear-gradient(135deg, #a01010, #8c0000);
    transform: translateY(-1px);
}

/* ==================== 加载状态 ==================== */
#ai-search-loading {
    text-align: center;
    padding: 40px;
    color: #8c0000;
}

.ai-loading-spinner {
    width: 40px;
    height: 40px;
    margin: 0 auto 15px;
    border: 4px solid #f0e0e0;
    border-top-color: #8c0000;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ==================== AI综述 ==================== */
#ai-answer-area {
    background: #fdfbf9;
    border: 1px solid rgba(140, 0, 0, 0.15);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
}

.ai-answer-header {
    font-weight: 700;
    color: #8c0000;
    font-size: 18px;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid rgba(140, 0, 0, 0.2);
}

.ai-answer-body {
    max-height: 60vh;
    overflow-y: auto;
}

/* ==================== 脚标 ==================== */
.ai-footnote {
    color: #8c0000;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    padding: 0 2px;
    transition: all 0.2s;
}

.ai-footnote:hover {
    background: rgba(140, 0, 0, 0.15);
    border-radius: 3px;
}

/* ==================== 来源卡片 ==================== */
#ai-sources-area {
    margin-top: 20px;
}

.ai-sources-header {
    font-weight: 700;
    color: #8c0000;
    font-size: 18px;
    margin-bottom: 15px;
}

.ai-source-card {
    display: flex;
    gap: 15px;
    padding: 15px;
    margin-bottom: 10px;
    background: white;
    border: 1px solid rgba(140, 0, 0, 0.1);
    border-radius: 10px;
    transition: all 0.3s;
}

.ai-source-card:hover {
    box-shadow: 0 4px 16px rgba(140, 0, 0, 0.1);
}

.ai-source-card.ai-highlight {
    border-color: #8c0000;
    box-shadow: 0 0 0 4px rgba(140, 0, 0, 0.2);
}

.ai-source-index {
    font-weight: 700;
    color: #8c0000;
    font-size: 18px;
    min-width: 30px;
}

.ai-source-thumb {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
}

.ai-source-info {
    flex: 1;
}

.ai-source-info h4 {
    margin: 0 0 5px;
}

.ai-source-info h4 a {
    color: #3a2a1a;
    text-decoration: none;
}

.ai-source-info h4 a:hover {
    color: #8c0000;
}

.ai-source-author,
.ai-source-time {
    font-size: 12px;
    color: #8b7355;
    margin-right: 10px;
}

.ai-source-info p {
    margin: 8px 0 0;
    font-size: 13px;
    color: #6b5b4e;
    line-height: 1.6;
}




/* ==================== 脚标悬浮提示 ==================== */
.ai-footnote-tooltip {
    background: #fffef9;
    border: 2px solid #8c0000;
    border-radius: 10px;
    padding: 14px;
    box-shadow: 0 8px 24px rgba(140, 0, 0, 0.2);
    pointer-events: none;
    animation: tooltipFadeIn 0.2s ease;
}

@keyframes tooltipFadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

.tooltip-header {
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(140, 0, 0, 0.15);
}

.tooltip-header strong {
    color: #8c0000;
    font-size: 14px;
    display: block;
}

.tooltip-author {
    font-size: 12px;
    color: #8b7355;
}

.tooltip-body {
    font-size: 13px;
    color: #3a2a1a;
    line-height: 1.6;
}

/* ==================== 匹配文本高亮 ==================== */
.ai-matched-text {
    background: #ffeb3b;
    padding: 1px 3px;
    border-radius: 2px;
    font-weight: 600;
}

/* ==================== 复制按钮 ==================== */
.ai-copy-btn {
    float: right;
    background: linear-gradient(135deg, #8c0000, #6d0000);
    color: white;
    border: none;
    border-radius: 20px;
    padding: 6px 16px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.ai-copy-btn:hover {
    background: linear-gradient(135deg, #a01010, #8c0000);
    transform: translateY(-1px);
}



/* ==================== 流式输出中的不完整标签隐藏 ==================== */
#ai-answer-content sup:not([data-id]) {
    display: none;
}




/* ==================== 多轮对话按钮 ==================== */
.ai-chat-btn {
    float: right;
    background: linear-gradient(135deg, #2a5298, #1e3c72);
    color: white;
    border: none;
    border-radius: 20px;
    padding: 6px 16px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    margin-right: 8px;
}

.ai-chat-btn:hover {
    background: linear-gradient(135deg, #3568b0, #2a5298);
    transform: translateY(-1px);
}

/* ==================== 弹窗遮罩 ==================== */
#ai-chat-modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 10001;
    backdrop-filter: blur(4px);
}

/* ==================== 弹窗主体 ==================== */
#ai-chat-modal {
    position: absolute;
    top: 5%;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 800px;
    height: 85vh;
    background: #fdfbf9;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ==================== 弹窗头部 ==================== */
.ai-chat-header {
    padding: 16px 20px;
    background: linear-gradient(135deg, #2a5298, #1e3c72);
    color: white;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.ai-chat-header h3 {
    margin: 0;
    font-size: 18px;
    white-space: nowrap;
}

.ai-chat-query-info {
    flex: 1;
    font-size: 13px;
    opacity: 0.9;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-style: italic;
}

.ai-chat-close {
    background: none;
    border: none;
    color: white;
    font-size: 28px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.ai-chat-close:hover {
    opacity: 1;
}

/* ==================== 消息区域 ==================== */
#ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #fdfbf9;
}

#ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

#ai-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

#ai-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(140, 0, 0, 0.2);
    border-radius: 3px;
}

/* ==================== 聊天加载 ==================== */
#ai-chat-loading {
    text-align: center;
    padding: 20px;
    color: #2a5298;
    flex-shrink: 0;
}

/* ==================== 消息气泡 ==================== */
.ai-chat-message {
    margin-bottom: 16px;
    animation: chatSlideIn 0.3s ease;
}

@keyframes chatSlideIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.ai-chat-role {
    font-weight: 700;
    font-size: 13px;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-chat-user .ai-chat-role {
    color: #2a5298;
}

.ai-chat-assistant .ai-chat-role {
    color: #8c0000;
}

.ai-chat-text {
    padding: 14px 18px;
    border-radius: 12px;
    line-height: 1.8;
    font-size: 15px;
}

.ai-chat-user .ai-chat-text {
    background: #e8f0fe;
    color: #1a1a2e;
}

.ai-chat-assistant .ai-chat-text {
    background: #fffef9;
    border: 1px solid rgba(140, 0, 0, 0.12);
    color: #3a2a1a;
}

/* ==================== 聊天复制按钮 ==================== */
.ai-chat-copy-btn {
    background: rgba(140, 0, 0, 0.1);
    color: #8c0000;
    border: 1px solid rgba(140, 0, 0, 0.2);
    border-radius: 12px;
    padding: 2px 12px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
    margin-left: auto;
}

.ai-chat-copy-btn:hover {
    background: rgba(140, 0, 0, 0.2);
}

/* ==================== 输入区域 ==================== */
.ai-chat-input-area {
    padding: 14px 20px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    background: white;
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

#ai-chat-input {
    flex: 1;
    padding: 12px 16px;
    font-size: 15px;
    border: 2px solid #2a5298;
    border-radius: 24px;
    outline: none;
    resize: none;
    font-family: 'Noto Serif SC', 'SimSun', serif;
    transition: box-shadow 0.3s;
}

#ai-chat-input:focus {
    box-shadow: 0 0 0 4px rgba(42, 82, 152, 0.1);
}

#ai-chat-send {
    padding: 12px 24px;
    background: linear-gradient(135deg, #2a5298, #1e3c72);
    color: white;
    border: none;
    border-radius: 24px;
    font-size: 15px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
    white-space: nowrap;
}

#ai-chat-send:hover {
    background: linear-gradient(135deg, #3568b0, #2a5298);
    transform: translateY(-1px);
}

#ai-chat-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* ==================== 弹窗响应式 ==================== */
@media (max-width: 768px) {
    #ai-chat-modal {
        width: 96%;
        top: 3%;
        height: 92vh;
        border-radius: 12px;
    }
    
    .ai-chat-header {
        padding: 12px 14px;
    }
    
    .ai-chat-header h3 {
        font-size: 16px;
    }
    
    #ai-chat-messages {
        padding: 12px;
    }
    
    .ai-chat-input-area {
        padding: 10px 14px;
        gap: 8px;
    }
    
    #ai-chat-input {
        padding: 10px 14px;
        font-size: 14px;
    }
    
    #ai-chat-send {
        padding: 10px 18px;
        font-size: 14px;
    }
}



/* ⭐ 防止不完整 HTML 标签暴露给用户 */
#ai-answer-content sup:empty,
#ai-chat-messages sup:empty {
    display: none;
}

#ai-answer-content sup:not([data-id]):not([data-article]),
#ai-chat-messages sup:not([data-id]):not([data-article]) {
    display: none;
}

/* 在流式输出中隐藏可能出现的原始标签文本 */
#ai-answer-content:empty::after,
#ai-chat-messages .ai-chat-answer:empty::after {
    content: '';
}
