/* Chat Widget Styles */

.chat-widget-container {
    position: fixed;
    bottom: 32px;
    right: 32px;
    z-index: 1000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    pointer-events: none; /* Allow clicks to pass through the container */
}

/* Floating Action Button */
.chat-fab {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, #27aae1 0%, #1e8ab8 100%);
    color: white;
    border: none;
    box-shadow: 0 8px 24px rgba(39, 170, 225, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    animation: chat-pulse 2s ease-in-out infinite;
    pointer-events: auto; /* Re-enable pointer events for the button */
}

.chat-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 32px rgba(39, 170, 225, 0.6);
}

.chat-fab:active {
    transform: scale(0.95);
}

@keyframes chat-pulse {
    0%, 100% {
        box-shadow: 0 8px 24px rgba(39, 170, 225, 0.4);
    }
    50% {
        box-shadow: 0 8px 24px rgba(39, 170, 225, 0.6), 0 0 0 8px rgba(39, 170, 225, 0.1);
    }
}

.chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #dc3545;
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    border: 2px solid white;
}

/* Chat Window */
.chat-window {
    width: 400px;
    height: 600px;
    max-height: calc(100vh - 120px); /* Ensure window doesn't exceed viewport with margins */
    background: white;
    border-radius: 16px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: chat-slide-up 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: auto; /* Re-enable pointer events for the chat window */
}

