Superconducting pairing mediated by spin fluctuations from first principles