{# The round thread — each round's feedback items paired with the project's answers,
   plus the agent's own raised concerns. `thread.rounds` is newest-first; `answered`
   (derived) = every feedback item has a matching answer (spec §5.6). #}
{% import "macros.html" as m %}
{% if thread.has_rounds %}
  {% for r in thread.rounds %}
  <section class="card fw-panel fw-round">
    <header class="fw-panel__head">
      <h2 class="card__title fw-panel__title">Round v{{ r.round }}</h2>
      <span class="fw-spacer"></span>
      {% if r.unreadable %}
      <span class="fw-round__status fw-round__status--unreadable mono">unreadable — {{ r.reason }}</span>
      {% else %}
      <span class="fw-round__status fw-round__status--{{ 'answered' if r.answered else 'open' }}">{{ 'answered' if r.answered else 'open' }}</span>
      {{ m.derived() }}
      {% endif %}
    </header>
    {% if not r.unreadable %}
    <div class="fw-round__body">
      <div class="fw-round__by mono">from {{ r.feedback.authored_by }} · {{ r.feedback.authored_at }}</div>
      {% for pair in r['items'] %}
      <article class="fw-fb">
        <header class="fw-fb__h">
          <span class="pill">{{ pair.item.id }}</span>
          <span class="badge badge-info">{{ pair.item.kind }}</span>
          {% if pair.item.priority %}<span class="pill pill--priority">priority {{ pair.item.priority }}</span>{% endif %}
          {% if pair.item.applies_to %}<span class="pill mono">{{ pair.item.applies_to.view }} · {{ pair.item.applies_to.ref }}</span>{% endif %}
          <span class="fw-fb__t">{{ pair.item.title }}</span>
        </header>
        <p class="fw-fb__body">{{ pair.item.body }}</p>
        {% if pair.answer %}
        <div class="fw-answer">
          <div class="fw-answer__h">
            <span class="fw-answer__lbl mono">↩ response</span>
            <span class="status-chip status-chip--{{ 'in-sync' if pair.answer.status in ('accepted','done') else ('stale' if pair.answer.status in ('deferred','needs_clarification') else 'tampered') }}"><span class="status-chip__dot"></span>{{ pair.answer.status }}</span>
          </div>
          {% if pair.answer.body %}<p class="fw-answer__body">{{ pair.answer.body }}</p>{% endif %}
          {% if pair.answer.evidence %}<p class="evidence">evidence · {{ pair.answer.evidence }}</p>{% endif %}
        </div>
        {% else %}
        <div class="fw-answer fw-answer--pending mono">awaiting a response</div>
        {% endif %}
      </article>
      {% endfor %}

      {% if r.agent_raised %}
      <div class="fw-agent">
        <div class="fw-agent__h mono">the project agent raised</div>
        {% for ar in r.agent_raised %}
        <div class="fw-agent__item">
          <span class="pill">{{ ar.id }}</span><span class="badge badge-neutral">{{ ar.kind }}</span>
          <span class="fw-agent__body">{{ ar.body }}</span>
          {% if ar.evidence %}<span class="evidence">· {{ ar.evidence }}</span>{% endif %}
        </div>
        {% endfor %}
      </div>
      {% endif %}
    </div>
    {% endif %}
  </section>
  {% endfor %}
{% else %}
  {{ m.empty_inline("No feedback rounds yet", "Compose feedback above — it's delivered into the project's feedback/ inbox and threads here with the project's response.") }}
{% endif %}
