<Window x:Class="HorseRacingPredictor.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Betting Predictor" Width="1100" Height="680"
        MinWidth="900" MinHeight="540"
        WindowStartupLocation="CenterScreen"
        Background="#1E1E2E"
        Loaded="Window_Loaded">

    <Window.Resources>
        <!-- =========================================================
             CATPPUCCIN MOCHA PALETTE
             ========================================================= -->
        <Color x:Key="CBase">#1E1E2E</Color>
        <Color x:Key="CMantle">#181825</Color>
        <Color x:Key="CCrust">#11111B</Color>
        <Color x:Key="CSurface0">#313244</Color>
        <Color x:Key="CSurface1">#45475A</Color>
        <Color x:Key="CSurface2">#585B70</Color>
        <Color x:Key="COverlay0">#6C7086</Color>
        <Color x:Key="CText">#CDD6F4</Color>
        <Color x:Key="CSubtext0">#A6ADC8</Color>
        <Color x:Key="CSubtext1">#BAC2DE</Color>
        <Color x:Key="CBlue">#89B4FA</Color>
        <Color x:Key="CGreen">#A6E3A1</Color>
        <Color x:Key="CRed">#F38BA8</Color>
        <Color x:Key="CPeach">#FAB387</Color>
        <Color x:Key="CLavender">#B4BEFE</Color>

        <SolidColorBrush x:Key="BrBase"       Color="{StaticResource CBase}"/>
        <SolidColorBrush x:Key="BrMantle"     Color="{StaticResource CMantle}"/>
        <SolidColorBrush x:Key="BrSurface0"   Color="{StaticResource CSurface0}"/>
        <SolidColorBrush x:Key="BrSurface1"   Color="{StaticResource CSurface1}"/>
        <SolidColorBrush x:Key="BrSurface2"   Color="{StaticResource CSurface2}"/>
        <SolidColorBrush x:Key="BrOverlay0"   Color="{StaticResource COverlay0}"/>
        <SolidColorBrush x:Key="BrText"       Color="{StaticResource CText}"/>
        <SolidColorBrush x:Key="BrSubtext0"   Color="{StaticResource CSubtext0}"/>
        <SolidColorBrush x:Key="BrBlue"       Color="{StaticResource CBlue}"/>
        <SolidColorBrush x:Key="BrGreen"      Color="{StaticResource CGreen}"/>
        <SolidColorBrush x:Key="BrRed"        Color="{StaticResource CRed}"/>
        <SolidColorBrush x:Key="BrPeach"      Color="{StaticResource CPeach}"/>
        <SolidColorBrush x:Key="BrLavender"   Color="{StaticResource CLavender}"/>

        <!-- =========================================================
             NAV BUTTON STYLE  (icon-only sidebar)
             ========================================================= -->
        <Style x:Key="NavBtn" TargetType="RadioButton">
            <Setter Property="Width" Value="48"/>
            <Setter Property="Height" Value="48"/>
            <Setter Property="Margin" Value="6,4"/>
            <Setter Property="Cursor" Value="Hand"/>
            <Setter Property="Foreground" Value="{StaticResource BrSubtext0}"/>
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="RadioButton">
                        <Grid>
                            <Border x:Name="Bg" CornerRadius="10" Background="{TemplateBinding Background}"/>
                            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="Bg" Property="Background" Value="#28283A"/>
                            </Trigger>
                            <Trigger Property="IsChecked" Value="True">
                                <Setter TargetName="Bg" Property="Background" Value="{StaticResource BrBlue}"/>
                                <Setter Property="Foreground" Value="#181825"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <!-- =========================================================
             ACCENT BUTTON
             ========================================================= -->
        <Style x:Key="AccentBtn" TargetType="Button">
            <Setter Property="Foreground" Value="#181825"/>
            <Setter Property="FontFamily" Value="Segoe UI Semibold"/>
            <Setter Property="FontSize" Value="13"/>
            <Setter Property="Padding" Value="18,7"/>
            <Setter Property="Cursor" Value="Hand"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border x:Name="Bd" CornerRadius="8"
                                Background="{TemplateBinding Background}"
                                Padding="{TemplateBinding Padding}">
                            <ContentPresenter 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.40"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <!-- =========================================================
             FLAT TEXTBOX
             ========================================================= -->
        <Style x:Key="FlatTb" TargetType="TextBox">
            <Setter Property="Background" Value="{StaticResource BrSurface0}"/>
            <Setter Property="Foreground" Value="{StaticResource BrText}"/>
            <Setter Property="CaretBrush" Value="{StaticResource BrText}"/>
            <Setter Property="BorderBrush" Value="{StaticResource BrSurface1}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Padding" Value="10,7"/>
            <Setter Property="FontSize" Value="13"/>
            <Setter Property="FontFamily" Value="Segoe UI"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="TextBox">
                        <Border x:Name="Bd" CornerRadius="6"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Padding="{TemplateBinding Padding}">
                            <ScrollViewer x:Name="PART_ContentHost"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsFocused" Value="True">
                                <Setter TargetName="Bd" Property="BorderBrush" Value="{StaticResource BrBlue}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <!-- =========================================================
             PASSWORD BOX
             ========================================================= -->
        <Style x:Key="FlatPb" TargetType="PasswordBox">
            <Setter Property="Background" Value="{StaticResource BrSurface0}"/>
            <Setter Property="Foreground" Value="{StaticResource BrText}"/>
            <Setter Property="CaretBrush" Value="{StaticResource BrText}"/>
            <Setter Property="BorderBrush" Value="{StaticResource BrSurface1}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Padding" Value="10,7"/>
            <Setter Property="FontSize" Value="13"/>
            <Setter Property="FontFamily" Value="Segoe UI"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="PasswordBox">
                        <Border x:Name="Bd" CornerRadius="6"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Padding="{TemplateBinding Padding}">
                            <ScrollViewer x:Name="PART_ContentHost"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsFocused" Value="True">
                                <Setter TargetName="Bd" Property="BorderBrush" Value="{StaticResource BrBlue}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <!-- =========================================================
             PROGRESS BAR
             ========================================================= -->
        <Style x:Key="ModernPb" TargetType="ProgressBar">
            <Setter Property="Height" Value="4"/>
            <Setter Property="Background" Value="{StaticResource BrSurface0}"/>
            <Setter Property="Foreground" Value="{StaticResource BrBlue}"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ProgressBar">
                        <Grid>
                            <Border CornerRadius="2" Background="{TemplateBinding Background}"/>
                            <Border x:Name="PART_Indicator" CornerRadius="2"
                                    Background="{TemplateBinding Foreground}"
                                    HorizontalAlignment="Left"/>
                            <Border x:Name="PART_Track"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <!-- =========================================================
             DATAGRID
             ========================================================= -->
        <Style x:Key="ModernDg" TargetType="DataGrid">
            <Setter Property="Background" Value="#282A3A"/>
            <Setter Property="Foreground" Value="{StaticResource BrText}"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="RowBackground" Value="#282A3A"/>
            <Setter Property="AlternatingRowBackground" Value="#2D2F42"/>
            <Setter Property="GridLinesVisibility" Value="Horizontal"/>
            <Setter Property="HorizontalGridLinesBrush" Value="#37394E"/>
            <Setter Property="HeadersVisibility" Value="Column"/>
            <Setter Property="RowHeaderWidth" Value="0"/>
            <Setter Property="AutoGenerateColumns" Value="True"/>
            <Setter Property="IsReadOnly" Value="True"/>
            <Setter Property="SelectionMode" Value="Single"/>
            <Setter Property="CanUserAddRows" Value="False"/>
            <Setter Property="CanUserDeleteRows" Value="False"/>
            <Setter Property="CanUserResizeRows" Value="False"/>
            <Setter Property="FontFamily" Value="Segoe UI"/>
            <Setter Property="FontSize" Value="13"/>
        </Style>
        <Style TargetType="DataGridColumnHeader">
            <Setter Property="Background" Value="#23243A"/>
            <Setter Property="Foreground" Value="{StaticResource BrBlue}"/>
            <Setter Property="FontFamily" Value="Segoe UI Semibold"/>
            <Setter Property="FontSize" Value="13"/>
            <Setter Property="Padding" Value="10,8"/>
            <Setter Property="BorderBrush" Value="#37394E"/>
            <Setter Property="BorderThickness" Value="0,0,0,1"/>
        </Style>
        <Style TargetType="DataGridCell">
            <Setter Property="Padding" Value="8,6"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="DataGridCell">
                        <Border Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}">
                            <ContentPresenter VerticalAlignment="Center"/>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsSelected" Value="True">
                    <Setter Property="Background" Value="#3C3F58"/>
                    <Setter Property="Foreground" Value="{StaticResource BrBlue}"/>
                </Trigger>
            </Style.Triggers>
        </Style>
        <Style TargetType="DataGridRow">
            <Setter Property="Margin" Value="0"/>
            <Style.Triggers>
                <Trigger Property="IsSelected" Value="True">
                    <Setter Property="Background" Value="#3C3F58"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>

    <!-- ================================================================
         MAIN LAYOUT : Sidebar | Content
         ================================================================ -->
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="64"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <!-- =============  SIDEBAR  ============= -->
        <Border Grid.Column="0" Background="#181825">
            <DockPanel LastChildFill="False">
                <!-- App icon -->
                <TextBlock DockPanel.Dock="Top" Text="BP"
                           FontFamily="Segoe UI Black" FontSize="18"
                           Foreground="{StaticResource BrBlue}"
                           HorizontalAlignment="Center" Margin="0,16,0,12"/>
                <Border DockPanel.Dock="Top" Height="1" Background="#37394E" Margin="10,0"/>

                <!-- Nav icons -->
                <StackPanel DockPanel.Dock="Top" Margin="0,8,0,0">
                    <RadioButton x:Name="navFootball" Style="{StaticResource NavBtn}"
                                 IsChecked="True" ToolTip="Calcio"
                                 Checked="navFootball_Checked">
                        <TextBlock Text="&#xE8D6;" FontFamily="Segoe MDL2 Assets" FontSize="20"
                                   Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType=RadioButton}}"/>
                    </RadioButton>
                    <RadioButton x:Name="navRacing" Style="{StaticResource NavBtn}"
                                 ToolTip="Corse Cavalli"
                                 Checked="navRacing_Checked">
                        <TextBlock Text="&#xE7C1;" FontFamily="Segoe MDL2 Assets" FontSize="20"
                                   Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType=RadioButton}}"/>
                    </RadioButton>
                    <RadioButton x:Name="navSettings" Style="{StaticResource NavBtn}"
                                 ToolTip="Impostazioni"
                                 Checked="navSettings_Checked">
                        <TextBlock Text="&#xE713;" FontFamily="Segoe MDL2 Assets" FontSize="20"
                                   Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType=RadioButton}}"/>
                    </RadioButton>
                    <RadioButton x:Name="navInfo" Style="{StaticResource NavBtn}"
                                 ToolTip="Informazioni"
                                 Checked="navInfo_Checked">
                        <TextBlock Text="&#xE946;" FontFamily="Segoe MDL2 Assets" FontSize="20"
                                   Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType=RadioButton}}"/>
                    </RadioButton>
                </StackPanel>
            </DockPanel>
        </Border>

        <!-- =============  CONTENT  ============= -->
        <DockPanel Grid.Column="1">
            <!-- Header -->
            <Border DockPanel.Dock="Top" Height="52" Background="#181825">
                <TextBlock x:Name="lblTitle" Text="Calcio"
                           FontFamily="Segoe UI Semibold" FontSize="20"
                           Foreground="{StaticResource BrText}"
                           VerticalAlignment="Center" Margin="24,0"/>
            </Border>
            <Border DockPanel.Dock="Top" Height="1" Background="#37394E"/>

            <!-- Page host -->
            <Grid Background="{StaticResource BrBase}">

                <!-- ====  PAGE: FOOTBALL  ==== -->
                <Grid x:Name="pageFootball" Margin="24,16">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <!-- Toolbar -->
                    <StackPanel Grid.Row="0" Orientation="Horizontal" Margin="0,0,0,12">
                        <DatePicker x:Name="dpFootball" Width="160"
                                    Background="{StaticResource BrSurface0}"
                                    Foreground="{StaticResource BrText}"
                                    FontSize="13" VerticalContentAlignment="Center"/>
                        <Button x:Name="btnDownloadFb" Content="Scarica Partite"
                                Style="{StaticResource AccentBtn}"
                                Background="{StaticResource BrBlue}" Margin="12,0,0,0"
                                Click="btnDownloadFb_Click"/>
                        <Button x:Name="btnExportFbCsv" Content="Esporta CSV"
                                Style="{StaticResource AccentBtn}"
                                Background="{StaticResource BrGreen}" Margin="8,0,0,0"
                                IsEnabled="False"
                                Click="btnExportFbCsv_Click"/>
                    </StackPanel>
                    <!-- Status -->
                    <StackPanel Grid.Row="1" Margin="0,0,0,8">
                        <ProgressBar x:Name="pbFootball" Style="{StaticResource ModernPb}" Margin="0,0,0,4"/>
                        <TextBlock x:Name="lblStatusFb" Text="Pronto"
                                   FontSize="12" Foreground="{StaticResource BrSubtext0}"/>
                    </StackPanel>
                    <!-- Grid -->
                    <DataGrid x:Name="dgFootball" Grid.Row="2" Style="{StaticResource ModernDg}"/>
                </Grid>

                <!-- ====  PAGE: HORSE RACING  ==== -->
                <Grid x:Name="pageRacing" Margin="24,16" Visibility="Collapsed">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <!-- Toolbar -->
                    <StackPanel Grid.Row="0" Orientation="Horizontal" Margin="0,0,0,12">
                        <ComboBox x:Name="cmbDay" Width="140"
                                  Background="{StaticResource BrSurface0}"
                                  Foreground="{StaticResource BrText}"
                                  FontSize="13" VerticalContentAlignment="Center"/>
                        <Button x:Name="btnDownloadRc" Content="Scarica Corse"
                                Style="{StaticResource AccentBtn}"
                                Background="{StaticResource BrBlue}" Margin="12,0,0,0"
                                Click="btnDownloadRc_Click"/>
                        <Button x:Name="btnExportRcCsv" Content="Esporta CSV"
                                Style="{StaticResource AccentBtn}"
                                Background="{StaticResource BrGreen}" Margin="8,0,0,0"
                                IsEnabled="False"
                                Click="btnExportRcCsv_Click"/>
                    </StackPanel>
                    <!-- Status -->
                    <StackPanel Grid.Row="1" Margin="0,0,0,8">
                        <ProgressBar x:Name="pbRacing" Style="{StaticResource ModernPb}" Margin="0,0,0,4"/>
                        <TextBlock x:Name="lblStatusRc" Text="Pronto"
                                   FontSize="12" Foreground="{StaticResource BrSubtext0}"/>
                    </StackPanel>
                    <!-- Grid -->
                    <DataGrid x:Name="dgRacing" Grid.Row="2" Style="{StaticResource ModernDg}"/>
                </Grid>

                <!-- ====  PAGE: SETTINGS  ==== -->
                <ScrollViewer x:Name="pageSettings" Visibility="Collapsed"
                              VerticalScrollBarVisibility="Auto" Padding="24,16">
                    <StackPanel MaxWidth="600" HorizontalAlignment="Left">

                        <!-- FOOTBALL API -->
                        <TextBlock Text="Calcio &#x2014; API" FontSize="16" FontFamily="Segoe UI Semibold"
                                   Foreground="{StaticResource BrBlue}" Margin="0,0,0,8"/>
                        <Border Background="#282A3A" CornerRadius="10" Padding="20" Margin="0,0,0,20">
                            <StackPanel>
                                <TextBlock Text="API Key (api-football)" Foreground="{StaticResource BrText}"
                                           FontSize="13" Margin="0,0,0,6"/>
                                <TextBox x:Name="txtApiKey" Style="{StaticResource FlatTb}"/>
                                <TextBlock Text="Cartella esportazione CSV" Foreground="{StaticResource BrText}"
                                           FontSize="13" Margin="0,14,0,6"/>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>
                                    <TextBox x:Name="txtFbExportPath" Style="{StaticResource FlatTb}" IsReadOnly="True"/>
                                    <Button Grid.Column="1" Content="Sfoglia..." Margin="8,0,0,0"
                                            Style="{StaticResource AccentBtn}" Background="{StaticResource BrSurface2}"
                                            Foreground="{StaticResource BrText}"
                                            Click="btnBrowseFbExport_Click"/>
                                </Grid>
                            </StackPanel>
                        </Border>

                        <!-- HORSE RACING API -->
                        <TextBlock Text="Corse Cavalli &#x2014; API" FontSize="16" FontFamily="Segoe UI Semibold"
                                   Foreground="{StaticResource BrBlue}" Margin="0,0,0,8"/>
                        <Border Background="#282A3A" CornerRadius="10" Padding="20" Margin="0,0,0,20">
                            <StackPanel>
                                <TextBlock Text="Username" Foreground="{StaticResource BrText}"
                                           FontSize="13" Margin="0,0,0,6"/>
                                <TextBox x:Name="txtRacingUser" Style="{StaticResource FlatTb}"/>
                                <TextBlock Text="Password" Foreground="{StaticResource BrText}"
                                           FontSize="13" Margin="0,14,0,6"/>
                                <PasswordBox x:Name="txtRacingPass" Style="{StaticResource FlatPb}"/>
                                <TextBlock Text="Cartella esportazione CSV" Foreground="{StaticResource BrText}"
                                           FontSize="13" Margin="0,14,0,6"/>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>
                                    <TextBox x:Name="txtRcExportPath" Style="{StaticResource FlatTb}" IsReadOnly="True"/>
                                    <Button Grid.Column="1" Content="Sfoglia..." Margin="8,0,0,0"
                                            Style="{StaticResource AccentBtn}" Background="{StaticResource BrSurface2}"
                                            Foreground="{StaticResource BrText}"
                                            Click="btnBrowseRcExport_Click"/>
                                </Grid>
                            </StackPanel>
                        </Border>

                        <!-- SAVE -->
                        <Button Content="Salva impostazioni"
                                Style="{StaticResource AccentBtn}"
                                Background="{StaticResource BrGreen}"
                                HorizontalAlignment="Left" Margin="0,4,0,24"
                                Click="btnSaveSettings_Click"/>
                    </StackPanel>
                </ScrollViewer>

                <!-- ====  PAGE: INFO  ==== -->
                <Grid x:Name="pageInfo" Visibility="Collapsed" Margin="24,16">
                    <Border Background="#282A3A" CornerRadius="12" Padding="32"
                            VerticalAlignment="Top" HorizontalAlignment="Left"
                            MaxWidth="520">
                        <StackPanel>
                            <TextBlock Text="Betting Predictor" FontSize="26"
                                       FontFamily="Segoe UI Black"
                                       Foreground="{StaticResource BrBlue}"/>
                            <TextBlock Text="Versione 2.0.0" FontSize="14"
                                       Foreground="{StaticResource BrSubtext0}" Margin="0,4,0,16"/>
                            <TextBlock TextWrapping="Wrap" FontSize="13" Foreground="{StaticResource BrText}"
                                       LineHeight="22">
                                Applicazione per lo scaricamento e l'analisi di dati sportivi
                                tramite API esterne. Supporta calcio e corse dei cavalli
                                con esportazione in CSV.
                            </TextBlock>
                            <TextBlock Text=".NET Framework 4.8.1  -  WPF"
                                       FontSize="12" Foreground="{StaticResource BrSubtext0}" Margin="0,16,0,0"/>
                            <TextBlock FontSize="12" Foreground="{StaticResource BrOverlay0}" Margin="0,8,0,0">
                                <Run Text="&#x00A9; 2025 - Tutti i diritti riservati"/>
                            </TextBlock>
                        </StackPanel>
                    </Border>
                </Grid>

            </Grid>
        </DockPanel>
    </Grid>
</Window>
