/**
 * Unified Chat Button Styles
 * Single source of truth for chat button appearance
 * Fixes all mobile positioning and encoding issues
 */

/* Button Base Styles */
.unified-chat-btn,
#unified-chat-button {
    position: fixed !important;
    bottom: 20px !important;
    right: 20px !important;
    z-index: 2147483647 !important;
    width: 60px !important;
    height: 60px !important;
    border-radius: 50% !important;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    border: none !important;
    color: white !important;
    cursor: pointer !important;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 !important;
    margin: 0 !important;
    transition: box-shadow 0.3s ease !important;
    /* NO TRANSFORM - breaks fixed positioning on mobile */
}

/* Dark Mode Support */
body.dark-mode .unified-chat-btn,
body.dark-mode #unified-chat-button {
    background: linear-gradient(135deg, #818cf8 0%, #a78bfa 100%) !important;
    box-shadow: 0 4px 20px rgba(129, 140, 248, 0.5) !important;
}

body.dark-mode .unified-chat-btn:hover,
body.dark-mode #unified-chat-button:hover {
    box-shadow: 0 6px 30px rgba(129, 140, 248, 0.7) !important;
}

.unified-chat-btn:hover,
#unified-chat-button:hover {
    box-shadow: 0 6px 30px rgba(102, 126, 234, 0.6) !important;
}

.unified-chat-btn:active,
#unified-chat-button:active {
    box-shadow: 0 2px 10px rgba(102, 126, 234, 0.3) !important;
}

.unified-chat-btn .chat-icon,
#unified-chat-button .chat-icon {
    width: 28px !important;
    height: 28px !important;
    color: white !important;
    flex-shrink: 0 !important;
}

.unified-chat-btn .chat-text,
#unified-chat-button .chat-text {
    display: none !important;
}

