We develop a general theory of canonical bases for quantum symmetric pairs
(\mathbf{U}, \mathbf{U}^\imath) with parameters of arbitrary finite type. We
construct new canonical bases for the simple integrable U-modules
and their tensor products regarded as \mathbf{U}^\imath-modules. We also
construct a canonical basis for the modified form of the quantum group
\mathbf{U}^\imath. To that end, we establish several new structural results
on quantum symmetric pairs, such as bilinear forms, braid group actions,
integral forms, Levi subalgebras (of real rank one), and integrality of the
intertwiners.Comment: v1, 76 pages. v2, 62 pages, much shortened appendix, modified
introduction and other corrections, to appear in Invent. Mat