Optimal Lipschitz criteria and local estimates for nonuniformly elliptic problems