:root {
    /* Professional Color Palette */
    --primary-blue: #2563eb;
    --primary-blue-light: #3b82f6;
    --primary-blue-dark: #1d4ed8;
    --secondary-teal: #0d9488;
    --secondary-teal-light: #14b8a6;
    --accent-purple: #7c3aed;
    --accent-orange: #ea580c;
    
    /* Grays */
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    
    /* Glass effect */
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-hover: rgba(255, 255, 255, 0.08);
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px 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);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    
    /* Border radius */
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    
    /* Sidebar */
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 60px;
}

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

html {
    background: #0a0a0a;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0a0a0a;
    background-attachment: fixed;
    min-height: 100vh;
    overflow: hidden;
    color: white;
}

/* iOS Status Bar Fix */
.ios-status-bar-fix {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: env(safe-area-inset-top);
    background: #0a0a0a;
    z-index: 1400;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #0a0a0a;
    pointer-events: none;
    z-index: -1;
}

/* Main Layout */
.chat-app {
    display: flex;
    height: 100vh;
    overflow: hidden;
    position: relative;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 2000;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    transform: translateX(-100%);
}

/* Desktop: sidebar always visible */
@media (min-width: 769px) {
    .sidebar {
        transform: translateX(0);
    }
}

/* Mobile: sidebar hidden by default */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
}

/* Sidebar Overlay */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 1999;
}

/* Only show overlay on mobile */
@media (max-width: 768px) {
    .sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
    }
}

