/* ─── BBF Chat Widget – Paula ──────────────────────────────────────── */

:root {
    /* BBF Brand Colors – extracted from babysbestfood.com */
    --bbf-primary:       #979BC9;   /* main lavender – buttons, header */
    --bbf-primary-dark:  #787BAF;   /* deeper lavender – headings */
    --bbf-primary-light: #eeeef8;   /* very light lavender – bot bubbles */
    --bbf-accent:        #8687B6;   /* mid lavender – labels */
    --bbf-cream:         #F8F5F0;   /* warm off-white background */
    --bbf-beige:         #F3E8CF;   /* warm beige – secondary bg */
    --bbf-section-bg:    #D3CAD8;   /* light lavender-grey section */
    --bbf-text:          #3C3C3C;
    --bbf-text-muted:    #888;
    --bbf-bg:            #ffffff;
    --bbf-border:        #e8e6ef;
    --bbf-radius:        18px;
    --bbf-shadow:        0 8px 40px rgba(120,123,175,0.18), 0 2px 12px rgba(0,0,0,0.08);
    --bbf-font:          'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --bbf-z:             99999;
}

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap');

/* ─── Root container ─── */
#bbf-chat-root {
    position: fixed;
    bottom: 24px;
    left: 24px;
    right: auto;
    z-index: var(--bbf-z);
    font-family: var(--bbf-font);
}

/* ─── Trigger Button ─── */
#bbf-chat-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, var(--bbf-primary) 0%, var(--bbf-primary-dark) 100%);
    color: white;
    border: none;
    border-radius: 50px;
    padding: 13px 20px 13px 16px;
    cursor: pointer;
    font-family: var(--bbf-font);
    font-size: 15px;
    font-weight: 700;
    box-shadow: 0 4px 20px rgba(151,155,201,0.5), 0 2px 8px rgba(0,0,0,0.10);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    letter-spacing: 0.01em;
}

#bbf-chat-trigger:hover {
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 6px 28px rgba(151,155,201,0.65), 0 3px 12px rgba(0,0,0,0.12);
}

#bbf-chat-trigger:active {
    transform: translateY(0) scale(0.98);
}

.bbf-trigger-label {
    font-weight: 800;
}

/* ─── Chat Window ─── */
#bbf-chat-window {
    position: absolute;
    bottom: 70px;
    left: 0;
    right: auto;
    z-index: 100000;
    width: 500px;
    min-width: 300px;
    max-width: min(600px, 92vw);
    height: 700px;
    min-height: 420px;
    max-height: 80vh;
    background: var(--bbf-bg);
    border-radius: var(--bbf-radius);
    box-shadow: var(--bbf-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: bbf-slide-up 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: 1px solid rgba(120,123,175,0.18);
    transition: box-shadow 0.2s;
}

/* When being resized – stronger shadow feedback */
#bbf-chat-window:focus-within {
    box-shadow: var(--bbf-shadow), 0 0 0 2px rgba(151,155,201,0.25);
}

/* Expanded / maximized state */
#bbf-chat-window.bbf-expanded {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    bottom: auto !important;
    right: auto !important;
    transform: translate(-50%, -50%) !important;
    width: min(820px, 92vw) !important;
    height: min(680px, 88vh) !important;
    max-width: 92vw !important;
    max-height: 88vh !important;
    border-radius: 20px !important;
    z-index: 100000 !important;

    animation: bbf-expand 0.25s cubic-bezier(0.34, 1.3, 0.64, 1);
}

@keyframes bbf-expand {
    from { opacity: 0.7; transform: translate(-50%, -48%) scale(0.96); }
    to   { opacity: 1;   transform: translate(-50%, -50%) scale(1); }
}

/* Backdrop overlay when expanded */
#bbf-chat-backdrop {
    display: none !important;
    pointer-events: none !important;
}

#bbf-chat-backdrop.visible {
    display: none !important;
    pointer-events: none !important;
}

@keyframes bbf-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

#bbf-chat-window[hidden] {
    display: none;
}


@keyframes bbf-slide-up {
    from { opacity: 0; transform: translateY(16px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Expand button – hidden by default */
#bbf-chat-expand { display: none; }

@media (hover: none) {
    /* Hide expand button on touch devices (mobile) */
    #bbf-chat-expand { display: none; }
    #bbf-chat-window { resize: none; }
    #bbf-chat-window::after { display: none; }
}

/* ─── Header ─── */
#bbf-chat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: linear-gradient(135deg, var(--bbf-primary) 0%, var(--bbf-primary-dark) 100%);
    color: white;
    flex-shrink: 0;
}

.bbf-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 2px solid rgba(255,255,255,0.4);
}

.bbf-header-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.bbf-header-name {
    font-size: 15px;
    font-weight: 800;
    letter-spacing: 0.01em;
}

.bbf-header-status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11.5px;
    opacity: 0.9;
    font-weight: 600;
}

