<Window x:Class="NexusInstaller.Views.NexusSetupWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:conv="clr-namespace:NexusInstaller.Converters"
        Title="Ninja Nexus Installer"
        Width="960" Height="720" MinWidth="880" MinHeight="640"
        WindowStyle="None"
        WindowState="Maximized"
        WindowStartupLocation="CenterScreen"
        ResizeMode="CanResizeWithGrip"
        Background="{StaticResource NexusBackgroundBrush}"
        KeyDown="Window_KeyDown">
    <Window.Resources>
        <conv:InstallStepStatusBrushConverter x:Key="StepStatusBrush"/>
        <conv:InstallStepStatusBorderBrushConverter x:Key="StepBorderBrush"/>
        <conv:InstallStepStatusPillBrushConverter x:Key="StatusPillBrush"/>
        <conv:InstallProgressEventKindBrushConverter x:Key="EventKindBrush"/>
        <conv:InstallStepActiveOpacityConverter x:Key="StepActiveOpacity"/>
        <conv:InstallStepRowBackgroundConverter x:Key="StepRowBackground"/>
        <conv:RequirementStatusBrushConverter x:Key="ReqBrush"/>
        <conv:InstallPhaseBrushConverter x:Key="PhaseBrush"/>
        <conv:InstallPhaseLabelConverter x:Key="PhaseLabel"/>
        <conv:BoolToVisibilityConverter x:Key="BoolVis"/>
        <conv:InverseBoolToVisibilityConverter x:Key="InvBoolVis"/>
        <conv:StringToVisibilityConverter x:Key="StringVis"/>
    </Window.Resources>

    <Grid>
        <Rectangle Fill="{StaticResource InstallerHorizonGlowBrush}" VerticalAlignment="Bottom" Height="360"/>

        <Grid Margin="48,28,48,24">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <!-- Header -->
            <Grid Grid.Row="0">
                <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                    <Image Source="/Assets/Lille_nexus_logo.png" Height="36" Stretch="Uniform" Margin="0,0,14,0"/>
                    <StackPanel VerticalAlignment="Center">
                        <TextBlock Text="Ninja Nexus Installer"
                                   Foreground="{StaticResource NexusTextPrimaryBrush}"
                                   FontSize="18" FontWeight="SemiBold"/>
                        <TextBlock Text="{Binding AdminStatusText}"
                                   Foreground="{StaticResource NexusTextSecondaryBrush}" FontSize="11"/>
                    </StackPanel>
                </StackPanel>
                <Button Content="✕" Style="{StaticResource InstallerCloseButtonStyle}"
                        HorizontalAlignment="Right" Click="CloseButton_Click"/>
            </Grid>

            <!-- Admin elevation prompt -->
            <Border Grid.Row="1" Margin="0,12,0,0" CornerRadius="12" Padding="16"
                    BorderBrush="#66EF4444" BorderThickness="1" Background="#18EF4444"
                    Visibility="{Binding ShowElevationPrompt, Converter={StaticResource BoolVis}}">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock TextWrapping="Wrap" Foreground="{StaticResource NexusTextPrimaryBrush}">
                        <Run Text="Ninja Nexus Setup skal køre som administrator for at installere, rydde op og opdatere Nexus-filer."/>
                    </TextBlock>
                    <Button Grid.Column="1" Content="Genstart som administrator"
                            Style="{StaticResource NexusPrimaryButton}" Margin="16,0,0,0"
                            Command="{Binding RelaunchAsAdminCommand}"/>
                </Grid>
            </Border>

            <!-- Step indicator -->
            <UniformGrid Grid.Row="2" Columns="6" Margin="0,16,0,16">
                <StackPanel HorizontalAlignment="Center">
                    <Ellipse Width="12" Height="12">
                        <Ellipse.Style>
                            <Style TargetType="Ellipse">
                                <Setter Property="Fill" Value="#334455"/>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsStep1Active}" Value="True">
                                        <Setter Property="Fill" Value="{StaticResource InstallerAccentGradientBrush}"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Ellipse.Style>
                    </Ellipse>
                    <TextBlock Text="Velkommen" FontSize="11" Margin="0,6,0,0"
                               Foreground="{StaticResource NexusTextSecondaryBrush}" HorizontalAlignment="Center"/>
                </StackPanel>
                <StackPanel HorizontalAlignment="Center">
                    <Ellipse Width="12" Height="12">
                        <Ellipse.Style>
                            <Style TargetType="Ellipse">
                                <Setter Property="Fill" Value="#334455"/>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsStep2Active}" Value="True">
                                        <Setter Property="Fill" Value="{StaticResource InstallerAccentGradientBrush}"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Ellipse.Style>
                    </Ellipse>
                    <TextBlock Text="Krav" FontSize="11" Margin="0,6,0,0"
                               Foreground="{StaticResource NexusTextSecondaryBrush}" HorizontalAlignment="Center"/>
                </StackPanel>
                <StackPanel HorizontalAlignment="Center">
                    <Ellipse Width="12" Height="12">
                        <Ellipse.Style>
                            <Style TargetType="Ellipse">
                                <Setter Property="Fill" Value="#334455"/>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsStep3Active}" Value="True">
                                        <Setter Property="Fill" Value="{StaticResource InstallerAccentGradientBrush}"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Ellipse.Style>
                    </Ellipse>
                    <TextBlock Text="Sti" FontSize="11" Margin="0,6,0,0"
                               Foreground="{StaticResource NexusTextSecondaryBrush}" HorizontalAlignment="Center"/>
                </StackPanel>
                <StackPanel HorizontalAlignment="Center">
                    <Ellipse Width="12" Height="12">
                        <Ellipse.Style>
                            <Style TargetType="Ellipse">
                                <Setter Property="Fill" Value="#334455"/>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsStep4Active}" Value="True">
                                        <Setter Property="Fill" Value="{StaticResource InstallerAccentGradientBrush}"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Ellipse.Style>
                    </Ellipse>
                    <TextBlock Text="Identitet" FontSize="11" Margin="0,6,0,0"
                               Foreground="{StaticResource NexusTextSecondaryBrush}" HorizontalAlignment="Center"/>
                </StackPanel>
                <StackPanel HorizontalAlignment="Center">
                    <Ellipse Width="12" Height="12">
                        <Ellipse.Style>
                            <Style TargetType="Ellipse">
                                <Setter Property="Fill" Value="#334455"/>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsStep5Active}" Value="True">
                                        <Setter Property="Fill" Value="{StaticResource InstallerAccentGradientBrush}"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Ellipse.Style>
                    </Ellipse>
                    <TextBlock Text="Sikkerhed" FontSize="11" Margin="0,6,0,0"
                               Foreground="{StaticResource NexusTextSecondaryBrush}" HorizontalAlignment="Center"/>
                </StackPanel>
                <StackPanel HorizontalAlignment="Center">
                    <Ellipse Width="12" Height="12">
                        <Ellipse.Style>
                            <Style TargetType="Ellipse">
                                <Setter Property="Fill" Value="#334455"/>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsStep6Active}" Value="True">
                                        <Setter Property="Fill" Value="{StaticResource InstallerAccentGradientBrush}"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Ellipse.Style>
                    </Ellipse>
                    <TextBlock Text="Installér" FontSize="11" Margin="0,6,0,0"
                               Foreground="{StaticResource NexusTextSecondaryBrush}" HorizontalAlignment="Center"/>
                </StackPanel>
            </UniformGrid>

            <!-- Glass content card -->
            <Border Grid.Row="3" Style="{StaticResource InstallerGlassCardStyle}"
                    MaxWidth="1280" MinHeight="400" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>

                    <StackPanel Grid.Row="0">
                        <TextBlock Text="{Binding StepTitle}" Style="{StaticResource NexusHeading}"/>
                        <TextBlock Text="{Binding StepSubtitle}" Style="{StaticResource NexusSubheading}"/>
                    </StackPanel>

                    <Grid Grid.Row="1" Margin="0,24,0,0">
                    <!-- Step 1 Welcome -->
                    <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center"
                                Visibility="{Binding IsWelcomeStep, Converter={StaticResource BoolVis}}">
                        <Image Source="/Assets/Stort_nexus_logo.png" Height="110" Stretch="Uniform"
                               HorizontalAlignment="Center" Margin="0,0,0,24"/>
                        <TextBlock Text="Velkommen til Ninja Nexus" Style="{StaticResource NexusHeading}"
                                   FontSize="24" HorizontalAlignment="Center"/>
                        <TextBlock Text="Et system. Alt forbundet." Style="{StaticResource NexusBodyText}"
                                   FontSize="16" HorizontalAlignment="Center" Margin="0,8,0,0"/>
                    </StackPanel>

                    <!-- Step 2 Requirements -->
                    <StackPanel Visibility="{Binding IsRequirementsStep, Converter={StaticResource BoolVis}}">
                        <ItemsControl ItemsSource="{Binding Requirements}">
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <UniformGrid Columns="2"/>
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Border Style="{StaticResource InstallerInnerCardStyle}" Margin="0,0,12,10" MinHeight="82">
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto"/>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="Auto"/>
                                            </Grid.ColumnDefinitions>
                                            <Ellipse Width="10" Height="10" VerticalAlignment="Center" Margin="0,0,12,0"
                                                     Fill="{Binding Status, Converter={StaticResource ReqBrush}}"/>
                                            <StackPanel Grid.Column="1">
                                                <TextBlock Text="{Binding Label}"
                                                           Foreground="{StaticResource NexusTextPrimaryBrush}" FontWeight="SemiBold"/>
                                                <TextBlock Text="{Binding Detail}" Style="{StaticResource NexusBodyText}" FontSize="12"/>
                                            </StackPanel>
                                            <TextBlock Grid.Column="2" Text="{Binding StatusDisplay}"
                                                       Foreground="{StaticResource NexusTextSecondaryBrush}"
                                                       VerticalAlignment="Center" FontSize="12"/>
                                        </Grid>
                                    </Border>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                        <StackPanel Orientation="Horizontal" Margin="0,12,0,0">
                            <Button Content="Opdatér tjek" Style="{StaticResource NexusSecondaryButton}"
                                    Command="{Binding RefreshRequirementsCommand}"/>
                            <Button Content="Download .NET Runtime" Style="{StaticResource InstallerGhostButtonStyle}"
                                    Command="{Binding DownloadDotNetCommand}" Margin="16,0,0,0"/>
                        </StackPanel>
                    </StackPanel>

                    <!-- Step 3 Path -->
                    <StackPanel Visibility="{Binding IsPathStep, Converter={StaticResource BoolVis}}">
                        <TextBlock Text="INSTALLATIONSMAPPE" Style="{StaticResource InstallerSectionLabelStyle}"/>
                        <Border Style="{StaticResource InstallerInnerCardStyle}">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <TextBox Text="{Binding InstallRoot, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                         IsReadOnly="False" Style="{StaticResource NexusTextBox}"/>
                                <Button Grid.Column="1" Content="Gennemse..." Margin="12,0,0,0"
                                        Style="{StaticResource NexusSecondaryButton}" Command="{Binding BrowseCommand}"/>
                            </Grid>
                        </Border>
                        <TextBlock Text="Standard: C:\NinjaNexusPOC" Style="{StaticResource NexusBodyText}" Margin="0,12,0,0"/>
                        <TextBlock Text="{Binding InstallPathValidationMessage}"
                                   Foreground="{StaticResource NexusErrorBrush}"
                                   TextWrapping="Wrap"
                                   Margin="0,8,0,0"
                                   Visibility="{Binding ShowInstallPathValidation, Converter={StaticResource BoolVis}}"/>
                        <CheckBox Content="Fresh POC reset (slet data efter backup — kun POC)"
                                  IsChecked="{Binding FreshPocResetConfirmed}" Style="{StaticResource NexusCheckBox}"
                                  Margin="0,12,0,0"/>
                    </StackPanel>

                    <!-- Step 4 Identity -->
                    <StackPanel Visibility="{Binding IsIdentityStep, Converter={StaticResource BoolVis}}">
                        <TextBlock Text="ORGANISATION" Style="{StaticResource InstallerSectionLabelStyle}"/>
                        <ComboBox ItemsSource="{Binding Organizations}"
                                  SelectedItem="{Binding SelectedOrganization, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                  DisplayMemberPath="DisplayName" IsEnabled="True"
                                  Style="{StaticResource NexusComboBox}" Margin="0,0,0,16"/>
                        <TextBlock Text="BRUGER" Style="{StaticResource InstallerSectionLabelStyle}"/>
                        <TextBox Text="{Binding UserEmail, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                 IsReadOnly="False"
                                 IsEnabled="{Binding AreIdentityInputsEnabled}"
                                 Style="{StaticResource NexusTextBox}" Margin="0,0,0,16"/>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <StackPanel Grid.Column="0" Margin="0,0,8,0">
                                <TextBlock Text="ROLLE" Style="{StaticResource InstallerSectionLabelStyle}"/>
                                <ComboBox ItemsSource="{Binding Roles}"
                                          SelectedItem="{Binding SelectedRole, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                          DisplayMemberPath="DisplayName"
                                          IsEnabled="{Binding AreIdentityInputsEnabled}"
                                          Style="{StaticResource NexusComboBox}"/>
                            </StackPanel>
                            <StackPanel Grid.Column="1" Margin="8,0,0,0">
                                <TextBlock Text="ENHEDSNAVN" Style="{StaticResource InstallerSectionLabelStyle}"/>
                                <TextBox Text="{Binding DeviceName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                         IsReadOnly="False"
                                         IsEnabled="{Binding AreIdentityInputsEnabled}"
                                         Style="{StaticResource NexusTextBox}"/>
                            </StackPanel>
                        </Grid>
                        <TextBlock Text="{Binding OrganizationStatusMessage}"
                                   Style="{StaticResource NexusBodyText}" Margin="0,12,0,0"
                                   Visibility="{Binding ShowOrganizationStatus, Converter={StaticResource BoolVis}}"/>
                    </StackPanel>

                    <!-- Step 5 Security -->
                    <StackPanel Visibility="{Binding IsSecurityStep, Converter={StaticResource BoolVis}}">
                        <TextBlock Text="IDENTITY STATUS" Style="{StaticResource InstallerSectionLabelStyle}" Margin="0,0,0,8"/>
                        <ItemsControl ItemsSource="{Binding ReadinessItems}" Margin="0,0,0,16">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Grid Margin="0,0,0,6">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*"/>
                                            <ColumnDefinition Width="Auto"/>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Text="{Binding Label}" Style="{StaticResource NexusBodyText}"/>
                                        <TextBlock Grid.Column="1" Text="{Binding StatusDisplay}"
                                                   Foreground="{StaticResource NexusTextSecondaryBrush}" FontSize="12"/>
                                    </Grid>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                        <Border Style="{StaticResource InstallerInnerCardStyle}" Margin="0,0,0,12">
                            <StackPanel>
                                <TextBlock Text="Lockdown, identitet og agent"
                                           Foreground="{StaticResource NexusTextPrimaryBrush}" FontWeight="SemiBold"/>
                                <TextBlock Style="{StaticResource NexusBodyText}" Margin="0,8,0,0"
                                           Text="Installer opretter lokal Nexus Identity og forbereder agent-metadata. Ingen permanent lockdown aktiveres."/>
                            </StackPanel>
                        </Border>
                        <Border Style="{StaticResource InstallerInnerCardStyle}" Margin="0,0,0,12">
                            <StackPanel>
                                <TextBlock Text="Opdateringskanal"
                                           Foreground="{StaticResource NexusTextPrimaryBrush}" FontWeight="SemiBold"/>
                                <TextBlock Style="{StaticResource NexusBodyText}" Margin="0,8,0,0"
                                           Text="Update channel verificeres mod nexus.ninjakernen.info ved installation og første start."/>
                            </StackPanel>
                        </Border>
                        <Border CornerRadius="14" Padding="16" BorderThickness="1" BorderBrush="#66F59E0B" Background="#18F59E0B">
                            <TextBlock TextWrapping="Wrap" FontSize="13">
                                <Run Text="POC-advarsel: " FontWeight="SemiBold" Foreground="#F59E0B"/>
                                <Run Text="Dette er en proof-of-concept. Permanent enheds-lockdown kræver eksplicit godkendelse og aktiveres ikke af denne installer."
                                     Foreground="{StaticResource NexusTextSecondaryBrush}"/>
                            </TextBlock>
                        </Border>
                    </StackPanel>

                    <!-- Step 6 Install -->
                    <StackPanel Visibility="{Binding IsInstallStep, Converter={StaticResource BoolVis}}">
                        <Border Style="{StaticResource InstallerInnerCardStyle}" Margin="0,0,0,12"
                                Visibility="{Binding ShowCompletionScreen, Converter={StaticResource BoolVis}}">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Border Width="44" Height="44" CornerRadius="22"
                                        Background="{StaticResource InstallerAccentGradientBrush}"
                                        VerticalAlignment="Top" Margin="0,2,16,0">
                                    <TextBlock Text="✓" HorizontalAlignment="Center" VerticalAlignment="Center"
                                               FontSize="22" FontWeight="Bold" Foreground="#FFFFFF"/>
                                </Border>
                                <StackPanel Grid.Column="1">
                                    <TextBlock Text="Ninja Nexus er installeret"
                                               Foreground="{StaticResource NexusTextPrimaryBrush}"
                                               FontSize="20" FontWeight="SemiBold"/>
                                    <TextBlock Text="{Binding BuildLabel, StringFormat='Klar til lokal POC: {0}'}"
                                               Style="{StaticResource NexusBodyText}" Margin="0,6,0,0"/>
                                    <TextBlock Text="{Binding InstallRoot, StringFormat='Installeret i: {0}'}"
                                               Style="{StaticResource NexusBodyText}" FontSize="12"
                                               Margin="0,6,0,0"/>
                                    <TextBlock Text="{Binding GeneratedDeviceId, StringFormat='Enheds-ID: {0}'}"
                                               Foreground="{StaticResource NexusCyanBrush}"
                                               FontSize="12" Margin="0,8,0,0"/>
                                </StackPanel>
                            </Grid>
                        </Border>

                        <!-- Global progress header -->
                        <Border Style="{StaticResource InstallerInnerCardStyle}" Margin="0,0,0,12"
                                Visibility="{Binding ShowInstallProgressHeader, Converter={StaticResource BoolVis}}">
                            <StackPanel>
                                <Grid Margin="0,0,0,10">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>
                                    <TextBlock Text="{Binding InstallProgressLabel}"
                                               Foreground="{StaticResource NexusTextPrimaryBrush}"
                                               FontWeight="SemiBold" FontSize="15"/>
                                    <Border Grid.Column="1" CornerRadius="10" Padding="10,4"
                                            Background="{Binding InstallStatusPill, Converter={StaticResource StatusPillBrush}}">
                                        <TextBlock Text="{Binding InstallStatusPill}"
                                                   Foreground="#FFFFFF" FontSize="11" FontWeight="SemiBold"/>
                                    </Border>
                                </Grid>
                                <ProgressBar Value="{Binding InstallProgressPercent, Mode=OneWay}" Maximum="100" Height="8"
                                             Foreground="{StaticResource InstallerAccentGradientBrush}"
                                             Background="#22081428" BorderThickness="0"/>
                                <TextBlock Margin="0,10,0,0"
                                           Text="{Binding CurrentInstallAction, StringFormat='Nuværende: {0}'}"
                                           Foreground="{StaticResource NexusCyanBrush}" FontSize="13"/>
                                <TextBlock Text="Installationen ser ud til at være fastlåst. Vent eller genstart installeren."
                                           Foreground="{StaticResource NexusErrorBrush}" FontSize="12"
                                           Margin="0,8,0,0"
                                           Visibility="{Binding IsInstallHung, Converter={StaticResource BoolVis}}"/>
                            </StackPanel>
                        </Border>

                        <!-- Step list timeline -->
                        <ItemsControl ItemsSource="{Binding InstallPhases}">
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <UniformGrid Columns="2"/>
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Border CornerRadius="12" Padding="10,8" Margin="0,0,10,8"
                                            BorderThickness="1"
                                            Background="{Binding Status, Converter={StaticResource StepRowBackground}}"
                                            BorderBrush="{Binding Status, Converter={StaticResource StepBorderBrush}}"
                                            Opacity="{Binding Status, Converter={StaticResource StepActiveOpacity}}">
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto"/>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="Auto"/>
                                                <ColumnDefinition Width="Auto"/>
                                            </Grid.ColumnDefinitions>
                                            <Grid Width="14" Height="14" VerticalAlignment="Center" Margin="0,0,12,0">
                                                <Ellipse Fill="{Binding Status, Converter={StaticResource StepStatusBrush}}"/>
                                                <Ellipse Visibility="{Binding ShowPulse, Converter={StaticResource BoolVis}}">
                                                    <Ellipse.Style>
                                                        <Style TargetType="Ellipse">
                                                            <Setter Property="Width" Value="14"/>
                                                            <Setter Property="Height" Value="14"/>
                                                            <Setter Property="Stroke" Value="{StaticResource NexusCyanBrush}"/>
                                                            <Setter Property="StrokeThickness" Value="2"/>
                                                            <Setter Property="Opacity" Value="0.35"/>
                                                        </Style>
                                                    </Ellipse.Style>
                                                </Ellipse>
                                            </Grid>
                                            <StackPanel Grid.Column="1">
                                                <TextBlock Text="{Binding Label}"
                                                           Foreground="{StaticResource NexusTextPrimaryBrush}"
                                                           FontWeight="SemiBold"/>
                                                <TextBlock Text="{Binding Detail}"
                                                           Foreground="{StaticResource NexusTextSecondaryBrush}"
                                                           FontSize="11" TextWrapping="Wrap"
                                                           Visibility="{Binding Detail, Converter={StaticResource StringVis}}"/>
                                            </StackPanel>
                                            <TextBlock Grid.Column="2" Text="{Binding ElapsedDisplay}"
                                                       Foreground="{StaticResource NexusTextSecondaryBrush}"
                                                       FontSize="11" VerticalAlignment="Center" Margin="0,0,10,0"/>
                                            <Border Grid.Column="3" CornerRadius="8" Padding="8,3"
                                                    Background="#22000000" VerticalAlignment="Center">
                                                <TextBlock Text="{Binding StatusDisplay}"
                                                           Foreground="{StaticResource NexusTextSecondaryBrush}"
                                                           FontSize="11" FontWeight="SemiBold"/>
                                            </Border>
                                        </Grid>
                                    </Border>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>

                        <!-- Live details / events panel -->
                        <Border Style="{StaticResource InstallerInnerCardStyle}" Margin="0,8,0,0"
                                MaxHeight="200">
                            <ScrollViewer VerticalScrollBarVisibility="Auto">
                            <StackPanel>
                                <TextBlock Text="DETALJER / LIVE LOG" Style="{StaticResource InstallerSectionLabelStyle}"/>
                                <ItemsControl ItemsSource="{Binding RecentInstallEvents}">
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <Grid Margin="0,0,0,6">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="Auto"/>
                                                    <ColumnDefinition Width="Auto"/>
                                                    <ColumnDefinition Width="*"/>
                                                </Grid.ColumnDefinitions>
                                                <TextBlock Text="{Binding DisplayTime}"
                                                           Foreground="{StaticResource NexusTextSecondaryBrush}"
                                                           FontSize="11" FontFamily="Consolas" Margin="0,0,8,0"/>
                                                <Border Grid.Column="1" CornerRadius="6" Padding="6,2" Margin="0,0,8,0"
                                                        Background="{Binding Kind, Converter={StaticResource EventKindBrush}}">
                                                    <TextBlock Text="{Binding KindLabel}" Foreground="#FFFFFF"
                                                               FontSize="10" FontWeight="SemiBold"/>
                                                </Border>
                                                <TextBlock Grid.Column="2" Text="{Binding Message}"
                                                           Foreground="{StaticResource NexusTextPrimaryBrush}"
                                                           FontSize="11" TextWrapping="Wrap"/>
                                            </Grid>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                            </StackPanel>
                            </ScrollViewer>
                        </Border>

                        <CheckBox Content="Start Nexus automatisk efter installation"
                                  IsChecked="{Binding StartAfterInstall}" Style="{StaticResource NexusCheckBox}"
                                  Margin="0,16,0,0" Visibility="{Binding IsInstalled, Converter={StaticResource InvBoolVis}}"/>

                        <TextBlock Text="{Binding GeneratedDeviceId, StringFormat='Enheds-ID: {0}'}"
                                   Foreground="{StaticResource NexusCyanBrush}" Margin="0,12,0,0"
                                   Visibility="{Binding IsInstalled, Converter={StaticResource BoolVis}}"/>

                        <TextBlock Text="{Binding ErrorMessage}" Foreground="{StaticResource NexusErrorBrush}"
                                   TextWrapping="Wrap" Margin="0,12,0,0"
                                   Visibility="{Binding ErrorMessage, Converter={StaticResource StringVis}}"/>
                    </StackPanel>
                    </Grid>
                </Grid>
            </Border>

            <!-- Collapsible log -->
            <Expander Grid.Row="4" Header="{Binding LogToggleLabel}" IsExpanded="{Binding IsLogExpanded}"
                      Margin="0,16,0,0" Foreground="{StaticResource NexusTextSecondaryBrush}"
                      Background="#12101828" BorderBrush="#22FFFFFF" BorderThickness="1" Padding="8">
                <TextBox Text="{Binding LogText, Mode=OneWay}" Style="{StaticResource InstallerLogTextStyle}" Height="140"/>
            </Expander>

            <!-- Footer -->
            <Grid Grid.Row="5" Margin="0,20,0,0">
                <StackPanel VerticalAlignment="Center">
                    <TextBlock Text="{Binding BuildLabel}" Style="{StaticResource NexusBodyText}"/>
                    <TextBlock Text="{Binding InstallRoot, StringFormat='Sti: {0}'}"
                               Style="{StaticResource NexusBodyText}" FontSize="11" Opacity="0.8"/>
                </StackPanel>
                <WrapPanel Orientation="Horizontal" HorizontalAlignment="Right">
                    <Button Content="Annuller" Style="{StaticResource NexusSecondaryButton}"
                            Command="{Binding CancelInstallCommand}" Margin="0,0,8,0"
                            Visibility="{Binding IsInstalling, Converter={StaticResource BoolVis}}"/>
                    <Button Content="Genprøv" Style="{StaticResource NexusSecondaryButton}"
                            Command="{Binding RetryInstallCommand}" Margin="0,0,8,0"
                            Visibility="{Binding ShowInstallFailedActions, Converter={StaticResource BoolVis}}"/>
                    <Button Content="Ryd fastlåst installation" Style="{StaticResource NexusSecondaryButton}"
                            Command="{Binding ClearStuckCommand}" Margin="0,0,8,0"
                            ToolTip="Brug kun hvis en tidligere installation sidder fast"
                            Visibility="{Binding IsInstallStep, Converter={StaticResource BoolVis}}"/>
                    <Button Content="Åbn logs" Style="{StaticResource NexusSecondaryButton}"
                            Command="{Binding OpenLogsCommand}" Margin="0,0,8,0"
                            ToolTip="Åbner lokal installationslog"
                            Visibility="{Binding IsInstallStep, Converter={StaticResource BoolVis}}"/>
                    <Button Content="Tilbage" Style="{StaticResource NexusSecondaryButton}"
                            Command="{Binding BackCommand}" Margin="0,0,8,0"
                            Visibility="{Binding CanGoBack, Converter={StaticResource BoolVis}}"/>
                    <Button Content="{Binding PrimaryButtonLabel}" Style="{StaticResource NexusPrimaryButton}"
                            Command="{Binding NextCommand}" Margin="0,0,8,0"
                            Visibility="{Binding IsInstallStep, Converter={StaticResource InvBoolVis}}"/>
                    <Button Content="Installér" Style="{StaticResource NexusPrimaryButton}"
                            Command="{Binding InstallCommand}" Margin="0,0,8,0"
                            Visibility="{Binding ShowPrimaryOnInstallStep, Converter={StaticResource BoolVis}}"/>
                    <Button Content="Afslut installer" Style="{StaticResource NexusSecondaryButton}"
                            Command="{Binding ExitInstallerCommand}" Margin="0,0,8,0"
                            Visibility="{Binding ShowCompletionScreen, Converter={StaticResource BoolVis}}"/>
                    <Button Content="Start Nexus" Style="{StaticResource NexusPrimaryButton}"
                            Command="{Binding StartNexusCommand}"
                            Visibility="{Binding ShowCompletionScreen, Converter={StaticResource BoolVis}}"/>
                </WrapPanel>
            </Grid>
        </Grid>
    </Grid>
</Window>
