/* ===== 新版聊天界面（所有 UI 主题通用布局） ===== */
.chat-view, .visitor-chat-view { display: flex; flex-direction: column; overflow: hidden; }
.chat-topbar {
    height: calc(46px + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
    background: #1f1f1f;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 6px;
    padding-left: 10px;
    padding-right: 10px;
    flex-shrink: 0;
    z-index: 5;
}
.chat-topbar .chat-back { color: #fff; font-size: 24px; line-height: 1; padding: 0 8px; background: none; border: 0; cursor: pointer; }
.chat-topbar-title { flex: 1; text-align: center; font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-topbar-right { width: 40px; text-align: right; font-size: 15px; color: rgba(255,255,255,.75); flex-shrink: 0; }
.chat-service-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: #fff;
    border-bottom: 1px solid #e8e8e8;
    flex-shrink: 0;
    z-index: 4;
}
.chat-service-avatar {
    width: 40px; height: 40px; border-radius: 8px; flex-shrink: 0;
    background: linear-gradient(135deg, #334155, #0f172a);
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-size: 15px; font-weight: 800;
}
.chat-service-meta { flex: 1; min-width: 0; }
.chat-service-name { font-size: 14px; font-weight: 700; color: #191919; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-service-status { display: flex; align-items: center; gap: 5px; font-size: 11px; color: #12a05c; margin-top: 3px; }
.chat-service-status i { width: 6px; height: 6px; border-radius: 50%; background: #22c55e; display: inline-block; }
.chat-service-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.chat-service-actions button, .chat-service-actions label { background: none; border: 0; font-size: 12px; font-weight: 600; color: #6366f1; cursor: pointer; }
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px 12px !important;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background-size: cover;
    background-position: center;
}
.msg-row { display: flex; align-items: flex-start; gap: 8px; max-width: 100%; }
.msg-row.mine { flex-direction: row; justify-content: flex-end; }
.msg-main { max-width: calc(100% - 56px); display: flex; flex-direction: column; gap: 4px; }
.msg-row.mine .msg-main { align-items: flex-end; }
.msg-bubble { order: 1; padding: 11px 14px; border-radius: 8px !important; font-size: 15px; line-height: 1.5; word-break: break-word; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.msg-row:not(.mine) .msg-bubble { background: #fff !important; color: #191919 !important; border-radius: 8px !important; box-shadow: 0 1px 2px rgba(0,0,0,.05) !important; }
.msg-row.mine .msg-bubble { background: #95EC69 !important; color: #191919 !important; border-radius: 8px !important; box-shadow: 0 1px 2px rgba(0,0,0,.05) !important; }
.msg-row.other::before {
    content: "服";
    width: 36px; height: 36px; border-radius: 8px; flex-shrink: 0;
    background: linear-gradient(135deg, #334155, #0f172a);
    color: #fff; font-size: 13px; font-weight: 800;
    display: flex; align-items: center; justify-content: center;
}
.msg-row.mine::after {
    content: "";
    width: 36px; height: 36px; border-radius: 8px; flex-shrink: 0;
    background-color: #2b7cff;
    background-image:
        radial-gradient(circle at 50% 30%, #fff 0 6px, transparent 6.5px),
        radial-gradient(ellipse at 50% 100%, #fff 0 13px, transparent 13.5px);
    background-repeat: no-repeat;
    box-shadow: 0 2px 6px rgba(43,124,255,.25);
}
.msg-meta { order: 3; font-size: 10px; color: #9aa3ad !important; padding: 0 2px; }
.msg-status { order: 2; font-size: 10px; }
.msg-bubble img { max-width: 220px; border-radius: 8px; display: block; }
.msg-bubble video { max-width: 240px; max-height: 300px; border-radius: 8px; display: block; background: #000; }
.msg-bubble audio { max-width: 200px; outline: none; }

/* 微信风格语音气泡 */
.msg-bubble.voice-msg-bubble { padding: 0 !important; background: transparent !important; box-shadow: none !important; }
.voice-bubble {
    display: inline-flex; align-items: center; gap: 8px;
    min-width: 96px; max-width: 230px;
    padding: 10px 14px; border-radius: 8px;
    background: #fff; color: #191919; cursor: pointer;
    box-shadow: 0 1px 2px rgba(0,0,0,.05);
    user-select: none; -webkit-user-select: none;
}
.msg-row.mine .voice-bubble { background: #95EC69; }
.voice-bubble .vb-play { font-size: 13px; line-height: 1; width: 14px; text-align: center; flex-shrink: 0; }
.voice-bubble .vb-waves { display: inline-flex; align-items: center; gap: 2px; height: 16px; flex: 1; }
.voice-bubble .vb-waves i {
    display: block; width: 2px; border-radius: 1px;
    background: currentColor; opacity: .55; flex-shrink: 0;
}
.voice-bubble .vb-waves i:nth-child(1) { height: 6px; }
.voice-bubble .vb-waves i:nth-child(2) { height: 12px; }
.voice-bubble .vb-waves i:nth-child(3) { height: 9px; }
.voice-bubble .vb-waves i:nth-child(4) { height: 14px; }
.voice-bubble.playing .vb-waves i { animation: vbWave .9s ease-in-out infinite; opacity: .9; }
.voice-bubble.playing .vb-waves i:nth-child(2) { animation-delay: .15s; }
.voice-bubble.playing .vb-waves i:nth-child(3) { animation-delay: .3s; }
.voice-bubble.playing .vb-waves i:nth-child(4) { animation-delay: .45s; }
.voice-bubble .vb-dur { font-size: 13px; color: #4b5563; flex-shrink: 0; }
.msg-row.mine .voice-bubble .vb-dur { color: #2f4f1f; }
@keyframes vbWave {
    0%, 100% { transform: scaleY(.6); }
    50% { transform: scaleY(1.25); }
}

/* 聊天背景选择 */
.bg-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0; }
.bg-swatch { height: 64px; border-radius: 12px; border: 2px solid transparent; cursor: pointer; background-size: cover; background-position: center; }
.bg-swatch.active { border-color: #6366f1; }
.bg-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.bg-actions .btn { flex: 1; min-width: 120px; }

.chat-tools {
    display: none;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px 10px;
    padding: 14px;
    background: #f5f5f5;
    border-top: 1px solid #e8e8e8;
    flex-shrink: 0;
}
.chat-tools.show { display: grid; }
.chat-tool { display: flex; flex-direction: column; align-items: center; gap: 6px; border: 0; background: none; cursor: pointer; font-size: 11px; color: #666; }
.chat-tool .ico { width: 52px; height: 52px; border-radius: 12px; background: #fff; display: flex; align-items: center; justify-content: center; font-size: 24px; box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.chat-tool:active .ico { transform: scale(.95); }

.chat-composer {
    position: relative !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    margin: 6px 12px calc(10px + env(safe-area-inset-bottom, 0px)) !important;
    display: flex;
    gap: 6px;
    align-items: center;
    background: #fff;
    padding: 6px 8px;
    border-radius: 24px;
    border: 1px solid #e5e5e5;
    flex-shrink: 0;
    z-index: 6;
}
.chat-input { flex: 1; width: 0; min-width: 0; border: none; background: transparent; padding: 9px 6px; font-size: 15px; outline: none; }
.composer-btn { width: 36px; height: 36px; border-radius: 50%; background: #f5f5f5; border: 0; font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.chat-send { flex-shrink: 0; white-space: nowrap; border-radius: 18px; padding: 0 15px; height: 36px; background: #07C160; color: #fff; border: 0; font-weight: 700; font-size: 14px; }

.emoji-panel { position: absolute; bottom: calc(74px + env(safe-area-inset-bottom, 0px)); left: 12px; right: 12px; max-height: 220px; overflow-y: auto; background: #fff; border-radius: 14px; padding: 12px; display: none; z-index: 30; border: 1px solid #e5e5e5; box-shadow: 0 -4px 18px rgba(0,0,0,.08); }
.emoji-panel.show { display: block; }
.chat-quick-panel { position: absolute; bottom: calc(74px + env(safe-area-inset-bottom, 0px)); left: 12px; right: 12px; background: #fff; border-radius: 14px; padding: 10px; display: none; z-index: 31; border: 1px solid #e5e5e5; box-shadow: 0 -4px 18px rgba(0,0,0,.08); }
.chat-quick-panel.show { display: block; }
.chat-quick-panel button { display: block; width: 100%; text-align: left; background: #f7f7f7; border: 0; border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; font-size: 13px; color: #333; cursor: pointer; }
.chat-quick-panel button:last-child { margin-bottom: 0; }

@media(max-width: 380px) {
    .chat-tool .ico { width: 46px; height: 46px; font-size: 21px; }
    .chat-tools { gap: 12px 6px; padding: 12px 8px; }
    .msg-main { max-width: calc(100% - 52px); }
    .chat-service-name { font-size: 13px; }
}

/* ===== 平板端 ===== */
@media (min-width: 768px) {
    .app, .visitor-app {
        max-width: 760px;
        height: calc(100vh - 32px);
        margin: 16px auto;
        border-radius: 24px;
        overflow: hidden;
        box-shadow: 0 24px 70px rgba(15,23,42,.18), 0 4px 16px rgba(15,23,42,.06);
        border: 1px solid rgba(255,255,255,.45);
    }
    .chat-topbar { height: 52px; padding-left: 14px; padding-right: 14px; }
    .chat-service-bar { padding: 12px 18px; }
    .chat-messages { padding: 20px 22px 14px !important; gap: 16px; }
    .msg-main { max-width: 72%; }
    .chat-tools { grid-template-columns: repeat(6, 1fr); gap: 16px 12px; padding: 16px; }
    .chat-tool .ico { width: 58px; height: 58px; font-size: 26px; }
    .chat-tool { font-size: 12px; }
    .chat-composer { margin: 8px 18px 14px !important; padding: 7px 10px; }
    .chat-input { font-size: 15px; }
    .emoji-panel, .chat-quick-panel { left: 18px; right: 18px; bottom: calc(82px + env(safe-area-inset-bottom, 0px)); }
    .modal { max-width: 520px; }
    .login-card { max-width: 420px; padding: 36px; }
    .visitor-list-view .app-bar, .app > .app-bar { border-radius: 0; }
}

/* ===== 电脑端：左右分栏 ===== */
@media (min-width: 1000px) {
    .app, .visitor-app {
        max-width: 1180px;
        height: calc(100vh - 40px);
        margin: 20px auto;
        border-radius: 26px;
        display: grid !important;
        grid-template-columns: 360px minmax(0, 1fr);
        grid-template-rows: 64px minmax(0, 1fr) 80px;
        overflow: hidden;
        box-shadow: 0 30px 90px rgba(15,23,42,.22), 0 6px 24px rgba(15,23,42,.08);
        border: 1px solid rgba(255,255,255,.5);
    }
    /* 会员端：左侧会话/个人中心，右侧聊天 */
    .app > .app-bar { grid-column: 1; grid-row: 1; height: 64px; border-right: 1px solid rgba(15,23,42,.06); }
    .app > .app-body { grid-column: 1; grid-row: 2; padding-bottom: 16px !important; border-right: 1px solid rgba(15,23,42,.06); }
    .app > .app-tabbar { grid-column: 1; grid-row: 3; position: relative; left: auto; right: auto; bottom: auto; height: 56px; margin: 8px 14px 14px; }
    .app > .chat-view { grid-column: 2; grid-row: 1 / span 3; position: relative; inset: auto; height: 100%; }
    .app:not(:has(.chat-view:not(.hidden)))::after {
        content: "选择左侧会话开始聊天";
        grid-column: 2; grid-row: 1 / span 3;
        display: flex; align-items: center; justify-content: center;
        color: #94a3b8; font-size: 14px; background: rgba(255,255,255,.16);
    }

    /* 访客端：左侧会话列表，右侧聊天 */
    .visitor-app { grid-template-rows: minmax(0, 1fr); }
    .visitor-app > .visitor-list-view { grid-column: 1; grid-row: 1; position: relative; inset: auto; height: 100%; }
    .visitor-app > .visitor-list-view.hidden { display: flex !important; }
    .visitor-app > .visitor-chat-view { grid-column: 2; grid-row: 1; position: relative; inset: auto; height: 100%; }
    .visitor-app > .visitor-chat-view.hidden { display: none; }
    .visitor-app:not(:has(.visitor-chat-view:not(.hidden)))::after {
        content: "选择左侧会话，或点击「发起新对话」开始聊天";
        grid-column: 2; grid-row: 1;
        display: flex; align-items: center; justify-content: center;
        color: #94a3b8; font-size: 14px; background: rgba(255,255,255,.16);
    }
    .visitor-app > .visitor-welcome { position: absolute; inset: 0; z-index: 200; }

    .chat-topbar { height: 56px; padding-left: 18px; padding-right: 18px; }
    .chat-service-bar { padding: 14px 24px; }
    .chat-messages { padding: 24px 30px 16px !important; gap: 18px; }
    .msg-main { max-width: 66%; }
    .msg-bubble { font-size: 15px; padding: 12px 16px; }
    .chat-tools { padding: 18px 24px; gap: 18px 16px; }
    .chat-tool .ico { width: 62px; height: 62px; font-size: 28px; }
    .chat-composer { margin: 10px 24px 16px !important; padding: 8px 12px; }
    .emoji-panel, .chat-quick-panel { left: 24px; right: 24px; bottom: calc(90px + env(safe-area-inset-bottom, 0px)); }
    .modal { max-width: 560px; }
    .login-card { max-width: 440px; padding: 40px; }
}

/* 超宽屏时给会话侧栏更多空间 */
@media (min-width: 1440px) {
    .app, .visitor-app { max-width: 1280px; grid-template-columns: 400px minmax(0, 1fr); }
}
