
<div class="info-box-row">
    @if(!empty($program->level_contain) && is_array($program->level_contain))
        @foreach($program->level_contain as $item)
            <div class="info-box">
                <div class="info-label">{{ $item['name'] ?? '' }}</div>
                <div class="info-value">{{ $item['description'] ?? '' }}</div>
            </div>
        @endforeach
    @endif
</div>
<div class="curriculum-container">
    <h2 class="curriculum-title">{{ $program->curriculum_title }}</h2>

    <div class="semester-grid">
        @foreach ($semesters as $index => $semester)
        <!-- First Semester -->
        <div class="semester-wrapper">
            <div class="semester-box" onclick="toggleSemester('{{ $index+1 }}')">
                <span>{{ $semester->name }}</span>
                <i class='bx bx-plus'></i>
            </div>
            <div id="sem_{{ $index+1 }}" class="semester-details">
                <div class="details-content">

                    <div class="course-table">
                        <div class="table-header">
                            <span class="course-title">Course Title</span>
                            <span class="credit-hours">Credit Hours</span>
                        </div>
                        @foreach($semester->subjects as $subject)
                            <div class="course-row">
                                <span>{{ $subject->name }}</span>
                                <span class="credit-hours">{{ $subject->code }}</span>
                            </div>
                        @endforeach

                    </div>
                </div>
            </div>
        </div>
        @endforeach
    </div>
