/**
 * ServiceLink Virtual Agent Widget Styles
 * Production-ready CSS with responsive design
 * Compatible with existing ServiceLink theme
 */

/* Widget Container */
.va-widget {
    position: fixed;
    z-index: 10000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    color: #333;
}

/* Position variants */
.va-position-bottom-right {
    bottom: 20px;
    right: 20px;
}

.va-position-bottom-left {
    bottom: 20px;
    left: 20px;
}

.va-position-top-right {
    top: 20px;
    right: 20px;
}

.va-position-top-left {
    top: 20px;
    left: 20px;
}

/* Toggle Button */
.va-toggle-button {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
    position: relative;
    border: none;
    outline: none;
}

.va-toggle-button:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.va-toggle-button:active {
    transform: scale(0.95);
}

.va-toggle-button .va-icon {
    width: 28px;
    height: 28px;
    color: white;
    object-fit: contain;
}

/* Pulse animation for notification */
.va-pulse {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: rgba(102, 126, 234, 0.3);
    animation: va-pulse-animation 2s infinite;
    pointer-events: none;
    opacity: 0;
}

@keyframes va-pulse-animation {
    0% {
        opacity: 1;
        transform: scale(1);
    }
    100% {
        opacity: 0;
        transform: scale(1.4);
    }
}

/* Chat Container */
.va-chat-container {
    width: 380px;
    height: 500px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.08);
}

/* Header */
.va-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 12px 12px 0 0;
}

.va-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    flex: 1;
}

.va-title .va-icon {
    width: 20px;
    height: 20px;
    object-fit: contain;
}

.va-status {
    font-size: 12px;
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: auto;
    margin-right: 12px;
}

.va-controls {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-shrink: 0;
}

.va-minimize-button,
.va-close-button {
    width: 28px;
    height: 28px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 6px;
    color: white;
    cursor: pointer;
    display: flex !important;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    padding: 0;
    margin: 0;
    outline: none;
}

.va-minimize-button:hover,
.va-close-button:hover {
    background: rgba(255, 255, 255, 0.25);
}

.va-minimize-button svg,
.va-close-button svg {
    width: 16px;
    height: 16px;
}

/* Messages Container */
.va-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.va-messages::-webkit-scrollbar {
    width: 6px;
}

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

.va-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
}

.va-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.2);
}

/* Message Styles */
.va-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: va-message-appear 0.3s ease;
}

@keyframes va-message-appear {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.va-message-user {
    align-self: flex-end;
}

.va-message-assistant {
    align-self: flex-start;
}

.va-message-error {
    align-self: center;
    max-width: 90%;
}

.va-message-content {
    padding: 10px 14px;
    border-radius: 18px;
    word-wrap: break-word;
    line-height: 1.4;
}

.va-message-user .va-message-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 6px;
}

.va-message-assistant .va-message-content {
    background: #f1f3f5;
    color: #333;
    border-bottom-left-radius: 6px;
}

.va-message-error .va-message-content {
    background: #ffe8e8;
    color: #d63031;
    border: 1px solid #fab1a0;
    text-align: center;
    font-size: 13px;
}

.va-message-time {
    font-size: 11px;
    color: #666;
    margin-top: 4px;
    padding: 0 4px;
}

.va-message-user .va-message-time {
    text-align: right;
}

.va-message-assistant .va-message-time {
    text-align: left;
}

/* Message content formatting */
.va-message-content strong {
    font-weight: 600;
}

.va-message-content em {
    font-style: italic;
}

.va-message-content code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 4px;
    border-radius: 3px;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-size: 12px;
}

/* Typing Indicator */
.va-typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
    animation: va-typing-appear 0.3s ease;
}

@keyframes va-typing-appear {
    from {
        opacity: 0;
        height: 0;
    }
    to {
        opacity: 1;
        height: auto;
    }
}

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

.va-typing-dots span {
    width: 6px;
    height: 6px;
    background: #666;
    border-radius: 50%;
    animation: va-typing-dot 1.4s infinite ease-in-out;
}

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

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

@keyframes va-typing-dot {
    0%, 80%, 100% {
        opacity: 0.3;
        transform: scale(1);
    }
    40% {
        opacity: 1;
        transform: scale(1.2);
    }
}

