Self-consistent theory of the quiet magnetotail in three dimensions