/* ============================================================
   CHATBOT — Kennedy Painting & Remodeling
   Companion styles for assets/js/chatbot.js
   Mobile-first, keyboard-aware, safe-area aware.
   ============================================================ */

/* ---- Root container ----
   IMPORTANT: This container must NEVER cover the viewport.
   It only wraps the toggle (bottom-right corner) and the
   chat window. All sizing is done on children, not here. */
.chatbot-container {
    position: fixed !important;
    right: 24px !important;
    bottom: 24px !important;
    z-index: 2147483000 !important;
    font-family: 'Poppins', sans-serif;
    /* No width/height — the container sizes to its children. */
}

/* ---- Toggle button ---- */
.chatbot-toggle {
    position: relative !important;
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    width: 60px !important;
    height: 60px !important;
    min-width: 60px !important;
    min-height: 60px !important;
    border-radius: 50% !important;
    border: none !important;
    background: linear-gradient(135deg, #1a73e8, #4a90e2) !important;
    color: #fff !important;
    font-size: 22px !important;
    cursor: pointer !important;
    box-shadow: 0 8px 24px rgba(26,115,232,0.4) !important;
    align-items: center !important;
    justify-content: center !important;
    transition: transform .2s, box-shadow .2s !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.chatbot-toggle i,
.chatbot-toggle .fas,
.chatbot-toggle .fa {
    color: #fff !important;
    font-size: 22px !important;
    line-height: 1 !important;
    pointer-events: none;
}
.chatbot-toggle:hover {
    transform: scale(1.06) !important;
    box-shadow: 0 10px 30px rgba(26,115,232,0.55) !important;
}
.chatbot-toggle:active { transform: scale(0.98) !important; }

.chatbot-toggle-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 12px;
    height: 12px;
    background: #ef4444;
    border-radius: 50%;
    border: 2px solid #fff;
    opacity: 0;
    transform: scale(0.6);
    transition: all .2s;
}
.chatbot-toggle.has-unread .chatbot-toggle-badge {
    opacity: 1;
    transform: scale(1);
    animation: kb-pulse 1.4s infinite;
}
@keyframes kb-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(239,68,68,.6); }
    70%  { box-shadow: 0 0 0 10px rgba(239,68,68,0); }
    100% { box-shadow: 0 0 0 0 rgba(239,68,68,0); }
}

/* ---- Chat window (hidden until .open) ---- */
.chatbot-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 580px;
    max-height: calc(100vh - 120px);
    max-height: calc(100dvh - 120px);
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.22);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(14px) scale(.98);
    pointer-events: none;
    transition: opacity .22s ease, transform .22s ease;
}
.chatbot-container.open .chatbot-window {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ---- Header ---- */
.chatbot-header {
    background: linear-gradient(135deg, #1a73e8, #4a90e2);
    color: #fff;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
.chatbot-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1 1 auto;
    min-width: 0;
}
.chatbot-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.22);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}
.chatbot-header-text { min-width: 0; }
.chatbot-title {
    font-size: 14.5px;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #fff;
}
.chatbot-subtitle {
    font-size: 11.5px;
    opacity: 0.9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #fff;
}

.chatbot-lang {
    display: flex;
    background: rgba(255,255,255,0.18);
    border-radius: 14px;
    padding: 2px;
    flex-shrink: 0;
}
.chatbot-lang button {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 12px;
    cursor: pointer;
    transition: all .15s;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
}
.chatbot-lang button.active {
    background: #fff;
    color: #1a73e8;
}

.chatbot-close {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 15px;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .15s;
    -webkit-tap-highlight-color: transparent;
}
.chatbot-close:hover { background: rgba(255,255,255,0.18); }

/* ---- Messages ---- */
.chatbot-messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 16px 14px;
    background: #f7f9fc;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}
.chatbot-messages::-webkit-scrollbar { width: 6px; }
.chatbot-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
.chatbot-messages::-webkit-scrollbar-track { background: transparent; }

.message { display: flex; width: 100%; }
.message.bot-message  { justify-content: flex-start; }
.message.user-message { justify-content: flex-end; }

