/*
 * WP Chat Plugin - WhatsApp Style Clean Version
 */

/* Chat toggle button - fixed at bottom right */
.wp-chat-toggle {
    position: fixed !important;
    bottom: 20px !important;
    right: 20px !important;
    width: 65px !important;
    height: 65px !important;
    background: #25D366 !important;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    box-shadow: 0 6px 20px rgba(37, 211, 102, 0.4) !important;
    transition: all 0.3s ease !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    z-index: 999999 !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    border: none !important;
    outline: none !important;
}

.wp-chat-toggle:hover {
    transform: scale(1.1) !important;
    box-shadow: 0 8px 25px rgba(37, 211, 102, 0.6) !important;
}

/* New message indicator */
.wp-chat-toggle.has-new-message {
    animation: pulse 2s infinite !important;
}

.wp-chat-toggle .new-message-indicator {
    position: absolute !important;
    top: -5px !important;
    right: -5px !important;
    width: 20px !important;
    height: 20px !important;
    background: #ff4444 !important;
    border-radius: 50% !important;
    border: 2px solid white !important;
    animation: bounce 1s infinite !important;
}

@keyframes pulse {
    0% { box-shadow: 0 6px 20px rgba(37, 211, 102, 0.4); }
    50% { box-shadow: 0 6px 20px rgba(37, 211, 102, 0.8), 0 0 0 10px rgba(37, 211, 102, 0.2); }
    100% { box-shadow: 0 6px 20px rgba(37, 211, 102, 0.4); }
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-5px); }
    60% { transform: translateY(-3px); }
}

.wp-chat-toggle svg {
    width: 28px !important;
    height: 28px !important;
    fill: white !important;
    color: white !important;
    display: block !important;
    max-width: 100% !important;
    max-height: 100% !important;
    pointer-events: none !important;
}

/* Chat container - WhatsApp style popup */
.wp-chat-container {
    position: fixed !important;
    bottom: 90px !important;
    right: 20px !important;
    width: 380px !important;
    height: auto !important;
    background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%) !important;
    border-radius: 20px 20px 8px 20px !important;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.12), 0 8px 25px rgba(0, 0, 0, 0.08) !important;
    border: 1px solid rgba(37, 211, 102, 0.1) !important;
    display: none !important;
    flex-direction: column !important;
    z-index: 1000000 !important;
    overflow: hidden !important;
    opacity: 0 !important;
    transform: translateY(20px) scale(0.95) !important;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    backdrop-filter: blur(10px) !important;
}

.wp-chat-container.open {
    display: flex !important;
    transform: translateY(0) scale(1) !important;
    opacity: 1 !important;
}

/* Chat header */
.wp-chat-header {
    background: linear-gradient(135deg, #128c7e 0%, #075e54 100%) !important;
    color: white !important;
    padding: 15px 20px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    border-radius: 20px 20px 0 0 !important;
    position: relative !important;
    overflow: hidden !important;
    height: 20% !important; /* 1/5 = 20% */
    min-height: 60px !important;
}

.wp-chat-header::before {
    content: '' !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    background: linear-gradient(45deg, rgba(255,255,255,0.1) 0%, transparent 50%, rgba(255,255,255,0.05) 100%) !important;
    pointer-events: none !important;
}

.wp-chat-header-avatar {
    width: 48px !important;
    height: 48px !important;
    background: linear-gradient(135deg, #25D366 0%, #128c7e 100%) !important;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-weight: 700 !important;
    font-size: 16px !important;
    color: white !important;
    margin-right: 15px !important;
    position: relative !important;
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3) !important;
    border: 3px solid rgba(255, 255, 255, 0.2) !important;
    z-index: 1 !important;
}

.wa-online-dot-header { 
    position: absolute !important; 
    bottom: 2px !important; 
    right: 2px !important; 
    width: 14px !important; 
    height: 14px !important; 
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%) !important; 
    border: 3px solid #075e54 !important; 
    border-radius: 50% !important; 
    box-shadow: 0 2px 6px rgba(34, 197, 94, 0.4) !important;
    animation: pulse-online 2s infinite !important;
}

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

.wp-chat-header-info {
    flex: 1 !important;
    z-index: 1 !important;
}

.wp-chat-header-info h3 {
    margin: 0 !important;
    font-size: 18px !important;
    font-weight: 700 !important;
    letter-spacing: -0.5px !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1) !important;
}

.wp-chat-header-info p {
    margin: 4px 0 0 0 !important;
    font-size: 13px !important;
    opacity: 0.9 !important;
    font-weight: 500 !important;
}

