/* BUILDER BEE CHAT WIDGET - ENHANCED VERSION */
/* This CSS includes all original styles PLUS new features for typing indicators, loading states, and error handling */

/* Chat Widget Container */
.intercom-namespace {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Chat Frame */
.intercom-frame {
    position: fixed;
    bottom: 80px;
    right: 20px;
    width: 400px;
    height: 600px;
    background: #1a202c;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    transform: scale(0.8) translateY(20px);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 9998;
    overflow: hidden;
}

.intercom-frame.active {
    transform: scale(1) translateY(0);
    opacity: 1;
    visibility: visible;
}

/* Messenger Frame */
.intercom-messenger-frame {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Messenger Container */
.intercom-messenger {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: #1a202c;
    border-radius: 12px;
    overflow: hidden;
}

/* Header */
.intercom-messenger-header {
    background: linear-gradient(135deg, #f97316, #ea580c);
    padding: 20px;
    flex-shrink: 0;
    border-radius: 12px 12px 0 0;
}

.intercom-messenger-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.intercom-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.bee-icon {
    font-size: 20px;
}

.intercom-header-text {
    flex: 1;
    color: white;
}

.intercom-header-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.2;
}

.intercom-header-subtitle {
    margin: 4px 0 0 0;
    font-size: 13px;
    opacity: 0.9;
    line-height: 1.2;
}

.intercom-close-button {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

.intercom-close-button:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Messenger Body - CRITICAL LAYOUT */
.intercom-messenger-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Critical for proper flex behavior */
    height: calc(100% - 84px); /* Account for header height */
}

/* Conversation Area - WITH PROPER SCROLLING */
.intercom-conversation {
    flex: 1;
    padding: 20px;
    overflow-y: scroll !important; /* Force scrolling to always be available */
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-height: 0; /* Critical for flex item */
    max-height: calc(100% - 140px); /* Reserve space for composer */
    background: #1a202c;
    
    /* Force scroll bar to always be visible */
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.4) rgba(255, 255, 255, 0.1);
}

/* Webkit scrollbar styling - Make it more visible */
.intercom-conversation::-webkit-scrollbar {
    width: 8px;
    background: rgba(255, 255, 255, 0.1);
}

.intercom-conversation::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.intercom-conversation::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.4);
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.intercom-conversation::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.6);
}

.intercom-conversation::-webkit-scrollbar-thumb:active {
    background: rgba(255, 255, 255, 0.8);
}

/* Message Styling */
.intercom-comment {
    display: flex;
    margin-bottom: 15px;
    animation: messageSlideIn 0.3s ease-out;
}

.intercom-comment-from-admin {
    justify-content: flex-start;
}

.intercom-comment-from-user {
    justify-content: flex-end;
}

.intercom-comment-body {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
}

.intercom-comment-from-admin .intercom-comment-body {
    background: linear-gradient(135deg, #f97316, #ea580c);
    color: white;
    border-bottom-left-radius: 6px;
}

.intercom-comment-from-user .intercom-comment-body {
    background: #374151;
    color: #e5e7eb;
    border-bottom-right-radius: 6px;
}

.intercom-comment-text {
    margin: 0;
    line-height: 1.4;
    font-size: 14px;
}

/* ========================================= */
/* NEW ENHANCED FEATURES - TYPING INDICATOR */
/* ========================================= */

.typing-indicator {
    opacity: 0.8;
    animation: typingPulse 2s infinite ease-in-out;
}

.typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.8);
    animation: typing-bounce 1.4s infinite ease-in-out;
}

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

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

.typing-dots span:nth-child(3) {
    animation-delay: 0s;
}

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

@keyframes typingPulse {
    0%, 100% {
        opacity: 0.8;
    }
    50% {
        opacity: 1;
    }
}

/* ========================================= */
/* NEW ENHANCED FEATURES - ERROR MESSAGES */
/* ========================================= */

