/* ==========================================================
   Floating customer-care chatbot (chatbot.js)
========================================================== */

/* The chat launcher takes the bottom-right corner; scroll-to-top sits above it
   (centred on the 60px launcher). WhatsApp has the bottom-left corner. */
.scroll-to-top { right: 31px; bottom: 96px; }

.cb-root {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 1100;
    font-family: 'Montserrat', system-ui, sans-serif;
}

/* Launcher */
.cb-launcher {
    position: relative;
    display: grid;
    place-items: center;
    width: 60px;
    height: 60px;
    border: none;
    border-radius: 50%;
    background: var(--brand-900, #064e3b);
    color: #fff;
    font-size: 1.45rem;
    cursor: pointer;
    box-shadow: 0 10px 28px rgba(6, 78, 59, 0.35);
    transition: transform 0.25s ease, background 0.25s ease;
}

.cb-launcher:hover { transform: translateY(-2px); background: var(--brand-700, #047857); }

.cb-launcher .cb-ico-close { display: none; font-size: 1.25rem; }
.cb-root.is-open .cb-ico-open { display: none; }
.cb-root.is-open .cb-ico-close { display: inline-block; }

.cb-online {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 12px;
    height: 12px;
    border: 2px solid #fff;
    border-radius: 50%;
    background: #22c55e;
}

.cb-root.is-open .cb-online { display: none; }

/* Over green sections the launcher turns gold so it stays visible */
.cb-root.on-green .cb-launcher {
    background: #fbbf24;
    color: var(--brand-900, #064e3b);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.3);
}
.cb-root.on-green .cb-launcher:hover { background: #f59e0b; }

/* Teaser bubble */
.cb-teaser {
    position: absolute;
    right: 0;
    bottom: 74px;
    width: 240px;
    padding: 14px 30px 14px 16px;
    border-radius: 14px 14px 4px 14px;
    background: #fff;
    color: var(--text-medium, #4b5563);
    font-size: 0.84rem;
    line-height: 1.5;
    box-shadow: 0 12px 30px rgba(16, 24, 40, 0.16);
    cursor: pointer;
    animation: cbPop 0.35s ease;
}

.cb-teaser[hidden] { display: none; }

.cb-teaser strong { color: var(--text-dark, #111827); }

.cb-teaser-close {
    position: absolute;
    top: 6px;
    right: 8px;
    border: none;
    background: none;
    color: var(--text-light, #6b7280);
    font-size: 1rem;
    cursor: pointer;
}

/* Panel */
.cb-panel {
    position: absolute;
    right: 0;
    bottom: 76px;
    display: flex;
    flex-direction: column;
    width: 380px;
    height: min(600px, calc(100vh - 140px));
    height: min(600px, calc(100dvh - 140px));
    overflow: hidden;
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 24px 60px rgba(16, 24, 40, 0.22);
    animation: cbPop 0.25s ease;
}

.cb-panel[hidden] { display: none; }

@keyframes cbPop {
    from { opacity: 0; transform: translateY(10px) scale(0.98); }
    to   { opacity: 1; transform: none; }
}

.cb-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 12px 14px 16px;
    background: var(--brand-900, #064e3b);
    color: #fff;
}

.cb-avatar {
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
    color: var(--brand-mint, #86efac);
}

.cb-title {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}

.cb-title strong { font-size: 0.95rem; }

.cb-title small {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.75);
}

.cb-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #22c55e;
}

.cb-icon-btn {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: rgba(255, 255, 255, 0.85);
    cursor: pointer;
}

.cb-icon-btn:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }

/* Messages */
.cb-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--bg-light, #f6f8f7);
    overscroll-behavior: contain;
}

.cb-msg { display: flex; margin-bottom: 10px; }
.cb-user { justify-content: flex-end; }

.cb-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.88rem;
    line-height: 1.55;
    overflow-wrap: anywhere;
}

.cb-bot .cb-bubble {
    border-bottom-left-radius: 4px;
    background: #fff;
    color: var(--text-dark, #111827);
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
}

.cb-user .cb-bubble {
    border-bottom-right-radius: 4px;
    background: var(--brand-900, #064e3b);
    color: #fff;
    white-space: pre-wrap;
}

.cb-bubble p { margin: 0 0 8px; }
.cb-bubble p:last-child { margin-bottom: 0; }

.cb-bubble ul {
    margin: 0 0 8px;
    padding-left: 18px;
    list-style: disc;
}

.cb-bubble ul:last-child { margin-bottom: 0; }
.cb-bubble li { margin: 2px 0; }

.cb-bubble a {
    font-weight: 700;
    color: var(--brand-700, #047857);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.cb-bubble strong { font-weight: 700; }

/* Quick replies */
.cb-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 4px 0 10px;
}

.cb-chip {
    padding: 7px 12px;
    border: 1px solid var(--brand-mint, #86efac);
    border-radius: 999px;
    background: #fff;
    color: var(--brand-900, #064e3b);
    font: inherit;
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.cb-chip:hover { background: var(--brand-900, #064e3b); color: #fff; }

/* Typing indicator */
.cb-typing .cb-bubble {
    display: inline-flex;
    gap: 4px;
    padding: 14px;
}

.cb-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--gray-300, #d1d5db);
    animation: cbBounce 1.2s infinite ease-in-out;
}

.cb-typing span:nth-child(2) { animation-delay: 0.15s; }
.cb-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes cbBounce {
    0%, 80%, 100% { transform: translateY(0); background: var(--gray-300, #d1d5db); }
    40% { transform: translateY(-5px); background: var(--brand-700, #047857); }
}

/* Composer */
.cb-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--gray-200, #e5e7eb);
    background: #fff;
}

.cb-input {
    flex: 1;
    min-height: 42px;
    max-height: 110px;
    padding: 10px 14px;
    border: 1px solid var(--gray-200, #e5e7eb);
    border-radius: 21px;
    background: var(--gray-50, #f9fafb);
    font: inherit;
    font-size: 16px;            /* avoids iOS zoom */
    line-height: 1.4;
    color: var(--text-dark, #111827);
    resize: none;
}

.cb-input:focus {
    outline: none;
    border-color: var(--brand-700, #047857);
    background: #fff;
}

.cb-send {
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 50%;
    background: var(--primary-color, #0d9488);
    color: #fff;
    cursor: pointer;
}

.cb-send:hover { background: var(--primary-dark, #0f766e); }
.cb-send:disabled { opacity: 0.55; cursor: wait; }

.cb-foot {
    margin: 0;
    padding: 0 12px 10px;
    background: #fff;
    text-align: center;
    font-size: 0.68rem;
    color: var(--text-light, #6b7280);
}

.cb-foot a { color: inherit; font-weight: 600; }

/* Pharmacy mobile cart bar: keep the floating buttons clear of it */
@media (max-width: 767px) {
    .cb-root { right: 16px; bottom: 16px; }
    .scroll-to-top { right: 22px; bottom: 84px; }
    body:has(.ph-cartbar:not([hidden])) .cb-root,
    body:has(.ph-cartbar:not([hidden])) .floating-whatsapp { bottom: 84px; }
    body:has(.ph-cartbar:not([hidden])) .scroll-to-top { bottom: 152px; }
    .cb-launcher { width: 54px; height: 54px; font-size: 1.3rem; }
    .cb-teaser { bottom: 66px; }
}

/* Phones: the panel becomes a full-screen sheet */
@media (max-width: 575px) {
    .cb-root.is-open { inset: 0; }
    .cb-root.is-open .cb-launcher { display: none; }
    .cb-panel {
        position: fixed;
        inset: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        padding-bottom: env(safe-area-inset-bottom);
    }
    .cb-teaser { width: 210px; }
}

/* While the chat is open, tuck the other floating buttons away */
body:has(.cb-root.is-open) .floating-whatsapp,
body:has(.cb-root.is-open) .scroll-to-top {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
