{# Jinja2 template for pairwise/win-loss-tie table (simple version) #}
{% if colordict %}
<style type="text/css">
  {% for cand, color in colordict.items() %}
  .color-{{ cand | escape_css }} { background-color: {{ color }}; }
  {% endfor %}
</style>
{% endif %}
<!-- JINJA2-PAIRWISE-TEMPLATE-USED -->


<div style="overflow-x:auto;">
    <table class="pairwise-table">
        <caption>{{ title | e }} pairwise matchups</caption>
        <tbody>
            {% for rk in candtoks %}
            <tr>
                <th>
                    <div>
                        <span class="colorblock color-{{ rk | escape_css }}"></span> {{ candnames[rk] }}
                    </div>
                    <small class="wlt-score">({{ "{:,}".format(wltdict[rk]['wins']) }}-{{ "{:,}".format(wltdict[rk]['losses']) }}-{{ "{:,}".format(wltdict[rk]['ties']) }})</small>
                </th>
                {% for ck in candtoks %}
                    {% if not loop.last %}
                        {% if candtoks.index(rk) > candtoks.index(ck) %}
                            <td>
                                <div class="matchup-cell-inner">
                                    {% set cell = paircells[rk][ck] if paircells else None %}
                                    {% if cell %}
                                    <div class="matchup-row">
                                        <span class="cand-name"><span class="colorblock color-{{ ck | escape_css }}"></span> {{ candnames[ck] }}:</span>
                                        <span class="cand-score">{{ "{:,}".format(cell.ck_score) }}<span class="score-percentage">({{ "%.1f"|format(cell.ck_pct) }}%)</span></span>
                                    </div>
                                    <div class="matchup-row">
                                        <span class="cand-name"><span class="colorblock color-{{ rk | escape_css }}"></span> {{ candnames[rk] }}:</span>
                                        <span class="cand-score">{{ "{:,}".format(cell.rk_score) }}<span class="score-percentage">({{ "%.1f"|format(cell.rk_pct) }}%)</span>{% if not (pairdict[ck][rk] > pairdict[rk][ck]) %}<sup>†</sup>{% endif %}</span>
                                    </div>
                                    <div class="no-pref-line" style="font-size:0.85em; color:#666; font-style:italic; text-align:center; margin-top:4px;">
                                        (No preference: {{ "{:,}".format(cell.no_pref) }}; {{ "%.1f"|format(cell.no_pref_pct) }}%)
                                    </div>
                                    {% else %}
                                    {# Fallback to original two-row layout if paircells missing #}
                                    {% set total_votes = pairdict[ck][rk] + pairdict[rk][ck] %}
                                    {% set ck_score = pairdict[ck][rk] %}
                                    {% set ck_percentage = (ck_score / total_votes * 100) if total_votes > 0 else 0 %}
                                    <div class="matchup-row">
                                        <span class="cand-name"><span class="colorblock color-{{ ck | escape_css }}"></span> {{ candnames[ck] }}:</span>
                                        <span class="cand-score">{{ "{:,}".format(ck_score) }}<span class="score-percentage">({{ "%.1f"|format(ck_percentage) }}%)</span></span>
                                    </div>
                                    {% set rk_score = pairdict[rk][ck] %}
                                    {% set rk_percentage = (rk_score / total_votes * 100) if total_votes > 0 else 0 %}
                                    <div class="matchup-row">
                                        <span class="cand-name"><span class="colorblock color-{{ rk | escape_css }}"></span> {{ candnames[rk] }}:</span>
                                        <span class="cand-score">{{ "{:,}".format(rk_score) }}<span class="score-percentage">({{ "%.1f"|format(rk_percentage) }}%)</span>{% if not (pairdict[ck][rk] > pairdict[rk][ck]) %}<sup>†</sup>{% endif %}</span>
                                    </div>
                                    {% endif %}
                                </div>
                            </td>
                        {% elif rk == ck %}
                            <td class="pseudo-header">
                                <div><span class="colorblock color-{{ rk | escape_css }}"></span> {{ candnames[rk] }} <br/>
                                {% if is_copeland_tie %}
                                    {{ "{:,}".format(wltdict[rk]['losses']) }} loss{{ 'es' if wltdict[rk]['losses'] != 1 else '' }} / {{ "{:,}".format(wltdict[rk]['wins']) }} victor{{ 'y' if wltdict[rk]['wins'] == 1 else 'ies' }}<sup>†</sup>
                                {% elif loop.index0 == 0 %}
                                    {{ "{:,}".format(wltdict[rk]['wins']) }} victor{{ 'y' if wltdict[rk]['wins'] == 1 else 'ies' }} ⇣
                                {% else %}
                                    ⇽ {{ "{:,}".format(wltdict[rk]['losses']) }} loss{{ 'es' if wltdict[rk]['losses'] != 1 else '' }} / {{ "{:,}".format(wltdict[rk]['wins']) }} victor{{ 'y' if wltdict[rk]['wins'] == 1 else 'ies' }}<sup>†</sup> ⇣
                                {% endif %}
                                </div>
                            </td>
                        {% else %}
                            {% if candtoks.index(rk) < candtoks.index(ck) %}
                                <td class="greyedOut"></td>
                            {% else %}
                                <td class="greyedOut"></td>
                            {% endif %}
                        {% endif %}
                    {% endif %}
                {% endfor %}
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>
{% if is_copeland_tie %}
<div class="footnote"><sup>†</sup> "Victories" and "losses" sometimes aren't displayed in the expected location when there are ties and/or cycles in the results, but the numbers provided should be accurate.</div>
{% endif %}
{% if svg_text %}
<div class="hscroll">{{ svg_text|safe }}</div>
{% endif %}
