/**
 * CVG Universal Chat Widget - Enhanced Styles
 * © 2025 Clearview Geographic LLC
 * 
 * Enhanced styles for new features: avatars, animations, enhanced responsive design
 * Extends the base cvg-chat-core.css with additional functionality
 */

/* Enhanced message styling with avatars */
.cvg-message-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
}

.cvg-message-avatar {
    font-size: 1.2rem;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.cvg-message-user .cvg-message-avatar {
    background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
}

.cvg-message-agent .cvg-message-avatar {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.cvg-message-system .cvg-message-avatar {
    background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
}

.cvg-message-author {
    font-weight: 600;
    color: #374151;
    flex: 1;
}

.cvg-message-time {
    font-size: 0.75rem;
    color: #9ca3af;
    margin-left: auto;
}

/* Enhanced input container with file upload button */
.cvg-input-container {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
    width: 100%;
}

.cvg-input-container textarea {
    flex: 1;
}

.cvg-input-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.cvg-file-btn {
    background: #6b7280;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 0.75rem;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 2.5rem;
}

.cvg-file-btn:hover {
    background: #4b5563;
}

/* Enhanced error messaging */
.cvg-error-message {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #dc2626;
    padding: 0.75rem;
    border-radius: 6px;
    margin-top: 1rem;
    font-size: 0.875rem;
    display: none;
}

.cvg-rate-limit-notice {
    background: #fef3c7;
    border: 1px solid #fcd34d;
    color: #92400e;
    padding: 0.75rem;
    border-radius: 6px;
    margin-top: 1rem;
    font-size: 0.875rem;
    text-align: center;
}

/* Enhanced powered by footer */
.cvg-powered-by {
    font-size: 0.7rem;
    opacity: 0.7;
    text-align: center;
    margin-top: 0.25rem;
}

/* Enhanced loading states with spinner */
.cvg-loading {
    position: relative;
    pointer-events: none;
}

.cvg-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 1rem;
    width: 16px;
    height: 16px;
    margin-top: -8px;
    border: 2px solid transparent;
    border-top-color: rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    animation: cvgSpinner 1s linear infinite;
}

@keyframes cvgSpinner {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Enhanced message animations */
.cvg-message {
    transition: all 0.3s ease;
}

.cvg-message:hover {
    transform: translateX(2px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* Enhanced widget pulse animation */
.cvg-chat-widget.cvg-pulse {
    animation: cvgWidgetPulse 2s infinite;
}

@keyframes cvgWidgetPulse {
    0%, 100% { 
        transform: scale(1);
        box-shadow: 0 4px 20px rgba(16, 185, 129, 0.4);
    }
    50% { 
        transform: scale(1.05);
        box-shadow: 0 8px 30px rgba(16, 185, 129, 0.6);
    }
}

/* Enhanced typing indicator with better animation */
.cvg-typing-indicator {
    padding: 0.75rem 1rem;
    color: #6b7280;
    font-size: 0.85rem;
    font-style: italic;
    background: rgba(16, 185, 129, 0.05);
    border-radius: 8px;
    margin: 0.5rem;
    display: none;
    align-items: center;
}

.cvg-typing-dots {
    display: inline-flex;
    margin-left: 0.5rem;
    gap: 2px;
}

.cvg-typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #10b981;
    display: block;
    animation: cvgTypingDots 1.4s infinite ease-in-out;
}

.cvg-typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.cvg-typing-dots span:nth-child(2) { animation-delay: -0.16s; }
.cvg-typing-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes cvgTypingDots {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1.2);
        opacity: 1;
    }
}

/* Enhanced responsive design for tablets */
@media (max-width: 768px) and (min-width: 481px) {
    .cvg-chat-window {
        width: calc(100vw - 2rem);
        max-width: 400px;
        height: calc(100vh - 4rem);
        max-height: 600px;
    }
    
    .cvg-chat-widget {
        padding: 0.875rem 1.375rem;
        font-size: 0.875rem;
    }
}

/* Enhanced mobile responsiveness */
@media (max-width: 480px) {
    .cvg-chat-window {
        width: 100vw;
        height: 100vh;
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        border-radius: 0;
        max-width: none;
        max-height: none;
    }
    
    .cvg-chat-header {
        border-radius: 0;
        padding: 1.25rem 1rem;
    }
    
    .cvg-chat-widget {
        bottom: 1rem;
        right: 1rem;
        padding: 0.75rem 1.25rem;
        font-size: 0.85rem;
        max-width: 180px;
    }
    
    .cvg-message-header {
        flex-wrap: wrap;
        gap: 0.25rem;
    }
    
    .cvg-message-time {
        flex-basis: 100%;
        margin-left: 2.5rem;
        font-size: 0.7rem;
    }
    
    .cvg-input-actions {
        flex-direction: column;
        gap: 0.25rem;
    }
    
    .cvg-file-btn {
        min-width: 100%;
        padding: 0.5rem;
    }
}

/* Enhanced dark mode with better contrast */
@media (prefers-color-scheme: dark) {
    .cvg-message-author {
        color: #f9fafb;
    }
    
    .cvg-message-time {
        color: #9ca3af;
    }
    
    .cvg-error-message {
        background: #450a0a;
        border-color: #dc2626;
        color: #fca5a5;
    }
    
    .cvg-rate-limit-notice {
        background: #451a03;
        border-color: #f59e0b;
        color: #fcd34d;
    }
    
    .cvg-typing-indicator {
        background: rgba(16, 185, 129, 0.1);
        color: #d1d5db;
    }
}

/* Enhanced high contrast mode */
@media (prefers-contrast: high) {
    .cvg-message {
        border: 2px solid #000;
    }
    
    .cvg-message-avatar {
        border: 2px solid #000;
    }
    
    .cvg-file-btn,
    .cvg-chat-input button {
        border: 2px solid #000;
    }
}

/* Enhanced print styles */
@media print {
    .cvg-chat-widget,
    .cvg-chat-window {
        display: none !important;
    }
}

/* Accessibility enhancements */
.cvg-chat-widget:focus-visible,
.cvg-file-btn:focus-visible,
.cvg-chat-input button:focus-visible {
    outline: 2px solid #10b981;
    outline-offset: 2px;
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    .cvg-message,
    .cvg-typing-dots span,
    .cvg-loading::after {
        animation: none;
    }
    
    .cvg-message:hover {
        transform: none;
    }
    
    .cvg-chat-widget.cvg-pulse {
        animation: none;
    }
}

/* Custom CSS properties for theming */
:root {
    --cvg-brand-primary: #10b981;
    --cvg-brand-secondary: #f97316;
    --cvg-border-radius: 8px;
    --cvg-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --cvg-shadow-color: rgba(0, 0, 0, 0.1);
    --cvg-transition: all 0.3s ease;
}

/* Theme customization support */
.cvg-chat-window[data-theme="minimal"] {
    box-shadow: 0 4px 20px var(--cvg-shadow-color);
}

.cvg-chat-window[data-theme="minimal"] .cvg-chat-header {
    background: var(--cvg-brand-primary);
}

.cvg-chat-window[data-theme="corporate"] {
    border-radius: 4px;
}

.cvg-chat-window[data-theme="corporate"] .cvg-chat-header {
    background: linear-gradient(90deg, var(--cvg-brand-primary), var(--cvg-brand-secondary));
}

/* Enhanced scrollbar styling */
.cvg-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.cvg-chat-messages::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 3px;
}

.cvg-chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.cvg-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Firefox scrollbar styling */
.cvg-chat-messages {
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 #f1f5f9;
}

/* Connection status indicators */
.cvg-chat-status.cvg-connecting::before {
    content: '🔄 ';
    animation: cvgSpinner 1s linear infinite;
    display: inline-block;
}

.cvg-chat-status.cvg-connected::before {
    content: '✅ ';
}

.cvg-chat-status.cvg-error::before {
    content: '❌ ';
}

/* File upload drag and drop styling */
.cvg-chat-window.cvg-drag-over {
    border: 2px dashed var(--cvg-brand-primary);
    background: rgba(16, 185, 129, 0.05);
}

.cvg-file-drop-zone {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(16, 185, 129, 0.1);
    border: 2px dashed var(--cvg-brand-primary);
    border-radius: var(--cvg-border-radius);
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: var(--cvg-brand-primary);
    font-weight: 600;
}

.cvg-file-drop-zone.cvg-active {
    display: flex;
}

/* Performance optimization - will-change for animated elements */
.cvg-typing-dots span,
.cvg-loading::after,
.cvg-message {
    will-change: transform, opacity;
}

/* Smooth scrolling for message container */
.cvg-chat-messages {
    scroll-behavior: smooth;
}
