/* ========================================
   BUILDER BEE CHAT WIDGET - ENTERPRISE GRADE
   Version: 2.0.0
   Optimized for all devices and accessibility
   ======================================== */

/* CSS Variables for easy theming */
:root {
    --bbp-primary: #FF6B35;
    --bbp-primary-dark: #E55A2B;
    --bbp-secondary: #F7931E;
    --bbp-dark-bg: rgba(15, 23, 42, 0.98);
    --bbp-card-bg: rgba(30, 41, 59, 0.95);
    --bbp-text-light: #ffffff;
    --bbp-text-muted: rgba(255, 255, 255, 0.7);
    --bbp-border-subtle: rgba(255, 255, 255, 0.1);
    --bbp-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    --bbp-radius-lg: 20px;
    --bbp-radius-md: 16px;
    --bbp-radius-sm: 12px;
    --bbp-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========================================
   CHAT CONTAINER - Main wrapper
   ======================================== */
#intercom-container.intercom-namespace {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999999;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ========================================
   CHAT FRAME - The chat window
   ======================================== */
#intercom-frame.intercom-frame {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 550px;
    max-height: calc(100vh - 120px);
    background: var(--bbp-dark-bg);
    border-radius: var(--bbp-radius-lg);
    box-shadow: var(--bbp-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: var(--bbp-transition);
    backdrop-filter: blur(20px);
    border: 1px solid var(--bbp-border-subtle);
}

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

/* ========================================
   MESSENGER FRAME - Inner container
   ======================================== */
.intercom-messenger-frame {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.intercom-messenger {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* ========================================
   CHAT HEADER
   ======================================== */
.intercom-messenger-header {
    background: linear-gradient(135deg, var(--bbp-primary) 0%, var(--bbp-secondary) 100%);
    padding: 16px 20px;
    flex-shrink: 0;
    position: relative;
}

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

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

.intercom-avatar .bee-icon {
    font-size: 24px;
    line-height: 1;
}

.intercom-header-text {
    flex: 1;
    min-width: 0;
}

.intercom-header-title {
    color: var(--bbp-text-light);
    font-size: 16px;
    font-weight: 600;
    margin: 0;
    line-height: 1.3;
}

.intercom-header-subtitle {
    color: rgba(255, 255, 255, 0.85);
    font-size: 13px;
    font-weight: 400;
    margin: 2px 0 0 0;
    line-height: 1.3;
}

/* Close Button */
#close-chat.intercom-close-button {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 8px;
    color: var(--bbp-text-light);
    font-size: 20px;
    font-weight: 300;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--bbp-transition);
    line-height: 1;
}

#close-chat.intercom-close-button:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

#close-chat.intercom-close-button:active {
    transform: scale(0.95);
}

/* ========================================
   CHAT BODY - Messages area container
   ======================================== */
.intercom-messenger-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    background: var(--bbp-card-bg);
}

/* ========================================
   CONVERSATION - Scrollable messages area
   ======================================== */
#chat-messages.intercom-conversation {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    min-height: 200px;
}

/* Custom Scrollbar */
#chat-messages.intercom-conversation::-webkit-scrollbar {
    width: 6px;
}

#chat-messages.intercom-conversation::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

#chat-messages.intercom-conversation::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

#chat-messages.intercom-conversation::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ========================================
   CHAT MESSAGES - Individual bubbles
   ======================================== */
.intercom-comment {
    max-width: 85%;
    animation: messageSlideIn 0.3s ease-out;
}

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

.intercom-comment-body {
    display: flex;
}

.intercom-comment-text {
    padding: 12px 16px;
    border-radius: var(--bbp-radius-md);
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    word-break: break-word;
    white-space: pre-wrap;
}

/* Admin/Bot Messages - Left aligned, orange */
.intercom-comment.intercom-comment-from-admin {
    align-self: flex-start;
}

.intercom-comment.intercom-comment-from-admin .intercom-comment-text {
    background: linear-gradient(135deg, var(--bbp-primary) 0%, var(--bbp-secondary) 100%);
    color: var(--bbp-text-light);
    border-radius: var(--bbp-radius-md) var(--bbp-radius-md) var(--bbp-radius-md) 4px;
    box-shadow: 0 2px 8px rgba(255, 107, 53, 0.3);
}

/* User Messages - Right aligned, gray */
.intercom-comment.intercom-comment-from-user {
    align-self: flex-end;
}

.intercom-comment.intercom-comment-from-user .intercom-comment-text {
    background: rgba(100, 116, 139, 0.6);
    color: var(--bbp-text-light);
    border-radius: var(--bbp-radius-md) var(--bbp-radius-md) 4px var(--bbp-radius-md);
}

