/**
 * CVG Universal Chat Widget - Core Styles
 * © 2025 Clearview Geographic LLC
 * 
 * Self-contained styles for the chat widget
 * Compatible with all modern browsers and responsive
 */

/* Reset and base styles for chat components */
.cvg-chat-widget,
.cvg-chat-window,
.cvg-chat-widget *,
.cvg-chat-window * {
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* Chat widget button */
.cvg-chat-widget {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 9999;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 20px rgba(16, 185, 129, 0.4);
    font-weight: 600;
    font-size: 0.9rem;
    border: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    max-width: 200px;
    white-space: nowrap;
    user-select: none;
}

.cvg-chat-widget:hover {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 8px 30px rgba(16, 185, 129, 0.6);
}

.cvg-chat-widget:active {
    transform: translateY(0) scale(0.98);
}

/* Chat window container */
.cvg-chat-window {
    position: fixed !important;
    bottom: 5rem !important;
    right: 2rem !important;
    width: 380px !important;
    height: 600px !important;
    background: white !important;
    border-radius: 16px !important;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3) !important;
    z-index: 10001 !important;
    display: none !important;
    flex-direction: column !important;
    border: 1px solid #e5e7eb !important;
    overflow: hidden !important;
    animation: cvgChatSlideIn 0.3s ease-out !important;
}

.cvg-chat-window[style*="flex"] {
    display: flex !important;
}

@keyframes cvgChatSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Chat header */
.cvg-chat-header {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 15px 15px 0 0;
}

.cvg-chat-title {
    font-weight: 700;
    font-size: 1rem;
    line-height: 1.2;
}

.cvg-chat-status {
    font-size: 0.8rem;
    opacity: 0.9;
    margin-top: 0.25rem;
}

.cvg-chat-close {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    transition: background-color 0.2s ease;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cvg-chat-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Chat content area */
.cvg-chat-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Form styles */
.cvg-chat-form {
    padding: 1.5rem;
    overflow-y: auto;
    background: #f8fafc;
    flex: 1;
}

.cvg-form-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.cvg-form-header h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1.2rem;
    font-weight: 700;
    color: #374151;
}

.cvg-form-header p {
    margin: 0;
    font-size: 0.9rem;
    color: #6b7280;
}

.cvg-form-field {
    margin-bottom: 1rem;
}

.cvg-form-field label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #374151;
    font-size: 0.9rem;
}

.cvg-form-field input,
.cvg-form-field textarea {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    background: white;
}

