<?php
/**
 * Plugin Name: 11. Football Leagues Profit Grid Home
 * Description: Displays a grid of football leagues with profit data and SEO links
 * Version: 2.5
 * Author: Lefoos
 */

if (!defined('ABSPATH')) {
    exit;
}

class FootballLeaguesProfitGrid {
    
    private $league_configs;
    
    public function __construct() {
        $this->league_configs = $this->get_league_configs();
        
        add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
        add_shortcode('leagues_profit_grid', array($this, 'render_grid_shortcode'));
        add_action('wp_head', array($this, 'add_structured_data'));
        add_action('wp_head', array($this, 'add_seo_meta_tags'));
        add_action('wp_footer', array($this, 'add_share_functionality'));
    }
    
    private function get_league_configs() {
        return array(
            'england_premier_league' => array(
                'name' => 'Premier League',
                'full_name' => 'England Premier League',
                'seo_name' => 'Premier League Predictions',
                'slug' => 'england-premier-league',
                'country' => 'England',
                'flag' => '🇬🇧',
                'logo' => 'https://over-under-predictions.com/wp-content/uploads/2025/08/england-premier-league.png',
                'url' => 'https://over-under-predictions.com/england-premier-league-predictions/'
            ),
            'england_championship' => array(
                'name' => 'Championship', 
                'full_name' => 'England Championship',
                'seo_name' => 'Championship Predictions',
                'slug' => 'england-championship',
                'country' => 'England',
                'flag' => '🇬🇧',
                'logo' => 'https://over-under-predictions.com/wp-content/uploads/2025/08/england-elf-championship.png',
                'url' => 'https://over-under-predictions.com/england-championship-predictions/'
            ),
            'england_efl_league_one' => array(
                'name' => 'EFL League One',
                'full_name' => 'England EFL League One',
                'seo_name' => 'EFL League One Predictions', 
                'slug' => 'england-efl-league-one',
                'country' => 'England',
                'flag' => '🇬🇧',
                'logo' => 'https://over-under-predictions.com/wp-content/uploads/2025/08/england-elf-league-one.png',
                'url' => 'https://over-under-predictions.com/england-efl-league-one-predictions/'
            ),
            'england_efl_league_two' => array(
                'name' => 'EFL League Two',
                'full_name' => 'England EFL League Two',
                'seo_name' => 'EFL League Two Predictions',
                'slug' => 'england-efl-league-two', 
                'country' => 'England',
                'flag' => '🇬🇧',
                'logo' => 'https://over-under-predictions.com/wp-content/uploads/2025/08/england-elf-league-two.png',
                'url' => 'https://over-under-predictions.com/england-efl-league-two-predictions/'
            ),
            'scotland_premiership' => array(
                'name' => 'Premiership',
                'full_name' => 'Scotland Premiership',
                'seo_name' => 'Premiership Predictions',
                'slug' => 'scotland-premiership',
                'country' => 'Scotland',
                'flag' => '🏴󠁧󠁢󠁳󠁣󠁴󠁿',
                'logo' => 'https://over-under-predictions.com/wp-content/uploads/2025/08/scotland_premiership.png',
                'url' => 'https://over-under-predictions.com/scotland-premiership-predictions/'
            ),
            'scotland_championship' => array(
                'name' => 'Championship',
                'full_name' => 'Scotland Championship',
                'seo_name' => 'Championship Predictions',
                'slug' => 'scotland-championship',
                'country' => 'Scotland',
                'flag' => '🏴󠁧󠁢󠁳󠁣󠁴󠁿',
                'logo' => 'https://over-under-predictions.com/wp-content/uploads/2025/10/scotland_championship.png',
                'url' => 'https://over-under-predictions.com/scotland-championship-predictions/'
            ),
            'scotland_league_one' => array(
                'name' => 'League One',
                'full_name' => 'Scotland League One',
                'seo_name' => 'League One Predictions',
                'slug' => 'scotland-league-one',
                'country' => 'Scotland',
                'flag' => '🏴󠁧󠁢󠁳󠁣󠁴󠁿',
                'logo' => 'https://over-under-predictions.com/wp-content/uploads/2025/08/scotland_league1.png',
                'url' => 'https://over-under-predictions.com/scotland-league-one-predictions/'
            ),
            'scotland_league_two' => array(
                'name' => 'League Two',
                'full_name' => 'Scotland League Two',
                'seo_name' => 'League Two Predictions',
                'slug' => 'scotland-league-two',
                'country' => 'Scotland',
                'flag' => '🏴󠁧󠁢󠁳󠁣󠁴󠁿',
                'logo' => 'https://over-under-predictions.com/wp-content/uploads/2025/08/scotland_league2.png',
                'url' => 'https://over-under-predictions.com/scotland-league-two-predictions/'
            ),
            'germany_bundesliga' => array(
                'name' => 'Bundesliga',
                'full_name' => 'Germany Bundesliga',
                'seo_name' => 'Bundesliga Predictions',
                'slug' => 'germany-bundesliga',
                'country' => 'Germany',
                'flag' => '🇩🇪',
                'logo' => 'https://over-under-predictions.com/wp-content/uploads/2025/08/Bundesliga.png',
                'url' => 'https://over-under-predictions.com/germany-bundesliga-predictions/'
            ),
            'germany_bundesliga_2' => array(
                'name' => 'Bundesliga 2',
                'full_name' => 'Germany Bundesliga 2',
                'seo_name' => 'Bundesliga 2 Predictions',
                'slug' => 'germany-bundesliga-2',
                'country' => 'Germany',
                'flag' => '🇩🇪',
                'logo' => 'https://over-under-predictions.com/wp-content/uploads/2025/08/Bundesliga2.png',
                'url' => 'https://over-under-predictions.com/germany-bundesliga-2-predictions/'
            ),
            'italy_serie_a' => array(
                'name' => 'Serie A',
                'full_name' => 'Italy Serie A',
                'seo_name' => 'Serie A Predictions',
                'slug' => 'italy-serie-a',
                'country' => 'Italy',
                'flag' => '🇮🇹',
                'logo' => 'https://over-under-predictions.com/wp-content/uploads/2025/08/italy-serie-a.png',
                'url' => 'https://over-under-predictions.com/italy-serie-a-predictions/'
            ),
            'italy_serie_b' => array(
                'name' => 'Serie B',
                'full_name' => 'Italy Serie B',
                'seo_name' => 'Serie B Predictions',
                'slug' => 'italy-serie-b',
                'country' => 'Italy',
                'flag' => '🇮🇹',
                'logo' => 'https://over-under-predictions.com/wp-content/uploads/2025/08/italy-serie-b.png',
                'url' => 'https://over-under-predictions.com/italy-serie-b-predictions/'
            ),
            'spain_la_liga' => array(
                'name' => 'La Liga',
                'full_name' => 'Spain La Liga',
                'seo_name' => 'La Liga Predictions',
                'slug' => 'spain-la-liga',
                'country' => 'Spain',
                'flag' => '🇪🇸',
                'logo' => 'https://over-under-predictions.com/wp-content/uploads/2025/08/la_liga.png',
                'url' => 'https://over-under-predictions.com/spain-la-liga-predictions/'
            ),
            'spain_segunda_division' => array(
                'name' => 'Segunda División',
                'full_name' => 'Spain Segunda División',
                'seo_name' => 'Segunda División Predictions',
                'slug' => 'spain-segunda-division',
                'country' => 'Spain',
                'flag' => '🇪🇸',
                'logo' => 'https://over-under-predictions.com/wp-content/uploads/2025/08/la-liga-2.png',
                'url' => 'https://over-under-predictions.com/spain-segunda-division-predictions/'
            ),
            'france_ligue_1' => array(
                'name' => 'Ligue 1',
                'full_name' => 'France Ligue 1',
                'seo_name' => 'Ligue 1 Predictions',
                'slug' => 'france-ligue-1',
                'country' => 'France',
                'flag' => '🇫🇷',
                'logo' => 'https://over-under-predictions.com/wp-content/uploads/2025/08/france_ligue1.png',
                'url' => 'https://over-under-predictions.com/france-ligue-1-predictions/'
            ),
            'france_ligue_2' => array(
                'name' => 'Ligue 2',
                'full_name' => 'France Ligue 2',
                'seo_name' => 'Ligue 2 Predictions',
                'slug' => 'france-ligue-2',
                'country' => 'France',
                'flag' => '🇫🇷',
                'logo' => 'https://over-under-predictions.com/wp-content/uploads/2025/08/france_ligue2.png',
                'url' => 'https://over-under-predictions.com/france-ligue-2-predictions/'
            ),
            'netherlands_eredivisie' => array(
                'name' => 'Eredivisie',
                'full_name' => 'Netherlands Eredivisie',
                'seo_name' => 'Eredivisie Predictions',
                'slug' => 'netherlands-eredivisie',
                'country' => 'Netherlands',
                'flag' => '🇳🇱',
                'logo' => 'https://over-under-predictions.com/wp-content/uploads/2025/10/netherlands_eredivisie.png',
                'url' => 'https://over-under-predictions.com/netherlands-eredivisie-predictions/'
            ),
            'belgium_pro_league' => array(
                'name' => 'Pro League',
                'full_name' => 'Belgium Pro League',
                'seo_name' => 'Pro League Predictions',
                'slug' => 'belgium-pro-league',
                'country' => 'Belgium',
                'flag' => '🇧🇪',
                'logo' => 'https://over-under-predictions.com/wp-content/uploads/2025/10/belgium_pro_league.png',
                'url' => 'https://over-under-predictions.com/belgium-pro-league-predictions/'
            ),
            'portugal_liga_portugal_betclic' => array(
                'name' => 'Liga Portugal',
                'full_name' => 'Portugal Liga Portugal Betclic',
                'seo_name' => 'Liga Portugal Predictions',
                'slug' => 'portugal-liga-portugal',
                'country' => 'Portugal',
                'flag' => '🇵🇹',
                'logo' => 'https://over-under-predictions.com/wp-content/uploads/2025/10/portugal_liga_portugal_betclic.png',
                'url' => 'https://over-under-predictions.com/portugal-liga-portugal-betclic-predictions/'
            ),
            'turkey_super_lig' => array(
                'name' => 'Süper Lig',
                'full_name' => 'Turkey Süper Lig',
                'seo_name' => 'Süper Lig Predictions',
                'slug' => 'turkey-super-lig',
                'country' => 'Turkey',
                'flag' => '🇹🇷',
                'logo' => 'https://over-under-predictions.com/wp-content/uploads/2025/10/turkey_super_lig.png',
                'url' => 'https://over-under-predictions.com/turkey-super-lig-predictions/'
            ),
            'greece_super_league' => array(
                'name' => 'Super League',
                'full_name' => 'Greece Super League',
                'seo_name' => 'Super League Predictions',
                'slug' => 'greece-super-league',
                'country' => 'Greece',
                'flag' => '🇬🇷',
                'logo' => 'https://over-under-predictions.com/wp-content/uploads/2025/10/greece_super_league.png',
                'url' => 'https://over-under-predictions.com/greece-super-league-predictions/'
            )
        );
    }
    