/* Error Messages */
.intercom-comment.error-message .intercom-comment-text {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* ========================================
   TYPING INDICATOR
   ======================================== */
.typing-indicator {
    align-self: flex-start;
}

.typing-indicator .intercom-comment-text {
    background: rgba(100, 116, 139, 0.4);
    padding: 14px 18px;
}

.typing-dots {
    display: flex;
    gap: 5px;
    align-items: center;
}

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

.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 typingBounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ========================================
   COMPOSER - Input area
   ======================================== */
.intercom-composer {
    padding: 16px 20px;
    background: var(--bbp-dark-bg);
    border-top: 1px solid var(--bbp-border-subtle);
    flex-shrink: 0;
}

.intercom-composer-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: rgba(100, 116, 139, 0.2);
    border: 2px solid rgba(100, 116, 139, 0.3);
    border-radius: var(--bbp-radius-sm);
    padding: 8px 12px;
    transition: var(--bbp-transition);
}

.intercom-composer-input-wrapper:focus-within {
    border-color: var(--bbp-primary);
    background: rgba(100, 116, 139, 0.3);
    box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.15);
}

/* Text Input */
#chat-input.intercom-composer-textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--bbp-text-light);
    font-size: 14px;
    font-family: inherit;
    line-height: 1.5;
    resize: none;
    outline: none;
    min-height: 24px;
    max-height: 120px;
    padding: 4px 0;
}

#chat-input.intercom-composer-textarea::placeholder {
    color: var(--bbp-text-muted);
}

#chat-input.intercom-composer-textarea:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Send Button */
#send-message.intercom-composer-send-button {
    width: 36px;
    height: 36px;
    min-width: 36px;
    background: linear-gradient(135deg, var(--bbp-primary) 0%, var(--bbp-secondary) 100%);
    border: none;
    border-radius: 10px;
    color: var(--bbp-text-light);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--bbp-transition);
    flex-shrink: 0;
}

#send-message.intercom-composer-send-button:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 12px rgba(255, 107, 53, 0.4);
}

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

#send-message.intercom-composer-send-button.loading {
    opacity: 0.6;
    pointer-events: none;
}

#send-message.intercom-composer-send-button svg {
    width: 16px;
    height: 16px;
}

/* ========================================
   LAUNCHER BUTTON - Chat bubble
   ======================================== */
#intercom-launcher.intercom-launcher {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--bbp-primary) 0%, var(--bbp-secondary) 100%);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(255, 107, 53, 0.4);
    transition: var(--bbp-transition);
    z-index: 999998;
}

#intercom-launcher.intercom-launcher:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 28px rgba(255, 107, 53, 0.5);
}

#intercom-launcher.intercom-launcher:active {
    transform: scale(0.95);
}

.intercom-launcher-icon {
    font-size: 26px;
    line-height: 1;
}

/* Notification Badge */
.intercom-launcher-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 22px;
    height: 22px;
    background: #ef4444;
    color: white;
    font-size: 12px;
    font-weight: 600;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--bbp-dark-bg);
    animation: badgePulse 2s infinite;
}

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

/* ========================================
   MOBILE RESPONSIVE - Tablet
   ======================================== */
@media (max-width: 768px) {
    #intercom-frame.intercom-frame {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: 75vh;
        max-height: 75vh;
        border-radius: var(--bbp-radius-lg) var(--bbp-radius-lg) 0 0;
        transform: translateY(100%);
    }

    #intercom-frame.intercom-frame.active {
        transform: translateY(0);
    }

    #intercom-launcher.intercom-launcher {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }

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

    #chat-messages.intercom-conversation {
        padding: 16px;
    }

    .intercom-composer {
        padding: 12px 16px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
}

/* ========================================
   MOBILE RESPONSIVE - Small phones
   ======================================== */
@media (max-width: 480px) {
    #intercom-frame.intercom-frame {
        height: 85vh;
        max-height: 85vh;
    }

    .intercom-messenger-header {
        padding: 14px 16px;
    }

    .intercom-header-title {
        font-size: 15px;
    }

    .intercom-header-subtitle {
        font-size: 12px;
    }

    .intercom-avatar {
        width: 40px;
        height: 40px;
    }

    .intercom-avatar .bee-icon {
        font-size: 22px;
    }

    #close-chat.intercom-close-button {
        width: 28px;
        height: 28px;
        font-size: 18px;
    }

    .intercom-comment-text {
        font-size: 14px;
        padding: 10px 14px;
    }

    .intercom-comment {
        max-width: 90%;
    }

    #intercom-launcher.intercom-launcher {
        bottom: 12px;
        right: 12px;
        width: 52px;
        height: 52px;
    }

    .intercom-launcher-icon {
        font-size: 22px;
    }
}

/* ========================================
   ACCESSIBILITY
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus visible styles */
#intercom-launcher.intercom-launcher:focus-visible,
#send-message.intercom-composer-send-button:focus-visible,
#close-chat.intercom-close-button:focus-visible {
    outline: 2px solid var(--bbp-primary);
    outline-offset: 2px;
}

/* Screen reader only class */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ========================================
   DARK MODE SUPPORT (already dark by default)
   ======================================== */
@media (prefers-color-scheme: light) {
    /* Keep dark theme for chat - it looks better */
}

/* ========================================
   PRINT STYLES - Hide chat when printing
   ======================================== */
@media print {
    #intercom-container.intercom-namespace {
        display: none !important;
    }
}
