Optical gain and loss in nanophotonics