/* Chatbot Container */
.chatbot-container {
    position: fixed;
    bottom: 30px; /* Same as back-to-top arrow */
    left: 30px; /* Directly opposite the back-to-top arrow (which is at right: 30px) */
    right: auto; /* Ensure right is not set */
    z-index: 10002 !important; /* Higher than navbar (10000) and mobile menu (10001) */
    font-family: 'DM Sans', 'Inter', sans-serif;
    max-width: 100%;
    box-sizing: border-box;
    overflow: visible;
    transform: translateZ(0); /* Force hardware acceleration */
    -webkit-transform: translateZ(0);
}

/* Chatbot Toggle Button */
.chatbot-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    border: none;
    box-shadow: 0 4px 20px rgba(0, 123, 255, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    color: white;
    font-size: 24px;
    touch-action: manipulation; /* Prevent double-tap zoom */
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none; /* Prevent text selection */
    user-select: none; /* Prevent text selection */
    -webkit-touch-callout: none; /* Prevent iOS callout menu */
}

.chatbot-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(0, 123, 255, 0.6);
}

.chatbot-toggle:active {
    transform: scale(0.95);
}

.chatbot-toggle.active {
    background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
    box-shadow: 0 4px 20px rgba(220, 53, 69, 0.4);
}

/* Chatbot Window */
    .chatbot-window {
        position: absolute;
        bottom: 80px;
        left: 0; /* Aligned to left since container is on left */
        right: auto;
        width: 350px;
        max-width: calc(100vw - 60px); /* Prevent overflow with proper viewport calculation */
        height: 500px;
        background: white;
        border-radius: 20px;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
        display: none;
        flex-direction: column;
        overflow: hidden;
        animation: slideUp 0.3s ease;
        box-sizing: border-box;
        transform: translateZ(0); /* Force hardware acceleration */
        -webkit-transform: translateZ(0);
        z-index: 10002 !important; /* Ensure window appears above navbar */
    }

.chatbot-window.active {
    display: flex;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Chatbot Header */
.chatbot-header {
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 20px 20px 0 0;
}

.chatbot-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.chatbot-close {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 5px;
    width: 30px;
    height: 30px;
    min-width: 44px; /* Touch target size */
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
    touch-action: manipulation; /* Prevent double-tap zoom */
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none; /* Prevent text selection */
    user-select: none; /* Prevent text selection */
    -webkit-touch-callout: none; /* Prevent iOS callout menu */
}

.chatbot-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(90deg);
}

/* Chatbot Messages Area */
.chatbot-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: #007bff;
    border-radius: 10px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #0056b3;
}

/* Message Bubbles */
.chatbot-message {
    display: flex;
    margin-bottom: 10px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chatbot-message.user {
    justify-content: flex-end;
}

.chatbot-message.bot {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    line-height: 1.4;
    font-size: 14px;
}

.chatbot-message.user .message-bubble {
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.chatbot-message.bot .message-bubble {
    background: white;
    color: #333;
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

/* Chatbot Input Area */
.chatbot-input-area {
    padding: 15px 20px;
    background: white;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 10px;
    align-items: center;
    touch-action: manipulation; /* Prevent zoom gestures */
}

.chatbot-input {
    flex: 1;
    padding: 12px 15px;
    border: 1px solid #e0e0e0;
    border-radius: 25px;
    font-size: 16px !important; /* 16px minimum to prevent iOS auto-zoom - force with !important */
    font-family: 'DM Sans', 'Inter', sans-serif;
    outline: none;
    transition: all 0.2s ease;
    -webkit-appearance: none; /* Remove iOS styling */
    appearance: none;
    min-width: 0; /* Prevent flex overflow */
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    -webkit-text-size-adjust: 100% !important; /* Prevent iOS text size adjustment */
    text-size-adjust: 100% !important;
    touch-action: manipulation !important; /* Prevent double-tap zoom */
    -webkit-tap-highlight-color: transparent;
    zoom: 1 !important; /* Prevent zoom on second click */
    transform: scale(1) !important; /* Prevent any scaling */
    -webkit-user-select: text; /* Allow text selection */
    user-select: text;
    -webkit-touch-callout: default;
}

.chatbot-input:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
    font-size: 16px !important; /* Ensure font-size stays 16px on focus to prevent zoom */
    -webkit-text-size-adjust: 100% !important;
    text-size-adjust: 100% !important;
    zoom: 1 !important; /* Prevent zoom on second click */
    transform: scale(1) !important; /* Prevent any scaling */
    touch-action: manipulation !important;
    -webkit-user-select: text !important;
    user-select: text !important;
}

.chatbot-send {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-size: 18px;
    touch-action: manipulation; /* Prevent double-tap zoom */
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none; /* Prevent text selection */
    user-select: none; /* Prevent text selection */
    -webkit-touch-callout: none; /* Prevent iOS callout menu */
    flex-shrink: 0;
}

.chatbot-send:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 15px rgba(0, 123, 255, 0.4);
}

.chatbot-send:active {
    transform: scale(0.95);
}

.chatbot-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Typing Indicator */
.chatbot-typing {
    display: flex;
    gap: 5px;
    padding: 12px 16px;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    max-width: 75px;
}

.chatbot-typing span {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.chatbot-typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.chatbot-typing 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;
    }
}

