@sharif32 A meio da noite (no accent on the A) does mean “In the middle of the night” The A is not a definite article here, but a preposition, which is why “a meio de” is acceptable as an idiom and doesn’t contradict any rules of gender agreement.
So, we can say both “A meio da noite” and “No meio da noite” with identical meaning (but in the second case, we do have a definite article there, since no = em + o). Both expressions sound natural.
Also, about when to use meio or meia, here’s an explanation: Meia ou metade ? When to use - #2 by Joseph