<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:sys="clr-namespace:System;assembly=mscorlib">

  <!-- Palette brushes are provided by LightPalette/DarkPalette dictionary. -->
  <!-- All brush lookups below use DynamicResource so swapping the palette applies live. -->

  <sys:Double x:Key="BaseFontSize">13</sys:Double>
  <FontFamily x:Key="BaseFont">Segoe UI</FontFamily>

  <!-- ====================================================== -->
  <!--  Window                                                  -->
  <!-- ====================================================== -->
  <Style TargetType="{x:Type Window}">
    <Setter Property="Background" Value="{DynamicResource AppBgBrush}" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="FontFamily" Value="{StaticResource BaseFont}" />
    <Setter Property="FontSize"   Value="{StaticResource BaseFontSize}" />
    <Setter Property="TextOptions.TextFormattingMode" Value="Ideal" />
    <Setter Property="TextOptions.TextRenderingMode"  Value="ClearType" />
    <Setter Property="UseLayoutRounding" Value="True" />
    <Setter Property="SnapsToDevicePixels" Value="True" />
  </Style>

  <!-- ====================================================== -->
  <!--  TextBlock / Label                                       -->
  <!-- ====================================================== -->
  <Style TargetType="{x:Type TextBlock}">
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="FontFamily" Value="{StaticResource BaseFont}" />
    <Setter Property="FontSize"   Value="{StaticResource BaseFontSize}" />
    <Setter Property="SnapsToDevicePixels" Value="True" />
  </Style>

  <Style TargetType="{x:Type Label}">
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="FontFamily" Value="{StaticResource BaseFont}" />
    <Setter Property="FontSize"   Value="{StaticResource BaseFontSize}" />
    <Setter Property="Padding"    Value="0,0,0,2" />
  </Style>

  <Style TargetType="{x:Type Separator}">
    <Setter Property="Background" Value="{DynamicResource BorderSoftBrush}" />
    <Setter Property="Height"     Value="1" />
    <Setter Property="Margin"     Value="0,6" />
  </Style>

  <!-- ====================================================== -->
  <!--  Button                                                  -->
  <!-- ====================================================== -->
  <Style x:Key="ThemeButtonStyle" TargetType="{x:Type Button}">
    <Setter Property="Background" Value="{DynamicResource SurfaceBrush}" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="BorderBrush" Value="{DynamicResource BorderStrongBrush}" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="Padding" Value="12,6" />
    <Setter Property="MinHeight" Value="28" />
    <Setter Property="Cursor" Value="Hand" />
    <Setter Property="FontFamily" Value="{StaticResource BaseFont}" />
    <Setter Property="FontSize"   Value="{StaticResource BaseFontSize}" />
    <Setter Property="HorizontalContentAlignment" Value="Center" />
    <Setter Property="VerticalContentAlignment"   Value="Center" />
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type Button}">
          <Border x:Name="Bd"
                  Background="{TemplateBinding Background}"
                  BorderBrush="{TemplateBinding BorderBrush}"
                  BorderThickness="{TemplateBinding BorderThickness}"
                  CornerRadius="6"
                  SnapsToDevicePixels="True"
                  TextElement.Foreground="{TemplateBinding Foreground}">
            <ContentPresenter x:Name="Cp"
                              Margin="{TemplateBinding Padding}"
                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                              TextElement.Foreground="{TemplateBinding Foreground}"
                              RecognizesAccessKey="True" />
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
              <Setter TargetName="Bd" Property="Background"  Value="{DynamicResource SurfaceAltBrush}" />
              <Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource AccentBrush}" />
            </Trigger>
            <Trigger Property="IsPressed" Value="True">
              <Setter TargetName="Bd" Property="Background" Value="{DynamicResource AccentSoftBrush}" />
            </Trigger>
            <Trigger Property="IsDefault" Value="True">
              <Setter TargetName="Bd" Property="Background"  Value="{DynamicResource AccentBrush}" />
              <Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource AccentBrush}" />
              <Setter Property="Foreground" Value="{DynamicResource AccentForegroundBrush}" />
            </Trigger>
            <MultiTrigger>
              <MultiTrigger.Conditions>
                <Condition Property="IsDefault"   Value="True" />
                <Condition Property="IsMouseOver" Value="True" />
              </MultiTrigger.Conditions>
              <Setter TargetName="Bd" Property="Background" Value="{DynamicResource AccentHoverBrush}" />
            </MultiTrigger>
            <Trigger Property="IsEnabled" Value="False">
              <Setter TargetName="Bd" Property="Background"  Value="{DynamicResource SurfaceAltBrush}" />
              <Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource BorderSoftBrush}" />
              <Setter Property="Foreground" Value="{DynamicResource TextMutedBrush}" />
              <Setter Property="Cursor" Value="Arrow" />
            </Trigger>
            <Trigger Property="IsKeyboardFocused" Value="True">
              <Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource AccentBrush}" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <!-- Implicit Button -->
  <Style TargetType="{x:Type Button}" BasedOn="{StaticResource ThemeButtonStyle}" />

  <!-- Keyed ToggleButton — lets inline styles BasedOn preserve theme while adding Content/Triggers. -->
  <Style x:Key="ThemeToggleButtonStyle" TargetType="{x:Type ToggleButton}">
    <Setter Property="Background" Value="{DynamicResource SurfaceBrush}" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="BorderBrush" Value="{DynamicResource BorderStrongBrush}" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="Padding" Value="12,6" />
    <Setter Property="MinHeight" Value="28" />
    <Setter Property="Cursor" Value="Hand" />
    <Setter Property="FontFamily" Value="{StaticResource BaseFont}" />
    <Setter Property="FontSize" Value="{StaticResource BaseFontSize}" />
    <Setter Property="HorizontalContentAlignment" Value="Center" />
    <Setter Property="VerticalContentAlignment" Value="Center" />
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ToggleButton}">
          <Border x:Name="Bd"
                  Background="{TemplateBinding Background}"
                  BorderBrush="{TemplateBinding BorderBrush}"
                  BorderThickness="{TemplateBinding BorderThickness}"
                  CornerRadius="6"
                  SnapsToDevicePixels="True">
            <ContentPresenter Margin="{TemplateBinding Padding}"
                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                              TextElement.Foreground="{TemplateBinding Foreground}"
                              RecognizesAccessKey="True" />
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
              <Setter TargetName="Bd" Property="Background" Value="{DynamicResource SurfaceAltBrush}" />
              <Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource AccentBrush}" />
            </Trigger>
            <Trigger Property="IsChecked" Value="True">
              <Setter TargetName="Bd" Property="Background" Value="{DynamicResource AccentBrush}" />
              <Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource AccentBrush}" />
              <Setter Property="Foreground" Value="{DynamicResource AccentForegroundBrush}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
              <Setter TargetName="Bd" Property="Background" Value="{DynamicResource SurfaceAltBrush}" />
              <Setter Property="Foreground" Value="{DynamicResource TextMutedBrush}" />
              <Setter Property="Cursor" Value="Arrow" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>
  <!-- Implicit ToggleButton via keyed style — inline view styles can BasedOn ThemeToggleButtonStyle to keep theme. -->
  <Style TargetType="{x:Type ToggleButton}" BasedOn="{StaticResource ThemeToggleButtonStyle}" />

  <!-- ToolBar uses its own keyed Button style — retarget so toolbar buttons also themed -->
  <Style x:Key="{x:Static ToolBar.ButtonStyleKey}" TargetType="{x:Type Button}" BasedOn="{StaticResource ThemeButtonStyle}" />
  <Style x:Key="{x:Static ToolBar.ToggleButtonStyleKey}" TargetType="{x:Type ToggleButton}" BasedOn="{StaticResource ThemeToggleButtonStyle}" />
  <Style x:Key="{x:Static ToolBar.SeparatorStyleKey}" TargetType="{x:Type Separator}">
    <Setter Property="Background" Value="{DynamicResource BorderSoftBrush}" />
    <Setter Property="Width" Value="1" />
    <Setter Property="Margin" Value="6,4" />
  </Style>

  <!-- ====================================================== -->
  <!--  TextBox / PasswordBox                                   -->
  <!-- ====================================================== -->
  <Style TargetType="{x:Type TextBox}">
    <Setter Property="Background" Value="{DynamicResource SurfaceBrush}" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="BorderBrush" Value="{DynamicResource BorderStrongBrush}" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="Padding" Value="4,2" />
    <Setter Property="MinHeight" Value="24" />
    <Setter Property="FontFamily" Value="{StaticResource BaseFont}" />
    <Setter Property="FontSize"   Value="{StaticResource BaseFontSize}" />
    <Setter Property="SelectionBrush" Value="{DynamicResource SelectionBrush}" />
    <Setter Property="CaretBrush" Value="{DynamicResource AccentBrush}" />
    <Setter Property="VerticalContentAlignment" Value="Center" />
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type TextBox}">
          <Border x:Name="Bd"
                  Background="{TemplateBinding Background}"
                  BorderBrush="{TemplateBinding BorderBrush}"
                  BorderThickness="{TemplateBinding BorderThickness}"
                  CornerRadius="5"
                  SnapsToDevicePixels="True">
            <ScrollViewer x:Name="PART_ContentHost"
                          Margin="{TemplateBinding Padding}"
                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                          Background="Transparent"
                          BorderThickness="0" />
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
              <Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource AccentBrush}" />
            </Trigger>
            <Trigger Property="IsKeyboardFocused" Value="True">
              <Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource AccentBrush}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
              <Setter TargetName="Bd" Property="Background"  Value="{DynamicResource SurfaceAltBrush}" />
              <Setter Property="Foreground" Value="{DynamicResource TextMutedBrush}" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <!-- TextBox inside ToolBar must be re-keyed too -->
  <Style x:Key="{x:Static ToolBar.TextBoxStyleKey}" TargetType="{x:Type TextBox}">
    <Setter Property="Background" Value="{DynamicResource SurfaceBrush}" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="BorderBrush" Value="{DynamicResource BorderStrongBrush}" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="Padding" Value="6,4" />
    <Setter Property="MinHeight" Value="26" />
    <Setter Property="CaretBrush" Value="{DynamicResource AccentBrush}" />
  </Style>

  <!-- DatePicker + inner DatePickerTextBox + Calendar popup -->
  <Style TargetType="{x:Type DatePicker}">
    <Setter Property="Background" Value="{DynamicResource SurfaceBrush}" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="BorderBrush" Value="{DynamicResource BorderStrongBrush}" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="Padding" Value="4,2" />
    <Setter Property="MinHeight" Value="24" />
    <Setter Property="FontFamily" Value="{StaticResource BaseFont}" />
    <Setter Property="FontSize"   Value="{StaticResource BaseFontSize}" />
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="CalendarStyle" Value="{DynamicResource ModernCalendarStyle}" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type DatePicker}">
          <Border Background="{TemplateBinding Background}"
                  BorderBrush="{TemplateBinding BorderBrush}"
                  BorderThickness="{TemplateBinding BorderThickness}"
                  CornerRadius="3"
                  SnapsToDevicePixels="True">
            <Grid>
              <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
              </Grid.ColumnDefinitions>
              <DatePickerTextBox x:Name="PART_TextBox"
                                 Grid.Column="0"
                                 Focusable="{TemplateBinding Focusable}"
                                 Foreground="{TemplateBinding Foreground}"
                                 Background="Transparent"
                                 VerticalContentAlignment="Center"
                                 Padding="{TemplateBinding Padding}" />
              <Button x:Name="PART_Button"
                      Grid.Column="1"
                      Focusable="False"
                      Width="24"
                      Background="Transparent"
                      BorderBrush="Transparent"
                      Foreground="{TemplateBinding Foreground}"
                      Cursor="Hand">
                <Button.Template>
                  <ControlTemplate TargetType="{x:Type Button}">
                    <Border x:Name="Bd" Background="{TemplateBinding Background}" CornerRadius="3">
                      <TextBlock Text="&#x1F4C5;"
                                 Foreground="{TemplateBinding Foreground}"
                                 HorizontalAlignment="Center"
                                 VerticalAlignment="Center"
                                 FontSize="12" />
                    </Border>
                    <ControlTemplate.Triggers>
                      <Trigger Property="IsMouseOver" Value="True">
                        <Setter TargetName="Bd" Property="Background" Value="{DynamicResource SurfaceAltBrush}" />
                      </Trigger>
                    </ControlTemplate.Triggers>
                  </ControlTemplate>
                </Button.Template>
              </Button>
              <Popup x:Name="PART_Popup"
                     Grid.Column="0" Grid.ColumnSpan="2"
                     StaysOpen="False"
                     AllowsTransparency="True"
                     Placement="Bottom"
                     PlacementTarget="{Binding ElementName=PART_TextBox}">
                <Border Background="{DynamicResource SurfaceBrush}"
                        BorderBrush="{DynamicResource BorderStrongBrush}"
                        BorderThickness="1"
                        CornerRadius="4"
                        Padding="4">
                  <Calendar x:Name="PART_Calendar"
                            Background="{DynamicResource SurfaceBrush}"
                            Foreground="{DynamicResource TextBrush}"
                            BorderBrush="{DynamicResource BorderStrongBrush}" />
                </Border>
              </Popup>
            </Grid>
          </Border>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style TargetType="{x:Type DatePickerTextBox}">
    <Setter Property="Background" Value="{DynamicResource SurfaceBrush}" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="CaretBrush" Value="{DynamicResource AccentBrush}" />
    <Setter Property="SelectionBrush" Value="{DynamicResource SelectionBrush}" />
    <Setter Property="BorderThickness" Value="0" />
    <Setter Property="Padding" Value="0" />
    <Setter Property="VerticalContentAlignment" Value="Center" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type DatePickerTextBox}">
          <Grid>
            <Border Background="{TemplateBinding Background}" />
            <ScrollViewer x:Name="PART_ContentHost"
                          Padding="{TemplateBinding Padding}"
                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                          Background="Transparent"
                          BorderThickness="0"
                          Focusable="False"
                          HorizontalScrollBarVisibility="Hidden"
                          VerticalScrollBarVisibility="Hidden" />
          </Grid>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="ModernCalendarStyle" TargetType="{x:Type Calendar}">
    <Setter Property="Background" Value="{DynamicResource SurfaceBrush}" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="BorderBrush" Value="{DynamicResource BorderStrongBrush}" />
    <!-- Override default template so CalendarItem is instantiated WITHOUT an explicit Aero style —
         letting my implicit CalendarItem style apply. -->
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type Calendar}">
          <StackPanel x:Name="PART_Root" HorizontalAlignment="Center">
            <CalendarItem x:Name="PART_CalendarItem"
                          Background="{TemplateBinding Background}"
                          BorderBrush="{TemplateBinding BorderBrush}"
                          BorderThickness="{TemplateBinding BorderThickness}"
                          Foreground="{TemplateBinding Foreground}" />
          </StackPanel>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style TargetType="{x:Type Calendar}" BasedOn="{StaticResource ModernCalendarStyle}" />

  <!-- Override default DatePicker calendar popup style (Aero2 ships light-themed version) -->
  <Style x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type DatePicker}, ResourceId=DatePickerCalendarStyle}"
         TargetType="{x:Type Calendar}"
         BasedOn="{StaticResource ModernCalendarStyle}" />

  <Style x:Key="CalendarNavButtonStyle" TargetType="{x:Type Button}">
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="BorderBrush" Value="Transparent" />
    <Setter Property="Cursor" Value="Hand" />
    <Setter Property="MinHeight" Value="28" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type Button}">
          <Border x:Name="Bd" Background="{TemplateBinding Background}"
                  CornerRadius="3" Padding="4">
            <TextBlock x:Name="NavText"
                       Text="{TemplateBinding Content}"
                       Foreground="{TemplateBinding Foreground}"
                       FontFamily="{TemplateBinding FontFamily}"
                       FontSize="{TemplateBinding FontSize}"
                       FontWeight="{TemplateBinding FontWeight}"
                       HorizontalAlignment="Center"
                       VerticalAlignment="Center" />
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
              <Setter TargetName="Bd" Property="Background" Value="{DynamicResource SurfaceAltBrush}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
              <Setter TargetName="NavText" Property="Foreground" Value="{DynamicResource TextMutedBrush}" />
              <Setter TargetName="NavText" Property="Opacity" Value="0.5" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style TargetType="{x:Type CalendarItem}">
    <Setter Property="Background" Value="{DynamicResource SurfaceBrush}" />
    <Setter Property="BorderBrush" Value="{DynamicResource BorderSoftBrush}" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type CalendarItem}">
          <ControlTemplate.Resources>
            <DataTemplate x:Key="{x:Static CalendarItem.DayTitleTemplateResourceKey}">
              <TextBlock Text="{Binding}" FontSize="10" FontWeight="SemiBold"
                         Foreground="{DynamicResource TextMutedBrush}"
                         HorizontalAlignment="Center" VerticalAlignment="Center"
                         Margin="0,4,0,4" />
            </DataTemplate>
          </ControlTemplate.Resources>
          <Border Background="{TemplateBinding Background}"
                  BorderBrush="{TemplateBinding BorderBrush}"
                  BorderThickness="0"
                  CornerRadius="5"
                  Padding="4">
            <Grid>
              <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
              </Grid.RowDefinitions>

              <!-- Header: prev / label / next -->
              <Grid Grid.Row="0">
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="Auto" />
                  <ColumnDefinition Width="*" />
                  <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <Button x:Name="PART_PreviousButton"
                        Grid.Column="0"
                        Style="{StaticResource CalendarNavButtonStyle}"
                        Content="&#x2039;"
                        FontSize="14" FontWeight="Bold" />
                <Button x:Name="PART_HeaderButton"
                        Grid.Column="1"
                        Style="{StaticResource CalendarNavButtonStyle}"
                        FontSize="13" FontWeight="SemiBold"
                        HorizontalContentAlignment="Center" />
                <Button x:Name="PART_NextButton"
                        Grid.Column="2"
                        Style="{StaticResource CalendarNavButtonStyle}"
                        Content="&#x203A;"
                        FontSize="14" FontWeight="Bold" />
              </Grid>

              <!-- Month view: 7-column grid of day buttons -->
              <Grid x:Name="PART_MonthView" Grid.Row="1"
                    HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                    Margin="0,4,0,0">
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="*" />
                  <ColumnDefinition Width="*" />
                  <ColumnDefinition Width="*" />
                  <ColumnDefinition Width="*" />
                  <ColumnDefinition Width="*" />
                  <ColumnDefinition Width="*" />
                  <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="*" />
                  <RowDefinition Height="*" />
                  <RowDefinition Height="*" />
                  <RowDefinition Height="*" />
                  <RowDefinition Height="*" />
                  <RowDefinition Height="*" />
                </Grid.RowDefinitions>
              </Grid>

              <!-- Year/Decade view: 4x3 grid of month/year buttons -->
              <Grid x:Name="PART_YearView" Grid.Row="1"
                    HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                    Visibility="Hidden" Margin="0,4,0,0">
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="*" />
                  <ColumnDefinition Width="*" />
                  <ColumnDefinition Width="*" />
                  <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                  <RowDefinition Height="*" />
                  <RowDefinition Height="*" />
                  <RowDefinition Height="*" />
                </Grid.RowDefinitions>
              </Grid>
            </Grid>
          </Border>
          <ControlTemplate.Triggers>
            <DataTrigger Binding="{Binding DisplayMode, RelativeSource={RelativeSource AncestorType={x:Type Calendar}}}" Value="Year">
              <Setter TargetName="PART_MonthView" Property="Visibility" Value="Hidden" />
              <Setter TargetName="PART_YearView"  Property="Visibility" Value="Visible" />
            </DataTrigger>
            <DataTrigger Binding="{Binding DisplayMode, RelativeSource={RelativeSource AncestorType={x:Type Calendar}}}" Value="Decade">
              <Setter TargetName="PART_MonthView" Property="Visibility" Value="Hidden" />
              <Setter TargetName="PART_YearView"  Property="Visibility" Value="Visible" />
            </DataTrigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style TargetType="{x:Type CalendarDayButton}">
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="BorderBrush" Value="Transparent" />
    <Setter Property="FontFamily" Value="{StaticResource BaseFont}" />
    <Setter Property="FontSize" Value="12" />
    <Setter Property="MinWidth" Value="24" />
    <Setter Property="MinHeight" Value="24" />
    <Setter Property="HorizontalContentAlignment" Value="Center" />
    <Setter Property="VerticalContentAlignment" Value="Center" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type CalendarDayButton}">
          <Border x:Name="Bd"
                  Background="{TemplateBinding Background}"
                  BorderBrush="{TemplateBinding BorderBrush}"
                  BorderThickness="1"
                  CornerRadius="3"
                  SnapsToDevicePixels="True">
            <!-- Explicit TextBlock (not ContentPresenter) so Foreground TemplateBinding beats implicit TextBlock style -->
            <TextBlock x:Name="DayText"
                       Text="{TemplateBinding Content}"
                       Foreground="{TemplateBinding Foreground}"
                       FontFamily="{TemplateBinding FontFamily}"
                       FontSize="{TemplateBinding FontSize}"
                       HorizontalAlignment="Center"
                       VerticalAlignment="Center"
                       SnapsToDevicePixels="True" />
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
              <Setter TargetName="Bd" Property="Background" Value="{DynamicResource SurfaceAltBrush}" />
            </Trigger>
            <Trigger Property="IsSelected" Value="True">
              <Setter TargetName="Bd" Property="Background" Value="{DynamicResource AccentBrush}" />
              <Setter TargetName="DayText" Property="Foreground" Value="{DynamicResource AccentForegroundBrush}" />
            </Trigger>
            <Trigger Property="IsToday" Value="True">
              <Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource AccentBrush}" />
              <Setter TargetName="DayText" Property="FontWeight" Value="Bold" />
            </Trigger>
            <Trigger Property="IsInactive" Value="True">
              <Setter TargetName="DayText" Property="Foreground" Value="{DynamicResource TextMutedBrush}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
              <Setter TargetName="DayText" Property="Foreground" Value="{DynamicResource TextMutedBrush}" />
              <Setter TargetName="DayText" Property="Opacity" Value="0.5" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style TargetType="{x:Type CalendarButton}">
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="BorderBrush" Value="Transparent" />
    <Setter Property="FontFamily" Value="{StaticResource BaseFont}" />
    <Setter Property="FontSize" Value="12" />
    <Setter Property="MinHeight" Value="28" />
    <Setter Property="Padding" Value="4" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type CalendarButton}">
          <Border x:Name="Bd"
                  Background="{TemplateBinding Background}"
                  BorderBrush="{TemplateBinding BorderBrush}"
                  BorderThickness="1"
                  CornerRadius="3"
                  Padding="{TemplateBinding Padding}"
                  SnapsToDevicePixels="True">
            <TextBlock x:Name="LabelText"
                       Text="{TemplateBinding Content}"
                       Foreground="{TemplateBinding Foreground}"
                       FontFamily="{TemplateBinding FontFamily}"
                       FontSize="{TemplateBinding FontSize}"
                       HorizontalAlignment="Center"
                       VerticalAlignment="Center"
                       SnapsToDevicePixels="True" />
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
              <Setter TargetName="Bd" Property="Background" Value="{DynamicResource SurfaceAltBrush}" />
            </Trigger>
            <Trigger Property="HasSelectedDays" Value="True">
              <Setter TargetName="Bd" Property="Background" Value="{DynamicResource AccentBrush}" />
              <Setter TargetName="LabelText" Property="Foreground" Value="{DynamicResource AccentForegroundBrush}" />
            </Trigger>
            <Trigger Property="IsInactive" Value="True">
              <Setter TargetName="LabelText" Property="Foreground" Value="{DynamicResource TextMutedBrush}" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style TargetType="{x:Type PasswordBox}">
    <Setter Property="Background" Value="{DynamicResource SurfaceBrush}" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="BorderBrush" Value="{DynamicResource BorderStrongBrush}" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="Padding" Value="6,4" />
    <Setter Property="MinHeight" Value="26" />
    <Setter Property="FontFamily" Value="{StaticResource BaseFont}" />
    <Setter Property="FontSize"   Value="{StaticResource BaseFontSize}" />
  </Style>

  <!-- ====================================================== -->
  <!--  CheckBox / RadioButton                                  -->
  <!-- ====================================================== -->
  <Style TargetType="{x:Type CheckBox}">
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="Background" Value="{DynamicResource SurfaceBrush}" />
    <Setter Property="BorderBrush" Value="{DynamicResource BorderStrongBrush}" />
    <Setter Property="FontFamily" Value="{StaticResource BaseFont}" />
    <Setter Property="FontSize"   Value="{StaticResource BaseFontSize}" />
    <Setter Property="VerticalContentAlignment" Value="Center" />
    <Setter Property="Padding" Value="6,0,0,0" />
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type CheckBox}">
          <StackPanel Orientation="Horizontal" Background="Transparent">
            <Border x:Name="Box"
                    Width="16" Height="16"
                    VerticalAlignment="Center"
                    Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="1"
                    CornerRadius="3"
                    SnapsToDevicePixels="True">
              <Path x:Name="Check"
                    Data="M 2 7 L 6 11 L 12 4"
                    Stroke="{DynamicResource AccentForegroundBrush}"
                    StrokeThickness="2"
                    StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeLineJoin="Round"
                    Visibility="Collapsed"
                    SnapsToDevicePixels="True" />
            </Border>
            <ContentPresenter Margin="{TemplateBinding Padding}"
                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                              TextElement.Foreground="{TemplateBinding Foreground}"
                              RecognizesAccessKey="True" />
          </StackPanel>
          <ControlTemplate.Triggers>
            <Trigger Property="IsChecked" Value="True">
              <Setter TargetName="Box"   Property="Background"  Value="{DynamicResource AccentBrush}" />
              <Setter TargetName="Box"   Property="BorderBrush" Value="{DynamicResource AccentBrush}" />
              <Setter TargetName="Check" Property="Visibility"  Value="Visible" />
            </Trigger>
            <Trigger Property="IsChecked" Value="{x:Null}">
              <Setter TargetName="Box"   Property="Background"  Value="{DynamicResource AccentSoftBrush}" />
              <Setter TargetName="Box"   Property="BorderBrush" Value="{DynamicResource AccentBrush}" />
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True">
              <Setter TargetName="Box" Property="BorderBrush" Value="{DynamicResource AccentBrush}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
              <Setter Property="Foreground" Value="{DynamicResource TextMutedBrush}" />
              <Setter TargetName="Box" Property="Background" Value="{DynamicResource SurfaceAltBrush}" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style TargetType="{x:Type RadioButton}">
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="Background" Value="{DynamicResource SurfaceBrush}" />
    <Setter Property="BorderBrush" Value="{DynamicResource BorderStrongBrush}" />
    <Setter Property="FontFamily" Value="{StaticResource BaseFont}" />
    <Setter Property="FontSize"   Value="{StaticResource BaseFontSize}" />
    <Setter Property="VerticalContentAlignment" Value="Center" />
    <Setter Property="Padding" Value="6,0,0,0" />
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type RadioButton}">
          <StackPanel Orientation="Horizontal" Background="Transparent">
            <Grid Width="16" Height="16" VerticalAlignment="Center">
              <Ellipse x:Name="Outer"
                       Fill="{TemplateBinding Background}"
                       Stroke="{TemplateBinding BorderBrush}"
                       StrokeThickness="1" />
              <Ellipse x:Name="Dot"
                       Width="8" Height="8"
                       Fill="{DynamicResource AccentBrush}"
                       Visibility="Collapsed" />
            </Grid>
            <ContentPresenter Margin="{TemplateBinding Padding}"
                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                              TextElement.Foreground="{TemplateBinding Foreground}"
                              RecognizesAccessKey="True" />
          </StackPanel>
          <ControlTemplate.Triggers>
            <Trigger Property="IsChecked" Value="True">
              <Setter TargetName="Outer" Property="Stroke" Value="{DynamicResource AccentBrush}" />
              <Setter TargetName="Dot"   Property="Visibility" Value="Visible" />
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True">
              <Setter TargetName="Outer" Property="Stroke" Value="{DynamicResource AccentBrush}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
              <Setter Property="Foreground" Value="{DynamicResource TextMutedBrush}" />
              <Setter TargetName="Outer" Property="Fill" Value="{DynamicResource SurfaceAltBrush}" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <!-- ====================================================== -->
  <!--  ComboBox                                                -->
  <!-- ====================================================== -->
  <!-- Transparent hit target for ComboBox dropdown toggle. Standalone Path in ComboBox template renders arrow. -->
  <Style x:Key="ComboBoxToggleButtonStyle" TargetType="{x:Type ToggleButton}">
    <Setter Property="OverridesDefaultStyle" Value="True" />
    <Setter Property="IsTabStop" Value="False" />
    <Setter Property="Focusable" Value="False" />
    <Setter Property="ClickMode" Value="Press" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ToggleButton}">
          <Border Background="Transparent" />
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="ThemeComboBoxStyle" TargetType="{x:Type ComboBox}">
    <Setter Property="Background" Value="{DynamicResource SurfaceBrush}" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="BorderBrush" Value="{DynamicResource BorderStrongBrush}" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="Padding" Value="8,3" />
    <Setter Property="MinHeight" Value="28" />
    <Setter Property="FontFamily" Value="{StaticResource BaseFont}" />
    <Setter Property="FontSize"   Value="{StaticResource BaseFontSize}" />
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="VerticalContentAlignment" Value="Center" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ComboBox}">
          <Grid SnapsToDevicePixels="True">
            <Border x:Name="Bd"
                    Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    CornerRadius="5"
                    SnapsToDevicePixels="True">
              <Grid>
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="*" />
                  <ColumnDefinition Width="24" />
                </Grid.ColumnDefinitions>
                <ContentPresenter x:Name="ContentSite"
                                  Grid.Column="0"
                                  Margin="{TemplateBinding Padding}"
                                  HorizontalAlignment="Left"
                                  VerticalAlignment="Center"
                                  Content="{TemplateBinding SelectionBoxItem}"
                                  ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
                                  ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                                  ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
                                  TextElement.Foreground="{TemplateBinding Foreground}"
                                  IsHitTestVisible="False" />
                <ToggleButton Grid.Column="0" Grid.ColumnSpan="2"
                              Style="{StaticResource ComboBoxToggleButtonStyle}"
                              IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                              HorizontalAlignment="Stretch"
                              Background="Transparent" />
                <Path Grid.Column="1"
                      HorizontalAlignment="Center" VerticalAlignment="Center"
                      Data="M 0 0 L 4 4 L 8 0 Z"
                      Fill="{DynamicResource TextMutedBrush}"
                      IsHitTestVisible="False" />
              </Grid>
            </Border>
            <TextBox x:Name="PART_EditableTextBox"
                     Margin="{TemplateBinding Padding}"
                     HorizontalAlignment="Left"
                     VerticalAlignment="Center"
                     Background="Transparent"
                     BorderThickness="0"
                     Foreground="{TemplateBinding Foreground}"
                     Focusable="True"
                     IsReadOnly="{TemplateBinding IsReadOnly}"
                     Visibility="Hidden" />
            <Popup x:Name="PART_Popup"
                   AllowsTransparency="True"
                   Placement="Bottom"
                   PopupAnimation="Slide"
                   IsOpen="{TemplateBinding IsDropDownOpen}"
                   Focusable="False">
              <Border MinWidth="{TemplateBinding ActualWidth}"
                      MaxHeight="{TemplateBinding MaxDropDownHeight}"
                      Background="{DynamicResource SurfaceBrush}"
                      BorderBrush="{DynamicResource BorderStrongBrush}"
                      BorderThickness="1"
                      CornerRadius="5"
                      Margin="0,2,0,0"
                      SnapsToDevicePixels="True">
                <ScrollViewer>
                  <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" />
                </ScrollViewer>
              </Border>
            </Popup>
          </Grid>
          <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
              <Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource AccentBrush}" />
            </Trigger>
            <Trigger Property="IsKeyboardFocusWithin" Value="True">
              <Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource AccentBrush}" />
            </Trigger>
            <Trigger Property="IsEditable" Value="True">
              <Setter TargetName="PART_EditableTextBox" Property="Visibility" Value="Visible" />
              <Setter TargetName="ContentSite"          Property="Visibility" Value="Hidden" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
              <Setter TargetName="Bd" Property="Background" Value="{DynamicResource SurfaceAltBrush}" />
              <Setter Property="Foreground" Value="{DynamicResource TextMutedBrush}" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style TargetType="{x:Type ComboBoxItem}">
    <Setter Property="Padding" Value="8,4" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ComboBoxItem}">
          <Border x:Name="Bd"
                  Background="{TemplateBinding Background}"
                  Padding="{TemplateBinding Padding}"
                  SnapsToDevicePixels="True">
            <ContentPresenter TextElement.Foreground="{TemplateBinding Foreground}" />
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
              <Setter TargetName="Bd" Property="Background" Value="{DynamicResource SurfaceAltBrush}" />
            </Trigger>
            <Trigger Property="IsHighlighted" Value="True">
              <Setter TargetName="Bd" Property="Background" Value="{DynamicResource SelectionBrush}" />
              <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
              <Setter Property="Foreground" Value="{DynamicResource TextMutedBrush}" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <!-- Implicit ComboBox uses the themed template. Toolbar variant reuses same template via BasedOn. -->
  <Style TargetType="{x:Type ComboBox}" BasedOn="{StaticResource ThemeComboBoxStyle}" />
  <Style x:Key="{x:Static ToolBar.ComboBoxStyleKey}" TargetType="{x:Type ComboBox}" BasedOn="{StaticResource ThemeComboBoxStyle}" />

  <Style x:Key="{x:Static ToolBar.CheckBoxStyleKey}" TargetType="{x:Type CheckBox}">
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="VerticalContentAlignment" Value="Center" />
  </Style>

  <Style x:Key="{x:Static ToolBar.RadioButtonStyleKey}" TargetType="{x:Type RadioButton}">
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="VerticalContentAlignment" Value="Center" />
  </Style>

  <!-- ====================================================== -->
  <!--  GroupBox                                                -->
  <!-- ====================================================== -->
  <Style TargetType="{x:Type GroupBox}">
    <Setter Property="Background" Value="{DynamicResource SurfaceBrush}" />
    <Setter Property="BorderBrush" Value="{DynamicResource BorderSoftBrush}" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="FontFamily" Value="{StaticResource BaseFont}" />
    <Setter Property="FontSize"   Value="{StaticResource BaseFontSize}" />
    <Setter Property="Padding" Value="10" />
    <Setter Property="Margin" Value="0,0,0,6" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type GroupBox}">
          <Border Background="{TemplateBinding Background}"
                  BorderBrush="{TemplateBinding BorderBrush}"
                  BorderThickness="{TemplateBinding BorderThickness}"
                  CornerRadius="8"
                  SnapsToDevicePixels="True">
            <DockPanel LastChildFill="True">
              <Border DockPanel.Dock="Top" Padding="10,6,10,4">
                <ContentPresenter ContentSource="Header"
                                  RecognizesAccessKey="True"
                                  TextElement.FontWeight="SemiBold"
                                  TextElement.Foreground="{DynamicResource TextBrush}" />
              </Border>
              <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0,1,0,0">
                <ContentPresenter Margin="{TemplateBinding Padding}" />
              </Border>
            </DockPanel>
          </Border>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <!-- ====================================================== -->
  <!--  TabControl / TabItem                                    -->
  <!-- ====================================================== -->
  <Style TargetType="{x:Type TabControl}">
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="BorderThickness" Value="0" />
    <Setter Property="Padding" Value="0" />
    <Setter Property="FontFamily" Value="{StaticResource BaseFont}" />
    <Setter Property="FontSize"   Value="{StaticResource BaseFontSize}" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type TabControl}">
          <Grid SnapsToDevicePixels="True">
            <Grid.RowDefinitions>
              <RowDefinition Height="Auto" />
              <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Border Grid.Row="0" BorderBrush="{DynamicResource BorderSoftBrush}" BorderThickness="0,0,0,1"
                    Background="{DynamicResource AppBgBrush}">
              <TabPanel x:Name="HeaderPanel"
                        Panel.ZIndex="1"
                        IsItemsHost="True"
                        Margin="8,6,8,0"
                        Background="Transparent" />
            </Border>
            <Border Grid.Row="1" Background="{DynamicResource AppBgBrush}">
              <ContentPresenter ContentSource="SelectedContent" />
            </Border>
          </Grid>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style TargetType="{x:Type TabItem}">
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="Foreground" Value="{DynamicResource TextMutedBrush}" />
    <Setter Property="FontFamily" Value="{StaticResource BaseFont}" />
    <Setter Property="FontSize"   Value="{StaticResource BaseFontSize}" />
    <Setter Property="Padding" Value="14,8" />
    <Setter Property="Margin" Value="0,0,2,0" />
    <Setter Property="Cursor" Value="Hand" />
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type TabItem}">
          <Grid>
            <Border x:Name="Bd"
                    Background="{TemplateBinding Background}"
                    BorderBrush="Transparent"
                    BorderThickness="0,0,0,2"
                    Padding="{TemplateBinding Padding}">
              <ContentPresenter ContentSource="Header"
                                HorizontalAlignment="Center"
                                VerticalAlignment="Center"
                                RecognizesAccessKey="True"
                                TextElement.Foreground="{TemplateBinding Foreground}"
                                TextElement.FontWeight="Medium" />
            </Border>
          </Grid>
          <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
              <Setter TargetName="Bd" Property="Background" Value="{DynamicResource SurfaceAltBrush}" />
              <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
            </Trigger>
            <Trigger Property="IsSelected" Value="True">
              <Setter TargetName="Bd" Property="Background"  Value="Transparent" />
              <Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource AccentBrush}" />
              <Setter Property="Foreground" Value="{DynamicResource AccentBrush}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
              <Setter Property="Foreground" Value="{DynamicResource TextMutedBrush}" />
              <Setter Property="Cursor" Value="Arrow" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <!-- ====================================================== -->
  <!--  ToolBar                                                 -->
  <!-- ====================================================== -->
  <Style TargetType="{x:Type ToolBarTray}">
    <Setter Property="Background" Value="{DynamicResource SurfaceBrush}" />
  </Style>

  <Style TargetType="{x:Type ToolBar}">
    <Setter Property="Background" Value="{DynamicResource SurfaceBrush}" />
    <Setter Property="BorderBrush" Value="{DynamicResource BorderSoftBrush}" />
    <Setter Property="BorderThickness" Value="0,0,0,1" />
    <Setter Property="Padding" Value="6,4" />
    <Setter Property="FontFamily" Value="{StaticResource BaseFont}" />
    <Setter Property="FontSize"   Value="{StaticResource BaseFontSize}" />
  </Style>

  <!-- ====================================================== -->
  <!--  StatusBar                                               -->
  <!-- ====================================================== -->
  <Style TargetType="{x:Type StatusBar}">
    <Setter Property="Background" Value="{DynamicResource SurfaceBrush}" />
    <Setter Property="Foreground" Value="{DynamicResource TextMutedBrush}" />
    <Setter Property="BorderBrush" Value="{DynamicResource BorderSoftBrush}" />
    <Setter Property="BorderThickness" Value="0,1,0,0" />
    <Setter Property="FontSize" Value="12" />
    <Setter Property="Padding" Value="8,2" />
  </Style>

  <Style TargetType="{x:Type StatusBarItem}">
    <Setter Property="Margin" Value="2,0" />
    <Setter Property="Padding" Value="4,0" />
  </Style>

  <!-- ====================================================== -->
  <!--  DataGrid                                                -->
  <!-- ====================================================== -->
  <Style TargetType="{x:Type DataGrid}">
    <Setter Property="Background" Value="{DynamicResource SurfaceBrush}" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="BorderBrush" Value="{DynamicResource BorderSoftBrush}" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="RowBackground" Value="{DynamicResource SurfaceBrush}" />
    <Setter Property="AlternatingRowBackground" Value="{DynamicResource SurfaceAltBrushAlt}" />
    <Setter Property="HorizontalGridLinesBrush" Value="{DynamicResource BorderSoftBrush}" />
    <Setter Property="VerticalGridLinesBrush"   Value="{DynamicResource BorderSoftBrush}" />
    <Setter Property="GridLinesVisibility" Value="Horizontal" />
    <Setter Property="RowHeaderWidth" Value="0" />
    <Setter Property="HeadersVisibility" Value="Column" />
    <Setter Property="FontFamily" Value="{StaticResource BaseFont}" />
    <Setter Property="FontSize"   Value="{StaticResource BaseFontSize}" />
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="CanUserResizeRows" Value="False" />
  </Style>

  <Style TargetType="{x:Type DataGridColumnHeader}">
    <Setter Property="Background" Value="{DynamicResource SurfaceAltBrush}" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="BorderBrush" Value="{DynamicResource BorderSoftBrush}" />
    <Setter Property="BorderThickness" Value="0,0,1,1" />
    <Setter Property="Padding" Value="10,6" />
    <Setter Property="FontWeight" Value="SemiBold" />
    <Setter Property="FontSize" Value="12" />
    <Setter Property="HorizontalContentAlignment" Value="Left" />
  </Style>

  <Style TargetType="{x:Type DataGridRow}">
    <Setter Property="Background" Value="{DynamicResource SurfaceBrush}" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="MinHeight" Value="26" />
  </Style>

  <Style TargetType="{x:Type DataGridCell}">
    <Setter Property="Padding" Value="8,4" />
    <Setter Property="BorderThickness" Value="0" />
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="FocusVisualStyle" Value="{x:Null}" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type DataGridCell}">
          <Border Background="{TemplateBinding Background}"
                  BorderBrush="{TemplateBinding BorderBrush}"
                  BorderThickness="{TemplateBinding BorderThickness}"
                  Padding="{TemplateBinding Padding}"
                  SnapsToDevicePixels="True">
            <ContentPresenter VerticalAlignment="Center" />
          </Border>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
    <Style.Triggers>
      <Trigger Property="IsSelected" Value="True">
        <Setter Property="Background" Value="{DynamicResource SelectionBrush}" />
        <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
      </Trigger>
    </Style.Triggers>
  </Style>

  <!-- ====================================================== -->
  <!--  ListView / ListBox                                      -->
  <!-- ====================================================== -->
  <Style TargetType="{x:Type ListView}">
    <Setter Property="Background" Value="{DynamicResource SurfaceBrush}" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="BorderBrush" Value="{DynamicResource BorderSoftBrush}" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="FontFamily" Value="{StaticResource BaseFont}" />
    <Setter Property="FontSize"   Value="{StaticResource BaseFontSize}" />
  </Style>

  <Style TargetType="{x:Type ListBox}">
    <Setter Property="Background" Value="{DynamicResource SurfaceBrush}" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="BorderBrush" Value="{DynamicResource BorderSoftBrush}" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="FontFamily" Value="{StaticResource BaseFont}" />
    <Setter Property="FontSize"   Value="{StaticResource BaseFontSize}" />
  </Style>

  <!-- ListBoxItem: default template hardcodes system bg; retemplate so theme follows -->
  <Style TargetType="{x:Type ListBoxItem}">
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="Padding" Value="8,4" />
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ListBoxItem}">
          <Border x:Name="Bd"
                  Background="{TemplateBinding Background}"
                  Padding="{TemplateBinding Padding}"
                  SnapsToDevicePixels="True">
            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                              TextElement.Foreground="{TemplateBinding Foreground}" />
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
              <Setter TargetName="Bd" Property="Background" Value="{DynamicResource SurfaceAltBrush}" />
            </Trigger>
            <Trigger Property="IsSelected" Value="True">
              <Setter TargetName="Bd" Property="Background" Value="{DynamicResource SelectionBrush}" />
              <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
              <Setter Property="Foreground" Value="{DynamicResource TextMutedBrush}" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style TargetType="{x:Type ListViewItem}">
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="Padding" Value="4,2" />
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ListViewItem}">
          <Border x:Name="Bd"
                  Background="{TemplateBinding Background}"
                  Padding="{TemplateBinding Padding}"
                  SnapsToDevicePixels="True">
            <GridViewRowPresenter Columns="{TemplateBinding GridView.ColumnCollection}"
                                  Content="{TemplateBinding Content}"
                                  TextElement.Foreground="{TemplateBinding Foreground}" />
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
              <Setter TargetName="Bd" Property="Background" Value="{DynamicResource SurfaceAltBrush}" />
            </Trigger>
            <Trigger Property="IsSelected" Value="True">
              <Setter TargetName="Bd" Property="Background" Value="{DynamicResource SelectionBrush}" />
              <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style TargetType="{x:Type GridViewColumnHeader}">
    <Setter Property="Background" Value="{DynamicResource SurfaceAltBrush}" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="BorderBrush" Value="{DynamicResource BorderSoftBrush}" />
    <Setter Property="BorderThickness" Value="0,0,1,1" />
    <Setter Property="Padding" Value="10,6" />
    <Setter Property="FontWeight" Value="SemiBold" />
    <Setter Property="FontSize" Value="12" />
    <Setter Property="HorizontalContentAlignment" Value="Left" />
  </Style>

  <!-- ====================================================== -->
  <!--  TreeView                                                -->
  <!-- ====================================================== -->
  <Style TargetType="{x:Type TreeView}">
    <Setter Property="Background" Value="{DynamicResource SurfaceBrush}" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="BorderBrush" Value="{DynamicResource BorderSoftBrush}" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="FontFamily" Value="{StaticResource BaseFont}" />
    <Setter Property="FontSize"   Value="{StaticResource BaseFontSize}" />
  </Style>

  <Style x:Key="TreeViewExpandToggleStyle" TargetType="{x:Type ToggleButton}">
    <Setter Property="Focusable" Value="False" />
    <Setter Property="Width" Value="16" />
    <Setter Property="Height" Value="16" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ToggleButton}">
          <Grid Background="Transparent">
            <Path x:Name="Arrow"
                  HorizontalAlignment="Center" VerticalAlignment="Center"
                  Data="M 0 0 L 0 8 L 4 4 Z"
                  Fill="{DynamicResource TextMutedBrush}"
                  RenderTransformOrigin="0.5,0.5" />
          </Grid>
          <ControlTemplate.Triggers>
            <Trigger Property="IsChecked" Value="True">
              <Setter TargetName="Arrow" Property="Data" Value="M 0 0 L 8 0 L 4 4 Z" />
              <Setter TargetName="Arrow" Property="Fill" Value="{DynamicResource TextBrush}" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style TargetType="{x:Type TreeViewItem}">
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="Padding" Value="2,1" />
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type TreeViewItem}">
          <Grid>
            <Grid.RowDefinitions>
              <RowDefinition Height="Auto" />
              <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="Auto" />
              <ColumnDefinition Width="Auto" />
              <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <ToggleButton x:Name="Expander"
                          Style="{StaticResource TreeViewExpandToggleStyle}"
                          ClickMode="Press"
                          IsChecked="{Binding Path=IsExpanded, RelativeSource={RelativeSource TemplatedParent}}" />
            <Border x:Name="Bd"
                    Grid.Column="1" Grid.ColumnSpan="2"
                    Background="{TemplateBinding Background}"
                    Padding="{TemplateBinding Padding}"
                    SnapsToDevicePixels="True">
              <ContentPresenter x:Name="PART_Header"
                                ContentSource="Header"
                                TextElement.Foreground="{TemplateBinding Foreground}"
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" />
            </Border>
            <ItemsPresenter x:Name="ItemsHost"
                            Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" />
          </Grid>
          <ControlTemplate.Triggers>
            <Trigger Property="IsExpanded" Value="False">
              <Setter TargetName="ItemsHost" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <Trigger Property="HasItems" Value="False">
              <Setter TargetName="Expander" Property="Visibility" Value="Hidden" />
            </Trigger>
            <Trigger Property="IsMouseOver" SourceName="Bd" Value="True">
              <Setter TargetName="Bd" Property="Background" Value="{DynamicResource SurfaceAltBrush}" />
            </Trigger>
            <Trigger Property="IsSelected" Value="True">
              <Setter TargetName="Bd" Property="Background" Value="{DynamicResource SelectionBrush}" />
              <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
              <Setter Property="Foreground" Value="{DynamicResource TextMutedBrush}" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <!-- ====================================================== -->
  <!--  ScrollBar — thin, modern                                -->
  <!-- ====================================================== -->
  <Style x:Key="ScrollBarThumbStyle" TargetType="{x:Type Thumb}">
    <Setter Property="IsTabStop" Value="False" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type Thumb}">
          <Border CornerRadius="4" Background="{DynamicResource ScrollThumbBrush}" Margin="2" />
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style TargetType="{x:Type ScrollBar}">
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="Foreground" Value="{DynamicResource BorderStrongBrush}" />
    <Setter Property="Width" Value="10" />
    <Setter Property="MinWidth" Value="10" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ScrollBar}">
          <Grid Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
            <Track Name="PART_Track" IsDirectionReversed="True">
              <Track.Thumb>
                <Thumb Style="{StaticResource ScrollBarThumbStyle}" />
              </Track.Thumb>
              <Track.IncreaseRepeatButton>
                <RepeatButton Opacity="0" Command="ScrollBar.PageDownCommand" />
              </Track.IncreaseRepeatButton>
              <Track.DecreaseRepeatButton>
                <RepeatButton Opacity="0" Command="ScrollBar.PageUpCommand" />
              </Track.DecreaseRepeatButton>
            </Track>
          </Grid>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
    <Style.Triggers>
      <Trigger Property="Orientation" Value="Horizontal">
        <Setter Property="Width" Value="Auto" />
        <Setter Property="Height" Value="10" />
        <Setter Property="MinHeight" Value="10" />
      </Trigger>
    </Style.Triggers>
  </Style>

  <!-- ====================================================== -->
  <!--  ProgressBar                                             -->
  <!-- ====================================================== -->
  <Style TargetType="{x:Type ProgressBar}">
    <Setter Property="Background" Value="{DynamicResource SurfaceAltBrush}" />
    <Setter Property="Foreground" Value="{DynamicResource AccentBrush}" />
    <Setter Property="BorderBrush" Value="Transparent" />
    <Setter Property="BorderThickness" Value="0" />
    <Setter Property="Height" Value="6" />
  </Style>

  <!-- ====================================================== -->
  <!--  InfoButton — small circular "?" help button            -->
  <!-- ====================================================== -->
  <Style x:Key="InfoButtonStyle" TargetType="{x:Type Button}">
    <Setter Property="Width" Value="18" />
    <Setter Property="Height" Value="18" />
    <Setter Property="Cursor" Value="Hand" />
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="BorderBrush" Value="{DynamicResource TextMutedBrush}" />
    <Setter Property="BorderThickness" Value="1.5" />
    <Setter Property="Padding" Value="0" />
    <Setter Property="FontSize" Value="11" />
    <Setter Property="FontWeight" Value="SemiBold" />
    <Setter Property="Foreground" Value="{DynamicResource TextMutedBrush}" />
    <Setter Property="FocusVisualStyle" Value="{x:Null}" />
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type Button}">
          <Grid>
            <Ellipse x:Name="Circle"
                     Fill="{TemplateBinding Background}"
                     Stroke="{TemplateBinding BorderBrush}"
                     StrokeThickness="{TemplateBinding BorderThickness}" />
            <TextBlock x:Name="Label"
                       Text="?"
                       Foreground="{TemplateBinding Foreground}"
                       FontSize="{TemplateBinding FontSize}"
                       FontWeight="{TemplateBinding FontWeight}"
                       HorizontalAlignment="Center"
                       VerticalAlignment="Center"
                       SnapsToDevicePixels="True" />
          </Grid>
          <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
              <Setter TargetName="Circle" Property="Fill"   Value="{DynamicResource AccentSoftBrush}" />
              <Setter TargetName="Circle" Property="Stroke" Value="{DynamicResource AccentBrush}" />
              <Setter TargetName="Label"  Property="Foreground" Value="{DynamicResource AccentBrush}" />
            </Trigger>
            <Trigger Property="IsPressed" Value="True">
              <Setter TargetName="Circle" Property="Fill" Value="{DynamicResource AccentBrush}" />
              <Setter TargetName="Label"  Property="Foreground" Value="{DynamicResource AccentForegroundBrush}" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <!-- ====================================================== -->
  <!--  ToolTip                                                 -->
  <!-- ====================================================== -->
  <Style TargetType="{x:Type ToolTip}">
    <Setter Property="Background" Value="{DynamicResource TooltipBgBrush}" />
    <Setter Property="Foreground" Value="{DynamicResource TooltipFgBrush}" />
    <Setter Property="Padding" Value="8,5" />
    <Setter Property="BorderBrush" Value="{DynamicResource TooltipBgBrush}" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="FontSize" Value="12" />
    <Setter Property="HasDropShadow" Value="True" />
  </Style>

  <!-- ====================================================== -->
  <!--  Menu / ContextMenu                                      -->
  <!-- ====================================================== -->
  <Style TargetType="{x:Type Menu}">
    <Setter Property="Background" Value="{DynamicResource SurfaceBrush}" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="FontFamily" Value="{StaticResource BaseFont}" />
    <Setter Property="FontSize"   Value="{StaticResource BaseFontSize}" />
  </Style>

  <Style TargetType="{x:Type ContextMenu}">
    <Setter Property="Background" Value="{DynamicResource SurfaceBrush}" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="BorderBrush" Value="{DynamicResource BorderSoftBrush}" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="Padding" Value="4" />
    <Setter Property="FontFamily" Value="{StaticResource BaseFont}" />
    <Setter Property="FontSize"   Value="{StaticResource BaseFontSize}" />
  </Style>

  <Style TargetType="{x:Type MenuItem}">
    <Setter Property="Padding" Value="8,4" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="Background" Value="Transparent" />
    <Style.Triggers>
      <Trigger Property="IsHighlighted" Value="True">
        <Setter Property="Background" Value="{DynamicResource SurfaceAltBrush}" />
      </Trigger>
      <Trigger Property="IsEnabled" Value="False">
        <Setter Property="Foreground" Value="{DynamicResource TextMutedBrush}" />
      </Trigger>
    </Style.Triggers>
  </Style>

</ResourceDictionary>