/* Keyboard Active State */
.chatbot-window.keyboard-active {
    position: fixed;
    bottom: auto !important;
    top: auto !important;
    max-height: 50vh !important;
    transition: all 0.3s ease;
    z-index: 10002 !important; /* Ensure it stays above navbar */
}

.chatbot-window.keyboard-active .chatbot-messages {
    max-height: calc(50vh - 120px);
    overflow-y: auto;
}

/* Responsive Design */
@media (max-width: 768px) {
    .chatbot-container {
        bottom: 15px; /* Same as back-to-top arrow (15px on mobile) */
        left: 15px; /* Directly opposite the back-to-top arrow (which is at right: 15px) */
        right: auto;
    }

    .chatbot-toggle {
        width: 56px;
        height: 56px;
        font-size: 22px;
        min-width: 44px; /* Touch target size */
        min-height: 44px;
    }

    .chatbot-window {
        width: calc(100% - 30px);
        max-width: 380px;
        height: calc(100vh - 120px);
        max-height: 500px;
        min-height: 400px;
        bottom: 80px;
        left: 0; /* Aligned to left since container is on left */
        right: auto;
        box-sizing: border-box;
    }

    .message-bubble {
        max-width: 85%;
    }

    .chatbot-input-area {
        padding: 12px 15px;
    }

    .chatbot-send {
        min-width: 44px; /* Touch target size */
        min-height: 44px;
    }
}

/* Tablet and smaller devices */
@media (max-width: 640px) {
    .chatbot-container {
        bottom: 15px; /* Same as back-to-top arrow */
        left: 15px; /* Directly opposite the back-to-top arrow */
        right: auto;
    }

    .chatbot-window {
        width: calc(100% - 24px);
        max-width: 100%;
        height: calc(100vh - 100px);
        max-height: 480px;
        min-height: 380px;
        bottom: 75px;
        left: 0; /* Aligned to left since container is on left */
        right: auto;
        box-sizing: border-box;
    }
}

/* Mobile devices */
@media (max-width: 576px) {
    .chatbot-container {
        bottom: 12px; /* Same as back-to-top arrow (12px on small mobile) */
        left: 12px; /* Directly opposite the back-to-top arrow (which is at right: 12px) */
        right: auto;
    }
}

@media (max-width: 480px) {
    .chatbot-container {
        bottom: 12px; /* Same as back-to-top arrow */
        left: 12px; /* Directly opposite the back-to-top arrow */
        right: auto;
    }

    .chatbot-toggle {
        width: 52px;
        height: 52px;
        font-size: 20px;
        min-width: 44px;
        min-height: 44px;
    }

    .chatbot-window {
        width: calc(100% - 20px);
        max-width: calc(100vw - 20px);
        height: calc(100vh - 90px);
        max-height: 450px;
        min-height: 350px;
        bottom: 80px;
        left: 0; /* Aligned to left since container is on left */
        right: auto;
        border-radius: 16px;
        box-sizing: border-box;
    }
    
    /* Keyboard active adjustments for mobile */
    .chatbot-window.keyboard-active {
        position: fixed;
        width: calc(100% - 20px) !important;
        max-width: calc(100vw - 20px) !important;
        height: auto !important;
        max-height: 50vh !important;
        min-height: 300px !important;
        bottom: auto !important;
        top: auto !important;
        left: 10px !important;
        right: 10px !important;
        box-sizing: border-box !important;
        z-index: 10002 !important; /* Ensure it stays above navbar */
    }
    
    .chatbot-window.keyboard-active .chatbot-messages {
        max-height: calc(50vh - 100px);
        padding: 10px 12px;
    }
    
    .chatbot-window.keyboard-active .chatbot-input-area {
        padding: 8px 10px;
        position: sticky;
        bottom: 0;
        background: white;
        border-top: 1px solid #e0e0e0;
    }

    .chatbot-header {
        padding: 12px 15px;
        border-radius: 16px 16px 0 0;
        min-height: 48px; /* Touch-friendly */
    }

    .chatbot-header h3 {
        font-size: 16px;
    }

    .chatbot-close {
        width: 36px;
        height: 36px;
        min-width: 44px; /* Touch target */
        min-height: 44px;
        font-size: 18px;
    }

    .chatbot-messages {
        padding: 12px 15px;
        gap: 12px;
    }

    .message-bubble {
        padding: 10px 14px;
        font-size: 13px;
        max-width: 88%;
        line-height: 1.5;
    }

    .chatbot-input-area {
        padding: 10px 12px;
        min-height: 60px;
    }

    .chatbot-input {
        padding: 10px 14px;
        font-size: 16px !important; /* 16px minimum to prevent iOS auto-zoom - force with !important */
        min-height: 20px;
        -webkit-text-size-adjust: 100% !important;
        text-size-adjust: 100% !important;
        zoom: 1 !important; /* Prevent zoom on second click */
        transform: scale(1) !important; /* Prevent any scaling */
    }

    .chatbot-send {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
        font-size: 16px;
    }
}

