Where is it brought down that one should wait after going to the bathroom and before having relations. I have heard this before and 2 reasons given. One is that because of the "ruach rah" in the bathroom that (I guess?) "attaches" itself to the private parts of ones body and therefore should avoid relations until a certain amount of time has past (next question.) And the other reason is because some sort of danger if the urine mixes together with semen. What are the sources for both reasons (if the 2nd one which I only heard once is valid.)

As well how much time is it that one should wait?

And is the only problem the "actual" relations or even the time the couple will spend together before hand.

The Rabbis taught: On coming from a privy a man should not have sexual
intercourse till he has waited long enough to walk half a mil, because
the demon of the privy is With him for that time; if he does, his
children will be epileptic.

Regarding the amount of time mentioned - 'half a mil' -

S"A 459:2 writes that the mil is 18 minutes. Rama 261:1 agrees. Biur
Halacha 459:2 s.v. Haviy quotes some who consider it 22.5 minutes and
others who say that it is 24 minutes. see here

...so that makes half a mil at least 9 minutes.

See also Mishna Brurah Siman 240 S.K. 54 who brings the above Gemara and adds
that the Gemara is only referring to a permanent bathroom [ie one with a seat] and not a temporary one.