/* ============================================
   官网在线客服 · 访客聊天挂件（🔥 2026-11-28）
   类名一律 .kf- 前缀，避免污染主站样式；
   颜色/圆角仅引用 css/style.css 设计令牌。
   ============================================ */

.kf-widget {
    position: fixed;
    right: 74px;  /* 让开右侧联系工具条（.side-toolbar 宽 64px） */
    bottom: 18px;
    width: 320px;
    height: 460px;
    max-height: calc(100vh - 36px);
    display: none;
    flex-direction: column;
    background: var(--bg-dark-2);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 14px;
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.5);
    z-index: 10000;
    overflow: hidden;
}

.kf-widget.open {
    display: flex;
}

/* 分类/历史视图：高度自适应内容（聊天视图仍固定高度，消息区才有滚动空间）。
   仅默认态生效——放大/自由拖动态的内联 height 优先级更高，不受影响 */
.kf-widget.catmode {
    height: auto;
}

/* 顶栏（🔥 2026-11-28 兼作拖动把手） */
.kf-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 14px;
    background: rgba(255, 255, 255, 0.04);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    user-select: none;
    cursor: move;
    touch-action: none;
}

/* 🔥 放大/缩小切换按钮（放大 = 页面居中大窗；缩小 = 回到默认右下角） */
.kf-max {
    display: inline-flex;
    background: none;
    border: none;
    color: var(--text-white-secondary);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
}

.kf-max svg {
    width: 14px;
    height: 14px;
}

.kf-max:hover {
    color: var(--text-white);
    background: rgba(255, 255, 255, 0.08);
}

/* 🔥 is-max 类只负责图标切换与输入框高度（窗口布局一律走 JS 内联几何，单一控制源） */
.kf-icon-restore {
    display: none;
}

.kf-widget.is-max .kf-icon-restore {
    display: block;
}

.kf-widget.is-max .kf-icon-expand {
    display: none;
}

/* 放大态输入框更高 */
.kf-widget.is-max .kf-input textarea {
    height: 170px;
}

/* 🔥 右下角缩放把手（可见斜纹，拖动调整窗口大小） */
.kf-resize {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 18px;
    height: 18px;
    cursor: nwse-resize;
    touch-action: none;
    z-index: 5;
}

.kf-resize::before {
    content: '';
    position: absolute;
    right: 4px;
    bottom: 4px;
    width: 9px;
    height: 9px;
    border-right: 2px solid rgba(255, 255, 255, 0.4);
    border-bottom: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 0 0 3px 0;
}

.kf-resize:hover::before {
    border-color: rgba(255, 255, 255, 0.8);
}

.kf-head-title {
    flex: 1;  /* 🔥 占满剩余空间，让放大/关闭两个按钮成组靠右（否则 space-between 会把放大钮挤到中间） */
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-white);
}

.kf-close {
    background: none;
    border: none;
    color: var(--text-white-secondary);
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
}

.kf-close:hover {
    color: var(--text-white);
    background: rgba(255, 255, 255, 0.08);
}/* 面板内容区 */
.kf-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* —— 分类选择视图 —— */
.kf-cat-view {
    padding: 14px;
    overflow-y: auto;
}

.kf-cat-hint {
    font-size: 0.78rem;
    color: var(--text-white-secondary);
    margin-bottom: 10px;
    line-height: 1.6;
}

.kf-cat-item {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    margin-bottom: 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    color: var(--text-white);
    font-size: 0.88rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.kf-cat-item:hover {
    border-color: var(--grad-primary);
    background: rgba(255, 255, 255, 0.09);
}

.kf-cat-online {
    font-size: 0.72rem;
    color: var(--text-white-secondary);
}

.kf-cat-online .kf-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #6b7280;
    margin-right: 5px;
    vertical-align: 1px;
}

.kf-cat-online.is-on .kf-dot {
    background: #12b76a;
}

/* 分类选择视图底部的公众号关注提示（方案C：离线触达兜底） */
.kf-gzh-hint {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
}

.kf-gzh-hint img {
    flex: 0 0 56px;
    width: 56px;
    height: 56px;
    border-radius: 6px;
    background: #fff;
}

.kf-gzh-hint span {
    font-size: 0.74rem;
    color: var(--text-white-secondary);
    line-height: 1.6;
}

/* —— 聊天视图 —— */
.kf-chat-view {
    flex: 1;
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.kf-chat-view.show {
    display: flex;
}

/* 状态行：状态文案 + 「切换类型」入口（2026-11-28） */
.kf-status-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: rgba(255, 255, 255, 0.04);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.kf-status {
    flex: 1;
    font-size: 0.75rem;
    color: var(--text-white-secondary);
    line-height: 1.6;
}

.kf-switch {
    flex: none;
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-sm);
    color: var(--text-white-secondary);
    font-size: 0.68rem;
    padding: 3px 8px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.kf-switch:hover {
    color: var(--text-white);
    border-color: var(--grad-primary);
}

.kf-msgs {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.kf-msg {
    max-width: 82%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 0.85rem;
    line-height: 1.6;
    word-break: break-word;
    white-space: pre-wrap;
}

.kf-msg.visitor {
    align-self: flex-end;
    background: var(--grad-primary);
    color: var(--text-white);
    border-bottom-right-radius: 4px;
}

.kf-msg.agent {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-white);
    border-bottom-left-radius: 4px;
}

.kf-msg.system {
    align-self: center;
    background: none;
    color: var(--text-white-secondary);
    font-size: 0.72rem;
    padding: 2px 6px;
}

.kf-msg .kf-sender {
    display: block;
    font-size: 0.68rem;
    opacity: 0.7;
    margin-bottom: 2px;
}

/* 输入区（🔥 2026-11-28 改竖排：输入框独占一行并加高，发送按钮单独一行靠右） */
.kf-input {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.04);
}

.kf-input textarea {
    width: 100%;
    resize: none;
    height: 76px;  /* 默认 3~4 行即可（放大态另调高） */
    padding: 8px 10px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-white);
    font-size: 0.85rem;
    font-family: inherit;
    outline: none;
}

.kf-input textarea:focus {
    border-color: var(--grad-primary);
}

.kf-input button {
    align-self: flex-end;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--grad-primary);
    color: var(--text-white);
    font-size: 0.82rem;
    cursor: pointer;
}

.kf-input button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 🔥 2026-11-29 输入区底部按钮行（图片 + 发送） */
.kf-input-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.kf-input .kf-img-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--text-white-secondary);
    font-size: 0.78rem;
    padding: 6px 12px;
}

.kf-input .kf-img-btn:hover:not(:disabled) {
    color: var(--text-white);
    border-color: var(--grad-primary);
}

/* 🔥 2026-11-29 图片消息气泡（点击原图） */
.kf-msg-img {
    display: block;
    max-width: 220px;
    max-height: 220px;
    border-radius: 8px;
    cursor: zoom-in;
    margin-top: 2px;
}

/* 联系工具条上的未读角标（2026-11-28 入口改为右侧 .side-tool-item） */
.kf-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: #e5484d;
    color: #fff;
    font-size: 0.68rem;
    line-height: 18px;
    text-align: center;
}

/* 移动端：宽度贴边（可覆盖在工具条之上，挂件 z-index 更高）；
   拖动/缩放/放大按钮均禁用，保持贴边布局 */
@media (max-width: 768px) {
    .kf-widget {
        right: 12px;
        left: 12px;
        width: auto;
        bottom: 86px;
    }

    .kf-head {
        cursor: default;
    }

    .kf-max {
        display: none;
    }

    .kf-resize {
        display: none;
    }
}
