/**
 * AI Product Popup - Frontend Styles
 */

#ai-product-popup {
    position: fixed;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    --ai-popup-primary: var(--ai-popup-color, #4f46e5);
    --ai-popup-bg: #ffffff;
    --ai-popup-text: #1f2937;
    --ai-popup-border: #e5e7eb;
    --ai-popup-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

/* Position variants */
#ai-product-popup.bottom-right {
    bottom: 20px;
    right: 20px;
}

#ai-product-popup.bottom-left {
    bottom: 20px;
    left: 20px;
}

#ai-product-popup.top-right {
    top: 20px;
    right: 20px;
}

#ai-product-popup.top-left {
    top: 20px;
    left: 20px;
}

.ai-popup-container {
    width: 380px;
    max-width: calc(100vw - 40px);
    background: var(--ai-popup-bg);
    border-radius: 16px;
    box-shadow: var(--ai-popup-shadow);
    overflow: hidden;
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
}

#ai-product-popup.active .ai-popup-container {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: auto;
}

/* Header */
.ai-popup-header {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--ai-popup-primary) 0%, color-mix(in srgb, var(--ai-popup-primary) 80%, black) 100%);
    color: white;
}

.ai-avatar {
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    flex-shrink: 0;
}

.ai-avatar svg {
    width: 24px;
    height: 24px;
    color: white;
}

.ai-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.ai-name {
    font-weight: 600;
    font-size: 16px;
    line-height: 1.3;
}

.ai-status {
    font-size: 12px;
    opacity: 0.8;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-status::before {
    content: '';
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.ai-popup-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-popup-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.ai-popup-close svg {
    width: 20px;
    height: 20px;
}

/* Body */
.ai-popup-body {
    padding: 20px;
    min-height: 120px;
    max-height: 300px;
    overflow-y: auto;
}

.ai-messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ai-message {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    animation: messageSlide 0.3s ease;
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-message-avatar {
    width: 32px;
    height: 32px;
    background: var(--ai-popup-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ai-message-avatar svg {
    width: 18px;
    height: 18px;
    color: white;
}

.ai-message-content {
    background: #f3f4f6;
    padding: 12px 16px;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    max-width: calc(100% - 50px);
}

.ai-message-content p {
    margin: 0;
    color: var(--ai-popup-text);
    font-size: 14px;
    line-height: 1.5;
}

/* Typing indicator */
.ai-typing {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
}

.ai-typing span {
    width: 8px;
    height: 8px;
    background: #d1d5db;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.ai-typing span:nth-child(1) {
    animation-delay: -0.32s;
}

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

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1);
    }
}

/* Footer */
.ai-popup-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--ai-popup-border);
    background: #f9fafb;
}

.ai-quick-replies {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.quick-reply {
    padding: 8px 16px;
    background: white;
    border: 1px solid var(--ai-popup-border);
    border-radius: 20px;
    font-size: 13px;
    color: var(--ai-popup-text);
    cursor: pointer;
    transition: all 0.2s;
}

.quick-reply:hover {
    border-color: var(--ai-popup-primary);
    color: var(--ai-popup-primary);
    background: color-mix(in srgb, var(--ai-popup-primary) 5%, white);
}

/* User reply */
.user-reply {
    align-self: flex-end;
    background: var(--ai-popup-primary);
    color: white;
    padding: 10px 16px;
    border-radius: 16px;
    border-bottom-right-radius: 4px;
    font-size: 14px;
    max-width: 80%;
    animation: messageSlide 0.3s ease;
}

/* Cursor for typing effect */
.typing-cursor::after {
    content: '|';
    animation: cursorBlink 1s infinite;
    color: var(--ai-popup-primary);
}

@keyframes cursorBlink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Product click indicator */
.ai-popup-trigger-hint {
    position: fixed;
    bottom: 100px;
    right: 20px;
    background: var(--ai-popup-primary);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    box-shadow: var(--ai-popup-shadow);
    animation: hintPulse 2s infinite;
    z-index: 999998;
}

@keyframes hintPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* Mobile responsiveness */
@media screen and (max-width: 480px) {
    #ai-product-popup {
        bottom: 10px !important;
        right: 10px !important;
        left: 10px !important;
        top: auto !important;
    }
    
    .ai-popup-container {
        width: 100%;
        max-width: 100%;
    }
    
    #ai-product-popup.top-left,
    #ai-product-popup.top-right {
        bottom: auto !important;
        top: 10px !important;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    #ai-product-popup {
        --ai-popup-bg: #1f2937;
        --ai-popup-text: #f9fafb;
        --ai-popup-border: #374151;
    }
    
    .ai-message-content {
        background: #374151;
    }
    
    .ai-popup-footer {
        background: #111827;
    }
    
    .quick-reply {
        background: #374151;
        color: #f9fafb;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    .ai-popup-container,
    .ai-message,
    .ai-status::before,
    .typing-cursor::after {
        animation: none !important;
        transition: none !important;
    }
}

/* Focus styles */
.ai-popup-close:focus,
.quick-reply:focus {
    outline: 2px solid var(--ai-popup-primary);
    outline-offset: 2px;
}

/* Scrollbar styling */
.ai-popup-body::-webkit-scrollbar {
    width: 6px;
}

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

.ai-popup-body::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.ai-popup-body::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}