/* Hide overlay on desktop */
@media (min-width: 769px) {
    .sidebar-overlay {
        display: none;
    }
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

.sidebar-header {
    padding: 8px 20px;
    min-height: 70px;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-close-btn {
    background: transparent;
    border: none;
    color: var(--gray-400);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
    display: none; /* Hidden by default */
}

@media (max-width: 768px) {
    .sidebar-close-btn {
        display: flex;
    }
}

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

.new-chat-btn {
    flex: 1;
    background: var(--primary-blue);
    border: none;
    border-radius: var(--radius-lg);
    padding: 0 14.91px;
    height: 2.4rem;
    color: white;
    font-weight: 600;
    font-size: 0.885rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7.45px;
    box-shadow: var(--shadow-md);
}

.new-chat-btn:hover {
    background: var(--primary-blue-light);
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

.new-chat-btn:active {
    transform: translateY(0);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.sidebar-section h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-300);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.chat-threads {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chat-thread {
    padding: 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    background: transparent;
    border: 1px solid transparent;
    color: var(--gray-200);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-thread:hover {
    background: var(--glass-hover);
    border-color: var(--glass-border);
}

.chat-thread.active {
    background: var(--glass-hover);
    border-color: var(--primary-blue);
    color: white;
}

.chat-thread-icon {
    font-size: 0.8rem;
    opacity: 0.7;
    flex-shrink: 0;
}

.chat-thread-content {
    flex: 1;
    min-width: 0; /* Allow content to shrink */
}

.chat-thread-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.chat-thread-date {
    font-size: 0.75rem;
    color: var(--gray-400);
}

.chat-thread-actions {
    display: flex;
    align-items: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.chat-thread:hover .chat-thread-actions {
    opacity: 1;
}

.delete-thread-btn {
    background: transparent;
    border: none;
    color: var(--gray-400);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.delete-thread-btn:hover {
    color: var(--accent-orange);
    background: rgba(234, 88, 12, 0.1);
}

.sidebar-footer {
    padding: 10px 20px;
    border-top: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    gap: 5px;
    height: 140px;
    box-sizing: border-box;
}

.sidebar-model-selector {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 4px;
}

.sidebar-model-selector label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--gray-300);
    margin-bottom: 4px;
}

.sidebar-model-selector input {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    color: white;
    font-size: 0.85rem;
    width: 100%;
    transition: all 0.2s ease;
    font-family: 'Inter', sans-serif;
}

.sidebar-model-selector input:focus {
    outline: none;
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.sidebar-model-selector input::placeholder {
    color: var(--gray-400);
}

.upload-btn {
    width: 100%;
    background: var(--primary-blue);
    border: none;
    border-radius: var(--radius-md);
    padding: 0 12px;
    height: 70px;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    box-shadow: var(--shadow-md);
    position: relative;
    overflow: hidden;
}

.upload-btn:hover {
    background: var(--primary-blue-light);
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

.footer-actions {
    display: flex;
    gap: 8px;
}

.dashboard-btn, .settings-btn {
    flex: 1;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 0 10px;
    height: 40px;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 0.85rem;
}

.dashboard-btn:hover, .settings-btn:hover {
    background: var(--glass-hover);
    transform: translateY(-1px);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Desktop: always respect sidebar width */
@media (min-width: 769px) {
    .main-content {
        margin-left: var(--sidebar-width);
    }
}

/* Mobile: no margin */
@media (max-width: 768px) {
    .main-content {
        margin-left: 0;
    }
}

/* Header */
.chat-header {
    display: flex;
    align-items: center;
    padding: 16px 24px;
    background: #0a0a0a;
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--glass-border);
    min-height: 70px;
    position: relative;
    z-index: 1000;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: white;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
}

/* Hide sidebar toggle on desktop */
@media (min-width: 769px) {
    .sidebar-toggle {
        display: none;
    }
}

.sidebar-toggle:hover {
    background: var(--glass-hover);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1.2rem;
    color: white;
}

.logo i {
    font-size: 1.4rem;
    color: var(--accent-orange);
}

.header-center {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
}

.current-thread-title {
    font-weight: 600;
    font-size: 1rem;
    color: var(--gray-200);
    text-align: center;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.model-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--gray-300);
    font-size: 0.85rem;
    font-weight: 500;
}

.model-selector input {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 8px 12px;
    color: white;
    font-size: 0.85rem;
    min-width: 180px;
    transition: all 0.2s ease;
}

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

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    scrollbar-width: thin;
    scrollbar-color: var(--glass-border) transparent;
    position: relative;
}

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

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

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

.message {
    display: flex;
    margin-bottom: 24px;
    animation: messageSlideIn 0.4s ease-out;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    flex-shrink: 0;
    font-size: 0.9rem;
}

.user-message {
    flex-direction: row-reverse;
}

.user-message .message-avatar {
    background: var(--primary-blue);
    color: white;
    margin-left: 12px;
    margin-right: 0;
}

.assistant-message .message-avatar {
    background: var(--secondary-teal);
    color: white;
}

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

.user-message .message-content {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.message-bubble {
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    margin-bottom: 6px;
    line-height: 1.6;
    font-size: 0.95rem;
    word-wrap: break-word;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
}

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

.assistant-message .message-bubble {
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    color: white;
    border-bottom-left-radius: var(--radius-sm);
}

.message-bubble:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.message-timestamp {
    font-size: 0.75rem;
    color: var(--gray-400);
    margin-top: 4px;
}

.user-message .message-timestamp {
    text-align: right;
}

/* Thinking Indicator */
.thinking-indicator {
    position: fixed;
    bottom: 140px;
    left: calc(var(--sidebar-width) + 24px);
    right: 24px;
    pointer-events: none;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
    z-index: 5;
}

.thinking-indicator.show {
    opacity: 1;
    transform: translateY(0);
}

/* Inline thinking indicator for streaming */
.thinking-indicator-inline {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    color: var(--gray-400);
}

.thinking-text-inline {
    font-weight: 500;
    color: var(--secondary-teal-light);
    font-size: 0.9rem;
}

.thinking-tooth {
    animation: thinkingPulse 2s ease-in-out infinite;
}

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

.thinking-text {
    font-weight: 500;
    color: var(--secondary-teal-light);
}

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

.thinking-dots .thinking-dot {
    width: 6px;
    height: 6px;
    background: var(--secondary-teal-light);
    border-radius: 50%;
    animation: thinkingDots 1.4s ease-in-out infinite;
}

.thinking-dots .thinking-dot:nth-child(1) { animation-delay: -0.32s; }
.thinking-dots .thinking-dot:nth-child(2) { animation-delay: -0.16s; }
.thinking-dots .thinking-dot:nth-child(3) { animation-delay: 0s; }

.thinking-dots span {
    width: 6px;
    height: 6px;
    background: var(--secondary-teal-light);
    border-radius: 50%;
    animation: thinkingDots 1.4s ease-in-out infinite;
}

.thinking-dots span:nth-child(1) { animation-delay: -0.32s; }
.thinking-dots span:nth-child(2) { animation-delay: -0.16s; }
.thinking-dots span:nth-child(3) { animation-delay: 0s; }

/* File Preview */
.file-preview-area {
    padding: 0 24px;
    margin-bottom: 16px;
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    transition: all 0.3s ease;
}

.file-preview-area.show {
    opacity: 1;
    max-height: 200px;
    margin-bottom: 16px;
}

.file-preview {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
    transition: all 0.2s ease;
}

.file-preview:hover {
    background: var(--glass-hover);
}

.file-preview .file-icon {
    width: 32px;
    height: 32px;
    background: var(--accent-purple);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.9rem;
}

.file-preview .file-info {
    flex: 1;
}

.file-preview .file-name {
    font-weight: 500;
    font-size: 0.9rem;
    color: white;
    margin-bottom: 2px;
}

.file-preview .file-size {
    font-size: 0.75rem;
    color: var(--gray-400);
}

.file-preview .remove-file {
    background: none;
    border: none;
    color: var(--gray-400);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
}

.file-preview .remove-file:hover {
    color: var(--accent-orange);
    background: rgba(234, 88, 12, 0.2);
}

/* Input Area */
.chat-input-container {
    padding: 24px;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--glass-border);
    height: 140px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.input-area {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xl);
    padding: 16px;
    transition: all 0.2s ease;
}

.input-area:focus-within {
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.file-upload-btn {
    background: none;
    border: none;
    color: var(--gray-400);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
    font-size: 1.1rem;
}

.file-upload-btn:hover {
    color: var(--primary-blue-light);
    background: rgba(37, 99, 235, 0.1);
}

.text-input-section {
    flex: 1;
}

#message-input {
    width: 100%;
    background: none;
    border: none;
    color: white;
    font-size: 0.95rem;
    line-height: 1.5;
    resize: none;
    outline: none;
    font-family: inherit;
    max-height: 120px;
}

#message-input::placeholder {
    color: var(--gray-400);
}

.send-section {
    display: flex;
    gap: 8px;
}

.cancel-btn, .send-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.cancel-btn {
    background: var(--accent-orange);
    color: white;
}

.cancel-btn:hover {
    background: #dc2626;
    transform: scale(1.05);
}

.send-btn {
    background: var(--primary-blue);
    color: white;
}

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

.send-btn:disabled {
    background: var(--gray-600);
    cursor: not-allowed;
    transform: none;
}

/* Quick Actions */
.quick-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.quick-action {
    background: none;
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 8px 12px;
    color: var(--gray-300);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    font-weight: 500;
}

.quick-action:hover {
    background: var(--glass-hover);
    border-color: var(--primary-blue);
    color: white;
    transform: translateY(-1px);
}

.quick-action i {
    font-size: 0.75rem;
}

/* Settings Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 1000;
}

.modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

.settings-modal {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xl);
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow: hidden;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.modal-overlay.show .settings-modal {
    transform: scale(1);
}

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

.modal-header h3 {
    font-size: 1.2rem;
    font-weight: 600;
    color: white;
}

.close-modal {
    background: none;
    border: none;
    color: var(--gray-400);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
    font-size: 1.1rem;
}

.close-modal:hover {
    color: white;
    background: var(--glass-hover);
}

.modal-content {
    padding: 24px;
    overflow-y: auto;
    max-height: 400px;
}

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

.setting-group label {
    display: block;
    font-weight: 500;
    color: var(--gray-200);
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.setting-group input[type="range"] {
    width: 100%;
    margin-right: 12px;
}

.setting-group input[type="number"],
.setting-group textarea {
    width: 100%;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    color: white;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.setting-group input[type="number"]:focus,
.setting-group textarea:focus {
    outline: none;
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.setting-group textarea:focus {
    border-color: rgba(37, 99, 235, 0.5);
    outline: none;
}

.setting-group small {
    display: block;
    margin-top: 6px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.75rem;
    line-height: 1.4;
}

.modal-footer {
    display: flex;
    gap: 12px;
    padding: 24px;
    border-top: 1px solid var(--glass-border);
}

.clear-history-btn,
.save-settings-btn {
    flex: 1;
    padding: 12px 16px;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.clear-history-btn {
    background: var(--accent-orange);
    color: white;
}

.clear-history-btn:hover {
    background: #dc2626;
    transform: translateY(-1px);
}

.save-settings-btn {
    background: var(--primary-blue);
    color: white;
}

.save-settings-btn:hover {
    background: var(--primary-blue-light);
    transform: translateY(-1px);
}

/* Animations */
@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

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

/* Responsive Design */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        height: 100vh;
        z-index: 2000;
        box-shadow: 2px 0 20px rgba(0, 0, 0, 0.5);
        padding-bottom: env(safe-area-inset-bottom);
    }

    .sidebar.open {
        left: 0;
    }
    
    /* Add overlay when sidebar is open */
    .sidebar.open::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: -1;
    }
    
    .sidebar-close-btn {
        display: block; /* Show close button on mobile */
    }

    .main-content {
        margin-left: 0;
    }
    
    .thinking-indicator {
        left: 24px;
    }
    
    .chat-header {
        padding: 12px 16px;
    }
    
    .chat-messages {
        padding: 16px;
    }
    
    .chat-input-container {
        padding: 16px;
    }
    
    .quick-actions {
        overflow-x: auto;
        flex-wrap: nowrap;
        padding-bottom: 4px;
    }
    
    .quick-action span {
        display: none;
    }
    
    .message-content {
        max-width: 85%;
    }
}

@media (max-width: 768px) {
    .model-selector {
        display: none;
    }
}

@media (max-width: 480px) {
    .current-thread-title {
        font-size: 0.9rem;
    }
    
    .message-bubble {
        font-size: 0.9rem;
        padding: 12px 14px;
    }
}

/* File type specific icons */
.file-icon.pdf {
    background: #dc2626;
}

.file-icon.image {
    background: var(--accent-purple);
}

.file-icon.document {
    background: var(--primary-blue);
}

/* Drag and Drop Styles */
.drag-over {
    position: relative;
}

.drag-over::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(37, 99, 235, 0.1);
    border: 3px dashed rgba(37, 99, 235, 0.5);
    z-index: 1000;
    pointer-events: none;
    animation: dragPulse 1s ease-in-out infinite alternate;
}

