<?php
require_once __DIR__ . '/../app/bootstrap.php';
use App\Core\Database;
$categories = Database::safeFetchAll('SELECT c.*, COUNT(p.id) product_count FROM categories c LEFT JOIN products p ON p.category_id=c.id AND p.status="published" WHERE c.status="active" GROUP BY c.id ORDER BY c.sort_order,c.name');
$pageTitle='Categories | '.BRAND_NAME; $pageDescription='Browse products by category.'; require ROOT_PATH.'/app/Layouts/frontend_header.php';
?>
<section class="container py-5"><div class="landing-hero p-4 p-lg-5 mb-4"><h1>Categories</h1><p class="lead mb-0">Browse the marketplace by product category.</p></div><div class="row g-4">
<?php if(!$categories): ?><div class="col-12"><div class="alert alert-info">No active categories found.</div></div><?php endif; ?>
<?php foreach($categories as $c): ?><div class="col-sm-6 col-lg-4"><div class="card module-card h-100"><div class="card-body"><h4><?= e($c['name']) ?></h4><p class="text-muted"><?= e($c['description'] ?? '') ?></p><div class="d-flex justify-content-between align-items-center"><span class="badge bg-light text-dark"><?= (int)$c['product_count'] ?> products</span><a class="btn btn-primary btn-sm" href="<?= url('public/products.php?category='.urlencode($c['slug'])) ?>">Browse</a></div></div></div></div><?php endforeach; ?>
</div></section><?php require ROOT_PATH.'/app/Layouts/frontend_footer.php'; ?>
