<div id="ai-person-timeline-{{ person.id }}">
  <div style="margin-bottom: 0.75rem; padding: 0.5rem 0.25rem; border-bottom: 1px solid rgba(0, 0, 0, 0.12);">
    <p class="is-size-7 has-text-weight-semibold">Timeline</p>
    <h3 class="title is-5" style="margin-bottom: 0.25rem;">{{ person.name }}</h3>
    <p class="is-size-7">Showing last {{ limit }} messages.</p>
  </div>

  <div id="ai-message-list-{{ person.id }}" style="max-height: 65vh; overflow-y: auto; padding-right: 0.25rem;">
    {% if message_rows %}
      {% for row in message_rows %}
        <article class="media ai-message-row" data-ts="{{ row.message.ts }}" style="margin-bottom: 0.75rem;">
          <div class="media-content">
            <div
              class="content"
              style="margin-left: {% if row.direction == 'out' %}15%{% else %}0{% endif %}; margin-right: {% if row.direction == 'in' %}15%{% else %}0{% endif %};">
              <div
                style="margin-bottom: 0.25rem; padding: 0.6rem; border-radius: 6px; border: 1px solid rgba(0, 0, 0, 0.15); background: {% if row.direction == 'out' %}#f0f7ff{% else %}transparent{% endif %}; box-shadow: none;">
                <p style="white-space: pre-wrap; margin-bottom: 0.35rem;">{{ row.message.text|default:"(no text)" }}</p>
                <p class="is-size-7">
                  {{ row.ts_label }}
                  {% if row.message.custom_author %}
                    | {{ row.message.custom_author }}
                  {% endif %}
                </p>
              </div>
            </div>
          </div>
        </article>
      {% endfor %}
    {% else %}
      <p class="has-text-grey">No messages found for this contact.</p>
    {% endif %}
  </div>
</div>
