#define NOMINMAX
#pragma comment(lib, "dwmapi.lib")
#include <Windows.h>
#include <dxgi.h>
#include <dwmapi.h>
#include <thread>
#include <chrono>
#include <d3d11.h>
#include <wincodec.h>
#include <string>
#include <vector>
#include <algorithm>
#include "Graphics.h"
#include <Globals.hxx>
#include <imgui/misc/imgui_freetype.h>
#include "imgui/imgui_internal.h"
#include "Fonts/Tahoma.h"
#include "Fonts/Tahoma_Bold.h"
#include "../Features/Cheats/Visuals/Visuals.h"
#include <ImGui/addons/colors/colors.h>
#include "Core/Features/Cheats/Aimbot/Silent/Silent.h"
#include "../Features/ConfigManager/ConfigManager.h"

extern HWND g_RobloxWindow;

// ==========================================
// WNDPROC
// ==========================================
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND Hwnd, UINT Msg, WPARAM WParam, LPARAM LParam);
static LRESULT CALLBACK WndProc(HWND Hwnd, UINT Msg, WPARAM WParam, LPARAM LParam)
{
    if (ImGui_ImplWin32_WndProcHandler(Hwnd, Msg, WParam, LParam))
        return true;

    switch (Msg) {
    case WM_SYSCOMMAND:
        if ((WParam & 0xfff0) == SC_KEYMENU) return 0;
        break;
    case WM_SYSKEYDOWN:
        if (WParam == VK_F4) {
            DestroyWindow(Hwnd);
            return 0;
        }
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    case WM_CLOSE:
        return 0;
    }
    return DefWindowProcA(Hwnd, Msg, WParam, LParam);
}

// ==========================================
// CLASS FUNCTIONS
// ==========================================
Graphics::Graphics() {
    Detail = std::make_unique<detail_t>();
    // Добавь инициализацию полей:
    Detail->Window = nullptr;
    Detail->Device = nullptr;
    Detail->DeviceContext = nullptr;
    Detail->GraphicsTargetView = nullptr;
    Detail->SwapChain = nullptr;
}
Graphics::~Graphics() { Destroy_Imgui(); Destroy_Window(); Destroy_Device(); }

bool Graphics::Create_Window()
{
    Detail->WindowClass.cbSize = sizeof(WNDCLASSEX);
    Detail->WindowClass.style = CS_HREDRAW | CS_VREDRAW;
    Detail->WindowClass.lpfnWndProc = WndProc;
    Detail->WindowClass.hInstance = GetModuleHandleA(NULL);
    Detail->WindowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
    Detail->WindowClass.lpszClassName = "FangOverlay";
    RegisterClassExA(&Detail->WindowClass);

    Detail->Window = CreateWindowExA(
        WS_EX_TOPMOST | WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_TOOLWINDOW,
        Detail->WindowClass.lpszClassName, "Fang Overlay", WS_POPUP,
        0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN),
        NULL, NULL, Detail->WindowClass.hInstance, NULL
    );
    if (!Detail->Window) return false;
    SetLayeredWindowAttributes(Detail->Window, RGB(0, 0, 0), 255, LWA_ALPHA);
    MARGINS margins = { -1 };
    DwmExtendFrameIntoClientArea(Detail->Window, &margins);
    ShowWindow(Detail->Window, SW_SHOW);
    UpdateWindow(Detail->Window);
    return true;
}

bool Graphics::Create_Device()
{
    IDXGIFactory1* dxgiFactory = nullptr;
    HRESULT hr = CreateDXGIFactory1(IID_PPV_ARGS(&dxgiFactory));
    if (FAILED(hr)) return false;

    IDXGIAdapter1* dxgiAdapter = nullptr;
    if (dxgiFactory->EnumAdapters1(0, &dxgiAdapter) == DXGI_ERROR_NOT_FOUND) {
        dxgiFactory->Release();
        return false;
    }

    DXGI_SWAP_CHAIN_DESC sd{};
    sd.BufferCount = 2;
    sd.BufferDesc.Width = 0; sd.BufferDesc.Height = 0;
    sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    sd.BufferDesc.RefreshRate.Numerator = 60; sd.BufferDesc.RefreshRate.Denominator = 1;
    sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    sd.OutputWindow = Detail->Window;
    sd.SampleDesc.Count = 1; sd.Windowed = TRUE;
    sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
    sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;

    D3D_FEATURE_LEVEL featureLevel;
    const D3D_FEATURE_LEVEL featureLevels[] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_0 };
    dxgiFactory->MakeWindowAssociation(Detail->Window, DXGI_MWA_NO_ALT_ENTER);

    hr = D3D11CreateDeviceAndSwapChain(dxgiAdapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr,
        D3D11_CREATE_DEVICE_BGRA_SUPPORT, featureLevels, ARRAYSIZE(featureLevels),
        D3D11_SDK_VERSION, &sd, &Detail->SwapChain, &Detail->Device, &featureLevel, &Detail->DeviceContext);

    dxgiAdapter->Release();
    dxgiFactory->Release();

    if (FAILED(hr)) return false;

    ID3D11Texture2D* pBackBuffer = nullptr;
    if (SUCCEEDED(Detail->SwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer))) && pBackBuffer) {
        Detail->Device->CreateRenderTargetView(pBackBuffer, nullptr, &Detail->GraphicsTargetView);
        pBackBuffer->Release();
    }
    else {
        return false;
    }

    return true;
}

bool Graphics::Create_Imgui()
{
    using namespace ImGui;
    CreateContext();
    StyleColorsDark();

    float MainScale = ImGui_ImplWin32_GetDpiScaleForMonitor(::MonitorFromPoint(POINT{ 0, 0 }, MONITOR_DEFAULTTOPRIMARY));
    ImGuiStyle& Style = ImGui::GetStyle();
    ImGuiIO& IO = ImGui::GetIO(); (void)IO;
    IO.IniFilename = nullptr;

    const unsigned int freetype_flags = ImGuiFreeTypeLoaderFlags_MonoHinting | ImGuiFreeTypeLoaderFlags_Monochrome;
    IO.Fonts->SetFontLoader(ImGuiFreeType::GetFontLoader());
    IO.Fonts->FontLoaderFlags = freetype_flags;

    ImFontConfig font_cfg{};
    font_cfg.PixelSnapH = true;
    font_cfg.OversampleH = 2;
    font_cfg.OversampleV = 1;
    font_cfg.RasterizerMultiply = 1.05f;
    font_cfg.FontLoaderFlags = freetype_flags;

    ImFontConfig font_configuration = font_cfg;
    font_configuration.FontDataOwnedByAtlas = false;
    float Verdana_Size = 13.0f * MainScale;

    IO.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(Tahoma), sizeof(Tahoma), Verdana_Size, &font_configuration);
    Tahoma_BoldXP = IO.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(Tahoma_Bold), sizeof(Tahoma_Bold), Verdana_Size, &font_configuration, IO.Fonts->GetGlyphRangesCyrillic());
    if (!Detail->Device || !Detail->DeviceContext) return false;
    if (!ImGui_ImplWin32_Init(Detail->Window)) return false;
    if (!ImGui_ImplDX11_Init(Detail->Device, Detail->DeviceContext)) return false;

    return true;
}

