Geometric principles of second messenger dynamics in dendritic spines