/* 客服系统样式 */

/* 浮动按钮 */
.cs-float-button {
    position: fixed;
    bottom: 90px;
    right: 30px;
    width: 68px;
    height: 68px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: 3px solid rgba(255, 255, 255, 0.95);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 15px 35px rgba(102, 126, 234, 0.4), 0 5px 15px rgba(102, 126, 234, 0.2), 0 0 0 0 rgba(102, 126, 234, 0.1);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 9999;
    animation: float 3s ease-in-out infinite, pulse-glow 2s ease-in-out infinite;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

@keyframes float {
    0%, 100% {
        transform: translateY(0px);
    }
    50% {
        transform: translateY(-10px);
    }
}

@keyframes pulse-glow {
    0%, 100% {
        box-shadow: 0 15px 35px rgba(102, 126, 234, 0.4), 0 5px 15px rgba(102, 126, 234, 0.2), 0 0 0 0 rgba(102, 126, 234, 0.1);
    }
    50% {
        box-shadow: 0 15px 35px rgba(102, 126, 234, 0.4), 0 5px 15px rgba(102, 126, 234, 0.2), 0 0 0 15px rgba(102, 126, 234, 0);
    }
}

.cs-float-button:hover {
    transform: scale(1.1) translateY(-2px);
    box-shadow: 0 20px 40px rgba(102, 126, 234, 0.5), 0 8px 20px rgba(102, 126, 234, 0.3);
    background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);
    border-color: rgba(255, 255, 255, 1);
}

.cs-float-button:active {
    transform: scale(0.95);
    box-shadow: 0 10px 25px rgba(102, 126, 234, 0.3), 0 3px 10px rgba(102, 126, 234, 0.2);
}

.cs-float-button.offline {
    background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
    animation: none;
}

.cs-float-button.busy {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    animation: pulse 2s infinite;
}

.cs-float-button i {
    color: white;
    font-size: 26px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease;
}

.cs-float-button:hover i {
    transform: scale(1.1);
}

.cs-float-button.online {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.cs-float-button.offline {
    background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
}

/* 徽章 */
.cs-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ef4444;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
}

/* 聊天窗口 */
.cs-chat-window {
    position: fixed;
    bottom: 160px;
    right: 30px;
    width: 420px;
    max-height: 75vh;
    min-height: 500px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 24px;
    box-shadow: 0 30px 60px -15px rgba(102, 126, 234, 0.3), 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 0 0 1px rgba(102, 126, 234, 0.05);
    display: none;
    flex-direction: column;
    z-index: 9998;
    overflow: hidden;
}

/* 确保聊天窗口不会超出视窗 */
@media (max-height: 700px) {
    .cs-chat-window {
        max-height: calc(100vh - 120px);
        min-height: 300px;
    }
}

@media (max-height: 500px) {
    .cs-chat-window {
        max-height: calc(100vh - 140px);
        min-height: 250px;
        bottom: 130px;
    }
}

.cs-chat-window.active {
    display: flex;
    animation: slideUp 0.3s ease-out;
}

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

/* 聊天头部 */
.cs-chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 18px 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 24px 24px 0 0;
    position: relative;
    overflow: hidden;
}

.cs-chat-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    animation: shimmer 3s infinite;
}

.cs-chat-info {
    display: flex;
    align-items: center;
}

.cs-chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
}

.cs-chat-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.cs-chat-details h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.cs-chat-details p {
    margin: 0;
    font-size: 12px;
    opacity: 0.9;
}

.cs-chat-controls {
    display: flex;
    gap: 10px;
}

.cs-control-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.cs-control-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.cs-end-conversation-btn {
    background: rgba(239, 68, 68, 0.8);
    border: none;
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.cs-end-conversation-btn:hover {
    background: rgba(239, 68, 68, 0.9);
    transform: translateY(-1px);
}

.cs-end-conversation-btn i {
    font-size: 12px;
}

/* 聊天消息区域 */
.cs-chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 22px;
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    max-height: calc(75vh - 220px);
    min-height: 220px;
    position: relative;
}

.cs-chat-messages::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(102, 126, 234, 0.1), transparent);
}

/* 自定义滚动条样式 */
.cs-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.cs-chat-messages::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 3px;
}

.cs-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.3);
    border-radius: 3px;
}

.cs-chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(102, 126, 234, 0.5);
}

