local API = rawget(_G, "LIDCOUNCIL_API")
local INTERNAL_API = type(API) == "table" and type(API.__internal) == "table" and API.__internal or nil
if type(INTERNAL_API) ~= "table" then
  error("LidCouncil missing internal API registry.")
end

local shared = INTERNAL_API.LIDCOUNCIL_LootEditorShared_Impl
if type(shared) ~= "table" then
  error("LidCouncil missing loot editor shared helpers.")
end

local BindMouseWheelScroll = shared.BindMouseWheelScroll
local ApplyFrameSkin = shared.ApplyFrameSkin
local MakeYellowSubHeader = shared.MakeYellowSubHeader
local CreateCustomDropdownControl = shared.CreateCustomDropdownControl
local CreateSimpleEditBox = shared.CreateSimpleEditBox
local CreateSectionShell = shared.CreateSectionShell
local EnsureLidTableEditorRows = shared.EnsureLidTableEditorRows

local function CreateRollColumnHeader(parent, text)
  local header = parent:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
  header:SetJustifyH("LEFT")
  header:SetText(tostring(text or ""))
  return header
end

local function CreateProfileTabButton(parent, labelText)
  local button = CreateFrame("Button", nil, parent, "UIPanelButtonTemplate")
  button:SetSize(180, 28)
  button.baseLabel = tostring(labelText or "")
  button:SetText(button.baseLabel)
  button.__lid_customBg = { 0.04, 0.06, 0.09, 0.74 }
  button.__lid_customHover = { 0.20, 0.42, 0.68, 0.20 }
  button.__lid_customPushed = { 0.12, 0.19, 0.28, 0.94 }
  button.__lid_customBorder = { 0.28, 0.42, 0.60, 0.42 }
  button.__lid_customText = { 0.86, 0.90, 0.96, 1.00 }
  button.activeFill = button:CreateTexture(nil, "ARTWORK", nil, -1)
  button.activeFill:SetAllPoints(button)
  button.activeFill:SetColorTexture(0.12, 0.20, 0.31, 0.74)
  button.activeFill:Hide()
  button.activeLine = button:CreateTexture(nil, "OVERLAY")
  button.activeLine:SetColorTexture(1.00, 0.82, 0.24, 0.95)
  button.activeLine:SetHeight(3)
  button.activeLine:SetPoint("BOTTOMLEFT", 5, 1)
  button.activeLine:SetPoint("BOTTOMRIGHT", -5, 1)
  button.activeLine:Hide()
  return button
end

local function CreateProfileStatCard(parent, title, detail)
  local card = CreateFrame("Frame", nil, parent)
  card:SetSize(128, 54)
  card:EnableMouse(true)
  card.__lidTooltipTitle = tostring(title or "")
  card.__lidTooltipDetail = tostring(detail or "")
  card:SetScript("OnEnter", function(self)
    if not GameTooltip then
      return
    end
    GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
    GameTooltip:SetText(self.__lidTooltipTitle, 1.00, 0.82, 0.28, 1.00, true)
    if self.__lidTooltipDetail ~= "" then
      GameTooltip:AddLine(self.__lidTooltipDetail, 0.92, 0.92, 0.96, true)
    end
    GameTooltip:Show()
  end)
  card:SetScript("OnLeave", function()
    if GameTooltip then
      GameTooltip:Hide()
    end
  end)

  local valueText = card:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
  valueText:SetPoint("TOPLEFT", 10, -8)
  valueText:SetJustifyH("LEFT")
  valueText:SetText("0")

  local titleText = card:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  titleText:SetPoint("TOPLEFT", valueText, "BOTTOMLEFT", 0, -4)
  titleText:SetPoint("RIGHT", -8, 0)
  titleText:SetJustifyH("LEFT")
  titleText:SetText(tostring(title or ""))

  return {
    frame = card,
    value = valueText,
    title = titleText,
  }
end

local function ApplyProfileActionAccent(button, accent)
  if not button then
    return
  end
  if accent == "create" then
    button.__lid_customBg = { 0.05, 0.22, 0.12, 0.96 }
    button.__lid_customHover = { 0.22, 0.82, 0.42, 0.22 }
    button.__lid_customPushed = { 0.08, 0.32, 0.16, 0.98 }
    button.__lid_customBorder = { 0.24, 0.82, 0.38, 0.96 }
    button.__lid_customText = { 0.92, 1.00, 0.92, 1.00 }
  else
    button.__lid_customBg = { 0.26, 0.07, 0.07, 0.96 }
    button.__lid_customHover = { 0.92, 0.30, 0.30, 0.22 }
    button.__lid_customPushed = { 0.40, 0.10, 0.10, 0.98 }
    button.__lid_customBorder = { 0.92, 0.36, 0.36, 0.96 }
    button.__lid_customText = { 1.00, 0.92, 0.92, 1.00 }
  end
end

local function AttachProfileActionTooltip(button, title, detail)
  if not button then
    return
  end
  button.__lidTooltipTitle = tostring(title or "")
  button.__lidTooltipDetail = tostring(detail or "")
  button:SetScript("OnEnter", function(self)
    if not GameTooltip then
      return
    end
    GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
    GameTooltip:SetText(self.__lidTooltipTitle, 1.00, 0.82, 0.28, 1.00, true)
    if self.__lidTooltipDetail ~= "" then
      GameTooltip:AddLine(self.__lidTooltipDetail, 0.92, 0.92, 0.96, true)
    end
    GameTooltip:Show()
  end)
  button:SetScript("OnLeave", function()
    if GameTooltip then
      GameTooltip:Hide()
    end
  end)
end

local function ApplyProfileUtilityActionStyle(button, variant)
  if not button then
    return
  end
  if variant == "delete" then
    button.__lid_customBg = { 0.18, 0.07, 0.07, 0.94 }
    button.__lid_customHover = { 0.62, 0.18, 0.18, 0.30 }
    button.__lid_customPushed = { 0.30, 0.08, 0.08, 0.98 }
    button.__lid_customBorder = { 0.84, 0.32, 0.32, 0.90 }
    button.__lid_customText = { 1.00, 0.72, 0.68, 1.00 }
  elseif variant == "remove" or variant == "restore" then
    button.__lid_customBg = { 0.14, 0.10, 0.04, 0.94 }
    button.__lid_customHover = { 0.48, 0.34, 0.10, 0.28 }
    button.__lid_customPushed = { 0.26, 0.18, 0.05, 0.98 }
    button.__lid_customBorder = { 0.78, 0.58, 0.22, 0.90 }
    button.__lid_customText = { 1.00, 0.86, 0.52, 1.00 }
  elseif variant == "utility" then
    button.__lid_customBg = { 0.07, 0.09, 0.12, 0.94 }
    button.__lid_customHover = { 0.18, 0.28, 0.40, 0.26 }
    button.__lid_customPushed = { 0.10, 0.16, 0.24, 0.98 }
    button.__lid_customBorder = { 0.38, 0.49, 0.62, 0.74 }
    button.__lid_customText = { 0.88, 0.92, 0.98, 1.00 }
  else
    button.__lid_customBg = { 0.05, 0.12, 0.20, 0.96 }
    button.__lid_customHover = { 0.16, 0.38, 0.66, 0.24 }
    button.__lid_customPushed = { 0.08, 0.20, 0.34, 0.98 }
    button.__lid_customBorder = { 0.34, 0.62, 0.92, 0.92 }
    button.__lid_customText = { 0.92, 0.96, 1.00, 1.00 }
  end
end

local function ApplyProfileUtilityDropdownStyle(dropdown)
  if not dropdown then
    return
  end
  dropdown.__lid_themeOverride = {
    active = { 0.36, 0.58, 0.86, 0.92 },
    border = { 0.38, 0.49, 0.62, 0.82 },
    text = { 0.88, 0.92, 0.98, 1.00 },
    dropdownButtonBg = { 0.07, 0.09, 0.12, 0.94 },
    dropdownPopupBg = { 0.05, 0.07, 0.10, 0.98 },
    dropdownCheckedText = { 0.92, 0.96, 1.00, 1.00 },
    dropdownTitleText = { 0.78, 0.84, 0.94, 1.00 },
  }
end

local function CreateDropdownControl(editor, parent, width, text)
  if type(CreateCustomDropdownControl) == "function" then
    return CreateCustomDropdownControl(editor, parent, {
      width = width,
      buttonHeight = 24,
      text = text,
    })
  end
  return CreateSimpleEditBox(parent, width, 22)
end