.bbf-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #6dea8e;
    box-shadow: 0 0 0 2px rgba(109,234,142,0.35);
    animation: bbf-pulse 2s infinite;
}

@keyframes bbf-pulse {
    0%, 100% { box-shadow: 0 0 0 2px rgba(109,234,142,0.35); }
    50%       { box-shadow: 0 0 0 5px rgba(109,234,142,0.1); }
}

#bbf-chat-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.85;
    transition: opacity 0.15s, background 0.15s;
}

#bbf-chat-close:hover {
    opacity: 1;
    background: rgba(255,255,255,0.2);
}

/* ─── Messages area ─── */
#bbf-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

#bbf-chat-messages::-webkit-scrollbar { width: 4px; }
#bbf-chat-messages::-webkit-scrollbar-track { background: transparent; }
#bbf-chat-messages::-webkit-scrollbar-thumb { background: #ddd; border-radius: 4px; }

/* ─── Message bubbles ─── */
.bbf-msg {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    animation: bbf-msg-in 0.22s ease;
    max-width: 92%;
}

@keyframes bbf-msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.bbf-msg.bbf-msg-bot { align-self: flex-start; }
.bbf-msg.bbf-msg-user { align-self: flex-end; flex-direction: row-reverse; }

.bbf-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--bbf-primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
}

.bbf-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.55;
    max-width: 260px;
    word-wrap: break-word;
}

.bbf-msg-bot .bbf-bubble {
    background: var(--bbf-primary-light);
    color: var(--bbf-text);
    border-bottom-left-radius: 4px;
}

.bbf-msg-user .bbf-bubble {
    background: linear-gradient(135deg, var(--bbf-primary) 0%, var(--bbf-primary-dark) 100%);
    color: white;
    border-bottom-right-radius: 4px;
    font-weight: 600;
}

/* ─── Typing indicator ─── */
.bbf-typing .bbf-bubble {
    padding: 12px 16px;
}

.bbf-typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
    height: 14px;
}

.bbf-typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--bbf-primary);
    animation: bbf-bounce 1.2s infinite ease-in-out;
}
.bbf-typing-dots span:nth-child(2) { animation-delay: 0.18s; }
.bbf-typing-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes bbf-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
    40%            { transform: translateY(-6px); opacity: 1; }
}

/* ─── Product cards grid ─── */
.bbf-products-wrap {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 310px;
    align-self: flex-start;
    padding-left: 36px;
}

.bbf-products-intro {
    font-size: 13px;
    color: var(--bbf-text);
    padding: 8px 12px;
    background: var(--bbf-primary-light);
    border-radius: 12px;
    margin-bottom: 2px;
}

.bbf-products-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.bbf-product-card {
    background: white;
    border: 1.5px solid var(--bbf-border);
    border-radius: 12px;
    overflow: hidden;
    text-decoration: none;
    color: var(--bbf-text);
    transition: border-color 0.18s, box-shadow 0.18s, transform 0.18s;
    display: flex;
    flex-direction: column;
}

.bbf-product-card:hover {
    border-color: var(--bbf-primary);
    box-shadow: 0 4px 14px rgba(151,155,201,0.25);
    transform: translateY(-2px);
    color: var(--bbf-text);
    text-decoration: none;
}

.bbf-product-img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: contain;
    background: var(--bbf-cream);
    padding: 6px;
}

.bbf-product-info {
    padding: 7px 8px 9px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.bbf-product-name {
    font-size: 11.5px;
    font-weight: 700;
    line-height: 1.3;
    color: var(--bbf-text);
}

.bbf-product-price {
    font-size: 11px;
    color: var(--bbf-primary-dark);
    font-weight: 800;
}

/* ─── Quick replies ─── */
#bbf-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 14px 10px;
    flex-shrink: 0;
}

.bbf-quick-btn {
    background: white;
    border: 1.5px solid var(--bbf-primary);
    color: var(--bbf-primary-dark);
    border-radius: 20px;
    padding: 5px 12px;
    font-size: 12.5px;
    font-weight: 700;
    cursor: pointer;
    font-family: var(--bbf-font);
    transition: background 0.15s, color 0.15s, transform 0.15s;
    white-space: nowrap;
}

.bbf-quick-btn:hover {
    background: var(--bbf-primary);
    color: white;
    transform: translateY(-1px);
}

/* ─── Input area ─── */
#bbf-chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1.5px solid var(--bbf-border);
    background: white;
    flex-shrink: 0;
}

