<?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>Verification Code · <?= 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>

            <div class="icon-circle mb-3"><i class="bi bi-shield-lock"></i></div>
            <h1 class="h3 fw-bold mb-2">Enter Login Code</h1>
            <p class="text-muted mb-4">We texted a 6-digit code to your phone ending in <strong><?= esc($maskedPhone) ?></strong>. It expires in 10 minutes.</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('login/verify') ?>" method="post">
                <?= csrf_field() ?>
                <div class="mb-3">
                    <label class="form-label small fw-semibold" for="code">Login Code</label>
                    <div class="input-icon">
                        <i class="bi bi-hash"></i>
                        <input type="text" inputmode="numeric" pattern="[0-9]{6}" maxlength="6" class="form-control form-control-lg" id="code" name="code"
                               placeholder="6-digit code" required autofocus style="letter-spacing: 0.3em;">
                    </div>
                </div>

                <button type="submit" class="btn btn-brand btn-lg w-100 mt-2">
                    <i class="bi bi-check-circle me-1"></i> Verify &amp; Log In
                </button>
            </form>

            <form action="<?= site_url('login/resend') ?>" method="post" class="text-center mt-3">
                <?= csrf_field() ?>
                <button type="submit" class="btn btn-link btn-sm text-decoration-none p-0">Didn't get a code? Resend it</button>
            </form>

            <a href="<?= site_url('login') ?>" class="d-block text-center text-decoration-none small mt-3 text-muted">Back to login</a>

            <p class="text-center text-muted small mt-5 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">One more step.</div>
                <div class="hero-sub">Every login now needs the code we just texted you — your password alone is never enough to get in.</div>
            </div>

            <div class="trust-badge d-flex align-items-center gap-2">
                <i class="bi bi-shield-check fs-5"></i>
                <span>This code only works once and expires automatically.</span>
            </div>
        </div>
    </div>
</div>
</body>
</html>
