<!doctype html>
<html lang="es">
<head>
  <meta charset="utf-8" />
  <title>Reporte DODA</title>
  <style>
    body { font-family: DejaVu Sans, Arial, Helvetica, sans-serif; font-size: 10pt; color: #111; }
    h1 { font-size: 16pt; margin: 0 0 6px; }
    h2 { font-size: 12pt; margin: 16px 0 8px; border-bottom: 1px solid #ccc; }
    .muted { color: #555; font-size: 9pt; }
    table { width: 100%; border-collapse: collapse; }
    th, td { border: 1px solid #ccc; padding: 4px 6px; vertical-align: top; }
    th { background: #f3f3f3; text-align: left; }
    .no-border td { border: none; padding: 2px 0; }
    .mono { font-family: DejaVu Sans Mono, Consolas, monospace; font-size: 8.5pt; white-space: pre-wrap; word-break: break-all; }
    .small { font-size: 8.5pt; }
  </style>
</head>
<body>
  <h1>Documento de operación (DODA)</h1>
  <p class="muted">Huella de contenido (SHA-256): <span class="mono">{{ fingerprint_sha256 }}</span></p>

  <h2>Datos generales</h2>
  <table>
    <tr>
      <th style="width: 22%;">Folio de integración</th><td>{{ doda.integration_number }}</td>
      <th style="width: 22%;">Patente</th><td>{{ doda.patent }}</td>
    </tr>
    <tr>
      <th>Aduana despacho</th><td>{{ doda.dispatch_customs }}</td>
      <th>Secciones aduaneras</th><td>{{ doda.customs_sections }}</td>
    </tr>
    <tr>
      <th>Operación</th><td>{{ doda.operation_type }}</td>
      <th>Estado</th><td>{{ doda.status }}</td>
    </tr>
    <tr>
      <th>Ident. transporte</th><td>{{ doda.transport_identification }}</td>
      <th>ID rápida</th><td>{{ doda.fast_id }}</td>
    </tr>
    <tr>
      <th>CAAT</th><td>{{ doda.caat }}</td>
      <th>Transacción / folio</th><td>{{ doda.transaction_number }}</td>
    </tr>
  </table>

  {% if linq_sat_qr %}
  <h2>QR (LINQ / SAT)</h2>
  <p class="mono small">{{ linq_sat_qr }}</p>
  {% endif %}

  {% if sat_chain_preview %}
  <h2>Cadena original / SAT (extracto)</h2>
  <p class="mono small">{{ sat_chain_preview }}</p>
  {% endif %}

  {% if sat_digital_seal_preview %}
  <h2>Sello digital (SAT) — extracto</h2>
  <p class="mono small">{{ sat_digital_seal_preview }}</p>
  {% endif %}

  <h2>Contenedores y precintos</h2>
  {% if containers|length == 0 %}
  <p class="muted">Sin contenedores registrados.</p>
  {% else %}
  <table>
    <thead>
      <tr>
        <th style="width:8%;">Línea</th>
        <th>Contenedor</th>
        <th style="width:38%;">Precintos (línea / valor)</th>
      </tr>
    </thead>
    <tbody>
    {% for c in containers %}
      <tr>
        <td>{{ c.container_line }}</td>
        <td class="mono">{{ c.container_value }}</td>
        <td>
          {% if c.seals|length == 0 %}
            <span class="muted">—</span>
          {% else %}
            <table class="no-border">
            {% for s in c.seals %}
              <tr>
                <td class="small" style="width: 18%;">{{ s.seal_line }}</td>
                <td class="mono small">{{ s.seal_value }}</td>
              </tr>
            {% endfor %}
            </table>
          {% endif %}
        </td>
      </tr>
    {% endfor %}
    </tbody>
  </table>
  {% endif %}

  <h2>Pedimentos nacionales</h2>
  {% if pedimentos_detail|length == 0 %}
  <p class="muted">Sin partidas de pedimentos nacionales.</p>
  {% else %}
  <table>
    <thead>
      <tr>
        <th style="width:8%;">Línea</th>
        <th>Patente auth.</th>
        <th>Documento / ped.</th>
        <th>Embarque</th>
        <th>COVE</th>
        <th>UMC</th>
        <th>Tipo</th>
      </tr>
    </thead>
    <tbody>
    {% for p in pedimentos_detail %}
      <tr>
        <td>{{ p.pedimento_line }}</td>
        <td class="mono">{{ p.authorization_patent }}</td>
        <td class="mono">{{ p.document }}</td>
        <td class="mono">{{ p.shipment }}</td>
        <td class="mono">{{ p.cove }}</td>
        <td class="mono">{{ p.umc }}</td>
        <td class="mono">{{ p.pedimento_type }}</td>
      </tr>
    {% endfor %}
    </tbody>
  </table>
  {% endif %}

  <h2>Pedimentos USA</h2>
  {% if american_pedimentos|length == 0 %}
  <p class="muted">Sin pedimentos americanos.</p>
  {% else %}
  <table>
    <thead>
      <tr>
        <th style="width:8%;">Línea</th>
        <th>Tipo</th>
        <th>Valor</th>
      </tr>
    </thead>
    <tbody>
    {% for a in american_pedimentos %}
      <tr>
        <td>{{ a.american_pedimento_line }}</td>
        <td class="mono">{{ a.american_pedimento_type }}</td>
        <td class="mono">{{ a.american_pedimento_value }}</td>
      </tr>
    {% endfor %}
    </tbody>
  </table>
  {% endif %}

  <p class="muted" style="margin-top: 18px;">
    Documento generado automáticamente. Los extractos de cadena / sello se truncan en este reporte;
    los datos de huella (SHA-256) reflejan el contenido completo persistido.
  </p>
</body>
</html>
