/* CSS Custom Properties */
:root {
    --alc-primary-color: #602276;
    --alc-secondary-color: #bf4a92;
    --alc-accent-color: #f1f3f5;
    --alc-text-color: #333;
    --alc-border-radius: 12px;
    --alc-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    --alc-transition: all 0.3s ease;
    --alc-z-index-widget: 999999;
    --alc-z-index-modal: 9999999;
}

/* Chat Widget Styles */
#alc-chat-widget {
    position: fixed;
    bottom: 60px;
    right: 20px;
    z-index: var(--alc-z-index-widget);
    font-family: 'Lato', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Enhanced Chat Buttons */
.alc-chat-button {
    cursor: pointer;
    transition: var(--alc-transition);
    box-shadow: var(--alc-shadow);
}

.alc-chat-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.2);
}

.alc-chat-button.alc-hidden {
    display: none !important;
}

/* Square Button */
#alc-chat-button-square {
    background: white;
    border: 2px solid var(--alc-primary-color);
    border-radius: var(--alc-border-radius);
    padding: 15px 20px;
    min-width: 160px;
    text-align: left;
}

#alc-chat-button-square .alc-button-text {
    color: var(--alc-primary-color);
    font-size: 14px;
    line-height: 1.4;
    font-weight: 400;
    text-align:left;
}

#alc-chat-button-square .alc-button-text strong {
    font-weight: 600;
    color: var(--alc-secondary-color);
}

/* Circle Button */
/* Enhanced Circle Button with Speech Bubble */
#alc-chat-button-circle {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    overflow: visible;
    border: 4px solid white;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    transition: transform 0.3s ease;
}

#alc-chat-button-circle img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

#alc-chat-button-circle .alc-popup {
    position: absolute;
    top: 0; /* Align with top of circle */
    right: 75px;
    /* Remove transform: translateY(-50%); */
    background: white;
    color: #602276;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    opacity: 1 !important;
    visibility: visible !important;
    z-index: 999999;
    border: 2px solid #602276;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    display: block !important;
    animation: bobble 3s ease-in-out infinite;
    width: 150px;
    text-align: left;
    line-height: 1.4;
    white-space: pre-line;
    padding-bottom: 30px !important;
}
#alc-chat-button-circle .alc-popup::after {
    content: "Chat now";
    position: absolute;
    bottom: 8px;
    left: 0;
    right: 0;
    color: #bf4a92 !important;
    font-weight: 700;
    font-size: 12px;
    text-align: left;
    padding-left:16px;
}


@keyframes bobble {
    0%, 100% { 
        transform: translateY(0px); 
    }
    50% { 
        transform: translateY(-4px); 
    }
}

#alc-chat-button-circle:hover {
    transform: scale(1.05);
}

#alc-chat-button-circle:hover .alc-popup {
    animation-play-state: paused;
    transform: translateY(-2px);
}

/* FIXED: Enhanced Chat Window */
#alc-chat-window {
    width: 350px;
    height: 500px;
    background: white;
    border-radius: var(--alc-border-radius);
    box-shadow: var(--alc-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideInUp 0.3s ease-out;
}

#alc-chat-window.alc-hidden {
    display: none;
}

@keyframes slideInUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Enhanced Chat Header with Back Button */
#alc-chat-header {
    background: var(--alc-primary-color);
    color: white;
    padding: 15px 20px;
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 10px;
    align-items: center;
    font-weight: 600;
    position: relative;
    z-index: 10;
    flex-shrink: 0;
}

/* Header Back Button */
.alc-header-back-btn {
    background: rgba(255,255,255,0.2);
    color: white;
    border: none;
    border-radius: 16px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease;
    white-space: nowrap;
    display: none;
}

.alc-header-back-btn:hover {
    background: rgba(255,255,255,0.3);
}

#alc-chat-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s ease;
}

#alc-chat-close:hover {
    background-color: rgba(255,255,255,0.2);
}

/* Messages Area */
#alc-chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: scroll; /* Changed from auto to scroll to force scrollbar */
    overflow-x: hidden;
    scroll-behavior: smooth;
    position: relative;
    height: 0; /* Force it to use flex: 1 properly */
    min-height: 0;
}

/* Force scrollbar to be visible */
#alc-chat-messages::-webkit-scrollbar {
    width: 12px !important;
    display: block !important;
}

#alc-chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1 !important;
    border-radius: 6px !important;
}

