{% extends "base_report.html" %}

{% block report_title %}Measurement Report{% endblock %}

{% block content %}
<!-- Recipe info + filters -->
<div class="info-box">
  <span class="label">Recipe:</span> {{ recipe.code }} — {{ recipe.name }}
  {% if filters_desc %}
  <br>
  <span class="label">Filters:</span> {{ filters_desc | join(' | ') }}
  {% endif %}
</div>

<!-- Summary -->
<div class="section">
  <div class="section-title">Summary</div>
  <div class="summary-grid">
    <div class="summary-card">
      <div class="number mono">{{ summary.total }}</div>
      <div class="label">Total</div>
    </div>
    <div class="summary-card pass-bg">
      <div class="number mono pass">{{ summary.pass_count }}</div>
      <div class="label">Pass ({{ summary.pass_rate }}%)</div>
    </div>
    <div class="summary-card warning-bg">
      <div class="number mono warning">{{ summary.warning_count }}</div>
      <div class="label">Warning ({{ summary.warning_rate }}%)</div>
    </div>
    <div class="summary-card fail-bg">
      <div class="number mono fail">{{ summary.fail_count }}</div>
      <div class="label">Fail ({{ summary.fail_rate }}%)</div>
    </div>
  </div>
</div>

<!-- Measurements Table -->
<div class="section">
  <div class="section-title">Measurements ({{ n_measurements }})</div>
  <table>
    <thead>
      <tr>
        <th>#</th>
        <th>Measurement Point</th>
        <th>Value</th>
        <th>Unit</th>
        <th>Result</th>
        <th>Date</th>
        <th>Operator</th>
        <th>Lot</th>
        <th>Serial</th>
      </tr>
    </thead>
    <tbody>
      {% for row in rows %}
      <tr class="{% if row.pass_fail == 'fail' %}fail-bg{% elif row.pass_fail == 'warning' %}warning-bg{% endif %}">
        <td class="mono">{{ row.num }}</td>
        <td>{{ row.subtask }}</td>
        <td class="mono">{{ row.value }}</td>
        <td>{{ row.unit }}</td>
        <td>
          <span class="{{ row.pass_fail }}">{{ row.pass_fail | upper }}</span>
        </td>
        <td class="mono">{{ row.measured_at }}</td>
        <td>{{ row.operator }}</td>
        <td>{{ row.lot_number }}</td>
        <td>{{ row.serial_number }}</td>
      </tr>
      {% endfor %}
    </tbody>
  </table>
</div>

{% endblock %}
