<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">Welcome, <?= htmlspecialchars(Auth::user()['name']) ?>!</h2>
            <p class="text-muted mb-0">Here is your mentorship and academic session overview.</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);">
                <i class="fa-solid fa-user-tie me-1"></i>Verified Mentor
            </span>
        </div>
    </div>

    <!-- Verification Alert for Mentors -->
    <?php if (empty($profile['verified'])): ?>
        <div class="boafo-card mb-4 p-4" style="border-left:4px solid var(--accent) !important;">
            <div class="d-flex align-items-start gap-3">
                <i class="fa-solid fa-circle-info flex-shrink-0" style="color:var(--accent);font-size:1.5rem;margin-top:2px;"></i>
                <div>
                    <h5 class="fw-bold mb-1" style="color:var(--dark);">Profile Verification Pending</h5>
                    <p style="color:var(--muted);font-size:0.88rem;margin:0;">Your profile is under review by the system administrator. Once approved, you will appear in the mentor directory and students can request your mentorship or book sessions.</p>
                </div>
            </div>
        </div>
    <?php endif; ?>

    <!-- Mentor Statistics Cards Row -->
    <div class="row g-4 mb-4">
        <div class="col-md-4">
            <div class="boafo-card p-4">
                <div class="d-flex align-items-center">
                    <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-user-clock" style="color:var(--accent-dark);font-size:1.2rem;"></i>
                    </div>
                    <div>
                        <h4 class="fw-bold font-outfit mb-0" style="color:var(--accent-dark);"><?= $pending_requests ?></h4>
                        <small style="color:var(--muted);">Pending Mentorship Requests</small>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card border-0 shadow-sm p-4 card-hover-effect">
                <div class="d-flex align-items-center">
                    <div class="badge-icon-box bg-primary-subtle text-primary rounded-circle me-3"><i class="fa-solid fa-calendar-day fs-4"></i></div>
                    <div>
                        <h4 class="fw-bold font-outfit text-dark mb-0"><?= count($upcoming_sessions) ?></h4>
                        <small class="text-muted text-xs">Upcoming Sessions</small>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="boafo-card p-4">
                <div class="d-flex align-items-center">
                    <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>
                        <h5 class="fw-bold font-outfit mb-1 text-truncate" style="color:var(--dark);max-width:180px;">
                            <?= htmlspecialchars($profile['university_name'] ?? 'Not Selected') ?>
                        </h5>
                        <small style="color:var(--muted);">Your Represented University</small>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="row g-4">
        <!-- Mentorship Requests -->
        <div class="col-lg-6">
            <div class="card border-0 shadow-sm mb-4 h-100">
                <div class="card-header bg-white border-0 py-3 d-flex justify-content-between align-items-center">
                    <h5 class="fw-bold font-outfit text-dark m-0">Pending Mentorship Requests</h5>
                    <span class="badge rounded-pill" style="background:rgba(244,161,29,0.15);color:var(--accent-dark);">
                        <?= $pending_requests ?> Requests
                    </span>
                </div>
                <div class="card-body p-4">
                    <?php if (!empty($requests)): ?>
                        <div class="list-group list-group-flush">
                            <?php foreach ($requests as $req): ?>
                                <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">
                                        <img src="<?= avatarUrl($req['avatar'], $req['first_name'] . ' ' . $req['last_name']) ?>" alt="Avatar" class="avatar-sm rounded-circle me-3">
                                        <div>
                                            <h6 class="fw-bold text-dark mb-1"><?= htmlspecialchars($req['first_name']) ?> <?= htmlspecialchars($req['last_name']) ?></h6>
                                            <p class="text-xs text-muted mb-0">Requested: <?= formatDate($req['created_at']) ?></p>
                                        </div>
                                    </div>
                                    <div class="d-flex gap-2">
                                        <form action="<?= APP_URL ?>/mentors/requests/<?= $req['id'] ?>/accept" method="POST" class="m-0">
                                            <?= csrf_field() ?>
                                            <button type="submit" class="btn btn-sm btn-success rounded-pill px-3">Accept</button>
                                        </form>
                                        <form action="<?= APP_URL ?>/mentors/requests/<?= $req['id'] ?>/decline" method="POST" class="m-0">
                                            <?= csrf_field() ?>
                                            <button type="submit" class="btn btn-sm btn-outline-danger rounded-pill px-3">Decline</button>
                                        </form>
                                    </div>
                                </div>
                            <?php endforeach; ?>
                        </div>
                    <?php else: ?>
                        <div class="text-center py-5">
                            <i class="fa-regular fa-folder-open text-muted display-4 mb-3"></i>
                            <h6 class="fw-bold text-muted">No Pending Requests</h6>
                            <p class="text-muted text-xs mx-auto">When student applicants request you as their mentor, they will show up here.</p>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>

        <!-- Mentoring Sessions -->
        <div class="col-lg-6">
            <div class="card border-0 shadow-sm mb-4 h-100">
                <div class="card-header bg-white border-0 py-3 d-flex justify-content-between align-items-center">
                    <h5 class="fw-bold font-outfit text-dark m-0">Mentoring Calendar</h5>
                    <a href="<?= APP_URL ?>/sessions" class="btn btn-xs btn-outline-primary rounded-pill px-3">Manage</a>
                </div>
                <div class="card-body p-4">
                    <?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="badge-icon-box bg-light text-primary rounded-3 p-3 me-3"><i class="fa-regular fa-calendar-days fs-4"></i></div>
                                        <div>
                                            <h6 class="fw-bold text-dark mb-1"><?= htmlspecialchars($sess['topic'] ?? 'Mentorship Consultation') ?></h6>
                                            <p class="text-xs text-muted mb-0">
                                                Student: <?= htmlspecialchars($sess['first_name']) ?> <?= htmlspecialchars($sess['last_name']) ?> | 
                                                Time: <?= formatDateTime($sess['scheduled_at']) ?>
                                            </p>
                                        </div>
                                    </div>
                                    <div>
                                        <?= statusBadge($sess['status']) ?>
                                    </div>
                                </div>
                            <?php endforeach; ?>
                        </div>
                    <?php else: ?>
                        <div class="text-center py-5">
                            <i class="fa-regular fa-calendar text-muted display-4 mb-3"></i>
                            <h6 class="fw-bold text-muted">No Sessions Booked</h6>
                            <p class="text-muted text-xs mx-auto">Students will schedule meetings using your profile booking calendar.</p>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>
</div>