.wp-chat-close {
    background: rgba(255, 255, 255, 0.1) !important;
    border: none !important;
    color: white !important;
    font-size: 20px !important;
    cursor: pointer !important;
    padding: 0 !important;
    width: 36px !important;
    height: 36px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 50% !important;
    transition: all 0.3s ease !important;
    backdrop-filter: blur(10px) !important;
    z-index: 1 !important;
    font-weight: 300 !important;
}

.wp-chat-close:hover {
    background: rgba(255, 255, 255, 0.2) !important;
    transform: scale(1.1) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2) !important;
}

/* Chat messages */
.wp-chat-messages { display: none !important; }

.wp-chat-message { display: none !important; }

.wp-chat-message.user {
    background: #dcf8c6 !important;
    align-self: flex-end !important;
    border-bottom-right-radius: 2px !important;
    margin-left: 50px !important;
    margin-right: 0 !important;
}

.wp-chat-message.admin {
    background: white !important;
    align-self: flex-start !important;
    border-bottom-left-radius: 2px !important;
    margin-right: 50px !important;
    margin-left: 0 !important;
}

/* Chat input */
.wp-chat-input-container { display: none !important; }

.wp-chat-input { display: none !important; }

.wp-chat-input:focus {
    border-color: #25D366 !important;
}

.wp-chat-send { display: none !important; }

.wp-chat-send:hover {
    background: #128c7e !important;
}

.wp-chat-send svg {
    width: 16px !important;
    height: 16px !important;
    fill: white !important;
}

/* Mobile responsive - WhatsApp style */
@media (max-width: 768px) {
    .wp-chat-container {
        width: calc(100vw - 20px) !important;
        max-width: 350px !important;
        height: calc(100vh - 100px) !important;
        max-height: 500px !important;
        bottom: 90px !important;
        right: 10px !important;
        left: 10px !important;
        margin: 0 auto !important;
        border-radius: 15px 15px 4px 15px !important;
        transform: translateY(20px) scale(0.95) !important;
        opacity: 0 !important;
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12) !important;
        position: fixed !important;
    }
    
    .wp-chat-container.open {
        transform: translateY(0) scale(1) !important;
        opacity: 1 !important;
    }
    
    .wp-chat-toggle {
        width: 60px !important;
        height: 60px !important;
        bottom: 20px !important;
        right: 20px !important;
        box-shadow: 0 4px 20px rgba(37, 211, 102, 0.5) !important;
    }
    
    .wp-chat-toggle svg {
        width: 28px !important;
        height: 28px !important;
    }
    
    .wp-chat-header {
        background: linear-gradient(135deg, #128c7e 0%, #075e54 100%) !important;
        padding: 15px 20px !important;
        border-radius: 15px 15px 0 0 !important;
        position: relative !important;
    }
    
    .wp-chat-messages {
        flex: 1 !important;
        padding: 15px !important;
        background: #f0f2f5 !important;
        background-image: 
            radial-gradient(circle at 25px 25px, rgba(255,255,255,.2) 2%, transparent 0%), 
            radial-gradient(circle at 75px 75px, rgba(255,255,255,.2) 2%, transparent 0%) !important;
        background-size: 100px 100px !important;
        overflow-y: auto !important;
    }
    
    .wp-chat-input-container {
        padding: 15px !important;
        background: white !important;
        border-top: 1px solid #e0e0e0 !important;
    }
    
    .wp-chat-input {
        border-radius: 25px !important;
        padding: 12px 20px !important;
        font-size: 16px !important;
        border: 1px solid #ddd !important;
        background: white !important;
    }
    
    .wp-chat-send {
        width: 44px !important;
        height: 44px !important;
        margin-left: 8px !important;
    }
}

/* Extra small mobile devices */
@media (max-width: 480px) {
    .wp-chat-container {
        width: calc(100vw - 10px) !important;
        height: calc(100vh - 80px) !important;
        bottom: 80px !important;
        right: 5px !important;
        left: 5px !important;
        border-radius: 10px 10px 4px 10px !important;
    }
    
    .wp-chat-toggle {
        width: 55px !important;
        height: 55px !important;
        bottom: 15px !important;
        right: 15px !important;
    }
    
    .wp-chat-toggle svg {
        width: 24px !important;
        height: 24px !important;
    }
    
    .wp-chat-header {
        padding: 12px 15px !important;
        border-radius: 10px 10px 0 0 !important;
    }
    
    .wp-chat-header-avatar {
        width: 35px !important;
        height: 35px !important;
        font-size: 12px !important;
    }
    
    .wp-chat-header-info h3 {
        font-size: 14px !important;
    }
    
    .wp-chat-header-info p {
        font-size: 11px !important;
    }
    
    .wp-chat-messages {
        padding: 10px !important;
    }
    
    .wp-chat-message {
        font-size: 13px !important;
        padding: 6px 10px !important;
    }
    
    .wp-chat-input-container {
        padding: 10px !important;
    }
    
    .wp-chat-input {
        padding: 10px 15px !important;
        font-size: 16px !important; /* Prevents zoom on iOS */
        border-radius: 20px !important;
    }
    
    .wp-chat-send {
        width: 40px !important;
        height: 40px !important;
    }
    
    .wp-chat-send svg {
        width: 14px !important;
        height: 14px !important;
    }
}