void Graphics::Destroy_Device()
{
    if (Detail->GraphicsTargetView) Detail->GraphicsTargetView->Release();
    if (Detail->SwapChain) Detail->SwapChain->Release();
    if (Detail->DeviceContext) Detail->DeviceContext->Release();
    if (Detail->Device) Detail->Device->Release();
}

void Graphics::Destroy_Window()
{
    DestroyWindow(Detail->Window);
    UnregisterClassA(Detail->WindowClass.lpszClassName, Detail->WindowClass.hInstance);
}

void Graphics::Destroy_Imgui()
{
    ImGui_ImplDX11_Shutdown();
    ImGui_ImplWin32_Shutdown();
    ImGui::DestroyContext();
}

void Graphics::Start_Render()
{
    MSG Msg;
    while (PeekMessage(&Msg, nullptr, 0, 0, PM_REMOVE)) {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }

    // ← ПРОВЕРКА: если устройство не создано - выходим
    if (!Detail || !Detail->SwapChain || !Detail->Device) return;

    if (Globals::Settings::Streamproof)
        SetWindowDisplayAffinity(Detail->Window, WDA_EXCLUDEFROMCAPTURE);
    else
        SetWindowDisplayAffinity(Detail->Window, WDA_NONE);

    static int last_w = 0, last_h = 0;
    RECT rect = { 0, 0, 0, 0 };

    // ← БЕЗОПАСНЫЙ ПОИСК ОКНА ROBLOX
    HWND roblox_hwnd = nullptr;
    EnumWindows([](HWND hwnd, LPARAM param) -> BOOL {
        char title[256];
        if (GetWindowTextA(hwnd, title, sizeof(title))) {
            if (strstr(title, "Roblox") != nullptr) {
                *(HWND*)param = hwnd;
                return FALSE;
            }
        }
        return TRUE;
        }, (LPARAM)&roblox_hwnd);

    if (roblox_hwnd && IsWindow(roblox_hwnd)) {
        if (GetWindowRect(roblox_hwnd, &rect)) {
            int width = rect.right - rect.left;
            int height = rect.bottom - rect.top;

            if (width > 0 && height > 0) {
                if (width != last_w || height != last_h) {
                    last_w = width;
                    last_h = height;

                    // ← ПРОВЕРКА перед изменением окна
                    if (Detail->Window && IsWindow(Detail->Window)) {
                        SetWindowPos(Detail->Window, HWND_TOPMOST, rect.left, rect.top, width, height, SWP_NOACTIVATE);
                    }

                    if (Detail->SwapChain) {
                        if (Detail->GraphicsTargetView) {
                            Detail->GraphicsTargetView->Release();
                            Detail->GraphicsTargetView = nullptr;
                        }
                        // ← ПРОВЕРКА перед ResizeBuffers
                        HRESULT hr = Detail->SwapChain->ResizeBuffers(0, width, height, DXGI_FORMAT_UNKNOWN, 0);
                        if (SUCCEEDED(hr)) {
                            ID3D11Texture2D* pBackBuffer = nullptr;
                            if (SUCCEEDED(Detail->SwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer))) && pBackBuffer) {
                                Detail->Device->CreateRenderTargetView(pBackBuffer, NULL, &Detail->GraphicsTargetView);
                                pBackBuffer->Release();
                            }
                        }
                    }
                    ImGui::GetIO().DisplaySize = ImVec2((float)width, (float)height);
                }
                else {
                    if (Detail->Window && IsWindow(Detail->Window)) {
                        SetWindowPos(Detail->Window, HWND_TOPMOST, rect.left, rect.top, width, height, SWP_NOACTIVATE | SWP_NOSIZE);
                    }
                }
            }
        }
    }

    ImGui_ImplDX11_NewFrame();
    ImGui_ImplWin32_NewFrame();
    ImGui::NewFrame();

    if (GetAsyncKeyState(VK_INSERT) & 1) {
        Running = !Running;
        if (Detail->Window && IsWindow(Detail->Window)) {
            if (Running) {
                SetWindowLongA(Detail->Window, GWL_EXSTYLE, WS_EX_TOOLWINDOW | WS_EX_LAYERED);
            }
            else {
                SetWindowLongA(Detail->Window, GWL_EXSTYLE, WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_LAYERED);
            }
        }
    }
}

void Graphics::End_Render()
{
    if (!Detail->GraphicsTargetView) return; // ← ДОБАВЬ ЭТО
    ImGui::Render();
    float ClearColor[4]{ 0, 0, 0, 0 };
    Detail->DeviceContext->OMSetRenderTargets(1, &Detail->GraphicsTargetView, nullptr);
    Detail->DeviceContext->ClearRenderTargetView(Detail->GraphicsTargetView, ClearColor);
    ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());

    if (Globals::Settings::Performance_Mode == 0) {
        std::this_thread::sleep_for(std::chrono::milliseconds(1));
        Detail->SwapChain->Present(0, 0);
    }
    else if (Globals::Settings::Performance_Mode == 1) {
        Detail->SwapChain->Present(1, 0);
    }
    else {
        Detail->SwapChain->Present(0, 0);
    }
}

// ==========================================
// DRAW CURSOR
// ==========================================
static void DrawCursor()
{
    if (!Driver || !SilentAimInstance.Address) return;
    if (!SilentAimInstance.Address) return;
    bool is_visible = Driver->Read<bool>(SilentAimInstance.Address + Offsets::GuiObject::Visible);
    if (!is_visible) return;

    POINT pt;
    if (!GetCursorPos(&pt)) return;

    // Получаем смещение окна Roblox
    HWND hwnd = FindWindowA(NULL, "Roblox");
    RECT rect;
    if (hwnd && GetWindowRect(hwnd, &rect)) {
        // Конвертируем в клиентские координаты
        ScreenToClient(hwnd, &pt);
    }

    bool right_click_held = GetAsyncKeyState(VK_RBUTTON) & 0x8000;
    float gap = right_click_held ? 4.0f : 10.0f;
    ImDrawList* draw = ImGui::GetBackgroundDrawList();
    ImU32 col = IM_COL32(255, 255, 255, 255);
    float dot_size = 4.0f;
    float line_width = 2.0f;
    float line_length = 10.0f;
    ImVec2 center = { (float)pt.x, (float)pt.y };

    draw->AddRectFilled({ center.x - dot_size * 0.5f, center.y - dot_size * 0.5f },
        { center.x + dot_size * 0.5f, center.y + dot_size * 0.5f }, col, 0.0f);

    draw->AddRectFilled({ center.x - line_width * 0.5f, center.y - gap - line_length },
        { center.x + line_width * 0.5f, center.y - gap }, col, 0.0f);

    draw->AddRectFilled({ center.x - line_width * 0.5f, center.y + gap },
        { center.x + line_width * 0.5f, center.y + gap + line_length }, col, 0.0f);

    draw->AddRectFilled({ center.x - gap - line_length, center.y - line_width * 0.5f },
        { center.x - gap, center.y + line_width * 0.5f }, col, 0.0f);

    draw->AddRectFilled({ center.x + gap, center.y - line_width * 0.5f },
        { center.x + gap + line_length, center.y + line_width * 0.5f }, col, 0.0f);
}