#bbf-chat-input {
    flex: 1;
    border: 1.5px solid var(--bbf-border);
    border-radius: 12px;
    padding: 9px 12px;
    font-family: var(--bbf-font);
    font-size: 13.5px;
    resize: none;
    outline: none;
    min-height: 38px;
    max-height: 100px;
    line-height: 1.45;
    color: var(--bbf-text);
    transition: border-color 0.18s;
    background: var(--bbf-cream);
}

#bbf-chat-input:focus {
    border-color: var(--bbf-primary);
    background: white;
}

#bbf-chat-input::placeholder {
    color: #bbb;
}

#bbf-chat-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--bbf-primary) 0%, var(--bbf-primary-dark) 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.18s, box-shadow 0.18s;
    box-shadow: 0 3px 14px rgba(120,123,175,0.55);
}
#bbf-chat-send svg {
    display: block;
    flex-shrink: 0;
}

#bbf-chat-send:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 14px rgba(151,155,201,0.5);
}

#bbf-chat-send:active {
    transform: scale(0.95);
}

#bbf-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ─── Footer ─── */
#bbf-chat-footer {
    text-align: center;
    font-size: 10.5px;
    color: var(--bbf-text-muted);
    padding: 6px 12px 8px;
    background: white;
    flex-shrink: 0;
}

/* ─── Login prompt banner ─── */
.bbf-login-banner {
    background: var(--bbf-primary-light);
    border: 1.5px solid rgba(245,166,35,0.3);
    border-radius: 12px;
    padding: 10px 13px;
    font-size: 12.5px;
    color: var(--bbf-text);
    line-height: 1.5;
    max-width: 92%;
    align-self: flex-start;
    margin-left: 36px;
}

.bbf-login-banner a {
    color: var(--bbf-primary-dark);
    font-weight: 700;
    text-decoration: underline;
}

/* ─── Mobile – Bottom Sheet ─── */
@media (max-width: 600px) {

    /* Root: trigger stays bottom-left/right, window fills screen */
    #bbf-chat-root {
        /* Keep trigger in corner */
        position: fixed;
        bottom: 20px;
        left: 16px;
        right: auto;
        z-index: var(--bbf-z);
    }

    /* Trigger button: smaller on mobile */
    #bbf-chat-trigger {
        padding: 11px 16px 11px 13px;
        font-size: 13.5px;
        gap: 7px;
    }

    /* Chat window: full-screen bottom sheet */
    #bbf-chat-window {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: unset !important;
        /* Height: use dvh (dynamic viewport height) so keyboard doesn't overlap */
        top: 0 !important;
        height: 100dvh !important;
        height: 100vh !important;
        max-height: 100dvh !important;
        min-height: unset !important;
        border-radius: 0 !important;
        border: none !important;
        animation: bbf-mobile-in 0.28s cubic-bezier(0.32, 0.72, 0, 1) !important;
    }

    /* When keyboard is open, window shrinks naturally with dvh */
    #bbf-chat-window.bbf-keyboard-open {
        height: 100dvh !important;
        max-height: 100dvh !important;
        top: 0 !important;
        border-radius: 0 !important;
    }

    @keyframes bbf-mobile-in {
        from { transform: translateY(100%); }
        to   { transform: none; }
    }

    /* Hide resize grip and expand button on mobile */
    #bbf-chat-window::after { display: none !important; }
    #bbf-chat-expand { display: none !important; }

    /* Drag handle pill at top of sheet */
    #bbf-chat-header::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 4px;
        border-radius: 2px;
        background: rgba(255,255,255,0.45);
    }

    #bbf-chat-header {
        position: relative;
        padding-top: 20px;
    }

    /* Messages area: bigger on mobile */
    #bbf-chat-messages {
        flex: 1;
        min-height: 0; /* critical for flex scroll */
    }

    /* Input: bigger on mobile */
    #bbf-chat-input {
        font-size: 16px !important;
        min-height: 52px;
        padding: 14px 16px;
        border-radius: 26px;
    }

    /* Input area: extra bottom padding for home bar */
    #bbf-chat-input-area {
        padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
    }

    /* Larger touch target for send button */
    #bbf-chat-send {
        width: 46px !important;
        height: 46px !important;
        flex-shrink: 0;
    }

    /* Quick reply buttons: slightly bigger touch target */
    .bbf-quick-btn {
        padding: 7px 14px;
        font-size: 13px;
    }

    /* Mobile: NO backdrop – window is fullscreen, backdrop would block interaction */
    #bbf-chat-backdrop,
    #bbf-chat-backdrop.visible {
        display: none !important;
        pointer-events: none !important;
        visibility: hidden !important;
    }

    /* Expanded state on mobile = full screen */
    #bbf-chat-window.bbf-expanded {
        top: 0 !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
    }
}
