Different custom panel CSS files for different user roles

I would like to have different Custom Panel CSS files for different roles, e.g. to hide the Panel Search button at the top right (customers) or not (admin).

I tried two ‘solutions’, none of them were successful :frowning:
Does anyone have another tip or are there errors in my attempts?
Is it even possible to have different Panel CSS files?

Solution 1
similar to the solution for role related blueprints I have set up the following plugin:

$user  = $kirby->user();

if ($user && $user->role() == 'admin') {
    $dir = __DIR__. '/admin/';
} elseif ($user && $user->role() == 'editor') {
    $dir = __DIR__ . '/editor/';
}

Kirby::plugin('jf/role-panelcss', [
    'panel' => [
    	'css' => $dir . 'css/custom-panel.css'
    ]

]);

The css files are located in the plugin-folder ‘/site/plugins/jf-role-panelcss/admin/css/custom-panel.css’ respectively ‘/site/plugins/jf-role-panelcss/editor/css/custom-panel.css’

Solution 2
custom root setup
index.php

require __DIR__ . '/kirby/bootstrap.php';

$kirby = new Kirby();
$user  = $kirby->user();

if ($user && $user->role() == 'admin') {
	$kirby = new Kirby([
		'roots' => [
			'assets' => __DIR__ . '/site/assets/admin/'
		],
	]);

} elseif ($user && $user->role() == 'editor') {
	$kirby = new Kirby([
		'roots' => [
			'assets' => __DIR__ . '/site/assets/editor/'
		],
	]);
}

echo $kirby->render();

config.php

return [

  'panel' => [
    'css' => kirby()->root('assets').'/css/custom-panel.css',
  ]

];

The second option won’t work because you can’t use Kirby() in the config.
The first one won’t work because there is no such extension.

But you can use this approach and use different config roots based on user role instead: https://getkirby.com/docs/reference/system/roots/config

@texnixe Thank you very much again! works great.

If someone needs this solution as well, please note that the role-specific config-root directories must obviously NOT be under site/config/, that didn’t work for me - I created a separate directory under /site.