#rfw-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    /* Moved to right as requested */
    z-index: 9999;
    font-family: 'Montserrat', sans-serif;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    /* Align to right */
}

/* The Floating Toggle Button */
#chat-toggle-btn {
    background-color: #21498A;
    /* Navy */
    color: white;
    border: none;
    border-radius: 50px;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 15px rgba(33, 73, 138, 0.4);
    cursor: pointer;
    transition: transform 0.3s ease, background 0.3s;
}

#chat-toggle-btn:hover {
    transform: translateY(-2px);
    background-color: #1a3c70;
}

.chat-label {
    font-weight: 700;
    font-size: 1rem;
}

/* The Chat Window (Hidden by default with 'hidden' class) */
#chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 350px;
    height: 500px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px);
    transition: all 0.3s ease;
    border: 1px solid #eee;
}

#chat-window.open {
    opacity: 1;
    pointer-events: all;
    transform: translateY(0);
}

#chat-window.hidden {
    display: none;
    /* Reinforce hiding */
}

/* Header */
.chat-header {
    background: linear-gradient(135deg, #21498A 0%, #006699 100%);
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: white;
}

.header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.bot-avatar {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    border: 2px solid white;
    object-fit: cover;
}

.header-info h4 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 700;
}

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    background-color: #10B981;
    /* Green */
    border-radius: 50%;
}

.status-text {
    font-size: 0.75rem;
    opacity: 0.9;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    opacity: 0.8;
}

.close-btn:hover {
    opacity: 1;
}

/* Messages Area */
#chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: #F9F9F9;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Message Bubbles */
.message {
    max-width: 80%;
    padding: 10px 15px;
    border-radius: 10px;
    font-size: 0.9rem;
    line-height: 1.5;
    animation: fadeIn 0.3s ease;
}

.bot-msg {
    align-self: flex-start;
    background-color: white;
    color: #333;
    border: 1px solid #eee;
    border-bottom-left-radius: 2px;
}

.user-msg {
    align-self: flex-end;
    background-color: #21498A;
    /* Navy */
    color: white;
    border-bottom-right-radius: 2px;
}

/* Input Form */
#chat-input-form {
    display: flex;
    padding: 15px;
    background: white;
    border-top: 1px solid #eee;
    gap: 10px;
}

#user-input {
    flex: 1;
    padding: 12px 15px;
    border: 1px solid #ddd;
    border-radius: 25px;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.9rem;
    outline: none;
    transition: border 0.3s;
}

#user-input:focus {
    border-color: #E6529D;
    /* Hot Pink */
}

#send-btn {
    background-color: #21498A;
    /* Navy */
    color: white;
    border: none;
    border-radius: 50%;
    width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.3s;
}

#send-btn:hover {
    background-color: #1a3c70;
}

/* Options Buttons */
.options-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 5px;
}

.chat-option-btn {
    background: white;
    border: 1px solid #E6529D;
    /* Pink Border */
    color: #E6529D;
    padding: 8px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.chat-option-btn:hover {
    background: #E6529D;
    color: white;
}

/* Typing Indicator */
.typing-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.typing-text {
    font-size: 0.8rem;
    color: #a0aec0;
    /* Lighter gray */
    font-style: italic;
    white-space: nowrap;
    opacity: 0.8;
}

.typing-dots {
    display: flex;
    gap: 4px;
    margin-top: 2px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background-color: #cbd5e0;
    /* Gray dots */
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

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

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

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes typingBounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* ========================================= */
/*  MOBILE OPTIMIZATION (Fixes Vertical Stretch) */
/* ========================================= */
@media (max-width: 640px) {

    /* 1. Reposition the main container slightly */
    #rfw-chat-widget {
        bottom: 15px;
        left: 15px;
        right: auto;
        align-items: flex-start;
    }

    /* 2. Make the Toggle Button easier to tap */
    #chat-toggle-btn {
        padding: 14px 24px;
        /* Larger touch target */
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    }

    /* 3. WIDE "HORIZONTAL" CHAT WINDOW */
    #chat-window {
        position: fixed;
        /* Locks it to the screen */
        bottom: 85px;
        /* Sits right above the toggle button */

        /* Center it horizontally */
        left: 3vw;
        right: 3vw;
        width: 94vw;
        /* Takes up 94% of the screen width */

        /* Adjust height to be proportional, not stretched */
        height: 60vh;
        /* Uses 60% of screen height */
        max-height: 500px;

        /* Reset transform for simpler animation on mobile */
        transform-origin: bottom center;
    }

    /* 4. Fix Typing Experience */
    #user-input {
        font-size: 16px;
        /* Prevents iPhone from zooming in when typing */
        padding: 12px;
    }

    /* 5. Adjust Header for smaller screens */
    .chat-header h4 {
        font-size: 14px;
    }
}