Use a monotonic increasing stack (smallest on bottom). Store indices. When you encounter a bar shorter than the stack top, the top bar can't extend further right.
Pop it and calculate its area. The left boundary is the new stack top (or if empty). The right boundary is the current index minus one.
After processing all bars, pop remaining elements. Their right boundary is (they extend to the end).