/* ============================================
   Premium Chat UI - Modern & Expensive Design
   ============================================ */

:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --secondary-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --dark-gradient: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    --glass-bg: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.2);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.2);
    --shadow-xl: 0 16px 64px rgba(0, 0, 0, 0.3);
    --text-primary: #1a1a1a;
    --text-secondary: #6b7280;
    --text-light: #9ca3af;
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --accent-color: #667eea;
    --success-color: #10b981;
    --error-color: #ef4444;
    --border-radius: 16px;
    --border-radius-lg: 24px;
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
    background-size: 400% 400%;
    animation: gradientShift 15s ease infinite;
    min-height: 100vh;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-md);
    overflow: hidden;
    margin: 0;
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Chat Modal */
.chat-modal {
    width: 100%;
    max-width: 480px;
    height: 90vh;
    max-height: 800px;
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--glass-border);
    overflow: hidden;
    animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

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

/* Header */
.chat-header {
    background: var(--primary-gradient);
    padding: var(--spacing-lg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-md);
    position: relative;
    z-index: 10;
    flex-shrink: 0;
}

.chat-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0) 100%);
    pointer-events: none;
}

.header-content {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    flex: 1;
}

.avatar-container {
    position: relative;
}

.avatar {
    width: 48px;
    height: 48px;
    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);
    color: white;
    transition: transform 0.3s ease;
}

.avatar:hover {
    transform: scale(1.05);
}

.avatar svg {
    width: 24px;
    height: 24px;
}

.status-indicator {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    background: var(--success-color);
    border: 2px solid white;
    border-radius: 50%;
    animation: pulse 2s ease-in-out infinite;
}

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

.header-info {
    flex: 1;
}

.agent-name {
    font-size: 18px;
    font-weight: 600;
    color: white;
    margin-bottom: 2px;
    letter-spacing: -0.02em;
}

.agent-status {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 400;
}

.close-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    position: relative;
    z-index: 1;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

.close-btn svg {
    width: 20px;
    height: 20px;
}

/* Messages Container */
.messages-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--spacing-lg);
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

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

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

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

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

/* Welcome Message */
.welcome-message {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    flex-shrink: 0;
}

.welcome-content {
    text-align: center;
    padding: var(--spacing-xl);
}

.welcome-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto var(--spacing-md);
    background: var(--primary-gradient);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: var(--shadow-md);
}

.welcome-icon svg {
    width: 32px;
    height: 32px;
}

.welcome-content h3 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--spacing-sm);
}

.welcome-content p {
    font-size: 15px;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* Message Bubbles */
.message {
    display: flex;
    margin-bottom: var(--spacing-md);
    animation: messageSlide 0.3s ease;
}

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

.message.user {
    justify-content: flex-end;
}

.message.assistant {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 75%;
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: var(--border-radius);
    position: relative;
    word-wrap: break-word;
    line-height: 1.5;
    font-size: 15px;
    box-shadow: var(--shadow-sm);
}

.message.user .message-bubble {
    background: var(--primary-gradient);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
    background: white;
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.message-time {
    font-size: 11px;
    color: var(--text-light);
    margin-top: var(--spacing-xs);
    opacity: 0.7;
}

.message.user .message-time {
    color: rgba(255, 255, 255, 0.8);
}

/* System Message */
.message.system {
    justify-content: center;
}

.message.system .message-bubble {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error-color);
    border: 1px solid rgba(239, 68, 68, 0.2);
    font-style: italic;
    font-size: 13px;
}

/* Loading Indicator */
.loading-indicator {
    display: flex;
    gap: 6px;
    padding: var(--spacing-md) var(--spacing-lg);
    background: white;
    border-radius: var(--border-radius);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(0, 0, 0, 0.05);
    max-width: 80px;
}

.loading-dot {
    width: 8px;
    height: 8px;
    background: var(--accent-color);
    border-radius: 50%;
    animation: loadingBounce 1.4s ease-in-out infinite;
}

.loading-dot:nth-child(1) { animation-delay: 0s; }
.loading-dot:nth-child(2) { animation-delay: 0.2s; }
.loading-dot:nth-child(3) { animation-delay: 0.4s; }

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

/* Input Container */
.input-container {
    background: white;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    padding: var(--spacing-md);
    box-shadow: 0 -2px 16px rgba(0, 0, 0, 0.05);
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: var(--spacing-sm);
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: var(--spacing-sm);
    border: 2px solid transparent;
    transition: all 0.3s ease;
}

.input-wrapper:focus-within {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.message-input {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    font-family: inherit;
    font-size: 15px;
    color: var(--text-primary);
    padding: var(--spacing-sm) var(--spacing-md);
    max-height: 120px;
    overflow-y: auto;
    outline: none;
    line-height: 1.5;
}

.message-input::placeholder {
    color: var(--text-light);
}

.send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-gradient);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.send-btn:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: var(--shadow-md);
}