@keyframes chat-slide-up {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Chat Header */
.chat-header {
    background: linear-gradient(135deg, #27aae1 0%, #1e8ab8 100%);
    color: white;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.chat-header-text h6 {
    font-weight: 600;
    margin: 0;
    font-size: 16px;
}

.chat-header-text small {
    opacity: 0.9;
    font-size: 12px;
}

.chat-header-actions {
    display: flex;
    gap: 8px;
}

.btn-icon {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.3);
}

.btn-icon:active {
    background: rgba(255, 255, 255, 0.4);
    transform: scale(0.95);
}

/* Ensure close button icon is clearly visible */
.btn-icon i {
    pointer-events: none;
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* Welcome Screen */
.chat-welcome {
    text-align: center;
    padding: 40px 20px;
}

/* Profile Collection Form */
.chat-profile-form {
    padding-bottom:30px;
    padding-left:20px;
    padding-right:20px;        
    max-width: 100%;
}

.profile-form-header {
    text-align: center;
    margin-bottom: 4px;
}

.profile-form-header .welcome-icon {
    font-size: 64px;
    color: #27aae1;
    margin-bottom: 6px;
}

.profile-form-header h5 {
    color: #e7e8eb;
    margin-bottom: 8px;
    font-weight: 600;
}

.profile-form-header p {
    color: #718096;
    font-size: 14px;
    line-height: 1.5;
}

.profile-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.profile-form .form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.profile-form label {
    font-size: 13px;
    font-weight: 600;
    color: #e7e8eb;
}

.profile-form .text-danger {
    color: #dc3545;
    margin-left: 3px;
    font-size: 14px;
}

.profile-form .form-control {
    width: 100%;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 14px;
    outline: none;
    transition: all 0.2s;
}

.profile-form .form-control:focus {
    border-color: #27aae1;
    box-shadow: 0 0 0 3px rgba(39, 170, 225, 0.1);
}

.btn-submit-profile {
    width: 100%;
    background: #27aae1;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 12px 20px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 8px;
}

.btn-submit-profile:hover:not(:disabled) {
    background: #1e8ab8;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(39, 170, 225, 0.3);
}

.btn-submit-profile:disabled {
    background: #cbd5e0;
    cursor: not-allowed;
}

.privacy-note {
    text-align: center;
    color: #718096;
    margin-top: 8px;
    margin-bottom: 0;
}

.privacy-note i {
    color: #27aae1;
    margin-right: 4px;
}

.welcome-icon {
    font-size: 64px;
    color: #27aae1;
    margin-bottom: 20px;
    animation: welcome-bounce 2s ease-in-out infinite;
}

@keyframes welcome-bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

.chat-welcome h5 {
    color: #2d3748;
    margin-bottom: 12px;
    font-weight: 600;
}

.chat-welcome p {
    color: #718096;
    font-size: 14px;
    line-height: 1.6;
}

.suggested-questions {
    margin-top: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.suggested-btn {
    background: white;
    border: 1px solid #e2e8f0;
    color: #27aae1;
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    font-size: 13px;
}

.suggested-btn:hover {
    background: #f7fafc;
    border-color: #27aae1;
    transform: translateX(4px);
}

/* Chat Message */
.chat-message {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    animation: message-slide-in 0.3s ease-out;
}

/* User messages align to the right */
.user-message {
    flex-direction: row-reverse;
    justify-content: flex-start;
}

/* Assistant messages align to the left */
.assistant-message {
    flex-direction: row;
    justify-content: flex-start;
}

@keyframes message-slide-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #27aae1;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.user-avatar {
    background: #718096;
}

.message-bubble {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 16px;
    position: relative;
}

.user-message .message-bubble {
    background: #27aae1;
    color: white;
    border-bottom-right-radius: 4px;
}

.assistant-message .message-bubble {
    background: white;
    color: #2d3748;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
}

.message-content {
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.message-time {
    font-size: 10px;
    margin-top: 6px;
    opacity: 0.7;
}

.user-message .message-time {
    text-align: right;
    color: rgba(255, 255, 255, 0.9);
}

.assistant-message .message-time {
    color: #a0aec0;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #cbd5e0;
    animation: typing-bounce 1.4s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

/* Chat Input */
.chat-input-container {
    background: white;
    border-top: 1px solid #e2e8f0;
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom)); /* Account for mobile safe areas */
}

.chat-input-disabled {
    text-align: center;
    padding: 12px;
    background: #f7fafc;
    border: 1px dashed #cbd5e0;
    border-radius: 8px;
    margin-bottom: 8px;
}

.chat-input-disabled p {
    margin: 0;
    color: #718096;
    font-size: 13px;
}

.chat-input-disabled i {
    color: #27aae1;
    margin-right: 6px;
}

.chat-form {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.chat-input {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 24px;
    padding: 12px 16px;
    font-size: 14px;
    outline: none;
    transition: all 0.2s;
}

.chat-input:focus {
    border-color: #27aae1;
    box-shadow: 0 0 0 3px rgba(39, 170, 225, 0.1);
}

.chat-input:disabled {
    background: #f7fafc;
    cursor: not-allowed;
}

.btn-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #27aae1;
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-send:hover:not(:disabled) {
    background: #1e8ab8;
    transform: scale(1.05);
}

.btn-send:disabled {
    background: #cbd5e0;
    cursor: not-allowed;
}

.chat-footer-text {
    text-align: center;
    color: #a0aec0;
}

.contact-link {
    color: #27aae1;
    text-decoration: none;
    font-weight: 500;
}

.contact-link:hover {
    text-decoration: underline;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .chat-widget-container {
        /* Don't change position - keep it as fixed with bottom/right only */
        /* This ensures the container doesn't block the entire screen */
    }

    .chat-fab {
        position: fixed;
        bottom: 20px;
        right: 20px;
        width: 60px;
        height: 60px;
        font-size: 26px;
        z-index: 998; /* Below mobile menu (1020) and chat window (999) */
    }

    .chat-window {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;       
        width: 100%;
        height: 90dvh; /* Use dynamic viewport height for mobile browsers */
        
        border-radius: 0;
        max-height: none;
        z-index: 999; /* Below mobile menu (1020) to prevent overlay */
        overflow: hidden;
        overscroll-behavior: contain;
    }

    /* Make header more prominent on mobile */
    .chat-header {
        padding: 20px 16px;
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
        min-height: 70px;
    }

    .chat-header-text h6 {
        font-size: 18px;
    }

    .chat-header-text small {
        font-size: 13px;
    }

    /* Make header buttons MUCH larger and more visible on mobile */
    .btn-icon {
        width: 48px;
        height: 48px;
        background: rgba(255, 255, 255, 0.3);
        font-size: 24px;
        border-radius: 12px;
        border: 2px solid rgba(255, 255, 255, 0.2);
    }

    .btn-icon:hover {
        background: rgba(255, 255, 255, 0.4);
    }

    .btn-icon:active {
        background: rgba(255, 255, 255, 0.5);
        transform: scale(0.92);
    }

    /* Add specific styling for close button icon */
    .btn-icon i {
        font-size: 24px;
        font-weight: bold;
    }

    .chat-header-actions {
        gap: 12px;
    }

    .message-bubble {
        max-width: 85%;
    }

    /* Ensure chat messages have proper padding on mobile */
    .chat-messages {
        padding: 16px;
        padding-bottom: 20px;
        touch-action: pan-y;
        max-height: calc(100dvh - 70px - 120px); /* Subtract header and input heights */
    }

    /* Ensure input container is always visible */
    .chat-input-container {
        padding: 16px;
        padding-bottom: max(16px, env(safe-area-inset-bottom));
        background: white;
        flex-shrink: 0;
    }

    /* Make profile form more mobile-friendly */
    .chat-profile-form {
        padding: 20px 16px;
    }

    /* Larger avatar on mobile */
    .chat-avatar {
        width: 48px;
        height: 48px;
        font-size: 26px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .chat-window {
        background: #1a202c;
    }

    .chat-messages {
        background: #2d3748;
    }

    .assistant-message .message-bubble {
        background: #374151;
        color: #f7fafc;
        border-color: #4a5568;
    }

    .chat-input-container {
        background: #1a202c;
        border-top-color: #4a5568;
    }

    .chat-input {
        background: #2d3748;
        color: #f7fafc;
        border-color: #4a5568;
    }

    .chat-welcome h5 {
        color: #f7fafc;
    }

    .chat-welcome p {
        color: #cbd5e0;
    }

    .suggested-btn {
        background: #2d3748;
        border-color: #4a5568;
        color: #63b3ed;
    }

    .suggested-btn:hover {
        background: #374151;
    }
}
