/**
 * Wonder Balloons AI Chatbot - Frontend Stylesheet
 *
 * Viewport-constrained, fully responsive, non-colliding layout.
 * Accurately fits desktop (420px width, max 600px / 100dvh - 32px height)
 * and mobile viewports (bottom-sheet, safe-area aware, zero horizontal scroll).
 *
 * @package WonderBalloonsAIChatbot
 */

:root {
    --wb-primary: #e05344;
    --wb-primary-dark: #b82f22;
    --wb-primary-light: #fff1f0;
    --wb-accent: #f59e0b;
    --wb-wa-green: #25D366;
    --wb-wa-hover: #1ebd5b;
    --wb-ink: #0f172a;
    --wb-ink-soft: #475569;
    --wb-ink-faint: #94a3b8;
    --wb-bg: #ffffff;
    --wb-surface: #f8fafc;
    --wb-line: #e2e8f0;
    --wb-shadow: 0 16px 48px -8px rgba(15, 23, 42, 0.28), 0 0 1px rgba(15, 23, 42, 0.12);
    --wb-radius-lg: 20px;
    --wb-radius-md: 14px;
    --wb-radius-sm: 8px;
    --wb-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ========================================================
   GLOBAL BOX SIZING & WRAPPER
   ======================================================== */
.wb-chatbot-wrapper {
    font-family: var(--wb-font);
    box-sizing: border-box;
}

.wb-chatbot-wrapper *,
.wb-chatbot-wrapper *::before,
.wb-chatbot-wrapper *::after {
    box-sizing: border-box;
}

/* ========================================================
   FLOATING LAUNCHER BUTTON
   Positioned safely above WhatsApp FAB (.wa-fab at bottom: 30px)
   ======================================================== */
.wb-launcher {
    position: fixed;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--wb-primary), var(--wb-primary-dark));
    border: none;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(224, 83, 68, 0.38), 0 2px 6px rgba(0, 0, 0, 0.1);
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease, opacity 0.2s ease, visibility 0.2s ease;
    padding: 0;
    outline: none;
    box-sizing: border-box;
}

/* Default Right position: Stacks 66px above WhatsApp button */
.wb-chatbot-wrapper.wb-pos-right .wb-launcher {
    bottom: 96px;
    right: 24px;
}

/* Alternative Left position */
.wb-chatbot-wrapper.wb-pos-left .wb-launcher {
    bottom: 24px;
    left: 24px;
}

.wb-launcher:hover {
    transform: scale(1.08) translateY(-3px);
    box-shadow: 0 14px 32px rgba(224, 83, 68, 0.48), 0 4px 10px rgba(0, 0, 0, 0.15);
}

.wb-launcher-avatar {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.25s ease, opacity 0.25s ease;
}

.wb-launcher-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
}

.wb-launcher-close-icon {
    position: absolute;
    font-size: 28px;
    line-height: 1;
    color: #ffffff;
    font-weight: 300;
    opacity: 0;
    transform: rotate(-90deg) scale(0.6);
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease;
}

/* When open on desktop: Launcher fades slightly or hides so window takes focus */
.wb-chatbot-wrapper.wb-open .wb-launcher {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8);
    visibility: hidden;
}

/* Pulsing outer ring to invite interaction */
.wb-launcher-pulse {
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid var(--wb-primary);
    opacity: 0;
    animation: wb-pulse 3s infinite;
    pointer-events: none;
}

.wb-chatbot-wrapper.wb-open .wb-launcher-pulse {
    display: none;
}

@keyframes wb-pulse {
    0% { transform: scale(0.95); opacity: 0.8; }
    50% { transform: scale(1.18); opacity: 0; }
    100% { transform: scale(1.18); opacity: 0; }
}

/* Floating Teaser Speech Bubble */
.wb-launcher-bubble {
    position: absolute;
    right: 74px;
    white-space: nowrap;
    background: #ffffff;
    color: var(--wb-ink);
    padding: 10px 16px;
    border-radius: 14px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14), 0 2px 6px rgba(15, 23, 42, 0.06);
    border: 1px solid var(--wb-line);
    display: flex;
    flex-direction: column;
    gap: 2px;
    pointer-events: none;
    opacity: 0;
    transform: translateX(10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    box-sizing: border-box;
}

.wb-launcher-bubble strong {
    font-size: 13px;
    font-weight: 700;
    color: var(--wb-ink);
}

.wb-launcher-bubble small {
    font-size: 11px;
    color: var(--wb-ink-soft);
}

.wb-launcher-bubble::after {
    content: '';
    position: absolute;
    right: -6px;
    top: 50%;
    transform: translateY(-50%) rotate(45deg);
    width: 12px;
    height: 12px;
    background: #ffffff;
    border-top: 1px solid var(--wb-line);
    border-right: 1px solid var(--wb-line);
}

