Trace inequalities for Carnot-Carathéodory spaces and applications