.bubble {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13.8px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    white-space: normal;
}
.bot-message .bubble {
    background: #fff;
    color: #1f2937;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.user-message .bubble {
    background: linear-gradient(135deg, #1a73e8, #4a90e2);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.msg-time {
    display: block;
    font-size: 10px;
    opacity: 0.55;
    margin-top: 4px;
    text-align: right;
}

/* ---- Typing indicator ---- */
.typing-indicator .bubble {
    display: inline-flex;
    gap: 4px;
    padding: 12px 16px;
}
.typing-indicator .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #9ca3af;
    animation: kb-bounce 1.2s infinite;
}
.typing-indicator .dot:nth-child(2) { animation-delay: .15s; }
.typing-indicator .dot:nth-child(3) { animation-delay: .3s; }
@keyframes kb-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: .5; }
    30%           { transform: translateY(-5px); opacity: 1; }
}

/* ---- Suggestion chips ---- */
.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 2px 0 0;
}
.chat-suggestions .chip {
    background: #fff;
    border: 1px solid #dbeafe;
    color: #1a73e8;
    font-size: 12.5px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 20px;
    cursor: pointer;
    font-family: inherit;
    transition: all .15s;
    -webkit-tap-highlight-color: transparent;
}
.chat-suggestions .chip:hover {
    background: #eff6ff;
    border-color: #1a73e8;
}
.chat-suggestions .chip:active { transform: scale(0.96); }

/* ---- Quick actions ---- */
.chat-quick-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-top: 4px;
}
.quick-action {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    font-size: 12.5px;
    color: #374151;
    text-decoration: none;
    cursor: pointer;
    font-family: inherit;
    transition: all .15s;
    -webkit-tap-highlight-color: transparent;
}
.quick-action:hover {
    background: #eff6ff;
    border-color: #1a73e8;
    color: #1a73e8;
    text-decoration: none;
}
.qa-icon { font-size: 14px; }

/* ---- Input ---- */
.chatbot-input {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: #fff;
    border-top: 1px solid #eef2f7;
    flex-shrink: 0;
    box-sizing: border-box;
}
.chatbot-input input {
    flex: 1 1 auto;
    min-width: 0;
    height: 42px;
    border: 1px solid #e5e7eb;
    border-radius: 24px;
    padding: 0 16px;
    font-family: inherit;
    outline: none;
    box-sizing: border-box;
    transition: border-color .15s, box-shadow .15s;
    font-size: 16px;  /* 16px prevents iOS auto-zoom on focus */
}
.chatbot-input input:focus {
    border-color: #1a73e8;
    box-shadow: 0 0 0 3px rgba(26,115,232,0.12);
}
.chatbot-input button {
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #1a73e8, #4a90e2);
    color: #fff;
    font-size: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-sizing: border-box;
    transition: transform .15s, box-shadow .15s;
    -webkit-tap-highlight-color: transparent;
}
.chatbot-input button:hover {
    transform: scale(1.06);
    box-shadow: 0 4px 12px rgba(26,115,232,0.4);
}
.chatbot-input button i { pointer-events: none; }

/* ---- Teaser (proactive nudge) ---- */
.chatbot-teaser {
    position: absolute;
    right: 0;
    bottom: 80px;
    max-width: 260px;
    background: #fff;
    color: #1f2937;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.4;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
    transition: opacity .25s, transform .25s;
}
.chatbot-teaser.show {
    opacity: 1;
    transform: translateY(0);
}

/* ============================================================
   Floating buttons — stack cleanly with WhatsApp
   ============================================================ */
.whatsapp-float {
    position: fixed;
    right: 24px;
    bottom: 100px;
    width: 56px;
    height: 56px;
    font-size: 26px;
    z-index: 10400;
}

/* ============================================================
   Tablet
   ============================================================ */
@media (max-width: 992px) {
    .chatbot-container { right: 18px !important; bottom: 18px !important; }
    .whatsapp-float     { right: 18px; bottom: 92px; }
}

/* ============================================================
   MOBILE
   ------------------------------------------------------------
   KEY RULE: the container NEVER grows beyond the toggle.
   The chat window is position: fixed on mobile so it
   anchors to the viewport, but the container itself
   stays in the corner — no full-screen overlay.
   ============================================================ */