.drag-over::after {
    content: '📎 Drop files here to upload';
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 30px 40px;
    color: white;
    font-size: 1.2rem;
    font-weight: 600;
    z-index: 1001;
    pointer-events: none;
    box-shadow: var(--shadow-xl);
}

@keyframes dragPulse {
    0% {
        opacity: 0.3;
    }
    100% {
        opacity: 0.6;
    }
}

/* Loading States */
.send-btn.loading {
    pointer-events: none;
}

.send-btn.loading i {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* Error States */
.message-bubble.error {
    background: rgba(239, 68, 68, 0.2) !important;
    border: 1px solid rgba(239, 68, 68, 0.3) !important;
    color: #fecaca !important;
}

/* Enhanced Mobile Styles */
@media (max-width: 640px) {
    .sidebar {
        width: 280px;
        overflow-y: auto;
    }
    
    .sidebar-footer {
        padding: 16px;
        padding-bottom: calc(20px + env(safe-area-inset-bottom) + 30px);
        gap: 16px;
    }
    
    .chat-header {
        padding: 12px 16px;
    }
    
    .logo {
        font-size: 1.1rem;
    }
    
    .logo i {
        font-size: 1.2rem;
    }
    
    .input-area {
        gap: 8px;
        padding: 12px;
    }
    
    .file-upload-btn,
    .cancel-btn,
    .send-btn {
        width: 32px;
        height: 32px;
        font-size: 0.8rem;
    }
    
    #message-input {
        font-size: 0.9rem;
    }
    
    .quick-actions {
        gap: 6px;
        margin-top: 8px;
    }
    
    .quick-action {
        padding: 6px 8px;
        font-size: 0.7rem;
    }
    
    .settings-modal {
        margin: 10px;
        width: calc(100% - 20px);
    }
    
    .modal-header,
    .modal-content,
    .modal-footer {
        padding: 16px 20px;
    }
    
    .thinking-indicator {
        left: 16px;
        right: 16px;
        bottom: 120px;
    }
    
    .new-chat-btn {
        padding: 10px 12px;
        font-size: 0.9rem;
    }
    
    .chat-thread {
        padding: 10px;
    }
    
    .chat-thread-title {
        font-size: 0.85rem;
    }
    
    .chat-thread-date {
        font-size: 0.7rem;
    }
    
    .sidebar-model-selector {
        gap: 8px;
        margin-bottom: 12px;
    }
    
    .sidebar-model-selector label {
        font-size: 0.85rem;
    }
    
    .sidebar-model-selector input {
        padding: 10px 12px;
        font-size: 0.85rem;
    }
    
    .upload-btn {
        padding: 12px;
        margin-bottom: 8px;
    }
    
    .footer-actions {
        gap: 12px;
    }
    
    .dashboard-btn,
    .settings-btn {
        padding: 12px;
        font-size: 0.85rem;
    }
}