/* Hide old chat buttons */
.smart-chat-btn:not(#unified-chat-button),
#smartChatButton:not(#unified-chat-button),
[class*="chat-btn"]:not(.unified-chat-btn):not(.chat-close):not(.chat-send):not(.quick-reply) {
    display: none !important;
}

/* Chat Modal Styles */
.chat-modal {
    display: none;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 2147483646 !important;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.chat-modal.show {
    display: flex !important;
}

.chat-overlay {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
}

.chat-container {
    position: relative !important;
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    width: 100%;
    max-width: 450px;
    max-height: 600px;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease-out;
}

/* Dark Mode Chat Container */
body.dark-mode .chat-container {
    background: rgba(31, 41, 55, 0.95);
    backdrop-filter: blur(20px);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(129, 140, 248, 0.2);
}

body.dark-mode .chat-header {
    background: linear-gradient(135deg, #818cf8 0%, #a78bfa 100%);
}

body.dark-mode .chat-body {
    background: transparent;
    color: #f9fafb;
}

body.dark-mode .chat-message.bot {
    background: rgba(55, 65, 81, 0.5);
    color: #f9fafb;
    border: 1px solid rgba(129, 140, 248, 0.2);
}

body.dark-mode .contact-btn {
    background: rgba(55, 65, 81, 0.3);
    border-color: rgba(129, 140, 248, 0.3);
    color: #f9fafb;
}

body.dark-mode .contact-btn:hover {
    background: rgba(129, 140, 248, 0.2);
    border-color: rgba(129, 140, 248, 0.5);
}

body.dark-mode .quick-reply {
    background: rgba(55, 65, 81, 0.3);
    color: #f9fafb;
    border-color: rgba(129, 140, 248, 0.3);
}

body.dark-mode .quick-reply:hover {
    background: rgba(129, 140, 248, 0.2);
    border-color: rgba(129, 140, 248, 0.5);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    border-radius: 16px 16px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.chat-close {
    background: transparent;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s ease;
    line-height: 1;
}

.chat-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    min-height: 300px;
    max-height: 400px;
}

/* Contact Methods */
.contact-methods {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 20px 0;
}

.contact-btn {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: white;
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    text-decoration: none;
    color: #1f2937;
    transition: all 0.2s ease;
    cursor: pointer;
}

.contact-btn:hover {
    border-color: #667eea;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.contact-btn svg {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
}

.contact-btn.whatsapp {
    border-color: #25D366;
}

.contact-btn.whatsapp:hover {
    background: #25D366;
    color: white;
}

.contact-btn.phone {
    border-color: #3b82f6;
}

.contact-btn.phone:hover {
    background: #3b82f6;
    color: white;
}

.contact-btn.email {
    border-color: #8b5cf6;
}

.contact-btn.email:hover {
    background: #8b5cf6;
    color: white;
}

.contact-btn.form {
    border-color: #667eea;
}

.contact-btn.form:hover {
    background: #667eea;
    color: white;
}

.contact-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.contact-info strong {
    font-size: 15px;
    font-weight: 600;
}

.contact-info span {
    font-size: 13px;
    opacity: 0.8;
}

.chat-message {
    margin-bottom: 15px;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message p {
    margin: 0;
    padding: 12px 16px;
    border-radius: 12px;
    display: inline-block;
    max-width: 80%;
}

.chat-message.bot p {
    background: #f3f4f6;
    color: #1f2937;
    border-bottom-left-radius: 4px;
}

.chat-message.user {
    text-align: right;
}

.chat-message.user p {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 15px;
}

.quick-reply {
    background: white;
    border: 2px solid #667eea;
    color: #667eea;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
}

.quick-reply:hover {
    background: #667eea;
    color: white;
    transform: translateY(-2px);
}

.chat-footer {
    padding: 20px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 10px;
    background: white;
    border-radius: 0 0 16px 16px;
}

.chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e5e7eb;
    border-radius: 24px;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s ease;
}

.chat-input:focus {
    border-color: #667eea;
}

.chat-send {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.chat-send:hover {
    transform: scale(1.05);
}

.chat-send:active {
    transform: scale(0.95);
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    .unified-chat-btn,
    #unified-chat-button {
        width: 56px !important;
        height: 56px !important;
        bottom: 16px !important;
        right: 16px !important;
    }
    
    .unified-chat-btn .chat-icon,
    #unified-chat-button .chat-icon {
        width: 24px !important;
        height: 24px !important;
    }
    
    .chat-modal {
        padding: 10px;
    }
    
    .chat-container {
        max-width: 100%;
        max-height: 90vh;
        border-radius: 12px;
    }
    
    .chat-header {
        padding: 16px;
        border-radius: 12px 12px 0 0;
    }
    
    .chat-header h3 {
        font-size: 1.1rem;
    }
    
    .chat-body {
        padding: 16px;
        min-height: 250px;
    }
    
    .chat-message p {
        max-width: 85%;
        font-size: 0.9rem;
    }
    
    .quick-reply {
        font-size: 0.8rem;
        padding: 6px 12px;
    }
    
    .chat-footer {
        padding: 16px;
    }
}

/* Extra small screens */
@media (max-width: 480px) {
    .unified-chat-btn,
    #unified-chat-button {
        width: 52px !important;
        height: 52px !important;
        bottom: 12px !important;
        right: 12px !important;
    }
    
    .chat-container {
        max-height: 95vh;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .chat-container {
        background: #1f2937;
    }
    
    .chat-message.bot p {
        background: #374151;
        color: #f9fafb;
    }
    
    .chat-input {
        background: #374151;
        color: white;
        border-color: #4b5563;
    }
    
    .chat-footer {
        background: #1f2937;
        border-top-color: #374151;
    }
    
    .quick-reply {
        background: #374151;
        border-color: #667eea;
        color: #a5b4fc;
    }
    
    .quick-reply:hover {
        background: #667eea;
        color: white;
    }
}

/* Ensure button always visible and on top */
html,
body {
    position: relative;
}

.unified-chat-btn,
#unified-chat-button {
    /* Force hardware acceleration */
    -webkit-transform: translate3d(0, 0, 0) !important;
    transform: translate3d(0, 0, 0) !important;
    -webkit-backface-visibility: hidden !important;
    backface-visibility: hidden !important;
    -webkit-perspective: 1000 !important;
    perspective: 1000 !important;
}
