/* ==============================================
   AI 浮窗 + 返回顶部（可迁移区块）
   ============================================== */
#ai-float-widget {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    pointer-events: none;
}
#ai-float-widget > * { pointer-events: auto; }

/* ---------- 返回顶部 ---------- */
.ai-float-backtop {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.92);
    color: #333;
    cursor: pointer;
    box-shadow: 0 2px 12px rgba(0,0,0,0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    pointer-events: none;
    padding: 0;
}
.ai-float-backtop.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}
.ai-float-backtop:hover {
    background: var(--red, #c91f1f);
    color: #fff;
    box-shadow: 0 4px 16px rgba(201,31,31,0.3);
}

/* ---------- 浮窗切换按钮 ---------- */
.ai-float-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #c91f1f 0%, #a01818 100%);
    color: #fff;
    font-size: 26px;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(201,31,31,0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: all 0.3s ease;
    z-index: 10;
}
.ai-float-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(201,31,31,0.45);
}
.ai-float-toggle.active {
    opacity: 0;
    transform: scale(0.5);
    pointer-events: none;
}
/* 面板打开时，返回顶部也隐藏 */
.ai-float-toggle.active ~ .ai-float-backtop {
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
}
.ai-float-toggle-icon { position: relative; z-index: 1; line-height: 1; }
.ai-float-toggle-pulse {
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid rgba(201,31,31,0.4);
    animation: aiFloatPulse 2s ease-out infinite;
}
.ai-float-toggle.active .ai-float-toggle-pulse { animation: none; opacity: 0; }
@keyframes aiFloatPulse {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(1.5); opacity: 0; }
}

/* ---------- 浮窗面板 ---------- */
.ai-float-chat {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 400px;
    height: 520px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.95);
    pointer-events: auto;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 5;
}

/* 粒子背景画布 */
.ai-particle-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none; /* 改为none，滚轮事件由父容器统一处理 */
}
.ai-float-chat.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* 浮窗头部 */
.ai-float-header {
    background: linear-gradient(135deg, #c91f1f 0%, #a01818 100%);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
    pointer-events: auto;
}
.ai-float-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}
.ai-float-avatar {
    width: 32px;
    height: 32px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}
.ai-float-title {
    font-size: 15px;
    font-weight: 600;
}
.ai-float-header-right {
    display: flex;
    gap: 6px;
}
.ai-float-newchat, .ai-float-close {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.15);
    color: #fff;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.ai-float-newchat:hover, .ai-float-close:hover {
    background: rgba(255,255,255,0.3);
}

