/**
 * ConvertyBot Chatbot - Modern Enhanced Frontend Styles
 * Premium, modern chat interface with smooth animations
 */

/* Import Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* CSS Variables for Theme */
:root {
    --convertybot-primary: #6366f1;
    --convertybot-primary-dark: #4f46e5;
    --convertybot-primary-light: #818cf8;
    --convertybot-secondary: #8b5cf6;
    --convertybot-success: #10b981;
    --convertybot-warning: #f59e0b;
    --convertybot-danger: #ef4444;
    --convertybot-bg-main: #ffffff;
    --convertybot-bg-secondary: #f9fafb;
    --convertybot-text-primary: #111827;
    --convertybot-text-secondary: #6b7280;
    --convertybot-border: #e5e7eb;
    --convertybot-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --convertybot-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --convertybot-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --convertybot-shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --convertybot-radius: 12px;
    --convertybot-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Mode Variables */
[data-theme="dark"] {
    --convertybot-bg-main: #1f2937;
    --convertybot-bg-secondary: #111827;
    --convertybot-text-primary: #f9fafb;
    --convertybot-text-secondary: #9ca3af;
    --convertybot-border: #374151;
}

/* Main Widget Container */
.convertybot-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999999;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--convertybot-text-primary);
}

/* Modern Chat Button */
.convertybot-chat-button {
    background: linear-gradient(135deg, var(--convertybot-primary) 0%, var(--convertybot-secondary) 100%);
    color: white;
    border: none;
    border-radius: 30px;
    padding: 14px 24px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    box-shadow: var(--convertybot-shadow-lg);
    transition: var(--convertybot-transition);
    font-size: 15px;
    font-weight: 500;
    position: relative;
    overflow: hidden;
}

.convertybot-chat-button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.convertybot-chat-button:hover {
    transform: translateY(-3px);
    box-shadow: var(--convertybot-shadow-xl);
}

.convertybot-chat-button:hover::before {
    width: 300px;
    height: 300px;
}

.convertybot-chat-button svg {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.convertybot-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--convertybot-danger);
    color: white;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 600;
    min-width: 20px;
    text-align: center;
    animation: pulse 2s infinite;
}

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

/* Modern Chat Window */
.convertybot-chat-window {
    position: absolute;
    bottom: 10px;
    right: 0;
    width: 420px;
    height: 600px;
    background: var(--convertybot-bg-main);
    border-radius: 20px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    animation: slideInUp 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Modern Chat Header */
.convertybot-chat-header {
    background: linear-gradient(135deg, var(--convertybot-primary) 0%, var(--convertybot-secondary) 100%);
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.convertybot-chat-header::after {
    content: '';
    position: absolute;
    bottom: -50%;
    right: -10%;
    width: 200px;
    height: 200px;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
    border-radius: 50%;
}

.convertybot-header-info {
    display: flex;
    align-items: center;
    gap: 14px;
    z-index: 1;
}

.convertybot-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.convertybot-header-text h4 {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.2px;
}

.convertybot-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    opacity: 0.95;
    margin-top: 2px;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
    animation: statusPulse 2s infinite;
}

@keyframes statusPulse {
    0%, 100% {
        box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
    }
    50% {
        box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.1);
    }
}

.convertybot-header-actions {
    display: flex;
    gap: 8px;
    z-index: 1;
}

.convertybot-header-actions button {
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    cursor: pointer;
    padding: 8px;
    border-radius: 10px;
    transition: var(--convertybot-transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.convertybot-header-actions button:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

/* Modern Messages Container */
.convertybot-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--convertybot-bg, var(--convertybot-bg-secondary));
    scroll-behavior: smooth;
}

.convertybot-message {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    animation: fadeInMessage 0.4s ease;
}

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

.convertybot-message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--convertybot-primary) 0%, var(--convertybot-secondary) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
    font-weight: 600;
    font-size: 14px;
}

.convertybot-message.user .message-avatar {
    background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
}

.message-content {
    max-width: 75%;
}

.message-bubble {
    background: white;
    padding: 12px 16px;
    border-radius: 18px;
    box-shadow: var(--convertybot-shadow-sm);
    word-wrap: break-word;
    font-size: 14px;
    line-height: 1.6;
}