    public function enqueue_scripts() {
        wp_enqueue_style('leagues-profit-grid-styles', plugin_dir_url(__FILE__) . 'assets/css/leagues-profit-grid.css', array(), '2.5');
    }
    
    public function add_seo_meta_tags() {
        global $post;
        if ($post && has_shortcode($post->post_content, 'leagues_profit_grid')) {
            $league_profits = $this->calculate_all_leagues_profit();
            $top_leagues = array_slice($league_profits, 0, 3, true);
            $top_league_key = key($top_leagues);
            $top_league_seo_name = $this->league_configs[$top_league_key]['seo_name'];
            $top_league_profit = number_format($top_leagues[$top_league_key]['total_profit'], 2);
            
            echo '<meta name="description" content="Live football leagues profitability ranking. ' . $top_league_seo_name . ' leads with ' . $top_league_profit . ' units profit. Compare over under predictions performance across Premier League Predictions, La Liga Predictions, Serie A Predictions, Bundesliga Predictions." />' . "\n";
            echo '<meta name="keywords" content="football predictions, over under betting, league profitability, sports betting, football statistics, Premier League predictions, La Liga predictions, Serie A predictions, Bundesliga predictions, Ligue 1 predictions, Eredivisie predictions" />' . "\n";
            echo '<meta property="og:title" content="Live Football Leagues Profitability Rankings - Over Under Predictions" />' . "\n";
            echo '<meta property="og:description" content="Real-time profit tracking across top football leagues. Data-driven over under predictions with proven results including Premier League Predictions, La Liga Predictions, and Serie A Predictions." />' . "\n";
            echo '<meta property="og:type" content="website" />' . "\n";
            echo '<meta name="twitter:card" content="summary_large_image" />' . "\n";
            echo '<meta name="twitter:title" content="Football Leagues Profitability Rankings" />' . "\n";
            echo '<meta name="twitter:description" content="Live tracking of over under predictions performance across major football leagues including Premier League Predictions and La Liga Predictions" />' . "\n";
            
            echo '<meta name="robots" content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1" />' . "\n";
            echo '<link rel="canonical" href="' . esc_url(home_url($_SERVER['REQUEST_URI'])) . '" />' . "\n";
        }
    }
    
