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

        :root {
            --bg-primary: #1a1d23;
            --bg-secondary: #23262d;
            --bg-tertiary: #2d3139;
            --accent: #5b9bd5;
            --accent-hover: #4a8bc4;
            --success: #10b981;
            --danger: #ef4444;
            --text-primary: #ffffff;
            --text-secondary: #a0a4aa;
            --border: #3a3d45;
        }

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

        .app-container {
            display: grid;
            grid-template-columns: 260px 1fr;
            grid-template-rows: 60px 1fr;
            height: 100vh;
        }

        /* Header */
        .header {
            grid-column: 1 / -1;
            background: var(--bg-secondary);
            border-bottom: 1px solid var(--border);
            padding: 8px 24px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            height: 60px;
            align-self: start;
        }

        .logo-container {
            display: flex;
            align-items: center;
            gap: 16px;
        }

        .logo-image {
            height: 48px;
            width: auto;
        }

        .logo-text {
            display: flex;
            flex-direction: column;
        }

        .logo {
            font-size: 20px;
            font-weight: 900;
            color: var(--text-primary);
            letter-spacing: -1px;
            font-family: 'Arial Black', 'Arial Bold', sans-serif;
            line-height: 1;
        }

        .logo-subtitle {
            font-size: 8px;
            font-weight: 500;
            color: var(--text-secondary);
            letter-spacing: 1.5px;
            text-transform: uppercase;
            margin-top: 1px;
            line-height: 1;
        }

        .header-stats {
            display: flex;
            gap: 16px;
            font-size: 12px;
        }

        .stat-item {
            color: var(--text-secondary);
            font-size: 12px;
        }

        .stat-value {
            color: var(--text-primary);
            font-weight: 600;
            margin-left: 4px;
        }

        /* Sidebar */
        .sidebar {
            background: var(--bg-secondary);
            border-right: 1px solid var(--border);
            padding: 20px;
            overflow-y: auto;
        }

        .mode-btn {
            width: 100%;
            padding: 12px 16px;
            margin-bottom: 8px;
            background: transparent;
            border: 1px solid var(--border);
            border-radius: 8px;
            color: var(--text-secondary);
            cursor: pointer;
            text-align: left;
            font-size: 14px;
            font-weight: 500;
            transition: all 0.2s;
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .mode-btn:hover {
            background: var(--bg-tertiary);
            border-color: var(--accent);
            color: var(--text-primary);
        }

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

        .sidebar-section {
            margin-top: 30px;
            padding-top: 20px;
            border-top: 1px solid var(--border);
        }

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

        .recent-item {
            padding: 8px 12px;
            margin-bottom: 6px;
            background: var(--bg-tertiary);
            border-radius: 6px;
            font-size: 12px;
            color: var(--text-secondary);
            cursor: pointer;
            transition: all 0.2s;
            display: flex;
            justify-content: space-between;
            align-items: center;
            gap: 8px;
        }

        .recent-item:hover {
            background: var(--bg-primary);
            color: var(--text-primary);
        }

        .recent-item.active {
            background: var(--accent);
            color: white;
        }

        .chat-name {
            flex: 1;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .chat-actions {
            display: none;
            gap: 4px;
        }

        .recent-item:hover .chat-actions {
            display: flex;
        }

        .chat-action-btn {
            background: transparent;
            border: none;
            color: var(--text-secondary);
            cursor: pointer;
            padding: 2px 4px;
            font-size: 10px;
            border-radius: 3px;
        }

        .chat-action-btn:hover {
            background: rgba(255,255,255,0.1);
            color: var(--text-primary);
        }

        /* Main Content */
        .main-content {
            background: var(--bg-primary);
            overflow-y: auto;
        }

        .content-view {
            display: none;
            height: 100%;
        }

        .content-view.active {
            display: flex;
            flex-direction: column;
        }

        /* CHAT MODE - Distinct Chat Interface */
        .chat-mode.active {
            display: flex;
            flex-direction: column;
            height: 100%;
        }

        .chat-messages {
            flex: 1;
            overflow-y: auto;
            padding: 24px;
            display: flex;
            flex-direction: column;
            gap: 16px;
        }

        .message {
            max-width: 80%;
            padding: 16px 20px;
            border-radius: 12px;
            line-height: 1.6;
            font-size: 14px;
        }

        .message.user {
            align-self: flex-end;
            background: var(--accent);
            color: white;
        }

        .message.ai {
            align-self: flex-start;
            background: var(--bg-secondary);
            border: 1px solid var(--border);
        }

        .message.ai h2,
        .message.ai h3,
        .message.ai h4 {
            font-weight: 600;
        }

        /* Don't override inline styles for section headers, only style general emphasis */
        .message.ai strong:not([style*="color"]) {
            color: var(--accent);
            font-weight: 600;
        }

        .message.ai ul,
        .message.ai ol {
            margin: 12px 0;
            padding-left: 24px;
        }

        .message.ai li {
            margin-bottom: 8px;
        }

        .message.ai code {
            background: var(--bg-tertiary);
            padding: 2px 6px;
            border-radius: 4px;
            font-family: 'Courier New', monospace;
            font-size: 13px;
        }

        /* Typing indicator animation */
        .typing-indicator {
            padding: 12px 20px !important;
        }

        .typing-dot {
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background: var(--text-secondary);
            animation: typing 1.4s infinite;
        }

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

        .typing-dot:nth-child(3) {
            animation-delay: 0.4s;
        }

        @keyframes typing {
            0%, 60%, 100% {
                opacity: 0.3;
                transform: translateY(0);
            }
            30% {
                opacity: 1;
                transform: translateY(-8px);
            }
        }

        .image-gallery {
            margin: 16px 0;
            padding: 16px;
            background: var(--bg-primary);
            border-radius: 8px;
            border: 1px solid var(--border);
        }

        .image-gallery-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 12px;
            padding-bottom: 8px;
            border-bottom: 1px solid var(--border);
        }

        .image-gallery-title {
            font-size: 14px;
            font-weight: 600;
            color: var(--accent);
        }

        .find-more-btn {
            padding: 4px 12px;
            background: var(--accent);
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 12px;
            transition: background 0.2s;
        }

        .find-more-btn:hover {
            background: var(--accent-hover);
        }

        .image-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 12px;
        }

        .image-item {
            background: var(--bg-secondary);
            border-radius: 6px;
            padding: 8px;
            border: 1px solid var(--border);
            cursor: pointer;
            transition: all 0.2s;
        }

        .image-item:hover {
            border-color: var(--accent);
            transform: translateY(-2px);
        }

        .image-item img {
            width: 100%;
            height: 150px;
            object-fit: contain;
            border-radius: 4px;
            background: #000;
        }

        .image-caption {
            margin-top: 8px;
            font-size: 11px;
            color: var(--text-secondary);
            text-align: center;
        }

        .teaching-prompts {
            margin-top: 32px;
            padding: 18px 20px;
            background: rgba(0, 0, 0, 0.35);
            border-radius: 10px;
            border: 1px solid rgba(255, 255, 255, 0.08);
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
        }

        .teaching-prompts-title {
            color: #94a3b8;
            font-size: 13px;
            font-weight: 600;
            margin-bottom: 14px;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .teaching-prompts ul {
            margin: 0;
            padding-left: 24px;
            list-style-type: disc;
        }

        .teaching-prompts li {
            color: #cbd5e1;
            margin-bottom: 10px;
            line-height: 1.6;
            font-size: 13.5px;
        }

        .chat-input-area {
            border-top: 1px solid var(--border);
            padding: 20px;
            background: var(--bg-secondary);
        }

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

        .chat-input {
            flex: 1;
            padding: 12px 16px;
            background: var(--bg-primary);
            border: 1px solid var(--border);
            border-radius: 8px;
            color: var(--text-primary);
            font-size: 14px;
            resize: none;
        }

        .chat-input:focus {
            outline: none;
            border-color: var(--accent);
        }

        .send-btn {
            padding: 12px 24px;
            background: var(--accent);
            color: white;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            font-weight: 600;
            transition: background 0.2s;
        }

        .send-btn:hover {
            background: var(--accent-hover);
        }

        /* QUIZ MODE - Distinct Quiz Interface */
        .quiz-mode {
            padding: 40px;
            max-width: 900px;
            margin: 0 auto;
            width: 100%;
        }

        .quiz-config-panel {
            background: var(--bg-secondary);
            border: 1px solid var(--border);
            border-radius: 12px;
            padding: 40px;
        }

        .config-grid {
            display: grid;
            gap: 24px;
        }

        .config-section {
            display: flex;
            flex-direction: column;
            gap: 12px;
            position: relative;
        }

        .config-label {
            font-size: 13px;
            font-weight: 600;
            color: var(--text-primary);
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .config-select {
            padding: 12px 16px;
            background: var(--bg-primary);
            border: 1px solid var(--border);
            border-radius: 8px;
            color: var(--text-primary);
            font-size: 15px;
            cursor: pointer;
        }

        .config-select:focus {
            outline: none;
            border-color: var(--accent);
        }

        .config-input {
            padding: 12px 16px;
            background: var(--bg-primary);
            border: 1px solid var(--border);
            border-radius: 8px;
            color: var(--text-primary);
            font-size: 15px;
        }

        .config-input:focus {
            outline: none;
            border-color: var(--accent);
        }

        .config-options {
            display: flex;
            flex-direction: column;
            gap: 10px;
        }

        .radio-option {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 12px 16px;
            background: var(--bg-primary);
            border: 1px solid var(--border);
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.2s;
        }

        .radio-option:hover {
            border-color: var(--accent);
        }

        .radio-option input[type="radio"] {
            width: 18px;
            height: 18px;
            cursor: pointer;
        }

        .radio-option span {
            color: var(--text-primary);
            font-size: 14px;
        }

        .quiz-stats-bar {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 16px;
            margin-bottom: 30px;
            padding: 20px;
            background: var(--bg-secondary);
            border-radius: 12px;
            border: 1px solid var(--border);
        }

        .quiz-stat {
            text-align: center;
        }

        .quiz-stat-label {
            font-size: 11px;
            color: var(--text-secondary);
            text-transform: uppercase;
            margin-bottom: 6px;
        }

        .quiz-stat-value {
            font-size: 28px;
            font-weight: 700;
            color: var(--accent);
        }

        .quiz-question-card {
            background: var(--bg-secondary);
            border: 1px solid var(--border);
            border-radius: 12px;
            padding: 32px;
            margin-bottom: 24px;
        }

        .question-header {
            display: flex;
            justify-content: space-between;
            margin-bottom: 24px;
            padding-bottom: 16px;
            border-bottom: 1px solid var(--border);
        }

        .question-number {
            font-size: 13px;
            color: var(--text-secondary);
        }

        .question-category {
            font-size: 12px;
            background: var(--bg-tertiary);
            padding: 4px 12px;
            border-radius: 4px;
            color: var(--accent);
        }

        .question-text {
            font-size: 17px;
            line-height: 1.7;
            margin-bottom: 24px;
            color: var(--text-primary);
        }

        .answer-options {
            display: flex;
            flex-direction: column;
            gap: 12px;
        }

        .answer-option {
            padding: 14px 18px;
            background: var(--bg-primary);
            border: 2px solid var(--border);
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.2s;
            display: flex;
            gap: 12px;
            align-items: center;
        }

        .answer-option:hover {
            border-color: var(--accent);
        }

        .answer-option.selected {
            border-color: var(--accent);
            background: rgba(59, 130, 246, 0.1);
        }

        .answer-option.correct {
            border-color: var(--success);
            background: rgba(16, 185, 129, 0.1);
        }

        .answer-option.incorrect {
            border-color: var(--danger);
            background: rgba(239, 68, 68, 0.1);
        }

        .option-letter {
            width: 28px;
            height: 28px;
            border-radius: 50%;
            background: var(--bg-tertiary);
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: 700;
            font-size: 13px;
            flex-shrink: 0;
        }

        .answer-option.selected .option-letter {
            background: var(--accent);
            color: white;
        }

        .explanation {
            display: none;
            margin-top: 24px;
            padding: 20px;
            background: var(--bg-primary);
            border-left: 3px solid var(--accent);
            border-radius: 6px;
        }

        .explanation.show {
            display: block;
        }

        .explanation-header {
            font-weight: 700;
            margin-bottom: 12px;
            color: var(--accent);
        }

        .quiz-actions {
            display: flex;
            gap: 12px;
            justify-content: center;
        }

        .quiz-btn {
            padding: 12px 28px;
            border: 1px solid var(--border);
            border-radius: 8px;
            cursor: pointer;
            font-weight: 600;
            transition: all 0.2s;
        }

        .quiz-btn-primary {
            background: var(--accent);
            border-color: var(--accent);
            color: white;
        }

        .quiz-btn-primary:hover {
            background: var(--accent-hover);
        }

        .quiz-btn-secondary {
            background: transparent;
            color: var(--text-secondary);
        }

        .quiz-btn-secondary:hover {
            border-color: var(--accent);
            color: var(--text-primary);
        }

        /* STUDY MODE - Distinct Resource Browser */
        .study-mode {
            padding: 40px;
        }

        .study-header {
            margin-bottom: 30px;
        }

        .study-header h1 {
            font-size: 28px;
            margin-bottom: 8px;
        }

        .study-search-container {
            display: flex;
            align-items: center;
            gap: 12px;
            max-width: 900px;
            margin-bottom: 30px;
        }

        .study-search {
            flex: 1;
            padding: 12px 18px;
            background: var(--bg-secondary);
            border: 1px solid var(--border);
            border-radius: 8px;
            color: var(--text-primary);
            font-size: 15px;
        }

        .study-search:focus {
            outline: none;
            border-color: var(--accent);
        }

        .lesson-buttons-inline {
            display: flex;
            gap: 8px;
            flex-shrink: 0;
        }

        .lesson-btn-inline {
            display: flex;
            align-items: center;
            gap: 6px;
            padding: 10px 16px;
            border: 1px solid var(--border);
            border-radius: 8px;
            background: var(--bg-secondary);
            color: var(--text-primary);
            font-size: 14px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.2s;
            white-space: nowrap;
        }

        .lesson-btn-inline .btn-icon {
            font-size: 16px;
        }

        .lesson-btn-inline.quick {
            border-color: #10b981;
        }

        .lesson-btn-inline.quick:hover {
            background: rgba(16, 185, 129, 0.1);
            border-color: #10b981;
            transform: translateY(-1px);
            box-shadow: 0 4px 12px rgba(16, 185, 129, 0.2);
        }

        .lesson-btn-inline.detailed {
            border-color: #8b5cf6;
        }

        .lesson-btn-inline.detailed:hover {
            background: rgba(139, 92, 246, 0.1);
            border-color: #8b5cf6;
            transform: translateY(-1px);
            box-shadow: 0 4px 12px rgba(139, 92, 246, 0.2);
        }

        .lesson-btn-inline:active {
            transform: translateY(0);
        }

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

        .resource-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
            gap: 20px;
        }

        .resource-card {
            background: var(--bg-secondary);
            border: 1px solid var(--border);
            border-radius: 12px;
            padding: 20px;
            cursor: pointer;
            transition: all 0.2s;
        }

        .resource-card:hover {
            border-color: var(--accent);
            transform: translateY(-2px);
        }

        .resource-icon {
            font-size: 32px;
            margin-bottom: 12px;
        }

        .resource-title {
            font-weight: 600;
            margin-bottom: 8px;
            color: var(--text-primary);
        }

        .resource-meta {
            font-size: 12px;
            color: var(--text-secondary);
        }

        /* PROGRESS MODE - Distinct Dashboard */
        .progress-mode {
            padding: 40px;
        }

        .progress-header {
            margin-bottom: 30px;
        }

        .progress-header h1 {
            font-size: 28px;
            margin-bottom: 8px;
        }

        .dashboard-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
            gap: 20px;
            margin-bottom: 40px;
        }

        .dashboard-card {
            background: var(--bg-secondary);
            border: 1px solid var(--border);
            border-radius: 12px;
            padding: 24px;
        }

        .dashboard-label {
            font-size: 12px;
            color: var(--text-secondary);
            text-transform: uppercase;
            margin-bottom: 8px;
        }

        .dashboard-value {
            font-size: 36px;
            font-weight: 700;
            color: var(--accent);
        }

        .topic-breakdown {
            margin-top: 40px;
        }

        .topic-breakdown h3 {
            font-size: 18px;
            margin-bottom: 20px;
        }

        .topic-row {
            display: flex;
            justify-content: space-between;
            padding: 16px 20px;
            margin-bottom: 8px;
            background: var(--bg-secondary);
            border: 1px solid var(--border);
            border-radius: 8px;
        }

        .topic-name {
            font-weight: 600;
        }

        .topic-score {
            color: var(--accent);
            font-weight: 700;
        }

        /* Loading */
        .loading {
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 60px;
            color: var(--text-secondary);
        }

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

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

        /* Hamburger Menu Button - Hidden on desktop */
        .mobile-menu-btn {
            display: none;
        }

        /* Sidebar Overlay - Hidden on desktop */
        .sidebar-overlay {
            display: none;
        }

        /* Hide header LLM selector on medium screens to prevent overlap */
        @media (max-width: 1700px) {
            .header-llm-selector {
                display: none !important;
            }

            .mobile-model-selector {
                display: block !important;
            }
        }

        /* Hide detail controls on smaller screens to prevent overlap with stats */
        @media (max-width: 1900px) {
            .header-detail-controls {
                display: none !important;
            }

            .mobile-detail-controls {
                display: block !important;
            }
        }

        /* Adjust header stats spacing on medium screens */
        @media (max-width: 1200px) {
            .header-stats {
                gap: 12px;
                font-size: 11px;
            }

            .stat-item {
                font-size: 11px;
            }
        }

        /* Mobile Responsive Styles */
        @media (max-width: 768px) {
            .app-container {
                grid-template-columns: 1fr;
                grid-template-rows: auto 1fr;
            }

            .header {
                padding: 8px 12px;
                gap: 8px;
                flex-wrap: nowrap;
                justify-content: space-between;
            }

            /* Logo on left */
            .header > div:first-child {
                flex: 0 0 auto;
                order: 1;
            }

            .logo {
                font-size: 20px;
            }

            .logo-subtitle {
                font-size: 8px;
            }

            /* Show hamburger menu button on right */
            .mobile-menu-btn {
                display: flex !important;
                background: var(--bg-tertiary);
                border: 1px solid var(--border);
                color: var(--text-primary);
                padding: 8px 12px;
                border-radius: 6px;
                cursor: pointer;
                font-size: 20px;
                min-width: 44px;
                min-height: 44px;
                align-items: center;
                justify-content: center;
                order: 3;
                margin-left: auto;
            }

            .mobile-menu-btn:hover {
                border-color: var(--accent);
            }

            /* Hide provider info and stats by default on mobile */
            #providerInfo {
                display: none !important;
            }

            .header-stats {
                display: none !important;
            }

            /* Hide desktop AI Model selector on mobile - use a more specific selector */
            .header > div[style*="position: absolute"] {
                display: none !important;
            }

            /* Show mobile AI Model selector in sidebar */
            .mobile-model-selector {
                display: block !important;
            }

            /* Show mobile user actions in sidebar */
            .mobile-user-actions {
                display: block !important;
            }

            /* Sidebar - hidden by default, shown when toggled */
            .sidebar {
                position: fixed;
                top: 0;
                left: -100%;
                width: 280px;
                height: 100vh;
                z-index: 1000;
                transition: left 0.3s ease;
                border-right: 1px solid var(--border);
                overflow-y: auto;
                box-shadow: 2px 0 10px rgba(0,0,0,0.5);
            }

            .sidebar.mobile-open {
                left: 0;
            }

            /* Overlay when sidebar is open */
            .sidebar-overlay {
                display: none;
                position: fixed;
                top: 0;
                left: 0;
                right: 0;
                bottom: 0;
                background: rgba(0,0,0,0.5);
                z-index: 999;
            }

            .sidebar-overlay.active {
                display: block;
            }

            .sidebar-section {
                display: block; /* Show recent chats in mobile sidebar */
            }

            .mode-btn {
                display: block;
                width: 100%;
                padding: 12px 16px;
                margin-right: 0;
                margin-bottom: 8px;
                text-align: left;
            }

            .main-content {
                padding: 12px;
                overflow-x: hidden;
            }

            .chat-messages {
                height: calc(100vh - 350px);
                min-height: 300px;
            }

            /* Quiz Mode Fixes */
            .quiz-question-view h2,
            .quiz-question-view p,
            .quiz-question-view div {
                word-wrap: break-word;
                overflow-wrap: break-word;
                max-width: 100%;
            }

            .quiz-question {
                font-size: 14px;
                line-height: 1.5;
                word-wrap: break-word;
                overflow-wrap: break-word;
            }

            .answer-option {
                font-size: 14px;
                padding: 10px;
                word-wrap: break-word;
                overflow-wrap: break-word;
                white-space: normal;
            }

            .quiz-nav-buttons {
                flex-direction: column;
                gap: 8px;
            }

            .quiz-nav-buttons button {
                width: 100%;
            }

            .quiz-result-item {
                padding: 12px;
                font-size: 14px;
            }

            .quiz-result-item strong {
                display: block;
                margin-bottom: 8px;
                word-wrap: break-word;
            }

            .chat-input-area {
                padding: 12px;
            }

            .chat-input {
                font-size: 16px; /* Prevents zoom on iOS */
            }

            .message {
                padding: 12px;
                font-size: 14px;
            }

            /* Quiz Configuration */
            .config-grid {
                grid-template-columns: 1fr !important;
            }

            .config-section {
                margin-bottom: 16px;
            }

            /* Study Resources */
            .resource-grid {
                grid-template-columns: 1fr !important;
            }

            /* Dataset Stats */
            .dataset-stats-content > div {
                grid-template-columns: 1fr !important;
            }

            /* Make tables scrollable */
            .quiz-result-summary table,
            .progress-table table {
                display: block;
                overflow-x: auto;
                white-space: nowrap;
            }

            /* Touch-friendly buttons */
            button, .send-btn {
                min-height: 44px;
                min-width: 44px;
            }

            /* Hide hamburger menu elements gracefully */
            .quiz-config-panel,
            .quiz-question-view,
            .quiz-results-view {
                padding: 12px;
            }
        }

        /* Tablet styles */
        @media (min-width: 769px) and (max-width: 1024px) {
            .sidebar {
                width: 200px;
            }

            .config-grid {
                grid-template-columns: 1fr !important;
            }

            .resource-grid {
                grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
            }
        }

        /* Very small mobile phones */
        @media (max-width: 375px) {
            .header {
                padding: 8px;
            }

            .logo {
                font-size: 20px;
            }

            .mode-btn {
                font-size: 12px;
                padding: 6px 12px;
            }

            .chat-input-area {
                padding: 8px;
            }

            select#llmProvider {
                font-size: 12px;
                padding: 6px 10px;
            }
        }

        /* ==================== AUTH MODAL STYLES ==================== */
        .auth-overlay {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.75);
            display: none;
            align-items: center;
            justify-content: center;
            z-index: 10000;
            backdrop-filter: blur(4px);
        }

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

        .auth-modal {
            background: var(--bg-secondary);
            border-radius: 16px;
            width: 90%;
            max-width: 440px;
            max-height: 90vh;
            overflow-y: auto;
            box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
            border: 1px solid var(--border);
            animation: slideUp 0.3s ease-out;
            -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
        }

        /* Mobile: Full screen modal */
        @media (max-width: 768px) {
            .auth-modal {
                width: 100%;
                height: 100%;
                max-height: 100vh;
                border-radius: 0;
                border: none;
            }

            .auth-modal-header {
                padding: 20px 16px 12px;
            }

            .auth-modal-title {
                font-size: 20px;
            }

            .auth-modal-subtitle {
                font-size: 13px;
            }

            .auth-modal-body {
                padding: 16px;
            }

            .form-label {
                font-size: 14px;
            }

            .form-input {
                font-size: 16px;  /* Prevents zoom on iOS */
                padding: 14px;
            }

            .auth-button, .oauth-button {
                padding: 14px;
                font-size: 15px;
            }

            .auth-tabs {
                gap: 6px;
                padding: 3px;
            }

            .auth-tab {
                padding: 12px;
                font-size: 15px;
            }

            .oauth-button {
                margin-bottom: 10px;
            }

            .form-checkbox-label {
                font-size: 14px;
            }

            .forgot-password-link {
                font-size: 14px;
                margin-top: 12px;
            }
        }

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

        .auth-modal-header {
            padding: 24px 24px 16px;
            border-bottom: 1px solid var(--border);
            text-align: center;
        }

        .auth-modal-title {
            font-size: 24px;
            font-weight: 700;
            color: var(--text-primary);
            margin-bottom: 8px;
        }

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

        .auth-modal-body {
            padding: 24px;
        }

        .auth-tabs {
            display: flex;
            gap: 8px;
            margin-bottom: 24px;
            background: var(--bg-tertiary);
            padding: 4px;
            border-radius: 8px;
        }

        .auth-tab {
            flex: 1;
            padding: 10px;
            background: transparent;
            border: none;
            color: var(--text-secondary);
            font-size: 14px;
            font-weight: 600;
            cursor: pointer;
            border-radius: 6px;
            transition: all 0.2s;
        }

        .auth-tab.active {
            background: var(--bg-secondary);
            color: var(--text-primary);
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
        }

        .auth-form {
            display: none;
        }

        .auth-form.active {
            display: block;
        }

        .form-group {
            margin-bottom: 16px;
        }

        .form-label {
            display: block;
            font-size: 13px;
            font-weight: 600;
            color: var(--text-primary);
            margin-bottom: 6px;
        }

        .form-input {
            width: 100%;
            padding: 12px;
            background: var(--bg-tertiary);
            border: 1px solid var(--border);
            border-radius: 8px;
            color: var(--text-primary);
            font-size: 14px;
            transition: all 0.2s;
        }

        .form-input:focus {
            outline: none;
            border-color: var(--accent);
            box-shadow: 0 0 0 3px rgba(91, 155, 213, 0.1);
        }

        .form-checkbox-group {
            display: flex;
            align-items: center;
            gap: 8px;
            margin: 12px 0;
        }

        .form-checkbox {
            width: 16px;
            height: 16px;
            cursor: pointer;
        }

        .form-checkbox-label {
            font-size: 13px;
            color: var(--text-secondary);
            cursor: pointer;
        }

        .auth-button {
            width: 100%;
            padding: 12px;
            background: var(--accent);
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 14px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.2s;
            margin-top: 8px;
        }

        .auth-button:hover {
            background: var(--accent-hover);
            transform: translateY(-1px);
            box-shadow: 0 4px 12px rgba(91, 155, 213, 0.3);
        }

        .auth-button:active {
            transform: translateY(0);
        }

        .auth-button:disabled {
            opacity: 0.5;
            cursor: not-allowed;
            transform: none;
        }

        .auth-divider {
            display: flex;
            align-items: center;
            gap: 12px;
            margin: 20px 0;
            color: var(--text-secondary);
            font-size: 13px;
        }

        .auth-divider::before,
        .auth-divider::after {
            content: '';
            flex: 1;
            height: 1px;
            background: var(--border);
        }

        .oauth-button {
            width: 100%;
            padding: 12px;
            background: white;
            color: #333;
            border: 1px solid #ddd;
            border-radius: 8px;
            font-size: 14px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.2s;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
            margin-bottom: 12px;
        }

        .oauth-button:hover {
            background: #f8f8f8;
            transform: translateY(-1px);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }

        .oauth-button img {
            width: 20px;
            height: 20px;
        }

        .oauth-button.microsoft {
            background: #2f2f2f;
            color: white;
            border-color: #2f2f2f;
        }

        .oauth-button.microsoft:hover {
            background: #1f1f1f;
        }

        .forgot-password-link {
            display: block;
            text-align: right;
            font-size: 13px;
            color: var(--accent);
            text-decoration: none;
            margin-top: 8px;
            cursor: pointer;
        }

        .forgot-password-link:hover {
            text-decoration: underline;
        }

        .auth-error {
            background: rgba(239, 68, 68, 0.1);
            border: 1px solid var(--danger);
            color: var(--danger);
            padding: 12px;
            border-radius: 8px;
            font-size: 13px;
            margin-bottom: 16px;
            display: none;
        }

        .auth-error.active {
            display: block;
        }

        .auth-success {
            background: rgba(16, 185, 129, 0.1);
            border: 1px solid var(--success);
            color: var(--success);
            padding: 12px;
            border-radius: 8px;
            font-size: 13px;
            margin-bottom: 16px;
            display: none;
        }

        .auth-success.active {
            display: block;
        }

        .user-menu {
            position: relative;
        }

        .user-button {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 8px 12px;
            background: var(--bg-tertiary);
            border: 1px solid var(--border);
            border-radius: 8px;
            color: var(--text-primary);
            cursor: pointer;
            transition: all 0.2s;
        }

        .user-button:hover {
            background: var(--bg-primary);
            border-color: var(--accent);
        }

        .user-avatar {
            width: 28px;
            height: 28px;
            border-radius: 50%;
            background: var(--accent);
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: 600;
            font-size: 12px;
        }

        .user-dropdown {
            position: absolute;
            top: calc(100% + 8px);
            right: 0;
            background: var(--bg-secondary);
            border: 1px solid var(--border);
            border-radius: 8px;
            min-width: 200px;
            box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
            display: none;
            z-index: 1000;
        }

        .user-dropdown.active {
            display: block;
        }

        .user-dropdown-item {
            padding: 12px 16px;
            border-bottom: 1px solid var(--border);
            cursor: pointer;
            transition: background 0.2s;
            font-size: 13px;
        }

        .user-dropdown-item:last-child {
            border-bottom: none;
        }

        .user-dropdown-item:hover {
            background: var(--bg-tertiary);
        }

        .user-info-section {
            padding: 12px 16px;
            border-bottom: 1px solid var(--border);
        }

        .user-email {
            font-size: 12px;
            color: var(--text-secondary);
        }

        .login-button {
            padding: 8px 16px;
            background: var(--accent);
            color: white;
            border: none;
            border-radius: 6px;
            font-size: 13px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.2s;
        }

        .login-button:hover {
            background: var(--accent-hover);
        }