.wb-chatbot-wrapper:not(.wb-open) .wb-launcher:hover .wb-launcher-bubble,
.wb-chatbot-wrapper:not(.wb-open).wb-bubble-show .wb-launcher-bubble {
    opacity: 1;
    transform: translateX(0);
}

.wb-chatbot-wrapper.wb-pos-left .wb-launcher-bubble {
    right: auto;
    left: 74px;
    transform: translateX(-10px);
}

.wb-chatbot-wrapper.wb-pos-left .wb-launcher-bubble::after {
    right: auto;
    left: -6px;
    border-top: none;
    border-right: none;
    border-bottom: 1px solid var(--wb-line);
    border-left: 1px solid var(--wb-line);
}

.wb-chatbot-wrapper.wb-pos-left:not(.wb-open) .wb-launcher:hover .wb-launcher-bubble,
.wb-chatbot-wrapper.wb-pos-left:not(.wb-open).wb-bubble-show .wb-launcher-bubble {
    transform: translateX(0);
}

/* ========================================================
   CHATBOT WINDOW MODAL — DESKTOP VIEWPORT CONSTRAINED
   Fixed coordinates: 20px from bottom & right.
   Never exceeds viewport height or width.
   ======================================================== */
.wb-window {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 420px;
    max-width: calc(100vw - 32px);
    height: 600px;
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
    background: var(--wb-bg);
    border-radius: var(--wb-radius-lg);
    box-shadow: var(--wb-shadow);
    border: 1px solid var(--wb-line);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-sizing: border-box;
    opacity: 0;
    pointer-events: none;
    transform: translateY(16px) scale(0.97);
    transform-origin: bottom right;
    transition: opacity 0.28s cubic-bezier(0.16, 1, 0.3, 1), transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 100000;
}

.wb-chatbot-wrapper.wb-pos-left .wb-window {
    right: auto;
    left: 20px;
    transform-origin: bottom left;
}

.wb-chatbot-wrapper.wb-open .wb-window {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

/* ========================================================
   HEADER (Fixed height, never shrinks)
   ======================================================== */
.wb-header {
    flex: 0 0 auto;
    background: linear-gradient(135deg, #ffffff 0%, var(--wb-surface) 100%);
    padding: 14px 18px;
    border-bottom: 1px solid var(--wb-line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    box-sizing: border-box;
}

.wb-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.wb-header-avatar {
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--wb-primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(224, 83, 68, 0.15);
}

.wb-header-avatar img {
    width: 28px;
    height: 28px;
    object-fit: contain;
}

.wb-avatar-status {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 9px;
    height: 9px;
    background: #10b981;
    border: 2px solid #ffffff;
    border-radius: 50%;
}

.wb-header-titles {
    min-width: 0;
}

.wb-header-titles h3 {
    margin: 0;
    font-size: 14.5px;
    font-weight: 700;
    color: var(--wb-ink);
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wb-header-titles p {
    margin: 2px 0 0;
    font-size: 11px;
    color: #10b981;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wb-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.wb-header-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 1px solid var(--wb-line);
    background: #ffffff;
    color: var(--wb-ink-soft);
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s ease;
    text-decoration: none;
    box-sizing: border-box;
}

.wb-header-btn:hover {
    background: var(--wb-surface);
    color: var(--wb-ink);
    border-color: #cbd5e1;
}

.wb-header-wa-btn {
    background: #e8faf1;
    border-color: #a7f3d0;
    color: #059669;
}

.wb-header-wa-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.wb-header-wa-btn:hover {
    background: #059669;
    color: #ffffff;
    border-color: #059669;
}

/* ========================================================
   CHAT BODY & MESSAGES
   Independently scrollable area; min-height: 0 is essential.
   ======================================================== */
.wb-body {
    flex: 1 1 0px;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #fafafa;
    scroll-behavior: smooth;
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch;
}

.wb-message-row {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    max-width: 90%;
    animation: wb-fade-in 0.22s ease-out;
    box-sizing: border-box;
}

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

.wb-message-row.wb-msg-bot {
    align-self: flex-start;
}

.wb-message-row.wb-msg-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.wb-msg-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--wb-primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.wb-msg-avatar img {
    width: 18px;
    height: 18px;
}

.wb-msg-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.5;
    word-break: break-word;
    overflow-wrap: break-word;
    position: relative;
    box-sizing: border-box;
    max-width: 100%;
}

.wb-msg-bot .wb-msg-bubble {
    background: #ffffff;
    color: var(--wb-ink);
    border: 1px solid var(--wb-line);
    border-top-left-radius: 4px;
    box-shadow: 0 2px 4px rgba(15, 23, 42, 0.03);
}

.wb-msg-user .wb-msg-bubble {
    background: linear-gradient(135deg, var(--wb-primary), var(--wb-primary-dark));
    color: #ffffff;
    border-top-right-radius: 4px;
    box-shadow: 0 3px 10px rgba(224, 83, 68, 0.25);
}

.wb-msg-content {
    word-break: break-word;
    overflow-wrap: break-word;
}

.wb-msg-bubble p {
    margin: 0 0 6px 0;
}

.wb-msg-bubble p:last-child {
    margin-bottom: 0;
}

.wb-msg-bubble strong {
    font-weight: 700;
}

.wb-msg-bubble ul, .wb-msg-bubble ol {
    margin: 4px 0 6px 16px;
    padding: 0;
}

.wb-msg-bubble li {
    margin-bottom: 3px;
}

.wb-msg-bubble a {
    color: var(--wb-primary);
    text-decoration: underline;
    font-weight: 600;
    word-break: break-word;
}

.wb-msg-user .wb-msg-bubble a {
    color: #ffffff;
}

.wb-msg-bot .wb-msg-bubble a:hover {
    color: var(--wb-primary-dark);
}

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

/* Typing Indicator Animation */
.wb-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: #ffffff;
    border: 1px solid var(--wb-line);
    border-radius: 16px;
    border-top-left-radius: 4px;
    width: fit-content;
}

.wb-typing-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--wb-primary);
    animation: wb-bounce 1.4s infinite ease-in-out both;
}

