/**
 * 飞创学术 RAG 智能客服样式
 */

/* ========================================
   聊天按钮
   ======================================== */
.rag-chat-fab {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9998;
    transition: all 0.3s ease;
    overflow: visible;
}

.rag-chat-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 28px rgba(0,0,0,0.25);
}

.rag-chat-fab-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}
.rag-chat-fab-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 50%;
}

.rag-chat-fab-label {
    position: absolute;
    bottom: calc(100% + 16px);
    left: 50%;
    transform: translateX(-50%);
    background: #ffffff;
    color: #334155;
    font-size: 14px;
    font-weight: 500;
    padding: 10px 18px;
    border-radius: 20px;
    white-space: nowrap;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.15);
    pointer-events: none;
    z-index: 1;
    border: 1px solid #e2e8f0;
    animation: fabLabelFloat 3s ease-in-out infinite;
}

.rag-chat-fab-label::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid #ffffff;
    filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.08));
}

@keyframes fabLabelFloat {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(-6px); }
}

/* ========================================
   聊天窗口
   ======================================== */
.rag-chat-window {
    position: fixed;
    bottom: 100px;
    right: 30px;
    width: 380px;
    height: 550px;
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
}

.rag-chat-window.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* ========================================
   聊天头部
   ======================================== */
.rag-chat-header {
    background: linear-gradient(135deg, #059669, #10b981);
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.rag-chat-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 16px;
}

.rag-chat-title i {
    font-size: 20px;
}
.rag-chat-title img {
    width: 28px; height: 28px;
    object-fit: contain;
    border-radius: 50%;
}

.rag-chat-actions {
    display: flex;
    gap: 8px;
}

.rag-chat-actions button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.rag-chat-actions button:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ========================================
   消息区域
   ======================================== */
.rag-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f8fafc;
}

/* 滚动条样式 */
.rag-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.rag-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.rag-chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.rag-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* ========================================
   消息样式
   ======================================== */
.rag-message {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    animation: messageSlideIn 0.3s ease;
}

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

.rag-message-user {
    flex-direction: row-reverse;
}

.rag-message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}
.rag-message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.rag-message-avatar-user {
    background: linear-gradient(135deg, #3b82f6, #60a5fa);
}

.rag-message-content {
    max-width: 280px;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
}

.rag-message-bot .rag-message-content {
    background: white;
    color: #334155;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.rag-message-user .rag-message-content {
    background: linear-gradient(135deg, #059669, #10b981);
    color: white;
}

.rag-message-error .rag-message-content {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

/* 欢迎消息特殊样式 */
.rag-message-welcome .rag-message-content {
    background: linear-gradient(135deg, #f0fdf4, #ffffff);
    border: 1px solid #bbf7d0;
}

.rag-message-welcome ul {
    margin: 12px 0;
    padding-left: 0;
    list-style: none;
}

.rag-message-welcome li {
    padding: 6px 0;
    padding-left: 8px;
    position: relative;
}

/* 打字状态 */
.rag-message-typing .rag-message-content {
    background: #f1f5f9;
    padding: 16px 20px;
}

.rag-typing-dots {
    display: flex;
    gap: 4px;
}

.rag-typing-dots span {
    width: 8px;
    height: 8px;
    background: #94a3b8;
    border-radius: 50%;
    animation: typingDot 1.4s infinite;
}

.rag-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.rag-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.6; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ========================================
   热门问题
   ======================================== */
.rag-hot-questions {
    margin-top: 16px;
    padding: 16px;
    background: white;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
}

.rag-hot-questions-title {
    font-size: 13px;
    color: #64748b;
    margin-bottom: 12px;
    font-weight: 500;
}

.rag-hot-question {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px 14px;
    margin-bottom: 8px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    font-size: 13px;
    color: #334155;
    cursor: pointer;
    transition: all 0.2s;
}

.rag-hot-question:hover {
    background: #f0fdf4;
    border-color: #86efac;
    color: #059669;
}

.rag-hot-question:last-child {
    margin-bottom: 0;
}

/* ========================================
   来源卡片
   ======================================== */
.rag-sources {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #e2e8f0;
}

.rag-sources-title {
    font-size: 13px;
    color: #64748b;
    margin-bottom: 10px;
    font-weight: 500;
}

.rag-source-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: #f8fafc;
    border-radius: 10px;
    margin-bottom: 8px;
    text-decoration: none;
    color: inherit;
    transition: all 0.2s;
    cursor: pointer;
}

.rag-source-card:hover {
    background: #f0fdf4;
    transform: translateX(4px);
}

.rag-source-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.rag-source-info {
    flex: 1;
    min-width: 0;
}

.rag-source-title {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: #334155;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rag-source-category {
    display: block;
    font-size: 11px;
    color: #64748b;
}

.rag-source-arrow {
    color: #94a3b8;
    font-size: 12px;
    flex-shrink: 0;
}

/* 消息中的链接 */
.rag-message-content a {
    color: #059669;
    text-decoration: none;
    font-weight: 500;
}

.rag-message-content a:hover {
    text-decoration: underline;
}

/* ========================================
   输入区域
   ======================================== */
.rag-chat-input-area {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid #e2e8f0;
}

.rag-chat-input-wrapper {
    display: flex;
    gap: 10px;
    background: #f8fafc;
    border-radius: 12px;
    padding: 4px;
    border: 1px solid #e2e8f0;
}

.rag-chat-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 12px 16px;
    font-size: 14px;
    outline: none;
    color: #334155;
}

.rag-chat-input::placeholder {
    color: #94a3b8;
}

.rag-chat-send {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #059669, #10b981);
    border: none;
    border-radius: 10px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.rag-chat-send:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.rag-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.rag-chat-footer {
    text-align: center;
    margin-top: 8px;
    font-size: 11px;
    color: #94a3b8;
}

/* ========================================
   响应式
   ======================================== */
@media (max-width: 480px) {
    .rag-chat-window {
        width: 100%;
        height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }

    .rag-chat-fab {
        bottom: 20px;
        right: 20px;
        width: 54px;
        height: 54px;
    }

    .rag-chat-fab-icon {
        font-size: 24px;
    }

    .rag-message-content {
        max-width: 240px;
    }
}

/* ========================================
   动画
   ======================================== */
@keyframes ragPulse {
    0%, 100% {
        box-shadow: 0 4px 20px rgba(16, 185, 129, 0.4);
    }
    50% {
        box-shadow: 0 4px 30px rgba(16, 185, 129, 0.6);
    }
}

.rag-chat-fab.new-message {
    animation: ragPulse 1.5s infinite;
}

/* 旧版客服隐藏（如果存在） */
#chatFab,
#chatModal,
#chatFabHint {
    display: none !important;
}
