/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
}

/* Header */
.app-header {
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    color: white;
    padding: 1rem 1.5rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.header-content h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.device-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.device-toggle select {
    padding: 0.3rem 0.6rem;
    border: none;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 0.9rem;
    cursor: pointer;
}

.device-toggle select option {
    background: #333;
    color: white;
}

.anycoder-link {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    opacity: 0.9;
}

.anycoder-link a {
    color: #fbbf24;
    text-decoration: none;
    font-weight: 600;
}

.anycoder-link a:hover {
    text-decoration: underline;
}

/* Chat container */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    scroll-behavior: smooth;
}

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

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Welcome message */
.welcome-message {
    text-align: center;
    padding: 2rem 1rem;
    color: #666;
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    border-radius: 12px;
    margin-bottom: 1rem;
}

.welcome-message h2 {
    color: #4f46e5;
    margin-bottom: 0.5rem;
}

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

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

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

.user-message .message-avatar {
    background: #3b82f6;
    color: white;
}

.assistant-message .message-avatar {
    background: #10b981;
    color: white;
}

.message-content {
    flex: 1;
    min-width: 0;
}

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
    font-size: 0.85rem;
}

.message-role {
    font-weight: 600;
    color: #4f46e5;
}

.user-message .message-role {
    color: #3b82f6;
}

.message-time {
    color: #6b7280;
    font-size: 0.75rem;
}

.message-text {
    background: #f8fafc;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    line-height: 1.5;
    word-wrap: break-word;
    border: 1px solid #e2e8f0;
}

.user-message .message-text {
    background: #dbeafe;
    border-color: #bfdbfe;
}

.assistant-message .message-text {
    background: #d1fae5;
    border-color: #a7f3d0;
}

.message.streaming .message-text {
    background: #fef3c7;
    border-color: #fde68a;
    position: relative;
}

.message.streaming .message-text::after {
    content: '|';
    animation: blink 1s infinite;
    color: #f59e0b;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Input container */
.chat-input-container {
    padding: 1rem 1.5rem;
    background: white;
    border-top: 1px solid #e5e7eb;
}

.input-wrapper {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

#messageInput {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    font-size: 1rem;
    font-family: inherit;
    resize: none;
    min-height: 44px;
    max-height: 120px;
    outline: none;
    transition: border-color 0.2s ease;
}

#messageInput:focus {
    border-color: #4f46e5;
}

#messageInput:disabled {
    background: #f9fafb;
    color: #6b7280;
}

#sendButton {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    color: white;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

#sendButton:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

#sendButton:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.send-icon {
    transition: transform 0.2s ease;
}

#sendButton:not(:disabled):hover .send-icon {
    transform: translateX(2px);
}

.input-status {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: #6b7280;
    text-align: center;
}

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

.loading-content {
    background: white;
    padding: 2rem;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    max-width: 400px;
    margin: 1rem;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e5e7eb;
    border-top: 4px solid #4f46e5;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

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

.loading-text h3 {
    color: #374151;
    margin-bottom: 0.5rem;
}

.loading-text p {
    color: #6b7280;
    font-size: 0.9rem;
}

/* Error message */
.error-message {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.error-content {
    background: white;
    padding: 2rem;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    max-width: 400px;
    margin: 1rem;
    border: 2px solid #ef4444;
}

.error-content h3 {
    color: #dc2626;
    margin-bottom: 1rem;
}

.error-content p {
    color: #6b7280;
    margin-bottom: 1.5rem;
    line-height: 1.5;
}

.error-content button {
    background: #ef4444;
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.2s ease;
}

.error-content button:hover {
    background: #dc2626;
}

/* Responsive design */
@media (max-width: 768px) {
    .app-container {
        height: 100vh;
        border-radius: 0;
    }
    
    .app-header {
        padding: 1rem;
    }
    
    .header-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .header-content h1 {
        font-size: 1.25rem;
    }
    
    .chat-messages {
        padding: 0.75rem;
    }
    
    .chat-input-container {
        padding: 0.75rem 1rem;
    }
    
    .message {
        margin-bottom: 0.75rem;
    }
    
    .message-avatar {
        width: 35px;
        height: 35px;
        font-size: 1rem;
    }
    
    .message-text {
        padding: 0.6rem 0.8rem;
        font-size: 0.95rem;
    }
    
    .welcome-message {
        padding: 1.5rem 1rem;
    }
    
    .welcome-message h2 {
        font-size: 1.25rem;
    }
    
    .loading-content,
    .error-content {
        margin: 1rem;
        padding: 1.5rem;
    }
}

@media (max-width: 480px) {
    .device-toggle {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }
    
    .device-toggle select {
        min-width: 120px;
    }
    
    .message {
        gap: 0.5rem;
    }
    
    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 0.9rem;
    }
    
    .message-text {
        padding: 0.5rem 0.7rem;
        font-size: 0.9rem;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .message-text {
        border-width: 2px;
    }
    
    #messageInput {
        border-width: 2px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .chat-messages {
        scroll-behavior: auto;
    }
}

/* Focus indicators for accessibility */
button:focus,
select:focus,
textarea:focus {
    outline: 2px solid #4f46e5;
    outline-offset: 2px;
}

/* Print styles */
@media print {
    .app-header,
    .chat-input-container,
    .loading-overlay,
    .error-message {
        display: none;
    }
    
    .chat-messages {
        overflow: visible;
        height: auto;
    }
    
    .message {
        break-inside: avoid;
        margin-bottom: 1rem;
    }
}