        /* ========================================
           MOBILE-FIRST BASE STYLES
           ======================================== */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        html, body {
            height: 100%;
            overflow: hidden;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background: #667eea;
            /* Handle safe areas for notched devices */
            padding-top: env(safe-area-inset-top);
            padding-left: env(safe-area-inset-left);
            padding-right: env(safe-area-inset-right);
        }

        /* Main app wrapper - mobile uses fixed positioning */
        .app {
            height: 100%;
            height: 100dvh;
            display: flex;
            flex-direction: column;
            overflow: hidden;
            background: #f5f5f5;
        }

        /* ========================================
           HEADER - Always visible
           ======================================== */
        .app-header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 12px 16px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            flex-shrink: 0;
            z-index: 100;
        }

        .app-header h1 {
            font-size: 16px;
            font-weight: 600;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .info-btn {
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background: rgba(255,255,255,0.3);
            border: none;
            color: white;
            font-size: 12px;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        /* Toggle Switch */
        .toggle-switch {
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .toggle-label {
            font-size: 14px;
            font-weight: 600;
            color: white;
        }

        .toggle-switch input {
            display: none;
        }

        .toggle-slider {
            width: 48px;
            height: 26px;
            background: rgba(255,255,255,0.3);
            border-radius: 26px;
            cursor: pointer;
            position: relative;
            transition: background 0.3s;
        }

        .toggle-slider::before {
            content: '';
            position: absolute;
            top: 2px;
            left: 2px;
            width: 22px;
            height: 22px;
            background: white;
            border-radius: 50%;
            transition: transform 0.3s;
            box-shadow: 0 2px 4px rgba(0,0,0,0.2);
        }

        .toggle-switch input:checked + .toggle-slider {
            background: rgba(255,255,255,0.5);
        }

        .toggle-switch input:checked + .toggle-slider::before {
            transform: translateX(22px);
        }

        /* ========================================
           CONTENT AREA - Fills middle space
           ======================================== */
        .content-area {
            flex: 1;
            overflow: hidden;
            position: relative;
            background: white;
        }

        /* Each panel takes full space, only one visible at a time */
        .panel {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            display: none;
            flex-direction: column;
            overflow: hidden;
            background: white;
        }

        .panel.active {
            display: flex;
        }

        .panel-scroll {
            flex: 1;
            overflow-y: auto;
            -webkit-overflow-scrolling: touch;
            padding: 16px;
        }

        /* ========================================
           CHAT PANEL
           ======================================== */
        #chatPanel .panel-scroll {
            padding: 16px;
            padding-bottom: 0;
        }

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

        .message {
            display: flex;
            gap: 10px;
            align-items: flex-start;
        }

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

        .message-avatar {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 10px;
            font-weight: 600;
            flex-shrink: 0;
        }

        .message.user .message-avatar {
            background: #667eea;
            color: white;
        }

        .message.bot .message-avatar {
            background: #e5e7eb;
            color: #374151;
        }

        .message.bot .message-avatar.rag {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }

        .message-content {
            max-width: 80%;
            padding: 10px 14px;
            border-radius: 16px;
            font-size: 14px;
            line-height: 1.4;
        }

        .message.user .message-content {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border-bottom-right-radius: 4px;
            cursor: pointer;
            transition: opacity 0.2s;
        }

        .message.user .message-content:hover {
            opacity: 0.85;
        }

        .message.bot .message-content {
            background: #f3f4f6;
            color: #1f2937;
            border-bottom-left-radius: 4px;
        }

        .message.system .message-content {
            background: #fef3c7;
            color: #92400e;
            max-width: 100%;
            text-align: center;
            font-size: 13px;
        }

        /* Chat input */
        .chat-input {
            padding: 12px 16px;
            background: white;
            border-top: 1px solid #e5e7eb;
            display: flex;
            gap: 10px;
            flex-shrink: 0;
        }

        .chat-input textarea {
            flex: 1;
            padding: 10px 16px;
            border: 1px solid #e5e7eb;
            border-radius: 18px;
            font-size: 16px;
            outline: none;
            resize: none;
            font-family: inherit;
            line-height: 1.4;
            min-height: 44px;
            max-height: 80px;
        }

        .chat-input textarea:focus {
            border-color: #667eea;
        }

        .chat-input button {
            padding: 12px 20px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            border-radius: 24px;
            font-weight: 600;
            cursor: pointer;
        }

        /* ========================================
           QUESTIONS PANEL
           ======================================== */
        .section-title {
            font-size: 11px;
            font-weight: 600;
            color: #6b7280;
            text-transform: uppercase;
            margin: 16px 0 8px 0;
            letter-spacing: 0.5px;
        }

        .section-title:first-child {
            margin-top: 0;
        }

        .question-item {
            padding: 14px 16px;
            background: #f9fafb;
            border: 1px solid #e5e7eb;
            border-radius: 12px;
            margin-bottom: 8px;
            cursor: pointer;
            display: flex;
            align-items: center;
            gap: 12px;
            font-size: 14px;
            transition: background 0.2s;
        }

        .question-item:hover {
            background: #f3f4f6;
        }

        .question-item:active {
            background: #e5e7eb;
        }

        .question-icon {
            font-size: 18px;
        }

        /* ========================================
           SETTINGS PANEL
           ======================================== */
        .settings-section {
            margin-bottom: 24px;
        }

        .settings-section h3 {
            font-size: 14px;
            font-weight: 600;
            color: #374151;
            margin-bottom: 12px;
        }

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

        .setting-label {
            font-size: 13px;
            color: #6b7280;
            margin-bottom: 6px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            gap: 8px;
        }

        .setting-label-text {
            display: flex;
            align-items: center;
            gap: 6px;
        }

        .setting-value {
            font-weight: 600;
            color: #374151;
        }

        .info-icon {
            width: 18px;
            height: 18px;
            border-radius: 50%;
            background: #e5e7eb;
            color: #6b7280;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            font-size: 11px;
            font-weight: 600;
            cursor: help;
            flex-shrink: 0;
        }

        .info-icon:hover {
            background: #667eea;
            color: white;
        }

        /* Tooltip */
        .tooltip {
            position: fixed;
            background: #1f2937;
            color: white;
            padding: 8px 12px;
            border-radius: 8px;
            font-size: 12px;
            line-height: 1.4;
            max-width: 250px;
            z-index: 10000;
            pointer-events: none;
            opacity: 0;
            transition: opacity 0.2s;
        }

        .tooltip.visible {
            opacity: 1;
        }

        input[type="range"] {
            width: 100%;
            height: 6px;
            border-radius: 3px;
            background: #e5e7eb;
            outline: none;
            -webkit-appearance: none;
        }

        input[type="range"]::-webkit-slider-thumb {
            -webkit-appearance: none;
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background: #667eea;
            cursor: pointer;
        }

        .checkbox-item {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 12px;
            background: #f9fafb;
            border-radius: 8px;
            margin-bottom: 8px;
        }

        .checkbox-item input {
            width: 18px;
            height: 18px;
            accent-color: #667eea;
        }

        .checkbox-item label {
            font-size: 14px;
            color: #374151;
        }

        .doc-link {
            display: block;
            width: 100%;
            padding: 14px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            text-decoration: none;
            border-radius: 12px;
            text-align: center;
            font-weight: 600;
            font-size: 14px;
            margin-top: 16px;
            border: none;
            cursor: pointer;
        }

        /* Document Panel */
        .panel-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 12px 16px;
            background: #f9fafb;
            border-bottom: 1px solid #e5e7eb;
            flex-shrink: 0;
        }

        .back-btn {
            display: flex;
            align-items: center;
            gap: 4px;
            background: none;
            border: none;
            color: #667eea;
            font-size: 14px;
            font-weight: 500;
            cursor: pointer;
            padding: 8px;
            margin: -8px;
        }

        .back-btn svg {
            width: 20px;
            height: 20px;
        }

        .panel-title {
            font-weight: 600;
            color: #374151;
        }

        .close-btn {
            background: none;
            border: none;
            font-size: 20px;
            color: #9ca3af;
            cursor: pointer;
            padding: 8px;
            margin: -8px;
        }

        .close-btn:hover {
            color: #374151;
        }

        #documentContent {
            font-size: 14px;
            line-height: 1.7;
            color: #374151;
        }

        #documentContent .document-text {
            white-space: pre-wrap;
            font-family: Georgia, serif;
        }

        .loading {
            text-align: center;
            color: #9ca3af;
            padding: 40px;
        }

        /* Loading spinner */
        .loading-message {
            display: flex;
            gap: 10px;
            align-items: flex-start;
        }

        .loading-message .message-content {
            display: flex;
            align-items: center;
            gap: 10px;
            background: #f3f4f6;
            color: #6b7280;
        }

        .spinner {
            width: 18px;
            height: 18px;
            border: 2px solid #e5e7eb;
            border-top-color: #667eea;
            border-radius: 50%;
            animation: spin 0.8s linear infinite;
        }

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

        /* ========================================
           PROCESS PANEL
           ======================================== */
        .process-step {
            padding: 14px;
            background: #f9fafb;
            border-left: 3px solid #667eea;
            border-radius: 0 8px 8px 0;
            margin-bottom: 12px;
        }

        .process-step.complete {
            border-left-color: #10b981;
        }

        .step-header {
            display: flex;
            align-items: center;
            gap: 10px;
            margin-bottom: 6px;
            flex-wrap: nowrap;
        }

        .step-icon {
            width: 24px;
            height: 24px;
            border-radius: 50%;
            background: #667eea;
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 12px;
        }

        .step-icon.complete {
            background: #10b981;
        }

        .step-title {
            font-weight: 600;
            font-size: 13px;
            text-transform: uppercase;
            color: #374151;
        }

        .step-description {
            font-size: 13px;
            color: #6b7280;
            margin-left: 34px;
        }

        .step-duration {
            font-size: 12px;
            color: #9ca3af;
            margin-left: 34px;
            margin-top: 4px;
        }

        .no-process {
            text-align: center;
            color: #9ca3af;
            padding: 40px;
        }

        .process-step.expandable {
            cursor: pointer;
        }

        .process-step.expandable:hover {
            background: #f3f4f6;
        }

        .expand-arrow {
            margin-left: auto;
            color: #9ca3af;
            font-size: 12px;
            transition: transform 0.2s;
        }

        .step-detail {
            margin-top: 12px;
            margin-left: 34px;
            padding: 12px;
            background: #f9fafb;
            border-radius: 8px;
            border: 1px solid #e5e7eb;
            font-size: 12px;
            overflow-x: auto;
        }

        .step-data-content {
            display: flex;
            flex-direction: column;
            gap: 8px;
        }

        .data-item {
            display: flex;
            flex-direction: column;
            gap: 2px;
        }

        .data-key {
            font-weight: 600;
            color: #374151;
            font-size: 11px;
            text-transform: uppercase;
        }

        .data-value {
            color: #6b7280;
            word-break: break-word;
            white-space: pre-wrap;
            font-family: monospace;
            font-size: 11px;
            background: white;
            padding: 6px 8px;
            border-radius: 4px;
            border: 1px solid #e5e7eb;
        }

        /* ========================================
           TAB BAR - Always at bottom
           ======================================== */
        .tab-bar {
            display: flex;
            background: white;
            border-top: 1px solid #e5e7eb;
            padding: 8px 0;
            padding-bottom: calc(8px + env(safe-area-inset-bottom));
            flex-shrink: 0;
            z-index: 100;
        }

        /* Extra padding for PWA standalone mode only */
        @media (display-mode: standalone) {
            .tab-bar {
                padding-bottom: max(60px, calc(40px + env(safe-area-inset-bottom)));
            }
        }

        /* iOS PWA detection via JavaScript class */
        .pwa-mode .app-header {
            padding-top: max(12px, calc(12px + env(safe-area-inset-top))) !important;
        }

        .pwa-mode .tab-bar {
            padding-bottom: 60px !important;
        }

        .tab-btn {
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 4px;
            padding: 8px;
            background: none;
            border: none;
            cursor: pointer;
            color: #9ca3af;
            font-size: 10px;
            font-weight: 500;
            transition: color 0.2s;
        }

        .tab-btn svg {
            width: 24px;
            height: 24px;
        }

        .tab-btn.active {
            color: #667eea;
        }

        /* ========================================
           MODAL
           ======================================== */
        .modal-overlay {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0,0,0,0.5);
            z-index: 1000;
            align-items: center;
            justify-content: center;
            padding: 20px;
        }

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

        .modal {
            background: white;
            border-radius: 16px;
            padding: 24px;
            max-width: 500px;
            width: 90%;
            max-height: 80vh;
            overflow-y: auto;
        }

        .modal h2 {
            font-size: 18px;
            margin-bottom: 12px;
        }

        .modal p {
            font-size: 14px;
            color: #6b7280;
            margin-bottom: 12px;
            line-height: 1.5;
        }

        .modal-close {
            float: right;
            background: none;
            border: none;
            font-size: 24px;
            cursor: pointer;
            color: #9ca3af;
        }

        .modal h3 {
            font-size: 16px;
            margin: 16px 0 8px 0;
            color: #374151;
        }

        .modal ol {
            margin: 12px 0;
            padding-left: 20px;
            color: #6b7280;
            font-size: 14px;
            line-height: 1.6;
        }

        .modal ol li {
            margin-bottom: 8px;
        }

        .flow-diagram {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 8px;
            margin: 15px 0;
            padding: 15px;
            background: #f9fafb;
            border-radius: 12px;
        }

        .flow-row {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            flex-wrap: wrap;
        }

        .flow-box {
            padding: 8px 12px;
            border-radius: 8px;
            font-size: 12px;
            font-weight: 500;
            text-align: center;
            white-space: nowrap;
        }

        .flow-box.user {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }

        .flow-box.process {
            background: #e0e7ff;
            color: #4338ca;
            border: 1px solid #c7d2fe;
        }

        .flow-box.data {
            background: #fef3c7;
            color: #92400e;
            border: 1px solid #fde68a;
        }

        .flow-box.result {
            background: #d1fae5;
            color: #065f46;
            border: 1px solid #a7f3d0;
        }

        .flow-arrow {
            color: #9ca3af;
            font-size: 16px;
            font-weight: bold;
        }

        .flow-arrow.down {
            font-size: 20px;
        }

        /* ========================================
           DESKTOP STYLES (min-width: 769px)
           ======================================== */
        @media (min-width: 769px) {
            .app {
                flex-direction: row;
            }

            /* Hide mobile tab bar on desktop */
            .tab-bar {
                display: none;
            }

            /* Show desktop sidebar */
            .desktop-sidebar {
                display: flex;
                flex-direction: column;
                width: 300px;
                border-right: 1px solid #e5e7eb;
                background: #f9fafb;
                flex-shrink: 0;
            }

            .desktop-sidebar-header {
                padding: 16px;
                background: #374151;
                color: white;
                font-weight: 600;
            }

            .desktop-sidebar-tabs {
                display: flex;
                border-bottom: 1px solid #e5e7eb;
            }

            .desktop-sidebar-tab {
                flex: 1;
                padding: 12px;
                background: none;
                border: none;
                cursor: pointer;
                font-size: 13px;
                font-weight: 500;
                color: #6b7280;
                border-bottom: 2px solid transparent;
            }

            .desktop-sidebar-tab:hover {
                background: #f3f4f6;
            }

            .desktop-sidebar-tab.active {
                color: #667eea;
                border-bottom-color: #667eea;
                background: white;
            }

            .desktop-sidebar-content {
                flex: 1;
                overflow-y: auto;
                padding: 16px;
                background: white;
            }

            /* Main area on desktop */
            .desktop-main {
                flex: 1;
                display: flex;
                flex-direction: column;
                min-width: 0;
            }

            .app-header {
                padding: 16px 24px;
            }

            .app-header h1 {
                font-size: 20px;
            }

            .content-area {
                flex: 1;
                display: flex;
                position: relative;
            }

            /* On desktop, chat and viz are side by side - always visible */
            #chatPanel {
                position: relative;
                flex: 1;
                border-right: 1px solid #e5e7eb;
                display: flex !important;
            }

            #processPanel {
                position: relative;
                width: 450px;
                flex-shrink: 0;
                background: #f9fafb;
                display: flex !important;
            }

            #processPanel::before {
                content: '🔍 Process Visualization';
                display: block;
                padding: 16px 20px;
                background: #374151;
                color: white;
                font-weight: 600;
                font-size: 16px;
                flex-shrink: 0;
            }

            #processPanel .panel-scroll {
                background: white;
                margin: 12px;
                border-radius: 8px;
                padding: 16px;
            }

            /* Document panel on desktop - overlay chat but not process panel */
            #documentPanel {
                position: absolute;
                left: 0;
                right: 450px; /* Leave space for process panel */
                top: 0;
                bottom: 0;
                z-index: 100;
                background: white;
            }

            #documentPanel .panel-scroll {
                overflow-y: auto;
                overflow-x: hidden;
                word-wrap: break-word;
            }

            /* Hide questions/settings panels on desktop (in sidebar) */
            #questionsPanel,
            #settingsPanel {
                display: none !important;
            }

            .chat-input {
                padding: 16px 24px;
            }

            .chat-input textarea {
                padding: 12px 20px;
            }
        }

        /* Hide desktop-only elements on mobile */
        @media (max-width: 768px) {
            .desktop-sidebar {
                display: none;
            }

            .desktop-main {
                display: contents;
            }
        }
