﻿/**
 * WebRTC Chat Widget - Streamlined CSS v4.1.0
 * Condensed and optimized styles
 */

/* ========== CSS Variables ========== */
:root {
    --webrtc-primary: #2563eb;
    --webrtc-primary-dark: #1d4ed8;
    --webrtc-success: #10b981;
    --webrtc-danger: #ef4444;
    --webrtc-warning: #f59e0b;
    --webrtc-white: #ffffff;
    --webrtc-gray-50: #f9fafb;
    --webrtc-gray-100: #f3f4f6;
    --webrtc-gray-200: #e5e7eb;
    --webrtc-gray-300: #d1d5db;
    --webrtc-gray-400: #9ca3af;
    --webrtc-gray-500: #6b7280;
    --webrtc-gray-600: #4b5563;
    --webrtc-gray-700: #374151;
    --webrtc-gray-800: #1f2937;
    --webrtc-gray-900: #111827;
    --webrtc-radius-sm: 6px;
    --webrtc-radius-md: 8px;
    --webrtc-radius-lg: 12px;
    --webrtc-radius-xl: 16px;
    --webrtc-radius-full: 50px;
    --webrtc-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --webrtc-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --webrtc-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --webrtc-shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    --webrtc-transition: all 0.2s ease-in-out;
    --webrtc-space-xs: 4px;
    --webrtc-space-sm: 8px;
    --webrtc-space-md: 16px;
    --webrtc-space-lg: 24px;
    --webrtc-space-xl: 32px;
}

/* ========== Widget Container ========== */
#webrtc-chat-widget {
    position: fixed;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    background: var(--webrtc-white);
    border-radius: var(--webrtc-radius-lg);
    box-shadow: var(--webrtc-shadow-xl);
    overflow: hidden;
    transition: var(--webrtc-transition);
    max-width: 380px;
    max-height: 600px;
    width: 380px;
    border: 1px solid var(--webrtc-gray-200);
}

/* Widget Positioning */
.webrtc-widget-bottom-right {
    bottom: 20px;
    right: 20px;
}

.webrtc-widget-bottom-left {
    bottom: 20px;
    left: 20px;
}

.webrtc-widget-top-right {
    top: 20px;
    right: 20px;
}

.webrtc-widget-top-left {
    top: 20px;
    left: 20px;
}

/* Minimized State */
#webrtc-chat-widget.minimized {
    height: 60px;
    width: 300px;
}

    #webrtc-chat-widget.minimized > *:not(#widget-header) {
        display: none !important;
    }

/* Notification Badge */
#webrtc-chat-widget.has-notification::after {
    content: '';
    position: absolute;
    top: -5px;
    right: -5px;
    width: 16px;
    height: 16px;
    background: var(--webrtc-danger);
    border-radius: var(--webrtc-radius-full);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.7;
        transform: scale(1.1);
    }
}

/* ========== Widget Header ========== */
#widget-header {
    background: linear-gradient(135deg, var(--webrtc-primary), var(--webrtc-primary-dark));
    color: var(--webrtc-white);
    padding: var(--webrtc-space-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: var(--webrtc-space-md);
    min-height: 60px;
    box-sizing: border-box;
}

    #widget-header:hover {
        background: linear-gradient(135deg, var(--webrtc-primary-dark), var(--webrtc-primary));
    }

#agent-avatar {
    display: flex;
    align-items: center;
    gap: var(--webrtc-space-sm);
    flex: 1;
}

.avatar-fallback {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: var(--webrtc-radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

#wave-indicator {
    font-size: 13px;
    opacity: 0.9;
    font-weight: 500;
}

/* ========== Connection Status ========== */
#connection-status {
    position: absolute;
    top: 5px;
    right: 10px;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: var(--webrtc-radius-sm);
    background: rgba(255, 255, 255, 0.2);
    color: var(--webrtc-white);
}

.status-connected {
    background: var(--webrtc-success) !important;
}

.status-disconnected {
    background: var(--webrtc-danger) !important;
}

/* ========== Chat Controls ========== */
#chat-controls {
    padding: var(--webrtc-space-lg);
    background: var(--webrtc-gray-50);
    display: flex;
    flex-direction: column;
    gap: var(--webrtc-space-md);
}

.chat-btn {
    padding: var(--webrtc-space-md) var(--webrtc-space-lg);
    border: none;
    border-radius: var(--webrtc-radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--webrtc-transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--webrtc-space-sm);
    min-height: 44px;
}

