/* CSS Variables for Theme Management */
:root {
    --primary-bg: #0f0f23;
    --secondary-bg: #1a1a2e;
    --tertiary-bg: #16213e;
    --accent-color: #00d4ff;
    --accent-hover: #00b8e6;
    --text-primary: #ffffff;
    --text-secondary: #b3b3b3;
    --text-muted: #666666;
    --border-color: #2d2d44;
    --success-color: #00ff88;
    --error-color: #ff4757;
    --warning-color: #ffa502;
    --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-secondary: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --gradient-accent: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    --shadow-light: 0 2px 10px rgba(0, 212, 255, 0.1);
    --shadow-medium: 0 4px 20px rgba(0, 212, 255, 0.15);
    --shadow-heavy: 0 8px 30px rgba(0, 212, 255, 0.2);
    --border-radius: 12px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light Theme */
[data-theme="light"] {
    --primary-bg: #ffffff;
    --secondary-bg: #f8f9fa;
    --tertiary-bg: #e9ecef;
    --text-primary: #212529;
    --text-secondary: #495057;
    --text-muted: #6c757d;
    --border-color: #dee2e6;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--primary-bg);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
}

/* App Container */
.app-container {
    display: flex;
    height: 100vh;
    position: relative;
}

/* Sidebar Styles */
.sidebar {
    width: 280px;
    background: var(--secondary-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 10;
    transition: var(--transition);
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.logo i {
    font-size: 28px;
    background: var(--gradient-accent);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.logo h1 {
    font-size: 24px;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.new-chat-btn {
    width: 100%;
    padding: 12px 16px;
    background: var(--gradient-accent);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: var(--transition);
    box-shadow: var(--shadow-light);
}

.new-chat-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

.chat-history {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}

.history-section h3 {
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chat-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-item {
    padding: 12px 16px;
    background: var(--tertiary-bg);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    border-left: 3px solid transparent;
}

.chat-item:hover {
    background: var(--border-color);
    border-left-color: var(--accent-color);
    transform: translateX(4px);
}

.chat-item.active {
    background: var(--border-color);
    border-left-color: var(--accent-color);
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--border-color);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    background: var(--gradient-secondary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-weight: 500;
    color: var(--text-primary);
}

.user-status {
    font-size: 12px;
    color: var(--success-color);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--primary-bg);
}

.chat-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--secondary-bg);
}

.chat-title h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

.chat-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
}

.chat-controls {
    display: flex;
    gap: 12px;
}

.control-btn {
    width: 40px;
    height: 40px;
    background: var(--tertiary-bg);
    border: none;
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.control-btn:hover {
    background: var(--accent-color);
    color: white;
    transform: scale(1.1);
}

.control-btn.active {
    background: var(--accent-color);
    color: white;
}

.control-btn.audio-active {
    background: var(--success-color);
    color: white;
    animation: audio-pulse 2s infinite;
}

@keyframes audio-pulse {
    0%, 100% { 
        box-shadow: 0 0 0 0 rgba(0, 255, 136, 0.7);
    }
    50% { 
        box-shadow: 0 0 0 8px rgba(0, 255, 136, 0);
    }
}

/* Chat Container */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    scroll-behavior: smooth;
}

/* Welcome Message */
.welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    max-width: 600px;
    margin: 0 auto;
}

.welcome-icon {
    width: 80px;
    height: 80px;
    background: var(--gradient-accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
    box-shadow: var(--shadow-medium);
}

.welcome-icon i {
    font-size: 36px;
    color: white;
}

.welcome-message h2 {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 12px;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-message p {
    font-size: 18px;
    color: var(--text-secondary);
    margin-bottom: 32px;
    line-height: 1.6;
}

.suggested-prompts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
    width: 100%;
    max-width: 800px;
}

.prompt-btn {
    padding: 16px 20px;
    background: var(--secondary-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    font-size: 14px;
    line-height: 1.4;
}

.prompt-btn:hover {
    background: var(--tertiary-bg);
    border-color: var(--accent-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-light);
}

.prompt-btn i {
    color: var(--accent-color);
    font-size: 16px;
}

/* Message Styles */
.message {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
    opacity: 0;
    animation: fadeInUp 0.5s ease forwards;
}

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

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 16px;
    color: white;
}

.user-message .message-avatar {
    background: var(--gradient-secondary);
}

.ai-message .message-avatar {
    background: var(--gradient-accent);
}

.message-content {
    flex: 1;
    background: var(--secondary-bg);
    border-radius: var(--border-radius);
    padding: 16px 20px;
    border-left: 3px solid transparent;
    transition: var(--transition);
}

.user-message .message-content {
    background: var(--gradient-primary);
    color: white;
    margin-left: auto;
    border-left-color: var(--accent-color);
}

.ai-message .message-content {
    border-left-color: var(--accent-color);
}

.message-content:hover {
    box-shadow: var(--shadow-light);
}

.message-text {
    line-height: 1.6;
    word-wrap: break-word;
}

.message-time {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 8px;
    opacity: 0.7;
}

.audio-control {
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.audio-replay-btn {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    font-size: 12px;
    transition: var(--transition);
}

.audio-replay-btn:hover {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.control-btn.speaking {
    animation: speaking-pulse 1s infinite;
}

@keyframes speaking-pulse {
    0%, 100% { 
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(0, 255, 136, 0.7);
    }
    50% { 
        transform: scale(1.05);
        box-shadow: 0 0 0 6px rgba(0, 255, 136, 0);
    }
}

/* Input Container */
.input-container {
    padding: 24px;
    background: var(--secondary-bg);
    border-top: 1px solid var(--border-color);
}

.input-wrapper {
    max-width: 800px;
    margin: 0 auto;
    position: relative;
    background: var(--primary-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    overflow: hidden;
    transition: var(--transition);
}

.input-wrapper:focus-within {
    border-color: var(--accent-color);
    box-shadow: var(--shadow-light);
}

#messageInput {
    width: 100%;
    padding: 16px 100px 16px 20px;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 16px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    min-height: 52px;
}

#messageInput::placeholder {
    color: var(--text-muted);
}

.voice-btn {
    position: absolute;
    right: 54px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    background: var(--tertiary-bg);
    border: none;
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.voice-btn:hover {
    background: var(--accent-color);
    color: white;
    transform: translateY(-50%) scale(1.1);
}

.voice-btn.recording {
    background: var(--error-color);
    color: white;
    animation: pulse-recording 1.5s infinite;
}

.voice-btn.processing {
    background: var(--warning-color);
    color: white;
}

@keyframes pulse-recording {
    0%, 100% { 
        box-shadow: 0 0 0 0 rgba(255, 71, 87, 0.7);
    }
    50% { 
        box-shadow: 0 0 0 10px rgba(255, 71, 87, 0);
    }
}

.send-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    background: var(--gradient-accent);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-btn:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
    opacity: 0.5;
}

.send-btn:not(:disabled):hover {
    transform: translateY(-50%) scale(1.1);
    box-shadow: var(--shadow-medium);
}

.input-footer {
    text-align: center;
    margin-top: 12px;
}

.disclaimer {
    font-size: 12px;
    color: var(--text-muted);
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 15, 35, 0.8);
    backdrop-filter: blur(10px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-overlay.active {
    display: flex;
}

.loading-spinner {
    text-align: center;
    color: var(--text-primary);
}

.spinner {
    width: 50px;
    height: 50px;
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-spinner p {
    font-size: 16px;
    color: var(--text-secondary);
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--secondary-bg);
    border-radius: var(--border-radius);
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-heavy);
    border: 1px solid var(--border-color);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.close-btn {
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 50%;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    background: var(--error-color);
    color: white;
}

.modal-body {
    padding: 24px;
}

.setting-item {
    margin-bottom: 20px;
}

.setting-item label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-primary);
}

.setting-item select,
.setting-item input[type="range"] {
    width: 100%;
    padding: 8px 12px;
    background: var(--primary-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    color: var(--text-primary);
    font-family: inherit;
}

.setting-item input[type="range"] {
    padding: 0;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px 20px;
    background: var(--secondary-bg);
    border-radius: var(--border-radius);
    margin: 16px 0;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

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

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

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Error Message Styles */
.message.ai-message .message-content.error {
    border-left-color: var(--error-color);
    background: rgba(255, 71, 87, 0.1);
}

.connection-warning {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--warning-color);
    color: white;
    padding: 16px;
    border-radius: var(--border-radius);
    z-index: 1000;
    font-size: 14px;
    max-width: 400px;
    box-shadow: var(--shadow-medium);
    display: flex;
    align-items: flex-start;
    gap: 12px;
    animation: slideInRight 0.3s ease-out;
    line-height: 1.4;
}

.warning-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.warning-title {
    font-weight: 600;
    font-size: 15px;
}

.warning-details {
    font-size: 13px;
    opacity: 0.9;
}

.warning-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 2px;
    border-radius: 2px;
    opacity: 0.7;
    transition: var(--transition);
}

.warning-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.2);
}

