<?php
$email = isset($_GET['email']) ? htmlspecialchars($_GET['email']) : '';
$mensajeError = "";

if (isset($_GET['error']) && $_GET['error'] === 'token_invalido') {
    $mensajeError = "El código ingresado es incorrecto o ha expirado.";
}
?>
<!DOCTYPE html>
<html lang="es">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Verificar código</title>
  <style>
    body {
      font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
      background: #f2f4f8;
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
      margin: 0;
    }

    .form-container {
      background: #fff;
      padding: 2.5rem;
      border-radius: 12px;
      box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
      width: 100%;
      max-width: 400px;
      text-align: center;
    }

    .form-container img {
      width: 64px;
      margin-bottom: 0;
    }

    .form-container h2 {
        margin-top: 0;
        margin-bottom: 0.5rem;
      font-size: 1.5rem;
      color: #333;
    }

    .form-container p {
      color: #666;
      font-size: 0.95rem;
      margin-bottom: 1.5rem;
    }

    .form-container label {
      display: block;
      text-align: left;
      margin-bottom: 0.5rem;
      font-weight: 500;
    }

    .form-container input[type="text"] {
      width: 90%;
      padding: 0.75rem;
      border: 1px solid #ccc;
      border-radius: 8px;
      margin-bottom: 1rem;
      font-size: 1rem;
      text-align: center;
      letter-spacing: 2px;
    }

    .form-container button {
      width: 70%;
      padding: 0.75rem;
      background-color: #28a745;
      border: none;
      color: #fff;
      font-size: 1rem;
      border-radius: 8px;
      cursor: pointer;
      transition: background-color 0.3s ease;
    }

    .form-container button:hover {
      background-color: #218838;
    }

    .error-message {
      color: #d93025;
      font-weight: bold;
      font-size: 0.95rem;
      margin-bottom: 1rem;
      text-align: center;
    }

    @media (max-width: 500px) {
      .form-container {
        width: 80%;
        padding: 2rem 1.5rem;
      }
    }
  </style>
</head>
<body>
  <div class="form-container">
    <img src="https://cdn-icons-png.flaticon.com/512/3064/3064197.png" alt="Token icon">
    <h2>Verifica tu código</h2>
    <p>Ingresa el código de 6 dígitos que te enviamos por correo electrónico.</p>
    
    <form method="POST" action="validar_tokenpass.php">
      <input type="hidden" name="email" value="<?= $email ?>">

      <label for="token">Código de verificación</label>
      <input type="text" name="token" id="token" maxlength="6" required>

      <?php if (!empty($mensajeError)): ?>
        <div class="error-message"><?= $mensajeError ?></div>
      <?php endif; ?>

      <button type="submit">Verificar código</button>
    </form>
  </div>
</body>
</html>