.wb-typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.wb-typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes wb-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1.1); opacity: 1; }
}

/* ========================================================
   QUICK REPLY CHIPS (Fixed height, horizontally scrollable)
   Never pushes the input offscreen.
   ======================================================== */
.wb-quick-replies {
    flex: 0 0 auto;
    padding: 6px 12px 8px;
    background: #ffffff;
    border-top: 1px solid var(--wb-line);
    display: flex;
    gap: 6px;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
    box-sizing: border-box;
    max-height: 48px;
    -webkit-overflow-scrolling: touch;
}

.wb-quick-replies::-webkit-scrollbar {
    display: none;
}

.wb-chip {
    display: inline-flex;
    align-items: center;
    padding: 5px 11px;
    background: var(--wb-surface);
    border: 1px solid var(--wb-line);
    border-radius: 18px;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--wb-ink-soft);
    cursor: pointer;
    transition: all 0.18s ease;
    user-select: none;
    flex-shrink: 0;
    line-height: 1.2;
}

.wb-chip:hover {
    background: var(--wb-primary-light);
    border-color: #fca5a5;
    color: var(--wb-primary);
    transform: translateY(-1px);
}

/* ========================================================
   INTERACTIVE QUOTE MODAL (Inside Chatbot)
   ======================================================== */
.wb-quote-modal {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(4px);
    z-index: 20;
    display: flex;
    align-items: flex-end;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
    box-sizing: border-box;
}

.wb-quote-modal.wb-modal-open {
    opacity: 1;
    pointer-events: auto;
}

.wb-quote-modal-inner {
    width: 100%;
    max-height: 85%;
    overflow-y: auto;
    background: #ffffff;
    border-radius: 18px 18px 0 0;
    padding: 16px 18px;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.15);
    transform: translateY(100%);
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    box-sizing: border-box;
}

.wb-quote-modal.wb-modal-open .wb-quote-modal-inner {
    transform: translateY(0);
}

.wb-quote-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2px;
}

.wb-quote-modal-header h4 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    color: var(--wb-ink);
}

.wb-quote-close {
    background: transparent;
    border: none;
    font-size: 20px;
    line-height: 1;
    color: var(--wb-ink-faint);
    cursor: pointer;
    padding: 2px;
}

.wb-quote-desc {
    margin: 0 0 10px;
    font-size: 11.5px;
    color: var(--wb-ink-soft);
}

.wb-form-group {
    margin-bottom: 10px;
}

.wb-form-group label {
    display: block;
    font-size: 10.5px;
    font-weight: 600;
    color: var(--wb-ink);
    margin-bottom: 3px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.wb-form-group input,
.wb-form-group select,
.wb-form-group textarea {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--wb-line);
    border-radius: var(--wb-radius-sm);
    font-size: 12.5px;
    color: var(--wb-ink);
    background: var(--wb-surface);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
    box-sizing: border-box;
}

.wb-form-group input:focus,
.wb-form-group select:focus,
.wb-form-group textarea:focus {
    border-color: var(--wb-primary);
    background: #ffffff;
    box-shadow: 0 0 0 2px rgba(224, 83, 68, 0.12);
}

.wb-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.wb-btn-submit {
    width: 100%;
    padding: 10px;
    background: linear-gradient(135deg, var(--wb-primary), var(--wb-primary-dark));
    color: #ffffff;
    border: none;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(224, 83, 68, 0.25);
    transition: transform 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}

