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

local RequireApi = INTERNAL_API.LIDPANELS_RequireApi_Impl
local ResolveOptionalApiFunction = INTERNAL_API.LIDPANELS_ResolveOptionalApiFunction_Impl
local BindMouseWheelScroll = INTERNAL_API.LIDPANELS_BindMouseWheelScroll_Impl
local CreateAboutFAQSection = INTERNAL_API.LIDPANELS_CreateAboutFAQSection_Impl
local CreateAboutUtilitySections = INTERNAL_API.LIDPANELS_CreateAboutUtilitySections_Impl
if type(RequireApi) ~= "function"
  or type(ResolveOptionalApiFunction) ~= "function"
  or type(BindMouseWheelScroll) ~= "function"
  or type(CreateAboutFAQSection) ~= "function"
  or type(CreateAboutUtilitySections) ~= "function" then
  error("LidPanels missing about page helpers.")
end

local Print = RequireApi("LIDPANELS_Print", _G.LIDPANELS_Print)
local ApplyFrameSkin = RequireApi("LIDPANELS_ApplyFrameSkin", _G.LIDPANELS_ApplyFrameSkin)
local MakeYellowSubHeader = RequireApi("LIDPANELS_MakeYellowSubHeader", _G.LIDPANELS_MakeYellowSubHeader)
local ShowErrorLogWindow = RequireApi("LIDPANELS_ShowErrorLogWindow", _G.LIDPANELS_ShowErrorLogWindow)
local ShowSilentLogWindow = RequireApi("LIDPANELS_ShowSilentLogWindow", _G.LIDPANELS_ShowSilentLogWindow)
local RootDB = RequireApi("LIDPANELS_RootDB", _G.LIDPANELS_RootDB)

local ABOUT_TITLE_R, ABOUT_TITLE_G, ABOUT_TITLE_B, ABOUT_TITLE_A = 0.6588, 0.4784, 0.9098, 1.0

local function SafeHookScript(frame, scriptName, handler)
  if frame and type(frame.HookScript) == "function" and type(handler) == "function" then
    pcall(frame.HookScript, frame, scriptName, handler)
  end
end

