<header class="npc-dossier-header faction-dossier-header" style="--npc-accent: {{profile.accent}};">
    <div class="npc-dossier-portrait faction-dossier-emblem" {{#if @root.isGM}}draggable="true" data-faction-dossier-drag="true" title="Drag {{profile.name}}"{{/if}}>
        {{#if profile.imageSrc}}<img src="{{profile.imageSrc}}" alt="{{profile.name}}" draggable="false">{{else}}<i class="fas fa-shield-halved"></i>{{/if}}
    </div>
    <div class="npc-dossier-title">
        <h2>{{profile.name}}</h2>
        <p>{{profile.subtitle}}</p>
        {{#if profile.showTabs}}
        <nav class="npc-dossier-tabs" aria-label="Organization dossier tabs">
            <button type="button" class="{{#if profile.tabs.isProfileTab}}active{{/if}}" data-action="setFactionDossierTab" data-tab="profile">Profile</button>
            <button type="button" class="{{#if profile.tabs.isJournalTab}}active{{/if}}" data-action="setFactionDossierTab" data-tab="journal">Journal</button>
            <button type="button" class="npc-dossier-tab-icon {{#if profile.tabs.isConnectionsTab}}active{{/if}}" data-action="setFactionDossierTab" data-tab="connections" title="Connections" aria-label="Connections"><i class="fas fa-share-nodes"></i></button>
            {{#if profile.hasChronicle}}<button type="button" class="npc-dossier-tab-icon {{#if profile.tabs.isChronicleTab}}active{{/if}}" data-action="setFactionDossierTab" data-tab="chronicle" title="Chronicle" aria-label="Chronicle"><i class="fas fa-scroll"></i></button>{{/if}}
        </nav>
        {{/if}}
    </div>
    {{#if profile.showHeaderActions}}
    <div class="npc-dossier-header-actions faction-dossier-header-actions">
        {{#if profile.showActions}}<button type="button" class="npc-dossier-action" data-action="openFactionActions" title="Organization actions" aria-label="Organization actions"><i class="fas fa-ellipsis"></i></button>{{/if}}
        {{#if profile.showCompactToggle}}
        <button type="button" class="npc-dossier-compact-toggle" data-action="toggleFactionDossierCompact" title="{{#if profile.compactMode}}Expand organization dossier{{else}}Compact organization dossier{{/if}}" aria-label="{{#if profile.compactMode}}Expand organization dossier{{else}}Compact organization dossier{{/if}}">
            <i class="fas {{#if profile.compactMode}}fa-expand{{else}}fa-compress{{/if}}"></i>
        </button>
        {{/if}}
    </div>
    {{/if}}
</header>

{{#if profile.showBody}}
<section class="npc-dossier-section faction-profile-body">
    {{#if profile.compactMode}}
    <div class="faction-profile-command-row">
        {{#if domain.hasLeader}}
        <button type="button" class="faction-profile-command-card" data-faction-domain-node="{{domain.leader.nodeId}}" data-faction-domain-drop="leader" {{#if @root.isGM}}draggable="true"{{/if}}>
            <span class="faction-profile-command-image nexus-entity-image is-person">{{#if domain.leader.imageSrc}}<img src="{{domain.leader.imageSrc}}" alt="">{{else}}<i class="fas fa-user"></i>{{/if}}</span>
            <span class="faction-profile-command-copy"><em><i class="fas fa-crown"></i> Ruled by</em><strong>{{domain.leader.name}}</strong><small>{{domain.leader.subtitle}}</small></span>
        </button>
        {{else}}
        <div class="faction-profile-command-card is-empty" data-faction-domain-drop="leader"><i class="fas fa-crown"></i><span><em>Ruled by</em><strong>No ruler appointed</strong></span></div>
        {{/if}}
        {{#if domain.hasSeat}}
        <button type="button" class="faction-profile-command-card is-seat" data-faction-domain-node="{{domain.seat.nodeId}}" data-faction-domain-drop="seat" {{#if @root.isGM}}draggable="true"{{/if}}>
            <span class="faction-profile-command-image is-square nexus-entity-image is-place">{{#if domain.seat.imageSrc}}<img src="{{domain.seat.imageSrc}}" alt="">{{else}}<i class="fas fa-landmark-dome"></i>{{/if}}</span>
            <span class="faction-profile-command-copy"><em><i class="fas fa-landmark-dome"></i> Seat of power</em><strong>{{domain.seat.name}}</strong><small>{{domain.seat.subtitle}}</small></span>
        </button>
        {{else}}
        <div class="faction-profile-command-card is-empty is-seat" data-faction-domain-drop="seat"><i class="fas fa-landmark-dome"></i><span><em>Seat of power</em><strong>No seat designated</strong></span></div>
        {{/if}}
    </div>
    {{/if}}

    {{#if profile.hasIdeology}}
    {{#if profile.compactMode}}<h3 class="npc-profile-section-heading"><span><i class="fas fa-compass"></i> Beliefs</span></h3>{{/if}}
    <div class="faction-ideology-panel"><div class="faction-ideology-grid">
        {{#each profile.ideology}}
        <article class="faction-ideology-card"><div class="faction-ideology-title" title="{{topicQuestion}}"><span class="faction-ideology-topic"><i class="{{topicIcon}}"></i><span>{{topicLabel}}</span></span><span class="faction-ideology-separator">-</span><strong>{{tenetLabel}}</strong></div><p>{{tenetDescription}}</p></article>
        {{/each}}
    </div></div>
    {{/if}}

    {{#if profile.identityChips.length}}
    <div class="npc-dossier-chip-row npc-dossier-chip-row-primary">{{#each profile.identityChips}}<span><em>{{label}}</em><strong>{{value}}</strong></span>{{/each}}</div>
    {{/if}}

    {{#if profile.profileRows.length}}
    <h3 class="npc-profile-section-heading npc-profile-information"><span><i class="fas fa-feather-pointed"></i> Information</span></h3>
    <div class="npc-dossier-custom-row">{{#each profile.profileRows}}<span><em>{{label}}</em><strong>{{value}}</strong></span>{{/each}}</div>
    {{/if}}

    {{#if profile.showDiplomacy}}
    <section class="faction-diplomacy-panel">
        <h3 class="npc-profile-section-heading faction-diplomacy-heading">
            <span><i class="fas fa-handshake"></i> Diplomacy</span>
            {{#if diplomacy.hasRelations}}<small>{{diplomacy.count}}</small>{{/if}}
        </h3>
        {{#if diplomacy.hasRelations}}
        <div class="faction-diplomacy-list">
            {{#each diplomacy.relations}}
            <article class="faction-diplomacy-card">
                <button type="button" class="faction-diplomacy-identity" data-faction-domain-node="{{nodeId}}" title="Open {{name}}">
                    <span class="faction-diplomacy-emblem">{{#if imageSrc}}<img src="{{imageSrc}}" alt="">{{else}}<i class="fas fa-shield-halved"></i>{{/if}}</span>
                    <span class="faction-diplomacy-copy">
                        <strong>{{name}}</strong>
                        <small>{{subtitle}}</small>
                    </span>
                </button>
                {{#if opinion}}
                <button type="button" class="connection-card-opinion faction-diplomacy-opinion" data-faction-diplomacy-opinion data-connection-edge-id="{{edgeId}}" style="--opinion-tier-color: {{opinion.tierColor}};" title="{{opinion.scoreLabel}} {{opinion.tierLabel}} &mdash; Show opinion breakdown" aria-label="{{opinion.scoreLabel}} {{opinion.tierLabel}}; show opinion breakdown"><i class="fas fa-scale-balanced"></i><b>{{opinion.scoreLabel}}</b><span>{{opinion.tierLabel}}</span></button>
                {{else}}
                <span class="faction-diplomacy-unrated" title="Opinions are not tracked for this relationship">Unrated</span>
                {{/if}}
                <div class="faction-diplomacy-details">
                    <span class="faction-diplomacy-role"><i class="fas fa-link"></i>{{relationshipLabel}}</span>
                    {{#if reciprocalLabel}}<span title="How {{name}} describes this relationship"><i class="fas fa-reply"></i>Their stance: {{reciprocalLabel}}</span>{{/if}}
                    {{#if hasReciprocalOpinion}}<span style="--opinion-tier-color: {{reciprocalOpinion.tierColor}};" title="{{name}}'s opinion of this organization"><i class="fas fa-arrow-left"></i>Their view: <b>{{reciprocalOpinion.scoreLabel}}</b> {{reciprocalOpinion.tierLabel}}</span>{{/if}}
                    {{#if note}}<p><i class="fas fa-note-sticky"></i>{{note}}</p>{{/if}}
                </div>
            </article>
            {{/each}}
        </div>
        {{else}}
        <div class="faction-diplomacy-empty"><i class="fas fa-handshake-slash"></i><span>No diplomatic relationships recorded.</span></div>
        {{/if}}
    </section>
    {{/if}}

    {{#if profile.hasCurrentThread}}
    <section class="npc-profile-current-thread">
        <h3 class="npc-profile-section-heading is-thread"><span><i class="fas fa-wand-sparkles"></i> Current Thread</span>{{#if profile.canRerollCurrentThread}}<button type="button" class="faction-current-thread-reroll" data-action="rerollFactionCurrentThread" title="Reroll Current Thread" aria-label="Reroll Current Thread"><i class="fas fa-dice"></i></button>{{/if}}</h3>
        <div class="faction-current-thread-grid">{{#each profile.currentThread}}<article><span><i class="{{icon}}"></i> {{label}}</span><strong>{{value}}</strong></article>{{/each}}</div>
    </section>
    {{/if}}

    {{#unless profile.identityChips.length}}{{#unless profile.hasCurrentThread}}{{#unless profile.profileRows.length}}{{#unless profile.hasIdeology}}<div class="npc-dossier-empty compact">{{profile.emptyLabel}}</div>{{/unless}}{{/unless}}{{/unless}}{{/unless}}
</section>
{{/if}}
