type JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue }; export function getLocalStorage(key: string, fallback: T): T { if (typeof window === 'undefined') return fallback; try { const raw = window.localStorage.getItem(key); if (!raw) return fallback; return JSON.parse(raw) as T; } catch { return fallback; } } export function setLocalStorage(key: string, value: T): void { if (typeof window === 'undefined') return; try { window.localStorage.setItem(key, JSON.stringify(value)); } catch { // Ignore write failures (storage full, blocked, etc.) } } export function removeLocalStorage(key: string): void { if (typeof window === 'undefined') return; try { window.localStorage.removeItem(key); } catch { // Ignore removal failures. } }