Theory of the anomalous skin effect in normal and superconducting metals