{# Live-state partial — HTMX-polled into the state cluster on server_detail.html.
   The parent .state-cluster section provides the heading context, so there is
   no <h2> here. Current players have no sub-header; they sit directly under
   the summary line. Recent players' header is "N Recent" and doubles as the
   modal trigger when N > 10. #}

{% if not snapshot or not snapshot_fresh %}
  <p class="muted">No data — server is not currently reporting.</p>
{% else %}
  <p class="server-live-summary">
    {{ snapshot.players }}/{{ snapshot.max_players }}
    {% if snapshot.hibernating %}· idle{% endif %}
    · {{ snapshot.map }}
    <small class="muted">polled {{ snapshot.last_seen_at | timeago }}</small>
  </p>
{% endif %}

{% if current_players %}
  <ul class="player-grid current">
    {% for session, profile in current_players %}
      {% set display_name = (profile and profile.persona_name) or session.name_at_join %}
      <li class="player-card current-card">
        <a class="player-link"
           href="https://steamcommunity.com/profiles/{{ session.steam_id_64 }}"
           target="_blank" rel="noopener noreferrer">
          {% if profile and profile.avatar_url %}
            <img class="avatar" src="{{ profile.avatar_url }}" alt="">
          {% else %}
            <span class="avatar placeholder" aria-hidden="true"></span>
          {% endif %}
          <span class="name" title="{{ display_name }}">{{ display_name }}</span>
        </a>
        <span class="meta">
          {{ session.joined_at | timeago }} · {{ session.min_ping }}-{{ session.max_ping }}ms
        </span>
      </li>
    {% endfor %}
  </ul>
{% endif %}

{% if recent_players_overview %}
  <h3 class="recent-header">
    {% if recent_players_total_count > 10 %}
      <button type="button" class="recent-header-trigger"
              data-inline-modal-open="recent-players-modal">
        {{ recent_players_total_count }} Recent
      </button>
    {% else %}
      {{ recent_players_total_count }} Recent
    {% endif %}
  </h3>
  <ul class="player-grid recent">
    {% for row in recent_players_overview %}
      {% set display_name = row.persona_name or row.name_at_join %}
      <li class="player-card recent-chip">
        <a class="player-link"
           href="https://steamcommunity.com/profiles/{{ row.steam_id_64 }}"
           target="_blank" rel="noopener noreferrer">
          {% if row.avatar_url %}
            <img class="avatar" src="{{ row.avatar_url }}" alt="">
          {% else %}
            <span class="avatar placeholder" aria-hidden="true"></span>
          {% endif %}
          <span class="name" title="{{ display_name }}">{{ display_name }}</span>
        </a>
        <span class="meta">· {{ row.last_seen | timeago }}</span>
      </li>
    {% endfor %}
  </ul>
{% endif %}
