/* ============================================================
   官网智能客服 · 悬浮聊天组件（cs- 前缀，独立于 main 样式）
   商务科技蓝主题：复用 style.css 的 CSS 变量
   ============================================================ */

/* --- 悬浮根容器：占位，不产生交互层 --- */
#csChatRoot {
    position: fixed;
    right: 28px;
    bottom: 28px;
    z-index: 1200;
}

/* --- 右下角悬浮胶囊钮（💬 + 在线咨询文字） --- */
.cs-launcher {
    position: fixed;
    right: 28px;
    bottom: 28px;
    z-index: 1201;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 52px;
    padding: 0 24px;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    white-space: nowrap;
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 60%, var(--primary-dark) 100%);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.02em;
    line-height: 1;
    box-shadow: 0 8px 24px rgba(18, 70, 160, 0.35);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.25s ease;
    font-family: var(--font-body);
}
.cs-launcher:hover {
    transform: translateY(-2px) scale(1.04);
    box-shadow: 0 12px 30px rgba(18, 70, 160, 0.45);
}
/* 呼吸光环提示（关闭态） */
.cs-launcher::before {
    content: "";
    position: absolute;
    inset: -6px;
    border-radius: 999px;
    border: 2px solid rgba(18, 70, 160, 0.35);
    animation: csPulse 2.4s ease-out infinite;
    pointer-events: none;
}
@keyframes csPulse {
    0%   { transform: scale(0.92); opacity: 0.9; }
    70%  { transform: scale(1.18); opacity: 0; }
    100% { transform: scale(1.18); opacity: 0; }
}
/* 在线状态小红点 */
.cs-launcher::after {
    content: "";
    position: absolute;
    top: 8px;
    right: 8px;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: #22C55E;
    border: 2px solid #fff;
}

/* 聊天窗被打开时按钮隐藏，由窗口头部 ✕ 关闭 */
.cs-launcher.cs-open {
    display: none;
}

/* --- 悬浮聊天窗口 --- */
.cs-window {
    position: fixed;
    right: 28px;
    bottom: 98px;
    z-index: 1202;
    width: 360px;
    height: min(480px, calc(100vh - 130px));
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: 0 16px 48px rgba(15, 23, 42, 0.22), 0 2px 8px rgba(15, 23, 42, 0.08);
    border: 1px solid rgba(18, 70, 160, 0.08);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    font-family: var(--font-body);
    font-size: 0.875rem;
    color: var(--text-dark);
    transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.22s ease;
}
.cs-window.cs-hidden {
    transform: translateY(16px) scale(0.96);
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}

/* 首页存在 .floating-cta（企业微信/免费试用）时上移错开 */
#csChatRoot.cs-has-cta .cs-launcher { bottom: 152px; }
#csChatRoot.cs-has-cta .cs-window { bottom: 224px; height: min(480px, calc(100vh - 256px)); }

/* --- 窗口头部 --- */
.cs-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 100%);
    color: #fff;
}
.cs-header-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex: 0 0 auto;
}
.cs-header-txt { flex: 1; min-width: 0; line-height: 1.35; }
.cs-header-title {
    font-size: 0.9375rem;
    font-weight: 700;
    letter-spacing: 0.01em;
}
.cs-header-sub {
    font-size: 0.72rem;
    opacity: 0.85;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cs-close {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}
.cs-close:hover { background: rgba(255, 255, 255, 0.3); }

/* --- 消息区 --- */
.cs-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 14px 14px 8px;
    background: var(--primary-bg);
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
}
.cs-body::-webkit-scrollbar { width: 6px; }
.cs-body::-webkit-scrollbar-thumb { background: rgba(18, 70, 160, 0.18); border-radius: 3px; }
.cs-body::-webkit-scrollbar-track { background: transparent; }

/* 气泡 */
.cs-row {
    display: flex;
    margin-bottom: 10px;
    align-items: flex-end;
}
.cs-row.cs-user { justify-content: flex-end; }
.cs-row.cs-bot { justify-content: flex-start; }

