local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")

if playerGui:FindFirstChild("CharlieServices") then
    playerGui.CharlieServices:Destroy()
end

local ScreenGui = Instance.new("ScreenGui")
ScreenGui.Name = "CharlieServices"
ScreenGui.ResetOnSpawn = false
ScreenGui.IgnoreGuiInset = true
ScreenGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
ScreenGui.Parent = playerGui

-- ============ MAIN FRAME ============
local Main = Instance.new("Frame")
Main.Size = UDim2.new(0, 425, 0, 325)
Main.Position = UDim2.new(0.5, -170, 0.5, -260)
Main.BackgroundColor3 = Color3.fromRGB(18, 18, 30)
Main.BorderSizePixel = 0
Main.ClipsDescendants = true
Main.Parent = ScreenGui
Instance.new("UICorner", Main).CornerRadius = UDim.new(0, 12)
local MainStroke = Instance.new("UIStroke")
MainStroke.Color = Color3.fromRGB(40, 40, 58)
MainStroke.Thickness = 1
MainStroke.Parent = Main

-- ============ TOP BAR ============
local TopBar = Instance.new("Frame")
TopBar.Size = UDim2.new(1, 0, 0, 46)
TopBar.BackgroundColor3 = Color3.fromRGB(232, 80, 10)
TopBar.BorderSizePixel = 0
TopBar.ZIndex = 5
TopBar.Parent = Main
Instance.new("UICorner", TopBar).CornerRadius = UDim.new(0, 12)

local TopBarFix = Instance.new("Frame")
TopBarFix.Size = UDim2.new(1, 0, 0.5, 0)
TopBarFix.Position = UDim2.new(0, 0, 0.5, 0)
TopBarFix.BackgroundColor3 = Color3.fromRGB(232, 80, 10)
TopBarFix.BorderSizePixel = 0
TopBarFix.ZIndex = 4
TopBarFix.Parent = TopBar

local AppBadge = Instance.new("TextLabel")
AppBadge.Size = UDim2.new(0, 36, 0, 22)
AppBadge.Position = UDim2.new(0, 10, 0.5, -11)
AppBadge.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
AppBadge.BackgroundTransparency = 0.6
AppBadge.Text = "APP"
AppBadge.TextColor3 = Color3.fromRGB(255, 255, 255)
AppBadge.Font = Enum.Font.GothamBold
AppBadge.TextSize = 10
AppBadge.ZIndex = 6
AppBadge.Parent = TopBar
Instance.new("UICorner", AppBadge).CornerRadius = UDim.new(0, 4)

local TitleLabel = Instance.new("TextLabel")
TitleLabel.Size = UDim2.new(0, 100, 0, 20)
TitleLabel.Position = UDim2.new(0, 54, 0, 5)
TitleLabel.BackgroundTransparency = 1
TitleLabel.Text = "Charlie Services"
TitleLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
TitleLabel.Font = Enum.Font.GothamBold
TitleLabel.TextSize = 13
TitleLabel.TextXAlignment = Enum.TextXAlignment.Left
TitleLabel.ZIndex = 6
TitleLabel.Parent = TopBar

local VersionLabel = Instance.new("TextLabel")
VersionLabel.Size = UDim2.new(0, 100, 0, 14)
VersionLabel.Position = UDim2.new(0, 54, 0, 26)
VersionLabel.BackgroundTransparency = 1
VersionLabel.Text = "v1.0 · active"
VersionLabel.TextColor3 = Color3.fromRGB(255, 200, 170)
VersionLabel.Font = Enum.Font.Gotham
VersionLabel.TextSize = 10
VersionLabel.TextXAlignment = Enum.TextXAlignment.Left
VersionLabel.ZIndex = 6
VersionLabel.Parent = TopBar

