<?php $pageTitle = 'Dashboard'; ?>
<div class="row g-3 mb-4">
    <div class="col-12">
        <div class="card-cix">
            <h3>Welcome back, <?= e($student['first_name'] ?? 'Student') ?>!</h3>
            <p class="text-secondary mb-1">Student Number: <strong style="color:var(--secondary)"><?= e($student['student_number'] ?? '') ?></strong></p>
            <?php if (!empty($student['package_name'])): ?>
                <p class="text-secondary">Package: <span class="badge-cix badge-active"><?= e($student['package_name']) ?></span></p>
            <?php endif; ?>
        </div>
    </div>
</div>
<div class="row g-3 mb-4">
    <div class="col-md-3"><div class="kpi-card"><div class="kpi-icon orange"><i class="fas fa-book"></i></div><div><div class="kpi-value"><?= (int)$activeCourses ?></div><div class="kpi-label">Active Courses</div></div></div></div>
    <div class="col-md-3"><div class="kpi-card"><div class="kpi-icon green"><i class="fas fa-laptop-code"></i></div><div><div class="kpi-value"><?= (int)$testsCompleted ?></div><div class="kpi-label">Tests Completed</div></div></div></div>
    <div class="col-md-3"><div class="kpi-card"><div class="kpi-icon blue"><i class="fas fa-award"></i></div><div><div class="kpi-value"><?= (int)$certificates ?></div><div class="kpi-label">Certificates</div></div></div></div>
    <div class="col-md-3"><div class="kpi-card"><div class="kpi-icon red"><i class="fas fa-credit-card"></i></div><div><div class="kpi-value"><?= (int)$pendingPayments ?></div><div class="kpi-label">Pending Payments</div></div></div></div>
</div>
<div class="row g-4">
    <div class="col-lg-8">
        <div class="card-cix">
            <div class="card-cix-header"><h5 class="mb-0"><i class="fas fa-book text-orange me-2"></i> My Courses</h5><a href="<?= base_url('student/courses') ?>" class="text-secondary small">View All</a></div>
            <?php if (empty($enrollments)): ?>
                <div class="empty-state"><i class="fas fa-book-open"></i><h5>No Courses Yet</h5><p>You haven't been enrolled in any courses yet.</p></div>
            <?php else: ?>
                <?php foreach ($enrollments as $en): ?>
                <div style="padding:0.75rem;border-bottom:1px solid var(--border);display:flex;align-items:center;gap:12px;">
                    <div style="width:48px;height:48px;border-radius:var(--radius-sm);background:var(--surface-2);display:flex;align-items:center;justify-content:center;flex-shrink:0;color:var(--secondary);font-size:1.2rem;"><i class="fas fa-book"></i></div>
                    <div style="flex:1;min-width:0;">
                        <h6 class="mb-0" style="font-size:0.95rem;"><?= e($en['course_title']) ?></h6>
                        <div class="progress-cix mt-1" style="max-width:200px;"><div class="progress-cix-bar orange" style="width:<?= (int)($en['progress_percent'] ?? 0) ?>%"></div></div>
                        <small class="text-secondary"><?= (int)($en['progress_percent'] ?? 0) ?>% complete</small>
                    </div>
                    <a href="<?= base_url('student/course/' . e($en['course_title'])) ?>" class="btn-cix btn-cix-sm btn-cix-outline">View</a>
                </div>
                <?php endforeach; ?>
            <?php endif; ?>
        </div>
    </div>
    <div class="col-lg-4">
        <div class="card-cix">
            <div class="card-cix-header"><h5 class="mb-0"><i class="fas fa-bullhorn text-orange me-2"></i> Announcements</h5></div>
            <?php if (empty($announcements)): ?>
                <div class="empty-state"><i class="fas fa-bell"></i><h5>No Announcements</h5><p>Check back later for updates.</p></div>
            <?php else: ?>
                <?php foreach ($announcements as $ann): ?>
                <div style="padding:0.75rem;border-bottom:1px solid var(--border);">
                    <div class="d-flex align-items-center gap-2 mb-1">
                        <?php if ($ann['is_pinned']): ?><span class="badge-cix badge-submitted" style="font-size:0.65rem;">PINNED</span><?php endif; ?>
                        <h6 class="mb-0" style="font-size:0.9rem;"><?= e($ann['title']) ?></h6>
                    </div>
                    <p class="text-secondary small mb-0"><?= e(substr($ann['content'], 0, 120)) ?>...</p>
                    <small class="text-secondary"><?= time_elapsed($ann['created_at']) ?></small>
                </div>
                <?php endforeach; ?>
            <?php endif; ?>
        </div>
    </div>
</div>
