/* AI Chatbot Widget Styles */

/* Prevent body scroll when chat is open (especially on mobile) */
body.ai-chatbot-open {
    overflow: hidden !important;
    touch-action: none;
    -webkit-overflow-scrolling: auto;
}

/* On mobile, ensure body stays in place */
@media (max-width: 480px) {
    body.ai-chatbot-open {
        position: fixed;
        width: 100%;
        left: 0;
        right: 0;
    }
}

.ai-chatbot-widget {
    position: fixed;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

.ai-chatbot-widget.bottom-right {
    bottom: 20px;
    right: 20px;
}

.ai-chatbot-widget.bottom-left {
    bottom: 20px;
    left: 20px;
}

/* Chat Button */
.ai-chatbot-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: #0084ff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    color: white;
    overflow: hidden;
    position: relative;
}

.ai-chatbot-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.ai-chatbot-button svg {
    width: 28px;
    height: 28px;
    position: relative;
    z-index: 1;
}

.ai-chatbot-button-image,
.ai-chatbot-button-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

/* Chat Window */
.ai-chatbot-window {
    position: absolute;
    bottom: 80px;
    width: 380px;
    height: 600px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: visible;
}

.ai-chatbot-widget.bottom-right .ai-chatbot-window {
    right: 0;
}

.ai-chatbot-widget.bottom-left .ai-chatbot-window {
    left: 0;
}

.ai-chatbot-widget.bottom-left .ai-chatbot-avatar {
    right: auto;
    left: 20px;
}

/* Header */
.ai-chatbot-header {
    background: linear-gradient(135deg, #0084ff, #0066cc);
    color: white;
    padding: 20px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    position: relative;
    overflow: visible;
}

.ai-chatbot-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.ai-chatbot-avatar {
    width: 100px;
    height: 100px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: -50px;
    right: 20px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border: 4px solid white;
    z-index: 10;
}

.ai-chatbot-avatar-image,
.ai-chatbot-avatar-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    position: absolute;
    top: 0;
    left: 0;
}

.ai-chatbot-avatar-icon {
    position: relative;
    z-index: 1;
    width: 50px;
    height: 50px;
    color: #0084ff;
}

.ai-chatbot-title {
    flex: 1;
    padding-right: 120px;
}

.ai-chatbot-title h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.ai-chatbot-status {
    font-size: 12px;
    opacity: 0.9;
}

.ai-chatbot-close {
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
    flex-shrink: 0;
    margin-left: 10px;
}

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

/* Messages Area */
.ai-chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f8f9fa;
    scroll-behavior: smooth;
}

.ai-chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.ai-chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ai-chatbot-messages::-webkit-scrollbar-thumb {
    background: #d0d0d0;
    border-radius: 3px;
}

.ai-chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #b0b0b0;
}

/* Message Bubbles */
.ai-chatbot-message {
    margin-bottom: 16px;
    animation: messageSlideIn 0.3s ease;
    display: flex;
}

/* User messages aligned to the LEFT (RTL mode) */
.ai-chatbot-message.user {
    justify-content: flex-start;
}

/* Assistant messages aligned to the RIGHT (RTL mode) */
.ai-chatbot-message.assistant {
    justify-content: flex-end;
}

/* Formatting inside messages */
.ai-chatbot-message-text b,
.ai-chatbot-message-text strong {
    font-weight: 600;
}

.ai-chatbot-message-text i,
.ai-chatbot-message-text em {
    font-style: italic;
}

.ai-chatbot-message-text br {
    line-height: 1.6;
}

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

.ai-chatbot-message-content {
    display: inline-block;
    max-width: 80%;
}

.ai-chatbot-message-text {
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    white-space: pre-wrap;
    display: inline-block;
}

/* User message bubble - blue background, rounded except bottom-right */
.ai-chatbot-message.user .ai-chatbot-message-text {
    background: #0084ff;
    color: white;
    border-bottom-right-radius: 4px;
}

/* Assistant message bubble - semi-transparent background, rounded except bottom-left */
.ai-chatbot-message.assistant .ai-chatbot-message-text {
    background: #0084ff15;
    color: #212529;
    border-bottom-left-radius: 4px;
}

.ai-chatbot-message-time {
    font-size: 11px;
    color: #6c757d;
    margin-top: 4px;
    padding: 0 8px;
    display: block;
}

.ai-chatbot-message.user .ai-chatbot-message-time {
    text-align: left;
}

.ai-chatbot-message.assistant .ai-chatbot-message-time {
    text-align: right;
}

/* Typing Indicator */
.ai-chatbot-typing-indicator {
    padding: 12px 16px;
    background: #e9ecef;
    border-radius: 18px;
    display: inline-flex;
    gap: 4px;
    margin: 0 20px 16px 20px;
}