/* 浮窗消息区 */
.ai-float-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: rgba(249, 250, 251, 0.85);
    scroll-behavior: smooth;
    position: relative;
    z-index: 1;
    pointer-events: auto;
}
.ai-float-messages::-webkit-scrollbar { width: 4px; }
.ai-float-messages::-webkit-scrollbar-track { background: transparent; }
.ai-float-messages::-webkit-scrollbar-thumb { background: #ddd; border-radius: 2px; }

/* 消息 */
.ai-float-msg {
    display: flex;
    margin-bottom: 14px;
    animation: aiFloatFadeIn 0.3s ease;
}
@keyframes aiFloatFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.ai-float-msg-user { justify-content: flex-end; }
.ai-float-msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #fcdce3;
    border: 2px solid #f5576c;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}
.ai-float-msg-content {
    max-width: 78%;
    margin-left: 8px;
}
.ai-float-msg-user .ai-float-msg-content {
    margin-right: 8px;
    margin-left: 0;
}
.ai-float-msg-text {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.6;
    word-wrap: break-word;
}
.ai-float-msg-ai .ai-float-msg-text {
    background: #fff;
    color: #333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
.ai-float-msg-user .ai-float-msg-text {
    background: linear-gradient(135deg, #c91f1f, #a01818);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* 浮窗输入区 */
.ai-float-input-area {
    background: rgba(255, 255, 255, 0.9);
    padding: 14px 16px 12px;
    border-top: 1px solid #eee;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
    pointer-events: auto;
}
.ai-float-input-wrap {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}
.ai-float-input {
    flex: 1;
    padding: 10px 16px;
    border: 1.5px solid #e5e7eb;
    border-radius: 20px;
    font-size: 13px;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 80px;
    transition: border-color 0.2s;
    line-height: 1.5;
}
.ai-float-input:focus { border-color: #c91f1f; box-shadow: 0 0 0 2px rgba(201,31,31,0.08); }
.ai-float-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #c91f1f, #a01818);
    color: #fff;
    font-size: 17px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 8px rgba(201,31,31,0.25);
}
.ai-float-send:hover { transform: scale(1.08); box-shadow: 0 4px 14px rgba(201,31,31,0.35); }
.ai-float-send:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.ai-float-tips {
    text-align: center;
    font-size: 11px;
    color: #aaa;
    margin-top: 8px;
}

/* 加载动画 */
.ai-float-loading {
    display: inline-flex;
    gap: 4px;
    padding: 4px 0;
}
.ai-float-loading span {
    width: 6px;
    height: 6px;
    background: #c91f1f;
    border-radius: 50%;
    animation: aiFloatBounce 1.4s infinite ease-in-out both;
}
.ai-float-loading span:nth-child(1) { animation-delay: -0.32s; }
.ai-float-loading span:nth-child(2) { animation-delay: -0.16s; }
@keyframes aiFloatBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* 打字光标 */
.typing-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: #c91f1f;
    margin-left: 2px;
    animation: typing-blink 1s infinite;
    vertical-align: text-bottom;
}
@keyframes typing-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* 浮窗内 markdown 微调 */
.ai-float-msg-text.markdown-content p { margin: 4px 0; }
.ai-float-msg-text.markdown-content ul { padding-left: 18px; list-style: disc; }
.ai-float-msg-text.markdown-content li { margin: 2px 0; }
.ai-float-msg-text.markdown-content strong { color: #c91f1f; }
.ai-float-msg-text.markdown-content code { background: #f3f4f6; padding: 1px 4px; border-radius: 3px; font-size: 0.9em; }
.ai-float-msg-text.markdown-content pre { background: #1f2937; color: #f9fafb; padding: 10px; border-radius: 6px; overflow-x: auto; margin: 6px 0; }
.ai-float-msg-text.markdown-content pre code { background: none; color: inherit; padding: 0; }

/* ---------- AI 气泡提示 ---------- */
.ai-bubble-hint {
    position: absolute;
    bottom: 110px;
    right: 0;
    width: 280px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(201, 31, 31, 0.18), 0 0 0 1px rgba(201, 31, 31, 0.06);
    padding: 16px;
    opacity: 0;
    transform: translateY(12px) scale(0.9);
    pointer-events: none;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 20;
}
.ai-bubble-hint.show {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}
.ai-bubble-hint.hiding {
    opacity: 0;
    transform: translateY(8px) scale(0.95);
    pointer-events: none;
}
.ai-bubble-content {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.ai-bubble-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #c91f1f 0%, #a01818 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    animation: aiBubbleFloat 2s ease-in-out infinite;
}
@keyframes aiBubbleFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}
.ai-bubble-text { flex: 1; }
.ai-bubble-title {
    font-size: 14px;
    font-weight: 700;
    color: #c91f1f;
    margin: 0 0 4px 0;
    line-height: 1.3;
}
.ai-bubble-desc {
    font-size: 13px;
    color: #555;
    margin: 0;
    line-height: 1.5;
}
.ai-bubble-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: none;
    background: #f3f4f6;
    color: #999;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    line-height: 1;
    padding: 0;
}
.ai-bubble-close:hover {
    background: #e5e7eb;
    color: #333;
}
/* 气泡小三角 */
.ai-bubble-tail {
    position: absolute;
    bottom: -8px;
    right: 24px;
    width: 16px;
    height: 16px;
    background: #fff;
    transform: rotate(45deg);
    box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.05);
    border-radius: 0 0 4px 0;
}
/* 打字机效果 */
.ai-bubble-desc.typing .ai-bubble-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: #c91f1f;
    margin-left: 2px;
    animation: aiBubbleBlink 0.8s infinite;
    vertical-align: text-bottom;
}
@keyframes aiBubbleBlink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}
/* 点击脉冲 */
.ai-bubble-hint.show .ai-bubble-avatar::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid rgba(201, 31, 31, 0.3);
    animation: aiBubblePulseRing 2s ease-out infinite;
}
@keyframes aiBubblePulseRing {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(1.4); opacity: 0; }
}

/* ---------- 移动端适配 ---------- */
@media (max-width: 480px) {
    #ai-float-widget { right: 12px; bottom: 12px; }
    .ai-float-chat {
        width: calc(100vw - 24px);
        height: 70vh;
        right: 0;
        bottom: 72px;
        border-radius: 12px;
    }
    .ai-float-toggle { width: 48px; height: 48px; font-size: 22px; }
    .ai-float-backtop { width: 36px; height: 36px; }
    .ai-bubble-hint {
        width: 240px;
        right: 0;
        bottom: 90px;
    }
}
