/* =========================================================================
 * 客服悬浮按钮 + 聊天窗口样式
 * ========================================================================= */

/* 悬浮按钮 */
.cs-float-btn {
    position: fixed;
    bottom: 80px;
    right: 20px;
    z-index: 9998;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--cs-btn-color, #0d6efd);
    box-shadow: 0 4px 20px rgba(13,110,253,.35);
    cursor: pointer;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 24px;
    border: none;
    outline: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.cs-float-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(13,110,253,.45);
}
.cs-float-btn:active {
    transform: scale(0.96);
}

/* 在线脉冲动画 */
.cs-float-btn.online::before {
    content: '';
    position: absolute;
    top: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    background: #22c55e;
    border-radius: 50%;
    border: 2px solid #fff;
    animation: cs-pulse 2s infinite;
}
@keyframes cs-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(34,197,94,.6); }
    70%  { box-shadow: 0 0 0 8px rgba(34,197,94,0); }
    100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}

/* 未读角标 */
.cs-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #ef4444;
    color: #fff;
    border-radius: 14px;
    min-width: 22px;
    height: 22px;
    font-size: 12px;
    line-height: 22px;
    text-align: center;
    font-weight: 600;
    padding: 0 6px;
    border: 2px solid #fff;
    display: none;
}
.cs-badge.show {
    display: block;
}

/* 按钮提示文字 */
.cs-btn-tooltip {
    position: absolute;
    right: 72px;
    top: 50%;
    transform: translateY(-50%);
    background: #1f2937;
    color: #fff;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 13px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s;
    pointer-events: none;
}
.cs-float-btn:hover .cs-btn-tooltip {
    opacity: 1;
    visibility: visible;
}

/* 状态文字 */
.cs-status-text {
    position: absolute;
    bottom: -22px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    white-space: nowrap;
    color: #6b7280;
    background: #fff;
    padding: 2px 8px;
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
}

/* ======== 聊天面板 ======== */
.cs-chat-panel {
    position: fixed;
    bottom: 150px;
    right: 20px;
    z-index: 9999;
    width: 380px;
    height: 540px;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 12px 48px rgba(0,0,0,.16), 0 4px 12px rgba(0,0,0,.08);
    display: flex;
    flex-direction: column;
    background: #fff;
    transition: opacity 0.3s, transform 0.3s;
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    pointer-events: none;
}
.cs-chat-panel.open {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: auto;
}

/* 面板头部 */
.cs-panel-header {
    background: var(--cs-btn-color, #0d6efd);
    color: #fff;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
.cs-panel-header .cs-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,.25);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}
.cs-panel-header .cs-header-info {
    flex: 1;
    min-width: 0;
}
.cs-panel-header .cs-header-name {
    font-weight: 600;
    font-size: 15px;
    line-height: 1.2;
}
.cs-panel-header .cs-header-status {
    font-size: 12px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 4px;
}
.cs-panel-header .cs-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    display: inline-block;
}
.cs-panel-header .cs-status-dot.online { background: #4ade80; }
.cs-panel-header .cs-status-dot.ai { background: #facc15; }
.cs-panel-header .cs-status-dot.offline { background: #9ca3af; }
.cs-panel-header .cs-close-btn {
    background: rgba(255,255,255,.2);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.cs-panel-header .cs-close-btn:hover {
    background: rgba(255,255,255,.35);
}

/* 消息区 */
.cs-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f5f6fa;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.cs-messages::-webkit-scrollbar {
    width: 4px;
}
.cs-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 2px;
}

/* 消息气泡 */
.cs-msg {
    display: flex;
    gap: 8px;
    max-width: 85%;
    animation: cs-msg-in 0.3s ease;
}
@keyframes cs-msg-in {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}
.cs-msg.visitor {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.cs-msg.visitor .cs-bubble {
    background: var(--cs-btn-color, #0d6efd);
    color: #fff;
    border-radius: 16px 16px 4px 16px;
}
.cs-msg.admin,
.cs-msg.ai {
    align-self: flex-start;
}
.cs-msg.admin .cs-bubble {
    background: #fff;
    color: #1f2937;
    border-radius: 16px 16px 16px 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.cs-msg.ai .cs-bubble {
    background: #ecfdf5;
    color: #065f46;
    border-radius: 16px 16px 16px 4px;
    border: 1px solid #a7f3d0;
}

.cs-msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: #fff;
}
.cs-msg.visitor .cs-msg-avatar { background: #6366f1; }
.cs-msg.admin .cs-msg-avatar  { background: #f59e0b; }
.cs-msg.ai .cs-msg-avatar     { background: #10b981; }

.cs-bubble {
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
    position: relative;
}
.cs-bubble img {
    max-width: 160px;
    border-radius: 8px;
    margin: 4px 0;
}
.cs-msg-time {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 4px;
    padding: 0 4px;
}

/* 系统消息 */
.cs-msg-system {
    text-align: center;
    font-size: 12px;
    color: #9ca3af;
    padding: 4px 0;
}

/* 时间分割线 */
.cs-time-divider {
    text-align: center;
    font-size: 11px;
    color: #9ca3af;
    padding: 8px 0;
}

/* 输入区 */
.cs-input-area {
    padding: 12px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
}
.cs-input-area textarea {
    flex: 1;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 14px;
    resize: none;
    outline: none;
    min-height: 42px;
    max-height: 100px;
    line-height: 1.5;
    font-family: inherit;
    transition: border-color 0.2s;
}
.cs-input-area textarea:focus {
    border-color: var(--cs-btn-color, #0d6efd);
    box-shadow: 0 0 0 3px rgba(13,110,253,.1);
}
.cs-send-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--cs-btn-color, #0d6efd);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s, background 0.2s;
}
.cs-send-btn:hover { background: #2563eb; }
.cs-send-btn:active { transform: scale(0.92); }
.cs-send-btn:disabled { background: #9ca3af; cursor: not-allowed; }

.cs-upload-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #f3f4f6;
    color: #6b7280;
    border: none;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}
.cs-upload-btn:hover { background: #e5e7eb; }

/* 加载指示器 */
.cs-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
}
.cs-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #9ca3af;
    animation: cs-typing 1.4s infinite both;
}
.cs-typing span:nth-child(2) { animation-delay: 0.2s; }
.cs-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes cs-typing {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

/* 已关闭提示 */
.cs-closed-notice {
    text-align: center;
    padding: 12px;
    background: #fef2f2;
    color: #991b1b;
    font-size: 13px;
    border-top: 1px solid #fecaca;
    flex-shrink: 0;
}

/* ======== H5 适配 ======== */
@media (max-width: 768px) {
    .cs-chat-panel {
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
    }
    .cs-chat-panel .cs-close-btn {
        font-size: 20px;
    }
    .cs-float-btn {
        width: 52px;
        height: 52px;
        bottom: 70px;
        right: 14px;
        font-size: 20px;
    }
    .cs-btn-tooltip { display: none; }
}
