/**
 * ConvertyBot Proactive Engagement Styles
 * Teaser bubble, exit overlay, badge, pulse, online indicator
 */

/* =====================================================================
   Proactive Notification Card — modern chat preview above the button
   ===================================================================== */
#convertybot-teaser-bubble {
    position: fixed;
    bottom: 90px;
    right: 20px;
    z-index: 999998;
    max-width: 320px;
    width: calc(100vw - 40px);
    background: #fff;
    color: #1d2327;
    border-radius: 16px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.06);
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.92);
    transition: opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.4s cubic-bezier(0.16, 1, 0.3, 1),
                visibility 0.4s;
    pointer-events: none;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    overflow: hidden;
}

#convertybot-teaser-bubble.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

#convertybot-teaser-bubble:hover {
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.16), 0 4px 12px rgba(0, 0, 0, 0.08);
}

/* Focus outline for keyboard accessibility */
#convertybot-teaser-bubble:focus-within {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* --- Avatar --- */
.teaser-bubble-avatar {
    position: relative;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--convertybot-gradient, linear-gradient(135deg, #040404, #2a2a2a));
    display: flex;
    align-items: center;
    justify-content: center;
}

.teaser-bubble-avatar svg {
    display: block;
}

.teaser-online-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #22c55e;
    border: 2px solid #fff;
}

/* --- Card body layout: avatar + text --- */
#convertybot-teaser-bubble > .teaser-bubble-avatar,
#convertybot-teaser-bubble > .teaser-bubble-body {
    /* Handled by the flex container below */
}

/* Flex wrapper for avatar + body (top section of card) */
#convertybot-teaser-bubble {
    display: flex;
    flex-direction: column;
}

/* Top section: avatar + message */
.teaser-bubble-avatar {
    margin: 16px 16px 0 16px;
}

.teaser-bubble-body {
    padding: 0 16px 0 16px;
    flex: 1;
    min-width: 0;
}

/* Use a row layout for avatar + body */
#convertybot-teaser-bubble {
    display: block; /* Reset — we'll use inner layout */
}

/* Inner layout via padding and positioning */
.teaser-bubble-avatar {
    position: absolute;
    top: 16px;
    left: 16px;
    margin: 0;
}

.teaser-bubble-body {
    padding: 16px 36px 14px 68px; /* left = avatar(40) + gap(12) + padding(16) */
    min-height: 40px;
}

/* --- Bot name --- */
.teaser-bubble-name {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: #1d2327;
    margin-bottom: 2px;
    letter-spacing: -0.01em;
}

/* --- Message text --- */
.teaser-bubble-text {
    font-size: 14px;
    line-height: 1.65;
    color: #475569;
    margin: 4px 0 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* --- Reply CTA bar --- */
.teaser-bubble-reply {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
    font-size: 13px;
    font-weight: 600;
    color: var(--convertybot-primary, #2563eb);
    transition: background 0.2s, color 0.2s;
}

.teaser-bubble-reply svg {
    transition: transform 0.2s;
}

#convertybot-teaser-bubble:hover .teaser-bubble-reply {
    background: #f1f5f9;
}

#convertybot-teaser-bubble:hover .teaser-bubble-reply svg {
    transform: translateX(3px);
}

/* --- Close button --- */
.convertybot-teaser-close {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    min-width: 36px;
    min-height: 36px;
    border: none;
    background: transparent;
    color: #94a3b8;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s, color 0.2s;
    box-sizing: border-box;
    z-index: 2;
}

.convertybot-teaser-close:hover,
.convertybot-teaser-close:focus {
    background: #f1f5f9;
    color: #475569;
    outline: none;
}

.convertybot-teaser-close:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 1px;
}

/* =====================================================================
   Notification Badge
   ===================================================================== */
.convertybot-badge {
    display: none;
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    border-radius: 10px;
    background: #dc2626;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    padding: 0 5px;
    z-index: 2;
    box-shadow: 0 2px 6px rgba(220, 38, 38, 0.4);
}

