<Window x:Class="AxCopilot.Views.StatisticsWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="clr-namespace:AxCopilot.ViewModels"
        Title="AX Copilot — 사용 통계"
        Width="800" Height="900"
        MinWidth="680" MinHeight="700"
        WindowStyle="None"
        AllowsTransparency="True"
        UseLayoutRounding="True"
        SnapsToDevicePixels="True"
        Background="Transparent"
        ResizeMode="CanResize"
        WindowStartupLocation="CenterScreen"
        ShowInTaskbar="True"
        Topmost="False"
        Icon="pack://application:,,,/Assets/icon.ico"
        MouseDown="Window_MouseDown">

    <Grid Margin="20">
        <Border CornerRadius="20" Background="White">
            <Border.Effect>
                <DropShadowEffect Color="Black" BlurRadius="22" ShadowDepth="4" Opacity="0.24"/>
            </Border.Effect>
        </Border>
        <Border Background="White" CornerRadius="20" ClipToBounds="True">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="64"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>

                <!-- ══ 헤더 ══ -->
                <Border Grid.Row="0" CornerRadius="20,20,0,0">
                    <Border.Background>
                        <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                            <GradientStop Color="#1A1B2E" Offset="0"/>
                            <GradientStop Color="#2B2D5B" Offset="0.5"/>
                            <GradientStop Color="#3B4ECC" Offset="1"/>
                        </LinearGradientBrush>
                    </Border.Background>
                    <Grid Margin="24,0">
                        <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                            <TextBlock Text="&#xE9D9;" FontFamily="Segoe MDL2 Assets"
                                       FontSize="18" Foreground="#88AAFFCC"
                                       VerticalAlignment="Center" Margin="0,0,12,0"/>
                            <TextBlock Text="사용 통계" FontSize="17" FontWeight="SemiBold"
                                       Foreground="White" VerticalAlignment="Center"/>
                            <TextBlock Text="최근 30일" FontSize="11" Foreground="#6688BBCC"
                                       VerticalAlignment="Center" Margin="12,0,0,0"/>
                        </StackPanel>
                        <!-- 닫기 + 새로고침 -->
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center">
                            <Button Width="32" Height="32" Background="Transparent" BorderThickness="0"
                                    Cursor="Hand" Click="Refresh_Click" ToolTip="새로고침">
                                <Button.Template>
                                    <ControlTemplate TargetType="Button">
                                        <Border x:Name="Bd" CornerRadius="8" Background="Transparent">
                                            <TextBlock Text="&#xE72C;" FontFamily="Segoe MDL2 Assets"
                                                       FontSize="13" Foreground="#88AAFFCC"
                                                       HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                        </Border>
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="IsMouseOver" Value="True">
                                                <Setter TargetName="Bd" Property="Background" Value="#22FFFFFF"/>
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Button.Template>
                            </Button>
                            <Button Width="32" Height="32" Background="Transparent" BorderThickness="0"
                                    Cursor="Hand" Click="Close_Click">
                                <Button.Template>
                                    <ControlTemplate TargetType="Button">
                                        <Border x:Name="Bd" CornerRadius="8" Background="Transparent">
                                            <TextBlock Text="&#xE711;" FontFamily="Segoe MDL2 Assets"
                                                       FontSize="11" Foreground="#88AAFFCC"
                                                       HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                        </Border>
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="IsMouseOver" Value="True">
                                                <Setter TargetName="Bd" Property="Background" Value="#22FFFFFF"/>
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Button.Template>
                            </Button>
                        </StackPanel>
                    </Grid>
                </Border>

                <!-- ══ 본문 ══ -->
                <Grid Grid.Row="1">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>

                    <!-- 탭 헤더 -->
                    <Border Grid.Row="0" Background="#F0F2F8" Padding="4" Margin="20,12,20,0" CornerRadius="10">
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                            <RadioButton x:Name="StatsTabMain" Content="메인" IsChecked="True"
                                         GroupName="StatsTab" Click="StatsTab_Click">
                                <RadioButton.Style>
                                    <Style TargetType="RadioButton">
                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="RadioButton">
                                                    <Border x:Name="Bd" CornerRadius="8" Padding="16,7" Cursor="Hand" Background="Transparent">
                                                        <TextBlock x:Name="Tb" Text="{TemplateBinding Content}" FontSize="12" FontWeight="SemiBold" Foreground="#8888AA" HorizontalAlignment="Center"/>
                                                    </Border>
                                                    <ControlTemplate.Triggers>
                                                        <Trigger Property="IsChecked" Value="True">
                                                            <Setter TargetName="Bd" Property="Background" Value="White"/>
                                                            <Setter TargetName="Tb" Property="Foreground" Value="#1A1B2E"/>
                                                        </Trigger>
                                                    </ControlTemplate.Triggers>
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </RadioButton.Style>
                            </RadioButton>
                            <RadioButton x:Name="StatsTabCommander" Content="AX Commander"
                                         GroupName="StatsTab" Click="StatsTab_Click"
                                         Style="{Binding Style, ElementName=StatsTabMain}"/>
                            <RadioButton x:Name="StatsTabAgent" Content="AX Agent"
                                         GroupName="StatsTab" Click="StatsTab_Click"
                                         Style="{Binding Style, ElementName=StatsTabMain}"/>
                        </StackPanel>
                    </Border>

                    <!-- ═══ 메인 탭 ═══ -->
                    <ScrollViewer x:Name="PanelMain" Grid.Row="1" VerticalScrollBarVisibility="Auto"
                                  HorizontalScrollBarVisibility="Disabled">
                    <StackPanel Margin="24,14,24,24">

                        <!-- ── 요약 카드 4개 ── -->
                        <Grid Margin="0,0,0,20">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="8"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="8"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="8"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>

                            <!-- 오늘 -->
                            <Border Grid.Column="0" Background="#F5F7FF" CornerRadius="12" Padding="12,11">
                                <StackPanel>
                                    <StackPanel Orientation="Horizontal" Margin="0,0,0,5">
                                        <TextBlock Text="&#xE8D1;" FontFamily="Segoe MDL2 Assets"
                                                   FontSize="11" Foreground="#4B5EFC" Margin="0,0,5,0" VerticalAlignment="Center"/>
                                        <TextBlock Text="오늘" FontSize="11" FontWeight="SemiBold" Foreground="#4B5EFC" VerticalAlignment="Center"/>
                                    </StackPanel>
                                    <TextBlock Text="{Binding TodayDate}" FontSize="10" Foreground="#9999BB"
                                               Margin="0,0,0,2"/>
                                    <TextBlock Text="{Binding TodaySummary}" FontSize="12" Foreground="#333355"
                                               TextWrapping="Wrap" LineHeight="18"/>
                                </StackPanel>
                            </Border>

                            <!-- 이번 주 -->
                            <Border Grid.Column="2" Background="#F0FFF5" CornerRadius="12" Padding="12,11">
                                <StackPanel>
                                    <StackPanel Orientation="Horizontal" Margin="0,0,0,5">
                                        <TextBlock Text="&#xE787;" FontFamily="Segoe MDL2 Assets"
                                                   FontSize="11" Foreground="#107C10" Margin="0,0,5,0" VerticalAlignment="Center"/>
                                        <TextBlock Text="주간" FontSize="11" FontWeight="SemiBold" Foreground="#107C10" VerticalAlignment="Center"/>
                                    </StackPanel>
                                    <TextBlock Text="{Binding WeekSummary}" FontSize="12" Foreground="#333355"
                                               TextWrapping="Wrap"/>
                                </StackPanel>
                            </Border>

                            <!-- 역대 최고 -->
                            <Border Grid.Column="4" Background="#FFFBF0" CornerRadius="12" Padding="12,11">
                                <StackPanel>
                                    <StackPanel Orientation="Horizontal" Margin="0,0,0,5">
                                        <TextBlock Text="&#xE734;" FontFamily="Segoe MDL2 Assets"
                                                   FontSize="11" Foreground="#C09010" Margin="0,0,5,0" VerticalAlignment="Center"/>
                                        <TextBlock Text="최고 기록" FontSize="11" FontWeight="SemiBold" Foreground="#C09010" VerticalAlignment="Center"/>
                                    </StackPanel>
                                    <TextBlock Text="{Binding PeakDate}" FontSize="10" Foreground="#9999BB"
                                               Margin="0,0,0,2"/>
                                    <TextBlock Text="{Binding PeakDaySummary}" FontSize="12" Foreground="#333355"
                                               TextWrapping="Wrap"/>
                                </StackPanel>
                            </Border>

                            <!-- 30일 합계 -->
                            <Border Grid.Column="6" Background="#FFF0FF" CornerRadius="12" Padding="12,11">
                                <StackPanel>
                                    <StackPanel Orientation="Horizontal" Margin="0,0,0,5">
                                        <TextBlock Text="&#xE9D9;" FontFamily="Segoe MDL2 Assets"
                                                   FontSize="11" Foreground="#8B2FC9" Margin="0,0,5,0" VerticalAlignment="Center"/>
                                        <TextBlock Text="30일" FontSize="11" FontWeight="SemiBold" Foreground="#8B2FC9" VerticalAlignment="Center"/>
                                    </StackPanel>
                                    <TextBlock Text="{Binding TotalOpensSummary}" FontSize="12" Foreground="#333355"
                                               TextWrapping="Wrap"/>
                                </StackPanel>
                            </Border>
                        </Grid>

                        <!-- ── 메인: AX Commander 14일 활동 ── -->
                        <Border Background="#F9FAFF" CornerRadius="14" Padding="18,12" Margin="0,0,0,14">
                            <StackPanel>
                                <StackPanel Orientation="Horizontal" Margin="0,0,0,10">
                                    <TextBlock Text="&#xE721;" FontFamily="Segoe MDL2 Assets"
                                               FontSize="13" Foreground="#4B5EFC" VerticalAlignment="Center" Margin="0,0,8,0"/>
                                    <TextBlock Text="AX Commander 호출 (14일)" FontSize="12" FontWeight="SemiBold"
                                               Foreground="#1A1B2E" VerticalAlignment="Center"/>
                                </StackPanel>
                                <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
                                    <ItemsControl ItemsSource="{Binding LauncherOpenBars}">
                                        <ItemsControl.ItemsPanel>
                                            <ItemsPanelTemplate><StackPanel Orientation="Horizontal"/></ItemsPanelTemplate>
                                        </ItemsControl.ItemsPanel>
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate DataType="{x:Type vm:DayBarItem}">
                                                <StackPanel Width="38" Margin="1,0" ToolTip="{Binding ToolTipText}">
                                                    <TextBlock Text="{Binding ValueLabel}" FontSize="8" Foreground="#9999BB"
                                                               HorizontalAlignment="Center" Margin="0,0,0,1"/>
                                                    <Border Height="52" VerticalAlignment="Bottom">
                                                        <Border CornerRadius="3,3,0,0" VerticalAlignment="Bottom"
                                                                Width="20"
                                                                Height="{Binding BarHeight}">
                                                            <Border.Style>
                                                                <Style TargetType="Border">
                                                                    <Setter Property="Background" Value="#4B5EFC"/>
                                                                    <Style.Triggers>
                                                                        <DataTrigger Binding="{Binding IsToday}" Value="True">
                                                                            <Setter Property="Background" Value="#5C6EFF"/>
                                                                        </DataTrigger>
                                                                        <DataTrigger Binding="{Binding HasData}" Value="False">
                                                                            <Setter Property="Background" Value="#EEEEF8"/>
                                                                        </DataTrigger>
                                                                    </Style.Triggers>
                                                                </Style>
                                                            </Border.Style>
                                                        </Border>
                                                    </Border>
                                                    <TextBlock Text="{Binding DayLabel}" FontSize="9" Foreground="#6B7280"
                                                               HorizontalAlignment="Center" Margin="0,2,0,0"/>
                                                </StackPanel>
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                    </ItemsControl>
                                </ScrollViewer>
                            </StackPanel>
                        </Border>

                        <!-- ── 메인: AX Agent 14일 대화 ── -->
                        <Border Background="#F0F4FF" CornerRadius="14" Padding="18,12" Margin="0,0,0,14">
                            <StackPanel>
                                <StackPanel Orientation="Horizontal" Margin="0,0,0,10">
                                    <TextBlock Text="&#xE8BD;" FontFamily="Segoe MDL2 Assets"
                                               FontSize="13" Foreground="#818CF8" VerticalAlignment="Center" Margin="0,0,8,0"/>
                                    <TextBlock Text="AX Agent 대화 (14일)" FontSize="12" FontWeight="SemiBold"
                                               Foreground="#1A1B2E" VerticalAlignment="Center"/>
                                </StackPanel>
                                <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
                                    <ItemsControl ItemsSource="{Binding ChatCountBars}">
                                        <ItemsControl.ItemsPanel>
                                            <ItemsPanelTemplate><StackPanel Orientation="Horizontal"/></ItemsPanelTemplate>
                                        </ItemsControl.ItemsPanel>
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate DataType="{x:Type vm:DayBarItem}">
                                                <StackPanel Width="38" Margin="1,0" ToolTip="{Binding ToolTipText}">
                                                    <TextBlock Text="{Binding ValueLabel}" FontSize="8" Foreground="#818CF8"
                                                               HorizontalAlignment="Center" Margin="0,0,0,1"/>
                                                    <Border Height="52" VerticalAlignment="Bottom">
                                                        <Border CornerRadius="3,3,0,0" VerticalAlignment="Bottom"
                                                                Width="20"
                                                                Height="{Binding BarHeight}">
                                                            <Border.Style>
                                                                <Style TargetType="Border">
                                                                    <Setter Property="Background" Value="#818CF8"/>
                                                                    <Style.Triggers>
                                                                        <DataTrigger Binding="{Binding IsToday}" Value="True">
                                                                            <Setter Property="Background" Value="#4B5EFC"/>
                                                                        </DataTrigger>
                                                                        <DataTrigger Binding="{Binding HasData}" Value="False">
                                                                            <Setter Property="Background" Value="#E5E7EB"/>
                                                                        </DataTrigger>
                                                                    </Style.Triggers>
                                                                </Style>
                                                            </Border.Style>
                                                        </Border>
                                                    </Border>
                                                    <TextBlock Text="{Binding DayLabel}" FontSize="9" Foreground="#6B7280"
                                                               HorizontalAlignment="Center" Margin="0,2,0,0"/>
                                                </StackPanel>
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                    </ItemsControl>
                                </ScrollViewer>
                            </StackPanel>
                        </Border>

                    </StackPanel>
                    </ScrollViewer>

                    <!-- ═══ AX Commander 탭 ═══ -->
                    <ScrollViewer x:Name="PanelCommander" Grid.Row="1" VerticalScrollBarVisibility="Auto"
                                  HorizontalScrollBarVisibility="Disabled" Visibility="Collapsed">
                    <StackPanel Margin="24,14,24,24">

                        <!-- ── 런처 호출 횟수 차트 ── -->
                        <Border Background="#F9FAFF" CornerRadius="14" Padding="18,12" Margin="0,0,0,14">
                            <StackPanel>
                                <StackPanel Orientation="Horizontal" Margin="0,0,0,14">
                                    <TextBlock Text="&#xE721;" FontFamily="Segoe MDL2 Assets"
                                               FontSize="14" Foreground="#4B5EFC" VerticalAlignment="Center" Margin="0,0,8,0"/>
                                    <TextBlock Text="AX Commander 호출 횟수 (최근 14일)" FontSize="13" FontWeight="SemiBold"
                                               Foreground="#1A1B2E" VerticalAlignment="Center"/>
                                </StackPanel>
                                <!-- 차트 영역 -->
                                <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
                                    <ItemsControl ItemsSource="{Binding LauncherOpenBars}">
                                        <ItemsControl.ItemsPanel>
                                            <ItemsPanelTemplate>
                                                <StackPanel Orientation="Horizontal"/>
                                            </ItemsPanelTemplate>
                                        </ItemsControl.ItemsPanel>
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate DataType="{x:Type vm:DayBarItem}">
                                                <Grid Width="42" Height="88" VerticalAlignment="Bottom" Margin="1,0"
                                                      ToolTip="{Binding ToolTipText, TargetNullValue={x:Null}}"
                                                      ToolTipService.IsEnabled="{Binding HasData}">
                                                    <!-- 값 레이블 -->
                                                    <TextBlock Text="{Binding ValueLabel}"
                                                               FontSize="9" Foreground="#9999BB"
                                                               HorizontalAlignment="Center"
                                                               VerticalAlignment="Top"/>
                                                    <!-- 막대 -->
                                                    <Border CornerRadius="4,4,0,0"
                                                            HorizontalAlignment="Center"
                                                            VerticalAlignment="Bottom"
                                                            Width="24"
                                                            Height="{Binding BarHeight}"
                                                            Margin="0,0,0,18">
                                                        <Border.Background>
                                                            <SolidColorBrush>
                                                                <SolidColorBrush.Color>
                                                                    <Color A="255" R="75" G="94" B="252"/>
                                                                </SolidColorBrush.Color>
                                                            </SolidColorBrush>
                                                        </Border.Background>
                                                        <Border.Style>
                                                            <Style TargetType="Border">
                                                                <Style.Triggers>
                                                                    <DataTrigger Binding="{Binding IsToday}" Value="True">
                                                                        <Setter Property="Background" Value="#FF5C6EFF"/>
                                                                    </DataTrigger>
                                                                    <DataTrigger Binding="{Binding HasData}" Value="False">
                                                                        <Setter Property="Background" Value="#EEEEF8"/>
                                                                    </DataTrigger>
                                                                </Style.Triggers>
                                                            </Style>
                                                        </Border.Style>
                                                    </Border>
                                                    <!-- 날짜 레이블 -->
                                                    <StackPanel VerticalAlignment="Bottom" HorizontalAlignment="Center">
                                                        <TextBlock Text="{Binding DayLabel}"
                                                                   FontSize="10" Foreground="#6B7280"
                                                                   HorizontalAlignment="Center"/>
                                                        <TextBlock Text="{Binding DateLabel}"
                                                                   FontSize="8" Foreground="#9CA3AF"
                                                                   HorizontalAlignment="Center"/>
                                                    </StackPanel>
                                                </Grid>
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                    </ItemsControl>
                                </ScrollViewer>
                            </StackPanel>
                        </Border>

                        <!-- ── PC 활성 시간 차트 ── -->
                        <Border Background="#F9FAFF" CornerRadius="14" Padding="18,12" Margin="0,0,0,14">
                            <StackPanel>
                                <StackPanel Orientation="Horizontal" Margin="0,0,0,14">
                                    <TextBlock Text="&#xE916;" FontFamily="Segoe MDL2 Assets"
                                               FontSize="14" Foreground="#107C10" VerticalAlignment="Center" Margin="0,0,8,0"/>
                                    <TextBlock Text="PC 활성 시간 (최근 14일)" FontSize="13" FontWeight="SemiBold"
                                               Foreground="#1A1B2E" VerticalAlignment="Center"/>
                                    <TextBlock Text="  ·  잠금 해제 후 활동 시간" FontSize="11"
                                               Foreground="#AAAACC" VerticalAlignment="Center"/>
                                </StackPanel>
                                <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
                                    <ItemsControl ItemsSource="{Binding ActiveTimeBars}">
                                        <ItemsControl.ItemsPanel>
                                            <ItemsPanelTemplate>
                                                <StackPanel Orientation="Horizontal"/>
                                            </ItemsPanelTemplate>
                                        </ItemsControl.ItemsPanel>
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate DataType="{x:Type vm:DayBarItem}">
                                                <Grid Width="42" Height="88" VerticalAlignment="Bottom" Margin="1,0"
                                                      ToolTip="{Binding ToolTipText, TargetNullValue={x:Null}}"
                                                      ToolTipService.IsEnabled="{Binding HasData}">
                                                    <TextBlock Text="{Binding ValueLabel}"
                                                               FontSize="8" Foreground="#9999BB"
                                                               HorizontalAlignment="Center"
                                                               VerticalAlignment="Top"
                                                               TextTrimming="CharacterEllipsis"/>
                                                    <Border CornerRadius="4,4,0,0"
                                                            HorizontalAlignment="Center"
                                                            VerticalAlignment="Bottom"
                                                            Width="24"
                                                            Height="{Binding BarHeight}"
                                                            Margin="0,0,0,18">
                                                        <Border.Style>
                                                            <Style TargetType="Border">
                                                                <Setter Property="Background" Value="#107C10"/>
                                                                <Style.Triggers>
                                                                    <DataTrigger Binding="{Binding IsToday}" Value="True">
                                                                        <Setter Property="Background" Value="#15A815"/>
                                                                    </DataTrigger>
                                                                    <DataTrigger Binding="{Binding HasData}" Value="False">
                                                                        <Setter Property="Background" Value="#EEEEF8"/>
                                                                    </DataTrigger>
                                                                </Style.Triggers>
                                                            </Style>
                                                        </Border.Style>
                                                    </Border>
                                                    <StackPanel VerticalAlignment="Bottom" HorizontalAlignment="Center">
                                                        <TextBlock Text="{Binding DayLabel}"
                                                                   FontSize="10" Foreground="#6B7280"
                                                                   HorizontalAlignment="Center"/>
                                                        <TextBlock Text="{Binding DateLabel}"
                                                                   FontSize="8" Foreground="#9CA3AF"
                                                                   HorizontalAlignment="Center"/>
                                                    </StackPanel>
                                                </Grid>
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                    </ItemsControl>
                                </ScrollViewer>
                            </StackPanel>
                        </Border>

                        <!-- ── 인기 명령어 ── -->
                        <Border Background="#F9FAFF" CornerRadius="14" Padding="18,14" Margin="0,0,0,14">
                            <StackPanel>
                                <StackPanel Orientation="Horizontal" Margin="0,0,0,14">
                                    <TextBlock Text="&#xE762;" FontFamily="Segoe MDL2 Assets"
                                               FontSize="14" Foreground="#8B2FC9" VerticalAlignment="Center" Margin="0,0,8,0"/>
                                    <TextBlock Text="자주 쓴 명령어 (최근 30일)" FontSize="13" FontWeight="SemiBold"
                                               Foreground="#1A1B2E" VerticalAlignment="Center"/>
                                </StackPanel>
                                <ItemsControl ItemsSource="{Binding TopCommands}">
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate DataType="{x:Type vm:CommandStatItem}">
                                            <Grid Margin="0,0,0,8">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="22"/>
                                                    <ColumnDefinition Width="140"/>
                                                    <ColumnDefinition Width="*"/>
                                                    <ColumnDefinition Width="44"/>
                                                </Grid.ColumnDefinitions>
                                                <!-- 순위 -->
                                                <TextBlock Grid.Column="0" Text="{Binding Rank}"
                                                           FontSize="11" FontWeight="Bold" Foreground="#BBBBCC"
                                                           VerticalAlignment="Center"/>
                                                <!-- 명령어 -->
                                                <TextBlock Grid.Column="1" Text="{Binding Command}"
                                                           FontSize="12" FontFamily="Consolas"
                                                           Foreground="#2B3280" FontWeight="SemiBold"
                                                           VerticalAlignment="Center" TextTrimming="CharacterEllipsis"/>
                                                <!-- 진행 바 -->
                                                <Border Grid.Column="2" Height="8" CornerRadius="4"
                                                        Background="#EEEEF8" VerticalAlignment="Center">
                                                    <Border CornerRadius="4" Background="#8B2FC9"
                                                            HorizontalAlignment="Left"
                                                            Width="{Binding BarWidth}"/>
                                                </Border>
                                                <!-- 횟수 -->
                                                <TextBlock Grid.Column="3" Text="{Binding Count}"
                                                           FontSize="11" Foreground="#9999BB"
                                                           HorizontalAlignment="Right"
                                                           VerticalAlignment="Center"/>
                                            </Grid>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                                <!-- 데이터 없을 때 -->
                                <TextBlock FontSize="12" Foreground="#AAAACC"
                                           HorizontalAlignment="Center" Margin="0,8">
                                    <TextBlock.Style>
                                        <Style TargetType="TextBlock">
                                            <Setter Property="Visibility" Value="Collapsed"/>
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding TopCommands.Count}" Value="0">
                                                    <Setter Property="Visibility" Value="Visible"/>
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </TextBlock.Style>
                                    아직 명령어 사용 데이터가 없습니다.
                                </TextBlock>
                            </StackPanel>
                        </Border>

                        <!-- ── 요일별 평균 호출 패턴 ── -->
                        <Border Background="#F5F7FF" CornerRadius="14" Padding="18,14" Margin="0,0,0,14">
                            <StackPanel>
                                <StackPanel Orientation="Horizontal" Margin="0,0,0,14">
                                    <TextBlock Text="&#xE787;" FontFamily="Segoe MDL2 Assets"
                                               FontSize="14" Foreground="#6366F1" VerticalAlignment="Center" Margin="0,0,8,0"/>
                                    <TextBlock Text="요일별 평균 호출 (30일)" FontSize="13" FontWeight="SemiBold"
                                               Foreground="#1A1B2E" VerticalAlignment="Center"/>
                                    <TextBlock Text="  ·  어느 요일에 가장 활발한지" FontSize="11"
                                               Foreground="#AAAACC" VerticalAlignment="Center"/>
                                </StackPanel>
                                <ItemsControl ItemsSource="{Binding WeekdayAvgBars}">
                                    <ItemsControl.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center"/>
                                        </ItemsPanelTemplate>
                                    </ItemsControl.ItemsPanel>
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate DataType="{x:Type vm:DayBarItem}">
                                            <Grid Width="60" Height="100" VerticalAlignment="Bottom" Margin="4,0"
                                                  ToolTip="{Binding ToolTipText}">
                                                <!-- 값 레이블 -->
                                                <TextBlock Text="{Binding ValueLabel}"
                                                           FontSize="10" Foreground="#6366F1" FontWeight="SemiBold"
                                                           HorizontalAlignment="Center" VerticalAlignment="Top"/>
                                                <!-- 막대 -->
                                                <Border CornerRadius="6,6,0,0"
                                                        HorizontalAlignment="Center"
                                                        VerticalAlignment="Bottom"
                                                        Width="36"
                                                        Height="{Binding BarHeight}"
                                                        Margin="0,0,0,22">
                                                    <Border.Style>
                                                        <Style TargetType="Border">
                                                            <Setter Property="Background" Value="#C7D2FE"/>
                                                            <Style.Triggers>
                                                                <DataTrigger Binding="{Binding IsToday}" Value="True">
                                                                    <Setter Property="Background" Value="#6366F1"/>
                                                                </DataTrigger>
                                                                <DataTrigger Binding="{Binding HasData}" Value="False">
                                                                    <Setter Property="Background" Value="#EEEEF8"/>
                                                                </DataTrigger>
                                                            </Style.Triggers>
                                                        </Style>
                                                    </Border.Style>
                                                </Border>
                                                <!-- 요일 레이블 -->
                                                <TextBlock Text="{Binding DayLabel}"
                                                           FontSize="12" FontWeight="SemiBold"
                                                           HorizontalAlignment="Center" VerticalAlignment="Bottom">
                                                    <TextBlock.Style>
                                                        <Style TargetType="TextBlock">
                                                            <Setter Property="Foreground" Value="#9CA3AF"/>
                                                            <Style.Triggers>
                                                                <DataTrigger Binding="{Binding IsToday}" Value="True">
                                                                    <Setter Property="Foreground" Value="#6366F1"/>
                                                                </DataTrigger>
                                                            </Style.Triggers>
                                                        </Style>
                                                    </TextBlock.Style>
                                                </TextBlock>
                                            </Grid>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                            </StackPanel>
                        </Border>

                    </StackPanel>
                    </ScrollViewer>

                    <!-- ═══ AX Agent 탭 ═══ -->
                    <ScrollViewer x:Name="PanelAgent" Grid.Row="1" VerticalScrollBarVisibility="Auto"
                                  HorizontalScrollBarVisibility="Disabled" Visibility="Collapsed">
                    <StackPanel Margin="24,14,24,24">

                        <!-- ── AX Agent 대화 빈도 (탭별) ── -->
                        <Border Background="#F0F4FF" CornerRadius="14" Padding="18,16" Margin="0,0,0,14">
                            <StackPanel>
                                <StackPanel Orientation="Horizontal" Margin="0,0,0,6">
                                    <TextBlock Text="&#xE8BD;" FontFamily="Segoe MDL2 Assets"
                                               FontSize="14" Foreground="#4B5EFC" VerticalAlignment="Center" Margin="0,0,8,0"/>
                                    <TextBlock Text="AX Agent 대화 빈도 (최근 14일)" FontSize="13" FontWeight="SemiBold"
                                               Foreground="#1A1B2E" VerticalAlignment="Center"/>
                                </StackPanel>
                                <TextBlock Text="{Binding AgentSummary}" FontSize="11" Foreground="#6B7280" Margin="0,0,0,10"/>
                                <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
                                    <ItemsControl ItemsSource="{Binding ChatCountBars}">
                                        <ItemsControl.ItemsPanel>
                                            <ItemsPanelTemplate><StackPanel Orientation="Horizontal"/></ItemsPanelTemplate>
                                        </ItemsControl.ItemsPanel>
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate DataType="{x:Type vm:DayBarItem}">
                                                <StackPanel Width="42" Margin="2,0" ToolTip="{Binding ToolTipText}">
                                                    <TextBlock Text="{Binding ValueLabel}" FontSize="9" Foreground="#4B5EFC"
                                                               HorizontalAlignment="Center" Margin="0,0,0,2"/>
                                                    <Border Height="88" VerticalAlignment="Bottom" CornerRadius="4,4,0,0">
                                                        <Border CornerRadius="4,4,0,0" VerticalAlignment="Bottom"
                                                                Height="{Binding BarHeight}">
                                                            <Border.Style>
                                                                <Style TargetType="Border">
                                                                    <Setter Property="Background" Value="#818CF8"/>
                                                                    <Style.Triggers>
                                                                        <DataTrigger Binding="{Binding IsToday}" Value="True">
                                                                            <Setter Property="Background" Value="#4B5EFC"/>
                                                                        </DataTrigger>
                                                                        <DataTrigger Binding="{Binding HasData}" Value="False">
                                                                            <Setter Property="Background" Value="#E5E7EB"/>
                                                                        </DataTrigger>
                                                                    </Style.Triggers>
                                                                </Style>
                                                            </Border.Style>
                                                        </Border>
                                                    </Border>
                                                    <TextBlock Text="{Binding DayLabel}" FontSize="10" Foreground="#6B7280"
                                                               HorizontalAlignment="Center" Margin="0,4,0,0"/>
                                                    <TextBlock Text="{Binding DateLabel}" FontSize="8" Foreground="#9CA3AF"
                                                               HorizontalAlignment="Center"/>
                                                </StackPanel>
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                    </ItemsControl>
                                </ScrollViewer>
                            </StackPanel>
                        </Border>

                        <!-- ── AX Agent 토큰 사용량 ── -->
                        <Border Background="#FFF7ED" CornerRadius="14" Padding="18,16" Margin="0,0,0,14">
                            <StackPanel>
                                <StackPanel Orientation="Horizontal" Margin="0,0,0,14">
                                    <TextBlock Text="&#xE9D9;" FontFamily="Segoe MDL2 Assets"
                                               FontSize="14" Foreground="#D97706" VerticalAlignment="Center" Margin="0,0,8,0"/>
                                    <TextBlock Text="토큰 사용량 (최근 14일)" FontSize="13" FontWeight="SemiBold"
                                               Foreground="#1A1B2E" VerticalAlignment="Center"/>
                                </StackPanel>
                                <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
                                    <ItemsControl ItemsSource="{Binding TokenUsageBars}">
                                        <ItemsControl.ItemsPanel>
                                            <ItemsPanelTemplate><StackPanel Orientation="Horizontal"/></ItemsPanelTemplate>
                                        </ItemsControl.ItemsPanel>
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate DataType="{x:Type vm:DayBarItem}">
                                                <StackPanel Width="42" Margin="2,0" ToolTip="{Binding ToolTipText}">
                                                    <TextBlock Text="{Binding ValueLabel}" FontSize="9" Foreground="#D97706"
                                                               HorizontalAlignment="Center" Margin="0,0,0,2"/>
                                                    <Border Height="88" VerticalAlignment="Bottom" CornerRadius="4,4,0,0">
                                                        <Border CornerRadius="4,4,0,0" VerticalAlignment="Bottom"
                                                                Height="{Binding BarHeight}">
                                                            <Border.Style>
                                                                <Style TargetType="Border">
                                                                    <Setter Property="Background" Value="#FBBF24"/>
                                                                    <Style.Triggers>
                                                                        <DataTrigger Binding="{Binding IsToday}" Value="True">
                                                                            <Setter Property="Background" Value="#D97706"/>
                                                                        </DataTrigger>
                                                                        <DataTrigger Binding="{Binding HasData}" Value="False">
                                                                            <Setter Property="Background" Value="#E5E7EB"/>
                                                                        </DataTrigger>
                                                                    </Style.Triggers>
                                                                </Style>
                                                            </Border.Style>
                                                        </Border>
                                                    </Border>
                                                    <TextBlock Text="{Binding DayLabel}" FontSize="10" Foreground="#6B7280"
                                                               HorizontalAlignment="Center" Margin="0,4,0,0"/>
                                                    <TextBlock Text="{Binding DateLabel}" FontSize="8" Foreground="#9CA3AF"
                                                               HorizontalAlignment="Center"/>
                                                </StackPanel>
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                    </ItemsControl>
                                </ScrollViewer>
                            </StackPanel>
                        </Border>

                        <!-- ── 탭별 대화 비율 (Chat/Cowork/Code) ── -->
                        <Border Background="#F5F0FF" CornerRadius="14" Padding="18,16" Margin="0,0,0,14">
                            <StackPanel>
                                <StackPanel Orientation="Horizontal" Margin="0,0,0,14">
                                    <TextBlock Text="&#xE9D9;" FontFamily="Segoe MDL2 Assets"
                                               FontSize="14" Foreground="#8B5CF6" VerticalAlignment="Center" Margin="0,0,8,0"/>
                                    <TextBlock Text="탭별 대화 비율 (30일)" FontSize="13" FontWeight="SemiBold"
                                               Foreground="#1A1B2E" VerticalAlignment="Center"/>
                                </StackPanel>
                                <ItemsControl ItemsSource="{Binding TabChatRatios}">
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate DataType="{x:Type vm:TabRatioItem}">
                                            <Grid Margin="0,0,0,10">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="65"/>
                                                    <ColumnDefinition Width="*"/>
                                                    <ColumnDefinition Width="Auto"/>
                                                </Grid.ColumnDefinitions>
                                                <!-- 탭 이름 -->
                                                <TextBlock Grid.Column="0" Text="{Binding TabName}"
                                                           FontSize="12" FontWeight="SemiBold"
                                                           Foreground="#333355" VerticalAlignment="Center"/>
                                                <!-- 진행 바 -->
                                                <Border Grid.Column="1" Height="14" CornerRadius="7"
                                                        Background="#EEEEF8" VerticalAlignment="Center">
                                                    <Border CornerRadius="7"
                                                            HorizontalAlignment="Left"
                                                            Width="{Binding BarWidth}"
                                                            Background="{Binding Color}"/>
                                                </Border>
                                                <!-- 비율 -->
                                                <TextBlock Grid.Column="2" Text="{Binding PercentLabel}"
                                                           FontSize="11" Foreground="#9999BB"
                                                           VerticalAlignment="Center" Margin="10,0,0,0"/>
                                            </Grid>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                            </StackPanel>
                        </Border>

                        <!-- ── 프롬프트/완료 토큰 비율 ── -->
                        <Border Background="#F0FFF5" CornerRadius="14" Padding="18,16" Margin="0,0,0,14">
                            <StackPanel>
                                <StackPanel Orientation="Horizontal" Margin="0,0,0,6">
                                    <TextBlock Text="&#xE943;" FontFamily="Segoe MDL2 Assets"
                                               FontSize="14" Foreground="#10B981" VerticalAlignment="Center" Margin="0,0,8,0"/>
                                    <TextBlock Text="입력/출력 토큰 비율 (30일)" FontSize="13" FontWeight="SemiBold"
                                               Foreground="#1A1B2E" VerticalAlignment="Center"/>
                                </StackPanel>
                                <TextBlock Text="{Binding TokenRatioSummary}" FontSize="11" Foreground="#6B7280" Margin="0,0,0,12"/>
                                <!-- 스택 바 -->
                                <Border CornerRadius="8" Height="24" ClipToBounds="True" Background="#E5E7EB" Margin="0,0,0,8">
                                    <StackPanel Orientation="Horizontal">
                                        <Border Background="#06B6D4" CornerRadius="8,0,0,8"
                                                Width="{Binding PromptBarWidth}"/>
                                        <Border Background="#F59E0B" CornerRadius="0,8,8,0"
                                                Width="{Binding CompletionBarWidth}"/>
                                    </StackPanel>
                                </Border>
                                <!-- 범례 -->
                                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                                    <Border Width="12" Height="12" CornerRadius="3" Background="#06B6D4" Margin="0,0,6,0"/>
                                    <TextBlock Text="{Binding PromptTokenLabel}" FontSize="11" Foreground="#555577"
                                               Margin="0,0,20,0" VerticalAlignment="Center"/>
                                    <Border Width="12" Height="12" CornerRadius="3" Background="#F59E0B" Margin="0,0,6,0"/>
                                    <TextBlock Text="{Binding CompletionTokenLabel}" FontSize="11" Foreground="#555577"
                                               VerticalAlignment="Center"/>
                                </StackPanel>
                            </StackPanel>
                        </Border>

                        <!-- ── 즐겨찾기 상위 항목 ── -->
                        <Border Background="#FFF9F0" CornerRadius="14" Padding="18,16"
                                Visibility="{Binding HasFavorites, Converter={StaticResource BoolToVisibilityConverter}}">
                            <StackPanel>
                                <StackPanel Orientation="Horizontal" Margin="0,0,0,14">
                                    <TextBlock Text="&#xE734;" FontFamily="Segoe MDL2 Assets"
                                               FontSize="14" Foreground="#D97706" VerticalAlignment="Center" Margin="0,0,8,0"/>
                                    <TextBlock Text="즐겨찾기 목록 (최근 추가순)" FontSize="13" FontWeight="SemiBold"
                                               Foreground="#1A1B2E" VerticalAlignment="Center"/>
                                </StackPanel>
                                <ItemsControl ItemsSource="{Binding TopFavorites}">
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate DataType="{x:Type vm:FavoriteStatItem}">
                                            <Grid Margin="0,0,0,7">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="22"/>
                                                    <ColumnDefinition Width="22"/>
                                                    <ColumnDefinition Width="*"/>
                                                </Grid.ColumnDefinitions>
                                                <!-- 순위 -->
                                                <TextBlock Grid.Column="0" Text="{Binding Rank}"
                                                           FontSize="11" FontWeight="Bold" Foreground="#DDBB88"
                                                           VerticalAlignment="Center"/>
                                                <!-- 아이콘 -->
                                                <TextBlock Grid.Column="1" Text="{Binding Icon}"
                                                           FontFamily="Segoe MDL2 Assets" FontSize="13"
                                                           Foreground="#D97706" VerticalAlignment="Center"/>
                                                <!-- 이름 + 경로 -->
                                                <StackPanel Grid.Column="2" VerticalAlignment="Center" Margin="4,0,0,0">
                                                    <TextBlock Text="{Binding Name}" FontSize="12" FontWeight="SemiBold"
                                                               Foreground="#2B3280" TextTrimming="CharacterEllipsis"/>
                                                    <TextBlock Text="{Binding Path}" FontSize="10" FontFamily="Consolas"
                                                               Foreground="#AAAACC" TextTrimming="CharacterEllipsis"/>
                                                </StackPanel>
                                            </Grid>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                            </StackPanel>
                        </Border>

                    </StackPanel>
                    </ScrollViewer>

                </Grid>

                <!-- ── 리사이즈 그립 ── -->
                <Border Grid.Row="1"
                        HorizontalAlignment="Right" VerticalAlignment="Bottom"
                        Width="22" Height="22" Margin="0,0,4,4"
                        Cursor="SizeNWSE" Background="Transparent"
                        Panel.ZIndex="100"
                        MouseLeftButtonDown="ResizeGrip_MouseLeftButtonDown">
                    <Canvas Width="13" Height="13">
                        <Rectangle Canvas.Left="10" Canvas.Top="10" Width="2.5" Height="2.5" RadiusX="1.2" RadiusY="1.2" Fill="#60444488"/>
                        <Rectangle Canvas.Left="6"  Canvas.Top="10" Width="2.5" Height="2.5" RadiusX="1.2" RadiusY="1.2" Fill="#40444488"/>
                        <Rectangle Canvas.Left="10" Canvas.Top="6"  Width="2.5" Height="2.5" RadiusX="1.2" RadiusY="1.2" Fill="#40444488"/>
                        <Rectangle Canvas.Left="2"  Canvas.Top="10" Width="2.5" Height="2.5" RadiusX="1.2" RadiusY="1.2" Fill="#25444488"/>
                        <Rectangle Canvas.Left="6"  Canvas.Top="6"  Width="2.5" Height="2.5" RadiusX="1.2" RadiusY="1.2" Fill="#25444488"/>
                        <Rectangle Canvas.Left="10" Canvas.Top="2"  Width="2.5" Height="2.5" RadiusX="1.2" RadiusY="1.2" Fill="#25444488"/>
                    </Canvas>
                </Border>

            </Grid>
        </Border>
    </Grid>
</Window>
