/* 燃坤AI智能客服 (RanKun AI) - 前端悬浮挂件极致现代风格 (全面优化移动端打字与半屏抽屉自适应) */

/* 移动端背景防穿透锁定 */
body.wpsa-body-locked {
    overflow: hidden !important;
    touch-action: none;
}

/* 移动端毛玻璃暗色遮罩背景 (Backdrop) */
.wpsa-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 999998;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

.wpsa-backdrop.wpsa-active {
    display: block;
    opacity: 1;
    pointer-events: auto;
}

#wpsa-widget-root {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* 主动探需微型提示气泡 (Proactive Teaser) */
.wpsa-proactive-teaser {
    position: absolute;
    bottom: 74px;
    right: 0;
    width: 280px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 12px 14px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
    opacity: 0;
    transform: translateY(10px) scale(0.95);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    cursor: pointer;
}

.wpsa-proactive-teaser.wpsa-teaser-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.wpsa-teaser-content {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    font-size: 13px;
    line-height: 1.45;
    color: #1e293b;
    font-weight: 500;
}

.wpsa-teaser-close {
    background: transparent;
    border: none;
    font-size: 16px;
    color: #94a3b8;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    transition: color 0.2s;
}

.wpsa-teaser-close:hover {
    color: #475569;
}

.wpsa-teaser-arrow {
    position: absolute;
    bottom: -6px;
    right: 24px;
    width: 12px;
    height: 12px;
    background: #ffffff;
    border-right: 1px solid #e2e8f0;
    border-bottom: 1px solid #e2e8f0;
    transform: rotate(45deg);
}

/* 悬浮启动图标 */
.wpsa-launcher {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #0768a4;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 25px -5px rgba(7, 104, 164, 0.4), 0 8px 10px -6px rgba(7, 104, 164, 0.2);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    -webkit-tap-highlight-color: transparent;
}

.wpsa-launcher:hover {
    transform: scale(1.06) translateY(-2px);
    box-shadow: 0 14px 28px -4px rgba(7, 104, 164, 0.5);
}

.wpsa-launcher.wpsa-hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.6);
}

.wpsa-launcher-icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.wpsa-launcher-icon svg {
    width: 28px;
    height: 28px;
}

.wpsa-launcher-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #ef4444;
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    height: 20px;
    width: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #ffffff;
    animation: wpsa-pulse 2s infinite;
}

@keyframes wpsa-pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

@keyframes wpsa-shake-kf {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}

.wpsa-shake {
    animation: wpsa-shake-kf 0.6s ease-in-out;
}

/* 聊天窗口主面板 */
.wpsa-chat-window {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 48px);
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 20px 40px -15px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 999999;
}

.wpsa-chat-window.wpsa-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* 顶部收起手柄 (移动端特有，桌面端隐藏) */
.wpsa-sheet-handle {
    display: none;
}

/* 顶部头部 */
.wpsa-window-header {
    background: #0768a4;
    color: #ffffff;
    padding: 16px;
    display: flex;
    flex-direction: column;
    position: relative;
}

.wpsa-header-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

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

.wpsa-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.wpsa-header-avatar svg {
    width: 24px;
    height: 24px;
    stroke: #ffffff;
}

.wpsa-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.wpsa-header-name {
    font-weight: 600;
    font-size: 15px;
    line-height: 1.2;
}

.wpsa-header-status {
    font-size: 11px;
    opacity: 0.9;
    margin-top: 3px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.wpsa-status-dot {
    width: 7px;
    height: 7px;
    background: #4ade80;
    border-radius: 50%;
    display: inline-block;
}

.wpsa-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.wpsa-close-btn {
    background: transparent;
    border: none;
    color: #ffffff;
    opacity: 0.85;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s, background 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.wpsa-close-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.18);
}

.wpsa-close-btn svg {
    width: 20px;
    height: 20px;
}

/* 消息流区域 */
.wpsa-messages-wrap {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
}