static bool CustomButton(const char* label, ImVec2 size, ImDrawList* drawList) {
    ImGuiIO& io = ImGui::GetIO();

    ImVec2 cursorPos = ImGui::GetCursorScreenPos();
    ImVec2 min = cursorPos;
    ImVec2 max = ImVec2(min.x + size.x, min.y + size.y);

    bool hovered = io.MousePos.x >= min.x && io.MousePos.x <= max.x &&
        io.MousePos.y >= min.y && io.MousePos.y <= max.y;

    bool clicked = hovered && io.MouseClicked[0];

    // Цвета в стиле чита
    ImU32 bgColor = hovered ? IM_COL32(80, 60, 80, 255) : IM_COL32(50, 40, 50, 255);
    ImU32 borderColor = hovered ? Menu::Accent : Menu::Outline;
    ImU32 textColor = hovered ? IM_COL32(255, 220, 255, 255) : Menu::Text;

    // Рисуем фон
    drawList->AddRectFilled(min, max, bgColor, 0.f, 0);

    // Рисуем рамку
    drawList->AddRect(min, max, borderColor, 0.f, 0, 1.f);

    // Текст по центру
    ImVec2 textSize = ImGui::CalcTextSize(label);
    ImVec2 textPos = ImVec2(
        min.x + (size.x - textSize.x) * 0.5f,
        min.y + (size.y - textSize.y) * 0.5f
    );
    drawList->AddText(textPos, textColor, label);

    // Продвигаем курсор
    ImGui::ItemSize(size);
    ImGui::ItemAdd(ImRect(min, max), ImGui::GetID(label));

    return clicked;
}