.ai-chatbot-typing-indicator span {
    width: 8px;
    height: 8px;
    background: #6c757d;
    border-radius: 50%;
    animation: typingDot 1.4s infinite;
}

.ai-chatbot-typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-chatbot-typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingDot {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: scale(0.8);
    }
    30% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Input Area */
.ai-chatbot-input-container {
    background: white;
    border-top: 1px solid #e9ecef;
    padding: 16px;
}

.ai-chatbot-input-form {
    display: flex;
    gap: 8px;
    align-items: center;
}

.ai-chatbot-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #dee2e6;
    border-radius: 24px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}

.ai-chatbot-input:focus {
    border-color: #0084ff;
}

.ai-chatbot-send-button {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background-color: #0084ff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: white;
}

.ai-chatbot-send-button:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(0, 132, 255, 0.4);
}

.ai-chatbot-send-button:active {
    transform: scale(0.95);
}

/* Actions */
.ai-chatbot-actions {
    margin-top: 12px;
    display: flex;
    justify-content: center;
}

.ai-chatbot-new-chat {
    background: transparent;
    border: 1px solid #dee2e6;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    color: #6c757d;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.ai-chatbot-new-chat:hover {
    background: #f8f9fa;
    border-color: #0084ff;
    color: #0084ff;
}

/* RTL Support - Layout is RTL by default (Hebrew) */
/* For LTR languages, reverse the alignment */
html[dir="ltr"] .ai-chatbot-message.user {
    justify-content: flex-end;
}

html[dir="ltr"] .ai-chatbot-message.assistant {
    justify-content: flex-start;
}

html[dir="ltr"] .ai-chatbot-message.user .ai-chatbot-message-text {
    border-bottom-left-radius: 18px;
    border-bottom-right-radius: 4px;
}

html[dir="ltr"] .ai-chatbot-message.assistant .ai-chatbot-message-text {
    border-bottom-right-radius: 18px;
    border-bottom-left-radius: 4px;
}

html[dir="ltr"] .ai-chatbot-message.user .ai-chatbot-message-time {
    text-align: right;
}

html[dir="ltr"] .ai-chatbot-message.assistant .ai-chatbot-message-time {
    text-align: left;
}

/* Tablet Responsive */
@media (max-width: 768px) and (min-width: 481px) {
    .ai-chatbot-window {
        width: 90vw;
        max-width: 450px;
        max-height: 80vh;
        height: 80vh;
    }
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .ai-chatbot-window {
        width: 100vw;
        /* Fallback for browsers that don't support dvh */
        height: 100vh;
        max-height: 100vh;
        /* Dynamic viewport height - accounts for browser UI */
        height: 100dvh;
        max-height: 100dvh;
        top: 0;
        left: 0 !important;
        right: 0 !important;
        border-radius: 0;
        position: fixed !important;
    }
    
    /* Header - absolute at top with space for avatar */
    .ai-chatbot-header {
        position: absolute;
        top: 40px;
        left: 0;
        right: 0;
        z-index: 10;
    }
    
    /* Avatar positioning for mobile - stick out above header */
    .ai-chatbot-avatar {
        top: -50% !important;
    }
    
    /* Messages area - positioned between header and footer */
    .ai-chatbot-messages {
        position: absolute;
        top: 120px; /* Below header + avatar space */
        bottom: 100px; /* Above footer with extra space for device navigation */
        left: 0;
        right: 0;
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    /* Input container - absolute at bottom with safe padding */
    .ai-chatbot-input-container {
        position: absolute;
        bottom: 20px; /* Extra space above device navigation bar */
        left: 0;
        right: 0;
        z-index: 9;
        background: white;
        border-top: 1px solid #e9ecef;
        padding: 12px;
    }
    
    /* Move "New Chat" button to be inline with input */
    .ai-chatbot-actions {
        display: none; /* Hide the original actions container */
    }
    
    /* Adjust input form to include new chat button */
    .ai-chatbot-input-form {
        display: flex;
        gap: 8px;
        align-items: center;
    }
    
    /* New chat button as inline + button */
    .ai-chatbot-new-chat-mobile {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        background: transparent;
        border: 1px solid #dee2e6;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #6c757d;
        flex-shrink: 0;
        transition: all 0.2s;
        order: -1; /* Place before input field (right side in RTL) */
    }
    
    .ai-chatbot-new-chat-mobile:hover,
    .ai-chatbot-new-chat-mobile:active {
        background: #f8f9fa;
        border-color: #0084ff;
        color: #0084ff;
    }
    
    .ai-chatbot-widget.bottom-right,
    .ai-chatbot-widget.bottom-left {
        bottom: 15px;
        right: 15px;
    }
}

/* Very Small Mobile (iPhone SE, etc) */
@media (max-height: 667px) {
    .ai-chatbot-window {
        max-height: 80vh;
        height: 80vh;
    }
}