-- ============ SEARCH BAR ============
local SearchBox = Instance.new("TextBox")
SearchBox.Size = UDim2.new(0, 110, 0, 28)
SearchBox.Position = UDim2.new(0, 158, 0.5, -14)
SearchBox.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
SearchBox.BackgroundTransparency = 0.45
SearchBox.PlaceholderText = "Search..."
SearchBox.PlaceholderColor3 = Color3.fromRGB(200, 160, 140)
SearchBox.Text = ""
SearchBox.TextColor3 = Color3.fromRGB(255, 255, 255)
SearchBox.Font = Enum.Font.Gotham
SearchBox.TextSize = 12
SearchBox.ClearTextOnFocus = false
SearchBox.ZIndex = 6
SearchBox.Parent = TopBar
Instance.new("UICorner", SearchBox).CornerRadius = UDim.new(0, 8)
local SearchStroke = Instance.new("UIStroke")
SearchStroke.Color = Color3.fromRGB(255, 255, 255)
SearchStroke.Transparency = 0.6
SearchStroke.Thickness = 1
SearchStroke.Parent = SearchBox

local SearchPad = Instance.new("UIPadding")
SearchPad.PaddingLeft = UDim.new(0, 8)
SearchPad.Parent = SearchBox

local CloseBtn = Instance.new("TextButton")
CloseBtn.Size = UDim2.new(0, 26, 0, 26)
CloseBtn.Position = UDim2.new(1, -34, 0.5, -13)
CloseBtn.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
CloseBtn.BackgroundTransparency = 0.5
CloseBtn.Text = "✕"
CloseBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
CloseBtn.Font = Enum.Font.GothamBold
CloseBtn.TextSize = 13
CloseBtn.ZIndex = 6
CloseBtn.Parent = TopBar
Instance.new("UICorner", CloseBtn).CornerRadius = UDim.new(0, 6)

-- ============ STATUS ROW ============
local function makeStatusPill(text, bgColor, textColor, xPos, width)
    local f = Instance.new("Frame")
    f.Size = UDim2.new(0, width, 0, 28)
    f.Position = UDim2.new(0, xPos, 0, 46)
    f.BackgroundColor3 = bgColor
    f.BorderSizePixel = 0
    f.ZIndex = 4
    f.Parent = Main
    local lbl = Instance.new("TextLabel")
    lbl.Size = UDim2.new(1, 0, 1, 0)
    lbl.BackgroundTransparency = 1
    lbl.Text = text
    lbl.TextColor3 = textColor
    lbl.Font = Enum.Font.GothamBold
    lbl.TextSize = 11
    lbl.ZIndex = 5
    lbl.Parent = f
end
makeStatusPill("● Undetected", Color3.fromRGB(25, 55, 25), Color3.fromRGB(100, 220, 100), 0, 113)
makeStatusPill("⚡ Fast inject", Color3.fromRGB(50, 30, 0), Color3.fromRGB(232, 80, 10), 113, 114)
makeStatusPill("↻ Auto-update", Color3.fromRGB(20, 50, 20), Color3.fromRGB(80, 200, 80), 227, 113)

-- ============ TAB BAR ============
local tabNames = {"Combat", "Visuals", "Movement", "Player", "Misc"}
local tabPages = {}
local tabButtons = {}
local activeTab = nil

local TabBar = Instance.new("Frame")
TabBar.Size = UDim2.new(1, 0, 0, 34)
TabBar.Position = UDim2.new(0, 0, 0, 74)
TabBar.BackgroundColor3 = Color3.fromRGB(14, 14, 22)
TabBar.BorderSizePixel = 0
TabBar.ZIndex = 4
TabBar.Parent = Main
Instance.new("UIListLayout", TabBar).FillDirection = Enum.FillDirection.Horizontal

-- Page container (normal tabs)
local PageContainer = Instance.new("Frame")
PageContainer.Size = UDim2.new(1, 0, 1, -108)
PageContainer.Position = UDim2.new(0, 0, 0, 108)
PageContainer.BackgroundTransparency = 1
PageContainer.ClipsDescendants = true
PageContainer.ZIndex = 3
PageContainer.Parent = Main

