<?php
function template30($institutions, $branch, $students_array, $examination, $array, $result, $class_id, $section_id)
{
    // âœ… SAFE MARKS SOURCE
    $marks = $students_array[0]['marksheet_data'] ?? [];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Holistic Progress Report</title>

<style>
/* âœ… BLACK & WHITE PRINT CSS */
@page{
  size:A4 landscape;
  margin:6mm;
}

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

html, body{
  width:100%;
  min-height:100vh;
  font-family:'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background:#ffffff;
  padding:20px;
  color:#000;
}

.onepage-report{
  max-width:1200px;
  margin:0 auto;
  background:#fff;
  border:2px solid #000;
  padding:25px;
}

 .school-header {
            text-align: center;
            padding: 10px 10px 14px 10px;
            border: 2px solid #111;
            border-radius: 12px;
            position: relative;
        }

        .school-logo {
            position: absolute;
            left: 10px;
            top: 10px;
            width: 55px;
            height: 55px;
            border-radius: 10px;
            overflow: hidden;
            border: 1px solid #ccc;
            background: #fff;
            display: flex;
            align-items: center;
            justify-content: center;
        }

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

        .school-name {
            font-size: 16px;
            font-weight: 900;
            text-transform: uppercase;
            margin-bottom: 4px;
        }

        .school-address { font-size: 12px; color: #333; margin-bottom: 3px; }
        .school-meta { font-size: 11px; color: #444; }


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

.year{
  text-align:center;
  font-size:24px;
  font-weight:900;
  margin-bottom:15px;
}
/* âœ… SIMPLE INFO TABLE */
.info-table{
  width:100%;
  margin-bottom:10px;
  border-collapse:collapse;
}

.info-table tr{
  border-bottom:1px solid #000;
}

.info-table td{
  padding:4px 6px;
  font-size:12px;
  vertical-align:middle;
}

.info-table td:first-child{
  width:30%;
  font-weight:600;
  text-align:left;
}

.info-table td:last-child{
  width:70%;
  text-align:left;
}


.page-title{
  font-weight:bold;
  font-size:15px;
  margin:10px 0;
  border-bottom:1px solid #000;
  padding-bottom:3px;
}

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

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

th{
  font-weight:bold;
}

.term-head{
  background:#000;
  color:#fff;
  font-weight:bold;
}

.sub-head{
  font-weight:bold;
  margin:12px 0 6px;
}

.blank-box{
  height:30px;
}

.remarks-line{
  border-bottom:1px dotted #000;
  min-height:20px;
  margin-top:4px;
}
/* âœ… FORCE SINGLE PAGE PRINT */
@media print {

  html, body{
    padding: 0 !important;
    margin: 0 !important;
    height: 100% !important;
  }

  .onepage-report{
    padding: 10px !important;      /* ðŸ”‘ reduce padding */
    border-width: 1px !important;
  }

  /* Reduce header height slightly */
  .school-header{
    padding: 6px 8px 8px 8px !important;
    margin-bottom: 6px !important;
  }

  .school-logo{
    width: 45px !important;
    height: 45px !important;
    top: 6px !important;
  }

  .school-name{
    font-size: 14px !important;
    margin-bottom: 2px !important;
  }

  .school-address{
    font-size: 11px !important;
    margin-bottom: 1px !important;
  }

  .school-meta{
    font-size: 10px !important;
  }

  .report-title{
    font-size: 18px !important;
    margin-top: 6px !important;
  }

  .year{
    font-size: 16px !important;
    margin-bottom: 8px !important;
  }

  .info-table td{
    padding: 3px 4px !important;
    font-size: 11px !important;
  }

  table{
    font-size: 10px !important;
  }

  th, td{
    padding: 3px 3px !important;
  }

  /* ðŸ”¥ CRITICAL: PREVENT PAGE BREAKS */
  table, tr, td, th, .school-header, .info-table{
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  /* Ensure colors stay exact */
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
  
  
}

</style>
</head>

<body>

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

<?php
// ✅ each student marks array
$marks = $stu['marksheet_data'] ?? [];
?>

<div class="onepage-report">

    <div class="school-header">
        <div class="school-logo">
            <?php if(!empty($institutions['logo'])): ?>
                <img src="<?= htmlspecialchars($institutions['logo']) ?>" alt="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>

    <table class="info-table">
        <tr><td>Name</td><td><?= htmlspecialchars($stu['name'] ?? '') ?></td></tr>
        <tr><td>Class & Sec.</td><td><?= htmlspecialchars($class_id ?? '') ?> <?= htmlspecialchars($section_id ?? '') ?></td></tr>
        <tr><td>Admission No.</td><td><?= htmlspecialchars($stu['admission_number'] ?? '') ?></td></tr>
        <tr><td>DOB</td><td><?= htmlspecialchars($stu['dob'] ?? '') ?></td></tr>
        <tr><td>Father</td><td><?= htmlspecialchars($stu['fathername'] ?? '') ?></td></tr>
        <tr><td>Mother</td><td><?= htmlspecialchars($stu['mothername'] ?? '') ?></td></tr>
    </table>

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

    <table>
        <tr class="term-head">
            <th></th>
            <th colspan="8">TERM - I</th>
        </tr>

        <tr>
            <th>Subject</th>
            <th>PT-1<br>40</th>
            <th>Ass.<br>5</th>
            <th>N.B.<br>5</th>
            <th>Marks<br>Out of<br>50</th>
            <th>PT-2<br>80/2=40</th>
            <th>Ass.<br>5</th>
            <th>N.B.<br>5</th>
            <th>Marks<br>Out of<br>50</th>
        </tr>

        <tr>
            <td>English</td>
            <td><?= $marks[119] ?? '' ?></td><td><?= $marks[120] ?? '' ?></td>
            <td><?= $marks[121] ?? '' ?></td><td><?= $marks[122] ?? '' ?></td>
            <td><?= $marks[123] ?? '' ?></td><td><?= $marks[124] ?? '' ?></td>
            <td><?= $marks[125] ?? '' ?></td><td><?= $marks[126] ?? '' ?></td>
        </tr>

        <tr>
            <td>Hindi</td>
            <td><?= $marks[127] ?? '' ?></td><td><?= $marks[128] ?? '' ?></td>
            <td><?= $marks[129] ?? '' ?></td><td><?= $marks[130] ?? '' ?></td>
            <td><?= $marks[131] ?? '' ?></td><td><?= $marks[132] ?? '' ?></td>
            <td><?= $marks[133] ?? '' ?></td><td><?= $marks[134] ?? '' ?></td>
        </tr>

        <tr>
            <td>Punjabi</td>
            <td><?= $marks[135] ?? '' ?></td><td><?= $marks[136] ?? '' ?></td>
            <td><?= $marks[137] ?? '' ?></td><td><?= $marks[138] ?? '' ?></td>
            <td><?= $marks[139] ?? '' ?></td><td><?= $marks[140] ?? '' ?></td>
            <td><?= $marks[141] ?? '' ?></td><td><?= $marks[142] ?? '' ?></td>
        </tr>

        <tr>
            <td>Maths</td>
            <td><?= $marks[143] ?? '' ?></td><td><?= $marks[144] ?? '' ?></td>
            <td><?= $marks[145] ?? '' ?></td><td><?= $marks[146] ?? '' ?></td>
            <td><?= $marks[147] ?? '' ?></td><td><?= $marks[148] ?? '' ?></td>
            <td><?= $marks[149] ?? '' ?></td><td><?= $marks[150] ?? '' ?></td>
        </tr>

        <tr>
            <td>EVS</td>
            <td><?= $marks[151] ?? '' ?></td><td><?= $marks[152] ?? '' ?></td>
            <td><?= $marks[153] ?? '' ?></td><td><?= $marks[154] ?? '' ?></td>
            <td><?= $marks[155] ?? '' ?></td><td><?= $marks[156] ?? '' ?></td>
            <td><?= $marks[157] ?? '' ?></td><td><?= $marks[158] ?? '' ?></td>
        </tr>

        <tr>
            <td>Drawing</td>
            <td><?= $marks[167] ?? '' ?></td><td><?= $marks[168] ?? '' ?></td>
            <td><?= $marks[169] ?? '' ?></td><td><?= $marks[170] ?? '' ?></td>
            <td><?= $marks[171] ?? '' ?></td><td><?= $marks[172] ?? '' ?></td>
            <td><?= $marks[173] ?? '' ?></td><td><?= $marks[174] ?? '' ?></td>
        </tr>

        <tr>
            <td>Computer</td>
            <td><?= $marks[175] ?? '' ?></td><td><?= $marks[176] ?? '' ?></td>
            <td><?= $marks[177] ?? '' ?></td><td><?= $marks[178] ?? '' ?></td>
            <td><?= $marks[179] ?? '' ?></td><td><?= $marks[180] ?? '' ?></td>
            <td><?= $marks[181] ?? '' ?></td><td><?= $marks[182] ?? '' ?></td>
        </tr>

        <tr>
            <td>GK</td>
            <td><?= $marks[183] ?? '' ?></td><td><?= $marks[184] ?? '' ?></td>
            <td><?= $marks[185] ?? '' ?></td><td><?= $marks[186] ?? '' ?></td>
            <td><?= $marks[187] ?? '' ?></td><td><?= $marks[188] ?? '' ?></td>
            <td><?= $marks[189] ?? '' ?></td><td><?= $marks[190] ?? '' ?></td>
        </tr>

        <tr>
            <td><b>Percentage</b></td>
            <td colspan="8"><?= $marks[191] ?? '' ?></td>
        </tr>
    </table>

    <div class="sub-head">CO-SCHOLASTICS</div>

    <table>
        <tr>
            <td>Height</td><td><?= $marks[192] ?? '' ?></td>
            <td>Weight</td><td><?= $marks[193] ?? '' ?></td>
        </tr>
        <tr>
            <td>Blood Group</td>
            <td colspan="3"><?= $marks[194] ?? '' ?></td>
        </tr>
    </table>

    <table>
        <tr><td>Working Days</td><td><?= $marks[195] ?? '' ?></td></tr>
        <tr><td>Days Attended</td><td><?= $marks[198] ?? '' ?></td></tr>
        <tr><td>Attendance %</td><td><?= $marks[201] ?? '' ?></td></tr>
    </table>

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

</div>

<?php } ?>

</body>

</html>
<?php } ?>
