/* ===== 客服聊天浮窗 ===== */

/* 开奖区右侧客服按钮 */
.cs-draw-fab {
    flex-shrink: 0;
    margin-left: auto;
    padding: 4px 4px 4px 16px;
    border: none;
    border-left: 1px solid #cbd5e1;
    background: transparent;
    cursor: pointer;
    position: relative;
    z-index: 3;
    line-height: 1;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 42px;
    transition: transform 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.cs-draw-fab:hover {
    transform: scale(1.06);
}

.cs-draw-fab:active {
    transform: scale(0.96);
}

.cs-draw-fab-icon-wrap {
    position: relative;
    line-height: 0;
    display: block;
}

.cs-draw-fab-logo {
    display: block;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    box-shadow: 0 2px 10px rgba(102, 126, 234, 0.35);
    pointer-events: none;
}

.cs-draw-fab-text {
    font-size: 10px;
    font-weight: 700;
    color: #667eea;
    letter-spacing: 0.5px;
    pointer-events: none;
    white-space: nowrap;
}

.cs-draw-fab.cs-fab-unread .cs-draw-fab-logo {
    animation: csFabPulse 1.6s ease-in-out infinite;
}

/* 面板锚点容器（无 FAB，仅承载弹层） */
.cs-widget {
    position: fixed;
    z-index: 10040;
    pointer-events: none;
    width: 0;
    height: 0;
    overflow: visible;
    font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Segoe UI', sans-serif;
}
.cs-fab-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 10px;
    background: #ff4d4f;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    display: none;
}
.cs-fab-badge.show { display: block; }

.cs-draw-fab .cs-fab-badge {
    top: -4px;
    right: -4px;
}

@keyframes csFabPulse {
    0%, 100% { box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15); }
    50% { box-shadow: 0 0 0 6px rgba(255, 77, 79, 0.28), 0 6px 20px rgba(255, 77, 79, 0.35); }
}

.cs-unread-tip {
    position: fixed;
    top: max(68px, calc(env(safe-area-inset-top, 0px) + 56px));
    left: 10px;
    right: 10px;
    z-index: 10050;
    display: none;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 12px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    font-size: 13px;
    line-height: 1.35;
    box-shadow: 0 8px 24px rgba(102, 126, 234, 0.38);
    cursor: pointer;
    user-select: none;
}

.cs-unread-tip.show {
    display: flex;
}

.cs-unread-tip-icon {
    flex-shrink: 0;
    font-size: 16px;
}

.cs-unread-tip-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cs-unread-tip-close {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.22);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    line-height: 1;
}

.cs-panel {
    position: absolute;
    right: 0;
    bottom: 12px;
    width: min(360px, calc(100vw - 32px));
    height: min(520px, calc(100vh - 120px));
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 16px 48px rgba(15, 23, 42, 0.22);
    display: none;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(8px) scale(0.96);
    opacity: 0;
    transition: transform 0.25s ease, opacity 0.25s ease;
    pointer-events: auto;
}

.cs-panel:not(.show) {
    display: none !important;
    visibility: hidden;
    pointer-events: none;
}
.cs-panel.show {
    display: flex;
    transform: translateY(0) scale(1);
    opacity: 1;
}
.cs-panel-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.cs-panel-title {
    font-size: 15px;
    font-weight: 700;
}
.cs-panel-sub {
    font-size: 11px;
    opacity: 0.88;
    margin-top: 2px;
}
.cs-panel-close {
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    flex-shrink: 0;
}
.cs-panel-close:hover { background: rgba(255,255,255,0.32); }

.cs-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px;
    background: #f8fafc;
    -webkit-overflow-scrolling: touch;
}
.cs-msg {
    display: flex;
    margin-bottom: 12px;
    gap: 8px;
}
.cs-msg.user { flex-direction: row-reverse; }
.cs-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}
.cs-msg.admin .cs-msg-avatar {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
}
.cs-msg-body { max-width: 78%; min-width: 0; }
.cs-msg-name {
    font-size: 11px;
    color: #94a3b8;
    margin-bottom: 4px;
}
.cs-msg.user .cs-msg-name { text-align: right; }
.cs-msg-bubble {
    padding: 10px 12px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
    background: #fff;
    color: #334155;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.cs-msg.user .cs-msg-bubble {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
}
.cs-msg-time {
    font-size: 10px;
    color: #cbd5e1;
    margin-top: 4px;
}
.cs-msg.user .cs-msg-time { text-align: right; }