-- ============ SEARCH RESULTS PAGE ============
local SearchPage = Instance.new("ScrollingFrame")
SearchPage.Size = UDim2.new(1, 0, 1, -108)
SearchPage.Position = UDim2.new(0, 0, 0, 108)
SearchPage.BackgroundTransparency = 1
SearchPage.BorderSizePixel = 0
SearchPage.ScrollBarThickness = 3
SearchPage.ScrollBarImageColor3 = Color3.fromRGB(232, 80, 10)
SearchPage.CanvasSize = UDim2.new(0, 0, 0, 0)
SearchPage.AutomaticCanvasSize = Enum.AutomaticSize.Y
SearchPage.Visible = false
SearchPage.ZIndex = 10
SearchPage.Parent = Main
local SearchLayout = Instance.new("UIListLayout")
SearchLayout.Padding = UDim.new(0, 10)
SearchLayout.SortOrder = Enum.SortOrder.LayoutOrder
SearchLayout.Parent = SearchPage
local SearchPadding = Instance.new("UIPadding")
SearchPadding.PaddingLeft = UDim.new(0, 12)
SearchPadding.PaddingRight = UDim.new(0, 12)
SearchPadding.PaddingTop = UDim.new(0, 10)
SearchPadding.PaddingBottom = UDim.new(0, 10)
SearchPadding.Parent = SearchPage

local SearchNoResult = Instance.new("TextLabel")
SearchNoResult.Size = UDim2.new(1, 0, 0, 40)
SearchNoResult.BackgroundTransparency = 1
SearchNoResult.Text = "No results found"
SearchNoResult.TextColor3 = Color3.fromRGB(100, 100, 120)
SearchNoResult.Font = Enum.Font.GothamBold
SearchNoResult.TextSize = 14
SearchNoResult.ZIndex = 11
SearchNoResult.Visible = false
SearchNoResult.LayoutOrder = 999
SearchNoResult.Parent = SearchPage

-- ============ ALL TOGGLE REGISTRY ============
-- Every toggle registers here so search can find it
local allToggles = {}
-- { label=string, tabName=string, row=Frame }

-- Helper: make a scrolling page
local function makePage(name)
    local page = Instance.new("ScrollingFrame")
    page.Size = UDim2.new(1, 0, 1, 0)
    page.BackgroundTransparency = 1
    page.BorderSizePixel = 0
    page.ScrollBarThickness = 3
    page.ScrollBarImageColor3 = Color3.fromRGB(232, 80, 10)
    page.CanvasSize = UDim2.new(0, 0, 0, 0)
    page.AutomaticCanvasSize = Enum.AutomaticSize.Y
    page.Visible = false
    page.ZIndex = 3
    page.Parent = PageContainer
    local layout = Instance.new("UIListLayout")
    layout.Padding = UDim.new(0, 10)
    layout.SortOrder = Enum.SortOrder.LayoutOrder
    layout.Parent = page
    local pad = Instance.new("UIPadding")
    pad.PaddingLeft = UDim.new(0, 12)
    pad.PaddingRight = UDim.new(0, 12)
    pad.PaddingTop = UDim.new(0, 10)
    pad.PaddingBottom = UDim.new(0, 10)
    pad.Parent = page
    return page
end

-- Helper: section label
local function makeLabel(parent, text, order)
    local lbl = Instance.new("TextLabel")
    lbl.Size = UDim2.new(1, 0, 0, 20)
    lbl.BackgroundTransparency = 1
    lbl.Text = "✦ " .. text
    lbl.TextColor3 = Color3.fromRGB(140, 140, 160)
    lbl.TextXAlignment = Enum.TextXAlignment.Left
    lbl.Font = Enum.Font.GothamBold
    lbl.TextSize = 12
    lbl.ZIndex = 4
    lbl.LayoutOrder = order
    lbl.Parent = parent
end

