/* Chat Widget CSS */
:root {
    --chat-primary: var(--rr-theme-primary, #8a38f5);
    --chat-secondary: var(--rr-theme-secondary, #07CBEB);
    --chat-header-bg: var(--rr-theme-primary, linear-gradient(90deg,
                rgba(170, 118, 221, 1) 0%,
                rgba(77, 96, 245, 1) 100%));
    --chat-white: var(--rr-common-white, #FFFFFF);
    --chat-text: var(--rr-text-body, #727272);
}

/* Floating Button */
.chat-widget-btn {
    position: fixed;
    bottom: 10px;
    /* Start slightly lower for pop-up effect */
    right: 50px;
    width: 60px;
    height: 60px;
    background-color: var(--chat-white);
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 9999;
    transition: all 0.4s ease;
    /* Animate all properties */

    /* Initial State: Hidden & Scaled Down */
    transform: scale(0);
    opacity: 0;
    visibility: hidden;
}

.chat-widget-btn:hover {
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

/* Loaded State: Visible & Scaled Up */
.chat-widget-btn.loaded {
    bottom: 30px;
    /* Move up to final position */
    transform: scale(1);
    opacity: 1;
    visibility: visible;
}

/* Rotation Animation (Active) */
#chat-widget.active .chat-widget-btn {
    transform: rotate(180deg) scale(1);
    /* Maintain scale */
}

/* Icon styling */
.chat-widget-btn svg {
    width: 24px;
    height: 24px;
    fill: var(--chat-header-bg);
    transition: opacity 0.2s ease;
}

/* Chat Window */
.chat-window {
    position: fixed;
    bottom: 30px;
    /* Aligned with button */
    right: 120px;
    width: 350px;
    height: 450px;
    background-color: var(--chat-white);
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transform: translateX(20px);
    /* Slide in from right */
    transition: all 0.3s ease;
}

#chat-widget.active .chat-window {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
}

/* Header */
.chat-header {
    background: linear-gradient(90deg,
            rgba(170, 118, 221, 1) 0%,
            rgba(77, 96, 245, 1) 100%);
    color: var(--chat-white);
    padding: 15px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
}

.chat-header .close-btn {
    cursor: pointer;
    font-size: 24px;
    opacity: 0.8;
    transition: opacity 0.2s;
    display: none;
    /* Hidden by default */
}

.chat-header .close-btn:hover {
    opacity: 1;
}

/* Body */
.chat-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: #f9f9f9;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-message {
    max-width: 80%;
    padding: 10px 15px;
    border-radius: 10px;
    font-size: 14px;
    line-height: 1.4;
}

.chat-message.bot {
    background-color: #e9e9e9;
    color: #333;
    align-self: flex-start;
    border-bottom-left-radius: 2px;
}

.chat-message.user {
    background-color: var(--chat-primary);
    color: var(--chat-white);
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

/* Footer */
.chat-footer {
    padding: 15px;
    border-top: 1px solid #eee;
    display: flex;
    align-items: center;
    /* vertically center items */
    gap: 10px;
    background-color: var(--chat-white);
}

.chat-footer input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 8px 15px;
    outline: none;
    font-size: 14px;
    background-color: #fff;
    color: #333;
    height: 36px;
    /* match button height */
    margin-left: 0;
}

.chat-footer input:focus {
    border-color: var(--chat-primary);
}

.chat-footer button {
    background-color: var(--chat-primary);
    color: var(--chat-white);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
}

.chat-footer button:hover {
    background-color: var(--chat-header-bg);
}

/* Responsive */
@media only screen and (max-width: 992px) {
    .chat-widget-btn {
        right: 30px;
    }

    .chat-window {
        right: 100px;
    }

    /* Fix overlap on tablet (move scroll button up) */
    #scroll-percentage {
        bottom: 110px !important;
        right: 30px !important;
    }

    #scroll-percentage.active {
        bottom: 110px !important;
    }
}

@media only screen and (max-width: 767px) {

    /* Move Scroll Button Up */
    #scroll-percentage {
        bottom: 110px !important;
        right: 20px !important;
    }

    #scroll-percentage.active {
        bottom: 110px !important;
    }

    /* Chat Button at Bottom */
    .chat-widget-btn {
        bottom: 30px;
        right: 20px;
        z-index: 90;
        /* Lower than offcanvas (999) and overlay (900) */
    }

    /* Chat Window Fullscreen */
    .chat-window {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        right: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        z-index: 99999;
        /* Cover everything */
        transform: translateY(100%);
        /* Slide up from bottom */
    }

    #chat-widget.active .chat-window {
        transform: translateY(0);
    }

    /* Show Close Button on Mobile */
    .chat-header .close-btn {
        display: block;
    }
}