/* ============================================================
 *  在线客服 聊天页（仿微信气泡）
 * ============================================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
    font-family: "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
    color: #1f2d4d; background: #cfe0f2; display: flex; justify-content: center;
    -webkit-font-smoothing: antialiased;
}
a { text-decoration: none; color: inherit; }
img { display: block; }

.stage { position: relative; width: 393px; height: 100vh; display: flex; flex-direction: column;
    background: #ededed; overflow: hidden; }

/* 顶部栏 */
.kf-nav { flex-shrink: 0; position: relative; height: 52px; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #1877ee, #0a49b8); color: #fff; }
/* 返回按钮：中文文字（原为 ‹ 符号） */
.kf-back { position: absolute; left: 12px; top: 0; height: 52px; display: flex; align-items: center;
    color: #fff; font-size: 15.5px; white-space: nowrap; }
.kf-back:active { opacity: .7; }
.kf-title { font-size: 17px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.kf-state { font-size: 11px; font-weight: 400; padding: 2px 8px; border-radius: 999px; }
.kf-state.on { background: rgba(255, 255, 255, .22); }
.kf-state.off { background: rgba(0, 0, 0, .22); }

/* 消息列表 */
.kf-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 12px 16px; }
.kf-more { margin: 0 auto 12px; width: max-content; padding: 5px 14px; border-radius: 999px;
    background: rgba(0, 0, 0, .06); color: #5c6b86; font-size: 12px; cursor: pointer; }
.kf-tip-card { margin: 0 auto 14px; max-width: 300px; padding: 8px 12px; border-radius: 8px;
    background: rgba(0, 0, 0, .06); color: #5c6b86; font-size: 12px; line-height: 1.6; text-align: center; }

.kf-time { margin: 12px auto 10px; width: max-content; padding: 2px 9px; border-radius: 4px;
    background: rgba(0, 0, 0, .13); color: #fff; font-size: 11px; }

.kf-row { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 14px; }
.kf-row.me { flex-direction: row-reverse; }
.kf-avatar { flex-shrink: 0; width: 36px; height: 36px; border-radius: 5px; display: flex; align-items: center;
    justify-content: center; font-size: 12px; color: #fff; background: #0a55e0; }
.kf-row.me .kf-avatar { background: #7b8aa6; }
.kf-side { max-width: 76%; display: flex; flex-direction: column; align-items: flex-start; }
.kf-row.me .kf-side { align-items: flex-end; }

.kf-bubble { position: relative; padding: 9px 12px; border-radius: 6px; background: #fff; color: #16233f;
    font-size: 15px; line-height: 1.6; word-break: break-word; white-space: pre-wrap;
    box-shadow: 0 1px 2px rgba(20, 40, 80, .07); }
.kf-row.me .kf-bubble { background: #95ec69; color: #10230a; }
.kf-bubble::after { content: ""; position: absolute; top: 11px; border: 6px solid transparent; }
.kf-row:not(.me) .kf-bubble::after { left: -11px; border-right-color: #fff; }
.kf-row.me .kf-bubble::after { right: -11px; border-left-color: #95ec69; }
.kf-bubble.plain { padding: 0; background: none !important; box-shadow: none; }
.kf-bubble.plain::after { display: none; }

/* 图片 / 视频 / 语音 */
.kf-media { max-width: 190px; border-radius: 6px; overflow: hidden; }
.kf-media img { width: 100%; height: auto; cursor: zoom-in; }
.kf-media video { width: 190px; height: auto; border-radius: 6px; background: #000; display: block; }
.kf-voice-bubble { display: flex; align-items: center; gap: 8px; min-width: 82px; cursor: pointer; }
.kf-voice-bubble .vi { width: 14px; height: 16px; flex-shrink: 0;
    background: currentColor; -webkit-mask: center/contain no-repeat; mask: center/contain no-repeat;
    -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M12 15a3 3 0 0 0 3-3V6a3 3 0 0 0-6 0v6a3 3 0 0 0 3 3zm5-3a5 5 0 0 1-10 0H5a7 7 0 0 0 6 6.92V21h2v-2.08A7 7 0 0 0 19 12h-2z'/></svg>");
    mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M12 15a3 3 0 0 0 3-3V6a3 3 0 0 0-6 0v6a3 3 0 0 0 3 3zm5-3a5 5 0 0 1-10 0H5a7 7 0 0 0 6 6.92V21h2v-2.08A7 7 0 0 0 19 12h-2z'/></svg>"); }
.kf-voice-bubble .vd { font-size: 13px; opacity: .75; }
.kf-voice-bubble.playing .vi { animation: kfPulse .9s ease-in-out infinite; }
@keyframes kfPulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* 引用预览（气泡内） */
.kf-quoted { margin-bottom: 6px; padding: 6px 9px; border-left: 3px solid rgba(10, 85, 224, .45);
    background: rgba(0, 0, 0, .05); border-radius: 4px; font-size: 12.5px; color: #5b6a85; line-height: 1.5; }
.kf-row.me .kf-quoted { border-left-color: rgba(16, 35, 10, .35); color: #3d5233; }

/* 状态 */
.kf-meta { margin-top: 4px; font-size: 11px; color: #97a3b8; display: flex; gap: 6px; align-items: center; }
.kf-row.me .kf-meta { justify-content: flex-end; }
.kf-row.pending .kf-bubble { opacity: .65; }
.kf-row.failed .kf-meta { color: #d63b3b; }
.kf-retry { color: #0862ee; cursor: pointer; text-decoration: underline; }

/* 引用条 */
.kf-quote { flex-shrink: 0; display: flex; align-items: center; gap: 10px; padding: 8px 14px;
    background: #f6f8fb; border-top: 1px solid #e2e8f0; font-size: 12.5px; color: #5b6a85; }
/* 必须显式覆盖：hidden 属性会被上面的 display 声明盖掉 */
.kf-quote[hidden] { display: none !important; }
.kq-txt { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kq-x { width: 20px; height: 20px; border-radius: 50%; background: #e4eaf3; color: #5b6a85;
    text-align: center; line-height: 20px; cursor: pointer; flex-shrink: 0; }

/* 输入区 */
.kf-bar { flex-shrink: 0; display: flex; align-items: center; gap: 7px; padding: 9px 10px;
    padding-bottom: calc(9px + env(safe-area-inset-bottom)); background: #f6f8fb; border-top: 1px solid #e2e8f0; }
.kf-ic { width: 34px; height: 34px; flex-shrink: 0; padding: 0; border: 1px solid #d7e0ec; border-radius: 8px;
    background: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.kf-ic img { width: 20px; height: 20px; }
.kf-ic:active { background: #eef3f9; }
.kf-ic[hidden] { display: none !important; }
.kf-ic.hold { background: #dff0ff; border-color: #9cc9f5; }
.kf-ic.hold img { opacity: .85; }
.kf-input { flex: 1; min-width: 0; height: 36px; padding: 0 12px; border: 1px solid #d7e0ec; border-radius: 8px;
    background: #fff; font-size: 15px; color: #1f2d4d; outline: none; font-family: inherit; }
.kf-send { flex-shrink: 0; height: 36px; padding: 0 16px; border: 0; border-radius: 8px;
    background: linear-gradient(135deg, #2f8bff, #0a55e0); color: #fff; font-size: 15px; cursor: pointer; }
.kf-send:disabled { opacity: .5; }

/* 按住说话浮层 */
.kf-rec { position: fixed; inset: 0; z-index: 400; display: flex; align-items: center; justify-content: center;
    background: rgba(0, 0, 0, .35); }
.kf-rec[hidden] { display: none !important; }
.kr-box { width: 172px; padding: 20px 16px 14px; border-radius: 14px; background: rgba(20, 30, 50, .88);
    color: #fff; text-align: center; }
.kr-wave { display: flex; align-items: flex-end; justify-content: center; gap: 4px; height: 34px; }
.kr-wave i { width: 5px; border-radius: 3px; background: #95ec69; animation: kfWave .9s ease-in-out infinite; }
.kr-wave i:nth-child(1) { height: 12px; animation-delay: 0s; }
.kr-wave i:nth-child(2) { height: 22px; animation-delay: .12s; }
.kr-wave i:nth-child(3) { height: 32px; animation-delay: .24s; }
.kr-wave i:nth-child(4) { height: 20px; animation-delay: .36s; }
.kr-wave i:nth-child(5) { height: 13px; animation-delay: .48s; }
@keyframes kfWave { 0%, 100% { transform: scaleY(.45); } 50% { transform: scaleY(1); } }
.kr-time { margin-top: 10px; font-size: 15px; font-family: "Liberation Sans", Arial, sans-serif; }
.kr-tip { margin-top: 4px; font-size: 12px; opacity: .8; }
.kf-rec.cancel .kr-tip { color: #ff9c9c; }
.kf-rec.cancel .kr-wave i { background: #ff9c9c; }

/* 图片大图 */
.kf-viewer { position: fixed; inset: 0; z-index: 500; display: none; align-items: center; justify-content: center;
    background: rgba(0, 0, 0, .9); padding: 16px; }
.kf-viewer.show { display: flex; }
.kf-viewer img { max-width: 100%; max-height: 100%; }

/* 轻提示 */
.toast { position: fixed; left: 50%; top: 44%; transform: translateX(-50%); max-width: 300px; padding: 10px 22px;
    border-radius: 8px; background: rgba(0, 0, 0, .8); color: #fff; font-size: 15px; z-index: 999;
    opacity: 0; transition: opacity .25s; pointer-events: none; text-align: center; }
.toast.show { opacity: 1; }