@media (max-width: 640px) {

    /* Container stays a small corner element */
    .chatbot-container {
        left: auto !important;
        right: calc(12px + env(safe-area-inset-right, 0px)) !important;
        bottom: calc(12px + env(safe-area-inset-bottom, 0px)) !important;
        top: auto !important;
        /* No width / height — sizes to the toggle. */
    }

    .chatbot-toggle {
        position: relative !important;   /* back to relative — no full overlay */
        width: 56px !important;
        height: 56px !important;
        min-width: 56px !important;
        min-height: 56px !important;
        font-size: 20px !important;
    }

    /* The chat window on mobile is fixed to the viewport edges.
       It's NOT inside the container's box — it floats above it. */
    .chatbot-window {
        position: fixed !important;
        left: 8px !important;
        right: 8px !important;
        bottom: calc(8px + env(safe-area-inset-bottom, 0px)) !important;
        top: 70px !important;                /* below the navbar */
        width: auto !important;
        max-width: none !important;
        height: auto !important;
        max-height: none !important;
        min-height: 0 !important;
        border-radius: 16px !important;
        overflow: hidden !important;
        z-index: 2147483000 !important;
    }

    /* When chat is open, hide the toggle */
    .chatbot-container.open .chatbot-toggle { display: none !important; }

    /* Compact header */
    .chatbot-header { padding: 10px 12px !important; gap: 8px !important; }
    .chatbot-avatar {
        width: 34px !important;
        height: 34px !important;
        font-size: 17px !important;
    }
    .chatbot-title    { font-size: 13.5px !important; }
    .chatbot-subtitle { font-size: 10.5px !important; }
    .chatbot-lang button { padding: 3px 7px !important; font-size: 10.5px !important; }
    .chatbot-close { padding: 6px 8px !important; font-size: 14px !important; }

    /* Messages */
    .chatbot-messages { padding: 12px 10px !important; gap: 8px !important; }
    .bubble {
        font-size: 13.5px !important;
        max-width: 88% !important;
        padding: 9px 12px !important;
    }

    /* Suggestion chips: horizontal scroll */
    .chat-suggestions {
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
        scrollbar-width: none;
    }
    .chat-suggestions::-webkit-scrollbar { display: none; }
    .chat-suggestions .chip {
        flex: 0 0 auto;
        white-space: nowrap;
        font-size: 12px !important;
        padding: 6px 11px !important;
    }

    /* Quick actions */
    .chat-quick-actions {
        grid-template-columns: 1fr 1fr !important;
        gap: 5px !important;
    }
    .quick-action { padding: 8px 8px !important; font-size: 12px !important; }

    /* Input */
    .chatbot-input {
        padding: 8px 10px !important;
        gap: 6px !important;
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)) !important;
    }
    .chatbot-input input {
        height: 42px !important;
        font-size: 16px !important;
        padding: 0 14px !important;
    }
    .chatbot-input button {
        flex: 0 0 42px !important;
        width: 42px !important;
        height: 42px !important;
        font-size: 15px !important;
    }

    /* WhatsApp stacks above the toggle */
    .whatsapp-float {
        right: calc(12px + env(safe-area-inset-right, 0px)) !important;
        bottom: calc(80px + env(safe-area-inset-bottom, 0px)) !important;
        width: 52px !important;
        height: 52px !important;
        font-size: 22px !important;
    }
}

/* Small phones */
@media (max-width: 380px) {
    .chatbot-window {
        left: 6px !important;
        right: 6px !important;
        top: 64px !important;
        bottom: calc(6px + env(safe-area-inset-bottom, 0px)) !important;
    }
    .chatbot-title    { font-size: 13px !important; }
    .chatbot-subtitle { font-size: 10px !important; }
    .chatbot-avatar {
        width: 30px !important;
        height: 30px !important;
        font-size: 15px !important;
    }
    .chatbot-header { padding: 8px 10px !important; }
    .chatbot-input input { padding: 0 12px !important; }
    .bubble { font-size: 13px !important; }
}

/* ============================================================
   Print — hide chatbot entirely
   ============================================================ */
@media print {
    .chatbot-container,
    .chatbot-toggle,
    .chatbot-window,
    .chatbot-teaser { display: none !important; }
}