.cs-bubble {
    max-width: 82%;
    padding: 9px 13px;
    border-radius: 16px;
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.84375rem;
}
.cs-bot .cs-bubble {
    background: var(--white);
    border: 1px solid rgba(18, 70, 160, 0.06);
    border-bottom-left-radius: 4px;
    color: var(--text-dark);
    box-shadow: var(--shadow-sm);
}
.cs-user .cs-bubble {
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    color: #fff;
    border-bottom-right-radius: 4px;
}
.cs-bubble strong { font-weight: 700; }

/* "正在输入…" 占位 */
.cs-typing .cs-bubble {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 14px;
}
.cs-typing .cs-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-light);
    animation: csBlink 1.2s infinite ease-in-out;
}
.cs-typing .cs-dot:nth-child(2) { animation-delay: 0.18s; }
.cs-typing .cs-dot:nth-child(3) { animation-delay: 0.36s; }
@keyframes csBlink {
    0%, 70%, 100% { opacity: 0.3; transform: translateY(0); }
    35% { opacity: 1; transform: translateY(-3px); }
}

/* 快捷问题胶囊 / 行业选项卡 */
.cs-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 2px 0 10px 4px;
    max-width: 88%;
}
.cs-chip {
    border: 1px solid rgba(18, 70, 160, 0.35);
    background: #fff;
    color: var(--primary);
    font-size: 0.8rem;
    padding: 6px 14px;
    border-radius: 50px;
    cursor: pointer;
    font-family: var(--font-body);
    transition: all 0.2s ease;
}
.cs-chip:hover {
    background: var(--primary-bg);
    border-color: var(--primary);
    transform: translateY(-1px);
}

/* 推荐产品卡 */
.cs-card {
    background: var(--white);
    border: 1px solid rgba(18, 70, 160, 0.1);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    margin: 8px 0;
    padding: 12px 14px;
}
.cs-card + .cs-card { margin-top: 8px; }
.cs-card-name {
    font-weight: 700;
    font-size: 0.875rem;
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    gap: 6px;
}
.cs-card-name .cs-tag {
    background: var(--primary-bg);
    color: var(--primary);
    font-size: 0.68rem;
    font-weight: 600;
    padding: 1px 8px;
    border-radius: 20px;
    flex: 0 0 auto;
}
.cs-card-reason {
    margin-top: 4px;
    font-size: 0.8rem;
    color: var(--text-mid);
    line-height: 1.6;
}
.cs-card-link {
    display: inline-block;
    margin-top: 9px;
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    color: #fff;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 6px 16px;
    border-radius: 50px;
    transition: all 0.2s ease;
}
.cs-card-link:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(18, 70, 160, 0.3);
    color: #fff;
}

/* 转人工按钮 */
.cs-human-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: none;
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, var(--accent-light), var(--accent) 70%, var(--accent-dark));
    padding: 7px 18px;
    border-radius: 50px;
    margin-top: 6px;
    box-shadow: 0 4px 12px rgba(249, 115, 22, 0.3);
    transition: all 0.2s ease;
}
.cs-human-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(249, 115, 22, 0.4); }
.cs-human-btn.cs-ghost {
    background: transparent;
    color: var(--accent-dark);
    border: 1px solid var(--accent-light);
    box-shadow: none;
    font-weight: 600;
}
.cs-human-btn.cs-ghost:hover { background: rgba(249, 115, 22, 0.08); }

/* 快捷入口小按钮（消息流内"快捷问题"） */
.cs-chip-link {
    border: none;
    background: none;
    color: var(--primary);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.76rem;
    text-decoration: underline dotted;
    padding: 0 2px 4px;
    align-self: flex-start;
}

