I don't know how the current market/marketing considerations would weigh in, because they seem to be changing all the time. But I'm going to give my two-bit spiel on sexuality and middle grade.
The reason I never thought of YA as belonging in kid-lit is exactly this matter. The pre-pubescent reader is decidedly different. Post puberty sexuality is another world.
In one of my MG manuscripts I hint at somewhat creepy behavior on the part of one adult, (any young adult or adult reader would recognize it as exploitative inappropriate sexual advance) but it is written as the sort of thing a kid would just think of as a wee-bit off, and creepy. In fact, for most MG readers it may very well go over their heads. Never described or named, and only there as a realistic detail explaining the motivation of another character's choices.
Personally, I would leave explicit pedophilia out of a MG. I also would not write in detail about doing tax returns while feeling lost in the long-form maze, or worrying about a job promotion because the boss is sleeping with another employee he might promote instead. These are part of older readers' world.
I know some kids experience pedophilia. But I don't think they have a way of entering the compulsive destructive mindset that propels it.
So as others said, it is a difficult matter.
As to cuss words, standards have changed a lot in recent years. I have a Beta reader who didn't like the word "heck" (the genteel "hell," which I also don't see as obscene as it is part of religious vocabulary IMO) and, conversely, I have friends who dislike the cleaned-up language in MG from years ago because it feels inauthentic. From what has been published in the last five plus years in MG, I think the range has widened a lot.
I personally do not use four-letter words in my real life speech. Never have. I'm not enamored of adult books that are littered with such words. But if you listen to real life eight to twelve year olds' speech and find that it fits there, I would defend your right to use it and would not be squeamish about it. I'd only ask that it be needed and not used for shock effect to rattle readers.
If you have an agent, ask for their opinion, too. Many professional hoops to get through, and they all matter.