We are sorry to hear of your miscarriage and your hard feelings.
Based on what you write, your actions prior to relations were in line with your rav's halachic rulings. Since it was likely larger than a
gris, the
stain on the mat did make you
niddah, and the two of you acted accordingly. Since it was found after you had gotten up from relations, the stain does
not halachically establish that you were
niddah during relations.
In other words, you were not
niddah during relations, so you need not perform
teshuvah for that prohibition. (You were neither
b'shogeg (inadvertent) nor
b'meizid (deliberate).) There are no grounds to see your miscarriage as punishment here.
Acts of
teshuvah, such as
tefillah and
tzedakah, are always valued. In general, we do recommend that women
abstain from relations when staining, as a precaution against close calls such as these. You should not feel bad about being unaware of this type of recommendation, as it is not strictly required by halachah.
We hope this helps you move forward. Please write back with any further questions.