Collective dynamics from stochastic thermodynamics