<Window x:Class="PSLauncher.App.Views.SettingsDialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="clr-namespace:PSLauncher.App.ViewModels"
        xmlns:loc="clr-namespace:PSLauncher.Core.Localization;assembly=PSLauncher.Core"
        Title="{x:Static loc:Strings.SettingsTitle}"
        Icon="pack://application:,,,/Resources/favicon.ico"
        Width="640" Height="720"
        MinWidth="540" MinHeight="500"
        WindowStartupLocation="CenterOwner"
        Background="{StaticResource Brush.Bg.Window}"
        d:DataContext="{d:DesignInstance Type=vm:SettingsViewModel}"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        mc:Ignorable="d"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <!-- Header -->
        <Border Grid.Row="0" Padding="32,24,32,16">
            <TextBlock Text="{x:Static loc:Strings.SettingsTitle}" FontSize="22" FontWeight="SemiBold"
                       Foreground="{StaticResource Brush.Text.Primary}" />
        </Border>

        <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto" Padding="32,0,32,16">
            <StackPanel>

                <!-- License de mise à jour (en tête : c'est l'info la plus importante,
                     elle conditionne ce que l'utilisateur peut télécharger.
                     Bordure colorée selon l'état : vert/jaune/rouge). -->
                <Border BorderThickness="2"
                        CornerRadius="6" Padding="20" Margin="0,0,0,16">
                    <Border.Style>
                        <Style TargetType="Border">
                            <Setter Property="Background" Value="#2A1414" />
                            <Setter Property="BorderBrush" Value="#EF4444" />
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding LicenseSeverity}" Value="Ok">
                                    <Setter Property="Background" Value="{StaticResource Brush.Status.InstalledBg}" />
                                    <Setter Property="BorderBrush" Value="{StaticResource Brush.Status.Installed}" />
                                </DataTrigger>
                                <DataTrigger Binding="{Binding LicenseSeverity}" Value="Warning">
                                    <Setter Property="Background" Value="{StaticResource Brush.Status.BusyBg}" />
                                    <Setter Property="BorderBrush" Value="{StaticResource Brush.Status.Busy}" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Border.Style>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <!-- Icône -->
                        <TextBlock Grid.Row="0" Grid.RowSpan="2" Grid.Column="0"
                                   Text="{Binding LicenseIcon}"
                                   FontSize="36" FontWeight="Bold"
                                   VerticalAlignment="Center"
                                   Margin="0,0,16,0">
                            <TextBlock.Style>
                                <Style TargetType="TextBlock">
                                    <Setter Property="Foreground" Value="#EF4444" />
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding LicenseSeverity}" Value="Ok">
                                            <Setter Property="Foreground" Value="{StaticResource Brush.Status.Installed}" />
                                        </DataTrigger>
                                        <DataTrigger Binding="{Binding LicenseSeverity}" Value="Warning">
                                            <Setter Property="Foreground" Value="{StaticResource Brush.Status.Busy}" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </TextBlock.Style>
                        </TextBlock>

                        <!-- Header text -->
                        <TextBlock Grid.Row="0" Grid.Column="1"
                                   Text="{x:Static loc:Strings.SettingsLicense}"
                                   FontSize="11" FontWeight="Bold"
                                   Foreground="{StaticResource Brush.Text.Secondary}" />
                        <TextBlock Grid.Row="1" Grid.Column="1"
                                   Text="{Binding LicenseInfo}"
                                   Foreground="{StaticResource Brush.Text.Primary}"
                                   FontWeight="SemiBold" FontSize="14"
                                   Margin="0,2,0,0"
                                   TextWrapping="Wrap" />

                        <!-- Machine ID en dessous -->
                        <Grid Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,12,0,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <StackPanel Grid.Column="0">
                                <TextBlock Text="{x:Static loc:Strings.SettingsMachineId}"
                                           FontSize="11"
                                           Foreground="{StaticResource Brush.Text.Secondary}" />
                                <TextBlock Text="{Binding MachineId}"
                                           FontFamily="Consolas" FontSize="11"
                                           Foreground="{StaticResource Brush.Text.Primary}"
                                           Margin="0,2,0,0" TextTrimming="CharacterEllipsis" />
                            </StackPanel>
                            <Button Grid.Column="1"
                                    Style="{StaticResource SecondaryButton}"
                                    Content="{x:Static loc:Strings.SettingsCopyMachineId}"
                                    Command="{Binding CopyMachineIdCommand}" />
                        </Grid>
                    </Grid>
                </Border>

                <!-- Langue de l'interface -->
                <Border Background="{StaticResource Brush.Bg.Card}"
                        BorderBrush="{StaticResource Brush.Border}" BorderThickness="1"
                        CornerRadius="6" Padding="20" Margin="0,0,0,16">
                    <StackPanel>
                        <TextBlock Text="{x:Static loc:Strings.SettingsLanguage}"
                                   FontSize="11" FontWeight="Bold"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   Margin="0,0,0,8" />
                        <ComboBox ItemsSource="{Binding AvailableLanguages}"
                                  DisplayMemberPath="Name"
                                  SelectedValuePath="Code"
                                  SelectedValue="{Binding Language, Mode=TwoWay}"
                                  Background="#1A1A20"
                                  Foreground="{StaticResource Brush.Text.Primary}"
                                  BorderBrush="{StaticResource Brush.Border}"
                                  BorderThickness="1" Padding="8" />
                        <TextBlock Text="{x:Static loc:Strings.SettingsLanguageHint}"
                                   FontSize="11" Foreground="{StaticResource Brush.Text.Secondary}"
                                   FontStyle="Italic" Margin="0,6,0,0" TextWrapping="Wrap" />
                    </StackPanel>
                </Border>

                <!--
                    Section "À propos" : version + copyright. Visible (pas dans l'Expander),
                    placée entre Langue et les paramètres avancés repliés. C'est l'info que
                    le support demande en premier en cas de bug.
                -->
                <Border Background="{StaticResource Brush.Bg.Card}"
                        BorderBrush="{StaticResource Brush.Border}" BorderThickness="1"
                        CornerRadius="6" Padding="20" Margin="0,0,0,16">
                    <StackPanel>
                        <TextBlock Text="{x:Static loc:Strings.SettingsAbout}"
                                   FontSize="11" FontWeight="Bold"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   Margin="0,0,0,8" />
                        <TextBlock FontSize="13"
                                   Foreground="{StaticResource Brush.Text.Primary}">
                            <Run Text="{x:Static loc:Strings.SettingsLauncherVersion}" />
                            <Run Text=" " />
                            <Run Text="{Binding LauncherVersion, Mode=OneWay}" FontWeight="SemiBold" />
                        </TextBlock>
                        <TextBlock Text="{x:Static loc:Strings.Copyright}"
                                   FontSize="12"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   Margin="0,4,0,0" />
                    </StackPanel>
                </Border>

                <!--
                    Sections "techniques" : Server / Installation / Cache / Database / Logs
                    repliées par défaut sous un Expander pour ne pas noyer les sections
                    importantes (License, Langue, About) qui restent dépliées.
                    Placé en BAS de la fenêtre car ce sont des trucs de power-user / support.
                -->
                <Expander x:Name="AdvancedExpander"
                          Header="{x:Static loc:Strings.SettingsAdvanced}"
                          Foreground="{StaticResource Brush.Text.Secondary}"
                          FontSize="11" FontWeight="Bold"
                          Background="Transparent" BorderThickness="0"
                          Margin="0,0,0,16" IsExpanded="False"
                          Expanded="OnAdvancedExpanded">
                    <StackPanel Margin="0,12,0,0">

                <!-- Serveur -->
                <Border Background="{StaticResource Brush.Bg.Card}"
                        BorderBrush="{StaticResource Brush.Border}" BorderThickness="1"
                        CornerRadius="6" Padding="20" Margin="0,0,0,16">
                    <StackPanel>
                        <TextBlock Text="{x:Static loc:Strings.SettingsServer}"
                                   FontSize="11" FontWeight="Bold"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   Margin="0,0,0,8" />
                        <TextBlock Text="{x:Static loc:Strings.SettingsApiUrl}"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   FontSize="12" Margin="0,0,0,4" />
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <TextBox Grid.Column="0"
                                     Text="{Binding ServerBaseUrl, UpdateSourceTrigger=PropertyChanged}"
                                     Background="#1A1A20"
                                     Foreground="{StaticResource Brush.Text.Primary}"
                                     BorderBrush="{StaticResource Brush.Border}"
                                     BorderThickness="1" Padding="8" />
                            <Button Grid.Column="1" Margin="8,0,0,0"
                                    Style="{StaticResource SecondaryButton}"
                                    Content="{x:Static loc:Strings.SettingsTest}"
                                    Command="{Binding TestConnectionCommand}"
                                    IsEnabled="{Binding IsTestingConnection, Converter={StaticResource InverseBoolToBool}}" />
                        </Grid>
                        <TextBlock Text="{Binding ConnectionStatus}"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   FontSize="12" Margin="0,8,0,0" TextWrapping="Wrap" />

                        <!-- URLs des onglets latéraux Report / Documentation -->
                        <TextBlock Text="{x:Static loc:Strings.SettingsReportUrl}"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   FontSize="12" Margin="0,16,0,4" />
                        <TextBox Text="{Binding ReportUrl, UpdateSourceTrigger=PropertyChanged}"
                                 Background="#1A1A20" Foreground="{StaticResource Brush.Text.Primary}"
                                 BorderBrush="{StaticResource Brush.Border}" BorderThickness="1" Padding="8"
                                 FontFamily="Consolas" />

                        <TextBlock Text="{x:Static loc:Strings.SettingsDocsUrl}"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   FontSize="12" Margin="0,12,0,4" />
                        <TextBox Text="{Binding DocumentationUrl, UpdateSourceTrigger=PropertyChanged}"
                                 Background="#1A1A20" Foreground="{StaticResource Brush.Text.Primary}"
                                 BorderBrush="{StaticResource Brush.Border}" BorderThickness="1" Padding="8"
                                 FontFamily="Consolas" />

                        <!-- Connexions parallèles : tuning de la queue de fin de DL -->
                        <TextBlock Text="{x:Static loc:Strings.SettingsParallelSegments}"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   FontSize="12" Margin="0,16,0,4" />
                        <TextBox Text="{Binding ParallelSegments, UpdateSourceTrigger=PropertyChanged}"
                                 Background="#1A1A20" Foreground="{StaticResource Brush.Text.Primary}"
                                 BorderBrush="{StaticResource Brush.Border}" BorderThickness="1" Padding="8"
                                 Width="80" HorizontalAlignment="Left" />
                        <TextBlock Text="{x:Static loc:Strings.SettingsParallelSegmentsHint}"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   FontSize="11" FontStyle="Italic" Margin="0,4,0,0"
                                   TextWrapping="Wrap" />
                    </StackPanel>
                </Border>

                <!-- Installation -->
                <Border Background="{StaticResource Brush.Bg.Card}"
                        BorderBrush="{StaticResource Brush.Border}" BorderThickness="1"
                        CornerRadius="6" Padding="20" Margin="0,0,0,16">
                    <StackPanel>
                        <TextBlock Text="{x:Static loc:Strings.SettingsInstallation}"
                                   FontSize="11" FontWeight="Bold"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   Margin="0,0,0,8" />
                        <TextBlock Text="{x:Static loc:Strings.SettingsInstallRoot}"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   FontSize="12" Margin="0,0,0,4" />
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <TextBox Grid.Column="0"
                                     Text="{Binding InstallRoot, UpdateSourceTrigger=PropertyChanged}"
                                     Background="#1A1A20"
                                     Foreground="{StaticResource Brush.Text.Primary}"
                                     BorderBrush="{StaticResource Brush.Border}"
                                     BorderThickness="1" Padding="8"
                                     FontFamily="Consolas" />
                            <Button Grid.Column="1" Margin="8,0,0,0"
                                    Style="{StaticResource SecondaryButton}"
                                    Content="{x:Static loc:Strings.SettingsBrowse}"
                                    Command="{Binding BrowseInstallRootCommand}" />
                        </Grid>
                    </StackPanel>
                </Border>

                <!-- Cache -->
                <Border Background="{StaticResource Brush.Bg.Card}"
                        BorderBrush="{StaticResource Brush.Border}" BorderThickness="1"
                        CornerRadius="6" Padding="20" Margin="0,0,0,16">
                    <StackPanel>
                        <TextBlock Text="{x:Static loc:Strings.SettingsCache}"
                                   FontSize="11" FontWeight="Bold"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   Margin="0,0,0,8" />
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <StackPanel Grid.Column="0">
                                <TextBlock Text="{Binding CacheDirectory}"
                                           FontFamily="Consolas" FontSize="11"
                                           Foreground="{StaticResource Brush.Text.Primary}"
                                           TextTrimming="CharacterEllipsis" />
                                <TextBlock FontSize="12"
                                           Foreground="{StaticResource Brush.Text.Secondary}">
                                    <Run Text="{x:Static loc:Strings.SettingsCacheSize}" />
                                    <Run Text=" " />
                                    <Run Text="{Binding CacheSizeDisplay}" FontWeight="SemiBold" />
                                </TextBlock>
                            </StackPanel>
                            <Button Grid.Column="1" Margin="8,0,0,0"
                                    Style="{StaticResource SecondaryButton}"
                                    Content="📁"
                                    Command="{Binding OpenCacheFolderCommand}" />
                            <Button Grid.Column="2" Margin="8,0,0,0"
                                    Style="{StaticResource SecondaryButton}"
                                    Content="{x:Static loc:Strings.SettingsClearCache}"
                                    Command="{Binding ClearCacheCommand}" />
                        </Grid>
                    </StackPanel>
                </Border>

                <!-- Base de données (XAMPP / MySQL) — config + test + replay -->
                <Border Background="{StaticResource Brush.Bg.Card}"
                        BorderBrush="{StaticResource Brush.Border}" BorderThickness="1"
                        CornerRadius="6" Padding="20" Margin="0,0,0,16">
                    <StackPanel>
                        <TextBlock Text="{x:Static loc:Strings.SettingsDatabase}"
                                   FontSize="11" FontWeight="Bold"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   Margin="0,0,0,8" />

                        <Grid Margin="0,0,0,8">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="100" />
                            </Grid.ColumnDefinitions>
                            <StackPanel Grid.Column="0" Margin="0,0,8,0">
                                <TextBlock Text="{x:Static loc:Strings.SettingsDbHost}"
                                           Foreground="{StaticResource Brush.Text.Secondary}"
                                           FontSize="12" Margin="0,0,0,4" />
                                <TextBox Text="{Binding DbHost, UpdateSourceTrigger=PropertyChanged}"
                                         Background="#1A1A20" Foreground="{StaticResource Brush.Text.Primary}"
                                         BorderBrush="{StaticResource Brush.Border}" BorderThickness="1" Padding="8" />
                            </StackPanel>
                            <StackPanel Grid.Column="1">
                                <TextBlock Text="{x:Static loc:Strings.SettingsDbPort}"
                                           Foreground="{StaticResource Brush.Text.Secondary}"
                                           FontSize="12" Margin="0,0,0,4" />
                                <TextBox Text="{Binding DbPort, UpdateSourceTrigger=PropertyChanged}"
                                         Background="#1A1A20" Foreground="{StaticResource Brush.Text.Primary}"
                                         BorderBrush="{StaticResource Brush.Border}" BorderThickness="1" Padding="8" />
                            </StackPanel>
                        </Grid>

                        <Grid Margin="0,0,0,8">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <StackPanel Grid.Column="0" Margin="0,0,8,0">
                                <TextBlock Text="{x:Static loc:Strings.SettingsDbUser}"
                                           Foreground="{StaticResource Brush.Text.Secondary}"
                                           FontSize="12" Margin="0,0,0,4" />
                                <TextBox Text="{Binding DbUser, UpdateSourceTrigger=PropertyChanged}"
                                         Background="#1A1A20" Foreground="{StaticResource Brush.Text.Primary}"
                                         BorderBrush="{StaticResource Brush.Border}" BorderThickness="1" Padding="8" />
                            </StackPanel>
                            <StackPanel Grid.Column="1">
                                <TextBlock Text="{x:Static loc:Strings.SettingsDbPassword}"
                                           Foreground="{StaticResource Brush.Text.Secondary}"
                                           FontSize="12" Margin="0,0,0,4" />
                                <TextBox Text="{Binding DbPassword, UpdateSourceTrigger=PropertyChanged}"
                                         Background="#1A1A20" Foreground="{StaticResource Brush.Text.Primary}"
                                         BorderBrush="{StaticResource Brush.Border}" BorderThickness="1" Padding="8"
                                         FontFamily="Consolas" />
                            </StackPanel>
                        </Grid>

                        <TextBlock Text="{x:Static loc:Strings.SettingsDbName}"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   FontSize="12" Margin="0,0,0,4" />
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <TextBox Grid.Column="0"
                                     Text="{Binding DbName, UpdateSourceTrigger=PropertyChanged}"
                                     Background="#1A1A20" Foreground="{StaticResource Brush.Text.Primary}"
                                     BorderBrush="{StaticResource Brush.Border}" BorderThickness="1" Padding="8"
                                     FontFamily="Consolas" />
                            <Button Grid.Column="1" Margin="8,0,0,0"
                                    Style="{StaticResource SecondaryButton}"
                                    Content="{x:Static loc:Strings.SettingsTest}"
                                    Command="{Binding TestDbCommand}"
                                    IsEnabled="{Binding IsTestingDb, Converter={StaticResource InverseBoolToBool}}" />
                        </Grid>
                        <TextBlock Text="{Binding DbConnectionStatus}"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   FontSize="12" Margin="0,8,0,0" TextWrapping="Wrap" />

                        <CheckBox IsChecked="{Binding DbAutoApplyMigrations}"
                                  Margin="0,12,0,0"
                                  Foreground="{StaticResource Brush.Text.Primary}"
                                  Content="{x:Static loc:Strings.SettingsDbAutoMigrate}" />

                        <Grid Margin="0,12,0,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="0"
                                       Text="{Binding MigrationsReplayStatus}"
                                       Foreground="{StaticResource Brush.Text.Secondary}"
                                       FontSize="12" VerticalAlignment="Center"
                                       TextWrapping="Wrap" />
                            <Button Grid.Column="1"
                                    Style="{StaticResource SecondaryButton}"
                                    Content="{x:Static loc:Strings.SettingsDbReplay}"
                                    Command="{Binding ReplayMigrationsCommand}"
                                    IsEnabled="{Binding IsReplayingMigrations, Converter={StaticResource InverseBoolToBool}}" />
                        </Grid>

                        <TextBlock Text="{x:Static loc:Strings.SettingsDbHint}"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   FontStyle="Italic" FontSize="11" Margin="0,8,0,0"
                                   TextWrapping="Wrap" />
                    </StackPanel>
                </Border>

                <!-- Outil Report (XAMPP htdocs deploy) -->
                <Border Background="{StaticResource Brush.Bg.Card}"
                        BorderBrush="{StaticResource Brush.Border}" BorderThickness="1"
                        CornerRadius="6" Padding="20" Margin="0,0,0,16">
                    <StackPanel>
                        <TextBlock Text="{x:Static loc:Strings.SettingsReportTool}"
                                   FontSize="11" FontWeight="Bold"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   Margin="0,0,0,8" />

                        <TextBlock Text="{x:Static loc:Strings.SettingsReportHtdocs}"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   FontSize="12" Margin="0,0,0,4" />
                        <TextBox Text="{Binding ReportHtdocsRoot, UpdateSourceTrigger=PropertyChanged}"
                                 Background="#1A1A20" Foreground="{StaticResource Brush.Text.Primary}"
                                 BorderBrush="{StaticResource Brush.Border}" BorderThickness="1" Padding="8"
                                 FontFamily="Consolas" />

                        <TextBlock Text="{x:Static loc:Strings.SettingsReportFolder}"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   FontSize="12" Margin="0,12,0,4" />
                        <TextBox Text="{Binding ReportFolderName, UpdateSourceTrigger=PropertyChanged}"
                                 Background="#1A1A20" Foreground="{StaticResource Brush.Text.Primary}"
                                 BorderBrush="{StaticResource Brush.Border}" BorderThickness="1" Padding="8"
                                 FontFamily="Consolas" />

                        <CheckBox IsChecked="{Binding ReportAutoDeploy}"
                                  Margin="0,12,0,0"
                                  Foreground="{StaticResource Brush.Text.Primary}"
                                  Content="{x:Static loc:Strings.SettingsReportAutoDeploy}" />

                        <!-- Conserver N backups -->
                        <Grid Margin="0,12,0,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="80" />
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="0"
                                       Text="{x:Static loc:Strings.SettingsReportMaxBackups}"
                                       Foreground="{StaticResource Brush.Text.Secondary}"
                                       FontSize="12" VerticalAlignment="Center" />
                            <TextBox Grid.Column="1"
                                     Text="{Binding ReportMaxBackups, UpdateSourceTrigger=PropertyChanged}"
                                     Background="#1A1A20" Foreground="{StaticResource Brush.Text.Primary}"
                                     BorderBrush="{StaticResource Brush.Border}" BorderThickness="1" Padding="8" />
                        </Grid>

                        <Grid Margin="0,12,0,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="0"
                                       Text="{Binding ReportDeployStatus}"
                                       Foreground="{StaticResource Brush.Text.Secondary}"
                                       FontSize="12" VerticalAlignment="Center"
                                       TextWrapping="Wrap" />
                            <Button Grid.Column="1"
                                    Style="{StaticResource SecondaryButton}"
                                    Content="{x:Static loc:Strings.SettingsReportRedeploy}"
                                    Command="{Binding RedeployReportCommand}"
                                    IsEnabled="{Binding IsDeployingReport, Converter={StaticResource InverseBoolToBool}}" />
                        </Grid>

                        <!-- Liste des backups disponibles avec bouton Revert par ligne -->
                        <TextBlock Text="{x:Static loc:Strings.SettingsReportBackups}"
                                   FontWeight="Bold" FontSize="11"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   Margin="0,16,0,6" />
                        <TextBlock Text="{x:Static loc:Strings.SettingsReportNoBackups}"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   FontSize="12" FontStyle="Italic"
                                   Visibility="{Binding HasReportBackups, Converter={StaticResource InverseBoolToVisibility}}" />
                        <ItemsControl ItemsSource="{Binding ReportBackups}"
                                      Visibility="{Binding HasReportBackups, Converter={StaticResource BoolToVisibility}}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Border Background="#1A1A20"
                                            BorderBrush="{StaticResource Brush.Border}" BorderThickness="1"
                                            CornerRadius="4" Padding="10,8" Margin="0,0,0,4">
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="*" />
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition Width="Auto" />
                                            </Grid.ColumnDefinitions>
                                            <StackPanel Grid.Column="0" VerticalAlignment="Center">
                                                <TextBlock Text="{Binding DateDisplay}"
                                                           Foreground="{StaticResource Brush.Text.Primary}"
                                                           FontSize="13" FontWeight="SemiBold" />
                                                <TextBlock Text="{Binding SizeDisplay}"
                                                           Foreground="{StaticResource Brush.Text.Secondary}"
                                                           FontSize="11" />
                                            </StackPanel>
                                            <TextBlock Grid.Column="1"
                                                       Text="{Binding FolderName}"
                                                       FontFamily="Consolas" FontSize="10"
                                                       Foreground="{StaticResource Brush.Text.Secondary}"
                                                       VerticalAlignment="Center" Margin="0,0,12,0" />
                                            <Button Grid.Column="2"
                                                    Style="{StaticResource SecondaryButton}"
                                                    Content="{x:Static loc:Strings.SettingsReportRevert}"
                                                    Command="{Binding RevertCommand}"
                                                    Padding="12,6" />
                                        </Grid>
                                    </Border>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </StackPanel>
                </Border>

                <!-- API PHP de stats (XAMPP htdocs deploy, mirror of Report/Doc) -->
                <Border Background="{StaticResource Brush.Bg.Card}"
                        BorderBrush="{StaticResource Brush.Border}" BorderThickness="1"
                        CornerRadius="6" Padding="20" Margin="0,0,0,16">
                    <StackPanel>
                        <TextBlock Text="{x:Static loc:Strings.SettingsApiTool}"
                                   FontSize="11" FontWeight="Bold"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   Margin="0,0,0,8" />

                        <TextBlock Text="{x:Static loc:Strings.SettingsReportHtdocs}"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   FontSize="12" Margin="0,0,0,4" />
                        <TextBox Text="{Binding ApiHtdocsRoot, UpdateSourceTrigger=PropertyChanged}"
                                 Background="#1A1A20" Foreground="{StaticResource Brush.Text.Primary}"
                                 BorderBrush="{StaticResource Brush.Border}" BorderThickness="1" Padding="8"
                                 FontFamily="Consolas" />

                        <TextBlock Text="{x:Static loc:Strings.SettingsReportFolder}"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   FontSize="12" Margin="0,12,0,4" />
                        <TextBox Text="{Binding ApiFolderName, UpdateSourceTrigger=PropertyChanged}"
                                 Background="#1A1A20" Foreground="{StaticResource Brush.Text.Primary}"
                                 BorderBrush="{StaticResource Brush.Border}" BorderThickness="1" Padding="8"
                                 FontFamily="Consolas" />

                        <CheckBox IsChecked="{Binding ApiAutoDeploy}"
                                  Margin="0,12,0,0"
                                  Foreground="{StaticResource Brush.Text.Primary}"
                                  Content="{x:Static loc:Strings.SettingsApiAutoDeploy}" />

                        <Grid Margin="0,12,0,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="80" />
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="0"
                                       Text="{x:Static loc:Strings.SettingsApiMaxBackups}"
                                       Foreground="{StaticResource Brush.Text.Secondary}"
                                       FontSize="12" VerticalAlignment="Center" />
                            <TextBox Grid.Column="1"
                                     Text="{Binding ApiMaxBackups, UpdateSourceTrigger=PropertyChanged}"
                                     Background="#1A1A20" Foreground="{StaticResource Brush.Text.Primary}"
                                     BorderBrush="{StaticResource Brush.Border}" BorderThickness="1" Padding="8" />
                        </Grid>

                        <Grid Margin="0,12,0,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="0"
                                       Text="{Binding ApiDeployStatus}"
                                       Foreground="{StaticResource Brush.Text.Secondary}"
                                       FontSize="12" VerticalAlignment="Center"
                                       TextWrapping="Wrap" />
                            <Button Grid.Column="1"
                                    Style="{StaticResource SecondaryButton}"
                                    Content="{x:Static loc:Strings.SettingsApiRedeploy}"
                                    Command="{Binding RedeployApiCommand}"
                                    IsEnabled="{Binding IsDeployingApi, Converter={StaticResource InverseBoolToBool}}" />
                        </Grid>

                        <TextBlock Text="{x:Static loc:Strings.SettingsApiBackups}"
                                   FontWeight="Bold" FontSize="11"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   Margin="0,16,0,6" />
                        <TextBlock Text="{x:Static loc:Strings.SettingsReportNoBackups}"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   FontSize="12" FontStyle="Italic"
                                   Visibility="{Binding HasApiBackups, Converter={StaticResource InverseBoolToVisibility}}" />
                        <ItemsControl ItemsSource="{Binding ApiBackups}"
                                      Visibility="{Binding HasApiBackups, Converter={StaticResource BoolToVisibility}}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Border Background="#1A1A20"
                                            BorderBrush="{StaticResource Brush.Border}" BorderThickness="1"
                                            CornerRadius="4" Padding="10,8" Margin="0,0,0,4">
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="*" />
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition Width="Auto" />
                                            </Grid.ColumnDefinitions>
                                            <StackPanel Grid.Column="0" VerticalAlignment="Center">
                                                <TextBlock Text="{Binding DateDisplay}"
                                                           Foreground="{StaticResource Brush.Text.Primary}"
                                                           FontSize="13" FontWeight="SemiBold" />
                                                <TextBlock Text="{Binding SizeDisplay}"
                                                           Foreground="{StaticResource Brush.Text.Secondary}"
                                                           FontSize="11" />
                                            </StackPanel>
                                            <TextBlock Grid.Column="1"
                                                       Text="{Binding FolderName}"
                                                       FontFamily="Consolas" FontSize="10"
                                                       Foreground="{StaticResource Brush.Text.Secondary}"
                                                       VerticalAlignment="Center" Margin="0,0,12,0" />
                                            <Button Grid.Column="2"
                                                    Style="{StaticResource SecondaryButton}"
                                                    Content="{x:Static loc:Strings.SettingsReportRevert}"
                                                    Command="{Binding RevertCommand}"
                                                    Padding="12,6" />
                                        </Grid>
                                    </Border>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </StackPanel>
                </Border>

                <!-- SteamVR : merge _steamvr/steamvr.vrsettings → fichier user à l'install -->
                <Border Background="{StaticResource Brush.Bg.Card}"
                        BorderBrush="{StaticResource Brush.Border}" BorderThickness="1"
                        CornerRadius="6" Padding="20" Margin="0,0,0,16">
                    <StackPanel>
                        <TextBlock Text="{x:Static loc:Strings.SettingsSteamVr}"
                                   FontSize="11" FontWeight="Bold"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   Margin="0,0,0,8" />

                        <CheckBox IsChecked="{Binding SteamVrAutoMerge}"
                                  Margin="0,4,0,0"
                                  Foreground="{StaticResource Brush.Text.Primary}"
                                  Content="{x:Static loc:Strings.SettingsSteamVrAutoMerge}" />

                        <TextBlock Text="{x:Static loc:Strings.SettingsSteamVrSettingsPath}"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   FontSize="12" Margin="0,16,0,4" TextWrapping="Wrap" />
                        <TextBox Text="{Binding SteamVrSettingsPathOverride, UpdateSourceTrigger=PropertyChanged}"
                                 Background="#1A1A20" Foreground="{StaticResource Brush.Text.Primary}"
                                 BorderBrush="{StaticResource Brush.Border}" BorderThickness="1" Padding="8"
                                 FontFamily="Consolas" />
                        <!-- Affiche le path canonique attendu si Steam est à l'emplacement
                             par défaut. Évite à l'opérateur d'avoir à chercher dans la doc. -->
                        <TextBlock FontSize="11" FontStyle="Italic"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   Margin="0,4,0,0"
                                   TextWrapping="Wrap">
                            <Run Text="Auto-détection standard : " />
                            <Run Text="{Binding SteamVrCanonicalPath, Mode=OneWay}"
                                 FontFamily="Consolas" />
                        </TextBlock>

                        <TextBlock Text="{x:Static loc:Strings.SettingsSteamVrProcesses}"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   FontSize="12" Margin="0,16,0,4" TextWrapping="Wrap" />
                        <TextBox Text="{Binding SteamVrProcessesToKill, UpdateSourceTrigger=PropertyChanged}"
                                 Background="#1A1A20" Foreground="{StaticResource Brush.Text.Primary}"
                                 BorderBrush="{StaticResource Brush.Border}" BorderThickness="1" Padding="8"
                                 FontFamily="Consolas"
                                 AcceptsReturn="True" TextWrapping="Wrap"
                                 MinHeight="120" MaxHeight="200"
                                 VerticalScrollBarVisibility="Auto" />
                    </StackPanel>
                </Border>

                <!-- Mode auto : auto-launch + auto-relaunch d'une version désignée -->
                <Border Background="{StaticResource Brush.Bg.Card}"
                        BorderBrush="{StaticResource Brush.Border}" BorderThickness="1"
                        CornerRadius="6" Padding="20" Margin="0,0,0,16">
                    <StackPanel>
                        <TextBlock Text="{x:Static loc:Strings.SettingsAutoMode}"
                                   FontSize="11" FontWeight="Bold"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   Margin="0,0,0,8" />

                        <CheckBox IsChecked="{Binding AutoModeFeatureEnabled}"
                                  Margin="0,4,0,0"
                                  Foreground="{StaticResource Brush.Text.Primary}"
                                  Content="{x:Static loc:Strings.SettingsAutoModeFeatureEnabled}" />

                        <CheckBox IsChecked="{Binding AutoModeWaitForHealthChecks}"
                                  Margin="0,8,0,0"
                                  Foreground="{StaticResource Brush.Text.Primary}"
                                  Content="{x:Static loc:Strings.SettingsAutoModeWaitForHealth}" />

                        <Grid Margin="0,12,0,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="100" />
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="0"
                                       Text="{x:Static loc:Strings.SettingsAutoModeGrace}"
                                       Foreground="{StaticResource Brush.Text.Secondary}"
                                       FontSize="12" VerticalAlignment="Center" />
                            <TextBox Grid.Column="1"
                                     Text="{Binding AutoModeGraceSeconds, UpdateSourceTrigger=PropertyChanged}"
                                     Background="#1A1A20" Foreground="{StaticResource Brush.Text.Primary}"
                                     BorderBrush="{StaticResource Brush.Border}" BorderThickness="1" Padding="8" />
                        </Grid>

                        <TextBlock Margin="0,12,0,4"
                                   Text="{Binding AutoModeSelectedVersion, StringFormat='Version désignée actuelle : v{0}', FallbackValue='Aucune version désignée'}"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   FontSize="12" FontStyle="Italic" />

                        <TextBlock Text="{x:Static loc:Strings.SettingsAutoModeArgs}"
                                   FontWeight="Bold" FontSize="11"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   Margin="0,16,0,6" TextWrapping="Wrap" />

                        <!-- Liste éditable d'arguments. Chaque ligne : Key + Value (optionnel) + Remove. -->
                        <ItemsControl ItemsSource="{Binding AutoModeArgs}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Grid Margin="0,0,0,4">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="Auto" />
                                        </Grid.ColumnDefinitions>
                                        <TextBox Grid.Column="0"
                                                 Text="{Binding Key, UpdateSourceTrigger=PropertyChanged}"
                                                 Background="#1A1A20" Foreground="{StaticResource Brush.Text.Primary}"
                                                 BorderBrush="{StaticResource Brush.Border}" BorderThickness="1" Padding="8"
                                                 FontFamily="Consolas"
                                                 Tag="{x:Static loc:Strings.SettingsAutoModeArgKey}"
                                                 ToolTip="{x:Static loc:Strings.SettingsAutoModeArgKey}" />
                                        <TextBox Grid.Column="1"
                                                 Text="{Binding Value, UpdateSourceTrigger=PropertyChanged}"
                                                 Background="#1A1A20" Foreground="{StaticResource Brush.Text.Primary}"
                                                 BorderBrush="{StaticResource Brush.Border}" BorderThickness="1" Padding="8"
                                                 FontFamily="Consolas"
                                                 Margin="6,0,6,0"
                                                 Tag="{x:Static loc:Strings.SettingsAutoModeArgValue}"
                                                 ToolTip="{x:Static loc:Strings.SettingsAutoModeArgValue}" />
                                        <Button Grid.Column="2"
                                                Style="{StaticResource SecondaryButton}"
                                                Content="{x:Static loc:Strings.SettingsAutoModeArgRemove}"
                                                Command="{Binding RemoveCommand}"
                                                Padding="10,6" />
                                    </Grid>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>

                        <Button Style="{StaticResource SecondaryButton}"
                                Content="{x:Static loc:Strings.SettingsAutoModeArgAdd}"
                                Command="{Binding AddAutoModeArgCommand}"
                                HorizontalAlignment="Left"
                                Margin="0,4,0,0" Padding="12,6" />
                    </StackPanel>
                </Border>

                <!-- Cache LAN P2P (peers du LAN partagent les ZIPs entre eux) -->
                <Border Background="{StaticResource Brush.Bg.Card}"
                        BorderBrush="{StaticResource Brush.Border}" BorderThickness="1"
                        CornerRadius="6" Padding="20" Margin="0,0,0,16">
                    <StackPanel>
                        <TextBlock Text="{x:Static loc:Strings.SettingsLanCache}"
                                   FontSize="11" FontWeight="Bold"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   Margin="0,0,0,8" />

                        <CheckBox IsChecked="{Binding LanServerEnabled}"
                                  Margin="0,4,0,0"
                                  Foreground="{StaticResource Brush.Text.Primary}"
                                  Content="{x:Static loc:Strings.SettingsLanCacheServerEnabled}" />
                        <CheckBox IsChecked="{Binding LanClientEnabled}"
                                  Margin="0,4,0,0"
                                  Foreground="{StaticResource Brush.Text.Primary}"
                                  Content="{x:Static loc:Strings.SettingsLanCacheClientEnabled}" />

                        <Grid Margin="0,12,0,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="100" />
                                <ColumnDefinition Width="12" />
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="100" />
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="0"
                                       Text="{x:Static loc:Strings.SettingsLanCacheServerPort}"
                                       Foreground="{StaticResource Brush.Text.Secondary}"
                                       FontSize="12" VerticalAlignment="Center" />
                            <TextBox Grid.Column="1"
                                     Text="{Binding LanServerPort, UpdateSourceTrigger=PropertyChanged}"
                                     Background="#1A1A20" Foreground="{StaticResource Brush.Text.Primary}"
                                     BorderBrush="{StaticResource Brush.Border}" BorderThickness="1" Padding="8" />
                            <TextBlock Grid.Column="3"
                                       Text="{x:Static loc:Strings.SettingsLanCacheDiscoveryPort}"
                                       Foreground="{StaticResource Brush.Text.Secondary}"
                                       FontSize="12" VerticalAlignment="Center" />
                            <TextBox Grid.Column="4"
                                     Text="{Binding LanDiscoveryPort, UpdateSourceTrigger=PropertyChanged}"
                                     Background="#1A1A20" Foreground="{StaticResource Brush.Text.Primary}"
                                     BorderBrush="{StaticResource Brush.Border}" BorderThickness="1" Padding="8" />
                        </Grid>

                        <Grid Margin="0,8,0,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="100" />
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="0"
                                       Text="{x:Static loc:Strings.SettingsLanCacheMaxCached}"
                                       Foreground="{StaticResource Brush.Text.Secondary}"
                                       FontSize="12" VerticalAlignment="Center" />
                            <TextBox Grid.Column="1"
                                     Text="{Binding LanMaxCachedVersions, UpdateSourceTrigger=PropertyChanged}"
                                     Background="#1A1A20" Foreground="{StaticResource Brush.Text.Primary}"
                                     BorderBrush="{StaticResource Brush.Border}" BorderThickness="1" Padding="8" />
                        </Grid>

                        <!-- Status serveur (read-only, alimenté par RefreshLanStatus) -->
                        <Grid Margin="0,12,0,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="0"
                                       Text="{Binding LanServerStatus}"
                                       Foreground="{StaticResource Brush.Text.Secondary}"
                                       FontSize="12" VerticalAlignment="Center"
                                       TextWrapping="Wrap" />
                            <Button Grid.Column="1"
                                    Style="{StaticResource SecondaryButton}"
                                    Content="↻"
                                    Command="{Binding RefreshLanStatusCommand}"
                                    ToolTip="Actualiser le statut + la liste des peers"
                                    Padding="12,6" />
                        </Grid>

                        <!-- Peers découverts auto (read-only) -->
                        <TextBlock Text="{x:Static loc:Strings.SettingsLanCacheDiscoveredPeers}"
                                   FontWeight="Bold" FontSize="11"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   Margin="0,16,0,6" />
                        <TextBlock Text="{x:Static loc:Strings.SettingsLanCacheNoDiscovered}"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   FontSize="12" FontStyle="Italic"
                                   Visibility="{Binding HasLanDiscoveredPeers, Converter={StaticResource InverseBoolToVisibility}}" />
                        <ItemsControl ItemsSource="{Binding LanDiscoveredPeers}"
                                      Visibility="{Binding HasLanDiscoveredPeers, Converter={StaticResource BoolToVisibility}}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Border Background="#1A1A20"
                                            BorderBrush="{StaticResource Brush.Border}" BorderThickness="1"
                                            CornerRadius="4" Padding="10,6" Margin="0,0,0,4">
                                        <TextBlock Text="{Binding}"
                                                   Foreground="{StaticResource Brush.Text.Primary}"
                                                   FontFamily="Consolas" FontSize="11" />
                                    </Border>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>

                        <!-- Peers manuels (1 URL par ligne, multiline TextBox) -->
                        <TextBlock Text="{x:Static loc:Strings.SettingsLanCacheManualPeers}"
                                   FontWeight="Bold" FontSize="11"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   Margin="0,16,0,6" />
                        <TextBox Text="{Binding LanManualPeers, UpdateSourceTrigger=PropertyChanged}"
                                 Background="#1A1A20" Foreground="{StaticResource Brush.Text.Primary}"
                                 BorderBrush="{StaticResource Brush.Border}" BorderThickness="1" Padding="8"
                                 FontFamily="Consolas" FontSize="11"
                                 AcceptsReturn="True"
                                 TextWrapping="NoWrap"
                                 VerticalScrollBarVisibility="Auto"
                                 MinHeight="60" />
                    </StackPanel>
                </Border>

                <!-- Outil Doc (XAMPP htdocs deploy, mirror of Report) -->
                <Border Background="{StaticResource Brush.Bg.Card}"
                        BorderBrush="{StaticResource Brush.Border}" BorderThickness="1"
                        CornerRadius="6" Padding="20" Margin="0,0,0,16">
                    <StackPanel>
                        <TextBlock Text="{x:Static loc:Strings.SettingsDocTool}"
                                   FontSize="11" FontWeight="Bold"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   Margin="0,0,0,8" />

                        <TextBlock Text="{x:Static loc:Strings.SettingsReportHtdocs}"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   FontSize="12" Margin="0,0,0,4" />
                        <TextBox Text="{Binding DocHtdocsRoot, UpdateSourceTrigger=PropertyChanged}"
                                 Background="#1A1A20" Foreground="{StaticResource Brush.Text.Primary}"
                                 BorderBrush="{StaticResource Brush.Border}" BorderThickness="1" Padding="8"
                                 FontFamily="Consolas" />

                        <TextBlock Text="{x:Static loc:Strings.SettingsReportFolder}"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   FontSize="12" Margin="0,12,0,4" />
                        <TextBox Text="{Binding DocFolderName, UpdateSourceTrigger=PropertyChanged}"
                                 Background="#1A1A20" Foreground="{StaticResource Brush.Text.Primary}"
                                 BorderBrush="{StaticResource Brush.Border}" BorderThickness="1" Padding="8"
                                 FontFamily="Consolas" />

                        <CheckBox IsChecked="{Binding DocAutoDeploy}"
                                  Margin="0,12,0,0"
                                  Foreground="{StaticResource Brush.Text.Primary}"
                                  Content="{x:Static loc:Strings.SettingsDocAutoDeploy}" />

                        <Grid Margin="0,12,0,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="80" />
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="0"
                                       Text="{x:Static loc:Strings.SettingsDocMaxBackups}"
                                       Foreground="{StaticResource Brush.Text.Secondary}"
                                       FontSize="12" VerticalAlignment="Center" />
                            <TextBox Grid.Column="1"
                                     Text="{Binding DocMaxBackups, UpdateSourceTrigger=PropertyChanged}"
                                     Background="#1A1A20" Foreground="{StaticResource Brush.Text.Primary}"
                                     BorderBrush="{StaticResource Brush.Border}" BorderThickness="1" Padding="8" />
                        </Grid>

                        <Grid Margin="0,12,0,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="0"
                                       Text="{Binding DocDeployStatus}"
                                       Foreground="{StaticResource Brush.Text.Secondary}"
                                       FontSize="12" VerticalAlignment="Center"
                                       TextWrapping="Wrap" />
                            <Button Grid.Column="1"
                                    Style="{StaticResource SecondaryButton}"
                                    Content="{x:Static loc:Strings.SettingsDocRedeploy}"
                                    Command="{Binding RedeployDocCommand}"
                                    IsEnabled="{Binding IsDeployingDoc, Converter={StaticResource InverseBoolToBool}}" />
                        </Grid>

                        <TextBlock Text="{x:Static loc:Strings.SettingsDocBackups}"
                                   FontWeight="Bold" FontSize="11"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   Margin="0,16,0,6" />
                        <TextBlock Text="{x:Static loc:Strings.SettingsReportNoBackups}"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   FontSize="12" FontStyle="Italic"
                                   Visibility="{Binding HasDocBackups, Converter={StaticResource InverseBoolToVisibility}}" />
                        <ItemsControl ItemsSource="{Binding DocBackups}"
                                      Visibility="{Binding HasDocBackups, Converter={StaticResource BoolToVisibility}}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Border Background="#1A1A20"
                                            BorderBrush="{StaticResource Brush.Border}" BorderThickness="1"
                                            CornerRadius="4" Padding="10,8" Margin="0,0,0,4">
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="*" />
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition Width="Auto" />
                                            </Grid.ColumnDefinitions>
                                            <StackPanel Grid.Column="0" VerticalAlignment="Center">
                                                <TextBlock Text="{Binding DateDisplay}"
                                                           Foreground="{StaticResource Brush.Text.Primary}"
                                                           FontSize="13" FontWeight="SemiBold" />
                                                <TextBlock Text="{Binding SizeDisplay}"
                                                           Foreground="{StaticResource Brush.Text.Secondary}"
                                                           FontSize="11" />
                                            </StackPanel>
                                            <TextBlock Grid.Column="1"
                                                       Text="{Binding FolderName}"
                                                       FontFamily="Consolas" FontSize="10"
                                                       Foreground="{StaticResource Brush.Text.Secondary}"
                                                       VerticalAlignment="Center" Margin="0,0,12,0" />
                                            <Button Grid.Column="2"
                                                    Style="{StaticResource SecondaryButton}"
                                                    Content="{x:Static loc:Strings.SettingsReportRevert}"
                                                    Command="{Binding RevertCommand}"
                                                    Padding="12,6" />
                                        </Grid>
                                    </Border>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </StackPanel>
                </Border>

                <!-- Bandeau de santé système : liste éditable des checks -->
                <Border Background="{StaticResource Brush.Bg.Card}"
                        BorderBrush="{StaticResource Brush.Border}" BorderThickness="1"
                        CornerRadius="6" Padding="20" Margin="0,0,0,16">
                    <StackPanel>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="0"
                                       Text="{x:Static loc:Strings.SettingsHealthChecks}"
                                       FontSize="11" FontWeight="Bold"
                                       Foreground="{StaticResource Brush.Text.Secondary}"
                                       VerticalAlignment="Center" />
                            <Button Grid.Column="1"
                                    Style="{StaticResource SecondaryButton}"
                                    Content="{x:Static loc:Strings.SettingsHealthAdd}"
                                    Command="{Binding AddHealthCheckCommand}"
                                    Padding="12,6" />
                        </Grid>

                        <TextBlock Text="{x:Static loc:Strings.SettingsHealthChecksHint}"
                                   FontSize="11" FontStyle="Italic"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   Margin="0,8,0,8" TextWrapping="Wrap" />

                        <TextBlock Text="{x:Static loc:Strings.SettingsHealthEmpty}"
                                   FontSize="12" FontStyle="Italic"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   Margin="0,4,0,0" TextWrapping="Wrap"
                                   Visibility="{Binding HasHealthChecks, Converter={StaticResource InverseBoolToVisibility}}" />

                        <ItemsControl ItemsSource="{Binding HealthChecks}"
                                      Visibility="{Binding HasHealthChecks, Converter={StaticResource BoolToVisibility}}"
                                      Margin="0,4,0,0">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Border Background="#1A1A20"
                                            BorderBrush="{StaticResource Brush.Border}" BorderThickness="1"
                                            CornerRadius="4" Padding="10,8" Margin="0,0,0,4">
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition Width="*" />
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition Width="Auto" />
                                            </Grid.ColumnDefinitions>
                                            <TextBlock Grid.Column="0"
                                                       Text="{Binding DisplayIcon}"
                                                       FontSize="20"
                                                       VerticalAlignment="Center"
                                                       Margin="2,0,12,0" />
                                            <StackPanel Grid.Column="1" VerticalAlignment="Center">
                                                <TextBlock Text="{Binding DisplayName}"
                                                           Foreground="{StaticResource Brush.Text.Primary}"
                                                           FontSize="13" FontWeight="SemiBold" />
                                                <TextBlock Text="{Binding DisplayDetail}"
                                                           Foreground="{StaticResource Brush.Text.Secondary}"
                                                           FontSize="11"
                                                           FontFamily="Consolas" />
                                            </StackPanel>
                                            <!-- Boutons ▲/▼ pour réordonner. CanExecute géré côté
                                                 ViewModel : grisés sur le premier/dernier item. -->
                                            <Button Grid.Column="2"
                                                    Style="{StaticResource SecondaryButton}"
                                                    Content="▲"
                                                    Command="{Binding MoveUpCommand}"
                                                    ToolTip="Monter dans la liste"
                                                    Margin="0,0,4,0"
                                                    Padding="10,6" />
                                            <Button Grid.Column="3"
                                                    Style="{StaticResource SecondaryButton}"
                                                    Content="▼"
                                                    Command="{Binding MoveDownCommand}"
                                                    ToolTip="Descendre dans la liste"
                                                    Margin="0,0,12,0"
                                                    Padding="10,6" />
                                            <Button Grid.Column="4"
                                                    Style="{StaticResource SecondaryButton}"
                                                    Content="{x:Static loc:Strings.SettingsHealthEdit}"
                                                    Command="{Binding EditCommand}"
                                                    Margin="0,0,6,0"
                                                    Padding="12,6" />
                                            <Button Grid.Column="5"
                                                    Style="{StaticResource SecondaryButton}"
                                                    Content="{x:Static loc:Strings.SettingsHealthDelete}"
                                                    Command="{Binding DeleteCommand}"
                                                    Padding="12,6" />
                                        </Grid>
                                    </Border>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </StackPanel>
                </Border>

                <!-- Logs (path + open button) -->
                <Border Background="{StaticResource Brush.Bg.Card}"
                        BorderBrush="{StaticResource Brush.Border}" BorderThickness="1"
                        CornerRadius="6" Padding="20" Margin="0,0,0,16">
                    <StackPanel>
                        <TextBlock Text="{x:Static loc:Strings.SettingsLogs}"
                                   FontSize="11" FontWeight="Bold"
                                   Foreground="{StaticResource Brush.Text.Secondary}"
                                   Margin="0,0,0,8" />
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <StackPanel Grid.Column="0">
                                <TextBlock Text="{Binding LogsDirectory}"
                                           FontFamily="Consolas" FontSize="11"
                                           Foreground="{StaticResource Brush.Text.Primary}"
                                           TextTrimming="CharacterEllipsis" />
                                <TextBlock Text="{x:Static loc:Strings.SettingsCacheRotation}"
                                           FontSize="12"
                                           Foreground="{StaticResource Brush.Text.Secondary}"
                                           Margin="0,2,0,0" />
                            </StackPanel>
                            <Button Grid.Column="1" Margin="8,0,0,0"
                                    Style="{StaticResource SecondaryButton}"
                                    Content="{x:Static loc:Strings.OpenButton}"
                                    Command="{Binding OpenLogsFolderCommand}" />
                        </Grid>
                    </StackPanel>
                </Border>

                    </StackPanel>
                </Expander>

            </StackPanel>
        </ScrollViewer>

        <!-- Footer -->
        <Border Grid.Row="2" Background="{StaticResource Brush.Bg.Footer}"
                BorderBrush="{StaticResource Brush.Border}" BorderThickness="0,1,0,0"
                Padding="20,12">
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                <Button Style="{StaticResource SecondaryButton}"
                        Content="{x:Static loc:Strings.ActionCancel}"
                        IsCancel="True"
                        Margin="0,0,12,0"
                        Click="OnCancel" />
                <Button Style="{StaticResource AccentButton}"
                        Content="{x:Static loc:Strings.ActionSave}"
                        Padding="32,8"
                        IsDefault="True"
                        Click="OnSave" />
            </StackPanel>
        </Border>
    </Grid>
</Window>