.convertybot-message.user .message-bubble {
    background: linear-gradient(135deg, var(--convertybot-primary) 0%, var(--convertybot-secondary) 100%);
    color: white;
    box-shadow: var(--convertybot-shadow-md);
}

.message-time {
    font-size: 11px;
    color: var(--convertybot-text-secondary);
    margin-top: 4px;
    padding: 0 4px;
}

/* Modern Suggestions */
.message-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.suggestion-chip {
    background: white;
    border: 1.5px solid var(--convertybot-border);
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--convertybot-transition);
    color: var(--convertybot-text-primary);
}

.suggestion-chip:hover {
    background: var(--convertybot-primary);
    color: white;
    border-color: var(--convertybot-primary);
    transform: translateY(-2px);
    box-shadow: var(--convertybot-shadow-md);
}

/* Modern Typing Indicator */
/* ✅ FIX Bug 4: Ensure typing area has white background */
.convertybot-typing {
    padding: 12px 20px;
    background: white;
}

.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: white;
    padding: 12px 16px;
    border-radius: 18px;
    box-shadow: var(--convertybot-shadow-sm);
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--convertybot-primary);
    animation: typingBounce 1.4s infinite;
}

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

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

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Modern Product Cards */
.convertybot-products {
    padding: 16px;
    background: white;
    border-top: 1px solid var(--convertybot-border);
}

.products-carousel {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 8px;
    scroll-behavior: smooth;
}

.product-card {
    min-width: 150px;
    background: white;
    border: 1px solid var(--convertybot-border);
    border-radius: 12px;
    padding: 10px;
    cursor: pointer;
    transition: var(--convertybot-transition);
}

.product-card:hover {
    box-shadow: var(--convertybot-shadow-md);
    transform: translateY(-3px);
    border-color: var(--convertybot-primary-light);
}

.product-card img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 8px;
    margin-bottom: 8px;
}

.product-card h5 {
    margin: 0 0 4px 0;
    font-size: 13px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--convertybot-text-primary);
}

.product-card .price {
    color: var(--convertybot-primary);
    font-weight: 700;
    font-size: 15px;
}

/* Product Actions */
.product-actions {
    margin-top: 8px;
}

.btn-view-product, .btn-add-to-cart {
    background: var(--convertybot-primary);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--convertybot-transition);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 2px;
}

.btn-view-product:hover, .btn-add-to-cart:hover {
    background: var(--convertybot-primary-dark);
    transform: scale(1.05);
}

/* See More Button */
.products-see-more {
    text-align: center;
    margin-top: 10px;
    padding: 0 16px;
}

.see-more-products-btn {
    background: linear-gradient(135deg, var(--convertybot-primary) 0%, var(--convertybot-secondary) 100%);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--convertybot-transition);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: var(--convertybot-shadow-sm);
}

.see-more-products-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--convertybot-shadow-lg);
}

.see-more-products-btn .arrow {
    font-size: 16px;
    transition: transform 0.3s ease;
}

.see-more-products-btn:hover .arrow {
    transform: translateX(3px);
}

/* Products Modal */
.ai-products-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
}

.modal-content {
    position: relative;
    background: var(--convertybot-white);
    border-radius: 20px;
    max-width: 90vw;
    max-height: 90vh;
    width: 800px;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    animation: modalSlideUp 0.3s ease;
}

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

.modal-header {
    padding: 20px 25px;
    border-bottom: 1px solid var(--convertybot-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, var(--convertybot-primary) 0%, var(--convertybot-secondary) 100%);
    color: white;
}

.modal-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: white;
    line-height: 1;
    padding: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--convertybot-transition);
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.1);
}

.modal-body {
    padding: 25px;
    max-height: 60vh;
    overflow-y: auto;
}

.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}

.modal-product-card {
    background: var(--convertybot-bg-secondary);
    border-radius: 15px;
    padding: 20px;
    border: 1px solid var(--convertybot-border);
    transition: var(--convertybot-transition);
    display: flex;
    gap: 15px;
}

.modal-product-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--convertybot-shadow-lg);
    border-color: var(--convertybot-primary);
}

.modal-product-card img {
    width: 100px;
    height: 100px;
    object-fit: cover;
    border-radius: 10px;
    flex-shrink: 0;
}

.no-image {
    width: 100px;
    height: 100px;
    background: var(--convertybot-border);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--convertybot-text-secondary);
    font-size: 12px;
    text-align: center;
    flex-shrink: 0;
}

