<?php
require_once __DIR__ . '/../config.php';
if (isCustomer()) redirect(SITE_URL . '/pages/account.php');

$msg = ''; $type = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $email = trim($_POST['email'] ?? '');
    if ($email) {
        $db = getDB();
        $stmt = $db->prepare("SELECT id FROM customers WHERE email=?");
        $stmt->execute([$email]);
        if ($stmt->fetch()) {
            // Success response (For now no actual email logic added per client requirement, just UI simulation)
            $msg = 'Password reset instructions have been sent to your email address.';
            $type = 'success';
        } else {
            // Same message for security (don't leak registered emails)
            $msg = 'Password reset instructions have been sent to your email address.';
            $type = 'success';
        }
    } else {
        $msg = 'Please enter your email address.';
        $type = 'error';
    }
}
$page_title = 'Forgot Password | Balimeen Private Limited';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1.0">
<title><?= h($page_title) ?></title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Outfit:wght@700;800;900&display=swap" rel="stylesheet">
<link rel="stylesheet" href="<?= SITE_URL ?>/assets/css/style.css">
<link rel="stylesheet" href="<?= SITE_URL ?>/assets/css/shop.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
</head>
<body style="background:#f1f5f9;display:flex;align-items:center;justify-content:center;min-height:100vh;">
<div class="auth-card" style="margin:20px;width:100%;max-width:400px;background:#fff;border-radius:20px;padding:40px 36px;box-shadow:0 8px 40px rgba(10,31,78,.1);">
  <div style="text-align:center;margin-bottom:24px;">
    <div class="auth-brand" style="margin:0 auto 20px;background:transparent;border:none;display:inline-flex;flex-direction:column;align-items:center;justify-content:center;width:64px;height:64px;border-radius:14px;">
      <img src="<?= SITE_URL ?>/assets/images/logo.jpg" alt="Balimeen" style="width:100%;height:100%;object-fit:contain;border-radius:14px;">
    </div>
    <h3 style="font-family:'Outfit',sans-serif;font-size:1.55rem;font-weight:800;color:#0a1f4e;margin-bottom:6px;">Reset Password</h3>
    <p class="sub-head" style="font-size:.87rem;color:#64748b;">Enter your email to receive reset instructions</p>
  </div>
  
  <?php if ($msg): ?>
  <div class="alert alert-<?= $type ?>" style="margin-bottom:18px;border-radius:9px;padding:11px 14px;background:<?= $type==='success'?'#f0fdf4':'#fef2f2' ?>;border:1px solid <?= $type==='success'?'#86efac':'#fca5a5' ?>;color:<?= $type==='success'?'#166534':'#991b1b' ?>;font-size:.87rem;font-weight:500;display:flex;align-items:center;gap:8px;">
    <i class="fas fa-<?= $type==='success'?'check':'exclamation' ?>-circle"></i> <?= h($msg) ?>
  </div>
  <?php endif; ?>

  <form method="POST">
    <label class="auth-form-label" style="font-size:.82rem;font-weight:600;color:#334155;margin-bottom:7px;display:block;"><i class="fas fa-envelope" style="color:#2557d6;margin-right:5px;"></i>Email Address</label>
    <div class="auth-input-wrap" style="position:relative;margin-bottom:18px;">
      <i class="fas fa-envelope ico" style="position:absolute;left:13px;top:50%;transform:translateY(-50%);color:#94a3b8;pointer-events:none;"></i>
      <input type="email" name="email" placeholder="your@email.com" required autofocus style="width:100%;padding:11px 13px 11px 36px;border:1.5px solid #e2e8f0;border-radius:9px;font-size:.92rem;outline:none;">
    </div>
    <button type="submit" class="auth-btn" style="width:100%;padding:13px;background:linear-gradient(135deg, #1a3a8a, #2557d6);color:#fff;border:none;border-radius:9px;font-weight:700;cursor:pointer;display:flex;align-items:center;justify-content:center;gap:8px;"><i class="fas fa-paper-plane"></i> Send Reset Link</button>
  </form>
  
  <div style="text-align:center;margin-top:24px;border-top:1px solid #f1f5f9;padding-top:20px;">
    <a href="login.php" style="font-size:.88rem;color:#64748b;font-weight:500;text-decoration:none;"><i class="fas fa-arrow-left"></i> Back to Login</a>
  </div>
</div>
</body></html>
