<Window x:Class="AxCopilot.Views.ChatWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
        xmlns:ctrl="clr-namespace:AxCopilot.Views.Controls"
        Title="AX Copilot — AX Agent"
        Width="1100" Height="760"
        MinWidth="700" MinHeight="520"
        WindowStyle="None"
        UseLayoutRounding="True"
        SnapsToDevicePixels="True"
        Background="{DynamicResource LauncherBackground}"
        ResizeMode="CanResizeWithGrip"
        WindowStartupLocation="CenterScreen"
        ShowInTaskbar="True"
        Icon="pack://application:,,,/Assets/icon.ico">

    <WindowChrome.WindowChrome>
        <WindowChrome CaptionHeight="48"
                      CornerRadius="0"
                      GlassFrameThickness="0"
                      ResizeBorderThickness="6"/>
    </WindowChrome.WindowChrome>

    <Window.Resources>
        <!-- 사이드바 버튼 -->
        <Style x:Key="GhostBtn" TargetType="Button">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="Cursor" Value="Hand"/>
            <Setter Property="Padding" Value="8,6"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border x:Name="Bd" Background="{TemplateBinding Background}"
                                CornerRadius="8" Padding="{TemplateBinding Padding}"
                                Opacity="1">
                            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="Bd" Property="Background" Value="#15FFFFFF"/>
                                <Setter TargetName="Bd" Property="Opacity" Value="0.85"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="Opacity" Value="0.35"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <!-- 탭 버튼 -->
        <Style x:Key="TopTabBtn" TargetType="RadioButton">
            <Setter Property="Foreground" Value="{DynamicResource SecondaryText}"/>
            <Setter Property="FontSize" Value="13"/>
            <Setter Property="FontWeight" Value="SemiBold"/>
            <Setter Property="Cursor" Value="Hand"/>
            <Setter Property="Padding" Value="18,6"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="RadioButton">
                        <Border x:Name="Bd" Background="Transparent"
                                CornerRadius="8" Padding="{TemplateBinding Padding}">
                            <ContentPresenter x:Name="Cp" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="Bd" Property="Background" Value="{DynamicResource ItemHoverBackground}"/>
                                <Setter Property="Foreground" Value="{DynamicResource PrimaryText}"/>
                            </Trigger>
                            <!-- IsChecked를 뒤에 두어 호버보다 선택 상태가 항상 우선 적용 -->
                            <Trigger Property="IsChecked" Value="True">
                                <Setter TargetName="Bd" Property="Background" Value="{DynamicResource ItemSelectedBackground}"/>
                                <Setter Property="Foreground" Value="White"/>
                                <Setter Property="FontWeight" Value="Bold"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="Opacity" Value="0.3"/>
                                <Setter Property="Cursor" Value="Arrow"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <!-- 테두리 호버 버튼 (배경색 변경 없이 테두리만 표시) -->
        <Style x:Key="OutlineHoverBtn" TargetType="Button">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="BorderBrush" Value="Transparent"/>
            <Setter Property="Cursor" Value="Hand"/>
            <Setter Property="Padding" Value="8,6,10,6"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border x:Name="Bd" Background="Transparent"
                                BorderBrush="Transparent"
                                BorderThickness="0"
                                CornerRadius="8" Padding="{TemplateBinding Padding}">
                            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="Bd" Property="Background" Value="#10FFFFFF"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="Opacity" Value="0.35"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <!-- 모든 드롭다운 메뉴는 코드-비하인드에서 커스텀 Popup으로 렌더링 -->
    </Window.Resources>

    <Border Background="{DynamicResource LauncherBackground}"
            BorderBrush="{DynamicResource BorderColor}"
            BorderThickness="1">
        <Grid>
            <Grid.ColumnDefinitions>
                <!-- 축소 아이콘 바 (사이드바 닫힘 시 표시) -->
                <ColumnDefinition x:Name="IconBarColumn" Width="0"/>
                <!-- 사이드바 (열림 시 표시) -->
                <ColumnDefinition x:Name="SidebarColumn" Width="270" MinWidth="0"/>
                <ColumnDefinition Width="*"/>
                <!-- 미리보기 스플리터 -->
                <ColumnDefinition x:Name="SplitterColumn" Width="0"/>
                <!-- 미리보기 패널 (파일 생성 시 표시) -->
                <ColumnDefinition x:Name="PreviewColumn" Width="0" MinWidth="0"/>
                <!-- Phase 32: 우측 설정 패널 (슬라이드인) -->
                <ColumnDefinition x:Name="SettingsPanelColumn" Width="Auto"/>
            </Grid.ColumnDefinitions>

            <!-- ══ 축소 아이콘 바 (사이드바 닫힘 시) ══ -->
            <Border x:Name="IconBarPanel" Grid.Column="0"
                    Background="{DynamicResource ItemBackground}"
                    Visibility="Collapsed">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="54"/>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="54"/>
                    </Grid.RowDefinitions>

                    <!-- 상단 아이콘들 -->
                    <StackPanel Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Center">
                        <Button Style="{StaticResource GhostBtn}" Padding="10,8"
                                Click="BtnNewChat_Click" ToolTip="새 대화"
                                WindowChrome.IsHitTestVisibleInChrome="True">
                            <TextBlock Text="&#xE710;" FontFamily="Segoe MDL2 Assets" FontSize="15"
                                       Foreground="{DynamicResource SecondaryText}"/>
                        </Button>
                    </StackPanel>

                    <StackPanel Grid.Row="1" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="0,8,0,0">
                        <Button Style="{StaticResource GhostBtn}" Padding="10,8"
                                Click="BtnToggleSidebar_Click" ToolTip="검색"
                                WindowChrome.IsHitTestVisibleInChrome="True">
                            <TextBlock Text="&#xE721;" FontFamily="Segoe MDL2 Assets" FontSize="14"
                                       Foreground="{DynamicResource SecondaryText}"/>
                        </Button>
                        <Button Style="{StaticResource GhostBtn}" Padding="10,8"
                                Click="BtnCategoryDrop_Click" ToolTip="대화 주제"
                                WindowChrome.IsHitTestVisibleInChrome="True">
                            <TextBlock Text="&#xE8BD;" FontFamily="Segoe MDL2 Assets" FontSize="14"
                                       Foreground="{DynamicResource SecondaryText}"/>
                        </Button>
                    </StackPanel>

                    <!-- 하단: 사용자 이니셜 -->
                    <Button x:Name="BtnUserIconBar" Grid.Row="2" Style="{StaticResource GhostBtn}"
                            HorizontalAlignment="Center" VerticalAlignment="Center"
                            ToolTip="" Padding="0"
                            WindowChrome.IsHitTestVisibleInChrome="True">
                        <Border Width="32" Height="32" CornerRadius="16"
                                Background="{DynamicResource AccentColor}">
                            <TextBlock x:Name="UserInitialIconBar" Text="U" FontSize="13" FontWeight="Bold"
                                       Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </Border>
                    </Button>
                </Grid>
            </Border>

            <!-- ══════════════════════════════════════════════════════ -->
            <!-- 좌측: 사이드바 (Phase 17-UI-D: AgentSidebarView UserControl) -->
            <!-- ══════════════════════════════════════════════════════ -->
            <ctrl:AgentSidebarView x:Name="Sidebar" Grid.Column="1"/>

            <!-- ══════════════════════════════════════════════════════ -->
            <!-- 우측: 메시지 영역                                       -->
            <!-- ══════════════════════════════════════════════════════ -->
            <Grid Grid.Column="2">
                <Grid.RowDefinitions>
                    <RowDefinition Height="48"/>
                    <RowDefinition Height="Auto"/>  <!-- 서브 바: 제목 + 프리뷰 -->
                    <RowDefinition Height="Auto"/>  <!-- 스티키 진행률 바 -->
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="Auto"/>  <!-- 입력 바 + Popup들 -->
                    <RowDefinition Height="Auto"/>  <!-- 파일 탐색기 -->
                    <RowDefinition Height="Auto"/>  <!-- 상태바 -->
                </Grid.RowDefinitions>

                <!-- ── 서브 바: 제목 + 프리뷰 버튼 (Claude 스타일) ── -->
                <Border Grid.Row="1" Background="{DynamicResource LauncherBackground}"
                        BorderBrush="{DynamicResource SeparatorColor}" BorderThickness="0,0,0,1"
                        Padding="12,4,12,4">
                    <Grid>
                        <!-- 좌: 대화 제목 -->
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center">
                            <Grid VerticalAlignment="Center">
                                <TextBlock x:Name="ChatTitle" Text="" FontSize="13" FontWeight="SemiBold"
                                           Foreground="{DynamicResource PrimaryText}"
                                           VerticalAlignment="Center" TextTrimming="CharacterEllipsis"
                                           MaxWidth="400" Cursor="Hand"
                                           MouseLeftButtonDown="ChatTitle_MouseDown"
                                           ToolTip="클릭하여 대화 이름 변경"/>
                                <TextBox x:Name="ChatTitleEdit" FontSize="13"
                                         Foreground="{DynamicResource PrimaryText}"
                                         Background="{DynamicResource HintBackground}"
                                         CaretBrush="{DynamicResource AccentColor}"
                                         BorderThickness="0" Padding="4,2"
                                         MaxWidth="400" MinWidth="80"
                                         Visibility="Collapsed"
                                         LostFocus="ChatTitleEdit_LostFocus"
                                         KeyDown="ChatTitleEdit_KeyDown"/>
                            </Grid>
                        </StackPanel>
                        <!-- 우: AgentSessionHeaderBar (모델/Plan/권한 칩) + 미리보기 -->
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center">
                            <!-- Phase 17-UI-C: AgentSessionHeaderBar UserControl -->
                            <ctrl:AgentSessionHeaderBar x:Name="SessionHeaderBar" VerticalAlignment="Center"/>
                            <Button x:Name="BtnPreviewToggle" Style="{StaticResource GhostBtn}"
                                    Click="BtnPreviewToggle_Click" ToolTip="미리보기 패널" Visibility="Collapsed"
                                    Padding="8,4">
                                <StackPanel Orientation="Horizontal">
                                    <Ellipse x:Name="PreviewDot" Width="6" Height="6" Fill="#22C55E"
                                             Margin="0,0,5,0" VerticalAlignment="Center"/>
                                    <TextBlock Text="미리보기" FontSize="12"
                                               Foreground="{DynamicResource PrimaryText}"
                                               VerticalAlignment="Center"/>
                                </StackPanel>
                            </Button>
                        </StackPanel>
                    </Grid>
                </Border>

                <!-- ── 에이전트 진행률 스티키 바 ── -->
                <Border x:Name="AgentProgressBar" Grid.Row="2" Visibility="Collapsed"
                        Background="{DynamicResource HintBackground}"
                        BorderBrush="{DynamicResource SeparatorColor}" BorderThickness="0,0,0,1"
                        Padding="16,6,16,6">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <!-- 아이콘 -->
                        <TextBlock Grid.Column="0" x:Name="ProgressIcon"
                                   Text="&#xE768;" FontFamily="Segoe MDL2 Assets" FontSize="12"
                                   Foreground="{DynamicResource AccentColor}"
                                   VerticalAlignment="Center" Margin="0,0,8,0"/>
                        <!-- 단계 텍스트 -->
                        <TextBlock Grid.Column="1" x:Name="ProgressStepLabel"
                                   Text="" FontSize="12"
                                   Foreground="{DynamicResource PrimaryText}"
                                   VerticalAlignment="Center" TextTrimming="CharacterEllipsis"
                                   MaxWidth="300" Margin="0,0,12,0"/>
                        <!-- 프로그레스 바 -->
                        <Border Grid.Column="2" CornerRadius="3" Background="#15FFFFFF"
                                Height="6" VerticalAlignment="Center" Margin="0,0,12,0">
                            <Border x:Name="ProgressFill" CornerRadius="3" HorizontalAlignment="Left"
                                    Width="0" Background="{DynamicResource AccentColor}"/>
                        </Border>
                        <!-- 퍼센트 -->
                        <TextBlock Grid.Column="3" x:Name="ProgressPercent"
                                   Text="0%" FontSize="11" FontWeight="SemiBold"
                                   Foreground="{DynamicResource AccentColor}"
                                   VerticalAlignment="Center" Margin="0,0,8,0" MinWidth="30" TextAlignment="Right"/>
                        <!-- 경과 시간 -->
                        <TextBlock Grid.Column="4" x:Name="ProgressElapsed"
                                   Text="0:00" FontSize="10.5"
                                   Foreground="{DynamicResource SecondaryText}"
                                   VerticalAlignment="Center"/>
                    </Grid>
                </Border>

                <!-- ── 상단 바: 토글 | 탭(중앙) | 설정+닫기 ── -->
                <Border Grid.Row="0" Background="{DynamicResource LauncherBackground}"
                        BorderBrush="{DynamicResource SeparatorColor}" BorderThickness="0,0,0,1">
                    <Grid>
                        <!-- 좌: 사이드바 토글 -->
                        <Button x:Name="BtnToggleSidebar" Style="{StaticResource GhostBtn}"
                                HorizontalAlignment="Left" VerticalAlignment="Center" Margin="8,0"
                                Click="BtnToggleSidebar_Click" ToolTip="사이드바 열기/닫기"
                                WindowChrome.IsHitTestVisibleInChrome="True">
                            <TextBlock x:Name="ToggleSidebarIcon" Text="&#xE76B;" FontFamily="Segoe MDL2 Assets" FontSize="18"
                                       Foreground="{DynamicResource SecondaryText}"/>
                        </Button>

                        <!-- 중앙: 탭 메뉴 -->
                        <Border HorizontalAlignment="Center" VerticalAlignment="Center"
                                Background="{DynamicResource HintBackground}"
                                CornerRadius="10" Padding="3"
                                WindowChrome.IsHitTestVisibleInChrome="True">
                            <StackPanel Orientation="Horizontal">
                                <RadioButton x:Name="TabChat" Content="Chat" Style="{StaticResource TopTabBtn}"
                                             IsChecked="True" GroupName="TopTab"
                                             Checked="TabChat_Checked"/>
                                <RadioButton x:Name="TabCowork" Content="Cowork" Style="{StaticResource TopTabBtn}"
                                             GroupName="TopTab"
                                             Checked="TabCowork_Checked"/>
                                <RadioButton x:Name="TabCode" Content="Code" Style="{StaticResource TopTabBtn}"
                                             GroupName="TopTab"
                                             Checked="TabCode_Checked"/>
                            </StackPanel>
                        </Border>

                        <!-- 우: 설정 + 최소화 + 최대화 + 닫기 -->
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right"
                                    VerticalAlignment="Center" Margin="0,0,4,0"
                                    WindowChrome.IsHitTestVisibleInChrome="True">
                            <Button Style="{StaticResource GhostBtn}" Click="BtnSettings_Click" ToolTip="설정 패널 (Ctrl+클릭: 전역 설정)">
                                <TextBlock Text="&#xE713;" FontFamily="Segoe MDL2 Assets" FontSize="13"
                                           Foreground="{DynamicResource SecondaryText}"/>
                            </Button>
                            <Button Style="{StaticResource GhostBtn}" Click="BtnMinimize_Click" ToolTip="최소화">
                                <TextBlock Text="&#xE921;" FontFamily="Segoe MDL2 Assets" FontSize="11"
                                           Foreground="{DynamicResource SecondaryText}"/>
                            </Button>
                            <Button Style="{StaticResource GhostBtn}" Click="BtnMaximize_Click" ToolTip="최대화">
                                <TextBlock x:Name="MaximizeIcon" Text="&#xE739;" FontFamily="Segoe MDL2 Assets" FontSize="11"
                                           Foreground="{DynamicResource SecondaryText}"/>
                            </Button>
                            <Button Style="{StaticResource GhostBtn}" Click="BtnClose_Click" ToolTip="닫기">
                                <TextBlock Text="&#xE711;" FontFamily="Segoe MDL2 Assets" FontSize="12"
                                           Foreground="{DynamicResource SecondaryText}"/>
                            </Button>
                        </StackPanel>
                    </Grid>
                </Border>

                <!-- ── 메시지 내 검색 바 (Ctrl+F) ── -->
                <Border x:Name="MessageSearchBar" Grid.Row="3" Visibility="Collapsed"
                        Panel.ZIndex="5" VerticalAlignment="Top"
                        Background="{DynamicResource HintBackground}"
                        BorderBrush="{DynamicResource SeparatorColor}" BorderThickness="0,0,0,1"
                        Padding="12,6" Margin="40,0,40,0" CornerRadius="0,0,10,10">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Grid.Column="0" Text="&#xE721;" FontFamily="Segoe MDL2 Assets" FontSize="13"
                                   Foreground="{DynamicResource SecondaryText}"
                                   VerticalAlignment="Center" Margin="0,0,8,0"/>
                        <TextBox x:Name="SearchTextBox" Grid.Column="1"
                                 FontSize="12.5" Padding="4,3"
                                 Background="Transparent" Foreground="{DynamicResource PrimaryText}"
                                 BorderThickness="0"
                                 TextChanged="SearchTextBox_TextChanged"/>
                        <TextBlock x:Name="SearchResultCount" Grid.Column="2"
                                   Text="" FontSize="11"
                                   Foreground="{DynamicResource SecondaryText}"
                                   VerticalAlignment="Center" Margin="8,0"/>
                        <Button Grid.Column="3" Style="{StaticResource GhostBtn}" Padding="4"
                                Click="SearchPrev_Click" ToolTip="이전 (Shift+Enter)">
                            <TextBlock Text="&#xE70E;" FontFamily="Segoe MDL2 Assets" FontSize="10"
                                       Foreground="{DynamicResource SecondaryText}"/>
                        </Button>
                        <Button Grid.Column="4" Style="{StaticResource GhostBtn}" Padding="4"
                                Click="SearchNext_Click" ToolTip="다음 (Enter)">
                            <TextBlock Text="&#xE70D;" FontFamily="Segoe MDL2 Assets" FontSize="10"
                                       Foreground="{DynamicResource SecondaryText}"/>
                        </Button>
                        <Button Grid.Column="5" Style="{StaticResource GhostBtn}" Padding="4"
                                Click="SearchClose_Click" ToolTip="닫기 (Esc)">
                            <TextBlock Text="&#xE711;" FontFamily="Segoe MDL2 Assets" FontSize="9"
                                       Foreground="{DynamicResource SecondaryText}"/>
                        </Button>
                    </Grid>
                </Border>

                <!-- ── 메시지 스크롤 ── -->
                <ScrollViewer x:Name="MessageScroll" Grid.Row="3"
                              VerticalScrollBarVisibility="Auto"
                              HorizontalScrollBarVisibility="Disabled"
                              Background="{DynamicResource LauncherBackground}">
                    <StackPanel x:Name="MessagePanel"
                                Margin="0,24,0,16"
                                HorizontalAlignment="Stretch">
                        <StackPanel.RenderTransform>
                            <TranslateTransform/>
                        </StackPanel.RenderTransform>
                    </StackPanel>
                </ScrollViewer>

                <!-- 빈 상태 -->
                <StackPanel x:Name="EmptyState" Grid.Row="3"
                            HorizontalAlignment="Center" VerticalAlignment="Center"
                            MaxWidth="520">

                    <!-- 부유 AI 아이콘 -->
                    <Border x:Name="EmptyIcon" CornerRadius="24" Width="72" Height="72"
                            HorizontalAlignment="Center" Margin="0,0,0,20">
                        <Border.Background>
                            <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                                <GradientStop Color="#4B5EFC" Offset="0"/>
                                <GradientStop Color="#8B6DFF" Offset="1"/>
                            </LinearGradientBrush>
                        </Border.Background>
                        <Border.RenderTransform>
                            <TranslateTransform x:Name="EmptyIconTranslate"/>
                        </Border.RenderTransform>
                        <Border.Triggers>
                            <EventTrigger RoutedEvent="Loaded">
                                <BeginStoryboard>
                                    <Storyboard RepeatBehavior="Forever" AutoReverse="True">
                                        <DoubleAnimation Storyboard.TargetName="EmptyIconTranslate"
                                                         Storyboard.TargetProperty="Y"
                                                         From="0" To="-6" Duration="0:0:1.8">
                                            <DoubleAnimation.EasingFunction>
                                                <SineEase EasingMode="EaseInOut"/>
                                            </DoubleAnimation.EasingFunction>
                                        </DoubleAnimation>
                                    </Storyboard>
                                </BeginStoryboard>
                            </EventTrigger>
                        </Border.Triggers>
                        <TextBlock Text="&#xE8BD;" FontFamily="Segoe MDL2 Assets" FontSize="30"
                                   Foreground="White"
                                   HorizontalAlignment="Center" VerticalAlignment="Center"/>
                    </Border>

                    <TextBlock x:Name="EmptyStateTitle" Text="작업 유형을 선택하세요" FontSize="18" FontWeight="SemiBold"
                               Foreground="{DynamicResource PrimaryText}" HorizontalAlignment="Center"/>
                    <TextBlock x:Name="EmptyStateDesc" Text="주제에 맞는 전문 프리셋이 자동 적용됩니다"
                               FontSize="12" Foreground="{DynamicResource SecondaryText}"
                               HorizontalAlignment="Center" Margin="0,8,0,24"/>

                    <!-- 대화 주제 버튼 (프리셋에서 동적 생성) -->
                    <WrapPanel x:Name="TopicButtonPanel" HorizontalAlignment="Center"
                               Margin="0,0,0,0"/>
                </StackPanel>

                <!-- ── 프롬프트 템플릿 팝업 ── -->
                <Popup x:Name="TemplatePopup" Grid.Row="4"
                       PlacementTarget="{Binding ElementName=InputBorder}"
                       Placement="Top" StaysOpen="False"
                       AllowsTransparency="True" PopupAnimation="Fade">
                    <Border Background="{DynamicResource LauncherBackground}"
                            BorderBrush="{DynamicResource BorderColor}"
                            BorderThickness="1" CornerRadius="10"
                            Padding="4" MinWidth="260" MaxWidth="400">
                        <StackPanel>
                            <TextBlock Text="프롬프트 템플릿" FontSize="12" FontWeight="SemiBold"
                                       Foreground="{DynamicResource PrimaryText}"
                                       Margin="10,8,10,6"/>
                            <ItemsControl x:Name="TemplateItems"/>
                            <TextBlock x:Name="TemplateEmptyHint"
                                       Text="등록된 템플릿이 없습니다. 설정에서 추가하세요."
                                       FontSize="11" Foreground="{DynamicResource SecondaryText}"
                                       Margin="10,4,10,8" Visibility="Collapsed"/>
                        </StackPanel>
                    </Border>
                </Popup>

                <!-- ── 권한 선택 팝업 ── -->
                <Popup x:Name="PermissionPopup" Grid.Row="4"
                       PlacementTarget="{Binding ElementName=BtnPermission}"
                       Placement="Top" StaysOpen="False"
                       AllowsTransparency="True" PopupAnimation="Fade">
                    <Border Background="{DynamicResource LauncherBackground}"
                            BorderBrush="{DynamicResource BorderColor}"
                            BorderThickness="1" CornerRadius="12"
                            Padding="6" MinWidth="260">
                        <StackPanel x:Name="PermissionItems" Margin="2"/>
                    </Border>
                </Popup>

                <!-- ── 데이터 활용 수준 팝업 ── -->
                <Popup x:Name="DataUsagePopup" Grid.Row="4"
                       PlacementTarget="{Binding ElementName=BtnDataUsage}"
                       Placement="Top" StaysOpen="False"
                       AllowsTransparency="True" PopupAnimation="Fade">
                    <Border Background="{DynamicResource LauncherBackground}"
                            BorderBrush="{DynamicResource BorderColor}"
                            BorderThickness="1" CornerRadius="12"
                            Padding="6" MinWidth="280">
                        <StackPanel x:Name="DataUsageItems" Margin="2"/>
                    </Border>
                </Popup>

                <!-- ── 슬래시 명령어 팝업 ── -->
                <Popup x:Name="SlashPopup" Grid.Row="4"
                       PlacementTarget="{Binding ElementName=InputBorder}"
                       Placement="Top" StaysOpen="False"
                       AllowsTransparency="True" PopupAnimation="Fade">
                    <Border Background="{DynamicResource LauncherBackground}"
                            BorderBrush="{DynamicResource BorderColor}"
                            BorderThickness="1" CornerRadius="10"
                            Padding="4" MinWidth="280"
                            PreviewMouseWheel="SlashPopup_PreviewMouseWheel">
                        <StackPanel>
                            <!-- 위 화살표 -->
                            <Border x:Name="SlashNavUp" Visibility="Collapsed" Cursor="Hand"
                                    CornerRadius="6" Padding="8,4,8,4" Margin="0,0,0,2">
                                <Border.Style>
                                    <Style TargetType="Border">
                                        <Setter Property="Background" Value="Transparent"/>
                                        <Style.Triggers>
                                            <Trigger Property="IsMouseOver" Value="True">
                                                <Setter Property="Background" Value="{DynamicResource ItemHoverBackground}"/>
                                            </Trigger>
                                        </Style.Triggers>
                                    </Style>
                                </Border.Style>
                                <TextBlock x:Name="SlashNavUpText" FontSize="10.5"
                                           HorizontalAlignment="Center"
                                           Foreground="{DynamicResource SecondaryText}"/>
                            </Border>
                            <!-- 아이템 목록 -->
                            <ItemsControl x:Name="SlashItems"/>
                            <!-- 아래 화살표 -->
                            <Border x:Name="SlashNavDown" Visibility="Collapsed" Cursor="Hand"
                                    CornerRadius="6" Padding="8,4,8,4" Margin="0,2,0,0">
                                <Border.Style>
                                    <Style TargetType="Border">
                                        <Setter Property="Background" Value="Transparent"/>
                                        <Style.Triggers>
                                            <Trigger Property="IsMouseOver" Value="True">
                                                <Setter Property="Background" Value="{DynamicResource ItemHoverBackground}"/>
                                            </Trigger>
                                        </Style.Triggers>
                                    </Style>
                                </Border.Style>
                                <TextBlock x:Name="SlashNavDownText" FontSize="10.5"
                                           HorizontalAlignment="Center"
                                           Foreground="{DynamicResource SecondaryText}"/>
                            </Border>
                        </StackPanel>
                    </Border>
                </Popup>

                <!-- ── 폴더 선택 팝업 ── -->
                <Popup x:Name="FolderMenuPopup" Grid.Row="4"
                       PlacementTarget="{Binding ElementName=FolderPathLabel}"
                       Placement="Top" StaysOpen="False"
                       AllowsTransparency="True" PopupAnimation="Fade">
                    <Border Background="{DynamicResource LauncherBackground}"
                            BorderBrush="{DynamicResource BorderColor}"
                            BorderThickness="1" CornerRadius="12"
                            Padding="6" MinWidth="300" MaxWidth="460">
                        <StackPanel x:Name="FolderMenuItems" Margin="2"/>
                    </Border>
                </Popup>

                <!-- ── 토스트 알림 ── -->
                <Border x:Name="ToastBorder" Grid.Row="3" Visibility="Collapsed"
                        Panel.ZIndex="20"
                        HorizontalAlignment="Center" VerticalAlignment="Bottom"
                        Margin="0,0,0,16"
                        Background="#E0202030" CornerRadius="20"
                        Padding="16,8,16,8" Opacity="0"
                        IsHitTestVisible="False">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock x:Name="ToastIcon" Text="&#xE73E;" FontFamily="Segoe MDL2 Assets" FontSize="12"
                                   Foreground="#78E08F" VerticalAlignment="Center" Margin="0,0,6,0"/>
                        <TextBlock x:Name="ToastText" Text="" FontSize="12"
                                   Foreground="White" VerticalAlignment="Center"/>
                    </StackPanel>
                </Border>

                <!-- ── 입력 바 ── -->
                <Border Grid.Row="4" Margin="40,0,40,18">
                    <StackPanel>
                        <!-- 무지개 글로우 + 입력 영역 (겹침 레이아웃) -->
                        <Grid>
                            <!-- 무지개 글로우 외부 테두리 (메시지 전송 시 애니메이션) -->
                            <Border x:Name="InputGlowBorder" CornerRadius="18" Opacity="0"
                                    Margin="-3" IsHitTestVisible="False">
                                <Border.BorderBrush>
                                    <LinearGradientBrush x:Name="RainbowBrush" StartPoint="0,0" EndPoint="1,1">
                                        <GradientStop Color="#FF6B6B" Offset="0.0"/>
                                        <GradientStop Color="#FECA57" Offset="0.17"/>
                                        <GradientStop Color="#48DBFB" Offset="0.33"/>
                                        <GradientStop Color="#FF9FF3" Offset="0.5"/>
                                        <GradientStop Color="#54A0FF" Offset="0.67"/>
                                        <GradientStop Color="#5F27CD" Offset="0.83"/>
                                        <GradientStop Color="#FF6B6B" Offset="1.0"/>
                                    </LinearGradientBrush>
                                </Border.BorderBrush>
                                <Border.BorderThickness>
                                    <Thickness>3</Thickness>
                                </Border.BorderThickness>
                                <Border.Effect>
                                    <BlurEffect Radius="6"/>
                                </Border.Effect>
                            </Border>
                            <!-- 실제 입력 영역 -->
                        <Border x:Name="InputBorder"
                                Background="{DynamicResource ItemBackground}"
                                CornerRadius="14" Padding="6"
                                BorderBrush="{DynamicResource BorderColor}" BorderThickness="1.5">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>

                                <!-- Row 0: Phase 17-UI-E: @ / 스킬 / 첨부 툴바 (AgentInputArea 툴바 전용) -->
                                <ctrl:AgentInputArea x:Name="InputToolbar" Grid.Row="0"
                                                     IsToolbarOnly="True"/>

                                <!-- Row 1: 모델 셀렉터 + 템플릿 버튼 -->
                                <Grid Grid.Row="1">
                                    <Button x:Name="BtnModelSelector"
                                            Style="{StaticResource OutlineHoverBtn}"
                                            HorizontalAlignment="Left"
                                            Margin="8,2,0,2"
                                            Click="BtnModelSelector_Click"
                                            ToolTip="모델 변경"
                                            WindowChrome.IsHitTestVisibleInChrome="True">
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="&#xEA86;" FontFamily="Segoe MDL2 Assets" FontSize="13"
                                                       Foreground="{DynamicResource SecondaryText}"
                                                       VerticalAlignment="Center" Margin="0,0,5,0"/>
                                            <TextBlock x:Name="ModelLabel" FontSize="13"
                                                       Foreground="{DynamicResource SecondaryText}"
                                                       VerticalAlignment="Center"/>
                                            <TextBlock Text="&#xE70D;" FontFamily="Segoe MDL2 Assets" FontSize="9"
                                                       Foreground="{DynamicResource SecondaryText}"
                                                       VerticalAlignment="Center" Margin="4,1,0,0"/>
                                        </StackPanel>
                                    </Button>
                                    <Button x:Name="BtnTemplateSelector"
                                            Style="{StaticResource OutlineHoverBtn}"
                                            HorizontalAlignment="Right"
                                            Margin="0,2,8,2"
                                            Click="BtnTemplateSelector_Click"
                                            ToolTip="프롬프트 템플릿"
                                            WindowChrome.IsHitTestVisibleInChrome="True">
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="&#xE8A5;" FontFamily="Segoe MDL2 Assets" FontSize="13"
                                                       Foreground="{DynamicResource SecondaryText}"
                                                       VerticalAlignment="Center" Margin="0,0,5,0"/>
                                            <TextBlock Text="템플릿" FontSize="13"
                                                       Foreground="{DynamicResource SecondaryText}"
                                                       VerticalAlignment="Center"/>
                                        </StackPanel>
                                    </Button>
                                </Grid>

                                <!-- Row 2: 첨부 파일 목록 -->
                                <ItemsControl x:Name="AttachedFilesPanel" Grid.Row="2"
                                              Margin="8,0,8,2" Visibility="Collapsed">
                                    <ItemsControl.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <WrapPanel/>
                                        </ItemsPanelTemplate>
                                    </ItemsControl.ItemsPanel>
                                </ItemsControl>

                                <!-- 입력 영역 (Row 3) -->
                                <Grid Grid.Row="3">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>

                                    <Grid Grid.Column="0">
                                        <TextBox x:Name="InputBox"
                                                 FontSize="14" FontFamily="Segoe UI, Malgun Gothic"
                                                 Foreground="{DynamicResource PrimaryText}"
                                                 Background="Transparent"
                                                 CaretBrush="{DynamicResource AccentColor}"
                                                 BorderThickness="0" Padding="14,10"
                                                 VerticalContentAlignment="Top"
                                                 AcceptsReturn="True"
                                                 PreviewKeyDown="InputBox_PreviewKeyDown"
                                                 TextChanged="InputBox_TextChanged"
                                                 TextWrapping="Wrap"
                                                 MinHeight="40" MaxHeight="160"
                                                 VerticalScrollBarVisibility="Auto"/>
                                        <!-- 워터마크 (프롬프트 카드 안내문구) -->
                                        <TextBlock x:Name="InputWatermark"
                                                   FontSize="14" FontFamily="Segoe UI, Malgun Gothic"
                                                   Foreground="{DynamicResource SecondaryText}"
                                                   Padding="14,10" IsHitTestVisible="False"
                                                   TextWrapping="Wrap" Opacity="0.7"
                                                   Visibility="Collapsed"/>
                                        <!-- 슬래시 명령어 칩 (명령 선택 후 표시) -->
                                        <Border x:Name="SlashCommandChip"
                                                HorizontalAlignment="Left" VerticalAlignment="Top"
                                                Margin="10,7,0,0" Visibility="Collapsed"
                                                CornerRadius="7" Padding="8,3,4,3"
                                                IsHitTestVisible="True">
                                            <Border.Background>
                                                <SolidColorBrush Color="#4B5EFC" Opacity="0.13"/>
                                            </Border.Background>
                                            <StackPanel Orientation="Horizontal">
                                                <TextBlock x:Name="SlashChipText"
                                                           FontSize="12.5" FontWeight="SemiBold"
                                                           Foreground="#4B5EFC"
                                                           VerticalAlignment="Center"/>
                                                <Border x:Name="SlashChipClose" Cursor="Hand"
                                                        Padding="4,0,2,0" Margin="2,0,0,0"
                                                        VerticalAlignment="Center">
                                                    <TextBlock Text="&#xE711;"
                                                               FontFamily="Segoe MDL2 Assets"
                                                               FontSize="8" Foreground="#4B5EFC"/>
                                                </Border>
                                            </StackPanel>
                                        </Border>
                                    </Grid>

                                    <!-- 파일 첨부 -->
                                    <Button x:Name="BtnAttach" Style="{StaticResource GhostBtn}" Grid.Column="1"
                                            Width="36" Height="36" Margin="0,0,2,0" VerticalAlignment="Bottom"
                                            Click="BtnAttach_Click" ToolTip="파일 첨부"
                                            WindowChrome.IsHitTestVisibleInChrome="True"
                                            AllowDrop="True">
                                        <TextBlock Text="&#xE723;" FontFamily="Segoe MDL2 Assets" FontSize="14"
                                                   Foreground="{DynamicResource SecondaryText}"/>
                                    </Button>

                                    <!-- 내보내기 -->
                                    <Button Style="{StaticResource GhostBtn}" Grid.Column="2"
                                            Width="36" Height="36" Margin="0,0,2,0" VerticalAlignment="Bottom"
                                            Click="BtnExport_Click" ToolTip="대화 내보내기"
                                            WindowChrome.IsHitTestVisibleInChrome="True">
                                        <TextBlock Text="&#xEDE1;" FontFamily="Segoe MDL2 Assets" FontSize="14"
                                                   Foreground="{DynamicResource SecondaryText}"/>
                                    </Button>

                                    <!-- 일시정지 -->
                                    <Border x:Name="BtnPause" Grid.Column="3"
                                            Width="32" Height="32" Margin="0,0,2,0"
                                            CornerRadius="8" Cursor="Hand"
                                            Background="#18D97706" Visibility="Collapsed"
                                            VerticalAlignment="Bottom"
                                            MouseLeftButtonUp="BtnPause_Click"
                                            ToolTip="일시정지 / 재개">
                                        <TextBlock x:Name="PauseIcon" Text="&#xE769;"
                                                   FontFamily="Segoe MDL2 Assets" FontSize="12"
                                                   Foreground="#D97706"
                                                   HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                    </Border>

                                    <!-- 중지/전송 -->
                                    <Button x:Name="BtnStop" Grid.Column="3"
                                            Width="36" Height="36" Margin="4,0,4,0"
                                            Cursor="Hand" Click="BtnStop_Click"
                                            VerticalAlignment="Bottom" Visibility="Collapsed"
                                            WindowChrome.IsHitTestVisibleInChrome="True">
                                        <Button.Template>
                                            <ControlTemplate TargetType="Button">
                                                <Border Background="#DD4444" CornerRadius="10">
                                                    <TextBlock Text="&#xE71A;" FontFamily="Segoe MDL2 Assets"
                                                               FontSize="13" Foreground="White"
                                                               HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                                </Border>
                                            </ControlTemplate>
                                        </Button.Template>
                                    </Button>
                                    <Button x:Name="BtnSend" Grid.Column="4"
                                            Width="36" Height="36" Margin="4,0,4,0"
                                            Cursor="Hand" Click="BtnSend_Click"
                                            VerticalAlignment="Bottom">
                                        <Button.Template>
                                            <ControlTemplate TargetType="Button">
                                                <Border x:Name="Bd" Background="{DynamicResource AccentColor}"
                                                        CornerRadius="10">
                                                    <TextBlock Text="&#xE724;" FontFamily="Segoe MDL2 Assets"
                                                               FontSize="13" Foreground="White"
                                                               HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                                </Border>
                                                <ControlTemplate.Triggers>
                                                    <Trigger Property="IsMouseOver" Value="True">
                                                        <Setter TargetName="Bd" Property="Opacity" Value="0.85"/>
                                                    </Trigger>
                                                    <Trigger Property="IsEnabled" Value="False">
                                                        <Setter TargetName="Bd" Property="Opacity" Value="0.3"/>
                                                    </Trigger>
                                                </ControlTemplate.Triggers>
                                            </ControlTemplate>
                                        </Button.Template>
                                    </Button>
                                </Grid>
                            </Grid>
                        </Border>
                        </Grid> <!-- 글로우 + 입력 Grid 닫기 -->

                        <!-- ── 폴더 바 + 권한 메뉴 (입력 하단, Cowork/Code 탭 전용) ── -->
                        <Border x:Name="FolderBar" Visibility="Collapsed"
                                Margin="4,4,4,0" MinHeight="34">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>  <!-- 0: 폴더 아이콘 -->
                                    <ColumnDefinition Width="*"/>     <!-- 1: 폴더 경로 -->
                                    <ColumnDefinition Width="Auto"/>  <!-- 2: 폴더 해제 X -->
                                    <ColumnDefinition Width="Auto"/>  <!-- 3: 구분선 -->
                                    <ColumnDefinition Width="Auto"/>  <!-- 4: 포맷/디자인 -->
                                    <ColumnDefinition Width="Auto"/>  <!-- 5: 구분선 -->
                                    <ColumnDefinition Width="Auto"/>  <!-- 6: 데이터 활용 -->
                                    <ColumnDefinition Width="Auto"/>  <!-- 7: 구분선 -->
                                    <ColumnDefinition Width="Auto"/>  <!-- 8: 권한 -->
                                </Grid.ColumnDefinitions>

                                <!-- 폴더 아이콘 -->
                                <TextBlock Grid.Column="0" Text="&#xED25;" FontFamily="Segoe MDL2 Assets" FontSize="14"
                                           Foreground="{DynamicResource AccentColor}"
                                           VerticalAlignment="Center" Margin="6,0,4,0"/>

                                <!-- 폴더 경로 (클릭 시 최근 폴더 메뉴) -->
                                <TextBlock x:Name="FolderPathLabel" Grid.Column="1"
                                           Text="폴더를 선택하세요" FontSize="13"
                                           Foreground="{DynamicResource SecondaryText}"
                                           VerticalAlignment="Center" TextTrimming="CharacterEllipsis"
                                           Cursor="Hand" MouseLeftButtonUp="FolderPathLabel_Click"
                                           ToolTip="클릭하여 폴더 변경"/>

                                <!-- 폴더 해제 -->
                                <Button Grid.Column="2" Style="{StaticResource GhostBtn}"
                                        Padding="6,4" Click="BtnFolderClear_Click" ToolTip="폴더 연결 해제">
                                    <TextBlock Text="&#xE711;" FontFamily="Segoe MDL2 Assets" FontSize="10"
                                               Foreground="{DynamicResource SecondaryText}"/>
                                </Button>

                                <!-- 구분선 -->
                                <Border Grid.Column="3" Width="1" Height="18" Margin="4,0"
                                        Background="{DynamicResource SeparatorColor}"/>

                                <!-- 포맷/디자인 드롭다운 (Cowork 전용, 코드비하인드에서 동적 생성) -->
                                <StackPanel x:Name="MoodIconPanel" Grid.Column="4" Orientation="Horizontal"
                                            VerticalAlignment="Center"/>

                                <!-- 구분선 (포맷/디자인 뒤) -->
                                <Border x:Name="FormatMoodSeparator" Grid.Column="5" Width="1" Height="18" Margin="4,0"
                                        Background="{DynamicResource SeparatorColor}" Visibility="Collapsed"/>

                                <!-- 데이터 활용 메뉴 -->
                                <Border x:Name="BtnDataUsage" Grid.Column="6" Cursor="Hand"
                                        Background="Transparent" Padding="6,4"
                                        MouseLeftButtonUp="BtnDataUsage_Click"
                                        ToolTip="폴더 데이터 활용 수준">
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock x:Name="DataUsageIcon" Text="&#xE9F5;" FontFamily="Segoe MDL2 Assets" FontSize="12"
                                                   Foreground="{DynamicResource SecondaryText}"
                                                   VerticalAlignment="Center" Margin="0,0,4,0"/>
                                        <TextBlock x:Name="DataUsageLabel" Text="적극" FontSize="12"
                                                   Foreground="{DynamicResource SecondaryText}"
                                                   VerticalAlignment="Center"/>
                                    </StackPanel>
                                </Border>

                                <!-- 구분선 -->
                                <Border Grid.Column="7" Width="1" Height="18" Margin="4,0"
                                        Background="{DynamicResource SeparatorColor}"/>

                                <!-- 권한 메뉴 -->
                                <Button x:Name="BtnPermission" Grid.Column="8" Style="{StaticResource GhostBtn}"
                                        Padding="6,4" Click="BtnPermission_Click" ToolTip="파일 접근 권한">
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock x:Name="PermissionIcon" Text="&#xE8D7;" FontFamily="Segoe MDL2 Assets" FontSize="12"
                                                   Foreground="{DynamicResource SecondaryText}"
                                                   VerticalAlignment="Center" Margin="0,0,4,0"/>
                                        <TextBlock x:Name="PermissionLabel" Text="Ask" FontSize="12"
                                                   Foreground="{DynamicResource SecondaryText}"
                                                   VerticalAlignment="Center"/>
                                    </StackPanel>
                                </Button>
                            </Grid>
                        </Border>

                        <!-- 포맷 선택 팝업 -->
                        <Popup x:Name="FormatMenuPopup" PlacementTarget="{Binding ElementName=BtnFormatMenu}"
                               Placement="Top" StaysOpen="False"
                               AllowsTransparency="True" PopupAnimation="Fade">
                            <Border Background="{DynamicResource LauncherBackground}"
                                    BorderBrush="{DynamicResource BorderColor}"
                                    BorderThickness="1" CornerRadius="12"
                                    Padding="6" MinWidth="200">
                                <StackPanel x:Name="FormatMenuItems" Margin="2"/>
                            </Border>
                        </Popup>

                        <!-- 디자인 선택 팝업 -->
                        <Popup x:Name="MoodMenuPopup" PlacementTarget="{Binding ElementName=BtnMoodMenu}"
                               Placement="Top" StaysOpen="False"
                               AllowsTransparency="True" PopupAnimation="Fade">
                            <Border Background="{DynamicResource LauncherBackground}"
                                    BorderBrush="{DynamicResource BorderColor}"
                                    BorderThickness="1" CornerRadius="12"
                                    Padding="6" MinWidth="380" MaxHeight="480">
                                <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
                                    <StackPanel x:Name="MoodMenuItems" Margin="2"/>
                                </ScrollViewer>
                            </Border>
                        </Popup>

                        <!-- Auto 권한 경고 배너 (1회 필수 표시, X로 닫기 가능) -->
                        <Border x:Name="AutoPermissionWarning" Visibility="Collapsed"
                                Background="#2ADD6B20" CornerRadius="6" Margin="4,2,4,0" Padding="8,4">
                            <Grid>
                                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                                    <TextBlock Text="&#xE7BA;" FontFamily="Segoe MDL2 Assets" FontSize="11"
                                               Foreground="#DD6B20" VerticalAlignment="Center" Margin="0,0,6,0"/>
                                    <TextBlock Text="⚠ Auto 모드: AI가 파일을 자동으로 읽고 수정합니다" FontSize="10.5"
                                               Foreground="#DD6B20" VerticalAlignment="Center" FontWeight="SemiBold"/>
                                </StackPanel>
                                <Button x:Name="BtnAutoWarningClose" HorizontalAlignment="Right" VerticalAlignment="Center"
                                        Style="{StaticResource GhostBtn}" Padding="2" Cursor="Hand"
                                        Click="BtnAutoWarningClose_Click" ToolTip="닫기">
                                    <TextBlock Text="&#xE711;" FontFamily="Segoe MDL2 Assets" FontSize="8"
                                               Foreground="#DD6B20"/>
                                </Button>
                            </Grid>
                        </Border>
                    </StackPanel>
                </Border>

                <!-- ── 파일 탐색기 패널 ── -->
                <Border x:Name="FileBrowserPanel" Grid.Row="5" Visibility="Collapsed"
                        Background="{DynamicResource LauncherBackground}"
                        BorderBrush="{DynamicResource SeparatorColor}" BorderThickness="0,1,0,0"
                        MaxHeight="220">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <!-- 툴바 -->
                        <Border Grid.Row="0" Background="#08FFFFFF" Padding="8,4">
                            <Grid>
                                <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                                    <TextBlock Text="&#xED25;" FontFamily="Segoe MDL2 Assets" FontSize="12"
                                               Foreground="{DynamicResource AccentColor}"
                                               VerticalAlignment="Center" Margin="0,0,6,0"/>
                                    <TextBlock x:Name="FileBrowserTitle" Text="파일 탐색기"
                                               FontSize="11.5" FontWeight="SemiBold"
                                               Foreground="{DynamicResource PrimaryText}"
                                               VerticalAlignment="Center"/>
                                </StackPanel>
                                <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                                    <Button Style="{StaticResource GhostBtn}" Padding="3"
                                            Click="BtnFileBrowserRefresh_Click" ToolTip="새로고침" Cursor="Hand">
                                        <TextBlock Text="&#xE72C;" FontFamily="Segoe MDL2 Assets" FontSize="11"
                                                   Foreground="{DynamicResource SecondaryText}"/>
                                    </Button>
                                    <Button Style="{StaticResource GhostBtn}" Padding="3"
                                            Click="BtnFileBrowserOpenFolder_Click" ToolTip="탐색기에서 열기" Cursor="Hand">
                                        <TextBlock Text="&#xE8A7;" FontFamily="Segoe MDL2 Assets" FontSize="11"
                                                   Foreground="{DynamicResource SecondaryText}"/>
                                    </Button>
                                    <Button Style="{StaticResource GhostBtn}" Padding="3"
                                            Click="BtnFileBrowserClose_Click" ToolTip="닫기" Cursor="Hand">
                                        <TextBlock Text="&#xE70D;" FontFamily="Segoe MDL2 Assets" FontSize="9"
                                                   Foreground="{DynamicResource SecondaryText}"/>
                                    </Button>
                                </StackPanel>
                            </Grid>
                        </Border>
                        <!-- 트리뷰 -->
                        <TreeView x:Name="FileTreeView" Grid.Row="1"
                                  Background="Transparent" BorderThickness="0"
                                  Foreground="{DynamicResource PrimaryText}"
                                  FontSize="11.5" Padding="4,2"/>
                    </Grid>
                </Border>

                <!-- ── 하단 상태바 (Claude 스타일) ── -->
                <Border Grid.Row="6" Background="{DynamicResource LauncherBackground}"
                        BorderBrush="{DynamicResource SeparatorColor}" BorderThickness="0,1,0,0"
                        Padding="12,4,12,4" Height="28">
                    <Grid>
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Left"
                                    VerticalAlignment="Center">
                            <!-- 상태 아이콘 (다이아몬드 + 애니메이션) -->
                            <TextBlock x:Name="StatusDiamond" Text="◆" FontSize="10"
                                       Foreground="{DynamicResource AccentColor}"
                                       VerticalAlignment="Center" Margin="0,0,6,0"
                                       RenderTransformOrigin="0.5,0.5">
                                <TextBlock.RenderTransform>
                                    <RotateTransform x:Name="StatusDiamondRotate" Angle="0"/>
                                </TextBlock.RenderTransform>
                            </TextBlock>
                            <TextBlock x:Name="StatusLabel" Text="대기 중" FontSize="11"
                                       Foreground="{DynamicResource SecondaryText}"
                                       VerticalAlignment="Center"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right"
                                    VerticalAlignment="Center">
                            <!-- 워크플로우 분석기 열기 버튼 (개발자 모드) -->
                            <Border x:Name="BtnShowAnalyzer" Visibility="Collapsed"
                                    CornerRadius="4" Padding="5,2" Margin="0,0,8,0"
                                    Background="#1A7C3AED" Cursor="Hand" ToolTip="워크플로우 분석기"
                                    MouseLeftButtonUp="BtnShowAnalyzer_Click">
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="&#xE9D9;" FontFamily="Segoe MDL2 Assets" FontSize="10"
                                               Foreground="#7C3AED" VerticalAlignment="Center" Margin="0,0,4,0"/>
                                    <TextBlock Text="분석기" FontSize="10" Foreground="#7C3AED"
                                               VerticalAlignment="Center"/>
                                </StackPanel>
                            </Border>
                            <TextBlock x:Name="StatusElapsed" Text="" FontSize="10"
                                       Foreground="{DynamicResource SecondaryText}"
                                       VerticalAlignment="Center" Margin="0,0,12,0"/>
                            <TextBlock x:Name="StatusTokens" Text="" FontSize="10"
                                       Foreground="{DynamicResource SecondaryText}"
                                       VerticalAlignment="Center"/>
                        </StackPanel>
                    </Grid>
                </Border>
            </Grid>

            <!-- ══ 미리보기 스플리터 (Column 3) ══ -->
            <GridSplitter x:Name="PreviewSplitter" Grid.Column="3" Width="5"
                          HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                          Background="Transparent" Cursor="SizeWE" Visibility="Collapsed"
                          ShowsPreview="True"/>

            <!-- ══ 문서 미리보기 패널 (Column 4) ══ -->
            <!--
                WebView2 에어스페이스 문제 해결:
                탭 바와 WebView2 콘텐츠를 DockPanel으로 분리.
                DockPanel.Dock="Top"인 탭 바는 별도 WPF 레이어로 렌더링되어
                WebView2 HWND에 가려지지 않음.
            -->
            <Border x:Name="PreviewPanel" Grid.Column="4" Visibility="Collapsed"
                    Background="{DynamicResource LauncherBackground}"
                    BorderBrush="{DynamicResource BorderColor}"
                    BorderThickness="1,0,0,0">
                <DockPanel LastChildFill="True">
                    <!-- 탭 바 + 도구 버튼 (DockPanel.Top — WebView2 위에 독립 레이어) -->
                    <Border DockPanel.Dock="Top" Background="#0AFFFFFF"
                            BorderBrush="{DynamicResource BorderColor}" BorderThickness="0,0,0,1"
                            Padding="0" Panel.ZIndex="10" Focusable="True"
                            PreviewMouseDown="PreviewTabBar_PreviewMouseDown">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <ScrollViewer Grid.Column="0" HorizontalScrollBarVisibility="Hidden"
                                          VerticalScrollBarVisibility="Disabled" CanContentScroll="True">
                                <StackPanel x:Name="PreviewTabPanel" Orientation="Horizontal"/>
                            </ScrollViewer>
                            <StackPanel Grid.Column="1" Orientation="Horizontal" Margin="4,0">
                                <Button x:Name="BtnOpenExternal" Style="{StaticResource GhostBtn}" Padding="6"
                                        Click="BtnOpenExternal_Click" ToolTip="외부 프로그램으로 열기" Cursor="Hand">
                                    <TextBlock Text="&#xE8A7;" FontFamily="Segoe MDL2 Assets" FontSize="12"
                                               Foreground="{DynamicResource SecondaryText}" IsHitTestVisible="False"/>
                                </Button>
                                <Button Style="{StaticResource GhostBtn}" Padding="6"
                                        Click="BtnClosePreview_Click" ToolTip="미리보기 닫기" Cursor="Hand">
                                    <TextBlock Text="&#xE711;" FontFamily="Segoe MDL2 Assets" FontSize="10"
                                               Foreground="{DynamicResource SecondaryText}" IsHitTestVisible="False"/>
                                </Button>
                            </StackPanel>
                        </Grid>
                    </Border>

                    <!-- 미리보기 콘텐츠 영역 (DockPanel.Fill — WebView2는 여기에만 존재) -->
                    <Grid ClipToBounds="True">
                        <wv2:WebView2 x:Name="PreviewWebView" Visibility="Collapsed"/>
                        <ScrollViewer x:Name="PreviewTextScroll" Visibility="Collapsed"
                                      VerticalScrollBarVisibility="Auto" Padding="12,8">
                            <TextBlock x:Name="PreviewTextBlock" TextWrapping="Wrap"
                                       FontFamily="Consolas" FontSize="12"
                                       Foreground="{DynamicResource PrimaryText}"/>
                        </ScrollViewer>
                        <DataGrid x:Name="PreviewDataGrid" Visibility="Collapsed"
                                  AutoGenerateColumns="True" IsReadOnly="True"
                                  HeadersVisibility="Column" GridLinesVisibility="All"
                                  Background="Transparent" Foreground="White"
                                  BorderThickness="0" CanUserAddRows="False"
                                  RowBackground="#0AFFFFFF" AlternatingRowBackground="#15FFFFFF"
                                  ColumnHeaderHeight="30" RowHeight="28" FontSize="11.5"/>
                        <TextBlock x:Name="PreviewEmpty" Text="미리보기할 파일이 없습니다"
                                   HorizontalAlignment="Center" VerticalAlignment="Center"
                                   FontSize="12" Foreground="{DynamicResource SecondaryText}"
                                   Visibility="Collapsed"/>
                    </Grid>
                </DockPanel>
            </Border>

            <!-- Phase 32: 우측 설정 패널 (슬라이드인) -->
            <ctrl:AgentSettingsPanel x:Name="SettingsPanel" Grid.Column="5"
                                     Visibility="Collapsed"/>

            <!-- 리사이즈 그립 -->
            <Thumb x:Name="ResizeGrip" Grid.Column="2"
                   Width="14" Height="14"
                   HorizontalAlignment="Right" VerticalAlignment="Bottom"
                   Cursor="SizeNWSE" Opacity="0.3"
                   DragDelta="ResizeGrip_DragDelta">
                <Thumb.Template>
                    <ControlTemplate>
                        <TextBlock Text="&#xE740;" FontFamily="Segoe MDL2 Assets" FontSize="10"
                                   Foreground="{DynamicResource SecondaryText}"/>
                    </ControlTemplate>
                </Thumb.Template>
            </Thumb>
        </Grid>
    </Border>
</Window>