</div>
<style>
    .info-box-row {
    display: flex;
    justify-content: center;
    gap: 32px;
    margin: 68px 0 109px 14px;
}
.info-box {
    border: 1px solid #bfc9d1;
    border-radius: 2px;
    background: #fff;
    min-width: 240px;
    padding: 32px 0 18px 0;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.02);
}
.info-label {
    color: #f7a600;
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 6px;
}
.info-value {
    color: #222;
    font-size: 1.1rem;
    font-weight: 400;
    margin-top: 4px;
}

    .curriculum-container {
        padding: 40px 5%;
        max-width: 1200px;
        margin: 0 auto;
        position: relative;
    }

    .curriculum-title {
        text-align: center;
        color: #ff6b00;
        font-size: 2rem;
        margin-bottom: 40px;
    }

    .semester-grid {
        display: grid;
        grid-template-columns: repeat(3, minmax(250px, 300px));
        gap: 30px;
        max-width: 1200px;
        margin: 0 auto;
        justify-content: center;
    }
    .semester-wrapper{
        width: 290px;
    }

    /* First row - 3 items */
    .semester-wrapper:nth-child(1),
    .semester-wrapper:nth-child(2),
    .semester-wrapper:nth-child(3) {
        grid-row: 1;
    }

    /* Second row - 2 items centered */
    .semester-wrapper:nth-child(4) {
        grid-row: 2;
        grid-column: 1 / 2;
        margin-left: 30%;
    }

    .semester-wrapper:nth-child(5) {
        grid-row: 2;
        grid-column: 2 / 3;
       margin-left: 60%;
    }

    /* Third row - 3 items */
    .semester-wrapper:nth-child(6),
    .semester-wrapper:nth-child(7),
    .semester-wrapper:nth-child(8) {
        grid-row: 3;
    }

    .semester-wrapper {
        position: relative;
    }

    .semester-details {
        display: none;
        width: 290px;
        background: white;
        border-bottom: 1px solid #e0e0e0;
        border-left: 1px solid #e0e0e0;
        border-right: 1px solid #e0e0e0;
        /* box-shadow: 0 4px 12px rgba(0,0,0,0.1); */
        position: absolute;
        top: 100%;
        left: 0;
        z-index: 100;
        margin-top: -1px;
    }

    .details-content {
        padding: 0;
    }

    .semester-box {
        width: 250px;
        background-color: #0082d6;
        border: 1px solid rgba(0, 70, 117, 0.18);
        color: white;
        padding: 15px 20px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        cursor: pointer;
        transition: all 0.3s ease;
        border-radius: 0;
        font-size: 16px;
        font-weight: 600;
        position: relative;
    }

    /* Add styles for active state */
    .semester-box.active {
        background-color: white;
        color: #0082d6;
        border: 1px solid #e0e0e0;
        border-bottom: none;
    }

    /* Style for the plus/cross icon */
    .semester-box i {
        font-size: 18px;
        color: inherit;
        transition: all 0.3s ease;
    }

    .semester-box.active i {
        background-color: #ff6b00;
        border-radius: 50%;
        color: #e0e0e0; /* Orange color for the X icon when active */
    }

    .table-header {
        display: flex;
        padding: 15px 20px;
        justify-content: space-between;
    }

    .table-header .course-title,
    .table-header .credit-hours {
        font-size: 14px;
        text-transform: capitalize;
        font-weight: 600;
        color: #ff870a;
    }

    .course-row {
        display: flex;
        padding: 15px 20px;
        justify-content: space-between;
    }
    .course-row .credit-hours {
        margin-right: 20%;
    }

    .course-row:last-child {
        border-bottom: none;
    }

    .course-row span {
        font-size: 14px;
        color: #666666;
        font-weight: 500;
    }
       /* Enhanced responsive styles */
       @media (max-width: 1200px) {
        .info-box-row {
            gap: 28px;
            margin: 60px 0 95px 12px;
        }
        .info-box {
            min-width: 220px;
            padding: 28px 0 16px 0;
        }
        .info-label, .info-value {
            font-size: 1rem;
        }
        .curriculum-container {
            padding: 35px 4%;
        }
        .curriculum-title {
            font-size: 1.8rem;
            margin-bottom: 35px;
        }
        .semester-grid {
            gap: 25px;
        }
        .semester-wrapper {
            width: 270px;
        }
        .semester-details {
            width: 270px;
        }
        .semester-box {
            width: 230px;
            padding: 13px 18px;
            font-size: 15px;
        }
        .table-header {
            padding: 13px 18px;
        }
        .course-row {
            padding: 13px 18px;
        }
        .table-header .course-title,
        .table-header .credit-hours,
        .course-row span {
            font-size: 13px;
        }
    }

    @media (max-width: 992px) {
        .info-box-row {
            gap: 24px;
            margin: 50px 0 80px 10px;
        }
        .info-box {
            min-width: 200px;
            padding: 24px 0 14px 0;
        }
        .info-label, .info-value {
            font-size: 0.95rem;
        }
        .curriculum-container {
            padding: 30px 3%;
        }
        .curriculum-title {
            font-size: 1.6rem;
            margin-bottom: 30px;
        }
        .semester-grid {
            grid-template-columns: repeat(2, minmax(200px, 250px));
            gap: 20px;
        }
        .semester-wrapper:nth-child(4),
        .semester-wrapper:nth-child(5) {
            margin-left: 80%;
            grid-column: auto;
            grid-row: auto;
        }
        .semester-wrapper {
            width: 250px;
        }
        .semester-details {
            width: 250px;
        }
        .semester-box {
            width: 210px;
            padding: 12px 16px;
            font-size: 14px;
        }
        .table-header {
            padding: 12px 16px;
        }
        .course-row {
            padding: 12px 16px;
        }
        .table-header .course-title,
        .table-header .credit-hours,
        .course-row span {
            font-size: 12px;
        }
    }

    @media (max-width: 900px) {
        .info-box-row {
            flex-direction: column;
            gap: 18px;
            align-items: center;
            margin: 40px 0 60px 0;
        }
        .info-box {
            min-width: 180px;
            padding: 20px 0 12px 0;
        }
        .info-label, .info-value {
            font-size: 0.9rem;
        }
        .curriculum-container {
            padding: 25px 2%;
        }
        .curriculum-title {
            font-size: 1.5rem;
            margin-bottom: 25px;
        }
        .semester-grid {
            gap: 18px;
        }
        .semester-wrapper {
            width: 230px;
        }
        .semester-details {
            width: 230px;
        }
        .semester-box {
            width: 190px;
            padding: 10px 14px;
            font-size: 13px;
        }
        .table-header {
            padding: 10px 14px;
        }
        .course-row {
            padding: 10px 14px;
        }
        .table-header .course-title,
        .table-header .credit-hours,
        .course-row span {
            font-size: 11px;
        }
    }

    @media (max-width: 768px) {
        .info-box-row {
            gap: 15px;
            margin: 30px 0 50px 0;
        }
        .info-box {
            min-width: 160px;
            padding: 18px 0 10px 0;
        }
        .info-label, .info-value {
            font-size: 0.85rem;
        }
        .curriculum-container {
            padding: 20px 2%;
        }
        .curriculum-title {
            font-size: 1.4rem;
            margin-bottom: 20px;
        }
        .semester-grid {
            gap: 15px;
        }
        .semester-wrapper {
            width: 210px;
        }
        .semester-details {
            width: 210px;
        }
        .semester-box {
            width: 170px;
            padding: 8px 12px;
            font-size: 12px;
        }
        .table-header {
            padding: 8px 12px;
        }
        .course-row {
            padding: 8px 12px;
        }
        .table-header .course-title,
        .table-header .credit-hours,
        .course-row span {
            font-size: 10px;
        }
    }

    @media (max-width: 600px) {
        .info-box-row {
            gap: 12px;
            margin: 25px 0 40px 0;
        }
        .info-box {
            min-width: 140px;
            padding: 15px 0 8px 0;
        }
        .info-label, .info-value {
            font-size: 0.8rem;
        }
        .curriculum-container {
            padding: 15px 1%;
        }
        .curriculum-title {
            font-size: 1.3rem;
            margin-bottom: 15px;
        }
        .semester-grid {
            gap: 12px;
        }
        .semester-wrapper {
            width: 190px;
        }
        .semester-details {
            width: 190px;
        }
        .semester-box {
            width: 150px;
            padding: 6px 10px;
            font-size: 11px;
        }
        .table-header {
            padding: 6px 10px;
        }
        .course-row {
            padding: 6px 10px;
        }
        .table-header .course-title,
        .table-header .credit-hours,
        .course-row span {
            font-size: 9px;
        }
    }

    @media (max-width: 576px) {
        .info-box-row {
            gap: 10px;
            margin: 20px 0 30px 0;
        }
        .info-box {
            min-width: 120px;
            padding: 12px 0 6px 0;
        }
        .info-label, .info-value {
            font-size: 0.75rem;
        }
        .curriculum-container {
            padding: 12px 1%;
        }
        .curriculum-title {
            font-size: 1.2rem;
            margin-bottom: 12px;
        }
        .semester-grid {
            display: block;
            padding: 0 20px;
        }
        .semester-wrapper {
            margin-bottom: 15px;
            display: flex;
            justify-content: center;
            position: relative;
            width: 250px;
        }
        .semester-details {
            width: 250px;
            left: 50%;
            transform: translateX(-50%);
        }
        .semester-wrapper:nth-child(4),
        .semester-wrapper:nth-child(5){
            margin-left: 0;
        }
        .semester-box {
            width: 250px;
            padding: 10px 15px;
            font-size: 14px;
        }
        .table-header {
            padding: 10px 15px;
        }
        .course-row {
            padding: 10px 15px;
        }
        .table-header .course-title,
        .table-header .credit-hours,
        .course-row span {
            font-size: 12px;
        }
    }

    @media (max-width: 480px) {
        .info-box-row {
            gap: 8px;
            margin: 15px 0 25px 0;
        }
        .info-box {
            min-width: 100px;
            padding: 10px 0 5px 0;
        }
        .info-label, .info-value {
            font-size: 0.7rem;
        }
        .curriculum-container {
            padding: 10px 1%;
        }
        .curriculum-title {
            font-size: 1.1rem;
            margin-bottom: 10px;
        }
        .semester-grid {
            padding: 0 15px;
        }
        .semester-wrapper {
            width: 220px;
            margin-bottom: 12px;
        }
        .semester-details {
            width: 220px;
        }
        .semester-box {
            width: 220px;
            padding: 8px 12px;
            font-size: 13px;
        }
        .table-header {
            padding: 8px 12px;
        }
        .course-row {
            padding: 8px 12px;
        }
        .table-header .course-title,
        .table-header .credit-hours,
        .course-row span {
            font-size: 11px;
        }
    }

    @media (max-width: 400px) {
        .info-box-row {
            gap: 6px;
            margin: 12px 0 20px 0;
        }
        .info-box {
            min-width: 90px;
            padding: 8px 0 4px 0;
        }
        .info-label, .info-value {
            font-size: 0.65rem;
        }
        .curriculum-container {
            padding: 8px 1%;
        }
        .curriculum-title {
            font-size: 1rem;
            margin-bottom: 8px;
        }
        .semester-grid {
            padding: 0 10px;
        }
        .semester-wrapper {
            width: 200px;
            margin-bottom: 10px;
        }
        .semester-details {
            width: 200px;
        }
        .semester-box {
            width: 200px;
            padding: 6px 10px;
            font-size: 12px;
        }
        .table-header {
            padding: 6px 10px;
        }
        .course-row {
            padding: 6px 10px;
        }
        .table-header .course-title,
        .table-header .credit-hours,
        .course-row span {
            font-size: 10px;
        }
    }

    @media (max-width: 360px) {
        .info-box-row {
            gap: 5px;
            margin: 10px 0 15px 0;
        }
        .info-box {
            min-width: 80px;
            padding: 6px 0 3px 0;
        }
        .info-label, .info-value {
            font-size: 0.6rem;
        }
        .curriculum-container {
            padding: 6px 1%;
        }
        .curriculum-title {
            font-size: 0.9rem;
            margin-bottom: 6px;
        }
        .semester-grid {
            padding: 0 8px;
        }
        .semester-wrapper {
            width: 180px;
            margin-bottom: 8px;
        }
        .semester-details {
            width: 180px;
        }
        .semester-box {
            width: 180px;
            padding: 5px 8px;
            font-size: 11px;
        }
        .table-header {
            padding: 5px 8px;
        }
        .course-row {
            padding: 5px 8px;
        }
        .table-header .course-title,
        .table-header .credit-hours,
        .course-row span {
            font-size: 9px;
        }
    }

