<Window x:Class="AxCopilot.Views.ResourceMonitorWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="AX Copilot — 리소스 모니터"
        Width="420" Height="460"
        MinWidth="360" MinHeight="400"
        WindowStyle="None"
        AllowsTransparency="True"
        UseLayoutRounding="True"
        SnapsToDevicePixels="True"
        Background="Transparent"
        ResizeMode="CanResize"
        WindowStartupLocation="CenterScreen"
        ShowInTaskbar="True"
        Topmost="True"
        Icon="pack://application:,,,/Assets/icon.ico"
        MouseDown="Window_MouseDown"
        KeyDown="Window_KeyDown">

    <Border Margin="14">
        <Border.Effect>
            <DropShadowEffect Color="Black" BlurRadius="20" ShadowDepth="4" Opacity="0.24"/>
        </Border.Effect>

        <Border Background="{DynamicResource LauncherBackground}"
                CornerRadius="16" ClipToBounds="True">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="50"/>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="44"/>
                </Grid.RowDefinitions>

                <!-- ── 헤더 ── -->
                <Border Grid.Row="0" CornerRadius="16,16,0,0">
                    <Border.Background>
                        <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                            <GradientStop Color="#1A1B2E" Offset="0"/>
                            <GradientStop Color="#2D3A6B" Offset="1"/>
                        </LinearGradientBrush>
                    </Border.Background>
                    <Grid Margin="18,0">
                        <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                            <TextBlock Text="&#xE9D9;" FontFamily="Segoe MDL2 Assets"
                                       FontSize="15" Foreground="#88AAFFCC"
                                       VerticalAlignment="Center" Margin="0,0,9,0"/>
                            <TextBlock Text="리소스 모니터" FontSize="14" FontWeight="SemiBold"
                                       Foreground="White" VerticalAlignment="Center"/>
                            <!-- 실시간 갱신 표시 -->
                            <Border Background="#22FFFFFF" CornerRadius="4"
                                    Padding="6,2" Margin="10,0,0,0" VerticalAlignment="Center">
                                <TextBlock x:Name="RefreshLabel" Text="● LIVE" FontSize="9"
                                           FontWeight="SemiBold" Foreground="#66FFAA"
                                           VerticalAlignment="Center"/>
                            </Border>
                        </StackPanel>
                        <!-- 닫기 버튼 -->
                        <Button Width="26" Height="26" HorizontalAlignment="Right"
                                Background="Transparent" BorderThickness="0" Cursor="Hand"
                                Click="Close_Click">
                            <Button.Template>
                                <ControlTemplate TargetType="Button">
                                    <Border x:Name="Bd" CornerRadius="6" Background="Transparent">
                                        <TextBlock Text="&#xE711;" FontFamily="Segoe MDL2 Assets"
                                                   FontSize="9" Foreground="#88AAFFCC"
                                                   HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                    </Border>
                                    <ControlTemplate.Triggers>
                                        <Trigger Property="IsMouseOver" Value="True">
                                            <Setter TargetName="Bd" Property="Background" Value="#33FFFFFF"/>
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Button.Template>
                        </Button>
                    </Grid>
                </Border>

                <!-- ── 본문 ── -->
                <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto"
                              HorizontalScrollBarVisibility="Disabled"
                              Padding="0,0,4,0">
                    <StackPanel Margin="20,16,20,8" >

                        <!-- CPU 게이지 -->
                        <Border Background="{DynamicResource ItemBackground}"
                                CornerRadius="12" Padding="16,14" Margin="0,0,0,10">
                            <StackPanel>
                                <Grid Margin="0,0,0,8">
                                    <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                                        <TextBlock Text="&#xE9D9;" FontFamily="Segoe MDL2 Assets"
                                                   FontSize="13" Foreground="#4B9EFC"
                                                   VerticalAlignment="Center" Margin="0,0,7,0"/>
                                        <TextBlock Text="CPU" FontSize="12" FontWeight="SemiBold"
                                                   Foreground="{DynamicResource PrimaryText}"
                                                   VerticalAlignment="Center"/>
                                    </StackPanel>
                                    <TextBlock x:Name="CpuValueText"
                                               Text="—" FontSize="20" FontWeight="Bold"
                                               Foreground="#4B9EFC"
                                               HorizontalAlignment="Right" VerticalAlignment="Center"/>
                                </Grid>
                                <!-- CPU 바 -->
                                <Border Height="10" CornerRadius="5"
                                        Background="{DynamicResource SeparatorColor}">
                                    <Border x:Name="CpuBar" CornerRadius="5"
                                            Background="#4B9EFC" HorizontalAlignment="Left"
                                            Width="0"/>
                                </Border>
                                <TextBlock x:Name="CpuNameText"
                                           Text="" FontSize="10"
                                           Foreground="{DynamicResource SecondaryText}"
                                           Margin="0,6,0,0" TextTrimming="CharacterEllipsis"/>
                            </StackPanel>
                        </Border>

                        <!-- RAM 게이지 -->
                        <Border Background="{DynamicResource ItemBackground}"
                                CornerRadius="12" Padding="16,14" Margin="0,0,0,10">
                            <StackPanel>
                                <Grid Margin="0,0,0,8">
                                    <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                                        <TextBlock Text="&#xE950;" FontFamily="Segoe MDL2 Assets"
                                                   FontSize="13" Foreground="#7C3AED"
                                                   VerticalAlignment="Center" Margin="0,0,7,0"/>
                                        <TextBlock Text="RAM" FontSize="12" FontWeight="SemiBold"
                                                   Foreground="{DynamicResource PrimaryText}"
                                                   VerticalAlignment="Center"/>
                                    </StackPanel>
                                    <TextBlock x:Name="RamValueText"
                                               Text="—" FontSize="20" FontWeight="Bold"
                                               Foreground="#7C3AED"
                                               HorizontalAlignment="Right" VerticalAlignment="Center"/>
                                </Grid>
                                <!-- RAM 바 -->
                                <Border Height="10" CornerRadius="5"
                                        Background="{DynamicResource SeparatorColor}">
                                    <Border x:Name="RamBar" CornerRadius="5"
                                            Background="#7C3AED" HorizontalAlignment="Left"
                                            Width="0"/>
                                </Border>
                                <TextBlock x:Name="RamDetailText"
                                           Text="" FontSize="10"
                                           Foreground="{DynamicResource SecondaryText}"
                                           Margin="0,6,0,0"/>
                            </StackPanel>
                        </Border>

                        <!-- 드라이브 섹션 -->
                        <TextBlock Text="드라이브" FontSize="10" FontWeight="SemiBold"
                                   Foreground="{DynamicResource SecondaryText}"
                                   Margin="2,4,0,8"/>
                        <ItemsControl x:Name="DriveList">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <!-- DriveDisplayItem 바인딩 -->
                                    <Border Background="{DynamicResource ItemBackground}"
                                            CornerRadius="10" Padding="14,10" Margin="0,0,0,6"
                                            Cursor="Hand">
                                        <Border.InputBindings>
                                            <MouseBinding MouseAction="LeftClick"
                                                          Command="{Binding OpenCommand}"/>
                                        </Border.InputBindings>
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="28"/>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="Auto"/>
                                            </Grid.ColumnDefinitions>
                                            <TextBlock Grid.Column="0"
                                                       Text="&#xEDA2;" FontFamily="Segoe MDL2 Assets"
                                                       FontSize="14" Foreground="#059669"
                                                       VerticalAlignment="Center"/>
                                            <StackPanel Grid.Column="1" VerticalAlignment="Center">
                                                <TextBlock Text="{Binding Label}"
                                                           FontSize="12" FontWeight="SemiBold"
                                                           Foreground="{DynamicResource PrimaryText}"
                                                           TextTrimming="CharacterEllipsis"/>
                                                <!-- 진행 바 -->
                                                <Border Height="5" CornerRadius="3" Margin="0,5,0,0"
                                                        Background="{DynamicResource SeparatorColor}">
                                                    <Border CornerRadius="3" HorizontalAlignment="Left"
                                                            Background="{Binding BarColor}"
                                                            Width="{Binding BarWidth}"/>
                                                </Border>
                                            </StackPanel>
                                            <TextBlock Grid.Column="2"
                                                       Text="{Binding Detail}"
                                                       FontSize="10" FontFamily="Consolas"
                                                       Foreground="{DynamicResource SecondaryText}"
                                                       VerticalAlignment="Center" Margin="10,0,0,0"/>
                                        </Grid>
                                    </Border>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>

                        <!-- 상위 프로세스 섹션 -->
                        <TextBlock Text="CPU 상위 프로세스" FontSize="10" FontWeight="SemiBold"
                                   Foreground="{DynamicResource SecondaryText}"
                                   Margin="2,8,0,8"/>
                        <ItemsControl x:Name="ProcessList">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Grid Margin="0,0,0,4">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="22"/>
                                            <ColumnDefinition Width="*"/>
                                            <ColumnDefinition Width="60"/>
                                            <ColumnDefinition Width="52"/>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Grid.Column="0" Text="{Binding Rank}"
                                                   FontSize="10" Foreground="{DynamicResource SecondaryText}"
                                                   VerticalAlignment="Center" HorizontalAlignment="Center"/>
                                        <TextBlock Grid.Column="1" Text="{Binding Name}"
                                                   FontSize="11" FontFamily="Consolas"
                                                   Foreground="{DynamicResource PrimaryText}"
                                                   VerticalAlignment="Center"
                                                   TextTrimming="CharacterEllipsis"/>
                                        <TextBlock Grid.Column="2" Text="{Binding MemText}"
                                                   FontSize="10"
                                                   Foreground="{DynamicResource SecondaryText}"
                                                   HorizontalAlignment="Right"
                                                   VerticalAlignment="Center"/>
                                        <Border Grid.Column="3" Height="6" CornerRadius="3"
                                                Margin="6,0,0,0" VerticalAlignment="Center"
                                                Background="{DynamicResource SeparatorColor}">
                                            <Border CornerRadius="3" Background="#BE185D"
                                                    HorizontalAlignment="Left"
                                                    Width="{Binding BarWidth}"/>
                                        </Border>
                                    </Grid>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>

                    </StackPanel>
                </ScrollViewer>

                <!-- ── 리사이즈 그립 ── -->
                <Border Grid.Row="2"
                        HorizontalAlignment="Right" VerticalAlignment="Bottom"
                        Width="20" Height="20" Margin="0,0,2,2"
                        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="#70AAAACC"/>
                        <Rectangle Canvas.Left="6"  Canvas.Top="10" Width="2.5" Height="2.5" RadiusX="1.2" RadiusY="1.2" Fill="#50AAAACC"/>
                        <Rectangle Canvas.Left="10" Canvas.Top="6"  Width="2.5" Height="2.5" RadiusX="1.2" RadiusY="1.2" Fill="#50AAAACC"/>
                        <Rectangle Canvas.Left="2"  Canvas.Top="10" Width="2.5" Height="2.5" RadiusX="1.2" RadiusY="1.2" Fill="#30AAAACC"/>
                        <Rectangle Canvas.Left="6"  Canvas.Top="6"  Width="2.5" Height="2.5" RadiusX="1.2" RadiusY="1.2" Fill="#30AAAACC"/>
                        <Rectangle Canvas.Left="10" Canvas.Top="2"  Width="2.5" Height="2.5" RadiusX="1.2" RadiusY="1.2" Fill="#30AAAACC"/>
                    </Canvas>
                </Border>

                <!-- ── 푸터 ── -->
                <Border Grid.Row="2" BorderBrush="{DynamicResource BorderColor}"
                        BorderThickness="0,1,0,0"
                        Background="{DynamicResource ItemBackground}"
                        CornerRadius="0,0,16,16">
                    <Grid Margin="18,0">
                        <TextBlock x:Name="UptimeText"
                                   Text="가동 시간: —"
                                   FontSize="10" Foreground="{DynamicResource SecondaryText}"
                                   HorizontalAlignment="Left" VerticalAlignment="Center"/>
                        <Button Content="닫기" HorizontalAlignment="Right"
                                Click="Close_Click" Width="68" Height="28"
                                Background="#4B5EFC" Foreground="White"
                                FontSize="11" FontWeight="SemiBold"
                                BorderThickness="0" Cursor="Hand">
                            <Button.Template>
                                <ControlTemplate TargetType="Button">
                                    <Border Background="{TemplateBinding Background}"
                                            CornerRadius="7" Padding="{TemplateBinding Padding}">
                                        <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                    </Border>
                                    <ControlTemplate.Triggers>
                                        <Trigger Property="IsMouseOver" Value="True">
                                            <Setter Property="Background" Value="#3B4EEC"/>
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Button.Template>
                        </Button>
                    </Grid>
                </Border>

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