<?php
function template29($institutions, $branch, $students_array, $examination, $array, $result, $class_id, $section_id)
{
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Holistic Progress Report</title>

<style>
/* ✅ PRINT SETTINGS - A4 LANDSCAPE */
@page{
  size: A4 landscape;
  margin: 6mm;
}

*{
  margin:0;
  padding:0;
  box-sizing:border-box;
}

/* ✅ SCREEN VIEW */
html, body{
  width: 100%;
  min-height: 100vh;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #f2f2f8;
  padding: 20px;
}

/* ✅ REPORT CONTAINER */
.onepage-report{
  max-width: 1200px;
  margin: 0 auto 20px auto;
  background: #fff;
  border: 4px solid #c4161c;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.15);
  overflow: visible;
}

/* ✅ SCHOOL HEADER */
.school-header{
  text-align:center;
  padding-bottom: 10px;
  border-bottom: 3px double #c4161c;
  margin-bottom: 10px;
}

.school-logo img{
  width: 140px;
  height: 70px;
  object-fit:contain;
}

.school-name{
  font-size: 34px;
  font-weight: 900;
  color:#2c2f83;
  margin-top:4px;
}

.school-address{
  font-size: 14px;
  margin-top:3px;
  color:#333;
}

.school-meta{
  font-size: 12px;
  margin-top:2px;
  color:#444;
}

/* ✅ REPORT TITLE */
.report-title{
  text-align:center;
  font-size: 26px;
  font-weight: 900;
  margin-top:8px;
  letter-spacing:1px;
  color:#111;
}

.year{
  text-align:center;
  font-size: 28px;
  font-weight: 900;
  color:#c4161c;
  margin:6px 0 12px 0;
}

/* ✅ STUDENT INFO TABLE */
.info-table{
  width: 100%;
  margin: 0 auto 10px auto;
  border-collapse: collapse;
}

.info-table td{
  border:none !important;
  padding: 5px 6px;
  font-size: 13px;
}

.info-table td:first-child{
  width: 20%;
  font-weight: 700;
  color:#2c2f83;
}

.line{
  display:inline-block;
  width: 70%;
  min-height: 16px;
  border-bottom: 2px dotted #888;
}

/* ✅ SECTION TITLE */
.page-title{
  font-weight:bold;
  font-size:14px;
  margin: 8px 0 6px 0;
  color:#2c2f83;
  padding-bottom: 3px;
  border-bottom: 2px solid #c4161c;
}

.sub-head{
  font-weight:bold;
  margin: 8px 0 5px;
  color: #2c2f83;
  font-size: 13px;
}

/* ✅ TABLE COMMON */
table{
  width:100%;
  border-collapse:collapse;
  font-size:10.5px;
}

th, td{
  border:1px solid #000;
  padding: 3px 4px;
  text-align:center;
  vertical-align:middle;
}

th{
  background:#b4b4d6;
  font-weight:700;
  font-size:10px;
}

.left{
  text-align:left;
  padding-left:7px;
  font-weight:600;
}

.term-head th{
  background:#2c2f83 !important;
  color:#fff !important;
}

/* ✅ SMALL BOX HEIGHT */
.blank-box{
  height:26px;
}

.remarks-line{
  border-bottom:1px dotted #444;
  min-height:18px;
  margin-top:3px;
  font-size:11px;
  padding:2px 0;
}

/* ✅ PRINT STYLES - EACH STUDENT ONE PAGE */
@media print{
  html, body{
    width: 297mm !important;
    height: 210mm !important;
    margin: 0 !important;
    padding: 0 !important;
    background:#fff !important;
  }

  body{
    padding:0 !important;
  }

  .onepage-report{
    width:100% !important;
    height:100% !important;
    margin:0 !important;
    padding:3mm !important;
    border-radius:0 !important;
    box-shadow:none !important;
    page-break-after: always !important;
    break-after: page !important;
  }

  .onepage-report:last-child{
    page-break-after: auto !important;
    break-after: auto !important;
  }

  .school-header{
    margin-bottom:3px;
    padding-bottom:3px;
  }

  .school-name{ font-size:28px; }
  .report-title{ font-size:20px; margin-top:4px; }
  .year{ font-size:22px; margin:4px 0 6px; }

  .info-table td{
    padding:2px 4px;
    font-size:11px;
  }

  .page-title{
    font-size:12px;
    margin:5px 0 4px;
  }

  table{
    font-size:9px;
  }

  th, td{
    padding:2px 3px;
  }

  .blank-box{ height:20px; }
  .remarks-line{ min-height:14px; font-size:10px; }

  *{
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }
}
</style>

</head>

<body>

<?php foreach($students_array as $stu){ ?>

<div class="onepage-report">

    <!-- ✅ SCHOOL HEADER -->
    <div class="school-header">
        <div class="school-logo">
            <?php if (!empty($institutions['logo'])): ?>
                <img src="<?= htmlspecialchars($institutions['logo']) ?>" alt="School Logo">
            <?php endif; ?>
        </div>

        <div class="school-name"><?= htmlspecialchars($institutions['institution_name']) ?></div>

        <div class="school-address">
            <?= htmlspecialchars($branch['address']) ?>
            <?php if (!empty($branch['pincode'])): ?> - <?= htmlspecialchars($branch['pincode']) ?> <?php endif; ?>
        </div>

        <div class="school-meta">
            <?= htmlspecialchars($branch['branch_code']) ?>
            <?php if (!empty($branch['contact_number'])): ?> , <?= htmlspecialchars($branch['contact_number']) ?> <?php endif; ?>
            <?php if (!empty($branch['email'])): ?> , <?= strtolower(htmlspecialchars($branch['email'])) ?> <?php endif; ?>
        </div>
    </div>

    <!-- ✅ REPORT TITLE -->
    <div class="report-title">HOLISTIC PROGRESS REPORT</div>
    <div class="year">2025-2026</div>

    <!-- ✅ STUDENT INFO -->
    <table class="info-table">
        <tr><td>Name</td><td>: <span class="line"><?= $stu['name'] ?? '' ?></span></td></tr>
        <tr><td>Class & Sec.</td><td>: <span class="line"><?= $class_id; ?> <?= $section_id; ?></span></td></tr>
        <tr><td>PEN No.</td><td>: <span class="line"><?= $stu['admission_number'] ?? '' ?></span></td></tr>
        <tr><td>Admission No.</td><td>: <span class="line"><?= $stu['admission_number'] ?? '' ?></span></td></tr>
        <tr><td>Date of Birth</td><td>: <span class="line"><?= $stu['dob'] ?? '' ?></span></td></tr>
        <tr><td>Father's Name</td><td>: <span class="line"><?= $stu['fathername'] ?? '' ?></span></td></tr>
        <tr><td>Mother's Name</td><td>: <span class="line"><?= $stu['mothername'] ?? '' ?></span></td></tr>
    </table>

    <!-- ✅ MARKS TABLE -->
    <div class="page-title">ACADEMIC PERFORMANCE: SCHOLASTIC AREAS</div>
<?php $m = $stu['marksheet_data'] ?? []; ?>
    <table>
        <tr class="term-head">
            <th></th>
            <th colspan="8">TERM - I (100 MARKS)</th>
        </tr>
        <tr>
            <th>Subject</th>
            <th>PT-1<br>40</th>
            <th>Ass.<br>5</th>
            <th>N.B.<br>5</th>
            <th>Out of<br>50</th>
            <th>PT-2<br>40</th>
            <th>Ass.<br>5</th>
            <th>N.B.<br>5</th>
            <th>Out of<br>50</th>
        </tr>

        <tr>
            <td class="left">English</td>
            <td><?= $m[109] ?? '' ?></td>
            <td><?= $m[110] ?? '' ?></td>
            <td><?= $m[111] ?? '' ?></td>
            <td><?= $m[112] ?? '' ?></td>
            <td><?= $m[113] ?? '' ?></td>
            <td><?= $m[114] ?? '' ?></td>
            <td><?= $m[115] ?? '' ?></td>
            <td><?= $m[116] ?? '' ?></td>
        </tr>

        <tr>
            <td class="left">Hindi</td>
            <td><?= $m[117] ?? '' ?></td>
            <td><?= $m[118] ?? '' ?></td>
            <td><?= $m[119] ?? '' ?></td>
            <td><?= $m[120] ?? '' ?></td>
            <td><?= $m[121] ?? '' ?></td>
            <td><?= $m[122] ?? '' ?></td>
            <td><?= $m[123] ?? '' ?></td>
            <td><?= $m[124] ?? '' ?></td>
        </tr>

        <tr>
            <td class="left">Punjabi</td>
            <td><?= $m[125] ?? '' ?></td>
            <td><?= $m[126] ?? '' ?></td>
            <td><?= $m[127] ?? '' ?></td>
            <td><?= $m[128] ?? '' ?></td>
            <td><?= $m[129] ?? '' ?></td>
            <td><?= $m[130] ?? '' ?></td>
            <td><?= $m[131] ?? '' ?></td>
            <td><?= $m[132] ?? '' ?></td>
        </tr>

        <tr>
            <td class="left">Maths</td>
            <td><?= $m[133] ?? '' ?></td>
            <td><?= $m[134] ?? '' ?></td>
            <td><?= $m[135] ?? '' ?></td>
            <td><?= $m[136] ?? '' ?></td>
            <td><?= $m[137] ?? '' ?></td>
            <td><?= $m[138] ?? '' ?></td>
            <td><?= $m[139] ?? '' ?></td>
            <td><?= $m[140] ?? '' ?></td>
        </tr>

        <tr>
            <td class="left">EVS</td>
            <td><?= $m[141] ?? '' ?></td>
            <td><?= $m[142] ?? '' ?></td>
            <td><?= $m[143] ?? '' ?></td>
            <td><?= $m[144] ?? '' ?></td>
            <td><?= $m[145] ?? '' ?></td>
            <td><?= $m[146] ?? '' ?></td>
            <td><?= $m[147] ?? '' ?></td>
            <td><?= $m[148] ?? '' ?></td>
        </tr>

        <tr>
            <td class="left"><b>G. Total</b></td>
            <td><?= $m[149] ?? '' ?></td>
            <td><?= $m[150] ?? '' ?></td>
            <td><?= $m[151] ?? '' ?></td>
            <td><?= $m[152] ?? '' ?></td>
            <td><?= $m[153] ?? '' ?></td>
            <td><?= $m[154] ?? '' ?></td>
            <td><?= $m[155] ?? '' ?></td>
            <td><?= $m[156] ?? '' ?></td>
        </tr>

        <tr>
            <td class="left">Drawing</td>
            <td><?= $m[157] ?? '' ?></td>
            <td><?= $m[158] ?? '' ?></td>
            <td><?= $m[159] ?? '' ?></td>
            <td><?= $m[160] ?? '' ?></td>
            <td><?= $m[161] ?? '' ?></td>
            <td><?= $m[162] ?? '' ?></td>
            <td><?= $m[163] ?? '' ?></td>
            <td><?= $m[164] ?? '' ?></td>
        </tr>

        <tr>
            <td class="left">G.K. / Apt</td>
            <td><?= $m[165] ?? '' ?></td>
            <td><?= $m[166] ?? '' ?></td>
            <td><?= $m[167] ?? '' ?></td>
            <td><?= $m[168] ?? '' ?></td>
            <td><?= $m[169] ?? '' ?></td>
            <td><?= $m[170] ?? '' ?></td>
            <td><?= $m[171] ?? '' ?></td>
            <td><?= $m[172] ?? '' ?></td>
        </tr>

        <tr>
            <td class="left"><b>Percentage</b></td>
            <td colspan="8"><?= $m[173] ?? '' ?></td>
        </tr>
    </table>

    <!-- ✅ EXTRA TABLES ADDED -->
    <div class="sub-head">CO-SCHOLASTICS AREAS</div>

    <table class="health">
        <tr>
            <th colspan="4" class="left">HEALTH STATUS</th>
        </tr>
        <tr>
            <td class="left">Height</td>
            <td><?= $m[174] ?? '' ?></td>
            <td class="left">Weight</td>
            <td><?= $m[175] ?? '' ?></td>
        </tr>
        <tr>
            <td class="left">Blood Group</td>
            <td colspan="3"><?= $m[176] ?? '' ?></td>
        </tr>
    </table>

    <table class="attendance" style="margin-top:8px;">
        <tr>
            <th class="left">ATTENDENCE</th>
            <th>TERM I</th>
        </tr>
        <tr>
            <td class="left">No of Working Days</td>
            <td><?= $m[177] ?? '' ?></td>
        </tr>
        <tr>
            <td class="left">Days Attended</td>
            <td><?= $m[180] ?? '' ?></td>
        </tr>
        <tr>
            <td class="left">Attendance %</td>
            <td><?= $m[183] ?? '' ?></td>
        </tr>
    </table>

    <table style="margin-top:8px;">
        <tr>
            <th class="left">Competition</th>
        </tr>
        <tr>
            <td class="blank-box"><?= $m[186] ?? '' ?></td>
        </tr>
        <tr>
            <td class="blank-box"><?= $m[187] ?? '' ?></td>
        </tr>
    </table>

    <div style="margin-top:8px; font-size:12px;"><b>Class Teacher's Remarks:</b></div>
    <div class="remarks-line"><?= $m[188] ?? '' ?></div>

</div>

<?php } ?>

</body>

</html>
<?php
}
?>
