Phase transitions at the nanoscale: wetting of nanoporous materials, cluster formation, and nanofriction