Ona godzinami leży, myśląc o nim.

English Translation

She lay awake for hours thinking about him.

Godzina is used in the plural instrumental, godzinami, to mean “for hours”. It gives an impression of a vague, not exact time period.
Compare a more precise time period: She lay for two hours, which would be “Ona leżała przez dwie godziny”, which is in the accusative as governed by przez.