<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= $isSuccess ? 'Payment successful' : 'Payment failed' ?></title>
    <style>
        * { box-sizing: border-box; }
        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            margin: 0;
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 1rem;
            background: #f5f5f5;
        }
        .card {
            background: #fff;
            border-radius: 12px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.08);
            padding: 2rem;
            max-width: 360px;
            width: 100%;
            text-align: center;
        }
        .icon {
            width: 64px;
            height: 64px;
            margin: 0 auto 1.25rem;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 2rem;
        }
        .icon.success { background: #d4edda; color: #155724; }
        .icon.failed { background: #f8d7da; color: #721c24; }
        h1 {
            margin: 0 0 0.5rem;
            font-size: 1.5rem;
            font-weight: 600;
            color: #333;
        }
        .sub {
            color: #666;
            font-size: 0.9rem;
            margin-bottom: 1.5rem;
        }
        .ref {
            font-size: 0.8rem;
            color: #888;
            word-break: break-all;
            margin-bottom: 1.5rem;
        }
        .btn-close {
            display: block;
            width: 100%;
            padding: 0.875rem 1.5rem;
            font-size: 1rem;
            font-weight: 500;
            color: #fff;
            background: #0d6efd;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            text-decoration: none;
            text-align: center;
        }
        .btn-close:active { opacity: 0.9; }
    </style>
</head>
<body>
    <div class="card">
        <div class="icon <?= $isSuccess ? 'success' : 'failed' ?>">
            <?= $isSuccess ? '✓' : '✕' ?>
        </div>
        <h1><?= $isSuccess ? 'Payment successful' : 'Payment failed' ?></h1>
        <p class="sub"><?= $isSuccess ? 'Your payment was completed successfully.' : 'The payment could not be completed. You can try again or use another method.' ?></p>
        <?php if (!empty($orderTrackingId) || !empty($merchantReference)): ?>
        <p class="ref">
            <?php if (!empty($merchantReference)): ?>Reference: <?= htmlspecialchars($merchantReference) ?><br><?php endif; ?>
            <?php if (!empty($orderTrackingId)): ?>Order ID: <?= htmlspecialchars($orderTrackingId) ?><?php endif; ?>
        </p>
        <?php endif; ?>
        <button type="button" class="btn-close" id="btnClose">Close window</button>
    </div>
    <script>
        (function() {
            var closeRedirectUrl = <?= json_encode($closeRedirectUrl ?? '') ?>;
            document.getElementById('btnClose').onclick = function() {
                try { window.close(); } catch (e) {}
                if (closeRedirectUrl) {
                    setTimeout(function() { location.href = closeRedirectUrl; }, 100);
                }
            };
        })();
    </script>
</body>
</html>
