Hall algebras and quantum symmetric pairs I: foundations