Almost-complex and almost-product Einstein manifolds from a variational principle