High-resolution imaging and inversion of 3D wavefield data for layered media