-- Core/Pages/Search.lua - ArenaCore's unique search implementation
-- Custom algorithm and architecture - completely original

local AC = _G.ArenaCore
if not AC then return end

-- Get localized strings
local L = AC.UILocalization
if not L then
    L = setmetatable({}, {
        __index = function(t, k)
            return k -- Fallback to key if localization not available
        end
    })
end

-- Helper function to get localized string
local function GetLocalizedString(section, key, fallback)
    if L and type(L.Get) == "function" then
        return L:Get(section, key, fallback)
    end
    return fallback or key
end

-- ArenaCore's unique color palette
local THEME = AC.COLORS or {
    PRIMARY      = {0.545, 0.271, 1.000, 1},
    TEXT         = {1,1,1,1},
    TEXT_2       = {0.706,0.706,0.706,1},
    TEXT_MUTED   = {0.5,0.5,0.5,1},
    INPUT_DARK   = {0.102, 0.102, 0.102, 1},
    BORDER       = {0.196, 0.196, 0.196, 1},
    BORDER_LIGHT = {0.278, 0.278, 0.278, 1},
    BG           = {0.200, 0.200, 0.200, 1},
}

local FONT_PATH = AC.FONT_PATH or "Interface/AddOns/ArenaCore/Media/Fonts/arenacore.ttf"

-- Custom state management system
local SearchState = {
    query = "",
    results = {},
    isSearching = false,
    lastSearchTime = 0,
    searchHistory = {},
    currentIndex = 0,
}

-- Persistent global state
AC.SearchState = AC.SearchState or SearchState

---------------------------------------------------------------------------
-- ARENACORE CUSTOM SEARCH ALGORITHM
-- Uses fuzzy matching with custom scoring system
---------------------------------------------------------------------------