/* Retry Notification */
.retry-notification {
    position: fixed;
    bottom: 100px;
    right: 20px;
    background: var(--accent-color);
    color: white;
    padding: 12px 16px;
    border-radius: var(--border-radius);
    z-index: 1000;
    font-size: 14px;
    box-shadow: var(--shadow-medium);
    animation: slideInRight 0.3s ease-out;
}

.retry-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.retry-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.retry-title {
    font-weight: 600;
    font-size: 14px;
}

.retry-details {
    font-size: 12px;
    opacity: 0.9;
}

.retry-notification i {
    font-size: 16px;
    color: white;
}

.connection-warning i {
    font-size: 16px;
}

/* Status Indicators */
.status-indicator {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 8px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: var(--transition);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.status-indicator:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

.status-indicator.online {
    background: rgba(0, 255, 136, 0.9);
    color: white;
}

.status-indicator.offline {
    background: rgba(255, 71, 87, 0.9);
    color: white;
}

.status-indicator.fallback {
    background: rgba(255, 165, 2, 0.9);
    color: white;
}

.status-indicator.checking {
    background: rgba(0, 212, 255, 0.9);
    color: white;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    animation: pulse 2s infinite;
}

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

/* Responsive Design */
@media (max-width: 768px) {
    .sidebar {
        width: 250px;
        transform: translateX(-100%);
        position: absolute;
        height: 100%;
        z-index: 100;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .suggested-prompts {
        grid-template-columns: 1fr;
    }
    
    .message {
        margin-left: 0;
        margin-right: 0;
    }
    
    .input-container {
        padding: 16px;
    }
}

@media (max-width: 480px) {
    .chat-header {
        padding: 16px 20px;
    }
    
    .messages-container {
        padding: 16px;
    }
    
    .welcome-message h2 {
        font-size: 24px;
    }
    
    .welcome-message p {
        font-size: 16px;
    }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--secondary-bg);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-color);
}

/* Selection Styles */
::selection {
    background: var(--accent-color);
    color: white;
}

/* Focus Styles */
*:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* High Performance Optimizations */
.messages-container {
    contain: layout style paint;
    will-change: scroll-position;
}

.message {
    contain: layout style paint;
}

.sidebar {
    contain: layout style paint;
}

/* Animations */
@keyframes slideInLeft {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.sidebar {
    animation: slideInLeft 0.3s ease-out;
}

.main-content {
    animation: slideInRight 0.3s ease-out;
}