/* frontend/css/chatbot.css - WhatsApp Floating Widget & AI Chatbot Styles */

:root {
    --wa-primary: #075E54;
    --wa-primary-dark: #054c44;
    --wa-green: #25D366;
    --wa-light-green: #D9FDD3;
    --wa-bg: #EFEAE2;
    --wa-chat-bg: #ECE5DD;
    --wa-text-dark: #111B21;
    --wa-text-muted: #667781;
    --wa-header-text: #FFFFFF;
    --wa-border: #E9EDEF;
    --wa-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}

/* Floating WhatsApp Launcher Button */
.wa-floating-btn-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 12px;
}

.wa-floating-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #25D366 0%, #128C7E 100%);
    color: #FFFFFF;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    box-shadow: 0 8px 24px rgba(37, 211, 102, 0.45);
    cursor: pointer;
    border: none;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
}

.wa-floating-btn:hover {
    transform: scale(1.08) rotate(5deg);
    box-shadow: 0 12px 28px rgba(37, 211, 102, 0.6);
}

.wa-floating-btn:active {
    transform: scale(0.95);
}

.wa-pulse-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background-color: rgba(37, 211, 102, 0.4);
    animation: wa-pulse 2.2s infinite;
    z-index: -1;
}

@keyframes wa-pulse {
    0% { transform: scale(1); opacity: 0.8; }
    70% { transform: scale(1.4); opacity: 0; }
    100% { transform: scale(1.4); opacity: 0; }
}

