<?php
$tenant = service('tenantContext')->hasTenant() ? service('tenantContext')->getTenant() : null;
$primaryColor   = safe_hex_color($tenant->primary_color ?? null, '#4f46e5');
$secondaryColor = safe_hex_color($tenant->secondary_color ?? null, '#f59e0b');
$hotelName      = $tenant->hotel_name ?? 'MaxYields PMS';
$heroImage      = 'https://images.unsplash.com/photo-1758448500688-3ababa93fd67?auto=format&fit=crop&w=1400&q=80';
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Forgot Password · <?= esc($hotelName) ?></title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">
    <?php include APPPATH . 'Views/auth/_auth_shared_styles.php'; ?>
</head>
<body>
<div class="login-shell d-flex">
    <div class="form-col col-lg-5 col-12 d-flex flex-column justify-content-center px-4 px-md-5 py-5 mx-auto">
        <div style="max-width: 380px; width: 100%; margin: 0 auto;">

            <div class="d-flex align-items-center gap-2 mb-4">
                <div class="brand-mark"><i class="bi bi-buildings-fill"></i></div>
                <div>
                    <div class="brand-name"><?= esc($hotelName) ?></div>
                    <div class="text-muted small">Hotel Property Management</div>
                </div>
            </div>

            <a href="<?= site_url('login') ?>" class="text-decoration-none small fw-semibold d-inline-flex align-items-center gap-1 mb-4" style="color: var(--brand);">
                <i class="bi bi-arrow-left"></i> Back to login
            </a>

            <div class="icon-circle mb-3"><i class="bi bi-shield-lock"></i></div>
            <h1 class="h3 fw-bold mb-2">Forgot Password?</h1>
            <p class="text-muted mb-4">No worries — enter your email and, if there's a phone number on file for your account, we'll text you a reset code.</p>

            <?php if (session()->getFlashdata('error')): ?>
                <div class="alert alert-danger py-2 small"><?= esc(session()->getFlashdata('error')) ?></div>
            <?php endif; ?>
            <?php if (session()->getFlashdata('success')): ?>
                <div class="alert alert-success py-2 small"><?= esc(session()->getFlashdata('success')) ?></div>
            <?php endif; ?>

            <form action="<?= site_url('forgot-password') ?>" method="post">
                <?= csrf_field() ?>
                <div class="mb-3">
                    <label class="form-label small fw-semibold" for="email">Email Address</label>
                    <div class="input-icon">
                        <i class="bi bi-envelope"></i>
                        <input type="email" class="form-control form-control-lg" id="email" name="email"
                               value="<?= esc(old('email')) ?>" placeholder="Enter your registered email" required autofocus>
                    </div>
                </div>

                <button type="submit" class="btn btn-brand btn-lg w-100 mt-2">
                    <i class="bi bi-send me-1"></i> Send Reset Code
                </button>
            </form>

            <div class="info-box mt-4 d-flex gap-2">
                <i class="bi bi-shield-check fs-5" style="color: var(--brand);"></i>
                <div class="small">
                    <strong>Secure &amp; Safe</strong><br>
                    <span class="text-muted">We'll only use the phone number already on file to send your code — never one typed in here.</span>
                </div>
            </div>

            <p class="text-center text-muted small mt-5 mb-0">
                <i class="bi bi-question-circle me-1"></i>Need help? <a href="<?= site_url('login') ?>" style="color: var(--brand);">Contact your administrator</a>
            </p>
            <p class="text-center text-muted small mt-2 mb-0">&copy; <?= date('Y') ?> <?= esc($hotelName) ?> · Powered by MaxYields PMS</p>
        </div>
    </div>

    <div class="hero-col col-lg-7 d-none d-lg-block">
        <div class="hero-overlay">
            <div class="mb-4">
                <div class="hero-headline mb-2">Back in, in three steps.</div>
                <div class="hero-sub">Verify your email, confirm the SMS code, choose a new password.</div>
            </div>

            <div class="d-flex flex-column gap-2 mb-4" style="max-width: 26rem;">
                <div class="feature-card d-flex align-items-start gap-3">
                    <i class="bi bi-envelope-check fs-4"></i>
                    <div>
                        <p class="title mb-0">Quick Recovery</p>
                        <p class="desc">Reset your password in just a few simple steps.</p>
                    </div>
                </div>
                <div class="feature-card d-flex align-items-start gap-3">
                    <i class="bi bi-shield-check fs-4"></i>
                    <div>
                        <p class="title mb-0">Secure Process</p>
                        <p class="desc">Codes expire in 10 minutes and only work once.</p>
                    </div>
                </div>
                <div class="feature-card d-flex align-items-start gap-3">
                    <i class="bi bi-headset fs-4"></i>
                    <div>
                        <p class="title mb-0">Need Assistance?</p>
                        <p class="desc">No phone on file? Ask your manager to reset it directly.</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>
