/* ==========================================================
   Omniservice AI Assistant — Plugin CSS
   All rules scoped to #ai-assistant / #ai-chat to avoid
   affecting the host site's styles.
   ========================================================== */


/* ==========================================================
   Floating Pill Button
   ========================================================== */

#ai-assistant {
    position: fixed;
    bottom: 15px;
    right: 15px;
    cursor: pointer;
    z-index: 99999;
    transform: translateZ(0);
    isolation: isolate;
}

#ai-assistant.invisible {
    display: none !important;
}

#ai-assistant .ai-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    color: white;
    font-family: 'Helvetica', 'Arial', sans-serif;
    position: relative;
}

#ai-assistant .ai-floating-button {
    height: 54px;
    width: auto;
    min-width: 54px;
    border-radius: 50px;
    padding: 0 22px 0 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: visible;
    cursor: pointer;
    box-shadow:
        0 4px 20px rgba(0, 0, 0, 0.22),
        0 2px 8px  rgba(0, 0, 0, 0.12),
        inset 0 1px 0 rgba(255, 255, 255, 0.18);
    border: none;
    transition: transform 0.22s ease, box-shadow 0.22s ease;
    white-space: nowrap;
    position: relative;
}

#ai-assistant .ai-floating-button::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50px;
    background: linear-gradient(
        145deg,
        rgba(255, 255, 255, 0.20) 0%,
        rgba(255, 255, 255, 0.05) 50%,
        transparent 100%
    );
    pointer-events: none;
}

#ai-assistant .ai-floating-button:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow:
        0 8px 30px rgba(0, 0, 0, 0.28),
        0 4px 12px rgba(0, 0, 0, 0.16),
        inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

/* ── Online indicator dot ──────────────────────────────────── */

#ai-assistant .ai-online-dot {
    position: absolute;
    top:   -4px;
    right: -4px;
    width:  13px;
    height: 13px;
    background: #22c55e;
    border-radius: 50%;
    border: 2.5px solid #fff;
    z-index: 2;
    animation: ai-dot-pulse 2.4s ease-in-out infinite;
}

@keyframes ai-dot-pulse {
    0%, 100% { box-shadow: 0 0 0 0   rgba(34, 197, 94, 0.55); }
    55%       { box-shadow: 0 0 0 7px rgba(34, 197, 94, 0);    }
}

/* ── Icon circle ───────────────────────────────────────────── */

#ai-assistant .ai-btn-icon {
    width:  34px;
    height: 34px;
    min-width: 34px;
    background: rgba(255, 255, 255, 0.22);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s ease;
}

#ai-assistant .ai-floating-button:hover .ai-btn-icon {
    background: rgba(255, 255, 255, 0.35);
}

#ai-assistant .ai-btn-icon i {
    color: white;
    font-size: 16px;
    line-height: 1;
}

/* ── Button text ───────────────────────────────────────────── */

#ai-assistant .ai-btn-text {
    color: white;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.3px;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.20);
    line-height: 1;
    user-select: none;
}

#ai-assistant .ai-floating-icon { display: none !important; }


/* ==========================================================
   Chat Container
   ========================================================== */

#ai-chat {
    position: fixed;
    right: 30px;
    bottom: 30px;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 620px;
    max-height: calc(100vh - 48px);
    display: flex;
    flex-direction: column;
    font-family: 'Helvetica', 'Arial', sans-serif;
    border-radius: 15px;
    border-color: rgba(0, 0, 0, 0.175);
    overflow: hidden;
    z-index: 99999;
    overscroll-behavior: contain;
    will-change: auto;
    background: #fff;
}

#ai-chat.invisible {
    display: none !important;
    pointer-events: none !important;
    visibility: hidden !important;
}

#ai-chat .card-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    padding: 12px;
}


/* ==========================================================
   Header
   ========================================================== */

#ai-chat .card-header-custom {
    border-radius: 15px 15px 0 0;
    background-color: black;
    font-size: 16px;
    flex-shrink: 0;
}

