/* 智能客服挂件 — 全部样式挂在 #kefu-widget 命名空间下，不污染站点样式
   折叠态：全身体现科技感的"数小旗"立绘 + 轮播话术气泡（最多同时 2 条） */
#kefu-widget {
    all: initial;
    font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
    font-size: 13px;
    color: #333;
}

#kefu-widget, #kefu-widget * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ---- 折叠态：右下角站立的数小旗 ---- */
#kefu-widget #kefu-fab {
    position: fixed;
    right: 14px;
    bottom: 0;
    width: 158px;
    height: 224px;
    border: 0;
    background: transparent;
    cursor: pointer;
    z-index: 99999;
    user-select: none;
    outline: none;
    /* 允许 Pointer Events 拖拽，触摸时阻止页面滚动接管手势 */
    touch-action: none;
}

/* 拖拽中光标反馈 */
#kefu-widget #kefu-fab.kefu-dragging {
    cursor: grabbing;
}

/* 立绘：透明底，投影增加立体感；轻微上下浮动体现"生命感"（GPU transform） */
#kefu-widget .kefu-fab-figure {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: auto;
    display: block;
    filter: drop-shadow(0 6px 14px rgba(47, 111, 237, .28));
    animation: kefuBob 3.2s ease-in-out infinite;
    -webkit-user-drag: none;
}

@keyframes kefuBob {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-5px);
    }
}

#kefu-widget #kefu-fab:hover .kefu-fab-figure,
#kefu-widget #kefu-fab:focus .kefu-fab-figure {
    animation: none;
    transform: translateY(-4px) scale(1.02);
}

/* ---- 轮播话术气泡：单条，位于小人左侧 ---- */
/* 显式宽度：绝对定位 shrink-to-fit 受 158px fab 包含块限制，不设宽会被压缩成竖条 */
#kefu-widget .kefu-scripts {
    position: absolute;
    right: calc(100% - 22px);
    bottom: 148px;
    width: 260px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    pointer-events: none;
}

#kefu-widget .kefu-script-bubble {
    position: relative;
    max-width: 250px;
    background: #fff;
    color: #333;
    font-size: 13px;
    line-height: 1.6;
    padding: 10px 14px;
    border-radius: 14px;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 18px rgba(31, 56, 110, .16), 0 0 0 1px rgba(47, 111, 237, .06);
    opacity: 0;
    transform: translateY(10px) scale(.96);
    transition: opacity .35s ease, transform .35s ease;
}

/* 气泡右侧小尾巴指向小人 */
#kefu-widget .kefu-script-bubble::after {
    content: "";
    position: absolute;
    right: -5px;
    bottom: 12px;
    width: 10px;
    height: 10px;
    background: #fff;
    border-radius: 2px;
    transform: rotate(45deg);
    box-shadow: 2px 2px 4px rgba(31, 56, 110, .06);
}

/* 第二条气泡尾巴位置错开，视觉更自然 */
#kefu-widget .kefu-script-bubble:nth-last-child(2)::after {
    bottom: auto;
    top: 12px;
}

#kefu-widget .kefu-script-bubble.kefu-script-in {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* ---- 展开面板：右下角弹出 ---- */
#kefu-widget #kefu-panel {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: 360px;
    height: 520px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, .18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 100000;
}

#kefu-widget .kefu-head {
    background: linear-gradient(135deg, #2f6fed, #5a9bff);
    color: #fff;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

/* 头部吉祥物头像（白色圆底，与图片白底融合） */
#kefu-widget .kefu-head-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #fff;
    object-fit: cover;
    object-position: center 30%;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, .35);
}

#kefu-widget .kefu-head-title {
    flex: 1;
    min-width: 0;
}

#kefu-widget .kefu-head b {
    font-size: 15px;
    display: block;
}

#kefu-widget .kefu-head-sub {
    font-size: 11px;
    opacity: .85;
}

#kefu-widget .kefu-close {
    background: transparent;
    border: 0;
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    padding: 4px;
}

