First-order thermodynamics of scalar-tensor cosmology