// ==========================================
// RENDER MENU (БЕЗ WOBBLY)
// ==========================================
void Graphics::Render_Menu()
{
    ImGuiStyle& Style = ImGui::GetStyle();
    ImGuiIO& Io = ImGui::GetIO(); (void)Io;
    ImGui::SetNextWindowSize(ImVec2(500, 530), ImGuiCond_Once);
    ImGui::SetNextWindowPos(Io.DisplaySize / 2, ImGuiCond_Once, ImVec2(0.5f, 0.5f));
    ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
    ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);

    bool MainWindow = ImGui::Begin("main", nullptr,
        ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoBackground);
    ImGui::PopStyleVar(2);

    if (MainWindow)
    {
        ImVec2 WinPos = ImGui::GetWindowPos();
        ImVec2 WinSize = ImGui::GetWindowSize();
        ImDrawList* DrawList = ImGui::GetWindowDrawList();

        float Top = ImGui::GetFontSize() + 6.0f * 2.0f + Style.WindowBorderSize - 8.0f;
        float Bottom = Style.WindowBorderSize + Style.WindowPadding.y + 1.0f;

        ImVec2 ContentMin = WinPos + ImVec2(
            Style.WindowBorderSize * 2.0f + Style.WindowPadding.x,
            Top + Style.WindowPadding.y + 6.0f
        );
        ImVec2 ContentMax = WinPos + ImVec2(
            WinSize.x - Style.WindowBorderSize * 2.0f - Style.WindowPadding.x,
            WinSize.y - Bottom
        );

        static int Section = 0;
        const char* TabLabels[] = { "Aimbot", "Visuals", "Rage", "Players", "Explorer", "Settings" };
        const int TabCount = IM_ARRAYSIZE(TabLabels);

        // ============================================
        // ФОН (ОБЫЧНЫЙ, БЕЗ WOBBLY)
        // ============================================
        DrawList->AddRectFilled(WinPos, WinPos + WinSize, Menu::Bg);
        DrawList->AddRect(WinPos + ImVec2(1, 1), WinPos + WinSize - ImVec2(1, 1), Menu::Outline);
        DrawList->AddRect(WinPos + ImVec2(2, 2), WinPos + WinSize - ImVec2(2, 2), Menu::Accent);
        DrawList->AddRectFilled(ContentMin, ContentMax, Menu::InnerBg);
        DrawList->AddRect(ContentMin - ImVec2(1, 1), ContentMax + ImVec2(1, 1), Menu::Outline);
        DrawList->AddRect(ContentMin - ImVec2(2, 2), ContentMax + ImVec2(2, 2), Menu::DarkAccent);

        ImGui::SetCursorScreenPos(ContentMin);
        ImGui::PushClipRect(ContentMin, ContentMax, true);

        // ============================================
        // КОНТЕНТ
        // ============================================
        ImGui::BeginGroup();

        if (Section == 0) // AIMBOT
        {
            ImVec2 AvailSize(ContentMax.x - ContentMin.x, ContentMax.y - ContentMin.y);
            float Spacing = Style.ItemSpacing.x;
            float LeftWidth = (AvailSize.x - Spacing) * 0.5f;
            float RightWidth = AvailSize.x - Spacing - LeftWidth;
            float SidePad = 4.0f;
            float HalfHeight = (AvailSize.y - SidePad * 2.0f) * 0.5f;

            ImGui::SetCursorPosX(ImGui::GetCursorPosX() + SidePad);
            ImGui::SetCursorPosY(ImGui::GetCursorPosY() + SidePad);

            if (Menu::BeginChild("Aimbot", ImVec2(LeftWidth - SidePad, HalfHeight)))
            {
                Menu::CheckBox("Enabled", &Globals::Aimbot::Enabled);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x + 12.0f);
                Menu::KeyBindEx("Aimbot Key", &Globals::Aimbot::Aimbot_Key, &Globals::Aimbot::Aimbot_Mode);
                Menu::CheckBox("Sticky aim", &Globals::Aimbot::AimbotSticky);
                Menu::CheckBox("Knocked check", &Globals::Aimbot::KnockedCheck);
                Menu::Combo("Aimbot type", &Globals::Aimbot::Aimbot_type, { "Mouse", "Camera" });
                Menu::Combo("HitPart", &Globals::Aimbot::HitPart, { "Head", "Torso", "LowerTorso" });
                if (Globals::Aimbot::Aimbot_type == 0)
                {
                    Menu::SliderFloat("Mouse smoothing X", &Globals::Aimbot::Mouse::Smoothing_X, 0.0f, 12.0f);
                    Menu::SliderFloat("Mouse smoothing Y", &Globals::Aimbot::Mouse::Smoothing_Y, 0.0f, 12.0f);
                    Menu::SliderFloat("Mouse sensitivty", &Globals::Aimbot::Mouse::Mouse_Sensitivty, 0.0f, 5.0f);
                }
                else if (Globals::Aimbot::Aimbot_type == 1)
                {
                    Menu::SliderFloat("Camera smoothing X", &Globals::Aimbot::Camera::Smoothing_X, 0.0f, 12.0f);
                    Menu::SliderFloat("Camera smoothing Y", &Globals::Aimbot::Camera::Smoothing_Y, 0.0f, 12.0f);
                }
                Menu::EndChild();
            }

            ImGui::SetCursorPosX(ImGui::GetCursorPosX() + SidePad);
            ImGui::SetCursorPosY(ImGui::GetCursorPosY() + SidePad);
            float BottomFOV = HalfHeight - 8;
            if (Menu::BeginChild("Aimbot FOV", ImVec2(LeftWidth - SidePad, BottomFOV)))
            {
                Menu::CheckBox("Draw", &Globals::Aimbot::DrawFov);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                Menu::ColorEdit4("FOV Color", Globals::Aimbot::FovColor);
                if (Globals::Aimbot::DrawFov)
                {
                    Menu::SliderFloat("Size", &Globals::Aimbot::FovSize, 1.0f, 500.0f);
                    Menu::CheckBox("Spin", &Globals::Aimbot::FovSpin);
                    if (Globals::Aimbot::FovSpin)
                    {
                        Menu::SliderInt("Speed", &Globals::Aimbot::FovSpinSpeed, 1, 5);
                    }
                    Menu::CheckBox("Use FOV", &Globals::Aimbot::useFov);
                }
                Menu::EndChild();
            }

            ImGui::SameLine(0.0f, Spacing);
            ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 248);
            if (Menu::BeginChild("Silent", ImVec2(RightWidth - SidePad, HalfHeight)))
            {
                Menu::CheckBox("Enabled", &Globals::Silent::Enabled);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x + 12.0f);
                Menu::KeyBindEx("Silent Key", &Globals::Silent::Silent_Key, &Globals::Silent::Silent_Mode);
                Menu::CheckBox("Sticky aim", &Globals::Silent::StickyAim);
                Menu::CheckBox("Knocked check", &Globals::Silent::KnockedCheck);
                Menu::Combo("Silent Part", &Globals::Silent::AimPart, { "Head", "Torso", "LowerTorso" });
                Menu::EndChild();
            }

            ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 236);
            ImGui::SetCursorPosX(ImGui::GetCursorPosX() + SidePad + 240.0f);
            if (Menu::BeginChild("Silent FOV", ImVec2(RightWidth - SidePad, BottomFOV)))
            {
                Menu::CheckBox("Draw", &Globals::Silent::DrawFov);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                Menu::ColorEdit4("FOV Color", Globals::Silent::FovColor);
                Menu::CheckBox("Gun based FOV", &Globals::Silent::GunBasedFov);
                if (Globals::Silent::GunBasedFov)
                {
                    Menu::SliderFloat("Default", &Globals::Silent::Fov, 0.0f, 300.0f);
                    Menu::SliderFloat("Double Barrel", &Globals::Silent::FovDoubleBarrel, 0.0f, 300.0f);
                    Menu::SliderFloat("Tactical", &Globals::Silent::FovTacticalShotgun, 0.0f, 300.0f);
                    Menu::SliderFloat("Revolver", &Globals::Silent::FovRevolver, 0.0f, 300.0f);
                }
                else
                {
                    Menu::SliderFloat("Static FOV", &Globals::Silent::Fov, 0.0f, 500.0f);
                }
                Menu::CheckBox("Spin", &Globals::Silent::FovSpin);
                if (Globals::Silent::FovSpin)
                {
                    Menu::SliderInt("Spin Speed", &Globals::Silent::FovSpinSpeed, 1, 5);
                }
                Menu::CheckBox("Use FOV", &Globals::Silent::UseFov);
                Menu::EndChild();
            }
        }

        if (Section == 1) // VISUALS
        {
            ImVec2 AvailSize(ContentMax.x - ContentMin.x, ContentMax.y - ContentMin.y);
            float Spacing = Style.ItemSpacing.x;
            float LeftWidth = (AvailSize.x - Spacing) * 0.5f;
            float RightWidth = AvailSize.x - Spacing - LeftWidth;
            float SidePad = 4.0f;
            float HalfHeight = (AvailSize.y - SidePad * 2.0f) * 0.5f;

            ImGui::SetCursorPosX(ImGui::GetCursorPosX() + SidePad);
            ImGui::SetCursorPosY(ImGui::GetCursorPosY() + SidePad);

            if (Menu::BeginChild("Visuals", ImVec2(LeftWidth - SidePad, HalfHeight)))
            {
                Menu::CheckBox("Enabled", &Globals::Visuals::Enabled);
                Menu::CheckBox("Box", &Globals::Visuals::Box);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                Menu::ColorEdit4("Box Color", Globals::Visuals::Colors::Box);
                if (Globals::Visuals::Box)
                {
                    Menu::CheckBox("Box Fill", &Globals::Visuals::Box_Fill);
                    ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                    Menu::ColorEdit4("Box Fill Top", Globals::Visuals::Colors::BoxFill_Top);
                    if (Globals::Visuals::Box_Fill_Gradient)
                    {
                        ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() - 24);
                        Menu::ColorEdit4("Box Fill Bottom", Globals::Visuals::Colors::BoxFill_Bottom);
                    }
                }
                Menu::CheckBox("Healthbar", &Globals::Visuals::Healthbar);
                if (Globals::Visuals::Healthbar_Type == 0)
                {
                    ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                    Menu::ColorEdit4("Healthbar Color", Globals::Visuals::Colors::Healthbar);
                }
                else if (Globals::Visuals::Healthbar_Type == 1)
                {
                    ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                    Menu::ColorEdit4("Healthbar Top", Globals::Visuals::Colors::Healthbar_Top);
                    ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() - 24);
                    Menu::ColorEdit4("Healthbar Middle", Globals::Visuals::Colors::Healthbar_Middle);
                    ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() - 51);
                    Menu::ColorEdit4("Healthbar Bottom", Globals::Visuals::Colors::Healthbar_Bottom);
                }
                Menu::CheckBox("Health", &Globals::Visuals::Health);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                Menu::ColorEdit4("Health Color", Globals::Visuals::Colors::Health);
                Menu::CheckBox("Name", &Globals::Visuals::Name);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                Menu::ColorEdit4("Name Color", Globals::Visuals::Colors::Name);
                Menu::CheckBox("Distance", &Globals::Visuals::Distance);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                Menu::ColorEdit4("Distance Color", Globals::Visuals::Colors::Distance);
                Menu::CheckBox("Rig Type", &Globals::Visuals::Rig_Type);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                Menu::ColorEdit4("Rig Type Color", Globals::Visuals::Colors::Rig_Type);
                Menu::CheckBox("Tool", &Globals::Visuals::Tool);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                Menu::ColorEdit4("Tool Color", Globals::Visuals::Colors::Tool);
                Menu::CheckBox("Skeleton", &Globals::Visuals::Skeleton);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                Menu::ColorEdit4("Skeleton Color", Globals::Visuals::Colors::Skeleton);
                Menu::CheckBox("Chams", &Globals::Visuals::Chams);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                Menu::ColorEdit4("Chams Color", Globals::Visuals::Colors::Chams);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() - 24);
                Menu::ColorEdit4("Chams Outline", Globals::Visuals::Colors::ChamsOutline);
                Menu::EndChild();
            }

            ImGui::SetCursorPosX(ImGui::GetCursorPosX() + SidePad);
            ImGui::SetCursorPosY(ImGui::GetCursorPosY() + SidePad);
            float Bottom = HalfHeight - 8;
            if (Menu::BeginChild("World", ImVec2(LeftWidth - SidePad, Bottom)))
            {
                Menu::CheckBox("Skybox Changer", &Globals::World::Skybox);
                if (Globals::World::Skybox)
                {
                    Menu::Combo("Skybox Type", &Globals::World::Skybox_Type, {
                        "Fang.wtf", "Space", "Pink Sky", "Minecraft", "Night Cloudy",
                        "Sparkling Night", "Winterness", "Dark Crimson", "Nebula",
                        "Tropical", "Green Sky"
                        });
                    Menu::CheckBox("Skybox Rotation", &Globals::World::Rotate);
                    if (Globals::World::Rotate)
                    {
                        Menu::SliderFloat("Rotation Speed", &Globals::World::Skybox_Rotate_Speed, 0.0f, 5.0f);
                    }
                }
                Menu::CheckBox("Atmosphere", &Globals::World::Ambience);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                Menu::ColorEdit4("Atmosphere Color", Globals::World::Colors::Ambience);
                Menu::CheckBox("Fog", &Globals::World::Fog);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                Menu::ColorEdit4("Fog Color", Globals::World::Colors::Fog);
                if (Globals::World::Fog)
                {
                    Menu::SliderFloat("Fog Distance", &Globals::World::Fog_Distance, 0.0f, 1000.0f);
                }
                Menu::CheckBox("Brightness", &Globals::World::Brightness);
                if (Globals::World::Brightness)
                {
                    Menu::SliderFloat("Brightness Value", &Globals::World::BrightnessI, 0.0f, 10.0f);
                }
                Menu::CheckBox("Exposure", &Globals::World::Exposure);
                if (Globals::World::Exposure)
                {
                    Menu::SliderFloat("Exposure Value", &Globals::World::ExposureI, -3.0f, 3.0f);
                }
                Menu::CheckBox("FOV", &Globals::World::FOV);
                if (Globals::World::FOV)
                {
                    Menu::SliderFloat("FOV Value", &Globals::World::FOV_Distance, 70.0f, 120.0f);
                }
                Menu::EndChild();
            }

            ImGui::SameLine(0.0f, Spacing);
            ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 248);
            if (Menu::BeginChild("Options", ImVec2(RightWidth - SidePad, AvailSize.y - SidePad * 2.0f)))
            {
                Menu::CheckBox("Exclude Client", &Globals::Settings::Client_Check);
                Menu::CheckBox("Exclude Team", &Globals::Settings::Team_Check);
                Menu::SliderFloat("Render Distance", &Globals::Visuals::Render_Distance, 0.0f, 500.0f);
                if (Globals::Visuals::Healthbar)
                {
                    Menu::Combo("Healthbar Style", &Globals::Visuals::Healthbar_Type, { "Static", "Gradient" });
                    Menu::SliderInt("Healthbar Thickness", &Globals::Visuals::Thickness, 1, 5);
                }
                if (Globals::Visuals::Box)
                {
                    Menu::Combo("Box Style", &Globals::Visuals::Box_Type, { "Bounding", "Corner" });
                }
                if (Globals::Visuals::Box_Fill)
                {
                    Menu::CheckBox("Fill Gradient", &Globals::Visuals::Box_Fill_Gradient);
                    if (Globals::Visuals::Box_Fill_Gradient)
                    {
                        Menu::CheckBox("Fill Rotation", &Globals::Visuals::Box_Fill_Gradient_Rotate);
                        if (Globals::Visuals::Box_Fill_Gradient_Rotate)
                        {
                            Menu::Combo("Rotation Type", &Globals::Visuals::Box_Fill_Type, { "Side", "Bottom", "Spin" });
                            Menu::SliderInt("Rotation Speed", &Globals::Visuals::BoxFillSpeed, 1, 5);
                        }
                    }
                }
                if (Globals::Visuals::Name)
                {
                    Menu::Combo("Name Display", &Globals::Visuals::Name_Type, { "Name", "Display Name", "Name & Display Name" });
                }
                if (Globals::Visuals::Chams)
                {
                    Menu::CheckBox("Chams Fade", &Globals::Visuals::ChamsFade);
                    if (Globals::Visuals::ChamsFade)
                    {
                        Menu::SliderInt("Fade Speed", &Globals::Visuals::ChamsFadeSpeed, 1, 5);
                    }
                }
                Menu::EndChild();
            }
        }

        if (Section == 2) // MISC/RAGE
        {
            ImVec2 AvailSize(ContentMax.x - ContentMin.x, ContentMax.y - ContentMin.y);
            float Spacing = Style.ItemSpacing.x;
            float LeftWidth = (AvailSize.x - Spacing) * 0.5f;
            float RightWidth = AvailSize.x - Spacing - LeftWidth;
            float SidePad = 4.0f;
            float HalfHeight = (AvailSize.y - SidePad * 2.0f) * 0.5f;

            ImGui::SetCursorPosX(ImGui::GetCursorPosX() + SidePad);
            ImGui::SetCursorPosY(ImGui::GetCursorPosY() + SidePad);

            if (Menu::BeginChild("other shit", ImVec2(AvailSize.x - SidePad * 2.0f, AvailSize.y - SidePad * 2.0f)))
            {
                Menu::CheckBox("Custom FireRate", &Globals::Misc::firerate);
                Menu::SliderFloat("Rate", &Globals::Misc::fireratevalue, 0.01f, 1.0f);
                ImGui::Separator();
                Menu::CheckBox("Enable Fly", &Globals::Misc::Fly);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x + 12.0f);
                Menu::KeyBindEx("Fly Key", &Globals::Misc::Fly_Key, &Globals::Misc::Fly_Mode);
                Menu::SliderFloat("Fly Speed", &Globals::Misc::Fly_Speed, 1.0f, 150.0f, "%.1f");
                Menu::CheckBox("Noclip", &Globals::Misc::Noclip);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x + 12.0f);
                Menu::KeyBindEx("Noclip Key", &Globals::Misc::Noclip_Key, &Globals::Misc::Noclip_Mode);
                Menu::CheckBox("Desync", &Globals::Misc::Desync);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x + 12.0f);
                Menu::KeyBindEx("Desync Key", &Globals::Misc::Desync_Key, &Globals::Misc::Desync_Mode);
                Menu::CheckBox("Ghost Chams", &Globals::Misc::DesyncChams);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                Menu::ColorEdit4("Ghost Color", Globals::Misc::DesyncChamsColor);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() - 24.0f);
                Menu::ColorEdit4("Ghost Outline", Globals::Misc::DesyncChamsOutline);
                Menu::CheckBox("Hitbox Expander", &Globals::Hitbox::Enabled);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x + 12.0f);
                Menu::KeyBindEx("Hitbox Key", &Globals::Hitbox::Hitbox_Key, &Globals::Hitbox::Hitbox_Mode);
                if (Globals::Hitbox::Enabled)
                {
                    Menu::SliderFloat("Hitbox Size", &Globals::Hitbox::Size, 1.0f, 20.0f, "%.1f");
                    Menu::CheckBox("Head Only", &Globals::Hitbox::HeadOnly);
                    Menu::CheckBox("Draw Hitbox", &Globals::Hitbox::DrawHitbox);
                    if (Globals::Hitbox::DrawHitbox)
                    {
                        ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                        Menu::ColorEdit4("Box Color", Globals::Hitbox::HitboxColor);
                        Menu::CheckBox("Fill Hitbox", &Globals::Hitbox::FillHitbox);
                        if (Globals::Hitbox::FillHitbox)
                        {
                            ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                            Menu::ColorEdit4("Fill Color", Globals::Hitbox::HitboxFillColor);
                        }
                        Menu::SliderFloat("Thickness", &Globals::Hitbox::HitboxThickness, 0.5f, 5.0f, "%.1f");
                    }
                }
                Menu::EndChild();
            }
        }

        if (Section == 3) {} // Players
        if (Section == 4) {} // Explorer
        // Section 5 - Settings
        if (Section == 5)
        {
            ImVec2 AvailSize(ContentMax.x - ContentMin.x, ContentMax.y - ContentMin.y);
            float Spacing = Style.ItemSpacing.x;
            float LeftWidth = (AvailSize.x - Spacing) * 0.5f;
            float RightWidth = AvailSize.x - Spacing - LeftWidth;
            float SidePad = 4.0f;
            float HalfHeight = (AvailSize.y - SidePad * 2.0f) * 0.5f;

            ImGui::SetCursorPosX(ImGui::GetCursorPosX() + SidePad);
            ImGui::SetCursorPosY(ImGui::GetCursorPosY() + SidePad);

            static char configName[64] = "";
            static int selectedConfig = 0;

            // ============================================
            // ЛЕВАЯ КОЛОНКА - НАСТРОЙКИ
            // ============================================
            if (Menu::BeginChild("Settings", ImVec2(LeftWidth - SidePad, HalfHeight)))
            {
                Menu::CheckBox("Streamproof", &Globals::Settings::Streamproof);
                Menu::Combo("Performance Type", &Globals::Settings::Performance_Mode, { "Low", "Medium", "High" });
                Menu::CheckBox("Wobbly Animation", &Globals::Settings::Wobbly_Enabled);
                if (Globals::Settings::Wobbly_Enabled)
                {
                    Menu::SliderFloat("Wobbly Strength", &Globals::Settings::Wobbly_Strength, 0.0f, 10.0f, "%.1f");
                    Menu::SliderFloat("Wobbly Speed", &Globals::Settings::Wobbly_Speed, 1.0f, 10.0f, "%.1f");
                }
                Menu::EndChild();
            }

            // ============================================
            // ПРАВАЯ КОЛОНКА - КОНФИГИ
            // ============================================
            ImGui::SameLine(0.0f, Spacing);

            if (Menu::BeginChild("Config", ImVec2(RightWidth - SidePad, HalfHeight)))
            {
                ImDrawList* DrawList = ImGui::GetWindowDrawList();

                // Поле ввода имени конфига
                ImVec2 inputPos = ImGui::GetCursorScreenPos();
                float inputWidth = ImGui::GetContentRegionAvail().x;
                float inputHeight = 20.f;
                ImVec2 inputMin = inputPos;
                ImVec2 inputMax = ImVec2(inputMin.x + inputWidth, inputMin.y + inputHeight);

                // 1. ГРАДИЕНТНЫЙ ФОН
                ImU32 inputBgTop = IM_COL32(26, 26, 26, 255);
                ImU32 inputBgBot = IM_COL32(31, 31, 31, 255);
                DrawList->AddRectFilledMultiColor(inputMin, inputMax, inputBgTop, inputBgTop, inputBgBot, inputBgBot);

                // 2. ВНУТРЕННЯЯ РАМКА
                DrawList->AddRect(inputMin + ImVec2(1, 1), inputMax - ImVec2(1, 1), IM_COL32(42, 42, 42, 255), 0.f, 0, 1.f);

                // 3. ГЛАВНАЯ РАМКА
                DrawList->AddRect(inputMin, inputMax, IM_COL32(0, 0, 0, 255), 0.f, 0, 1.f);

                // 4. InputText (с правильными отступами чтобы текст не выходил)
                ImGui::PushStyleColor(ImGuiCol_Text, Menu::TextDim);
                ImGui::PushStyleColor(ImGuiCol_FrameBg, IM_COL32(0, 0, 0, 0));
                ImGui::PushStyleColor(ImGuiCol_Border, IM_COL32(0, 0, 0, 0));
                ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
                ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(4.f, 0.f));  // ← МЕНЬШЕ ОТСТУП
                ImGui::PushItemWidth(inputWidth - 8.f);  // ← ЧУТЬ УЖЕ ЧТОБЫ ВЛЕЗЛО
                ImGui::SetCursorScreenPos(ImVec2(inputMin.x + 4.f, inputMin.y - 1.f));  // ← ОТСТУП СЛЕВА 4px
                ImGui::InputText("##ConfigName", configName, sizeof(configName));
                ImGui::PopItemWidth();
                ImGui::PopStyleVar(2);
                ImGui::PopStyleColor(3);

                // 5. Продвигаем курсор вниз
                ImGui::SetCursorScreenPos(ImVec2(inputMin.x, inputMax.y + 8.f));

                ImGui::Spacing();

                // Кнопки ПОДГОНЯЕМ ПОД ОКНО
                float contentWidth = ImGui::GetContentRegionAvail().x;
                float buttonWidth = (contentWidth - Style.ItemSpacing.x * 2) / 3;
                ImVec2 buttonSize(buttonWidth, 20.f);

                ImVec2 cursorPos = ImGui::GetCursorScreenPos();

                // ============================================
                // SAVE BUTTON
                // ============================================
                ImVec2 saveMin = cursorPos;
                ImVec2 saveMax = ImVec2(saveMin.x + buttonSize.x, saveMin.y + buttonSize.y);

                bool saveHovered = ImGui::IsMouseHoveringRect(saveMin, saveMax);
                bool saveClicked = saveHovered && ImGui::IsMouseClicked(0);

                // 1. ГРАДИЕНТНЫЙ ФОН (#1a1a1a → #1f1f1f)
                ImU32 saveBgTop = IM_COL32(26, 26, 26, 255);
                ImU32 saveBgBot = IM_COL32(31, 31, 31, 255);
                DrawList->AddRectFilledMultiColor(saveMin, saveMax, saveBgTop, saveBgTop, saveBgBot, saveBgBot);

                // 2. ВНУТРЕННЯЯ РАМКА
                ImU32 saveInner = saveHovered ? IM_COL32(53, 42, 53, 255) : IM_COL32(42, 42, 42, 255);
                DrawList->AddRect(saveMin + ImVec2(1, 1), saveMax - ImVec2(1, 1), saveInner, 0.f, 0, 1.f);

                // 3. ГЛАВНАЯ РАМКА (#000000)
                DrawList->AddRect(saveMin, saveMax, IM_COL32(0, 0, 0, 255), 0.f, 0, 1.f);

                // 4. Свечение при наведении
                if (saveHovered) {
                    DrawList->AddRectFilled(saveMin + ImVec2(2, 2), saveMax - ImVec2(2, 2),
                        IM_COL32(200, 150, 200, 70), 0.f, 0);
                }

                // 5. Текст (СЕРЫЙ КАК В COMBO/KEYBIND - Menu::TextDim)
                ImVec2 saveTextSize = ImGui::CalcTextSize("Save");
                ImVec2 saveTextPos(saveMin.x + (buttonSize.x - saveTextSize.x) * 0.5f,
                    saveMin.y + (buttonSize.y - saveTextSize.y) * 0.5f);
                DrawList->AddText(saveTextPos, Menu::TextDim, "Save");  // ← ИЗМЕНЁН ЦВЕТ!

                if (saveClicked) {
                    if (strlen(configName) > 0) {
                        try { Config::Manager::Save(configName); }
                        catch (...) {}
                    }
                }

                // ============================================
                // LOAD BUTTON
                // ============================================
                ImGui::SetCursorScreenPos(ImVec2(saveMin.x + buttonSize.x + Style.ItemSpacing.x, saveMin.y));
                ImVec2 loadMin = ImGui::GetCursorScreenPos();
                ImVec2 loadMax = ImVec2(loadMin.x + buttonSize.x, loadMin.y + buttonSize.y);

                bool loadHovered = ImGui::IsMouseHoveringRect(loadMin, loadMax);
                bool loadClicked = loadHovered && ImGui::IsMouseClicked(0);

                // 1. ГРАДИЕНТНЫЙ ФОН
                ImU32 loadBgTop = IM_COL32(26, 26, 26, 255);
                ImU32 loadBgBot = IM_COL32(31, 31, 31, 255);
                DrawList->AddRectFilledMultiColor(loadMin, loadMax, loadBgTop, loadBgTop, loadBgBot, loadBgBot);

                // 2. ВНУТРЕННЯЯ РАМКА
                ImU32 loadInner = loadHovered ? IM_COL32(53, 42, 53, 255) : IM_COL32(42, 42, 42, 255);
                DrawList->AddRect(loadMin + ImVec2(1, 1), loadMax - ImVec2(1, 1), loadInner, 0.f, 0, 1.f);

                // 3. ГЛАВНАЯ РАМКА
                DrawList->AddRect(loadMin, loadMax, IM_COL32(0, 0, 0, 255), 0.f, 0, 1.f);

                // 4. Свечение
                if (loadHovered) {
                    DrawList->AddRectFilled(loadMin + ImVec2(2, 2), loadMax - ImVec2(2, 2),
                        IM_COL32(153, 115, 153, 50), 0.f, 0);
                }

                // 5. Текст (СЕРЫЙ КАК В COMBO/KEYBIND - Menu::TextDim)
                ImVec2 loadTextSize = ImGui::CalcTextSize("Load");
                ImVec2 loadTextPos(loadMin.x + (buttonSize.x - loadTextSize.x) * 0.5f,
                    loadMin.y + (buttonSize.y - loadTextSize.y) * 0.5f);
                DrawList->AddText(loadTextPos, Menu::TextDim, "Load");  // ← ИЗМЕНЁН ЦВЕТ!

                if (loadClicked) {
                    try {
                        auto configs = Config::Manager::ListConfigs();
                        if (selectedConfig >= 0 && selectedConfig < (int)configs.size()) {
                            Config::Manager::Load(configs[selectedConfig]);
                        }
                    }
                    catch (...) {}
                }

                // ============================================
                // DELETE BUTTON
                // ============================================
                ImGui::SetCursorScreenPos(ImVec2(loadMin.x + buttonSize.x + Style.ItemSpacing.x, loadMin.y));
                ImVec2 deleteMin = ImGui::GetCursorScreenPos();
                ImVec2 deleteMax = ImVec2(deleteMin.x + buttonSize.x, deleteMin.y + buttonSize.y);

                bool deleteHovered = ImGui::IsMouseHoveringRect(deleteMin, deleteMax);
                bool deleteClicked = deleteHovered && ImGui::IsMouseClicked(0);

                // 1. ГРАДИЕНТНЫЙ ФОН
                ImU32 deleteBgTop = IM_COL32(26, 26, 26, 255);
                ImU32 deleteBgBot = IM_COL32(31, 31, 31, 255);
                DrawList->AddRectFilledMultiColor(deleteMin, deleteMax, deleteBgTop, deleteBgTop, deleteBgBot, deleteBgBot);

                // 2. ВНУТРЕННЯЯ РАМКА
                ImU32 deleteInner = deleteHovered ? IM_COL32(53, 42, 53, 255) : IM_COL32(42, 42, 42, 255);
                DrawList->AddRect(deleteMin + ImVec2(1, 1), deleteMax - ImVec2(1, 1), deleteInner, 0.f, 0, 1.f);

                // 3. ГЛАВНАЯ РАМКА
                DrawList->AddRect(deleteMin, deleteMax, IM_COL32(0, 0, 0, 255), 0.f, 0, 1.f);

                // 4. Свечение
                if (deleteHovered) {
                    DrawList->AddRectFilled(deleteMin + ImVec2(2, 2), deleteMax - ImVec2(2, 2),
                        IM_COL32(153, 115, 153, 50), 0.f, 0);
                }

                // 5. Текст (СЕРЫЙ КАК В COMBO/KEYBIND - Menu::TextDim)
                ImVec2 deleteTextSize = ImGui::CalcTextSize("Delete");
                ImVec2 deleteTextPos(deleteMin.x + (buttonSize.x - deleteTextSize.x) * 0.5f,
                    deleteMin.y + (buttonSize.y - deleteTextSize.y) * 0.5f);
                DrawList->AddText(deleteTextPos, Menu::TextDim, "Delete");  // ← ИЗМЕНЁН ЦВЕТ!

                if (deleteClicked) {
                    try {
                        auto configs = Config::Manager::ListConfigs();
                        if (selectedConfig >= 0 && selectedConfig < (int)configs.size()) {
                            Config::Manager::DeleteConfig(configs[selectedConfig]);
                            if (selectedConfig >= (int)Config::Manager::ListConfigs().size() &&
                                !Config::Manager::ListConfigs().empty()) {
                                selectedConfig = std::max(0, (int)Config::Manager::ListConfigs().size() - 1);
                            }
                        }
                    }
                    catch (...) {}
                }

                // Продвигаем курсор вниз после кнопок
                ImGui::SetCursorScreenPos(ImVec2(cursorPos.x, cursorPos.y + buttonSize.y + 8.f));

                ImGui::Spacing();

                // Список конфигов
                try {
                    auto configs = Config::Manager::ListConfigs();

                    if (!configs.empty() && selectedConfig >= (int)configs.size()) {
                        selectedConfig = 0;
                    }
                    if (configs.empty()) {
                        selectedConfig = -1;
                    }

                    if (!configs.empty()) {
                        std::vector<const char*> items;
                        items.reserve(configs.size());
                        for (const auto& cfg : configs) {
                            items.push_back(cfg.c_str());
                        }

                        ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x);
                        Menu::Combo("##ConfigList", &selectedConfig, items);
                        ImGui::PopItemWidth();
                    }
                    else {
                        ImGui::TextDisabled("No configs found");
                    }
                }
                catch (...) {
                    ImGui::TextDisabled("Error loading configs");
                }

                Menu::EndChild();
            }
        }

        ImGui::EndGroup();
        ImGui::PopClipRect();

        // ============================================
        // ЗАГОЛОВОК И ТАБЫ (ПОВЕРХ ВСЕГО)
        // ============================================
        float TextX = WinPos.x + Style.WindowBorderSize + 8.0f;
        float TextY = WinPos.y + (Top - ImGui::CalcTextSize("Fang.wtf").y) * 0.5f + 8.0f;
        ImVec2 TextPos(TextX, TextY);
        Menu::DrawLabelShadow(DrawList, TextPos, Menu::Accent, "Fang.");
        TextPos.x += ImGui::CalcTextSize("Fang.").x;
        Menu::DrawLabelShadow(DrawList, TextPos, Menu::Text, "wtf");
        Menu::Tabs(DrawList, WinPos, TextY, Section, TabLabels, TabCount, 10.0f, 8.0f);
    }
    ImGui::End();

}