    public function add_structured_data() {
        global $post;
        if ($post && has_shortcode($post->post_content, 'leagues_profit_grid')) {
            $league_profits = $this->calculate_all_leagues_profit();
            $last_updated = $this->get_last_updated_date($league_profits);
            $update_frequency = $this->get_update_frequency();
            ?>
            <script type="application/ld+json">
            {
                "@context": "https://schema.org",
                "@type": "ItemList",
                "name": "Live Football Leagues Profitability Rankings - Over Under Predictions",
                "description": "Real-time ranking of football leagues by profitability for over under predictions. Track performance across Premier League Predictions, La Liga Predictions, Serie A Predictions, Bundesliga Predictions and other major competitions with live profit data.",
                "numberOfItems": <?php echo count($this->league_configs); ?>,
                "itemListOrder": "https://schema.org/Descending",
                "dateModified": "<?php echo $last_updated; ?>",
                "mainEntityOfPage": {
                    "@type": "WebPage",
                    "@id": "<?php echo esc_url(home_url($_SERVER['REQUEST_URI'])); ?>"
                },
                "author": {
                    "@type": "Organization",
                    "name": "Over Under Predictions",
                    "url": "https://over-under-predictions.com"
                },
                "publisher": {
                    "@type": "Organization",
                    "name": "Over Under Predictions",
                    "logo": {
                        "@type": "ImageObject",
                        "url": "https://over-under-predictions.com/wp-content/uploads/2025/08/logo.png"
                    }
                },
                "mainEntity": {
                    "@type": "SportsOrganization",
                    "name": "Football Leagues Profitability Rankings",
                    "description": "Live updated profitability data for football predictions across major leagues"
                },
                "potentialAction": {
                    "@type": "UpdateAction",
                    "target": {
                        "@type": "EntryPoint",
                        "urlTemplate": "<?php echo esc_url(home_url($_SERVER['REQUEST_URI'])); ?>"
                    },
                    "actionFrequency": "<?php echo $update_frequency; ?>"
                },
                "itemListElement": [
                    <?php
                    $i = 0;
                    foreach ($league_profits as $league_key => $profit_data) {
                        $league = $this->league_configs[$league_key];
                        if ($i > 0) echo ',';
                        ?>
                        {
                            "@type": "ListItem",
                            "position": <?php echo $i + 1; ?>,
                            "url": "<?php echo esc_js($league['url']); ?>",
                            "name": "<?php echo esc_js($league['seo_name']); ?> - Profit: <?php echo number_format($profit_data['total_profit'], 2); ?> units",
                            "description": "Over under predictions performance for <?php echo esc_js($league['seo_name']); ?> with <?php echo $profit_data['total_matches']; ?> predictions analyzed",
                            "additionalProperty": {
                                "@type": "PropertyValue",
                                "name": "profit",
                                "value": "<?php echo number_format($profit_data['total_profit'], 2); ?>"
                            }
                        }
                        <?php
                        $i++;
                    }
                    ?>
                ]
            }
            </script>
            
            <script type="application/ld+json">
            {
                "@context": "https://schema.org",
                "@type": "Organization",
                "name": "Over Under Predictions",
                "url": "https://over-under-predictions.com",
                "logo": "https://over-under-predictions.com/wp-content/uploads/2025/08/logo.png",
                "description": "Professional football predictions and betting tips with proven profitability across major leagues including Premier League Predictions, La Liga Predictions, and Serie A Predictions.",
                "sameAs": [],
                "address": {
                    "@type": "PostalAddress",
                    "addressCountry": "GR"
                }
            }
            </script>
            <?php
        }
    }
    
    private function get_update_frequency() {
        return "Daily";
    }
    
