/* ============================================================
   客服系统 - 全局浮动聊天组件
   右下角浮动按钮 + 聊天窗口；独立于站内信体系
   ============================================================ */

.kefu-widget {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 2147483000;
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

.kefu-widget[hidden] { display: none; }

/* ---------- 浮动按钮 ---------- */
.kefu-fab {
    position: relative;
    width: 54px;
    height: 54px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #ff6b8a, #ff8fab);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(255, 107, 138, .45);
    transition: transform .2s ease, box-shadow .2s ease;
}
.kefu-fab:hover {
    transform: translateY(-2px) scale(1.04);
    box-shadow: 0 12px 28px rgba(255, 107, 138, .55);
}
.kefu-fab-ico {
    width: 26px;
    height: 26px;
}

/* 未读红点 */
.kefu-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 10px;
    background: #ff3b30;
    color: #fff;
    font-size: 11px;
    line-height: 18px;
    text-align: center;
    font-weight: 600;
    box-shadow: 0 0 0 2px #fff;
}
.kefu-badge[hidden] { display: none; }

/* ---------- 聊天窗口 ---------- */
.kefu-panel {
    position: fixed;
    width: 480px;
    max-width: calc(100vw - 32px);
    height: 640px;
    max-height: calc(100vh - 48px);
    background: #fff;
    border-radius: 14px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 18px 48px rgba(20, 20, 40, .22);
    border: 1px solid rgba(0, 0, 0, .06);
    z-index: 2147483000;
    animation: kefuIn .2s ease;
}
.kefu-panel[hidden] { display: none; }
@keyframes kefuIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* 头部（可拖动） */
.kefu-head {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: linear-gradient(135deg, #ff6b8a, #ff8fab);
    color: #fff;
    cursor: move;
    user-select: none;
}
.kefu-head-title {
    font-size: 15px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}
.kefu-head-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4cdf91;
    box-shadow: 0 0 0 3px rgba(76, 223, 145, .3);
}
.kefu-close {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, .18);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .2s;
}
.kefu-close:hover { background: rgba(255, 255, 255, .32); }
.kefu-close svg { width: 15px; height: 15px; }

/* 消息区 */
.kefu-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain; /* 阻止滚动穿透到背景页面 */
    padding: 14px 14px 6px;
    background: #f7f8fb;
    scrollbar-width: none; /* 隐藏滚动条（仍可滚动） */
}
.kefu-body::-webkit-scrollbar { display: none; }
.kefu-tip {
    font-size: 12px;
    color: #9aa0b0;
    text-align: center;
    line-height: 1.6;
    background: #fff;
    border-radius: 8px;
    padding: 8px 10px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .04);
}

/* 单条消息 */
.kefu-msg {
    display: flex;
    margin-bottom: 12px;
}
/* 仅增量新增的消息播放入场动画（历史渲染不播放，避免重开聊天框时跳动） */
.kefu-msg.kefu-new { animation: kefuMsgIn .28s ease both; }
@keyframes kefuMsgIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
/* 历史加载中 */
.kefu-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 26px 0;
    font-size: 13px;
    color: #9aa0b0;
}
.kefu-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #ffd3de;
    border-top-color: #ff6b8a;
    border-radius: 50%;
    animation: kefuSpin .7s linear infinite;
}
@keyframes kefuSpin {
    to { transform: rotate(360deg); }
}
.kefu-msg.admin {
    justify-content: flex-start;
}
.kefu-msg.user {
    justify-content: flex-end;
}
/* wrap 限宽且随内容收缩：短消息不撑满、长消息在 78% 内换行 */
.kefu-msg-wrap {
    max-width: 78%;
    display: inline-block;
}
.kefu-msg-bubble {
    display: inline-block;
    max-width: 100%;
    padding: 9px 13px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
    white-space: pre-wrap;
}
.kefu-msg.admin .kefu-msg-bubble {
    background: #fff;
    color: #2b2f3a;
    border-top-left-radius: 3px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .05);
}
.kefu-msg.user .kefu-msg-bubble {
    background: linear-gradient(135deg, #ff6b8a, #ff8fab);
    color: #fff;
    border-top-right-radius: 3px;
}
.kefu-msg-time {
    font-size: 11px;
    color: #b3b8c4;
    margin-top: 4px;
    padding: 0 2px;
}
.kefu-msg.admin .kefu-msg-wrap { text-align: left; }
.kefu-msg.user .kefu-msg-wrap { text-align: right; }

/* 底部输入 */
.kefu-foot {
    flex-shrink: 0;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #f0f1f4;
    background: #fff;
}
.kefu-input {
    flex: 1;
    min-height: 38px;
    max-height: 100px;
    resize: none;
    border: 1px solid #e3e6ec;
    border-radius: 10px;
    padding: 9px 12px;
    font-size: 14px;
    font-family: inherit;
    color: #2b2f3a;
    outline: none;
    transition: border-color .2s;
}
.kefu-input:focus { border-color: #ff6b8a; }
.kefu-input::placeholder { color: #b3b8c4; }
.kefu-send {
    flex-shrink: 0;
    height: 38px;
    padding: 0 18px;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, #ff6b8a, #ff8fab);
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: opacity .2s, transform .1s;
}
.kefu-send:hover { opacity: .9; }
.kefu-send:active { transform: scale(.97); }
.kefu-send:disabled { opacity: .5; cursor: not-allowed; }

/* 状态条（会话关闭提示） */
.kefu-status-line {
    font-size: 12px;
    color: #9aa0b0;
    text-align: center;
    padding: 6px 0;
}

@media (max-width: 480px) {
    .kefu-widget { right: 14px; bottom: 14px; }
    .kefu-panel {
        position: fixed;
        top: auto;
        left: 10px;
        right: 10px;
        bottom: 80px;
        transform: none;
        width: calc(100vw - 20px);
        height: calc(100vh - 130px);
    }
}