.convertybot-badge.active {
    display: block;
    animation: convertybot-badge-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes convertybot-badge-pop {
    0% { transform: scale(0); }
    70% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* =====================================================================
   Chat Button Pulse Animation (Observer Level)
   ===================================================================== */
.convertybot-chat-button.has-pulse {
    animation: convertybot-pulse-glow 2.5s ease-in-out infinite;
}

@keyframes convertybot-pulse-glow {
    0%, 100% {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
    50% {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15),
                    0 0 0 8px rgba(var(--convertybot-primary-rgb, 4, 4, 4), 0.12);
    }
}

/* =====================================================================
   Online Indicator (green dot)
   ===================================================================== */
.convertybot-online-indicator {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #22c55e;
    border: 2px solid #fff;
    z-index: 2;
    animation: convertybot-online-pulse 2s ease-in-out infinite;
}

@keyframes convertybot-online-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* =====================================================================
   Hover Tooltip (Observer)
   ===================================================================== */
.convertybot-hover-tooltip {
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: 8px;
    background: #1e293b;
    color: #fff;
    font-size: 12px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 8px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transform: translateY(4px);
    transition: all 0.2s ease;
    pointer-events: none;
}

.convertybot-hover-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    right: 16px;
    border: 5px solid transparent;
    border-top-color: #1e293b;
}

.convertybot-chat-button:hover .convertybot-hover-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* =====================================================================
   Exit Intent Overlay
   FIXED: z-index bumped to 10000000 to stay above widget (999999)
   FIXED: added top/left/right/bottom fallback for browsers without inset
   ===================================================================== */
#convertybot-exit-overlay {
    position: fixed;
    /* Fallback for browsers that don't support inset */
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000000;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.35s ease, visibility 0.35s;
}

#convertybot-exit-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.exit-overlay-card {
    background: #fff;
    color: #1d2327;
    border-radius: 20px;
    padding: 36px 32px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    transform: scale(0.9) translateY(20px);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#convertybot-exit-overlay.visible .exit-overlay-card {
    transform: scale(1) translateY(0);
}

.exit-overlay-icon {
    font-size: 40px;
    margin-bottom: 12px;
    line-height: 1;
}

.exit-overlay-title {
    font-size: 20px;
    font-weight: 700;
    color: #1d2327;
    margin: 0 0 8px;
    line-height: 1.3;
}

.exit-overlay-text {
    font-size: 15px;
    color: #64748b;
    margin: 0 0 24px;
    line-height: 1.55;
}

.exit-overlay-chat-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--convertybot-gradient, linear-gradient(135deg, #040404, #2a2a2a));
    color: #fff;
    border: none;
    padding: 12px 28px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.exit-overlay-chat-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.exit-overlay-chat-btn:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

.exit-overlay-chat-btn svg {
    width: 18px;
    height: 18px;
}

.exit-overlay-close {
    display: block;
    margin: 16px auto 0;
    background: none;
    border: none;
    color: #64748b;
    font-size: 13px;
    cursor: pointer;
    padding: 8px 16px;
    min-height: 44px;
    transition: color 0.2s;
}

.exit-overlay-close:hover {
    color: #334155;
}

.exit-overlay-close:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* =====================================================================
   Dark mode support — inherit from widget theme if set
   Complete coverage: teaser, overlay, close buttons, text colors
   ===================================================================== */
@media (prefers-color-scheme: dark) {
    .convertybot-widget[data-theme="auto"] #convertybot-teaser-bubble,
    .convertybot-widget[data-theme="dark"] #convertybot-teaser-bubble {
        background: #1e293b;
        color: #e2e8f0;
    }

    .convertybot-widget[data-theme="auto"] .teaser-bubble-name,
    .convertybot-widget[data-theme="dark"] .teaser-bubble-name {
        color: #f1f5f9;
    }

    .convertybot-widget[data-theme="auto"] .teaser-bubble-text,
    .convertybot-widget[data-theme="dark"] .teaser-bubble-text {
        color: #94a3b8;
    }

    .convertybot-widget[data-theme="auto"] .teaser-bubble-reply,
    .convertybot-widget[data-theme="dark"] .teaser-bubble-reply {
        background: #0f172a;
        border-top-color: #334155;
    }

    .convertybot-widget[data-theme="auto"] .teaser-online-dot,
    .convertybot-widget[data-theme="dark"] .teaser-online-dot {
        border-color: #1e293b;
    }

    .convertybot-widget[data-theme="auto"] .convertybot-teaser-close,
    .convertybot-widget[data-theme="dark"] .convertybot-teaser-close {
        color: #64748b;
    }

    .convertybot-widget[data-theme="auto"] .convertybot-teaser-close:hover,
    .convertybot-widget[data-theme="dark"] .convertybot-teaser-close:hover {
        background: #334155;
        color: #cbd5e1;
    }

    .convertybot-widget[data-theme="auto"] .exit-overlay-card,
    .convertybot-widget[data-theme="dark"] .exit-overlay-card {
        background: #1e293b;
        color: #e2e8f0;
    }

    .convertybot-widget[data-theme="auto"] .exit-overlay-title,
    .convertybot-widget[data-theme="dark"] .exit-overlay-title {
        color: #f1f5f9;
    }

    .convertybot-widget[data-theme="auto"] .exit-overlay-text,
    .convertybot-widget[data-theme="dark"] .exit-overlay-text {
        color: #94a3b8;
    }

    .convertybot-widget[data-theme="auto"] .exit-overlay-close,
    .convertybot-widget[data-theme="dark"] .exit-overlay-close {
        color: #94a3b8;
    }

    .convertybot-widget[data-theme="auto"] .exit-overlay-close:hover,
    .convertybot-widget[data-theme="dark"] .exit-overlay-close:hover {
        color: #cbd5e1;
    }

    .convertybot-widget[data-theme="auto"] .convertybot-online-indicator,
    .convertybot-widget[data-theme="dark"] .convertybot-online-indicator {
        border-color: #1e293b;
    }
}

