/*
 * ELC Mart AI Assistant — chat toggle icon: support avatar, online status dot,
 * notification badge, and the attention-pulse animation around the button.
 *
 * Loaded after chat-widget.css, and only styles the toggle icon itself — the chat
 * window/messages styling stays in chat-widget.css.
 */

#elc-ai-chat-icon {
    position: relative;
    overflow: visible; /* let the status dot, badge, and pulse rings sit on/outside the circle's edge */
    background: transparent; /* the avatar SVG supplies its own circular background */
}

#elc-ai-avatar-img {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    animation: elc-avatar-bob 2.6s ease-in-out infinite;
}

@keyframes elc-avatar-bob {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-3px) rotate(-2.5deg); }
}

/* 2. Online status dot — small green dot at the top-right edge of the circle. */
#elc-ai-online-dot {
    position: absolute;
    top: -1px;
    right: -1px;
    width: 14px;
    height: 14px;
    background: #22c55e;
    border: 2px solid #ffffff;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.05);
    z-index: 2;
}

/* 3. Notification badge — small red bubble showing "1" to draw the eye. */
#elc-ai-notify-badge {
    position: absolute;
    top: -4px;
    left: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    background: #e53935;
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    border-radius: 999px;
    border: 2px solid #ffffff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    z-index: 2;
}

/*
 * 4. Pulse/wave animation around the button — invisible for the first 4.5s after
 * the page loads (nothing distracting during initial page render/reading), then
 * gently pulses on a loop to invite a click. Pure CSS via animation-delay, so it
 * needs no JS timer. Two staggered rings (::before/::after) give a fuller "wave".
 */
#elc-ai-chat-icon::before,
#elc-ai-chat-icon::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid #0073aa;
    opacity: 0;
    pointer-events: none;
    animation: elc-avatar-pulse 2.6s ease-out infinite;
    animation-delay: 4.5s;
    z-index: 0;
}
#elc-ai-chat-icon::after {
    border-color: #22c55e;
    animation-delay: 4.9s; /* slight stagger from ::before for a layered wave effect */
}

@keyframes elc-avatar-pulse {
    0% {
        transform: scale(1);
        opacity: 0.55;
    }
    70% {
        transform: scale(1.55);
        opacity: 0;
    }
    100% {
        transform: scale(1.55);
        opacity: 0;
    }
}

/*
 * Once the visitor has opened the chat at least once, it's no longer "attention
 * seeking" — chat-widget.js adds the .elc-engaged class on first open, which
 * hides the badge and stops the pulse rings.
 */
#elc-ai-chat-icon.elc-engaged #elc-ai-notify-badge {
    display: none;
}
#elc-ai-chat-icon.elc-engaged::before,
#elc-ai-chat-icon.elc-engaged::after {
    animation: none;
    opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
    #elc-ai-chat-icon::before,
    #elc-ai-chat-icon::after {
        animation: none;
    }
    #elc-ai-avatar-img {
        animation: none;
    }
}

/*
 * Proactive greeting speech bubble — built dynamically by chat-widget.js and
 * inserted as a sibling of #elc-ai-chat-icon inside #elc-ai-widget-container, so it
 * shares that container's fixed positioning/stacking context (z-index: 99999).
 * Shown once per browser tab (sessionStorage-guarded in JS), 4.5s after page load.
 */
#elc-ai-greeting-bubble {
    position: absolute;
    bottom: 6px;
    right: 74px; /* clears the 60px desktop icon + a small gap */
    max-width: 240px;
    background: #ffffff;
    color: #1f2d3d;
    font-size: 13px;
    line-height: 1.45;
    padding: 12px 32px 12px 14px;
    border-radius: 14px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
    z-index: 3;
    cursor: pointer;
    animation: elc-bubble-in 0.35s ease-out;
}

/* Tail pointing from the bubble toward the chat icon. */
#elc-ai-greeting-bubble::after {
    content: "";
    position: absolute;
    top: 50%;
    right: -7px;
    transform: translateY(-50%);
    border-width: 7px 0 7px 8px;
    border-style: solid;
    border-color: transparent transparent transparent #ffffff;
}

#elc-ai-greeting-bubble .elc-bubble-close {
    position: absolute;
    top: 4px;
    right: 6px;
    background: none;
    border: none;
    color: #8a94a3;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    padding: 4px;
}
#elc-ai-greeting-bubble .elc-bubble-close:hover {
    color: #1f2d3d;
}

@keyframes elc-bubble-in {
    0% {
        opacity: 0;
        transform: translateY(6px) scale(0.96);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

#elc-ai-greeting-bubble.elc-bubble-out {
    animation: elc-bubble-out 0.25s ease-in forwards;
    pointer-events: none;
}
@keyframes elc-bubble-out {
    to {
        opacity: 0;
        transform: translateY(6px) scale(0.96);
    }
}

/* Mobile: narrower icon, tighter container edges (see chat-widget.css breakpoint) —
   pull the bubble in to match and cap its width so it never overflows the viewport. */
@media (max-width: 480px) {
    #elc-ai-greeting-bubble {
        right: 62px;
        max-width: calc(100vw - 100px);
        font-size: 12.5px;
    }
}

/*
 * "Deb is typing…" indicator — shown the instant a message is sent, and kept on
 * screen through the artificial human-like delay in chat-widget.js before the
 * actual reply is revealed.
 */
.elc-typing-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
}
.elc-typing-label {
    font-size: 12px;
    color: #667085;
    font-style: italic;
}
.elc-typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}
.elc-typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #8a94a3;
    display: inline-block;
    animation: elc-typing-pulse 1.1s ease-in-out infinite;
}
.elc-typing-dots span:nth-child(2) {
    animation-delay: 0.15s;
}
.elc-typing-dots span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes elc-typing-pulse {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* Smooth reveal for a bot reply once the typing delay finishes, instead of it
   snapping instantly into view. */
.elc-fade-in {
    animation: elc-msg-fade-in 0.3s ease-out;
}
@keyframes elc-msg-fade-in {
    0% {
        opacity: 0;
        transform: translateY(4px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (prefers-reduced-motion: reduce) {
    .elc-typing-dots span {
        animation: none;
        opacity: 0.8;
    }
    .elc-fade-in {
        animation: none;
    }
}
