function __kitty_tab_set -d "Tint the current kitty tab for the given ssh/mosh host"
    set -l host $argv[1]
    set -q KITTY_WINDOW_ID; and type -q kitten; and test -n "$host"
    or return 0

    set -l colors (__kitty_host_color $host)
    # If the typed name only got a hash color, retry with the
    # ssh_config-resolved hostname (it may be in the explicit table).
    if test (string split ' ' $colors)[3] = hash
        set -l resolved (command ssh -G $host 2>/dev/null \
            | string match -r '^hostname .*' | string split ' ')[2]
        if test -n "$resolved"; and test "$resolved" != "$host"
            set -l rcolors (__kitty_host_color $resolved)
            test (string split ' ' $rcolors)[3] = explicit; and set colors $rcolors
        end
    end
    set -l bg (string split ' ' $colors)[1]
    set -l fg (string split ' ' $colors)[2]

    # Active tab: full host-color background, readable fg.
    # Inactive tab: keep theme's dark background (NONE), host color as text only.
    kitten @ set-tab-color "active_bg=$bg" "active_fg=$fg" \
        "inactive_bg=NONE" "inactive_fg=$bg" 2>/dev/null
    kitten @ set-tab-title "$host" 2>/dev/null
end
