/* CustomerService 访客聊天窗口样式 */

/* ---- 右下角悬浮按钮组：在线客服/电话/QQ/微信 ---- */
.cs-fab-stack {
    position: fixed;
    right: 20px;
    bottom: 28px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    z-index: 99990;
}
.cs-fab-item { position: relative; }

.cs-fab {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    color: #fff;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .18);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .15s ease;
}
.cs-fab:hover { transform: scale(1.08); }
.cs-fab.cs-chat { background: #2563eb; }
.cs-fab.cs-phone { background: #ff6b35; }
.cs-fab.cs-qq { background: #12b7f5; }
.cs-fab.cs-wechat { background: #07c160; }

.cs-fab-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    line-height: 18px;
    padding: 0 5px;
    background: #ef4444;
    color: #fff;
    font-size: 12px;
    border-radius: 9999px;
}

.cs-pop {
    display: none;
    position: absolute;
    right: 64px;
    top: 50%;
    transform: translateY(-50%);
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, .16);
    padding: 14px 16px;
    white-space: nowrap;
    z-index: 99991;
}
.cs-pop::after {
    content: '';
    position: absolute;
    right: -6px;
    top: 50%;
    margin-top: -6px;
    width: 12px;
    height: 12px;
    background: #fff;
    transform: rotate(45deg);
}
.cs-pop.show { display: block; }
.cs-pop-line {
    display: block;
    color: #1f2937 !important;
    text-decoration: none;
    font-size: 14px;
    line-height: 2;
}
.cs-pop-line:hover { color: #2563eb !important; }
.cs-pop-line strong { font-size: 15px; letter-spacing: .5px; }
.cs-pop-note {
    font-size: 12px;
    color: #94a3b8;
    margin-top: 6px;
    text-align: center;
}
.cs-pop-qr {
    display: block;
    width: 150px;
    height: auto;
    border-radius: 6px;
}

/* ---- 聊天窗口 ---- */
.cs-panel {
    position: fixed;
    right: 20px;
    bottom: 100px;
    width: 400px;
    height: 560px;
    max-height: calc(100vh - 120px);
    min-height: 400px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 99992;
    transition: all .3s ease;
}
.cs-panel.cs-hide { display: none; }
.cs-panel.cs-drag { outline: 2px dashed #2563eb; outline-offset: -6px; }
.cs-panel.cs-maximized {
    left: 50%;
    top: 50%;
    right: auto;
    bottom: auto;
    width: 80vw;
    height: 80vh;
    max-width: 900px;
    max-height: 700px;
    transform: translate(-50%, -50%);
    border-radius: 16px;
}

.cs-panel-head {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #fff;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.cs-panel-head .cs-title { font-size: 15px; font-weight: bold; letter-spacing: 1px; }
.cs-close {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    opacity: .85;
    margin-left: 6px;
}
.cs-close:hover { opacity: 1; }
.cs-maximize {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    opacity: .85;
    margin-left: 6px;
    padding: 2px 4px;
}
.cs-maximize:hover { opacity: 1; }
.cs-maximize svg { vertical-align: middle; }

.cs-mode {
    display: flex;
    margin-left: 10px;
    background: rgba(255, 255, 255, .16);
    border-radius: 9999px;
    padding: 2px 10px;
    align-items: center;
}
.cs-mode-label { font-size: 12px; color: rgba(255,255,255,.95); }
.cs-mode-btn {
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, .85);
    font-size: 12px;
    padding: 3px 10px;
    border-radius: 9999px;
    cursor: pointer;
    white-space: nowrap;
    margin-left: 6px;
}
.cs-mode-btn:hover { background: rgba(255,255,255,.15); }

.cs-msg .cs-name {
    font-size: 11px;
    color: #94a3b8;
    margin-bottom: 3px;
    user-select: none;
}

.cs-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    background: #f6f8fb;
}
.cs-tip,
.cs-systip {
    text-align: center;
    font-size: 12px;
    color: #94a3b8;
    margin: 6px 0;
    white-space: pre-line;
}
.cs-msg { display: flex; margin-bottom: 10px; }
.cs-msg.agent { justify-content: flex-start; }
.cs-msg.visitor { justify-content: flex-end; }
.cs-msg > div {
    max-width: 82%;
    min-width: 40px;
}
.cs-bubble {
    max-width: 100%;
    min-width: 40px;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
    white-space: normal;
    display: inline-block;
    text-align: left;
}
.cs-msg.agent .cs-bubble,
.cs-msg.agent .cs-media { background: #fff; border: 1px solid #e5eaf1; color: #1f2937; }
.cs-msg.visitor .cs-bubble,
.cs-msg.visitor .cs-media { background: #2563eb; color: #fff; }
.cs-msg.ai .cs-bubble,
.cs-msg.ai .cs-media { background: #f3f0ff; border: 1px solid #ddd3fb; color: #1f2937; }

.cs-link {
    color: #2563eb !important;
    text-decoration: underline;
    word-break: break-all;
}
.cs-msg.visitor .cs-link { color: #fff !important; }

/* 媒体消息 */
.cs-media {
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    display: inline-block;
    max-width: 100%;
}
.cs-media-image { padding: 4px; background: #fff; border: 1px solid #e5eaf1; }
.cs-msg.visitor .cs-media-image { background: #2563eb; border-color: #2563eb; }
.cs-msg.ai .cs-media-image { background: #f3f0ff; border: 1px solid #ddd3fb; }
.cs-img {
    display: block;
    max-width: 220px;
    max-height: 220px;
    width: auto;
    height: auto;
    border-radius: 8px;
    cursor: zoom-in;
    background: #f1f5f9;
}
.cs-img-copy {
    position: absolute;
    right: 8px;
    bottom: 8px;
    border: none;
    background: rgba(15, 23, 42, .65);
    color: #fff;
    font-size: 12px;
    padding: 3px 8px;
    border-radius: 999px;
    cursor: pointer;
}
.cs-img-copy:hover { background: rgba(15, 23, 42, .85); }

.cs-media-file {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    min-width: 180px;
    border: 1px solid #e5eaf1;
    border-radius: 10px;
    background: #fff;
}
.cs-file-icon { font-size: 22px; }
.cs-file-name {
    display: block;
    color: #2563eb !important;
    font-size: 13px;
    text-decoration: none;
    word-break: break-all;
    max-width: 180px;
}
.cs-file-name:hover { text-decoration: underline; }
.cs-file-size { font-size: 11px; color: #94a3b8; margin-top: 2px; }
.cs-msg.visitor .cs-file-name { color: #fff !important; }
.cs-msg.visitor .cs-file-size { color: rgba(255,255,255,.8); }

/* 底部工具栏 + 输入 */
.cs-foot {
    border-top: 1px solid #e5eaf1;
    background: #fff;
    padding: 8px 10px 10px;
    position: relative;
}
.cs-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}
.cs-tool {
    border: none;
    background: #f1f5f9;
    border-radius: 8px;
    width: 32px;
    height: 28px;
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
}
.cs-tool:hover { background: #e2e8f0; }
.cs-tool-hint {
    margin-left: auto;
    font-size: 11px;
    color: #94a3b8;
}
.cs-emoji-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    max-height: 140px;
    overflow-y: auto;
    padding: 8px;
    margin-bottom: 8px;
    background: #f8fafc;
    border: 1px solid #e5eaf1;
    border-radius: 8px;
}
.cs-emoji-panel.cs-hide { display: none; }
.cs-emoji-item {
    border: none;
    background: transparent;
    width: 32px;
    height: 32px;
    font-size: 18px;
    cursor: pointer;
    border-radius: 6px;
}
.cs-emoji-item:hover { background: #e2e8f0; }

.cs-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.cs-input {
    flex: 1;
    resize: none;
    border: 1px solid #dbe2ea;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 14px;
    height: 58px;
    outline: none;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}
.cs-input:focus { border-color: #93c5fd; }
.cs-send {
    border: none;
    background: #2563eb;
    color: #fff;
    border-radius: 8px;
    padding: 9px 16px;
    font-size: 14px;
    cursor: pointer;
}
.cs-send:hover { background: #1d4ed8; }

@media (max-width: 768px) {
    .cs-panel {
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
        width: auto;
        height: auto;
        max-height: none;
        min-height: 0;
        border-radius: 0;
    }
      /* 移动端"最大化" = 本就全屏, 需清掉居中变换, 否则会偏移到屏幕外 */
      .cs-panel,
      .cs-panel.cs-maximized {
          left: 0;
          right: 0;
          top: 0;
          bottom: 0;
          width: auto;
          height: auto;
          max-width: none;
          max-height: none;
          min-height: 0;
          transform: none;
          border-radius: 0;
      }
      /* 移动端已是全屏, 最大化按钮无意义 */
      .cs-maximize { display: none; }
    .cs-fab-stack { right: 14px; bottom: 20px; }
    .cs-tool-hint { display: none; }
    .cs-img { max-width: 180px; max-height: 180px; }
}

/* ---- 面板拖动 ---- */
.cs-panel .cs-panel-head {
    cursor: move;
    user-select: none;
}
.cs-panel.cs-moving {
    transition: none !important;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .28) !important;
}
.cs-panel.cs-moving .cs-panel-head {
    background: #1d4ed8;
}
@media (max-width: 991px) {
    .cs-panel .cs-panel-head { cursor: default; }
}

/* ============================================================
   移动端键盘适配: 软键盘弹出时视口高度骤减,
   面板必须用动态视口单位(dvh)并让消息区收缩, 保证输入框始终可见
   ============================================================ */
@media (max-width: 768px) {
    .cs-panel,
    .cs-panel.cs-maximized {
        bottom: 0;
        height: 100vh;          /* 兜底 */
        height: 100dvh;         /* 动态视口: 键盘弹出时自动缩小 */
        max-height: 100dvh;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    /* 消息区可收缩, 把空间让给输入区 */
    .cs-panel .cs-body {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    /* 输入区固定在底部, 不被压缩 */
    .cs-panel .cs-foot {
        flex: 0 0 auto !important;
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
        background: #fff;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, .06);
        position: relative;
        z-index: 2;
    }
    .cs-panel .cs-input-row {
        padding: 8px 12px;
    }
    .cs-panel .cs-input {
        min-height: 40px;
        max-height: 88px;
    }
}

/* ---- AI 回复末尾「获取报价方案」按钮 ---- */
.cs-cta {
    margin-top: 10px;
    padding-top: 9px;
    border-top: 1px dashed rgba(0, 0, 0, .08);
    text-align: left;
}
.cs-cta-btn {
    display: inline-block;
    padding: 5px 14px;
    border: 1px solid #1d4ed8;
    border-radius: 6px;
    background: #fff;
    color: #1d4ed8;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.5;
    text-decoration: none;
    cursor: pointer;
    transition: background .15s, color .15s;
}
.cs-cta-btn:hover {
    background: #1d4ed8;
    color: #fff;
}
@media (max-width: 991px) {
    .cs-cta-btn {
        display: block;
        text-align: center;
        padding: 8px 14px;
    }
}

/* ===== CS-PANEL-DEFENSE: 面板永不超出视口 =====
   兜底约束: 即使媒体查询未命中/被覆盖, 面板也不会宽于视口
   ============================================== */
.cs-panel {
    max-width: calc(100vw - 16px);
    box-sizing: border-box;
}
@media (max-width: 991px) {
    .cs-panel {
        left: 0 !important;
        right: 0 !important;
        width: auto !important;
        max-width: 100vw !important;
        margin: 0 !important;
        transform: none !important;
        border-radius: 0 !important;
    }
    .cs-panel .cs-panel-head,
    .cs-panel .cs-foot,
    .cs-panel .cs-body,
    .cs-panel .cs-input-row {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
    }
    /* 移动端关闭"最大化"的居中变换, 否则面板会偏移到屏幕外 */
    .cs-panel.cs-maximized {
        left: 0 !important;
        right: 0 !important;
        top: 0 !important;
        bottom: 0 !important;
        width: auto !important;
        height: 100dvh !important;
        max-width: 100vw !important;
        transform: none !important;
    }
}

/* ===== 移动端主动接客气泡 ===== */
.cs-invite {
    position: fixed;
    right: 12px;
    bottom: 240px;
    width: calc(100vw - 24px);
    max-width: 330px;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 10px 34px rgba(15, 35, 80, .20);
    padding: 15px 15px 13px;
    z-index: 99991;
    box-sizing: border-box;
    opacity: 0;
    transform: translateY(16px) scale(.96);
    transition: opacity .28s ease, transform .28s ease;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.cs-invite-show { opacity: 1; transform: translateY(0) scale(1); }
.cs-invite-close {
    position: absolute; top: 6px; right: 6px;
    width: 28px; height: 28px; border: 0; background: transparent;
    color: #9aa5b4; font-size: 20px; line-height: 1; cursor: pointer;
    border-radius: 50%; padding: 0;
    display: flex; align-items: center; justify-content: center;
}
.cs-invite-close:active { background: #f1f5f9; color: #475569; }
.cs-invite-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.cs-invite-avatar {
    width: 36px; height: 36px; flex: none; border-radius: 50%;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    display: flex; align-items: center; justify-content: center;
    font-size: 19px; line-height: 1;
}
.cs-invite-title { font-size: 14.5px; font-weight: 700; color: #1f2937; line-height: 1.3; }
.cs-invite-sub { font-size: 11.5px; color: #10b981; margin-top: 2px; }
.cs-invite-sub::before {
    content: ''; display: inline-block; width: 6px; height: 6px;
    border-radius: 50%; background: #10b981; margin-right: 4px;
    vertical-align: middle;
}
.cs-invite-text {
    font-size: 13.5px; line-height: 1.68; color: #4b5563; margin-bottom: 12px;
}
.cs-invite-btn {
    width: 100%; height: 42px; border: 0; border-radius: 9px;
    background: linear-gradient(135deg, #2563eb, #1d4ed8); color: #fff;
    font-size: 14.5px; font-weight: 600; cursor: pointer; padding: 0;
    -webkit-tap-highlight-color: transparent;
}
.cs-invite-btn:active { opacity: .86; }
@media (min-width: 992px) {
    .cs-invite { display: none !important; }   /* 桌面端不用气泡 */
}
