/* ============================================================
   先风短链 · AI智能客服悬浮组件样式 (v4 美化版)
   全部样式集中于本文件；组件 DOM 由 kefu.js 动态创建
   设计要点：沿用站点品牌蓝紫，收敛渐变使用，统一按钮体系，
   自定义细滚动条，头像区分角色，移除所有 hover 上浮位移。
   ============================================================ */

/* 用 :where() 把 reset 特异性降为 0，否则 #kf-root * 的 ID 权重会压死
   下面所有 .kf-xxx 类规则的 margin/padding（曾导致气泡无内边距、
   用户消息 margin-left:auto 失效而整体左偏） */
:where(#kf-root, #kf-root *) {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

#kf-root {
    position: fixed;
    right: 20px;
    bottom: 104px;
    z-index: 2147483000;
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* ---------- 悬浮按钮 ---------- */
#kf-btn {
    width: 44px;
    height: 157px;
    border-radius: 22px;
    background: linear-gradient(180deg, #5b8cff 0%, #3f4fd8 100%);
    box-shadow: 0 8px 22px rgba(58, 99, 255, 0.38), inset 0 1px 0 rgba(255, 255, 255, 0.35);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 11px;
    padding: 13px 0 14px;
    cursor: pointer;
    position: relative;
    border: 2px solid rgba(255, 255, 255, 0.9);
    transition: box-shadow 0.2s ease, filter 0.2s ease;
}
/* ⚠️ 遵守铁律：hover 仅做外发光/提亮，禁止 translateY 等上浮位移 */
#kf-btn:hover {
    box-shadow: 0 10px 30px rgba(58, 99, 255, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.45);
    filter: brightness(1.06);
}
#kf-btn svg {
    width: 32px;
    height: 32px;
    display: block;
    flex: none;
}
#kf-btn-label {
    position: static;
    background: none;
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    line-height: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    gap: 3px;
    opacity: 1;
    pointer-events: none;
}
#kf-btn-label span {
    display: block;
    line-height: 1;
    text-align: center;
}
#kf-btn .kf-dot {
    position: absolute;
    top: 6px;
    right: 4px;
    width: 12px;
    height: 12px;
    background: #ff4757;
    border: 2px solid #fff;
    border-radius: 50%;
    display: none;
}

#kf-root.kf-in-member {
    right: 41px;
    bottom: 104px;
}
#kf-root.kf-in-member #kf-panel {
    bottom: 104px;
    max-height: calc(100vh - 124px);
}
/* ---------- 聊天面板 ---------- */
#kf-panel {
    position: fixed;
    right: 20px;
    bottom: 24px;
    width: 376px;
    height: 580px;
    max-height: calc(100vh - 48px);
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 18px 50px rgba(18, 38, 60, 0.20);
    display: none;
    flex-direction: column;
    overflow: hidden;
}

#kf-panel.kf-open {
    display: flex;
}

/* 头部（v10：删副标题，整体压矮） */
#kf-head {
    background: linear-gradient(135deg, #45a9f1 0%, #6C5CE7 100%);
    color: #fff;
    padding: 12px 18px;
    flex-shrink: 0;
    position: relative;
    display: flex;
    align-items: center;
    gap: 11px;
}

#kf-head-ava {
    width: 34px;
    height: 34px;
    border-radius: 11px;
    background: rgba(255, 255, 255, 0.20);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#kf-head-ava svg {
    width: 20px;
    height: 20px;
}

#kf-head-text {
    flex: 1;
    min-width: 0;
}

#kf-head-title {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

#kf-close {
    position: absolute;
    right: 12px;
    top: 15px;
    width: 28px;
    height: 28px;
    background: rgba(255, 255, 255, 0.18);
    border: none;
    border-radius: 50%;
    color: #fff;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}

#kf-close:hover {
    background: rgba(255, 255, 255, 0.34);
}

/* 状态条 */
#kf-status {
    flex-shrink: 0;
    padding: 8px 18px;
    background: #f7fafc;
    box-shadow: inset 0 -1px 0 #eef2f6;
    font-size: 12px;
    color: #5a6b85;
    display: flex;
    align-items: center;
    gap: 7px;
}