-- Helper: toggle row (also registers with search)
local function makeToggleRow(parent, labelText, order, callback, tabName)
    local row = Instance.new("Frame")
    row.Size = UDim2.new(1, 0, 0, 48)
    row.BackgroundColor3 = Color3.fromRGB(22, 22, 34)
    row.BorderSizePixel = 0
    row.ZIndex = 4
    row.LayoutOrder = order
    row.Parent = parent
    Instance.new("UICorner", row).CornerRadius = UDim.new(0, 10)
    local s = Instance.new("UIStroke")
    s.Color = Color3.fromRGB(40, 40, 58)
    s.Thickness = 1
    s.Parent = row

    local lbl = Instance.new("TextLabel")
    lbl.Size = UDim2.new(1, -70, 1, 0)
    lbl.Position = UDim2.new(0, 14, 0, 0)
    lbl.BackgroundTransparency = 1
    lbl.Text = labelText
    lbl.TextColor3 = Color3.fromRGB(200, 200, 220)
    lbl.TextXAlignment = Enum.TextXAlignment.Left
    lbl.Font = Enum.Font.GothamBold
    lbl.TextSize = 13
    lbl.ZIndex = 5
    lbl.Parent = row

    local pill = Instance.new("Frame")
    pill.Size = UDim2.new(0, 44, 0, 24)
    pill.Position = UDim2.new(1, -56, 0.5, -12)
    pill.BackgroundColor3 = Color3.fromRGB(40, 40, 58)
    pill.ZIndex = 5
    pill.Parent = row
    Instance.new("UICorner", pill).CornerRadius = UDim.new(1, 0)

    local circle = Instance.new("Frame")
    circle.Size = UDim2.new(0, 18, 0, 18)
    circle.Position = UDim2.new(0, 3, 0.5, -9)
    circle.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
    circle.ZIndex = 6
    circle.Parent = pill
    Instance.new("UICorner", circle).CornerRadius = UDim.new(1, 0)

    local btn = Instance.new("TextButton")
    btn.Size = UDim2.new(1, 0, 1, 0)
    btn.BackgroundTransparency = 1
    btn.Text = ""
    btn.ZIndex = 7
    btn.Parent = row

    local on = false

    -- shared toggle logic
    local function doToggle()
        on = not on
        TweenService:Create(pill, TweenInfo.new(0.18), {
            BackgroundColor3 = on and Color3.fromRGB(232, 80, 10) or Color3.fromRGB(40, 40, 58)
        }):Play()
        TweenService:Create(circle, TweenInfo.new(0.18), {
            Position = on and UDim2.new(1, -21, 0.5, -9) or UDim2.new(0, 3, 0.5, -9)
        }):Play()
        if callback then callback(on) end
    end

    btn.MouseButton1Click:Connect(doToggle)

    -- Register for search
    if tabName then
        table.insert(allToggles, {
            label = labelText,
            tabName = tabName,
            row = row,
            pill = pill,
            circle = circle,
            doToggle = doToggle,
        })
    end

    return row
end

