<?php
function template31(
    $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>
@page{ size:A4 landscape; margin:6mm; }
*{ margin:0; padding:0; box-sizing:border-box; }

body{
  font-family: Arial, Helvetica, sans-serif;
  margin:20px;
  background:#fff;
  color:#000;
}

.onepage-report{
  max-width:1150px;
  margin:0 auto;
  border:2px solid #000;
  padding:12px;
}

/* ===== HEADER ===== */
.school-header{
  text-align:center;
  border:2px solid #000;
  border-radius:10px;
  padding:8px;
  position:relative;
}

.school-logo{
  position:absolute;
  left:10px;
  top:0;
  bottom:0;
  margin:auto 0;
  width:55px;
  height:55px;
}

.school-logo img{ width:100%; height:100%; object-fit:contain; }

.school-name{ font-size:18px; font-weight:900; }
.school-address{ font-size:12px; }
.school-meta{ font-size:11px; }

.report-title{
  text-align:center;
  font-size:20px;
  font-weight:900;
  margin-top:6px;
}

.year{
  text-align:center;
  font-size:16px;
  font-weight:bold;
  margin-bottom:10px;
}

table{
  width:100%;
  border-collapse:collapse;
  font-size:11px;
}

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

.page-title{
  font-weight:bold;
  font-size:14px;
  margin:8px 0 4px;
  border-bottom:1px solid #000;
}

.sub-head{ font-weight:bold; margin:10px 0 4px; }
.blank-box{ height:28px; }
.remarks-line{ border-bottom:1px dotted #000; min-height:18px; }

@media print{
  .onepage-report{ page-break-after:always; break-after:page; }
  .onepage-report:last-child{ page-break-after:auto; break-after:auto; }
  @media print {

  /* reduce header height */
  .school-header{
    padding: 4px 8px !important;   /* was 8px */
  }

  /* slightly smaller logo */
  .school-logo{
    width: 45px !important;
    height: 45px !important;
  }

  /* tighten text */
  .school-name{
    font-size: 15px !important;
    line-height: 1.1 !important;
  }

  .school-address{
    font-size: 11px !important;
    line-height: 1.1 !important;
  }

  .school-meta{
    font-size: 10px !important;
    line-height: 1.1 !important;
  }
  .onepage-report {
    page-break-after: always;
    break-after: page;
  }

  /* prevent last blank page (optional) */
  .onepage-report:last-child {
    page-break-after: auto;
    break-after: auto;
  }
}
}
</style>
</head>

<body>

<?php foreach ($students_array as $student): ?>
<?php $marks = $student['marksheet_data'] ?? []; ?>

<div class="onepage-report">

<!-- ===== HEADER ===== -->
<div class="school-header">
  <div class="school-logo">
    <?php if(!empty($institutions['logo'])): ?>
      <img src="<?= htmlspecialchars($institutions['logo']) ?>">
    <?php endif; ?>
  </div>
  <div class="school-name"><?= htmlspecialchars($institutions['institution_name']) ?></div>
  <div class="school-address"><?= htmlspecialchars($branch['address']) ?></div>
  <div class="school-meta"><?= htmlspecialchars($branch['branch_code']) ?></div>
</div>

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

<!-- ===== TERM I ===== -->
<div class="page-title">ACADEMIC PERFORMANCE: SCHOLASTIC AREAS</div>

<table>
<thead>
<tr><th colspan="7">TERM - I (100 MARKS)</th></tr>
<tr>
<th>Subject</th>
<th>PT</th>
<th>Sub Enr.</th>
<th>NB</th>
<th>Half Yr</th>
<th>Total</th>
<th>Grade</th>
</tr>
</thead>
<tbody>

<tr><td>English</td><td><?= $marks[78] ?? '' ?></td><td><?= $marks[79] ?? '' ?></td><td><?= $marks[80] ?? '' ?></td><td><?= $marks[81] ?? '' ?></td><td><?= $marks[82] ?? '' ?></td><td><?= $marks[83] ?? '' ?></td></tr>
<tr><td>Hindi</td><td><?= $marks[84] ?? '' ?></td><td><?= $marks[85] ?? '' ?></td><td><?= $marks[86] ?? '' ?></td><td><?= $marks[87] ?? '' ?></td><td><?= $marks[88] ?? '' ?></td><td><?= $marks[89] ?? '' ?></td></tr>
<tr><td>Punjabi</td><td><?= $marks[90] ?? '' ?></td><td><?= $marks[91] ?? '' ?></td><td><?= $marks[92] ?? '' ?></td><td><?= $marks[93] ?? '' ?></td><td><?= $marks[94] ?? '' ?></td><td><?= $marks[95] ?? '' ?></td></tr>
<tr><td>Maths</td><td><?= $marks[96] ?? '' ?></td><td><?= $marks[97] ?? '' ?></td><td><?= $marks[98] ?? '' ?></td><td><?= $marks[99] ?? '' ?></td><td><?= $marks[100] ?? '' ?></td><td><?= $marks[101] ?? '' ?></td></tr>

<tr>
<td>G.Total</td>
<td colspan="3"><?= $marks[114] ?? '' ?></td>
<td><?= $marks[115] ?? '' ?></td>
<td><?= $marks[116] ?? '' ?></td>
<td><?= $marks[117] ?? '' ?></td>
</tr>

<tr>
<td>Percentage</td>
<td colspan="6"><?= $marks[136] ?? '' ?></td>
</tr>

</tbody>
</table>

<!-- ===== HEALTH ===== -->
<div class="sub-head">HEALTH STATUS</div>
<table>
<tr><td>Height</td><td><?= $marks[137] ?? '' ?></td><td>Weight</td><td><?= $marks[138] ?? '' ?></td></tr>
<tr><td>Blood Group</td><td colspan="3"><?= $marks[139] ?? '' ?></td></tr>
</table>

<!-- ===== ATTENDANCE ===== -->
<div class="sub-head">ATTENDANCE</div>
<table>
<tr><th></th><th>Term I</th><th>Term II</th><th>Total</th></tr>
<tr><td>Working Days</td><td><?= $marks[140] ?? '' ?></td><td><?= $marks[141] ?? '' ?></td><td><?= $marks[142] ?? '' ?></td></tr>
<tr><td>Days Attended</td><td><?= $marks[143] ?? '' ?></td><td><?= $marks[144] ?? '' ?></td><td><?= $marks[145] ?? '' ?></td></tr>
<tr><td>Attendance %</td><td><?= $marks[146] ?? '' ?></td><td><?= $marks[147] ?? '' ?></td><td><?= $marks[148] ?? '' ?></td></tr>
</table>

<!-- ===== COMPETITION ===== -->
<div class="sub-head">Competition</div>
<table>
<tr><td class="blank-box"><?= $marks[149] ?? '' ?></td></tr>
<tr><td class="blank-box"><?= $marks[150] ?? '' ?></td></tr>
</table>

<!-- ===== REMARKS ===== -->
<div style="margin-top:8px;"><b>Class Teacher’s Remarks:</b></div>
<div class="remarks-line"><?= $marks[151] ?? '' ?></div>

</div>

<?php endforeach; ?>

</body>
</html>
<?php } ?>