.va-typing-text {
    font-size: 12px;
    color: #666;
    font-style: italic;
}

/* Input Container */
.va-input-container {
    padding: 16px;
    border-top: 1px solid #e9ecef;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: #fafbfc;
}

.va-input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: border-color 0.2s ease;
    max-height: 120px;
    min-height: 40px;
    background: white;
}

.va-input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

.va-input::placeholder {
    color: #999;
}

.va-send-button {
    width: 40px;
    height: 40px;
    background: #e9ecef;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.va-send-button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.va-send-button.va-enabled {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.va-send-button.va-enabled:hover {
    transform: scale(1.05);
}

.va-send-button svg {
    width: 18px;
    height: 18px;
}

/* Suggestions */
.va-suggestions {
    padding: 12px 16px 0;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    background: #fafbfc;
    border-top: 1px solid #e9ecef;
}

.va-suggestion {
    background: white;
    border: 1px solid #ddd;
    border-radius: 16px;
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.va-suggestion:hover {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

/* Theme Variations */
.va-theme-dark {
    color: #e9ecef;
}

.va-theme-dark .va-chat-container {
    background: #2c3e50;
    border-color: #34495e;
}

.va-theme-dark .va-message-assistant .va-message-content {
    background: #34495e;
    color: #e9ecef;
}

.va-theme-dark .va-input-container {
    background: #34495e;
    border-color: #4a5f7a;
}

.va-theme-dark .va-input {
    background: #2c3e50;
    border-color: #4a5f7a;
    color: #e9ecef;
}

.va-theme-dark .va-input::placeholder {
    color: #95a5a6;
}

.va-theme-dark .va-typing-indicator {
    background: #34495e;
    border-color: #4a5f7a;
}

/* Compact Theme */
.va-theme-compact .va-chat-container {
    width: 320px;
    height: 400px;
}

.va-theme-compact .va-header {
    padding: 12px 16px;
}

.va-theme-compact .va-messages {
    padding: 12px;
    gap: 8px;
}

.va-theme-compact .va-input-container {
    padding: 12px;
}

/* Mobile Responsiveness */
@media (max-width: 480px) {
    .va-chat-container {
        width: calc(100vw - 40px);
        max-width: 380px;
        height: 60vh;
        max-height: 500px;
    }
    
    .va-widget.va-position-bottom-right,
    .va-widget.va-position-bottom-left {
        right: 20px;
        left: 20px;
        bottom: 20px;
    }
    
    .va-toggle-button {
        width: 56px;
        height: 56px;
    }
    
    .va-toggle-button .va-icon {
        width: 24px;
        height: 24px;
    }
}

@media (max-width: 320px) {
    .va-chat-container {
        width: calc(100vw - 20px);
        height: 70vh;
    }
    
    .va-widget.va-position-bottom-right,
    .va-widget.va-position-bottom-left {
        right: 10px;
        left: 10px;
        bottom: 10px;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .va-toggle-button {
        border: 2px solid white;
    }
    
    .va-chat-container {
        border: 2px solid #333;
    }
    
    .va-message-assistant .va-message-content {
        border: 1px solid #666;
    }
    
    .va-input {
        border-width: 2px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .va-toggle-button,
    .va-send-button,
    .va-suggestion,
    .va-message {
        animation: none;
        transition: none;
    }
    
    .va-pulse {
        animation: none;
    }
    
    .va-typing-dots span {
        animation: none;
    }
}

/* Print styles */
@media print {
    .va-widget {
        display: none !important;
    }
}

/* Focus indicators for accessibility */
.va-toggle-button:focus-visible,
.va-send-button:focus-visible,
.va-minimize-button:focus-visible,
.va-close-button:focus-visible,
.va-suggestion:focus-visible {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

.va-input:focus-visible {
    outline: 2px solid #667eea;
    outline-offset: -2px;
}

/* Custom scrollbar for Firefox */
.va-messages {
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.1) transparent;
}

/* Error states */
.va-widget.va-error .va-toggle-button {
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
}

.va-widget.va-offline .va-status {
    background: #e74c3c;
}

.va-widget.va-offline .va-status::before {
    content: "Offline";
}

/* Loading states */
.va-widget.va-loading .va-toggle-button {
    animation: va-loading-spin 1s linear infinite;
}

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