/* =========================================================
   REALCRM CHATBOT CSS
   Color: #0094AA
========================================================= */

:root {
    --cb-primary:      #0094AA;
    --cb-primary-dark: #007F91;
    --cb-white:        #ffffff;
    --cb-bg:           #f8f9fa;
    --cb-text:         #333333;
    --cb-muted:        #999999;
    --cb-border:       #e0e0e0;
}


/* =========================================================
   FLOATING TOGGLE BUTTON
========================================================= */

.chatbot-toggle {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 9999999;

    width: 52px;
    height: 52px;
    border-radius: 50%;

    background: var(--cb-primary);
    color: var(--cb-white);
    border: none;
    cursor: pointer;

    display: flex;
    align-items: center;
    justify-content: center;

    box-shadow: 0 4px 16px rgba(0, 148, 170, 0.45);
    transition: background 0.25s, transform 0.2s;
    box-sizing: border-box;
    padding: 0;
    margin: 0;
}

.chatbot-toggle:hover {
    background: var(--cb-primary-dark);
    transform: scale(1.07);
}

/* Hide the floating toggle whenever the window is open, so it can't
   peek out from behind the rounded corners of the chat window
   (this was causing the "double bubble" look on mobile) */
body:has(.chatbot-window.active) .chatbot-toggle {
    display: none !important;
}

.chat-icon {
    font-size: 22px;
    line-height: 1;
    pointer-events: none;
}


/* =========================================================
   CHATBOT WINDOW — DESKTOP (min 1025px)
========================================================= */

.chatbot-window {
    position: fixed;
    right: 20px;
    bottom: 82px;
    z-index: 9999998;

    width: 340px;
    height: 400px;

    background: var(--cb-white);
    border-radius: 16px;
    box-shadow: 0 10px 36px rgba(0,0,0,0.17);
    overflow: hidden;

    display: flex;
    flex-direction: column;

    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 14px;
    box-sizing: border-box;

    opacity: 0;
    visibility: hidden;
    transform: translateY(12px) scale(0.97);
    transform-origin: bottom right;

    transition:
        opacity    0.25s ease,
        visibility 0.25s ease,
        transform  0.25s ease;
}

.chatbot-window.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}


/* =========================================================
   HEADER
========================================================= */

.chatbot-header {
    height: 54px;
    min-height: 54px;
    flex-shrink: 0;

    background: var(--cb-primary);
    color: var(--cb-white);
    padding: 0 14px;

    display: flex;
    align-items: center;
    gap: 10px;
    box-sizing: border-box;
    overflow: hidden;
}

.chatbot-bot-icon {
    width: 34px;
    height: 34px;
    min-width: 34px;
    flex-shrink: 0;

    background: rgba(255,255,255,0.18);
    border-radius: 50%;
    overflow: hidden;

    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.chatbot-bot-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}

.chatbot-title-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chatbot-title-text strong {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.chatbot-title-text span {
    display: flex;
    align-items: center;
    height: 10px;
}

.online-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    animation: cb-pulse 2s infinite;
    flex-shrink: 0;
}

@keyframes cb-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.4; }
}

.chatbot-close {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    min-width: 30px;
    background: transparent;
    border: none;
    color: var(--cb-white);
    font-size: 17px;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    padding: 0;
}

.chatbot-close:hover {
    background: rgba(255,255,255,0.18);
}


/* =========================================================
   MESSAGES AREA
========================================================= */

.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 14px;
    background: var(--cb-bg);
    display: flex;
    flex-direction: column;
    gap: 4px;
    scroll-behavior: smooth;
    box-sizing: border-box;
    min-height: 0;
    width: 100%;
}

