A Generalizable and Privacy-Preserving Framework for Anomaly Detection in Heterogeneous IoT Environments