Work statistics and thermal phase transitions.