/* Additional responsive improvements */
@media (max-width: 480px) {
    .sidebar-header {
        padding: 16px;
    }
    
    .sidebar-content {
        padding: 16px;
    }
    
    .sidebar-footer {
        padding: 16px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom) + 20px);
    }
    
    .chat-input-container {
        padding: 16px;
    }
    
    .drag-over::after {
        padding: 20px 30px;
        font-size: 1rem;
    }
}

/* Desktop sidebar toggle behavior */
@media (min-width: 769px) {
    .sidebar.open {
        width: var(--sidebar-collapsed-width);
    }
    
    .sidebar.open .sidebar-header span,
    .sidebar.open .sidebar-section h3,
    .sidebar.open .chat-thread-content,
    .sidebar.open .chat-thread-actions,
    .sidebar.open .dashboard-btn span,
    .sidebar.open .settings-btn {
        opacity: 0;
        pointer-events: none;
    }
    
    .sidebar.open .new-chat-btn {
        padding: 12px;
        justify-content: center;
    }
    
    .sidebar.open .chat-thread {
        justify-content: center;
        padding: 12px;
    }
    
    .sidebar.open .sidebar-footer {
        flex-direction: column;
        gap: 4px;
    }
    
    .sidebar.open .upload-btn {
        padding: 8px;
        font-size: 0.8rem;
    }
    
    .sidebar.open .footer-actions {
        flex-direction: column;
        gap: 4px;
    }
    
    .sidebar.open .dashboard-btn,
    .sidebar.open .settings-btn {
        padding: 8px;
        justify-content: center;
        font-size: 0.75rem;
    }
    
    .sidebar.open .sidebar-model-selector {
        margin-bottom: 8px;
    }
    
    .sidebar.open .sidebar-model-selector label {
        display: none;
    }
    
    .sidebar.open .sidebar-model-selector input {
        padding: 8px 6px;
        font-size: 0.75rem;
        text-align: center;
    }
    
    /* Adjust thinking indicator position when sidebar is collapsed */
    .sidebar.open ~ .main-content .thinking-indicator {
        left: calc(var(--sidebar-collapsed-width) + 24px);
    }
}

