document.addEventListener("DOMContentLoaded", () => {
  const sidebar = document.getElementById("sidebar");
  const role = localStorage.getItem("user_role");

  if (!sidebar || !role) return;

  MENU_CONFIG.forEach(section => {
    if (!section.roles.includes(role)) return;

    const sectionDiv = document.createElement("div");
    sectionDiv.className = "menu-section";

    const title = document.createElement("h4");
    title.textContent = section.section;
    sectionDiv.appendChild(title);

    section.items.forEach(item => {
      const link = document.createElement("a");
      link.href = item.page;
      link.className = "menu-item";
      link.innerHTML = `<span class="icon">${item.icon}</span> ${item.label}`;
      sectionDiv.appendChild(link);
    });

    sidebar.appendChild(sectionDiv);
  });
});
