<table style="width: 100%; border-collapse: collapse; margin-top: 10px; page-break-inside: auto; orphans: 3; widows: 3;">
  <!-- Fila de encabezados -->
  <tr style="background-color: #303d50; page-break-inside: avoid; break-inside: avoid; display: table-row;">
    <td class="celda-i" style="width: 14%; padding: 10px 5px 10px 20px; border: 1px solid #303d50;">
      <label style="margin-bottom: 0px; font-weight: bold; color: white; font-size: 13px;">Item</label>
    </td>
    <td class="celda-c" style="width: 20%; padding: 10px 5px; border: 1px solid #303d50;">
      <label style="margin-bottom: 0px; font-weight: bold; color: white; font-size: 13px;">Descriptores</label>
    </td>
    <td class="celda-c" style="width: 5%; padding: 10px 5px; border: 1px solid #303d50; text-align: center;">
      <label style="margin-bottom: 0px; font-weight: bold; color: white; font-size: 13px;">Escala 100%</label>
    </td>
    <td class="celda-c" style="width: 5%; padding: 10px 5px; border: 1px solid #303d50; text-align: center;">
      <label style="margin-bottom: 0px; font-weight: bold; color: white; font-size: 13px;">Escala 33%</label>
    </td>
    <td class="celda-c" style="width: 5%; padding: 10px 5px; border: 1px solid #303d50; text-align: center;">
      <label style="margin-bottom: 0px; font-weight: bold; color: white; font-size: 13px;">Valor absoluto</label>
    </td>
    <td class="celda-c" style="width: 12%; padding: 10px 5px; border: 1px solid #303d50; text-align: center;">
      <label style="margin-bottom: 0px; font-weight: bold; color: white; font-size: 13px;">Valor relativo ponderado</label>
    </td>
    <td class="celda-d" style="width: 39%; padding: 10px 20px 10px 5px; border: 1px solid #303d50;">
      <label style="margin-bottom: 0px; font-weight: bold; color: white; font-size: 13px;">Fuentes de información que soportan el puntaje</label>
    </td>
  </tr>
  
  <!-- Filas de datos -->
  {% for fila in filas %}
  <tr style="border-bottom: 1px solid #e0e0e0; {% if fila.es_subtotal %}background-color: #f9f9f9;{% endif %} page-break-inside: avoid; break-inside: avoid; display: table-row;">
    {% if fila.es_seccion_principal %}
    <!-- Fila principal que abarca todas las columnas -->
    <td colspan="7" style="padding: 10px 20px; background-color: #f5f5f5; border: 1px solid #e0e0e0;">
      <p style="margin: 0; font-size: 14px; color: #002857; font-weight: bold;">
        {{ fila.item }}
      </p>
    </td>
    {% elif fila.es_subtotal %}
    <!-- Fila de subtotal -->
    <td class="celda-i" style="width: 14%; padding: 10px 5px 10px 20px; vertical-align: middle; border: 1px solid #e0e0e0;">
      <p style="margin: 0; font-size: 13px; color: #002857; font-weight: bold;">
        {{ fila.item }}
      </p>
    </td>
    <td class="celda-c" style="width: 25%; padding: 10px 5px; vertical-align: middle; border: 1px solid #e0e0e0;">
      <!-- Vacío para subtotal -->
    </td>
    <td class="celda-c" style="width: 5%; padding: 10px 5px; text-align: center; vertical-align: middle; border: 1px solid #e0e0e0;">
      <p style="margin: 0; font-size: 13px; color: #002857; font-weight: bold;">
        {% if fila.escala100 %}{{ fila.escala100 }}%{% else %}-{% endif %}
      </p>
    </td>
    <td class="celda-c" style="width: 5%; padding: 10px 5px; text-align: center; vertical-align: middle; border: 1px solid #e0e0e0;">
      <p style="margin: 0; font-size: 13px; color: #002857; font-weight: bold;">
        {% if fila.escala33 %}{{ fila.escala33|floatformat:2 }}%{% else %}-{% endif %}
      </p>
    </td>
    <td class="celda-c" style="width: 5%; padding: 10px 5px; text-align: center; vertical-align: middle; border: 1px solid #e0e0e0;">
      <p style="margin: 0; font-size: 13px; color: #002857; font-weight: bold;">
        {{ fila.valor_absoluto|default:'-' }}
      </p>
    </td>
    <td class="celda-c" style="width: 12%; padding: 10px 5px; text-align: center; vertical-align: middle; border: 1px solid #e0e0e0;">
      <p style="margin: 0; font-size: 13px; color: #002857; font-weight: bold;">
        {{ fila.valor_relativo_ponderado|default:0|floatformat:2 }}
      </p>
    </td>
    <td class="celda-d" style="width: 39%; padding: 10px 20px 10px 5px; vertical-align: middle; border: 1px solid #e0e0e0;">
      <!-- Vacío para subtotal -->
    </td>
    {% else %}
    <!-- Columna Item -->
    <td class="celda-i" style="width: 14%; padding: 10px 5px 10px 20px; vertical-align: top; border: 1px solid #e0e0e0; page-break-inside: avoid; break-inside: avoid;">
      <p style="margin: 0; font-size: 13px; color: #002857; font-weight: {% if fila.es_item_principal %}bold{% else %}normal{% endif %};">
        {{ fila.item }}
      </p>
    </td>
    
    <!-- Columna Descriptores -->
    <td class="celda-c" style="width: 20%; padding: 10px 5px; vertical-align: top; border: 1px solid #e0e0e0;">
      {% if fila.descriptores %}
        <div style="font-size: 11px; color: #002857;">
          {% for descriptor in fila.descriptores %}
            <div style="margin-bottom: 5px; line-height: 1.4;">
              {% if descriptor.valor == fila.valor_absoluto %}
                <i class="fa-solid fa-circle" style="font-size: 14px; color: #002857; vertical-align: middle; margin-right: 5px;"></i>
              {% else %}
                <i class="fa-regular fa-circle" style="font-size: 14px; color: #ccc; vertical-align: middle; margin-right: 5px;"></i>
              {% endif %}
              <span style="vertical-align: middle;">{{ descriptor.valor }}: {{ descriptor.texto }}</span>
            </div>
          {% endfor %}
        </div>
      {% else %}
        <div style="min-height: 50px;"></div>
      {% endif %}
    </td>
    
    <!-- Columna Escala 100% -->
    <td class="celda-c" style="width: 5%; padding: 10px 5px; text-align: center; vertical-align: top; border: 1px solid #e0e0e0;">
      <p style="margin: 0; font-size: 13px; color: #002857;">
        {{ fila.escala100|default:'-' }}
      </p>
    </td>
    
    <!-- Columna Escala 33% -->
    <td class="celda-c" style="width: 5%; padding: 10px 5px; text-align: center; vertical-align: top; border: 1px solid #e0e0e0;">
      <p style="margin: 0; font-size: 13px; color: #002857;">
        {{ fila.escala33|default:'-' }}
      </p>
    </td>
    
    <!-- Columna Valor absoluto -->
    <td class="celda-c" style="width: 5%; padding: 10px 5px; text-align: center; vertical-align: top; border: 1px solid #e0e0e0;">
      <p style="margin: 0; font-size: 13px; color: #002857; font-weight: {% if fila.valor_absoluto %}bold{% endif %};">
        {{ fila.valor_absoluto|default:'-' }}
      </p>
    </td>
    
    <!-- Columna Valor relativo ponderado -->
    <td class="celda-c" style="width: 12%; padding: 10px 5px; text-align: center; vertical-align: top; border: 1px solid #e0e0e0;">
      <p style="margin: 0; font-size: 13px; color: #002857;">
        {{ fila.valor_relativo_ponderado|default:'0'|floatformat:3 }}
      </p>
    </td>
    
    <!-- Columna Fuentes de información -->
    <td class="celda-d" style="width: 39%; padding: 10px 20px 10px 5px; vertical-align: top; border: 1px solid #e0e0e0; page-break-inside: avoid; break-inside: avoid;">
      <p style="margin: 0; font-size: 11px; color: #002857; font-family: 'Roboto', sans-serif;">
        {{ fila.fuentes_informacion|default:'' }}
      </p>
    </td>
    {% endif %}
  </tr>
  {% endfor %}
</table>