/* ============================================================
   在线客服 · 客户端对话页（全新设计）
   自包含样式：本页不加载 app.css / admin-theme.css
   移动端与桌面端共用同一套结构与观感，仅随视口流式缩放
   ============================================================ */

/* ---------- 设计变量 ---------- */
.kf-page {
    --brand: #2563eb;
    --brand-600: #1d4ed8;
    --brand-500: #3b82f6;
    --brand-50: #eff6ff;
    --brand-100: #dbeafe;
    --brand-grad: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    --ink: #0f172a;
    --text: #1f2937;
    --muted: #8a94a6;
    --line: #e8eef8;
    --surface: #ffffff;
    --canvas: #f4f7fc;
    --radius: 16px;
    --shadow-card: 0 26px 60px -24px rgba(15, 23, 42, .38), 0 6px 18px rgba(15, 23, 42, .06);
    --shadow-bubble: 0 2px 10px rgba(15, 23, 42, .05);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

.kf-page {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(8px, 2.2vw, 22px);
    font-family: "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", "微软雅黑",
                 -apple-system, "Segoe UI", system-ui, sans-serif;
    color: var(--text);
    background:
        radial-gradient(1200px 700px at 50% -18%, #e7f0ff 0%, rgba(231, 240, 255, 0) 62%),
        radial-gradient(900px 600px at 88% 108%, #eef2ff 0%, rgba(238, 242, 255, 0) 60%),
        #eef2f8;
    -webkit-font-smoothing: antialiased;
}

/* ---------- 对话外壳：手机 / 电脑统一为同一张卡片 ---------- */
.kf-shell {
    position: relative;
    width: 100%;
    max-width: 880px;
    height: calc(100vh - 2 * clamp(8px, 2.2vw, 22px));
    height: calc(100dvh - 2 * clamp(8px, 2.2vw, 22px));
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-radius: clamp(14px, 2.2vw, 20px);
    box-shadow: var(--shadow-card);
    overflow: hidden;
}

/* ---------- 顶部栏 ---------- */
.kf-top {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: clamp(12px, 2vw, 16px) clamp(14px, 2.4vw, 22px);
    background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
    border-bottom: 1px solid var(--line);
}

.kf-top-avatar {
    flex: 0 0 auto;
    width: clamp(42px, 6vw, 48px);
    height: clamp(42px, 6vw, 48px);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: 14px;
    background: var(--brand-grad);
    color: #fff;
    font-size: clamp(16px, 2.4vw, 19px);
    font-weight: 700;
    box-shadow: 0 8px 18px -10px rgba(37, 99, 235, .85);
    user-select: none;
}
.kf-top-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.kf-top-info { min-width: 0; flex: 1 1 auto; }
.kf-top-title {
    font-size: clamp(15px, 1.9vw, 16.5px);
    font-weight: 700;
    color: var(--ink);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.kf-top-sub {
    margin-top: 3px;
    font-size: clamp(11.5px, 1.5vw, 12.5px);
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kf-top-status {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 13px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    color: var(--brand);
    background: var(--brand-50);
    border: 1px solid var(--brand-100);
}
.kf-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 0 3px rgba(34, 197, 94, .16);
}
.is-closed .kf-dot,
.kf-dot.dot-off { background: #9ca3af; box-shadow: 0 0 0 3px rgba(156, 163, 175, .16); }
.is-closed .kf-top-status { color: #6b7280; background: #f3f4f6; border-color: #e5e7eb; }

/* 客服端：返回按钮 */
.kf-back {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    line-height: 1;
    color: var(--brand);
    text-decoration: none;
    background: var(--brand-50);
    border-radius: 10px;
    transition: background .16s;
}
.kf-back:hover { background: var(--brand-100); }

/* 客服端：顶栏操作按钮 */
.kf-actions {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.kf-mini {
    height: 30px;
    padding: 0 11px;
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
    border-radius: 9px;
    font: inherit;
    font-size: 12.5px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background .16s, border-color .16s, color .16s;
}
.kf-mini:hover { background: var(--brand-50); border-color: var(--brand-100); color: var(--brand); }
.kf-mini.danger:hover { background: #fef2f2; border-color: #fecaca; color: #dc2626; }
.kf-mini-form { display: inline; margin: 0; }

/* 客服端：快捷回复条 */
.quick-bar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px clamp(12px, 2.2vw, 18px);
    overflow-x: auto;
    background: #fff;
    border-top: 1px solid var(--line);
    scrollbar-width: none;
}
.quick-bar::-webkit-scrollbar { display: none; }
.quick-chip {
    flex: 0 0 auto;
    height: 30px;
    max-width: 180px;
    padding: 0 13px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #f6f9ff;
    color: #4b5563;
    font: inherit;
    font-size: 12.5px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background .16s, color .16s, border-color .16s;
}
.quick-chip:hover { background: var(--brand-50); border-color: var(--brand-100); color: var(--brand); }
.quick-chip:disabled { opacity: .5; cursor: default; }
.quick-ico { margin-right: 3px; }
.quick-manage {
    flex: 0 0 auto;
    margin-left: auto;
    font-size: 12px;
    color: var(--muted);
    text-decoration: none;
}
.quick-manage:hover { color: var(--brand); }

/* ---------- 消息流 ---------- */
.kf-stream {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding: clamp(14px, 2.6vw, 24px);
    background-color: var(--canvas);
    background-image:
        radial-gradient(circle at 12% 6%, rgba(37, 99, 235, .05), transparent 42%),
        radial-gradient(circle at 90% 96%, rgba(37, 99, 235, .055), transparent 46%);
    -webkit-overflow-scrolling: touch;
}
.kf-stream::-webkit-scrollbar { width: 8px; }
.kf-stream::-webkit-scrollbar-thumb { background: #dbe3f0; border-radius: 8px; }
.kf-stream::-webkit-scrollbar-thumb:hover { background: #c7d3e6; }

@keyframes kf-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: none; }
}

.msg-row { max-width: 100%; margin-bottom: clamp(14px, 2vw, 18px); animation: kf-in .26s cubic-bezier(.2, .8, .3, 1) both; }
.msg-row:last-child { margin-bottom: 4px; }

/* 居中的时间分隔条 */
.msg-time-divider {
    margin: clamp(16px, 2.4vw, 22px) auto clamp(10px, 1.6vw, 14px);
    text-align: center;
    font-size: 12px;
    color: #a2acbc;
    letter-spacing: .2px;
    user-select: none;
}
.msg-time-divider:first-child { margin-top: 2px; }

/* ---------- 消息行方向（客户页与客服页共用） ---------- */
/* 左侧（对方）：头像在左，名称在上、气泡在下 */
.msg-row.left {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    max-width: 86%;
    margin-right: auto;
}
.msg-row.left .msg-col { flex: 1 1 auto; align-items: flex-start; }

/* 右侧（自己）：整体右对齐 */
.msg-row.right {
    display: flex;
    justify-content: flex-end;
    margin-left: auto;
    max-width: 86%;
}
.msg-row.right .msg-col { align-items: flex-end; }

/* 头像（不带在线状态点） */
.msg-avatar {
    flex: 0 0 auto;
    width: clamp(38px, 5.4vw, 44px);
    height: clamp(38px, 5.4vw, 44px);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: 50%;
    background: var(--brand-grad);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    user-select: none;
}
.msg-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* 名称 + 对话内容列 */
.msg-col {
    display: flex;
    flex-direction: column;
    min-width: 0;
    max-width: 100%;
}
.msg-author {
    margin: 0 0 6px 2px;
    font-size: 12.5px;
    line-height: 1.4;
    color: var(--muted);
}
.msg-row.right .msg-author { margin: 0 2px 6px 0; text-align: right; }

/* ---------- 气泡 ---------- */
.bubble {
    width: fit-content;
    max-width: 100%;
    padding: 11px 15px;
    font-size: 15px;
    line-height: 1.62;
    border-radius: 16px;
    word-break: break-word;
    white-space: pre-wrap;
}

/* 气泡圆角尾巴：左侧消息尾在左上，右侧消息尾在右上 */
.msg-row.left .bubble { border-top-left-radius: 6px; }
.msg-row.right .bubble { border-top-right-radius: 6px; }

/* 客服方消息（.from-admin）：品牌蓝渐变气泡 */
.msg-row.from-admin .bubble {
    background: var(--brand-grad);
    color: #fff;
    border: none;
    box-shadow: 0 10px 20px -12px rgba(37, 99, 235, .9);
}
/* 对方消息（.from-customer）：白底浅描边气泡 */
.msg-row.from-customer .bubble {
    background: #fff;
    color: var(--text);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-bubble);
}
.msg-row.from-customer .bubble a { color: var(--brand); }

/* 图片气泡 */
.bubble-image {
    padding: 5px;
    background: #fff !important;
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow-bubble);
    line-height: 0;
}
.msg-image { display: block; max-width: 240px; max-height: 300px; border-radius: 10px; cursor: zoom-in; }

/* 文件气泡 */
.file-bubble {
    display: inline-flex;
    align-items: center;
    gap: 11px;
    text-decoration: none;
    padding: 11px 15px;
    background: #fff !important;
    border: 1px solid var(--line);
    border-radius: 14px;
    color: var(--text);
    box-shadow: var(--shadow-bubble);
}
.msg-row.from-admin .file-bubble {
    background: var(--brand-grad) !important;
    border: none;
    color: #fff;
    box-shadow: 0 10px 20px -12px rgba(37, 99, 235, .9);
}
.file-icon { font-size: 24px; line-height: 1; }
.file-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.file-name { font-size: 14px; font-weight: 600; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { font-size: 12px; opacity: .8; }
.msg-row.from-customer .file-size { color: var(--muted); }

/* 时间（仅客服工作台视图使用；客户页时间改为居中的 .msg-time-divider） */
.msg-time { margin-top: 5px; padding: 0 4px; font-size: 11px; color: #9aa6b8; }
.msg-row.left .msg-time { text-align: left; padding-left: 2px; }
.msg-row.right .msg-time { text-align: right; padding-right: 2px; }

/* ---------- 输入区 ---------- */
.kf-composer {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: clamp(10px, 1.8vw, 14px) clamp(12px, 2.2vw, 18px);
    padding-bottom: calc(clamp(10px, 1.8vw, 14px) + env(safe-area-inset-bottom));
    background: #fff;
    border-top: 1px solid var(--line);
}
.kf-composer textarea {
    flex: 1 1 auto;
    /* 高度与两侧按钮严格一致：1 行文本 = 44px（含内边距与描边） */
    height: 44px;
    min-height: 44px;
    max-height: 130px;
    padding: 10px 16px;
    font: inherit;
    font-size: 15px;
    line-height: 1.4;
    color: var(--text);
    background: #f3f6fc;
    border: 1.5px solid transparent;
    border-radius: 22px;
    outline: none;
    resize: none;
    transition: background .16s, border-color .16s, box-shadow .16s;
}
.kf-composer textarea::placeholder { color: #a7b1c2; }
.kf-composer textarea:focus {
    background: #fff;
    border-color: var(--brand);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, .12);
}

.kf-attach {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #f3f6fc;
    color: var(--brand);
    cursor: pointer;
    user-select: none;
    transition: background .16s, transform .16s;
}
.kf-attach:hover { background: var(--brand-50); transform: translateY(-1px); }
.kf-attach-plus {
    font-size: 26px;
    font-weight: 300;
    line-height: 1;
    margin-top: -2px;
}

.kf-send {
    flex: 0 0 auto;
    height: 44px;
    padding: 0 24px;
    border: none;
    border-radius: 22px;
    font: inherit;
    font-size: 15px;
    font-weight: 600;
    color: #fff;
    background: var(--brand-grad);
    cursor: pointer;
    box-shadow: 0 10px 20px -10px rgba(37, 99, 235, .95);
    transition: filter .16s, transform .16s;
}
.kf-send:hover { filter: brightness(1.05); transform: translateY(-1px); }
.kf-send:active { transform: translateY(0); }

/* 会话已结束 */
.kf-closed {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-size: 13.5px;
    color: var(--muted);
}

/* ---------- 通用按钮 ---------- */
.kf-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 42px;
    padding: 0 22px;
    border: none;
    border-radius: 21px;
    font: inherit;
    font-size: 14.5px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: filter .16s, transform .16s;
}
.kf-btn-primary { color: #fff; background: var(--brand-grad); box-shadow: 0 10px 20px -10px rgba(37, 99, 235, .95); }
.kf-btn-primary:hover { filter: brightness(1.05); transform: translateY(-1px); }
.kf-btn-sm { height: 36px; padding: 0 18px; font-size: 13.5px; flex: 0 0 auto; }

/* ---------- 上传进度 ---------- */
.kf-progress {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    height: 3px;
    background: var(--brand-100);
    overflow: hidden;
}
.kf-progress > span {
    display: block;
    height: 100%;
    width: 0;
    background: var(--brand-grad);
    transition: width .18s ease;
}

/* ---------- 图片灯箱 ---------- */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 99;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(9, 14, 26, .86);
    backdrop-filter: blur(4px);
}
.lightbox.is-open { display: flex; }
.lightbox img { max-width: 92vw; max-height: 88vh; border-radius: 12px; box-shadow: 0 30px 80px rgba(0, 0, 0, .5); }
.lightbox-close {
    position: absolute;
    top: 18px;
    right: 22px;
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    line-height: 1;
    color: #fff;
    background: rgba(255, 255, 255, .16);
    border-radius: 50%;
    cursor: pointer;
}

/* ---------- 会话失效页 ---------- */
.kf-empty {
    width: 100%;
    max-width: 420px;
    padding: clamp(28px, 6vw, 44px);
    text-align: center;
    background: #fff;
    border-radius: 20px;
    box-shadow: var(--shadow-card);
}
.kf-empty-badge { font-size: 46px; line-height: 1; margin-bottom: 14px; }
.kf-empty-title { margin: 0 0 8px; font-size: 20px; font-weight: 700; color: var(--ink); }
.kf-empty-sub { margin: 0 0 24px; font-size: 14px; line-height: 1.7; color: var(--muted); }

/* ---------- 无障碍 ---------- */
@media (prefers-reduced-motion: reduce) {
    .msg-row { animation: none; }
    .kf-btn, .kf-send, .kf-attach { transition: none; }
}