    private function get_last_updated_date($league_profits) {
        $latest_timestamp = 0;
        foreach ($this->league_configs as $league_key => $league_config) {
            $configs = $this->get_market_configs($league_key);
            foreach ($configs as $market_key => $config) {
                $history_data = $this->get_market_history($config, $league_key);
                if ($history_data) {
                    foreach ($history_data as $match) {
                        if (isset($match['date_str'])) {
                            $timestamp = $this->parse_date($match['date_str']);
                            if ($timestamp > $latest_timestamp) {
                                $latest_timestamp = $timestamp;
                            }
                        }
                    }
                }
            }
        }
        
        if ($latest_timestamp > 0) {
            return date('c', $latest_timestamp);
        }
        
        return date('c');
    }
    
private function get_market_urls($league_slug) {
    if ($league_slug === 'portugal-liga-portugal') {
        $league_slug = 'portugal-liga-portugal-betclic';
    }
    
    return array(
        '1x2' => 'https://over-under-predictions.com/' . $league_slug . '-1x2-predictions/',
        'btts' => 'https://over-under-predictions.com/' . $league_slug . '-btts-predictions/',
        'corners' => 'https://over-under-predictions.com/' . $league_slug . '-over-under-corners-predictions/',
        'cards' => 'https://over-under-predictions.com/' . $league_slug . '-over-under-cards-predictions/',
        'over_under_1_5' => 'https://over-under-predictions.com/' . $league_slug . '-over-under-1-5-goals-predictions/',
        'over_under_2_5' => 'https://over-under-predictions.com/' . $league_slug . '-over-under-2-5-goals-predictions/',
        'over_under_3_5' => 'https://over-under-predictions.com/' . $league_slug . '-over-under-3-5-goals-predictions/'
    );
}
    
public function render_grid_shortcode($atts) {
    $atts = shortcode_atts(array(
        'leagues_per_row' => '3',
        'show_country' => 'true'
    ), $atts);
    
    $league_profits = $this->calculate_all_leagues_profit();
    $total_leagues = count($league_profits);
    $total_matches = array_sum(array_column($league_profits, 'total_matches'));
    $last_updated = $this->get_last_updated_date($league_profits);
    
    $top_leagues = array_slice($league_profits, 0, 3, true);
    $top_leagues_data = [];
    $i = 0;
    foreach ($top_leagues as $league_key => $profit_data) {
        $top_leagues_data[$i] = [
            'seo_name' => $this->league_configs[$league_key]['seo_name'],
            'profit' => $profit_data['total_profit']
        ];
        $i++;
    }
    
    ob_start();
    ?>

    <section class="profit-grid-section" aria-label="Football Leagues Profitability Rankings">
        <div class="grid-header-section">
            <h2 class="grid-main-title">Live Over Under Prediction Profitability Rankings</h2>
            <div class="grid-description">
                <p>
    Track real-time <strong>profitability</strong> across 21 football leagues including 
    the <strong>Premier League</strong>, <strong>La Liga</strong>, <strong>Serie A</strong>, and <strong>Bundesliga</strong>. 
    Our system updates as matches conclude, revealing which leagues deliver the best <strong>returns</strong>.
</p>

                <div class="last-updated">
                    <small>Last updated: <time datetime="<?php echo date('c'); ?>"><?php echo date('F j, Y'); ?></time></small>
                </div>
            </div>
        </div>
        
        <div class="profit-grid-wrapper">
            <div class="profit-grid-container" data-leagues-per-row="<?php echo esc_attr($atts['leagues_per_row']); ?>" role="list" aria-label="Football leagues ranked by profitability">
                <?php 
                $rank = 0;
                foreach ($league_profits as $league_key => $profit_data): 
                    $rank++;
                    $league = $this->league_configs[$league_key];
                    $profit_class = $profit_data['total_profit'] > 0 ? 'profit-positive' : ($profit_data['total_profit'] < 0 ? 'profit-negative' : 'profit-neutral');
                    $profit_per_match = $profit_data['total_matches'] > 0 ? $profit_data['total_profit'] / $profit_data['total_matches'] : 0;
                    $total_all_matches = $this->calculate_total_all_matches($league_key);
                    $market_urls = $this->get_market_urls($league['slug']);
                    
                    $ranking_badge = '';
                    if ($rank === 1) {
                        $ranking_badge = '<span class="ranking-badge rank-1">🥇</span>';
                    } elseif ($rank === 2) {
                        $ranking_badge = '<span class="ranking-badge rank-2">🥈</span>';
                    } elseif ($rank === 3) {
                        $ranking_badge = '<span class="ranking-badge rank-3">🥉</span>';
                    }
                ?>
                    <div class="grid-item-card" data-profit="<?php echo esc_attr($profit_data['total_profit']); ?>" role="listitem">
                        <a href="<?php echo esc_url($league['url']); ?>" class="grid-item-link" 
                           title="View detailed over under predictions and statistics for <?php echo esc_attr($league['seo_name']); ?>"
                           aria-label="<?php echo esc_attr($league['seo_name']); ?> - Total profit: <?php echo number_format($profit_data['total_profit'], 2); ?> units from <?php echo $profit_data['total_matches']; ?> predictions">
                            
                            <div class="logo-wrapper">
                                <img src="<?php echo esc_url($league['logo']); ?>" 
                                     alt="<?php echo esc_attr($league['seo_name']); ?> official league logo" 
                                     class="league-logo-image" 
                                     loading="lazy"
                                     width="160"
                                     height="160">
                            </div>
                            
                            <?php echo $ranking_badge; ?>
                            
                            <div class="market-buttons-container">
                                <div class="market-button-row">
                                    <a href="<?php echo esc_url($market_urls['1x2']); ?>" class="market-button-single" title="1X2 Match Result Predictions for <?php echo esc_attr($league['seo_name']); ?>">
                                        <span class="market-button-text">1X2</span>
                                    </a>
                                    <a href="<?php echo esc_url($market_urls['btts']); ?>" class="market-button-single" title="Both Teams To Score Predictions for <?php echo esc_attr($league['seo_name']); ?>">
                                        <span class="market-button-text">BTTS</span>
                                    </a>
                                    <a href="<?php echo esc_url($market_urls['corners']); ?>" class="market-button-single" title="Over/Under Corners Predictions for <?php echo esc_attr($league['seo_name']); ?>">
                                        <span class="market-button-text">O/U Corners</span>
                                    </a>
                                    <a href="<?php echo esc_url($market_urls['cards']); ?>" class="market-button-single" title="Over/Under Cards Predictions for <?php echo esc_attr($league['seo_name']); ?>">
                                        <span class="market-button-text">O/U Cards</span>
                                    </a>
                                </div>
                                
                                <div class="market-button-row">
                                    <a href="<?php echo esc_url($market_urls['over_under_1_5']); ?>" class="market-button-single" title="Over/Under 1.5 Goals Predictions for <?php echo esc_attr($league['seo_name']); ?>">
                                        <span class="market-button-text">O/U 1.5</span>
                                    </a>
                                    <a href="<?php echo esc_url($market_urls['over_under_2_5']); ?>" class="market-button-single" title="Over/Under 2.5 Goals Predictions for <?php echo esc_attr($league['seo_name']); ?>">
                                        <span class="market-button-text">O/U 2.5</span>
                                    </a>
                                    <a href="<?php echo esc_url($market_urls['over_under_3_5']); ?>" class="market-button-single" title="Over/Under 3.5 Goals Predictions for <?php echo esc_attr($league['seo_name']); ?>">
                                        <span class="market-button-text">O/U 3.5</span>
                                    </a>
                                    <button type="button" class="market-button-single share-button" 
        data-league-name="<?php echo esc_attr($league['seo_name']); ?>"
        data-league-url="<?php echo esc_url($league['url']); ?>"
        title="Share <?php echo esc_attr($league['seo_name']); ?> on social media">
    <span class="market-button-text">❤️ Share</span>
</button>
                                </div>
                            </div>
                            
                            <div class="profit-section">
                                <div class="item-title"><?php echo esc_html($league['seo_name']); ?></div>
                                
                                <div class="profit-amount <?php echo $profit_class; ?>">
                                    <?php echo number_format($profit_data['total_profit'], 2); ?> units
                                </div>
                                <div class="details-grid">
                                    <div class="detail-box">
                                        <span class="detail-number"><?php echo $total_all_matches; ?></span>
                                        <span class="detail-text">Total Matches</span>
                                    </div>
                                    <div class="detail-box">
                                        <span class="detail-number"><?php echo $profit_data['total_matches'] > 0 ? number_format(($profit_data['total_profit'] / $profit_data['total_matches']) * 100, 1) : '0.0'; ?>%</span>
                                        <span class="detail-text">ROI</span>
                                    </div>
                                </div>
                                
                                <div class="country-info-inside">
                                    <span class="country-flag-inside"><?php echo $league['flag']; ?></span>
                                    <span class="country-name-inside"><?php echo esc_html($league['country']); ?></span>
                                </div>
                            </div>
                            
                            <div class="analytics-button-container">
                                <a href="<?php echo esc_url($league['url']); ?>" class="full-analytics-button" 
                                   title="View comprehensive analytics and ROI metrics for <?php echo esc_attr($league['seo_name']); ?>">
                                    Full Analytics & ROI Metrics
                                </a>
                            </div>
                        </a>
                    </div>
                <?php endforeach; ?>
            </div>
        </div>
        
        <div class="content-section">
            <div class="rich-content">
                <h2>Professional Football Predictions Across Major Leagues</h2>
                <p>Our comprehensive <strong>over/under predictions</strong> platform provides real-time profitability tracking for the world's top football competitions. Whether you're looking for <strong>Premier League Predictions</strong>, <strong>La Liga Predictions</strong>, or <strong>Serie A Predictions</strong>, our data-driven approach ensures you get the most accurate insights.</p>
                
                <h3>Why Choose Our Football Predictions?</h3>
                <ul>
    <li><strong style="color: #475569;">Live Profit Tracking:</strong> Real-time updates on prediction performance across all major leagues</li>
    <li><strong style="color: #475569;">Data-Driven Analysis:</strong> In-depth statistical insights based on thousands of matches</li>
    <li><strong style="color: #475569;">Multiple Market Coverage:</strong> Comprehensive predictions including over/under goals, both teams to score, and match results</li>
    <li><strong style="color: #475569;">Proven Profitability:</strong> Transparent tracking showing actual profit/loss for every league</li>
</ul>

                
                <h3>Top Performing Leagues</h3>
<p>Our <strong><?php echo $top_leagues_data[0]['seo_name']; ?></strong> leads with <span style="color: #28a745; font-weight: 700;"><?php echo number_format($top_leagues_data[0]['profit'], 2); ?> units</span> profit, followed by <strong><?php echo $top_leagues_data[1]['seo_name']; ?></strong> with <span style="color: #28a745; font-weight: 700;"><?php echo number_format($top_leagues_data[1]['profit'], 2); ?> units</span> and <strong><?php echo $top_leagues_data[2]['seo_name']; ?></strong> with <span style="color: #28a745; font-weight: 700;"><?php echo number_format($top_leagues_data[2]['profit'], 2); ?> units</span>. The system integrates expert predictions as matches conclude, providing up-to-date league information.</p>

                
                <div class="keywords-section">
                    <strong>Popular Search Terms:</strong> Premier League Predictions, La Liga Predictions, Serie A Predictions, Bundesliga Predictions, Ligue 1 Predictions, Over Under Predictions, Football Betting Tips, Soccer Predictions
                </div>
            </div>
        </div>
    </section>

    <?php
    return ob_get_clean();
}
    
