<div class="container py-4">
    <!-- Welcome Header -->
    <div class="row align-items-center mb-4">
        <div class="col-md-8">
            <h2 class="fw-bold font-outfit text-dark m-0">
                Hello, <?= htmlspecialchars(Auth::user()['name']) ?>! 👋
            </h2>
            <p class="mb-0" style="color:var(--muted);">Welcome to your dashboard. Here's a summary of your university prep journey.</p>
        </div>
        <div class="col-md-4 text-md-end mt-3 mt-md-0">
            <span class="badge rounded-pill px-3 py-2 text-uppercase"
                  style="background:var(--gradient-primary);color:white;font-family:var(--font-heading);letter-spacing:0.5px;">
                <i class="fa-solid fa-graduation-cap me-1"></i> SHS Student
            </span>
        </div>
    </div>

    <!-- Profile Completion Banner -->
    <?php if ($completion < 100): ?>
        <div class="boafo-card mb-4 p-4 position-relative overflow-hidden"
             style="background: var(--gradient-primary);border:none;">
            <div class="row align-items-center position-relative" style="z-index:1;">
                <div class="col-md-9">
                    <h4 class="fw-bold font-outfit text-white mb-1">
                        Complete Your Profile Setup
                        <span class="badge ms-2 fw-bold" style="background:rgba(255,255,255,0.2);font-size:0.85rem;"><?= $completion ?>%</span>
                    </h4>
                    <p class="mb-3" style="color:rgba(255,255,255,0.75);font-size:0.9rem;">
                        Add your biography, school details, and WASSCE grades to unlock accurate AI admissions analysis and personalized scholarship matches.
                    </p>
                    <div class="progress rounded-pill" style="height:8px;background:rgba(255,255,255,0.2);">
                        <div class="progress-bar rounded-pill"
                             style="width:<?= $completion ?>%;background:var(--accent);"
                             role="progressbar" aria-valuenow="<?= $completion ?>" aria-valuemin="0" aria-valuemax="100">
                        </div>
                    </div>
                </div>
                <div class="col-md-3 text-md-end mt-3 mt-md-0">
                    <a href="<?= APP_URL ?>/profile/edit" class="btn-accent-boafo">
                        <i class="fa-solid fa-pen-to-square"></i> Update Profile
                    </a>
                </div>
            </div>
            <i class="fa-solid fa-sparkles position-absolute opacity-10"
               style="right:-20px;top:-20px;font-size:10rem;pointer-events:none;color:rgba(255,255,255,0.15);"></i>
        </div>
    <?php endif; ?>

    <!-- Quick Stats Cards -->
    <div class="row g-4 mb-4">
        <!-- Saved Universities -->
        <div class="col-lg-3 col-md-6">
            <div class="boafo-card p-4 h-100">
                <div class="d-flex align-items-center mb-3">
                    <div class="d-flex align-items-center justify-content-center rounded-3 me-3"
                         style="width:48px;height:48px;background:rgba(30,58,95,0.1);">
                        <i class="fa-solid fa-building-columns" style="color:var(--primary);font-size:1.2rem;"></i>
                    </div>
                    <div>
                        <h3 class="fw-bold font-outfit mb-0" style="color:var(--primary);"><?= $saved_unis ?></h3>
                        <small style="color:var(--muted);">Saved Universities</small>
                    </div>
                </div>
                <a href="<?= APP_URL ?>/universities" class="fw-semibold text-decoration-none"
                   style="font-size:0.8rem;color:var(--primary);">
                    Browse Universities <i class="fa-solid fa-arrow-right ms-1"></i>
                </a>
            </div>
        </div>
        <!-- Saved Scholarships -->
        <div class="col-lg-3 col-md-6">
            <div class="boafo-card p-4 h-100">
                <div class="d-flex align-items-center mb-3">
                    <div class="d-flex align-items-center justify-content-center rounded-3 me-3"
                         style="width:48px;height:48px;background:rgba(244,161,29,0.15);">
                        <i class="fa-solid fa-award" style="color:var(--accent-dark);font-size:1.2rem;"></i>
                    </div>
                    <div>
                        <h3 class="fw-bold font-outfit mb-0" style="color:var(--accent-dark);"><?= $saved_schs ?></h3>
                        <small style="color:var(--muted);">Saved Scholarships</small>
                    </div>
                </div>
                <a href="<?= APP_URL ?>/scholarships" class="fw-semibold text-decoration-none"
                   style="font-size:0.8rem;color:var(--accent-dark);">
                    Browse Scholarships <i class="fa-solid fa-arrow-right ms-1"></i>
                </a>
            </div>
        </div>
        <!-- Connected Mentors -->
        <div class="col-lg-3 col-md-6">
            <div class="boafo-card p-4 h-100">
                <div class="d-flex align-items-center mb-3">
                    <div class="d-flex align-items-center justify-content-center rounded-3 me-3"
                         style="width:48px;height:48px;background:rgba(30,58,95,0.1);">
                        <i class="fa-solid fa-user-group" style="color:var(--primary);font-size:1.2rem;"></i>
                    </div>
                    <div>
                        <h3 class="fw-bold font-outfit mb-0" style="color:var(--primary);"><?= $active_mentors ?></h3>
                        <small style="color:var(--muted);">Connected Mentors</small>
                    </div>
                </div>
                <a href="<?= APP_URL ?>/mentors" class="fw-semibold text-decoration-none"
                   style="font-size:0.8rem;color:var(--primary);">
                    Mentor Network <i class="fa-solid fa-arrow-right ms-1"></i>
                </a>
            </div>
        </div>
        <!-- WASSCE Grades -->
        <div class="col-lg-3 col-md-6">
            <div class="boafo-card p-4 h-100">
                <div class="d-flex align-items-center mb-3">
                    <div class="d-flex align-items-center justify-content-center rounded-3 me-3"
                         style="width:48px;height:48px;background:rgba(244,161,29,0.15);">
                        <i class="fa-solid fa-scroll" style="color:var(--accent-dark);font-size:1.2rem;"></i>
                    </div>
                    <div>
                        <h3 class="fw-bold font-outfit mb-0" style="color:var(--accent-dark);"><?= $wassce_count ?></h3>
                        <small style="color:var(--muted);">WASSCE Grades Saved</small>
                    </div>
                </div>
                <a href="<?= APP_URL ?>/profile/wassce" class="fw-semibold text-decoration-none"
                   style="font-size:0.8rem;color:var(--accent-dark);">
                    Manage Grades <i class="fa-solid fa-arrow-right ms-1"></i>
                </a>
            </div>
        </div>
    </div>

    <!-- Sessions & Notifications -->
    <div class="row g-4">
        <!-- Upcoming Sessions -->
        <div class="col-lg-8">
            <div class="boafo-card h-100">
                <div class="card-header-custom">
                    <h5 class="fw-bold font-outfit m-0" style="color:var(--dark);">
                        <i class="fa-regular fa-calendar-days me-2" style="color:var(--primary);"></i>
                        Upcoming Sessions
                    </h5>
                    <a href="<?= APP_URL ?>/sessions" class="btn-outline-boafo" style="padding:0.4rem 1rem;font-size:0.8rem;">
                        View All
                    </a>
                </div>
                <div class="card-body-custom">
                    <?php if (!empty($upcoming_sessions)): ?>
                        <div class="list-group list-group-flush">
                            <?php foreach ($upcoming_sessions as $sess): ?>
                                <div class="list-group-item border-0 py-3 px-0 d-flex justify-content-between align-items-center">
                                    <div class="d-flex align-items-center">
                                        <div class="d-flex align-items-center justify-content-center rounded-3 me-3 flex-shrink-0"
                                             style="width:44px;height:44px;background:rgba(30,58,95,0.08);">
                                            <i class="fa-regular fa-calendar-check" style="color:var(--primary);font-size:1.1rem;"></i>
                                        </div>
                                        <div>
                                            <h6 class="fw-bold mb-1" style="color:var(--dark);font-size:0.9rem;">
                                                <?= htmlspecialchars($sess['topic'] ?? 'Mentorship Session') ?>
                                            </h6>
                                            <p class="mb-0" style="font-size:0.78rem;color:var(--muted);">
                                                <i class="fa-regular fa-user me-1" style="color:var(--primary);"></i>
                                                <?= htmlspecialchars($sess['first_name']) ?> <?= htmlspecialchars($sess['last_name']) ?>
                                                &nbsp;|&nbsp;
                                                <i class="fa-regular fa-clock ms-1 me-1" style="color:var(--primary);"></i>
                                                <?= formatDateTime($sess['scheduled_at']) ?>
                                            </p>
                                        </div>
                                    </div>
                                    <div class="ms-2"><?= statusBadge($sess['status']) ?></div>
                                </div>
                            <?php endforeach; ?>
                        </div>
                    <?php else: ?>
                        <div class="empty-state">
                            <div class="empty-icon"><i class="fa-regular fa-calendar-check"></i></div>
                            <h4>No Sessions Scheduled</h4>
                            <p>Book academic prep or college transition consultations with verified mentors and tutors.</p>
                            <a href="<?= APP_URL ?>/mentors" class="btn-primary-boafo">
                                <i class="fa-solid fa-users"></i> Find a Mentor
                            </a>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>

        <!-- Recent Notifications -->
        <div class="col-lg-4">
            <div class="boafo-card h-100">
                <div class="card-header-custom">
                    <h5 class="fw-bold font-outfit m-0" style="color:var(--dark);">
                        <i class="fa-solid fa-bell me-2" style="color:var(--primary);"></i>
                        Recent Activity
                    </h5>
                    <?php if ($unread_notifications > 0): ?>
                        <span class="badge rounded-pill" style="background:var(--accent);color:white;">
                            <?= $unread_notifications ?> New
                        </span>
                    <?php endif; ?>
                </div>
                <div class="card-body-custom">
                    <?php if (!empty($notifications)): ?>
                        <div class="timeline-activity">
                            <?php foreach ($notifications as $notif): ?>
                                <div class="d-flex pb-3 position-relative">
                                    <div class="flex-shrink-0 me-3 mt-1" style="width:10px;height:10px;border-radius:50%;
                                         background:<?= $notif['is_read'] ? 'var(--border)' : 'var(--primary)' ?>;
                                         box-shadow:<?= !$notif['is_read'] ? '0 0 0 3px rgba(30,58,95,0.15)' : 'none' ?>;">
                                    </div>
                                    <div>
                                        <p class="mb-1 <?= $notif['is_read'] ? '' : 'fw-semibold' ?>"
                                           style="font-size:0.85rem;color:<?= $notif['is_read'] ? 'var(--muted)' : 'var(--dark)' ?>;">
                                            <strong><?= htmlspecialchars($notif['title']) ?></strong>:
                                            <?= htmlspecialchars($notif['body']) ?>
                                        </p>
                                        <small style="color:var(--muted);font-size:0.72rem;"><?= timeAgo($notif['created_at']) ?></small>
                                    </div>
                                </div>
                            <?php endforeach; ?>
                        </div>
                        <div class="text-center mt-2">
                            <a href="<?= APP_URL ?>/notifications" class="text-decoration-none fw-semibold"
                               style="font-size:0.8rem;color:var(--primary);">
                                View all notifications <i class="fa-solid fa-arrow-right ms-1"></i>
                            </a>
                        </div>
                    <?php else: ?>
                        <div class="empty-state" style="padding:2rem 1rem;">
                            <div class="empty-icon"><i class="fa-regular fa-bell-slash"></i></div>
                            <p>No recent activity notifications.</p>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>

    <!-- Action Widgets Row -->
    <div class="row g-4 mt-2">
        <!-- Admission Analyzer CTA -->
        <div class="col-md-6">
            <div class="boafo-card p-4 h-100 d-flex flex-column">
                <div class="mb-3">
                    <div class="d-inline-flex align-items-center justify-content-center rounded-3 mb-3"
                         style="width:52px;height:52px;background:rgba(30,58,95,0.1);">
                        <i class="fa-solid fa-brain" style="color:var(--primary);font-size:1.4rem;"></i>
                    </div>
                    <h5 class="fw-bold font-outfit mb-2" style="color:var(--dark);">Admission Projections</h5>
                    <p style="color:var(--muted);font-size:0.88rem;">
                        Calculate your WASSCE aggregates and check eligibility for specific undergraduate programs 
                        across major Ghanaian universities.
                    </p>
                </div>
                <div class="mt-auto">
                    <a href="<?= APP_URL ?>/admission-analyzer" class="btn-primary-boafo">
                        <i class="fa-solid fa-magnifying-glass-chart"></i> Run Analyzer
                    </a>
                </div>
            </div>
        </div>
        <!-- Transition Checklist CTA -->
        <div class="col-md-6">
            <div class="boafo-card p-4 h-100 d-flex flex-column">
                <div class="mb-3">
                    <div class="d-inline-flex align-items-center justify-content-center rounded-3 mb-3"
                         style="width:52px;height:52px;background:rgba(244,161,29,0.15);">
                        <i class="fa-solid fa-route" style="color:var(--accent-dark);font-size:1.4rem;"></i>
                    </div>
                    <h5 class="fw-bold font-outfit mb-2" style="color:var(--dark);">Transition Preparation Checklist</h5>
                    <p style="color:var(--muted);font-size:0.88rem;">
                        Don't miss a step before registration day! Track medical reports, hostel bookings, 
                        fee payments, and academic documents.
                    </p>
                </div>
                <div class="mt-auto">
                    <a href="<?= APP_URL ?>/transition/checklist" class="btn-accent-boafo">
                        <i class="fa-solid fa-list-check"></i> Open Checklist
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>