.wb-btn-submit:hover {
    transform: translateY(-1px);
    box-shadow: 0 5px 14px rgba(224, 83, 68, 0.35);
}

/* ========================================================
   FOOTER INPUT BAR (Fixed height, always visible)
   ======================================================== */
.wb-footer {
    flex: 0 0 auto;
    padding: 10px 14px 10px;
    background: #ffffff;
    border-top: 1px solid var(--wb-line);
    box-sizing: border-box;
}

.wb-chat-input-box {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--wb-surface);
    border: 1px solid var(--wb-line);
    border-radius: 22px;
    padding: 3px 5px 3px 12px;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}

.wb-chat-input-box:focus-within {
    border-color: var(--wb-primary);
    background: #ffffff;
    box-shadow: 0 0 0 2px rgba(224, 83, 68, 0.1);
}

.wb-chat-input-box textarea {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 13px;
    color: var(--wb-ink);
    outline: none;
    resize: none;
    padding: 6px 0;
    line-height: 1.35;
    min-height: 36px;
    max-height: 72px;
    font-family: inherit;
    box-sizing: border-box;
}

.wb-chat-input-box textarea::placeholder {
    color: var(--wb-ink-faint);
}

.wb-action-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    flex-shrink: 0;
}

.wb-action-btn:hover {
    background: var(--wb-line);
}

.wb-send-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--wb-primary);
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, background 0.2s;
    flex-shrink: 0;
}

.wb-send-btn svg {
    width: 15px;
    height: 15px;
    fill: currentColor;
    margin-left: 2px;
}

.wb-send-btn:hover {
    background: var(--wb-primary-dark);
    transform: scale(1.05);
}

.wb-footer-brand {
    text-align: center;
    margin-top: 5px;
    font-size: 9.5px;
    color: var(--wb-ink-faint);
}

/* ========================================================
   INLINE SHORTCODE BOX
   ======================================================== */
.wb-inline-chatbot-box {
    background: var(--wb-surface);
    border: 1px solid var(--wb-line);
    border-radius: var(--wb-radius-md);
    padding: 20px;
    text-align: center;
    margin: 20px 0;
    box-sizing: border-box;
}

.wb-inline-chatbot-box p {
    font-size: 14px;
    margin-bottom: 14px;
    color: var(--wb-ink);
}

/* ========================================================
   MOBILE RESPONSIVENESS (<= 600px)
   Bottom-sheet modal; accounts for safe areas and keyboards.
   Prevents background page scroll without overflow issues.
   ======================================================== */
@media (max-width: 600px) {
    /* Launcher positioning on mobile: 90px from bottom (stacks above WhatsApp button) */
    .wb-chatbot-wrapper.wb-pos-right .wb-launcher {
        bottom: 90px;
        right: 18px;
        width: 54px;
        height: 54px;
    }

    .wb-chatbot-wrapper.wb-pos-left .wb-launcher {
        bottom: 20px;
        left: 18px;
        width: 54px;
        height: 54px;
    }

    .wb-launcher-avatar {
        width: 30px;
        height: 30px;
    }

    .wb-launcher-bubble {
        display: none !important;
    }

    /* Full bottom-sheet on mobile */
    .wb-window {
        position: fixed;
        inset: auto 0 0 0;
        width: 100%;
        max-width: 100vw;
        height: 90vh;
        height: 90dvh;
        max-height: calc(100vh - 16px);
        max-height: calc(100dvh - 16px);
        border-radius: 20px 20px 0 0;
        bottom: 0;
        right: 0;
        left: 0;
        box-shadow: 0 -8px 32px rgba(15, 23, 42, 0.25);
        border-bottom: none;
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease;
        z-index: 100000;
    }

    .wb-chatbot-wrapper.wb-open .wb-window {
        transform: translateY(0);
    }

    .wb-header {
        padding: 12px 14px;
        border-radius: 20px 20px 0 0;
    }

    .wb-body {
        padding: 14px 12px;
    }

    .wb-footer {
        padding: 8px 12px max(8px, env(safe-area-inset-bottom, 8px));
    }

    /* Prevent background page scroll on mobile when chat is open */
    body.wb-chat-active {
        overflow: hidden !important;
        position: fixed;
        width: 100%;
        height: 100%;
    }
}

/* Extra small devices (320px - 360px) */
@media (max-width: 360px) {
    .wb-header-titles h3 {
        font-size: 13px;
    }
    .wb-header-titles p {
        font-size: 10px;
    }
    .wb-header-avatar {
        width: 34px;
        height: 34px;
    }
    .wb-msg-bubble {
        font-size: 12.5px;
    }
}