.wa-badge-unread {
    position: absolute;
    top: -2px;
    right: -2px;
    background-color: #E53E3E;
    color: #FFFFFF;
    font-size: 11px;
    font-weight: 700;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #FFFFFF;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

/* Tooltip Pill beside Floating Button */
.wa-teaser-tooltip {
    background: #FFFFFF;
    color: #111B21;
    padding: 10px 16px;
    border-radius: 24px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    border: 1px solid rgba(0,0,0,0.06);
    transition: all 0.3s ease;
    animation: wa-bounce-subtle 4s ease-in-out infinite;
}

.wa-teaser-tooltip:hover {
    transform: translateX(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
}

.wa-teaser-close {
    color: #8696A0;
    font-size: 12px;
    margin-left: 4px;
    cursor: pointer;
}
.wa-teaser-close:hover { color: #111B21; }

@keyframes wa-bounce-subtle {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

/* WhatsApp Chat Drawer / Modal */
.wa-chat-window {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 390px;
    max-width: calc(100vw - 32px);
    height: 600px;
    max-height: calc(100vh - 120px);
    background-color: #FFFFFF;
    border-radius: 20px;
    box-shadow: var(--wa-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 10000;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    /* Use transform-based transition only to avoid layout flicker */
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    border: 1px solid rgba(0, 0, 0, 0.08);
    /* GPU compositing to eliminate repaint flicker during streaming */
    will-change: transform, opacity;
    contain: layout;
}

.wa-chat-window.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* Header */
.wa-chat-header {
    background: linear-gradient(135deg, #075E54 0%, #128C7E 100%);
    color: var(--wa-header-text);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    position: relative;
    z-index: 10;
}

.wa-avatar-container {
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background-color: #FFFFFF;
    padding: 2px;
    flex-shrink: 0;
}

.wa-avatar-img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.wa-online-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    background-color: #25D366;
    border-radius: 50%;
    border: 2px solid #075E54;
}

.wa-header-info {
    margin-left: 12px;
    flex-grow: 1;
}

.wa-header-title {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.2;
    display: flex;
    align-items: center;
    gap: 6px;
}

.wa-verified-icon {
    color: #4cd964;
    font-size: 12px;
}

.wa-header-status {
    font-size: 11px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 4px;
}

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

.wa-btn-shortcut-human {
    background-color: rgba(255, 255, 255, 0.18);
    color: #FFFFFF;
    border: none;
    border-radius: 14px;
    padding: 5px 10px;
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.wa-btn-shortcut-human:hover {
    background-color: #25D366;
    color: #FFFFFF;
    transform: translateY(-1px);
}

.wa-btn-close {
    background: none;
    border: none;
    color: #FFFFFF;
    font-size: 16px;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 50%;
    opacity: 0.85;
    transition: opacity 0.2s ease;
}
.wa-btn-close:hover { opacity: 1; background-color: rgba(255,255,255,0.15); }

/* Chat Body (WhatsApp Wallpaper look) */
.wa-chat-body {
    flex: 1 1 0;
    min-height: 0; /* Critical: allows flex child to shrink below content size */
    overflow-y: scroll; /* scroll (not auto) avoids layout shifts that cause flicker */
    overscroll-behavior: contain;
    padding: 16px;
    background-color: #EFEAE2;
    background-image: radial-gradient(rgba(0, 0, 0, 0.04) 1px, transparent 1px);
    background-size: 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    /* Smooth scrolling without triggering layout recalcs */
    scroll-behavior: smooth;
    will-change: scroll-position;
}

/* Security notice banner */
.wa-chat-encryption-notice {
    align-self: center;
    background-color: #FFF3C4;
    color: #7A5B00;
    font-size: 11px;
    line-height: 1.4;
    padding: 6px 12px;
    border-radius: 8px;
    max-width: 90%;
    text-align: center;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
    margin-bottom: 4px;
}

/* Bubbles */
.wa-msg {
    display: flex;
    flex-direction: column;
    max-width: 84%;
    margin-bottom: 2px;
    animation: wa-slide-up 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes wa-slide-up {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.wa-msg-bot {
    align-self: flex-start;
}

.wa-msg-user {
    align-self: flex-end;
}

.wa-bubble {
    padding: 9px 13px;
    border-radius: 12px;
    font-size: 13.5px;
    line-height: 1.45;
    position: relative;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    word-break: break-word;
}

.wa-msg-bot .wa-bubble {
    background-color: #FFFFFF;
    color: #111B21;
    border-top-left-radius: 3px;
}

.wa-msg-user .wa-bubble {
    background-color: #D9FDD3;
    color: #111B21;
    border-top-right-radius: 3px;
}

.wa-bubble-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    font-size: 10px;
    color: #667781;
    margin-top: 3px;
    margin-left: 8px;
    float: right;
}

.wa-check-read {
    color: #53BDEB;
    font-size: 11px;
}

/* Typing Indicator */
.wa-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    background: #FFFFFF;
    border-radius: 12px;
    border-top-left-radius: 3px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    width: fit-content;
    margin-bottom: 4px;
}

.wa-dot {
    width: 6px;
    height: 6px;
    background-color: #8696A0;
    border-radius: 50%;
    animation: wa-dot-blink 1.4s infinite ease-in-out both;
}

.wa-dot:nth-child(1) { animation-delay: -0.32s; }
.wa-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes wa-dot-blink {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Predetermined Question Pills (Chips) */
.wa-pills-container {
    flex-shrink: 0;         /* Never get squeezed — always visible */
    min-height: 44px;       /* Reserve constant vertical space */
    background-color: #FFFFFF;
    border-top: 1px solid #E9EDEF;
    padding: 8px 14px;
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    align-items: center;
    gap: 8px;
    scrollbar-width: thin;
    scroll-snap-type: x proximity;
}

.wa-pills-container::-webkit-scrollbar {
    height: 3px;
}
.wa-pills-container::-webkit-scrollbar-thumb {
    background-color: #CCD0D5;
    border-radius: 4px;
}

.wa-pill-btn {
    flex-shrink: 0;
    background-color: #F0F2F5;
    border: 1px solid #D1D7DB;
    color: #111B21;
    font-size: 12px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 18px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.wa-pill-btn:hover {
    background-color: #E7FCE3;
    border-color: #25D366;
    color: #075E54;
    transform: translateY(-1px);
}

.wa-pill-btn i {
    color: #128C7E;
    font-size: 11px;
}

/* Chat Footer & Input */
.wa-chat-footer {
    flex-shrink: 0;   /* Never get squeezed */
    background-color: #F0F2F5;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-top: 1px solid #E9EDEF;
}

.wa-input-box {
    flex-grow: 1;
    background-color: #FFFFFF;
    border: 1px solid #E9EDEF;
    border-radius: 20px;
    padding: 9px 16px;
    font-size: 13.5px;
    outline: none;
    color: #111B21;
    transition: border-color 0.2s ease;
}

.wa-input-box:focus {
    border-color: #25D366;
}

.wa-input-box::placeholder {
    color: #8696A0;
}

.wa-btn-send {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #128C7E;
    color: #FFFFFF;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.wa-btn-send:hover {
    background-color: #075E54;
    transform: scale(1.05);
}

.wa-btn-send:disabled {
    background-color: #CCD0D5;
    cursor: not-allowed;
    transform: none;
}

/* Call to action inside bot bubble */
.wa-bubble-cta {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.wa-cta-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background-color: #25D366;
    color: #FFFFFF !important;
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
    padding: 7px 12px;
    border-radius: 8px;
    cursor: pointer;
    user-select: none;
    transition: all 0.2s ease;
}

.wa-cta-btn:hover {
    background-color: #128C7E;
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.wa-cta-btn:active {
    transform: translateY(0);
}

.wa-cta-btn.secondary {
    background-color: #1A3A5F;
}
.wa-cta-btn.secondary:hover {
    background-color: #0A2338;
}

/* Mobile full-screen or compact responsiveness */
@media (max-width: 480px) {
    .wa-chat-window {
        bottom: 0;
        right: 0;
        width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        max-width: 100vw;
        border-radius: 0;
    }
    .wa-floating-btn-container {
        bottom: 18px;
        right: 18px;
    }
}