.cs-message {
    margin-bottom: 15px;
    display: flex;
    animation: messageSlide 0.3s ease-out;
}

@keyframes messageSlide {
    from {
        transform: translateX(-20px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.cs-message.user {
    justify-content: flex-end;
}

.cs-message-content {
    max-width: 70%;
    min-width: 60px;
    padding: 10px 16px;
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
    display: inline-block;
}

.cs-message.cs .cs-message-content {
    background: #ffffff;
    color: #374151;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border: 1px solid #e5e7eb;
    border-radius: 18px;
}

/* 短消息特殊处理 */
.cs-message.cs .cs-message-content:has(.cs-message-text:empty) {
    padding: 12px 16px;
    min-width: 80px;
    text-align: center;
}

.cs-message.cs .cs-message-content .cs-message-text:empty::before {
    content: "•";
    color: #9ca3af;
}

.message.user .cs-message-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 18px;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3), 0 2px 4px rgba(102, 126, 234, 0.2);
}

/* 用户短消息特殊处理 */
.message.user .cs-message-content:has(.cs-message-text:empty) {
    padding: 12px 16px;
    min-width: 80px;
    text-align: center;
}

.message.user .cs-message-content .cs-message-text:empty::before {
    content: "•";
    color: rgba(255, 255, 255, 0.7);
}

.cs-message-info {
    font-size: 11px;
    margin-top: 4px;
    opacity: 0.7;
    line-height: 1.2;
}

.message.cs .cs-message-info {
    text-align: left;
    color: #6b7280;
}

.message.user .cs-message-info {
    text-align: right;
    color: rgba(255, 255, 255, 0.8);
    justify-content: flex-end;
}

/* 单字符消息优化 */
.cs-message-content .cs-message-text {
    word-break: break-word;
    min-height: 20px;
    display: inline-block;
}

/* 防止消息内容过小 */
.cs-message-content .cs-message-text:only-child:empty {
    min-width: 40px;
    min-height: 20px;
}

/* 徽入区域 */
.cs-chat-input {
    padding: 20px;
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
    border-radius: 0 0 24px 24px 0 0;
}

.cs-input-container {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

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

.cs-input {
    width: 100%;
    padding: 12px 45px 12px 16px;
    border: 2px solid #e5e7eb;
    background: #f9fafb;
    border-radius: 24px;
    outline: none;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    max-height: 120px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    color: #000000;
}

.cs-input:focus {
    border-color: #667eea;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1), 0 0 0 1px rgba(102, 126, 234, 0.05), 0 4px 12px rgba(102, 126, 234, 0.1);
    color: #000000;
}

.cs-input-tools {
    position: absolute;
    right: 8px;
    bottom: 8px;
    display: flex;
    gap: 5px;
}

.cs-tool-btn {
    background: none;
    border: none;
    color: #6b7280;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.cs-tool-btn:hover {
    background: #f3f4f6;
    color: #667eea;
    transform: scale(1.1);
}

.cs-send-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3), 0 2px 4px rgba(102, 126, 234, 0.2);
}

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

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

/* 欢迎界面 */
.cs-welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    text-align: center;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.9) 0%, rgba(248, 250, 252, 0.9) 100%);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    overflow-y: auto;
    overflow-x: hidden;
    max-height: calc(75vh - 140px);
    min-height: 320px;
    position: relative;
}

.cs-welcome::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at 50% 50%, rgba(102, 126, 234, 0.05) 0%, transparent 70%);
    pointer-events: none;
}

/* 欢迎界面滚动条 */
.cs-welcome::-webkit-scrollbar {
    width: 6px;
}

.cs-welcome::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 3px;
}

.cs-welcome::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.3);
    border-radius: 3px;
}

.cs-welcome::-webkit-scrollbar-thumb:hover {
    background: rgba(102, 126, 234, 0.5);
}

.cs-welcome-icon {
    width: 88px;
    height: 88px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3), 0 4px 12px rgba(102, 126, 234, 0.2);
    animation: welcome-icon-pulse 2s ease-in-out infinite;
    position: relative;
    z-index: 1;
}

@keyframes welcome-icon-pulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3), 0 4px 12px rgba(102, 126, 234, 0.2);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 12px 30px rgba(102, 126, 234, 0.4), 0 6px 15px rgba(102, 126, 234, 0.3);
    }
}