.intercom-comment.error-message .intercom-comment-body {
    background: linear-gradient(135deg, #dc2626, #b91c1c) !important;
    border-left: 3px solid #fca5a5;
    position: relative;
}

.intercom-comment.error-message .intercom-comment-text {
    color: #fef2f2 !important;
}

.intercom-comment.error-message .intercom-comment-body::before {
    content: "⚠️";
    position: absolute;
    top: 8px;
    left: 8px;
    font-size: 12px;
}

.intercom-comment.error-message .intercom-comment-text {
    margin-left: 20px;
}

/* ========================================= */
/* NEW ENHANCED FEATURES - LOADING STATES */
/* ========================================= */

.intercom-composer-send-button.loading {
    opacity: 0.7;
    pointer-events: none;
    cursor: not-allowed;
}

.intercom-composer-send-button.loading span {
    animation: spin 1s linear infinite;
}

.intercom-composer-textarea:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.intercom-composer-input-wrapper.loading {
    border-color: #f97316;
    background: rgba(249, 115, 22, 0.1);
}

@keyframes spin {
    from { 
        transform: rotate(0deg); 
    }
    to { 
        transform: rotate(360deg); 
    }
}

/* ========================================= */
/* NEW ENHANCED FEATURES - CONNECTION STATUS */
/* ========================================= */

.connection-status {
    position: absolute;
    top: 10px;
    right: 50px;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.connection-status.connected {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
    opacity: 1;
}

.connection-status.connecting {
    background: rgba(249, 115, 22, 0.2);
    color: #f97316;
    opacity: 1;
}

.connection-status.error {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
    opacity: 1;
}

/* ========================================= */
/* NEW ENHANCED FEATURES - MESSAGE ANIMATIONS */
/* ========================================= */

.intercom-comment-from-admin .intercom-comment-body {
    animation: messageSlideInLeft 0.4s ease-out;
}

.intercom-comment-from-user .intercom-comment-body {
    animation: messageSlideInRight 0.4s ease-out;
}

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

@keyframes messageSlideInRight {
    from {
        opacity: 0;
        transform: translateX(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

/* ========================================= */
/* NEW ENHANCED FEATURES - HOVER EFFECTS */
/* ========================================= */

.intercom-comment-body:hover {
    transform: translateY(-1px);
    transition: transform 0.2s ease;
}

.intercom-composer-send-button:not(.loading):hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(249, 115, 22, 0.4);
}

.intercom-composer-send-button:not(.loading):active {
    transform: scale(0.95);
}

/* Composer - FIXED AT BOTTOM */
.intercom-composer {
    padding: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: #1a202c;
    flex-shrink: 0; /* NEVER shrink */
    position: sticky; /* Stay at bottom */
    bottom: 0;
    z-index: 10;
}

.intercom-composer-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: #374151;
    border-radius: 24px;
    padding: 8px 8px 8px 16px;
    border: 2px solid transparent;
    transition: all 0.2s ease;
}

.intercom-composer-input-wrapper:focus-within {
    border-color: #f97316;
    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.1);
}

.intercom-composer-textarea {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: #e5e7eb;
    font-size: 14px;
    line-height: 1.4;
    resize: none;
    min-height: 20px;
    max-height: 120px;
    padding: 8px 0;
    font-family: inherit;
    transition: opacity 0.2s ease;
}

.intercom-composer-textarea::placeholder {
    color: #9ca3af;
}

.intercom-composer-send-button {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #f97316, #ea580c);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

/* Launcher Button */
.intercom-launcher {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #f97316, #ea580c);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(249, 115, 22, 0.4);
    transition: all 0.3s ease;
    z-index: 9999;
}

.intercom-launcher:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(249, 115, 22, 0.6);
}

.intercom-launcher-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #dc2626;
    color: white;
    font-size: 12px;
    font-weight: 600;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    animation: badgePulse 2s infinite;
}

@keyframes badgePulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

.intercom-launcher-icon {
    font-size: 24px;
    color: white;
}

/* Animations */
@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========================================= */
/* ENHANCED MOBILE RESPONSIVENESS */
/* ========================================= */

@media (max-width: 768px) {
    .intercom-frame {
        width: calc(100vw - 40px);
        height: 500px;
        right: 20px;
        left: 20px;
        bottom: 80px;
    }
    
    .intercom-launcher {
        width: 55px;
        height: 55px;
        bottom: 15px;
        right: 15px;
    }
    
    .intercom-launcher-icon {
        font-size: 22px;
    }
    
    .intercom-conversation {
        padding: 15px;
    }
    
    .intercom-composer {
        padding: 15px;
    }
    
    .intercom-messenger-header {
        padding: 15px;
    }
    
    /* Enhanced mobile typing indicator */
    .typing-dots {
        padding: 6px 10px;
    }
    
    .typing-dots span {
        width: 6px;
        height: 6px;
    }
    
    /* Mobile error messages */
    .intercom-comment.error-message .intercom-comment-body {
        max-width: 95%;
    }
    
    /* Mobile connection status */
    .connection-status {
        top: 8px;
        right: 40px;
        font-size: 10px;
    }
}

@media (max-width: 480px) {
    .intercom-frame {
        width: calc(100vw - 20px);
        right: 10px;
        left: 10px;
        height: 450px;
    }
    
    .intercom-comment-body {
        max-width: 90%;
    }
    
    .intercom-composer-input-wrapper {
        padding: 6px 6px 6px 12px;
    }
    
    .intercom-composer-send-button {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }
    
    /* Smaller typing indicator for very small screens */
    .typing-dots span {
        width: 5px;
        height: 5px;
    }
}

/* ========================================= */
/* ACCESSIBILITY ENHANCEMENTS */
/* ========================================= */

@media (prefers-reduced-motion: reduce) {
    .intercom-comment,
    .intercom-comment-body,
    .typing-dots span,
    .intercom-launcher-badge {
        animation: none;
    }
    
    .intercom-frame {
        transition: opacity 0.2s ease;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .intercom-comment-from-admin .intercom-comment-body {
        background: #000;
        color: #fff;
        border: 2px solid #fff;
    }
    
    .intercom-comment-from-user .intercom-comment-body {
        background: #fff;
        color: #000;
        border: 2px solid #000;
    }
    
    .intercom-composer-input-wrapper {
        border: 2px solid #fff;
    }
}

/* Focus indicators for keyboard navigation */
.intercom-composer-textarea:focus,
.intercom-composer-send-button:focus,
.intercom-close-button:focus {
    outline: 2px solid #f97316;
    outline-offset: 2px;
}

/* ========================================= */
/* PRINT STYLES (for conversation exports) */
/* ========================================= */

@media print {
    .intercom-namespace {
        position: static;
        width: 100%;
        height: auto;
    }
    
    .intercom-frame {
        position: static;
        width: 100%;
        height: auto;
        box-shadow: none;
        border: 1px solid #ccc;
    }
    
    .intercom-launcher {
        display: none;
    }
    
    .intercom-composer {
        display: none;
    }
    
    .intercom-conversation {
        overflow: visible;
        max-height: none;
    }
}