.video-btn {
    background: var(--webrtc-primary);
    color: var(--webrtc-white);
}

    .video-btn:hover {
        background: var(--webrtc-primary-dark);
        transform: translateY(-1px);
    }

.audio-btn {
    background: var(--webrtc-success);
    color: var(--webrtc-white);
}

    .audio-btn:hover {
        background: #059669;
        transform: translateY(-1px);
    }

.text-btn {
    background: var(--webrtc-gray-600);
    color: var(--webrtc-white);
}

    .text-btn:hover {
        background: var(--webrtc-gray-700);
        transform: translateY(-1px);
    }

/* ========== Video Container ========== */
#video-container {
    position: relative;
    background: var(--webrtc-gray-900);
    height: 300px;
    overflow: hidden;
}

#remote-video, #local-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#local-video {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 100px;
    height: 75px;
    border-radius: var(--webrtc-radius-md);
    border: 2px solid var(--webrtc-white);
    box-shadow: var(--webrtc-shadow-md);
}

#video-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
    padding: var(--webrtc-space-lg);
    display: flex;
    justify-content: center;
    gap: var(--webrtc-space-md);
}

.control-btn {
    width: 48px;
    height: 48px;
    border: none;
    border-radius: var(--webrtc-radius-full);
    background: rgba(255, 255, 255, 0.2);
    color: var(--webrtc-white);
    font-size: 18px;
    cursor: pointer;
    transition: var(--webrtc-transition);
    backdrop-filter: blur(10px);
}

    .control-btn:hover {
        background: rgba(255, 255, 255, 0.3);
        transform: scale(1.1);
    }

    .control-btn.hangup {
        background: var(--webrtc-danger);
    }

        .control-btn.hangup:hover {
            background: #dc2626;
        }

/* ========== Text Chat ========== */
#text-chat {
    height: 400px;
    display: flex;
    flex-direction: column;
}

#chat-messages {
    flex: 1;
    padding: var(--webrtc-space-md);
    overflow-y: auto;
    background: var(--webrtc-gray-50);
    border-bottom: 1px solid var(--webrtc-gray-200);
}

.chat-message {
    margin-bottom: var(--webrtc-space-md);
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: messageSlide 0.3s ease-out;
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.sent {
    align-self: flex-end;
}

    .chat-message.sent .message-content {
        background: var(--webrtc-primary);
        color: var(--webrtc-white);
        border-radius: var(--webrtc-radius-lg) var(--webrtc-radius-lg) var(--webrtc-radius-sm) var(--webrtc-radius-lg);
    }

.chat-message.received .message-content {
    background: var(--webrtc-white);
    color: var(--webrtc-gray-800);
    border: 1px solid var(--webrtc-gray-200);
    border-radius: var(--webrtc-radius-lg) var(--webrtc-radius-lg) var(--webrtc-radius-lg) var(--webrtc-radius-sm);
}

.message-content {
    padding: var(--webrtc-space-md);
    word-wrap: break-word;
    box-shadow: var(--webrtc-shadow-sm);
}

.message-time {
    font-size: 11px;
    color: var(--webrtc-gray-500);
    margin-top: var(--webrtc-space-xs);
    text-align: right;
}

.chat-message.received .message-time {
    text-align: left;
}

#chat-input-container {
    display: flex;
    padding: var(--webrtc-space-md);
    background: var(--webrtc-white);
    border-top: 1px solid var(--webrtc-gray-200);
    gap: var(--webrtc-space-sm);
}

#chat-input {
    flex: 1;
    padding: var(--webrtc-space-md);
    border: 1px solid var(--webrtc-gray-300);
    border-radius: var(--webrtc-radius-md);
    outline: none;
    font-size: 14px;
}

    #chat-input:focus {
        border-color: var(--webrtc-primary);
        box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    }

#send-message {
    padding: var(--webrtc-space-md) var(--webrtc-space-lg);
    background: var(--webrtc-primary);
    color: var(--webrtc-white);
    border: none;
    border-radius: var(--webrtc-radius-md);
    cursor: pointer;
    font-weight: 600;
    transition: var(--webrtc-transition);
    white-space: nowrap;
}

    #send-message:hover {
        background: var(--webrtc-primary-dark);
    }

/* ========== Agent Panel ========== */
#agent-panel {
    padding: var(--webrtc-space-lg);
    background: var(--webrtc-gray-50);
    border-top: 1px solid var(--webrtc-gray-200);
}

