<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<style>
  @page { size: A4 landscape; margin: 15mm; }
  body { font-family: "Noto Sans CJK JP", "Hiragino Kaku Gothic Pro", sans-serif; font-size: 10pt; }
  h1 { font-size: 14pt; text-align: center; margin-bottom: 4px; }
  .subtitle { text-align: center; font-size: 10pt; color: #555; margin-bottom: 12px; }
  table { width: 100%; border-collapse: collapse; margin-top: 8px; }
  th, td { border: 1px solid #888; padding: 4px 6px; text-align: right; }
  th { background: #e8f5e9; text-align: center; }
  .col-name { text-align: left; }
  .col-area { text-align: right; }
  tr.total-row { font-weight: bold; background: #f5f5f5; }
  .zero { color: #bbb; }
</style>
</head>
<body>
<h1>施肥計画書</h1>
<p class="subtitle">{{ plan.year }}年度　{{ plan.variety.crop.name }} / {{ plan.variety.name }}　「{{ plan.name }}」</p>

<table>
  <thead>
    <tr>
      <th class="col-name">圃場名</th>
      <th class="col-area">面積(反)</th>
      {% for fert in fertilizers %}
      <th>{{ fert.name }}<br><small>（袋）</small></th>
      {% endfor %}
      <th>合計袋数</th>
    </tr>
  </thead>
  <tbody>
    {% for row in rows %}
    <tr>
      <td class="col-name">{{ row.field.name }}</td>
      <td class="col-area">{{ row.field.area_tan }}</td>
      {% for cell in row.cells %}
      <td>{% if cell %}{{ cell }}{% else %}<span class="zero">-</span>{% endif %}</td>
      {% endfor %}
      <td>{{ row.total }}</td>
    </tr>
    {% endfor %}
  </tbody>
  <tfoot>
    <tr class="total-row">
      <td class="col-name">合計</td>
      <td></td>
      {% for total in fert_totals %}
      <td>{{ total }}</td>
      {% endfor %}
      <td>{{ grand_total }}</td>
    </tr>
  </tfoot>
</table>
</body>
</html>