-- Custom search catalog with enhanced metadata
local SearchCatalog = {
    -- Arena Frames
    {id = "arena_scale", label = "Frame Scale", category = "Arena Frames", keywords = {"scale", "size", "arena", "frames"}, page = "ArenaFrames", weight = 100, description = "Adjust the overall size of arena frames"},
    {id = "arena_width", label = "Frame Width", category = "Arena Frames", keywords = {"width", "size", "arena", "frames"}, page = "ArenaFrames", weight = 95, description = "Adjust arena frame width"},
    {id = "arena_height", label = "Frame Height", category = "Arena Frames", keywords = {"height", "size", "arena", "frames"}, page = "ArenaFrames", weight = 95, description = "Adjust arena frame height"},
    {id = "health_texture", label = "Health Bar Texture", category = "Arena Frames", keywords = {"health", "texture", "bar", "statusbar"}, page = "ArenaFrames", weight = 90, description = "Visual texture for health bars"},
    {id = "health_color", label = "Health Bar Color", category = "Arena Frames", keywords = {"health", "color", "bar", "class"}, page = "ArenaFrames", weight = 90, description = "Health bar color settings"},
    {id = "health_format", label = "Health Text Format", category = "Arena Frames", keywords = {"health", "text", "format", "percentage"}, page = "ArenaFrames", weight = 85, description = "How health values are displayed"},
    {id = "mana_texture", label = "Mana Bar Texture", category = "Arena Frames", keywords = {"mana", "texture", "bar", "power", "resource"}, page = "ArenaFrames", weight = 90, description = "Visual texture for mana/power bars"},
    {id = "mana_color", label = "Mana Bar Color", category = "Arena Frames", keywords = {"mana", "color", "bar", "power", "resource"}, page = "ArenaFrames", weight = 90, description = "Mana/power bar color settings"},
    {id = "mana_format", label = "Mana Text Format", category = "Arena Frames", keywords = {"mana", "text", "format", "percentage", "power"}, page = "ArenaFrames", weight = 85, description = "How mana/power values are displayed"},
    {id = "cast_settings", label = "Cast Bar Settings", category = "Arena Frames", keywords = {"cast", "bar", "casting", "spell", "channel"}, page = "ArenaFrames", weight = 88, description = "Enemy cast bar display options"},
    {id = "class_icons", label = "Class Icons", category = "Arena Frames", keywords = {"class", "icon", "portrait", "spec"}, page = "ArenaFrames", weight = 92, description = "Class and specialization icon display"},
    {id = "trinket_display", label = "Trinket Display", category = "Arena Frames", keywords = {"trinket", "pvp", "cooldown", "icon"}, page = "ArenaFrames", weight = 93, description = "PvP trinket tracking and display"},
    {id = "racial_display", label = "Racial Display", category = "Arena Frames", keywords = {"racial", "cooldown", "ability", "icon"}, page = "ArenaFrames", weight = 93, description = "Racial ability tracking and display"},
    {id = "dr_icons", label = "DR Icons", category = "Arena Frames", keywords = {"dr", "diminishing", "returns", "cc", "stun"}, page = "ArenaFrames", weight = 91, description = "Diminishing returns icon display"},
    {id = "target_highlight", label = "Target Highlight", category = "Arena Frames", keywords = {"target", "highlight", "border", "glow"}, page = "ArenaFrames", weight = 87, description = "Visual highlight for your current target"},

    -- Diminishing Returns
    {id = "dr_size", label = "DR Icon Size", category = "Diminishing Returns", keywords = {"dr", "size", "scale", "diminishing", "returns"}, page = "DiminishingReturns", weight = 94, description = "Adjust size of DR icons"},
    {id = "dr_spacing", label = "DR Icon Spacing", category = "Diminishing Returns", keywords = {"dr", "spacing", "gap", "diminishing", "returns"}, page = "DiminishingReturns", weight = 89, description = "Space between DR icons"},
    {id = "dr_growth", label = "DR Growth Direction", category = "Diminishing Returns", keywords = {"dr", "growth", "direction", "layout"}, page = "DiminishingReturns", weight = 88, description = "Which way DR icons expand"},
    {id = "dr_stacking", label = "DR Stacking Mode", category = "Diminishing Returns", keywords = {"dr", "stacking", "layout", "rows"}, page = "DiminishingReturns", weight = 86, description = "Single row vs stacked layout"},
    {id = "dr_dynamic", label = "DR Dynamic Positioning", category = "Diminishing Returns", keywords = {"dr", "dynamic", "positioning", "collapse"}, page = "DiminishingReturns", weight = 87, description = "Collapse gaps when categories disabled"},
    {id = "dr_categories", label = "DR Categories", category = "Diminishing Returns", keywords = {"dr", "categories", "stun", "silence", "root", "disorient"}, page = "DiminishingReturns", weight = 90, description = "Enable/disable specific DR categories"},

    -- Trinkets/Other
    {id = "trinket_size", label = "Trinket Icon Size", category = "Trinkets/Other", keywords = {"trinket", "size", "scale", "icon"}, page = "TrinketsOther", weight = 92, description = "Adjust trinket icon size"},
    {id = "trinket_position", label = "Trinket Position", category = "Trinkets/Other", keywords = {"trinket", "position", "location"}, page = "TrinketsOther", weight = 89, description = "Where trinket icons appear"},
    {id = "trinket_style", label = "Trinket Display Style", category = "Trinkets/Other", keywords = {"trinket", "style", "design", "horde", "alliance"}, page = "TrinketsOther", weight = 91, description = "Trinket icon visual style"},
    {id = "racial_size", label = "Racial Icon Size", category = "Trinkets/Other", keywords = {"racial", "size", "scale", "icon"}, page = "TrinketsOther", weight = 92, description = "Adjust racial icon size"},
    {id = "racial_position", label = "Racial Position", category = "Trinkets/Other", keywords = {"racial", "position", "location"}, page = "TrinketsOther", weight = 89, description = "Where racial icons appear"},

    -- Class Packs
    {id = "classpack_enable", label = "Class Pack Enable", category = "Class Packs", keywords = {"class", "pack", "enable", "tribadges"}, page = "ClassPacks", weight = 95, description = "Enable/disable class pack system"},
    {id = "classpack_position", label = "Class Pack Position", category = "Class Packs", keywords = {"class", "pack", "position", "location"}, page = "ClassPacks", weight = 88, description = "Where class pack icons appear"},
    {id = "classpack_size", label = "Class Pack Size", category = "Class Packs", keywords = {"class", "pack", "size", "scale", "icon"}, page = "ClassPacks", weight = 91, description = "Adjust class pack icon size"},
    {id = "classpack_editor", label = "Class Pack Editor", category = "Class Packs", keywords = {"class", "pack", "editor", "customize", "spells"}, page = "ClassPacks", weight = 93, description = "Customize spell configurations for each class"},
    
    -- Class-specific spell configurations
    {id = "warrior_spells", label = "Warrior Spells", category = "Class Packs > Editor", keywords = {"warrior", "spells", "class", "pack"}, page = "ClassPacks", weight = 85, description = "Configure Warrior class pack spells"},
    {id = "paladin_spells", label = "Paladin Spells", category = "Class Packs > Editor", keywords = {"paladin", "spells", "class", "pack"}, page = "ClassPacks", weight = 85, description = "Configure Paladin class pack spells"},
    {id = "hunter_spells", label = "Hunter Spells", category = "Class Packs > Editor", keywords = {"hunter", "spells", "class", "pack"}, page = "ClassPacks", weight = 85, description = "Configure Hunter class pack spells"},
    {id = "rogue_spells", label = "Rogue Spells", category = "Class Packs > Editor", keywords = {"rogue", "spells", "class", "pack"}, page = "ClassPacks", weight = 85, description = "Configure Rogue class pack spells"},
    {id = "priest_spells", label = "Priest Spells", category = "Class Packs > Editor", keywords = {"priest", "spells", "class", "pack"}, page = "ClassPacks", weight = 85, description = "Configure Priest class pack spells"},
    {id = "shaman_spells", label = "Shaman Spells", category = "Class Packs > Editor", keywords = {"shaman", "spells", "class", "pack"}, page = "ClassPacks", weight = 85, description = "Configure Shaman class pack spells"},
    {id = "mage_spells", label = "Mage Spells", category = "Class Packs > Editor", keywords = {"mage", "spells", "class", "pack"}, page = "ClassPacks", weight = 85, description = "Configure Mage class pack spells"},
    {id = "warlock_spells", label = "Warlock Spells", category = "Class Packs > Editor", keywords = {"warlock", "spells", "class", "pack"}, page = "ClassPacks", weight = 85, description = "Configure Warlock class pack spells"},
    {id = "monk_spells", label = "Monk Spells", category = "Class Packs > Editor", keywords = {"monk", "spells", "class", "pack"}, page = "ClassPacks", weight = 85, description = "Configure Monk class pack spells"},
    {id = "druid_spells", label = "Druid Spells", category = "Class Packs > Editor", keywords = {"druid", "spells", "class", "pack"}, page = "ClassPacks", weight = 85, description = "Configure Druid class pack spells"},
    {id = "dh_spells", label = "Demon Hunter Spells", category = "Class Packs > Editor", keywords = {"demon", "hunter", "spells", "class", "pack"}, page = "ClassPacks", weight = 85, description = "Configure Demon Hunter class pack spells"},
    {id = "dk_spells", label = "Death Knight Spells", category = "Class Packs > Editor", keywords = {"death", "knight", "spells", "class", "pack"}, page = "ClassPacks", weight = 85, description = "Configure Death Knight class pack spells"},
    {id = "evoker_spells", label = "Evoker Spells", category = "Class Packs > Editor", keywords = {"evoker", "spells", "class", "pack"}, page = "ClassPacks", weight = 85, description = "Configure Evoker class pack spells"},

    -- More Goodies
    {id = "debuffs_enable", label = "Debuffs Enable", category = "More Goodies", keywords = {"debuffs", "enable", "show", "icons"}, page = "MoreGoodies", weight = 90, description = "Enable/disable debuff display"},
    {id = "debuffs_max", label = "Max Debuffs", category = "More Goodies", keywords = {"debuffs", "max", "count", "limit"}, page = "MoreGoodies", weight = 84, description = "Maximum number of debuffs to show"},
    {id = "debuffs_position", label = "Debuffs Position", category = "More Goodies", keywords = {"debuffs", "position", "location", "x", "y"}, page = "MoreGoodies", weight = 86, description = "Where debuff icons appear"},
    {id = "debuffs_scale", label = "Debuffs Scale", category = "More Goodies", keywords = {"debuffs", "scale", "size", "icons"}, page = "MoreGoodies", weight = 87, description = "Adjust debuff icon size"},
    {id = "debuffs_growth", label = "Debuffs Growth", category = "More Goodies", keywords = {"debuffs", "growth", "direction", "layout"}, page = "MoreGoodies", weight = 85, description = "Which way debuff icons expand"},
    {id = "debuffs_spacing", label = "Debuffs Spacing", category = "More Goodies", keywords = {"debuffs", "spacing", "gap", "icons"}, page = "MoreGoodies", weight = 83, description = "Space between debuff icons"},
    
    {id = "blackout_enable", label = "Blackout Enable", category = "More Goodies > Blackout", keywords = {"blackout", "enable", "defensive", "cooldowns"}, page = "MoreGoodies", weight = 92, description = "Enable/disable blackout feature"},
    {id = "blackout_color", label = "Blackout Color", category = "More Goodies > Blackout", keywords = {"blackout", "color", "background"}, page = "MoreGoodies", weight = 88, description = "Blackout background color"},
    {id = "blackout_duration", label = "Blackout Duration", category = "More Goodies > Blackout", keywords = {"blackout", "duration", "time"}, page = "MoreGoodies", weight = 86, description = "How long blackout lasts"},
    {id = "nameplate_gcd", label = "Nameplate GCD", category = "More Goodies > Nameplate GCD", keywords = {"nameplate", "gcd", "cooldown", "tracker"}, page = "MoreGoodies", weight = 89, description = "GCD tracking on nameplates"},
    {id = "party_class", label = "Party Class Indicators", category = "More Goodies > Party Class Indicators", keywords = {"party", "class", "icons", "indicators"}, page = "MoreGoodies", weight = 91, description = "Class icons on party frames"},
    {id = "dispel_tracker", label = "Dispel Tracker", category = "More Goodies > Dispel Tracker", keywords = {"dispel", "tracker", "cooldown", "healer"}, page = "MoreGoodies", weight = 90, description = "Track enemy dispel cooldowns"},
    {id = "absorbs_display", label = "Absorbs Display", category = "More Goodies > Absorbs", keywords = {"absorbs", "shields", "absorption"}, page = "MoreGoodies", weight = 87, description = "Show absorption shields on frames"},

    -- Misc/General Features
    {id = "portrait_swap", label = "Class Portrait Swap", category = "Misc", keywords = {"class", "portrait", "swap", "player", "target"}, page = "Misc", weight = 93, description = "Replace portraits with class icons"},
    {id = "achievement_unlocks", label = "Achievement Unlocks", category = "Misc", keywords = {"achievement", "unlocks", "rewards", "themes"}, page = "Misc", weight = 89, description = "Unlock features based on achievements"},
    {id = "tab_players", label = "Tab Players Only", category = "Misc", keywords = {"tab", "target", "players", "arena", "pvp"}, page = "Misc", weight = 85, description = "Tab-targeting only hits players in PvP"},
    {id = "queue_status", label = "Queue Status Tracker", category = "Misc", keywords = {"queue", "status", "tracker", "pvp", "arena"}, page = "Misc", weight = 86, description = "Show queue status and wait times"},
    {id = "chat_arena", label = "Chat In Arena", category = "Misc", keywords = {"chat", "arena", "hide", "pvp"}, page = "Misc", weight = 84, description = "Chat visibility in arena matches"},
    {id = "minimap_arena", label = "Minimap In Arena", category = "Misc", keywords = {"minimap", "arena", "hide", "pvp"}, page = "Misc", weight = 84, description = "Minimap visibility in arena matches"},
    {id = "dampening_display", label = "Dampening Display", category = "Misc", keywords = {"dampening", "arena", "percentage", "pvp"}, page = "Misc", weight = 87, description = "Show dampening percentage"},

    -- Frames/Nameplates
    {id = "party_scale", label = "Party Frame Scale", category = "Frames/Nameplates > Party Frames", keywords = {"party", "frame", "scale", "size"}, page = "frames", weight = 88, description = "Adjust party frame size"},
    {id = "party_castbars", label = "Party Cast Bars", category = "Frames/Nameplates > Party Frames", keywords = {"party", "cast", "bars", "casting"}, page = "frames", weight = 89, description = "Cast bars on party frames"},
    {id = "party_auras", label = "Party Buffs/Debuffs", category = "Frames/Nameplates > Party Frames", keywords = {"party", "buffs", "debuffs", "auras"}, page = "frames", weight = 87, description = "Buff and debuff display on party frames"},
    {id = "party_roles", label = "Party Role Icons", category = "Frames/Nameplates > Party Frames", keywords = {"party", "role", "icons", "tank", "healer"}, page = "frames", weight = 86, description = "Role icons on party frames"},
    {id = "nameplate_indicators", label = "Nameplate Indicators", category = "Frames/Nameplates > Nameplates", keywords = {"nameplate", "indicators", "icons", "enemy"}, page = "frames", weight = 90, description = "Visual indicators on nameplates"},

    -- Misc Features
    {id = "test_mode", label = "Test Mode", category = "Misc", keywords = {"test", "mode", "preview", "frames"}, page = "Misc", weight = 85, description = "Test arena frame appearance"},
    {id = "edit_mode", label = "Edit Mode", category = "Misc", keywords = {"edit", "mode", "drag", "position", "frames"}, page = "Misc", weight = 86, description = "Drag to reposition frame elements"},
    {id = "frame_lock", label = "Frame Lock", category = "Misc", keywords = {"lock", "frames", "position", "edit"}, page = "Misc", weight = 84, description = "Lock/unlock frame positions"},
    {id = "reset_positions", label = "Reset Positions", category = "Misc", keywords = {"reset", "positions", "default", "frames"}, page = "Misc", weight = 83, description = "Reset all frame positions to default"},

    -- Performance
    {id = "combat_filter", label = "Combat Log Filter", category = "Performance", keywords = {"combat", "log", "filter", "performance"}, page = "performance", weight = 87, description = "Filter combat log events for performance"},
    {id = "update_frequency", label = "Update Frequency", category = "Performance", keywords = {"update", "frequency", "performance", "fps"}, page = "performance", weight = 86, description = "How often frames update"},
    {id = "debug_mode", label = "Debug Mode", category = "Performance", keywords = {"debug", "mode", "testing", "development"}, page = "performance", weight = 82, description = "Enable debug output for troubleshooting"},

    -- Profiles
    {id = "profile_manage", label = "Profile Management", category = "Profiles", keywords = {"profile", "manage", "create", "delete"}, page = "Profiles", weight = 90, description = "Create, delete, and switch profiles"},
    {id = "profile_export", label = "Profile Export", category = "Profiles", keywords = {"profile", "export", "share", "string"}, page = "Profiles", weight = 88, description = "Export settings as shareable string"},
    {id = "profile_import", label = "Profile Import", category = "Profiles", keywords = {"profile", "import", "load", "string"}, page = "Profiles", weight = 88, description = "Import settings from shared string"},
    {id = "profile_auto", label = "Auto Profile Switch", category = "Profiles", keywords = {"profile", "auto", "switch", "spec"}, page = "Profiles", weight = 85, description = "Automatically switch profiles per spec"},

    -- Textures
    {id = "health_width", label = "Health Bar Width", category = "Textures", keywords = {"health", "bar", "width", "texture"}, page = "Textures", weight = 86, description = "Health bar texture width"},
    {id = "health_height", label = "Health Bar Height", category = "Textures", keywords = {"health", "bar", "height", "texture"}, page = "Textures", weight = 86, description = "Health bar texture height"},
    {id = "mana_width", label = "Mana Bar Width", category = "Textures", keywords = {"mana", "bar", "width", "texture", "power"}, page = "Textures", weight = 86, description = "Mana bar texture width"},
    {id = "mana_height", label = "Mana Bar Height", category = "Textures", keywords = {"mana", "bar", "height", "texture", "power"}, page = "Textures", weight = 86, description = "Mana bar texture height"},
    {id = "cast_width", label = "Cast Bar Width", category = "Textures", keywords = {"cast", "bar", "width", "texture"}, page = "Textures", weight = 86, description = "Cast bar texture width"},
    {id = "cast_height", label = "Cast Bar Height", category = "Textures", keywords = {"cast", "bar", "height", "texture"}, page = "Textures", weight = 86, description = "Cast bar texture height"},
    {id = "border_thickness", label = "Border Thickness", category = "Textures", keywords = {"border", "thickness", "outline"}, page = "Textures", weight = 84, description = "Thickness of frame borders"},

    -- General Settings
    {id = "ui_scale", label = "UI Scale", category = "Arena Frames > General", keywords = {"ui", "scale", "interface", "size"}, page = "ArenaFrames", weight = 87, description = "Overall UI scale adjustment"},
    {id = "font_settings", label = "Font Settings", category = "Arena Frames > General", keywords = {"font", "text", "size", "style"}, page = "ArenaFrames", weight = 85, description = "Font customization options"},
    {id = "color_settings", label = "Color Settings", category = "Arena Frames > General", keywords = {"color", "theme", "customization"}, page = "ArenaFrames", weight = 86, description = "Color customization options"},
}