local function BuildAboutPage(editor, aboutPage)
  if not editor or not aboutPage then return end

  local function StyleAboutTitle(fs)
    if not fs then return end
    fs:SetTextColor(ABOUT_TITLE_R, ABOUT_TITLE_G, ABOUT_TITLE_B, ABOUT_TITLE_A)
  end

  local function MakeAboutTitle(parent, text, x, y)
    local title = MakeYellowSubHeader(parent, text, x or 0, y or 0)
    StyleAboutTitle(title)
    return title
  end

  local aboutNavBg = CreateFrame("Frame", nil, aboutPage, "BackdropTemplate")
  aboutNavBg:SetPoint("TOPLEFT", 0, -44)
  aboutNavBg:SetPoint("BOTTOMLEFT", 0, 0)
  aboutNavBg:SetWidth(240)
  ApplyFrameSkin(aboutNavBg)
  editor.aboutNavBg = aboutNavBg

  local aboutRightBg = CreateFrame("Frame", nil, aboutPage, "BackdropTemplate")
  aboutRightBg:SetPoint("TOPLEFT", aboutNavBg, "TOPRIGHT", 12, 0)
  aboutRightBg:SetPoint("BOTTOMRIGHT", 0, 0)
  ApplyFrameSkin(aboutRightBg)
  aboutRightBg:SetClipsChildren(true)
  editor.aboutRightBg = aboutRightBg

  local aboutScroll = CreateFrame("ScrollFrame", nil, aboutRightBg, "UIPanelScrollFrameTemplate")
  aboutScroll:SetPoint("TOPLEFT", 18, -12)
  aboutScroll:SetPoint("BOTTOMRIGHT", -28, 12)
  BindMouseWheelScroll(aboutScroll)
  editor.aboutScroll = aboutScroll

  local aboutNavLoadedBtn = CreateFrame("Button", nil, aboutNavBg, "UIPanelButtonTemplate")
  aboutNavLoadedBtn:SetSize(200, 20)
  aboutNavLoadedBtn:SetPoint("TOPLEFT", 6, -18)
  aboutNavLoadedBtn:SetText("Loaded Components")
  editor.aboutNavLoadedBtn = aboutNavLoadedBtn

  local aboutNavErrorsBtn = CreateFrame("Button", nil, aboutNavBg, "UIPanelButtonTemplate")
  aboutNavErrorsBtn:SetSize(200, 20)
  aboutNavErrorsBtn:SetPoint("TOPLEFT", 6, -44)
  aboutNavErrorsBtn:SetText("Errors")
  editor.aboutNavErrorsBtn = aboutNavErrorsBtn

  local aboutNavSilentBtn = CreateFrame("Button", nil, aboutNavBg, "UIPanelButtonTemplate")
  aboutNavSilentBtn:SetSize(200, 20)
  aboutNavSilentBtn:SetPoint("TOPLEFT", 6, -70)
  aboutNavSilentBtn:SetText("Silent Errors")
  editor.aboutNavSilentBtn = aboutNavSilentBtn

  local aboutNavUpdatesBtn = CreateFrame("Button", nil, aboutNavBg, "UIPanelButtonTemplate")
  aboutNavUpdatesBtn:SetSize(200, 20)
  aboutNavUpdatesBtn:SetPoint("TOPLEFT", 6, -96)
  aboutNavUpdatesBtn:SetText("Changelog")
  editor.aboutNavUpdatesBtn = aboutNavUpdatesBtn

  local aboutNavFaqBtn = CreateFrame("Button", nil, aboutNavBg, "UIPanelButtonTemplate")
  aboutNavFaqBtn:SetSize(200, 20)
  aboutNavFaqBtn:SetPoint("TOPLEFT", 6, -122)
  aboutNavFaqBtn:SetText("FAQ")
  editor.aboutNavFaqBtn = aboutNavFaqBtn

  local aboutNavCreditsBtn = CreateFrame("Button", nil, aboutNavBg, "UIPanelButtonTemplate")
  aboutNavCreditsBtn:SetSize(200, 20)
  aboutNavCreditsBtn:SetPoint("TOPLEFT", 6, -148)
  aboutNavCreditsBtn:SetText("Credits")
  editor.aboutNavCreditsBtn = aboutNavCreditsBtn

  local aboutNavStressBtn = CreateFrame("Button", nil, aboutNavBg, "UIPanelButtonTemplate")
  aboutNavStressBtn:SetSize(200, 20)
  aboutNavStressBtn:SetPoint("TOPLEFT", 6, -174)
  aboutNavStressBtn:SetText("Stresstest")
  editor.aboutNavStressBtn = aboutNavStressBtn

  local aboutNavTutorialImagesBtn = CreateFrame("Button", nil, aboutNavBg, "UIPanelButtonTemplate")
  aboutNavTutorialImagesBtn:SetSize(200, 20)
  aboutNavTutorialImagesBtn:SetPoint("TOPLEFT", 6, -200)
  aboutNavTutorialImagesBtn:SetText("Disable Tutorial Images")
  editor.aboutNavTutorialImagesBtn = aboutNavTutorialImagesBtn

  local aboutNavDeveloperBtn = CreateFrame("Button", nil, aboutNavBg, "UIPanelButtonTemplate")
  aboutNavDeveloperBtn:SetSize(200, 20)
  aboutNavDeveloperBtn:SetPoint("TOPLEFT", 6, -226)
  aboutNavDeveloperBtn:SetText("Developer Mode")
  editor.aboutNavDeveloperBtn = aboutNavDeveloperBtn

  local aboutContent = CreateFrame("Frame", nil, aboutScroll)
  aboutContent:SetSize(1, 1)
  aboutScroll:SetScrollChild(aboutContent)
  editor.aboutContent = aboutContent

  local function SetAboutContentHeight(h)
    if not aboutContent then return end
    local minH = (aboutScroll and aboutScroll.GetHeight and aboutScroll:GetHeight()) or 1
    if type(h) ~= "number" then h = minH end
    if h < minH then h = minH end
    aboutContent:SetHeight(h)
    if aboutScroll and aboutScroll.UpdateScrollChildRect then aboutScroll:UpdateScrollChildRect() end
  end
  editor.SetAboutContentHeight = SetAboutContentHeight

  aboutScroll:SetScript("OnSizeChanged", function(self)
    local w = self:GetWidth() - 28
    if w < 1 then w = 1 end
    aboutContent:SetWidth(w)
    if editor and editor.UpdateAboutOverviewLayout then editor:UpdateAboutOverviewLayout() end
    if editor and editor.UpdateAboutUpdatesLayout then editor:UpdateAboutUpdatesLayout() end
    if editor and editor.UpdateAboutFAQLayout then editor:UpdateAboutFAQLayout() end
    if editor and editor.UpdateAboutCreditsLayout then editor:UpdateAboutCreditsLayout() end
    if editor and editor.UpdateAboutStressLayout then editor:UpdateAboutStressLayout() end
    if editor and editor.UpdateAboutTutorialImagesLayout then editor:UpdateAboutTutorialImagesLayout() end
    if editor and editor.UpdateAboutDeveloperLayout then editor:UpdateAboutDeveloperLayout() end
    if self.UpdateScrollChildRect then self:UpdateScrollChildRect() end
  end)

  local aboutOverview = CreateFrame("Frame", nil, aboutContent)
  aboutOverview:SetPoint("TOPLEFT", 0, 0)
  aboutOverview:SetPoint("BOTTOMRIGHT", 0, 0)
  editor.aboutOverview = aboutOverview

  local aboutMeta = aboutOverview:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  aboutMeta:SetPoint("TOPLEFT", 0, 0)
  aboutMeta:SetWidth(520)
  aboutMeta:SetJustifyH("LEFT")
  aboutMeta:SetText("")
  editor.aboutMeta = aboutMeta

  local aboutDesc = aboutOverview:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  aboutDesc:SetPoint("TOPLEFT", 0, -60)
  aboutDesc:SetWidth(560)
  aboutDesc:SetJustifyH("LEFT")
  aboutDesc:SetText("")
  editor.aboutDesc = aboutDesc

  local aboutUpdateNewsBtn = CreateFrame("Button", nil, aboutOverview, "UIPanelButtonTemplate")
  aboutUpdateNewsBtn:SetSize(170, 22)
  aboutUpdateNewsBtn:SetPoint("TOPLEFT", aboutDesc, "BOTTOMLEFT", 0, -12)
  aboutUpdateNewsBtn:SetText("Show Update News")
  aboutUpdateNewsBtn:SetScript("OnClick", function()
    local showFn = ResolveOptionalApiFunction("LIDPANELS_ShowUpdateNews")
    if showFn then
      showFn()
    elseif Print then
      Print("Update News is currently unavailable.")
    end
  end)
  editor.aboutUpdateNewsBtn = aboutUpdateNewsBtn

  local aboutLogo = aboutOverview:CreateTexture(nil, "ARTWORK")
  aboutLogo:SetSize(140, 140)
  aboutLogo:SetPoint("TOPRIGHT", -8, -8)
  aboutLogo:SetTexture("Interface\\AddOns\\LidPanels\\Media\\Lidpanels\\Logos\\About_Lid.tga")
  editor.aboutLogo = aboutLogo

  local function UpdateAboutOverviewLayout()
    if not aboutContent or not aboutMeta or not aboutDesc then return end
    if editor and editor.aboutSection and editor.aboutSection ~= "Overview" then return end
    local contentW = aboutContent:GetWidth() or 0
    local logoW = 140
    local pad = 20
    local textW = contentW - logoW - pad
    if textW < 200 then textW = 200 end
    aboutMeta:SetWidth(textW)
    aboutDesc:SetWidth(textW)
    local metaH = aboutMeta.GetStringHeight and aboutMeta:GetStringHeight() or 0
    local descH = aboutDesc.GetStringHeight and aboutDesc:GetStringHeight() or 0
    local buttonH = 0
    if aboutUpdateNewsBtn and aboutUpdateNewsBtn:IsShown() then
      buttonH = (aboutUpdateNewsBtn:GetHeight() or 0) + 18
    end
    local totalH = 60 + descH + buttonH + 40
    if metaH > 0 then
      totalH = metaH + 20 + descH + buttonH + 40
    end
    if editor and editor.SetAboutContentHeight then
      editor:SetAboutContentHeight(math.max(520, math.floor(totalH)))
    end
  end
  editor.UpdateAboutOverviewLayout = UpdateAboutOverviewLayout
  SafeHookScript(aboutContent, "OnSizeChanged", UpdateAboutOverviewLayout)
  UpdateAboutOverviewLayout()
  SafeHookScript(aboutOverview, "OnShow", UpdateAboutOverviewLayout)

  local aboutLoaded = CreateFrame("Frame", nil, aboutContent)
  aboutLoaded:SetAllPoints(aboutContent)
  aboutLoaded:Hide()
  editor.aboutLoaded = aboutLoaded

  local infoLabel = MakeAboutTitle(aboutLoaded, "Loaded Components", 0, 0)

  local aboutDetails = aboutLoaded:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  aboutDetails:SetPoint("TOPLEFT", infoLabel, "BOTTOMLEFT", 0, -6)
  aboutDetails:SetWidth(560)
  aboutDetails:SetJustifyH("LEFT")
  aboutDetails:SetText("")
  editor.aboutDetails = aboutDetails

  local aboutErrorsFrame = CreateFrame("Frame", nil, aboutContent)
  aboutErrorsFrame:SetAllPoints(aboutContent)
  aboutErrorsFrame:Hide()
  editor.aboutErrorsFrame = aboutErrorsFrame

  local errLabel = MakeAboutTitle(aboutErrorsFrame, "Errors", 0, 0)

  local statusIcon = aboutErrorsFrame:CreateTexture(nil, "ARTWORK")
  statusIcon:SetSize(18, 18)
  statusIcon:SetPoint("TOPLEFT", errLabel, "BOTTOMLEFT", 0, -10)
  editor.aboutStatusIcon = statusIcon

  local statusText = aboutErrorsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
  statusText:SetPoint("LEFT", statusIcon, "RIGHT", 6, 0)
  statusText:SetText("")
  editor.aboutStatusText = statusText

  local aboutErrors = aboutErrorsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  aboutErrors:SetPoint("TOPLEFT", statusIcon, "BOTTOMLEFT", 0, -10)
  aboutErrors:SetWidth(560)
  aboutErrors:SetJustifyH("LEFT")
  aboutErrors:SetText("")
  editor.aboutErrors = aboutErrors

  local errorLogBtn = CreateFrame("Button", nil, aboutErrorsFrame, "UIPanelButtonTemplate")
  errorLogBtn:SetSize(120, 20)
  errorLogBtn:SetPoint("TOPLEFT", aboutErrors, "BOTTOMLEFT", 0, -8)
  errorLogBtn:SetText("ErrorLog")
  errorLogBtn:SetScript("OnClick", function()
    ShowErrorLogWindow()
  end)
  editor.errorLogBtn = errorLogBtn

  local aboutSilentFrame = CreateFrame("Frame", nil, aboutContent)
  aboutSilentFrame:SetAllPoints(aboutContent)
  aboutSilentFrame:Hide()
  editor.aboutSilentFrame = aboutSilentFrame

  local silentLabel = MakeAboutTitle(aboutSilentFrame, "Silent Errors", 0, 0)

  local aboutSilent = aboutSilentFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  aboutSilent:SetPoint("TOPLEFT", silentLabel, "BOTTOMLEFT", 0, -4)
  aboutSilent:SetWidth(560)
  aboutSilent:SetJustifyH("LEFT")
  aboutSilent:SetText("")
  editor.aboutSilent = aboutSilent

  local silentLogBtn = CreateFrame("Button", nil, aboutSilentFrame, "UIPanelButtonTemplate")
  silentLogBtn:SetSize(140, 20)
  silentLogBtn:SetPoint("TOPLEFT", aboutSilent, "BOTTOMLEFT", 0, -8)
  silentLogBtn:SetText("SilentErrorLog")
  silentLogBtn:SetScript("OnClick", function()
    ShowSilentLogWindow()
  end)
  editor.silentLogBtn = silentLogBtn

  local aboutUpdatesFrame = CreateFrame("Frame", nil, aboutContent)
  aboutUpdatesFrame:SetAllPoints(aboutContent)
  aboutUpdatesFrame:Hide()
  editor.aboutUpdatesFrame = aboutUpdatesFrame

  local updatesHeader = MakeAboutTitle(aboutUpdatesFrame, "Changelog", 0, 0)

  local aboutUpdates = aboutUpdatesFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  aboutUpdates:SetPoint("TOPLEFT", updatesHeader, "BOTTOMLEFT", 0, -4)
  aboutUpdates:SetWidth(560)
  aboutUpdates:SetJustifyH("LEFT")
  aboutUpdates:SetText("")
  aboutUpdates:Hide()
  editor.aboutUpdates = aboutUpdates

  local updatesContainer = CreateFrame("Frame", nil, aboutUpdatesFrame)
  updatesContainer:SetPoint("TOPLEFT", updatesHeader, "BOTTOMLEFT", 0, -8)
  updatesContainer:SetPoint("TOPRIGHT", aboutUpdatesFrame, "TOPRIGHT", -10, -8)
  updatesContainer:SetHeight(10)
  editor.aboutUpdatesContainer = updatesContainer

  local CHANGELOG_ENTRIES = {
    {
      version = "Version 1.0.2 [Editor / Workflow polish] - 2026-04-23",
      sections = {
        { title = "Dropdowns", bullets = {
            "Optimized the long dropdown menus with the new custom dropdown style",
            "Restyled the dropdowns to match the LidPanels purple theme",
            "Fixed the custom-background dropdown paging/scroll bleed bug",
            "Sorted custom backgrounds alphabetically in the panel dropdown",
        } },
        { title = "UI Settings / Minimap", bullets = {
            "Fixed minimap icon hover-only visibility bug",
            "Updated the minimap visibility wording in UI Settings",
        } },
        { title = "Grouping", bullets = {
            "Added profile grouping with drag-and-drop, collapse/expand, and group rename/delete management",
            "Added category grouping in My Backgrounds with drag-and-drop and group management",
        } },
        { title = "My Backgrounds", bullets = {
            "Added rename/delete category actions in the details pane",
            "Started drag-and-drop moving of backgrounds into another category",
            "Improved drag-and-drop feedback and kept the source category selected after moving",
        } },
        { title = "Panels", bullets = {
            "Copy Panel now supports selecting a target profile",
            "Added paging to the Copy Panel target-profile dropdown for long profile lists",
        } },
        { title = "Editor / About", bullets = {
            "Updated addon version metadata to 1.0.2",
            "Updated WoW client metadata to 12.0.5 (Build 67451)",
        } },
      },
    },
    {
      version = "Version 1.0.1 [UserMedia Migration] - 2026-03-08",
      sections = {
        { title = "Media Path", bullets = {
            "Custom backgrounds now load from AddOns/LidPanels_UserMedia/Your_Backgrounds",
            "Removed old LidPanels/Media/Your_Backgrounds path usage",
        } },
        { title = "Bugfixes", bullets = {
            "My Collection can now be deleted permanently (it no longer reappears after /reload)",
        } },
        { title = "Packaging", bullets = {
            "LidPanels_UserMedia is now an optional dependency (LidPanels still works without it)",
            "Added placeholder guidance file in LidPanels_UserMedia/Your_Backgrounds",
        } },
      },
    },
    {
      version = "Version 1.0.0 [Release build] - 2026-03-01",
      notes = {
        "All stress and performance tests passed",
        "Promoted to stable",
        "Public release (tested)",
        "Stability verified - ready for live environments",
        "Tested and validated for production",
      },
    },
    { version = "Version 0.9 [BETA]", notes = { "Product test by developer" } },
    {
      version = "Version 0.8 [BETA]",
      notes = {
        "Polishing LidPanels",
        "First stresstest",
      },
    },
    {
      version = "Version 0.7 [BETA]",
      sections = {
        { title = "Editor / UI", bullets = {
            "Small layout changes for better visibility",
            "Small features for Import/Export",
            "Small text modifications",
        } },
        { title = "Panels", bullets = {
            "Added Texture Selection",
            "Added Icon Selection",
            "Added Model Selection",
            "Small layout changes for better visibility",
        } },
        { title = "Tutorial", bullets = {
            "Added Tutorial for Add image into folder",
            "Updated Tutorial for My Backgrounds",
        } },
      },
    },
    { version = "Version 0.6 [BETA]", notes = { "Product test by developer" } },
    {
      version = "Version 0.5 [BETA]",
      sections = {
        { title = "Core", bullets = {
            "Reduced addon-interaction risk by scoping popup hooks and debug tracing",
            "Added developer-mode-only diagnostics behavior for debug and silent tracing",
            "Added capped debug buffers (info/errors/silent) to avoid unbounded growth",
        } },
        { title = "Editor / About", bullets = {
            "Updated version and client metadata to 12.0.1 (Build 65940)",
            "Standardized Developer Mode naming and related labels",
        } },
      },
    },
    {
      version = "Version 0.4 [BETA]",
      sections = {
        { title = "Editor", bullets = {
            "Added icon picker",
            "Added custom backgrounds manager",
            "Added custom backgrounds",
            "Finalized UI",
            "Fixed minor bugs",
            "Finalized profiles",
            "Finalized panels",
        } },
        { title = "Panels", bullets = { "Added custom background support" } },
        { title = "Tutorials", bullets = { "Added custom background tutorial" } },
        { title = "UI Settings", bullets = { "Added minimap transparency" } },
        { title = "About", bullets = { "Added status summaries" } },
      },
    },
    {
      version = "Version 0.3 [BETA]",
      sections = {
        { title = "Editor", bullets = {
            "Added multi-skin editor",
            "Added themed logos",
            "Added header backgrounds",
            "Added custom design",
        } },
        { title = "Profiles", bullets = {
            "Added full profile system",
            "Added create/rename/copy/delete",
            "Added import/export",
            "Added profile per character",
            "Added spec-based profiles",
            "Added automatic spec switch",
        } },
        { title = "Panels", bullets = {
            "Added full panel editor",
            "Added 1 color / 2 color / background",
            "Added border styles",
        } },
        { title = "Tutorials", bullets = {
            "Added profile tutorial",
            "Added panel tutorial",
        } },
        { title = "UI Settings", bullets = { "Added minimap icon size" } },
        { title = "About", bullets = {
            "Added loaded components",
            "Added errors",
            "Added silent errors",
            "Added changelog",
        } },
      },
    },
  }

  local updatesLines = {}
  local updatesDividers = {}

  local function GetUpdatesLine(index)
    local fs = updatesLines[index]
    if not fs then
      fs = updatesContainer:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
      fs:SetJustifyH("LEFT")
      updatesLines[index] = fs
    end
    return fs
  end

  local function GetUpdatesDivider(index)
    local tx = updatesDividers[index]
    if not tx then
      tx = updatesContainer:CreateTexture(nil, "ARTWORK")
      tx:SetColorTexture(1, 1, 1, 0.14)
      tx:SetHeight(1)
      updatesDividers[index] = tx
    end
    return tx
  end

  local function HideUnusedUpdates(fromLine, fromDivider)
    for i = fromLine, #updatesLines do updatesLines[i]:Hide() end
    for i = fromDivider, #updatesDividers do updatesDividers[i]:Hide() end
  end

  local function UpdateChangelogText()
    local width = (aboutContent:GetWidth() or 560) - 14
    if width < 220 then width = 220 end
    local lineIndex, dividerIndex, y = 1, 1, 0

    for _, entry in ipairs(CHANGELOG_ENTRIES) do
      local divider = GetUpdatesDivider(dividerIndex); dividerIndex = dividerIndex + 1
      divider:ClearAllPoints()
      divider:SetPoint("TOPLEFT", updatesContainer, "TOPLEFT", 0, y)
      divider:SetWidth(width)
      divider:Show()
      y = y - 12

      local versionLine = GetUpdatesLine(lineIndex); lineIndex = lineIndex + 1
      versionLine:ClearAllPoints()
      versionLine:SetPoint("TOPLEFT", updatesContainer, "TOPLEFT", 0, y)
      versionLine:SetWidth(width)
      versionLine:SetText(entry.version or "")
      local vf, _, vflags = versionLine:GetFont()
      versionLine:SetFont(vf, 16, vflags)
      versionLine:SetTextColor(ABOUT_TITLE_R, ABOUT_TITLE_G, ABOUT_TITLE_B, ABOUT_TITLE_A)
      versionLine:Show()
      y = y - (versionLine:GetStringHeight() + 8)

      for _, note in ipairs(entry.notes or {}) do
        local noteLine = GetUpdatesLine(lineIndex); lineIndex = lineIndex + 1
        noteLine:ClearAllPoints()
        noteLine:SetPoint("TOPLEFT", updatesContainer, "TOPLEFT", 8, y)
        noteLine:SetWidth(width - 8)
        noteLine:SetText(string.char(226, 128, 162) .. " " .. tostring(note))
        local nf, _, nflags = noteLine:GetFont()
        noteLine:SetFont(nf, 13, nflags)
        noteLine:SetTextColor(0.9, 0.9, 0.9, 1)
        noteLine:Show()
        y = y - (noteLine:GetStringHeight() + 2)
      end

      for _, section in ipairs(entry.sections or {}) do
        local sectionLine = GetUpdatesLine(lineIndex); lineIndex = lineIndex + 1
        sectionLine:ClearAllPoints()
        sectionLine:SetPoint("TOPLEFT", updatesContainer, "TOPLEFT", 0, y)
        sectionLine:SetWidth(width)
        sectionLine:SetText(section.title or "")
        local sf, _, sflags = sectionLine:GetFont()
        sectionLine:SetFont(sf, 14, sflags)
        sectionLine:SetTextColor(ABOUT_TITLE_R, ABOUT_TITLE_G, ABOUT_TITLE_B, ABOUT_TITLE_A)
        sectionLine:Show()
        y = y - (sectionLine:GetStringHeight() + 4)

        for _, bulletText in ipairs(section.bullets or {}) do
          local bulletLine = GetUpdatesLine(lineIndex); lineIndex = lineIndex + 1
          bulletLine:ClearAllPoints()
          bulletLine:SetPoint("TOPLEFT", updatesContainer, "TOPLEFT", 8, y)
          bulletLine:SetWidth(width - 8)
          bulletLine:SetText(string.char(226, 128, 162) .. " " .. tostring(bulletText))
          local bf, _, bflags = bulletLine:GetFont()
          bulletLine:SetFont(bf, 13, bflags)
          bulletLine:SetTextColor(0.9, 0.9, 0.9, 1)
          bulletLine:Show()
          y = y - (bulletLine:GetStringHeight() + 2)
        end
        y = y - 6
      end
      y = y - 8
    end

    HideUnusedUpdates(lineIndex, dividerIndex)
    updatesContainer:SetHeight(math.max(40, -y + 6))
  end

  local function UpdateAboutUpdatesLayout()
    if not aboutContent or not updatesContainer then return end
    if editor and editor.aboutSection and editor.aboutSection ~= "Updates" then return end
    UpdateChangelogText()
    local h = updatesContainer:GetHeight() or 400
    if editor and editor.SetAboutContentHeight then
      editor:SetAboutContentHeight(math.max(520, math.floor(h + 140)))
    end
  end
  editor.UpdateAboutUpdatesLayout = UpdateAboutUpdatesLayout
  SafeHookScript(aboutUpdatesFrame, "OnShow", UpdateAboutUpdatesLayout)
  SafeHookScript(aboutContent, "OnSizeChanged", UpdateAboutUpdatesLayout)

  CreateAboutFAQSection(editor, aboutContent, {
    MakeAboutTitle = MakeAboutTitle,
    SafeHookScript = SafeHookScript,
    titleColor = { ABOUT_TITLE_R, ABOUT_TITLE_G, ABOUT_TITLE_B, ABOUT_TITLE_A },
  })

  CreateAboutUtilitySections(editor, aboutContent, {
    MakeAboutTitle = MakeAboutTitle,
    MakeYellowSubHeader = MakeYellowSubHeader,
    RootDB = RootDB,
    SafeHookScript = SafeHookScript,
    titleColor = { ABOUT_TITLE_R, ABOUT_TITLE_G, ABOUT_TITLE_B, ABOUT_TITLE_A },
  })

  function editor:ShowAboutSection(which)
    self.aboutSection = which or "Overview"
    if self.aboutOverview then self.aboutOverview:SetShown(self.aboutSection == "Overview") end
    if self.aboutLoaded then self.aboutLoaded:SetShown(self.aboutSection == "Loaded") end
    if self.aboutErrorsFrame then self.aboutErrorsFrame:SetShown(self.aboutSection == "Errors") end
    if self.aboutSilentFrame then self.aboutSilentFrame:SetShown(self.aboutSection == "Silent") end
    if self.aboutUpdatesFrame then self.aboutUpdatesFrame:SetShown(self.aboutSection == "Updates") end
    if self.aboutFAQFrame then self.aboutFAQFrame:SetShown(self.aboutSection == "FAQ") end
    if self.aboutCreditsFrame then self.aboutCreditsFrame:SetShown(self.aboutSection == "Credits") end
    if self.aboutStressFrame then self.aboutStressFrame:SetShown(self.aboutSection == "Stresstest") end
    if self.aboutTutorialImagesFrame then self.aboutTutorialImagesFrame:SetShown(self.aboutSection == "TutorialImages") end
    if self.aboutDeveloperFrame then self.aboutDeveloperFrame:SetShown(self.aboutSection == "Developer") end

    if self.aboutSection == "Updates" and self.UpdateAboutUpdatesLayout then
      self:UpdateAboutUpdatesLayout()
    end
    if self.aboutSection == "Overview" and self.UpdateAboutOverviewLayout then
      self:UpdateAboutOverviewLayout()
    end
    if self.aboutSection == "FAQ" then
      if self.UpdateFAQText then self:UpdateFAQText() end
      if self.UpdateAboutFAQLayout then self:UpdateAboutFAQLayout() end
    end
    if self.aboutSection == "Credits" and self.UpdateAboutCreditsLayout then
      self:UpdateAboutCreditsLayout()
    end
    if self.aboutSection == "Stresstest" and self.UpdateAboutStressLayout then
      self:UpdateAboutStressLayout()
    end
    if self.aboutSection == "TutorialImages" then
      if self.RefreshTutorialImagesSection then self:RefreshTutorialImagesSection() end
      if self.UpdateAboutTutorialImagesLayout then self:UpdateAboutTutorialImagesLayout() end
    end
    if self.aboutSection == "Developer" then
      if self.RefreshDeveloperSection then self:RefreshDeveloperSection() end
      if self.UpdateAboutDeveloperLayout then self:UpdateAboutDeveloperLayout() end
    end
  end

  aboutNavLoadedBtn:SetScript("OnClick", function()
    if editor and editor.ShowAboutSection then editor:ShowAboutSection("Loaded") end
  end)
  aboutNavErrorsBtn:SetScript("OnClick", function()
    if editor and editor.ShowAboutSection then editor:ShowAboutSection("Errors") end
  end)
  aboutNavSilentBtn:SetScript("OnClick", function()
    if editor and editor.ShowAboutSection then editor:ShowAboutSection("Silent") end
  end)
  aboutNavUpdatesBtn:SetScript("OnClick", function()
    if editor and editor.ShowAboutSection then editor:ShowAboutSection("Updates") end
  end)
  aboutNavFaqBtn:SetScript("OnClick", function()
    if editor and editor.ShowAboutSection then editor:ShowAboutSection("FAQ") end
  end)
  aboutNavCreditsBtn:SetScript("OnClick", function()
    if editor and editor.ShowAboutSection then editor:ShowAboutSection("Credits") end
  end)
  aboutNavStressBtn:SetScript("OnClick", function()
    if editor and editor.ShowAboutSection then editor:ShowAboutSection("Stresstest") end
  end)
  aboutNavTutorialImagesBtn:SetScript("OnClick", function()
    if editor and editor.ShowAboutSection then editor:ShowAboutSection("TutorialImages") end
  end)
  aboutNavDeveloperBtn:SetScript("OnClick", function()
    if editor and editor.ShowAboutSection then editor:ShowAboutSection("Developer") end
  end)
end

INTERNAL_API.LIDPANELS_BuildAboutPage_Impl = BuildAboutPage