/* ==================== SERVER OFFLINE PAGE ==================== */
#offline-page {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(135deg, #1a1d23 0%, #23262d 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.offline-container {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 48px;
    max-width: 600px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.offline-icon {
    font-size: 72px;
    margin-bottom: 24px;
    animation: pulse 2s ease-in-out infinite;
}

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

.offline-container h1 {
    font-size: 32px;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.offline-container > p {
    font-size: 18px;
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.offline-message {
    background: var(--bg-tertiary);
    border-radius: 8px;
    padding: 24px;
    margin: 24px 0;
    text-align: left;
}

.offline-message p {
    margin-bottom: 12px;
    color: var(--text-primary);
}

.offline-message ul {
    margin-left: 20px;
    line-height: 1.8;
    color: var(--text-secondary);
}

.offline-message li {
    margin-bottom: 8px;
}

.offline-note {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 14px;
    font-style: italic;
}

.retry-btn {
    background: var(--accent);
    color: white;
    border: none;
    padding: 14px 32px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 24px;
}

.retry-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(91, 155, 213, 0.3);
}

.retry-btn span {
    font-size: 20px;
}

.auto-retry {
    margin-top: 16px;
    color: var(--text-secondary);
    font-size: 14px;
}

#retry-countdown {
    color: var(--accent);
    font-weight: 600;
}
