<div class="d-sm-flex align-items-center justify-content-between mb-4">
    <h1 class="h3 mb-0 text-white">🎂 Birthdays - <?= htmlspecialchars($monthName) ?></h1>
    <div>
        <a href="<?= $baseUrl ?>/birthdays?month=<?= $currentMonth == 1 ? 12 : $currentMonth - 1 ?>" class="btn btn-sm btn-primary"><i class="fas fa-chevron-left mr-1"></i>Previous</a>
        <a href="<?= $baseUrl ?>/birthdays?month=<?= $currentMonth == 12 ? 1 : $currentMonth + 1 ?>" class="btn btn-sm btn-primary">Next<i class="fas fa-chevron-right ml-1"></i></a>
    </div>
</div>

<?php if (!empty($celebrants)): ?>
<div class="row">
    <?php foreach ($celebrants as $member): ?>
    <?php
        $dob = $member->dob ?? '';
        $day = '';
        $age = '';
        if ($dob) {
            $parts = explode('-', $dob);
            $day = (int)($parts[2] ?? 0);
            $birthYear = (int)($parts[0] ?? 0);
            if ($birthYear > 0) {
                $age = date('Y') - $birthYear;
            }
        }
        $avatar = $member->avatar
            ? $baseUrl . '/' . ltrim($member->avatar, '/')
            : $baseUrl . '/img/undraw_profile.svg';
        $today = (int)date('d');
        $isToday = $day === $today;
    ?>
    <div class="col-lg-4 col-md-6 mb-4">
        <div class="card glass-card h-100 <?= $isToday ? 'border-warning' : '' ?>">
            <div class="card-body text-center">
                <?php if ($isToday): ?>
                <div class="mb-2"><span class="badge badge-warning">Celebrating Today!</span></div>
                <?php endif; ?>
                <img src="<?= $avatar ?>" class="rounded-circle mb-3" style="width: 80px; height: 80px; object-fit: cover; border: 3px solid rgba(78, 115, 223, 0.3);">
                <h5 class="text-white"><?= htmlspecialchars($member->name) ?></h5>
                <?php if ($dob): ?>
                <p class="text-muted mb-2"><?= date('F j', strtotime($dob)) ?><?= $age ? ' (' . $age . ' years)' : '' ?></p>
                <?php endif; ?>
                <a href="<?= $baseUrl ?>/birthdays/wishes/<?= $member->id ?>" class="btn btn-sm btn-primary mt-2">
                    <i class="fas fa-gift mr-1"></i>Send Birthday Wish
                </a>
            </div>
        </div>
    </div>
    <?php endforeach; ?>
</div>
<?php else: ?>
<div class="card glass-card">
    <div class="card-body text-center py-5">
        <i class="fas fa-birthday-cake fa-3x text-muted mb-3"></i>
        <p class="text-white mb-0">No birthdays this month.</p>
        <?php if (!$birthdayFieldExists): ?>
        <p class="text-muted mt-2 small">Admin: Go to <a href="<?= $baseUrl ?>/profile-fields" class="text-primary">Profile Fields</a> and add a "Date of Birth" field so members can submit their DOB.</p>
        <?php endif; ?>
    </div>
</div>
<?php endif; ?>