-- Helper: slider row
local function makeSliderRow(parent, labelText, order, minVal, maxVal, defaultVal, callback)
    local row = Instance.new("Frame")
    row.Size = UDim2.new(1, 0, 0, 72)
    row.BackgroundColor3 = Color3.fromRGB(22, 22, 34)
    row.BorderSizePixel = 0
    row.ZIndex = 4
    row.LayoutOrder = order
    row.Parent = parent
    Instance.new("UICorner", row).CornerRadius = UDim.new(0, 10)
    local s = Instance.new("UIStroke")
    s.Color = Color3.fromRGB(40, 40, 58)
    s.Thickness = 1
    s.Parent = row

    local pad = Instance.new("UIPadding")
    pad.PaddingLeft = UDim.new(0, 12)
    pad.PaddingRight = UDim.new(0, 12)
    pad.PaddingTop = UDim.new(0, 10)
    pad.Parent = row

    local lbl = Instance.new("TextLabel")
    lbl.Size = UDim2.new(0.7, 0, 0, 18)
    lbl.BackgroundTransparency = 1
    lbl.Text = labelText
    lbl.TextColor3 = Color3.fromRGB(200, 200, 220)
    lbl.TextXAlignment = Enum.TextXAlignment.Left
    lbl.Font = Enum.Font.GothamBold
    lbl.TextSize = 13
    lbl.ZIndex = 5
    lbl.Parent = row

    local valLbl = Instance.new("TextLabel")
    valLbl.Size = UDim2.new(0.3, 0, 0, 18)
    valLbl.Position = UDim2.new(0.7, 0, 0, 10)
    valLbl.BackgroundTransparency = 1
    valLbl.Text = tostring(defaultVal)
    valLbl.TextColor3 = Color3.fromRGB(232, 80, 10)
    valLbl.TextXAlignment = Enum.TextXAlignment.Right
    valLbl.Font = Enum.Font.GothamBold
    valLbl.TextSize = 13
    valLbl.ZIndex = 5
    valLbl.Parent = row

    local track = Instance.new("TextButton")
    track.Size = UDim2.new(1, 0, 0, 14)
    track.Position = UDim2.new(0, 0, 0, 36)
    track.BackgroundColor3 = Color3.fromRGB(40, 40, 58)
    track.BorderSizePixel = 0
    track.Text = ""
    track.ZIndex = 5
    track.Parent = row
    Instance.new("UICorner", track).CornerRadius = UDim.new(1, 0)

    local defaultRatio = (defaultVal - minVal) / (maxVal - minVal)
    local fill = Instance.new("Frame")
    fill.Size = UDim2.new(defaultRatio, 0, 1, 0)
    fill.BackgroundColor3 = Color3.fromRGB(232, 80, 10)
    fill.BorderSizePixel = 0
    fill.ZIndex = 6
    fill.Parent = track
    Instance.new("UICorner", fill).CornerRadius = UDim.new(1, 0)

    local knob = Instance.new("Frame")
    knob.Size = UDim2.new(0, 18, 0, 18)
    knob.Position = UDim2.new(defaultRatio, -9, 0.5, -9)
    knob.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
    knob.BorderSizePixel = 0
    knob.ZIndex = 7
    knob.Parent = track
    Instance.new("UICorner", knob).CornerRadius = UDim.new(1, 0)

    local sliding = false
    track.InputBegan:Connect(function(input)
        if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
            sliding = true
        end
    end)
    UserInputService.InputEnded:Connect(function(input)
        if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
            sliding = false
        end
    end)
    UserInputService.InputChanged:Connect(function(input)
        if sliding and (input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch) then
            local rx = math.clamp((input.Position.X - track.AbsolutePosition.X) / track.AbsoluteSize.X, 0, 1)
            local val = math.floor(minVal + rx * (maxVal - minVal))
            valLbl.Text = tostring(val)
            fill.Size = UDim2.new(rx, 0, 1, 0)
            knob.Position = UDim2.new(rx, -9, 0.5, -9)
            if callback then callback(val) end
        end
    end)
end

-- ============ TAB PAGES ============

-- MOVEMENT
local movePage = makePage("Movement")
makeLabel(movePage, "Quick toggles", 1)
makeToggleRow(movePage, "⚡  Speed Boost", 2, function(on)
    local hum = player.Character and player.Character:FindFirstChildOfClass("Humanoid")
    if hum then hum.WalkSpeed = on and 60 or 16 end
end, "Movement")
makeToggleRow(movePage, "▲  High Jump", 3, function(on)
    local hum = player.Character and player.Character:FindFirstChildOfClass("Humanoid")
    if hum then hum.JumpPower = on and 120 or 50 end
end, "Movement")
local infConn = nil
makeToggleRow(movePage, "∞  Infinite Jump", 4, function(on)
    if on then
        infConn = UserInputService.JumpRequest:Connect(function()
            local hum = player.Character and player.Character:FindFirstChildOfClass("Humanoid")
            if hum then hum:ChangeState(Enum.HumanoidStateType.Jumping) end
        end)
    else
        if infConn then infConn:Disconnect() infConn = nil end
    end
end, "Movement")
local noclipConn = nil
makeToggleRow(movePage, "◎  Noclip", 5, function(on)
    if on then
        noclipConn = RunService.Stepped:Connect(function()
            if player.Character then
                for _, p in pairs(player.Character:GetDescendants()) do
                    if p:IsA("BasePart") then p.CanCollide = false end
                end
            end
        end)
    else
        if noclipConn then noclipConn:Disconnect() noclipConn = nil end
    end
end, "Movement")
makeLabel(movePage, "Speed control", 6)
makeSliderRow(movePage, "Walk Speed", 7, 0, 200, 16, function(val)
    local hum = player.Character and player.Character:FindFirstChildOfClass("Humanoid")
    if hum then hum.WalkSpeed = val end
end)
makeSliderRow(movePage, "Jump Power", 8, 0, 300, 50, function(val)
    local hum = player.Character and player.Character:FindFirstChildOfClass("Humanoid")
    if hum then hum.JumpPower = val end
end)

