```lua
local imgui = require('imgui')
local encoding = require('encoding')
encoding.default = 'CP1251'
local u8 = encoding.UTF8
local windowVisible = imgui.ImBool(false)
local inputText = imgui.ImBuffer(1024)
local inputTitle = imgui.ImBuffer(256)
local searchQuery = imgui.ImBuffer(256)
local notes = {}
local function toggleWindow()
    windowVisible.v = not windowVisible.v
end

local function initialize()
    sampRegisterChatCommand('notepad', toggleWindow)
    while not isSampAvailable() do
        wait(200)
    end

    imgui.Process = false
end

local function addNote()
    if inputText.v ~= '' and inputTitle.v ~= '' then
        table.insert(notes, {
            title = inputTitle.v,
            content = inputText.v
        })

        inputText.v = ''
        inputTitle.v = ''
    end
end

local function drawNotes()
    imgui.Text(u8'Заметки:')
    for i, note in ipairs(notes) do
        local isMatch = searchQuery.v == '' or note.title:lower():find(searchQuery.v:lower()) or note.content:lower():find(searchQuery.v:lower())
        if isMatch and imgui.TreeNode(note.title .. '##' .. i) then
            imgui.TextWrapped(note.content)
            if imgui.Button(u8'Редактировать##' .. i) then
                inputTitle.v = note.title
                inputText.v = note.content
                table.remove(notes, i)
            end

            imgui.SameLine()
            if imgui.Button(u8'Удалить##' .. i) then table.remove(notes, i) end
            imgui.TreePop()
        end
    end
end

local function drawFrame()
    if not windowVisible.v then return end
    local resX, resY = getScreenResolution()
    imgui.SetNextWindowPos(imgui.ImVec2(resX / 2 - 250, resY / 2 - 200), imgui.Cond.FirstUseEver)
    imgui.SetNextWindowSize(imgui.ImVec2(500, 400), imgui.Cond.FirstUseEver)
    imgui.Begin(u8'Блокнот для Даня Модеров', windowVisible, imgui.WindowFlags.MenuBar)
    if imgui.BeginMenuBar() then
        if imgui.BeginMenu(u8'Действия') then
            if imgui.MenuItem(u8'Очистить все заметки') then notes = {} end
            imgui.EndMenu()
        end

        imgui.EndMenuBar()
    end

    imgui.InputText(u8'Название заметки', inputTitle, imgui.ImVec2(-1, 0))
    imgui.InputTextMultiline(u8'Новая заметка', inputText, imgui.ImVec2(-1, 100))
    if imgui.Button(u8'Добавить заметку') then addNote() end
    imgui.Separator()
    imgui.InputText(u8'Поиск', searchQuery, imgui.ImVec2(-1, 0))
    drawNotes()
    imgui.End()
end

function main()
    initialize()
    while true do
        wait(0)
        imgui.Process = windowVisible.v
    end
end

function imgui.OnDrawFrame()
    drawFrame()
end

function apply_custom_style()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    local ImVec4 = imgui.ImVec4
    style.WindowRounding = 5.0
    style.WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
    style.ChildWindowRounding = 5.0
    style.FrameRounding = 5.0
    style.ItemSpacing = imgui.ImVec2(10.0, 10.0)
    style.ScrollbarSize = 15.0
    style.ScrollbarRounding = 5.0
    style.GrabMinSize = 10.0
    style.GrabRounding = 5.0
    colors[clr.WindowBg] = ImVec4(0.1, 0.1, 0.1, 1.0)
    colors[clr.TitleBg] = ImVec4(0.2, 0.2, 0.2, 1.0)
    colors[clr.TitleBgActive] = ImVec4(0.3, 0.3, 0.3, 1.0)
    colors[clr.Button] = ImVec4(0.2, 0.2, 0.2, 1.0)
    colors[clr.ButtonHovered] = ImVec4(0.3, 0.3, 0.3, 1.0)
    colors[clr.ButtonActive] = ImVec4(0.4, 0.4, 0.4, 1.0)
    colors[clr.FrameBg] = ImVec4(0.2, 0.2, 0.2, 1.0)
    colors[clr.FrameBgHovered] = ImVec4(0.3, 0.3, 0.3, 1.0)
    colors[clr.FrameBgActive] = ImVec4(0.4, 0.4, 0.4, 1.0)
    colors[clr.CheckMark] = ImVec4(0.0, 0.5, 0.0, 1.0)
end

apply_custom_style()
```
Figure out how to optimize the code, how to improve the code, how to improve the interface, how to make it clearer and simpler, figure out what functions can be added, how to implement them, implement the complete ready optimized and improved code