.cvg-form-field input:focus,
.cvg-form-field textarea:focus {
    border-color: #10b981;
    outline: none;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.cvg-form-field textarea {
    resize: vertical;
    min-height: 80px;
}

.cvg-chat-submit {
    width: 100%;
    padding: 1rem;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
    font-size: 0.95rem;
    transition: all 0.2s ease;
}

.cvg-chat-submit:hover {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    transform: translateY(-1px);
}

.cvg-chat-submit:active {
    transform: translateY(0);
}

/* Messages area */
.cvg-chat-messages {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    background: #f8fafc;
    display: none;
}

.cvg-message {
    margin-bottom: 1rem;
    padding: 0.75rem;
    border-radius: 12px;
    background: white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.cvg-message-user {
    margin-left: 2rem;
    border-left: 4px solid #f97316;
}

.cvg-message-agent {
    border-left: 4px solid #10b981;
}

.cvg-message-system {
    border-left: 4px solid #6b7280;
    font-size: 0.85rem;
    opacity: 0.9;
}

.cvg-message-header {
    font-weight: 700;
    font-size: 0.85rem;
    color: #374151;
    margin-bottom: 0.25rem;
}

.cvg-message-content {
    color: #4b5563;
    line-height: 1.5;
    white-space: pre-wrap;
}

.cvg-message-time {
    font-size: 0.75rem;
    color: #9ca3af;
    margin-top: 0.5rem;
    text-align: right;
}

/* Chat input area */
.cvg-chat-input {
    padding: 1rem;
    border-top: 1px solid #e5e7eb;
    background: white;
    display: none;
    gap: 0.5rem;
    align-items: flex-end;
}

.cvg-chat-input textarea {
    flex: 1;
    padding: 0.75rem;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    resize: none;
    font-family: inherit;
    font-size: 0.9rem;
    min-height: 2.5rem;
    max-height: 6rem;
    transition: border-color 0.2s ease;
}

.cvg-chat-input textarea:focus {
    border-color: #10b981;
    outline: none;
}

.cvg-chat-input button {
    padding: 0.75rem 1.5rem;
    background: #10b981;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    transition: background-color 0.2s ease;
    white-space: nowrap;
}

.cvg-chat-input button:hover {
    background: #059669;
}

.cvg-chat-input button:disabled {
    background: #9ca3af;
    cursor: not-allowed;
}

/* Chat footer */
.cvg-chat-footer {
    padding: 0.75rem 1rem;
    background: #f9fafb;
    font-size: 0.75rem;
    color: #6b7280;
    text-align: center;
    border-top: 1px solid #f3f4f6;
}

/* Responsive design */
@media (max-width: 480px) {
    .cvg-chat-window {
        width: calc(100vw - 1rem);
        height: calc(100vh - 1rem);
        bottom: 0.5rem;
        right: 0.5rem;
        left: 0.5rem;
        top: 0.5rem;
        width: auto;
        height: auto;
    }
    
    .cvg-chat-widget {
        bottom: 1rem;
        right: 1rem;
        padding: 0.75rem 1.25rem;
        font-size: 0.85rem;
    }
    
    .cvg-form-field input,
    .cvg-form-field textarea {
        font-size: 16px; /* Prevent zoom on iOS */
    }
}

@media (max-width: 360px) {
    .cvg-chat-widget {
        padding: 0.5rem 1rem;
        font-size: 0.8rem;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .cvg-chat-window {
        background: #1f2937;
        border-color: #374151;
    }
    
    .cvg-chat-form {
        background: #111827;
    }
    
    .cvg-chat-messages {
        background: #111827;
    }
    
    .cvg-message {
        background: #374151;
        color: #f3f4f6;
    }
    
    .cvg-message-header {
        color: #f9fafb;
    }
    
    .cvg-message-content {
        color: #e5e7eb;
    }
    
    .cvg-form-field label {
        color: #f9fafb;
    }
    
    .cvg-form-field input,
    .cvg-form-field textarea {
        background: #374151;
        border-color: #4b5563;
        color: #f3f4f6;
    }
    
    .cvg-form-field input:focus,
    .cvg-form-field textarea:focus {
        border-color: #10b981;
        background: #4b5563;
    }
    
    .cvg-chat-input {
        background: #1f2937;
        border-color: #374151;
    }
    
    .cvg-chat-input textarea {
        background: #374151;
        border-color: #4b5563;
        color: #f3f4f6;
    }
    
    .cvg-chat-footer {
        background: #111827;
        color: #9ca3af;
        border-color: #374151;
    }
    
    .cvg-form-header h3 {
        color: #f9fafb;
    }
    
    .cvg-form-header p {
        color: #d1d5db;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .cvg-chat-widget {
        border: 2px solid white;
    }
    
    .cvg-chat-window {
        border: 2px solid #000;
    }
    
    .cvg-form-field input:focus,
    .cvg-form-field textarea:focus {
        box-shadow: 0 0 0 3px #000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .cvg-chat-widget,
    .cvg-chat-submit,
    .cvg-chat-close,
    .cvg-form-field input,
    .cvg-form-field textarea,
    .cvg-chat-input button {
        transition: none;
    }
    
    .cvg-chat-window {
        animation: none;
    }
    
    .cvg-chat-widget:hover,
    .cvg-chat-submit:hover {
        transform: none;
    }
}

/* Print styles */
@media print {
    .cvg-chat-widget,
    .cvg-chat-window {
        display: none !important;
    }
}

/* Accessibility improvements */
.cvg-chat-widget:focus,
.cvg-chat-close:focus,
.cvg-chat-submit:focus,
.cvg-chat-input button:focus {
    outline: 2px solid #10b981;
    outline-offset: 2px;
}

/* Loading states */
.cvg-loading {
    opacity: 0.6;
    pointer-events: none;
}

.cvg-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid transparent;
    border-top-color: #10b981;
    border-radius: 50%;
    animation: cvgSpin 1s linear infinite;
}

@keyframes cvgSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Error states */
.cvg-error {
    border-color: #ef4444 !important;
}

.cvg-error-message {
    color: #ef4444;
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

/* Success states */
.cvg-success {
    border-color: #10b981 !important;
}

/* Typing indicator */
.cvg-typing-indicator {
    display: flex;
    align-items: center;
    padding: 0.5rem 0.75rem;
    color: #6b7280;
    font-size: 0.8rem;
    font-style: italic;
}

.cvg-typing-dots {
    display: inline-flex;
    margin-left: 0.5rem;
}

.cvg-typing-dots span {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background-color: #6b7280;
    margin: 0 1px;
    animation: cvgTyping 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; }

@keyframes cvgTyping {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}
