  Motivated by the problem of the residual surface resistance of the
superconducting radio-frequency (SRF) cavities, we develop a microscopic theory
of the surface impedance of s-wave superconductors with magnetic impurities. We
analytically calculate the current response function and surface impedance for
a sample with spatially uniform distribution of impurities, treating magnetic
impurities in the framework of the Shiba theory. The obtained general
expressions hold in a wide range of parameter values, such as temperature,
frequency, mean free path, and exchange coupling strength. This generality, on
the one hand, allows for direct numerical implementation of our results to
describe experimental systems (SRF cavities, superconducting qubits) under
various practically relevant conditions. On the other hand, explicit analytical
expressions can be obtained in a number of limiting cases, which makes possible
further theoretical investigation of certain regimes. As a feature of key
relevance to SRF cavities, we show that in the regime of "gapless
superconductivity" the surface resistance exhibits saturation at zero
temperature. Our theory thus explicitly demonstrates that magnetic impurities,
presumably contained in the oxide surface layer of the SRF cavities, provide a
microscopic mechanism for the residual resistance.