-- PLAYER
local playerPage = makePage("Player")
makeLabel(playerPage, "Player settings", 1)
makeToggleRow(playerPage, "👻  God Mode", 2, function(on)
    local hum = player.Character and player.Character:FindFirstChildOfClass("Humanoid")
    if hum then hum.MaxHealth = on and math.huge or 100; hum.Health = hum.MaxHealth end
end, "Player")
makeToggleRow(playerPage, "🔦  Always Day", 3, function(on)
    game:GetService("Lighting").TimeOfDay = on and "14:00:00" or "12:00:00"
    game:GetService("Lighting").Brightness = on and 2 or 1
end, "Player")
makeLabel(playerPage, "Field of View", 4)
makeSliderRow(playerPage, "FOV", 5, 70, 120, 70, function(val)
    local cam = workspace.CurrentCamera
    if cam then cam.FieldOfView = val end
end)

-- VISUALS
local visualsPage = makePage("Visuals")
makeLabel(visualsPage, "Visual toggles", 1)
makeToggleRow(visualsPage, "🌙  Night Mode", 2, function(on)
    game:GetService("Lighting").TimeOfDay = on and "02:00:00" or "14:00:00"
end, "Visuals")
makeToggleRow(visualsPage, "🌫️  Remove Fog", 3, function(on)
    game:GetService("Lighting").FogEnd = on and 9999999 or 1000
end, "Visuals")
makeToggleRow(visualsPage, "💡  Full Bright", 4, function(on)
    game:GetService("Lighting").Brightness = on and 5 or 1
    game:GetService("Lighting").Ambient = on and Color3.fromRGB(255,255,255) or Color3.fromRGB(70,70,70)
end, "Visuals")

-- COMBAT
local combatPage = makePage("Combat")
makeLabel(combatPage, "Combat settings", 1)
makeToggleRow(combatPage, "🏃  Auto Sprint", 2, function(on)
    local hum = player.Character and player.Character:FindFirstChildOfClass("Humanoid")
    if hum then hum.WalkSpeed = on and 28 or 16 end
end, "Combat")
makeSliderRow(combatPage, "Hit Range", 3, 5, 100, 10, function(val)
    -- placeholder
end)

-- MISC
local miscPage = makePage("Misc")
makeLabel(miscPage, "Misc options", 1)
makeToggleRow(miscPage, "🏷️  Name Tag", 2, function(on)
    local char = player.Character
    if not char then return end
    local head = char:FindFirstChild("Head")
    if not head then return end
    if on then
        local bb = Instance.new("BillboardGui")
        bb.Name = "CSTag"; bb.Adornee = head
        bb.Size = UDim2.new(0, 140, 0, 40)
        bb.StudsOffset = Vector3.new(0, 3, 0)
        bb.AlwaysOnTop = true; bb.Parent = head
        local tl = Instance.new("TextLabel")
        tl.Size = UDim2.new(1, 0, 1, 0)
        tl.BackgroundTransparency = 1
        tl.Text = "Charlie Services"
        tl.TextColor3 = Color3.fromRGB(232, 80, 10)
        tl.TextStrokeTransparency = 0
        tl.TextScaled = true
        tl.Font = Enum.Font.GothamBold
        tl.Parent = bb
    else
        local tag = head:FindFirstChild("CSTag")
        if tag then tag:Destroy() end
    end
end, "Misc")
makeToggleRow(miscPage, "🎮  Anti AFK", 3, function(on)
    if on then
        local vu = game:GetService("VirtualUser")
        player.Idled:Connect(function()
            vu:Button2Down(Vector2.new(0,0), workspace.CurrentCamera.CFrame)
            task.wait(1)
            vu:Button2Up(Vector2.new(0,0), workspace.CurrentCamera.CFrame)
        end)
    end
end, "Misc")

