Do you drink any caffeine at all?
I used to think (or I believe was told), that two cups and no more before noon is ok, but found my sleep was just an utter mess. I tried everything , sleep test, black out curtains, magnesium, CBD oil, melatonin, yet it never occurred to me it could be coffee as I never drank it outside of the morning.
I cut out caffeine completely. Had a horrible withdrawal; headache from hell, back ache , neck ache, everything ache, but then around day 6 or 7 I did something I had not done in years - slept all night AND had a vivid dream (showing I was in deep REM sleep).