/* ==========================================================================
   在线客服 · 聊天窗样式（运行于 iframe 内部，天然与宿主页面隔离）
   ========================================================================== */
:root {
    --kf-primary: #2F6BFF;
    --kf-primary-dark: #1F55DB;
    --kf-text: #1F2937;
    --kf-sub: #6B7280;
    --kf-placeholder: #9CA3AF;
    --kf-line: #E5E7EB;
    --kf-bg: #F5F7FA;
    --kf-bubble: #FFFFFF;
    --kf-danger: #EF4444;
    --kf-success: #22C55E;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* 用 hidden 属性控制显隐时必须提升优先级，避免被组件的 display 覆盖 */
[hidden] { display: none !important; }

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    background: transparent;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
                 "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: var(--kf-text);
}

button { font-family: inherit; cursor: pointer; }
img { display: block; max-width: 100%; }

/* ---------- 隐藏测量探针 ---------- */
.kf-measure {
    position: absolute;
    left: -9999px;
    top: -9999px;
    white-space: nowrap;
    visibility: hidden;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0 22px;
    height: 60px;
    font-size: 15px;
    font-weight: 500;
}

/* 测量探针中的图标需要与真实按钮保持同样尺寸，否则测出的宽度会偏小 */
.kf-measure .kf-launcher-icon {
    width: 20px;
    height: 20px;
    display: inline-block;
}

/* ---------- 收起态：浮窗按钮 ---------- */
.kf-launcher {
    position: absolute;
    right: 0;
    bottom: 0;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 22px;
    border: 0;
    border-radius: 30px;
    color: #fff;
    font-size: 15px;
    font-weight: 500;
    white-space: nowrap;
    background: linear-gradient(135deg, var(--kf-primary) 0%, var(--kf-primary-dark) 100%);
    box-shadow: 0 6px 20px rgba(47, 107, 255, .35);
    transition: transform .15s ease, box-shadow .15s ease;
    overflow: visible;
}
.kf-launcher:hover { transform: translateY(-2px); box-shadow: 0 10px 26px rgba(47, 107, 255, .45); }
.kf-launcher:active { transform: translateY(0) scale(.98); }
.kf-launcher-icon { display: inline-flex; align-items: center; }
.kf-launcher-text { display: inline-block; }

.kf-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--kf-danger);
    color: #fff;
    font-size: 12px;
    line-height: 20px;
    text-align: center;
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(239, 68, 68, .45);
}

/* ---------- 收起态提示气泡 ---------- */
.kf-tip {
    position: absolute;
    right: 0;
    bottom: 72px;
    max-width: 230px;
    padding: 9px 14px;
    background: #fff;
    color: var(--kf-text);
    border-radius: 10px;
    font-size: 13px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .12);
    animation: kf-fade-in .25s ease;
}
.kf-tip-arrow {
    position: absolute;
    right: 30px;
    bottom: -6px;
    width: 12px;
    height: 12px;
    background: #fff;
    transform: rotate(45deg);
    box-shadow: 3px 3px 6px rgba(0, 0, 0, .05);
}
@keyframes kf-fade-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- 展开态：面板 ---------- */
.kf-panel {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--kf-bg);
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, .16);
}

/* 头部 */
.kf-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: linear-gradient(135deg, var(--kf-primary) 0%, var(--kf-primary-dark) 100%);
    color: #fff;
}
.kf-header-avatar {
    position: relative;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .22);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
    flex: 0 0 auto;
}
.kf-header-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.kf-header-avatar-txt { font-size: 16px; font-weight: 600; }
.kf-dot {
    position: absolute;
    right: -1px;
    bottom: -1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #9CA3AF;
    border: 2px solid var(--kf-primary);
}
.kf-dot.online { background: var(--kf-success); }

.kf-header-info { flex: 1 1 auto; min-width: 0; }
.kf-header-title {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.kf-header-sub { font-size: 12px; opacity: .85; }

.kf-hbtn {
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 6px;
    background: rgba(255, 255, 255, .16);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s ease;
}
.kf-hbtn:hover { background: rgba(255, 255, 255, .3); }

/* 消息区 */
.kf-body {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 14px 12px 6px;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}
.kf-body::-webkit-scrollbar { width: 6px; }
.kf-body::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, .14); border-radius: 3px; }

