<div class="augur-nexus-tool augur-theme-fantasy nexus-browser-panel-shell">
    <div class="nexus-browser-hero-wrap">
        <div class="nexus-browser-hero {{#if hasRootScene}}has-root{{/if}}">
            <span class="nexus-browser-hero-backdrop {{#unless rootSceneThumb}}no-thumb{{/unless}}">
                {{#if rootSceneThumb}}
                <img src="{{rootSceneThumb}}" alt="{{rootSceneName}}">
                {{else}}
                <i class="fas fa-map"></i>
                {{/if}}
            </span>
            <span class="nexus-browser-hero-overlay"></span>
            <div class="nexus-browser-hero-corner-actions">
                {{#if isGM}}
                <button type="button" class="nexus-browser-hero-corner-action" data-action="setCurrentAsNexus" title="Set the current scene as the Nexus scene" aria-label="Set the current scene as the Nexus scene">
                    <i class="fas fa-crosshairs"></i>
                </button>
                <button type="button" class="nexus-browser-hero-corner-action {{#if appearanceOpen}}is-active{{/if}}" data-action="toggleNexusAppearance" title="Nexus appearance" aria-label="Nexus appearance" aria-expanded="{{#if appearanceOpen}}true{{else}}false{{/if}}">
                    <i class="fas fa-gear"></i>
                </button>
                {{/if}}
            </div>
            <div class="nexus-browser-hero-copy">
                <div class="nexus-browser-root-name" title="{{rootSceneName}}">{{rootSceneName}}</div>
                <div class="nexus-browser-pill-type">Nexus Scene</div>
            </div>
            <div class="nexus-browser-root-actions hero">
                <button type="button" class="site-entry-clear nexus-browser-action icon-only" data-action="returnToParentScene" title="Return to the parent scene" aria-label="Return to the parent scene" {{#unless hasBackTarget}}disabled{{/unless}}>
                    <i class="fas fa-circle-arrow-left"></i>
                </button>
                {{#if isGM}}
                <button type="button" class="site-entry-clear nexus-browser-action icon-only" data-action="openSitesTool" title="Open Sites tool" aria-label="Open Sites tool" {{#unless canOpenSitesTool}}disabled{{/unless}}>
                    <i class="fas fa-location-dot"></i>
                </button>
                {{/if}}
                <button type="button" class="site-entry-clear nexus-browser-action" data-action="openRootScene" title="Open the Nexus scene" {{#unless canOpenRootScene}}disabled{{/unless}}>
                    <i class="fas fa-map"></i>
                    <span>{{#if canOpenRootScene}}Go To Nexus{{else if rootSceneIsCurrent}}Nexus Active{{else if hasRootScene}}Scene Locked{{else}}No Nexus Scene{{/if}}</span>
                </button>
            </div>
        </div>
        {{#if appearanceOpen}}
        <section class="nexus-appearance-panel" aria-label="Nexus appearance">
            <header>
                <i class="fas fa-palette" aria-hidden="true"></i>
                <span><strong>Appearance</strong><small>Interface accent</small></span>
            </header>
            <div class="nexus-accent-presets" role="group" aria-label="Accent presets">
                {{#each accentPresets}}
                <button type="button" class="nexus-accent-preset {{#if selected}}is-selected{{/if}}" data-action="setNexusAccent" data-accent="{{value}}" title="{{label}}" aria-label="Use {{label}} accent" aria-pressed="{{#if selected}}true{{else}}false{{/if}}">
                    <span class="nexus-accent-swatch" style="--preset-accent: {{value}}"></span>
                    <small>{{label}}</small>
                </button>
                {{/each}}
            </div>
            <label class="nexus-accent-custom">
                <span>Custom</span>
                <input type="color" value="{{accentColor}}" data-nexus-accent-picker aria-label="Custom interface accent">
            </label>
        </section>
        {{/if}}
        <div class="nexus-browser-summary-line under-pill">
            <span class="nexus-browser-summary-chip" title="{{currentSceneName}}">Current: {{currentSceneName}}</span>
            {{#if hasParentScene}}
            <span class="nexus-browser-summary-chip" title="{{parentSceneName}}">Parent: {{parentSceneName}}</span>
            {{/if}}
        </div>
    </div>

    <div class="nexus-browser-tab-select">
        <i class="fas fa-layer-group" aria-hidden="true"></i>
        <select name="nexusBrowserTab" data-action="setNexusTab" aria-label="Nexus browser section">
            <option value="sites" {{#if isSitesTab}}selected{{/if}}>Sites</option>
            <option value="people" {{#if isPeopleTab}}selected{{/if}}>People</option>
            <option value="factions" {{#if isFactionsTab}}selected{{/if}}>Organizations</option>
            <option value="ships" {{#if isShipsTab}}selected{{/if}}>Ships</option>
        </select>
        <i class="fas fa-chevron-down" aria-hidden="true"></i>
    </div>

    {{#if isSitesTab}}
    <div class="nexus-browser-search-bar">
        <i class="fas fa-search"></i>
        <input type="search" name="nexusSceneSearch" value="{{searchQuery}}" placeholder="Search scenes, sites, locations, and shops" autocomplete="off" spellcheck="false" dir="ltr">
        <button type="button" class="site-entry-clear nexus-browser-search-clear" data-action="clearSceneSearch" title="Clear search" {{#unless isSearching}}hidden{{/unless}}>
            <i class="fas fa-times"></i>
        </button>
        <button type="button" class="nexus-browser-filter-toggle {{#if groupSitesByFaction}}is-active{{/if}}" data-action="toggleSiteFactionGrouping" title="Group direct locations by organization" aria-label="Group direct locations by organization" aria-pressed="{{groupSitesByFaction}}">
            <i class="fas fa-shield-halved"></i>
            <span class="nexus-browser-filter-check"><i class="fas fa-check"></i></span>
        </button>
        <button type="button" class="nexus-browser-filter-toggle {{#if focusSitesToCurrentBranch}}is-active{{/if}}" data-action="toggleSiteBranchFocus" title="Focus on current branch" aria-label="Focus on current branch" aria-pressed="{{focusSitesToCurrentBranch}}" {{#unless canFocusSitesToCurrentBranch}}disabled{{/unless}}>
            <i class="fas fa-code-branch"></i>
            <span class="nexus-browser-filter-check"><i class="fas fa-check"></i></span>
        </button>
        <button type="button" class="site-entry-clear nexus-browser-collapse-all" data-action="collapseAllScenes" title="Collapse all scenes" {{#unless hasRows}}disabled{{/unless}}>
            <i class="fas fa-compress-alt"></i>
        </button>
    </div>
    <section class="nexus-browser-section nexus-browser-tree-section">
        {{#if focusSitesToCurrentBranch}}
        <aside class="nexus-browser-branch-notice" aria-live="polite">
            <i class="fas fa-code-branch" aria-hidden="true"></i>
            <span>
                <strong>Current Branch</strong>
                <small>Other Nexus branches are hidden.</small>
            </span>
            <button type="button" data-action="toggleSiteBranchFocus" title="Show all Nexus branches">Show All</button>
        </aside>
        {{/if}}
        <div class="nexus-browser-tree" {{#unless hasRows}}hidden{{/unless}}>
            {{#each rows}}
            {{#if this.isLocationFactionGroup}}
            <div class="nexus-browser-site-faction-group {{#if this.isIndependent}}is-independent{{/if}}" style="margin-left: {{this.indent}}; --faction-accent: {{this.accent}};" data-node-id="{{this.id}}" data-view-parent-node-id="{{this.viewParentNodeId}}" data-view-depth="{{this.viewDepth}}" data-name="{{this.name}}" data-search-text="{{this.searchText}}" data-has-children="true" data-virtual-faction-group="true">
                <div class="nexus-browser-site-faction-header" {{#if this.factionId}}data-action="openFactionDossier" data-entity-id="{{this.factionId}}" role="button" tabindex="0" title="Open {{this.name}}"{{/if}}>
                    <span class="nexus-browser-site-faction-emblem">
                        {{#if this.imageSrc}}<img src="{{this.imageSrc}}" alt="">{{else}}<i class="fas fa-map-location-dot" aria-hidden="true"></i>{{/if}}
                    </span>
                    <span class="nexus-browser-site-faction-copy">
                        <strong>{{this.name}}</strong>
                        <small>{{this.subtitle}}</small>
                    </span>
                    <span class="nexus-browser-site-faction-count">{{this.count}}</span>
                    <button type="button" class="nexus-browser-site-faction-fold {{#unless this.expanded}}collapsed{{/unless}}" data-action="toggleSiteFactionGroup" data-group-id="{{this.id}}" title="Toggle {{this.name}} locations" aria-label="Toggle {{this.name}} locations" aria-expanded="{{this.expanded}}">
                        <i class="fas fa-chevron-down"></i>
                    </button>
                </div>
            </div>
            {{else}}
            <div class="nexus-browser-pill-shell {{#if this.isPending}}pending-site{{/if}} {{#if this.hasIcon}}has-site-icon{{/if}} {{#if this.isPlayerHidden}}is-player-hidden{{/if}} {{#if this.hasFactionAccent}}has-faction-accent{{/if}}" style="margin-left: {{this.indent}};{{#if this.hasFactionAccent}} --faction-accent: {{this.factionAccent}};{{/if}}" title="{{this.name}}" data-node-id="{{this.id}}" data-node-kind="{{this.nodeKind}}" data-scene-id="{{this.sceneId}}" data-parent-node-id="{{this.parentNodeId}}" data-view-parent-node-id="{{this.viewParentNodeId}}" data-parent-scene-id="{{this.parentSceneId}}" data-site-id="{{this.siteId}}" data-page-id="{{this.pageId}}" data-journal-entry-id="{{this.journalEntryId}}" data-depth="{{this.depth}}" data-view-depth="{{this.viewDepth}}" data-name="{{this.name}}" data-search-text="{{this.searchText}}" data-entity-id="{{this.entityId}}" data-entity-type="{{this.entityType}}" data-shop-id="{{this.shopId}}" data-uuid="{{this.uuid}}" data-image-src="{{this.imageSrc}}" data-placement-image-src="{{this.placementImageSrc}}" data-thumb="{{this.thumb}}" data-icon-src="{{this.iconSrc}}" data-has-children="{{this.hasChildren}}" data-connection-target-id="{{this.connections.nodeId}}" data-player-visibility-label="{{this.playerVisibilityLabel}}" data-player-visibility-icon="{{this.playerVisibilityIcon}}" {{#if this.canDragPlace}}draggable="true" data-nexus-place-drag="true"{{/if}}{{#if this.canDragEntity}}draggable="true" data-nexus-entity-drag="true"{{/if}}{{#if this.canDragShop}}draggable="true" data-nexus-shop-drag="true"{{/if}}>
                {{#if ../showSceneIcons}}
                {{#if this.iconSrc}}
                <span class="nexus-browser-pill-emblem">
                    <img src="{{this.iconSrc}}" alt="{{this.name}}">
                </span>
                {{/if}}
                {{/if}}
                <div class="nexus-browser-pill {{#if this.isCurrent}}current{{/if}} {{#if this.isCurrentAncestor}}current-ancestor{{/if}} {{#if this.isRoot}}root{{/if}} {{#if this.hasChildren}}has-children{{/if}}">
                    {{#if this.isPending}}
                    {{else}}
                    <span class="nexus-browser-pill-backdrop {{#unless this.thumb}}no-thumb{{/unless}}">
                        {{#if this.thumb}}
                        <img src="{{this.thumb}}" alt="{{this.name}}">
                        {{/if}}
                    </span>
                    <span class="nexus-browser-pill-overlay"></span>
                    {{/if}}
                    <span class="nexus-browser-pill-copy">
                        <span class="nexus-browser-pill-name">
                            {{#if this.isPlayerHidden}}<i class="fa-solid fa-eye-slash" aria-hidden="true"></i>{{/if}}
                            {{this.name}}
                        </span>
                        <span class="nexus-browser-pill-type">{{this.nodeTypeLabel}}</span>
                    </span>
                    <span class="nexus-browser-pill-actions">
                        {{#if this.hasOptions}}
                        <span class="nexus-browser-pill-options">
                            {{#if this.isShop}}
                            <button type="button" class="nexus-browser-pill-action secondary" data-action="toggleShopOptions" data-shop-id="{{this.shopId}}" title="Shop options" aria-label="Shop options"><i class="fas fa-ellipsis"></i></button>
                            {{else if this.isLocation}}
                            <button type="button" class="nexus-browser-pill-action secondary" data-action="toggleLocationOptions" data-entity-id="{{this.entityId}}" data-player-visibility-label="{{this.playerVisibilityLabel}}" data-player-visibility-icon="{{this.playerVisibilityIcon}}" title="Location options" aria-label="Location options"><i class="fas fa-ellipsis"></i></button>
                            {{else}}
                            <button type="button" class="nexus-browser-pill-action secondary" data-action="toggleSceneOptions" data-node-kind="{{this.nodeKind}}" data-scene-id="{{this.sceneId}}" data-parent-scene-id="{{this.parentSceneId}}" data-site-id="{{this.siteId}}" data-page-id="{{this.pageId}}" data-journal-entry-id="{{this.journalEntryId}}" data-player-visibility-label="{{this.playerVisibilityLabel}}" data-player-visibility-icon="{{this.playerVisibilityIcon}}" data-can-rename="{{#if this.canRename}}true{{else}}false{{/if}}" data-can-configure="{{#if this.canConfigure}}true{{else}}false{{/if}}" data-can-delete="{{#if this.canDelete}}true{{else}}false{{/if}}" title="Scene options" aria-label="Scene options" aria-expanded="false"><i class="fas fa-ellipsis"></i></button>
                            {{/if}}
                        </span>
                        {{/if}}
                        {{#if this.canOpen}}
                        <button type="button" class="nexus-browser-pill-action secondary" data-action="openLineageScene" data-node-kind="{{this.nodeKind}}" data-entity-id="{{this.entityId}}" data-scene-id="{{this.sceneId}}" data-site-id="{{this.siteId}}" data-page-id="{{this.pageId}}" data-journal-entry-id="{{this.journalEntryId}}" data-parent-scene-id="{{this.parentSceneId}}" title="{{this.openLabel}}">
                            <i class="fas fa-map"></i>
                        </button>
                        {{/if}}
                        {{#if this.connections.nodeId}}
                        <button type="button" class="nexus-browser-pill-action secondary nexus-browser-connection-toggle {{#if this.connections.expanded}}active{{/if}} {{#if this.connections.hasConnections}}has-count{{/if}}" data-action="toggleLineageConnections" data-connection-target-id="{{this.connections.nodeId}}" title="Show connections" aria-label="Show connections">
                            <i class="fas fa-share-nodes"></i>
                            <span>{{this.connections.total}}</span>
                        </button>
                        {{/if}}
                        {{#if this.hasChildren}}
                        <button type="button" class="nexus-browser-pill-action {{#if this.isCollapsed}}collapsed{{/if}}" data-action="toggleLineageBranch" data-node-id="{{this.id}}" title="Toggle nested places">
                            <i class="fas fa-chevron-down"></i>
                        </button>
                        {{/if}}
                    </span>
                </div>
                {{#if this.connections.expanded}}
                <div class="nexus-browser-connection-drawer" data-connection-target-id="{{this.connections.nodeId}}">
                    {{#each this.connections.groups}}
                    <section class="nexus-browser-connection-group {{#if hiddenForPlayers}}is-player-hidden{{/if}}" data-connection-category-id="{{id}}" style="--connection-category-color: {{color}};">
                        <h4>
                            <i class="{{icon}}"></i>
                            <span>{{label}}</span>
                            {{#if hiddenForPlayers}}<i class="fa-solid fa-eye-slash nexus-browser-connection-group-hidden-icon" aria-hidden="true"></i>{{/if}}
                            {{#if @root.isGM}}
                            <span class="nexus-browser-connection-group-order">
                                <button type="button" data-action="openLineageConnectionGroupActions" data-connection-target-id="{{../nodeId}}" data-connection-category-id="{{id}}" title="Group actions" aria-label="Group actions">
                                    <i class="fas fa-ellipsis"></i>
                                </button>
                                {{#if canMoveUp}}
                                <button type="button" data-action="moveLineageConnectionGroup" data-connection-target-id="{{../nodeId}}" data-connection-category-id="{{id}}" data-connection-group-move="-1" title="Move group up" aria-label="Move group up">
                                    <i class="fas fa-chevron-up"></i>
                                </button>
                                {{/if}}
                                {{#if canMoveDown}}
                                <button type="button" data-action="moveLineageConnectionGroup" data-connection-target-id="{{../nodeId}}" data-connection-category-id="{{id}}" data-connection-group-move="1" title="Move group down" aria-label="Move group down">
                                    <i class="fas fa-chevron-down"></i>
                                </button>
                                {{/if}}
                            </span>
                            {{/if}}
                            <strong>{{count}}</strong>
                        </h4>
                        {{#each cards}}
                        <div class="nexus-browser-connection-row-wrap {{#if isPlayerHidden}}is-player-hidden{{/if}}" style="--connection-category-color: {{color}};">
                        <button type="button" class="nexus-browser-connection-row {{#if missing}}missing{{/if}} {{#if isPlayerHidden}}is-player-hidden{{/if}}" data-action="openLineageConnection" data-connection-edge-id="{{edgeId}}" data-connection-node-id="{{nodeId}}" {{#if @root.isGM}}draggable="true"{{/if}}>
                            <span class="nexus-browser-connection-image">
                                {{#if img}}
                                <img src="{{img}}" alt="{{name}}">
                                {{else}}
                                <i class="{{icon}}"></i>
                                {{/if}}
                            </span>
                            <span class="nexus-browser-connection-copy">
                                <strong>
                                    {{#if isPlayerHidden}}<i class="fa-solid fa-eye-slash" aria-hidden="true"></i>{{/if}}
                                    {{name}}
                                </strong>
                                <em>{{subtitle}}</em>
                                {{#if note}}
                                <small>{{note}}</small>
                                {{/if}}
                            </span>
                        </button>
                        {{#if @root.isGM}}
                        <button type="button" class="nexus-browser-connection-row-action" data-action="openLineageConnectionActions" data-connection-edge-id="{{edgeId}}" data-connection-node-id="{{nodeId}}" title="Connection actions" aria-label="Connection actions">
                            <i class="fas fa-ellipsis"></i>
                        </button>
                        {{/if}}
                        </div>
                        {{/each}}
                    </section>
                    {{/each}}
                </div>
                {{/if}}
            </div>
            {{/if}}
            {{/each}}
        </div>
        <div class="nexus-browser-empty" {{#if hasRows}}hidden{{/if}}>{{#if isSearching}}No places match this search.{{else}}No scenes, sites, locations, or shops have been created yet.{{/if}}</div>
    </section>
    {{/if}}

    {{#if isPeopleTab}}
    <div class="nexus-browser-people-toolbar">
        <div class="nexus-browser-search-bar">
            <i class="fas fa-search"></i>
            <input type="search" name="nexusPeopleSearch" value="{{peopleSearchQuery}}" placeholder="Search people" autocomplete="off" spellcheck="false" dir="ltr">
            <button type="button" class="site-entry-clear nexus-browser-search-clear" data-action="clearPeopleSearch" title="Clear search" {{#unless isPeopleSearching}}hidden{{/unless}}>
                <i class="fas fa-times"></i>
            </button>
        </div>
        <div class="nexus-browser-people-filters" aria-label="People filters">
            <button type="button" class="nexus-browser-filter-toggle {{#if filterEntitiesToCurrentScene}}is-active{{/if}}" data-action="togglePeopleSceneFilter" title="Only people on this scene{{#if filterEntitiesToCurrentScene}} ({{people.presentCount}} of {{people.totalCount}}){{/if}}" aria-label="Only people on this scene" aria-pressed="{{filterEntitiesToCurrentScene}}" {{#unless canFilterEntitiesToCurrentScene}}disabled{{/unless}}>
                <i class="fas fa-location-dot"></i>
                <span class="nexus-browser-filter-check"><i class="fas fa-check"></i></span>
            </button>
            <button type="button" class="nexus-browser-filter-toggle {{#if groupPeopleByFaction}}is-active{{/if}}" data-action="togglePeopleFactionGrouping" title="Group people by organization" aria-label="Group people by organization" aria-pressed="{{groupPeopleByFaction}}">
                <i class="fas fa-shield-halved"></i>
                <span class="nexus-browser-filter-check"><i class="fas fa-check"></i></span>
            </button>
            {{#if people.hasCollapsibleGroups}}
            <button type="button" class="nexus-browser-filter-toggle nexus-browser-group-fold-toggle" data-action="toggleAllPeopleFactionGroups" data-idle-label="{{#if people.allGroupsCollapsed}}Expand all organizations{{else}}Collapse all organizations{{/if}}" title="{{#if people.allGroupsCollapsed}}Expand all organizations{{else}}Collapse all organizations{{/if}}" aria-label="{{#if people.allGroupsCollapsed}}Expand all organizations{{else}}Collapse all organizations{{/if}}" {{#if isPeopleSearching}}disabled{{/if}}>
                <i class="fas {{#if people.allGroupsCollapsed}}fa-angles-down{{else}}fa-angles-up{{/if}}"></i>
            </button>
            {{/if}}
        </div>
    </div>
    <section class="nexus-browser-section nexus-browser-tree-section">
        <div class="nexus-browser-tree nexus-browser-people-tree nexus-browser-npc-tree" {{#unless people.hasRows}}hidden{{/unless}}>
            {{#if people.grouped}}
            {{#each people.groups}}
            <section class="nexus-browser-people-group {{#if isUnaffiliated}}is-unaffiliated{{/if}}" data-people-faction-group="{{id}}" data-search-text="{{searchText}}" data-expanded="{{expanded}}">
                <div class="nexus-browser-people-group-header" style="--faction-accent: {{accent}};" {{#unless isUnaffiliated}}data-action="openFactionDossier" data-entity-id="{{entityId}}" data-entity-type="{{entityType}}" data-name="{{name}}" data-image-src="{{imageSrc}}" data-placement-image-src="{{placementImageSrc}}" data-player-visibility-label="{{playerVisibilityLabel}}" data-player-visibility-icon="{{playerVisibilityIcon}}" title="Open {{name}}" role="button" tabindex="0" {{#if @root.isGM}}draggable="true" data-nexus-entity-drag="true"{{/if}}{{/unless}}>
                    <span class="nexus-browser-people-group-main">
                        <span class="nexus-browser-people-group-emblem">
                            {{#if imageSrc}}
                            <img src="{{imageSrc}}" alt="">
                            {{else}}
                            <i class="fas {{#if isUnaffiliated}}fa-user-slash{{else}}fa-shield-halved{{/if}}"></i>
                            {{/if}}
                        </span>
                        <span class="nexus-browser-people-group-copy">
                            <strong>{{#if isPlayerHidden}}<i class="fa-solid fa-eye-slash" aria-hidden="true"></i>{{/if}}{{name}}</strong>
                            <small>{{subtitle}}</small>
                        </span>
                    </span>
                    <span class="nexus-browser-people-group-count">{{count}}</span>
                    {{#if hasOptions}}
                    <button type="button" class="nexus-browser-people-group-action" data-action="toggleFactionOptions" data-entity-id="{{entityId}}" data-player-visibility-label="{{playerVisibilityLabel}}" data-player-visibility-icon="{{playerVisibilityIcon}}" title="Organization options" aria-label="Organization options">
                        <i class="fas fa-ellipsis"></i>
                    </button>
                    {{/if}}
                    {{#if hasMembers}}
                    <button type="button" class="nexus-browser-people-group-action nexus-browser-people-group-fold" data-action="togglePeopleFactionGroup" data-faction-id="{{id}}" title="{{#if expanded}}Collapse{{else}}Expand{{/if}} {{name}}" aria-label="{{#if expanded}}Collapse{{else}}Expand{{/if}} {{name}}" aria-expanded="{{expanded}}">
                        <i class="fas {{#if expanded}}fa-chevron-up{{else}}fa-chevron-down{{/if}} nexus-browser-people-group-chevron"></i>
                    </button>
                    {{/if}}
                </div>
                <div class="nexus-browser-people-group-rows" {{#unless expanded}}hidden{{/unless}}>
                    {{#each rows}}
                    {{> "modules/augur-nexus/templates/nexus/npc-directory-row.hbs"}}
                    {{/each}}
                </div>
            </section>
            {{/each}}
            {{else}}
            {{#each people.rows}}
            {{> "modules/augur-nexus/templates/nexus/npc-directory-row.hbs"}}
            {{/each}}
            {{/if}}
        </div>
        <div class="nexus-browser-empty" {{#if people.hasRows}}hidden{{/if}}>{{people.emptyLabel}}</div>
    </section>
    {{/if}}

    {{#if isFactionsTab}}
    <div class="nexus-browser-people-toolbar">
        <div class="nexus-browser-search-bar">
            <i class="fas fa-search"></i>
            <input type="search" name="nexusFactionSearch" value="{{factionSearchQuery}}" placeholder="Search organizations" autocomplete="off" spellcheck="false" dir="ltr">
            <button type="button" class="site-entry-clear nexus-browser-search-clear" data-action="clearFactionSearch" title="Clear search" {{#unless isFactionSearching}}hidden{{/unless}}>
                <i class="fas fa-times"></i>
            </button>
        </div>
        <div class="nexus-browser-people-filters" aria-label="Organization filters">
            <button type="button" class="nexus-browser-filter-toggle {{#if filterEntitiesToCurrentScene}}is-active{{/if}}" data-action="toggleFactionSceneFilter" title="Only organizations on this scene{{#if filterEntitiesToCurrentScene}} ({{factions.presentCount}} of {{factions.totalCount}}){{/if}}" aria-label="Only organizations on this scene" aria-pressed="{{filterEntitiesToCurrentScene}}" {{#unless canFilterEntitiesToCurrentScene}}disabled{{/unless}}>
                <i class="fas fa-location-dot"></i>
                <span class="nexus-browser-filter-check"><i class="fas fa-check"></i></span>
            </button>
        </div>
    </div>
    <section class="nexus-browser-section nexus-browser-tree-section">
        <div class="nexus-browser-tree nexus-browser-people-tree nexus-browser-faction-tree" {{#unless factions.hasRows}}hidden{{/unless}}>
            {{#each factions.rows}}
            <div class="nexus-browser-pill-shell npc-pill-shell faction-pill-shell has-site-icon {{#if isPlayerHidden}}is-player-hidden{{/if}}" title="{{name}}" data-node-id="{{id}}" data-entity-id="{{entityId}}" data-entity-type="{{entityType}}" data-name="{{name}}" data-search-text="{{searchText}}" data-image-src="{{imageSrc}}" data-placement-image-src="{{placementImageSrc}}" data-connection-target-id="{{connections.nodeId}}" data-player-visibility-label="{{playerVisibilityLabel}}" data-player-visibility-icon="{{playerVisibilityIcon}}" {{#if @root.isGM}}draggable="true" data-nexus-entity-drag="true"{{/if}}>
                <span class="nexus-browser-pill-emblem npc-pill-portrait faction-pill-emblem" style="--npc-accent: {{accent}};">
                    {{#if imageSrc}}
                    <img src="{{imageSrc}}" alt="{{name}}">
                    {{else}}
                    <i class="fas fa-shield-halved"></i>
                    {{/if}}
                </span>
                <div class="nexus-browser-pill npc-pill faction-pill" style="--npc-accent: {{accent}};">
                    <span class="nexus-browser-pill-overlay"></span>
                    <span class="nexus-browser-pill-copy">
                        <span class="nexus-browser-pill-name">
                            {{#if isPlayerHidden}}<i class="fa-solid fa-eye-slash" aria-hidden="true"></i>{{/if}}
                            {{name}}
                        </span>
                        <span class="nexus-browser-pill-type">{{subtitle}}</span>
                    </span>
                    <span class="nexus-browser-pill-actions">
                        {{#if hasOptions}}
                        <span class="nexus-browser-pill-options">
                            <button type="button" class="nexus-browser-pill-action secondary" data-action="toggleFactionOptions" data-entity-id="{{entityId}}" data-player-visibility-label="{{playerVisibilityLabel}}" data-player-visibility-icon="{{playerVisibilityIcon}}" title="Organization options" aria-label="Organization options" aria-expanded="false">
                                <i class="fas fa-ellipsis"></i>
                            </button>
                        </span>
                        {{/if}}
                        {{#if connections.nodeId}}
                        <button type="button" class="nexus-browser-pill-action secondary nexus-browser-connection-toggle {{#if connections.expanded}}active{{/if}} {{#if connections.hasConnections}}has-count{{/if}}" data-action="toggleLineageConnections" data-connection-target-id="{{connections.nodeId}}" title="Show connections" aria-label="Show connections">
                            <i class="fas fa-share-nodes"></i>
                            <span>{{connections.total}}</span>
                        </button>
                        {{/if}}
                    </span>
                </div>
                {{#if connections.expanded}}
                <div class="nexus-browser-connection-drawer" data-connection-target-id="{{connections.nodeId}}">
                    {{#each connections.groups}}
                    <section class="nexus-browser-connection-group {{#if hiddenForPlayers}}is-player-hidden{{/if}}" data-connection-category-id="{{id}}" style="--connection-category-color: {{color}};">
                        <h4>
                            <i class="{{icon}}"></i>
                            <span>{{label}}</span>
                            {{#if hiddenForPlayers}}<i class="fa-solid fa-eye-slash nexus-browser-connection-group-hidden-icon" aria-hidden="true"></i>{{/if}}
                            {{#if @root.isGM}}
                            <span class="nexus-browser-connection-group-order">
                                <button type="button" data-action="openLineageConnectionGroupActions" data-connection-target-id="{{../nodeId}}" data-connection-category-id="{{id}}" title="Group actions" aria-label="Group actions">
                                    <i class="fas fa-ellipsis"></i>
                                </button>
                                {{#if canMoveUp}}
                                <button type="button" data-action="moveLineageConnectionGroup" data-connection-target-id="{{../nodeId}}" data-connection-category-id="{{id}}" data-connection-group-move="-1" title="Move group up" aria-label="Move group up">
                                    <i class="fas fa-chevron-up"></i>
                                </button>
                                {{/if}}
                                {{#if canMoveDown}}
                                <button type="button" data-action="moveLineageConnectionGroup" data-connection-target-id="{{../nodeId}}" data-connection-category-id="{{id}}" data-connection-group-move="1" title="Move group down" aria-label="Move group down">
                                    <i class="fas fa-chevron-down"></i>
                                </button>
                                {{/if}}
                            </span>
                            {{/if}}
                            <strong>{{count}}</strong>
                        </h4>
                        {{#each cards}}
                        <div class="nexus-browser-connection-row-wrap {{#if isPlayerHidden}}is-player-hidden{{/if}}" style="--connection-category-color: {{color}};">
                        <button type="button" class="nexus-browser-connection-row {{#if missing}}missing{{/if}} {{#if isPlayerHidden}}is-player-hidden{{/if}}" data-action="openLineageConnection" data-connection-edge-id="{{edgeId}}" data-connection-node-id="{{nodeId}}" {{#if @root.isGM}}draggable="true"{{/if}}>
                            <span class="nexus-browser-connection-image">
                                {{#if img}}
                                <img src="{{img}}" alt="{{name}}">
                                {{else}}
                                <i class="{{icon}}"></i>
                                {{/if}}
                            </span>
                            <span class="nexus-browser-connection-copy">
                                <strong>
                                    {{#if isPlayerHidden}}<i class="fa-solid fa-eye-slash" aria-hidden="true"></i>{{/if}}
                                    {{name}}
                                </strong>
                                <em>{{subtitle}}</em>
                                {{#if note}}
                                <small>{{note}}</small>
                                {{/if}}
                            </span>
                        </button>
                        {{#if @root.isGM}}
                        <button type="button" class="nexus-browser-connection-row-action" data-action="openLineageConnectionActions" data-connection-edge-id="{{edgeId}}" data-connection-node-id="{{nodeId}}" title="Connection actions" aria-label="Connection actions">
                            <i class="fas fa-ellipsis"></i>
                        </button>
                        {{/if}}
                        </div>
                        {{/each}}
                    </section>
                    {{/each}}
                </div>
                {{/if}}
            </div>
            {{/each}}
        </div>
        <div class="nexus-browser-empty" {{#if factions.hasRows}}hidden{{/if}}>{{factions.emptyLabel}}</div>
    </section>
    {{/if}}

    {{#if isShipsTab}}
    <div class="nexus-browser-people-toolbar">
        <div class="nexus-browser-search-bar">
            <i class="fas fa-search"></i>
            <input type="search" name="nexusShipSearch" value="{{shipSearchQuery}}" placeholder="Search ships" autocomplete="off" spellcheck="false" dir="ltr">
            <button type="button" class="site-entry-clear nexus-browser-search-clear" data-action="clearShipSearch" title="Clear search" {{#unless isShipSearching}}hidden{{/unless}}>
                <i class="fas fa-times"></i>
            </button>
        </div>
        <div class="nexus-browser-people-filters" aria-label="Ship filters">
            <button type="button" class="nexus-browser-filter-toggle {{#if filterEntitiesToCurrentScene}}is-active{{/if}}" data-action="toggleShipSceneFilter" title="Only ships on this scene{{#if filterEntitiesToCurrentScene}} ({{ships.presentCount}} of {{ships.totalCount}}){{/if}}" aria-label="Only ships on this scene" aria-pressed="{{filterEntitiesToCurrentScene}}" {{#unless canFilterEntitiesToCurrentScene}}disabled{{/unless}}>
                <i class="fas fa-location-dot"></i>
                <span class="nexus-browser-filter-check"><i class="fas fa-check"></i></span>
            </button>
            <button type="button" class="nexus-browser-filter-toggle {{#if groupShipsByFaction}}is-active{{/if}}" data-action="toggleShipFactionGrouping" title="Group ships by organization" aria-label="Group ships by organization" aria-pressed="{{groupShipsByFaction}}">
                <i class="fas fa-shield-halved"></i>
                <span class="nexus-browser-filter-check"><i class="fas fa-check"></i></span>
            </button>
            {{#if ships.hasCollapsibleGroups}}
            <button type="button" class="nexus-browser-filter-toggle nexus-browser-group-fold-toggle" data-action="toggleAllShipFactionGroups" data-idle-label="{{#if ships.allGroupsCollapsed}}Expand all organizations{{else}}Collapse all organizations{{/if}}" title="{{#if ships.allGroupsCollapsed}}Expand all organizations{{else}}Collapse all organizations{{/if}}" aria-label="{{#if ships.allGroupsCollapsed}}Expand all organizations{{else}}Collapse all organizations{{/if}}" {{#if isShipSearching}}disabled{{/if}}>
                <i class="fas {{#if ships.allGroupsCollapsed}}fa-angles-down{{else}}fa-angles-up{{/if}}"></i>
            </button>
            {{/if}}
        </div>
    </div>
    <section class="nexus-browser-section nexus-browser-tree-section">
        <div class="nexus-browser-tree nexus-browser-people-tree nexus-browser-ship-tree" {{#unless ships.hasRows}}hidden{{/unless}}>
            {{#if ships.grouped}}
            {{#each ships.groups}}
            <section class="nexus-browser-people-group {{#if isUnaffiliated}}is-unaffiliated{{/if}}" data-ship-faction-group="{{id}}" data-search-text="{{searchText}}" data-expanded="{{expanded}}">
                <div class="nexus-browser-people-group-header" style="--faction-accent: {{accent}};" {{#unless isUnaffiliated}}data-action="openFactionDossier" data-entity-id="{{entityId}}" data-entity-type="{{entityType}}" data-name="{{name}}" data-image-src="{{imageSrc}}" data-placement-image-src="{{placementImageSrc}}" data-player-visibility-label="{{playerVisibilityLabel}}" data-player-visibility-icon="{{playerVisibilityIcon}}" title="Open {{name}}" role="button" tabindex="0" {{#if @root.isGM}}draggable="true" data-nexus-entity-drag="true"{{/if}}{{/unless}}>
                    <span class="nexus-browser-people-group-main">
                        <span class="nexus-browser-people-group-emblem">
                            {{#if imageSrc}}
                            <img src="{{imageSrc}}" alt="">
                            {{else}}
                            <i class="fas {{#if isUnaffiliated}}fa-rocket{{else}}fa-shield-halved{{/if}}"></i>
                            {{/if}}
                        </span>
                        <span class="nexus-browser-people-group-copy">
                            <strong>{{#if isPlayerHidden}}<i class="fa-solid fa-eye-slash" aria-hidden="true"></i>{{/if}}{{name}}</strong>
                            <small>{{subtitle}}</small>
                        </span>
                    </span>
                    <span class="nexus-browser-people-group-count">{{count}}</span>
                    {{#if hasOptions}}
                    <button type="button" class="nexus-browser-people-group-action" data-action="toggleFactionOptions" data-entity-id="{{entityId}}" data-player-visibility-label="{{playerVisibilityLabel}}" data-player-visibility-icon="{{playerVisibilityIcon}}" title="Organization options" aria-label="Organization options">
                        <i class="fas fa-ellipsis"></i>
                    </button>
                    {{/if}}
                    {{#if hasMembers}}
                    <button type="button" class="nexus-browser-people-group-action nexus-browser-people-group-fold" data-action="toggleShipFactionGroup" data-faction-id="{{id}}" title="{{#if expanded}}Collapse{{else}}Expand{{/if}} {{name}}" aria-label="{{#if expanded}}Collapse{{else}}Expand{{/if}} {{name}}" aria-expanded="{{expanded}}">
                        <i class="fas {{#if expanded}}fa-chevron-up{{else}}fa-chevron-down{{/if}} nexus-browser-people-group-chevron"></i>
                    </button>
                    {{/if}}
                </div>
                <div class="nexus-browser-people-group-rows" {{#unless expanded}}hidden{{/unless}}>
                    {{#each rows}}
                    {{> "modules/augur-nexus/templates/nexus/ship-directory-row.hbs"}}
                    {{/each}}
                </div>
            </section>
            {{/each}}
            {{else}}
            {{#each ships.rows}}
            {{> "modules/augur-nexus/templates/nexus/ship-directory-row.hbs"}}
            {{/each}}
            {{/if}}
        </div>
        <div class="nexus-browser-empty" {{#if ships.hasRows}}hidden{{/if}}>{{ships.emptyLabel}}</div>
    </section>
    {{/if}}

    <div class="nexus-browser-footer">
        {{#if isSitesTab}}
        <label class="nexus-browser-icon-toggle">
            <input type="checkbox" name="nexusBrowserShowIcons" {{#if showSceneIcons}}checked{{/if}}>
            <span class="nexus-browser-icon-toggle-box" aria-hidden="true">
                <i class="fas fa-check"></i>
            </span>
            <span class="nexus-browser-icon-toggle-label">Show Icons</span>
        </label>
        {{else}}
        <span></span>
        {{/if}}
        {{#if isGM}}
        <div class="nexus-browser-root-create">
            {{#if isSitesTab}}
            <button type="button" class="site-entry-clear nexus-browser-new-root" data-action="toggleRootSceneMenu" title="Create a new root scene" aria-expanded="false">
                <i class="fas fa-plus"></i>
                <span>New Root Scene</span>
            </button>
            {{else if isPeopleTab}}
            <button type="button" class="site-entry-clear nexus-browser-new-root" data-action="createNpc" title="Create a new person">
                <i class="fas fa-user-plus"></i>
                <span>New Person</span>
            </button>
            <button type="button" class="site-entry-clear nexus-browser-new-root" data-action="createFaction" title="Create a new organization">
                <i class="fas fa-shield-halved"></i>
                <span>New Organization</span>
            </button>
            {{else if isFactionsTab}}
            <button type="button" class="site-entry-clear nexus-browser-new-root" data-action="createFaction" title="Create a new organization">
                <i class="fas fa-plus"></i>
                <span>New Organization</span>
            </button>
            {{else if isShipsTab}}
            <button type="button" class="site-entry-clear nexus-browser-new-root" data-action="createShip" title="Create a new ship">
                <i class="fas fa-plus"></i>
                <span>New Ship</span>
            </button>
            {{/if}}
        </div>
        {{/if}}
    </div>
</div>

