Claire Foy feared a stalker would kill her and her daughter and is still struggling to sleep, a court has heard.