/* ==========================================================
   04889dh · 前台在线客服悬浮窗
   ========================================================== */
.kefu-widget {
    position: fixed;
    right: 16px;
    bottom: 76px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
}

/* ---------- 悬浮按钮 ---------- */
/*
 * 客服入口：图标 + 「客服」文字的胶囊按钮。
 * 比纯圆形图标更易被访客发现，也符合「点击进入客服」的直觉。
 */
.kefu-fab {
    position: relative;
    height: 48px;
    padding: 0 16px 0 13px;
    border: none;
    border-radius: 24px;
    background: #cc0000;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    box-shadow: 0 4px 14px rgba(204, 0, 0, .35);
    transition: transform .15s ease;
}
.kefu-fab:hover { transform: scale(1.04); }
.kefu-fab[hidden] { display: none; }
.kefu-fab svg { flex: none; }
/* 「客服」文字 */
.kefu-fab-text {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: .5px;
    line-height: 1;
    white-space: nowrap;
}
.kefu-badge {
    position: absolute;
    top: -6px;
    left: -6px;
    min-width: 19px;
    height: 19px;
    padding: 0 5px;
    border-radius: 999px;
    background: #ff4d4f;
    color: #fff;
    font-size: 11px;
    line-height: 19px;
    text-align: center;
    border: 2px solid #fff;
}
.kefu-badge[hidden] { display: none; }

/* ---------- 聊天面板 ---------- */
.kefu-panel {
    position: absolute;
    right: 0;
    bottom: 62px;
    width: 340px;
    max-width: calc(100vw - 32px);
    height: 480px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, .22);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.kefu-panel[hidden] { display: none; }

.kefu-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: #cc0000;
    color: #fff;
    flex: none;
}
.kefu-head-title { font-size: 15px; font-weight: 600; margin-right: auto; }

/* 提示音开关：与关闭按钮并排 */
.kefu-sound {
    border: none;
    background: transparent;
    color: #fff;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    padding: 3px 7px;
    border-radius: 6px;
    opacity: .9;
    flex: none;
}
.kefu-sound:hover { opacity: 1; background: rgba(255, 255, 255, .18); }
.kefu-sound[hidden] { display: none; }
/* 已开启但浏览器未放行：闪烁提示需点一下页面 */
.kefu-sound.pending { animation: kefu-blink 1.4s ease-in-out infinite; }
@keyframes kefu-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: .35; }
}
.kefu-close {
    border: none;
    background: transparent;
    color: #fff;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    opacity: .85;
    flex: none;
}
.kefu-close:hover { opacity: 1; }

/* ---------- 登录/开始 ---------- */
.kefu-login {
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 9px;
    overflow-y: auto;
    min-height: 0;
    flex: 1;
}
.kefu-login[hidden] { display: none; }
.kefu-tip { margin: 0; font-size: 12.5px; color: #6b7280; line-height: 1.55; }
.kefu-login input {
    width: 100%;
    padding: 9px 10px;
    border: 1px solid #d8dbe0;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
}
.kefu-login input:focus { border-color: #cc0000; }
.kefu-member summary {
    font-size: 12.5px;
    color: #cc0000;
    cursor: pointer;
    list-style: none;
    user-select: none;
}
.kefu-member summary::-webkit-details-marker { display: none; }
.kefu-member summary:before { content: "▸ "; }
.kefu-member[open] summary:before { content: "▾ "; }
.kefu-member input { margin-top: 7px; }
.kefu-start {
    padding: 10px;
    border: none;
    border-radius: 8px;
    background: #cc0000;
    color: #fff;
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
}
.kefu-start:hover { background: #b30000; }
.kefu-err {
    font-size: 12.5px;
    color: #d4380d;
    background: #fff2e8;
    border: 1px solid #ffccc7;
    border-radius: 6px;
    padding: 7px 9px;
}
.kefu-err[hidden] { display: none; }

/* ---------- 消息区 ---------- */
.kefu-body {
    flex: 1;
    /* flex 子项默认 min-height:auto，必须置 0 才会收缩并产生滚动条 */
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px;
    background: #f7f8fa;
    scrollbar-width: thin;
}
.kefu-body::-webkit-scrollbar { width: 6px; }
.kefu-body::-webkit-scrollbar-track { background: #eceef1; }
.kefu-body::-webkit-scrollbar-thumb { background: #c2c7ce; border-radius: 3px; }
.kefu-body[hidden] { display: none; }
.kefu-msg { margin-bottom: 11px; display: flex; flex-direction: column; }
.kefu-msg.mine { align-items: flex-end; }
.kefu-msg.sys { align-items: center; }
/*
 * 系统消息（欢迎语 / 无人接待时的自动应答）
 * 用小号浅灰字显示时几乎看不清，这里放大加粗加深，并垫一层浅色底，
 * 让访客一眼就能看到「有人应答我了」。
 */
.kefu-msg.sys span {
    font-size: 14px;
    font-weight: 700;
    color: #4b5563;
    text-align: center;
    line-height: 1.6;
    max-width: 92%;
    padding: 7px 10px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}
.kefu-bubble {
    max-width: 80%;
    padding: 8px 11px;
    border-radius: 10px;
    background: #fff;
    border: 1px solid #e5e7eb;
    font-size: 13.5px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}
.kefu-msg.mine .kefu-bubble { background: #cc0000; color: #fff; border-color: #cc0000; }
.kefu-meta { font-size: 10.5px; color: #9aa0a6; margin-top: 3px; }

/* ---------- 输入区 ---------- */
.kefu-foot {
    display: flex;
    gap: 7px;
    padding: 9px 10px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
    flex: none;
    align-items: flex-end;
}
.kefu-foot[hidden] { display: none; }
.kefu-foot textarea {
    flex: 1;
    padding: 8px 9px;
    border: 1px solid #d8dbe0;
    border-radius: 8px;
    font-size: 13.5px;
    font-family: inherit;
    resize: none;
    outline: none;
    line-height: 1.5;
}
.kefu-foot textarea:focus { border-color: #cc0000; }
.kefu-send {
    padding: 8px 14px;
    border: none;
    border-radius: 8px;
    background: #cc0000;
    color: #fff;
    font-size: 13.5px;
    font-family: inherit;
    cursor: pointer;
    flex: none;
}
.kefu-send:hover { background: #b30000; }

@media (max-width: 480px) {
    .kefu-widget { right: 12px; bottom: 68px; }
    .kefu-panel { width: calc(100vw - 24px); height: 62vh; }
}
