First-principles theory of superconducting heterostructures