/* ---- 消息区 ---- */
#kefu-widget .kefu-body {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    background: #f7f9fc;
}

#kefu-widget .kefu-msg {
    display: flex;
    margin-bottom: 10px;
    gap: 8px;
}

/* 机器人消息左侧的数小旗小头像 */
#kefu-widget .kefu-msg-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #fff;
    border: 1px solid #e5eaf2;
    object-fit: cover;
    object-position: center 30%;
    flex-shrink: 0;
    margin-top: 2px;
}

#kefu-widget .kefu-bubble {
    max-width: 78%;
    padding: 9px 12px;
    border-radius: 10px;
    font-size: 13px;
    line-height: 1.6;
    word-break: break-word;
    white-space: pre-wrap;
}

#kefu-widget .kefu-msg-bot .kefu-bubble {
    background: #fff;
    border: 1px solid #e5eaf2;
    border-top-left-radius: 2px;
}

#kefu-widget .kefu-msg-user {
    flex-direction: row-reverse;
}

#kefu-widget .kefu-msg-user .kefu-bubble {
    background: #2f6fed;
    color: #fff;
    border-top-right-radius: 2px;
}

#kefu-widget .kefu-msg-error .kefu-bubble {
    background: #fff3f3;
    border: 1px solid #f5c6c6;
    color: #c0392b;
}

/* ---- 热门问题 ---- */
#kefu-widget .kefu-hot {
    margin-top: 4px;
}

#kefu-widget .kefu-hot-label {
    font-size: 11px;
    color: #8a97ad;
    margin: 2px 0 8px;
}

#kefu-widget .kefu-hot-chip {
    display: inline-block;
    font-size: 12px;
    color: #2f6fed;
    background: #eaf1ff;
    border: 0;
    border-radius: 14px;
    padding: 4px 10px;
    margin: 0 6px 6px 0;
    cursor: pointer;
}

#kefu-widget .kefu-hot-chip:hover {
    background: #dbe7ff;
}

/* ---- 输入区 ---- */
#kefu-widget .kefu-foot {
    border-top: 1px solid #eee;
    padding: 10px 12px;
    display: flex;
    gap: 8px;
    background: #fff;
    flex-shrink: 0;
}

#kefu-widget .kefu-input {
    flex: 1;
    border: 1px solid #dfe5ee;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
    outline: none;
    min-width: 0;
}

#kefu-widget .kefu-input:focus {
    border-color: #2f6fed;
}

#kefu-widget .kefu-send {
    border: 0;
    background: #2f6fed;
    color: #fff;
    border-radius: 8px;
    padding: 8px 16px;
    cursor: pointer;
    font-size: 13px;
}

#kefu-widget .kefu-send:disabled {
    opacity: .6;
    cursor: default;
}

/* ---- 底部品牌栏 ---- */
#kefu-widget .kefu-brand {
    background: #fff;
    border-top: 1px solid #f0f3f8;
    color: #9aa7bd;
    font-size: 11px;
    text-align: center;
    padding: 6px 10px;
    flex-shrink: 0;
    user-select: none;
}

/* ---- 无障碍：尊重系统"减少动态效果"偏好 ---- */
@media (prefers-reduced-motion: reduce) {
    #kefu-widget .kefu-fab-figure {
        animation: none !important;
    }

    #kefu-widget .kefu-script-bubble {
        transition: none !important;
    }
}

/* ---- 移动端响应式 ---- */
@media (max-width: 768px) {
    #kefu-widget #kefu-panel {
        width: calc(100vw - 24px);
        height: 60vh;
        right: 12px;
        bottom: 12px;
        left: auto;
    }

    #kefu-widget #kefu-fab {
        width: 96px;
        height: 136px;
        right: 10px;
    }

    #kefu-widget .kefu-scripts {
        right: calc(100% - 14px);
        bottom: 96px;
        width: 62vw;
    }

    #kefu-widget .kefu-script-bubble {
        max-width: 58vw;
        font-size: 12px;
        padding: 8px 12px;
    }
}
