Optimal design problems in thin-film and diffractive optics