/* ============================================================
   访客端样式 · 柔光薰衣草
   ============================================================ */

:root {
    --brand: #5a72ff;
    --brand-2: #8a5cff;
    --brand-soft: #eef2ff;
    --ink: #111a33;
    --ink-2: #5c6885;
    --ink-3: #8b96b3;
    --line: rgba(17, 26, 51, .07);
    --surface: #ffffff;
    --ok: #2fcf8f;
    --warn-bg: #fff8ee;
    --warn-line: #ffe4c2;
    --warn-ink: #a2600a;
    --radius: 28px;
    --font: "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", "Segoe UI", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body.kf-visitor {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 28px 20px;
    display: grid;
    place-items: center;
    font-family: var(--font);
    color: var(--ink);
    background:
        radial-gradient(1100px 760px at 8% -12%, #dfe6ff 0%, rgba(223, 230, 255, 0) 58%),
        radial-gradient(900px 720px at 92% 112%, #ecdfff 0%, rgba(236, 223, 255, 0) 56%),
        linear-gradient(180deg, #f4f7fe 0%, #eef2fa 100%);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

::selection { background: rgba(90, 114, 255, .22); }

/* 背景装饰 */
.backdrop {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 0;
}
.backdrop::before,
.backdrop::after {
    content: "";
    position: absolute;
    border-radius: 50%;
    filter: blur(2px);
}
.backdrop::before {
    width: 460px;
    height: 460px;
    left: -180px;
    top: -160px;
    background: radial-gradient(circle at 35% 30%, rgba(90, 114, 255, .22), rgba(90, 114, 255, 0) 68%);
}
.backdrop::after {
    width: 520px;
    height: 520px;
    right: -200px;
    bottom: -200px;
    background: radial-gradient(circle at 60% 60%, rgba(138, 92, 255, .20), rgba(138, 92, 255, 0) 68%);
}

/* ---------- 主卡片 ---------- */
.chat-shell {
    position: relative;
    z-index: 1;
    width: min(462px, 100%);
    height: min(742px, calc(100dvh - 56px));
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow:
        0 44px 96px -44px rgba(24, 38, 92, .48),
        0 16px 36px -24px rgba(24, 38, 92, .22),
        0 0 0 1px rgba(17, 26, 51, .05);
    animation: shell-in .55s cubic-bezier(.2, .8, .25, 1) both;
}

/* ---------- 头部 ---------- */
.chat-header {
    position: relative;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 22px 22px 26px;
    color: #fff;
    background: linear-gradient(128deg, #5468ff 0%, #6c5bff 52%, #9258ff 100%);
    overflow: hidden;
}
.chat-header::before {
    content: "";
    position: absolute;
    inset: 0;
    background:
        radial-gradient(340px 180px at 12% -30%, rgba(255, 255, 255, .34), rgba(255, 255, 255, 0) 70%),
        radial-gradient(300px 200px at 100% 120%, rgba(255, 255, 255, .16), rgba(255, 255, 255, 0) 70%);
    pointer-events: none;
}
.chat-header::after {
    content: "";
    position: absolute;
    width: 190px;
    height: 190px;
    right: -64px;
    top: -96px;
    border-radius: 50%;
    border: 34px solid rgba(255, 255, 255, .08);
    pointer-events: none;
}

.agent-block {
    position: relative;
    display: flex;
    align-items: center;
    gap: 13px;
    min-width: 0;
}

.avatar-wrap {
    position: relative;
    flex: none;
    width: 52px;
    height: 52px;
}

.agent-avatar {
    width: 52px;
    height: 52px;
    display: block;
    border-radius: 50%;
    object-fit: cover;
    background: rgba(255, 255, 255, .22);
    box-shadow:
        0 0 0 2px rgba(255, 255, 255, .9),
        0 10px 22px -10px rgba(20, 28, 70, .65);
}

.status-dot {
    position: absolute;
    right: -1px;
    bottom: 1px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, .92);
}
.status-dot.on {
    background: var(--ok);
    animation: pulse 2.6s ease-out infinite;
}
.status-dot.off { background: #c2c9da; }

.agent-meta { min-width: 0; }

.agent-name {
    margin: 0;
    font-size: 17.5px;
    font-weight: 600;
    letter-spacing: .2px;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-shadow: 0 1px 2px rgba(30, 20, 80, .16);
}

.agent-status {
    margin: 4px 0 0;
    font-size: 12.5px;
    color: rgba(255, 255, 255, .84);
    letter-spacing: .3px;
}

.header-badge {
    position: relative;
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 11px;
    font-size: 11px;
    letter-spacing: .4px;
    color: rgba(255, 255, 255, .95);
    background: rgba(255, 255, 255, .14);
    border: 1px solid rgba(255, 255, 255, .26);
    border-radius: 999px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
.header-badge::before {
    content: "✓";
    display: grid;
    place-items: center;
    width: 13px;
    height: 13px;
    font-size: 8.5px;
    font-weight: 700;
    color: #fff;
    background: rgba(255, 255, 255, .22);
    border-radius: 50%;
}

/* ---------- 消息区 ---------- */
.chat-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 18px 12px;
    background:
        radial-gradient(circle at 1px 1px, rgba(90, 114, 255, .055) 1px, transparent 0) 0 0 / 20px 20px,
        linear-gradient(180deg, #f8faff 0%, #f5f7fd 100%);
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

.chat-body::-webkit-scrollbar { width: 5px; }
.chat-body::-webkit-scrollbar-thumb {
    background: rgba(90, 114, 255, .16);
    border-radius: 99px;
}

.day-divider {
    display: flex;
    justify-content: center;
    margin: 2px 0 18px;
}
.day-divider span {
    padding: 5px 13px;
    font-size: 11px;
    letter-spacing: .4px;
    color: #7b86a2;
    background: rgba(17, 26, 51, .055);
    border-radius: 999px;
}

.msg-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.msg-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    animation: msg-in .34s cubic-bezier(.2, .8, .25, 1) both;
}
.msg-row.me { justify-content: flex-end; }

.msg-avatar {
    flex: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    background: #eaeefb;
    box-shadow: 0 3px 8px -3px rgba(23, 37, 84, .35);
}

.msg-col {
    display: flex;
    flex-direction: column;
    gap: 5px;
    max-width: 79%;
    min-width: 0;
}
.msg-row.me .msg-col { align-items: flex-end; }

.bubble {
    max-width: 100%;
    padding: 10px 14px;
    font-size: 14.5px;
    line-height: 1.66;
    color: var(--ink);
    word-break: break-word;
    white-space: pre-wrap;
    background: #fff;
    border: 1px solid rgba(17, 26, 51, .055);
    border-radius: 18px 18px 18px 6px;
    box-shadow:
        0 2px 4px rgba(23, 37, 84, .035),
        0 10px 22px -18px rgba(23, 37, 84, .5);
}
.msg-row.me .bubble {
    color: #fff;
    border: 0;
    background: linear-gradient(135deg, #5a72ff 0%, #7a5cff 100%);
    border-radius: 18px 18px 6px 18px;
    box-shadow: 0 12px 24px -14px rgba(90, 114, 255, .8);
}

.bubble.media {
    padding: 5px;
    line-height: 0;
    overflow: hidden;
    background: #fff;
    border: 1px solid rgba(17, 26, 51, .06);
}
.msg-row.me .bubble.media {
    background: #fff;
    border: 0;
    box-shadow: 0 12px 26px -18px rgba(23, 37, 84, .5);
}
.bubble.media img {
    display: block;
    width: auto;
    max-width: 224px;
    max-height: 260px;
    border-radius: 13px;
    cursor: zoom-in;
    object-fit: cover;
}

.msg-time {
    padding: 0 5px;
    font-size: 10.5px;
    letter-spacing: .2px;
    color: #a0aac2;
    font-variant-numeric: tabular-nums;
}

/* 输入中 */
.typing {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
    padding: 11px 14px;
    background: #fff;
    border: 1px solid rgba(17, 26, 51, .06);
    border-radius: 16px 16px 16px 6px;
    box-shadow: 0 10px 22px -18px rgba(23, 37, 84, .5);
}
.typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #b5bfdc;
    animation: typing 1.3s ease-in-out infinite;
}
.typing span:nth-child(2) { animation-delay: .16s; }
.typing span:nth-child(3) { animation-delay: .32s; }

/* 常见问题胶囊（固定在输入框上方最底部） */
.quick-strip {
    flex: none;
    padding: 9px 14px 2px;
    background: rgba(255, 255, 255, .94);
    border-top: 1px solid rgba(17, 26, 51, .055);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
.suggestions {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 1px 2px 2px;
    scrollbar-width: none;
}
.suggestions::-webkit-scrollbar { display: none; }
.suggestions button {
    flex: none;
    padding: 8px 13px;
    font-family: inherit;
    font-size: 12.5px;
    white-space: nowrap;
    color: #55617d;
    background: #fff;
    border: 1px solid rgba(90, 114, 255, .18);
    border-radius: 999px;
    cursor: pointer;
    transition: transform .15s ease, color .15s ease, border-color .15s ease, box-shadow .2s ease;
    box-shadow: 0 4px 10px -8px rgba(23, 37, 84, .45);
}
.suggestions button:hover {
    color: var(--brand);
    border-color: rgba(90, 114, 255, .42);
    transform: translateY(-1px);
}
.suggestions button:active { transform: scale(.97); }

/* 离线提示 */
.offline-tip {
    flex: none;
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 18px 8px;
    padding: 9px 12px;
    font-size: 12.5px;
    line-height: 1.5;
    color: var(--warn-ink);
    background: var(--warn-bg);
    border: 1px solid var(--warn-line);
    border-radius: 12px;
}
.offline-tip svg { flex: none; opacity: .85; }

/* ---------- 输入区 ---------- */
.composer {
    flex: none;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 8px 14px calc(12px + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, .94);
    border-top: 0;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.icon-btn {
    flex: none;
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    color: #6b7694;
    background: #f2f5fc;
    border: 0;
    border-radius: 14px;
    cursor: pointer;
    transition: color .15s ease, background .15s ease, transform .12s ease;
}
.icon-btn:hover { color: var(--brand); background: #e9eefe; }
.icon-btn:active { transform: scale(.94); }

.input-box {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    padding: 2px 12px;
    background: #f2f5fc;
    border: 1px solid transparent;
    border-radius: 16px;
    transition: background .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.input-box:focus-within {
    background: #fff;
    border-color: rgba(90, 114, 255, .45);
    box-shadow: 0 0 0 4px rgba(90, 114, 255, .1);
}
#input {
    flex: 1;
    min-width: 0;
    width: 100%;
    max-height: 108px;
    padding: 9px 0;
    font-family: inherit;
    font-size: 14.5px;
    line-height: 1.6;
    color: var(--ink);
    background: transparent;
    border: 0;
    outline: 0;
    resize: none;
}
#input::placeholder { color: #a3adc6; }

.send-btn {
    flex: none;
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(135deg, #5a72ff 0%, #8a5cff 100%);
    border: 0;
    border-radius: 15px;
    cursor: pointer;
    box-shadow: 0 10px 20px -8px rgba(90, 114, 255, .8);
    transition: transform .14s ease, box-shadow .2s ease, opacity .15s ease;
}
.send-btn:hover { transform: translateY(-1px); box-shadow: 0 14px 24px -8px rgba(90, 114, 255, .85); }
.send-btn:active { transform: scale(.94); }
.send-btn:disabled { opacity: .45; box-shadow: none; cursor: default; transform: none; }

/* ---------- 图片预览 ---------- */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 28px;
    background: rgba(8, 12, 28, .86);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    cursor: zoom-out;
    animation: fade-in .22s ease both;
}
.lightbox img {
    max-width: 92vw;
    max-height: 88vh;
    border-radius: 14px;
    box-shadow: 0 30px 80px -30px rgba(0, 0, 0, .8);
}

/* ---------- 动效 ---------- */
@keyframes shell-in {
    from { opacity: 0; transform: translateY(14px) scale(.985); }
    to   { opacity: 1; transform: none; }
}
@keyframes msg-in {
    from { opacity: 0; transform: translateY(8px) scale(.985); }
    to   { opacity: 1; transform: none; }
}
@keyframes fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes pulse {
    0%   { box-shadow: 0 0 0 0 rgba(47, 207, 143, .5); }
    70%  { box-shadow: 0 0 0 7px rgba(47, 207, 143, 0); }
    100% { box-shadow: 0 0 0 0 rgba(47, 207, 143, 0); }
}
@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: .42; }
    30%           { transform: translateY(-4px); opacity: 1; }
}

/* ---------- 手机 ---------- */
@media (max-width: 720px), (max-height: 660px) {
    body.kf-visitor {
        padding: 0;
        display: block;
        background: #f5f7fd;
    }
    .backdrop { display: none; }
    .chat-shell {
        width: 100%;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        box-shadow: none;
        animation: none;
    }
    .chat-header { padding: calc(16px + env(safe-area-inset-top)) 16px 20px; }
    .header-badge { display: none; }
    .chat-body { padding: 16px 14px 10px; }
    .msg-col { max-width: 84%; }
    .bubble { font-size: 14.5px; }
    .quick-strip { padding: 8px 12px 2px; }
    .offline-tip { margin: 0 14px 8px; }
    .composer { padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); }
    .icon-btn { width: 40px; height: 40px; }
    .send-btn { width: 42px; height: 42px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
    .chat-body { scroll-behavior: auto; }
}

/* ---------- 已读回执 / 拉黑提示 ---------- */
.read-state {
    margin-left: 6px;
    color: #a7b1c8;
}
.read-state.read { color: #5a72ff; }

.blocked-tip {
    flex: none;
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 18px 8px;
    padding: 9px 12px;
    font-size: 12.5px;
    line-height: 1.5;
    color: #b42336;
    background: #fff1f3;
    border: 1px solid #ffd6dc;
    border-radius: 12px;
}
.blocked-tip svg { flex: none; opacity: .9; }

.composer.disabled { opacity: .72; }
.composer textarea:disabled { cursor: not-allowed; color: var(--ink-3); }
.composer .icon-btn:disabled { opacity: .45; cursor: not-allowed; }

/* ===== 手机端禁止整页左右滑动与缩放 ===== */
html, body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    overscroll-behavior-x: none;
    touch-action: pan-y;
    -webkit-text-size-adjust: 100%;
}
.chat-shell { max-width: 100vw; overflow-x: hidden; }
.bubble img { max-width: 100%; }

/* ===== 禁止页面缩放：只允许纵向滚动 ===== */
.chat-shell, .messages, .composer { touch-action: pan-y; }

/* ---------- 开启系统通知横幅 ---------- */
.push-banner {
    flex: none;
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 16px 10px;
    padding: 10px 11px;
    background: linear-gradient(135deg, #eef2ff 0%, #f7f0ff 100%);
    border: 1px solid rgba(90, 114, 255, .14);
    border-radius: 15px;
}
.push-banner-icon {
    flex: none;
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    color: #5a72ff;
    background: #fff;
    border-radius: 11px;
    box-shadow: 0 4px 12px rgba(90, 114, 255, .12);
}
.push-banner-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.push-banner-text b { font-size: 12.5px; color: #25305a; font-weight: 700; }
.push-banner-text span { font-size: 11px; line-height: 1.35; color: #7b86a2; }
.push-banner-btn {
    flex: none;
    height: 30px;
    padding: 0 13px;
    border: 0;
    border-radius: 10px;
    background: linear-gradient(135deg, #5a72ff, #8a5cff);
    color: #fff;
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 5px 14px rgba(90, 114, 255, .24);
}
.push-banner-btn:disabled { opacity: .6; }
.push-banner-close {
    flex: none;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #9aa4bd;
    font-size: 17px;
    line-height: 1;
    cursor: pointer;
}
.push-banner-close:active { background: rgba(17, 26, 51, .06); }

@media (max-width: 720px), (max-height: 660px) {
    .push-banner { margin: 0 12px 8px; padding: 9px 10px; }
    .push-banner-icon { width: 31px; height: 31px; }
    .push-banner-text span { font-size: 10.5px; }
    .push-banner-btn { height: 28px; padding: 0 11px; font-size: 11.5px; }
}

