/* ========================================
   AI CHAT WIDGET - 微奇小助
   ======================================== */

.chat-widget {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 9999;
    font-family: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* 悬浮按钮 */
.chat-fab {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary, #4facfe), var(--accent, #00f2fe));
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    box-shadow: 0 8px 30px rgba(79, 172, 254, 0.35), 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: visible;
}

.chat-fab:hover {
    transform: scale(1.08) translateY(-2px);
    box-shadow: 0 12px 40px rgba(79, 172, 254, 0.5), 0 6px 16px rgba(0, 0, 0, 0.2);
}

.chat-fab::before {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    background: inherit;
    opacity: 0.3;
    z-index: -1;
    animation: chatPulse 2.5s ease-in-out infinite;
}

@keyframes chatPulse {
    0%, 100% { transform: scale(1); opacity: 0.3; }
    50% { transform: scale(1.2); opacity: 0; }
}

.chat-fab-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 3px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
    border: 2px solid #0a0e1a;
    line-height: 1;
}

/* 聊天面板 */
.chat-panel {
    position: absolute;
    right: 0;
    bottom: 76px;
    width: 380px;
    max-width: calc(100vw - 48px);
    height: 560px;
    max-height: calc(100vh - 120px);
    background: var(--bg-card, #111827);
    border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
    border-radius: 20px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
    display: none;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    animation: chatSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-panel.open {
    display: flex;
}

@keyframes chatSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* 头部 */
.chat-header {
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--primary, #4facfe), var(--accent, #00f2fe));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    position: relative;
}

.chat-avatar::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 10px;
    height: 10px;
    background: #10b981;
    border-radius: 50%;
    border: 2px solid #fff;
}

.chat-title {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.2;
}

.chat-subtitle {
    font-size: 11px;
    opacity: 0.85;
    margin-top: 2px;
}

.chat-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: background 0.2s;
}

.chat-close:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* 消息区 */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--bg-dark, #0a0e1a);
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}
.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}
.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

.chat-message {
    display: flex;
    gap: 8px;
    max-width: 85%;
    animation: msgFadeIn 0.3s ease;
}

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

.chat-message.user {
    flex-direction: row-reverse;
    margin-left: auto;
}

.chat-message .msg-avatar {
    width: 28px;
    height: 28px;
    min-width: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: #fff;
}

.chat-message.bot .msg-avatar {
    background: linear-gradient(135deg, var(--primary, #4facfe), var(--accent, #00f2fe));
}

.chat-message.user .msg-avatar {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-secondary, #94a3b8);
}

.msg-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.65;
    color: var(--text-primary, #f1f5f9);
    word-wrap: break-word;
    word-break: break-word;
}

.chat-message.bot .msg-bubble {
    background: var(--bg-card, #111827);
    border: 1px solid var(--border, rgba(255, 255, 255, 0.06));
    border-top-left-radius: 4px;
}

.chat-message.user .msg-bubble {
    background: linear-gradient(135deg, var(--primary, #4facfe), var(--accent, #00f2fe));
    color: #fff;
    border-top-right-radius: 4px;
}

.msg-bubble strong { font-weight: 700; }
.msg-bubble em { font-style: italic; }
.msg-bubble code {
    background: rgba(255, 255, 255, 0.08);
    padding: 1px 6px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 13px;
}
.msg-bubble ul, .msg-bubble ol {
    margin: 6px 0;
    padding-left: 22px;
}
.msg-bubble li { padding: 2px 0; }
.msg-bubble p { margin: 0; }
.msg-bubble p + p { margin-top: 6px; }
.msg-bubble a {
    color: var(--accent, #00f2fe);
    text-decoration: underline;
}

.chat-message.user .msg-bubble a {
    color: #fff;
}

/* 欢迎消息 */
.chat-welcome {
    text-align: center;
    padding: 20px 12px;
    color: var(--text-secondary, #94a3b8);
}

.chat-welcome h4 {
    font-size: 15px;
    color: var(--text-primary, #f1f5f9);
    margin-bottom: 8px;
    font-weight: 700;
}

.chat-welcome p {
    font-size: 13px;
    line-height: 1.6;
    margin-bottom: 16px;
}

.chat-suggestions {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chat-suggestion {
    padding: 9px 14px;
    background: var(--bg-card, #111827);
    border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
    border-radius: 10px;
    color: var(--text-secondary, #94a3b8);
    font-size: 13px;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.chat-suggestion:hover {
    border-color: var(--primary, #4facfe);
    color: var(--text-primary, #f1f5f9);
    background: rgba(79, 172, 254, 0.06);
}

.chat-suggestion i {
    color: var(--primary, #4facfe);
    margin-right: 8px;
    font-size: 11px;
}

/* 加载动画 */
.chat-typing {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
    align-items: center;
}

.chat-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted, #64748b);
    animation: typingBounce 1.4s infinite ease-in-out;
}

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

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

/* 输入区 */
.chat-input-wrap {
    padding: 12px 14px;
    border-top: 1px solid var(--border, rgba(255, 255, 255, 0.06));
    background: var(--bg-card, #111827);
    flex-shrink: 0;
}

.chat-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    min-height: 40px;
    max-height: 120px;
    padding: 10px 14px;
    background: var(--bg-dark, #0a0e1a);
    border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
    border-radius: 20px;
    color: var(--text-primary, #f1f5f9);
    font-size: 14px;
    line-height: 1.5;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
}

.chat-input:focus {
    border-color: var(--primary, #4facfe);
}

.chat-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--primary, #4facfe), var(--accent, #00f2fe));
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.chat-send:hover:not(:disabled) {
    transform: scale(1.05);
}

.chat-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.chat-footer {
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-muted, #64748b);
    text-align: center;
}

/* Light mode 适配 */
[data-theme="light"] .chat-panel {
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.15);
}

[data-theme="light"] .chat-message.bot .msg-bubble {
    background: #fff;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

[data-theme="light"] .chat-input {
    background: #fff;
}

[data-theme="light"] .msg-bubble code {
    background: rgba(15, 23, 42, 0.06);
}

[data-theme="light"] .chat-fab-badge {
    border-color: #f8fafc;
}

/* 移动端 */
@media (max-width: 640px) {
    .chat-widget {
        right: 16px;
        bottom: 16px;
    }
    .chat-panel {
        width: calc(100vw - 32px);
        height: calc(100vh - 100px);
        bottom: 74px;
    }
    .chat-fab {
        width: 54px;
        height: 54px;
        font-size: 20px;
    }
}

/* back-to-top 与聊天按钮堆叠时的位置调整 */
@media (max-width: 640px) {
    .back-to-top {
        bottom: 86px !important;
        right: 20px !important;
    }
}
