<!DOCTYPE html>
<?php
/* Standalone trial-request page — where "Request a trial" on ppradhan.com lands.
   Deliberately NOT the login screen: a marketing visitor has no account yet, so
   showing them a sign-in box (even with a modal over it) is the wrong first
   impression. Vars: $baseUrl, $assetsUrl, $error, $success, $old */
if (!isset($baseUrl)) $baseUrl = '';
if (!isset($assetsUrl)) $assetsUrl = rtrim((string) $baseUrl, '/') . '/assets';
$b     = rtrim((string) $baseUrl, '/');
$token = \PpPhp\Core\Security::CSRF()->Token();
$old   = is_array($old ?? null) ? $old : [];
$v     = static fn(string $k): string => htmlspecialchars((string) ($old[$k] ?? ''), ENT_QUOTES, 'UTF-8');
$durations = [24 => '1 day', 72 => '3 days', 168 => '1 week', 336 => '2 weeks'];
?>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Request a trial · <?= htmlspecialchars(\PpPhp\Core\Brand::name()) ?></title>
    <meta name="description" content="Request a trial of <?= htmlspecialchars(\PpPhp\Core\Brand::name()) ?> — the rapid application builder for PHP and MySQL.">
    <?php include constant('BASE_PATH') . '/core/views/favicon.php'; ?>
    <link href="<?= $assetsUrl ?>/icons/bootstrap-icons.css" rel="stylesheet">
    <style>
    /* Self-contained: this page is the first thing a stranger sees, so it must
       not depend on console theming that may change underneath it. */
    *,*::before,*::after{box-sizing:border-box}
    :root{
      --ink:#0f172a;--ink-2:#475569;--ink-3:#7c8aa3;--bg:#fff;--bg-2:#f7f8fc;--line:#e5e9f2;
      --brand:#4f46e5;--brand-2:#6d28d9;--blue:#3b82f6;--purple:#a855f7;--ok:#16a34a;--err:#dc2626;
    }
    @media (prefers-color-scheme:dark){
      :root{--ink:#e8edf7;--ink-2:#a9b6cc;--ink-3:#8b98b0;--bg:#0b1020;--bg-2:#111830;--line:#222c48}
    }
    body{margin:0;min-height:100vh;background:var(--bg);color:var(--ink);
      font:16px/1.6 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;-webkit-font-smoothing:antialiased}
    a{color:var(--brand);text-decoration:none}
    .shell{display:grid;grid-template-columns:minmax(0,.92fr) minmax(0,1.08fr);min-height:100vh}
    @media (max-width:940px){.shell{grid-template-columns:1fr}}

    /* ── left: why bother ── */
    .aside{position:relative;overflow:hidden;padding:3rem 3rem;color:#eef2ff;
      background:linear-gradient(150deg,#1e1b4b 0%,#312e81 45%,#4c1d95 100%)}
    @media (max-width:940px){.aside{padding:2.2rem 1.5rem}}
    .aside::after{content:"";position:absolute;inset:auto -120px -160px auto;width:420px;height:420px;
      border-radius:50%;background:radial-gradient(circle,rgba(139,92,246,.5),transparent 68%)}
    .brand{display:flex;align-items:center;gap:.7rem;font-weight:800;font-size:1.15rem;
      color:#fff;position:relative;z-index:1;margin-bottom:2.6rem}
    .brand svg{width:34px;height:34px}
    .aside h1{position:relative;z-index:1;font-size:clamp(1.7rem,3vw,2.3rem);font-weight:830;
      letter-spacing:-.025em;line-height:1.18;margin:0 0 .9rem;max-width:15ch}
    .aside .lede{position:relative;z-index:1;color:#c7cdf5;font-size:1rem;max-width:46ch;margin:0}
    .pts{position:relative;z-index:1;margin:2.2rem 0 0;padding:0;list-style:none}
    .pts li{display:flex;gap:.75rem;align-items:flex-start;padding:.55rem 0;font-size:.92rem;color:#dcdffb}
    .pts i{color:#a5b4fc;margin-top:3px}
    .aside footer{position:relative;z-index:1;margin-top:2.6rem;padding-top:1.4rem;
      border-top:1px solid rgba(255,255,255,.15);font-size:.8rem;color:#a9b0e0}

    /* ── right: the form ── */
    .pane{display:flex;align-items:center;justify-content:center;padding:3rem 2rem;background:var(--bg-2)}
    @media (max-width:940px){.pane{padding:2rem 1.1rem}}
    .card{width:100%;max-width:560px;background:var(--bg);border:1px solid var(--line);
      border-radius:20px;padding:2.2rem;box-shadow:0 24px 70px rgba(15,23,42,.10)}
    @media (max-width:560px){.card{padding:1.5rem 1.2rem;border-radius:16px}}
    .card h2{font-size:1.4rem;font-weight:820;letter-spacing:-.02em;margin:0 0 .35rem}
    .card .sub{color:var(--ink-2);font-size:.92rem;margin:0 0 1.5rem}
    .grid2{display:grid;grid-template-columns:1fr 1fr;gap:.9rem}
    @media (max-width:560px){.grid2{grid-template-columns:1fr}}
    .f{margin-bottom:.9rem}
    label{display:block;font-size:.8rem;font-weight:700;margin-bottom:.32rem;color:var(--ink)}
    label .opt{font-weight:500;color:var(--ink-3);font-size:.76rem}
    .req{color:var(--err)}
    input[type=text],input[type=email],select,textarea{
      width:100%;border:1px solid var(--line);border-radius:11px;padding:.7rem .85rem;
      background:var(--bg);color:var(--ink);font:inherit;font-size:.93rem;transition:.15s}
    textarea{resize:vertical;min-height:104px;line-height:1.55}
    input:focus,select:focus,textarea:focus{outline:none;border-color:var(--brand);
      box-shadow:0 0 0 3px color-mix(in srgb,var(--brand) 18%,transparent)}
    input::placeholder,textarea::placeholder{color:var(--ink-3)}
    .hint{font-size:.76rem;color:var(--ink-3);margin-top:.3rem}
    .count{float:right;font-variant-numeric:tabular-nums}
    .chips{display:flex;gap:.45rem;flex-wrap:wrap}
    .chip{flex:1 1 auto;position:relative}
    .chip input{position:absolute;opacity:0;inset:0;cursor:pointer}
    .chip span{display:block;text-align:center;border:1px solid var(--line);border-radius:10px;
      padding:.55rem .5rem;font-size:.85rem;font-weight:650;cursor:pointer;transition:.15s;color:var(--ink-2)}
    .chip input:checked+span{border-color:var(--brand);color:var(--brand);
      background:color-mix(in srgb,var(--brand) 10%,transparent)}
    .chip input:focus-visible+span{box-shadow:0 0 0 3px color-mix(in srgb,var(--brand) 18%,transparent)}
    .consent{display:flex;gap:.6rem;align-items:flex-start;font-size:.85rem;color:var(--ink-2);
      background:var(--bg-2);border:1px solid var(--line);border-radius:12px;padding:.8rem .9rem;margin:.3rem 0 1.2rem}
    .consent input{margin-top:3px;flex:none;width:16px;height:16px;accent-color:var(--brand)}
    .go{width:100%;border:0;border-radius:12px;padding:.9rem 1rem;font-size:.98rem;font-weight:750;
      color:#fff;cursor:pointer;background:linear-gradient(135deg,var(--brand),var(--brand-2));
      box-shadow:0 12px 28px color-mix(in srgb,var(--brand) 32%,transparent);transition:.15s}
    .go:hover{filter:brightness(1.07);transform:translateY(-1px)}
    .go:disabled{opacity:.65;cursor:default;transform:none}
    .foot{text-align:center;font-size:.84rem;color:var(--ink-3);margin-top:1.1rem}
    .hp{position:absolute;left:-9999px;width:1px;height:1px;overflow:hidden}

    .alert{display:flex;gap:.65rem;align-items:flex-start;border-radius:12px;padding:.85rem 1rem;
      font-size:.9rem;margin-bottom:1.3rem;line-height:1.55}
    .alert i{margin-top:2px;font-size:1.05rem}
    .alert.err{background:color-mix(in srgb,var(--err) 10%,var(--bg));
      border:1px solid color-mix(in srgb,var(--err) 34%,var(--line));color:color-mix(in srgb,var(--err) 72%,var(--ink))}
    .done{text-align:center;padding:1rem 0 .4rem}
    .done .tick{width:66px;height:66px;border-radius:50%;display:grid;place-items:center;margin:0 auto 1.1rem;
      font-size:31px;color:#fff;background:linear-gradient(135deg,#10b981,#059669);
      box-shadow:0 12px 30px rgba(16,185,129,.35)}
    .done h2{margin-bottom:.5rem}
    .done p{color:var(--ink-2);font-size:.93rem;max-width:42ch;margin:0 auto 1.4rem}
    .next{text-align:left;border:1px solid var(--line);border-radius:12px;padding:1rem 1.1rem;margin-bottom:1.3rem}
    .next b{display:block;font-size:.82rem;margin-bottom:.5rem}
    .next li{font-size:.86rem;color:var(--ink-2);margin-bottom:.3rem}
    </style>
</head>
<body>
<div class="shell">

    <aside class="aside">
        <a class="brand" href="https://ppradhan.com">
            <?= \PpPhp\Core\Brand::lockup(34) ?>
        </a>
        <h1>Let's get you building.</h1>
        <p class="lede">Tell us a little about what you want to build. We review every request personally
           and set you up with a trial licence — usually the same day.</p>
        <ul class="pts">
            <li><i class="bi bi-check-circle-fill"></i><span>Full access to the builder — nothing is crippled in the trial.</span></li>
            <li><i class="bi bi-check-circle-fill"></i><span>A sandbox database included, so there is nothing to configure first.</span></li>
            <li><i class="bi bi-check-circle-fill"></i><span>Keep anything you build. Generated apps are yours outright.</span></li>
            <li><i class="bi bi-check-circle-fill"></i><span>No card, no automatic renewal, no sales sequence.</span></li>
        </ul>
        <footer>Already have an account? <a href="<?= $b ?>/login" style="color:#c7d2fe">Sign in instead &rarr;</a></footer>
    </aside>

    <main class="pane">
        <div class="card">
        <?php if (!empty($success)): ?>
            <div class="done">
                <div class="tick"><i class="bi bi-check-lg"></i></div>
                <h2>Request received</h2>
                <p><?= htmlspecialchars((string) $success, ENT_QUOTES, 'UTF-8') ?></p>
                <div class="next">
                    <b>What happens next</b>
                    <ol style="margin:0;padding-left:1.1rem">
                        <li>An administrator reviews your request.</li>
                        <li>You get an email with your sign-in details.</li>
                        <li>You log in and start building — the sandbox is already there.</li>
                    </ol>
                </div>
                <a class="go" style="display:block;text-decoration:none;text-align:center" href="https://ppradhan.com">Back to ppradhan.com</a>
            </div>
        <?php else: ?>
            <h2>Request a trial</h2>
            <p class="sub">Four short answers. No card, no obligation.</p>

            <?php if (!empty($error)): ?>
                <div class="alert err"><i class="bi bi-exclamation-triangle-fill"></i>
                    <div><?= htmlspecialchars((string) $error, ENT_QUOTES, 'UTF-8') ?></div></div>
            <?php endif; ?>

            <form method="post" action="<?= $b ?>/temporary-access/request" id="trialForm" novalidate>
                <?= \PpPhp\Core\Security::CSRF()->HiddenField() ?>
                <input type="hidden" name="return_to" value="request-trial">
                <!-- Honeypot: a real person never fills this; bots usually do. -->
                <div class="hp" aria-hidden="true">
                    <label>Website</label><input type="text" name="website" tabindex="-1" autocomplete="off">
                </div>

                <div class="grid2">
                    <div class="f">
                        <label for="full_name">Your name <span class="req">*</span></label>
                        <input type="text" id="full_name" name="full_name" required maxlength="140"
                               autocomplete="name" placeholder="Sujit Pradhan" value="<?= $v('full_name') ?>">
                    </div>
                    <div class="f">
                        <label for="email">Work email <span class="req">*</span></label>
                        <input type="email" id="email" name="email" required maxlength="190"
                               autocomplete="email" placeholder="you@company.com" value="<?= $v('email') ?>">
                    </div>
                </div>

                <div class="grid2">
                    <div class="f">
                        <label for="organization">Organisation <span class="opt">optional</span></label>
                        <input type="text" id="organization" name="organization" maxlength="180"
                               autocomplete="organization" placeholder="Acme Ltd" value="<?= $v('organization') ?>">
                    </div>
                    <div class="f">
                        <label for="role_title">Your role <span class="opt">optional</span></label>
                        <input type="text" id="role_title" name="role_title" maxlength="140"
                               autocomplete="organization-title" placeholder="Developer" value="<?= $v('role_title') ?>">
                    </div>
                </div>

                <div class="f">
                    <label for="use_case">What would you like to build? <span class="req">*</span>
                        <span class="count opt"><span id="ucCount">0</span>/1000</span></label>
                    <textarea id="use_case" name="use_case" required maxlength="1000"
                              placeholder="e.g. An inventory and order system for our three branches — about 12 tables, five staff logins, and monthly reports."><?= $v('use_case') ?></textarea>
                    <div class="hint">A sentence or two is plenty. It helps us set the trial up the right way for you.</div>
                </div>

                <div class="f">
                    <label>How long do you need?</label>
                    <div class="chips">
                        <?php $sel = (int) ($old['requested_duration_hours'] ?? 168);
                        foreach ($durations as $hours => $label): ?>
                            <label class="chip">
                                <input type="radio" name="requested_duration_hours" value="<?= $hours ?>"
                                       <?= $sel === $hours ? 'checked' : '' ?>>
                                <span><?= htmlspecialchars($label) ?></span>
                            </label>
                        <?php endforeach; ?>
                    </div>
                </div>

                <label class="consent">
                    <input type="checkbox" name="consent" value="1" required <?= !empty($old['consent']) ? 'checked' : '' ?>>
                    <span>I agree that <?= htmlspecialchars(\PpPhp\Core\Brand::name()) ?> may contact me by email about this request. We will not add you
                          to a mailing list, and we do not share your details.</span>
                </label>

                <button type="submit" class="go" id="trialGo">Send request <i class="bi bi-arrow-right ms-1"></i></button>
                <p class="foot">Reviewed by a person, usually the same day.</p>
            </form>
        <?php endif; ?>
        </div>
    </main>
</div>

<script>
(function () {
    var ta = document.getElementById('use_case'), c = document.getElementById('ucCount');
    if (ta && c) {
        var upd = function () { c.textContent = ta.value.length; };
        ta.addEventListener('input', upd); upd();
    }
    var form = document.getElementById('trialForm'), go = document.getElementById('trialGo');
    if (form && go) form.addEventListener('submit', function () {
        // Native validation runs first; only lock the button once it passes, or a
        // person correcting a typo would be stuck with a disabled button.
        if (!form.checkValidity()) return;
        go.disabled = true;
        go.innerHTML = 'Sending…';
    });
    var first = document.getElementById('full_name');
    if (first && !first.value) first.focus();
})();
</script>
</body>
</html>
