// --- Basic Todo Model --- const STORAGE_KEY = 'todos-v1'; const CATEGORY_KEY = 'todo-categories'; window.todos = window.todos || []; window.categories = window.categories || []; // For backward compatibility, assign to local variables as references let todos = window.todos; let categories = window.categories; function loadTodos() { todos = JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]'); categories = JSON.parse(localStorage.getItem(CATEGORY_KEY) || '[]'); } function saveTodos() { localStorage.setItem(STORAGE_KEY, JSON.stringify(todos)); localStorage.setItem(CATEGORY_KEY, JSON.stringify(categories)); } function getNextId() { return todos.length ? Math.max(...todos.map(t => t.id)) + 1 : 1; } function renderForm() { const form = document.getElementById('todo-form'); form.innerHTML = `
`; // Autocomplete for categories const datalist = document.getElementById('category-list'); datalist.innerHTML = categories.map(cat => `