#kf-status .kf-st-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #2ed573;
    flex-shrink: 0;
    box-shadow: 0 0 0 3px rgba(46, 213, 115, 0.18);
}

#kf-status.kf-st-human .kf-st-dot {
    background: #ffa502;
    box-shadow: 0 0 0 3px rgba(255, 165, 2, 0.18);
}

#kf-status.kf-st-off .kf-st-dot {
    background: #ced6e0;
    box-shadow: none;
}

/* 消息区 */
#kf-msgs {
    flex: 1;
    overflow-y: auto;
    padding: 16px 18px 12px;
    background: #f5f8fb;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: rgba(69, 169, 241, 0.32) transparent;
}

#kf-msgs::-webkit-scrollbar {
    width: 6px;
}

#kf-msgs::-webkit-scrollbar-track {
    background: transparent;
}

#kf-msgs::-webkit-scrollbar-thumb {
    background: rgba(69, 169, 241, 0.30);
    border-radius: 3px;
}

#kf-msgs::-webkit-scrollbar-thumb:hover {
    background: rgba(69, 169, 241, 0.52);
}

.kf-msg {
    margin-bottom: 14px;
    display: flex;
    flex-direction: column;
    /* v12：恢复左右分栏 —— 发送贴右、回复靠左，气泡宽度贴合内容 */
    width: -webkit-fit-content;
    width: fit-content;
    max-width: 86%;
    animation: kf-fade-in 0.28s ease both;
}

@keyframes kf-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.kf-msg.kf-user {
    /* 目标样式：我在头像左侧、气泡在标签行下方，发送组整体靠右 */
    align-items: flex-start;
    flex-direction: row;
    gap: 8px;
    margin-left: auto;
    /* 补偿头像 30px + gap 8px，让发送气泡与回复气泡等宽 */
    max-width: calc(86% + 38px);
}

.kf-msg.kf-bot,
.kf-msg.kf-admin {
    align-items: flex-start;
    flex-direction: row;
    gap: 8px;
    /* 与用户侧同样的 38px 补偿，保证回复气泡与发送气泡等宽 */
    max-width: calc(86% + 38px);
}

.kf-msg.kf-sys {
    align-items: center;
    margin-left: auto;
    margin-right: auto;
    max-width: 100%;
}

/* 角色头像：与角色标签同一水平线、上下居中对齐
   （标签行高约 16.5px、头像 30px → -7px 让两者中心重合） */
.kf-ava {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: -7px;
}

.kf-ava svg {
    width: 17px;
    height: 17px;
}

.kf-ava-bot {
    background: linear-gradient(135deg, #45a9f1 0%, #6C5CE7 100%);
}

.kf-ava-admin {
    background: linear-gradient(135deg, #2ecc71 0%, #16a34a 100%);
}

/* 用户头像：中等饱和纯蓝 + 白色人像，与 AI 侧蓝紫渐变头像视觉重量相当 */
.kf-ava-user {
    background: #5b8def;
}

.kf-msg-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.kf-msg.kf-user .kf-msg-body {
    align-items: flex-end;
}

.kf-msg.kf-bot .kf-msg-body,
.kf-msg.kf-admin .kf-msg-body {
    align-items: flex-start;
}

.kf-msg.kf-sys .kf-msg-body {
    align-items: center;
}

/* 角色标签：在气泡上方，与头像同一水平线、上下居中 */
.kf-msg .kf-role {
    font-size: 11px;
    color: #8fa1b8;
    margin-bottom: 4px;
}

.kf-msg.kf-user .kf-role {
    text-align: right;
}

.kf-msg.kf-sys .kf-role {
    display: none;
}

.kf-msg .kf-bubble {
    /* 四边等距 7px；四角统一 8px */
    padding: 7px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
    max-width: 100%;
}

/* 用户气泡：淡蓝底 + 深蓝字 */
.kf-msg.kf-user .kf-bubble {
    background: #e3f0ff;
    color: #1c4f8a;
    -webkit-text-fill-color: #1c4f8a;
    text-shadow: none;
    font-weight: 500;
    box-shadow: 0 2px 8px rgba(69, 169, 241, 0.18);
}

.kf-msg.kf-bot .kf-bubble {
    background: #fff;
    color: #2b3a4f;
    box-shadow: 0 1px 3px rgba(18, 38, 60, 0.08);
}

.kf-msg.kf-admin .kf-bubble {
    background: #eafaf0;
    color: #1f6b3f;
}

/* 「正在输入」三点：只做透明度呼吸，不位移、不弹跳 */
.kf-bubble-typing {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 12px 14px !important;
    min-height: 0 !important;
}
.kf-bubble-typing i {
    display: block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #9aa8ba;
    animation: kf-typing-blink 1.2s ease-in-out infinite;
}
.kf-bubble-typing i:nth-child(2) { animation-delay: .18s; }
.kf-bubble-typing i:nth-child(3) { animation-delay: .36s; }
@keyframes kf-typing-blink {
    0%, 65%, 100% { opacity: .25; }
    32% { opacity: 1; }
}

.kf-msg.kf-sys .kf-bubble {
    background: rgba(90, 107, 133, 0.10);
    color: #5a6b85;
    font-size: 12px;
    border-radius: 8px;
    padding: 5px 14px;
    width: auto;
}

.kf-msg .kf-time {
    font-size: 11px;
    color: #a8b7c9;
    margin-top: 4px;
}

.kf-msg.kf-user .kf-time {
    text-align: right;
    margin-top: 5px;
}

/* 快捷问题 */
#kf-quick {
    flex-shrink: 0;
    padding: 10px 16px 4px;
    background: #f5f8fb;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    border-top: 1px solid #eef2f6;
}

#kf-quick button {
    border: 1px solid #d6e4f5;
    background: #fff;
    color: #3d7cc9;
    font-size: 12px;
    padding: 6px 13px;
    border-radius: 16px;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

#kf-quick button:hover {
    background: #eaf3fd;
    border-color: #45a9f1;
}