#alc-chat-messages::-webkit-scrollbar-thumb {
    background: var(--alc-primary-color) !important;
    border-radius: 6px !important;
}

#alc-chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--alc-secondary-color) !important;
}

/* Firefox scrollbar */
#alc-chat-messages {
    scrollbar-width: auto !important;
    scrollbar-color: var(--alc-primary-color) #f1f1f1 !important;
}

.alc-message {
    margin-bottom: 15px;
    display: flex;
    animation: messageSlideIn 0.3s ease-out;
}

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

.alc-message.alc-bot {
    justify-content: flex-start;
}

.alc-message.alc-user {
    justify-content: flex-end;
}

.alc-message-content {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.4;
    position: relative;
}

.alc-bot .alc-message-content {
    background: #F7F4F8;
    color: var(--alc-text-color);
    border-bottom-left-radius: 6px;
    border: 0px;
}
.alc-user .alc-message-content {
    background: var(--alc-primary-color);
    color: white;
    border-bottom-right-radius: 6px;
}

/* Typing Indicator */
.alc-typing-dots {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

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

.alc-typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.alc-typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
    0%, 80%, 100% { 
        transform: scale(0.8); 
        opacity: 0.5; 
    }
    40% { 
        transform: scale(1); 
        opacity: 1; 
    }
}

/* Message Status */
.message-status {
    font-size: 12px;
    opacity: 0.7;
    margin-left: 5px;
}

/* Action Buttons in Messages */
.alc-action-buttons {
    margin-top: 10px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.alc-phone-button,
.alc-learn-more-button {
    background: var(--alc-secondary-color);
    color: white !important;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition: background-color 0.2s ease;
}

.alc-phone-button:hover,
.alc-learn-more-button:hover {
    background: #a03d7a;
    color: white;
}

/* Enhanced Input Area */
#alc-chat-input-area {
    padding: 20px;
    border-top: 1px solid #e9ecef;
    background: white;
    position: relative;
    z-index: 5;
    flex-shrink: 0;
}

.alc-input-container {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    position: relative;
}

/* Address Input Wrapper */
.alc-address-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    position: relative;
    flex: 1;
}

#alc-chat-input {
    flex: 1;
    border: 2px solid #e9ecef;
    border-radius: 20px;
    padding: 10px 15px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s ease;
    font-family: inherit;
    line-height: 1.4;
    background: white;
    z-index: 1;
}

/* Auto-resizing textarea styles */
textarea#alc-chat-input {
    resize: none;
    overflow: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
    min-height: 40px;
    max-height: 120px;
    transition: height 0.2s ease;
}

textarea#alc-chat-input::-webkit-scrollbar {
    display: none;
}

#alc-chat-input:focus {
    border-color: var(--alc-primary-color);
    z-index: 2;
}

#alc-chat-send,
.alc-close-chat-btn {
    background: var(--alc-primary-color);
    color: white;
    border: none;
    border-radius: 20px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease;
    height: fit-content;
    align-self: flex-end;
    white-space: nowrap;
}

#alc-chat-send:hover,
.alc-close-chat-btn:hover {
    background: #4f1c60;
}

.alc-close-chat-btn {
    background: #6c757d;
}

.alc-close-chat-btn:hover {
    background: #5a6268;
}

/* Buttons Container */
.alc-buttons-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.alc-option-button {
    background: white;
    border: 2px solid var(--alc-primary-color);
    color: var(--alc-primary-color);
    padding: 12px 15px;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
    transition: var(--alc-transition);
    text-align: left;
    font-family: inherit;
    font-weight: 500;
}

.alc-option-button:hover {
    background: var(--alc-primary-color);
    color: white;
}



