/* 在线客服聊天样式 */

/* 悬浮按钮 */
.chat-float-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    transition: all 0.3s ease;
    z-index: 999;
}

.chat-float-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 30px rgba(102, 126, 234, 0.6);
}

.chat-float-btn.hidden {
    display: none;
}

/* 未读消息气泡 */
.chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4757;
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

/* 聊天窗口容器 */
.chat-window {
    position: fixed;
    bottom: 100px;
    right: 30px;
    width: 400px;
    height: 600px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 998;
    overflow: hidden;
}

.chat-window.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* 聊天头部 */
.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 16px 16px 0 0;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.chat-header-text h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.chat-header-text p {
    margin: 4px 0 0 0;
    font-size: 12px;
    opacity: 0.9;
}

.chat-header-actions {
    display: flex;
    gap: 8px;
}

.chat-header-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    font-size: 18px;
}

.chat-header-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* 聊天消息区域 */
.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 3px;
}

/* 消息项 */
.chat-message {
    display: flex;
    gap: 10px;
    animation: messageSlideIn 0.3s ease;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.chat-message.user .message-avatar {
    background: linear-gradient(135deg, #48c6ef 0%, #6f86d6 100%);
}

.message-content {
    max-width: 70%;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: 16px;
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    word-wrap: break-word;
    line-height: 1.5;
}

.chat-message.user .message-bubble {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.message-time {
    font-size: 11px;
    color: #999;
    padding: 0 8px;
}

.chat-message.user .message-time {
    text-align: right;
}

/* 系统消息 */
.chat-message.system {
    justify-content: center;
}

.chat-message.system .message-bubble {
    background: #e9ecef;
    font-size: 12px;
    color: #6c757d;
    padding: 8px 12px;
    border-radius: 12px;
}

/* 输入区域 */
.chat-input-area {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid #e9ecef;
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.chat-input-wrapper {
    flex: 1;
    position: relative;
}

.chat-input {
    width: 100%;
    border: 1px solid #e9ecef;
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 14px;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
    max-height: 100px;
    min-height: 44px;
}

.chat-input:focus {
    border-color: #667eea;
}

.chat-send-btn {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: transform 0.2s;
    flex-shrink: 0;
}

.chat-send-btn:hover:not(:disabled) {
    transform: scale(1.05);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 输入工具栏 */
.chat-input-toolbar {
    display: flex;
    gap: 8px;
    padding: 8px 0 0 0;
}

.toolbar-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: #6c757d;
    cursor: pointer;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.2s;
}

.toolbar-btn:hover {
    background: #f8f9fa;
    color: #667eea;
}

/* 移动端适配 */
@media (max-width: 768px) {
    .chat-window {
        width: 100%;
        height: 100vh;
        height: 100dvh; /* 动态视口高度,考虑移动端浏览器地址栏 */
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        border-radius: 0;
        max-height: 100vh;
        max-height: 100dvh;
    }

    .chat-float-btn {
        bottom: 20px;
        right: 20px;
        width: 56px;
        height: 56px;
        font-size: 24px;
    }

    /* 聊天窗口打开时隐藏悬浮按钮 */
    .chat-window.active ~ .chat-float-btn {
        opacity: 0;
        pointer-events: none;
        transform: scale(0);
    }

    /* 移动端头部调整 */
    .chat-header {
        padding: 16px 20px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }

    .chat-header-btn {
        width: 40px;
        height: 40px;
        font-size: 24px;
        border-radius: 50%;
    }

    .chat-header-text h3 {
        font-size: 18px;
    }

    .chat-header-text p {
        font-size: 13px;
    }

    /* 消息区域调整 */
    .chat-messages {
        padding: 16px;
        gap: 16px;
    }

    /* 消息气泡在移动端可以更宽 */
    .message-content {
        max-width: 80%;
    }

    .message-bubble {
        padding: 14px 18px;
        font-size: 15px;
        line-height: 1.6;
    }

    /* 输入区域移动端优化 */
    .chat-input-area {
        padding: 12px 16px;
        padding-bottom: max(12px, env(safe-area-inset-bottom)); /* 适配刘海屏 */
        background: white;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    }

    .chat-input {
        font-size: 16px; /* 防止 iOS 缩放 */
        padding: 14px 16px;
        min-height: 48px;
        border-radius: 24px;
    }

    .chat-send-btn {
        width: 48px;
        height: 48px;
        font-size: 22px;
        border-radius: 50%;
    }

    /* 头像在移动端稍大 */
    .message-avatar {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }

    .chat-avatar {
        width: 44px;
        height: 44px;
        font-size: 22px;
    }
}

/* 打字动画 */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #999;
    animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-10px);
    }
}