.chatbot-messages::-webkit-scrollbar       { width: 4px; }
.chatbot-messages::-webkit-scrollbar-track { background: transparent; }
.chatbot-messages::-webkit-scrollbar-thumb { background: #c0cdd0; border-radius: 10px; }

.message-row {
    display: flex;
    flex-direction: column;
    max-width: 78%;
    min-width: 0;
    animation: cb-slide-in 0.22s ease;
}

.bot-row  { align-self: flex-start; }
.user-row { align-self: flex-end; }

@keyframes cb-slide-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.bot-message {
    padding: 10px 13px;
    background: var(--cb-white);
    color: var(--cb-text);
    border: 1px solid var(--cb-border);
    border-radius: 14px;
    border-bottom-left-radius: 3px;
    font-size: 13px;
    line-height: 1.5;
    word-break: break-word;
    overflow-wrap: anywhere;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    box-sizing: border-box;
}

.user-message {
    padding: 10px 13px;
    background: var(--cb-primary);
    color: var(--cb-white);
    border-radius: 14px;
    border-bottom-right-radius: 3px;
    font-size: 13px;
    line-height: 1.5;
    word-break: break-word;
    overflow-wrap: anywhere;
    box-sizing: border-box;
}

.message-time {
    font-size: 10px;
    color: var(--cb-muted);
    margin-top: 3px;
    padding: 0 3px;
    margin-bottom: 6px;
}

.bot-row  .message-time { align-self: flex-start; }
.user-row .message-time { align-self: flex-end; }

.typing-message {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 9px 12px;
    background: var(--cb-white);
    border: 1px solid var(--cb-border);
    border-radius: 14px;
    border-bottom-left-radius: 3px;
}

.typing-message span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #aaa;
    animation: cb-typing 1.3s infinite;
}

.typing-message span:nth-child(2) { animation-delay: 0.18s; }
.typing-message span:nth-child(3) { animation-delay: 0.36s; }

@keyframes cb-typing {
    0%, 60%, 100% { transform: translateY(0);    opacity: 0.35; }
    30%            { transform: translateY(-5px); opacity: 1;    }
}


/* =========================================================
   INPUT AREA
========================================================= */

.chatbot-input-area {
    flex-shrink: 0;
    height: 60px;
    min-height: 60px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: var(--cb-white);
    border-top: 1px solid var(--cb-border);
    box-sizing: border-box;
    width: 100%;
}

