/**
 * Captain Superlac AI Assistant - Premium Styles
 * Aesthetic: Pastel Green + Modern Glassmorphism
 */

:root {
    --ai-primary: #e8f5e9;
    --ai-accent: #4caf50;
    --ai-accent-hover: #43a047;
    --ai-text-dark: #2c3e50;
    --ai-text-muted: #7f8c8d;
    --ai-bg-white: #ffffff;
    --ai-shadow-soft: 0 10px 40px rgba(0, 0, 0, 0.08);
    --ai-glass: rgba(255, 255, 255, 0.85);
    --ai-radius-lg: 24px;
    --ai-radius-md: 16px;
    --ai-radius-sm: 12px;
}

#ai-assistant-widget {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 10000;
    font-family: 'Outfit', 'Inter', system-ui, sans-serif;
}

/* Floating Trigger Button */
#ai-trigger {
    width: 125px;
    height: 125px;
    background: transparent;
    padding: 0;
    border: none;
    cursor: pointer;
    box-shadow: none;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    overflow: visible;
}

#ai-trigger video,
#ai-trigger .mascot-fallback-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    animation: breathing 4s ease-in-out infinite;
    filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.1));
    opacity: 1 !important;
}

#ai-trigger:hover {
    transform: scale(1.1) translateY(-5px);
    box-shadow: 0 15px 50px rgba(76, 175, 80, 0.2);
}

/* Chat Window */
#ai-window {
    position: absolute;
    bottom: 85px;
    right: 0;
    width: 400px;
    height: 650px;
    max-height: calc(100vh - 150px);
    background: var(--ai-bg-white);
    backdrop-filter: blur(25px);
    border-radius: var(--ai-radius-lg);
    box-shadow: 0 30px 100px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transition: all 0.6s cubic-bezier(0.19, 1, 0.22, 1);
    border: 1px solid rgba(232, 245, 233, 0.5);
}

.ai-window-hidden {
    opacity: 0;
    transform: scale(0.9) translateY(40px);
    pointer-events: none;
}

.ai-window-visible {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: all;
}

/* Header */
.ai-header {
    padding: 24px;
    background: linear-gradient(135deg, #ffffff 0%, #f1f8f1 100%);
    border-bottom: 1px solid rgba(0, 0, 0, 0.03);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ai-header-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.ai-avatar-container {
    position: relative;
    width: 48px;
    height: 48px;
}

.ai-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #fff;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    animation: floating 3s ease-in-out infinite;
    position: relative;
    z-index: 2;
}

.ai-status h3 {
    margin: 0;
    font-size: 17px;
    font-weight: 700;
    color: var(--ai-text-dark);
}

.status-online {
    font-size: 12px;
    color: var(--ai-accent);
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
}

.status-dot {
    width: 7px;
    height: 7px;
    background: var(--ai-accent);
    border-radius: 50%;
    animation: pulseDot 2s infinite;
}

#ai-close {
    background: rgba(0, 0, 0, 0.04);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: #666;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

#ai-close:hover {
    background: #ffebee;
    color: #e53935;
}

/* Messages Area */
.ai-messages {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: linear-gradient(to bottom, #ffffff, #fafdfa);
}

.message {
    max-width: 88%;
    padding: 14px 18px;
    border-radius: var(--ai-radius-md);
    font-size: 14.5px;
    line-height: 1.6;
    animation: elasticSlide 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.ai-msg {
    background: var(--ai-primary);
    color: var(--ai-text-dark);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.05);
    border: 1px solid rgba(76, 175, 80, 0.1);
}

.user-msg {
    background: #f8f9fa;
    color: var(--ai-text-dark);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    border: 1px solid #eee;
}

/* Rich Components */
.product-card,
.calc-card,
.dealer-card {
    background: #fff;
    border-radius: var(--ai-radius-md);
    padding: 16px;
    margin-top: 12px;
    border: 1px solid rgba(0, 0, 0, 0.05);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.04);
    transition: transform 0.3s;
}

.product-card:hover {
    transform: translateY(-3px);
}

.card-desc {
    font-size: 12px;
    color: #666;
    margin: 4px 0;
}

.card-tag {
    display: inline-block;
    padding: 4px 10px;
    background: var(--ai-primary);
    color: var(--ai-accent);
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    margin-bottom: 8px;
    text-transform: uppercase;
}

.card-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 6px;
    display: block;
}

.card-result {
    background: #f1f8f1;
    border-radius: var(--ai-radius-sm);
    padding: 12px;
    text-align: center;
    margin: 10px 0;
    border-left: 4px solid var(--ai-accent);
}

.card-result span {
    font-size: 24px;
    font-weight: 800;
    color: var(--ai-accent);
    display: block;
}

/* Quick Chips */
.ai-quick-chips {
    padding: 0 24px 15px 24px;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
}

.quick-chip {
    padding: 8px 16px;
    background: #fff;
    border: 1px solid #eee;
    border-radius: 20px;
    font-size: 13px;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.3s;
    color: var(--ai-text-dark);
    font-weight: 500;
}

.quick-chip:hover {
    background: var(--ai-primary);
    border-color: var(--ai-accent);
    color: var(--ai-accent);
}