    private function calculate_total_all_matches($league_key) {
        $configs = $this->get_market_configs($league_key);
        $max_matches = 0;
        
        foreach ($configs as $market_key => $config) {
            $history_data = $this->get_market_history($config, $league_key);
            
            if (!$history_data || !is_array($history_data)) {
                continue;
            }
            
            $market_matches = count($history_data);
            if ($market_matches > $max_matches) {
                $max_matches = $market_matches;
            }
        }
        
        return $max_matches;
    }
    
    private function calculate_all_leagues_profit() {
        $leagues_profit = [];
        
        foreach ($this->league_configs as $league_key => $league_config) {
            $profit_data = $this->calculate_league_total_profit($league_key);
            if ($profit_data !== null) {
                $leagues_profit[$league_key] = $profit_data;
            }
        }
        
        uasort($leagues_profit, function($a, $b) {
            return $b['total_profit'] <=> $a['total_profit'];
        });
        
        return $leagues_profit;
    }
    
    private function calculate_league_total_profit($league_key) {
        $configs = $this->get_market_configs($league_key);
        $total_profit = 0;
        $total_matches = 0;
        
        foreach ($configs as $market_key => $config) {
            $history_data = $this->get_market_history($config, $league_key);
            
            if (!$history_data || !is_array($history_data)) {
                continue;
            }
            
            $market_profit = 0;
            $market_matches = 0;
            
            foreach ($history_data as $match) {
                if ($this->is_match_settled($match, $config['type'])) {
                    $profit = $this->calculate_match_profit($match, $config['type']);
                    $market_profit += $profit;
                    $market_matches++;
                }
            }
            
            $total_profit += $market_profit;
            $total_matches += $market_matches;
        }
        
        return [
            'total_profit' => $total_profit,
            'total_matches' => $total_matches
        ];
    }
    
    private function get_market_configs($league) {
        $league_slug = $league;
        
        return array(
            '1x2' => array(
                'name' => $this->league_configs[$league]['full_name'] . ' - 1X2 Match Result',
                'short_name' => '1X2',
                'history_file' => "{$league_slug}_1x2_history.json",
                'type' => '1x2'
            ),
            '1_5' => array(
                'name' => $this->league_configs[$league]['full_name'] . ' - Over/Under 1.5 Goals',
                'short_name' => 'O/U 1.5',
                'history_file' => "{$league_slug}_over_under_1_5_history.json",
                'type' => 'over_under'
            ),
            '2_5' => array(
                'name' => $this->league_configs[$league]['full_name'] . ' - Over/Under 2.5 Goals',
                'short_name' => 'O/U 2.5', 
                'history_file' => "{$league_slug}_over_under_2_5_history.json",
                'type' => 'over_under'
            ),
            '3_5' => array(
                'name' => $this->league_configs[$league]['full_name'] . ' - Over/Under 3.5 Goals',
                'short_name' => 'O/U 3.5',
                'history_file' => "{$league_slug}_over_under_3_5_history.json", 
                'type' => 'over_under'
            ),
            'btts' => array(
                'name' => $this->league_configs[$league]['full_name'] . ' - Both Teams To Score',
                'short_name' => 'BTTS',
                'history_file' => "{$league_slug}_btts_history.json",
                'type' => 'btts'
            ),
            'corners' => array(
                'name' => $this->league_configs[$league]['full_name'] . ' - Over/Under Corners',
                'short_name' => 'O/U Corners',
                'history_file' => "{$league_slug}_corners_history.json",
                'type' => 'corners'
            ),
            'cards' => array(
                'name' => $this->league_configs[$league]['full_name'] . ' - Over/Under Cards', 
                'short_name' => 'O/U Cards',
                'history_file' => "{$league_slug}_cards_history.json",
                'type' => 'cards'
            )
        );
    }
    
    private function get_market_history($config, $league) {
        $possible_paths = [];
        
        switch ($config['type']) {
            case '1x2':
                $possible_paths[] = ABSPATH . 'wp-content/plugins/06. Universal 1X2 Predictions/' . $config['history_file'];
                break;
            case 'over_under':
                if (strpos($config['history_file'], 'over_under_1_5') !== false) {
                    $possible_paths[] = ABSPATH . 'wp-content/plugins/06. Universal Over Under 1.5 Predictions/' . $config['history_file'];
                } elseif (strpos($config['history_file'], 'over_under_2_5') !== false) {
                    $possible_paths[] = ABSPATH . 'wp-content/plugins/06. Universal Over Under 2.5 Predictions/' . $config['history_file'];
                } elseif (strpos($config['history_file'], 'over_under_3_5') !== false) {
                    $possible_paths[] = ABSPATH . 'wp-content/plugins/06. Universal Over Under 3.5 Predictions/' . $config['history_file'];
                }
                break;
            case 'btts':
                $possible_paths[] = ABSPATH . 'wp-content/plugins/06. Universal BTTS Predictions/' . $config['history_file'];
                break;
            case 'corners':
                $possible_paths[] = ABSPATH . 'wp-content/plugins/06. Universal Over Under Corners Predictions/' . $config['history_file'];
                break;
            case 'cards':
                $possible_paths[] = ABSPATH . 'wp-content/plugins/06. Universal Over Under Cards Predictions/' . $config['history_file'];
                break;
        }

        foreach ($possible_paths as $path) {
            if (file_exists($path)) {
                $json_data = file_get_contents($path);
                $data = json_decode($json_data, true);
                
                if (json_last_error() === JSON_ERROR_NONE && is_array($data)) {
                    return $data;
                }
            }
        }
        
        return null;
    }
    
    private function is_match_settled($match, $type) {
        if ($this->is_future_match($match)) {
            return false;
        }
        
        $is_settled = false;
        
        if ($type === '1x2') {
            $is_settled = isset($match['actual_result']) && !empty(trim($match['actual_result'])) && $match['actual_result'] !== '-';
        } elseif ($type === 'btts') {
            $is_settled = isset($match['actual_btts']) && !empty(trim($match['actual_btts'])) && $match['actual_btts'] !== '-';
        } elseif ($type === 'corners' || $type === 'cards') {
            $is_settled = isset($match['actual_result']) && !empty(trim($match['actual_result'])) && $match['actual_result'] !== '-';
        } else {
            $is_settled = isset($match['actual_over_under']) && !empty(trim($match['actual_over_under'])) && $match['actual_over_under'] !== '-';
        }
        
        return $is_settled;
    }
    