#ai-chat #ai-close-chat,
#ai-chat #ai-expand-chat,
#ai-chat #ai-clear-chat {
    padding: 2px 5px;
    border-radius: 5px;
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

#ai-chat #ai-close-chat:hover  { background: #ff1919; transform: scale(1.05); }
#ai-chat #ai-clear-chat:hover  { background: #0d6efd; transform: scale(1.05); }
#ai-chat #ai-expand-chat:hover { background: rgba(255, 255, 255, 0.2); transform: scale(1.05); }


/* ==========================================================
   Chat Messages Area
   ========================================================== */

#ai-chat #ai-chat-wrapper {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    font-size: 16px;
    padding: 10px;
    padding-right: 6px;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

#ai-chat #ai-chat-wrapper::-webkit-scrollbar       { width: 8px; }
#ai-chat #ai-chat-wrapper::-webkit-scrollbar-thumb { background: #dadada; border-radius: 10px; }
#ai-chat #ai-chat-wrapper::-webkit-scrollbar-track { background: transparent; }


/* ==========================================================
   Messages
   ========================================================== */

#ai-chat .avatar-img {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    object-fit: cover;
}

#ai-chat .ai-message {
    border-radius: 15px;
    background-color: #dadada;
    color: black;
    max-width: 80%;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

#ai-chat .user-message {
    border-radius: 15px;
    background-color: #0d6efd;
    color: white;
    max-width: 80%;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

#ai-chat .ai-message p,
#ai-chat .user-message p { margin-bottom: 6px; }
#ai-chat .ai-message p:last-of-type,
#ai-chat .user-message p:last-of-type { margin-bottom: 0; }


/* ==========================================================
   Form
   ========================================================== */

#ai-chat #ai-chat-form {
    flex-shrink: 0;
}

#ai-chat #ai-chat-form .d-flex {
    align-items: flex-end;
}

#ai-chat #ai-user-message {
    border-color: #dee2e6;
    font-family: 'Helvetica', 'Arial', sans-serif;
    font-size: 15px;
    resize: none;
    min-height: 46px;
    max-height: 90px;
    line-height: 1.4;
    padding-top: 12px;
    padding-bottom: 12px;
    overflow-y: auto;
}

#ai-chat #ai-send-button {
    background: #0d6efd;
    border-color: #0d6efd;
    font-size: 16px;
    color: white;
    flex-shrink: 0;
    align-self: flex-end;
    width: 46px;
    min-width: 46px;
    height: 46px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

#ai-chat #ai-send-button:hover,
#ai-chat #ai-send-button:active {
    background: #0a58ca;
    border-color: #0a58ca;
}


/* ==========================================================
   WhatsApp Button
   ========================================================== */

#ai-chat #ai-whatsapp-button {
    width: 46px;
    min-width: 46px;
    height: 46px;
    border-radius: 50%;
    background: #ffffff;
    border: 1.5px solid #e0e0e0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.10);
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none !important;
    flex-shrink: 0;
    align-self: flex-end;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#ai-chat #ai-whatsapp-button i {
    color: #25D366;
    font-size: 22px;
    line-height: 1;
}

#ai-chat #ai-whatsapp-button:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
    text-decoration: none !important;
}


/* ==========================================================
   Lead Form
   ========================================================== */

#ai-chat #ai-lead-form {
    flex-shrink: 0;
    margin-bottom: 10px;
}

#ai-chat #ai-lead-form .bg-light {
    background-color: #f8f9fa !important;
}


/* ==========================================================
   Expanded State
   ========================================================== */

#ai-chat.expanded {
    left: 24px !important;
    right: 24px !important;
    top: 24px !important;
    bottom: 24px !important;
    width: auto !important;
    max-width: none !important;
    height: auto !important;
    max-height: none !important;
}

#ai-chat.expanded #ai-chat-wrapper {
    flex: 1;
    min-height: 0;
}


/* ==========================================================
   Streaming cursor
   ========================================================== */

#ai-chat .ai-cursor {
    display: inline-block;
    width: 2px;
    height: 0.85em;
    background: #888;
    margin-left: 2px;
    vertical-align: middle;
    border-radius: 1px;
    animation: ai-blink 0.9s step-end infinite;
}

@keyframes ai-blink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0; }
}


/* ==========================================================
   Code formatting
   ========================================================== */

#ai-chat .ai-message pre {
    background: #1e1e1e;
    color: #d4d4d4;
    border-radius: 8px;
    padding: 12px;
    margin: 8px 0 4px;
    overflow-x: auto;
    font-size: 13px;
    line-height: 1.5;
}

#ai-chat .ai-message pre code {
    background: none;
    color: inherit;
    padding: 0;
    border-radius: 0;
    font-size: inherit;
}

#ai-chat .ai-message code {
    background: #e8e8e8;
    color: #c7254e;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 85%;
    font-family: 'Courier New', Courier, monospace;
}


/* ==========================================================
   Tablet Responsive
   ========================================================== */

@media (min-width: 577px) and (max-width: 991px) {
    #ai-chat {
        right: 18px;
        bottom: 18px;
        width: 420px;
        max-width: calc(100vw - 36px);
        height: 650px;
        max-height: calc(100vh - 36px);
    }
}


/* ==========================================================
   Mobile Responsive
   ========================================================== */

@media (max-width: 576px) {
    #ai-assistant {
        right: 18px;
        bottom: 18px;
        z-index: 99998;
    }

    /* Pill → circle on mobile */
    #ai-assistant .ai-floating-button {
        width: 56px !important;
        height: 56px !important;
        min-width: 56px !important;
        padding: 0 !important;
        border-radius: 50% !important;
        justify-content: center !important;
    }
    #ai-assistant .ai-btn-text { display: none !important; }
    #ai-assistant .ai-btn-icon {
        width: 30px !important;
        height: 30px !important;
        min-width: 30px !important;
    }
    #ai-assistant .ai-btn-icon i { font-size: 15px !important; }
    #ai-assistant .ai-online-dot {
        width: 11px !important;
        height: 11px !important;
        top: -3px !important;
        right: -3px !important;
    }

    #ai-chat {
        left: 10px;
        right: 10px;
        bottom: 10px;
        width: calc(100vw - 20px);
        height: calc(100dvh - 20px);
        max-height: calc(100dvh - 20px);
        border-radius: 16px;
    }

    #ai-chat.expanded {
        left: 0 !important;
        right: 0 !important;
        top: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        border-radius: 0;
    }

    #ai-chat .card-header-custom {
        padding: 12px !important;
        font-size: 15px;
    }

    #ai-chat .card-body { padding: 10px; }

    #ai-chat #ai-chat-wrapper {
        padding: 8px;
        padding-right: 2px;
        font-size: 15px;
    }

    #ai-chat #ai-user-message {
        min-height: 44px;
        max-height: 80px;
        font-size: 15px;
    }

    #ai-chat #ai-send-button,
    #ai-chat #ai-whatsapp-button {
        width: 44px;
        min-width: 44px;
        height: 44px;
    }

    #ai-chat #ai-whatsapp-button i { font-size: 20px; }

    #ai-chat .avatar-img {
        width: 36px;
        height: 36px;
        min-width: 36px;
    }

    #ai-chat .ai-message,
    #ai-chat .user-message {
        max-width: 78vw;
        font-size: 14px;
    }
}


/* ==========================================================
   Very Small Mobile
   ========================================================== */

@media (max-width: 380px) {
    #ai-chat {
        left: 6px;
        right: 6px;
        bottom: 6px;
        width: calc(100vw - 12px);
        height: calc(100dvh - 12px);
        max-height: calc(100dvh - 12px);
    }

    #ai-chat .ai-message,
    #ai-chat .user-message { max-width: 76vw; }
    #ai-chat #ai-user-message { font-size: 14px; }
}
