(function () { const state = { items: [], draft: null, imageTarget: -1 }; function el(id) { return document.getElementById(id); } function a(s) { return esc(String(s == null ? '' : s)).replace(/"/g, '"'); } function canManage(s) { if (!s || typeof currentUser === 'undefined' || !currentUser) return false; if (currentUser.role === 'admin') return true; return s.created_by != null && Number(s.created_by) === Number(currentUser.id); } function isAdmin() { return typeof currentUser !== 'undefined' && !!currentUser && currentUser.role === 'admin'; } function openModal(id) { const node = el(id); if (node) node.classList.add('open'); } function closeModal(id) { const node = el(id); if (node) node.classList.remove('open'); } function showList() { el('qsEditorView').hidden = true; el('qsListView').hidden = false; } function showEditor() { el('qsListView').hidden = true; el('qsEditorView').hidden = false; } async function fetchScales() { const res = await fetch(API + '/api/grade-scales', { headers: hdr() }); const data = await res.json().catch(() => ({})); if (!res.ok) throw new Error(data.error || 'Не удалось загрузить критерии'); state.items = Array.isArray(data.items) ? data.items : []; } function renderList() { const list = el('qsList'); if (!state.items.length) { list.innerHTML = '