We show that all Lindblad operators (i.e. generators of quantum semigroups) on a finite-dimensional Hilbert space satisfying the detailed balance condition with respect to the thermal equilibrium state can be written as a gradient system with respect to the relative entropy. We discuss also thermodynamically consistent couplings to macroscopic systems, either as damped Hamiltonian systems with constant temperature or as GENERIC systems. In particular we discuss the coupling of a quantum dot coupled to macroscopic charge carriers.