.kf-loading,
.kf-empty {
    text-align: center;
    color: var(--kf-placeholder);
    font-size: 13px;
    padding: 30px 0;
}
/* 连接失败后的可点击重试入口 */
.kf-loading-retry {
    color: var(--kf-primary);
    cursor: pointer;
    text-decoration: underline;
}

/* ===== 消息扩展：引用 / 撤回 / 视频 / 操作按钮 ===== */

/* 气泡内的引用块，点击可跳到原消息 */
.kf-quote {
    display: block;
    margin-bottom: 6px;
    padding: 6px 8px;
    border-left: 3px solid var(--kf-primary);
    background: rgba(0, 0, 0, .05);
    border-radius: 4px;
    font-size: 12px;
    line-height: 1.5;
    cursor: pointer;
}
.kf-quote-who { color: var(--kf-primary); font-weight: 600; }
.kf-quote-text { color: var(--kf-placeholder); }

/* 撤回后的占位（双方都只看得到这一行文字） */
.kf-msg-revoked {
    text-align: center;
    margin: 10px 0;
    color: var(--kf-placeholder);
    font-size: 12px;
}

/* 视频消息 */
.kf-bubble .kf-video {
    display: block;
    max-width: 220px;
    max-height: 260px;
    border-radius: 8px;
    background: #000;
}