/* 🔥 FIXED MOBILE WITH PROPER VIEWPORT HANDLING */
@media (max-width: 480px) {
    /* COMPLETELY HIDE widget on mobile by default */
    #alc-chat-widget {
        display: none !important;
    }
    
    /* Only show widget when chat is open */
    body.alc-chat-open #alc-chat-widget {
        display: flex !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important;
        z-index: 999999 !important;
    }
    
    /* Chat window full screen when open */
    body.alc-chat-open #alc-chat-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-height: 100vh !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    /* Hide ALL chat buttons on mobile */
    .alc-chat-button,
    #alc-chat-button-square,
    #alc-chat-button-circle {
        display: none !important;
    }
    
    /* Mobile styles only when chat is open */
    body.alc-chat-open #alc-chat-header {
        padding: 15px 20px !important;
        padding-top: calc(15px + env(safe-area-inset-top)) !important;
        flex-shrink: 0 !important;
    }
    
    body.alc-chat-open #alc-chat-messages {
        flex: 1 !important;
        padding: 15px 20px !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        min-height: 0 !important;
        max-height: 100% !important;
        scrollbar-width: auto !important;
    }
    
    body.alc-chat-open #alc-chat-messages::-webkit-scrollbar {
        width: 12px !important;
    }
    
    body.alc-chat-open #alc-chat-messages::-webkit-scrollbar-thumb {
        background: rgba(96, 34, 118, 0.8) !important;
        border-radius: 6px !important;
        border: 2px solid transparent !important;
        background-clip: content-box !important;
    }
    
    body.alc-chat-open #alc-chat-input-area {
        padding: 15px 20px !important;
        padding-bottom: calc(15px + env(safe-area-inset-bottom)) !important;
        border-top: 1px solid #e9ecef !important;
        background: white !important;
        flex-shrink: 0 !important;
    }
    
    body.alc-chat-open #alc-chat-input {
        font-size: 16px !important;
        min-height: 44px !important;
        padding: 12px 15px !important;
    }
    
    body.alc-chat-open #alc-chat-send,
    body.alc-chat-open .alc-close-chat-btn {
        padding: 12px 20px !important;
        min-height: 44px !important;
        font-size: 16px !important;
    }
    
    body.alc-chat-open {
        overflow: hidden !important;
        position: fixed !important;
        width: 100% !important;
        height: 100% !important;
        top: 0 !important;
        left: 0 !important;
    }
}

/* Add viewport change handling */
@supports (height: 100dvh) {
    @media (max-width: 480px) {
        body.alc-chat-open #alc-chat-widget,
        body.alc-chat-open #alc-chat-window {
            height: 100dvh !important;
            max-height: 100dvh !important;
        }
    }
}

/* Tablets */
@media (min-width: 481px) and (max-width: 768px) {
    #alc-chat-window {
        width: 400px;
        height: 600px;
    }
    
}

/* Large screens */
@media (min-width: 1200px) {
    #alc-chat-window {
        width: 380px;
        height: 550px;
    }
}

/* Accessibility */
.alc-chat-button:focus,
#alc-chat-close:focus,
#alc-chat-input:focus,
#alc-chat-send:focus,
.alc-option-button:focus,
.alc-phone-button:focus,
.alc-learn-more-button:focus,
.alc-header-back-btn:focus {
    outline: 2px solid var(--alc-secondary-color);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --alc-primary-color: #000;
        --alc-secondary-color: #000;
        --alc-accent-color: #fff;
        --alc-text-color: #000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Loading Animation */
.alc-loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--alc-primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Enhanced mobile keyboard handling */
@media (max-width: 480px) {
    /* Keep existing mobile styles and add: */
    
    #alc-chat-messages {
        /* Existing styles plus: */
        scroll-behavior: smooth !important;
        overscroll-behavior: contain !important;
    }
    
    #alc-chat-input {
        /* Existing styles plus: */
        transform: translateZ(0) !important; /* Force hardware acceleration */
    }
    
    /* Ensure header stays fixed during keyboard events */
    #alc-chat-header {
        position: sticky !important;
        top: 0 !important;
        z-index: 100 !important;
    }
}

@media (max-width: 480px) {

    @media (max-width: 480px) {
    .alc-chat-button,
    #alc-chat-button-square,
    #alc-chat-button-circle {
        display: none !important;
    }

}

/* Mobile autocomplete fixes */
@media (max-width: 480px) {
   
    
    /* Ensure chat input area doesn't overlap */
    #alc-chat-input-area {
        position: relative !important;
        z-index: 999998 !important;
    }
    
    /* Fix viewport height issues */
    #alc-chat-window {
        height: 100vh !important;
        height: 100dvh !important;
    }
}

/* Keyboard open adjustments */
.alc-keyboard-active {
    -webkit-user-select: text !important;
    user-select: text !important;
}

