.chat-widget-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    font-family: "ingra", "Helvetica Neue", Helvetica, Arial, sans-serif;
    touch-action: manipulation;
    pointer-events: auto;
    width: 60px;
    height: 60px;
}

.chat-icon {
    width: 60px;
    height: 60px;
    background-color: #dc3545;
    border-radius: 50%;
    cursor: pointer;
    display: flex !important;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    pointer-events: auto;
    z-index: 1001;
    position: fixed !important;
    bottom: 20px !important;
    right: 20px !important;
}

.chat-icon svg {
    fill: #fff;
    width: 30px;
    height: 30px;
}

.chat-window {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 400px;
    height: 600px;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    overscroll-behavior: contain;
    touch-action: pan-y;
}

.chat-header {
    background: #dc3545;
    color: #fff;
    padding: 15px;
    position: relative;
    display: flex;
    align-items: center;
}

.chat-header .chat-logo {
    width: 24px;
    height: 24px;
    margin-right: 10px;
}

.chat-title {
    margin: 0;
    font-size: 16px;
    font-weight: 500;
}

.chat-subtitle {
    margin: 0;
    font-size: 12px;
    opacity: 0.9;
    margin-left: auto;
}

.chat-close-button {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.chat-close-button:hover {
    opacity: 1;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}

.message {
    margin-bottom: 10px;
    max-width: 80%;
    padding: 8px 12px;
    border-radius: 15px;
    line-height: 1.4;
    font-size: 14px;
}

.assistant-message {
    background: #f5f5f5;
    color: #333;
    margin-right: auto;
    border-bottom-left-radius: 5px;
    display: flex;
    align-items: flex-end;
    padding: 8px 12px;
}

.assistant-message .chat-logo {
    width: 30px;
    height: 30px;
    margin-right: 12px;
    position: relative;
    bottom: 15px;
    align-self: flex-end;
}

.assistant-message-content {
    flex-grow: 1;
    padding: 0;
}

.chat-input-container {
    padding: 15px;
    border-top: 1px solid #eee;
    background: #fff;
    position: relative;
    box-sizing: border-box;
    width: 100%;
    display: flex;
    align-items: flex-start;
}

.chat-input {
    width: 100%;
    padding: 12px;
    padding-right: 40px;
    border: 1px solid #ddd;
    border-radius: 20px;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
    font-size: 14px;
    font-family: "ingra", "Helvetica Neue", Helvetica, Arial, sans-serif;
    resize: none;
    max-height: 120px;
    min-height: 44px;
    overflow-y: auto;
    line-height: 1.4;
}

.chat-input:focus {
    border-color: #dc3545;
}

.chat-input.disabled {
    background-color: #f8f9fa;
    border-color: #eee;
    cursor: not-allowed;
}

/* Submit button styles */
.chat-submit-button {
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    color: #dc3545;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
    position: absolute;
    right: 25px;
    top: 15px;
    transform: none;
    z-index: 2;
}

.chat-submit-button:hover {
    color: #c82333;
}

.chat-submit-button:disabled {
    color: #ccc;
    cursor: not-allowed;
}

/* Mobile responsiveness */
@media screen and (max-width: 480px) {
    .chat-window {
        width: 100%;
        height: 100%;
        max-height: 100vh;
        bottom: 0;
        right: 0;
        border-radius: 0;
        position: fixed;
    }

    .chat-window.mobile {
        width: 100vw;
        height: 100vh;
    }

    /* When keyboard is likely open (based on viewport height) */
    @media (max-height: 600px) {
        .chat-window {
            height: 100vh;
        }

        .chat-messages {
            flex: 1;
            max-height: 40vh;
        }

        .chat-welcome {
            padding: 10px 0;
        }

        .chat-welcome .chat-logo {
            width: 40px;
            height: 40px;
            margin-bottom: 8px;
        }

        .chat-welcome h3 {
            font-size: 16px;
            margin-bottom: 5px;
        }
    }

    /* Adjust the chat icon position on mobile */
    .chat-icon {
        bottom: 10px;
        right: 10px;
        width: 50px;
        height: 50px;
        display: flex !important;
        z-index: 1001;
        opacity: 1 !important;
        visibility: visible !important;
    }

    .chat-icon svg {
        width: 25px;
        height: 25px;
    }

    /* Adjust header for mobile */
    .chat-header {
        padding: 12px 16px;
    }

    /* Adjust input area for mobile */
    .chat-input-container {
        padding: 12px;
        background: #fff;
        border-top: 1px solid #e5e7eb;
    }

    .chat-input {
        font-size: 16px; /* Prevent zoom on iOS */
    }

    /* Ensure messages are readable on mobile */
    .assistant-message-content,
    .user-message-content {
        font-size: 15px;
        padding: 10px 14px;
    }

    /* Adjust submit button position on mobile */
    .chat-submit-button {
        right: 20px;
    }

    /* Hide icon only when chat is open */
    body.chat-open .chat-icon {
        display: none !important;
    }
    
    .chat-window[style*="display: flex"] ~ .chat-icon {
        display: none !important;
    }
    
    .chat-window[style*="display: none"] ~ .chat-icon {
        display: flex !important;
    }
}

/* Fix for iOS safari viewport height issues */
@supports (-webkit-touch-callout: none) {
    .chat-window.mobile {
        height: -webkit-fill-available;
    }
}

/* Typing indicator styles */
.typing-indicator {
    font-style: italic;
    color: #666;
    font-size: 14px;
    margin-bottom: 10px;
    padding-left: 12px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.typing-text {
    display: inline;
}

.typing-dots {
    display: inline;
}

.typing-dots span {
    width: 3px;
    height: 3px;
    background: #666;
    border-radius: 50%;
    display: inline-block;
    margin: 0 1px;
    animation: bounce 1.4s infinite ease-in-out;
    position: relative;
    top: -3px;
}

/* Make sure links in messages are properly styled */
.assistant-message a {
    color: #dc3545;
    text-decoration: none;
}

.assistant-message a:hover {
    text-decoration: underline;
}

/* Ensure proper box sizing for all elements */
*, *:before, *:after {
    box-sizing: border-box;
    font-family: "ingra", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

/* Logo styles */
.chat-logo {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    vertical-align: middle;
}

.chat-welcome {
    text-align: center;
    padding: 20px 0;
}

.chat-welcome .chat-logo {
    width: 60px;
    height: 60px;
    margin-bottom: 10px;
}

/* User message styles */
.message.user-message {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 10px;
    width: 100%;
    max-width: none;
    padding: 0;
}

.user-message-content {
    background: #fde8e8;  /* Light pink background */
    color: #333;
    padding: 8px 12px;
    border-radius: 15px;
    border-bottom-right-radius: 5px;
    max-width: 80%;
    margin-left: auto;
}

/* Animation for typing indicator */
@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}

/* When chat is minimized, ensure the page scrolls normally and the icon is visible */
.chat-window[style*="display: none"] + .chat-icon {
    pointer-events: auto;
    display: flex !important;
}

/* Extra rule to ensure icon is always visible when chat window is hidden */
.chat-widget-container > .chat-icon {
    z-index: 1001;
}

/* Only lock scrolling when chat-open class is present */
body.chat-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
    top: 0 !important;
    left: 0 !important;
}

/* Ensure scrolling is enabled when chat-open class is removed */
body:not(.chat-open) {
    overflow: visible !important;
    position: static !important;
    width: auto !important;
    height: auto !important;
    top: auto !important;
    left: auto !important;
}

/* Add specific override for mobile to ensure scrolling works when minimized */
@media screen and (max-width: 480px) {
    body:not(.chat-open) {
        overflow: auto !important;
        position: static !important;
        height: auto !important;
        width: auto !important;
        overscroll-behavior-y: auto !important;
    }
}

/* Extra rules specifically for v2.chilli.ee */
@media screen and (max-width: 768px) {
    .chat-widget-container {
        position: fixed !important;
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        width: 50px !important;
        height: 50px !important;
        bottom: 80px !important;
        right: 10px !important;
        z-index: 9999 !important;
        overflow: visible !important;
    }
    
    .chat-icon {
        position: fixed !important;
        bottom: 80px !important;
        right: 10px !important;
        width: 50px !important;
        height: 50px !important;
        display: flex !important;
        z-index: 9999 !important;
        visibility: visible !important;
        opacity: 1 !important;
        overflow: visible !important;
        pointer-events: auto !important;
    }

    /* Make the close button more prominent on mobile */
    .chat-close-button {
        top: 12px;
        right: 12px;
        font-size: 24px;
        opacity: 1;
        z-index: 1002;
    }

    /* Make chat window take fullscreen on mobile and keep top elements visible */
    .chat-window.mobile {
        width: 100vw;
        height: 100vh;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        padding-bottom: 70px; /* Make room for bottom nav */
    }
}

/* Ensure icon is visible even in case of deeply nested issues */
html body .chat-widget-container .chat-icon,
body .chat-widget-container .chat-icon,
.chat-widget-container .chat-icon {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Styling for hidden chat icon when chat is open */
.chat-window[style*="display: flex"] ~ .chat-icon,
.chat-window[style*="display: block"] ~ .chat-icon,
body.chat-open .chat-icon {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
    position: absolute !important;
}

/* Make sure the chat icon is visible when the chat window is hidden */
.chat-window[style*="display: none"] ~ .chat-icon {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    position: fixed !important;
}

/* Extra overrides for specific selectors */
html body .chat-widget-container:has(.chat-window[style*="display: flex"]) .chat-icon {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
}

/* When the chat window is open, hidden icon also through parent */
.chat-widget-container:has(.chat-window[style*="display: flex"]) > .chat-icon {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
}

/* Extra rules specifically for v2.chilli.ee */
@media screen and (max-width: 768px) {
    /* Hide icon when chat is open */
    .chat-window[style*="display: flex"] ~ .chat-icon,
    .chat-window[style*="display: block"] ~ .chat-icon,
    body.chat-open .chat-icon {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
        pointer-events: none !important;
    }
    
    /* Make sure icon is visible and correctly styled when chat is closed */
    .chat-window[style*="display: none"] ~ .chat-icon {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        pointer-events: auto !important;
    }
}

/* Special styles for v2.chilli.ee integration */
.chat-icon.v2-mobile-style {
    position: static !important;
    bottom: auto !important;
    right: auto !important;
    width: auto !important;
    height: auto !important;
    background-color: transparent !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    display: inline-block !important;
}

/* Style for our chat icon when integrated in their navbar */
.chat-icon-container {
    padding: 0;
}

.chat-icon-container .nav-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #212529;
    text-decoration: none;
    padding: 8px 0;
}

.chat-icon-container .bi {
    font-size: 1.25rem;
    color: #dc3545;
    margin-bottom: 2px;
}

/* Handle mobile navbar integration on v2.chilli.ee */
@media screen and (max-width: 768px) {
    .mobile-navbar .row .chat-icon-container .nav-link {
        padding: 8px 2px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        color: inherit;
        text-decoration: none;
    }
    
    .mobile-navbar .row .chat-icon-container .bi {
        font-size: 1.15rem;
        margin-bottom: 1px;
        line-height: 1;
    }
    
    .mobile-navbar .row .chat-icon-container .small {
        font-size: 0.7rem;
        line-height: 1.1;
    }
    
    /* Make our floating chat-widget-container hidden when we're using the navbar */
    .v2-mobile-style.chat-icon {
        opacity: 0 !important;
        visibility: hidden !important;
        pointer-events: none !important;
    }
    
    /* When the chat is open but we're integrated in navbar, make chat expand properly */
    body.chat-open .mobile-navbar {
        z-index: 999;
    }
    
    /* Adjust column widths for 5 items instead of 4 */
    .mobile-navbar .row .col-3.chat-icon-container {
        flex: 0 0 20%;
        max-width: 20%;
        width: 20%;
        padding-left: 0;
        padding-right: 0;
    }
    
    /* Also adjust the other columns */
    .mobile-navbar .row .col-3 {
        flex: 0 0 20%;
        max-width: 20%;
        width: 20%;
    }
    
    /* Match our icon style to existing icons */
    .mobile-navbar .row .chat-icon-container .bi-chat-quote-fill {
        font-size: 1.25rem;
        color: #212529;
        line-height: 1;
        margin: 0 auto 4px;
        display: block;
    }
    
    /* Match our text style to existing text */
    .mobile-navbar .row .chat-icon-container .small {
        font-size: 12px;
        margin: 0;
        padding: 0;
        line-height: 1.2;
    }
}

/* When the chat window is open, make sure bottom navbar is not over the chat */
body.chat-open .mobile-navbar {
    display: none !important;
}

/* Load Bootstrap Icons in case they're not already loaded by the main site */
@import url("https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css");

/* Mobile close button styles - remove since we're not using it anymore */
.mobile-close-button {
    display: none;
}

@media screen and (max-width: 768px) {
    /* Adjust input area padding to normal value since there's no close button */
    .chat-input-container {
        padding: 15px;
    }
    
    /* Handle navbar button active state */
    .chat-icon-container .nav-link.active {
        color: #dc3545;
    }
    
    /* Make our chat window full screen on mobile */
    .chat-window.mobile {
        width: 100vw;
        height: 100vh;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        margin: 0;
        border-radius: 0;
    }
}

/* Import Bootstrap Icons */
@import url("https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css");

/* v2.chilli.ee Mobile Navbar Integration */
.chat-icon-link {
    text-decoration: none;
    color: #212529;
    font-size: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 8px 0;
}

.chat-icon-link.active {
    color: #0d6efd;
    font-weight: 500;
}

.chat-icon-link i {
    font-size: 1.25rem;
    margin-bottom: 0.1rem;
}

/* Mobile-specific styling */
@media (max-width: 768px) {
    .chat-icon-link {
        font-size: 11px;
        padding: 6px 0;
    }
    
    .chat-icon-link i {
        font-size: 1.1rem;
        margin-bottom: 0.1rem;
    }
    
    .chat-icon-container.v2-mobile-style {
        padding: 0;
        width: 100%;
        height: 100%;
        background: transparent;
        box-shadow: none;
    }
    
    /* Adjustments when the chat is active */
    body.chat-open .chat-widget {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-height: 100%;
        max-width: 100%;
        border-radius: 0;
        z-index: 10000;
    }
}

/* Extra rule specifically for v2.chilli.ee mobile integration */
@media screen and (max-width: 768px) {
    /* Ensure the floating icon is completely hidden when we have navbar integration */
    .chat-icon.v2-mobile-style,
    .v2-mobile-style.chat-icon {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
        position: absolute !important;
        pointer-events: none !important;
        z-index: -1 !important;
        width: 0 !important;
        height: 0 !important;
        overflow: hidden !important;
    }
    
    /* Ensure proper visibility for navbar integration */
    .mobile-navbar .row .chat-icon-container {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
}