/* 消息操作按钮：桌面悬停出现，触屏设备常驻半透明 */
.kf-acts {
    display: inline-flex;
    gap: 8px;
    margin-left: 8px;
    opacity: 0;
    transition: opacity .15s ease;
}
.kf-msg:hover .kf-acts { opacity: 1; }
.kf-act {
    border: 0;
    padding: 2px 4px;
    background: none;
    color: var(--kf-placeholder);
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
}
.kf-act:hover { color: var(--kf-primary); }
/* 「再点一次撤回」的确认态 */
.kf-act-danger { color: #EF4444 !important; font-weight: 600; }

/* 引用跳转后的短暂高亮 */
.kf-msg-hit .kf-bubble {
    box-shadow: 0 0 0 2px var(--kf-primary);
}

/* 编辑器上方的引用条 */
.kf-quote-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: rgba(0, 0, 0, .05);
    border-left: 3px solid var(--kf-primary);
    font-size: 12px;
    color: var(--kf-placeholder);
}
.kf-quote-bar-label { flex: none; color: var(--kf-primary); font-weight: 600; }
.kf-quote-bar-text {
    flex: 1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.kf-quote-bar-close {
    flex: none;
    padding: 0 2px;
    border: 0;
    background: none;
    color: var(--kf-placeholder);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
}
.kf-quote-bar-close:hover { color: #EF4444; }

/* 触屏设备没有 hover，操作按钮直接常驻，否则用户根本点不到 */
@media (hover: none) {
    .kf-acts { opacity: .9; gap: 4px; }
    /* 常驻还不够：必须自己撑出足够的点击面积，否则 12px 的小字总是点空 */
    .kf-act { padding: 8px 10px; font-size: 13px; }
}

@media (max-width: 768px) {
    .kf-bubble .kf-video { max-width: 62vw; }
}

.kf-time-line {
    text-align: center;
    margin: 12px 0 10px;
}
.kf-time-line span {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 10px;
    background: rgba(0, 0, 0, .06);
    color: var(--kf-sub);
    font-size: 12px;
}

.kf-msg {
    display: flex;
    margin-bottom: 12px;
    align-items: flex-start;
    gap: 8px;
}
.kf-msg-visitor { flex-direction: row-reverse; }

.kf-avatar {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--kf-primary);
    color: #fff;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.kf-avatar img { width: 100%; height: 100%; object-fit: cover; }

.kf-bubble-wrap { max-width: 72%; display: flex; flex-direction: column; }
.kf-msg-visitor .kf-bubble-wrap { align-items: flex-end; }

.kf-bubble {
    position: relative;
    padding: 9px 13px;
    border-radius: 12px;
    background: var(--kf-bubble);
    color: var(--kf-text);
    word-break: break-word;
    white-space: pre-wrap;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .06);
    border-top-left-radius: 4px;
}
.kf-msg-visitor .kf-bubble {
    background: var(--kf-primary);
    color: #fff;
    border-top-left-radius: 12px;
    border-top-right-radius: 4px;
}
.kf-bubble img {
    display: block;
    max-width: 190px;
    max-height: 220px;
    /* 最小尺寸兜底：加载中或失败时不会把气泡塌成一条线 */
    min-width: 64px;
    min-height: 44px;
    border-radius: 8px;
    background: rgba(0, 0, 0, .06);
    cursor: zoom-in;
}
.kf-bubble .kf-img-fail { font-size: 13px; opacity: .8; }
.kf-bubble a { color: inherit; text-decoration: underline; word-break: break-all; }

.kf-meta {
    font-size: 11px;
    color: var(--kf-placeholder);
    margin-top: 4px;
    padding: 0 2px;
    display: flex;
    align-items: center;
    gap: 4px;
}
.kf-msg-visitor .kf-meta { justify-content: flex-end; }

.kf-state { font-size: 11px; }
.kf-state-pending { color: var(--kf-placeholder); }
.kf-state-failed { color: var(--kf-danger); cursor: pointer; text-decoration: underline; }
.kf-state-read { color: var(--kf-primary); }

.kf-msg-system {
    text-align: center;
    margin: 10px 0;
}
.kf-msg-system span {
    display: inline-block;
    max-width: 88%;
    padding: 5px 12px;
    border-radius: 8px;
    background: rgba(0, 0, 0, .05);
    color: var(--kf-sub);
    font-size: 12px;
    word-break: break-word;
    white-space: pre-wrap;
}

/* 正在输入 */
.kf-typing {
    flex: 0 0 auto;
    padding: 2px 16px 6px;
    font-size: 12px;
    color: var(--kf-sub);
}

/* 编辑器 */
.kf-editor {
    flex: 0 0 auto;
    border-top: 1px solid var(--kf-line);
    background: #fff;
    padding: 8px 10px 10px;
}
.kf-tools {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}
.kf-tool {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border: 0;
    background: transparent;
    color: var(--kf-sub);
    font-size: 13px;
    padding: 3px 4px;
    border-radius: 6px;
    transition: color .15s ease, background .15s ease;
}
.kf-tool:hover { color: var(--kf-primary); background: rgba(47, 107, 255, .08); }
.kf-tools-tip { font-size: 12px; color: var(--kf-danger); }

.kf-input {
    width: 100%;
    min-height: 44px;
    max-height: 120px;
    resize: none;
    border: 0;
    outline: none;
    padding: 4px 2px;
    font-size: 14px;
    line-height: 1.6;
    font-family: inherit;
    color: var(--kf-text);
    background: transparent;
}
.kf-input::placeholder { color: var(--kf-placeholder); }

.kf-editor-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.kf-counter { font-size: 12px; color: var(--kf-placeholder); }

.kf-send {
    border: 0;
    border-radius: 6px;
    padding: 7px 20px;
    background: var(--kf-primary);
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    transition: background .15s ease, opacity .15s ease;
}
.kf-send:hover { background: var(--kf-primary-dark); }
.kf-send:disabled { opacity: .45; cursor: not-allowed; }

/* 登录 / 注册（开启「需登录才能咨询」后展示） */
.kf-auth {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    top: var(--kf-header-h);
    overflow-y: auto;
    padding: 20px 18px 18px;
    background: var(--kf-bg);
}
.kf-auth-head { text-align: center; margin-bottom: 16px; }
.kf-auth-title { font-size: 17px; font-weight: 600; color: var(--kf-text); }
.kf-auth-sub { margin-top: 6px; font-size: 12.5px; color: var(--kf-sub); line-height: 1.6; }

.kf-auth-tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: #EAEDF5;
    border-radius: 10px;
    margin-bottom: 14px;
}
.kf-auth-tab {
    flex: 1 1 0;
    height: 34px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--kf-sub);
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
}
.kf-auth-tab.active {
    background: #fff;
    color: var(--kf-primary);
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
}