-- ============ TAB SWITCHING ============
local pages = {
    Combat   = combatPage,
    Visuals  = visualsPage,
    Movement = movePage,
    Player   = playerPage,
    Misc     = miscPage,
}

local function switchTab(name)
    SearchPage.Visible = false
    PageContainer.Visible = true
    for n, pg in pairs(pages) do pg.Visible = false end
    if pages[name] then pages[name].Visible = true end
    activeTab = name
    for n, tb in pairs(tabButtons) do
        tb.btn.TextColor3 = n == name and Color3.fromRGB(232, 80, 10) or Color3.fromRGB(120, 120, 140)
        tb.line.Visible = n == name
    end
end

for i, tabName in ipairs(tabNames) do
    local btn = Instance.new("TextButton")
    btn.Size = UDim2.new(0, 68, 1, 0)
    btn.BackgroundTransparency = 1
    btn.Text = tabName
    btn.TextColor3 = tabName == "Movement" and Color3.fromRGB(232, 80, 10) or Color3.fromRGB(120, 120, 140)
    btn.Font = Enum.Font.GothamBold
    btn.TextSize = 11
    btn.ZIndex = 5
    btn.LayoutOrder = i
    btn.Parent = TabBar

    local underline = Instance.new("Frame")
    underline.Size = UDim2.new(1, 0, 0, 2)
    underline.Position = UDim2.new(0, 0, 1, -2)
    underline.BackgroundColor3 = Color3.fromRGB(232, 80, 10)
    underline.BorderSizePixel = 0
    underline.Visible = tabName == "Movement"
    underline.ZIndex = 6
    underline.Parent = btn

    tabButtons[tabName] = {btn = btn, line = underline}
    btn.MouseButton1Click:Connect(function()
        SearchBox.Text = ""
        switchTab(tabName)
    end)
end

switchTab("Movement")

-- ============ SEARCH LOGIC ============
-- Cloned rows that live in the search page
local searchClones = {}

local function clearSearchClones()
    for _, c in pairs(searchClones) do
        pcall(function() c:Destroy() end)
    end
    searchClones = {}
end

