<?php
session_start();

if (!isset($_SESSION["user_id"]) || !in_array($_SESSION["role"], ["customer","company_admin"])) {
    header("Location: ../auth/login.php");
    exit;
}

$tx = $_GET["tx"] ?? "";
?>

<!DOCTYPE html>
<html>
<head>
    <title>Payment Successful</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <style>
        * {
            box-sizing: border-box;
        }

        body {
            margin: 0;
            font-family: Arial, sans-serif;
            background: linear-gradient(135deg, #dcfce7, #f8fafc);
            min-height: 100vh;
            padding: 24px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .success-card {
            width: 100%;
            max-width: 460px;
            background: white;
            border-radius: 28px;
            padding: 34px;
            text-align: center;
            box-shadow: 0 20px 50px rgba(15, 23, 42, 0.14);
        }

        .success-icon {
            width: 88px;
            height: 88px;
            border-radius: 50%;
            background: #22c55e;
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 46px;
            margin: 0 auto 22px;
        }

        h1 {
            margin: 0;
            color: #111827;
            font-size: 30px;
        }

        .subtitle {
            color: #6b7280;
            margin: 10px 0 24px;
            line-height: 1.5;
        }

        .tx-box {
            background: #f8fafc;
            border: 1px solid #e5e7eb;
            border-radius: 16px;
            padding: 16px;
            margin-bottom: 24px;
            text-align: left;
        }

        .tx-label {
            color: #6b7280;
            font-size: 13px;
            margin-bottom: 6px;
        }

        .tx-code {
            color: #166534;
            font-size: 16px;
            font-weight: bold;
            word-break: break-all;
        }

        .btn {
            display: block;
            width: 100%;
            padding: 15px;
            border-radius: 14px;
            background: #2563eb;
            color: white;
            text-decoration: none;
            font-weight: bold;
            font-size: 16px;
        }

        .btn:hover {
            background: #1d4ed8;
        }

        .small-link {
            display: block;
            margin-top: 14px;
            color: #6b7280;
            text-decoration: none;
            font-size: 14px;
        }
    </style>
</head>

<body>

<div class="success-card">

    <div class="success-icon">✓</div>

    <h1>Payment Successful</h1>

    <p class="subtitle">
        Your payment has been completed successfully.
    </p>

    <?php if ($tx): ?>
        <div class="tx-box">
            <div class="tx-label">Transaction Code</div>
            <div class="tx-code"><?php echo htmlspecialchars($tx); ?></div>
        </div>
    <?php endif; ?>

    <a href="dashboard.php" class="btn">Back to Dashboard</a>

    <a href="scan_qr.php" class="small-link">Make another payment</a>

</div>

<?php require __DIR__ . '/../config/auto_update.php'; ?>
</body>
</html>