We appreciate your concern for halachah.
As it happens, your questions about the nature of shekiah get to the core of the issue. From the Talmud onward, there have been discussion and debate about how properly to define shekiat hachamah. So, for example, both R Moshe Feinstein and R Ovadia Yosef take differing possible conceptions of shekiah into account in formulating grounds for leniency in pressing situations for minutes past shekiah.
In addition to questions about shekiah as a possible ground for leniency, there are grounds to argue that the hefsek taharah need only be inserted by shekiah, not completed by then. Further, as you note, calendars are not exact for every exact location, nor are clocks.
Thus, in a situation such as yours, where the hefsek taharah was within seconds of the calculated shekiah time, there is a strong basis for leniency, such as we expressed. Such a leniency is usually not relied on if a woman has just made a failed attempt at a hefsek taharah, which calls into greater question her status at shekiah.
As we further noted, you should take every precaution to avoid this type of situation in the future.
For discussion, including many relevant citations, see R Ovadia Yosef's Taharat HaBayit 2:13. A look at popular niddah manuals should turn up instructions to ask a halachic question in cases such as yours.
Please write with any further questions.