/* Input Area */
.ai-input-wrapper {
    padding: 20px 24px 24px 24px;
    background: #fff;
}

.ai-input-container {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #f8f9fa;
    padding: 8px;
    border-radius: var(--ai-radius-md);
    border: 1px solid #eee;
    transition: all 0.3s;
}

.ai-input-container:focus-within {
    background: #fff;
    border-color: var(--ai-accent);
    box-shadow: 0 0 0 4px rgba(76, 175, 80, 0.1);
}

#ai-input {
    flex: 1;
    background: transparent;
    border: none;
    padding: 12px;
    margin: 0;
    box-shadow: none !important;
    outline: none;
    font-size: 15px;
    color: #2c3e50 !important;
    /* Explicit high-contrast color */
    width: 100%;
    min-width: 0;
}

#ai-send {
    width: 42px;
    height: 42px;
    background: var(--ai-accent);
    color: white;
    border: none;
    border-radius: var(--ai-radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

#ai-send:hover {
    background: var(--ai-accent-hover);
    transform: scale(1.05);
}

/* Animations */
@keyframes breathing {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

@keyframes floating {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-5px);
    }
}

@keyframes pulseDot {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.4);
        opacity: 0.5;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes elasticSlide {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.ai-typing {
    padding: 0 24px 10px 24px;
}

.typing-content {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    color: #4caf50;
    font-weight: 500;
    font-style: italic;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--ai-accent);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite;
    opacity: 0.6;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
    }

    30% {
        transform: translateY(-6px);
    }
}

.typing-cursor {
    display: inline-block;
    width: 2px;
    background: var(--ai-accent);
    margin-left: 2px;
    animation: cursorBlink 0.8s infinite;
}

@keyframes cursorBlink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

/* Scrollbar */
.ai-messages::-webkit-scrollbar {
    width: 4px;
}

.ai-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ai-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 10px;
}

/* Scoped Utility */
#ai-assistant-widget .hidden {
    display: none !important;
}

/* CTAs */
.ai-cta-btn {
    display: block;
    width: 100%;
    margin-top: 12px;
    padding: 10px;
    background: var(--ai-accent);
    color: white;
    text-align: center;
    border-radius: var(--ai-radius-sm);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s;
}

.ai-cta-btn:hover {
    background: var(--ai-accent-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.2);
}

.ai-cta-outline {
    background: transparent;
    border: 1px solid var(--ai-accent);
    color: var(--ai-accent);
}

.ai-cta-outline:hover {
    background: var(--ai-primary);
}

/* Contextual Hint Bubble */
.ai-hint-bubble {
    position: absolute;
    bottom: 140px;
    right: 0;
    width: 260px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(15px);
    border: 1px solid rgba(76, 175, 80, 0.2);
    padding: 12px 18px;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 9999;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.5s cubic-bezier(0.19, 1, 0.22, 1);
    pointer-events: none;
    border-bottom-right-radius: 4px;
}

.ai-hint-bubble-visible {
    opacity: 1;
    transform: translateY(0);
    animation: hintFloat 4s ease-in-out infinite;
}

.ai-hint-hide {
    opacity: 0 !important;
    transform: translateY(10px) !important;
    pointer-events: none !important;
}

.ai-hint-text {
    font-size: 13px;
    color: var(--ai-text-dark);
    font-weight: 500;
    line-height: 1.4;
    text-align: left;
}

.ai-hint-bubble::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 54px;
    width: 16px;
    height: 16px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(15px);
    transform: rotate(45deg);
    border-right: 1px solid rgba(76, 175, 80, 0.2);
    border-bottom: 1px solid rgba(76, 175, 80, 0.2);
    border-bottom-right-radius: 2px;
}

@keyframes hintFloat {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-6px);
    }
}

@media (max-width: 480px) {
    #ai-window {
        width: 100vw;
        height: 100vh;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }

    .ai-hint-bubble {
        width: 220px;
        right: 10px;
    }
}

/* ─── iPhone / Small Mobile — Alive Chatbot Icon ─── */
@media (max-width: 430px) {
    #ai-assistant-widget {
        bottom: 18px;
        /* pushed down to clear Safari toolbar */
        right: 16px;
    }

    #ai-trigger {
        width: 125px;
        height: 125px;
    }

    /* Video won't exist on iPhone (replaced by .mascot-fallback-img via mascot.js)
       GSAP handles the alive bob+scale animation on the fallback img.
       We only add the glow ring via CSS pseudo-element. */

    /* Soft green glow ring behind the icon */
    #ai-trigger::before {
        content: '';
        position: absolute;
        inset: -6px;
        border-radius: 50%;
        background: radial-gradient(circle, rgba(76, 175, 80, 0.18) 0%, transparent 70%);
        animation: glowPulse 3s ease-in-out infinite;
        pointer-events: none;
        z-index: -1;
    }

    .ai-hint-bubble {
        bottom: 145px;
    }
}

/* Soft glow ring pulse */
@keyframes glowPulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 0.5;
    }

    50% {
        transform: scale(1.15);
        opacity: 1;
    }
}