-- Custom search algorithm with unique scoring system
local function ArenaCoreFuzzySearch(query)
    if not query or query:len() < 2 then
        return {}
    end
    
    local results = {}
    local lowerQuery = query:lower()
    local queryWords = {}
    for word in lowerQuery:gmatch("%S+") do
        queryWords[#queryWords + 1] = word
    end
    
    for _, item in ipairs(SearchCatalog) do
        local score = 0
        local matchFactors = {}
        
        -- Label matching (highest weight)
        local labelLower = item.label:lower()
        if labelLower == lowerQuery then
            score = score + 200
            matchFactors[#matchFactors + 1] = "exact_label"
        elseif labelLower:find(lowerQuery, 1, true) == 1 then
            score = score + 150
            matchFactors[#matchFactors + 1] = "starts_with_label"
        elseif labelLower:find(lowerQuery, 1, true) then
            score = score + 100
            matchFactors[#matchFactors + 1] = "contains_label"
        end
        
        -- Category matching
        local categoryLower = item.category:lower()
        if categoryLower:find(lowerQuery, 1, true) then
            score = score + 80
            matchFactors[#matchFactors + 1] = "category_match"
        end
        
        -- Keyword matching with multi-word support
        local keywordMatches = 0
        if item.keywords then
            for _, keyword in ipairs(item.keywords) do
                local keywordLower = keyword:lower()
                for _, queryWord in ipairs(queryWords) do
                    if keywordLower:find(queryWord, 1, true) then
                        keywordMatches = keywordMatches + 1
                        score = score + 40
                        matchFactors[#matchFactors + 1] = "keyword_" .. keyword
                        break
                    end
                end
            end
        end
        
        -- Description matching (lower weight)
        if item.description then
            local descLower = item.description:lower()
            if descLower:find(lowerQuery, 1, true) then
                score = score + 20
                matchFactors[#matchFactors + 1] = "description_match"
            end
        end
        
        -- Weight bonus
        score = score + (item.weight or 50)
        
        -- Multi-word bonus
        if keywordMatches >= #queryWords and #queryWords > 1 then
            score = score + 50
            matchFactors[#matchFactors + 1] = "multiword_bonus"
        end
        
        if score > 0 then
            results[#results + 1] = {
                entry = item,
                score = score,
                matchFactors = matchFactors
            }
        end
    end
    
    -- Custom sorting: score -> weight -> label
    table.sort(results, function(a, b)
        if a.score ~= b.score then
            return a.score > b.score
        end
        local weightA = a.entry.weight or 50
        local weightB = b.entry.weight or 50
        if weightA ~= weightB then
            return weightA > weightB
        end
        return a.entry.label < b.entry.label
    end)
    
    -- Limit results for performance
    local maxResults = 25
    if #results > maxResults then
        for i = maxResults + 1, #results do
            results[i] = nil
        end
    end
    
    return results
end

---------------------------------------------------------------------------
-- ARENACORE CUSTOM UI COMPONENTS
-- Unique visual design and interaction patterns
---------------------------------------------------------------------------

-- Custom search input widget with ArenaCore styling
local function CreateArenaCoreSearchInput(parent, width, onSearchCallback, onClearCallback)
    local widget = CreateFrame("Frame", nil, parent, "BackdropTemplate")
    widget:SetSize(width, 32)
    widget:SetBackdrop({
        bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
        edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
        tile = true, tileSize = 16, edgeSize = 1,
        insets = { left = 2, right = 2, top = 2, bottom = 2 },
    })
    widget:SetBackdropColor(THEME.INPUT_DARK[1], THEME.INPUT_DARK[2], THEME.INPUT_DARK[3], 0.95)
    widget:SetBackdropBorderColor(THEME.BORDER[1], THEME.BORDER[2], THEME.BORDER[3], 1)
    
    -- ArenaCore styled search icon
    local searchIcon = widget:CreateFontString(nil, "OVERLAY")
    if AC.SafeSetFont then
        AC.SafeSetFont(searchIcon, FONT_PATH, 12, "")
    else
        searchIcon:SetFont(FONT_PATH, 12, "")
    end
    searchIcon:SetPoint("LEFT", 10, 0)
    searchIcon:SetTextColor(THEME.TEXT_MUTED[1], THEME.TEXT_MUTED[2], THEME.TEXT_MUTED[3], 1)
    searchIcon:SetText("|TInterface\\AddOns\\ArenaCore\\Media\\UI\\search-icon.tga:16:16:0:0|t")
    
    -- Custom edit box
    local editBox = CreateFrame("EditBox", nil, widget)
    editBox:SetPoint("LEFT", 32, 0)
    editBox:SetPoint("RIGHT", widget, "RIGHT", -32, 0)
    editBox:SetHeight(20)
    editBox:SetAutoFocus(false)
    
    if AC.SafeSetFont then
        AC.SafeSetFont(editBox, FONT_PATH, 13, "")
    else
        editBox:SetFont(FONT_PATH, 13, "")
    end
    
    -- CRITICAL FIX: Force text color with multiple methods for visibility
    editBox:SetTextColor(1, 1, 1, 1)           -- White text
    editBox:SetFontObject(GameFontNormal)      -- Use standard font object
    editBox:SetTextColor(1, 1, 1, 1)           -- Set again after font object
    editBox:SetMaxLetters(60)
    
    -- Custom placeholder
    local placeholder = editBox:CreateFontString(nil, "OVERLAY")
    if AC.SafeSetFont then
        AC.SafeSetFont(placeholder, FONT_PATH, 12, "")
    else
        placeholder:SetFont(FONT_PATH, 12, "")
    end
    placeholder:SetPoint("LEFT", 2, 0)
    placeholder:SetTextColor(THEME.TEXT_MUTED[1], THEME.TEXT_MUTED[2], THEME.TEXT_MUTED[3], 0.7)
    placeholder:SetText(GetLocalizedString("SEARCH", "placeholder", "Search ArenaCore settings..."))
    
    -- ArenaCore styled clear button
    local clearButton = CreateFrame("Button", nil, widget)
    clearButton:SetSize(18, 18)
    clearButton:SetPoint("RIGHT", -8, 0)
    clearButton:Hide()
    
    local clearIcon = clearButton:CreateFontString(nil, "OVERLAY")
    if AC.SafeSetFont then
        AC.SafeSetFont(clearIcon, FONT_PATH, 14, "OUTLINE")
    else
        clearIcon:SetFont(FONT_PATH, 14, "OUTLINE")
    end
    clearIcon:SetPoint("CENTER", 0, 0)
    clearIcon:SetText("×")
    clearIcon:SetTextColor(THEME.TEXT_MUTED[1], THEME.TEXT_MUTED[2], THEME.TEXT_MUTED[3], 1)
    
    -- Custom hover effects
    clearButton:SetScript("OnEnter", function()
        clearIcon:SetTextColor(THEME.PRIMARY[1], THEME.PRIMARY[2], THEME.PRIMARY[3], 1)
        widget:SetBackdropBorderColor(THEME.PRIMARY[1], THEME.PRIMARY[2], THEME.PRIMARY[3], 0.8)
    end)
    
    clearButton:SetScript("OnLeave", function()
        clearIcon:SetTextColor(THEME.TEXT_MUTED[1], THEME.TEXT_MUTED[2], THEME.TEXT_MUTED[3], 1)
        widget:SetBackdropBorderColor(THEME.BORDER[1], THEME.BORDER[2], THEME.BORDER[3], 1)
    end)
    
    clearButton:SetScript("OnClick", function()
        editBox:SetText("")
        editBox:ClearFocus()
        if onClearCallback then onClearCallback() end
    end)
    
    -- Custom text change handler with ArenaCore debouncing
    local searchDelayTimer
    editBox:SetScript("OnTextChanged", function(self, userInput)
        if not userInput then return end
        
        local text = self:GetText()
        SearchState.query = text
        AC.SearchState.query = text
        
        -- Force text color (ArenaCore styling)
        self:SetTextColor(THEME.TEXT[1], THEME.TEXT[2], THEME.TEXT[3], 1)
        
        placeholder:SetShown(text == "")
        clearButton:SetShown(text ~= "")
        
        -- Cancel previous search
        if searchDelayTimer then
            searchDelayTimer:Cancel()
            searchDelayTimer = nil
        end
        
        if text:len() >= 2 then
            SearchState.isSearching = true
            -- ArenaCore custom debounce timing
            searchDelayTimer = C_Timer.NewTimer(0.25, function()
                SearchState.isSearching = false
                if onSearchCallback then onSearchCallback(text) end
            end)
        elseif text == "" then
            SearchState.results = {}
            AC.SearchState.results = {}
            if onClearCallback then onClearCallback() end
        end
    end)
    
    -- Custom focus effects
    editBox:SetScript("OnEditFocusGained", function()
        widget:SetBackdropBorderColor(THEME.PRIMARY[1], THEME.PRIMARY[2], THEME.PRIMARY[3], 1)
        searchIcon:SetTextColor(THEME.PRIMARY[1], THEME.PRIMARY[2], THEME.PRIMARY[3], 1)
        -- CRITICAL FIX: Ensure text stays white when focused
        editBox:SetTextColor(1, 1, 1, 1)
    end)
    
    editBox:SetScript("OnEditFocusLost", function()
        widget:SetBackdropBorderColor(THEME.BORDER[1], THEME.BORDER[2], THEME.BORDER[3], 1)
        searchIcon:SetTextColor(THEME.TEXT_MUTED[1], THEME.TEXT_MUTED[2], THEME.TEXT_MUTED[3], 1)
        -- CRITICAL FIX: Ensure text stays white when not focused
        editBox:SetTextColor(1, 1, 1, 1)
    end)
    
    editBox:SetScript("OnEscapePressed", function(self)
        self:SetText("")
        self:ClearFocus()
        if onClearCallback then onClearCallback() end
    end)
    
    editBox:SetScript("OnEnterPressed", function(self)
        self:ClearFocus()
    end)
    
    -- Store references
    widget.editBox = editBox
    widget.placeholder = placeholder
    widget.clearButton = clearButton
    widget.searchIcon = searchIcon
    
    return widget
end

-- Custom result card with ArenaCore styling
local function CreateArenaCoreResultCard(parent, item, yOffset, cardWidth)
    local card = CreateFrame("Frame", nil, parent, "BackdropTemplate")
    card:SetSize(cardWidth, 64)
    card:SetPoint("TOPLEFT", 0, yOffset)
    
    -- ArenaCore custom backdrop
    card:SetBackdrop({
        bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
        edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
        tile = true, tileSize = 16, edgeSize = 1,
        insets = { left = 2, right = 2, top = 2, bottom = 2 },
    })
    card:SetBackdropColor(THEME.BG[1], THEME.BG[2], THEME.BG[3], 0.9)
    card:SetBackdropBorderColor(THEME.BORDER_LIGHT[1], THEME.BORDER_LIGHT[2], THEME.BORDER_LIGHT[3], 1)
    
    -- Category badge
    local categoryBadge = card:CreateFontString(nil, "OVERLAY")
    if AC.SafeSetFont then
        AC.SafeSetFont(categoryBadge, FONT_PATH, 9, "")
    else
        categoryBadge:SetFont(FONT_PATH, 9, "")
    end
    categoryBadge:SetPoint("TOPRIGHT", -12, -8)
    categoryBadge:SetTextColor(THEME.PRIMARY[1], THEME.PRIMARY[2], THEME.PRIMARY[3], 0.9)
    categoryBadge:SetText(item.entry.category)
    categoryBadge:SetJustifyH("RIGHT")
    
    -- Result title
    local titleLabel = card:CreateFontString(nil, "OVERLAY")
    if AC.SafeSetFont then
        AC.SafeSetFont(titleLabel, FONT_PATH, 13, "")
    else
        titleLabel:SetFont(FONT_PATH, 13, "")
    end
    titleLabel:SetPoint("TOPLEFT", 14, -8)
    titleLabel:SetPoint("RIGHT", categoryBadge, "LEFT", -10, 0)
    titleLabel:SetTextColor(THEME.TEXT[1], THEME.TEXT[2], THEME.TEXT[3], 1)
    titleLabel:SetText(item.entry.label)
    titleLabel:SetJustifyH("LEFT")
    titleLabel:SetWordWrap(false)
    
    -- Description
    local descLabel = card:CreateFontString(nil, "OVERLAY")
    if AC.SafeSetFont then
        AC.SafeSetFont(descLabel, FONT_PATH, 10, "")
    else
        descLabel:SetFont(FONT_PATH, 10, "")
    end
    descLabel:SetPoint("TOPLEFT", 14, -28)
    descLabel:SetPoint("RIGHT", card, "RIGHT", -100, 0)
    descLabel:SetTextColor(THEME.TEXT_2[1], THEME.TEXT_2[2], THEME.TEXT_2[3], 1)
    descLabel:SetText(item.entry.description or "")
    descLabel:SetJustifyH("LEFT")
    descLabel:SetWordWrap(false)
    
    -- Score indicator (visual feedback)
    if item.score and item.score > 150 then
        local scoreIndicator = card:CreateTexture(nil, "ARTWORK")
        scoreIndicator:SetSize(4, 4)
        scoreIndicator:SetPoint("TOPLEFT", 8, -10)
        scoreIndicator:SetColorTexture(THEME.PRIMARY[1], THEME.PRIMARY[2], THEME.PRIMARY[3], 1)
    end
    
    -- ArenaCore styled action button
    local actionButton = CreateFrame("Button", nil, card, "BackdropTemplate")
    actionButton:SetSize(95, 28)
    actionButton:SetPoint("RIGHT", -10, 0)
    
    actionButton:SetBackdrop({
        bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
        edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
        tile = true, tileSize = 16, edgeSize = 1,
        insets = { left = 1, right = 1, top = 1, bottom = 1 },
    })
    actionButton:SetBackdropColor(THEME.PRIMARY[1], THEME.PRIMARY[2], THEME.PRIMARY[3], 0.2)
    actionButton:SetBackdropBorderColor(THEME.PRIMARY[1], THEME.PRIMARY[2], THEME.PRIMARY[3], 0.6)
    
    local actionText = actionButton:CreateFontString(nil, "OVERLAY")
    if AC.SafeSetFont then
        AC.SafeSetFont(actionText, FONT_PATH, 10, "")
    else
        actionText:SetFont(FONT_PATH, 10, "")
    end
    actionText:SetPoint("CENTER", 0, 0)
    actionText:SetText(GetLocalizedString("SEARCH", "navigate", "Navigate"))
    actionText:SetTextColor(THEME.TEXT[1], THEME.TEXT[2], THEME.TEXT[3], 1)
    
    -- Custom button interactions
    actionButton:SetScript("OnEnter", function()
        actionButton:SetBackdropColor(THEME.PRIMARY[1], THEME.PRIMARY[2], THEME.PRIMARY[3], 0.4)
        actionButton:SetBackdropBorderColor(THEME.PRIMARY[1], THEME.PRIMARY[2], THEME.PRIMARY[3], 1)
        actionText:SetTextColor(1, 1, 1, 1)
        card:SetBackdropBorderColor(THEME.PRIMARY[1], THEME.PRIMARY[2], THEME.PRIMARY[3], 0.8)
    end)
    
    actionButton:SetScript("OnLeave", function()
        actionButton:SetBackdropColor(THEME.PRIMARY[1], THEME.PRIMARY[2], THEME.PRIMARY[3], 0.2)
        actionButton:SetBackdropBorderColor(THEME.PRIMARY[1], THEME.PRIMARY[2], THEME.PRIMARY[3], 0.6)
        actionText:SetTextColor(THEME.TEXT[1], THEME.TEXT[2], THEME.TEXT[3], 1)
        card:SetBackdropBorderColor(THEME.BORDER_LIGHT[1], THEME.BORDER_LIGHT[2], THEME.BORDER_LIGHT[3], 1)
    end)
    
    actionButton:SetScript("OnClick", function()
        if item.entry.page and AC.ShowPage then
            AC:ShowPage(item.entry.page)
            if AC.UpdateNavigationForPage then
                AC:UpdateNavigationForPage(item.entry.page)
            end
        end
    end)
    
    -- Card hover effects
    card:EnableMouse(true)
    card:SetScript("OnEnter", function()
        card:SetBackdropColor(THEME.BG[1], THEME.BG[2], THEME.BG[3], 1)
        card:SetBackdropBorderColor(THEME.PRIMARY[1], THEME.PRIMARY[2], THEME.PRIMARY[3], 0.9)
    end)
    
    card:SetScript("OnLeave", function()
        card:SetBackdropColor(THEME.BG[1], THEME.BG[2], THEME.BG[3], 0.9)
        card:SetBackdropBorderColor(THEME.BORDER_LIGHT[1], THEME.BORDER_LIGHT[2], THEME.BORDER_LIGHT[3], 1)
    end)
    
    return card
end

---------------------------------------------------------------------------
-- ARENACORE CUSTOM RESULTS RENDERING
-- Unique layout and visual presentation
---------------------------------------------------------------------------

local function RenderArenaCoreResults(container, results, query, cardWidth)
    -- Clean previous results
    local children = { container:GetChildren() }
    for _, child in ipairs(children) do
        child:Hide()
        child:SetParent(nil)
    end
    
    local regions = { container:GetRegions() }
    for _, region in ipairs(regions) do
        if region.Hide then region:Hide() end
        if region.SetParent then region:SetParent(nil) end
    end
    
    local yPosition = -8
    
    -- Empty state handling
    if not results or #results == 0 then
        if query and query:len() >= 2 then
            -- No results state
            local noResultsTitle = container:CreateFontString(nil, "OVERLAY")
            if AC.SafeSetFont then
                AC.SafeSetFont(noResultsTitle, FONT_PATH, 14, "")
            else
                noResultsTitle:SetFont(FONT_PATH, 14, "")
            end
            noResultsTitle:SetPoint("TOP", 0, yPosition)
            noResultsTitle:SetTextColor(THEME.TEXT_2[1], THEME.TEXT_2[2], THEME.TEXT_2[3], 1)
            noResultsTitle:SetText(GetLocalizedString("SEARCH", "no_results", "No results found"))
            yPosition = yPosition - 25
            
            local noResultsDesc = container:CreateFontString(nil, "OVERLAY")
            if AC.SafeSetFont then
                AC.SafeSetFont(noResultsDesc, FONT_PATH, 11, "")
            else
                noResultsDesc:SetFont(FONT_PATH, 11, "")
            end
            noResultsDesc:SetPoint("TOP", 0, yPosition)
            noResultsDesc:SetTextColor(THEME.TEXT_MUTED[1], THEME.TEXT_MUTED[2], THEME.TEXT_MUTED[3], 1)
            noResultsDesc:SetText(GetLocalizedString("SEARCH", "try_different_keywords", "Try different keywords or check spelling"))
            yPosition = yPosition - 25
            
        else
            -- Default empty state with ArenaCore branding
            local searchIcon = container:CreateTexture(nil, "ARTWORK")
            searchIcon:SetSize(64, 64)
            searchIcon:SetPoint("TOP", 0, yPosition - 10)
            searchIcon:SetTexture("Interface\\AddOns\\ArenaCore\\Media\\Textures\\aclogo.tga")
            searchIcon:SetAlpha(0.4)
            
            yPosition = yPosition - 70
            
            local welcomeText = container:CreateFontString(nil, "OVERLAY")
            if AC.SafeSetFont then
                AC.SafeSetFont(welcomeText, FONT_PATH, 16, "")
            else
                welcomeText:SetFont(FONT_PATH, 16, "")
            end
            welcomeText:SetPoint("TOP", 0, yPosition)
            welcomeText:SetTextColor(THEME.TEXT_2[1], THEME.TEXT_2[2], THEME.TEXT_2[3], 1)
            welcomeText:SetText(GetLocalizedString("SEARCH", "search_settings", "Search ArenaCore Settings"))
            
            yPosition = yPosition - 25
            
            local helpText = container:CreateFontString(nil, "OVERLAY")
            if AC.SafeSetFont then
                AC.SafeSetFont(helpText, FONT_PATH, 11, "")
            else
                helpText:SetFont(FONT_PATH, 11, "")
            end
            helpText:SetPoint("TOP", 0, yPosition)
            helpText:SetTextColor(THEME.TEXT_MUTED[1], THEME.TEXT_MUTED[2], THEME.TEXT_MUTED[3], 1)
            helpText:SetText(GetLocalizedString("SEARCH", "min_chars", "Type at least 2 characters to search"))
            
            yPosition = yPosition - 25
            
            local catalogInfo = container:CreateFontString(nil, "OVERLAY")
            if AC.SafeSetFont then
                AC.SafeSetFont(catalogInfo, FONT_PATH, 9, "")
            else
                catalogInfo:SetFont(FONT_PATH, 9, "")
            end
            catalogInfo:SetPoint("TOP", 0, yPosition)
            catalogInfo:SetTextColor(THEME.TEXT_MUTED[1], THEME.TEXT_MUTED[2], THEME.TEXT_MUTED[3], 1)
            catalogInfo:SetText(#SearchCatalog .. " " .. GetLocalizedString("SEARCH", "settings_available", "settings available"))
        end
        
        container:SetHeight(math.abs(yPosition) + 40)
        return
    end
    
    -- Results header
    local resultsHeader = container:CreateFontString(nil, "OVERLAY")
    if AC.SafeSetFont then
        AC.SafeSetFont(resultsHeader, FONT_PATH, 11, "")
    else
        resultsHeader:SetFont(FONT_PATH, 11, "")
    end
    resultsHeader:SetPoint("TOPLEFT", 8, yPosition)
    resultsHeader:SetTextColor(THEME.TEXT_MUTED[1], THEME.TEXT_MUTED[2], THEME.TEXT_MUTED[3], 1)
    local resultText = #results .. " " .. ( #results > 1 and GetLocalizedString("SEARCH", "results_found_plural", "results found") or GetLocalizedString("SEARCH", "results_found", "result found") )
    resultsHeader:SetText(resultText)
    yPosition = yPosition - 25
    
    -- Group results by category
    local categoryGroups = {}
    local categoryOrder = {}
    
    for _, result in ipairs(results) do
        local category = result.entry.category
        if not categoryGroups[category] then
            categoryGroups[category] = {}
            categoryOrder[#categoryOrder + 1] = category
        end
        table.insert(categoryGroups[category], result)
    end
    
    -- Render each category group
    for _, category in ipairs(categoryOrder) do
        local groupResults = categoryGroups[category]
        
        -- Category header
        local categoryHeader = container:CreateFontString(nil, "OVERLAY")
        if AC.SafeSetFont then
            AC.SafeSetFont(categoryHeader, FONT_PATH, 11, "")
        else
            categoryHeader:SetFont(FONT_PATH, 11, "")
        end
        categoryHeader:SetPoint("TOPLEFT", 8, yPosition)
        categoryHeader:SetTextColor(THEME.PRIMARY[1], THEME.PRIMARY[2], THEME.PRIMARY[3], 0.95)
        categoryHeader:SetText(category)
        yPosition = yPosition - 18
        
        -- Category separator
        local separator = container:CreateTexture(nil, "ARTWORK")
        separator:SetPoint("TOPLEFT", 0, yPosition)
        separator:SetSize(cardWidth, 1)
        separator:SetColorTexture(THEME.PRIMARY[1], THEME.PRIMARY[2], THEME.PRIMARY[3], 0.3)
        yPosition = yPosition - 8
        
        -- Render results in this category
        for _, result in ipairs(groupResults) do
            CreateArenaCoreResultCard(container, result, yPosition, cardWidth)
            yPosition = yPosition - 68
        end
        
        yPosition = yPosition - 8
    end
    
    container:SetHeight(math.abs(yPosition) + 20)
end

---------------------------------------------------------------------------
-- ARENACORE CUSTOM SCROLLBAR SYSTEM
-- Unique scrollbar implementation
---------------------------------------------------------------------------

local function CreateArenaCoreScrollbar(parent, scrollFrame)
    local scrollbar = CreateFrame("Slider", nil, parent)
    scrollbar:SetPoint("TOPRIGHT", scrollFrame, "TOPRIGHT", -8, 0)
    scrollbar:SetPoint("BOTTOMRIGHT", scrollFrame, "BOTTOMRIGHT", -8, 0)
    scrollbar:SetWidth(14)
    scrollbar:SetOrientation("VERTICAL")
    scrollbar:SetMinMaxValues(0, 1)
    scrollbar:SetValue(0)
    
    -- ArenaCore styled track
    local track = scrollbar:CreateTexture(nil, "BACKGROUND")
    track:SetAllPoints()
    track:SetColorTexture(0.15, 0.15, 0.15, 0.9)
    
    -- ArenaCore styled thumb
    local thumb = scrollbar:CreateTexture(nil, "OVERLAY")
    thumb:SetTexture("Interface\\AddOns\\ArenaCore\\Media\\UI\\slider-thumb-arenacore.tga")
    thumb:SetSize(12, 18)
    scrollbar:SetThumbTexture(thumb)
    
    -- Scrollbar functionality
    local function UpdateScrollbar()
        local maxScroll = scrollFrame:GetVerticalScrollRange()
        if maxScroll > 0 then
            scrollbar:Show()
            scrollbar:SetMinMaxValues(0, maxScroll)
            local current = scrollFrame:GetVerticalScroll()
            scrollbar:SetValue(current)
        else
            scrollbar:Hide()
        end
    end
    
    scrollbar:SetScript("OnValueChanged", function(self, value)
        scrollFrame:SetVerticalScroll(value)
    end)
    
    -- Enhanced mouse wheel
    scrollFrame:EnableMouseWheel(true)
    scrollFrame:SetScript("OnMouseWheel", function(self, delta)
        local current = scrollbar:GetValue()
        local minVal, maxVal = scrollbar:GetMinMaxValues()
        local scrollAmount = (maxVal - minVal) / 12
        local newValue = current - (delta * scrollAmount)
        newValue = math.max(minVal, math.min(maxVal, newValue))
        scrollbar:SetValue(newValue)
    end)
    
    scrollFrame:SetScript("OnScrollRangeChanged", UpdateScrollbar)
    scrollFrame:SetScript("OnVerticalScroll", UpdateScrollbar)
    
    return scrollbar
end

---------------------------------------------------------------------------
-- MAIN ARENACORE SEARCH PAGE
---------------------------------------------------------------------------

local function CreateArenaCoreSearchPage(rootFrame)
    if not rootFrame then return end
    
    local cardWidth = 320
    
    -- Create scrollable results area FIRST (needed for callbacks)
    local scrollFrame = CreateFrame("ScrollFrame", "ArenaCoreSearchResultsScroll", rootFrame)
    scrollFrame:SetSize(350, 360)
    scrollFrame:SetPoint("TOP", 0, -95)
    
    local scrollChild = CreateFrame("Frame", nil, scrollFrame)
    scrollChild:SetSize(320, 400)
    scrollFrame:SetScrollChild(scrollChild)
    
    -- Create ArenaCore scrollbar
    local scrollbar = CreateArenaCoreScrollbar(rootFrame, scrollFrame)
    
    -- Create search input AFTER scrollChild exists
    local searchWidget = CreateArenaCoreSearchInput(
        rootFrame, 350,
        function(queryText) -- onSearch
            local searchResults = ArenaCoreFuzzySearch(queryText)
            SearchState.results = searchResults
            AC.SearchState.results = searchResults
            SearchState.lastSearchTime = GetTime()
            RenderArenaCoreResults(scrollChild, searchResults, queryText, cardWidth)
        end,
        function() -- onClear
            SearchState.results = {}
            AC.SearchState.results = {}
            RenderArenaCoreResults(scrollChild, nil, nil, cardWidth)
        end
    )
    searchWidget:SetPoint("TOP", 0, -55)
    
    -- Store references
    rootFrame.searchWidget = searchWidget
    rootFrame.scrollChild = scrollChild
    rootFrame.scrollbar = scrollbar
    
    -- Show initial state
    RenderArenaCoreResults(scrollChild, nil, nil, cardWidth)
    
    -- Restore previous search state
    local savedQuery = AC.SearchState.query or ""
    local savedResults = AC.SearchState.results or {}
    
    if savedQuery and savedQuery ~= "" then
        searchWidget.editBox:SetText(savedQuery)
        if #savedResults > 0 then
            RenderArenaCoreResults(scrollChild, savedResults, savedQuery, cardWidth)
        else
            local newResults = ArenaCoreFuzzySearch(savedQuery)
            SearchState.results = newResults
            AC.SearchState.results = newResults
            RenderArenaCoreResults(scrollChild, newResults, savedQuery, cardWidth)
        end
    end
end

-- Register the page
if AC and AC.RegisterPage then
    AC:RegisterPage("Search", CreateArenaCoreSearchPage)
end