/* Typing indicator */
.typing-indicator {
    background: #f0f0f0 !important;
    border-radius: 15px !important;
    padding: 8px 12px !important;
    max-width: 60px !important;
    align-self: flex-start !important;
    margin-right: 50px !important;
    margin-left: 0 !important;
    border-bottom-left-radius: 2px !important;
}

.typing-dots {
    display: flex !important;
    gap: 4px !important;
    justify-content: center !important;
}

.typing-dots span {
    width: 8px !important;
    height: 8px !important;
    background: #999 !important;
    border-radius: 50% !important;
    animation: typing 1.4s infinite ease-in-out !important;
}

.typing-dots span:nth-child(1) {
    animation-delay: -0.32s !important;
}

.typing-dots span:nth-child(2) {
    animation-delay: -0.16s !important;
}

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

/* WhatsApp Popup Body Styles */
.wa-popup-body {
    padding: 0 !important;
    background: transparent !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    gap: 0 !important;
    height: 300px !important; /* 恢复原来的高度 */
    position: relative !important;
}

/* 中间气泡信息区域 - 有图案背景 (增加高度) */
.wa-bubble-section {
    width: 100% !important;
    height: 66.67% !important; /* 增加高度以填补底部减少的空间 */
    padding: 10px 20px 20px 20px !important; /* 减少顶部内边距，让气泡靠近题头 */
    background: #f0f2f5 !important;
    background-image: 
        radial-gradient(circle at 20px 20px, rgba(0, 0, 0, 0.05) 1px, transparent 1px),
        radial-gradient(circle at 60px 60px, rgba(0, 0, 0, 0.03) 1px, transparent 1px),
        radial-gradient(circle at 100px 100px, rgba(0, 0, 0, 0.02) 1px, transparent 1px) !important;
    background-size: 80px 80px !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-start !important; /* 左对齐，类似WhatsApp */
    justify-content: flex-start !important; /* 顶部对齐 */
    gap: 10px !important;
    position: relative !important;
}

.wa-hero {
    position: relative !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-start !important; /* 左对齐，类似WhatsApp */
    gap: 8px !important;
    margin-bottom: 0 !important;
    width: 100% !important;
}

.wa-hero-image {
    width: 90px !important;
    height: 90px !important;
    border-radius: 50% !important;
    object-fit: cover !important;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15), 0 4px 12px rgba(37, 211, 102, 0.2) !important;
    border: 4px solid rgba(255, 255, 255, 0.8) !important;
    transition: all 0.3s ease !important;
}

.wa-hero-image:hover {
    transform: scale(1.05) !important;
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.2), 0 6px 18px rgba(37, 211, 102, 0.3) !important;
}

.wa-bubble {
    background: linear-gradient(135deg, #b8e6b8 0%, #a5d6a7 100%) !important;
    color: #1b5e20 !important;
    padding: 10px 14px !important;
    border-radius: 18px 18px 18px 4px !important;
    font-size: 13px !important;
    line-height: 1.4 !important;
    width: 57% !important; /* WhatsApp按钮85%的2/3 = 约57% */
    text-align: left !important; /* 左对齐文本 */
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1), 0 2px 8px rgba(37, 211, 102, 0.2) !important;
    position: relative !important;
    font-weight: 500 !important;
    border: 1px solid rgba(37, 211, 102, 0.1) !important;
    backdrop-filter: blur(5px) !important;
    word-wrap: break-word !important;
    white-space: normal !important;
    min-height: 2.8em !important; /* 确保有足够高度显示两行 */
}

.wa-bubble::before {
    content: '' !important;
    position: absolute !important;
    bottom: -10px !important;
    left: 25px !important;
    width: 0 !important;
    height: 0 !important;
    border-left: 10px solid transparent !important;
    border-right: 10px solid transparent !important;
    border-top: 10px solid #b8e6b8 !important;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1)) !important;
}

/* 下面WhatsApp按钮区域 - 纯白色背景 (降低1/3) */
.wa-button-section {
    width: 100% !important;
    height: 13.33% !important; /* 原来20%降低1/3 = 13.33% */
    padding: 8px 20px !important;
    background: #ffffff !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 6px !important;
}