/* Also support explicit dark theme data attribute (non-media-query) */
.convertybot-widget[data-theme="dark"] #convertybot-teaser-bubble {
    background: #1e293b;
    color: #e2e8f0;
}

.convertybot-widget[data-theme="dark"] .teaser-bubble-name {
    color: #f1f5f9;
}

.convertybot-widget[data-theme="dark"] .teaser-bubble-text {
    color: #94a3b8;
}

.convertybot-widget[data-theme="dark"] .teaser-bubble-reply {
    background: #0f172a;
    border-top-color: #334155;
}

.convertybot-widget[data-theme="dark"] .teaser-online-dot {
    border-color: #1e293b;
}

.convertybot-widget[data-theme="dark"] .convertybot-teaser-close {
    color: #64748b;
}

.convertybot-widget[data-theme="dark"] .convertybot-teaser-close:hover {
    background: #334155;
    color: #cbd5e1;
}

.convertybot-widget[data-theme="dark"] .exit-overlay-card {
    background: #1e293b;
    color: #e2e8f0;
}

.convertybot-widget[data-theme="dark"] .exit-overlay-title {
    color: #f1f5f9;
}

.convertybot-widget[data-theme="dark"] .exit-overlay-text {
    color: #94a3b8;
}

.convertybot-widget[data-theme="dark"] .exit-overlay-close {
    color: #94a3b8;
}

.convertybot-widget[data-theme="dark"] .exit-overlay-close:hover {
    color: #cbd5e1;
}

/* =====================================================================
   Responsive — Mobile adjustments
   Match both 768px (tablet) and 480px (mobile, aligns with frontend.css)
   ===================================================================== */
@media (max-width: 768px) {
    #convertybot-teaser-bubble {
        right: 12px;
        bottom: 80px;
        max-width: 290px;
    }

    .exit-overlay-card {
        padding: 28px 24px;
        border-radius: 16px;
    }

    .exit-overlay-title {
        font-size: 18px;
    }
}

@media (max-width: 480px) {
    #convertybot-teaser-bubble {
        right: 8px;
        left: 8px;
        bottom: 75px;
        max-width: none;
        width: auto;
    }

    .teaser-bubble-body {
        padding: 12px 36px 10px 60px;
    }

    .teaser-bubble-avatar {
        width: 34px;
        height: 34px;
        top: 14px;
        left: 14px;
    }

    .teaser-bubble-avatar svg {
        width: 18px;
        height: 18px;
    }

    .exit-overlay-card {
        padding: 24px 20px;
        width: 94%;
    }

    .exit-overlay-title {
        font-size: 16px;
    }

    .exit-overlay-chat-btn {
        padding: 10px 22px;
        font-size: 14px;
    }
}

/* =====================================================================
   Reduced Motion — disable infinite animations for vestibular sensitivity
   ===================================================================== */
@media (prefers-reduced-motion: reduce) {
    .convertybot-chat-button.has-pulse {
        animation: none;
    }

    .convertybot-online-indicator {
        animation: none;
    }

    .convertybot-badge.active {
        animation: none;
    }

    #convertybot-teaser-bubble {
        transition: opacity 0.15s, visibility 0.15s;
        transform: none;
    }

    #convertybot-teaser-bubble.visible {
        transform: none;
    }

    #convertybot-exit-overlay {
        transition: opacity 0.01ms, visibility 0.01ms;
    }

    .exit-overlay-card {
        transition: none;
        transform: none;
    }

    #convertybot-exit-overlay.visible .exit-overlay-card {
        transform: none;
    }
}
