/* ============================================================
   BARRELBITE AI - RESPONSIVE FLOATING CHATBOT
   ============================================================ */


/* ============================================================
   1. CHATBOT CONTAINER
   ============================================================ */

.bb-chatbot {
    position: fixed;

    right: 24px;
    bottom: 24px;

    z-index: 9999;

    font-family: inherit;

    box-sizing: border-box;

    --bb-viewport-top: 0px;
    --bb-viewport-height: 100dvh;
}

.bb-chatbot *,
.bb-chatbot *::before,
.bb-chatbot *::after {
    box-sizing: border-box;
}


/* ============================================================
   2. FLOATING TOGGLE BUTTON
   ============================================================ */

.bb-chat-toggle {
    display: inline-flex;

    align-items: center;
    justify-content: center;

    gap: 8px;

    border: 1px solid #d4a52d;

    background: #d4a52d;
    color: #111;

    padding: 14px 20px;

    border-radius: 30px;

    font-size: 14px;
    font-weight: 700;

    line-height: 1.2;

    white-space: nowrap;

    cursor: pointer;

    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);

    transition:
        background 0.2s ease,
        box-shadow 0.2s ease,
        transform 0.2s ease;
}

.bb-chat-toggle:hover {
    background: #f0bd3e;

    box-shadow: 0 10px 32px rgba(0, 0, 0, 0.4);

    transform: translateY(-2px);
}

.bb-chat-toggle:active {
    transform: translateY(0);
}

.bb-chat-toggle-icon {
    display: inline-flex;

    align-items: center;
    justify-content: center;

    font-size: 17px;
}

.bb-chat-toggle-text {
    display: inline-block;
}

.bb-chat-toggle:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 3px;
}


/* ============================================================
   3. CHATBOT WINDOW - DESKTOP
   ============================================================ */

.bb-chat-window {
    position: absolute;

    right: 0;
    bottom: 65px;

    width: 380px;
    max-width: calc(100vw - 32px);

    height: 520px;

    max-height: min(
        calc(100vh - 110px),
        calc(100dvh - 110px)
    );

    display: flex;
    flex-direction: column;

    min-height: 0;

    background: #151a22;

    border: 1px solid #343c48;
    border-radius: 14px;

    overflow: hidden;

    box-shadow: 0 16px 50px rgba(0, 0, 0, 0.5);

    color: #eef1f5;

    isolation: isolate;
}


/* ============================================================
   4. HIDDEN STATE
   ============================================================ */

.bb-chat-window[hidden] {
    display: none !important;
}


/* ============================================================
   5. CHATBOT HEADER
   ============================================================ */

.bb-chat-header {
    display: flex;

    justify-content: space-between;
    align-items: center;

    gap: 12px;

    flex: 0 0 auto;

    min-width: 0;

    padding: 14px 16px;

    background: #1d2430;

    border-bottom: 1px solid #343c48;
}

.bb-chat-header-info {
    display: flex;
    flex-direction: column;

    min-width: 0;

    flex: 1;
}

.bb-chat-title {
    display: block;

    color: #e7ad22;

    font-size: 15px;
    font-weight: 700;

    line-height: 1.4;

    overflow-wrap: anywhere;
}

.bb-chat-subtitle {
    display: block;

    margin-top: 4px;

    color: #aeb6c3;

    font-size: 12px;
    line-height: 1.4;

    overflow-wrap: anywhere;
}


/* ============================================================
   6. CLOSE BUTTON
   ============================================================ */

.bb-chat-close,
#bbChatClose {
    display: flex;

    align-items: center;
    justify-content: center;

    flex: 0 0 40px;

    width: 40px;
    height: 40px;

    padding: 0;

    border: 0;
    border-radius: 8px;

    background: transparent;
    color: #fff;

    font-size: 18px;

    cursor: pointer;

    transition: background 0.2s ease;
}

.bb-chat-close:hover,
#bbChatClose:hover {
    background: rgba(255, 255, 255, 0.1);
}

.bb-chat-close:focus-visible,
#bbChatClose:focus-visible {
    outline: 2px solid #d4a52d;
    outline-offset: 2px;
}


