stateDiagram-v2
    direction LR
    init: Initialization
    app_loaded: Built-in App Mode – select target app via SDK load_app interface
    ext_ctrl: External Control Mode – switch control modes via SDK switch_mode interface

    offline_connected: USB connected, waiting for control service

    state ext_ctrl {
      direction LR
      planning_pos: Position control (trajectory)
      servo_pos_joint: Position servo – joint space
      servo_pos_cart: Position servo – Cartesian space
      servo_vel_joint: Velocity servo – joint space
      servo_vel_cart: Velocity servo – Cartesian space
      gravity_comp: Gravity compensation
    }

    [*] --> init: power on
    init --> offline_connected: USB attached
    offline_connected --> ext_ctrl: control service started
    ext_ctrl --> app_loaded: base button [long press]
    app_loaded --> ext_ctrl: SDK call [unload_app]
    app_loaded --> ext_ctrl: base button [long press]
    ext_ctrl --> app_loaded: SDK call [load_app]

    classDef cyan     fill:#00FFFF,stroke:#007F7F,stroke-width:2px,color:#000;
    classDef blue     fill:#7F7FFF,stroke:#3F3F7F,stroke-width:2px,color:#000;
    classDef red      fill:#FF7F7F,stroke:#7F3F3F,stroke-width:2px,color:#000;
    classDef purple   fill:#FF7FFF,stroke:#7F3F7F,stroke-width:2px,color:#000;
    classDef green    fill:#7FFF7F,stroke:#3F7F3F,stroke-width:2px,color:#000;
    classDef yellow   fill:#FFFF3F,stroke:#7F7F3F,stroke-width:2px,color:#000;
    classDef light_grey fill:#BBBBBB,stroke:#777777,stroke-width:2px,color:#000;

    class planning_pos green
    class servo_pos_joint green
    class servo_pos_cart green
    class servo_vel_joint green
    class servo_vel_cart green
    class gravity_comp green

    class self_check yellow
    class calibration_needed yellow, flashing
    class offline_idle light_grey
    class offline_connected light_grey, breathing
    class failure red