<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Access Pin</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link href="https://fonts.googleapis.com/css2?family=DM+Mono:wght@300;400;500&family=DM+Sans:wght@300;400;500&display=swap" rel="stylesheet">
    <style>
        *, *::before, *::after {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }

        :root {
            --bg-left: #0d0d0d;
            --bg-right: #111111;
            --surface: #1a1a1a;
            --border: #2a2a2a;
            --border-focus: #ffffff;
            --text-primary: #f0ede8;
            --text-muted: #4a4a4a;
            --text-subtle: #6a6a6a;
            --accent: #f0ede8;
            --error: #e05252;
            --warning: #e0903a;
            --glow: rgba(240, 237, 232, 0.04);
        }

        body {
            font-family: 'DM Sans', sans-serif;
            background-color: var(--bg-right);
            min-height: 100vh;
            display: flex;
        }

        .left-panel {
            width: 45%;
            background: var(--bg-left);
            border-right: 1px solid var(--border);
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            padding: 48px 56px;
            position: relative;
            overflow: hidden;
        }

        .left-panel::before {
            content: '';
            position: absolute;
            top: -120px;
            left: -120px;
            width: 400px;
            height: 400px;
            background: radial-gradient(circle, rgba(255,255,255,0.03) 0%, transparent 70%);
            pointer-events: none;
        }

        .left-panel::after {
            content: '';
            position: absolute;
            bottom: -80px;
            right: -80px;
            width: 300px;
            height: 300px;
            background: radial-gradient(circle, rgba(255,255,255,0.02) 0%, transparent 70%);
            pointer-events: none;
        }

        .brand {
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .brand-dot {
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background: var(--text-primary);
        }

        .brand-name {
            font-family: 'DM Mono', monospace;
            font-size: 12px;
            font-weight: 500;
            letter-spacing: 0.12em;
            text-transform: uppercase;
            color: var(--text-primary);
        }

        .left-content {
            flex: 1;
            display: flex;
            flex-direction: column;
            justify-content: center;
            padding: 60px 0;
        }

        .left-label {
            font-family: 'DM Mono', monospace;
            font-size: 11px;
            font-weight: 400;
            letter-spacing: 0.14em;
            text-transform: uppercase;
            color: var(--text-muted);
            margin-bottom: 20px;
        }

        .left-heading {
            font-size: 40px;
            font-weight: 300;
            color: var(--text-primary);
            line-height: 1.2;
            letter-spacing: -0.02em;
            margin-bottom: 20px;
        }

        .left-heading span {
            color: var(--text-subtle);
        }

        .left-desc {
            font-size: 14px;
            font-weight: 300;
            color: var(--text-subtle);
            line-height: 1.7;
            max-width: 280px;
        }

        .left-footer {
            font-family: 'DM Mono', monospace;
            font-size: 11px;
            color: var(--text-muted);
            letter-spacing: 0.06em;
        }

        .right-panel {
            flex: 1;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 48px;
            background: var(--bg-right);
        }

        .form-wrap {
            width: 100%;
            max-width: 340px;
            animation: fadeUp 0.5s ease both;
        }

        @keyframes  fadeUp {
            from { opacity: 0; transform: translateY(16px); }
            to   { opacity: 1; transform: translateY(0); }
        }

        .lock-icon {
            width: 36px;
            height: 36px;
            color: var(--text-primary);
            margin-bottom: 32px;
            transition: color 0.3s ease;
        }

        .lock-icon.locked {
            color: var(--error);
        }

        .form-title {
            font-family: 'DM Mono', monospace;
            font-size: 13px;
            font-weight: 500;
            letter-spacing: 0.1em;
            text-transform: uppercase;
            color: var(--text-primary);
            margin-bottom: 6px;
        }

        .form-subtitle {
            font-size: 13px;
            font-weight: 300;
            color: var(--text-subtle);
            margin-bottom: 40px;
            line-height: 1.5;
        }

        .pin-inputs {
            display: flex;
            gap: 10px;
            margin-bottom: 12px;
        }

        .pin-input {
            width: 68px;
            height: 72px;
            border: 1px solid var(--border);
            border-radius: 10px;
            font-family: 'DM Mono', monospace;
            font-size: 24px;
            font-weight: 400;
            text-align: center;
            color: var(--text-primary);
            background: var(--surface);
            outline: none;
            transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
            caret-color: transparent;
            -webkit-text-security: disc;
        }

        .pin-input:focus {
            border-color: var(--border-focus);
            background: #1f1f1f;
            box-shadow: 0 0 0 3px var(--glow);
            transform: translateY(-2px);
        }

        .pin-input.filled {
            background: #1f1f1f;
            border-color: #3a3a3a;
        }

        .pin-input.shake {
            animation: shake 0.35s ease;
        }

        .pin-input:disabled {
            opacity: 0.2;
            cursor: not-allowed;
        }

        @keyframes  shake {
            0%, 100% { transform: translateX(0); }
            20%       { transform: translateX(-6px); }
            40%       { transform: translateX(6px); }
            60%       { transform: translateX(-4px); }
            80%       { transform: translateX(4px); }
        }

        .message {
            font-size: 11px;
            font-family: 'DM Mono', monospace;
            letter-spacing: 0.04em;
            min-height: 16px;
            margin-bottom: 28px;
        }

        .message.error   { color: var(--error); }
        .message.warning { color: var(--warning); }

        .lockout-timer {
            margin-bottom: 32px;
        }

        .lockout-timer .countdown {
            font-family: 'DM Mono', monospace;
            font-size: 36px;
            font-weight: 300;
            color: var(--text-primary);
            letter-spacing: 0.06em;
        }

        .lockout-timer .countdown-label {
            font-size: 11px;
            color: var(--text-muted);
            letter-spacing: 0.1em;
            text-transform: uppercase;
            margin-top: 4px;
            font-family: 'DM Mono', monospace;
        }

        .submit-btn {
            width: 100%;
            height: 50px;
            background: var(--accent);
            color: #0d0d0d;
            border: none;
            border-radius: 10px;
            font-family: 'DM Mono', monospace;
            font-size: 11px;
            font-weight: 500;
            letter-spacing: 0.14em;
            text-transform: uppercase;
            cursor: pointer;
            transition: opacity 0.15s ease, transform 0.1s ease;
            margin-top: 8px;
        }

        .submit-btn:hover:not(:disabled) { opacity: 0.88; }
        .submit-btn:active:not(:disabled) { transform: scale(0.98); }
        .submit-btn:disabled { opacity: 0.15; cursor: not-allowed; }

        @media (max-width: 700px) {
            body { flex-direction: column; }

            .left-panel {
                width: 100%;
                border-right: none;
                border-bottom: 1px solid var(--border);
                padding: 36px 28px;
                min-height: unset;
            }

            .left-content { padding: 28px 0; }
            .left-heading { font-size: 28px; }
            .left-footer { display: none; }

            .right-panel { padding: 36px 28px; align-items: flex-start; }
            .pin-input { width: 60px; height: 64px; }
        }
    </style>
</head>
<body>

<?php
    $lockedUntil = $lockedUntil ?? null;
    $isLocked = $lockedUntil && \Illuminate\Support\Carbon::now()->lessThan($lockedUntil);
    $lockSecondsRemaining = $isLocked ? (int) \Illuminate\Support\Carbon::now()->diffInSeconds($lockedUntil) : 0;
?>

<div class="left-panel">
    <div class="brand">
        <div class="brand-dot"></div>
        <span class="brand-name">Secure Access</span>
    </div>

    <div class="left-content">
        <p class="left-label">Protected area</p>
        <h1 class="left-heading">Verify your<br><span>identity</span></h1>
        <p class="left-desc">Enter your 4-digit PIN to gain access. After 5 failed attempts you will be locked out temporarily.</p>
    </div>

    <div class="left-footer"><?php echo e(date('Y')); ?> &mdash; All rights reserved</div>
</div>

<div class="right-panel">
    <div class="form-wrap">
        <svg class="lock-icon <?php echo e($isLocked ? 'locked' : ''); ?>" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
            <rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
            <path d="M7 11V7a5 5 0 0 1 10 0v4"/>
        </svg>

        <p class="form-title"><?php echo e($isLocked ? 'Locked out' : 'Enter PIN'); ?></p>
        <p class="form-subtitle"><?php echo e($isLocked ? 'Account temporarily locked' : 'Enter your 4-digit PIN to continue'); ?></p>

        <?php if($errors->any()): ?>
            <p class="message <?php echo e($isLocked ? 'warning' : 'error'); ?>" id="status-msg"><?php echo e($errors->first()); ?></p>
        <?php else: ?>
            <p class="message error" id="status-msg"></p>
        <?php endif; ?>

        <?php if($isLocked): ?>
            <div class="lockout-timer">
                <div class="countdown" id="countdown"><?php echo e(gmdate('i:s', $lockSecondsRemaining)); ?></div>
                <div class="countdown-label">remaining</div>
            </div>
        <?php endif; ?>

        <form method="POST" action="<?php echo e(route('pin.verify')); ?>" id="pin-form">
            <?php echo csrf_field(); ?>
            <input type="hidden" name="pin" id="pin-hidden">

            <div class="pin-inputs">
                <input class="pin-input" type="tel" maxlength="1" inputmode="numeric" pattern="[0-9]" autocomplete="off" data-index="0" <?php echo e($isLocked ? 'disabled' : ''); ?>>
                <input class="pin-input" type="tel" maxlength="1" inputmode="numeric" pattern="[0-9]" autocomplete="off" data-index="1" <?php echo e($isLocked ? 'disabled' : ''); ?>>
                <input class="pin-input" type="tel" maxlength="1" inputmode="numeric" pattern="[0-9]" autocomplete="off" data-index="2" <?php echo e($isLocked ? 'disabled' : ''); ?>>
                <input class="pin-input" type="tel" maxlength="1" inputmode="numeric" pattern="[0-9]" autocomplete="off" data-index="3" <?php echo e($isLocked ? 'disabled' : ''); ?>>
            </div>

            <button type="submit" class="submit-btn" id="submit-btn" <?php echo e($isLocked ? 'disabled' : ''); ?>>
                <?php echo e($isLocked ? 'Locked' : 'Verify'); ?>

            </button>
        </form>
    </div>
</div>

<script>
    const inputs   = document.querySelectorAll('.pin-input');
    const hidden   = document.getElementById('pin-hidden');
    const btn      = document.getElementById('submit-btn');
    const isLocked = <?php echo e($isLocked ? 'true' : 'false'); ?>;

    function getPin() {
        return Array.from(inputs).map(i => i.value).join('');
    }

    function updateState() {
        const pin = getPin();
        hidden.value = pin;
        btn.disabled = pin.length < 4 || isLocked;
        inputs.forEach(i => i.classList.toggle('filled', i.value !== ''));
    }

    if (!isLocked) {
        inputs.forEach((input, idx) => {
            input.addEventListener('keydown', (e) => {
                if (e.key === 'Backspace') {
                    if (input.value === '' && idx > 0) {
                        inputs[idx - 1].value = '';
                        inputs[idx - 1].focus();
                    } else {
                        input.value = '';
                    }
                    updateState();
                    e.preventDefault();
                }
            });

            input.addEventListener('input', () => {
                const val = input.value.replace(/\D/g, '');
                input.value = val.slice(-1);
                if (input.value && idx < inputs.length - 1) {
                    inputs[idx + 1].focus();
                }
                updateState();
            });

            input.addEventListener('paste', (e) => {
                e.preventDefault();
                const pasted = (e.clipboardData.getData('text') || '').replace(/\D/g, '').slice(0, 4);
                pasted.split('').forEach((char, i) => {
                    if (inputs[i]) inputs[i].value = char;
                });
                const next = Math.min(pasted.length, inputs.length - 1);
                inputs[next].focus();
                updateState();
            });
        });

        document.getElementById('pin-form').addEventListener('submit', (e) => {
            if (getPin().length < 4) {
                e.preventDefault();
                inputs.forEach(i => i.classList.add('shake'));
                document.getElementById('status-msg').textContent = 'Please enter all 4 digits.';
                setTimeout(() => inputs.forEach(i => i.classList.remove('shake')), 400);
            }
        });

        inputs[0].focus();
    }

    <?php if($isLocked): ?>
    (function () {
        let seconds = <?php echo e($lockSecondsRemaining); ?>;
        const el = document.getElementById('countdown');

        const tick = setInterval(() => {
            seconds--;
            if (seconds <= 0) {
                clearInterval(tick);
                location.reload();
                return;
            }
            const m = String(Math.floor(seconds / 60)).padStart(2, '0');
            const s = String(seconds % 60).padStart(2, '0');
            el.textContent = `${m}:${s}`;
        }, 1000);
    })();
    <?php endif; ?>
</script>

</body>
</html><?php /**PATH /home/crownfir/public_html/resources/views/home/pin.blade.php ENDPATH**/ ?>