<div class="container py-4">
    <!-- Header -->
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h2 class="fw-bold font-outfit text-dark m-0">My Profile</h2>
            <p class="text-muted mb-0">View and manage your account details and qualifications.</p>
        </div>
        <a href="<?= APP_URL ?>/profile/edit" class="btn btn-outline-primary rounded-pill px-4"><i class="fa-solid fa-user-pen me-2"></i>Edit Profile</a>
    </div>

    <div class="row g-4">
        <!-- Profile Card -->
        <div class="col-lg-4">
            <div class="card border-0 shadow-sm text-center p-4 h-100 card-hover-effect">
                <div class="position-relative d-inline-block mx-auto mb-3">
                    <img src="<?= avatarUrl($user['avatar'], $user['first_name'] . ' ' . $user['last_name']) ?>" alt="Avatar" class="rounded-circle border border-4 border-white shadow" style="width: 120px; height: 120px; object-fit: cover;">
                </div>
                <h4 class="fw-bold font-outfit text-dark mb-1"><?= htmlspecialchars($user['first_name'] . ' ' . $user['last_name']) ?></h4>
                <p class="text-xs text-uppercase text-primary fw-semibold mb-3 tracking-wider"><?= htmlspecialchars($user['role']) ?></p>
                <hr class="my-3 text-muted opacity-25">
                <div class="text-start">
                    <div class="d-flex align-items-center mb-3">
                        <i class="fa-regular fa-envelope text-primary fs-5 me-3" style="width: 20px;"></i>
                        <div>
                            <small class="text-muted text-xs d-block">Email Address</small>
                            <span class="text-sm font-medium text-dark"><?= htmlspecialchars($user['email']) ?></span>
                        </div>
                    </div>
                    <div class="d-flex align-items-center mb-3">
                        <i class="fa-solid fa-phone text-primary fs-5 me-3" style="width: 20px;"></i>
                        <div>
                            <small class="text-muted text-xs d-block">Phone Number</small>
                            <span class="text-sm font-medium text-dark"><?= htmlspecialchars($user['phone'] ?: 'N/A') ?></span>
                        </div>
                    </div>
                    <div class="d-flex align-items-center">
                        <i class="fa-regular fa-calendar text-primary fs-5 me-3" style="width: 20px;"></i>
                        <div>
                            <small class="text-muted text-xs d-block">Joined Date</small>
                            <span class="text-sm font-medium text-dark"><?= formatDate($user['created_at']) ?></span>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Academic & Biography details -->
        <div class="col-lg-8">
            <div class="card border-0 shadow-sm p-4 h-100">
                <?php if (Auth::isStudent()): ?>
                    <!-- Student details -->
                    <h5 class="fw-bold font-outfit text-dark mb-4 border-bottom pb-2">Academic Biography</h5>
                    
                    <div class="row g-3 mb-4">
                        <div class="col-md-6">
                            <small class="text-muted text-xs">High School (SHS)</small>
                            <p class="font-medium text-dark"><?= htmlspecialchars($profile['shs_school'] ?: 'Not Provided') ?></p>
                        </div>
                        <div class="col-md-6">
                            <small class="text-muted text-xs">SHS Program</small>
                            <p class="font-medium text-dark text-capitalize"><?= htmlspecialchars($profile['shs_program'] ?: 'Not Provided') ?></p>
                        </div>
                        <div class="col-md-6">
                            <small class="text-muted text-xs">Graduation Year</small>
                            <p class="font-medium text-dark"><?= htmlspecialchars($profile['graduation_year'] ?: 'Not Provided') ?></p>
                        </div>
                        <div class="col-md-6">
                            <small class="text-muted text-xs">Intended Program</small>
                            <p class="font-medium text-dark"><?= htmlspecialchars($profile['intended_program'] ?: 'Not Provided') ?></p>
                        </div>
                        <div class="col-md-6">
                            <small class="text-muted text-xs">Preferred University</small>
                            <p class="font-medium text-dark"><?= htmlspecialchars($profile['preferred_university'] ?: 'Not Provided') ?></p>
                        </div>
                        <div class="col-md-6">
                            <small class="text-muted text-xs">Location</small>
                            <p class="font-medium text-dark"><?= htmlspecialchars($profile['city'] ?? '') ?><?= !empty($profile['region_name']) ? ', ' . htmlspecialchars($profile['region_name']) : '' ?></p>
                        </div>
                    </div>

                    <h5 class="fw-bold font-outfit text-dark mb-3 border-bottom pb-2">Interests & About</h5>
                    <div class="mb-4">
                        <small class="text-muted text-xs">Biography</small>
                        <p class="text-sm text-dark lead-sm"><?= nl2br(htmlspecialchars($profile['bio'] ?: 'No biography added yet.')) ?></p>
                    </div>
                    <div class="row g-3">
                        <div class="col-md-6">
                            <small class="text-muted text-xs">Career Interests</small>
                            <p class="text-sm text-dark"><?= htmlspecialchars($profile['career_interests'] ?: 'Not Provided') ?></p>
                        </div>
                        <div class="col-md-6">
                            <small class="text-muted text-xs">Academic Strengths</small>
                            <p class="text-sm text-dark"><?= htmlspecialchars($profile['academic_strengths'] ?: 'Not Provided') ?></p>
                        </div>
                    </div>

                    <!-- WASSCE Transcript Widget -->
                    <div class="mt-4 pt-3 border-top">
                        <div class="d-flex justify-content-between align-items-center mb-3">
                            <h5 class="fw-bold font-outfit text-dark m-0">WASSCE Results</h5>
                            <a href="<?= APP_URL ?>/profile/wassce" class="btn btn-xs btn-outline-primary rounded-pill px-3">Manage Grades</a>
                        </div>
                        <?php if (!empty($wassce)): ?>
                            <div class="row g-2">
                                <?php foreach ($wassce as $res): ?>
                                    <div class="col-md-3 col-6">
                                        <div class="border rounded p-2 text-center bg-light shadow-2xs">
                                            <small class="text-xs text-muted text-truncate d-block" title="<?= htmlspecialchars($res['subject']) ?>"><?= htmlspecialchars($res['subject']) ?></small>
                                            <span class="fs-5 fw-bold text-primary"><?= htmlspecialchars($res['grade']) ?></span>
                                        </div>
                                    </div>
                                <?php endforeach; ?>
                            </div>
                        <?php else: ?>
                            <p class="text-xs text-muted">No WASSCE results entered yet. Please add your grades to compute your admission eligibility score.</p>
                        <?php endif; ?>
                    </div>
                <?php else: ?>
                    <h5 class="fw-bold font-outfit text-dark mb-3 border-bottom pb-2">Biography</h5>
                    <p class="text-sm text-dark lead-sm mb-4"><?= nl2br(htmlspecialchars($profile['bio'] ?? 'No biography added yet.')) ?></p>
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>