local function BuildLootProfilesPageScaffold(editor, page)
  if not editor or not page then
    return
  end

  local navBg, rightBg = CreateSectionShell(page, 240)
  editor.lootProfilesNavBg = navBg
  editor.lootProfilesRightBg = rightBg
  -- The persistent header bar already identifies the enabled profile. Keeping
  -- a second "Current Profile" line directly under the Profile page title is
  -- redundant and crowds the page hierarchy.
  if editor.profilesCurrentLabel then
    editor.profilesCurrentLabel:Hide()
  end

  local navTitle = navBg:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
  navTitle:SetPoint("TOPLEFT", 8, -8)
  navTitle:SetText("Profiles")
  editor.lootProfilesNavTitle = navTitle

  local listScroll = CreateFrame("ScrollFrame", nil, navBg, "UIPanelScrollFrameTemplate")
  listScroll:SetPoint("TOPLEFT", 8, -32)
  listScroll:SetPoint("BOTTOMRIGHT", -26, 138)
  BindMouseWheelScroll(listScroll, 18)
  editor.lootProfilesListScroll = listScroll

  local listContent = CreateFrame("Frame", nil, listScroll)
  listContent:SetSize(208, 1)
  listScroll:SetScrollChild(listContent)
  editor.lootProfilesListContent = listContent
  editor.lootProfileButtons = {}

  local prevBtn = CreateFrame("Button", nil, navBg, "UIPanelButtonTemplate")
  prevBtn:SetSize(60, 20)
  prevBtn:SetPoint("BOTTOMLEFT", 8, 112)
  prevBtn:SetText("< Prev")
  editor.lootProfilesPrevBtn = prevBtn

  local nextBtn = CreateFrame("Button", nil, navBg, "UIPanelButtonTemplate")
  nextBtn:SetSize(60, 20)
  nextBtn:SetPoint("BOTTOMRIGHT", -8, 112)
  nextBtn:SetText("Next >")
  editor.lootProfilesNextBtn = nextBtn

  local pageText = navBg:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  pageText:SetPoint("LEFT", prevBtn, "RIGHT", 8, 0)
  pageText:SetPoint("RIGHT", nextBtn, "LEFT", -8, 0)
  pageText:SetJustifyH("CENTER")
  pageText:SetText("")
  editor.lootProfilesPageText = pageText

  local addGroupBtn = CreateFrame("Button", nil, navBg, "UIPanelButtonTemplate")
  addGroupBtn:SetSize(100, 22)
  addGroupBtn:SetPoint("BOTTOMLEFT", 8, 78)
  addGroupBtn:SetText("Create Group")
  ApplyProfileActionAccent(addGroupBtn, "create")
  AttachProfileActionTooltip(addGroupBtn, "Create Group", "Organize local profiles. Creating a group does not create a raider or session.")
  editor.lootAddGroupBtn = addGroupBtn

  local addProfileBtn = CreateFrame("Button", nil, navBg, "UIPanelButtonTemplate")
  addProfileBtn:SetSize(100, 22)
  addProfileBtn:SetPoint("LEFT", addGroupBtn, "RIGHT", 8, 0)
  addProfileBtn:SetText("Create Profile")
  ApplyProfileActionAccent(addProfileBtn, "create")
  AttachProfileActionTooltip(addProfileBtn, "Create Profile", "Create a raid-season profile. It remains inactive until you activate it.")
  editor.lootAddProfileBtn = addProfileBtn

  local deleteGroupBtn = CreateFrame("Button", nil, navBg, "UIPanelButtonTemplate")
  deleteGroupBtn:SetSize(100, 22)
  deleteGroupBtn:SetPoint("BOTTOMLEFT", 8, 48)
  deleteGroupBtn:SetText("Delete Group")
  ApplyProfileActionAccent(deleteGroupBtn, "delete")
  AttachProfileActionTooltip(deleteGroupBtn, "Delete Group", "Remove the selected group. Its profiles stay available and can be assigned to another group.")
  editor.lootDeleteGroupBtn = deleteGroupBtn

  local deleteBtn = CreateFrame("Button", nil, navBg, "UIPanelButtonTemplate")
  deleteBtn:SetSize(100, 22)
  deleteBtn:SetPoint("LEFT", deleteGroupBtn, "RIGHT", 8, 0)
  deleteBtn:SetText("Delete Profile")
  ApplyProfileActionAccent(deleteBtn, "delete")
  AttachProfileActionTooltip(deleteBtn, "Delete Profile", "Remove the selected local profile. Active profiles and profiles with running sessions cannot be deleted.")
  editor.lootDeleteProfileBtn = deleteBtn

  local feedback = navBg:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  feedback:SetPoint("BOTTOMLEFT", 8, 5)
  feedback:SetWidth(224)
  feedback:SetJustifyH("LEFT")
  if feedback.SetMaxLines then
    feedback:SetMaxLines(1)
  end
  feedback:SetText("")
  editor.lootProfilesFeedback = feedback

  local footerDivider = navBg:CreateTexture(nil, "ARTWORK")
  footerDivider:SetTexture("Interface\\Buttons\\WHITE8x8")
  footerDivider:SetPoint("BOTTOMLEFT", 8, 46)
  footerDivider:SetSize(224, 1)
  footerDivider:SetVertexColor(0.32, 0.38, 0.46, 0.68)
  editor.lootProfilesFooterDivider = footerDivider

  local actionHint = navBg:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  actionHint:SetPoint("BOTTOMLEFT", 8, 25)
  actionHint:SetWidth(224)
  actionHint:SetJustifyH("LEFT")
  actionHint:SetJustifyV("BOTTOM")
  if actionHint.SetMaxLines then
    actionHint:SetMaxLines(1)
  end
  actionHint:SetText("")
  editor.lootProfilesActionHint = actionHint

  local emptyState = CreateFrame("Frame", nil, rightBg, "BackdropTemplate")
  ApplyFrameSkin(emptyState)
  emptyState:SetPoint("TOPLEFT", 18, -18)
  emptyState:SetPoint("BOTTOMRIGHT", -18, 18)
  emptyState:Hide()
  editor.lootProfilesEmptyStateFrame = emptyState

  local emptyTitle = emptyState:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
  emptyTitle:SetPoint("TOPLEFT", 18, -18)
  emptyTitle:SetPoint("RIGHT", emptyState, "RIGHT", -18, 0)
  emptyTitle:SetJustifyH("LEFT")
  emptyTitle:SetText("No Profile selected")
  editor.lootProfilesEmptyStateTitle = emptyTitle

  local emptyText = emptyState:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
  emptyText:SetPoint("TOPLEFT", emptyTitle, "BOTTOMLEFT", 0, -12)
  emptyText:SetPoint("RIGHT", emptyState, "RIGHT", -18, 0)
  emptyText:SetJustifyH("LEFT")
  emptyText:SetJustifyV("TOP")
  emptyText:SetSpacing(4)
  emptyText:SetText(
    "Please create a new profile by pressing \"Create Profile\".\n\n" ..
    "A profile is made per season and will be used throughout the full raid season to collect Loot List points.\n\n" ..
    "When a season ends and a new season begins, create a new profile."
  )
  editor.lootProfilesEmptyStateText = emptyText

  local rightScroll = CreateFrame("ScrollFrame", nil, rightBg, "UIPanelScrollFrameTemplate")
  rightScroll:SetPoint("TOPLEFT", 6, -6)
  rightScroll:SetPoint("BOTTOMRIGHT", -28, 6)
  BindMouseWheelScroll(rightScroll, 18)
  editor.lootProfilesRightScroll = rightScroll

  local rightContent = CreateFrame("Frame", nil, rightScroll)
  rightContent:SetSize(1, 1)
  rightScroll:SetScrollChild(rightContent)
  editor.lootProfilesRightContent = rightContent

  local title = rightContent:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
  title:SetPoint("TOPLEFT", 18, -16)
  title:SetText("Profile Settings")
  editor.lootProfilesTitle = title

  local sizeFrame = CreateFrame("Frame", nil, rightContent)
  sizeFrame:SetSize(260, 18)
  sizeFrame:EnableMouse(true)
  sizeFrame:Hide()
  editor.lootProfileSizeFrame = sizeFrame

  local sizeText = sizeFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  sizeText:SetPoint("CENTER", sizeFrame, "CENTER", 0, 0)
  sizeText:SetJustifyH("CENTER")
  sizeText:SetText("")
  editor.lootProfileSizeText = sizeText

  sizeFrame:SetScript("OnEnter", function(self)
    if not GameTooltip then return end
    GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
    GameTooltip:SetText("Profile Size", 1, 0.82, 0.28, 1, true)
    local lines = type(self.__tooltipLines) == "table" and self.__tooltipLines or {}
    for _, line in ipairs(lines) do
      GameTooltip:AddLine(tostring(line), 0.92, 0.92, 0.96, true)
    end
    GameTooltip:Show()
  end)
  sizeFrame:SetScript("OnLeave", function()
    if GameTooltip then GameTooltip:Hide() end
  end)

  local status = rightContent:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
  status:SetPoint("TOPLEFT", 18, -44)
  status:SetText("Status: Inactive")
  editor.lootProfileStatus = status

  local statusDetail = rightContent:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  statusDetail:SetJustifyH("LEFT")
  statusDetail:SetText("")
  editor.lootProfileStatusDetail = statusDetail

  local summary = rightContent:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  summary:SetPoint("TOPLEFT", 18, -70)
  summary:SetWidth(520)
  summary:SetJustifyH("LEFT")
  summary:SetText("")
  editor.lootProfileSummary = summary

  local activateBtn = CreateFrame("Button", nil, rightContent, "UIPanelButtonTemplate")
  activateBtn:SetSize(110, 22)
  activateBtn:SetPoint("TOPLEFT", 18, -112)
  activateBtn:SetText("Activate")
  activateBtn.__lid_customBg = { 0.05, 0.22, 0.12, 0.96 }
  activateBtn.__lid_customHover = { 0.22, 0.82, 0.42, 0.22 }
  activateBtn.__lid_customPushed = { 0.08, 0.32, 0.16, 0.98 }
  activateBtn.__lid_customBorder = { 0.24, 0.82, 0.38, 0.96 }
  activateBtn.__lid_customText = { 0.92, 1.00, 0.92, 1.00 }
  editor.lootActivateProfileBtn = activateBtn

  local deactivateBtn = CreateFrame("Button", nil, rightContent, "UIPanelButtonTemplate")
  deactivateBtn:SetSize(110, 22)
  deactivateBtn:SetPoint("LEFT", activateBtn, "RIGHT", 10, 0)
  deactivateBtn:SetText("Deactivate")
  deactivateBtn.__lid_customBg = { 0.07, 0.08, 0.10, 0.92 }
  deactivateBtn.__lid_customHover = { 0.88, 0.62, 0.16, 0.26 }
  deactivateBtn.__lid_customPushed = { 0.34, 0.22, 0.06, 0.98 }
  deactivateBtn.__lid_customBorder = { 0.48, 0.44, 0.32, 0.74 }
  deactivateBtn.__lid_customText = { 0.88, 0.90, 0.94, 1.00 }
  editor.lootDeactivateProfileBtn = deactivateBtn

  local copyBtn = CreateFrame("Button", nil, rightContent, "UIPanelButtonTemplate")
  copyBtn:SetSize(110, 22)
  copyBtn:SetPoint("LEFT", deactivateBtn, "RIGHT", 10, 0)
  copyBtn:SetText("Copy Profile")
  copyBtn.__lid_customBg = { 0.05, 0.09, 0.16, 0.92 }
  copyBtn.__lid_customHover = { 0.22, 0.48, 0.82, 0.18 }
  copyBtn.__lid_customPushed = { 0.08, 0.16, 0.28, 0.98 }
  copyBtn.__lid_customBorder = { 0.34, 0.58, 0.90, 0.90 }
  copyBtn.__lid_customText = { 0.90, 0.96, 1.00, 1.00 }
  editor.lootCopyProfileBtn = copyBtn

  local clearSimulationBtn = CreateFrame("Button", nil, rightContent, "UIPanelButtonTemplate")
  clearSimulationBtn:SetSize(144, 22)
  clearSimulationBtn:SetText("Clear Content")
  clearSimulationBtn:Hide()
  editor.lootClearSimulationContentBtn = clearSimulationBtn

  local sectionFrameLevel = math.max((rightContent:GetFrameLevel() or 1) - 1, 0)

  local heroFrame = CreateFrame("Frame", nil, rightContent, "BackdropTemplate")
  ApplyFrameSkin(heroFrame)
  heroFrame:EnableMouse(false)
  heroFrame:SetFrameLevel(sectionFrameLevel)
  editor.lootProfileHeroFrame = heroFrame

  local statusDot = heroFrame:CreateTexture(nil, "ARTWORK")
  statusDot:SetSize(10, 10)
  statusDot:SetTexture("Interface\\Buttons\\WHITE8X8")
  editor.lootProfileStatusDot = statusDot

  local actionsHeader = rightContent:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  actionsHeader:SetJustifyH("LEFT")
  actionsHeader:SetText("Profile Actions")
  editor.lootProfileActionsHeader = actionsHeader

  editor.lootProfileHeroRaidPreviewFrame = CreateFrame("Frame", nil, heroFrame, "BackdropTemplate")
  ApplyFrameSkin(editor.lootProfileHeroRaidPreviewFrame)
  editor.lootProfileHeroRaidPreviewFrame:EnableMouse(false)
  if editor.lootProfileHeroRaidPreviewFrame.SetBackdropColor then
    editor.lootProfileHeroRaidPreviewFrame:SetBackdropColor(0, 0, 0, 0)
  end
  if editor.lootProfileHeroRaidPreviewFrame.SetBackdropBorderColor then
    editor.lootProfileHeroRaidPreviewFrame:SetBackdropBorderColor(0, 0, 0, 0)
  end

  editor.lootProfileHeroRaidPreviewTitle = editor.lootProfileHeroRaidPreviewFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  editor.lootProfileHeroRaidPreviewTitle:SetPoint("TOPLEFT", 10, -8)
  editor.lootProfileHeroRaidPreviewTitle:SetJustifyH("LEFT")
  editor.lootProfileHeroRaidPreviewTitle:SetText("Season and Raid")

  editor.lootProfileHeroRaidPreviewTexture = editor.lootProfileHeroRaidPreviewFrame:CreateTexture(nil, "ARTWORK")
  editor.lootProfileHeroRaidPreviewTexture:SetTexCoord(0, 1, 0, 1)
  editor.lootProfileHeroRaidPreviewTexture:SetVertexColor(1, 1, 1, 1)

  editor.lootProfileHeroRaidPreviewLabel = editor.lootProfileHeroRaidPreviewFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  editor.lootProfileHeroRaidPreviewLabel:SetJustifyH("LEFT")
  editor.lootProfileHeroRaidPreviewLabel:SetText("")

  editor.lootProfileHeroRaidPreviewEmpty = editor.lootProfileHeroRaidPreviewFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  editor.lootProfileHeroRaidPreviewEmpty:SetJustifyH("CENTER")
  editor.lootProfileHeroRaidPreviewEmpty:SetText("No profile-season raid selected.")

  editor.lootProfileHeroRaidPreviewButton = CreateFrame("Button", nil, editor.lootProfileHeroRaidPreviewFrame)
  editor.lootProfileHeroRaidPreviewButton:SetAllPoints(editor.lootProfileHeroRaidPreviewFrame)
  editor.lootProfileHeroRaidPreviewButton:EnableMouse(false)
  editor.lootProfileHeroRaidPreviewButton:Hide()

  local activityFrame = CreateFrame("Frame", nil, rightContent, "BackdropTemplate")
  ApplyFrameSkin(activityFrame)
  activityFrame:EnableMouse(false)
  editor.lootProfileActivityFrame = activityFrame

  local profileStatCards = {}
  local profileStatLabels = {
    { key = "sessions", title = "Sessions", detail = "Completed sessions saved for this profile." },
    { key = "items", title = "Items Awarded", detail = "Loot recorded in this profile outside simulations." },
    { key = "participants", title = "Participants", detail = "Unique raiders recorded after joining LidCouncil sessions." },
    { key = "rolls", title = "Roll Options", detail = "Roll choices currently configured for council-managed loot." },
  }
  for _, info in ipairs(profileStatLabels) do
    profileStatCards[info.key] = CreateProfileStatCard(rightContent, info.title, info.detail)
  end
  editor.lootProfileStatCards = profileStatCards

  local activityHeader = rightContent:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  activityHeader:SetJustifyH("LEFT")
  activityHeader:SetText("")
  editor.lootProfileActivityHeader = activityHeader

  editor.lootProfileStatDividers = {}
  for index = 1, 3 do
    local divider = rightContent:CreateTexture(nil, "OVERLAY")
    divider:SetColorTexture(0.82, 0.68, 0.30, 0.68)
    divider:SetSize(1, 36)
    divider:Hide()
    editor.lootProfileStatDividers[index] = divider
  end

  local membersFrame = CreateFrame("Frame", nil, rightContent, "BackdropTemplate")
  ApplyFrameSkin(membersFrame)
  membersFrame:EnableMouse(false)
  editor.lootProfileMembersFrame = membersFrame

  local membersHeader = membersFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  membersHeader:SetPoint("TOPLEFT", 12, -10)
  membersHeader:SetJustifyH("LEFT")
  membersHeader:SetText("Members & Roles")
  editor.lootProfileMembersHeader = membersHeader

  local membersActionHint = membersFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  membersActionHint:SetPoint("TOPRIGHT", -12, -10)
  membersActionHint:SetJustifyH("RIGHT")
  membersActionHint:SetText("")
  editor.lootProfileMembersActionHint = membersActionHint

  editor.lootProfileMemberDividers = {}
  for index = 1, 2 do
    local divider = rightContent:CreateTexture(nil, "OVERLAY")
    divider:SetColorTexture(0.82, 0.68, 0.30, 0.62)
    divider:SetHeight(1)
    divider:Hide()
    editor.lootProfileMemberDividers[index] = divider
  end

  local masterCard = CreateFrame("Frame", nil, rightContent, "BackdropTemplate")
  ApplyFrameSkin(masterCard)
  masterCard:EnableMouse(false)
  editor.lootProfileMasterCard = masterCard

  local masterCardTitle = masterCard:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  masterCardTitle:SetPoint("TOPLEFT", 12, -10)
  masterCardTitle:SetJustifyH("LEFT")
  masterCardTitle:SetText("Profile Master")
  editor.lootProfileMasterCardTitle = masterCardTitle

  local masterRoleEmblem = masterCard:CreateTexture(nil, "ARTWORK")
  masterRoleEmblem:SetSize(36, 36)
  masterRoleEmblem:SetTexture("Interface\\AddOns\\LidCouncil\\Media\\LidCouncil\\Emblems\\Emblem_Master.tga")
  editor.lootProfileMasterRoleEmblem = masterRoleEmblem

  local masterCardIcon = masterCard:CreateTexture(nil, "ARTWORK")
  masterCardIcon:SetSize(24, 24)
  masterCardIcon:SetPoint("TOPLEFT", 12, -28)
  editor.lootProfileMasterCardIcon = masterCardIcon

  local masterCardValue = masterCard:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
  masterCardValue:SetPoint("TOPLEFT", masterCardIcon, "TOPRIGHT", 10, 0)
  masterCardValue:SetJustifyH("LEFT")
  masterCardValue:SetText("Unassigned")
  editor.lootProfileMasterCardValue = masterCardValue

  local masterCardMeta = masterCard:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  masterCardMeta:SetPoint("TOPLEFT", masterCardValue, "BOTTOMLEFT", 0, -4)
  masterCardMeta:SetJustifyH("LEFT")
  masterCardMeta:SetText("Full profile control")
  editor.lootProfileMasterCardMeta = masterCardMeta

  local transferMasterBtn = CreateFrame("Button", nil, masterCard, "BackdropTemplate")
  ApplyFrameSkin(transferMasterBtn)
  transferMasterBtn:SetSize(136, 24)
  transferMasterBtn.label = transferMasterBtn:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  transferMasterBtn.label:SetPoint("CENTER", 0, 0)
  transferMasterBtn.label:SetText("Transfer Master")
  transferMasterBtn:SetScript("OnEnter", function(self)
    if self.SetBackdropColor and self.__hoverBackdrop then
      self:SetBackdropColor(self.__hoverBackdrop[1], self.__hoverBackdrop[2], self.__hoverBackdrop[3], self.__hoverBackdrop[4])
    end
    if GameTooltip then
      GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
      GameTooltip:SetText(self.__lidTooltipTitle or "Transfer Profile Master", 1.00, 0.82, 0.28, 1.00, true)
      if self.__lidTooltipDetail and self.__lidTooltipDetail ~= "" then
        GameTooltip:AddLine(self.__lidTooltipDetail, 0.92, 0.92, 0.96, true)
      end
      GameTooltip:Show()
    end
  end)
  transferMasterBtn:SetScript("OnLeave", function(self)
    if self.SetBackdropColor and self.__normalBackdrop then
      self:SetBackdropColor(self.__normalBackdrop[1], self.__normalBackdrop[2], self.__normalBackdrop[3], self.__normalBackdrop[4])
    end
    if GameTooltip then
      GameTooltip:Hide()
    end
  end)
  editor.lootProfileTransferMasterBtn = transferMasterBtn

  local councilCard = CreateFrame("Frame", nil, rightContent, "BackdropTemplate")
  ApplyFrameSkin(councilCard)
  councilCard:EnableMouse(false)
  editor.lootProfileCouncilCard = councilCard

  local councilCardTitle = councilCard:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  councilCardTitle:SetPoint("TOPLEFT", 12, -10)
  councilCardTitle:SetJustifyH("LEFT")
  councilCardTitle:SetText("Council Members")
  editor.lootProfileCouncilCardTitle = councilCardTitle

  local councilRoleEmblem = councilCard:CreateTexture(nil, "ARTWORK")
  councilRoleEmblem:SetSize(36, 36)
  councilRoleEmblem:SetTexture("Interface\\AddOns\\LidCouncil\\Media\\LidCouncil\\Emblems\\Emblem_Council.tga")
  editor.lootProfileCouncilRoleEmblem = councilRoleEmblem

  local councilCardValue = councilCard:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  councilCardValue:SetPoint("TOPLEFT", 12, -28)
  councilCardValue:SetJustifyH("LEFT")
  councilCardValue:SetText("0 member(s)")
  editor.lootProfileCouncilCardValue = councilCardValue

  local councilCardMeta = councilCard:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  councilCardMeta:SetPoint("TOPLEFT", 12, -46)
  councilCardMeta:SetJustifyH("LEFT")
  councilCardMeta:SetText("No council members yet.")
  editor.lootProfileCouncilCardMeta = councilCardMeta

  local councilRowsFrame = CreateFrame("Frame", nil, councilCard)
  councilRowsFrame:EnableMouse(false)
  editor.lootProfileCouncilRowsFrame = councilRowsFrame
  editor.lootProfileCouncilRows = {}

  local raiderFrame = CreateFrame("Frame", nil, rightContent, "BackdropTemplate")
  ApplyFrameSkin(raiderFrame)
  raiderFrame:EnableMouse(false)
  editor.lootProfileRaiderFrame = raiderFrame

  local raiderToggleBtn = CreateFrame("Button", nil, raiderFrame, "BackdropTemplate")
  ApplyFrameSkin(raiderToggleBtn)
  if raiderToggleBtn.SetBackdropColor then
    raiderToggleBtn:SetBackdropColor(0.08, 0.08, 0.11, 0.98)
  end
  raiderToggleBtn:SetSize(180, 28)
  raiderToggleBtn.roleEmblem = raiderToggleBtn:CreateTexture(nil, "ARTWORK")
  raiderToggleBtn.roleEmblem:SetSize(36, 36)
  raiderToggleBtn.roleEmblem:SetTexture("Interface\\AddOns\\LidCouncil\\Media\\LidCouncil\\Emblems\\Emblem_Raider.tga")
  raiderToggleBtn.arrowText = raiderToggleBtn:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  raiderToggleBtn.arrowText:SetPoint("LEFT", 10, 0)
  raiderToggleBtn.arrowText:SetTextColor(1.00, 0.82, 0.24, 1.00)
  raiderToggleBtn.labelText = raiderToggleBtn:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
  raiderToggleBtn.labelText:SetPoint("LEFT", raiderToggleBtn.arrowText, "RIGHT", 8, 0)
  raiderToggleBtn.labelText:SetPoint("RIGHT", -10, 0)
  raiderToggleBtn.labelText:SetJustifyH("LEFT")
  editor.lootProfileRaiderToggleBtn = raiderToggleBtn

  local raiderSummary = raiderFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  raiderSummary:SetPoint("TOPLEFT", 12, -40)
  raiderSummary:SetJustifyH("LEFT")
  raiderSummary:SetText("No class data yet.")
  editor.lootProfileRaiderSummary = raiderSummary

  local raiderRowsFrame = CreateFrame("Frame", nil, raiderFrame)
  raiderRowsFrame:EnableMouse(false)
  editor.lootProfileRaiderRowsFrame = raiderRowsFrame
  editor.lootProfileRaiderRows = {}

  local tabStrip = CreateFrame("Frame", nil, rightContent)
  tabStrip:EnableMouse(false)
  tabStrip.background = tabStrip:CreateTexture(nil, "BACKGROUND")
  tabStrip.background:SetAllPoints(tabStrip)
  tabStrip.background:SetColorTexture(0.015, 0.025, 0.04, 0.82)
  tabStrip.bottomLine = tabStrip:CreateTexture(nil, "BORDER")
  tabStrip.bottomLine:SetPoint("BOTTOMLEFT", tabStrip, "BOTTOMLEFT", 0, 0)
  tabStrip.bottomLine:SetPoint("BOTTOMRIGHT", tabStrip, "BOTTOMRIGHT", 0, 0)
  tabStrip.bottomLine:SetHeight(1)
  tabStrip.bottomLine:SetColorTexture(0.38, 0.54, 0.72, 0.62)
  editor.lootProfileTabStrip = tabStrip

  local overviewToggleBtn = CreateProfileTabButton(tabStrip, "Overview")
  editor.lootProfileOverviewToggleBtn = overviewToggleBtn

  local accessToggleBtn = CreateProfileTabButton(tabStrip, "Roles & Rights")
  editor.lootProfileAccessToggleBtn = accessToggleBtn

  local accessHeader = MakeYellowSubHeader(rightContent, "Roles & Rights", 18, -152)
  editor.lootProfileAccessHeader = accessHeader

  local accessSummary = rightContent:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  accessSummary:SetPoint("TOPLEFT", 18, -176)
  accessSummary:SetWidth(520)
  accessSummary:SetJustifyH("LEFT")
  accessSummary:SetText("")
  editor.lootProfileAccessSummary = accessSummary

  local roleContextFrame = CreateFrame("Frame", nil, rightContent, "BackdropTemplate")
  ApplyFrameSkin(roleContextFrame)
  roleContextFrame:SetFrameLevel(sectionFrameLevel)
  editor.lootProfileRoleContextFrame = roleContextFrame

  local roleContextIcon = roleContextFrame:CreateTexture(nil, "ARTWORK")
  roleContextIcon:SetSize(48, 48)
  roleContextIcon:SetTexCoord(0, 1, 0, 1)
  editor.lootProfileRoleContextIcon = roleContextIcon

  local roleContextTitle = roleContextFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
  roleContextTitle:SetJustifyH("LEFT")
  editor.lootProfileRoleContextTitle = roleContextTitle

  local roleContextDetail = roleContextFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  roleContextDetail:SetJustifyH("LEFT")
  editor.lootProfileRoleContextDetail = roleContextDetail

  local roleContextHint = roleContextFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  roleContextHint:SetJustifyH("LEFT")
  roleContextHint:SetText("Changes save immediately. Locked rights cannot be changed.")
  roleContextHint:SetTextColor(0.68, 0.70, 0.76, 1.00)
  editor.lootProfileRoleContextHint = roleContextHint

  local roleSessionBadge = CreateFrame("Frame", nil, roleContextFrame, "BackdropTemplate")
  ApplyFrameSkin(roleSessionBadge)
  roleSessionBadge:SetSize(112, 20)
  roleSessionBadge.label = roleSessionBadge:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  roleSessionBadge.label:SetPoint("CENTER", 0, 0)
  roleSessionBadge.label:SetText("HOSTING SESSION")
  editor.lootProfileRoleSessionBadge = roleSessionBadge

  local accessFrame = CreateFrame("Frame", nil, rightContent, "BackdropTemplate")
  ApplyFrameSkin(accessFrame)
  accessFrame:EnableMouse(false)
  accessFrame:SetFrameLevel(sectionFrameLevel)
  editor.lootProfileAccessFrame = accessFrame

  editor.lootProfilePermissionPolicyTitle = accessFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  editor.lootProfilePermissionPolicyTitle:SetJustifyH("LEFT")
  editor.lootProfilePermissionPolicyTitle:SetText("Role Permissions")

  editor.lootProfilePermissionPolicySummary = accessFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  editor.lootProfilePermissionPolicySummary:SetJustifyH("LEFT")
  editor.lootProfilePermissionPolicySummary:SetText("")

  local permissionResetBtn = CreateFrame("Button", nil, accessFrame, "UIPanelButtonTemplate")
  permissionResetBtn:SetSize(180, 20)
  permissionResetBtn:SetText("Restore Default Permissions")
  editor.lootProfilePermissionPolicyResetBtn = permissionResetBtn

  local permissionFooterDivider = accessFrame:CreateTexture(nil, "BORDER")
  permissionFooterDivider:SetHeight(1)
  permissionFooterDivider:SetColorTexture(0.34, 0.30, 0.18, 0.64)
  editor.lootProfilePermissionPolicyFooterDivider = permissionFooterDivider

  local permissionFooter = accessFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  permissionFooter:SetJustifyH("LEFT")
  permissionFooter:SetText("Permissions are saved immediately.")
  permissionFooter:SetTextColor(0.68, 0.70, 0.76, 1.00)
  editor.lootProfilePermissionPolicyFooter = permissionFooter

  editor.lootProfilePermissionPolicyHeaderRight = accessFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  editor.lootProfilePermissionPolicyHeaderRight:SetJustifyH("LEFT")
  editor.lootProfilePermissionPolicyHeaderRight:SetText("Permission")

  editor.lootProfilePermissionPolicyHeaderMaster = accessFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  editor.lootProfilePermissionPolicyHeaderMaster:SetJustifyH("CENTER")
  editor.lootProfilePermissionPolicyHeaderMaster:SetText("Master")

  editor.lootProfilePermissionPolicyHeaderSessionHost = accessFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  editor.lootProfilePermissionPolicyHeaderSessionHost:SetJustifyH("CENTER")
  editor.lootProfilePermissionPolicyHeaderSessionHost:SetText("Host")

  editor.lootProfilePermissionPolicyHeaderCouncil = accessFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  editor.lootProfilePermissionPolicyHeaderCouncil:SetJustifyH("CENTER")
  editor.lootProfilePermissionPolicyHeaderCouncil:SetText("Council")

  editor.lootProfilePermissionPolicyHeaderRaider = accessFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  editor.lootProfilePermissionPolicyHeaderRaider:SetJustifyH("CENTER")
  editor.lootProfilePermissionPolicyHeaderRaider:SetText("Raider")

  editor.lootProfilePermissionPolicyRows = {}

  local raidToggleBtn = CreateProfileTabButton(tabStrip, "Image")
  editor.lootProfileRaidToggleBtn = raidToggleBtn

  local raidHeader = MakeYellowSubHeader(rightContent, "Profile Image", 18, -152)
  editor.lootRaidHeader = raidHeader

  local raidLabel = rightContent:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  raidLabel:SetPoint("TOPLEFT", 18, -176)
  raidLabel:SetText("Select Profile Image:")
  editor.lootRaidLabel = raidLabel

  local raidSeasonLabel = rightContent:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  raidSeasonLabel:SetPoint("TOPLEFT", 18, -176)
  raidSeasonLabel:SetText("Raid Season:")
  editor.lootRaidSeasonLabel = raidSeasonLabel

  local raidSeasonDropdown = CreateDropdownControl(editor, rightContent, 210, "(profile season)")
  raidSeasonDropdown:SetPoint("LEFT", raidSeasonLabel, "RIGHT", 8, 0)
  editor.lootRaidSeasonDropdown = raidSeasonDropdown

  local raidDropdown = CreateDropdownControl(editor, rightContent, 260, "(select image)")
  raidDropdown:SetPoint("LEFT", raidLabel, "RIGHT", 8, 0)
  editor.lootRaidDropdown = raidDropdown

  local saveRaidBtn = CreateFrame("Button", nil, rightContent, "UIPanelButtonTemplate")
  saveRaidBtn:SetSize(96, 22)
  saveRaidBtn:SetPoint("LEFT", raidDropdown, "RIGHT", 10, 0)
  saveRaidBtn:SetText("Clear Image")
  editor.lootSaveRaidBtn = saveRaidBtn

  local raidHint = rightContent:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  raidHint:SetPoint("TOPLEFT", 18, -202)
  raidHint:SetWidth(520)
  raidHint:SetJustifyH("LEFT")
  raidHint:SetText("Choose the artwork used in this profile's overview. Only images from this profile's raid season are shown.")
  editor.lootRaidHint = raidHint

  local raidFrame = CreateFrame("Frame", nil, rightContent, "BackdropTemplate")
  ApplyFrameSkin(raidFrame)
  raidFrame:EnableMouse(false)
  raidFrame:SetFrameLevel(sectionFrameLevel)
  editor.lootProfileRaidFrame = raidFrame

  local raidGalleryTitle = raidFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
  raidGalleryTitle:SetJustifyH("LEFT")
  raidGalleryTitle:SetText("Available Artwork")
  editor.lootRaidGalleryTitle = raidGalleryTitle

  local raidGalleryFrame = CreateFrame("Frame", nil, raidFrame)
  raidGalleryFrame:SetFrameLevel(sectionFrameLevel + 2)
  editor.lootRaidGalleryFrame = raidGalleryFrame
  editor.lootProfileImageTiles = {}

  for index = 1, 16 do
    local tile = CreateFrame("Button", nil, raidGalleryFrame, "BackdropTemplate")
    ApplyFrameSkin(tile)
    tile:SetFrameLevel(raidGalleryFrame:GetFrameLevel() + 1)
    tile:SetSize(132, 98)
    tile:SetBackdropColor(0.02, 0.03, 0.05, 0.96)
    tile:SetBackdropBorderColor(0.26, 0.33, 0.43, 0.90)

    local artwork = tile:CreateTexture(nil, "ARTWORK")
    artwork:SetPoint("TOPLEFT", 4, -4)
    artwork:SetPoint("TOPRIGHT", -4, -4)
    artwork:SetHeight(68)
    artwork:SetTexCoord(0.05, 0.80, 0.04, 0.64)
    tile.artwork = artwork

    local artworkShade = tile:CreateTexture(nil, "ARTWORK", nil, 1)
    artworkShade:SetPoint("TOPLEFT", artwork, "TOPLEFT", 0, 0)
    artworkShade:SetPoint("BOTTOMRIGHT", artwork, "BOTTOMRIGHT", 0, 0)
    artworkShade:SetColorTexture(0, 0, 0, 0.20)
    tile.artworkShade = artworkShade

    local emptyText = tile:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
    emptyText:SetPoint("CENTER", artwork, "CENTER", 0, 0)
    emptyText:SetText("No artwork")
    emptyText:Hide()
    tile.emptyText = emptyText

    local nameText = tile:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
    nameText:SetPoint("TOPLEFT", artwork, "BOTTOMLEFT", 4, -4)
    nameText:SetPoint("TOPRIGHT", artwork, "BOTTOMRIGHT", -4, -4)
    nameText:SetJustifyH("CENTER")
    nameText:SetWordWrap(false)
    nameText:SetText("")
    tile.nameText = nameText

    local selectedText = tile:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
    selectedText:SetPoint("TOPRIGHT", tile, "TOPRIGHT", -6, -6)
    selectedText:SetText("Selected")
    selectedText:SetTextColor(1.00, 0.82, 0.24, 1.00)
    selectedText:Hide()
    tile.selectedText = selectedText

    tile:SetScript("OnEnter", function(self)
      if self:IsEnabled() and self.SetBackdropBorderColor then
        self:SetBackdropBorderColor(0.42, 0.66, 0.96, 1.00)
      end
      if GameTooltip and self.__lootProfileImageName then
        GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
        GameTooltip:SetText(self.__lootProfileImageName, 1.00, 0.82, 0.24, 1.00)
        GameTooltip:AddLine(self.__lootProfileImageIsClear and "Use no decorative profile artwork." or "Use this artwork in the profile overview.", 0.88, 0.90, 0.94, true)
        GameTooltip:Show()
      end
    end)
    tile:SetScript("OnLeave", function(self)
      if self.SetBackdropBorderColor then
        local selected = self.__lootProfileImageSelected == true
        self:SetBackdropBorderColor(selected and 1.00 or 0.26, selected and 0.78 or 0.33, selected and 0.20 or 0.43, selected and 1.00 or 0.90)
      end
      if GameTooltip then
        GameTooltip:Hide()
      end
    end)
    tile:SetScript("OnClick", function(self)
      if type(editor.SelectLootProfileImage) == "function" then
        editor:SelectLootProfileImage(self.__lootProfileImageEntry)
      end
    end)
    tile:Hide()
    editor.lootProfileImageTiles[index] = tile
  end

  local rollHeader = MakeYellowSubHeader(rightContent, "Roll Settings", 18, -242)
  editor.lootRollHeader = rollHeader

  local rollText = rightContent:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  rollText:SetPoint("TOPLEFT", 18, -266)
  rollText:SetWidth(520)
  rollText:SetJustifyH("LEFT")
  rollText:SetText("")
  editor.lootRollOptionsText = rollText

  local rollTemplateLabel = rightContent:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  rollTemplateLabel:SetPoint("TOPLEFT", 18, -292)
  rollTemplateLabel:SetText("Select Template:")
  editor.lootRollTemplateLabel = rollTemplateLabel

  local rollTemplateDropdown = CreateDropdownControl(editor, rightContent, 220, "Default WoW Template")
  rollTemplateDropdown:SetPoint("LEFT", rollTemplateLabel, "RIGHT", 8, 0)
  editor.lootRollTemplateDropdown = rollTemplateDropdown

  local rollSettingsToolsDropdown = CreateDropdownControl(editor, rightContent, 168, "Roll Settings Tools")
  ApplyProfileUtilityDropdownStyle(rollSettingsToolsDropdown)
  editor.lootRollSettingsToolsDropdown = rollSettingsToolsDropdown

  local rollResponsiveHint = rightContent:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
  rollResponsiveHint:SetPoint("TOPLEFT", 18, -320)
  rollResponsiveHint:SetWidth(520)
  rollResponsiveHint:SetJustifyH("LEFT")
  rollResponsiveHint:SetText("")
  rollResponsiveHint:Hide()
  editor.lootRollResponsiveHint = rollResponsiveHint

  local rollAccessHint = rightContent:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
  rollAccessHint:SetWidth(520)
  rollAccessHint:SetJustifyH("LEFT")
  rollAccessHint:SetText("")
  rollAccessHint:Hide()
  editor.lootRollAccessHint = rollAccessHint

  editor.lootRollPriorityHeader = CreateRollColumnHeader(rightContent, "Pick")
  editor.lootRollMoveHeader = CreateRollColumnHeader(rightContent, "Move")
  editor.lootRollDescriptionHeader = CreateRollColumnHeader(rightContent, "Description")
  editor.lootRollIconHeader = CreateRollColumnHeader(rightContent, "Icon")
  editor.lootRollColorHeader = CreateRollColumnHeader(rightContent, "Color")
  editor.lootRollAppearanceHeader = CreateRollColumnHeader(rightContent, "Visual")
  editor.lootRollPointDetailsHeader = CreateRollColumnHeader(rightContent, "Point Rule")
  editor.lootRollCategoryHeader = CreateRollColumnHeader(rightContent, "Category")

  local rollNewOptionLabel = rightContent:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  rollNewOptionLabel:SetJustifyH("LEFT")
  rollNewOptionLabel:SetText("New option:")
  editor.lootRollNewOptionLabel = rollNewOptionLabel

  local rollEdit = CreateSimpleEditBox(rightContent, 220, 22)
  rollEdit:SetPoint("TOPLEFT", 18, -334)
  editor.lootRollOptionEdit = rollEdit

  local addRollBtn = CreateFrame("Button", nil, rightContent, "UIPanelButtonTemplate")
  addRollBtn:SetSize(110, 22)
  addRollBtn:SetPoint("LEFT", rollEdit, "RIGHT", 10, 0)
  addRollBtn:SetText("Add Option")
  ApplyProfileUtilityActionStyle(addRollBtn, "add")
  editor.lootAddRollOptionBtn = addRollBtn

  local removeRollBtn = CreateFrame("Button", nil, rightContent, "UIPanelButtonTemplate")
  removeRollBtn:SetSize(130, 22)
  removeRollBtn:SetPoint("LEFT", addRollBtn, "RIGHT", 10, 0)
  removeRollBtn:SetText("Remove Selected")
  ApplyProfileUtilityActionStyle(removeRollBtn, "remove")
  AttachProfileActionTooltip(removeRollBtn, "Remove Selected Option", "Click a roll option row to select it, then remove it.")
  editor.lootRemoveRollOptionBtn = removeRollBtn

  local rollOptionActionsHeader = rightContent:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  rollOptionActionsHeader:SetJustifyH("LEFT")
  rollOptionActionsHeader:SetText("Edit Options")
  editor.lootRollOptionActionsHeader = rollOptionActionsHeader

  local rollOptionSaveStatus = rightContent:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  rollOptionSaveStatus:SetJustifyH("LEFT")
  rollOptionSaveStatus:SetText("Saved")
  rollOptionSaveStatus:SetTextColor(0.28, 1.00, 0.46, 1.00)
  rollOptionSaveStatus:Hide()
  editor.lootRollOptionSaveStatus = rollOptionSaveStatus

  local testRollBtn = CreateFrame("Button", nil, rightContent, "UIPanelButtonTemplate")
  testRollBtn:SetSize(120, 22)
  testRollBtn:SetPoint("TOPLEFT", 18, -362)
  testRollBtn:SetText("Test Popup")
  ApplyProfileUtilityActionStyle(testRollBtn, "utility")
  editor.lootTestRollPopupBtn = testRollBtn

  local previewHostBoardBtn = CreateFrame("Button", nil, rightContent, "UIPanelButtonTemplate")
  previewHostBoardBtn:SetSize(150, 22)
  previewHostBoardBtn:SetPoint("LEFT", testRollBtn, "RIGHT", 10, 0)
  previewHostBoardBtn:SetText("Preview Board")
  ApplyProfileUtilityActionStyle(previewHostBoardBtn, "utility")
  editor.lootPreviewHostBoardBtn = previewHostBoardBtn

  local rollPreviewActionsHeader = rightContent:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  rollPreviewActionsHeader:SetJustifyH("LEFT")
  rollPreviewActionsHeader:SetText("Preview")
  editor.lootRollPreviewActionsHeader = rollPreviewActionsHeader

  local rollExportBtn = CreateFrame("Button", nil, rightContent, "UIPanelButtonTemplate")
  rollExportBtn:SetSize(118, 22)
  rollExportBtn:SetPoint("LEFT", previewHostBoardBtn, "RIGHT", 10, 0)
  rollExportBtn:SetText("Export")
  AttachProfileActionTooltip(rollExportBtn, "Export Roll Settings", "Open a copyable settings string for this profile. Exporting does not change the profile.")
  editor.lootRollExportBtn = rollExportBtn

  local rollImportStringBtn = CreateFrame("Button", nil, rightContent, "UIPanelButtonTemplate")
  rollImportStringBtn:SetSize(104, 22)
  rollImportStringBtn:SetPoint("LEFT", rollExportBtn, "RIGHT", 10, 0)
  rollImportStringBtn:SetText("Import Text")
  AttachProfileActionTooltip(rollImportStringBtn, "Import Roll Settings Text", "Replace this profile's roll settings with a previously exported LidCouncil settings string.")
  editor.lootRollImportStringBtn = rollImportStringBtn

  local rollImportProfileDropdown = CreateDropdownControl(editor, rightContent, 170, "Import Profile")
  rollImportProfileDropdown:SetPoint("LEFT", rollImportStringBtn, "RIGHT", 10, 0)
  editor.lootRollImportProfileDropdown = rollImportProfileDropdown

  local rollTransferActionsHeader = rightContent:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  rollTransferActionsHeader:SetJustifyH("LEFT")
  rollTransferActionsHeader:SetText("Transfer Settings")
  editor.lootRollTransferActionsHeader = rollTransferActionsHeader

  local rollInlinePreviewFrame = CreateFrame("Frame", nil, rightContent, "BackdropTemplate")
  ApplyFrameSkin(rollInlinePreviewFrame)
  rollInlinePreviewFrame:EnableMouse(false)
  rollInlinePreviewFrame:SetFrameLevel(sectionFrameLevel + 1)
  editor.lootRollInlinePreviewFrame = rollInlinePreviewFrame

  local rollInlinePreviewTitle = rollInlinePreviewFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  rollInlinePreviewTitle:SetPoint("TOPLEFT", 10, -8)
  rollInlinePreviewTitle:SetJustifyH("LEFT")
  rollInlinePreviewTitle:SetText("Live Roll Button Preview")
  editor.lootRollInlinePreviewTitle = rollInlinePreviewTitle

  local rollInlinePreviewHint = rollInlinePreviewFrame:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
  rollInlinePreviewHint:SetPoint("TOPLEFT", rollInlinePreviewTitle, "BOTTOMLEFT", 0, -3)
  rollInlinePreviewHint:SetJustifyH("LEFT")
  rollInlinePreviewHint:SetText("Matches the player roll window's option order and sections.")
  editor.lootRollInlinePreviewHint = rollInlinePreviewHint

  local rollInlinePreviewNeedFrame = CreateFrame("Frame", nil, rollInlinePreviewFrame, "BackdropTemplate")
  ApplyFrameSkin(rollInlinePreviewNeedFrame)
  rollInlinePreviewNeedFrame:EnableMouse(false)
  rollInlinePreviewNeedFrame:SetFrameLevel((rollInlinePreviewFrame:GetFrameLevel() or 1) + 1)
  if rollInlinePreviewNeedFrame.SetBackdropColor then
    rollInlinePreviewNeedFrame:SetBackdropColor(0.06, 0.08, 0.12, 0.98)
  end
  local rollInlinePreviewNeedTitle = rollInlinePreviewNeedFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  rollInlinePreviewNeedTitle:SetPoint("TOPLEFT", 10, -8)
  rollInlinePreviewNeedTitle:SetJustifyH("LEFT")
  rollInlinePreviewNeedTitle:SetText("Need")
  rollInlinePreviewNeedTitle:SetTextColor(1.00, 0.82, 0.32, 1.00)
  local rollInlinePreviewNeedEmpty = rollInlinePreviewNeedFrame:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
  rollInlinePreviewNeedEmpty:SetPoint("TOPLEFT", 10, -28)
  rollInlinePreviewNeedEmpty:SetText("No options")
  editor.lootRollInlinePreviewNeedFrame = rollInlinePreviewNeedFrame
  editor.lootRollInlinePreviewNeedTitle = rollInlinePreviewNeedTitle
  editor.lootRollInlinePreviewNeedEmpty = rollInlinePreviewNeedEmpty

  local rollInlinePreviewGreedFrame = CreateFrame("Frame", nil, rollInlinePreviewFrame, "BackdropTemplate")
  ApplyFrameSkin(rollInlinePreviewGreedFrame)
  rollInlinePreviewGreedFrame:EnableMouse(false)
  rollInlinePreviewGreedFrame:SetFrameLevel((rollInlinePreviewFrame:GetFrameLevel() or 1) + 1)
  if rollInlinePreviewGreedFrame.SetBackdropColor then
    rollInlinePreviewGreedFrame:SetBackdropColor(0.06, 0.08, 0.12, 0.98)
  end
  local rollInlinePreviewGreedTitle = rollInlinePreviewGreedFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  rollInlinePreviewGreedTitle:SetPoint("TOPLEFT", 10, -8)
  rollInlinePreviewGreedTitle:SetJustifyH("LEFT")
  rollInlinePreviewGreedTitle:SetText("Greed / Pass")
  rollInlinePreviewGreedTitle:SetTextColor(0.78, 0.88, 1.00, 1.00)
  local rollInlinePreviewGreedEmpty = rollInlinePreviewGreedFrame:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
  rollInlinePreviewGreedEmpty:SetPoint("TOPLEFT", 10, -28)
  rollInlinePreviewGreedEmpty:SetText("No options")
  editor.lootRollInlinePreviewGreedFrame = rollInlinePreviewGreedFrame
  editor.lootRollInlinePreviewGreedTitle = rollInlinePreviewGreedTitle
  editor.lootRollInlinePreviewGreedEmpty = rollInlinePreviewGreedEmpty

  local rollInlinePreviewEmpty = rollInlinePreviewFrame:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
  rollInlinePreviewEmpty:SetJustifyH("LEFT")
  rollInlinePreviewEmpty:SetText("No roll options configured.")
  rollInlinePreviewEmpty:Hide()
  editor.lootRollInlinePreviewEmpty = rollInlinePreviewEmpty
  editor.lootRollInlinePreviewButtons = {}

  for index = 1, 12 do
    local previewButton = CreateFrame("Button", nil, rollInlinePreviewFrame, "BackdropTemplate")
    previewButton:SetBackdrop({
      bgFile = "Interface\\Buttons\\WHITE8x8",
      edgeFile = "Interface\\Buttons\\WHITE8x8",
      edgeSize = 1,
    })
    previewButton:SetBackdropColor(0.03, 0.04, 0.06, 0.96)
    previewButton:SetBackdropBorderColor(0.30, 0.38, 0.50, 0.88)
    previewButton:EnableMouse(false)

    local icon = previewButton:CreateTexture(nil, "ARTWORK")
    icon:SetSize(16, 16)
    icon:SetPoint("LEFT", 7, 0)
    previewButton.icon = icon

    local label = previewButton:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
    label:SetPoint("LEFT", icon, "RIGHT", 6, 0)
    label:SetPoint("RIGHT", previewButton, "RIGHT", -7, 0)
    label:SetJustifyH("LEFT")
    previewButton.label = label
    previewButton:Hide()
    editor.lootRollInlinePreviewButtons[index] = previewButton
  end

  editor.lootRollOptionRows = {}

  local rollFrame = CreateFrame("Frame", nil, rightContent, "BackdropTemplate")
  ApplyFrameSkin(rollFrame)
  rollFrame:EnableMouse(false)
  rollFrame:SetFrameLevel(sectionFrameLevel)
  editor.lootProfileRollFrame = rollFrame

  local rollToggleBtn = CreateProfileTabButton(tabStrip, "Rolls")
  editor.lootProfileRollToggleBtn = rollToggleBtn

  local pointsHeader = MakeYellowSubHeader(rightContent, "Point Settings", 18, -374)
  editor.lootPointsHeader = pointsHeader

  local pointModeLabel = rightContent:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  pointModeLabel:SetPoint("TOPLEFT", 18, -398)
  pointModeLabel:SetText("Loot List Type:")
  editor.lootPointModeLabel = pointModeLabel

  local pointModeDropdown = CreateDropdownControl(editor, rightContent, 180, "LidTable")
  pointModeDropdown:SetPoint("LEFT", pointModeLabel, "RIGHT", 8, 0)
  editor.lootPointModeDropdown = pointModeDropdown

  local pointsHint = rightContent:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  pointsHint:SetPoint("TOPLEFT", 18, -426)
  pointsHint:SetWidth(520)
  pointsHint:SetJustifyH("LEFT")
  pointsHint:SetText("")
  editor.lootPointsHint = pointsHint

  local lidTablePointsLabel = rightContent:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
  lidTablePointsLabel:SetText("Points")
  editor.lootLidTablePointsLabel = lidTablePointsLabel

  local lidTableItemLevelLabel = rightContent:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
  lidTableItemLevelLabel:SetText("Item Level")
  editor.lootLidTableItemLevelLabel = lidTableItemLevelLabel

  local lidTableSetPieceLabel = rightContent:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
  lidTableSetPieceLabel:SetText("Setpiece Points")
  editor.lootLidTableSetPieceLabel = lidTableSetPieceLabel

  editor.lootLidTableOffSpecLabel = rightContent:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
  editor.lootLidTableOffSpecLabel:SetText("Off-Spec")
  editor.lootLidTableTransmogLabel = rightContent:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
  editor.lootLidTableTransmogLabel:SetText("Transmog")
  editor.lootLidTableDisenchantLabel = rightContent:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
  editor.lootLidTableDisenchantLabel:SetText("Disenchant")

  editor.lootLidTableRows = EnsureLidTableEditorRows(editor.lootLidTableRows, rightContent, 15)

  local customRulesHeader = CreateRollColumnHeader(rightContent, "Add Custom Rules")
  editor.lootPointCustomRulesHeader = customRulesHeader

  local levelRuleLabel = CreateRollColumnHeader(rightContent, "Item Level")
  editor.lootPointItemLevelLabel = levelRuleLabel
  local levelPointsLabel = CreateRollColumnHeader(rightContent, "Points")
  levelPointsLabel:SetJustifyH("RIGHT")
  editor.lootPointLevelPointsLabel = levelPointsLabel

  local levelEdit = CreateSimpleEditBox(rightContent, 72, 22)
  levelEdit:SetPoint("TOPLEFT", 18, -398)
  editor.lootPointItemLevelEdit = levelEdit

  local levelPointsEdit = CreateSimpleEditBox(rightContent, 70, 22)
  levelPointsEdit:SetPoint("LEFT", levelEdit, "RIGHT", 10, 0)
  editor.lootPointLevelValueEdit = levelPointsEdit
  -- Retain the old reference for internal callers that still use it.
  editor.lootPointValueEdit = levelPointsEdit

  local itemRuleLabel = CreateRollColumnHeader(rightContent, "Specific Loot Item")
  editor.lootPointItemLabel = itemRuleLabel
  local itemPointsLabel = CreateRollColumnHeader(rightContent, "Points")
  itemPointsLabel:SetJustifyH("RIGHT")
  editor.lootPointItemPointsLabel = itemPointsLabel

  local itemDropdown = CreateDropdownControl(editor, rightContent, 210, "(select profile-season loot item)")
  itemDropdown:SetPoint("TOPLEFT", 18, -426)
  editor.lootPointItemDropdown = itemDropdown

  local itemPointsEdit = CreateSimpleEditBox(rightContent, 70, 22)
  itemPointsEdit:SetPoint("LEFT", itemDropdown, "RIGHT", 10, 0)
  editor.lootPointItemValueEdit = itemPointsEdit

  local addLevelRuleBtn = CreateFrame("Button", nil, rightContent, "UIPanelButtonTemplate")
  addLevelRuleBtn:SetSize(140, 22)
  addLevelRuleBtn:SetPoint("TOPLEFT", 18, -430)
  addLevelRuleBtn:SetText("Add Level Rule")
  ApplyProfileUtilityActionStyle(addLevelRuleBtn, "add")
  editor.lootAddPointRuleBtn = addLevelRuleBtn

  local addItemRuleBtn = CreateFrame("Button", nil, rightContent, "UIPanelButtonTemplate")
  addItemRuleBtn:SetSize(140, 22)
  addItemRuleBtn:SetPoint("LEFT", addLevelRuleBtn, "RIGHT", 10, 0)
  addItemRuleBtn:SetText("Add Item Rule")
  ApplyProfileUtilityActionStyle(addItemRuleBtn, "add")
  editor.lootAddItemPointRuleBtn = addItemRuleBtn

  local removeRuleBtn = CreateFrame("Button", nil, rightContent, "UIPanelButtonTemplate")
  removeRuleBtn:SetSize(140, 22)
  removeRuleBtn:SetPoint("LEFT", addItemRuleBtn, "RIGHT", 10, 0)
  removeRuleBtn:SetText("Remove Selected")
  ApplyProfileUtilityActionStyle(removeRuleBtn, "remove")
  AttachProfileActionTooltip(removeRuleBtn, "Remove Selected Point Rule", "Click the Select control or an empty area of a point rule row, then remove it.")
  editor.lootRemovePointRuleBtn = removeRuleBtn

  local existingRulesHeader = CreateRollColumnHeader(rightContent, "Existing Rules")
  editor.lootPointExistingRulesHeader = existingRulesHeader

  local pointRuleFeedback = rightContent:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  pointRuleFeedback:SetJustifyH("LEFT")
  pointRuleFeedback:SetTextColor(1.00, 0.36, 0.28, 1.00)
  pointRuleFeedback:Hide()
  editor.lootPointRuleFeedback = pointRuleFeedback

  local transferHeader = CreateRollColumnHeader(rightContent, "Transfer")
  editor.lootPointTransferHeader = transferHeader

  local pointExportBtn = CreateFrame("Button", nil, rightContent, "UIPanelButtonTemplate")
  pointExportBtn:SetSize(80, 22)
  pointExportBtn:SetPoint("TOPLEFT", 18, -458)
  pointExportBtn:SetText("Export")
  ApplyProfileUtilityActionStyle(pointExportBtn, "utility")
  editor.lootPointExportBtn = pointExportBtn

  local pointImportStringBtn = CreateFrame("Button", nil, rightContent, "UIPanelButtonTemplate")
  pointImportStringBtn:SetSize(96, 22)
  pointImportStringBtn:SetPoint("LEFT", pointExportBtn, "RIGHT", 10, 0)
  pointImportStringBtn:SetText("Import Text")
  ApplyProfileUtilityActionStyle(pointImportStringBtn, "utility")
  editor.lootPointImportStringBtn = pointImportStringBtn

  local pointImportProfileDropdown = CreateDropdownControl(editor, rightContent, 170, "Import From Profile")
  pointImportProfileDropdown:SetPoint("LEFT", pointImportStringBtn, "RIGHT", 10, 0)
  ApplyProfileUtilityDropdownStyle(pointImportProfileDropdown)
  editor.lootPointImportProfileDropdown = pointImportProfileDropdown

  local ruleText = rightContent:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  ruleText:SetPoint("TOPLEFT", 18, -494)
  ruleText:SetWidth(520)
  ruleText:SetJustifyH("LEFT")
  ruleText:SetText("")
  editor.lootPointRulesText = ruleText

  local pointRuleSelectHeader = CreateRollColumnHeader(rightContent, "Select")
  editor.lootPointRuleSelectHeader = pointRuleSelectHeader
  local pointRuleDescriptionHeader = CreateRollColumnHeader(rightContent, "Rule")
  editor.lootPointRuleDescriptionHeader = pointRuleDescriptionHeader
  local pointRulePointsHeader = CreateRollColumnHeader(rightContent, "Points")
  pointRulePointsHeader:SetJustifyH("RIGHT")
  editor.lootPointRulePointsHeader = pointRulePointsHeader
  editor.lootPointRuleRows = {}

  local pointsFrame = CreateFrame("Frame", nil, rightContent, "BackdropTemplate")
  ApplyFrameSkin(pointsFrame)
  pointsFrame:EnableMouse(false)
  pointsFrame:SetFrameLevel(sectionFrameLevel)
  editor.lootProfilePointsFrame = pointsFrame

  local pointsToggleBtn = CreateProfileTabButton(tabStrip, "Points")
  editor.lootProfilePointsToggleBtn = pointsToggleBtn

  local backupToggleBtn = CreateProfileTabButton(tabStrip, "Backups")
  editor.lootProfileBackupToggleBtn = backupToggleBtn

  local backupHeader = MakeYellowSubHeader(rightContent, "Local Backups", 18, -494)
  editor.lootProfileBackupHeader = backupHeader

  local backupFrame = CreateFrame("Frame", nil, rightContent, "BackdropTemplate")
  ApplyFrameSkin(backupFrame)
  backupFrame:EnableMouse(false)
  backupFrame:SetFrameLevel(sectionFrameLevel)
  editor.lootProfileBackupFrame = backupFrame

  local backupText = rightContent:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  backupText:SetWidth(520)
  backupText:SetJustifyH("LEFT")
  backupText:SetText("Backups are saved locally on this client and include the Loot List, session history, and Live Board history.")
  editor.lootProfileBackupText = backupText

  local backupCreateHeader = CreateRollColumnHeader(rightContent, "Create Local Backup")
  editor.lootProfileBackupCreateHeader = backupCreateHeader

  local saveBackupBtn = CreateFrame("Button", nil, rightContent, "UIPanelButtonTemplate")
  saveBackupBtn:SetSize(118, 22)
  saveBackupBtn:SetText("Save Backup")
  ApplyProfileUtilityActionStyle(saveBackupBtn, "add")
  AttachProfileActionTooltip(saveBackupBtn, "Save Local Backup", "Create a local snapshot of this profile. Backups are never sent to other players.")
  editor.lootProfileSaveBackupBtn = saveBackupBtn

  local backupSavedHeader = CreateRollColumnHeader(rightContent, "Saved Backups")
  editor.lootProfileBackupSavedHeader = backupSavedHeader

  local backupDropdown = CreateDropdownControl(editor, rightContent, 250, "Select Saved Backup")
  ApplyProfileUtilityDropdownStyle(backupDropdown)
  editor.lootProfileBackupDropdown = backupDropdown

  local loadBackupBtn = CreateFrame("Button", nil, rightContent, "UIPanelButtonTemplate")
  loadBackupBtn:SetSize(108, 22)
  loadBackupBtn:SetText("Restore Backup")
  ApplyProfileUtilityActionStyle(loadBackupBtn, "restore")
  AttachProfileActionTooltip(loadBackupBtn, "Restore Selected Backup", "Replace this profile's Loot List, session history, Live Board history, and roll statistics with the selected local snapshot.")
  editor.lootProfileLoadBackupBtn = loadBackupBtn

  local deleteBackupBtn = CreateFrame("Button", nil, rightContent, "UIPanelButtonTemplate")
  deleteBackupBtn:SetSize(118, 22)
  deleteBackupBtn:SetText("Delete Selected")
  ApplyProfileUtilityActionStyle(deleteBackupBtn, "delete")
  AttachProfileActionTooltip(deleteBackupBtn, "Delete Selected Backup", "Remove only the selected local backup. This does not change the current profile.")
  editor.lootProfileDeleteBackupBtn = deleteBackupBtn

  if type(INTERNAL_API.LIDCOUNCIL_ProfileTransferPage_Impl) == "table" then
    INTERNAL_API.LIDCOUNCIL_ProfileTransferPage_Impl.Build(editor, rightContent, {
      CreateProfileTabButton = CreateProfileTabButton,
      ApplyFrameSkin = ApplyFrameSkin,
      MakeYellowSubHeader = MakeYellowSubHeader,
      CreateDropdownControl = CreateDropdownControl,
      CreateSimpleEditBox = CreateSimpleEditBox,
      ApplyProfileUtilityDropdownStyle = ApplyProfileUtilityDropdownStyle,
      ApplyProfileUtilityActionStyle = ApplyProfileUtilityActionStyle,
      AttachProfileActionTooltip = AttachProfileActionTooltip,
    })
  end

  if editor.__lootProfileRaidersCollapsed == nil then
    editor.__lootProfileRaidersCollapsed = true
  end

  page.__contentHeight = 1
end

INTERNAL_API.LIDCOUNCIL_BuildLootProfilesPageScaffold_Impl = BuildLootProfilesPageScaffold