    private function is_future_match($match) {
        if (empty($match['date_str'])) {
            return false;
        }
        
        $match_timestamp = $this->parse_date($match['date_str']);
        $current_timestamp = current_time('timestamp');
        
        return $match_timestamp > ($current_timestamp + 7200);
    }
    
    private function parse_date($date_str) {
        if (empty($date_str)) {
            return 0;
        }
        
        $formats = [
            'd/m/Y H:i',
            'd/m/Y H:i:s',
            'd/m/Y',
            'Y-m-d H:i:s',
            'Y-m-d H:i',
            'Y-m-d',
        ];
        
        foreach ($formats as $format) {
            $date = DateTime::createFromFormat($format, $date_str);
            if ($date !== false) {
                return $date->getTimestamp();
            }
        }
        
        return strtotime($date_str);
    }
    
    private function calculate_match_profit($match, $type) {
        if (!$this->is_match_settled($match, $type)) {
            return 0;
        }
        
        if ($type === '1x2') {
            return $this->calculate_1x2_profit($match);
        } elseif ($type === 'btts') {
            return $this->calculate_btts_profit($match);
        } elseif ($type === 'corners') {
            return $this->calculate_corners_profit($match);
        } elseif ($type === 'cards') {
            return $this->calculate_cards_profit($match);
        } else {
            return $this->calculate_over_under_profit($match);
        }
    }
    
    private function calculate_1x2_profit($match) {
        if (!isset($match['actual_result']) || !isset($match['prediction'])) {
            return 0;
        }

        $prediction_map = ['H' => '1', 'D' => 'X', 'A' => '2'];
        $actual_result = trim($match['actual_result']);
        $predicted_result = trim($match['prediction']);
        
        $actual_result = $prediction_map[$actual_result] ?? $actual_result;
        $predicted_result = $prediction_map[$predicted_result] ?? $predicted_result;

        $odds = 0;
        if ($predicted_result === '1') {
            $odds = isset($match['home_odds']) ? floatval($match['home_odds']) : 0;
        } elseif ($predicted_result === 'X') {
            $odds = isset($match['draw_odds']) ? floatval($match['draw_odds']) : 0;
        } elseif ($predicted_result === '2') {
            $odds = isset($match['away_odds']) ? floatval($match['away_odds']) : 0;
        }

        if ($odds <= 1.0) {
            return 0;
        }

        if ($predicted_result === $actual_result) {
            $profit = $odds - 1;
            return $profit;
        } else {
            return -1;
        }
    }
    
    private function calculate_over_under_profit($match) {
        if (!isset($match['result']) || !isset($match['actual_over_under'])) {
            return 0;
        }

        $actual_result = trim($match['actual_over_under']);
        $predicted_result = trim($match['result']);
        
        $odds = 0;
        if ($predicted_result === 'Over') {
            $odds = isset($match['over_odds']) ? floatval($match['over_odds']) : 0;
        } elseif ($predicted_result === 'Under') {
            $odds = isset($match['under_odds']) ? floatval($match['under_odds']) : 0;
        }

        if ($odds <= 1.0) {
            return 0;
        }

        if ($predicted_result === $actual_result) {
            $profit = $odds - 1;
            return $profit;
        } else {
            return -1;
        }
    }
    
    private function calculate_btts_profit($match) {
        if (!isset($match['result']) || !isset($match['actual_btts'])) {
            return 0;
        }

        $actual_result = trim($match['actual_btts']);
        $predicted_result = trim($match['result']);
        
        $odds = 0;
        if ($predicted_result === 'Yes') {
            $odds = isset($match['btts_yes_odds']) ? floatval($match['btts_yes_odds']) : 0;
        } elseif ($predicted_result === 'No') {
            $odds = isset($match['btts_no_odds']) ? floatval($match['btts_no_odds']) : 0;
        }

        if ($odds <= 1.0) {
            return 0;
        }

        if ($predicted_result === $actual_result) {
            $profit = $odds - 1;
            return $profit;
        } else {
            return -1;
        }
    }
    
    private function calculate_corners_profit($match) {
        if (!isset($match['prediction_result']) || !isset($match['actual_result'])) {
            return 0;
        }

        $actual_result = trim($match['actual_result']);
        $predicted_result = trim($match['prediction_result']);
        
        $odds = isset($match['odds']) ? floatval($match['odds']) : 0;

        if ($odds <= 1.0) {
            return 0;
        }

        if ($predicted_result === $actual_result) {
            $profit = $odds - 1;
            return $profit;
        } else {
            return -1;
        }
    }
    
    private function calculate_cards_profit($match) {
        return $this->calculate_corners_profit($match);
    }

    public function add_share_functionality() {
        global $post;
        if ($post && has_shortcode($post->post_content, 'leagues_profit_grid')) {
            $this->output_share_script();
        }
    }

