/* Chat Widget Styles */
.chat-widget-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: flex-end; /* Align items to the right */
}

/* Scroll blocking for body when chat is open on small devices */
body.no-scroll {
    overflow: hidden;
}

.chat-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: var(--primary-blue); /* Changed to primary blue */
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    color: #fff;
    font-size: 1.8rem; /* Larger icon */
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: fixed; /* Keep it fixed for consistent positioning */
    bottom: 20px; /* Default bottom position */
    right: 20px; /* Default right position */
    z-index: 1001; /* Ensure button is above chat window when closed */
}

.chat-toggle-btn:hover {
    transform: scale(1.1);
    background-color: #0056b3; /* Darker blue on hover */
}

.chat-window {
    width: 360px; /* Slightly wider for a modern feel */
    height: 500px; /* Taller for more message history */
    background-color: #f0f2f5; /* Light grey background, similar to WhatsApp */
    border: 1px solid #ddd;
    border-radius: 10px; /* Softer corners */
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    font-family: 'Segoe UI', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    overflow: hidden;
    transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: fixed; /* Changed to fixed to cover the screen */
    bottom: 20px; /* Default bottom position */
    right: 20px; /* Default right position */
    transform: translateY(100%) scale(0.8); /* Start hidden below and smaller */
    opacity: 0;
    pointer-events: none; /* Disable interactions when hidden */
    z-index: 1000; /* Ensure chat window is below toggle button when closed */
}

.chat-widget-container:not(.closed) .chat-window {
    transform: translateY(0) scale(1); /* Slide up and scale to full size */
    opacity: 1;
    pointer-events: auto; /* Enable interactions when open */
    bottom: 20px; /* Maintain default bottom position */
    right: 20px; /* Maintain default right position */
}

.chat-widget-container.closed .chat-window {
    display: none; /* Ensure it's completely hidden when closed */
}

.chat-widget-container:not(.closed) .chat-toggle-btn {
    display: none; /* Hide toggle button when chat is open */
}

.chat-widget-container.closed .chat-toggle-btn {
    display: flex; /* Show toggle button when chat is closed */
}

.chat-header {
    background-color: var(--primary-blue); /* Changed to primary blue */
    color: #fff;
    padding: 15px 20px;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 1.15em;
}

.chat-close-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.3rem;
    cursor: pointer;
    transition: transform 0.3s ease;
}

.chat-close-btn:hover {
    transform: rotate(90deg);
}

.chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 15px;
    background-color: #e5ddd5; /* WhatsApp chat background */
    display: flex;
    flex-direction: column;
}

.chat-message {
    max-width: 80%; /* Slightly less width for a cleaner look */
    padding: 10px 12px; /* Adjusted padding */
    border-radius: 10px; /* Softer message bubbles */
    margin-bottom: 8px; /* Less margin between messages */
    line-height: 1.4;
    word-wrap: break-word;
    position: relative;
    font-size: 0.95em;
}

.chat-message.user {
    background-color: var(--primary-blue); /* Changed to primary blue */
    color: #fff; /* Changed text color for better contrast */
    align-self: flex-end;
    border-bottom-right-radius: 2px; /* Pointed corner for user messages */
}

.chat-message.ai {
    background-color: #fff; /* White for AI messages */
    color: #333;
    align-self: flex-start;
    border-bottom-left-radius: 2px; /* Pointed corner for AI messages */
}

.chat-message button {
    display: block;
    margin-top: 8px;
    padding: 8px 12px;
    border-radius: 15px;
    background-color: var(--primary-blue); /* Changed to primary blue */
    color: #fff;
    border: none;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    font-size: 0.9em;
    transition: background-color 0.3s ease;
}

.chat-message button:hover {
    background-color: #0056b3; /* Darker blue on hover */
}

.chat-input {
    display: flex;
    align-items: center;
    padding: 10px 15px; /* Adjusted padding */
    border-top: 1px solid #eee;
    background-color: #f0f2f5; /* Match chat window background */
}

