Spaces:
Running
Running
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Modern Chat Interface</title> | |
| <style> | |
| * { | |
| margin: 0; | |
| padding: 0; | |
| box-sizing: border-box; | |
| } | |
| body { | |
| font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif; | |
| background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | |
| height: 100vh; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| padding: 20px; | |
| } | |
| .chat-container { | |
| width: 100%; | |
| max-width: 400px; | |
| height: 600px; | |
| background: white; | |
| border-radius: 20px; | |
| box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2); | |
| display: flex; | |
| flex-direction: column; | |
| overflow: hidden; | |
| animation: slideIn 0.5s ease-out; | |
| } | |
| @keyframes slideIn { | |
| from { | |
| opacity: 0; | |
| transform: translateY(20px); | |
| } | |
| to { | |
| opacity: 1; | |
| transform: translateY(0); | |
| } | |
| } | |
| .chat-header { | |
| background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | |
| color: white; | |
| padding: 20px; | |
| display: flex; | |
| align-items: center; | |
| gap: 10px; | |
| } | |
| .avatar { | |
| width: 40px; | |
| height: 40px; | |
| border-radius: 50%; | |
| background: rgba(255, 255, 255, 0.2); | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| font-size: 20px; | |
| } | |
| .header-info h2 { | |
| font-size: 18px; | |
| font-weight: 600; | |
| } | |
| .header-info p { | |
| font-size: 14px; | |
| opacity: 0.8; | |
| } | |
| .chat-messages { | |
| flex: 1; | |
| overflow-y: auto; | |
| padding: 20px; | |
| display: flex; | |
| flex-direction: column; | |
| gap: 12px; | |
| } | |
| .chat-messages::-webkit-scrollbar { | |
| width: 6px; | |
| } | |
| .chat-messages::-webkit-scrollbar-track { | |
| background: #f1f1f1; | |
| } | |
| .chat-messages::-webkit-scrollbar-thumb { | |
| background: #888; | |
| border-radius: 3px; | |
| } | |
| .message { | |
| max-width: 70%; | |
| padding: 12px 16px; | |
| border-radius: 18px; | |
| animation: messageSlide 0.3s ease-out; | |
| word-wrap: break-word; | |
| } | |
| @keyframes messageSlide { | |
| from { | |
| opacity: 0; | |
| transform: translateY(10px); | |
| } | |
| to { | |
| opacity: 1; | |
| transform: translateY(0); | |
| } | |
| } | |
| .message.sent { | |
| background: #667eea; | |
| color: white; | |
| align-self: flex-end; | |
| border-bottom-right-radius: 4px; | |
| } | |
| .message.received { | |
| background: #f1f0f0; | |
| color: #333; | |
| align-self: flex-start; | |
| border-bottom-left-radius: 4px; | |
| } | |
| .message-time { | |
| font-size: 11px; | |
| margin-top: 4px; | |
| opacity: 0.7; | |
| } | |
| .chat-input-container { | |
| padding: 20px; | |
| background: #f9f9f9; | |
| display: flex; | |
| gap: 10px; | |
| align-items: center; | |
| } | |
| .chat-input { | |
| flex: 1; | |
| padding: 12px 20px; | |
| border: none; | |
| border-radius: 25px; | |
| background: white; | |
| font-size: 16px; | |
| outline: none; | |
| transition: box-shadow 0.3s; | |
| box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); | |
| } | |
| .chat-input:focus { | |
| box-shadow: 0 4px 10px rgba(102, 126, 234, 0.3); | |
| } | |
| .send-button { | |
| width: 45px; | |
| height: 45px; | |
| border: none; | |
| border-radius: 50%; | |
| background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | |
| color: white; | |
| cursor: pointer; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| transition: transform 0.2s, box-shadow 0.2s; | |
| box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); | |
| } | |
| .send-button:hover { | |
| transform: scale(1.05); | |
| box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3); | |
| } | |
| .send-button:active { | |
| transform: scale(0.95); | |
| } | |
| .typing-indicator { | |
| display: flex; | |
| align-items: center; | |
| gap: 4px; | |
| padding: 12px 16px; | |
| background: #f1f0f0; | |
| border-radius: 18px; | |
| align-self: flex-start; | |
| margin-bottom: 12px; | |
| opacity: 0; | |
| transition: opacity 0.3s; | |
| } | |
| .typing-indicator.show { | |
| opacity: 1; | |
| } | |
| .typing-dot { | |
| width: 8px; | |
| height: 8px; | |
| background: #999; | |
| border-radius: 50%; | |
| 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% { | |
| transform: translateY(0); | |
| } | |
| 30% { | |
| transform: translateY(-10px); | |
| } | |
| } | |
| @media (max-width: 480px) { | |
| body { | |
| padding: 0; | |
| } | |
| .chat-container { | |
| height: 100vh; | |
| max-width: 100%; | |
| border-radius: 0; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="chat-container"> | |
| <div class="chat-header"> | |
| <div class="avatar">💬</div> | |
| <div class="header-info"> | |
| <h2>Chat Support</h2> | |
| <p>Online</p> | |
| </div> | |
| </div> | |
| <div class="chat-messages" id="messages"> | |
| <div class="message received"> | |
| <div>Hello! How can I help you today?</div> | |
| <div class="message-time">2:30 PM</div> | |
| </div> | |
| <div class="message sent"> | |
| <div>Hi there! I'm looking for assistance with my account.</div> | |
| <div class="message-time">2:31 PM</div> | |
| </div> | |
| <div class="message received"> | |
| <div>I'd be happy to help! What seems to be the issue?</div> | |
| <div class="message-time">2:32 PM</div> | |
| </div> | |
| </div> | |
| <div class="typing-indicator" id="typing"> | |
| <div class="typing-dot"></div> | |
| <div class="typing-dot"></div> | |
| <div class="typing-dot"></div> | |
| </div> | |
| <div class="chat-input-container"> | |
| <input type="text" class="chat-input" id="input" placeholder="Type a message..." maxlength="500"> | |
| <button class="send-button" id="send"> | |
| <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> | |
| <path d="m22 2-7 20-4-9-9-4Z"/> | |
| <path d="M22 2 11 13"/> | |
| </svg> | |
| </button> | |
| </div> | |
| </div> | |
| <script> | |
| const messagesContainer = document.getElementById('messages'); | |
| const input = document.getElementById('input'); | |
| const sendButton = document.getElementById('send'); | |
| const typingIndicator = document.getElementById('typing'); | |
| let messageHistory = JSON.parse(localStorage.getItem('chatHistory')) || [ | |
| { text: "Hello! How can I help you today?", type: "received", time: "2:30 PM" }, | |
| { text: "Hi there! I'm looking for assistance with my account.", type: "sent", time: "2:31 PM" }, | |
| { text: "I'd be happy to help! What seems to be the issue?", type: "received", time: "2:32 PM" } | |
| ]; | |
| function renderMessages() { | |
| messagesContainer.innerHTML = ''; | |
| messageHistory.forEach(msg => { | |
| const messageDiv = document.createElement('div'); | |
| messageDiv.className = `message ${msg.type}`; | |
| messageDiv.innerHTML = ` | |
| <div>${msg.text}</div> | |
| <div class="message-time">${msg.time}</div> | |
| `; | |
| messagesContainer.appendChild(messageDiv); | |
| }); | |
| messagesContainer.scrollTop = messagesContainer.scrollHeight; | |
| } | |
| function addMessage(text, type) { | |
| const now = new Date(); | |
| const time = now.toLocaleTimeString('en-US', { | |
| hour: 'numeric', | |
| minute: '2-digit' | |
| }); | |
| const message = { text, type, time }; | |
| messageHistory.push(message); | |
| localStorage.setItem('chatHistory', JSON.stringify(messageHistory)); | |
| renderMessages(); | |
| } | |
| function showTypingIndicator() { | |
| typingIndicator.classList.add('show'); | |
| messagesContainer.scrollTop = messagesContainer.scrollHeight; | |
| setTimeout(() => { | |
| typingIndicator.classList.remove('show'); | |
| const responses = [ | |
| "Thanks for your message!", | |
| "Let me check that for you", | |
| "I'll get back to you shortly", | |
| "I'm not familar with that", | |
| "One moment please", | |
| "I'm looking into it" | |
| ]; | |
| const randomResponse = responses[Math.floor(Math.random() * responses.length)]; | |
| addMessage(randomResponse, "received"); | |
| }, 1500); | |
| } | |
| function sendMessage() { | |
| const text = input.value.trim(); | |
| if (text) { | |
| addMessage(text, "sent"); | |
| input.value = ''; | |
| setTimeout(showTypingIndicator, 1000); | |
| } | |
| } | |
| sendButton.addEventListener('click', sendMessage); | |
| input.addEventListener('keypress', (e) => { | |
| if (e.key === 'Enter') { | |
| sendMessage(); | |
| } | |
| }); | |
| renderMessages(); | |
| </script> | |
| </body> | |
| </html> |