/**
 * AI Chatbot Widget Styles
 * Professional design matching Devmatix Solutions theme
 */

/* Chatbot Widget Container */
.ai-chatbot-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1050; /* Lower than Bootstrap modal (1055) but still visible */
    font-family: 'Poppins', sans-serif;
    /* Allow clicks to pass through to elements behind */
    pointer-events: none;
}

/* Enable pointer events only on chatbot interactive elements */
.ai-chatbot-widget .chatbot-toggle {
    pointer-events: auto;
}

/* Only enable pointer events on chatbot window when it's visible/open */
.ai-chatbot-widget.open .chatbot-window,
.ai-chatbot-widget.open .chatbot-window * {
    pointer-events: auto;
}

/* Hide chatbot when modal is open */
body.modal-open .ai-chatbot-widget {
    z-index: 1030; /* Lower than modal backdrop (1040) */
    pointer-events: none;
}

body.modal-open .ai-chatbot-widget .chatbot-window {
    display: none !important;
}

/* Toggle Button */
.chatbot-toggle {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 5px 20px rgba(0, 119, 182, 0.4);
    transition: all 0.3s ease;
    position: relative;
}

.chatbot-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 25px rgba(0, 119, 182, 0.5);
}

.chatbot-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #00e5ff;
    color: var(--dark-color);
    font-size: 10px;
    font-weight: 700;
    padding: 3px 6px;
    border-radius: 10px;
    border: 2px solid white;
}

/* Chatbot Window */
.chatbot-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 600px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    display: none;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px);
    opacity: 0;
    transition: all 0.3s ease;
    /* Ensure proper text rendering */
    writing-mode: horizontal-tb;
    text-orientation: mixed;
    direction: ltr;
    /* When closed/hidden, don't block interactions */
    pointer-events: none;
}

.chatbot-window.show {
    opacity: 1;
    transform: translateY(0);
    /* When visible, allow interactions */
    pointer-events: auto;
}

/* Mobile: Override transform when showing */
@media (max-width: 768px) {
    .chatbot-window.show {
        transform: translateY(0) !important;
        opacity: 1 !important;
    }
}

/* Chatbot Header */
.chatbot-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chatbot-avatar {
    width: 45px;
    height: 45px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.chatbot-header h6 {
    color: white;
    font-weight: 600;
    margin: 0;
}

.chatbot-header small {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.75rem;
}

.btn-close-chatbot {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
    z-index: 10;
}

.btn-close-chatbot:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

/* Mobile: Ensure close button is always visible */
@media (max-width: 768px) {
    .btn-close-chatbot {
        width: 35px;
        height: 35px;
        font-size: 18px;
    }
    
    .chatbot-header {
        position: relative;
        z-index: 5;
    }
}

/* Messages Container */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f8f9fa;
}

.message {
    margin-bottom: 15px;
    animation: fadeInUp 0.3s ease;
}

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

