<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Telegram Web Clone</title>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        :root {
            --primary-color: #2196f3;
            --bg-light: #ffffff;
            --bg-dark: #1a1a1a;
            --text-light: #333333;
            --text-dark: #ffffff;
            --chat-bg-light: #f5f5f5;
            --chat-bg-dark: #2c2c2c;
            --border-light: #e0e0e0;
            --border-dark: #404040;
            --hover-light: #f0f2f5;
            --hover-dark: #383838;
            --shadow-light: 0 2px 4px rgba(0,0,0,0.1);
            --shadow-dark: 0 2px 4px rgba(0,0,0,0.3);
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
        }

        body {
            background: var(--bg-light);
            color: var(--text-light);
            transition: all 0.3s ease;
        }

        body.dark-mode {
            background: var(--bg-dark);
            color: var(--text-dark);
        }

        .container {
            display: flex;
            height: 100vh;
        }

        /* Sidebar Styles */
        .sidebar {
            width: 320px;
            border-right: 1px solid var(--border-light);
            display: flex;
            flex-direction: column;
            background: var(--bg-light);
            transition: all 0.3s ease;
        }

        .dark-mode .sidebar {
            background: var(--bg-dark);
            border-color: var(--border-dark);
        }

        .sidebar-header {
            padding: 16px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: 1px solid var(--border-light);
        }

        .dark-mode .sidebar-header {
            border-color: var(--border-dark);
        }

        .search-box {
            padding: 12px 16px;
            position: relative;
        }

        .search-input {
            width: 100%;
            padding: 8px 32px 8px 12px;
            border: none;
            border-radius: 20px;
            background: var(--chat-bg-light);
            color: var(--text-light);
            font-size: 14px;
        }

        .dark-mode .search-input {
            background: var(--chat-bg-dark);
            color: var(--text-dark);
        }

        .chat-list {
            flex: 1;
            overflow-y: auto;
        }

        .chat-item {
            padding: 12px 16px;
            display: flex;
            align-items: center;
            cursor: pointer;
            transition: background 0.2s;
        }

        .chat-item:hover {
            background: var(--hover-light);
        }

        .dark-mode .chat-item:hover {
            background: var(--hover-dark);
        }

        .chat-avatar {
            width: 48px;
            height: 48px;
            border-radius: 50%;
            margin-right: 12px;
            object-fit: cover;
        }

        .chat-content {
            flex: 1;
        }

        .chat-name {
            font-weight: 600;
            margin-bottom: 4px;
        }

        .chat-message {
            font-size: 14px;
            color: #666;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .dark-mode .chat-message {
            color: #aaa;
        }

        /* Main Chat Area */
        .main-chat {
            flex: 1;
            display: flex;
            flex-direction: column;
            background: var(--chat-bg-light);
        }

        .dark-mode .main-chat {
            background: var(--chat-bg-dark);
        }

        .chat-header {
            padding: 16px;
            display: flex;
            align-items: center;
            background: var(--bg-light);
            border-bottom: 1px solid var(--border-light);
        }

        .dark-mode .chat-header {
            background: var(--bg-dark);
            border-color: var(--border-dark);
        }

        .messages-container {
            flex: 1;
            padding: 20px;
            overflow-y: auto;
        }

        .message {
            max-width: 65%;
            margin-bottom: 12px;
            padding: 8px 12px;
            border-radius: 8px;
            position: relative;
        }

        .message.sent {
            background: var(--primary-color);
            color: white;
            margin-left: auto;
            border-radius: 8px 8px 0 8px;
        }

        .message.received {
            background: white;
            margin-right: auto;
            border-radius: 8px 8px 8px 0;
        }

        .dark-mode .message.received {
            background: var(--chat-bg-dark);
        }

        .message-input-container {
            padding: 16px;
            background: var(--bg-light);
            border-top: 1px solid var(--border-light);
            display: flex;
            align-items: center;
        }

        .dark-mode .message-input-container {
            background: var(--bg-dark);
            border-color: var(--border-dark);
        }

        .message-input {
            flex: 1;
            padding: 12px;
            border: none;
            border-radius: 20px;
            background: var(--chat-bg-light);
            margin: 0 12px;
            font-size: 14px;
        }

        .dark-mode .message-input {
            background: var(--chat-bg-dark);
            color: var(--text-dark);
        }

        .btn {
            padding: 8px;
            border: none;
            background: none;
            color: var(--primary-color);
            cursor: pointer;
            border-radius: 50%;
            width: 40px;
            height: 40px;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: background 0.2s;
        }

        .btn:hover {
            background: rgba(33, 150, 243, 0.1);
        }

        /* Profile Drawer */
        .profile-drawer {
            position: fixed;
            right: -380px;
            top: 0;
            width: 380px;
            height: 100vh;
            background: var(--bg-light);
            border-left: 1px solid var(--border-light);
            transition: right 0.3s ease;
            z-index: 1000;
        }

        .dark-mode .profile-drawer {
            background: var(--bg-dark);
            border-color: var(--border-dark);
        }

        .profile-drawer.open {
            right: 0;
        }

        .profile-header {
            padding: 20px;
            text-align: center;
            border-bottom: 1px solid var(--border-light);
        }

        .dark-mode .profile-header {
            border-color: var(--border-dark);
        }

        .profile-avatar {
            width: 120px;
            height: 120px;
            border-radius: 50%;
            margin: 0 auto 16px;
            object-fit: cover;
        }

        /* Animations */
        @keyframes slideIn {
            from { transform: translateX(100%); }
            to { transform: translateX(0); }
        }

        @keyframes fadeIn {
            from { opacity: 0; }
            to { opacity: 1; }
        }

        .message {
            animation: fadeIn 0.3s ease;
        }

        .chat-item {
            animation: fadeIn 0.3s ease;
        }

        /* Responsive Design */
        @media (max-width: 768px) {
            .sidebar {
                width: 100%;
                position: absolute;
                transform: translateX(-100%);
                transition: transform 0.3s ease;
            }

            .sidebar.open {
                transform: translateX(0);
            }

            .profile-drawer {
                width: 100%;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <!-- Sidebar -->
        <div class="sidebar">
            <div class="sidebar-header">
                <button class="btn" onclick="toggleMenu()">
                    <i class="fas fa-bars"></i>
                </button>
                <button class="btn" onclick="toggleTheme()">
                    <i class="fas fa-moon"></i>
                </button>
            </div>
            <div class="search-box">
                <input type="text" class="search-input" placeholder="Search">
            </div>
            <div class="chat-list">
                <!-- Chats will be dynamically added here -->
            </div>
        </div>

        <!-- Main Chat Area -->
        <div class="main-chat">
            <div class="chat-header">
                <img src="https://picsum.photos/48/48?random=1" alt="Current Chat" class="chat-avatar">
                <div class="chat-content">
                    <div class="chat-name">Current Chat</div>
                    <div class="chat-status">online</div>
                </div>
                <button class="btn" onclick="toggleProfile()">
                    <i class="fas fa-info-circle"></i>
                </button>
            </div>
            <div class="messages-container">
                <!-- Messages will be dynamically added here -->
            </div>
            <div class="message-input-container">
                <button class="btn">
                    <i class="fas fa-paperclip"></i>
                </button>
                <input type="text" class="message-input" placeholder="Write a message...">
                <button class="btn" onclick="sendMessage()">
                    <i class="fas fa-paper-plane"></i>
                </button>
            </div>
        </div>

        <!-- Profile Drawer -->
        <div class="profile-drawer">
            <div class="profile-header">
                <img src="https://picsum.photos/120/120?random=2" alt="Profile" class="profile-avatar">
                <h2>User Name</h2>
                <p>@username</p>
            </div>
            <!-- Profile content will be added here -->
        </div>
    </div>

    <script>
        // Sample data for chats
        const chats = [
            {
                id: 1,
                name: "John Doe",
                lastMessage: "Hey, how are you?",
                avatar: "https://picsum.photos/48/48?random=3"
            },
            {
                id: 2,
                name: "Jane Smith",
                lastMessage: "See you tomorrow!",
                avatar: "https://picsum.photos/48/48?random=4"
            },
            // Add more chat data here
        ];

        // Sample messages
        const messages = [
            {
                id: 1,
                text: "Hi there!",
                sent: false,
                timestamp: new Date()
            },
            {
                id: 2,
                text: "Hello! How are you?",
                sent: true,
                timestamp: new Date()
            }
            // Add more messages here
        ];

        // Function to toggle dark mode
        function toggleTheme() {
            document.body.classList.toggle('dark-mode');
        }

        // Function to toggle profile drawer
        function toggleProfile() {
            document.querySelector('.profile-drawer').classList.toggle('open');
        }

        // Function to toggle mobile menu
        function toggleMenu() {
            document.querySelector('.sidebar').classList.toggle('open');
        }

        // Function to send message
        function sendMessage() {
            const input = document.querySelector('.message-input');
            const text = input.value.trim();
            
            if (text) {
                const message = {
                    id: messages.length + 1,
                    text: text,
                    sent: true,
                    timestamp: new Date()
                };
                
                addMessageToChat(message);
                input.value = '';
            }
        }

        // Function to add message to chat
        function addMessageToChat(message) {
            const messagesContainer = document.querySelector('.messages-container');
            const messageElement = document.createElement('div');
            messageElement.classList.add('message', message.sent ? 'sent' : 'received');
            messageElement.textContent = message.text;
            messagesContainer.appendChild(messageElement);
            messagesContainer.scrollTop = messagesContainer.scrollHeight;
        }

        // Function to render chat list
        function renderChats() {
            const chatList = document.querySelector('.chat-list');
            chatList.innerHTML = '';

            chats.forEach(chat => {
                const chatElement = document.createElement('div');
                chatElement.classList.add('chat-item');
                chatElement.innerHTML = `
                    <img src="${chat.avatar}" alt="${chat.name}" class="chat-avatar">
                    <div class="chat-content">
                        <div class="chat-name">${chat.name}</div>
                        <div class="chat-message">${chat.lastMessage}</div>
                    </div>
                `;
                chatList.appendChild(chatElement);
            });
        }

        // Initialize the app
        function init() {
            renderChats();
            messages.forEach(message => addMessageToChat(message));

            // Event listener for message input
            document.querySelector('.message-input').addEventListener('keypress', (e) => {
                if (e.key === 'Enter') {
                    sendMessage();
                }
            });
        }

        // Call init when the page loads
        document.addEventListener('DOMContentLoaded', init);
    </script>
</body>
</html>