/* PWA Install Bottom Sheet Styles */
.pwa-bottom-sheet-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.pwa-bottom-sheet-overlay.show {
    opacity: 1;
}

.pwa-bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #1c1c1e;
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    max-height: 85vh;
    overflow: hidden;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
}

.pwa-bottom-sheet-overlay.show .pwa-bottom-sheet {
    transform: translateY(0);
}

.pwa-sheet-header {
    padding: 12px 20px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pwa-sheet-handle {
    width: 40px;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    margin: 0 auto;
}

.pwa-close-btn {
    position: absolute;
    right: 16px;
    top: 8px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 16px;
    color: white;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.pwa-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.pwa-sheet-content {
    padding: 0 20px 20px;
}

.pwa-app-info {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
}

.pwa-app-icon {
    width: 60px;
    height: 60px;
    border-radius: 14px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.pwa-app-details {
    flex: 1;
}

.pwa-app-details h3 {
    color: white;
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 4px;
}

.pwa-app-details p {
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    line-height: 1.4;
}

.share-icon-svg {
    display: inline-block;
    vertical-align: middle;
    margin: 0 4px;
    color: #007AFF;
}

.pwa-preview {
    margin-top: 16px;
    text-align: center;
}

.pwa-preview-image {
    width: 100%;
    max-width: 300px;
    height: auto;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Responsive bottom sheet for tablets/desktop */
@media (min-width: 768px) {
    .pwa-bottom-sheet {
        max-width: 500px;
        left: 50%;
        transform: translateX(-50%) translateY(100%);
        border-radius: 16px 16px 16px 16px;
        margin-bottom: 20px;
    }
    
    .pwa-bottom-sheet-overlay.show .pwa-bottom-sheet {
        transform: translateX(-50%) translateY(0);
    }
}

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

/* PWA and Mobile Specific Styles */
@media (display-mode: standalone) {
    /* Force everything black in PWA */
    html, body {
        background: #0a0a0a !important;
        background-color: #0a0a0a !important;
    }
    
    /* Remove overscroll and pull-to-refresh in PWA mode */
    body {
        overscroll-behavior: none;
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100%;
        background: #0a0a0a !important;
        padding-top: 0;
        margin-top: 0;
    }
    
    /* Remove any top overlays that might hide content */
    
    .chat-app {
        height: 100vh;
        height: 100dvh;
        background: #0a0a0a;
        padding-top: 0;
    }
    
    .main-content {
        height: 100%;
        background: #0a0a0a;
        position: relative;
        padding-top: 0;
    }
    
    .chat-messages {
        overscroll-behavior: contain;
    }
    
    /* Make header sticky and visible in PWA */
    .chat-header {
        position: fixed;
        top: env(safe-area-inset-top);
        left: 0;
        right: 0;
        padding: 16px 24px;
        background: #0a0a0a;
        z-index: 1500;
        border-bottom: 1px solid var(--glass-border);
        min-height: 70px;
    }
    
    /* Adjust chat messages to account for fixed header */
    .chat-messages {
        padding-top: calc(70px + env(safe-area-inset-top));
    }
    
    /* Mobile PWA: no margin and overlay sidebar */
    @media (max-width: 768px) {
        .main-content {
            margin-left: 0 !important;
        }
        
        .sidebar {
            position: fixed;
            top: 0;
            left: 0;
            height: 100vh;
            transform: translateX(-100%);
            z-index: 2500;
        }
        
        .sidebar.open {
            transform: translateX(0);
            box-shadow: 2px 0 20px rgba(0, 0, 0, 0.5);
        }
    }
    
    /* Desktop PWA: keep sidebar visible */
    @media (min-width: 769px) {
        .main-content {
            margin-left: var(--sidebar-width) !important;
        }
        
        .sidebar {
            transform: translateX(0) !important;
        }
    }
}

/* Mobile-specific keyboard handling */
@media (max-width: 768px) {
    /* Hide quick actions on mobile */
    .quick-actions {
        display: none !important;
    }
    
    /* Make header sticky on mobile too */
    .chat-header {
        position: fixed;
        top: env(safe-area-inset-top);
        left: 0;
        right: 0;
        z-index: 1500;
        background: #0a0a0a;
        min-height: 70px;
    }
    
    /* Adjust chat messages for fixed header */
    .chat-messages {
        padding-top: calc(70px + env(safe-area-inset-top));
    }
    
    /* Adjust input area for mobile */
    .chat-input-container {
        padding: 12px 16px;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 100;
    }

    /* Position file preview area properly on mobile */
    .file-preview-area {
        position: fixed;
        bottom: 120px; /* Above the input area */
        left: 0;
        right: 0;
        z-index: 50; /* Below chat messages, above background */
        background: #0a0a0a; /* Solid background for visibility */
        padding: 8px 16px;
        max-height: 150px;
        overflow-y: auto;
    }

    .file-preview-area.show {
        max-height: 150px;
    }
    
    /* Remove border from input area on mobile */
    .input-area {
        border: none;
        background: rgba(20, 20, 20, 0.95);
        padding: 12px;
    }
    
    /* Adjust chat messages to account for fixed input */
    .chat-messages {
        padding-bottom: 100px;
        padding-top: calc(70px + env(safe-area-inset-top));
    }
    
    /* When keyboard is visible */
    .keyboard-visible .chat-input-container {
        bottom: 0;
    }
    
    .keyboard-visible .chat-messages {
        padding-bottom: 20px;
    }
}

/* iOS specific fixes */
@supports (-webkit-touch-callout: none) {
    /* iOS keyboard handling */
    .chat-input-container {
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    /* Prevent iOS bounce effect and handle status bar */
    .chat-app {
        position: fixed;
        width: 100%;
        height: 100%;
        top: 0;
        background: #0a0a0a;
    }
    
    /* Extend sidebar to top in PWA */
    @media (display-mode: standalone) {
        .sidebar {
            padding-top: env(safe-area-inset-top);
            top: 0;
            height: 100vh;
            background: #0a0a0a;
        }
        
        .sidebar-header {
            padding-top: calc(24px + env(safe-area-inset-top));
        }
        
        /* Ensure thinking indicator is below fixed header */
        .thinking-indicator {
            top: calc(70px + env(safe-area-inset-top));
            bottom: auto;
        }
    }
}

/* ========================================
   IMAGE SEARCH COMPONENTS
   ======================================== */

/* Image search container */
.image-search-container {
    margin: 16px 0;
    animation: fadeIn 0.3s ease;
}

/* Loading state */
.image-search-loading {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    color: var(--gray-400);
    font-size: 14px;
}

.image-loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--glass-border);
    border-top-color: var(--primary-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.image-loading-text {
    color: var(--gray-400);
    font-size: 14px;
}

/* Image result container */
.image-search-result {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: all 0.3s ease;
    margin: 0 auto;
    animation: slideUp 0.4s ease;
}

.image-search-result:hover {
    border-color: var(--primary-blue-light);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.1);
}

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

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Header with query and count */
.image-result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--glass-border);
    background: rgba(0, 0, 0, 0.2);
}

.image-result-query {
    font-size: 13px;
    color: var(--gray-300);
    font-weight: 500;
}

.image-result-count {
    font-size: 10px;
    color: var(--gray-500);
}

/* Main image */
.image-result-main {
    position: relative;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-result-img {
    width: 100%;
    height: auto;
    display: block;
    transition: opacity 0.3s ease;
}

.image-result-img:hover {
    opacity: 0.95;
}

/* Dislike button (bottom right corner) */
.image-dislike-btn {
    position: absolute;
    bottom: 6px;
    right: 6px;
    width: 24px;
    height: 24px;
    background: rgba(0, 0, 0, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    opacity: 0.8;
    transition: all 0.2s ease;
    backdrop-filter: blur(8px);
    z-index: 10;
}

.image-dislike-btn:hover {
    opacity: 1;
    background: rgba(231, 76, 60, 0.9);
    color: white;
    border-color: rgba(231, 76, 60, 0.6);
    transform: scale(1.15);
}

.image-dislike-btn:active {
    transform: scale(0.9);
}

.image-result-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 40px;
    color: var(--gray-500);
}

.image-result-error i {
    font-size: 32px;
    opacity: 0.5;
}

/* Image info */
.image-result-info {
    padding: 8px 12px;
    border-bottom: 1px solid var(--glass-border);
}

.image-result-title {
    font-size: 11px;
    color: var(--gray-200);
    margin-bottom: 4px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Action buttons */
.image-result-actions {
    display: flex;
    flex-direction: row;
    gap: 8px;
    padding: 12px 16px;
}

.image-action-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: var(--gray-300);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.image-action-btn:hover {
    background: var(--glass-hover);
    border-color: var(--primary-blue-light);
    color: var(--primary-blue-light);
    transform: translateY(-1px);
}

.image-action-btn i {
    font-size: 11px;
}

.view-more-btn {
    background: var(--glass-bg);
}

.view-more-btn:hover {
    background: var(--glass-hover);
}

/* No results / error states */
.image-no-results,
.image-error {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 24px;
    color: var(--gray-500);
    font-size: 13px;
}

.image-no-results i,
.image-error i {
    font-size: 18px;
    opacity: 0.6;
}

.image-error {
    color: var(--accent-orange);
}

/* ========================================
   IMAGE GALLERY MODAL
   ======================================== */

.image-gallery-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.image-gallery-modal.show {
    opacity: 1;
}

.image-gallery-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(10px);
}

.image-gallery-content {
    position: relative;
    width: 90%;
    max-width: 1200px;
    max-height: 90vh;
    background: var(--gray-900);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: modalSlideUp 0.3s ease;
}

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

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

.image-gallery-header h3 {
    font-size: 18px;
    color: var(--gray-100);
    font-weight: 600;
}

.image-gallery-close {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: var(--gray-400);
    cursor: pointer;
    transition: all 0.2s ease;
}

.image-gallery-close:hover {
    background: var(--accent-orange);
    border-color: var(--accent-orange);
    color: white;
    transform: rotate(90deg);
}

.image-gallery-grid {
    padding: 24px;
    overflow-y: auto;
    max-height: 70vh;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 16px;
}

/* Gallery image card */
.gallery-image-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
}

.gallery-image-card:hover {
    border-color: var(--primary-blue);
    transform: translateY(-4px);
    box-shadow: 0 8px 20px rgba(37, 99, 235, 0.2);
}

.gallery-image-card img {
    width: 100%;
    height: 180px;
    object-fit: cover;
    background: #000;
    transition: transform 0.3s ease;
}

.gallery-image-card:hover img {
    transform: scale(1.05);
}

.gallery-image-info {
    padding: 12px;
}

.gallery-image-title {
    font-size: 13px;
    color: var(--gray-200);
    font-weight: 500;
    margin-bottom: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gallery-image-meta {
    font-size: 11px;
    color: var(--gray-500);
    margin-bottom: 8px;
}

.gallery-image-source {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--primary-blue-light);
    text-decoration: none;
    transition: color 0.2s ease;
}

.gallery-image-source:hover {
    color: var(--primary-blue);
}

/* Mobile responsive */
@media (max-width: 768px) {
    .image-gallery-content {
        width: 95%;
        max-height: 85vh;
    }

    .image-gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 12px;
        padding: 16px;
    }

    .gallery-image-card img {
        height: 140px;
    }

    .image-result-actions {
        flex-direction: row;
        gap: 4px;
        padding: 8px 10px;
    }

    .image-action-btn {
        font-size: 9px;
        padding: 6px 8px;
        gap: 3px;
    }

    .image-action-btn i {
        font-size: 8px;
    }

    .image-result-header {
        padding: 8px 10px;
    }

    .image-result-query {
        font-size: 11px;
    }

    .image-result-count {
        font-size: 8px;
    }

    .image-result-title {
        font-size: 9px;
    }

    .image-result-info {
        padding: 6px 10px;
    }
}