<Application x:Class="SquadDash.App"
             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"
             xmlns:shell="clr-namespace:System.Windows.Shell;assembly=PresentationFramework"
             xmlns:local="clr-namespace:SquadDash">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Themes/Light.xaml" />
                <ResourceDictionary Source="Themes/ToolIcons.xaml" />
                <ResourceDictionary Source="Themes/ImageEditorIcons.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <!-- Transcript selection dimmed at 50% opacity when context menu is open (focus leaves RTB) -->
            <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}"
                             Color="{x:Static SystemColors.HighlightColor}"
                             Opacity="0.2"/>

            <!-- Issue 1: Themed button — applied explicitly, not globally -->
            <!-- Font Size Tokens -->
            <sys:Double x:Key="FontSizeTiny">7</sys:Double>
            <sys:Double x:Key="FontSizeXSmall">10</sys:Double>
            <sys:Double x:Key="FontSizeSmall">11</sys:Double>
            <sys:Double x:Key="FontSizeBody">12</sys:Double>
            <sys:Double x:Key="FontSizeNormal">13</sys:Double>
            <sys:Double x:Key="FontSizeMedium">14</sys:Double>
            <sys:Double x:Key="FontSizeLarge">15</sys:Double>
            <sys:Double x:Key="FontSizeLargePlus">16</sys:Double>
            <sys:Double x:Key="FontSizeSubtitle">18</sys:Double>
            <sys:Double x:Key="FontSizeTitle">20</sys:Double>
            <sys:Double x:Key="FontSizeHeading">22</sys:Double>
            <sys:Double x:Key="FontSizeHero">52</sys:Double>
            <sys:Double x:Key="FontSizeDisplay">180</sys:Double>

            <Style x:Key="ThemedButtonStyle" TargetType="Button">
                <Setter Property="Background" Value="{DynamicResource InputSurface}"/>
                <Setter Property="Foreground" Value="{DynamicResource LabelText}"/>
                <Setter Property="BorderBrush" Value="{DynamicResource InputBorder}"/>
                <Setter Property="BorderThickness" Value="1"/>
                <Setter Property="Padding" Value="8,4"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <Border x:Name="border"
                                    Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    CornerRadius="3"
                                    Padding="{TemplateBinding Padding}">
                                <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter TargetName="border" Property="Background" Value="{DynamicResource HoverSurface}"/>
                                </Trigger>
                                <Trigger Property="IsPressed" Value="True">
                                    <Setter TargetName="border" Property="Background" Value="{DynamicResource PanelSurface}"/>
                                </Trigger>
                                <Trigger Property="IsEnabled" Value="False">
                                    <Setter TargetName="border" Property="Opacity" Value="0.5"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- Flat / link-style button — transparent background, themed hover; use for report rows etc. -->
            <Style x:Key="FlatButtonStyle" TargetType="Button">
                <Setter Property="Background"       Value="Transparent"/>
                <Setter Property="Foreground"       Value="{DynamicResource BodyText}"/>
                <Setter Property="BorderBrush"      Value="Transparent"/>
                <Setter Property="BorderThickness"  Value="0"/>
                <Setter Property="Padding"          Value="4,2"/>
                <Setter Property="Cursor"           Value="Hand"/>
                <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
                <Setter Property="HorizontalContentAlignment" Value="Left"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <Border x:Name="border"
                                    Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    CornerRadius="2"
                                    Padding="{TemplateBinding Padding}">
                                <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                  VerticalAlignment="Center"/>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter TargetName="border" Property="Background" Value="{DynamicResource HoverSurface}"/>
                                </Trigger>
                                <Trigger Property="IsPressed" Value="True">
                                    <Setter TargetName="border" Property="Background" Value="{DynamicResource InputSurface}"/>
                                </Trigger>
                                <Trigger Property="IsEnabled" Value="False">
                                    <Setter TargetName="border" Property="Opacity" Value="0.5"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- Panel close button (×) — transparent base, clearly-visible CaptionButtonHover
                 background on hover so users can see the button is clickable. -->
            <Style x:Key="PanelCloseButtonStyle" TargetType="Button">
                <Setter Property="Background" Value="Transparent"/>
                <Setter Property="Foreground" Value="{DynamicResource LabelText}"/>
                <Setter Property="BorderBrush" Value="Transparent"/>
                <Setter Property="BorderThickness" Value="0"/>
                <Setter Property="Padding" Value="0,0,0,3"/>
                <Setter Property="Cursor" Value="Hand"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <Border x:Name="border"
                                    Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    CornerRadius="4"
                                    Padding="{TemplateBinding Padding}">
                                <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter TargetName="border" Property="Background" Value="{DynamicResource CaptionButtonHover}"/>
                                </Trigger>
                                <Trigger Property="IsPressed" Value="True">
                                    <Setter TargetName="border" Property="Background" Value="{DynamicResource HoverSurface}"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <Style x:Key="ThemedIconButtonStyle"
                   TargetType="Button"
                   BasedOn="{StaticResource PanelCloseButtonStyle}">
                <Setter Property="Foreground" Value="{DynamicResource SubtleText}"/>
                <Setter Property="FontWeight" Value="SemiBold"/>
                <Setter Property="Padding" Value="0"/>
            </Style>

            <!-- Shared filter TextBox for panel headers — rounded with (filter) placeholder -->
            <Style x:Key="PanelFilterBoxStyle" TargetType="TextBox">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="TextBox">
                            <Border Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    Padding="4,2"
                                    CornerRadius="3">
                                <Grid>
                                    <TextBlock x:Name="Placeholder"
                                               Text="(filter)"
                                               Foreground="{DynamicResource SubtleText}"
                                               FontSize="{TemplateBinding FontSize}"
                                               VerticalAlignment="Center"
                                               IsHitTestVisible="False"
                                               Visibility="Collapsed" />
                                    <ScrollViewer x:Name="PART_ContentHost"
                                                  VerticalAlignment="Center"
                                                  VerticalScrollBarVisibility="Hidden"
                                                  HorizontalScrollBarVisibility="Hidden" />
                                </Grid>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="Text" Value="">
                                    <Setter TargetName="Placeholder" Property="Visibility" Value="Visible" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- Clear button for panel filter boxes (low-contrast ×, brightens on hover) -->
            <Style x:Key="PanelFilterClearButtonStyle" TargetType="Button">
                <Setter Property="Background" Value="Transparent" />
                <Setter Property="BorderThickness" Value="0" />
                <Setter Property="Foreground" Value="{DynamicResource SubtleText}" />
                <Setter Property="Cursor" Value="Hand" />
                <Setter Property="Padding" Value="0" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <Border Background="{TemplateBinding Background}"
                                    Padding="{TemplateBinding Padding}">
                                <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Foreground" Value="{DynamicResource LabelText}" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- Transcript inline button (e.g. copy-code 📋) — transparent base, dark-aware hover -->
            <Style x:Key="TranscriptInlineButtonStyle" TargetType="Button">
                <Setter Property="Background" Value="Transparent"/>
                <Setter Property="Foreground" Value="{DynamicResource SubtleText}"/>
                <Setter Property="BorderBrush" Value="Transparent"/>
                <Setter Property="BorderThickness" Value="0"/>
                <Setter Property="Padding" Value="0"/>
                <Setter Property="Cursor" Value="Hand"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <Border x:Name="border"
                                    Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    CornerRadius="3"
                                    Padding="{TemplateBinding Padding}">
                                <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter TargetName="border" Property="Background" Value="{DynamicResource CaptionButtonHover}"/>
                                </Trigger>
                                <Trigger Property="IsPressed" Value="True">
                                    <Setter TargetName="border" Property="Background" Value="{DynamicResource HoverSurface}"/>
                                </Trigger>
                                <Trigger Property="IsEnabled" Value="False">
                                    <Setter TargetName="border" Property="Opacity" Value="0.5"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- Transcript action button (agent launch / report viewer).
                 Faint blue tint at rest so it reads as a button; hover deepens the tint.
                 No text decoration — used for both the tool-transcript "Transcript" chip
                 and the agent-report "📋 … report" button. -->
            <Style x:Key="TranscriptActionButtonStyle" TargetType="Button">
                <Setter Property="Background"       Value="{DynamicResource TranscriptActionSurface}"/>
                <Setter Property="Foreground"       Value="{DynamicResource TranscriptActionText}"/>
                <Setter Property="BorderBrush"      Value="{DynamicResource TranscriptActionBorder}"/>
                <Setter Property="BorderThickness"  Value="1"/>
                <Setter Property="Padding"          Value="6,2"/>
                <Setter Property="Cursor"           Value="Hand"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <Border x:Name="border"
                                    Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    CornerRadius="3"
                                    Padding="{TemplateBinding Padding}">
                                <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter TargetName="border" Property="Background" Value="{DynamicResource TranscriptActionHoverSurface}"/>
                                </Trigger>
                                <Trigger Property="IsPressed" Value="True">
                                    <Setter TargetName="border" Property="Background" Value="{DynamicResource TranscriptActionHoverSurface}"/>
                                    <Setter TargetName="border" Property="Opacity" Value="0.8"/>
                                </Trigger>
                                <Trigger Property="IsEnabled" Value="False">
                                    <Setter TargetName="border" Property="Opacity" Value="0.5"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- Danger button style — for destructive actions (e.g. "Close Now").
                 Background/hover/pressed use DangerButton* theme tokens so the red
                 tones invert correctly between light (hover = darker red) and
                 dark (hover = lighter/brighter red). Foreground is always white. -->
            <Style x:Key="DangerButtonStyle" TargetType="Button">
                <Setter Property="Background"   Value="{DynamicResource DangerButtonBg}"/>
                <Setter Property="Foreground"   Value="{DynamicResource DangerButtonFg}"/>
                <Setter Property="BorderBrush"  Value="{DynamicResource DangerButtonBg}"/>
                <Setter Property="BorderThickness" Value="1"/>
                <Setter Property="Padding"      Value="8,4"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <Border x:Name="border"
                                    Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    CornerRadius="3"
                                    Padding="{TemplateBinding Padding}">
                                <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter TargetName="border" Property="Background" Value="{DynamicResource DangerButtonHover}"/>
                                    <Setter TargetName="border" Property="BorderBrush" Value="{DynamicResource DangerButtonHover}"/>
                                </Trigger>
                                <Trigger Property="IsPressed" Value="True">
                                    <Setter TargetName="border" Property="Background" Value="{DynamicResource DangerButtonPressed}"/>
                                    <Setter TargetName="border" Property="BorderBrush" Value="{DynamicResource DangerButtonPressed}"/>
                                </Trigger>
                                <Trigger Property="IsEnabled" Value="False">
                                    <Setter TargetName="border" Property="Opacity" Value="0.5"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- Default themed CheckBox — applies to all CheckBoxes app-wide -->
            <Style TargetType="CheckBox">
                <Setter Property="Foreground"               Value="{DynamicResource LabelText}"/>
                <Setter Property="Background"               Value="{DynamicResource InputSurface}"/>
                <Setter Property="BorderBrush"              Value="{DynamicResource CheckBoxBorder}"/>
                <Setter Property="BorderThickness"          Value="1"/>
                <Setter Property="VerticalContentAlignment" Value="Center"/>
                <Setter Property="Cursor"                   Value="Hand"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="CheckBox">
                            <Grid Background="Transparent">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="16"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Border x:Name="checkBorder"
                                        Width="14" Height="14"
                                        Background="{TemplateBinding Background}"
                                        BorderBrush="{TemplateBinding BorderBrush}"
                                        BorderThickness="{TemplateBinding BorderThickness}"
                                        CornerRadius="2"
                                        VerticalAlignment="Center"
                                        HorizontalAlignment="Center">
                                    <Path x:Name="checkMark"
                                          Data="M 2,6 L 5,9 L 11,3"
                                          Stroke="{DynamicResource LabelText}"
                                          StrokeThickness="1.8"
                                          StrokeStartLineCap="Round"
                                          StrokeEndLineCap="Round"
                                          StrokeLineJoin="Round"
                                          Visibility="Collapsed"/>
                                </Border>
                                <ContentPresenter Grid.Column="1"
                                                  Margin="4,0,0,0"
                                                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                                  RecognizesAccessKey="True"/>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsChecked" Value="True">
                                    <Setter TargetName="checkMark" Property="Visibility" Value="Visible"/>
                                </Trigger>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter TargetName="checkBorder" Property="Background" Value="{DynamicResource HoverSurface}"/>
                                </Trigger>
                                <Trigger Property="IsEnabled" Value="False">
                                    <Setter Property="Opacity" Value="0.5"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <Style x:Key="ThemedCheckBoxStyle"
                   TargetType="CheckBox"
                   BasedOn="{StaticResource {x:Type CheckBox}}" />

            <Style x:Key="QuickReplyButtonStyle" TargetType="Button">
                <Setter Property="Background" Value="{DynamicResource QuickReplySurface}"/>
                <Setter Property="Foreground" Value="{DynamicResource QuickReplyText}"/>
                <Setter Property="BorderBrush" Value="{DynamicResource QuickReplyBorder}"/>
                <Setter Property="BorderThickness" Value="1"/>
                <Setter Property="Cursor" Value="Hand"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <Border x:Name="border"
                                    Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    CornerRadius="3"
                                    Padding="{TemplateBinding Padding}">
                                <ContentPresenter HorizontalAlignment="Center"
                                                  VerticalAlignment="Center"
                                                  TextElement.Foreground="{TemplateBinding Foreground}"/>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter TargetName="border" Property="Background" Value="{DynamicResource QuickReplyHoverSurface}"/>
                                </Trigger>
                                <Trigger Property="IsPressed" Value="True">
                                    <Setter TargetName="border" Property="Opacity" Value="0.8"/>
                                </Trigger>
                                <Trigger Property="IsEnabled" Value="False">
                                    <Setter TargetName="border" Property="Opacity" Value="0.5"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- Issue 5: Themed sub-menu MenuItem -->
            <Style x:Key="ThemedMenuItemStyle" TargetType="MenuItem">
                <Setter Property="Background" Value="{DynamicResource ChromeSurface}"/>
                <Setter Property="Foreground" Value="{DynamicResource LabelText}"/>
                <Setter Property="FontSize" Value="{DynamicResource FontSizeNormal}"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="MenuItem">
                            <Border x:Name="Border"
                                    Background="{TemplateBinding Background}"
                                    BorderBrush="{DynamicResource PanelBorder}"
                                    BorderThickness="0"
                                    Padding="6,3,6,3">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" SharedSizeGroup="MenuItemIconColumn"/>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="Auto" SharedSizeGroup="MenuItemIGTColumn"/>
                                        <ColumnDefinition Width="14"/>
                                    </Grid.ColumnDefinitions>
                                    <ContentPresenter x:Name="Icon" Grid.Column="0"
                                                      ContentSource="Icon"
                                                      VerticalAlignment="Center"
                                                      Margin="0,0,6,0"/>
                                    <ContentPresenter x:Name="HeaderHost" Grid.Column="1"
                                                      ContentSource="Header"
                                                      RecognizesAccessKey="True"
                                                      VerticalAlignment="Center"/>
                                    <TextBlock x:Name="IGT" Grid.Column="2"
                                               Text="{TemplateBinding InputGestureText}"
                                               Margin="14,0,0,0"
                                               Foreground="{DynamicResource BodyText}"
                                               VerticalAlignment="Center"/>
                                    <Path x:Name="Arrow" Grid.Column="3"
                                          Data="M0,0 L0,8 L4,4 z"
                                          Fill="{DynamicResource BodyText}"
                                          VerticalAlignment="Center"
                                          Margin="4,0,0,0"
                                          Visibility="Collapsed"/>
                                    <Popup x:Name="SubMenuPopup"
                                           IsOpen="{TemplateBinding IsSubmenuOpen}"
                                           Placement="Right"
                                           HorizontalOffset="-4"
                                           VerticalOffset="-3"
                                           AllowsTransparency="True"
                                           Focusable="False"
                                           PopupAnimation="Fade">
                                        <Border x:Name="SubMenuBorder"
                                                Background="{DynamicResource ChromeSurface}"
                                                BorderBrush="{DynamicResource PanelBorder}"
                                                BorderThickness="1"
                                                Padding="2">
                                            <ItemsPresenter KeyboardNavigation.DirectionalNavigation="Cycle"/>
                                        </Border>
                                    </Popup>
                                </Grid>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="HasItems" Value="True">
                                    <Setter TargetName="Arrow" Property="Visibility" Value="Visible"/>
                                </Trigger>
                                <Trigger Property="IsHighlighted" Value="True">
                                    <Setter TargetName="Border" Property="Background" Value="{DynamicResource HoverSurface}"/>
                                </Trigger>
                                <Trigger Property="IsEnabled" Value="False">
                                    <Setter Property="Foreground" Value="{DynamicResource SubtleText}"/>
                                </Trigger>
                                <Trigger Property="IsChecked" Value="True">
                                    <Setter TargetName="Icon" Property="ContentTemplate">
                                        <Setter.Value>
                                            <DataTemplate>
                                                <Path Data="M0,4 L3,7 L9,1" Stroke="{DynamicResource LabelText}" StrokeThickness="1.5" Width="12" Height="10"/>
                                            </DataTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- Tint submenu items: swatch background preserved on hover, colored border appears instead -->
            <Style x:Key="TintMenuItemStyle" TargetType="MenuItem">
                <Setter Property="Background" Value="{DynamicResource ChromeSurface}"/>
                <Setter Property="Foreground" Value="{DynamicResource LabelText}"/>
                <Setter Property="FontSize" Value="{DynamicResource FontSizeNormal}"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="MenuItem">
                            <Border x:Name="Border"
                                    Background="{TemplateBinding Background}"
                                    BorderBrush="Transparent"
                                    BorderThickness="1"
                                    Padding="6,3,6,3">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" SharedSizeGroup="MenuItemIconColumn"/>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="Auto" SharedSizeGroup="MenuItemIGTColumn"/>
                                        <ColumnDefinition Width="14"/>
                                    </Grid.ColumnDefinitions>
                                    <ContentPresenter x:Name="Icon" Grid.Column="0"
                                                      ContentSource="Icon"
                                                      VerticalAlignment="Center"
                                                      Margin="0,0,6,0"/>
                                    <ContentPresenter x:Name="HeaderHost" Grid.Column="1"
                                                      ContentSource="Header"
                                                      RecognizesAccessKey="True"
                                                      VerticalAlignment="Center"/>
                                    <TextBlock x:Name="IGT" Grid.Column="2"
                                               Text="{TemplateBinding InputGestureText}"
                                               Margin="14,0,0,0"
                                               Foreground="{DynamicResource BodyText}"
                                               VerticalAlignment="Center"/>
                                    <Path x:Name="Arrow" Grid.Column="3"
                                          Data="M0,0 L0,8 L4,4 z"
                                          Fill="{DynamicResource BodyText}"
                                          VerticalAlignment="Center"
                                          Margin="4,0,0,0"
                                          Visibility="Collapsed"/>
                                    <Popup x:Name="SubMenuPopup"
                                           IsOpen="{TemplateBinding IsSubmenuOpen}"
                                           Placement="Right"
                                           HorizontalOffset="-4"
                                           VerticalOffset="-3"
                                           AllowsTransparency="True"
                                           Focusable="False"
                                           PopupAnimation="Fade">
                                        <Border x:Name="SubMenuBorder"
                                                Background="{DynamicResource ChromeSurface}"
                                                BorderBrush="{DynamicResource PanelBorder}"
                                                BorderThickness="1"
                                                Padding="2">
                                            <ItemsPresenter KeyboardNavigation.DirectionalNavigation="Cycle"/>
                                        </Border>
                                    </Popup>
                                </Grid>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="HasItems" Value="True">
                                    <Setter TargetName="Arrow" Property="Visibility" Value="Visible"/>
                                </Trigger>
                                <!-- On hover: keep swatch background, show hue-matched border instead -->
                                <Trigger Property="IsHighlighted" Value="True">
                                    <Setter TargetName="Border" Property="BorderBrush"
                                            Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Foreground}"/>
                                </Trigger>
                                <Trigger Property="IsEnabled" Value="False">
                                    <Setter Property="Foreground" Value="{DynamicResource SubtleText}"/>
                                </Trigger>
                                <Trigger Property="IsChecked" Value="True">
                                    <Setter TargetName="Icon" Property="ContentTemplate">
                                        <Setter.Value>
                                            <DataTemplate>
                                                <Path Data="M0,4 L3,7 L9,1" Stroke="{DynamicResource LabelText}" StrokeThickness="1.5" Width="12" Height="10"/>
                                            </DataTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- Issue 5: Top-level menu item style -->
            <Style x:Key="TopLevelMenuItemStyle" TargetType="MenuItem" BasedOn="{StaticResource ThemedMenuItemStyle}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="MenuItem">
                            <Border x:Name="Border"
                                    Background="Transparent"
                                    Padding="8,4,8,4">
                                <Grid>
                                    <ContentPresenter ContentSource="Header" RecognizesAccessKey="True"/>
                                    <Popup x:Name="SubMenuPopup"
                                           IsOpen="{TemplateBinding IsSubmenuOpen}"
                                           Placement="Bottom"
                                           HorizontalOffset="-4"
                                           AllowsTransparency="True"
                                           Focusable="False"
                                           PopupAnimation="Fade">
                                        <Border Background="{DynamicResource ChromeSurface}"
                                                BorderBrush="{DynamicResource PanelBorder}"
                                                BorderThickness="1"
                                                Padding="2">
                                            <ItemsPresenter KeyboardNavigation.DirectionalNavigation="Cycle"/>
                                        </Border>
                                    </Popup>
                                </Grid>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsHighlighted" Value="True">
                                    <Setter TargetName="Border" Property="Background" Value="{DynamicResource HoverSurface}"/>
                                </Trigger>
                                <Trigger Property="IsSubmenuOpen" Value="True">
                                    <Setter TargetName="Border" Property="Background" Value="{DynamicResource HoverSurface}"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- Themed ContextMenu separator -->
            <Style x:Key="ThemedSeparatorStyle" TargetType="Separator">
                <Setter Property="Background" Value="{DynamicResource PanelBorder}"/>
                <Setter Property="Height" Value="1"/>
                <Setter Property="Margin" Value="4,2,4,2"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Separator">
                            <Border Height="1"
                                    Background="{DynamicResource PanelBorder}"
                                    Margin="4,2,4,2"/>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- Selector: returns ThemedMenuItemStyle for MenuItem, null for Separator -->
            <local:MenuItemStyleSelector x:Key="ThemedMenuItemStyleSelector"
                                         MenuItemStyle="{StaticResource ThemedMenuItemStyle}"/>

            <!-- Themed ContextMenu: dark background, themed items, themed separators -->
            <Style x:Key="ThemedContextMenuStyle" TargetType="ContextMenu">
                <Setter Property="Background" Value="{DynamicResource ChromeSurface}"/>
                <Setter Property="BorderBrush" Value="{DynamicResource PanelBorder}"/>
                <Setter Property="BorderThickness" Value="1"/>
                <Setter Property="Padding" Value="2"/>
                <Setter Property="ItemContainerStyleSelector" Value="{StaticResource ThemedMenuItemStyleSelector}"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="ContextMenu">
                            <Border Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    Padding="{TemplateBinding Padding}"
                                    CornerRadius="4">
                                <StackPanel IsItemsHost="True"
                                            KeyboardNavigation.DirectionalNavigation="Cycle"/>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- Scrollbar repeat button (transparent, no arrows) -->
            <Style x:Key="ScrollBarLineButtonStyle" TargetType="RepeatButton"><Setter Property="SnapsToDevicePixels" Value="True"/>
                <Setter Property="OverridesDefaultStyle" Value="True"/>
                <Setter Property="Focusable" Value="False"/>
                <Setter Property="Height" Value="0"/>
                <Setter Property="Width" Value="0"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="RepeatButton">
                            <Border Background="Transparent"/>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- Scrollbar page button (track area, transparent) -->
            <Style x:Key="ScrollBarPageButtonStyle" TargetType="RepeatButton">
                <Setter Property="SnapsToDevicePixels" Value="True"/>
                <Setter Property="OverridesDefaultStyle" Value="True"/>
                <Setter Property="IsTabStop" Value="False"/>
                <Setter Property="Focusable" Value="False"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="RepeatButton">
                            <Border Background="Transparent"/>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- Scrollbar thumb -->
            <Style x:Key="ScrollBarThumbStyle" TargetType="Thumb">
                <Setter Property="SnapsToDevicePixels" Value="True"/>
                <Setter Property="OverridesDefaultStyle" Value="True"/>
                <Setter Property="IsTabStop" Value="False"/>
                <Setter Property="Focusable" Value="False"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Thumb">
                            <!-- Transparent Grid = full-width hit area -->
                            <Grid Background="Transparent">
                                <Border x:Name="ThumbBorder"
                                        Background="{DynamicResource ScrollBarThumbBrush}"
                                        CornerRadius="2.5"
                                        Margin="3,2"/>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter TargetName="ThumbBorder" Property="Background"
                                            Value="{DynamicResource ScrollBarThumbHoverBrush}"/>
                                </Trigger>
                                <Trigger Property="IsDragging" Value="True">
                                    <Setter TargetName="ThumbBorder" Property="Background"
                                            Value="{DynamicResource ScrollBarThumbPressedBrush}"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- Global ScrollBar style — no x:Key, applies to all ScrollBar controls -->
            <Style TargetType="ScrollBar">
                <Setter Property="SnapsToDevicePixels" Value="True"/>
                <Setter Property="OverridesDefaultStyle" Value="True"/>
                <Style.Triggers>
                    <!-- Vertical -->
                    <Trigger Property="Orientation" Value="Vertical">
                        <Setter Property="Width" Value="11"/>
                        <Setter Property="MinWidth" Value="11"/>
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="ScrollBar">
                                    <Border Background="{DynamicResource ScrollBarTrackBrush}"
                                            CornerRadius="6">
                                        <local:MinThumbTrack x:Name="PART_Track"
                                                             IsDirectionReversed="True"
                                                             MinThumbLength="32"
                                                             Margin="0,3,0,3">
                                            <local:MinThumbTrack.DecreaseRepeatButton>
                                                <RepeatButton Style="{StaticResource ScrollBarPageButtonStyle}"
                                                              Command="ScrollBar.PageUpCommand"/>
                                            </local:MinThumbTrack.DecreaseRepeatButton>
                                            <local:MinThumbTrack.Thumb>
                                                <Thumb Style="{StaticResource ScrollBarThumbStyle}"/>
                                            </local:MinThumbTrack.Thumb>
                                            <local:MinThumbTrack.IncreaseRepeatButton>
                                                <RepeatButton Style="{StaticResource ScrollBarPageButtonStyle}"
                                                              Command="ScrollBar.PageDownCommand"/>
                                            </local:MinThumbTrack.IncreaseRepeatButton>
                                        </local:MinThumbTrack>
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                    <!-- Horizontal -->
                    <Trigger Property="Orientation" Value="Horizontal">
                        <Setter Property="Height" Value="11"/>
                        <Setter Property="MinHeight" Value="11"/>
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="ScrollBar">
                                    <Border Background="{DynamicResource ScrollBarTrackBrush}"
                                            CornerRadius="6">
                                        <local:MinThumbTrack x:Name="PART_Track"
                                                             MinThumbLength="32"
                                                             Margin="3,0,3,0">
                                            <local:MinThumbTrack.DecreaseRepeatButton>
                                                <RepeatButton Style="{StaticResource ScrollBarPageButtonStyle}"
                                                              Command="ScrollBar.PageLeftCommand"/>
                                            </local:MinThumbTrack.DecreaseRepeatButton>
                                            <local:MinThumbTrack.Thumb>
                                                <Thumb Style="{StaticResource ScrollBarThumbStyle}"/>
                                            </local:MinThumbTrack.Thumb>
                                            <local:MinThumbTrack.IncreaseRepeatButton>
                                                <RepeatButton Style="{StaticResource ScrollBarPageButtonStyle}"
                                                              Command="ScrollBar.PageRightCommand"/>
                                            </local:MinThumbTrack.IncreaseRepeatButton>
                                        </local:MinThumbTrack>
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                </Style.Triggers>
            </Style>

            <!-- Implicit TreeViewItem style for recursive theming (all depths) -->
            <Style TargetType="TreeViewItem">
                <Setter Property="Foreground" Value="{DynamicResource LabelText}" />
                <Setter Property="FontSize"   Value="{DynamicResource FontSizeNormal}" />
            </Style>

            <!-- Implicit Hyperlink style for themed hover behavior -->
            <Style TargetType="Hyperlink">
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Background" Value="{DynamicResource TranscriptLinkHoverSurface}" />
                    </Trigger>
                </Style.Triggers>
            </Style>

            <!-- Issue 5: Themed menu separator -->
            <!-- Fix: old Rectangle used {TemplateBinding Margin} inside a Height="1" container,
                 causing the margin to eat all available space and render the line at zero size.
                 Now: Border with BorderThickness="0,1,0,0" draws a single 1px top-edge line;
                 margin lives inside the template only (no double-application); LineColor is the
                 correct semantic token for divider lines in both Light and Dark themes. -->
            <Style x:Key="ThemedMenuSeparatorStyle" TargetType="Separator">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Separator">
                            <Border BorderThickness="0,1,0,0"
                                    Margin="4,2,4,2"
                                    BorderBrush="{DynamicResource LineColor}"/>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- Floating scroll-to-bottom button overlaid on the transcript RichTextBox -->
            <Style x:Key="ScrollToBottomButtonStyle" TargetType="Button">
                <Setter Property="Background"       Value="{DynamicResource CardSurface}"/>
                <Setter Property="Foreground"       Value="{DynamicResource LabelText}"/>
                <Setter Property="BorderBrush"      Value="{DynamicResource LineColor}"/>
                <Setter Property="BorderThickness"  Value="1"/>
                <Setter Property="Cursor"           Value="Hand"/>
                <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
                <!-- Non-focusable: prevents the button from stealing focus from the transcript
                     RichTextBox when clicked. If focus moves away from the RichTextBox, WPF
                     emits a scroll-to-caret event that sets IsUserScrolledAway=true before
                     ExecutePendingScrollToEnd fires, causing the deferred scroll to be skipped. -->
                <Setter Property="Focusable"        Value="False"/>
                <Setter Property="IsTabStop"        Value="False"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <Border x:Name="border"
                                    Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    CornerRadius="18"
                                    Width="36" Height="36"
                                    SnapsToDevicePixels="True">
                                <Border.Effect>
                                    <DropShadowEffect BlurRadius="8"
                                                      Opacity="0.18"
                                                      ShadowDepth="2"
                                                      Direction="270"
                                                      Color="#000000"/>
                                </Border.Effect>
                                <ContentPresenter HorizontalAlignment="Center"
                                                  VerticalAlignment="Center"/>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter TargetName="border" Property="Background"
                                            Value="{DynamicResource HoverSurface}"/>
                                </Trigger>
                                <Trigger Property="IsPressed" Value="True">
                                    <Setter TargetName="border" Property="Background"
                                            Value="{DynamicResource PanelSurface}"/>
                                </Trigger>
                                <Trigger Property="IsEnabled" Value="False">
                                    <Setter TargetName="border" Property="Opacity" Value="0.5"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- Caption button style (minimize / maximize-restore) -->
            <Style x:Key="CaptionButtonStyle" TargetType="Button">
                <Setter Property="Background" Value="Transparent"/>
                <Setter Property="Foreground" Value="{DynamicResource LabelText}"/>
                <Setter Property="BorderThickness" Value="0"/>
                <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
                <Setter Property="Cursor" Value="Arrow"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <Border x:Name="border"
                                    Background="{TemplateBinding Background}"
                                    BorderThickness="0">
                                <ContentPresenter HorizontalAlignment="Center"
                                                  VerticalAlignment="Center"
                                                  TextElement.Foreground="{TemplateBinding Foreground}"/>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter TargetName="border" Property="Background"
                                            Value="{DynamicResource CaptionButtonHover}"/>
                                </Trigger>
                                <Trigger Property="IsPressed" Value="True">
                                    <Setter TargetName="border" Property="Background"
                                            Value="{DynamicResource HoverSurface}"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- Caption close button style (red hover) -->
            <Style x:Key="CaptionCloseButtonStyle" TargetType="Button"
                   BasedOn="{StaticResource CaptionButtonStyle}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <Border x:Name="border"
                                    Background="{TemplateBinding Background}"
                                    BorderThickness="0">
                                <ContentPresenter x:Name="content"
                                                  HorizontalAlignment="Center"
                                                  VerticalAlignment="Center"
                                                  TextElement.Foreground="{TemplateBinding Foreground}"/>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter TargetName="border" Property="Background"
                                            Value="{DynamicResource CaptionCloseHover}"/>
                                    <Setter Property="Foreground"
                                            Value="{DynamicResource CaptionCloseHoverText}"/>
                                </Trigger>
                                <Trigger Property="IsPressed" Value="True">
                                    <Setter TargetName="border" Property="Background"
                                            Value="{DynamicResource CaptionCloseHover}"/>
                                    <Setter TargetName="border" Property="Opacity" Value="0.8"/>
                                    <Setter Property="Foreground"
                                            Value="{DynamicResource CaptionCloseHoverText}"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- Themed Expander: uses theme tokens for header text, arrow, and background.
                 Arrow rotates 90° when expanded. -->
            <Style x:Key="ThemedExpanderStyle" TargetType="Expander">
                <Setter Property="Foreground" Value="{DynamicResource SubtleText}"/>
                <Setter Property="Background" Value="{DynamicResource InputSurface}"/>
                <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Expander">
                            <StackPanel>
                                <Border x:Name="HeaderBorder"
                                        Background="Transparent"
                                        Padding="2,2,2,2"
                                        Cursor="Hand">
                                    <DockPanel LastChildFill="True">
                                        <Path x:Name="Arrow"
                                              DockPanel.Dock="Left"
                                              Data="M 1.5,3.5 Q 1.5,1.5 3.25,2.47 L 8.75,5.53 Q 10.5,6.5 8.75,7.47 L 3.25,10.53 Q 1.5,11.5 1.5,9.5 Z"
                                              Width="7" Height="9"
                                              Stretch="Fill"
                                              Opacity="0.6"
                                              Fill="{DynamicResource SubtleText}"
                                              VerticalAlignment="Center"
                                              Margin="0,0,6,0"
                                              RenderTransformOrigin="0.5,0.5">
                                            <Path.RenderTransform>
                                                <RotateTransform Angle="0"/>
                                            </Path.RenderTransform>
                                        </Path>
                                        <ContentPresenter ContentSource="Header"
                                                          VerticalAlignment="Center"
                                                          TextElement.FontSize="{DynamicResource FontSizeSmall}"
                                                          TextElement.Foreground="{DynamicResource LabelText}"/>
                                    </DockPanel>
                                </Border>
                                <ContentPresenter x:Name="ExpandSite"
                                                  Margin="0,2,0,0"
                                                  Visibility="Collapsed"/>
                            </StackPanel>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsExpanded" Value="True">
                                    <Setter TargetName="ExpandSite" Property="Visibility" Value="Visible"/>
                                    <Setter TargetName="Arrow" Property="RenderTransform">
                                        <Setter.Value>
                                            <RotateTransform Angle="90"/>
                                        </Setter.Value>
                                    </Setter>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- Themed RadioButton: draws a circle glyph using theme colors instead of the
                 default Windows system RadioButton which ignores app themes. -->
            <Style x:Key="ThemedRadioButtonStyle" TargetType="RadioButton">
                <Setter Property="Foreground"      Value="{DynamicResource LabelText}"/>
                <Setter Property="Background"      Value="Transparent"/>
                <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
                <Setter Property="Cursor"          Value="Hand"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="RadioButton">
                            <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                                <!-- Outer ring -->
                                <Grid Width="14" Height="14"
                                      VerticalAlignment="Center"
                                      Margin="0,0,6,0">
                                    <Ellipse x:Name="OuterRing"
                                             Width="14" Height="14"
                                             Stroke="{DynamicResource CheckBoxBorder}"
                                             StrokeThickness="1.5"
                                             Fill="Transparent"/>
                                    <!-- Inner fill dot (visible when checked) -->
                                    <Ellipse x:Name="InnerDot"
                                             Width="7" Height="7"
                                             Fill="{DynamicResource LabelText}"
                                             HorizontalAlignment="Center"
                                             VerticalAlignment="Center"
                                             Visibility="Collapsed"/>
                                </Grid>
                                <ContentPresenter VerticalAlignment="Center"
                                                  TextElement.Foreground="{TemplateBinding Foreground}"/>
                            </StackPanel>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsChecked" Value="True">
                                    <Setter TargetName="InnerDot" Property="Visibility" Value="Visible"/>
                                </Trigger>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter TargetName="OuterRing" Property="Opacity" Value="0.7"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <ControlTemplate x:Key="ThemedComboBoxToggleButtonTemplate" TargetType="{x:Type ToggleButton}">
                <Border x:Name="Border"
                        Background="{DynamicResource InputSurface}"
                        BorderBrush="{DynamicResource ChipBorder}"
                        BorderThickness="1"
                        CornerRadius="4">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="20"/>
                        </Grid.ColumnDefinitions>
                        <Border Grid.Column="0" Background="Transparent"/>
                        <Border Grid.Column="1" Background="Transparent">
                            <Path x:Name="ArrowPath"
                                  HorizontalAlignment="Center"
                                  VerticalAlignment="Center"
                                  Data="M 0 0 L 4 4 L 8 0 Z"
                                  Fill="{DynamicResource BodyText}"/>
                        </Border>
                    </Grid>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter TargetName="Border" Property="Background" Value="{DynamicResource HoverSurface}"/>
                    </Trigger>
                    <Trigger Property="IsChecked" Value="True">
                        <Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource LabelText}"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>

            <Style x:Key="ThemedComboBoxItemStyle" TargetType="{x:Type ComboBoxItem}">
                <Setter Property="OverridesDefaultStyle" Value="True"/>
                <Setter Property="SnapsToDevicePixels" Value="True"/>
                <Setter Property="Foreground" Value="{DynamicResource LabelText}"/>
                <Setter Property="Background" Value="Transparent"/>
                <Setter Property="Padding" Value="8,4"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ComboBoxItem}">
                            <Border x:Name="ItemBorder"
                                    Background="{TemplateBinding Background}"
                                    Padding="{TemplateBinding Padding}">
                                <ContentPresenter TextElement.Foreground="{TemplateBinding Foreground}"/>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter TargetName="ItemBorder" Property="Background" Value="{DynamicResource HoverSurface}"/>
                                </Trigger>
                                <Trigger Property="IsSelected" Value="True">
                                    <Setter TargetName="ItemBorder" Property="Background" Value="{DynamicResource ChipSelectedSurface}"/>
                                    <Setter Property="Foreground" Value="{DynamicResource LabelText}"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <Style x:Key="ThemedComboBoxStyle" TargetType="{x:Type ComboBox}" BasedOn="{x:Null}">
                <Setter Property="OverridesDefaultStyle" Value="True"/>
                <Setter Property="SnapsToDevicePixels" Value="True"/>
                <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
                <Setter Property="Foreground" Value="{DynamicResource LabelText}"/>
                <Setter Property="ItemContainerStyle" Value="{StaticResource ThemedComboBoxItemStyle}"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ComboBox}">
                            <Grid>
                                <ToggleButton x:Name="ToggleButton"
                                              OverridesDefaultStyle="True"
                                              Focusable="False"
                                              IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                                              ClickMode="Press"
                                              Template="{StaticResource ThemedComboBoxToggleButtonTemplate}"/>
                                <ContentPresenter x:Name="ContentSite"
                                                  IsHitTestVisible="False"
                                                  Content="{TemplateBinding SelectionBoxItem}"
                                                  ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
                                                  ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                                                  Margin="8,3,26,3"
                                                  VerticalAlignment="Center"
                                                  HorizontalAlignment="Left"
                                                  TextElement.Foreground="{DynamicResource LabelText}"/>
                                <Popup x:Name="Popup"
                                       Placement="Bottom"
                                       IsOpen="{TemplateBinding IsDropDownOpen}"
                                       AllowsTransparency="True"
                                       Focusable="False"
                                       PopupAnimation="Slide">
                                    <Grid x:Name="DropDown"
                                          SnapsToDevicePixels="True"
                                          MinWidth="{TemplateBinding ActualWidth}"
                                          MaxHeight="{TemplateBinding MaxDropDownHeight}">
                                        <Border x:Name="DropDownBorder"
                                                Background="{DynamicResource CardSurface}"
                                                BorderBrush="{DynamicResource ChipBorder}"
                                                BorderThickness="1"
                                                CornerRadius="4"/>
                                        <ScrollViewer Margin="1"
                                                      SnapsToDevicePixels="True"
                                                      Background="Transparent"
                                                      VerticalScrollBarVisibility="Auto"
                                                      HorizontalScrollBarVisibility="Disabled">
                                            <StackPanel IsItemsHost="True"
                                                        KeyboardNavigation.DirectionalNavigation="Contained"/>
                                        </ScrollViewer>
                                    </Grid>
                                </Popup>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- Left-side nav item for paged dialogs (e.g. Preferences).
                 Selected state is signalled by Tag="selected" set from code-behind. -->
            <Style x:Key="PrefsNavItemStyle" TargetType="Button">
                <Setter Property="Background" Value="Transparent"/>
                <Setter Property="Foreground" Value="{DynamicResource BodyText}"/>
                <Setter Property="BorderBrush" Value="Transparent"/>
                <Setter Property="BorderThickness" Value="0"/>
                <Setter Property="HorizontalContentAlignment" Value="Left"/>
                <Setter Property="Padding" Value="14,9"/>
                <Setter Property="Cursor" Value="Hand"/>
                <Setter Property="FontSize" Value="{DynamicResource FontSizeNormal}"/>
                <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <Border x:Name="border"
                                    Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    Padding="{TemplateBinding Padding}">
                                <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                  VerticalAlignment="Center"
                                                  TextElement.Foreground="{TemplateBinding Foreground}"/>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter TargetName="border" Property="Background" Value="{DynamicResource HoverSurface}"/>
                                </Trigger>
                                <Trigger Property="IsPressed" Value="True">
                                    <Setter TargetName="border" Property="Background" Value="{DynamicResource AppSurface}"/>
                                </Trigger>
                                <DataTrigger Binding="{Binding Tag, RelativeSource={RelativeSource Self}}" Value="selected">
                                    <Setter TargetName="border" Property="Background" Value="{DynamicResource AppSurface}"/>
                                    <Setter Property="Foreground" Value="{DynamicResource ImportantText}"/>
                                    <Setter Property="FontWeight" Value="SemiBold"/>
                                </DataTrigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>


            <!-- ── Themed TabItem ──────────────────────────────────────────────────
                 Tint-aware 3px accent bar at the top of the selected tab.
                 Inactive tabs use ChromeSurface + SubtleText; hover uses HoverSurface.
                 Selected tab uses AppSurface so it visually connects to the content area. -->
            <Style x:Key="ThemedTabItemStyle" TargetType="TabItem">
                <Setter Property="Background"       Value="{DynamicResource ChromeSurface}"/>
                <Setter Property="Foreground"       Value="{DynamicResource SubtleText}"/>
                <Setter Property="BorderBrush"      Value="{DynamicResource InputBorder}"/>
                <Setter Property="BorderThickness"  Value="1"/>
                <Setter Property="Padding"          Value="12,6"/>
                <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
                <Setter Property="FontSize"         Value="{DynamicResource FontSizeBody}"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="TabItem">
                            <Grid x:Name="Root" Margin="0,0,2,0" SnapsToDevicePixels="True">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="3"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>
                                <!-- Tint-aware accent top bar (visible on selected tab only) -->
                                <Rectangle x:Name="AccentBar"
                                           Grid.Row="0"
                                           Fill="{DynamicResource QueueTabActiveBorder}"
                                           RadiusX="2" RadiusY="2"
                                           Visibility="Collapsed"/>
                                <!-- Tab background spans both rows -->
                                <Border x:Name="TabBorder"
                                        Grid.Row="0" Grid.RowSpan="2"
                                        Background="{TemplateBinding Background}"
                                        BorderBrush="{TemplateBinding BorderBrush}"
                                        BorderThickness="1,0,1,0"
                                        CornerRadius="3,3,0,0"/>
                                <!-- Header text below the 3px accent row -->
                                <ContentPresenter Grid.Row="1"
                                                  ContentSource="Header"
                                                  HorizontalAlignment="Center"
                                                  VerticalAlignment="Center"
                                                  Margin="{TemplateBinding Padding}"
                                                  TextElement.Foreground="{TemplateBinding Foreground}"/>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsSelected" Value="True">
                                    <Setter TargetName="AccentBar" Property="Visibility" Value="Visible"/>
                                    <Setter TargetName="TabBorder" Property="Background" Value="{DynamicResource AppSurface}"/>
                                    <Setter TargetName="Root"      Property="Margin"     Value="0,0,2,-1"/>
                                    <Setter Property="Foreground"  Value="{DynamicResource LabelText}"/>
                                    <Setter Property="FontWeight"  Value="SemiBold"/>
                                </Trigger>
                                <MultiTrigger>
                                    <MultiTrigger.Conditions>
                                        <Condition Property="IsSelected"   Value="False"/>
                                        <Condition Property="IsMouseOver"  Value="True"/>
                                    </MultiTrigger.Conditions>
                                    <Setter TargetName="TabBorder" Property="Background" Value="{DynamicResource HoverSurface}"/>
                                    <Setter Property="Foreground"  Value="{DynamicResource BodyText}"/>
                                </MultiTrigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- ── Themed TabControl ──────────────────────────────────────────────
                 ChromeSurface tab strip with a 1px InputBorder bottom line;
                 content area uses AppSurface. Pair with ThemedTabItemStyle. -->
            <Style x:Key="ThemedTabControlStyle" TargetType="TabControl">
                <Setter Property="Background"      Value="{DynamicResource AppSurface}"/>
                <Setter Property="BorderBrush"     Value="{DynamicResource InputBorder}"/>
                <Setter Property="BorderThickness" Value="0"/>
                <Setter Property="Padding"         Value="0"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="TabControl">
                            <Grid SnapsToDevicePixels="True">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>
                                <!-- Tab strip -->
                                <Border Grid.Row="0"
                                        Background="{DynamicResource ChromeSurface}"
                                        BorderBrush="{DynamicResource InputBorder}"
                                        BorderThickness="0,0,0,1">
                                    <TabPanel x:Name="HeaderPanel"
                                              IsItemsHost="True"
                                              Background="Transparent"
                                              Margin="6,4,0,0"/>
                                </Border>
                                <!-- Content area -->
                                <Border Grid.Row="1"
                                        Background="{TemplateBinding Background}"
                                        BorderBrush="{TemplateBinding BorderBrush}"
                                        BorderThickness="{TemplateBinding BorderThickness}">
                                    <ContentPresenter x:Name="PART_SelectedContentHost"
                                                      ContentSource="SelectedContent"/>
                                </Border>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

        </ResourceDictionary>
    </Application.Resources>
</Application>
