In perfect competition, why is there economic loss if marginal cost > marginal revenue? Here's a graph for reference:


In the left graph, I read from a book (CFA L1 notes) that


  At any output above the quantity where $MR = MC$, the firm will be generating losses on its marginal production and will maximize profits by reducing output to where $MR = MC$."


But now consider this:



$Q'$ is an output level above the one at which $MC=MR$. Shouldn't the yellow region represent a positive economic profit in this case? I can understand that at any output level above the one at which $ATC=MR$, the firm would start making losses. But isn't the quote above incorrect, or am I missing something? Sure, you might be making a suboptimal profit at output $= Q’$, but you’re certainly not making an outright loss.
There is no loss at Q' and you are indeed right that the yellow area represents the firm profits. However, if you were to compare the yellow area to the blue area you would find that the latter is greater. So profit for the firm is not optimal at Q' but is optimal at Q*. This is what the quote refers to, it says the firm will be generating losses on its marginal production (so on the quantity Q' - Q*). It does not say that the firm will generate losses on production in general. This will only happen beyond MR=ATC or TC=TR