/* ============================================================
   7. CHAT MESSAGES CONTAINER
   ============================================================ */

.bb-chat-messages {
    display: flex;
    flex-direction: column;

    flex: 1 1 auto;

    min-height: 0;
    min-width: 0;

    gap: 12px;

    padding: 16px;

    overflow-y: auto;
    overflow-x: hidden;

    overscroll-behavior: contain;

    -webkit-overflow-scrolling: touch;

    scrollbar-width: thin;
    scrollbar-color: #46505e transparent;
}

.bb-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.bb-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.bb-chat-messages::-webkit-scrollbar-thumb {
    background: #46505e;

    border-radius: 10px;
}


/* ============================================================
   8. CHAT MESSAGE BUBBLES
   ============================================================ */

.bb-chat-message {
    display: block;

    flex: 0 0 auto;

    width: fit-content;
    max-width: 88%;

    min-width: 0;

    padding: 12px 14px;

    border-radius: 12px;

    font-size: 13px;
    font-weight: 400;

    line-height: 1.6;

    overflow-wrap: anywhere;
    word-break: normal;

    white-space: pre-wrap;

    color: #eef1f5;
}


/* ============================================================
   9. ASSISTANT MESSAGE
   ============================================================ */

.bb-chat-assistant {
    background: #252d39;

    color: #eef1f5;

    align-self: flex-start;

    border-bottom-left-radius: 4px;
}


/* ============================================================
   10. USER MESSAGE
   ============================================================ */

.bb-chat-user {
    background: #7a5b17;

    color: #fff;

    align-self: flex-end;

    border-bottom-right-radius: 4px;
}


/* ============================================================
   11. CHATBOT INPUT FORM
   ============================================================ */

.bb-chat-form,
#bbChatForm {
    display: block;

    flex: 0 0 auto;

    min-width: 0;

    margin: 0;

    padding: 12px;

    background: #151a22;

    border-top: 1px solid #343c48;
}


/* ============================================================
   12. INPUT ROW
   ============================================================ */

.bb-chat-input-row {
    display: flex;

    align-items: stretch;

    width: 100%;

    min-width: 0;

    gap: 8px;
}


/* ============================================================
   13. MESSAGE INPUT
   ============================================================ */

#bbChatInput {
    display: block;

    flex: 1 1 auto;

    width: 100%;
    min-width: 0;

    min-height: 44px;

    padding: 11px 12px;

    margin: 0;

    background: #0f141b;

    color: #fff;

    border: 1px solid #343c48;
    border-radius: 8px;

    font-family: inherit;
    font-size: 14px;

    line-height: 1.4;

    outline: none;

    transition: border-color 0.2s ease;
}

#bbChatInput::placeholder {
    color: #929daa;
    opacity: 1;
}

#bbChatInput:focus {
    border-color: #d4a52d;
}

#bbChatInput:disabled {
    opacity: 0.6;
}


/* ============================================================
   14. SEND BUTTON
   ============================================================ */

.bb-chat-send,
#bbChatSend {
    display: flex;

    align-items: center;
    justify-content: center;

    flex: 0 0 44px;

    width: 44px;
    min-height: 44px;

    padding: 0;

    margin: 0;

    border: 0;
    border-radius: 8px;

    background: #d4a52d;
    color: #111;

    font-size: 18px;
    font-weight: 700;

    cursor: pointer;

    transition: background 0.2s ease;
}

.bb-chat-send:hover,
#bbChatSend:hover {
    background: #f0bd3e;
}

.bb-chat-send:disabled,
#bbChatSend:disabled {
    opacity: 0.5;

    cursor: not-allowed;
}

.bb-chat-send:focus-visible,
#bbChatSend:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}


/* ============================================================
   15. TABLET
   SCREEN WIDTH: 641px - 768px
   ============================================================ */

@media (min-width: 641px) and (max-width: 768px) {

    .bb-chatbot {
        right: 16px;
        bottom: 16px;
    }

    .bb-chat-window {
        width: min(380px, calc(100vw - 32px));

        height: min(520px, calc(100dvh - 100px));

        max-height: calc(100dvh - 100px);

        bottom: 65px;
    }

}


