Existing deep learning models for flood forecasting face challenges of performance decay when dealing with long-term dependencies and a lack of physical constraints. To address these issues, this study proposes a flood forecasting framework, Hydro-S4D, which integrates a structured state space model (S4D) with a novel hydrology-specific loss function(HydroLoss). The framework leverages the S4D model’s capability to efficiently capture long-term dependencies, and proposes a customized composite loss function HydroLoss. This function integrates weighted MSE, trend consistency, peak attention, and phase correction to embed physical hydrological constraints into the model training process. Application to a typical hydrological station in the Pearl River Delta demonstrates that the framework significantly improves forecast accuracy, achieving a Nash-Sutcliffe efficiency (NSE) of 0.9 for 1-day lead time and maintaining it at approximately 0.6 for 7-day lead time. The proposed model outperforms benchmark models, such as the long short-term memory (LSTM) network, in fitting flood peaks, preserving hydrograph shapes, and providing balanced uncertainty quantification, thereby addressing their overconfidence or underconfidence issues. The results show that integrating advanced sequence models with domain-aware loss functions is an effective approach to enhancing the accuracy and reliability of medium- and long-term flood forecasts. The proposed Hydro-S4D framework imparts great physical realism and practical value to data-driven hydrological models.