#queue-status {
    background: var(--webrtc-white);
    padding: var(--webrtc-space-md);
    border-radius: var(--webrtc-radius-md);
    margin-bottom: var(--webrtc-space-md);
    text-align: center;
    font-weight: 600;
    color: var(--webrtc-gray-700);
    border: 1px solid var(--webrtc-gray-200);
}

#queue-count {
    color: var(--webrtc-primary);
    font-size: 18px;
}

#agent-controls {
    background: var(--webrtc-white);
    padding: var(--webrtc-space-lg);
    border-radius: var(--webrtc-radius-md);
    margin-bottom: var(--webrtc-space-md);
    text-align: center;
    border: 1px solid var(--webrtc-gray-200);
    box-shadow: var(--webrtc-shadow-sm);
}

.call-info {
    margin-bottom: var(--webrtc-space-md);
    font-weight: 600;
    color: var(--webrtc-gray-700);
}

#accept-call, #decline-call {
    padding: var(--webrtc-space-md) var(--webrtc-space-xl);
    border: none;
    border-radius: var(--webrtc-radius-md);
    font-weight: 600;
    cursor: pointer;
    margin: 0 var(--webrtc-space-sm);
    transition: var(--webrtc-transition);
    min-width: 100px;
}

.accept-btn {
    background: var(--webrtc-success);
    color: var(--webrtc-white);
}

    .accept-btn:hover {
        background: #059669;
        transform: translateY(-1px);
    }

.decline-btn {
    background: var(--webrtc-danger);
    color: var(--webrtc-white);
}

    .decline-btn:hover {
        background: #dc2626;
        transform: translateY(-1px);
    }

#agent-status {
    background: var(--webrtc-white);
    padding: var(--webrtc-space-md);
    border-radius: var(--webrtc-radius-md);
    border: 1px solid var(--webrtc-gray-200);
}

#status-select {
    width: 100%;
    padding: var(--webrtc-space-md);
    border: 1px solid var(--webrtc-gray-300);
    border-radius: var(--webrtc-radius-md);
    font-size: 14px;
    background: var(--webrtc-white);
    cursor: pointer;
}

    #status-select:focus {
        outline: none;
        border-color: var(--webrtc-primary);
        box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    }

/* ========== Responsive Design ========== */
@media (max-width: 480px) {
    #webrtc-chat-widget {
        width: calc(100vw - 20px);
        max-width: 360px;
        right: 10px !important;
        left: 10px !important;
        margin: 0 auto;
    }

    .webrtc-widget-bottom-right,
    .webrtc-widget-bottom-left {
        bottom: 10px;
    }

    #video-container {
        height: 250px;
    }

    #local-video {
        width: 80px;
        height: 60px;
    }

    #text-chat {
        height: 350px;
    }
}

@media (max-height: 600px) {
    #webrtc-chat-widget {
        max-height: calc(100vh - 40px);
    }

    #video-container {
        height: 200px;
    }

    #text-chat {
        height: 250px;
    }
}

/* ========== Accessibility ========== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

button:focus,
input:focus,
select:focus {
    outline: 2px solid var(--webrtc-primary);
    outline-offset: 2px;
}

/* ========== Dark Theme Support ========== */
@media (prefers-color-scheme: dark) {
    .webrtc-theme-auto {
        --webrtc-white: #1f2937;
        --webrtc-gray-50: #111827;
        --webrtc-gray-100: #1f2937;
        --webrtc-gray-200: #374151;
        --webrtc-gray-300: #4b5563;
        --webrtc-gray-700: #d1d5db;
        --webrtc-gray-800: #f3f4f6;
        --webrtc-gray-900: #ffffff;
    }
}

/* ========== Theme Variants ========== */
.webrtc-theme-dark {
    --webrtc-white: #1f2937;
    --webrtc-gray-50: #111827;
    --webrtc-gray-100: #1f2937;
    --webrtc-gray-200: #374151;
    --webrtc-gray-300: #4b5563;
    --webrtc-gray-700: #d1d5db;
    --webrtc-gray-800: #f3f4f6;
    --webrtc-gray-900: #ffffff;
}

.webrtc-theme-minimal {
    box-shadow: var(--webrtc-shadow-md);
}

    .webrtc-theme-minimal #widget-header {
        background: var(--webrtc-gray-100);
        color: var(--webrtc-gray-800);
    }

/* ========== Animations ========== */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

#webrtc-chat-widget {
    animation: slideUp 0.3s ease-out;
}

.chat-message {
    animation: fadeIn 0.3s ease-out;
}

/* ========== Utility Classes ========== */
.hidden {
    display: none !important;
}

.invisible {
    visibility: hidden !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
