Text this: Gauge invariant quantum thermodynamics: foundations and applications to critical systems