/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #f1f5f9;
    --accent-color: #3b82f6;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --background: #ffffff;
    --background-secondary: #f8fafc;
    --border-color: #e2e8f0;
    --success-color: #10b981;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --border-radius: 8px;
    --transition: all 0.2s ease-in-out;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--background-secondary);
    min-height: 100vh;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 1200px;
    margin: 0 auto;
    background-color: var(--background);
    box-shadow: var(--shadow-lg);
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--accent-color) 100%);
    color: white;
    padding: 2rem 1.5rem;
    text-align: center;
}

.header-content {
    max-width: 800px;
    margin: 0 auto;
}

.title {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
    margin-bottom: 1rem;
}

.anycoder-link {
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    font-size: 0.9rem;
    padding: 0.5rem 1rem;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: var(--border-radius);
    transition: var(--transition);
    display: inline-block;
}

.anycoder-link:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.5);
}

/* Settings Panel */
.settings-panel {
    background-color: var(--background);
    border-bottom: 1px solid var(--border-color);
    padding: 1.5rem;
}

.settings-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    align-items: center;
    max-width: 800px;
    margin: 0 auto;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.setting-group label {
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.device-select,
.model-select {
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 0.9rem;
    background-color: var(--background);
    color: var(--text-primary);
    transition: var(--transition);
}

.device-select:focus,
.model-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.initialize-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: var(--border-radius);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    height: fit-content;
    align-self: end;
}

.initialize-btn:hover:not(:disabled) {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
}

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

/* Chat Container */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chat-messages {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    min-height: 400px;
    max-height: 600px;
}

/* Message Styles */
.message {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    animation: fadeInUp 0.3s ease-out;
}

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

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

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

.assistant-message .message-avatar,
.welcome-message .message-avatar {
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
}

.message-content {
    flex: 1;
    max-width: 70%;
}

.user-message .message-content {
    margin-left: auto;
    text-align: right;
}

.user-message .user-message,
.assistant-message .assistant-message,
.welcome-message .assistant-message {
    display: inline-block;
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius);
    font-size: 0.95rem;
    line-height: 1.5;
    word-wrap: break-word;
    max-width: 100%;
}

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

.assistant-message .assistant-message,
.welcome-message .assistant-message {
    background-color: var(--secondary-color);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.welcome-message {
    opacity: 0.8;
    font-style: italic;
}

/* Input Area */
.input-area {
    border-top: 1px solid var(--border-color);
    padding: 1.5rem;
    background-color: var(--background);
}

.input-container {
    display: flex;
    gap: 1rem;
    max-width: 800px;
    margin: 0 auto;
}

.message-input {
    flex: 1;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    resize: none;
    font-family: inherit;
    line-height: 1.5;
    transition: var(--transition);
    min-height: 50px;
    max-height: 120px;
}

.message-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.message-input:disabled {
    background-color: var(--background-secondary);
    color: var(--text-secondary);
    cursor: not-allowed;
}

.send-btn {
    width: 50px;
    height: 50px;
    border: none;
    border-radius: var(--border-radius);
    background-color: var(--primary-color);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
    background-color: var(--primary-hover);
    transform: scale(1.05);
}

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

.send-icon {
    font-size: 1.2rem;
    transform: rotate(45deg);
}

.input-status {
    margin-top: 0.75rem;
    text-align: center;
}

.status-text {
    font-size: 0.85rem;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    display: inline-block;
    transition: var(--transition);
}

.status-text.ready {
    background-color: rgba(16, 185, 129, 0.1);
    color: var(--success-color);
}

.status-text.loading,
.status-text.generating {
    background-color: rgba(59, 130, 246, 0.1);
    color: var(--accent-color);
}

.status-text.error {
    background-color: rgba(239, 68, 68, 0.1);
    color: var(--error-color);
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.loading-overlay.hidden {
    display: none;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

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

.loading-text {
    text-align: center;
    color: white;
}

.loading-text p {
    margin-bottom: 0.5rem;
}

.loading-tips {
    font-size: 0.9rem;
    opacity: 0.8;
}

/* Responsive Design */
@media (max-width: 768px) {
    .app-container {
        margin: 0;
        min-height: 100vh;
    }
    
    .header {
        padding: 1.5rem 1rem;
    }
    
    .title {
        font-size: 2rem;
    }
    
    .settings-panel {
        padding: 1rem;
    }
    
    .settings-content {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .chat-messages {
        padding: 1rem;
        min-height: 300px;
    }
    
    .message {
        margin-bottom: 1rem;
    }
    
    .message-content {
        max-width: 85%;
    }
    
    .input-area {
        padding: 1rem;
    }
    
    .input-container {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .send-btn {
        width: 100%;
        height: 45px;
    }
}

@media (max-width: 480px) {
    .title {
        font-size: 1.75rem;
    }
    
    .subtitle {
        font-size: 1rem;
    }
    
    .message-avatar {
        width: 35px;
        height: 35px;
        font-size: 1rem;
    }
    
    .message-content {
        max-width: 90%;
    }
    
    .user-message .user-message,
    .assistant-message .assistant-message {
        padding: 0.6rem 0.8rem;
        font-size: 0.9rem;
    }
}

/* Scrollbar Styling */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: var(--background-secondary);
}

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

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus styles for keyboard navigation */
button:focus,
select:focus,
textarea:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border-color: #000000;
        --text-secondary: #000000;
    }
}

This chatbot application includes:

**Features:**
- Modern, responsive design that works on all devices
- Real-time streaming responses using TextStreamer
- Multiple model support (Gemma 3 270M, Gemma 2 2B, Llama 3.2 1B)
- CPU/GPU toggle with WebGPU support detection
- Professional UI with smooth animations
- Error handling and loading states
- Accessibility features (keyboard navigation, screen reader support)
- Chat history with system prompts
- Auto-resizing text input
- Mobile-optimized interface

**Key Technical Features:**
- Uses the exact transformers.js import and pipeline setup you specified
- Implements TextStreamer for real-time response streaming
- Handles multiple ONNX models for different performance needs
- Proper error handling and user feedback
- Responsive design that adapts to all screen sizes
- Professional styling with CSS custom properties

The application initializes models on-demand, streams responses in real-time, and provides a clean chat interface similar to modern AI chatbots.