 :root {
            --primary: #4F46E5;
            --primary-hover: #4338CA;
            --bg-body: #F3F4F6;
            --bg-panel: #FFFFFF;
            --text-main: #111827;
            --text-muted: #6B7280;
            --border: #E5E7EB;
            --msg-sent: #4F46E5;
            --msg-received: #FFFFFF;
            --radius: 16px;
            --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }

        [data-theme="dark"] {
            --primary: #6366F1;
            --primary-hover: #818CF8;
            --bg-body: #111827;
            --bg-panel: #1F2937;
            --text-main: #F9FAFB;
            --text-muted: #9CA3AF;
            --border: #374151;
            --msg-sent: #6366F1;
            --msg-received: #374151;
        }

        * { box-sizing: border-box; margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }

        body { background-color: var(--bg-body); color: var(--text-main); height: 100vh; display: flex; align-items: center; justify-content: center; }

        .hidden { display: none !important; }

        /* Auth Forms */
        .auth-container { background: var(--bg-panel); padding: 40px; border-radius: var(--radius); box-shadow: var(--shadow); width: 100%; max-width: 400px; text-align: center; }
        .auth-container h2 { margin-bottom: 24px; color: var(--primary); font-weight: 700; }
        .input-group { margin-bottom: 16px; text-align: left; position: relative; }
        input { width: 100%; padding: 12px 16px; border: 1px solid var(--border); border-radius: 8px; outline: none; transition: border-color 0.2s; font-size: 15px; }
        input:focus { border-color: var(--primary); }
        
        input[type="file"] { padding: 8px; font-size: 13px; background: #f9f9f9; }

        button { width: 100%; padding: 12px; background: var(--primary); color: white; border: none; border-radius: 8px; font-size: 16px; font-weight: 600; cursor: pointer; transition: background 0.2s; }
        button:hover { background: var(--primary-hover); }
        .auth-switch { margin-top: 16px; font-size: 14px; color: var(--text-muted); }
        .auth-switch a { color: var(--primary); text-decoration: none; font-weight: 600; }

        /* App Container */
        .app-container { display: flex; width: 100%; height: 100vh; max-width: 1200px; background: var(--bg-panel); box-shadow: var(--shadow); }
        @media (min-width: 1024px) { .app-container { height: 90vh; border-radius: var(--radius); overflow: hidden; } }

        /* Sidebar */
        .sidebar { width: 350px; border-right: 1px solid var(--border); display: flex; flex-direction: column; background: var(--bg-body); z-index: 10; }
        .sidebar-header { padding: 20px; border-bottom: 1px solid var(--border); background: var(--bg-panel);}
        .profile-info { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
        .profile-avatar { width: 48px; height: 48px; border-radius: 50%; background: var(--primary); color: white; display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: bold; object-fit: cover; }
        .profile-details h3 { font-size: 16px; margin-bottom: 4px; }
        .profile-details p { font-size: 12px; color: var(--text-muted); cursor: pointer; display: flex; align-items: center; gap: 4px; }
        
        .theme-toggle { width: 40px; height: 40px; border-radius: 50%; background: var(--bg-body); border: 1px solid var(--border); color: var(--text-main); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s; }
        .theme-toggle:hover { background: var(--border); }
        
        .search-bar { display: flex; gap: 8px; }
        .search-result { margin-top: 10px; background: var(--bg-panel); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
        .contacts-list { flex: 1; overflow-y: auto; }
        
        .contact-item { padding: 16px 20px; display: flex; align-items: center; gap: 12px; cursor: pointer; transition: background 0.2s; border-bottom: 1px solid var(--border); }
        .contact-item:hover { background: #EEF2FF; }
        .contact-item.active { background: #E0E7FF; border-right: 3px solid var(--primary); }
        .contact-avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: #ccc; }

        /* Chat Area */
        .chat-area { flex: 1; display: flex; flex-direction: column; background: var(--bg-body); position: relative; }
        .chat-header { padding: 15px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; background: var(--bg-panel); }
        .back-btn { display: none; background: none; color: var(--text-main); padding: 8px; width: auto; font-size: 20px;}
        
        .messages-container { flex: 1; padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
        .message { max-width: 75%; padding: 10px 16px; border-radius: 18px; font-size: 15px; line-height: 1.4; box-shadow: 0 1px 2px rgba(0,0,0,0.1); word-break: break-word;}
        .message.sent { background: var(--msg-sent); color: white; align-self: flex-end; border-bottom-right-radius: 4px; }
        .message.received { background: var(--msg-received); color: var(--text-main); align-self: flex-start; border-bottom-left-radius: 4px; }
        .msg-sender { font-size: 11px; opacity: 0.7; margin-bottom: 4px; font-weight: bold; }
        
        .file-msg { display: flex; flex-direction: column; align-items: center; gap: 8px; }
        .chat-image { max-width: 200px; max-height: 200px; border-radius: 8px; cursor: pointer; transition: transform 0.2s; }
        .chat-image:hover { transform: scale(1.05); }
        .file-msg a { color: inherit; text-decoration: underline; cursor: pointer; }
        .file-msg i { margin-right: 8px; }

        .input-area { padding: 15px 20px; background: var(--bg-panel); border-top: 1px solid var(--border); display: flex; gap: 12px; }
        .input-area input { border-radius: 24px; padding: 12px 20px; background: var(--bg-body); border: none; flex: 1; }
        .send-btn { width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; padding: 0; flex-shrink: 0;}
        .attach-btn { width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; padding: 0; flex-shrink: 0; background: var(--bg-body); color: var(--text-muted); border: 1px solid var(--border); cursor: pointer; transition: all 0.2s;}
        .attach-btn:hover { background: var(--border); color: var(--text-main); }

        .empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-muted); background: var(--bg-panel); }
        .empty-state i { font-size: 48px; margin-bottom: 16px; color: var(--border); }

        /* Mobile */
        @media (max-width: 768px) {
            .sidebar { width: 100%; position: absolute; height: 100%; transition: transform 0.3s ease; }
            .sidebar.mobile-hidden { transform: translateX(-100%); }
            .chat-area { width: 100%; }
            .back-btn { display: block; }
        }

        /* Custom Alert */
        .custom-alert {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.5);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 1000;
            animation: fadeIn 0.2s ease;
        }

        .alert-content {
            background: var(--bg-panel);
            padding: 30px;
            border-radius: var(--radius);
            box-shadow: var(--shadow);
            max-width: 400px;
            width: 90%;
            text-align: center;
            animation: slideUp 0.3s ease;
        }

        .alert-icon {
            font-size: 40px;
            color: var(--primary);
            margin-bottom: 16px;
        }

        .alert-message {
            font-size: 16px;
            color: var(--text-main);
            margin-bottom: 24px;
            line-height: 1.5;
        }

        .alert-btn {
            width: auto;
            padding: 10px 30px;
            background: var(--primary);
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 14px;
            font-weight: 600;
            cursor: pointer;
            transition: background 0.2s;
        }

        .alert-btn:hover {
            background: var(--primary-hover);
        }

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

        @keyframes slideUp {
            from { transform: translateY(20px); opacity: 0; }
            to { transform: translateY(0); opacity: 1; }
        }