.chatbot-input {
    flex: 1;
    min-width: 0;
    height: 38px;
    border: 1.5px solid #d4dde0;
    border-radius: 20px;
    padding: 0 14px;
    font-size: 13px;
    font-family: inherit;
    color: var(--cb-text);
    background: var(--cb-white);
    outline: none;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.chatbot-input::placeholder { color: #a0adb2; }

.chatbot-input:focus {
    border-color: var(--cb-primary);
    box-shadow: 0 0 0 3px rgba(0,148,170,0.10);
}

.chatbot-send {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    min-width: 38px;
    border: none;
    border-radius: 50%;
    background: var(--cb-primary);
    color: var(--cb-white);
    font-size: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.15s;
    padding: 0;
    box-sizing: border-box;
}

.chatbot-send:hover    { background: var(--cb-primary-dark); transform: scale(1.06); }
.chatbot-send:disabled { opacity: 0.55; cursor: not-allowed; }


/* =========================================================
   TABLET — 601px to 1024px
   Centered floating window
========================================================= */

@media (min-width: 601px) and (max-width: 1024px) {

    /* Toggle button — LEFT side on tablet */
    .chatbot-toggle {
        right: auto;
        right: 144px;
        bottom: 20px;
        width: 52px;
        height: 52px;
    }

    .chatbot-window {
        /* Center horizontally on tablet */
        right: 50%;
        left: auto;
        transform: translateX(50%) translateY(12px) scale(0.97);
        transform-origin: bottom center;
        bottom: 90px;

        width: 400px;
        max-width: calc(100vw - 40px);
        height: 420px;

        border-radius: 16px;
    }

    .chatbot-window.active {
        transform: translateX(50%) translateY(0) scale(1);
        opacity: 1;
        visibility: visible;
    }

    .chatbot-header {
        height: 56px;
        min-height: 56px;
        padding: 0 16px;
    }

    .chatbot-title-text strong { font-size: 15px; }

    .chatbot-messages { padding: 14px 16px; }

    .message-row { max-width: 76%; }

    .bot-message,
    .user-message { font-size: 13.5px; padding: 10px 14px; }

    .chatbot-input-area { padding: 10px 14px; height: 62px; min-height: 62px; }

    .chatbot-input  { height: 40px; font-size: 13.5px; }
    .chatbot-send   { width: 40px; height: 40px; min-width: 40px; }
}


/* =========================================================
   MOBILE — max 600px
   Full-width bottom sheet
   (contained inside its own fixed box — width/height use
   100% + dvh, not 100vw/100vh, so it can never force a
   horizontal/vertical scrollbar on the rest of the page)
========================================================= */

@media (max-width: 600px) {

    /* Toggle button — RIGHT side on mobile */
    .chatbot-toggle {
        position: fixed !important;
        right: 16px !important;
        left: auto !important;
        bottom: 16px !important;
        width: 50px;
        height: 50px;
    }

    /* Window — centered card with equal left/right spacing */
    .chatbot-window {
        position: fixed !important;
        left: 50% !important;
        right: auto !important;
        bottom: 14px !important;
        top: auto !important;

        transform: translateX(-50%) translateY(14px) scale(0.97) !important;
        transform-origin: bottom center !important;

        width: calc(100% - 32px) !important;
        max-width: calc(100% - 32px) !important;
        min-width: 0 !important;
        margin: 0 !important;

        height: 70vh !important;
        height: 70dvh !important;
        max-height: 70vh !important;
        max-height: 70dvh !important;

        border-radius: 18px !important;
        box-shadow: 0 8px 30px rgba(0,0,0,0.18) !important;
    }

    .chatbot-window.active {
        transform: translateX(-50%) translateY(0) scale(1) !important;
        opacity: 1 !important;
        visibility: visible !important;
    }

    /* Header */
    .chatbot-header {
        border-radius: 18px 18px 0 0;
        height: 54px;
        min-height: 54px;
        padding: 0 16px;
        width: 100%;
        box-sizing: border-box;
    }

    .chatbot-title-text strong { font-size: 15px; }

    /* Messages */
    .chatbot-messages {
        padding: 14px 16px;
        width: 100%;
        box-sizing: border-box;
    }

    .message-row { max-width: 80%; }

    .bot-message,
    .user-message { font-size: 13.5px; padding: 10px 13px; }

    /* Input area — full width, nothing cut off */
    .chatbot-input-area {
        padding: 10px 14px;
        height: 62px;
        min-height: 62px;
        width: 100%;
        box-sizing: border-box;
    }

    .chatbot-input  { height: 40px; font-size: 13.5px; }
    .chatbot-send   {
        width: 40px;
        height: 40px;
        min-width: 40px;
        flex-shrink: 0;
        font-size: 16px;
    }
}


/* =========================================================
   SMALL MOBILE — max 400px
========================================================= */

@media (max-width: 400px) {

    .chatbot-toggle {
        right: 12px !important;
        left: auto !important;
        bottom: 12px !important;
        width: 46px;
        height: 46px;
    }

    .chatbot-window {
        height: 75vh !important;
        height: 75dvh !important;
        max-height: 75vh !important;
        max-height: 75dvh !important;
        width: calc(100% - 24px) !important;
        max-width: calc(100% - 24px) !important;
        left: 50% !important;
        right: auto !important;
        bottom: 10px !important;
        transform: translateX(-50%) translateY(14px) scale(0.97) !important;
    }

    .chatbot-window.active {
        transform: translateX(-50%) translateY(0) scale(1) !important;
    }

    .chatbot-messages { padding: 12px 14px; }

    .chatbot-input-area {
        padding: 9px 12px;
        height: 58px;
        min-height: 58px;
    }

    .chatbot-title-text strong { font-size: 14px; }

    .chatbot-input { height: 38px; }
    .chatbot-send  { width: 38px; height: 38px; min-width: 38px; }
}