document.addEventListener('DOMContentLoaded', function () { const loginForm = document.getElementById('loginForm'); if (loginForm) { loginForm.addEventListener('submit', async function(e) { e.preventDefault(); const phone = document.getElementById('phone').value.trim(); const password = document.getElementById('password').value; const msg = document.getElementById('loginMsg'); msg.classList.add('d-none'); msg.textContent = ''; const response = await fetch('login.php', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({phone, password}) }); const data = await response.json(); if(data.success) { window.location.reload(); } else { msg.classList.remove('d-none'); msg.textContent = data.message; } }); } });