flowchart TD
    A["HyprTile Launcher"] -->|"F6"| B["notes_overlay"]

    B --> State["NotesOverlayState"]
    State --> Visible["visible"]
    State --> Mode["mode: Liste oder Editor"]
    State --> Focus["focus: Liste/Suche, Titel, Markdown, Ziel-Datum"]
    State --> Search["search"]
    State --> Items["NotesListItem[] bis 256"]
    State --> Current["current_id / current_type"]
    State --> Title["title"]
    State --> Markdown["markdown bis 131072 Bytes"]
    State --> Todo["Todo-Felder"]
    State --> Cursor["Cursor / Selection / Scroll"]
    State --> Dirty["dirty"]
    State --> Preview["preview_mode"]
    State --> Status["status"]

    B --> UI["Overlay UI"]
    UI --> ListView["Listen-/Suchansicht"]
    UI --> EditorView["Editor"]
    UI --> Toolbar["Markdown Toolbar"]
    UI --> TodoBar["Todo-Leiste"]
    UI --> Picker["Interne Datei-/Bildauswahl"]
    UI --> PreviewView["Markdown Preview"]

    ListView --> SearchBox["Suche"]
    ListView --> NoteList["Notiz-/Todo-Liste"]
    ListView --> NewNote["Neue Notiz"]
    ListView --> NewTodo["Neues Todo"]
    ListView --> OpenSelected["Ausgewählten Eintrag öffnen"]

    B --> Backend["hyprtile-notes CLI"]
    Backend --> ReadCmd["notes_read_command"]
    ReadCmd --> CLI["hyprtile-notes/hyprtile-notes"]
    CLI --> Json["JSON Antwort"]
    Json --> AppJson["app_json_parse_object / array"]

    SearchBox --> UpdateList["notes_overlay_update_if_needed"]
    UpdateList --> Backend
    Backend --> Items

    NewNote --> EditorView
    NewTodo --> EditorView
    OpenSelected --> LoadNote["Eintrag laden"]
    LoadNote --> Backend
    Backend --> Title
    Backend --> Markdown
    Backend --> Todo

    EditorView --> TitleField["Titel-Feld"]
    EditorView --> MarkdownField["Markdown-Feld"]
    EditorView --> TargetDate["Todo Ziel-Datum"]
    EditorView --> Save["Speichern"]
    EditorView --> DirtyFlag["dirty markieren"]

    TitleField --> TextInput["Text einfügen"]
    MarkdownField --> TextInput
    TargetDate --> TextInput

    TextInput --> Utf8Safe["UTF-8 Cursor-Grenzen"]
    Utf8Safe --> Cursor
    TextInput --> DirtyFlag

    MarkdownField --> Selection["Selection Handling"]
    Selection --> Copy["Copy"]
    Selection --> Cut["Cut"]
    Selection --> DeleteSelection["Selection löschen"]
    Selection --> SelectAll["Alles auswählen"]

    MarkdownField --> CursorMove["Cursor Navigation"]
    CursorMove --> LeftRight["Links / Rechts"]
    CursorMove --> UpDown["Hoch / Runter"]
    CursorMove --> HomeEnd["Home / End"]
    CursorMove --> WithSelect["Shift-Selection Varianten"]

    Toolbar --> H1["Heading"]
    Toolbar --> Bold["Bold"]
    Toolbar --> Italic["Italic"]
    Toolbar --> Underline["Underline"]
    Toolbar --> List["Liste"]
    Toolbar --> Link["Link"]
    Toolbar --> Image["Bild einfügen"]
    Toolbar --> File["Datei einfügen"]
    Toolbar --> Export["Export"]
    Toolbar --> PreviewToggle["Preview umschalten"]

    H1 --> MdTransform["Markdown transformieren"]
    Bold --> MdTransform
    Italic --> MdTransform
    Underline --> MdTransform
    List --> MdTransform
    Link --> MdTransform
    MdTransform --> Markdown

    TodoBar --> Percent["Todo Prozent"]
    TodoBar --> TodoStatus["Todo Status"]
    TodoBar --> TargetDate
    Percent --> Todo
    TodoStatus --> Todo

    Image --> Picker
    File --> Picker

    Picker --> Cwd["cwd"]
    Picker --> Filter["Filter"]
    Picker --> PickerItems["Datei-/Ordnerliste bis 512"]
    Picker --> OpenFile["Enter / Klick öffnet"]
    Picker --> Parent[".. / Backspace"]
    Picker --> Cancel["Esc"]

    OpenFile --> InsertAttachment["notes_insert_attachment_from_path"]
    InsertAttachment --> AssetDir["~/.hyprtile/notes/assets"]
    AssetDir --> MarkdownLink["Markdown-Link oder Bild-Markdown"]
    MarkdownLink --> Markdown

    PreviewToggle --> PreviewView
    PreviewView --> MarkdownParse["Markdown grob rendern"]
    MarkdownParse --> TextPreview["Textblöcke"]
    MarkdownParse --> ImageRefs["Bildreferenzen"]
    ImageRefs --> ResolveAsset["assets/ oder absolute Pfade auflösen"]
    ResolveAsset --> ImageCache["notes_image_cache"]
    ImageCache --> FFmpegImage["Bild über FFmpeg laden"]
    FFmpegImage --> SDLTexture["SDL_Texture Preview"]

    Save --> TempMd["temporäre Markdown-Datei"]
    TempMd --> Backend
    Backend --> Saved["gespeichert"]
    Saved --> DirtyClear["dirty = 0"]
    Saved --> UpdateList

    Export --> ExportFormat["PDF / HTML / Markdown o.ä."]
    ExportFormat --> Backend

    B --> Render["render_notes_overlay"]
    Render --> Panel["1680x920 Panel"]
    Render --> Sidebar["330px Sidebar"]
    Render --> EditorPanel["Editorbereich"]
    Render --> ToolButtons["15 Toolbar Buttons"]
    Render --> StatusLine["Statuszeile"]