<!DOCTYPE html>
{# academics/templates/report_cards/anglophone_primary.html #}
{# Matches scanned template: doc 13 — MARKS /20, Term page + Annual results page #}
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
  @page { size: A4 portrait; margin: 8mm 8mm 8mm 8mm; }
  * { box-sizing: border-box; margin: 0; padding: 0; }

  body { font-family: Arial, sans-serif; font-size: 7.5pt; color: #000; }

  /* ── School header ── */
  .school-header { text-align: center; margin-bottom: 3mm; }
  .school-header h1 { font-size: 11pt; font-weight: bold; text-transform: uppercase; }
  .school-header h2 { font-size: 9pt; }
  .school-header .logo-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2mm; }
  .school-header .logo-row img { height: 20mm; }
  .school-header .title-block { flex: 1; }

  /* ── Meta row (CLASS / TERM / Teacher) ── */
  .meta-row { display: flex; gap: 6mm; margin-bottom: 2mm; border-bottom: 1.5pt solid #000; padding-bottom: 1mm; }
  .meta-cell { flex: 1; }
  .meta-cell label { font-weight: bold; font-size: 7pt; }
  .meta-cell span  { border-bottom: 1pt dotted #000; display: inline-block; min-width: 30mm; }

  /* ── Main marks table ── */
  table.marks-table { width: 100%; border-collapse: collapse; }
  table.marks-table th, table.marks-table td {
    border: 0.5pt solid #000;
    padding: 0.8mm 0.8mm;
    text-align: center;
    vertical-align: middle;
  }
  table.marks-table td.label { text-align: left; }

  /* Header rows */
  .th-dark { background: #2c3e6e; color: #fff; font-weight: bold; font-size: 7pt; }
  .th-mid  { background: #bfc9e0; font-weight: bold; font-size: 6.5pt; }

  /* Domain column — rotated text */
  td.domain-cell {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    white-space: nowrap;
    font-weight: bold;
    font-size: 6.5pt;
    text-align: center;
    width: 8mm;
    background: #eef0f8;
  }

  tr.totals-row td { font-weight: bold; background: #f2f4fb; }

  /* ── Annual results box ── */
  .annual-box { border: 1.5pt solid #000; padding: 3mm; margin-top: 3mm; width: 60%; float: right; }
  .annual-box h3 { font-size: 8pt; text-align: center; font-weight: bold; margin-bottom: 2mm;
                   background: #2c3e6e; color: #fff; padding: 1mm; }
  .annual-box .row { display: flex; justify-content: space-between; margin-bottom: 1.5mm; }
  .annual-box .row label { font-weight: bold; }
  .annual-box .row span  { border-bottom: 1pt dotted #000; min-width: 25mm; display: inline-block; }

  /* Decision checkboxes */
  .decision-box { border: 1pt solid #000; padding: 2mm; margin-top: 3mm; }
  .decision-box h4 { font-weight: bold; font-size: 7.5pt; margin-bottom: 2mm; text-align: center; }
  .decision-row { display: flex; gap: 8mm; }
  .decision-row label { display: flex; align-items: center; gap: 1mm; font-size: 7.5pt; }
  .checkbox { width: 4mm; height: 4mm; border: 1pt solid #000; display: inline-block; text-align: center; line-height: 4mm; }
  .checkbox.checked::after { content: '✓'; font-size: 8pt; }

  /* Signature row */
  .sig-row { display: flex; justify-content: space-between; margin-top: 4mm; border-top: 1pt solid #000; padding-top: 2mm; }
  .sig-cell { text-align: center; width: 30mm; }
  .sig-cell .line { border-top: 1pt solid #000; margin-top: 6mm; font-size: 6.5pt; }

  .next-term { margin-top: 3mm; font-size: 7pt; }
  .next-term strong { font-size: 7.5pt; }

  .clearfix::after { content: ''; display: block; clear: both; }
  .page-break { page-break-before: always; }
</style>
</head>
<body>

{# ═══════════════════════════════════════════════════════════════════
   TERM PAGE  (one per term — term 1, 2, and 3)
════════════════════════════════════════════════════════════════════ #}
{% for term_data in terms %}

{% if not forloop.first %}<div class="page-break"></div>{% endif %}

<!-- School header -->
<div class="school-header">
  <div class="logo-row">
    {% if school.logo %}<img src="{{ school.logo.url }}" alt="Logo">{% else %}<div style="width:20mm"></div>{% endif %}
    <div class="title-block">
      <h1>{{ school.name }}</h1>
      <h2>PROGRESS REPORT CARD / ANGLOPHONE PRIMARY</h2>
      <div style="font-size:8pt">{{ school.address }} | Tel: {{ school.phone }}</div>
    </div>
    {% if school.logo %}<img src="{{ school.logo.url }}" alt="Logo">{% else %}<div style="width:20mm"></div>{% endif %}
  </div>
</div>

<!-- Student / Class meta -->
<div class="meta-row">
  <div class="meta-cell"><label>Student: </label><span>{{ student.get_full_name }}</span></div>
  <div class="meta-cell"><label>Class: </label><span>{{ report_card.school_class }}</span></div>
  <div class="meta-cell"><label>TERM </label><span style="border:1pt solid #000;padding:0 3mm;font-weight:bold">{{ term_data.term.term }}</span></div>
  <div class="meta-cell"><label>Year: </label><span>{{ term_data.term.academic_year }}</span></div>
</div>
<div class="meta-row" style="margin-top:-1mm">
  <div class="meta-cell"><label>Class Teacher: </label><span>{{ report_card.school_class.class_teacher.get_display_name }}</span></div>
  <div class="meta-cell"><label>Date of Birth: </label><span>{{ student.date_of_birth|date:"d/m/Y" }}</span></div>
  <div class="meta-cell"><label>Sex: </label><span>{{ student.get_gender_display }}</span></div>
</div>

<!-- Marks table -->
<table class="marks-table">
  <thead>
    <tr>
      <th class="th-dark" rowspan="2" style="width:8mm">DOM.</th>
      <th class="th-dark" rowspan="2" style="width:28mm">ACTIVITIES</th>
      <th class="th-dark" rowspan="2" style="width:38mm">SUB-ACTIVITIES</th>
      <th class="th-dark" colspan="3">MARKS /20</th>
      <th class="th-dark" rowspan="2" style="width:12mm">Synthese Marks</th>
      <th class="th-dark" rowspan="2" style="width:14mm">APPRECIATION</th>
    </tr>
    <tr>
      {% for m in term_data.month_labels %}
      <th class="th-mid" style="width:10mm">{{ m }}</th>
      {% endfor %}
    </tr>
  </thead>
  <tbody>
    {% for row in term_data.rows %}
      {% if row.is_domain_header %}
        {# domain header is embedded via rowspan in first subject row #}
      {% else %}
      <tr>
        {% if row.show_domain %}
        <td class="domain-cell" rowspan="{{ row.domain_rowspan }}">{{ row.domain }}</td>
        {% endif %}
        {% if row.show_activity %}
        <td style="writing-mode:vertical-rl;transform:rotate(180deg);font-size:6.5pt;font-weight:bold;width:8mm;background:#f5f5f5;"
            rowspan="{{ row.activity_rowspan }}">{{ row.activity }}</td>
        {% endif %}
        <td class="label">{{ row.sub_activity }}</td>
        {% for score in row.month_scores %}
        <td>{{ score|default:'' }}</td>
        {% endfor %}
        <td style="font-weight:bold">{{ row.synthese|default:'' }}</td>
        <td>{{ row.appreciation|default:'' }}</td>
      </tr>
      {% endif %}
    {% endfor %}

    <!-- TOTAL row -->
    <tr class="totals-row">
      <td colspan="3" style="text-align:right;font-weight:bold">TOTAL</td>
      {% for m_total in term_data.month_totals %}
      <td>{{ m_total|default:'' }}</td>
      {% endfor %}
      <td>{{ term_data.total_synthese|default:'' }}</td>
      <td></td>
    </tr>
    <!-- AVERAGE row -->
    <tr class="totals-row">
      <td colspan="3" style="text-align:right">AVERAGE</td>
      {% for m_avg in term_data.month_averages %}
      <td>{{ m_avg|default:'' }}</td>
      {% endfor %}
      <td>{{ term_data.average|default:'' }}</td>
      <td></td>
    </tr>
    <!-- POSITION row -->
    <tr class="totals-row">
      <td colspan="3" style="text-align:right">POSITION</td>
      <td colspan="3"></td>
      <td>{{ report_card.position|default:'' }}/{{ term_data.class_size }}</td>
      <td></td>
    </tr>
  </tbody>
</table>

<!-- Conduct / Remarks row -->
<table style="width:100%;border-collapse:collapse;margin-top:2mm">
  <tr>
    <td style="border:0.5pt solid #000;padding:1mm 2mm;width:50%">
      <strong>CONDUCT:</strong>&nbsp;
      <span style="border-bottom:1pt dotted #000;display:inline-block;min-width:40mm">
        {{ report_card.conduct|default:'' }}
      </span>
    </td>
    <td style="border:0.5pt solid #000;padding:1mm 2mm">
      <strong>REMARKS:</strong>&nbsp;
      <span style="border-bottom:1pt dotted #000;display:inline-block;min-width:60mm">
        {{ report_card.class_teacher_remark|default:'' }}
      </span>
    </td>
  </tr>
</table>

<!-- Signature row -->
<div class="sig-row">
  <div class="sig-cell"><div class="line">Head Teacher Sign.</div></div>
  <div class="sig-cell"><div class="line">Class Teacher Sign.</div></div>
  <div class="sig-cell"><div class="line">Parent Sign.</div></div>
</div>

{% if term_data.term.term == 3 %}
{# ── Annual Results block (shown only on Term 3 page) ── #}
<div class="clearfix" style="margin-top:4mm">
  <div class="annual-box">
    <h3>ANNUAL RESULTS</h3>
    <div class="row"><label>1st Term Average</label><span>{{ report_card.term1_average|default:'…' }}</span></div>
    <div class="row"><label>2nd Term Average</label><span>{{ report_card.term2_average|default:'…' }}</span></div>
    <div class="row"><label>3rd Term Average</label><span>{{ report_card.term3_average|default:'…' }}</span></div>
    <div class="row" style="border-top:1pt solid #000;padding-top:1mm;margin-top:1mm">
      <label>Annual Average</label><span style="font-weight:bold">{{ report_card.annual_average|default:'…' }}</span>
    </div>
    <div class="row"><label>Annual Position</label><span>{{ report_card.annual_position|default:'…' }}/{{ term_data.class_size }}</span></div>

    <!-- Decision -->
    <div class="decision-box" style="margin-top:2mm">
      <h4>DECISION</h4>
      <div class="decision-row">
        <label>
          <span class="checkbox {% if report_card.promotion_status == 'promoted' %}checked{% endif %}"></span>
          Promoted
        </label>
        <label>
          <span class="checkbox {% if report_card.promotion_status == 'repeat' %}checked{% endif %}"></span>
          Repeat
        </label>
        <label>
          <span class="checkbox {% if report_card.promotion_status == 'dismissed' %}checked{% endif %}"></span>
          Dismissed
        </label>
      </div>
    </div>
  </div>

  <!-- Head teacher remark -->
  <div style="width:37%;border:0.5pt solid #000;padding:2mm;margin-top:2mm">
    <strong style="font-size:7pt">Head Teacher Remark:</strong>
    <div style="min-height:15mm;border-bottom:0.5pt dotted #000;margin-top:1mm">
      {{ report_card.head_teacher_remark|default:'' }}
    </div>
  </div>
</div>

<div class="next-term" style="margin-top:3mm">
  <strong>NEXT TERM BEGINS:</strong>
  <span style="border-bottom:1pt solid #000;display:inline-block;min-width:30mm">
    {{ report_card.next_term_begins|date:"d/m/Y"|default:'…………………' }}
  </span>
</div>

<!-- Final sig row for annual page -->
<div class="sig-row">
  <div class="sig-cell"><div class="line">Head Teacher Sign.</div></div>
  <div class="sig-cell"><div class="line">Class Teacher Sign.</div></div>
  <div class="sig-cell"><div class="line">Parent Sign.</div></div>
</div>
{% endif %}

{% endfor %}{# end terms loop #}

</body>
</html>
