Magnesium citrate
Magnesium citrate is magnesium bound to citric acid, a well-absorbed oral form of an essential mineral. Magnesium is a cofactor for hundreds of enzymes and dampens nerve and muscle excitability, which is why it is used for muscle cramps and spasm, for sleep support, and to correct low magnesium.
It is taken with food to soften the effect on the stomach, and in the evening, which suits both the sleep and the cramp indications. Unabsorbed magnesium draws water into the bowel, so looser stools are the usual sign that the gut has had more than it can take up. Magnesium also binds several drugs in the gut and blocks their absorption, notably levothyroxine, the antibiotics doxycycline and ciprofloxacin, and gabapentin, whose uptake is reduced the same way, so a gap of a couple of hours from other medicines is the standard precaution. Blood magnesium is the marker used to check the picture, though it reflects stores only roughly.
Diarrhoea that does not settle, or ongoing cramps and palpitations despite supplementation, should be assessed rather than managed by trial and error. Anyone with reduced kidney function needs a doctor's view before taking magnesium at all, since the kidneys are what clear it.
Reference information, not medical advice. Discuss any change with your doctor.