           },
                            body: JSON.stringify(payload),
                        });

                        if (!response.ok) {
                             // Try to read error message from backend if it's JSON
                             let errorMsg = `Network response was not ok (Status: ${response.status})`;
                             try {
                                 const errData = await response.json();
                                 errorMsg = errData.msg || errData.deta