@media (max-width: 480px) {
    #alc-chat-input {
        -webkit-user-select: text !important;
        user-select: text !important;
        -webkit-appearance: none !important;
        appearance: none !important;
        transform: translateZ(0) !important; /* Force hardware acceleration */
    }
    
    /* Prevent zoom on focus */
    #alc-chat-input {
        font-size: 16px !important;
    }
    
    /* Keep keyboard area stable */
    #alc-chat-input-area {
        position: sticky !important;
        bottom: 0 !important;
        background: white !important;
        z-index: 1000 !important;
    }
}

.alc-message-content a {
    color: #602276;
    text-decoration: underline;
    cursor: pointer;
}

.alc-message-content a:hover {
    color: #005a87;
    text-decoration: none;
}

.alc-message-content a:visited {
    color: #0073aa;
}

/* Ensure links work on mobile */
.alc-message-content a {
    -webkit-tap-highlight-color: rgba(0,0,0,0.1);
}

/* ========================================= */
/* Mapbox Autocomplete Styling             */
/* ========================================= */

/* Ensure the main chat window has a sufficient z-index */
/* This allows the autocomplete to be positioned above it */
#alc-chat-window {
    z-index: 9999999; /* A very high value, but less than the autocomplete */
    /* Add this if it's not already defined or if its z-index is too low */
}
/* Styling for Mapbox Autocomplete on Desktop */
@media screen and (min-width: 481px) { /* Applies to screens wider than 480px (desktop) */
    .alc-mapbox-autocomplete {
        background-color: #ffffff; /* White background */
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); /* Soft shadow */
        padding: 5px; /* 5px padding all around the container */
        border-radius: 4px; /* Optional: adds slightly rounded corners */
        border: 1px solid #ddd; /* Optional: a subtle border */
        max-height: 200px; /* Optional: Add a max height with scroll if many results */
        overflow-y: auto; /* Optional: Enable vertical scrolling */
    }

    /* Optional: Style for individual autocomplete items within the container */
    .alc-mapbox-autocomplete .alc-autocomplete-item {
        padding: 8px 10px; /* Padding for each item */
        cursor: pointer;
        color: #333; /* Text color */
    }

    /* Optional: Hover state for individual items */
    .alc-mapbox-autocomplete .alc-autocomplete-item:hover,
    .alc-mapbox-autocomplete .alc-autocomplete-item.selected { /* Also apply to selected item */
        background-color: #f0f0f0; /* Light gray on hover/selected */
    }
}
/* Autocomplete container - this is the main box for suggestions */
.alc-mapbox-autocomplete {
    background-color: #fff; /* White background for visibility */
    border: 1px solid #ddd; /* Light grey border */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); /* Soft, subtle shadow for depth */
    border-radius: 8px; /* Rounded corners */
    padding: 5px 0; /* Vertical padding inside the box */
    max-height: 250px; /* Limit height and enable scrolling */
    overflow-y: auto; /* Enable vertical scrolling */
    
    /* Crucial for stacking: Make sure it's on top of other elements */
    /* The !important is used to override the inline `z-index` set by JavaScript */
    z-index: 10000001 !important; 
    
    /* Positioning (fixed) is handled by JavaScript, but keeping here for clarity */
    position: fixed; 
}

/* Individual autocomplete suggestion item */
.alc-autocomplete-item {
    padding: 10px 15px; /* Padding for each item */
    cursor: pointer; /* Indicate it's clickable */
    font-size: 0.95em; /* Slightly smaller font than chat messages */
    line-height: 1.4; /* Good readability */
    color: #333; /* Dark grey text */
    border-bottom: 1px solid #eee; /* Separator line between items */
}

/* Remove the border from the last item in the list */
.alc-autocomplete-item:last-child {
    border-bottom: none;
}

/* Styling for when an item is hovered over or selected (e.g., via keyboard navigation) */
.alc-autocomplete-item:hover,
.alc-autocomplete-item.selected {
    background-color: #f0f0f0; /* Light grey background on hover/selection */
}

/* Ensure the text within the suggestion items wraps correctly */
.alc-autocomplete-item .alc-autocomplete-text {
    white-space: normal; /* Allow text to wrap within its container */
    overflow: visible; /* Prevent unwanted text truncation */
    text-overflow: clip; /* Ensures text is not clipped unexpectedly */
}

/* You might already have styles for .alc-input-container, but ensure it's not hiding things */
.alc-input-container {
    position: relative; /* Important if you ever decide to position autocomplete absolutely within it */
    z-index: 1; /* Ensures the input field itself is above other elements */
}