Mine did that last spring; I used Goop Automotive glue to stick it back. That didn't water seal it though, so I had to get a clear water seal chaulk and put a bead on the lower seal. It doesn't look too good, but it keeps the rain out. I called around and 1 shop wanted $500 to reseal it.
I lifted the top partially to glue it back on while it wasn't under tension, the glue is on both sides, and you'll have to unzip the headliner to gain access to the interior side.
Best of luck.