#xzr8-chat {
    position: fixed;
    bottom: 25px;
    right: 25px;
    z-index: 999999;
}

#chat-ui {
    display: none;
    width: 360px;
    height: 520px;
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 12px 50px rgba(0, 0, 0, 0.15);
    flex-direction: column;
    overflow: hidden;
    margin-bottom: 20px;
    border: 1px solid rgba(0, 0, 0, 0.05);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

#chat-header {
    background: #ffb400;
    /* 亮橙色 */
    color: #1a1a1a;
    padding: 10px 15px;
    font-weight: 700;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 10px rgba(255, 180, 0, 0.2);
}

#chat-msgs {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    overflow-x: hidden !important;
    /* 消除水平滚动条 */
    background: #f4f7f9;
    /* 浅蓝灰底色 */
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#chat-input-area {
    padding: 15px;
    display: flex;
    align-items: center;
    background: #fff;
    border-top: 1px solid #eee;
    gap: 10px;
}

#xzr8-text {
    flex: 1;
    border: 1px solid #e0e0e0;
    padding: 10px 15px;
    background: #fff;
    border-radius: 8px;
    outline: none;
    font-size: 14px;
    transition: border 0.3s;
    box-shadow: none !important;
    -webkit-appearance: none !important;
}

#xzr8-text:focus {
    border-color: #ffb400;
}

/* 访客气泡 (右侧) */
.u-msg {
    background: #ffb400 !important;
    color: #1a1a1a !important;
    align-self: flex-end !important;
    margin: 4px 0 4px 15% !important;
    padding: 10px 14px !important;
    border-radius: 12px 12px 2px 12px !important;
    font-size: 14px !important;
    max-width: 80% !important;
    box-shadow: 0 2px 5px rgba(255, 180, 0, 0.2) !important;
    position: relative !important;
    word-break: break-all !important;
    white-space: pre-line !important;
    display: flex !important;
    flex-direction: column !important;
    width: fit-content !important;
    height: auto !important;
}

/* 客服气泡 (左侧) */
.a-msg {
    background: #fff !important;
    color: #333 !important;
    align-self: flex-start !important;
    margin: 4px 15% 4px 0 !important;
    padding: 10px 14px !important;
    border-radius: 12px 12px 12px 2px !important;
    border: 1px solid #e0e0e0 !important;
    font-size: 14px !important;
    max-width: 80% !important;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.03) !important;
    position: relative !important;
    word-break: break-all !important;
    white-space: pre-line !important;
    display: flex !important;
    flex-direction: column !important;
    width: fit-content !important;
    height: auto !important;
}

.u-msg span,
.a-msg span {
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
}

.m-time {
    font-size: 10px;
    opacity: 0.6;
    margin-top: 4px;
    display: block;
    text-align: right;
}

.a-msg .m-time {
    text-align: left;
}

#chat-bubble {
    width: 60px;
    height: 60px;
    background: #ffb400;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(255, 180, 0, 0.4);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#chat-bubble:hover {
    transform: scale(1.05);
}

.xzr8-icon-btn {
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, opacity 0.2s;
    opacity: 0.8;
}

.xzr8-icon-btn:hover {
    transform: scale(1.1);
    opacity: 1;
}

.xzr8-icon-btn:active {
    transform: scale(0.9);
}

/* 移动端安全适配 */
@media (max-width: 480px) {
    #chat-ui {
        width: 100vw !important;
        height: 100dvh !important;
        /* 动态视口高度，关键！ */
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        border-radius: 0 !important;
        margin: 0 !important;
        z-index: 1000000 !important;
        background: #fff !important;
        flex-direction: column;
        overflow: hidden;
    }

    #chat-msgs {
        flex: 1 !important;
        min-height: 0 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    #xzr8-chat {
        bottom: 20px !important;
        right: 20px !important;
    }

    #chat-header {
        padding: 0 15px !important;
        position: sticky !important;
        top: 0 !important;
        z-index: 1000001 !important;
        flex-shrink: 0 !important;
    }

    .mobile-close {
        visibility: visible !important;
    }

    #chat-input-area {
        flex-shrink: 0 !important;
        padding: 12px 10px !important;
        gap: 8px !important;
        background: #fff !important;
        border-top: 1px solid #eee !important;
        z-index: 100 !important;
        position: relative !important;
    }

    #xzr8-text {
        font-size: 16px !important;
        /* 防止 iOS 自动放大 */
        padding: 10px !important;
        height: 40px !important;
    }
}

.mobile-close {
    display: flex;
    visibility: hidden;
    cursor: pointer;
    padding: 10px 0;
    align-items: center;
    width: 24px;
}

.header-close {
    display: flex;
    cursor: pointer;
    padding: 10px 0;
    align-items: center;
    width: 24px;
}
