<!DOCTYPE html>
<html lang="en" class="h-full">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>IEUM</title>
    <link rel="icon" type="image/x-icon" href="/static/favicon.ico">
    <!-- Local Fonts -->
    <link rel="stylesheet" href="/static/fonts/fonts.css">
    <!-- Tailwind CSS (Local) -->
    <script src="/static/vendor/tailwind/tailwind.min.js"></script>
    <link rel="stylesheet" href="/static/css/styles.css">
    <!-- Monaco Editor (Local) -->
    <link rel="stylesheet" href="/static/vendor/monaco/vs/editor/editor.main.css">
    <script>
        tailwind.config = {
            darkMode: 'class',
            theme: {
                extend: {
                    colors: {
                        dark: {
                            50: '#f8fafc',
                            100: '#f1f5f9',
                            200: '#e2e8f0',
                            300: '#b8c5d6',
                            400: '#8b9cb3',
                            500: '#5f7082',
                            600: '#455261',
                            700: '#2d3848',
                            800: '#1e2632',
                            900: '#141a23',
                            950: '#0d1117',
                        },
                        vscode: {
                            bg: '#1a1d21',
                            sidebar: '#21252b',
                            active: '#2c313a',
                            border: '#3a3f4b',
                            text: '#abb2bf',
                            accent: '#4d8fcc',
                            muted: '#5c6370',
                        },
                        mx: {
                            blue: '#61afef',
                            green: '#98c379',
                            yellow: '#e5c07b',
                            red: '#e06c75',
                            purple: '#c678dd',
                            cyan: '#56b6c2',
                            orange: '#d19a66',
                        }
                    }
                }
            }
        }
    </script>
    <style>
        .resizer {
            width: 4px;
            cursor: col-resize;
            background: transparent;
            transition: background 0.2s;
        }
        .resizer:hover {
            background: #0e639c;
        }
        .file-tree-item:hover {
            background: #2a2d2e;
        }
        .file-tree-item.selected {
            background: #37373d;
        }
        .tab-item {
            border-right: 1px solid #252526;
        }
        .tab-item.active {
            background: #1e1e1e;
            border-bottom: 1px solid #1e1e1e;
        }
        .tab-item:not(.active) {
            background: #2d2d2d;
        }
        /* Scrollbar */
        ::-webkit-scrollbar {
            width: 10px;
            height: 10px;
        }
        ::-webkit-scrollbar-track {
            background: transparent;
        }
        ::-webkit-scrollbar-thumb {
            background: #424242;
            border-radius: 5px;
        }
        ::-webkit-scrollbar-thumb:hover {
            background: #4f4f4f;
        }
        /* Animation */
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
        .message {
            animation: fadeIn 0.2s ease-out;
        }
        /* Input focus */
        #messageInput:focus {
            box-shadow: 0 0 0 1px #0e639c;
        }
        /* Drag and drop */
        .file-tree-item[draggable="true"] {
            cursor: grab;
        }
        .file-tree-item[draggable="true"]:active {
            cursor: grabbing;
        }
        .file-tree-item.opacity-50 {
            opacity: 0.5;
        }
        .drop-target.drag-over {
            background: rgba(78, 143, 204, 0.2);
            border: 1px dashed #4d8fcc;
            border-radius: 4px;
        }
    </style>