/* 输入区 */
#kf-input-bar {
    flex-shrink: 0;
    padding: 12px 14px;
    background: #fff;
    border-top: 1px solid #eef2f6;
}

#kf-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

#kf-input {
    flex: 1;
    border: 1px solid #dde5ee;
    border-radius: 10px;
    padding: 9px 13px;
    font-size: 14px;
    line-height: 1.5;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 96px;
    min-height: 40px;
    background: #fbfdff;
    color: #2b3a4f;
    transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

#kf-input:focus {
    border-color: #45a9f1;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(69, 169, 241, 0.12);
}

#kf-send {
    flex-shrink: 0;
    height: 40px;
    padding: 0 18px;
    background: linear-gradient(135deg, #45a9f1 0%, #6C5CE7 100%);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    cursor: pointer;
    transition: filter 0.15s ease;
}

/* ⚠️ 遵守铁律：hover 仅提亮，禁止位移 */
#kf-send:hover {
    filter: brightness(1.06);
}

#kf-send.kf-dis {
    opacity: 0.5;
    cursor: not-allowed;
}

#kf-tools {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 9px;
}

/* 转人工：统一为品牌蓝描边，弃用与主题冲突的橙色 */
#kf-human {
    border: 1px solid #cfe0fb;
    background: #f3f8ff;
    color: #3d7cc9;
    font-size: 12px;
    padding: 5px 13px;
    border-radius: 14px;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

#kf-human:hover {
    background: #e6f1ff;
    border-color: #45a9f1;
}

#kf-human.kf-dis {
    border-color: #dde5ee;
    background: #f5f8fb;
    color: #a8b7c9;
    cursor: not-allowed;
}

#kf-tip {
    font-size: 11px;
    color: #a8b7c9;
}

/* 移动端：全屏面板 */
@media (max-width: 640px) {
    #kf-root {
        right: 14px;
        bottom: 18px;
    }

    #kf-panel {
        right: 0;
        bottom: 0;
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }

    #kf-root.kf-in-member {
        right: 14px;
        bottom: 18px;
    }
    #kf-root.kf-in-member #kf-panel {
        bottom: 0;
        max-height: 100vh;
    }
    #kf-btn {
        width: 38px;
        height: 132px;
        border-radius: 19px;
        gap: 8px;
        padding: 10px 0 12px;
    }
    #kf-btn svg {
        width: 27px;
        height: 27px;
    }
    #kf-btn-label {
        font-size: 13px;
        gap: 2px;
    }
}
