# ── Table view ─────────────────────────────

  log::section "WireGuard Clients"
  cmd::list::_render_header $has_groups

  for conf in "${dir}"/*.conf; do
    [[ -f "$conf" ]] || continue

    local client_name
    client_name=$(basename "$conf" .conf)

    local ip="${p_ips[$client_name]:-}"
    if [[ -z "$ip" ]]; then
      # Fallback for peers not in precomputed data
      ip=$(grep "^Address" "$conf" | awk '{print $3}' | cut -d'/' -f1)
    fi

    local ip="${p_ips[$client_name]}"
    local type
    type=$(cmd::list::_get_type "$ip")

    [[ -n "$filter_type" && "$type" != "$filter_type" ]] && continue

    local pubkey="${p_pubkeys[$client_name]:-}"
    local handshake_ts="${wg_handshakes[$pubkey]:-0}"
    local is_blocked="${p_blocked[$client_name]:-false}"
    local is_restricted="${p_restricted[$client_name]:-false}"
    local last_ts="${p_last_ts[$client_name]:-}"

    # Filters
    if $online_only; then
      cmd::list::_is_connected "$handshake_ts" || continue
    fi
    if $offline_only; then
      cmd::list::_is_connected "$handshake_ts" && continue
    fi
    if $restricted_only && [[ "$is_restricted" != "true" ]]; then
      continue
    fi
    if $blocked_only && [[ "$is_blocked" != "true" ]]; then
      continue
    fi
    if $allowed_only && { [[ "$is_blocked" == "true" ]] || [[ "$is_restricted" == "true" ]]; }; then
      continue
    fi

    local status last_seen display_type rule group_display
    status=$(cmd::list::_format_status "$client_name" "$pubkey" \
      "$is_blocked" "$is_restricted" "$handshake_ts" "$last_ts")
    last_seen=$(cmd::list::_format_last_seen "$client_name" "$pubkey" \
      "$is_blocked" "$last_ts" "" "$handshake_ts")
    display_type=$(cmd::list::display_type "$client_name" "$type" "${p_subtypes[$client_name]:-}")
    rule="${p_rules[$client_name]:-—}"

    local padded_status
    padded_status=$(cmd::list::pad_status "$status" 25)

    if $has_groups; then
      group_display="${peer_group_map[$client_name]:-—}"
      local rule_col_width=12 group_col_width=12
      [[ "$rule" == "—" ]] && rule_col_width=14
      [[ "$group_display" == "—" ]] && group_col_width=14
      printf "  %-28s %-15s %-13s %-${rule_col_width}s %-${group_col_width}s %s %s\n" \
        "$client_name" "$ip" "$display_type" "$rule" \
        "$group_display" "$padded_status" "$last_seen"
    else
      local rule_col_width=12
      [[ "$rule" == "—" ]] && rule_col_width=14
      printf "  %-28s %-15s %-13s %-${rule_col_width}s %s %s\n" \
        "$client_name" "$ip" "$display_type" "$rule" \
        "$padded_status" "$last_seen"
    fi
  done

  cmd::list::_render_footer $has_groups

  # Group summary
  local group_summary=""
  if $has_groups; then
    declare -A group_counts
    for peer in "${!peer_group_map[@]}"; do
      local g="${peer_group_map[$peer]}"
      group_counts["$g"]=$(( ${group_counts["$g"]:-0} + 1 )) || true
    done
    for g in "${!group_counts[@]}"; do
      group_summary+="${group_counts[$g]} in ${g}, "
    done
    group_summary="${group_summary%, }"
  fi

    declare -A rule_counts
    for name in "${!p_rules[@]}"; do
      local r="${p_rules[$name]}"
      rule_counts["$r"]=$(( ${rule_counts["$r"]:-0} + 1 )) || true
    done
    cmd::list::_render_summary "$group_summary" rule_counts