.product-info {
    flex: 1;
}

.modal-product-card h5 {
    font-size: 16px;
    font-weight: 700;
    color: var(--convertybot-text-primary);
    margin: 0 0 8px 0;
    line-height: 1.3;
}

.modal-product-card .price {
    font-size: 18px;
    font-weight: 700;
    color: var(--convertybot-primary);
    margin-bottom: 8px;
}

.product-description {
    font-size: 13px;
    color: var(--convertybot-text-secondary);
    line-height: 1.4;
    margin-bottom: 12px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.modal-product-card .product-actions {
    display: flex;
    gap: 8px;
    margin-top: auto;
}

.modal-product-card .btn-view-product,
.modal-product-card .btn-add-to-cart {
    padding: 8px 16px;
    font-size: 12px;
    border-radius: 8px;
}

.btn-add-to-cart {
    background: var(--convertybot-secondary);
}

.btn-add-to-cart:hover {
    background: #059669;
}

/* Mobile Responsive for Modal */
@media (max-width: 768px) {
    .modal-content {
        width: 95vw;
        margin: 0 10px;
    }
    
    .products-grid {
        grid-template-columns: 1fr;
    }
    
    .modal-product-card {
        flex-direction: column;
        text-align: center;
    }
    
    .modal-product-card img,
    .no-image {
        width: 80px;
        height: 80px;
        margin: 0 auto 10px auto;
    }
}

/* Modern Input Area */
.convertybot-chat-input {
    padding: 16px;
    background: white;
    border-top: 1px solid var(--convertybot-border);
}

.convertybot-chat-input form {
    display: flex;
    gap: 10px;
    align-items: center;
}

.convertybot-chat-input input {
    flex: 1;
    padding: 12px 18px;
    border: 2px solid var(--convertybot-border);
    border-radius: 25px;
    outline: none;
    font-size: 14px;
    font-family: inherit;
    transition: var(--convertybot-transition);
    background: var(--convertybot-bg-secondary);
}

.convertybot-chat-input input:focus {
    border-color: var(--convertybot-primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.convertybot-chat-input input::placeholder {
    color: var(--convertybot-text-secondary);
}

.convertybot-chat-input button {
    background: linear-gradient(135deg, var(--convertybot-primary) 0%, var(--convertybot-secondary) 100%);
    color: white;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--convertybot-transition);
    box-shadow: var(--convertybot-shadow-md);
    flex-shrink: 0;
}

.convertybot-chat-input button:hover {
    transform: scale(1.1);
    box-shadow: var(--convertybot-shadow-lg);
}

.convertybot-chat-input button:active {
    transform: scale(0.95);
}

.convertybot-chat-input button svg {
    width: 20px;
    height: 20px;
    margin-left: 2px;
}

/* Enhanced Scrollbar */
.convertybot-chat-messages::-webkit-scrollbar {
    width: 8px;
}

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

.convertybot-chat-messages::-webkit-scrollbar-thumb {
    background: var(--convertybot-border);
    border-radius: 10px;
}

.convertybot-chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--convertybot-text-secondary);
}

/* Mobile Responsive Design */
@media (max-width: 480px) {
    .convertybot-widget {
        bottom: 0;
        right: 0;
        left: 0;
    }
    
    .convertybot-chat-window {
        width: 100%;
        height: 100vh;
        bottom: 0;
        border-radius: 0;
        max-height: 100vh;
    }
    
    .convertybot-chat-button {
        bottom: 16px;
        right: 16px;
        position: fixed;
    }
}

/* Loading Animation */
.convertybot-loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--convertybot-primary);
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Success Animation */
.message-success {
    animation: successPulse 0.5s ease;
}

@keyframes successPulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 20px rgba(16, 185, 129, 0.3);
    }
    100% {
        transform: scale(1);
    }
}

/* Connection Status Bar */
.connection-status {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--convertybot-success) 0%, var(--convertybot-primary) 50%, var(--convertybot-secondary) 100%);
    animation: connectionFlow 2s linear infinite;
}

@keyframes connectionFlow {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

/* Emoji Support */
.emoji {
    font-size: 1.2em;
    vertical-align: middle;
}

/* Focus Visible */
button:focus-visible,
input:focus-visible {
    outline: 2px solid var(--convertybot-primary);
    outline-offset: 2px;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}