Advanced persistent threats (APT) are a challenging threat in cybersecurity because of their stealth, persistence, and adaptation to evade traditional detection systems. To tackle this issue, we put forward an optimized deep learning approach that combines a Convolutional Neural Network-Long Short-Term Memory (CNN-LSTM) architecture with the lime mold algorithm (SMA) for better APT detection. During training, the SMA balances exploration and exploitation well, leading to faster convergence and better performance. The SMA-optimized CNN-LSTM was evaluated on the Unraveled dataset, a benchmark for network intrusion detection, with 94.3% accuracy and precision, recall, and F1 scores of 92.8%, 93.5%, and 93.1%, respectively. Furthermore, the model had a false positive rate of 2% and a false negative rate of 3% and was thus more able to detect. Scalability tests confirmed the model's efficiency at handling high traffic, with distributed training processing 50,000 records/s and reducing training time by 35% over single-node setups. These results show that combining novel optimization techniques with deep learning is an effective approach for APT detection. The proposed framework is robust, scalable, and efficient, and it significantly advances real-time APT detection and improves the resilience of critical cybersecurity infrastructures.