<div class="container py-4">
    <!-- Breadcrumb -->
    <nav aria-label="breadcrumb" class="mb-4">
        <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="<?= APP_URL ?>/universities" class="text-decoration-none">Discovery Center</a></li>
            <li class="breadcrumb-item active" aria-current="page"><?= htmlspecialchars($university['name']) ?></li>
        </ol>
    </nav>

    <!-- University Hero Profile Card -->
    <div class="card border-0 shadow-sm overflow-hidden mb-4 bg-glass">
        <?php
            $bannerStyle = !empty($university['banner'])
                ? 'background-image:url(' . UPLOAD_URL . '/banners/' . htmlspecialchars($university['banner']) . ');background-size:cover;background-position:center;'
                : 'background: linear-gradient(135deg, #1a2940 0%, #2f4858 100%);';
        ?>
        <div class="university-header-banner position-relative" style="height: 220px; <?= $bannerStyle ?>">
            <!-- Decorative overlay -->
            <div class="position-absolute w-100 h-100" style="background:linear-gradient(to top, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0.15) 100%);"></div>
            <?php if (empty($university['banner'])): ?>
                <div class="position-absolute w-100 h-100 opacity-25" style="background: radial-gradient(circle at 70% 30%, #ffc107 0%, transparent 60%);"></div>
            <?php endif; ?>
            
            <div class="position-absolute bottom-0 start-0 p-4 d-flex align-items-end flex-wrap gap-3">
                <div class="bg-white rounded-3 p-2 shadow" style="width: 100px; height: 100px; flex-shrink:0;">
                    <img src="<?= logoUrl($university['logo'] ?? null) ?>" alt="<?= htmlspecialchars($university['name']) ?> Logo" class="w-100 h-100" style="object-fit: contain;"></div>
                <div class="text-white">
                    <span class="badge bg-warning text-dark text-uppercase mb-1"><?= htmlspecialchars($university['university_type']) ?></span>
                    <h3 class="fw-bold font-outfit m-0"><?= htmlspecialchars($university['name']) ?></h3>
                    <p class="m-0 text-white-50 text-sm"><i class="fa-solid fa-location-dot me-1 text-warning"></i> <?= htmlspecialchars($university['city']) ?>, <?= htmlspecialchars($university['region_name'] ?? 'Ghana') ?></p>
                </div>
            </div>

            <!-- Save University Button -->
            <?php if (Auth::check()): ?>
                <div class="position-absolute top-3 end-3">
                    <?php if ($is_saved): ?>
                        <form action="<?= APP_URL ?>/universities/<?= $university['id'] ?>/unsave" method="POST" class="d-inline">
                            <?= csrf_field() ?>
                            <button type="submit" class="btn btn-warning rounded-pill px-4 shadow-sm font-outfit fw-bold"><i class="fa-solid fa-bookmark me-2"></i> Saved</button>
                        </form>
                    <?php else: ?>
                        <form action="<?= APP_URL ?>/universities/<?= $university['id'] ?>/save" method="POST" class="d-inline">
                            <?= csrf_field() ?>
                            <button type="submit" class="btn btn-light rounded-pill px-4 shadow-sm font-outfit fw-bold"><i class="fa-regular fa-bookmark me-2"></i> Save</button>
                        </form>
                    <?php endif; ?>
                </div>
            <?php endif; ?>
        </div>

        <div class="card-body p-4 border-top">
            <div class="row g-4">
                <div class="col-lg-8">
                    <h5 class="fw-bold font-outfit text-dark mb-3">About the University</h5>
                    <p class="text-muted leading-relaxed"><?= nl2br(htmlspecialchars($university['description'])) ?></p>
                </div>
                <div class="col-lg-4">
                    <div class="bg-light rounded p-4 border border-light">
                        <h6 class="fw-bold font-outfit text-dark mb-3">Quick Directory</h6>
                        <ul class="list-unstyled text-sm mb-0">
                            <li class="d-flex align-items-center mb-3">
                                <i class="fa-solid fa-earth-africa text-primary fs-5 me-3" style="width:20px;"></i>
                                <div>
                                    <small class="text-muted d-block text-xs">Official Website</small>
                                    <a href="<?= htmlspecialchars($university['website']) ?>" target="_blank" class="fw-medium text-dark text-break"><?= htmlspecialchars($university['website']) ?></a>
                                </div>
                            </li>
                            <li class="d-flex align-items-center mb-3">
                                <i class="fa-solid fa-arrow-up-right-from-square text-primary fs-5 me-3" style="width:20px;"></i>
                                <div>
                                    <small class="text-muted d-block text-xs">Admissions Portal</small>
                                    <a href="<?= htmlspecialchars($university['application_portal']) ?>" target="_blank" class="fw-medium text-primary text-break">Apply Online <i class="fa-solid fa-chevron-right ms-1 text-xs"></i></a>
                                </div>
                            </li>
                            <li 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 d-block text-xs">Admissions Email</small>
                                    <span class="fw-medium text-dark text-break"><?= htmlspecialchars($university['contact_email'] ?: 'N/A') ?></span>
                                </div>
                            </li>
                            <li class="d-flex align-items-center">
                                <i class="fa-solid fa-phone text-primary fs-5 me-3" style="width:20px;"></i>
                                <div>
                                    <small class="text-muted d-block text-xs">Admissions Hotline</small>
                                    <span class="fw-medium text-dark"><?= htmlspecialchars($university['contact_phone'] ?: 'N/A') ?></span>
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Section Navigation Tabs -->
    <div class="row g-4 mt-2">
        <div class="col-12">
            <ul class="nav nav-pills nav-fill bg-white p-2 rounded-pill shadow-sm mb-4" id="universityTab" role="tablist">
                <li class="nav-item" role="presentation">
                    <button class="nav-link active rounded-pill font-outfit fw-bold py-3" id="programs-tab" data-bs-toggle="tab" data-bs-target="#programs" type="button" role="tab" aria-controls="programs" aria-selected="true">
                        <i class="fa-solid fa-graduation-cap me-2"></i> Programs Offered
                    </button>
                </li>
                <li class="nav-item" role="presentation">
                    <button class="nav-link rounded-pill font-outfit fw-bold py-3" id="mentors-tab" data-bs-toggle="tab" data-bs-target="#mentors" type="button" role="tab" aria-controls="mentors" aria-selected="false">
                        <i class="fa-solid fa-users me-2"></i> Student Mentors
                    </button>
                </li>
                <li class="nav-item" role="presentation">
                    <button class="nav-link rounded-pill font-outfit fw-bold py-3" id="scholarships-tab" data-bs-toggle="tab" data-bs-target="#scholarships" type="button" role="tab" aria-controls="scholarships" aria-selected="false">
                        <i class="fa-solid fa-award me-2"></i> Scholarships
                    </button>
                </li>
            </ul>

            <div class="tab-content" id="universityTabContent">
                <!-- Programs Tab -->
                <div class="tab-pane fade show active" id="programs" role="tabpanel" aria-labelledby="programs-tab">
                    <div class="card border-0 shadow-sm p-4">
                        <h5 class="fw-bold font-outfit text-dark mb-4 border-bottom pb-2">Offered Academic Programs</h5>
                        <?php if (!empty($programs)): ?>
                            <div class="row g-3">
                                <?php foreach ($programs as $prog): ?>
                                    <div class="col-md-6">
                                        <div class="border rounded p-3 h-100 bg-light-subtle d-flex flex-column">
                                            <div class="d-flex justify-content-between align-items-start mb-2">
                                                <h6 class="fw-bold text-dark m-0"><?= htmlspecialchars($prog['name']) ?></h6>
                                                <span class="badge bg-secondary text-uppercase text-2xs"><?= htmlspecialchars($prog['duration_years']) ?> Years</span>
                                            </div>
                                            <p class="text-xs text-muted mb-3"><?= htmlspecialchars(ucfirst($prog['degree_level'] ?? 'bachelor')) ?> Degree</p>
                                            <div class="mt-auto d-flex justify-content-between align-items-center text-xs border-top pt-2">
                                                <span class="text-muted">Required WASSCE Cut-off: <strong class="text-primary"><?= $prog['min_aggregate'] ?: 'N/A' ?></strong></span>
                                                <?php if (Auth::isStudent()): ?>
                                                    <a href="<?= APP_URL ?>/admission-analyzer" class="btn btn-xs btn-outline-primary rounded-pill px-2">Analyze Eligibility</a>
                                                <?php endif; ?>
                                            </div>
                                        </div>
                                    </div>
                                <?php endforeach; ?>
                            </div>
                        <?php else: ?>
                            <div class="text-center py-5 text-muted">
                                <i class="fa-solid fa-list-check display-6 mb-3"></i>
                                <p class="text-sm">No programs logged in the database yet.</p>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>

                <!-- Mentors Tab -->
                <div class="tab-pane fade" id="mentors" role="tabpanel" aria-labelledby="mentors-tab">
                    <div class="card border-0 shadow-sm p-4">
                        <h5 class="fw-bold font-outfit text-dark mb-4 border-bottom pb-2">Student & Alumni Mentors</h5>
                        <?php if (!empty($mentors)): ?>
                            <div class="row g-3">
                                <?php foreach ($mentors as $ment): ?>
                                    <div class="col-md-6">
                                        <div class="border rounded p-3 d-flex align-items-center card-hover-effect">
                                            <img src="<?= avatarUrl($ment['avatar'], $ment['first_name'] . ' ' . $ment['last_name']) ?>" alt="Mentor" class="avatar-md rounded-circle me-3">
                                            <div class="flex-grow-1">
                                                <h6 class="fw-bold text-dark mb-1"><?= htmlspecialchars($ment['first_name']) ?> <?= htmlspecialchars($ment['last_name']) ?></h6>
                                                <p class="text-xs text-muted mb-2"><?= htmlspecialchars($ment['program']) ?> (L<?= $ment['year_level'] ?>00)</p>
                                                <a href="<?= APP_URL ?>/mentors/<?= $ment['id'] ?>" class="btn btn-xs btn-primary rounded-pill px-3">View Profile</a>
                                            </div>
                                        </div>
                                    </div>
                                <?php endforeach; ?>
                            </div>
                        <?php else: ?>
                            <div class="text-center py-5 text-muted">
                                <i class="fa-solid fa-user-slash display-6 mb-3"></i>
                                <p class="text-sm">No verified mentors representing this university yet.</p>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>

                <!-- Scholarships Tab -->
                <div class="tab-pane fade" id="scholarships" role="tabpanel" aria-labelledby="scholarships-tab">
                    <div class="card border-0 shadow-sm p-4">
                        <h5 class="fw-bold font-outfit text-dark mb-4 border-bottom pb-2">Associated Scholarships</h5>
                        <?php if (!empty($scholarships)): ?>
                            <div class="row g-3">
                                <?php foreach ($scholarships as $sch): ?>
                                    <div class="col-md-6">
                                        <div class="border rounded p-3 h-100 bg-light-subtle d-flex flex-column">
                                            <span class="badge bg-success-subtle text-success text-uppercase align-self-start mb-2 text-2xs"><?= htmlspecialchars($sch['scholarship_type']) ?></span>
                                            <h6 class="fw-bold text-dark mb-2"><?= htmlspecialchars($sch['name']) ?></h6>
                                            <p class="text-xs text-muted mb-3">Coverage: <?= htmlspecialchars($sch['coverage']) ?></p>
                                            <div class="mt-auto d-flex justify-content-between align-items-center text-xs border-top pt-2">
                                                <span class="text-danger fw-semibold">Deadline: <?= formatDate($sch['application_deadline']) ?></span>
                                                <a href="<?= APP_URL ?>/scholarships/<?= htmlspecialchars($sch['slug']) ?>" class="btn btn-xs btn-outline-success rounded-pill px-2">Details</a>
                                            </div>
                                        </div>
                                    </div>
                                <?php endforeach; ?>
                            </div>
                        <?php else: ?>
                            <div class="text-center py-5 text-muted">
                                <i class="fa-solid fa-award display-6 mb-3"></i>
                                <p class="text-sm">No active scholarships linked directly to this university yet.</p>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