local function doSearch(query)
    clearSearchClones()
    query = query:lower():gsub("^%s+",""):gsub("%s+$","")

    if query == "" then
        -- back to normal tab view
        SearchPage.Visible = false
        PageContainer.Visible = true
        SearchNoResult.Visible = false
        -- restore tab underlines
        for n, tb in pairs(tabButtons) do
            tb.btn.TextColor3 = n == activeTab and Color3.fromRGB(232, 80, 10) or Color3.fromRGB(120, 120, 140)
            tb.line.Visible = n == activeTab
        end
        return
    end

    -- show search page
    PageContainer.Visible = false
    SearchPage.Visible = true
    for n, tb in pairs(tabButtons) do
        tb.btn.TextColor3 = Color3.fromRGB(120, 120, 140)
        tb.line.Visible = false
    end

    local found = 0
    local idx = 1
    for _, entry in ipairs(allToggles) do
        local lowerLabel = entry.label:lower()
        if lowerLabel:find(query, 1, true) then
            found = found + 1

            -- Make a fresh row clone in the search page
            local clone = Instance.new("Frame")
            clone.Size = UDim2.new(1, 0, 0, 48)
            clone.BackgroundColor3 = Color3.fromRGB(22, 22, 34)
            clone.BorderSizePixel = 0
            clone.ZIndex = 11
            clone.LayoutOrder = idx
            clone.Parent = SearchPage
            Instance.new("UICorner", clone).CornerRadius = UDim.new(0, 10)
            local cs = Instance.new("UIStroke")
            cs.Color = Color3.fromRGB(40, 40, 58)
            cs.Thickness = 1
            cs.Parent = clone

            -- Label with tab name hint
            local clbl = Instance.new("TextLabel")
            clbl.Size = UDim2.new(1, -70, 0, 26)
            clbl.Position = UDim2.new(0, 14, 0, 4)
            clbl.BackgroundTransparency = 1
            clbl.Text = entry.label
            clbl.TextColor3 = Color3.fromRGB(200, 200, 220)
            clbl.TextXAlignment = Enum.TextXAlignment.Left
            clbl.Font = Enum.Font.GothamBold
            clbl.TextSize = 13
            clbl.ZIndex = 12
            clbl.Parent = clone

            local tabHint = Instance.new("TextLabel")
            tabHint.Size = UDim2.new(1, -70, 0, 14)
            tabHint.Position = UDim2.new(0, 14, 0, 30)
            tabHint.BackgroundTransparency = 1
            tabHint.Text = "in " .. entry.tabName
            tabHint.TextColor3 = Color3.fromRGB(100, 100, 130)
            tabHint.TextXAlignment = Enum.TextXAlignment.Left
            tabHint.Font = Enum.Font.Gotham
            tabHint.TextSize = 10
            tabHint.ZIndex = 12
            tabHint.Parent = clone

            -- Pill toggle (mirrors real row state via doToggle)
            local cpill = Instance.new("Frame")
            cpill.Size = UDim2.new(0, 44, 0, 24)
            cpill.Position = UDim2.new(1, -56, 0.5, -12)
            cpill.BackgroundColor3 = Color3.fromRGB(40, 40, 58)
            cpill.ZIndex = 12
            cpill.Parent = clone
            Instance.new("UICorner", cpill).CornerRadius = UDim.new(1, 0)

            local ccircle = Instance.new("Frame")
            ccircle.Size = UDim2.new(0, 18, 0, 18)
            ccircle.Position = UDim2.new(0, 3, 0.5, -9)
            ccircle.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
            ccircle.ZIndex = 13
            ccircle.Parent = cpill
            Instance.new("UICorner", ccircle).CornerRadius = UDim.new(1, 0)

            local cbtn = Instance.new("TextButton")
            cbtn.Size = UDim2.new(1, 0, 1, 0)
            cbtn.BackgroundTransparency = 1
            cbtn.Text = ""
            cbtn.ZIndex = 14
            cbtn.Parent = clone

            cbtn.MouseButton1Click:Connect(function()
                entry.doToggle()
            end)

            table.insert(searchClones, clone)
            idx = idx + 1
        end
    end

    SearchNoResult.Visible = found == 0
    SearchNoResult.LayoutOrder = idx
end

SearchBox:GetPropertyChangedSignal("Text"):Connect(function()
    doSearch(SearchBox.Text)
end)

-- ============ DRAGGABLE ============
local dragging, dragInput, dragStart, startPos = false, nil, nil, nil
TopBar.InputBegan:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
        dragging = true
        dragStart = input.Position
        startPos = Main.Position
        input.Changed:Connect(function()
            if input.UserInputState == Enum.UserInputState.End then dragging = false end
        end)
    end
end)
TopBar.InputChanged:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
        dragInput = input
    end
end)
UserInputService.InputChanged:Connect(function(input)
    if dragging and input == dragInput then
        local delta = input.Position - dragStart
        Main.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y)
    end
end)

-- ============ CLOSE / OPEN ============
local OpenBtn = Instance.new("TextButton")
OpenBtn.Size = UDim2.new(0, 50, 0, 50)
OpenBtn.Position = UDim2.new(0, 20, 1, -70)
OpenBtn.BackgroundColor3 = Color3.fromRGB(232, 80, 10)
OpenBtn.Text = "CS"
OpenBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
OpenBtn.Font = Enum.Font.GothamBold
OpenBtn.TextSize = 14
OpenBtn.Visible = false
OpenBtn.ZIndex = 20
OpenBtn.Parent = ScreenGui
Instance.new("UICorner", OpenBtn).CornerRadius = UDim.new(1, 0)

CloseBtn.MouseButton1Click:Connect(function()
    Main.Visible = false
    OpenBtn.Visible = true
end)
OpenBtn.MouseButton1Click:Connect(function()
    Main.Visible = true
    OpenBtn.Visible = false
end)

print("✅ Charlie Services loaded! — Search bar active")

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: