/*
 * XPANDSIA AI Chatbot Widget
 * ─────────────────────────────────────────────────────────────────────
 * Stacked above the WhatsApp float on the same side, RTL-aware, with
 * generous spacing so the two buttons NEVER overlap regardless of
 * viewport size.
 *
 * Hide/show uses `display: none|flex` (NOT transform/opacity) because the
 * legacy `force-visibility.js` MutationObserver overrides those properties.
 */

/* ═══════════ POSITIONING TOKENS — single source of truth ═══════════ */
:root {
    --xp-fab-size:        60px;
    --xp-fab-edge:        30px;
    --xp-fab-gap:         16px;  /* visual breathing room between the two buttons */
    --xp-wa-bottom:       30px;  /* must match .whatsapp-float bottom */
    --xp-wa-size:         60px;  /* must match .whatsapp-float size */
}

@media (max-width: 768px) {
    :root {
        --xp-fab-size:    52px;
        --xp-fab-edge:    18px;
        --xp-fab-gap:     14px;
        --xp-wa-bottom:   20px;
        --xp-wa-size:     55px;
    }
}

/* ═══════════ FLOATING BUTTON ═══════════ */
.chatbot-float {
    position: fixed !important;
    /* Stacked above WhatsApp: WA top-edge = WA bottom + WA size, then add gap */
    bottom: calc(var(--xp-wa-bottom) + var(--xp-wa-size) + var(--xp-fab-gap));
    right: var(--xp-fab-edge);
    width: var(--xp-fab-size);
    height: var(--xp-fab-size);
    background: linear-gradient(135deg, #FFD400, #FFE55C);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 25px rgba(255, 212, 0, 0.4);
    cursor: pointer;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.25s ease;
    z-index: 1000;
    border: 2px solid rgba(0, 0, 0, 0.08);
    padding: 0;
}

.chatbot-float:hover {
    transform: translateY(-4px) scale(1.06);
    box-shadow: 0 12px 30px rgba(255, 212, 0, 0.5);
}

/* Hidden state — display:none is the only property force-visibility doesn't touch */
.chatbot-float.is-hidden {
    display: none !important;
}

.chatbot-float svg {
    width: 28px;
    height: 28px;
    color: #000;
}

/* Pulse ring */
.chatbot-float::before {
    content: '';
    position: absolute;
    top: -4px; left: -4px; right: -4px; bottom: -4px;
    border-radius: 50%;
    border: 2px solid #FFD400;
    opacity: 0;
    animation: chatbotPulse 2.4s ease-out infinite;
    pointer-events: none;
}

@keyframes chatbotPulse {
    0%   { transform: scale(0.95); opacity: 0.7; }
    80%  { transform: scale(1.35); opacity: 0; }
    100% { transform: scale(1.35); opacity: 0; }
}

/* RTL: mirror to left edge */
[dir="rtl"] .chatbot-float {
    left: var(--xp-fab-edge);
    right: auto;
}

/* ═══════════ CHAT PANEL ═══════════ */
.chatbot-panel {
    position: fixed;
    bottom: calc(var(--xp-wa-bottom) + var(--xp-wa-size) + var(--xp-fab-gap));
    right: var(--xp-fab-edge);
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 540px;
    max-height: calc(100vh - 140px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(0, 0, 0, 0.05);
    flex-direction: column;
    overflow: hidden;
    z-index: 1001;
    display: none !important; /* CLOSED state — survives force-visibility */
}

.chatbot-panel.is-open {
    display: flex !important;
    animation: chatbotPanelIn 0.25s ease-out;
}

@keyframes chatbotPanelIn {
    from { transform: translateY(15px) scale(0.96); opacity: 0; }
    to   { transform: translateY(0) scale(1); opacity: 1; }
}

[dir="rtl"] .chatbot-panel {
    left: var(--xp-fab-edge);
    right: auto;
}

/* On mobile, the panel goes nearly fullscreen-width */
@media (max-width: 768px) {
    .chatbot-panel {
        right: 8px;
        left: 8px;
        width: auto;
        max-width: none;
        height: calc(100vh - 130px);
        max-height: calc(100vh - 130px);
    }
    [dir="rtl"] .chatbot-panel {
        left: 8px;
        right: 8px;
    }
}

/* ═══════════ HEADER ═══════════ */
.chatbot-header {
    background: linear-gradient(135deg, #1a1a1a 0%, #000 100%);
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.chatbot-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #FFD400, #FFE55C);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    color: #000;
    font-size: 18px;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

.chatbot-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chatbot-header-avatar::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 10px;
    height: 10px;
    background: #22c55e;
    border: 2px solid #000;
    border-radius: 50%;
}

.chatbot-header-text { flex: 1; min-width: 0; }
.chatbot-header-title  { font-size: 15px; font-weight: 700; line-height: 1.2; margin: 0; }
.chatbot-header-status { font-size: 12px; opacity: 0.7; margin: 2px 0 0; }

.chatbot-close {
    background: rgba(255, 255, 255, 0.16);
    border: 1px solid rgba(255, 255, 255, 0.22);
    color: #fff;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.25s ease;
    flex-shrink: 0;
    position: relative;
    z-index: 2;
    -webkit-tap-highlight-color: rgba(255, 212, 0, 0.4);
    user-select: none;
    padding: 0;
}

.chatbot-close svg {
    width: 18px; height: 18px;
    flex: 0 0 auto !important;
    flex-shrink: 0 !important;
    min-width: 18px !important;
    display: block !important;
}

.chatbot-close:hover  { background: rgba(255, 255, 255, 0.28); transform: rotate(90deg); }
.chatbot-close:active { background: rgba(255, 212, 0, 0.35); transform: scale(0.92); }

/* ═══════════ MESSAGES ═══════════ */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f8f9fa;
    scroll-behavior: smooth;
}

.chatbot-messages::-webkit-scrollbar { width: 6px; }
.chatbot-messages::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.15); border-radius: 3px; }

.chatbot-msg {
    display: flex;
    margin-bottom: 12px;
    animation: chatbotMsgIn 0.25s ease-out;
}

@keyframes chatbotMsgIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.chatbot-msg-bot  { justify-content: flex-start; }
.chatbot-msg-user { justify-content: flex-end; }

.chatbot-bubble {
    max-width: 78%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.chatbot-msg-bot .chatbot-bubble {
    background: #fff;
    color: #1a1a1a;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.chatbot-msg-user .chatbot-bubble {
    background: #FFD400;
    color: #000;
    border-bottom-right-radius: 4px;
    font-weight: 500;
}

.chatbot-typing .chatbot-bubble { padding: 14px 16px; display: inline-flex; align-items: center; gap: 4px; }
.chatbot-typing-dot { width: 7px; height: 7px; background: #999; border-radius: 50%; animation: chatbotTyping 1.2s ease-in-out infinite; }
.chatbot-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.chatbot-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes chatbotTyping { 0%, 60%, 100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-4px); opacity: 1; } }

/* ═══════════ INPUT ═══════════ */
.chatbot-input-wrap {
    padding: 12px 16px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    background: #fff;
    flex-shrink: 0;
}

.chatbot-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.chatbot-input {
    flex: 1;
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 80px;
    line-height: 1.4;
    transition: border-color 0.2s ease;
}

.chatbot-input:focus { border-color: #FFD400; }

.chatbot-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #FFD400, #FFE55C);
    color: #000;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, opacity 0.2s ease;
    flex-shrink: 0;
}

.chatbot-send:hover:not(:disabled) { transform: scale(1.08); box-shadow: 0 4px 14px rgba(255,212,0,0.5); }
.chatbot-send:disabled              { opacity: 0.4; cursor: not-allowed; }
/* flex-shrink:0 + min-width prevents flexbox from crushing the icon to 0 width */
.chatbot-send svg {
    width: 20px; height: 20px;
    flex: 0 0 auto !important;
    flex-shrink: 0 !important;
    min-width: 20px !important;
    display: block !important;
    transform: translateX(1px); /* optical-center the send arrow */
}

.chatbot-disclaimer {
    font-size: 10px;
    color: #888;
    text-align: center;
    margin-top: 8px;
}

/* ---- Quick-Reply Buttons ---- */
.chatbot-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 12px 8px;
    animation: fadeIn .2s ease;
}

.chatbot-btn {
    background: #fff;
    border: 1.5px solid #FFD400;
    border-radius: 1.5rem;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 600;
    color: #1a1a1a;
    cursor: pointer;
    transition: background .15s ease, transform .1s ease, box-shadow .15s ease;
    white-space: nowrap;
}

.chatbot-btn:hover {
    background: #FFD400;
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(255,212,0,.35);
}

.chatbot-btn:active { transform: scale(.97); }

@keyframes fadeIn { from { opacity:0; transform: translateY(4px); } to { opacity:1; transform: none; } }