// ==========================================
// RENDER VISUALS
// ==========================================
void Graphics::Render_Visuals()
{
    DrawCursor();
    Visuals::RunService();

    if (Globals::Misc::Desync && Globals::Misc::desync_active && Globals::Misc::DesyncChams)
    {
        SDK::VisualEngine Ve(Globals::VisualEngine.Address);
        SDK::Vector3 pos = Globals::Misc::desync_activation_pos;

        float w = 2.0f;
        float h = 3.0f;
        float d = 1.0f;

        HWND hwnd = FindWindowA(0, "Roblox");
        POINT offset = { 0, 0 };
        RECT ClientRect = { 0, 0, 0, 0 };

        if (hwnd) {
            ClientToScreen(hwnd, &offset);
            GetClientRect(hwnd, &ClientRect);
        }

        auto v1 = Ve.World_To_Screen(SDK::Vector3(pos.x - w, pos.y + h, pos.z - d)); ImVec2 s1(v1.x + offset.x, v1.y + offset.y);
        auto v2 = Ve.World_To_Screen(SDK::Vector3(pos.x + w, pos.y + h, pos.z - d)); ImVec2 s2(v2.x + offset.x, v2.y + offset.y);
        auto v3 = Ve.World_To_Screen(SDK::Vector3(pos.x + w, pos.y + h, pos.z + d)); ImVec2 s3(v3.x + offset.x, v3.y + offset.y);
        auto v4 = Ve.World_To_Screen(SDK::Vector3(pos.x - w, pos.y + h, pos.z + d)); ImVec2 s4(v4.x + offset.x, v4.y + offset.y);
        auto v5 = Ve.World_To_Screen(SDK::Vector3(pos.x - w, pos.y - h, pos.z - d)); ImVec2 s5(v5.x + offset.x, v5.y + offset.y);
        auto v6 = Ve.World_To_Screen(SDK::Vector3(pos.x + w, pos.y - h, pos.z - d)); ImVec2 s6(v6.x + offset.x, v6.y + offset.y);
        auto v7 = Ve.World_To_Screen(SDK::Vector3(pos.x + w, pos.y - h, pos.z + d)); ImVec2 s7(v7.x + offset.x, v7.y + offset.y);
        auto v8 = Ve.World_To_Screen(SDK::Vector3(pos.x - w, pos.y - h, pos.z + d)); ImVec2 s8(v8.x + offset.x, v8.y + offset.y);

        auto vc = Ve.World_To_Screen(pos); ImVec2 center(vc.x + offset.x, vc.y + offset.y);

        if (vc.x > offset.x && vc.y > offset.y && vc.x < (offset.x + ClientRect.right) && vc.y < (offset.y + ClientRect.bottom))
        {
            ImDrawList* DrawList = ImGui::GetBackgroundDrawList();

            ImU32 FillColor = ImGui::ColorConvertFloat4ToU32(*(ImVec4*)Globals::Misc::DesyncChamsColor);
            ImU32 OutlineColor = ImGui::ColorConvertFloat4ToU32(*(ImVec4*)Globals::Misc::DesyncChamsOutline);

            DrawList->AddQuadFilled(s1, s2, s6, s5, FillColor);
            DrawList->AddQuadFilled(s2, s3, s7, s6, FillColor);
            DrawList->AddQuadFilled(s3, s4, s8, s7, FillColor);
            DrawList->AddQuadFilled(s4, s1, s5, s8, FillColor);
            DrawList->AddQuadFilled(s1, s2, s3, s4, FillColor);
            DrawList->AddQuadFilled(s5, s6, s7, s8, FillColor);

            float t = 1.5f;
            DrawList->AddLine(s1, s2, OutlineColor, t); DrawList->AddLine(s2, s3, OutlineColor, t);
            DrawList->AddLine(s3, s4, OutlineColor, t); DrawList->AddLine(s4, s1, OutlineColor, t);
            DrawList->AddLine(s5, s6, OutlineColor, t); DrawList->AddLine(s6, s7, OutlineColor, t);
            DrawList->AddLine(s7, s8, OutlineColor, t); DrawList->AddLine(s8, s5, OutlineColor, t);
            DrawList->AddLine(s1, s5, OutlineColor, t); DrawList->AddLine(s2, s6, OutlineColor, t);
            DrawList->AddLine(s3, s7, OutlineColor, t); DrawList->AddLine(s4, s8, OutlineColor, t);

            const char* Text = "DESYNC";
            ImGui::PushFont(Tahoma_BoldXP);

            ImVec2 TextSize = ImGui::CalcTextSize(Text);

            // FIX: Без std::min
            float s12 = s1.y < s2.y ? s1.y : s2.y;
            float s34 = s3.y < s4.y ? s3.y : s4.y;
            float highestY = s12 < s34 ? s12 : s34;

            ImVec2 TextPos(center.x - (TextSize.x / 2.0f), highestY - TextSize.y - 4.0f);

            ImU32 BlackStroke = IM_COL32(0, 0, 0, 255);
            DrawList->AddText(ImVec2(TextPos.x + 1, TextPos.y), BlackStroke, Text);
            DrawList->AddText(ImVec2(TextPos.x - 1, TextPos.y), BlackStroke, Text);
            DrawList->AddText(ImVec2(TextPos.x, TextPos.y + 1), BlackStroke, Text);
            DrawList->AddText(ImVec2(TextPos.x, TextPos.y - 1), BlackStroke, Text);
            DrawList->AddText(ImVec2(TextPos.x + 1, TextPos.y + 1), BlackStroke, Text);
            DrawList->AddText(ImVec2(TextPos.x - 1, TextPos.y - 1), BlackStroke, Text);
            DrawList->AddText(ImVec2(TextPos.x + 1, TextPos.y - 1), BlackStroke, Text);
            DrawList->AddText(ImVec2(TextPos.x - 1, TextPos.y + 1), BlackStroke, Text);

            DrawList->AddText(TextPos, OutlineColor, Text);

            ImGui::PopFont();
        }
    }
}