.kf-auth-error {
    margin-bottom: 12px;
    padding: 9px 12px;
    border-radius: 8px;
    background: #FEF2F2;
    color: #B42318;
    font-size: 13px;
    line-height: 1.5;
}

.kf-auth-form { display: flex; flex-direction: column; gap: 10px; }
.kf-auth-input {
    width: 100%;
    height: 42px;
    padding: 0 13px;
    border: 1px solid var(--kf-line);
    border-radius: 9px;
    /* 16px 不能改小：iOS 上聚焦小于 16px 的输入框会自动放大整个页面 */
    font-size: 16px;
    font-family: inherit;
    color: var(--kf-text);
    background: #fff;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.kf-auth-input:focus {
    border-color: var(--kf-primary);
    box-shadow: 0 0 0 3px rgba(47, 107, 255, .12);
}
.kf-auth-input::placeholder { color: var(--kf-placeholder); }

.kf-auth-codewrap { display: flex; gap: 8px; }
.kf-auth-codewrap .kf-auth-input { flex: 1 1 auto; min-width: 0; }
.kf-auth-codebtn {
    flex: 0 0 auto;
    height: 42px;
    padding: 0 13px;
    border: 1px solid var(--kf-primary);
    border-radius: 9px;
    background: #fff;
    color: var(--kf-primary);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: opacity .15s ease;
}
.kf-auth-codebtn:disabled { opacity: .5; cursor: not-allowed; }

.kf-auth-submit {
    height: 44px;
    margin-top: 4px;
    border: 0;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--kf-primary) 0%, var(--kf-primary-dark) 100%);
    color: #fff;
    font-size: 15px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(47, 107, 255, .28);
    transition: opacity .15s ease;
}
.kf-auth-submit:disabled { opacity: .6; cursor: not-allowed; box-shadow: none; }