/* 人工留资表单卡 */
.cs-form-card {
    background: var(--white);
    border: 1px solid rgba(18, 70, 160, 0.12);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 14px;
    margin: 8px 0 10px;
    max-width: 88%;
}
.cs-form-title {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: 2px;
}
.cs-form-note {
    font-size: 0.75rem;
    color: var(--text-mid);
    margin-bottom: 10px;
}
.cs-form-card input,
.cs-form-card textarea {
    width: 100%;
    border: 1px solid rgba(100, 116, 139, 0.35);
    border-radius: 10px;
    padding: 8px 11px;
    font-size: 0.82rem;
    font-family: var(--font-body);
    color: var(--text-dark);
    background: #fff;
    outline: none;
    box-sizing: border-box;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    margin-bottom: 8px;
}
.cs-form-card input:focus,
.cs-form-card textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(18, 70, 160, 0.12);
}
.cs-form-card textarea { resize: vertical; min-height: 58px; }
.cs-form-err {
    color: #DC2626;
    font-size: 0.75rem;
    margin: 4px 0 0;
    display: none;
}
.cs-form-err.cs-show { display: block; }
.cs-form-submit {
    width: 100%;
    border: none;
    cursor: pointer;
    border-radius: 10px;
    padding: 9px;
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, var(--accent-light), var(--accent) 70%, var(--accent-dark));
    transition: all 0.2s ease;
}
.cs-form-submit:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(249, 115, 22, 0.35); }
.cs-form-submit:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

/* 联系卡（电话 + 企微码） */
.cs-contact-card {
    background: var(--white);
    border: 1px dashed rgba(18, 70, 160, 0.3);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    margin: 6px 0 10px;
    max-width: 88%;
}
.cs-contact-phone a {
    color: var(--primary);
    font-weight: 700;
    font-size: 0.92rem;
}
.cs-contact-qr {
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.cs-contact-qr img {
    width: 86px;
    height: 86px;
    object-fit: contain;
    border-radius: 8px;
    border: 1px solid #E2E8F0;
    background: #fff;
}
.cs-contact-qr span { font-size: 0.76rem; color: var(--text-mid); line-height: 1.5; }

/* --- 输入区 --- */
.cs-inputbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: var(--white);
    border-top: 1px solid #EEF2F7;
}
.cs-inputbar input {
    flex: 1;
    min-width: 0;
    border: 1px solid rgba(100, 116, 139, 0.35);
    border-radius: 50px;
    padding: 9px 16px;
    font-size: 0.85rem;
    font-family: var(--font-body);
    color: var(--text-dark);
    background: var(--white);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.cs-inputbar input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(18, 70, 160, 0.12);
}
.cs-send-btn {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    color: #fff;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    transition: all 0.2s ease;
}
.cs-send-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 14px rgba(18, 70, 160, 0.35); }
.cs-send-btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

/* --- 窗口底部服务时间小字 --- */
.cs-footer-note {
    flex: 0 0 auto;
    text-align: center;
    padding: 5px 10px 7px;
    font-size: 0.7rem;
    color: var(--text-light);
    background: var(--white);
    border-top: 1px solid #F1F5F9;
}

/* --- 移动端（≤480px）自适应 --- */
@media (max-width: 480px) {
    #csChatRoot { right: 12px; bottom: 12px; }
    .cs-launcher,
    #csChatRoot.cs-has-cta .cs-launcher {
        right: 12px;
        bottom: 12px;
        height: 46px;
        padding: 0 16px;
        font-size: 14px;
    }
    .cs-window,
    #csChatRoot.cs-has-cta .cs-window {
        right: 10px;
        bottom: 74px;
        left: 10px;
        width: auto;
        height: min(480px, 85vh, calc(100vh - 88px));
    }
    /* 首页双浮钮上移到圆钮上方，避免被遮挡（:has 现代浏览器均支持） */
    body:has(#csChatRoot.cs-has-cta) .floating-cta {
        bottom: 74px;
        right: 12px;
    }
    .cs-bubble { max-width: 88%; }
    .cs-chips, .cs-form-card, .cs-contact-card { max-width: 94%; }
}
