<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <style>
    /* Global styles */
    body { font-family: Arial, sans-serif; font-size: 10pt; margin: 0; padding: 0; }
    h1, h2 { margin: 0; }
    /* Portrait page */
    @page portrait { size: A4 portrait; margin: 20mm; }
    .portrait { page: portrait; page-break-after: always; }
    .header { display: flex; justify-content: space-between; margin-bottom: 8mm; }
    .title { text-align: center; font-size: 14pt; margin-bottom: 6mm; }
    .section { margin-top: 6mm; }
    .section h2 { font-size: 12pt; text-transform: uppercase; margin-bottom: 2mm; }
    .section p { margin: 1mm 0; }
    .signatures { display: flex; justify-content: space-between; margin-top: 8mm; }
    /* Landscape page */
    @page landscape { size: A4 landscape; margin: 15mm; }
    .landscape { page: landscape; page-break-after: always; }
    .board-title { text-align: left; font-size: 12pt; margin-bottom: 4mm; }
    table { width: 100%; border-collapse: collapse; margin-bottom: 4mm; }
    th, td { border: 1px solid #000; padding: 2mm; text-align: left; }
    th { font-weight: bold; font-size: 9pt; }
    .nested-table { width: 100%; border-collapse: collapse; }
    .nested-table th, .nested-table td { border: none; padding: 1mm; }
  </style>
</head>
<body>

<!-- PORTRAIT: Cover & Summary (Sections A–G) -->
<div class="portrait">
  <div class="header">
    <div>Report Ref: {{report_ref}}</div>
    <div>Page {{page_number}} of {{total_pages}}</div>
  </div>
  <h1 class="title">ELECTRICAL INSTALLATION CONDITION REPORT</h1>
  <div style="text-align:center;">
    <img src="{{front_image_url}}" alt="Front of Building" style="max-width:80%; height:auto;" />
  </div>
  <!-- Section A -->
  <div class="section">
    <h2>Section A. Details of the Client</h2>
    <p><strong>Client:</strong> {{client_name}}</p>
    <p><strong>Address:</strong> {{client_address}}</p>
  </div>
  <!-- Section B -->
  <div class="section">
    <h2>Section B. Reason for Producing this Report</h2>
    <p>{{report_reason}}</p>
    <p><strong>Inspection Dates:</strong> {{inspection_dates}}</p>
  </div>
  <!-- Section C -->
  <div class="section">
    <h2>Section C. Details of the Installation</h2>
    <p><strong>Occupier:</strong> {{occupier}}</p>
    <p><strong>Address:</strong> {{occupier_address}}</p>
    <p><strong>Description of Premises:</strong> {{premises_type}}{{#other_type}}, Other: {{other_type}}{{/other_type}}</p>
    <p><strong>Evidence of Alterations:</strong> {{alterations}}</p>
    <p><strong>Estimated Age:</strong> {{estimated_age}}</p>
    <p><strong>Previous Inspection:</strong> {{previous_inspection_date}}</p>
    <p><strong>Records Available:</strong> {{records_available}}</p>
    <p><strong>DNO:</strong> {{dno}}</p>
    <p><strong>Sub‑Station No:</strong> {{substation_number}}</p>
  </div>
</div>

<!-- PORTRAIT: Extent to Declaration (Sections D–G) -->
<div class="portrait">
  <!-- Section D -->
  <div class="section">
    <h2>Section D. Extent & Limitations</h2>
    <p>{{extent_of_installation}}</p>
    <p>{{limitations}}</p>
  </div>
  <!-- Section E -->
  <div class="section">
    <h2>Section E. Summary of Condition</h2>
    <p><strong>General Condition:</strong> {{general_condition}}</p>
    <p><strong>Overall Assessment:</strong> {{overall_assessment}}</p>
  </div>
  <!-- Section F -->
  <div class="section">
    <h2>Section F. Recommendations</h2>
    <p>{{recommendations}}</p>
    <p><strong>Date of Next Inspection:</strong> {{next_inspection_date}}</p>
  </div>
  <!-- Section G -->
  <div class="section declaration">
    <h2>Section G. Declaration</h2>
    <div class="signatures">
      <div>
        <p>Inspected & Tested by:</p>
        <p>{{inspector_name}}</p>
        <p>{{inspector_position}}</p>
      </div>
      <div>
        <p>Report Authorised by:</p>
        <p>{{authoriser_name}}</p>
        <p>{{authoriser_position}}</p>
      </div>
    </div>
    <p><strong>Date:</strong> {{declaration_date}}</p>
  </div>
</div>

<!-- PORTRAIT: Schedules & Observations (Sections H–K) -->
<div class="portrait">
  <!-- Section H -->
  <div class="section">
    <h2>Section H. Schedule(s) of Inspection & Test Results</h2>
    <table>
      <thead>
        <tr>
          <th>Item No</th><th>Description</th><th>Outcome</th><th>Further Investigation</th>
        </tr>
      </thead>
      <tbody>
        {{#inspection_schedule_rows}}
        <tr>
          <td>{{item_no}}</td>
          <td>{{description}}</td>
          <td>{{outcome}}</td>
          <td>{{further_investigation}}</td>
        </tr>
        {{/inspection_schedule_rows}}
      </tbody>
    </table>
  </div>
  <!-- Section I -->
  <div class="section">
    <h2>Section I. Supply Characteristics & Earthing Arrangements</h2>
    <table>
      <tbody>
        <tr><td><strong>Earthing Arrangements:</strong> {{earthing_arrangements}}</td></tr>
        <tr><td><strong>Supply Type:</strong> {{supply_type}}</td></tr>
        <tr><td><strong>Prospective Fault Current:</strong> {{prospective_fault_current}}</td></tr>
        <tr><td><strong>Loop Impedance:</strong> {{loop_impedance}}</td></tr>
      </tbody>
    </table>
  </div>
  <!-- Section J -->
  <div class="section">
    <h2>Section J. Particulars of Installation</h2>
    <table>
      <tbody>
        <tr><td><strong>Means of Earthing:</strong> {{means_of_earthing}}</td></tr>
        <tr><td><strong>Main Switch Rating:</strong> {{main_switch_rating}}</td></tr>
        <!-- additional particulars rows -->
      </tbody>
    </table>
  </div>
  <!-- Section K -->
  <div class="section">
    <h2>Section K. Observations</h2>
    <table>
      <thead>
        <tr><th>Ref</th><th>Fault Code</th><th>Observation</th><th>FI</th></tr>
      </thead>
      <tbody>
        {{#observations_rows}}
        <tr>
          <td>{{ref}}</td><td>{{fault_code}}</td><td>{{comment}}</td><td>{{fi_flag}}</td>
        </tr>
        {{/observations_rows}}
      </tbody>
    </table>
  </div>
</div>

<!-- LANDSCAPE: One page per board -->
{{#boards}}
<div class="landscape">
  <div class="board-title">Test Results – Board {{board_name}}</div>
  <!-- Distribution board details -->
  <table>
    <tr><th>Board Ref</th><td>{{board_ref}}</td><th>Supply Rating</th><td>{{supply_rating}}</td></tr>
    <tr><th>Associated RCD</th><td>{{associated_rcd}}</td><th>PFC/PSCC</th><td>{{prospective_fault_current}}</td></tr>
  </table>
  <!-- Circuit results table -->
  <table>
    <thead>
      <tr>
        <th>Circuit No</th><th>Description</th><th>Conductor</th><th>Protective Device</th><th>Outcome</th><th>FI</th>
      </tr>
    </thead>
    <tbody>
      {{#circuit_results}}
      <tr>
        <td>{{circuit_no}}</td>
        <td>{{circuit_description}}</td>
        <td>{{conductor_details}}</td>
        <td>{{protective_device}}</td>
        <td>{{outcome}}</td>
        <td>{{further_investigation}}</td>
      </tr>
      {{/circuit_results}}
    </tbody>
  </table>
</div>
{{/boards}}

</body>
</html>
