OK, on the schematic in post #144 (not 145, sorry), look at the bottom two diodes in the bridge rectifier. The two that are connected to CN1-1-2.
The left one will conduct if CN1-1-2 tries to go more negative than the 0V rail. The right one conduct if CN1-1-2 tries to go more postive than the +48V rail. Between the two of them, CN1-1-2 is clamped to be between about -0.7V and about +48.7V relative to the 0V rail.
So from the point of view of all the circuitry, which operates relative to the 0V rail, that point (CN1-1-2) alternates between those two voltages, at mains frequency. It is not a perfect square wave. Here's what it looks like in simulation.
View attachment 15551
R11 limits the current that can flow from that pin into the PIC, to prevent damage and misoperation, and C13 provides a bit of filtering in case there is some noise on the mains supply. Firmware should also perform basic filtering so that if transitions are detected on that input that are closer together than, say, 10 ms, they would be ignored.
That layout is looking better. You can still move components a lot closer together. Aligning THT resistors in the same direction will help with this. They can be spaced at 0.1" pitch.
I don't like the track from pin 7 of the left hand Allegro chip. It should be further inside the groundplane area, so it's protected from influence from the high-voltage area through capacitive coupling within the PCB and from creepage along the underside of the PCB.
It's looking good though!