/* Very small mobile devices */
@media (max-width: 360px) {
    .chatbot-container {
        bottom: 12px; /* Same as back-to-top arrow */
        left: 12px; /* Directly opposite the back-to-top arrow */
        right: auto;
    }

    .chatbot-toggle {
        width: 48px;
        height: 48px;
        font-size: 18px;
    }

    .chatbot-window {
        width: calc(100% - 16px);
        max-width: calc(100vw - 16px);
        height: calc(100vh - 80px);
        max-height: 420px;
        min-height: 320px;
        bottom: 80px;
        left: 0; /* Aligned to left since container is on left */
        right: auto;
        border-radius: 12px;
        box-sizing: border-box;
    }
    
    /* Keyboard active for very small screens */
    .chatbot-window.keyboard-active {
        width: calc(100% - 16px) !important;
        max-width: calc(100vw - 16px) !important;
        max-height: 45vh !important;
        min-height: 280px !important;
        bottom: auto !important;
        top: auto !important;
        left: 8px !important;
        right: 8px !important;
        box-sizing: border-box !important;
        z-index: 10002 !important; /* Ensure it stays above navbar */
    }
    
    .chatbot-window.keyboard-active .chatbot-messages {
        max-height: calc(45vh - 90px);
    }

    .chatbot-header {
        padding: 10px 12px;
        border-radius: 12px 12px 0 0;
    }

    .chatbot-header h3 {
        font-size: 15px;
    }

    .chatbot-messages {
        padding: 10px 12px;
    }

    .message-bubble {
        padding: 8px 12px;
        font-size: 12px;
        max-width: 90%;
    }

    .chatbot-input-area {
        padding: 8px 10px;
    }

    .chatbot-input {
        padding: 8px 12px;
        font-size: 16px !important; /* 16px minimum to prevent iOS auto-zoom - force with !important */
        -webkit-text-size-adjust: 100% !important;
        text-size-adjust: 100% !important;
        zoom: 1 !important; /* Prevent zoom on second click */
        transform: scale(1) !important; /* Prevent any scaling */
    }

    .chatbot-send {
        width: 40px;
        height: 40px;
        font-size: 15px;
    }
}

/* Landscape orientation for mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .chatbot-window {
        height: calc(100vh - 80px);
        max-height: 400px;
        min-height: 300px;
    }

    .chatbot-messages {
        padding: 10px 15px;
    }
    
    /* Keyboard active in landscape */
    .chatbot-window.keyboard-active {
        max-height: 60vh !important;
        min-height: 250px !important;
        z-index: 10002 !important; /* Ensure it stays above navbar */
    }
    
    .chatbot-window.keyboard-active .chatbot-messages {
        max-height: calc(60vh - 100px);
    }
}

/* Landscape orientation for small mobile */
@media (max-width: 480px) and (orientation: landscape) {
    .chatbot-window {
        height: calc(100vh - 70px);
        max-height: 350px;
        min-height: 280px;
    }

    .chatbot-header {
        padding: 10px 15px;
    }

    .chatbot-messages {
        padding: 8px 12px;
        gap: 8px;
    }

    .message-bubble {
        padding: 8px 12px;
        font-size: 12px;
    }
    
    /* Keyboard active in landscape on small screens */
    .chatbot-window.keyboard-active {
        max-height: 55vh !important;
        min-height: 220px !important;
        z-index: 10002 !important; /* Ensure it stays above navbar */
    }
    
    .chatbot-window.keyboard-active .chatbot-messages {
        max-height: calc(55vh - 90px);
    }
}

/* Accessibility */
.chatbot-toggle:focus,
.chatbot-close:focus,
.chatbot-send:focus,
.chatbot-input:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

/* Hide chatbot on print */
@media print {
    .chatbot-container {
        display: none !important;
    }
}