.wa-button {
    display: inline-flex !important;
    align-items: center !important;
    gap: 8px !important;
    background: #25D366 !important;
    color: white !important;
    padding: 8px 16px !important;
    border-radius: 20px !important;
    text-decoration: none !important;
    font-weight: 600 !important;
    font-size: 14px !important;
    box-shadow: 0 4px 15px rgba(37, 211, 102, 0.4) !important;
    transition: all 0.3s ease !important;
    border: none !important;
    cursor: pointer !important;
    position: relative !important;
    letter-spacing: 0.3px !important;
    width: 85% !important; /* 比气泡更宽，占宽度的85% */
    justify-content: center !important;
}


.wa-button:hover {
    background: #128c7e !important;
    transform: translateY(-2px) !important;
    box-shadow: 0 6px 20px rgba(37, 211, 102, 0.6) !important;
    color: white !important;
    text-decoration: none !important;
}

.wa-button-icon {
    width: 20px !important;
    height: 20px !important;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="white"><path d="M12.04 2C6.58 2 2.13 6.45 2.13 11.91C2.13 13.66 2.59 15.31 3.48 16.73L2.11 22L7.5 20.63C8.86 21.39 10.4 21.8 12.04 21.8C17.5 21.8 21.95 17.35 21.95 11.89C21.95 6.43 17.5 2 12.04 2ZM17.14 16.15C16.88 16.72 15.24 17.57 14.85 17.69C14.46 17.81 14.17 17.81 13.88 17.69C13.59 17.57 12.67 17.29 11.53 16.29C10.6 15.45 9.98 14.44 9.7 13.95C9.42 13.46 9.2 13.19 8.93 12.62C8.66 12.05 7.97 11.39 7.71 11.12C7.44 10.85 7.2 10.79 7.01 10.79C6.82 10.79 6.61 10.79 6.4 10.79C6.19 10.79 5.86 10.87 5.58 11.15C5.3 11.43 4.5 12.19 4.5 13.66C4.5 15.13 5.53 16.56 5.67 16.73C5.81 16.9 7.3 19.31 9.66 20.3C11.93 21.2 12.3 21.08 13.88 20.96C15.46 20.84 17.04 19.93 17.32 19.36C17.6 18.79 17.6 18.31 17.52 18.14C17.44 17.97 17.44 17.81 17.14 17.24L17.14 16.15Z"/></svg>') no-repeat center !important;
    background-size: contain !important;
}

.wa-footer {
    display: flex !important;
    align-items: center !important;
    gap: 4px !important;
    font-size: 11px !important;
    color: #666 !important;
    margin-top: 2px !important;
    padding: 2px 0 !important;
    border-top: 1px solid rgba(37, 211, 102, 0.1) !important;
    justify-content: center !important;
}

.wa-online-dot {
    width: 10px !important;
    height: 10px !important;
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%) !important;
    border-radius: 50% !important;
    animation: pulse-dot 2s infinite !important;
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.4) !important;
}

.wa-sep {
    color: #ccc !important;
    font-weight: 300 !important;
}

.wa-privacy {
    color: #666 !important;
    text-decoration: none !important;
    font-size: 12px !important;
    transition: color 0.3s ease !important;
    font-weight: 500 !important;
}

.wa-privacy:hover {
    color: #25D366 !important;
    text-decoration: underline !important;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Mobile responsive for popup */
@media (max-width: 768px) {
    .wp-chat-container {
        width: calc(100vw - 20px) !important;
        max-width: 360px !important;
        bottom: 90px !important;
        right: 10px !important;
        left: 10px !important;
        margin: 0 auto !important;
    }
    
    .wa-popup-body {
        padding: 25px 20px !important;
        gap: 20px !important;
    }
    
    .wa-hero-image {
        width: 80px !important;
        height: 80px !important;
    }
    
    .wa-bubble {
        padding: 14px 18px !important;
        font-size: 14px !important;
        max-width: 220px !important;
    }
    
    .wa-button {
        padding: 16px 32px !important;
        font-size: 16px !important;
        min-width: 180px !important;
    }
    
    .wa-button-icon {
        width: 20px !important;
        height: 20px !important;
    }
    
    .wp-chat-header {
        padding: 18px 20px !important;
    }
    
    .wp-chat-header-avatar {
        width: 44px !important;
        height: 44px !important;
        font-size: 15px !important;
    }
    
    .wp-chat-header-info h3 {
        font-size: 16px !important;
    }
    
    .wp-chat-header-info p {
        font-size: 12px !important;
    }
}

/* Hide in admin */
body.wp-admin .wp-chat-toggle,
body.wp-admin .wp-chat-container {
    display: none !important;
}