<div class="sa-card mb-8">
    <div class="flex justify-between items-center mb-8">
        <div>
            <h3 class="text-2xl font-bold"><?= e($tenant['business_name']) ?></h3>
            <p class="text-muted">Business ID: #<?= e($tenant['id']) ?> &bull; Joined: <?= date('M j, Y H:i', strtotime($tenant['created_at'])) ?></p>
        </div>
        <div class="flex gap-4">
            <?php if ($tenant['status'] === 'suspended'): ?>
                <form action="<?= APP_URL ?>/superadmin/tenants/<?= $tenant['id'] ?>/activate" method="POST">
                    <?= Security::csrfField() ?>
                    <button type="submit" class="btn btn-sa-primary py-2 px-6">Activate Business</button>
                </form>
            <?php else: ?>
                <form action="<?= APP_URL ?>/superadmin/tenants/<?= $tenant['id'] ?>/suspend" method="POST" onsubmit="return confirm('Are you sure you want to suspend this tenant? They will lose dashboard access immediately.')">
                    <?= Security::csrfField() ?>
                    <button type="submit" class="btn btn-outline py-2 px-6 text-danger">Suspend Business</button>
                </form>
            <?php endif; ?>
        </div>
    </div>

    <div class="grid-2 gap-8 mb-8" style="grid-template-columns: 2fr 1fr;">
        <div>
            <div class="text-xs text-muted font-bold tracking-widest uppercase mb-4 opacity-50">Business Information</div>
            <div class="p-6 bg-raised rounded mb-6">
                <div class="grid-2 gap-y-4">
                    <div>
                        <div class="text-xs text-muted mb-1">Company Name</div>
                        <div class="font-bold"><?= e($tenant['business_name']) ?></div>
                    </div>
                    <div>
                        <div class="text-xs text-muted mb-1">Registration Email</div>
                        <div class="font-bold"><?= e($tenant['business_email']) ?></div>
                    </div>
                    <div>
                        <div class="text-xs text-muted mb-1">Slug / Domain</div>
                        <div class="font-bold">/t/<?= e($tenant['slug']) ?></div>
                    </div>
                    <div>
                        <div class="text-xs text-muted mb-1">Contact Phone</div>
                        <div class="font-bold"><?= e($tenant['business_phone'] ?: 'N/A') ?></div>
                    </div>
                </div>
            </div>

            <div class="text-xs text-muted font-bold tracking-widest uppercase mb-4 opacity-50">Current Subscription</div>
            <div class="p-6 bg-raised rounded flex justify-between items-center">
                <?php if ($subscription): ?>
                <div>
                    <div class="text-lg font-extrabold text-primary-color"><?= e($subscription['plan_name']) ?> Plan</div>
                    <div class="text-xs text-muted mt-1">Starting from <?= date('M j, Y', strtotime($subscription['created_at'])) ?></div>
                </div>
                <div class="text-right">
                    <div class="text-xl font-black"><?= setting('currency_symbol', 'GH₵') ?><?= number_format($subscription['amount'], 2) ?> <span class="text-xs text-muted">/ mo</span></div>
                    <?php 
                    $subBadge = [
                        'active'    => 'badge-success',
                        'cancelled' => 'badge-warning',
                        'expired'   => 'badge-danger'
                    ];
                    $badg = $subBadge[$subscription['status']] ?? 'badge-muted';
                    ?>
                    <span class="badge <?= $badg ?> mt-2"><?= strtoupper(e($subscription['status'])) ?></span>
                </div>
                <?php else: ?>
                <div class="text-muted italic">No active subscription found.</div>
                <?php endif; ?>
            </div>
        </div>

        <div>
            <div class="text-xs text-muted font-bold tracking-widest uppercase mb-4 opacity-50">Admin Actions</div>
            <div class="sa-card bg-raised">
                <form action="<?= APP_URL ?>/superadmin/tenants/<?= $tenant['id'] ?>/login-as-admin" method="POST">
                    <?= Security::csrfField() ?>
                    <button type="submit" class="btn btn-outline w-full mb-3" style="justify-content:center;">Log in as Tenant Admin</button>
                </form>
                <form action="<?= APP_URL ?>/superadmin/tenants/<?= $tenant['id'] ?>/reset-password" method="POST" onsubmit="return confirm('This will reset the admin password. Continue?')">
                    <?= Security::csrfField() ?>
                    <button type="submit" class="btn btn-outline w-full mb-3" style="justify-content:center;">Reset Account Password</button>
                </form>
                <form action="<?= APP_URL ?>/superadmin/tenants/<?= $tenant['id'] ?>/delete" method="POST" onsubmit="return confirm('Are you sure you want to delete this tenant account? This action is permanent and cannot be undone. All business data will be purged.')">
                    <?= Security::csrfField() ?>
                    <button type="submit" class="btn btn-outline w-full text-danger" style="justify-content:center;">Delete Tenant Account</button>
                </form>
                <p class="text-xs text-muted mt-6 text-center leading-relaxed">
                    Account deletion is permanent. All related business data, products, and sales logs will be purged.
                </p>
            </div>
        </div>
    </div>
</div>