#chatInput {
    flex-grow: 1;
    padding: 10px 15px;
    border: 1px solid #ccc;
    border-radius: 20px; /* Rounded input field */
    margin-right: 10px;
    font-size: 1em;
    outline: none;
    transition: border-color 0.3s ease;
}

#chatInput:focus {
    border-color: var(--primary-blue); /* Changed to primary blue */
}

#chatSendBtn {
    width: 45px;
    height: 45px;
    background-color: var(--primary-blue); /* Changed to primary blue */
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: background-color 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

#chatSendBtn:hover {
    background-color: #0056b3; /* Darker blue on hover */
}

/* Typing indicator styles */
.typing-indicator {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    align-self: flex-start;
    position: relative;
    width: 50px;
    height: 30px;
}

.cookie-icon {
    font-size: 24px;
    color: #8B4513;
    position: absolute;
    left: 0;
    animation: cookie-float 2s infinite ease-in-out;
}

.gear-icon {
    font-size: 16px;
    color: #696969;
    position: absolute;
    left: 25px;
    top: -5px;
    animation: gear-rotate 2s infinite linear;
}

@keyframes cookie-float {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-5px);
    }
}

@keyframes gear-rotate {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

/* Responsive adjustments for smaller screens */
@media (max-width: 600px) {
    .chat-widget-container {
        /* On small screens, the container itself doesn't need to be full screen,
           as the chat window and toggle button are now fixed. */
        position: static; /* Remove fixed positioning from container */
        width: auto;
        height: auto;
        background-color: transparent; /* Remove overlay from container */
        justify-content: flex-end;
        align-items: flex-end;
    }

    .chat-toggle-btn {
        width: 50px;
        height: 50px;
        font-size: 1.5rem;
        bottom: calc(20px + env(safe-area-inset-bottom)); /* Adjust bottom for safe area */
        right: 20px; /* Keep consistent right position */
    }

    .chat-window {
        width: 100vw;
        height: 100vh;
        max-height: -webkit-fill-available; /* Ensure it fills available height */
        border-radius: 0;
        top: 0;
        left: 0;
        bottom: 0;
        right: 0;
        box-shadow: none;
        padding-bottom: env(safe-area-inset-bottom);
        transform: translateY(0) scale(1); /* Always full screen on mobile */
        opacity: 1;
        display: flex; /* Ensure it's always flex when open */
    }

    .chat-widget-container:not(.closed) .chat-window {
        transform: translateY(0) scale(1); /* Ensure it's full screen and visible */
        opacity: 1;
        pointer-events: auto;
    }

    .chat-header {
        padding: 12px 15px;
        font-size: 1em;
        border-top-left-radius: 0;
        border-top-right-radius: 0;
    }

    .chat-messages {
        padding: 10px;
    }

    .chat-message {
        max-width: 90%;
        padding: 8px 12px;
        font-size: 0.9em;
    }

    .chat-input {
        padding: 8px 0;
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
    }

    #chatInput {
        padding: 10px 12px;
        margin-left: 10px;
        font-size: 0.9em;
    }

    #chatSendBtn {
        width: 40px;
        height: 40px;
        margin-right: 10px;
    }
}

@media (max-width: 300px) {
    .chat-toggle-btn {
        width: 45px;
        height: 45px;
        font-size: 1.3rem;
        bottom: calc(15px + env(safe-area-inset-bottom));
        right: 15px;
    }

    .chat-header {
        padding: 10px 12px;
        font-size: 0.9em;
    }

    .chat-messages {
        padding: 8px;
    }

    .chat-message {
        padding: 6px 10px;
        font-size: 0.85em;
    }

    .chat-input {
        padding: 6px 0;
        padding-bottom: calc(6px + env(safe-area-inset-bottom));
    }

    #chatInput {
        padding: 8px 10px;
        margin-left: 8px;
        font-size: 0.85em;
    }

    #chatSendBtn {
        width: 35px;
        height: 35px;
        margin-right: 8px;
    }
}
