  Starting from a microscopic system-baths description, we derive the general
conditions for a time-local quantum master equation (QME) to satisfy the first
and second law of thermodynamics at the fluctuating level. Using counting
statistics, we show that the fluctuating second law can be rephrased as a
Generalized Quantum Detailed Balance condition (GQDB), i.e., a symmetry of the
time-local generators which ensures the validity of the fluctuation theorem.
When requiring in addition a strict system-bath energy conservation, the GQDB
reduces to the usual notion of detailed balance which ensures QMEs with
Gibbsian steady states. However, if energy conservation is only required on
average, QMEs with non Gibbsian steady states can still maintain a certain
level of thermodynamic consistency. Applying our theory to commonly used QMEs,
we show that the Redfield equation breaks the GQDB, and that some recently
derived approximation schemes based on the Redfield equation (which hold beyond
the secular approximation and allow to derive a QME of Lindblad form) satisfy
the GQDB and the average first law. We find that performing the secular
approximation is the only way to ensure the first and second law at the
fluctuating level.
