/**
 * Floating Contact Icon Component
 * 
 * Features:
 * - IP-based regional display (WeChat for China, WhatsApp for international)
 * - Responsive design with accessibility compliance
 * - Professional hover animations and shadows
 * - Non-intrusive positioning with proper spacing
 * - Cross-browser compatibility
 */

:root {
    --floating-contact-size: 56px;
    --floating-contact-size-mobile: 48px;
    --floating-contact-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    --floating-contact-shadow-hover: 0 6px 20px rgba(0, 0, 0, 0.25);
    --floating-contact-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --floating-contact-z-index: 9999;
    --floating-contact-spacing: 24px;
    --floating-contact-spacing-mobile: 20px;
}

/* Main floating contact button */
.floating-contact {
    position: fixed;
    bottom: var(--floating-contact-spacing);
    right: var(--floating-contact-spacing);
    width: var(--floating-contact-size);
    height: var(--floating-contact-size);
    background: #fff;
    border-radius: 50%;
    box-shadow: var(--floating-contact-shadow);
    cursor: pointer;
    z-index: var(--floating-contact-z-index);
    transition: var(--floating-contact-transition);
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    outline: none;
    will-change: transform, box-shadow;
    user-select: none;
    
    /* Ensure minimum touch target size for accessibility */
    min-width: 44px;
    min-height: 44px;
    
    /* Prevent layout shift during loading */
    opacity: 0;
    transform: scale(0.8) translateY(20px);
}

.floating-contact.loaded {
    opacity: 1;
    transform: scale(1) translateY(0);
}

/* Hover effects */
.floating-contact:hover {
    transform: scale(1.05) translateY(-2px);
    box-shadow: var(--floating-contact-shadow-hover);
}

.floating-contact:active {
    transform: scale(0.95) translateY(0);
}

/* Focus styles for keyboard navigation */
.floating-contact:focus {
    outline: 2px solid #007AFF;
    outline-offset: 2px;
}

.floating-contact:focus:not(:focus-visible) {
    outline: none;
}

/* Icon styles */
.floating-contact-icon {
    width: 32px;
    height: 32px;
    transition: var(--floating-contact-transition);
}

/* WeChat specific styling */
.floating-contact.wechat {
    background: linear-gradient(135deg, #07C160 0%, #00A651 100%);
    color: white;
}

.floating-contact.wechat:hover {
    background: linear-gradient(135deg, #00A651 0%, #07C160 100%);
}

.floating-contact.wechat .floating-contact-icon {
    filter: brightness(0) invert(1);
}

/* WhatsApp specific styling */
.floating-contact.whatsapp {
    background: linear-gradient(135deg, #25D366 0%, #128C7E 100%);
    color: white;
}

.floating-contact.whatsapp:hover {
    background: linear-gradient(135deg, #128C7E 0%, #25D366 100%);
}

.floating-contact.whatsapp .floating-contact-icon {
    font-size: 28px;
}

/* Loading state */
.floating-contact.loading {
    background: #f0f0f0;
    cursor: default;
}

.floating-contact.loading::after {
    content: '';
    width: 20px;
    height: 20px;
    border: 2px solid #ccc;
    border-top: 2px solid #007AFF;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* QR Code Modal */
.floating-contact-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    z-index: calc(var(--floating-contact-z-index) + 1);
    display: none;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    animation: fadeIn 0.3s ease-out;
}

.floating-contact-modal.show {
    display: flex;
}

.floating-contact-modal-content {
    background: white;
    border-radius: 16px;
    padding: 32px;
    max-width: 400px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease-out;
    position: relative;
}

.floating-contact-modal-header {
    margin-bottom: 24px;
}

.floating-contact-modal-title {
    font-size: 24px;
    font-weight: 600;
    margin: 0 0 8px 0;
    color: #1a1a1a;
}

.floating-contact-modal-subtitle {
    font-size: 16px;
    color: #666;
    margin: 0;
}

.floating-contact-qr-container {
    margin: 24px 0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
}

.floating-contact-qr-image {
    max-width: 200px;
    width: 100%;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.floating-contact-phone {
    font-size: 18px;
    font-weight: 600;
    color: #1a1a1a;
    margin: 16px 0;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.floating-contact-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: #f0f0f0;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: #666;
    transition: var(--floating-contact-transition);
}

.floating-contact-close:hover {
    background: #e0e0e0;
    color: #333;
}

.floating-contact-close:focus {
    outline: 2px solid #007AFF;
    outline-offset: 2px;
}

/* Responsive design */
@media (max-width: 768px) {
    .floating-contact {
        bottom: var(--floating-contact-spacing-mobile);
        right: var(--floating-contact-spacing-mobile);
        width: var(--floating-contact-size-mobile);
        height: var(--floating-contact-size-mobile);
    }
    
    .floating-contact-icon {
        width: 28px;
        height: 28px;
    }
    
    .floating-contact.whatsapp .floating-contact-icon {
        font-size: 24px;
    }
    
    .floating-contact-modal-content {
        padding: 24px;
        margin: 20px;
    }
    
    .floating-contact-modal-title {
        font-size: 20px;
    }
    
    .floating-contact-qr-image {
        max-width: 180px;
    }
}

@media (max-width: 480px) {
    .floating-contact {
        bottom: 16px;
        right: 16px;
    }
    
    .floating-contact-modal-content {
        padding: 20px;
        margin: 16px;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .floating-contact {
        border: 2px solid;
    }
    
    .floating-contact.wechat {
        border-color: #00A651;
    }
    
    .floating-contact.whatsapp {
        border-color: #128C7E;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .floating-contact,
    .floating-contact-icon,
    .floating-contact-close {
        transition: none;
    }
    
    .floating-contact:hover {
        transform: none;
    }
    
    .floating-contact-modal {
        animation: none;
    }
    
    .floating-contact-modal-content {
        animation: none;
    }
}

/* Print styles */
@media print {
    .floating-contact,
    .floating-contact-modal {
        display: none !important;
    }
}

/* Animations */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .floating-contact-modal {
        background: rgba(0, 0, 0, 0.85);
    }
    
    .floating-contact-modal-content {
        background: #1a1a1a;
        color: white;
    }
    
    .floating-contact-modal-title {
        color: white;
    }
    
    .floating-contact-modal-subtitle {
        color: #ccc;
    }
    
    .floating-contact-phone {
        background: #2a2a2a;
        color: white;
        border-color: #444;
    }
    
    .floating-contact-close {
        background: #333;
        color: #ccc;
    }
    
    .floating-contact-close:hover {
        background: #444;
        color: white;
    }
}