<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>SFDAO Audit Report</title>
    <style>
      :root {
        color-scheme: light;
        font-family: "Helvetica Neue", Arial, sans-serif;
        line-height: 1.6;
      }

      body {
        margin: 2rem;
        color: #111;
        background: #f7f7f2;
      }

      h1,
      h2,
      h3 {
        margin-bottom: 0.5rem;
      }

      section {
        background: #fff;
        padding: 1.5rem;
        border-radius: 12px;
        margin-bottom: 1.5rem;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
      }

      table {
        width: 100%;
        border-collapse: collapse;
        margin-top: 0.75rem;
      }

      th,
      td {
        text-align: left;
        padding: 0.5rem 0.75rem;
        border-bottom: 1px solid #e6e6df;
      }

      th {
        background: #f0efe7;
      }

      .metric-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
        gap: 0.75rem;
      }

      .metric-card {
        background: #fbfbf8;
        border: 1px solid #ecece5;
        border-radius: 10px;
        padding: 0.75rem;
      }

      .metric-card strong {
        display: block;
        font-size: 1.1rem;
        margin-bottom: 0.25rem;
      }
    </style>
  </head>
  <body>
    <h1>SFDAO Audit Report</h1>

    <section>
      <h2>Executive Summary</h2>
      <p><strong>Overall Score:</strong> {{ composite_score.total | round(3) }}</p>
    </section>

    <section>
      <h2>Metrics</h2>
      <div class="metric-grid">
        {% for name, values in composite_score.components | dictsort %}
        <div class="metric-card">
          <strong>{{ name }}</strong>
          <div>value: {{ values.value | round(3) }}</div>
          <div>weight: {{ values.weight | round(3) }}</div>
          <div>weighted: {{ values.weighted | round(3) }}</div>
        </div>
        {% endfor %}
      </div>
    </section>

    {% if composite_score.penalties %}
    <section>
      <h2>Penalties</h2>
      <ul>
        {% for penalty in composite_score.penalties %}
        <li>{{ penalty.metric }}: -{{ penalty.amount | round(3) }}{% if penalty.reason %} ({{ penalty.reason }}){% endif %}</li>
        {% endfor %}
      </ul>
    </section>
    {% endif %}

    {% if metadata.ml_utility %}
    <section>
      <h2>ML Utility (TSTR)</h2>
      <p>Measures if models trained on synthetic data perform comparably to models trained on real data.</p>
      <div class="metric-grid">
        <div class="metric-card">
          <strong>TSTR AUC</strong>
          <div>{{ metadata.ml_utility.tstr_auc | round(3) }}</div>
        </div>
        <div class="metric-card">
          <strong>TRTR AUC (baseline)</strong>
          <div>{{ metadata.ml_utility.trtr_auc | round(3) }}</div>
        </div>
        <div class="metric-card">
          <strong>Utility Ratio</strong>
          <div>{{ metadata.ml_utility.utility_ratio | round(3) }}</div>
        </div>
        <div class="metric-card">
          <strong>TSTR F1</strong>
          <div>{{ metadata.ml_utility.tstr_f1 | round(3) }}</div>
        </div>
        <div class="metric-card">
          <strong>TRTR F1 (baseline)</strong>
          <div>{{ metadata.ml_utility.trtr_f1 | round(3) }}</div>
        </div>
      </div>
      <table>
        <thead>
          <tr>
            <th>Parameter</th>
            <th>Value</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>Model Type</td>
            <td>{{ metadata.ml_utility.model_type }}</td>
          </tr>
          <tr>
            <td>Target Column</td>
            <td>{{ metadata.ml_utility.target_column }}</td>
          </tr>
          <tr>
            <td>Number of Features</td>
            <td>{{ metadata.ml_utility.n_features }}</td>
          </tr>
        </tbody>
      </table>
    </section>
    {% endif %}

    <section>
      <h2>Metadata</h2>
      <table>
        <thead>
          <tr>
            <th>Key</th>
            <th>Value</th>
          </tr>
        </thead>
        <tbody>
          {% for key, value in metadata | dictsort %}
          {% if key != 'ml_utility' and key != 'financial_facts' %}
          <tr>
            <td>{{ key }}</td>
            <td>{{ value }}</td>
          </tr>
          {% endif %}
          {% endfor %}
        </tbody>
      </table>
    </section>
  </body>
</html>