.send-btn:active:not(:disabled) {
    transform: scale(0.95);
}

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

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

/* Stop Generating Button */
.stop-btn {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 20px;
    background: var(--error-color);
    border: none;
    color: white;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    transition: all 0.3s ease;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.stop-btn.visible {
    display: flex;
}

.stop-btn:hover {
    background: #dc2626;
    transform: scale(1.05);
    box-shadow: var(--shadow-md);
}

.stop-btn:active {
    transform: scale(0.95);
}

.stop-btn svg {
    width: 14px;
    height: 14px;
}

.stop-btn span {
    white-space: nowrap;
}

.input-footer {
    margin-top: var(--spacing-sm);
}

.config-inputs {
    display: flex;
    gap: var(--spacing-sm);
}

.config-input {
    flex: 1;
    padding: var(--spacing-xs) var(--spacing-sm);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    font-size: 12px;
    font-family: inherit;
    background: var(--bg-secondary);
    color: var(--text-primary);
    outline: none;
    transition: all 0.3s ease;
}

.config-input:focus {
    border-color: var(--accent-color);
    background: white;
}

.dynamic-vars-section {
    display: flex;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-sm);
}

.dynamic-vars-section .config-input {
    flex: 1;
}

.connect-btn {
    padding: var(--spacing-xs) var(--spacing-md);
    border: 1px solid var(--accent-color);
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    background: var(--accent-color);
    color: white;
    cursor: pointer;
    outline: none;
    transition: all 0.3s ease;
    white-space: nowrap;
    min-width: 80px;
}

.connect-btn:hover:not(:disabled) {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.connect-btn:active:not(:disabled) {
    transform: translateY(0);
}

.connect-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.connect-btn.connected {
    background: var(--error-color);
    border-color: var(--error-color);
}

.connect-btn.connected:hover:not(:disabled) {
    background: #dc2626;
    border-color: #dc2626;
}

.connect-btn-text {
    display: inline-block;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    margin-top: var(--spacing-xs);
    font-size: 11px;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    transition: background-color 0.3s ease;
}

.status-dot.connected {
    background-color: var(--success-color);
    box-shadow: 0 0 6px var(--success-color);
}

.status-dot.connecting {
    background-color: #f59e0b;
    animation: pulse 1.5s ease-in-out infinite;
}

.status-dot.disconnected {
    background-color: var(--error-color);
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.status-text {
    font-weight: 500;
}

.message-bubble.processing {
    font-style: italic;
    color: var(--text-secondary);
}

/* Open Chat Button */
.open-chat-btn {
    position: fixed;
    bottom: var(--spacing-lg);
    right: var(--spacing-lg);
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--primary-gradient);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
    transition: all 0.3s ease;
    z-index: 1000;
}

.open-chat-btn:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-xl);
}

.open-chat-btn svg {
    width: 28px;
    height: 28px;
}

.open-chat-btn.hidden {
    display: none;
}

/* Error Message */
.error-message {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error-color);
    padding: var(--spacing-md);
    border-radius: var(--border-radius);
    border: 1px solid rgba(239, 68, 68, 0.2);
    margin: var(--spacing-md) var(--spacing-lg);
    font-size: 14px;
    text-align: center;
}

/* Responsive Design */
@media (max-width: 640px) {
    .chat-modal {
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }

    .message-bubble {
        max-width: 85%;
    }

    .config-inputs {
        flex-direction: column;
    }
}

/* Smooth Transitions */
* {
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* Custom Scrollbar for Webkit */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