.user-message {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.user-message .message-content {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.bot-message {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.bot-message .message-content {
    background: white;
    color: var(--text-color);
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.message-content p {
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.5;
}

.message-time {
    font-size: 0.7rem;
    color: var(--text-light);
    margin-top: 5px;
    padding: 0 5px;
}

/* Typing Indicator */
.typing-indicator .message-content {
    background: white;
    border: 1px solid #e0e0e0;
    padding: 15px 20px;
}

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

.typing-dots span {
    width: 8px;
    height: 8px;
    background: var(--primary-color);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

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

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Suggestions */
.chatbot-suggestions {
    padding: 15px 20px;
    background: white;
    border-top: 1px solid #e0e0e0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.suggestion-item {
    background: rgba(0, 119, 182, 0.1);
    color: var(--primary-color);
    padding: 8px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 1px solid rgba(0, 119, 182, 0.2);
}

.suggestion-item:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 3px 10px rgba(0, 119, 182, 0.3);
}

/* Input Area */
.chatbot-input-area {
    padding: 15px 20px;
    background: white;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 10px;
    align-items: center;
}

.chatbot-input {
    flex: 1;
    border: 2px solid #e0e0e0;
    border-radius: 25px;
    padding: 10px 20px;
    font-size: 0.9rem;
    outline: none;
    transition: all 0.3s ease;
}

.chatbot-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 119, 182, 0.1);
}

.chatbot-send-btn {
    width: 45px;
    height: 45px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    border: none;
    border-radius: 50%;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 3px 10px rgba(0, 119, 182, 0.3);
}

.chatbot-send-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 5px 15px rgba(0, 119, 182, 0.4);
}

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

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

/* Responsive - Mobile Optimized */
@media (max-width: 768px) {
    .ai-chatbot-widget {
        bottom: 15px;
        right: 15px;
        left: auto;
        width: auto;
        z-index: 1020; /* Below navbar (1030) */
        pointer-events: none !important; /* Don't block page interactions */
    }
    
    /* Enable pointer events only on chatbot toggle button */
    .ai-chatbot-widget .chatbot-toggle {
        pointer-events: auto !important;
    }
    
    /* Only enable pointer events on chatbot window when it's open */
    .ai-chatbot-widget.open .chatbot-window,
    .ai-chatbot-widget.open .chatbot-window * {
        pointer-events: auto !important;
    }
    
    /* When chatbot window is closed, ensure it doesn't block anything */
    .ai-chatbot-widget:not(.open) .chatbot-window {
        pointer-events: none !important;
        display: none !important;
    }
    
    /* Ensure all page elements are clickable */
    .navbar,
    .navbar *,
    main,
    main *,
    footer,
    footer *,
    form,
    form *,
    input,
    textarea,
    button,
    a {
        pointer-events: auto !important;
    }
    
    .chatbot-toggle {
        width: 55px;
        height: 55px;
        font-size: 22px;
        flex-shrink: 0;
    }
    
    .chatbot-badge {
        font-size: 9px;
        padding: 2px 5px;
    }
    
    .chatbot-window {
        position: fixed !important;
        width: calc(100vw - 20px) !important;
        max-width: calc(100vw - 20px) !important;
        min-width: calc(100vw - 20px) !important;
        height: 70vh !important;
        max-height: 70vh !important;
        min-height: 400px !important;
        right: 10px !important;
        left: 10px !important;
        bottom: 90px !important;
        top: auto !important;
        border-radius: 20px !important;
        box-shadow: 0 -5px 30px rgba(0, 0, 0, 0.3) !important;
        display: flex !important;
        flex-direction: column !important;
        writing-mode: horizontal-tb !important;
        text-orientation: mixed !important;
        direction: ltr !important;
        transform: translateY(0) !important;
        /* Prevent resizing when keyboard appears - use fixed height */
        overflow: hidden !important;
        /* Lock height to prevent expansion */
        resize: none !important;
    }
    
    /* When keyboard is visible, use visual viewport if available */
    @supports (height: 100dvh) {
        .chatbot-window {
            max-height: min(70vh, 70dvh) !important;
            height: min(70vh, 70dvh) !important;
        }
    }
    
    /* Prevent window from expanding beyond viewport when keyboard appears */
    @media (max-width: 768px) {
        .chatbot-window {
            /* Use smaller fixed pixel height to ensure buttons are visible */
            max-height: 450px !important;
            height: 450px !important;
            /* Adjust bottom position to account for keyboard */
            bottom: 100px !important;
        }
    }
    
    @media (max-width: 480px) {
        .chatbot-window {
            /* Smaller height for small phones */
            max-height: 400px !important;
            height: 400px !important;
            bottom: 90px !important;
        }
    }
    
    .chatbot-header {
        padding: 15px !important;
        border-radius: 20px 20px 0 0 !important;
        flex-shrink: 0;
        display: flex !important;
        flex-direction: row !important;
        position: sticky;
        top: 0;
        z-index: 10;
    }
    
    .chatbot-header > div {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
    }
    
    .chatbot-avatar {
        width: 40px;
        height: 40px;
        font-size: 18px;
        flex-shrink: 0;
    }
    
    .chatbot-header h6 {
        font-size: 0.95rem;
        white-space: normal;
        word-wrap: break-word;
    }
    
    .chatbot-header small {
        font-size: 0.7rem;
        white-space: normal;
        display: block;
    }
    
    .chatbot-messages {
        padding: 15px;
        flex: 1;
        overflow-y: auto;
        min-height: 0;
        max-height: none;
        /* Ensure messages don't push buttons out of view */
        overflow-anchor: none;
    }
    
    /* Mobile: Limit messages area to ensure buttons are visible */
    @media (max-width: 768px) {
        .chatbot-messages {
            /* Fixed max-height: 450px window - 70px header - 60px input - 50px suggestions = 270px */
            max-height: 270px !important;
            min-height: 150px;
            overflow-y: auto;
        }
    }
    
    @media (max-width: 480px) {
        .chatbot-messages {
            /* Fixed max-height: 400px window - 70px header - 60px input - 50px suggestions = 220px */
            max-height: 220px !important;
            min-height: 120px;
            overflow-y: auto;
        }
    }
    
    .message {
        display: flex !important;
        flex-direction: column !important;
        writing-mode: horizontal-tb !important;
    }
    
    .message-content {
        max-width: 85%;
        padding: 10px 14px;
        font-size: 0.9rem;
        word-wrap: break-word;
        white-space: normal;
    }
    
    .message-content p {
        margin: 0;
        line-height: 1.5;
        word-wrap: break-word;
        white-space: normal;
    }
    
    .message-time {
        font-size: 0.65rem;
        white-space: nowrap;
    }
    
    .chatbot-suggestions {
        padding: 12px 15px;
        gap: 6px;
        flex-shrink: 0;
        display: flex !important;
        flex-wrap: wrap !important;
        flex-direction: row !important;
        max-height: 80px;
        overflow-y: auto;
    }
    
    .suggestion-item {
        padding: 6px 10px;
        font-size: 0.75rem;
        white-space: nowrap;
        writing-mode: horizontal-tb !important;
    }
    
    .chatbot-input-area {
        padding: 12px 15px;
        flex-shrink: 0;
        display: flex !important;
        flex-direction: row !important;
        align-items: center;
        min-height: 60px;
        max-height: 60px;
        position: sticky;
        bottom: 0;
        z-index: 10;
        background: white;
        border-top: 1px solid #e0e0e0;
        /* Prevent expansion */
        overflow: hidden;
    }
    
    .chatbot-input {
        padding: 10px 15px;
        font-size: 0.9rem;
        width: 100%;
        min-width: 0;
        writing-mode: horizontal-tb !important;
        flex: 1;
        margin-right: 8px;
    }
    
    .chatbot-send-btn {
        width: 40px;
        height: 40px;
        font-size: 16px;
        flex-shrink: 0;
        min-width: 40px;
        min-height: 40px;
    }
}

@media (max-width: 480px) {
    .chatbot-window {
        width: calc(100vw - 10px) !important;
        max-width: calc(100vw - 10px) !important;
        min-width: calc(100vw - 10px) !important;
        height: 65vh !important;
        max-height: 65vh !important;
        min-height: 350px !important;
        right: 5px !important;
        left: 5px !important;
        bottom: 85px !important;
    }
    
    .chatbot-toggle {
        width: 50px;
        height: 50px;
        font-size: 20px;
    }
    
    .message-content {
        max-width: 90%;
        padding: 8px 12px;
        font-size: 0.85rem;
    }
    
    .chatbot-suggestions {
        padding: 10px 12px;
    }
    
    .suggestion-item {
        padding: 5px 8px;
        font-size: 0.7rem;
    }
}

/* Touch-friendly improvements for mobile */
@media (max-width: 768px) {
    .chatbot-toggle,
    .chatbot-send-btn,
    .suggestion-item,
    .btn-close-chatbot {
        -webkit-tap-highlight-color: rgba(0, 119, 182, 0.3);
        touch-action: manipulation;
    }
    
    /* Prevent text selection on mobile */
    .chatbot-window {
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
    
    .chatbot-input,
    .message-content p {
        -webkit-user-select: text;
        -moz-user-select: text;
        -ms-user-select: text;
        user-select: text;
    }
    
    /* Better touch targets */
    .chatbot-toggle {
        min-width: 55px;
        min-height: 55px;
    }
    
    .chatbot-send-btn {
        min-width: 40px;
        min-height: 40px;
    }
    
    .suggestion-item {
        min-height: 36px;
        display: flex;
        align-items: center;
    }
}

/* Scrollbar Styling */
.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

