/* 客服聊天组件样式 */
.chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    max-width: calc(100vw - 48px);
}

/* 切换按钮 */
.chat-toggle {
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, #0F172A 0%, #1E293B 100%);
    border-radius: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    flex-shrink: 0;
}

.chat-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2), 0 3px 6px rgba(0, 0, 0, 0.15);
}

.chat-toggle svg {
    width: 28px;
    height: 28px;
    color: #F8FAFC;
}

.unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #F97316;
    color: #FFF;
    font-size: 11px;
    font-weight: 600;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    box-shadow: 0 2px 4px rgba(249, 115, 22, 0.4);
}

/* 聊天面板 */
.chat-panel {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 360px;
    height: 520px;
    background: #FFFFFF;
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12), 0 4px 8px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* 聊天头部 */
.chat-header {
    background: linear-gradient(135deg, #0F172A 0%, #1E293B 100%);
    color: #F8FAFC;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

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

.chat-close {
    background: none;
    border: none;
    color: #F8FAFC;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: background 0.2s;
}

.chat-close:hover {
    background: rgba(248, 250, 252, 0.1);
}

.chat-close svg {
    width: 20px;
    height: 20px;
}

/* 连接状态 */
.chat-status {
    padding: 10px 20px;
    background: #F8FAFC;
    border-bottom: 1px solid #E2E8F0;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    flex-shrink: 0;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #94A3B8;
}

.chat-status.online .status-dot {
    background: #22D3EE;
    box-shadow: 0 0 8px rgba(34, 211, 238, 0.5);
    animation: pulse 2s ease-in-out infinite;
}

.chat-status.connecting .status-dot {
    background: #F59E0B;
}

.chat-status.offline .status-dot {
    background: #94A3B8;
}

.chat-status.error .status-dot {
    background: #EF4444;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.status-text {
    color: #64748B;
    font-weight: 500;
}

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

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

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

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

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #94A3B8;
}

/* 消息气泡 */
.chat-message {
    display: flex;
    flex-direction: column;
    max-width: 75%;
    animation: messageSlideIn 0.3s ease-out;
}

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

.chat-message.own {
    align-self: flex-end;
    align-items: flex-end;
}

.chat-message.other {
    align-self: flex-start;
    align-items: flex-start;
}

.message-content {
    padding: 10px 14px;
    border-radius: 12px;
    word-wrap: break-word;
    white-space: pre-wrap;
    font-size: 14px;
    line-height: 1.5;
}

.chat-message.own .message-content {
    background: linear-gradient(135deg, #38BDF8 0%, #22D3EE 100%);
    color: #FFFFFF;
    border-bottom-right-radius: 4px;
}

.chat-message.other .message-content {
    background: #F1F5F9;
    color: #1E293B;
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 11px;
    color: #94A3B8;
    margin-top: 4px;
    padding: 0 4px;
}

/* 输入区域 */
.chat-input-wrapper {
    padding: 16px;
    background: #FFFFFF;
    border-top: 1px solid #E2E8F0;
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #CBD5E1;
    border-radius: 8px;
    font-size: 14px;
    resize: none;
    font-family: inherit;
    line-height: 1.5;
    max-height: 100px;
    transition: border-color 0.2s;
}

.chat-input:focus {
    outline: none;
    border-color: #38BDF8;
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.1);
}

.chat-input::placeholder {
    color: #94A3B8;
}

.chat-send {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #38BDF8 0%, #22D3EE 100%);
    border: none;
    border-radius: 8px;
    color: #FFFFFF;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}

.chat-send:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(56, 189, 248, 0.3);
}

.chat-send:active {
    transform: translateY(0);
}

.chat-send svg {
    width: 18px;
    height: 18px;
}

/* 移动端适配 */
@media (max-width: 768px) {
    .chat-widget {
        bottom: max(16px, env(safe-area-inset-bottom));
        right: 16px;
    }

    .chat-toggle {
        width: 54px;
        height: 54px;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    }

    .chat-panel {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        max-width: 100vw;
        border-radius: 0;
        box-shadow: none;
    }

    .chat-header {
        padding: 16px 20px;
        padding-top: max(16px, env(safe-area-inset-top));
    }

    .chat-messages {
        padding: 12px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .chat-input-wrapper {
        padding: 12px 16px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .chat-message {
        max-width: 85%;
    }

    .message-content {
        font-size: 15px;
        padding: 12px 16px;
    }

    .chat-input {
        font-size: 16px; /* 防止iOS自动放大 */
        padding: 12px 14px;
    }

    .chat-send {
        width: 44px;
        height: 44px;
    }
}

/* 小屏手机 */
@media (max-width: 375px) {
    .chat-widget {
        bottom: max(12px, env(safe-area-inset-bottom));
        right: 12px;
    }

    .chat-toggle {
        width: 50px;
        height: 50px;
    }

    .chat-toggle svg {
        width: 24px;
        height: 24px;
    }

    .unread-badge {
        top: -3px;
        right: -3px;
        min-width: 18px;
        height: 18px;
        font-size: 10px;
    }
}