.cs-empty {
    text-align: center;
    color: #94a3b8;
    font-size: 13px;
    padding: 40px 16px;
}

.cs-input-area {
    padding: 10px 12px 12px;
    border-top: 1px solid #eef2f7;
    background: #fff;
    flex-shrink: 0;
}
.cs-input-row {
    display: flex;
    gap: 6px;
    align-items: flex-end;
}
.cs-image-btn {
    width: 36px;
    height: 36px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #fff;
    font-size: 16px;
    cursor: pointer;
    flex-shrink: 0;
    line-height: 1;
    padding: 0;
}
.cs-image-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.cs-msg-img {
    max-width: 180px;
    max-height: 180px;
    border-radius: 8px;
    display: block;
    cursor: pointer;
}
.cs-msg-bubble img.cs-msg-img {
    padding: 0;
    background: transparent;
    box-shadow: none;
}
.cs-input {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 14px;
    resize: none;
    min-height: 40px;
    max-height: 100px;
    line-height: 1.4;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
}
.cs-input:focus { border-color: #667eea; }
.cs-send-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    flex-shrink: 0;
    transition: opacity 0.15s;
}
.cs-send-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.cs-send-btn:not(:disabled):hover { opacity: 0.9; }

@media (max-width: 768px) {
    /* 开奖区内：浮在右上角，不挤压号码行 */
    .hall-draw-inner .cs-draw-fab {
        position: absolute;
        top: 50%;
        right: 4px;
        transform: translateY(-50%);
        margin-left: 0;
        padding: 2px;
        border-left: none;
        min-width: 38px;
        z-index: 4;
    }

    .cs-draw-fab {
        padding-left: 12px;
        padding-right: 2px;
        min-width: 36px;
    }

    .hall-draw-inner .cs-draw-fab-logo,
    .cs-draw-fab-logo {
        width: 28px;
        height: 28px;
    }

    .hall-draw-inner .cs-draw-fab-text {
        font-size: 9px;
    }

    .cs-panel {
        position: fixed;
        left: 8px;
        right: 8px;
        top: max(148px, calc(env(safe-area-inset-top, 0px) + 136px));
        bottom: auto;
        width: auto;
        height: min(380px, calc(100dvh - 168px));
        max-height: calc(100dvh - 168px);
        border-radius: 14px;
        box-shadow: 0 8px 32px rgba(15, 23, 42, 0.28);
        transform: none;
    }

    .cs-panel.show {
        transform: none;
    }

    .cs-unread-tip {
        top: max(92px, calc(env(safe-area-inset-top, 0px) + 80px));
    }
    .cs-panel-header {
        padding: 10px 12px;
    }
    .cs-panel-title {
        font-size: 14px;
    }
    .cs-panel-sub {
        font-size: 10px;
        line-height: 1.35;
    }
    .cs-messages {
        padding: 10px;
    }
    .cs-msg-bubble {
        font-size: 13px;
        padding: 8px 10px;
    }
    .cs-input-area {
        padding: 8px 10px max(10px, env(safe-area-inset-bottom, 0px));
    }
    .cs-input {
        font-size: 13px;
        min-height: 36px;
    }
}

@media (max-width: 480px) {
    .cs-draw-fab-logo {
        width: 26px;
        height: 26px;
    }

    .cs-panel {
        left: 6px;
        right: 6px;
        top: max(140px, calc(env(safe-area-inset-top, 0px) + 128px));
        height: min(340px, calc(100dvh - 156px));
        max-height: calc(100dvh - 156px);
    }
    .cs-panel-sub {
        display: none;
    }
}
