Magnetic confinement, Alfven wave reflection, and the origins of X-ray and mass-loss 'dividing lines' for late-type giants and supergiants