/* KinVital Chatbot Bubble Styles */
.kinvital-chatbot-bubble {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Allow pointer events on interactive elements */
.kinvital-chatbot-bubble .chatbot-toggle,
.kinvital-chatbot-bubble .chatbot-container,
.kinvital-chatbot-bubble .chatbot-container.open,
.kinvital-chatbot-bubble .mobile-close-overlay {
    pointer-events: auto;
}

.chatbot-message-bubble {
    position: absolute;
    bottom: 90px;
    right: 0;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1;
    pointer-events: none;
}

.chatbot-message-bubble.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.message-content {
    background: #0099DE;
    color: white;
    padding: 12px 16px;
    border-radius: 18px 18px 4px 18px;
    box-shadow: 0 4px 12px rgba(0, 153, 222, 0.3);
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    position: relative;
    max-width: 200px;
}

.message-arrow {
    position: absolute;
    bottom: -6px;
    right: 20px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid #0099DE;
}

.message-text {
    display: block;
    line-height: 1.4;
}

.chatbot-toggle {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, #0099DE, #0077CC);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 153, 222, 0.3);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    z-index: 2;
    border: 2px solid #0099DE;
}

.chatbot-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0, 153, 222, 0.4);
}

.chatbot-toggle:active {
    transform: scale(0.95);
}

.bubble-logo {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
    animation: pulse 2s infinite;
    background: white;
    border: 2px solid rgba(255, 255, 255, 0.8);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}


.chatbot-container {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: min(95vw, 480px);
    height: min(80vh, 700px);
    background: #f7f7fb;
    border-radius: 16px;
    border: 1px solid #e6e6ef;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1;
}

.chatbot-container.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.chatbot-header {
    background: linear-gradient(135deg, #0099DE, #0077CC);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 16px;
    font-weight: 600;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 2;
    border-bottom: 1px solid #e6e6ef;
}

.chatbot-header h3 {
    color: white !important;
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.chatbot-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s ease;
}

.chatbot-close:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #f7f7fb;
}

.chatbot-iframe-container {
    height: 100%;
    overflow: hidden;
    position: relative;
}

#chatbot-iframe {
    width: 100%;
    height: 100%;
    border: none;
}

.chatbot-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 0;
}

.chatbot-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Mobile Styles */
@media (max-width: 1024px) {
    .kinvital-chatbot-bubble {
        bottom: 20px;
        right: 20px;
        left: auto;
        top: auto;
    }

    .chatbot-toggle {
        position: fixed;
        bottom: 20px;
        right: 20px;
        z-index: 1000001;
        width: 60px;
        height: 60px;
    }

    /* Hide the launcher bubble while chat is open on mobile to avoid overlap */
    .kinvital-chatbot-bubble.chat-open .chatbot-toggle {
        display: none !important;
    }

    .bubble-logo {
        width: 40px;
        height: 40px;
    }

    .chatbot-message-bubble {
        position: fixed;
        right: 20px;
        bottom: 90px;
        max-width: min(260px, calc(100vw - 60px));
        pointer-events: none;
        z-index: 1000000;
    }

    .message-content {
        white-space: normal;
        max-width: 100%;
    }

    .chatbot-container {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        max-width: none;
        transform: translateY(100%);
        z-index: 999999; /* Above mobile overlay */
    }

    .chatbot-container.open {
        transform: translateY(0);
    }

    .chatbot-header {
        position: relative;
        border-bottom: none;
        border-radius: 0;
    }

    .chatbot-iframe-container {
        height: calc(100% - 64px);
        position: relative;
        z-index: 2;
        pointer-events: auto;
    }

    .mobile-close-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.3);
        z-index: 999998; /* Below chat container but above page content */
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease;
    }

    .mobile-close-overlay.active {
        opacity: 1;
        visibility: visible;
    }

    .chatbot-overlay {
        display: none; /* Mobile uses full screen, no overlay needed */
    }
}

/* Animations */
@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0) scale(1);
    }
    40% {
        transform: translateY(-20px) scale(1.1);
    }
    60% {
        transform: translateY(-8px) scale(1.05);
    }
}

.chatbot-toggle.bounce {
    animation: bounce 1s ease;
}

/* Coordinated bouncing for both toggle and message bubble */
.chatbot-toggle.coordinated-bounce,
.chatbot-message-bubble.coordinated-bounce {
    animation: bounce 1s ease;
}

/* Loading state for iframe */
.chatbot-iframe-container {
    position: relative;
}

.chatbot-iframe-container::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 4px solid #e6e6ef;
    border-top: 4px solid #0099DE;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    opacity: 0;
    visibility: hidden;
    z-index: 1;
}

.chatbot-iframe-container.loading::before {
    opacity: 1;
    visibility: visible;
}

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Focus states for accessibility */
.chatbot-toggle:focus {
    outline: 2px solid #0099DE;
    outline-offset: 2px;
}

.chatbot-close:focus {
    outline: 2px solid white;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .chatbot-toggle {
        background: #111;
        border: 2px solid #0099DE;
    }

    .chatbot-container {
        border: 2px solid #111;
        background: #fff;
    }

    .chatbot-header {
        background: #0099DE;
    }
}

/* Mobile body scroll prevention */
body.chatbot-open-mobile {
    overflow: hidden;
    /* Removed position: fixed to allow normal interaction */
}

/* Print styles - hide chatbot when printing */
@media print {
    .kinvital-chatbot-bubble {
        display: none !important;
    }
}