.cs-welcome-icon i {
    color: white;
    font-size: 40px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.cs-welcome h3 {
    margin: 0 0 10px 0;
    color: #1f2937;
    font-size: 20px;
}

.cs-welcome p {
    margin: 0 0 30px 0;
    color: #6b7280;
    font-size: 14px;
    line-height: 1.5;
}

.cs-welcome-form {
    width: 100%;
    max-width: 300px;
}

.cs-form-group {
    margin-bottom: 15px;
}

.cs-form-group label {
    display: block;
    margin-bottom: 5px;
    color: #374151;
    font-size: 14px;
    font-weight: 500;
}

.cs-form-group input,
.cs-form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid rgba(209, 213, 219, 0.5);
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border-radius: 12px;
    outline: none;
    font-family: inherit;
    font-size: 14px;
    transition: all 0.2s ease;
    color: #000000;
}

.cs-form-group input:focus,
.cs-form-group textarea:focus {
    border-color: rgba(102, 126, 234, 0.5);
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
    color: #000000;
}

.cs-form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.cs-start-btn {
    width: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
    padding: 14px 24px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3), 0 2px 4px rgba(102, 126, 234, 0.2);
    position: relative;
    overflow: hidden;
    z-index: 1;
}

.cs-start-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s ease;
    z-index: -1;
}

.cs-start-btn:hover::before {
    left: 100%;
}

.cs-start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.4), 0 4px 8px rgba(102, 126, 234, 0.3);
    background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);
}

.cs-start-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 输入状态 */
.cs-typing-indicator {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    background: white;
    border-radius: 18px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    margin-bottom: 15px;
    max-width: 60px;
}

.cs-typing-dots {
    display: flex;
    gap: 3px;
}

.cs-typing-dot {
    width: 8px;
    height: 8px;
    background: #6b7280;
    border-radius: 50%;
    animation: typingDot 1.4s infinite ease-in-out;
}

.cs-typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

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

@keyframes typingDot {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* 响应式设计 */
@media (max-width: 480px) {
    .cs-float-button {
        bottom: 80px;
        right: 20px;
        width: 56px;
        height: 56px;
    }
    
    .cs-chat-window {
        width: calc(100vw - 24px);
        max-height: calc(100vh - 180px);
        min-height: 350px;
        bottom: 140px;
        right: 12px;
        left: 12px;
        border-radius: 16px;
    }
    
    .cs-chat-messages {
        max-height: calc(100vh - 280px);
        min-height: 180px;
        padding: 16px;
    }
    
    .cs-welcome {
        max-height: calc(100vh - 180px);
        min-height: 250px;
        padding: 24px 16px;
    }
    
    .cs-message-content {
        max-width: 85%;
    }
    
    .cs-chat-header {
        padding: 12px 16px;
    }
    
    .cs-chat-input {
        padding: 16px;
    }
}

/* 超小屏幕适配 */
@media (max-width: 360px) {
    .cs-float-button {
        bottom: 76px;
        right: 16px;
        width: 52px;
        height: 52px;
    }
    
    .cs-chat-window {
        width: calc(100vw - 16px);
        max-height: calc(100vh - 150px);
        min-height: 320px;
        bottom: 130px;
        right: 8px;
        left: 8px;
        border-radius: 12px;
    }
    
    .cs-chat-messages {
        max-height: calc(100vh - 250px);
        min-height: 160px;
        padding: 12px;
    }
    
    .cs-welcome {
        max-height: calc(100vh - 150px);
        min-height: 220px;
        padding: 20px 12px;
    }
    
    .cs-chat-header {
        padding: 10px 12px;
    }
    
    .cs-chat-header h4 {
        font-size: 14px;
    }
    
    .cs-chat-input {
        padding: 12px;
    }
    
    .cs-welcome h3 {
        font-size: 18px;
    }
    
    .cs-welcome p {
        font-size: 13px;
    }
}

/* 连接状态 */
.cs-status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
}

.cs-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.cs-status-dot.online {
    background: #10b981;
}

.cs-status-dot.offline {
    background: #6b7280;
}

.cs-status-dot.busy {
    background: #f59e0b;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 currentColor;
    }
    70% {
        box-shadow: 0 0 0 4px rgba(0, 0, 0, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(0, 0, 0, 0);
    }
}