.kf-auth-foot {
    margin-top: 14px;
    text-align: center;
    font-size: 12.5px;
    color: var(--kf-sub);
    line-height: 1.9;
}
/* 底部文字链接：忘记密码 / 返回登录 / 退出登录 */
.kf-auth-link {
    padding: 0 6px;
    border: 0;
    background: none;
    color: var(--kf-primary);
    font-size: 12.5px;
    font-family: inherit;
    cursor: pointer;
}
.kf-auth-link:hover { text-decoration: underline; }
.kf-auth-link-danger { color: #B42318; }

/* 留言表单 */
.kf-offline {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    top: var(--kf-header-h);
    background: #fff;
    padding: 18px 16px;
    overflow-y: auto;
}
.kf-offline-head {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 14px;
    color: var(--kf-text);
}
.kf-field { display: block; margin-bottom: 12px; }
.kf-field > span { display: block; font-size: 13px; color: var(--kf-sub); margin-bottom: 5px; }
.kf-field > span i { color: var(--kf-danger); font-style: normal; }
.kf-field input,
.kf-field textarea,
.kf-rate-input {
    width: 100%;
    border: 1px solid var(--kf-line);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 14px;
    font-family: inherit;
    color: var(--kf-text);
    outline: none;
    resize: none;
    background: #fff;
    transition: border-color .15s ease;
}
.kf-field input:focus,
.kf-field textarea:focus,
.kf-rate-input:focus { border-color: var(--kf-primary); }

.kf-field-inline { display: flex; flex-direction: column; }
.kf-field-inline input { flex: 1 1 auto; }
.kf-captcha {
    margin-top: 6px;
    width: 100px;
    height: 34px;
    border-radius: 6px;
    border: 1px solid var(--kf-line);
    cursor: pointer;
    object-fit: cover;
}
.kf-offline-foot {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}
.kf-btn-ghost,
.kf-btn-primary {
    flex: 1 1 0;
    border-radius: 8px;
    padding: 9px 0;
    font-size: 14px;
    border: 1px solid transparent;
    transition: opacity .15s ease, background .15s ease;
}
.kf-btn-ghost { background: #fff; border-color: var(--kf-line); color: var(--kf-sub); }
.kf-btn-ghost:hover { background: #F9FAFB; }
.kf-btn-primary { background: var(--kf-primary); color: #fff; }
.kf-btn-primary:hover { background: var(--kf-primary-dark); }

/* 评价卡片 */
.kf-rate {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    top: var(--kf-header-h);
    background: #fff;
    padding: 20px 16px;
    overflow-y: auto;
}
.kf-rate-title { font-size: 15px; font-weight: 600; margin-bottom: 14px; text-align: center; }
.kf-stars { display: flex; justify-content: center; gap: 8px; margin-bottom: 14px; }
.kf-star {
    font-size: 28px;
    line-height: 1;
    color: #D1D5DB;
    cursor: pointer;
    transition: color .12s ease, transform .12s ease;
}
.kf-star:hover { transform: scale(1.12); }
.kf-star.active { color: #F59E0B; }
.kf-rate-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; justify-content: center; }
.kf-tag {
    padding: 4px 12px;
    border-radius: 14px;
    border: 1px solid var(--kf-line);
    font-size: 12px;
    color: var(--kf-sub);
    cursor: pointer;
    transition: all .15s ease;
}
.kf-tag.active {
    border-color: var(--kf-primary);
    color: var(--kf-primary);
    background: rgba(47, 107, 255, .08);
}
.kf-rate-foot { display: flex; gap: 10px; margin-top: 14px; }

/* 提示 */
.kf-toast {
    position: absolute;
    left: 50%;
    top: 76px;
    transform: translateX(-50%);
    max-width: 84%;
    padding: 8px 16px;
    border-radius: 8px;
    background: rgba(17, 24, 39, .88);
    color: #fff;
    font-size: 13px;
    z-index: 20;
    animation: kf-fade-in .2s ease;
    text-align: center;
}

/* 图片预览 */
.kf-viewer {
    position: fixed;
    left: 0; top: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, .82);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99;
    cursor: zoom-out;
    padding: 20px;
}
.kf-viewer img { max-width: 100%; max-height: 100%; border-radius: 6px; }

/* ==========================================================================
   移动端适配
   --------------------------------------------------------------------------
   安全区说明：
     本页面运行在 iframe 中，而 iOS 只在顶层文档应用安全区，
     所以 iframe 内直接写 env(safe-area-inset-*) 取到的往往是 0。
     因此这里统一使用 CSS 变量 --kf-safe-*，
     该变量由 chat.js 结合「宿主页面探测值」与「iframe 内 env 兜底」计算后写入，
     默认值为 env()，即使脚本未执行也不会错位。
   ========================================================================== */
:root {
    --kf-safe-top: env(safe-area-inset-top, 0px);
    --kf-safe-right: env(safe-area-inset-right, 0px);
    --kf-safe-bottom: env(safe-area-inset-bottom, 0px);
    --kf-safe-left: env(safe-area-inset-left, 0px);
    /* 头部实际高度：桌面 12+38+12 = 62px；移动端因安全区会变化，见下方媒体查询 */
    --kf-header-h: 62px;
}

/* 中等屏幕（平板 / 大屏手机）也按移动端处理 */
@media (max-width: 768px) {
    .kf-panel { border-radius: 0; }

    /*
     * 输入类控件字号必须 ≥ 16px：
     * iOS Safari 在聚焦字号小于 16px 的输入框时会自动放大整个页面，
     * 导致界面错位且无法自动缩回。
     */
    .kf-input,
    .kf-field input,
    .kf-field textarea,
    .kf-rate-input,
    .kf-of-captcha {
        font-size: 16px;
    }

    /* 顶部安全区：灵动岛 / 刘海 */
    .kf-header {
        padding-top: calc(10px + var(--kf-safe-top));
        padding-left: calc(12px + var(--kf-safe-left));
        padding-right: calc(12px + var(--kf-safe-right));
    }

    /* 头部变高后，留言表单与评价卡片的起始位置要同步下移 */
    :root { --kf-header-h: calc(60px + var(--kf-safe-top)); }

    /* 底部安全区：Home Indicator */
    .kf-editor { padding-bottom: calc(8px + var(--kf-safe-bottom)); }
    .kf-offline { padding-bottom: calc(18px + var(--kf-safe-bottom)); }
    .kf-auth { padding-bottom: calc(18px + var(--kf-safe-bottom)); }
    .kf-rate { padding-bottom: calc(20px + var(--kf-safe-bottom)); }

    .kf-body {
        padding-left: calc(12px + var(--kf-safe-left));
        padding-right: calc(12px + var(--kf-safe-right));
    }
    .kf-typing {
        padding-left: calc(16px + var(--kf-safe-left));
        padding-right: calc(16px + var(--kf-safe-right));
    }

    /* 触摸目标不小于 44x44（iOS 人机界面指南） */
    .kf-hbtn { width: 36px; height: 36px; }
    .kf-hbtn svg { width: 18px; height: 18px; }
    .kf-send { padding: 10px 24px; font-size: 15px; }
    .kf-tool { padding: 7px 8px; font-size: 13px; }
    .kf-tag { padding: 7px 15px; font-size: 13px; }
    .kf-star { font-size: 34px; }
    .kf-btn-ghost,
    .kf-btn-primary { padding: 12px 0; font-size: 15px; }
    .kf-captcha { width: 108px; height: 40px; margin-top: 8px; }

    .kf-bubble-wrap { max-width: 78%; }
    .kf-bubble img { max-width: 62vw; }

    /* 移动端不做 hover 位移，避免误触抖动 */
    .kf-launcher:hover { transform: none; box-shadow: 0 6px 20px rgba(47, 107, 255, .35); }
    .kf-star:hover { transform: none; }
}

/* 小屏手机（iPhone SE / iPhone 12 mini 等 320~390 宽） */
@media (max-width: 390px) {
    .kf-bubble-wrap { max-width: 84%; }
    .kf-bubble { padding: 8px 11px; }
    .kf-avatar { width: 28px; height: 28px; font-size: 12px; }
    .kf-header-avatar { width: 34px; height: 34px; }
    .kf-header-title { font-size: 14px; }
    .kf-editor-foot .kf-counter { font-size: 11px; }
    .kf-body { padding: 12px 10px 6px; }
}

/* 横屏 / 键盘弹出后可视高度很小时，压缩头部与输入区，保证消息区可见 */
@media (max-height: 500px) {
    .kf-header {
        padding-top: calc(6px + var(--kf-safe-top));
        padding-bottom: 6px;
    }
    .kf-header-avatar { width: 30px; height: 30px; }
    .kf-header-sub { display: none; }
    .kf-input { min-height: 34px; max-height: 68px; }
    .kf-editor { padding-top: 4px; padding-bottom: calc(4px + var(--kf-safe-bottom)); }
    .kf-tools { margin-bottom: 2px; }
}

/* ==========================================================================
   公告（聊天窗内的信息流）
   --------------------------------------------------------------------------
   与 .kf-offline / .kf-rate 同一套做法：整块覆盖在头部以下，
   这样不需要去动「消息区 / 输入区」的显隐，避免与会话状态逻辑打架。
   ========================================================================== */
.kf-ann {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    top: var(--kf-header-h);
    background: #fff;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 5;                      /* 盖住消息区与输入区；toast(20) / 图片预览(99) 仍在其上 */
}
.kf-ann-head {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--kf-line);
    background: #fff;
    position: sticky; top: 0; z-index: 2;
}
.kf-ann-back {
    width: 30px; height: 30px; flex: 0 0 auto;
    border: 0; border-radius: 6px; background: transparent;
    color: var(--kf-text); cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
}
.kf-ann-back:hover { background: var(--kf-bg); }
.kf-ann-headtitle { font-size: 15px; font-weight: 600; }

.kf-ann-list { padding: 10px 12px 4px; }
.kf-ann-item {
    border: 1px solid var(--kf-line); border-radius: 10px;
    padding: 12px; margin-bottom: 12px; background: #fff;
}
.kf-ann-itemhead { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.kf-ann-top {
    font-size: 11px; color: #fff; background: var(--kf-primary);
    border-radius: 4px; padding: 1px 6px;
}
.kf-ann-itemtime { font-size: 12px; color: var(--kf-placeholder); }
.kf-ann-itemtitle { font-size: 15px; font-weight: 600; margin-bottom: 6px; word-break: break-word; }
.kf-ann-body { font-size: 14px; line-height: 1.75; color: var(--kf-text); }
.kf-ann-p { margin: 0 0 8px; white-space: pre-wrap; word-break: break-word; }
.kf-ann-p:last-child { margin-bottom: 0; }
.kf-ann-img {
    max-width: 100%; display: block; margin: 8px 0;
    border-radius: 8px; background: var(--kf-bg); cursor: zoom-out;
}
.kf-ann-video {
    max-width: 100%; display: block; margin: 8px 0;
    border-radius: 8px; background: #000;
}

.kf-ann-acts { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.kf-ann-like {
    border: 1px solid var(--kf-line); background: #fff; color: var(--kf-sub);
    border-radius: 14px; padding: 3px 12px; font-size: 12.5px;
    font-family: inherit; cursor: pointer;
}
.kf-ann-like.on { background: var(--kf-primary); border-color: var(--kf-primary); color: #fff; }

.kf-ann-cmts { margin-top: 4px; }
.kf-ann-cmt { background: var(--kf-bg); border-radius: 8px; padding: 8px 10px; margin-top: 6px; }
.kf-ann-cmt-body { font-size: 13.5px; white-space: pre-wrap; word-break: break-word; }
.kf-ann-cmttime { font-size: 11px; color: var(--kf-placeholder); margin-top: 2px; }
.kf-ann-cmtreply {
    margin-top: 6px; padding: 6px 8px;
    border-left: 3px solid var(--kf-primary); background: #fff;
    border-radius: 0 6px 6px 0; font-size: 13px;
    white-space: pre-wrap; word-break: break-word;
}
.kf-ann-replylabel { color: var(--kf-primary); font-weight: 600; }

.kf-ann-form { display: flex; gap: 8px; margin-top: 10px; }
.kf-ann-input {
    flex: 1 1 auto; min-width: 0; height: 34px; padding: 0 10px;
    border: 1px solid var(--kf-line); border-radius: 8px;
    font-size: 16px;               /* 16px 以下 iOS 会放大输入框，导致布局抖动 */
    font-family: inherit; color: var(--kf-text); background: #fff;
}
.kf-ann-input:focus { outline: none; border-color: var(--kf-primary); }
.kf-ann-send {
    flex: 0 0 auto; height: 34px; padding: 0 14px;
    border: 0; border-radius: 8px; background: var(--kf-primary);
    color: #fff; font-size: 13px; font-family: inherit; cursor: pointer;
}
.kf-ann-send:disabled { opacity: .6; cursor: default; }
.kf-ann-priv { font-size: 11.5px; color: var(--kf-placeholder); margin-top: 8px; }

.kf-ann-status {
    padding: 12px 14px; font-size: 13px; text-align: center;
    color: var(--kf-placeholder);
}
.kf-ann-retry {
    margin-left: 8px; border: 1px solid var(--kf-line); border-radius: 6px;
    background: #fff; color: var(--kf-primary);
    padding: 2px 10px; font-size: 12px; font-family: inherit; cursor: pointer;
}
.kf-ann-foot { padding: 0 12px calc(16px + env(safe-area-inset-bottom, 0px)); }
.kf-ann-foot .kf-btn-ghost { width: 100%; }

/* 头部按钮上的未读红点（公告入口） */
.kf-hbtn { position: relative; }
.kf-hbtn-dot {
    position: absolute; top: 2px; right: 2px;
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--kf-danger); border: 1px solid #fff;
}

/* 小屏：头部多了一个按钮，标题区再收一点，避免换行 */
@media (max-width: 390px) {
    .kf-ann-item { padding: 10px; }
}

/* 触摸设备：去掉会延迟点击的 300ms 与点击高亮 */
@media (hover: none) and (pointer: coarse) {
    .kf-launcher,
    .kf-send,
    .kf-tool,
    .kf-hbtn,
    .kf-btn-primary,
    .kf-btn-ghost,
    .kf-tag,
    .kf-star {
        touch-action: manipulation;
    }
}
