Could be blocked sunroof drains, rarely mentioned, but affects the e8x 1 series quite often, so stands to reason it would do the same to the e9x's, particularly if you car has lived outside or in dusty areas in its life.
I would suggest opening the sunroof fully, zip-tie-ing a hose pipe to the drains under the car (under the covers behind the jackpads) and opening the tap slowly, and back flushing the full system, and cleaning up all the water and gunk with a large drying towel/micorfibre or dishcloth(s)
The dirt in the undercar drains tends to clog up them up over time, not allowing the sunroof to drain, eventually the water level rises to a point where it finds empty screw holes and slots where it drips onto the top of the headliner, and then rolls its way down with gravity, usually behind the A-pillar and into the footwell, but also the visors (this can manifest as wet carpets after rain or washing the car, but dry generally everywhere else).
Can be done alone, but preferably a 2 man job. Don't try and unblock the drains from the sunroof with a stoker, you will most likely pop the drains off the sunroof nipples/drain fittings, and water will then leak directly into your car.
zip tie the gutters on the sunroof afterwards for good measure and future-proofing.