</head>
<body class="h-full bg-vscode-bg text-vscode-text dark overflow-hidden">
    <div id="app" class="h-full flex flex-col">
        <!-- Main Layout -->
        <div class="flex-1 flex min-h-0 main-layout">
            <!-- Chat Panel (Left Side - 25%) -->
            <aside id="chatPanel" class="w-[25%] min-w-[280px] max-w-[400px] bg-vscode-sidebar flex flex-col border-r border-vscode-border relative">
                <!-- Chat Header with Project Name -->
                <div class="h-12 px-3 flex items-center justify-between border-b border-vscode-border">
                    <div class="flex items-center gap-2 flex-1 min-w-0">
                        <span id="projectName" class="text-lg font-bold tracking-wide truncate text-vscode-text">IEUM</span>
                    </div>
                    <div class="flex items-center">
                        <button id="newSessionBtn" class="p-1.5 hover:bg-vscode-active rounded text-dark-400 hover:text-white" data-tooltip="New conversation" data-i18n-tooltip="webui.new_session_tooltip">
                            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
                            </svg>
                        </button>
                        <button id="toggleSessionsBtn" class="p-1.5 hover:bg-vscode-active rounded text-dark-400 hover:text-white flex items-center gap-0.5" data-tooltip="Conversation history" data-i18n-tooltip="webui.session_history_tooltip">
                            <span id="sessionCount" class="text-[10px] text-dark-500">0</span>
                            <svg class="w-3.5 h-3.5 transition-transform" id="sessionChevron" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
                            </svg>
                        </button>
                    </div>
                </div>

                <!-- Session List (Dropdown) -->
                <div id="sessionListContainer" class="absolute left-0 right-0 top-12 z-10 bg-vscode-sidebar border border-vscode-border shadow-lg hidden max-h-72 overflow-y-auto">
                    <div id="sessionList">
                        <!-- Sessions loaded dynamically -->
                    </div>
                </div>

                <!-- Messages -->
                <div id="messages" class="flex-1 overflow-y-auto p-3 space-y-3">
                </div>

                <!-- Input Area -->
                <div class="p-3 border-t border-transparent bg-vscode-sidebar">
                    <div class="flex items-center gap-2">
                        <textarea
                            id="messageInput"
                            rows="1"
                            placeholder="Type a message... (/ commands, @ file reference, ? shortcuts)"
                            data-i18n-placeholder="webui.placeholder"
                            class="flex-1 bg-vscode-bg border border-vscode-border rounded-lg px-3 py-2.5 text-sm text-vscode-text placeholder-dark-500 resize-none focus:outline-none focus:border-vscode-accent transition-all"
                        ></textarea>
                        <button
                            id="sendBtn"
                            class="w-9 h-9 flex-shrink-0 flex items-center justify-center rounded-lg bg-vscode-accent text-white hover:bg-vscode-accent/80 active:scale-95 transition-all duration-150 disabled:opacity-50 disabled:cursor-not-allowed"
                            data-tooltip="Send (Enter)" data-tooltip-pos="top" data-i18n-tooltip="webui.send_tooltip"
                        >
                            <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24">
                                <path d="M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"/>
                            </svg>
                        </button>
                    </div>
                    <div class="flex items-center justify-between mt-2 px-1">
                        <label class="flex items-center gap-2 cursor-pointer text-xs text-dark-500 hover:text-dark-300 transition-colors">
                            <button id="autoApproveToggleBtn" class="relative w-7 h-4 rounded-full bg-vscode-border transition-colors">
                                <span id="autoApproveIndicator" class="absolute left-0.5 top-0.5 w-3 h-3 rounded-full bg-dark-400 transform transition-transform"></span>
                            </button>
                            <span id="autoApproveText" data-i18n="webui.auto_approve_label">Auto-approve</span>
                        </label>
                        <div class="flex items-center gap-1">
                            <span id="modelName" class="text-[10px] text-dark-500 truncate max-w-28"></span>
                            <button id="settingsBtn" class="p-1 hover:bg-vscode-active rounded text-dark-500 hover:text-white" data-tooltip="Model settings" data-i18n-tooltip="webui.settings_tooltip">
                                <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"/>
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/>
                                </svg>
                            </button>
                        </div>
                    </div>
                </div>
            </aside>

            <!-- Chat Resizer -->
            <div class="resizer" id="chatResizer"></div>

            <!-- VS Code Style Editor Section (75%) -->
            <div class="flex-1 flex min-w-0 editor-section">
                <!-- File Explorer Panel -->
                <aside id="explorerPanel" class="w-56 bg-vscode-sidebar flex flex-col border-r border-vscode-border">
                    <!-- Editor Toolbar -->
                    <div class="h-9 px-2 flex items-center gap-1 border-b border-vscode-border">
                        <button id="newFolderBtn" class="p-1.5 hover:bg-vscode-active rounded text-dark-400 hover:text-white" data-tooltip="New folder" data-i18n-tooltip="webui.new_folder_tooltip">
                            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 13h6m-3-3v6m-9 1V7a2 2 0 012-2h6l2 2h6a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2z"/>
                            </svg>
                        </button>
                        <button id="newFileBtn" class="p-1.5 hover:bg-vscode-active rounded text-dark-400 hover:text-white" data-tooltip="New file" data-i18n-tooltip="webui.new_file_tooltip">
                            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 13h6m-3-3v6m5 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
                            </svg>
                        </button>
                        <div class="w-px h-4 bg-vscode-border mx-1"></div>
                        <button id="saveFileBtn" class="p-1.5 hover:bg-vscode-active rounded text-dark-400 hover:text-white" data-tooltip="Save (Ctrl+S)" data-i18n-tooltip="webui.save_tooltip">
                            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7H5a2 2 0 00-2 2v9a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-3m-1 4l-3 3m0 0l-3-3m3 3V4"/>
                            </svg>
                        </button>
                        <button id="saveAllBtn" class="p-1.5 hover:bg-vscode-active rounded text-dark-400 hover:text-white" data-tooltip="Save all (Ctrl+Shift+S)" data-i18n-tooltip="webui.save_all_tooltip">
                            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 16v2a2 2 0 01-2 2H5a2 2 0 01-2-2V9a2 2 0 012-2h2m3-4h6l2 2h4a2 2 0 012 2v8a2 2 0 01-2 2H8a2 2 0 01-2-2V7a2 2 0 012-2z"/>
                            </svg>
                        </button>
                        <div class="w-px h-4 bg-vscode-border mx-1"></div>
                        <button id="undoBtn" class="p-1.5 hover:bg-vscode-active rounded text-dark-400 hover:text-white" data-tooltip="Undo (Ctrl+Z)" data-i18n-tooltip="webui.undo_tooltip">
                            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"/>
                            </svg>
                        </button>
                        <button id="redoBtn" class="p-1.5 hover:bg-vscode-active rounded text-dark-400 hover:text-white" data-tooltip="Redo (Ctrl+Y)" data-i18n-tooltip="webui.redo_tooltip">
                            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 10h-10a8 8 0 00-8 8v2M21 10l-6 6m6-6l-6-6"/>
                            </svg>
                        </button>
                    </div>
                    <!-- File Tree Section -->
                    <div class="flex-1 flex flex-col min-h-0">
                        <div class="h-6 px-2 flex items-center justify-between text-[11px] font-semibold uppercase tracking-wider text-dark-400 group">
                            <div class="flex items-center gap-1">
                                <svg class="w-3 h-3 transform rotate-90" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/>
                                </svg>
                                <span id="fileTreeProjectName">IEUM</span>
                            </div>
                            <button id="toggleHiddenBtn" class="p-0.5 hover:bg-vscode-active rounded" data-tooltip="Show hidden files" data-i18n-tooltip="webui.show_hidden_tooltip">
                                <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 5.411m0 0L21 21"/>
                                </svg>
                            </button>
                            <button id="refreshFilesBtn" class="p-0.5 hover:bg-vscode-active rounded" data-tooltip="Refresh" data-i18n-tooltip="webui.refresh_tooltip">
                                <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
                                </svg>
                            </button>
                        </div>
                        <div id="fileTree" class="flex-1 overflow-y-auto text-[13px]">
                        </div>
                    </div>
                </aside>

                <!-- Explorer Resizer -->
                <div class="resizer" id="explorerResizer"></div>

                <!-- Editor Area -->
                <main class="flex-1 flex flex-col min-w-0 bg-vscode-bg">
                    <!-- Tabs -->
                    <div class="h-9 bg-vscode-sidebar flex items-end border-b border-vscode-border">
                        <div id="editorTabs" class="flex h-full">
                        </div>
                    </div>

                    <!-- Breadcrumb -->
                    <div id="breadcrumb" class="h-6 px-3 flex items-center text-xs text-dark-400 bg-vscode-bg border-b border-vscode-border">
                        <span data-i18n="webui.select_file">Select a file</span>
                    </div>

                    <!-- Monaco Editor Container -->
                    <div id="editorContainer" class="flex-1 relative">
                        <div id="welcomeScreen" class="absolute inset-0 flex items-center justify-center">
                            <div class="text-center">
                                <svg class="w-20 h-20 mx-auto mb-4 text-dark-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1" d="M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"/>
                                </svg>
                                <h2 class="text-xl font-light text-dark-400 mb-2" data-i18n="webui.editor_welcome_title">IEUM Editor</h2>
                                <p class="text-dark-500 text-sm" data-i18n="webui.editor_welcome_hint">Select a file to edit</p>
                            </div>
                        </div>
                        <div id="monacoEditor" class="absolute inset-0 hidden"></div>
                    </div>
                </main>
            </div>
        </div>

        <!-- Status Bar -->
        <footer class="h-6 bg-vscode-accent flex items-center justify-between px-3 text-xs text-white status-bar">
            <div class="flex items-center gap-4">
                <span id="connectionStatus" class="flex items-center gap-1">
                    <span class="w-2 h-2 rounded-full bg-mx-green"></span>
                    <span data-i18n="webui.connected">Connected</span>
                </span>
                <span id="currentFile" data-i18n="webui.no_file">No file</span>
            </div>
            <div class="flex items-center gap-4">
                <span id="cursorPosition">Ln 1, Col 1</span>
                <span id="fileEncoding">UTF-8</span>
                <span id="fileLanguage">Plain Text</span>
            </div>
        </footer>
    </div>

    <!-- Settings Modal -->
    <div id="settingsModal" class="fixed inset-0 bg-black/50 backdrop-blur-sm hidden items-center justify-center z-50">
        <div class="bg-vscode-sidebar border border-vscode-border rounded-lg shadow-2xl max-w-lg w-full mx-4 max-h-[80vh] flex flex-col">
            <div class="p-4 border-b border-vscode-border flex items-center justify-between">
                <h3 class="font-medium text-white" data-i18n="webui.settings_title">Settings</h3>
                <button id="closeSettingsBtn" class="p-1 hover:bg-vscode-active rounded">
                    <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
                    </svg>
                </button>
            </div>
            <div class="p-4 space-y-4 overflow-y-auto">
                <!-- Model Provider -->
                <div class="space-y-2">
                    <label class="text-sm font-medium">Provider</label>
                    <select id="providerSelect" class="w-full bg-vscode-bg border border-vscode-border rounded px-3 py-2 text-sm focus:outline-none focus:border-vscode-accent">
                        <option value="ollama">Ollama</option>
                        <option value="vllm">vLLM</option>
                        <option value="lmstudio">LM Studio</option>
                        <option value="openrouter">OpenRouter</option>
                        <option value="openai">OpenAI</option>
                        <option value="anthropic">Anthropic</option>
                    </select>
                </div>

                <!-- Base URL -->
                <div id="baseUrlGroup" class="space-y-2">
                    <label class="text-sm font-medium">Base URL</label>
                    <input type="text" id="baseUrlInput" placeholder="http://localhost:11434"
                        class="w-full bg-vscode-bg border border-vscode-border rounded px-3 py-2 text-sm placeholder-dark-500 focus:outline-none focus:border-vscode-accent">
                </div>

                <!-- API Key -->
                <div id="apiKeyGroup" class="space-y-2 hidden">
                    <label class="text-sm font-medium">API Key</label>
                    <div class="relative">
                        <input type="password" id="apiKeyInput" placeholder="sk-..."
                            class="w-full bg-vscode-bg border border-vscode-border rounded px-3 py-2 pr-10 text-sm placeholder-dark-500 focus:outline-none focus:border-vscode-accent">
                        <button type="button" id="toggleApiKeyBtn" class="absolute right-2 top-1/2 -translate-y-1/2 p-1 text-dark-400 hover:text-white" data-tooltip="Show/Hide key" data-i18n-tooltip="webui.toggle_api_key" data-tooltip-pos="left">
                            <svg id="eyeIcon" class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/>
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/>
                            </svg>
                            <svg id="eyeOffIcon" class="w-4 h-4 hidden" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 5.411m0 0L21 21"/>
                            </svg>
                        </button>
                    </div>
                </div>

                <!-- Model Selection -->
                <div class="space-y-2">
                    <div class="flex items-center justify-between">
                        <label class="text-sm font-medium">Model</label>
                        <button id="refreshModelsBtn" class="text-xs text-dark-400 hover:text-white flex items-center gap-1">
                            <svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
                            </svg>
                            Refresh
                        </button>
                    </div>
                    <div id="modelSelectWrapper">
                        <select id="modelSelect" class="w-full bg-vscode-bg border border-vscode-border rounded px-3 py-2 text-sm focus:outline-none focus:border-vscode-accent">
                            <option value="">Select a model...</option>
                        </select>
                    </div>
                    <div id="modelInputWrapper" class="hidden">
                        <input type="text" id="modelInput" placeholder="gpt-4o, claude-3-opus, etc."
                            class="w-full bg-vscode-bg border border-vscode-border rounded px-3 py-2 text-sm placeholder-dark-500 focus:outline-none focus:border-vscode-accent">
                    </div>
                    <p id="modelStatus" class="text-xs text-dark-500 hidden"></p>
                </div>
            </div>

            <!-- GitHub Integration -->
            <div class="px-4 pb-4 border-t border-vscode-border pt-4 mt-2">
                <div class="flex items-center gap-2 mb-3">
                    <svg class="w-4 h-4 text-white" fill="currentColor" viewBox="0 0 24 24">
                        <path fill-rule="evenodd" clip-rule="evenodd" d="M12 2C6.477 2 2 6.477 2 12c0 4.42 2.87 8.17 6.84 9.5.5.08.66-.23.66-.5v-1.69c-2.77.6-3.36-1.34-3.36-1.34-.46-1.16-1.11-1.47-1.11-1.47-.91-.62.07-.6.07-.6 1 .07 1.53 1.03 1.53 1.03.87 1.52 2.34 1.07 2.91.83.09-.65.35-1.09.63-1.34-2.22-.25-4.55-1.11-4.55-4.92 0-1.11.38-2 1.03-2.71-.1-.25-.45-1.29.1-2.64 0 0 .84-.27 2.75 1.02.79-.22 1.65-.33 2.5-.33.85 0 1.71.11 2.5.33 1.91-1.29 2.75-1.02 2.75-1.02.55 1.35.2 2.39.1 2.64.65.71 1.03 1.6 1.03 2.71 0 3.82-2.34 4.66-4.57 4.91.36.31.69.92.69 1.85V21c0 .27.16.59.67.5C19.14 20.16 22 16.42 22 12A10 10 0 0012 2z"/>
                    </svg>
                    <span class="text-sm font-medium">GitHub Integration</span>
                </div>
                <div class="space-y-3">
                    <div class="space-y-1">
                        <label class="text-xs text-dark-400">Personal Access Token</label>
                        <input type="password" id="githubPatInput" placeholder="ghp_..."
                            class="w-full bg-vscode-bg border border-vscode-border rounded px-3 py-2 text-sm placeholder-dark-500 focus:outline-none focus:border-vscode-accent">
                        <p class="text-[10px] text-dark-500" data-i18n="webui.github_enterprise_note">GitHub Enterprise supported. Token enables GitHub MCP automatically</p>
                    </div>
                    <div class="space-y-1">
                        <label class="text-xs text-dark-400">GitHub Host (Enterprise)</label>
                        <input type="text" id="githubHostInput" placeholder="https://github.com"
                            class="w-full bg-vscode-bg border border-vscode-border rounded px-3 py-2 text-sm placeholder-dark-500 focus:outline-none focus:border-vscode-accent">
                        <p class="text-[10px] text-dark-500" data-i18n="webui.github_host_note">Default: github.com / Enterprise: your-company.ghe.com</p>
                    </div>
                </div>
            </div>

            <!-- Language Setting -->
            <div class="px-4 pb-4 border-t border-vscode-border pt-4 mt-2">
                <label class="block text-xs text-dark-400 mb-1" data-i18n="webui.language_label">Language</label>
                <select id="languageSelect" class="w-full bg-vscode-bg border border-vscode-border rounded px-3 py-2 text-sm focus:outline-none focus:border-vscode-accent">
                    <option value="en">English</option>
                    <option value="ko">한국어 (Korean)</option>
                </select>
            </div>

            <!-- Save Location -->
            <div class="px-4 pb-2">
                <label class="block text-xs text-dark-400 mb-1" data-i18n="webui.settings_save_location_label">Settings save location</label>
                <select id="saveLocationSelect" class="w-full bg-vscode-bg border border-vscode-border rounded px-3 py-2 text-sm focus:outline-none focus:border-vscode-accent">
                    <option value="global" data-i18n="webui.settings_save_location_global">Global (~/.ieum/.env)</option>
                    <option value="local" data-i18n="webui.settings_save_location_local">Local (project/.env)</option>
                </select>
            </div>

            <!-- Save Button -->
            <div class="p-4 border-t border-vscode-border">
                <button id="saveSettingsBtn" class="w-full py-2 px-4 bg-vscode-accent text-white rounded font-medium hover:bg-blue-600 transition-colors">
                    <span data-i18n="webui.settings_save_btn">Save</span>
                </button>
            </div>
        </div>
    </div>

    <!-- W01: Mobile Overlay (for file tree drawer) -->
    <div id="mobileOverlay" class="mobile-overlay" onclick="window.__closeMobilePanels && window.__closeMobilePanels()"></div>

    <!-- W01: Mobile Explorer Toggle (hamburger) -->
    <button id="mobileExplorerToggle" class="mobile-explorer-toggle" aria-label="Toggle file explorer" onclick="window.__toggleMobileExplorer && window.__toggleMobileExplorer()">
        <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"/>
        </svg>
    </button>

    <!-- W01: Mobile Bottom Navigation -->
    <nav id="mobileNav" class="mobile-nav" role="navigation" aria-label="Mobile navigation">
        <button class="mobile-nav-btn active" data-panel="chat" onclick="window.__switchMobilePanel && window.__switchMobilePanel('chat')">
            <svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"/>
            </svg>
            <span>Chat</span>
        </button>
        <button class="mobile-nav-btn" data-panel="editor" onclick="window.__switchMobilePanel && window.__switchMobilePanel('editor')">
            <svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"/>
            </svg>
            <span>Editor</span>
        </button>
        <button class="mobile-nav-btn" data-panel="files" onclick="window.__toggleMobileExplorer && window.__toggleMobileExplorer()">
            <svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"/>
            </svg>
            <span>Files</span>
        </button>
    </nav>

    <!-- Toast Container -->
    <div id="toastContainer" class="fixed bottom-10 right-4 space-y-2 z-50"></div>

    <!-- Monaco Editor Loader (Local) -->
    <script src="/static/vendor/monaco/vs/loader.js"></script>
    <script>
        require.config({ paths: { vs: '/static/vendor/monaco/vs' } });
        window.monacoReady = new Promise(resolve => {
            require(['vs/editor/editor.main'], function () {
                resolve(monaco);
            });
        });
    </script>
    <!-- i18n: Load translations before app.js -->
    <script>
    (function() {
        'use strict';
        // Detect locale from browser or localStorage
        var savedLocale = localStorage.getItem('ieum_lang');
        var browserLocale = (navigator.language || navigator.userLanguage || 'en').split('-')[0];
        var locale = savedLocale || (['en', 'ko'].indexOf(browserLocale) >= 0 ? browserLocale : 'en');

        // Set html lang attribute
        document.documentElement.lang = locale;

        // Store globally for app.js to use
        window.__ieum_locale = locale;
        window.__ieum_i18n = {};

        // Fetch translations
        fetch('/api/i18n/' + locale)
            .then(function(r) { return r.json(); })
            .then(function(data) {
                window.__ieum_i18n = data;
                // Apply translations to static HTML elements with data-i18n attributes
                document.querySelectorAll('[data-i18n]').forEach(function(el) {
                    var key = el.getAttribute('data-i18n');
                    if (data[key]) el.textContent = data[key];
                });
                document.querySelectorAll('[data-i18n-tooltip]').forEach(function(el) {
                    var key = el.getAttribute('data-i18n-tooltip');
                    if (data[key]) el.setAttribute('data-tooltip', data[key]);
                });
                document.querySelectorAll('[data-i18n-placeholder]').forEach(function(el) {
                    var key = el.getAttribute('data-i18n-placeholder');
                    if (data[key]) el.setAttribute('placeholder', data[key]);
                });
            })
            .catch(function() { /* fallback: keep English defaults */ });
    })();
    </script>
    <script src="/static/js/app.js"></script>
    <!-- W01: Mobile Responsive Panel Switching -->
    <script>
    (function() {
        'use strict';

        var MOBILE_BREAKPOINT = 768;
        var currentPanel = 'chat';

        function isMobile() {
            return window.innerWidth <= MOBILE_BREAKPOINT;
        }

        function switchMobilePanel(panel) {
            if (!isMobile()) return;
            currentPanel = panel;

            var chatPanel = document.getElementById('chatPanel');
            var editorSection = document.querySelector('.editor-section');
            var explorerPanel = document.getElementById('explorerPanel');
            var overlay = document.getElementById('mobileOverlay');
            var navBtns = document.querySelectorAll('.mobile-nav-btn');

            // Close file explorer overlay if open
            if (panel !== 'files') {
                explorerPanel.classList.remove('mobile-active');
                overlay.classList.remove('active');
            }

            // Update nav button active states
            navBtns.forEach(function(btn) {
                btn.classList.toggle('active', btn.getAttribute('data-panel') === panel);
            });

            if (panel === 'chat') {
                chatPanel.classList.remove('mobile-hidden');
                editorSection.classList.remove('mobile-active');
            } else if (panel === 'editor') {
                chatPanel.classList.add('mobile-hidden');
                editorSection.classList.add('mobile-active');
            }
        }

        function toggleMobileExplorer() {
            var explorerPanel = document.getElementById('explorerPanel');
            var overlay = document.getElementById('mobileOverlay');
            var isActive = explorerPanel.classList.contains('mobile-active');

            if (isActive) {
                explorerPanel.classList.remove('mobile-active');
                overlay.classList.remove('active');
            } else {
                explorerPanel.classList.add('mobile-active');
                overlay.classList.add('active');
            }
        }

        function closeMobilePanels() {
            var explorerPanel = document.getElementById('explorerPanel');
            var overlay = document.getElementById('mobileOverlay');
            explorerPanel.classList.remove('mobile-active');
            overlay.classList.remove('active');
        }

        // Reset layout when resizing from mobile to desktop
        function handleResize() {
            if (!isMobile()) {
                var chatPanel = document.getElementById('chatPanel');
                var editorSection = document.querySelector('.editor-section');
                var explorerPanel = document.getElementById('explorerPanel');
                var overlay = document.getElementById('mobileOverlay');

                chatPanel.classList.remove('mobile-hidden');
                editorSection.classList.remove('mobile-active');
                explorerPanel.classList.remove('mobile-active');
                overlay.classList.remove('active');
            }
        }

        window.addEventListener('resize', handleResize);

        // Expose to global scope for onclick handlers
        window.__switchMobilePanel = switchMobilePanel;
        window.__toggleMobileExplorer = toggleMobileExplorer;
        window.__closeMobilePanels = closeMobilePanels;
    })();
    </script>
</body>
</html>