    private function output_share_script() {
        ?>
        <script type="text/javascript">
        document.addEventListener('DOMContentLoaded', function() {
            const shareButtons = document.querySelectorAll('.share-button');
            
            shareButtons.forEach(button => {
                button.addEventListener('click', function(e) {
                    e.preventDefault();
                    e.stopPropagation();
                    
                    const leagueName = this.getAttribute('data-league-name');
                    const leagueUrl = this.getAttribute('data-league-url');
                    
                    const shareText = `Check out ${leagueName} predictions and profitability analysis on Over Under Predictions! ${leagueUrl}`;
                    
                    if (navigator.share) {
                        navigator.share({
                            title: leagueName + ' Predictions',
                            text: shareText,
                            url: leagueUrl
                        }).catch(console.error);
                    } else {
                        openSharePopup(leagueName, leagueUrl, shareText);
                    }
                });
            });
            
            function openSharePopup(leagueName, leagueUrl, shareText) {
                const popup = document.createElement('div');
                popup.className = 'share-popup-overlay';
                popup.innerHTML = `
                    <div class="share-popup">
                        <div class="share-popup-header">
                            <h3>Share ${leagueName}</h3>
                            <button class="close-popup">&times;</button>
                        </div>
                        <div class="share-buttons">
                            <a href="https://twitter.com/intent/tweet?text=${encodeURIComponent(shareText)}" target="_blank" class="share-option twitter">
                                <span>Twitter</span>
                            </a>
                            <a href="https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(leagueUrl)}&quote=${encodeURIComponent(shareText)}" target="_blank" class="share-option facebook">
                                <span>Facebook</span>
                            </a>
                            <a href="https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(leagueUrl)}" target="_blank" class="share-option linkedin">
                                <span>LinkedIn</span>
                            </a>
                            <a href="https://api.whatsapp.com/send?text=${encodeURIComponent(shareText)}" target="_blank" class="share-option whatsapp">
                                <span>WhatsApp</span>
                            </a>
                            <button class="share-option copy-link" data-url="${leagueUrl}">
                                <span>Copy Link</span>
                            </button>
                        </div>
                    </div>
                `;
                
                document.body.appendChild(popup);
                
                popup.querySelector('.close-popup').addEventListener('click', () => {
                    document.body.removeChild(popup);
                });
                
                popup.addEventListener('click', (e) => {
                    if (e.target === popup) {
                        document.body.removeChild(popup);
                    }
                });
                
                popup.querySelector('.copy-link').addEventListener('click', function() {
                    navigator.clipboard.writeText(this.getAttribute('data-url')).then(() => {
                        const originalText = this.querySelector('span').textContent;
                        this.querySelector('span').textContent = 'Copied!';
                        setTimeout(() => {
                            this.querySelector('span').textContent = originalText;
                        }, 2000);
                    });
                });
            }
        });
        </script>
        
        <style>
        .share-popup-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.5);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 10000;
        }
        
        .share-popup {
            background: white;
            border-radius: 10px;
            padding: 20px;
            max-width: 400px;
            width: 90%;
            box-shadow: 0 10px 30px rgba(0,0,0,0.3);
        }
        
        .share-popup-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            border-bottom: 1px solid #eee;
            padding-bottom: 10px;
        }
        
        .share-popup-header h3 {
            margin: 0;
            color: #333;
            font-size: 18px;
        }
        
        .close-popup {
            background: none;
            border: none;
            font-size: 24px;
            cursor: pointer;
            color: #666;
        }
        
        .share-buttons {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 10px;
        }
        
        .share-option {
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: 6px;
            text-decoration: none;
            color: #333;
            font-weight: 600;
            transition: all 0.3s ease;
            background: white;
            cursor: pointer;
        }
        
        .share-option:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(0,0,0,0.15);
        }
        
        .share-option.twitter { border-color: #1DA1F2; color: #1DA1F2; }
        .share-option.facebook { border-color: #4267B2; color: #4267B2; }
        .share-option.linkedin { border-color: #0077B5; color: #0077B5; }
        .share-option.whatsapp { border-color: #25D366; color: #25D366; }
        .share-option.copy-link { border-color: #FF9800; color: #FF9800; }
        
        .share-option.twitter:hover { background: #1DA1F2; color: white; }
        .share-option.facebook:hover { background: #4267B2; color: white; }
        .share-option.linkedin:hover { background: #0077B5; color: white; }
        .share-option.whatsapp:hover { background: #25D366; color: white; }
        .share-option.copy-link:hover { background: #FF9800; color: white; }
        </style>
        <?php
    }
}

new FootballLeaguesProfitGrid();


//////////////////////////////////////////

.profit-grid-section {
    margin: 5px 0;
    padding: 0 15px;
}

.grid-header-section {
    text-align: center;
    margin-bottom: 40px;
    max-width: 950px;
    margin-left: auto;
    margin-right: auto;
}

.grid-main-title {
    font-size: 28px;
    font-family: Arial, sans-serif;
    font-weight: 800;
    color: #FF9800;
    margin-bottom: 15px;
    line-height: 1.2;
}

.grid-description {
    font-size: 1.1rem;
    font-family: Arial, sans-serif;
    margin-bottom: 15px;
    line-height: 1.7;
    color: #fff;
}

.grid-description strong {
    color: #fff;
    font-weight: 700;
}

.last-updated {
    max-width: 100%; 
    margin-top: 15px;
    padding: 10px;
    background: rgba(255, 152, 0, 0.1);
    border-radius: 6px;
    display: none;
}

.last-updated small {
    color: #ccc;
    font-size: 14px;
}

.profit-grid-wrapper {
    margin: 20px 0;
}

.profit-grid-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 25px;
    max-width: 1400px;
    margin: 0 auto;
}

.grid-item-card {
    background-color: #fff;
    border: 2px solid #4267B2;
    border-radius: 10px;
    padding: 25px 20px;
    text-align: center;
    position: relative;
    overflow: hidden; /* Προσθέσαμε αυτό */
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Top Blue Border for Grid Cards */
.grid-item-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 6px;
    background: #4267B2;
    border-radius: 10px 10px 0 0;
    z-index: 1;
}

.grid-item-card:hover {
    border-color: #FF9800;
}

.grid-item-link {
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
}

.logo-wrapper {
    width: 160px;
    height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 15px auto;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    flex-shrink: 0;
}

.league-logo-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 4px;
	border: 6px solid #C7C8C6;
}


.market-buttons-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 0 auto 20px auto;
    width: 100%;
    flex-shrink: 0;
    align-items: center; 
}

.market-button-row {
    display: flex;
    justify-content: space-between;
    width: 100%;
    gap: 0;
}

.market-button-row:first-child {
    margin-bottom: 4px;
}

.market-button-row:last-child {
    margin-top: 4px;
}

.market-button-single {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 6px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border: 1px solid #C7C8C6;
    border-radius: 6px;
    text-decoration: none;
    transition: all 0.3s ease;
    font-size: 11px;
    font-weight: 700;
    color: #475569;
    text-align: center;
    line-height: 1.2;
    min-height: 36px;
    max-width: 100%;
    margin-right: 8px;
}

.market-button-single:last-child {
    margin-right: 0;
}

.market-button-single:hover {
    background: linear-gradient(135deg, #FF9800 0%, #e68900 100%);
    border-color: #FF9800;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 152, 0, 0.4);
}

.market-button-text {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

/* Share Button Specific Styling */
.market-button-single.share-button {
    background: linear-gradient(135deg, #4267B2 0%, #365899 100%) !important;
    border-color: #4267B2 !important;
    color: white !important;
    padding: 10px 10px !important;
}

.market-button-single.share-button:hover {
    background: linear-gradient(135deg, #365899 0%, #4267B2 100%) !important;
    border-color: #4267B2 !important;
    color: white !important;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(66, 103, 178, 0.4);
}

/* Share button text alignment */
.market-button-single.share-button .market-button-text {
    color: white !important;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    font-size: 11px;
}


/* Profit Section */
.profit-section {
    margin-bottom: 15px; 
    padding: 20px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 5px;
    border: 1px solid #C7C8C6;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    z-index: 2;
}

.profit-section .item-title {
    font-size: 16px;
    font-weight: 800;
    color: #475569;
    line-height: 1.3;
    display: block;
    margin-bottom: 10px;
    text-align: center;
}

.profit-amount {
    font-size: 22px;
    font-weight: 800;
    margin-bottom: 8px;
    line-height: 1.2;
    letter-spacing: -0.5px;
}

.profit-positive {
    color: #28a745;
    text-shadow: 0 2px 4px rgba(40, 167, 69, 0.2);
}

.profit-negative {
    color: #dc3545;
    text-shadow: 0 2px 4px rgba(220, 53, 69, 0.2);
}

.profit-neutral {
    color: #6c757d;
}

.profit-text {
    font-size: 11px;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 700;
    margin-bottom: 15px;
}

.details-grid {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    margin-top: 15px;
    margin-bottom: 15px;
}

.detail-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 12px;
    background: white;
    border-radius: 5px;
    border: 1px solid #C7C8C6;
    flex: 1;
    min-width: 0;
}

.detail-number {
    font-size: 13px;
    font-weight: 800;
    color: #2c3e50;
    line-height: 1.2;
    margin-bottom: 3px;
}

.detail-text {
    font-size: 10px;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    line-height: 1.2;
}

/* Country info ΜΕΣΑ στο profit-section */
.country-info-inside {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 1px;
    padding: 8px 0;
    border-top: 1px solid #e9ecef;
}

.country-flag-inside {
    font-size: 24px;
    flex-shrink: 0;
}

.country-name-inside {
    font-size: 16px;
    font-weight: 800;
    color: #FF9800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    position: relative;
    top: -2px; 
}

/* Full Analytics Button */
.analytics-button-container {
    margin-top: 10px;
    flex-shrink: 0;
}

.full-analytics-button {
    display: block;
    width: 100%;
    padding: 12px 20px;
    background: linear-gradient(135deg, #FF9800 0%, #e68900 100%);
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
    transition: all 0.3s ease;
    border: 2px solid transparent;
    line-height: 1.2;
}

.full-analytics-button:hover {
    background: linear-gradient(135deg, #e68900 0%, #FF9800 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 152, 0, 0.4);
    border-color: #FF9800;
    color: white;
}

.ranking-badge {
    position: absolute;
    top: 15px;
    right: 15px;
    font-size: 32px;
    z-index: 15;
}

.rank-1 { color: #FFD700; } 
.rank-2 { color: #C0C0C0; } 
.rank-3 { color: #CD7F32; } 

.content-section {
    max-width: 1200px;
    margin: 30px auto 0;
    padding: 40px;
    background-color: #fff;
    border-radius: 10px;
    border: 2px solid #C7C8C6;
}

.rich-content h2 {
    display: inline-block; 
    font-size: 24px;
    font-family: Arial, sans-serif;
    font-weight: 800;
    color: #475569;
    margin-bottom: 30px;
    line-height: 1.3;
    position: relative;
}

.rich-content h2::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0; 
    bottom: -5px;
    height: 3px;
    background-color: #FF9800;
    border-radius: 2px;
}

.rich-content h3 {
    display: inline-block; 
    font-size: 24px;
    font-family: Arial, sans-serif;
    font-weight: 800;
    color: #475569;
    margin-bottom: 30px;
    line-height: 1.3;
    position: relative;
}

.rich-content h3::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0; 
    bottom: -5px;
    height: 3px;
    background-color: #FF9800;
    border-radius: 2px;
}

.rich-content p {
    font-size: 1.1rem;
    font-family: Arial, sans-serif;
    line-height: 1.7;
    color: #475569;
    margin-bottom: 20px;
}

.rich-content ul {
    list-style: none;
    padding-left: 0;
}

.rich-content li {
    position: relative;
    padding-left: 22px;
    margin-bottom: 15px;
    font-size: 1.1rem;
    font-family: Arial, sans-serif;
    color: #475569;
    line-height: 1.7;
}

.rich-content li::before {
    content: "✓";
    color: #28a745; 
    font-weight: bold;
    font-size: 1.3rem;
    position: absolute;
    left: 0;
    top: -4px;
}

.rich-content strong {
    font-weight: 600;
    font-size: 1.1rem;
    font-family: Arial, sans-serif;
    color: #475569;
    line-height: 1.7;
}

.keywords-section {
    margin-top: 30px;
    padding: 15px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 6px;
    border: 1px solid #B8B8B8;
    font-size: 1.1rem;
    font-weight: 600;
    font-family: Arial, sans-serif;
    color: #9E9FA0;
}

.keywords-section strong {
    font-size: 1.1rem;
    font-weight: 600;
    font-family: Arial, sans-serif;
    color: #9E9FA0;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .profit-grid-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }
}

@media (max-width: 768px) {
    .profit-grid-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }
    
    .grid-item-card {
        padding: 20px 15px;
    }
    
    .logo-wrapper {
        width: 140px;
        height: 140px;
        margin-bottom: 12px;
    }
    
    .market-buttons-container {
        margin-bottom: 15px;
    }
    
    .market-button-row {
        gap: 6px;
    }
    
    .market-button-single {
        padding: 8px 4px;
        font-size: 10px;
        min-height: 32px;
    }
    
    .market-button-text {
        font-size: 10px;
    }
    
    .profit-section {
        padding: 15px;
    }
    
    .profit-section .item-title {
        font-size: 14px;
    }
    
    .profit-amount {
        font-size: 20px;
    }
    
    .country-info-inside {
        margin-top: 8px;
        padding: 6px 0;
    }
    
    .country-flag-inside {
        font-size: 20px;
    }
    
    .country-name-inside {
        font-size: 12px;
    }
    
    .full-analytics-button {
        padding: 10px 15px;
        font-size: 12px;
    }
    
    .ranking-badge {
        font-size: 28px;
        top: 12px;
        right: 12px;
    }
    
    .details-grid {
        gap: 10px;
        margin-bottom: 12px;
    }
    
    .detail-box {
        padding: 6px 8px;
    }
    
    .detail-number {
        font-size: 12px;
    }
    
    .detail-text {
        font-size: 9px;
    }
    
    .grid-main-title {
        font-size: 26px;
    }
    
    .grid-description {
        font-size: 16px;
    }
    
    .content-section {
        padding: 30px 20px;
        margin-top: 40px;
    }
    
    .rich-content h2 {
        font-size: 22px;
    }
    
    .rich-content h3 {
        font-size: 18px;
    }
}

@media (max-width: 480px) {
    .profit-grid-container {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .profit-grid-section {
        padding: 0 10px;
    }
    
    .grid-item-card {
        padding: 18px 12px;
    }
    
    .logo-wrapper {
        width: 160px;
        height: 160px;
        margin-bottom: 12px;
    }
    
    .market-button-single {
        padding: 10px 6px;
        font-size: 11px;
        min-height: 36px;
    }
    
    .market-button-text {
        font-size: 11px;
    }
    
    .profit-section .item-title {
        font-size: 15px;
    }
    
    .country-info-inside {
        flex-wrap: wrap;
        justify-content: center;
        gap: 6px;
    }
    
    .details-grid {
        gap: 10px;
        margin-bottom: 10px;
    }
    
    .detail-box {
        padding: 6px 8px;
    }
    
    .detail-number {
        font-size: 11px;
    }
    
    .detail-text {
        font-size: 8px;
    }
    
    .grid-main-title {
        font-size: 24px;
    }
    
    .content-section {
        padding: 25px 15px;
    }
    
    .rich-content h2 {
        font-size: 20px;
    }
    
    .rich-content h3 {
        font-size: 17px;
    }
    
    .ranking-badge {
        font-size: 24px;
        top: 10px;
        right: 10px;
    }
}

.league-logo-image {
    content-visibility: auto;
    contain-intrinsic-size: 160px;
}