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91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>LCARS Multimodal Chat Agent</title>
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&display=swap');
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body {
            font-family: 'Orbitron', monospace;
            background: linear-gradient(135deg, #000 0%, #111 50%, #000 100%);
            color: #ff9900;
            min-height: 100vh;
            overflow-x: hidden;
        }
        .lcars-container {
            display: grid;
            grid-template-areas:
                "header"
                "main-content"
                "bottom-panel";
            grid-template-rows: auto 1fr auto;
            min-height: 100vh;
            padding: 20px;
            gap: 20px;
        }
        .header {
            grid-area: header;
            text-align: center;
            padding: 15px;
            background: rgba(255, 153, 0, 0.1);
            border: 2px solid #ff9900;
            border-radius: 15px;
        }
        .main-content {
            grid-area: main-content;
            display: flex;
            flex-direction: column;
            gap: 20px;
        }
        .chat-container {
            flex: 1;
            display: flex;
            flex-direction: column;
            background: rgba(0, 0, 0, 0.7);
            border: 2px solid #ff9900;
            border-radius: 15px;
            overflow: hidden;
        }
        .message-area {
            flex: 1;
            padding: 20px;
            overflow-y: auto;
            max-height: 500px;
        }
        .message {
            margin-bottom: 15px;
            padding: 10px;
            border-radius: 10px;
            animation: fadeIn 0.3s;
        }
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
        .user-message {
            background: rgba(255, 153, 0, 0.2);
            border-left: 4px solid #ff9900;
        }
        .assistant-message {
            background: rgba(0, 153, 255, 0.2);
            border-left: 4px solid #0099ff;
        }
        .thinking-message {
            background: rgba(153, 0, 255, 0.2);
            border-left: 4px solid #9900ff;
            font-style: italic;
        }
        .input-section {
            padding: 15px;
            background: rgba(50, 50, 50, 0.9);
            border-top: 2px solid #ff9900;
        }
        .input-row {
            display: flex;
            gap: 10px;
            margin-bottom: 10px;
            align-items: center;
        }
        .lcars-input {
            flex: 1;
            padding: 12px 20px;
            background: #333;
            border: 2px solid #ff9900;
            border-radius: 20px;
            color: #ff9900;
            font-family: 'Orbitron', monospace;
            font-size: 16px;
        }
        .lcars-input:focus {
            outline: none;
            border-color: #ffcc00;
            box-shadow: 0 0 10px rgba(255, 204, 0, 0.3);
        }
        .lcars-button {
            background: linear-gradient(45deg, #ff6600, #ff9900);
            border: none;
            border-radius: 20px;
            padding: 12px 25px;
            color: #000;
            font-family: 'Orbitron', monospace;
            font-weight: 700;
            cursor: pointer;
            transition: all 0.3s;
            text-transform: uppercase;
        }
        .lcars-button:hover {
            background: linear-gradient(45deg, #ff9900, #ffcc00);
            transform: translateY(-2px);
            box-shadow: 0 4px 15px rgba(255, 153, 0, 0.4);
        }
        .lcars-button:active {
            transform: translateY(0);
        }
        .file-input {
            display: none;
        }
        .file-label {
            background: linear-gradient(45deg, #0066cc, #0099ff);
            border: none;
            border-radius: 20px;
            padding: 12px 25px;
            color: #fff;
            font-family: 'Orbitron', monospace;
            font-weight: 700;
            cursor: pointer;
            transition: all 0.3s;
            text-transform: uppercase;
        }
        .file-label:hover {
            background: linear-gradient(45deg, #0099ff, #00ccff);
            transform: translateY(-2px);
            box-shadow: 0 4px 15px rgba(0, 153, 255, 0.4);
        }
        .status-bar {
            display: flex;
            justify-content: space-between;
            padding: 10px;
            background: rgba(255, 153, 0, 0.1);
            border: 1px solid #ff9900;
            border-radius: 10px;
            font-size: 14px;
        }
        .bottom-panel {
            grid-area: bottom-panel;
            text-align: center;
            padding: 15px;
            background: rgba(255, 153, 0, 0.1);
            border: 2px solid #ff9900;
            border-radius: 15px;
            font-size: 12px;
        }
        #file-status {
            color: #00ff99;
            font-weight: bold;
        }
        #system-status {
            color: #ff9900;
            font-weight: bold;
        }
        #message-count {
            color: #9900ff;
            font-weight: bold;
        }
        @media (max-width: 768px) {
            .input-row {
                flex-direction: column;
            }
            .lcars-button, .file-label {
                width: 100%;
            }
        }
    </style>
</head>
<body>
    <div class="lcars-container">
        <div class="header">
            <h1>L.C.A.R.S - Local Computer Advanced Reasoning System v3.0 </h1>
        </div>
        
        <div class="main-content">
            <div class="chat-container">
                <div class="message-area" id="messages">
                    <div class="message assistant-message">
                        <strong>SYSTEM:</strong> LCARS Multimodal Chat Agent initialized. Ready for communication.
                    </div>
                </div>
                <div class="input-section">
                    <div class="input-row">
                        <input type="text" class="lcars-input" id="user-input" placeholder="Enter your message..." />
                        <button class="lcars-button" onclick="sendMessage()">TRANSMIT</button>
                    </div>
                    <div class="input-row">
                        <input type="file" class="file-input" id="file-input" accept="*" />
                        <label for="file-input" class="file-label">๐Ÿ“Ž ATTACH FILE</label>
                        <button class="lcars-button" onclick="saveSession()">๐Ÿ’พ SAVE SESSION</button>
                        <button class="lcars-button" onclick="clearChat()">๐Ÿ—‘๏ธ CLEAR CHAT</button>
                    </div>
                    <div class="status-bar">
                        <span>File Status: <span id="file-status">NONE</span></span>
                        <span>System Status: <span id="system-status">SYSTEM ONLINE</span></span>
                        <span>Messages: <span id="message-count">0</span></span>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="bottom-panel">
            ๐Ÿš€ L.C.A.R.S - Enhanced Local Computer Advanced Reasoning System v3.0 โ€ข Starfleet Command โ€ข Computer Core Online
        </div>
    </div>

    <script>
        // Chat state
        let chatHistory = [];
        let messageCount = 1;
        let currentFile = null;
        
        // DOM Elements
        const messageArea = document.getElementById('messages');
        const userInput = document.getElementById('user-input');
        const fileInput = document.getElementById('file-input');
        const fileStatus = document.getElementById('file-status');
        const systemStatus = document.getElementById('system-status');
        const messageCountEl = document.getElementById('message-count');
        
        // File handling
        fileInput.addEventListener('change', function(e) {
            if (e.target.files.length > 0) {
                currentFile = e.target.files[0];
                fileStatus.textContent = `${currentFile.name} (${formatFileSize(currentFile.size)})`;
                fileStatus.style.color = '#00ff99';
            }
        });
        
        // Format file size
        function formatFileSize(bytes) {
            if (bytes === 0) return '0 Bytes';
            const k = 1024;
            const sizes = ['Bytes', 'KB', 'MB', 'GB'];
            const i = Math.floor(Math.log(bytes) / Math.log(k));
            return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
        }
        
        // Add message to chat
        function addMessage(content, sender, isThinking = false) {
            const messageDiv = document.createElement('div');
            messageDiv.classList.add('message');
            
            if (sender === 'user') {
                messageDiv.classList.add('user-message');
                messageDiv.innerHTML = `<strong>USER:</strong> ${content}`;
            } else if (isThinking) {
                messageDiv.classList.add('thinking-message');
                messageDiv.innerHTML = `<strong>THINKING:</strong> ${content}`;
            } else {
                messageDiv.classList.add('assistant-message');
                messageDiv.innerHTML = `<strong>LCARS:</strong> ${content}`;
            }
            
            messageArea.appendChild(messageDiv);
            messageArea.scrollTop = messageArea.scrollHeight;
            
            if (!isThinking) {
                messageCount++;
                messageCountEl.textContent = messageCount;
            }
            
            return messageDiv;
        }
        
        // Send message function
        async function sendMessage() {
            const message = userInput.value.trim();
            if (!message && !currentFile) return;
            
            systemStatus.textContent = 'PROCESSING REQUEST';
            document.querySelector('.lcars-button[onclick="sendMessage()"]').disabled = true;
            
            // Add user message
            let displayMessage = message;
            if (currentFile) displayMessage += ` [FILE: ${currentFile.name}]`;
            addMessage(displayMessage, 'user');
            userInput.value = '';
            
            // Show thinking
            const thinkingDiv = addMessage('Analyzing input and formulating response...', 'assistant', true);
            
            try {
                // Simulate API call delay
                await new Promise(resolve => setTimeout(resolve, 1500));
                
                // Remove thinking message
                if (thinkingDiv && thinkingDiv.parentNode) {
                    thinkingDiv.parentNode.removeChild(thinkingDiv);
                }
                
                // Generate response
                const response = generateResponse(message);
                addMessage(response, 'assistant');
                
                // Update chat history
                chatHistory.push({role: 'user', content: message, file: currentFile ? currentFile.name : null});
                chatHistory.push({role: 'assistant', content: response});
                
                // Reset file
                currentFile = null;
                fileInput.value = '';
                fileStatus.textContent = 'NONE';
                fileStatus.style.color = '';
            } catch (error) {
                // Remove thinking message
                if (thinkingDiv && thinkingDiv.parentNode) {
                    thinkingDiv.parentNode.removeChild(thinkingDiv);
                }
                addMessage(`ERROR: ${error.message}`, 'assistant');
            } finally {
                systemStatus.textContent = 'SYSTEM ONLINE';
                document.querySelector('.lcars-button[onclick="sendMessage()"]').disabled = false;
            }
        }
        
        // Generate a response (simulated)
        function generateResponse(input) {
            const responses = [
                "I've processed your request. The analysis indicates optimal parameters for execution.",
                "Understood. I'm initiating the requested protocols now.",
                "Acknowledged. The system has completed the background processes related to your query.",
                "Confirmed. I've updated the main database with the new information.",
                "Processing complete. The results have been archived in the primary LCARS network.",
                "Task finished. All subsystems report nominal status.",
                "Operation successful. The requested files have been transferred to your personal directory.",
                "Analysis complete. I recommend proceeding with the next phase of the mission.",
                "Data received. I'm cross-referencing with Starfleet's central archives.",
                "Query resolved. The solution has been implemented across all connected systems."
            ];
            
            // Check for specific keywords
            if (input.toLowerCase().includes('hello') || input.toLowerCase().includes('hi')) {
                return "Greetings! I am LCARS, the Local Computer Advanced Reasoning System. How may I assist you today?";
            }
            if (input.toLowerCase().includes('help')) {
                return "I can assist with various tasks including data analysis, file processing, system diagnostics, and mission planning. Please specify your requirements.";
            }
            if (input.toLowerCase().includes('status')) {
                return "All primary systems are functioning within normal parameters. No critical alerts detected. Secondary systems report 97.3% efficiency.";
            }
            
            return responses[Math.floor(Math.random() * responses.length)];
        }
        
        // Save session
        function saveSession() {
            if (chatHistory.length === 0) {
                addMessage('No conversation to save.', 'assistant');
                return;
            }
            
            const sessionData = {
                timestamp: new Date().toISOString(),
                chatHistory: chatHistory
            };
            
            const blob = new Blob([JSON.stringify(sessionData, null, 2)], {type: 'application/json'});
            const url = URL.createObjectURL(blob);
            const a = document.createElement('a');
            a.href = url;
            a.download = `lcars_session_${new Date().toISOString().split('T')[0]}.json`;
            document.body.appendChild(a);
            a.click();
            document.body.removeChild(a);
            URL.revokeObjectURL(url);
            addMessage('Session saved successfully.', 'assistant');
        }
        
        // Clear chat
        function clearChat() {
            if (confirm('Are you sure you want to clear the chat history?')) {
                messageArea.innerHTML = '<div class="message assistant-message"><strong>SYSTEM:</strong> LCARS Multimodal Chat Agent initialized. Ready for communication.</div>';
                chatHistory = [];
                messageCount = 1;
                messageCountEl.textContent = '0';
                addMessage('Chat cleared.', 'assistant');
            }
        }
        
        // Handle Enter key press
        userInput.addEventListener('keypress', function(e) {
            if (e.key === 'Enter') {
                sendMessage();
            }
        });
        
        // Initial message count update
        messageCountEl.textContent = messageCount;
    </script>
</body>
</html>