/* ============================================================
   16. MOBILE
   SCREEN WIDTH: UP TO 640px
   ============================================================ */

@media (max-width: 640px) {

    /* --------------------------------------------------------
       Floating button
       -------------------------------------------------------- */

    .bb-chatbot {
        right: 12px;

        bottom: calc(
            12px + env(safe-area-inset-bottom, 0px)
        );
    }

    .bb-chat-toggle {
        padding: 13px 16px;

        font-size: 13px;

        border-radius: 26px;
    }

    /* --------------------------------------------------------
       Full available-screen chatbot panel
       -------------------------------------------------------- */

    .bb-chat-window {
        position: fixed;

        top: calc(
            var(--bb-viewport-top, 0px) + 8px
        );

        right: 8px;

        bottom: auto;
        left: 8px;

        width: auto;

        max-width: none;

        height: calc(
            var(--bb-viewport-height, 100dvh) - 16px
        );

        max-height: none;

        min-height: 0;

        border-radius: 12px;

        z-index: 10000;
    }

    /* Hide the launcher while the mobile panel is open. */

    .bb-chatbot.bb-chat-open .bb-chat-toggle {
        display: none;
    }

    /* --------------------------------------------------------
       Header
       -------------------------------------------------------- */

    .bb-chat-header {
        padding: 12px 14px;

        gap: 10px;
    }

    .bb-chat-title {
        font-size: 15px;
    }

    .bb-chat-subtitle {
        font-size: 11px;
    }

    /* --------------------------------------------------------
       Messages
       -------------------------------------------------------- */

    .bb-chat-messages {
        padding: 12px;

        gap: 10px;
    }

    .bb-chat-message {
        max-width: 92%;

        padding: 11px 12px;

        font-size: 13px;

        line-height: 1.55;
    }

    /* --------------------------------------------------------
       Input
       -------------------------------------------------------- */

    .bb-chat-form,
    #bbChatForm {
        padding: 10px;
    }

    .bb-chat-input-row {
        gap: 8px;
    }

    #bbChatInput {
        min-height: 44px;

        padding: 10px 11px;

        /*
         * 16px helps prevent automatic zoom
         * when focusing inputs on iPhones.
         */
        font-size: 16px;
    }

    .bb-chat-send,
    #bbChatSend {
        flex-basis: 44px;

        width: 44px;
        min-height: 44px;
    }

}


/* ============================================================
   17. VERY SMALL MOBILE DEVICES
   SCREEN WIDTH: UP TO 360px
   ============================================================ */

@media (max-width: 360px) {

    .bb-chatbot {
        right: 8px;
    }

    .bb-chat-toggle {
        padding: 12px 14px;

        font-size: 12px;
    }

    .bb-chat-window {
        top: calc(
            var(--bb-viewport-top, 0px) + 4px
        );

        right: 4px;
        left: 4px;

        height: calc(
            var(--bb-viewport-height, 100dvh) - 8px
        );

        border-radius: 10px;
    }

    .bb-chat-header {
        padding: 9px 10px;
    }

    .bb-chat-messages {
        padding: 10px;
    }

    .bb-chat-message {
        max-width: 94%;
    }

    .bb-chat-form,
    #bbChatForm {
        padding: 8px;
    }

}


/* ============================================================
   18. SHORT SCREENS / LANDSCAPE ORIENTATION
   ============================================================ */

@media (max-height: 500px) and (min-width: 641px) {

    .bb-chatbot {
        bottom: 8px;
    }

    .bb-chat-window {
        height: calc(100dvh - 80px);

        max-height: calc(100dvh - 80px);

        bottom: 62px;
    }

    .bb-chat-header {
        padding: 8px 12px;
    }

    .bb-chat-messages {
        padding: 10px;
    }

    .bb-chat-form,
    #bbChatForm {
        padding: 8px;
    }

}


/* ============================================================
   19. ACCESSIBILITY
   ============================================================ */

@media (prefers-reduced-motion: reduce) {

    .bb-chat-toggle,
    .bb-chat-close,
    #bbChatClose,
    #bbChatInput,
    .bb-chat-send,
    #bbChatSend {
        transition: none;
    }

}