Magnetism in transition-metal-doped ZnO: A first-principles study