.wpsa-messages-inner {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.wpsa-msg-row {
    display: flex;
    width: 100%;
}

.wpsa-msg-row.wpsa-user-row {
    justify-content: flex-end;
}

.wpsa-msg-row.wpsa-agent-row {
    justify-content: flex-start;
}

.wpsa-bubble {
    max-width: 82%;
    padding: 11px 15px;
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
}

.wpsa-agent-bubble {
    background: #ffffff;
    color: #1e293b;
    border: 1px solid #e2e8f0;
    border-radius: 14px 14px 14px 3px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.wpsa-user-bubble {
    background: #0768a4;
    color: #ffffff;
    border-radius: 14px 14px 3px 14px;
}

/* 推荐快捷提问胶囊 */
.wpsa-suggestions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 4px;
}

.wpsa-chip {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    color: #0768a4;
    font-size: 12px;
    padding: 8px 12px;
    border-radius: 18px;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.wpsa-chip:hover {
    background: #f0f7fc;
    border-color: #bae0ff;
    transform: translateX(2px);
}

/* 打字中指示器 */
.wpsa-typing-indicator {
    display: none;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 14px 14px 14px 3px;
    width: fit-content;
    margin-top: 8px;
}

.wpsa-typing-indicator.wpsa-visible {
    display: flex;
}

.wpsa-typing-indicator span {
    width: 6px;
    height: 6px;
    background: #94a3b8;
    border-radius: 50%;
    animation: wpsa-bounce 1.4s infinite ease-in-out both;
}

.wpsa-typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.wpsa-typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes wpsa-bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* 留资交互卡片 */
.wpsa-lead-card {
    background: #ffffff;
    border: 1.5px solid #bae0ff;
    border-radius: 12px;
    padding: 14px;
    margin-top: 6px;
    box-shadow: 0 4px 12px -2px rgba(7, 104, 164, 0.1);
}

.wpsa-card-title {
    font-weight: 600;
    font-size: 13px;
    color: #1e3a8a;
    margin-bottom: 4px;
}

.wpsa-card-desc {
    font-size: 12px;
    color: #64748b;
    margin-bottom: 10px;
    line-height: 1.4;
}

.wpsa-card-input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 14px;
    margin-bottom: 8px;
    box-sizing: border-box;
}

.wpsa-card-input:focus {
    border-color: #0768a4;
    outline: none;
}

.wpsa-card-btn {
    width: 100%;
    background: #0768a4;
    color: #ffffff;
    border: none;
    border-radius: 6px;
    padding: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.wpsa-card-btn:hover {
    background: #054d7a;
}

/* 输入框区域 (PC 与基线) */
.wpsa-input-area {
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    box-sizing: border-box;
    width: 100%;
}

.wpsa-input-box {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    background: #f8fafc;
    border: 1.5px solid #e2e8f0;
    border-radius: 24px;
    padding: 4px 6px 4px 14px;
    box-sizing: border-box;
    transition: all 0.2s ease;
}

.wpsa-input-box:focus-within {
    background: #ffffff;
    border-color: #0768a4;
    box-shadow: 0 0 0 3px rgba(7, 104, 164, 0.12);
}

.wpsa-input-box textarea {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    background: transparent;
    font-size: 14px;
    max-height: 80px;
    min-height: 24px;
    height: 24px;
    padding: 2px 0;
    margin: 0;
    line-height: 24px;
    box-sizing: border-box;
    font-family: inherit;
    color: #0f172a;
    -webkit-appearance: none;
}

.wpsa-input-box textarea::placeholder {
    color: #94a3b8;
}

.wpsa-input-box button.wpsa-send-btn {
    background: #0768a4;
    color: #ffffff;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
    padding: 0;
    margin: 0;
}

.wpsa-input-box button.wpsa-send-btn:hover {
    background: #054d7a;
    transform: scale(1.05);
}

.wpsa-input-box button.wpsa-send-btn:active {
    transform: scale(0.92);
}

.wpsa-input-box button.wpsa-send-btn svg {
    width: 15px;
    height: 15px;
}

/* 底部极简条 */
.wpsa-footer-bar {
    background: #f8fafc;
    border-top: 1px solid #f1f5f9;
    padding: 6px 12px;
    text-align: center;
    font-size: 11px;
    color: #94a3b8;
    user-select: none;
    -webkit-user-select: none;
}

/* ========================================================
   📱 移动端自适应重构：半屏底部抽屉 + 软键盘防遮挡 + 16px防缩放
   ======================================================== */
@media (max-width: 600px) {
    #wpsa-widget-root {
        bottom: 18px;
        right: 18px;
    }

    .wpsa-launcher {
        width: 56px;
        height: 56px;
        box-shadow: 0 8px 24px rgba(7, 104, 164, 0.45);
    }

    .wpsa-launcher-icon svg {
        width: 26px;
        height: 26px;
    }

    /* 移动端改为优雅的 Bottom Sheet 半屏抽屉，彻底告别死板布满全屏 */
    .wpsa-chat-window {
        position: fixed;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 82dvh;
        max-height: 82dvh;
        border-radius: 20px 20px 0 0 !important;
        box-shadow: 0 -12px 36px rgba(0, 0, 0, 0.25);
        display: flex;
        flex-direction: column;
        overflow: hidden;
        z-index: 999999;
        transform: translateY(100%);
        opacity: 1;
        transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), height 0.2s ease, border-radius 0.2s ease;
    }

    .wpsa-chat-window.wpsa-open {
        transform: translateY(0);
        pointer-events: auto;
    }

    /* 顶部下推/收起胶囊手柄条 */
    .wpsa-sheet-handle {
        display: block;
        width: 42px;
        height: 4px;
        background: rgba(255, 255, 255, 0.45);
        border-radius: 2px;
        margin: -6px auto 10px auto;
        cursor: pointer;
        transition: background 0.2s, transform 0.15s;
    }

    .wpsa-sheet-handle:active {
        background: rgba(255, 255, 255, 0.85);
        transform: scaleY(1.3);
    }

    .wpsa-window-header {
        padding: 12px 16px 14px 16px;
        border-radius: 20px 20px 0 0;
    }

    .wpsa-header-name {
        font-size: 15px;
    }

    .wpsa-header-status {
        font-size: 11px;
    }

    .wpsa-messages-wrap {
        padding: 12px 14px;
    }

    .wpsa-bubble {
        max-width: 86%;
        font-size: 14.5px;
        line-height: 1.5;
        padding: 10px 14px;
    }

    /* 🚨 核心修复：移动端字体必须 >= 16px，彻底杜绝 iOS Safari / 微信 点击输入框时的强制缩放放大 BUG！ */
    .wpsa-input-area {
        padding: 8px 12px;
        background: #ffffff;
    }

    .wpsa-input-box {
        padding: 4px 6px 4px 14px;
    }

    .wpsa-input-box textarea {
        font-size: 16px !important;
        line-height: 24px;
        min-height: 24px;
        height: 24px;
        padding: 2px 0;
    }

    .wpsa-card-input {
        font-size: 16px !important;
    }

    .wpsa-input-box button.wpsa-send-btn {
        width: 34px;
        height: 34px;
    }

    .wpsa-footer-bar {
        padding: 6px 12px calc(6px + env(safe-area-inset-bottom, 0px)) 12px;
        font-size: 10.5px;
    }

    .wpsa-proactive-teaser {
        width: calc(100vw - 36px);
        right: 0;
        bottom: 74px;
    }
}