</style>

<script>
    function toggleSemester(semesterId) {
        const details = document.getElementById('sem_'+semesterId);
        const semesterBox = details.previousElementSibling;
        const icon = semesterBox.querySelector('i');

        // Close all other open semesters first
        const allDetails = document.querySelectorAll('.semester-details');
        const allBoxes = document.querySelectorAll('.semester-box');
        allDetails.forEach(detail => {
            if (detail.id !== 'sem_'+semesterId && detail.style.display === 'block') {
                detail.style.display = 'none';
                detail.previousElementSibling.classList.remove('active');
                detail.previousElementSibling.querySelector('i').className = 'bx bx-plus';
            }
        });

        if (details.style.display === 'block') {
            details.style.display = 'none';
            semesterBox.classList.remove('active');
            icon.className = 'bx bx-plus';
        } else {
            details.style.display = 'block';
            semesterBox.classList.add('active');
            icon.className = 'bx bx-x';
        }
    }

    // Close details when clicking outside
    document.addEventListener('click', function(event) {
        if (!event.target.closest('.semester-wrapper')) {
            const allDetails = document.querySelectorAll('.semester-details');
            const allBoxes = document.querySelectorAll('.semester-box');
            allDetails.forEach(detail => {
                detail.style.display = 'none';
                detail.previousElementSibling.classList.remove('active');
                detail.previousElementSibling.querySelector('i').className = 'bx bx-plus';
            });
        }
    });
</script>
