/* SunBlog AI 知识库 - 前端聊天界面 */

.sunblog-chat-fab {
    position: fixed;
    left: 24px;
    bottom: 24px;
    width: 56px;
    height: 56px;
    border-radius: 28px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 22px;
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
    z-index: 99998;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    display: flex;
    align-items: center;
    justify-content: center;
}
.sunblog-chat-fab:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 8px 28px rgba(102, 126, 234, 0.55);
}
.sunblog-chat-fab-text {
    position: absolute;
    left: 68px;
    top: 50%;
    transform: translateY(-50%);
    background: #fff;
    color: #353b48;
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 13px;
    white-space: nowrap;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}
.sunblog-chat-fab:hover .sunblog-chat-fab-text {
    opacity: 1;
}

/* Chat Window */
.sunblog-chat-window {
    position: fixed;
    left: 24px;
    bottom: 24px;
    width: 380px;
    height: 560px;
    max-height: calc(100vh - 48px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.2);
    z-index: 99999;
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: sunblog-slide-up 0.3s ease-out;
}
@keyframes sunblog-slide-up {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}
.sunblog-chat-window.open { display: flex; }

.sunblog-chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.sunblog-chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 18px;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}
.sunblog-chat-title { font-size: 14px; font-weight: 600; }
.sunblog-chat-subtitle { font-size: 11px; opacity: 0.85; margin-top: 2px; }

.sunblog-chat-close {
    width: 28px;
    height: 28px;
    border-radius: 14px;
    background: rgba(255,255,255,0.15);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}
.sunblog-chat-close:hover { background: rgba(255,255,255,0.3); }

.sunblog-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f8f9fc;
}
.sunblog-chat-messages::-webkit-scrollbar { width: 6px; }
.sunblog-chat-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }

.sunblog-msg {
    display: flex;
    margin-bottom: 12px;
    align-items: flex-start;
    gap: 8px;
}
.sunblog-msg.user { flex-direction: row-reverse; }
.sunblog-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 14px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}
.sunblog-msg.bot .sunblog-msg-avatar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
}
.sunblog-msg.user .sunblog-msg-avatar {
    background: #fff;
    border: 1px solid #e1e7ed;
    color: #7f8fa6;
}
.sunblog-msg-bubble {
    max-width: 78%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.6;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.sunblog-msg.bot .sunblog-msg-bubble {
    background: #fff;
    color: #2f3640;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.sunblog-msg.user .sunblog-msg-bubble {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.sunblog-msg-bubble a { color: #667eea; text-decoration: underline; }
.sunblog-msg.user .sunblog-msg-bubble a { color: #fff; }
.sunblog-msg-bubble code {
    background: rgba(102, 126, 234, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: Consolas, monospace;
    font-size: 12px;
    color: #667eea;
}
.sunblog-msg.user .sunblog-msg-bubble code { background: rgba(255,255,255,0.2); color: #fff; }

.sunblog-msg-meta {
    font-size: 10px;
    color: #999;
    margin-top: 4px;
    text-align: right;
}
.sunblog-msg.bot .sunblog-msg-meta { text-align: left; }

.sunblog-source-box {
    margin-top: 8px;
    padding: 8px 10px;
    background: #f0f4ff;
    border-radius: 6px;
    font-size: 11px;
    color: #5a6a8a;
    border-left: 2px solid #667eea;
}
.sunblog-source-box .label { font-weight: 600; margin-bottom: 4px; color: #667eea; }
.sunblog-source-box a { color: #667eea; display: block; margin-bottom: 2px; text-decoration: none; }
.sunblog-source-box a:hover { text-decoration: underline; }

/* Typing indicator */
.sunblog-typing {
    display: inline-flex;
    gap: 4px;
    padding: 8px 0;
}
.sunblog-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #667eea;
    opacity: 0.4;
    animation: sunblog-bounce 1.2s infinite;
}
.sunblog-typing span:nth-child(2) { animation-delay: 0.2s; }
.sunblog-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes sunblog-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* Input area */
.sunblog-chat-input-wrap {
    padding: 12px;
    background: #fff;
    border-top: 1px solid #eef0f4;
}
.sunblog-chat-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.sunblog-chat-input {
    flex: 1;
    min-height: 36px;
    max-height: 120px;
    padding: 8px 12px;
    border: 1px solid #e1e7ed;
    border-radius: 18px;
    font-size: 13px;
    resize: none;
    outline: none;
    font-family: inherit;
    line-height: 1.5;
}
.sunblog-chat-input:focus { border-color: #667eea; }
.sunblog-chat-send {
    width: 36px;
    height: 36px;
    border-radius: 18px;
    border: none;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    flex-shrink: 0;
    transition: transform 0.2s;
}
.sunblog-chat-send:hover { transform: scale(1.08); }
.sunblog-chat-send:disabled { opacity: 0.5; cursor: not-allowed; }
.sunblog-chat-footer-hint {
    text-align: center;
    font-size: 10px;
    color: #9aa5b5;
    margin-top: 6px;
}

/* Quick questions */
.sunblog-quick-q {
    padding: 12px 16px 0;
    background: #f8f9fc;
    border-top: 1px solid #eef0f4;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.sunblog-quick-q-title {
    width: 100%;
    font-size: 11px;
    color: #7f8fa6;
    margin-bottom: 4px;
}
.sunblog-quick-q button {
    padding: 5px 12px;
    background: #fff;
    border: 1px solid #dcdde1;
    border-radius: 14px;
    font-size: 11px;
    color: #5a6a8a;
    cursor: pointer;
    transition: all 0.2s;
}
.sunblog-quick-q button:hover {
    border-color: #667eea;
    color: #667eea;
}

/* Responsive */
@media (max-width: 480px) {
    .sunblog-chat-window {
        left: 0;
        bottom: 0;
        width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }
    .sunblog-chat-fab { left: 16px; bottom: 16px; }
}

/* Dark mode support */
body.dark-mode .sunblog-chat-window { background: #1f2330; }
body.dark-mode .sunblog-chat-messages { background: #1a1d28; }
body.dark-mode .sunblog-msg.bot .sunblog-msg-bubble { background: #2a2f3e; color: #e8ebf0; box-shadow: none; }
body.dark-mode .sunblog-chat-input-wrap { background: #1f2330; border-top-color: #2a2f3e; }
body.dark-mode .sunblog-chat-input { background: #2a2f3e; border-color: #3a3f4e; color: #e8ebf0; }
body.dark-mode .sunblog-quick-q { background: #1a1d28; border-top-color: #2a2f3e; }
body.dark-mode .sunblog-quick-q button { background: #2a2f3e; border-color: #3a3f4e; color: #aab5c5; }
body.dark-mode .sunblog-source-box { background: #2a2f3e; color: #aab5c5; }
