<?php
// 功能：网站统计分析文件
// 作者：启肯科技
// Q Q：328493711
// 微信：13738373177（同手机）
// 官网：http://www.qiken.com
// 说明：QKCMS-轻量级AI智能内容管理建站系统
// 版权：© 2025 温州启肯网络有限公司 保留所有权利，盗版必究。

if (!defined('ADMIN_LOADED')) {
  header('HTTP/1.1 403 Forbidden');
  exit('Access Denied');
}


global $conn;
$php_version = phpversion();

$keyword_count = getKeywordCount($conn);
$mysql_version = getMySQLVersion();

$db_size_text = '0 MB';
$db_charset_text = 'utf8';
$db_max_connections_text = 'N/A';
try {
  if (isset($conn) && ($conn instanceof mysqli) && empty($conn->connect_error)) {
    /*
    $res = $conn->query("SELECT ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS size_mb FROM information_schema.tables WHERE table_schema = DATABASE()");
    if ($res && ($row = $res->fetch_assoc())) {
      $size = (float)($row['size_mb'] ?? 0);
      $db_size_text = $size >= 1024 ? (round($size / 1024, 2) . ' GB') : (number_format($size, 2) . ' MB');
    }
    if ($res) $res->close();
    */
    $res = $conn->query("SHOW VARIABLES LIKE 'character_set_connection'");
    if ($res && ($row = $res->fetch_assoc())) {
      $db_charset_text = (string)($row['Value'] ?? $db_charset_text);
    }
    if ($res) $res->close();

    $res = $conn->query("SHOW VARIABLES LIKE 'max_connections'");
    if ($res && ($row = $res->fetch_assoc())) {
      $db_max_connections_text = (string)($row['Value'] ?? $db_max_connections_text);
    }
    if ($res) $res->close();
  }
} catch (Exception $e) {
}
$article_count = getArticleCount();
$user_count = getUserCount();
$comment_count = getCommentCount();
$category_count = getCategoryCount();
$navigation_count = get_table_count('navigation', 'navigation_count', 0);
$catgroup_count = get_table_count('catgroup', 'catgroup_count', 0);
$report_count = getReportCount();
$search_count = getSearchCount();
$order_count = getOrderCount();

/*
$file_info = countFilesAndSize(dirname(__DIR__));
$file_count = $file_info['count'];
$formatted_size = formatBytes($file_info['size']);

$installed_plugins = get_installed_plugins();
$plugin_count = count($installed_plugins);
*/

$template_tag_count = 0;
try {
  $categories = ['site' => '网站全局标签', 'article' => '文章页标签', 'category' => '列表页标签', 'goods' => '商品页标签', 'loop' => '常用循环标签'];
  $category_counts = [];

  foreach ($categories as $key => $name) {
    $sql = "SELECT COUNT(DISTINCT code) as count FROM tplmark WHERE category = '$key'";
    $result = $conn->query($sql);
    if ($result) {
      $row = $result->fetch_assoc();
      $category_counts[$key] = $row['count'];
    } else {
      $category_counts[$key] = 0;
    }
  }

  $template_tag_count = array_sum($category_counts);
} catch (Exception $e) {
  $template_tag_count = 0;
}
$trend_days = 7;
$trend_dates = [];
$trend_date_map = [];
for ($i = $trend_days - 1; $i >= 0; $i--) {
  $day = date('Y-m-d', strtotime("-{$i} day"));
  $trend_dates[] = $day;
  $trend_date_map[$day] = true;
}
$traffic_pv = array_fill_keys($trend_dates, 0);
$traffic_uv = array_fill_keys($trend_dates, 0);
$traffic_ip = array_fill_keys($trend_dates, 0);
$traffic_spider = array_fill_keys($trend_dates, 0);
$traffic_session = array_fill_keys($trend_dates, 0);
$content_posts = array_fill_keys($trend_dates, 0);
$content_comments = array_fill_keys($trend_dates, 0);
$content_users = array_fill_keys($trend_dates, 0);
$content_search_terms = array_fill_keys($trend_dates, 0);
$content_shares = array_fill_keys($trend_dates, 0);
try {
  $days_window = $trend_days - 1;
  $sql_counter = "SELECT stat_date, SUM(pv) AS pv_total, SUM(uv) AS uv_total, SUM(ip_count) AS ip_total, SUM(spider_count) AS spider_total, SUM(session_count) AS session_total FROM counter WHERE stat_date >= DATE_SUB(CURDATE(), INTERVAL {$days_window} DAY) GROUP BY stat_date";
  $res_counter = $conn->query($sql_counter);
  if ($res_counter) {
    while ($row = $res_counter->fetch_assoc()) {
      $d = (string)$row['stat_date'];
      if (isset($trend_date_map[$d])) {
        $traffic_pv[$d] = (int)$row['pv_total'];
        $traffic_uv[$d] = (int)$row['uv_total'];
        $traffic_ip[$d] = (int)$row['ip_total'];
        $traffic_spider[$d] = (int)$row['spider_total'];
        $traffic_session[$d] = (int)$row['session_total'];
      }
    }
    $res_counter->close();
  }
} catch (Exception $e) {
}
try {
  $days_window = $trend_days - 1;
  $sql_posts = "SELECT DATE(created_at) AS d, COUNT(*) AS c FROM posts WHERE created_at >= DATE_SUB(CURDATE(), INTERVAL {$days_window} DAY) GROUP BY DATE(created_at)";
  $res_posts = $conn->query($sql_posts);
  if ($res_posts) {
    while ($row = $res_posts->fetch_assoc()) {
      $d = (string)$row['d'];
      if (isset($trend_date_map[$d])) $content_posts[$d] = (int)$row['c'];
    }
    $res_posts->close();
  }
  $sql_comments = "SELECT DATE(created_at) AS d, COUNT(*) AS c FROM comments WHERE created_at >= DATE_SUB(CURDATE(), INTERVAL {$days_window} DAY) GROUP BY DATE(created_at)";
  $res_comments = $conn->query($sql_comments);
  if ($res_comments) {
    while ($row = $res_comments->fetch_assoc()) {
      $d = (string)$row['d'];
      if (isset($trend_date_map[$d])) $content_comments[$d] = (int)$row['c'];
    }
    $res_comments->close();
  }
  $sql_users = "SELECT DATE(created_at) AS d, COUNT(*) AS c FROM users WHERE created_at >= DATE_SUB(CURDATE(), INTERVAL {$days_window} DAY) GROUP BY DATE(created_at)";
  $res_users = $conn->query($sql_users);
  if ($res_users) {
    while ($row = $res_users->fetch_assoc()) {
      $d = (string)$row['d'];
      if (isset($trend_date_map[$d])) $content_users[$d] = (int)$row['c'];
    }
    $res_users->close();
  }
  $sql_search = "SELECT DATE(search_time) AS d, COUNT(DISTINCT search_term) AS c FROM search WHERE search_time >= DATE_SUB(CURDATE(), INTERVAL {$days_window} DAY) GROUP BY DATE(search_time)";
  $res_search = $conn->query($sql_search);
  if ($res_search) {
    while ($row = $res_search->fetch_assoc()) {
      $d = (string)$row['d'];
      if (isset($trend_date_map[$d])) $content_search_terms[$d] = (int)$row['c'];
    }
    $res_search->close();
  }
  $sql_shares = "SELECT DATE(created_at) AS d, COUNT(*) AS c FROM shares WHERE created_at >= DATE_SUB(CURDATE(), INTERVAL {$days_window} DAY) GROUP BY DATE(created_at)";
  $res_shares = $conn->query($sql_shares);
  if ($res_shares) {
    while ($row = $res_shares->fetch_assoc()) {
      $d = (string)$row['d'];
      if (isset($trend_date_map[$d])) $content_shares[$d] = (int)$row['c'];
    }
    $res_shares->close();
  }
} catch (Exception $e) {
}
$trend_labels = [];
foreach ($trend_dates as $d) {
  $trend_labels[] = date('m-d', strtotime($d));
}
$trend_payload = [
  'labels' => $trend_labels,
  'traffic' => [
    'pv' => array_values($traffic_pv),
    'uv' => array_values($traffic_uv),
    'ip' => array_values($traffic_ip),
    'spider' => array_values($traffic_spider),
    'session' => array_values($traffic_session),
  ],
  'content' => [
    'posts' => array_values($content_posts),
    'comments' => array_values($content_comments),
    'users' => array_values($content_users),
    'search_terms' => array_values($content_search_terms),
    'shares' => array_values($content_shares),
  ],
];

$license_data = null;
global $qkcms_license_info;

// 获取代理ID
$agent_id = 0;
if (file_exists(dirname(__DIR__) . '/license.php')) {
  require_once dirname(__DIR__) . '/license.php';
  if (defined('QKCMS_AGENT_ID')) {
    $agent_id = (int)QKCMS_AGENT_ID;
  }
}

// 获取程序版本号（从云端授权API返回的system_info.version获取）
$version = '1.0.0';
if (isset($qkcms_license_info['version'])) {
  $version = $qkcms_license_info['version'];
}

// 获取系统缓存时间（从云端授权API返回的system_info.cache_time获取）
$cache_time_text = '3600秒';
if (isset($qkcms_license_info['cache_time'])) {
  $cache_time = (int)$qkcms_license_info['cache_time'];
  if ($cache_time <= 0) {
    $cache_time_text = '不缓存';
  } elseif ($cache_time < 60) {
    $cache_time_text = $cache_time . '秒';
  } elseif ($cache_time < 3600) {
    $cache_time_text = ($cache_time / 60) . '分钟';
  } else {
    $cache_time_text = ($cache_time / 3600) . '小时';
  }
}

$project_identifier = '';
if (isset($qkcms_license_info['app_identifier'])) {
  $project_identifier = trim((string)$qkcms_license_info['app_identifier']);
}
if ($project_identifier === '' && isset($_SESSION['qkcms_license_cache']['data']['app_identifier'])) {
  $project_identifier = trim((string)$_SESSION['qkcms_license_cache']['data']['app_identifier']);
}
if ($project_identifier === '' && function_exists('payapi_settings_get')) {
  $project_identifier = trim((string)payapi_settings_get('app_identifier', ''));
}
if ($project_identifier === '') $project_identifier = 'QKCMS';

if (isset($qkcms_license_info) && !empty($qkcms_license_info)) {
  $license_data = $qkcms_license_info;
} elseif (isset($_SESSION['qkcms_license_cache']['data'])) {
  $license_data = $_SESSION['qkcms_license_cache']['data'];
} elseif (function_exists('qk_license_cached_data')) {
  $license_data = qk_license_cached_data();
}

if ($license_data) {
  if ($version === '1.0.0' && isset($license_data['version']) && trim((string)$license_data['version']) !== '') {
    $version = trim((string)$license_data['version']);
  }
  if ($cache_time_text === '3600秒' && isset($license_data['cache_time'])) {
    $cache_time = (int)$license_data['cache_time'];
    if ($cache_time <= 0) {
      $cache_time_text = '不缓存';
    } elseif ($cache_time < 60) {
      $cache_time_text = $cache_time . '秒';
    } elseif ($cache_time < 3600) {
      $cache_time_text = ($cache_time / 60) . '分钟';
    } else {
      $cache_time_text = ($cache_time / 3600) . '小时';
    }
  }
  if ($project_identifier === '' && isset($license_data['app_identifier'])) {
    $project_identifier = trim((string)$license_data['app_identifier']);
  }
}

if (!function_exists('format_license_duration')) {
  function format_license_duration($seconds)
  {
    if ($seconds <= 0) return '已到期';
    if ($seconds < 60) return $seconds . ' 秒';
    if ($seconds < 3600) return ceil($seconds / 60) . ' 分钟';
    if ($seconds < 86400) return ceil($seconds / 3600) . ' 小时';
    return ceil($seconds / 86400) . ' 天';
  }
}
?>
<style>
  .admin-stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 22px;
  }

  .admin-stat-card {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    background: linear-gradient(180deg, var(--card-soft, #f8fafc) 0%, #ffffff 100%);
    border-radius: 10px;
    border: 1px solid color-mix(in srgb, var(--card-color, #94a3b8) 22%, #ffffff);
    box-shadow: 0 8px 12px -12px rgba(15, 23, 42, 0.24);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    position: relative;
    overflow: hidden;
    will-change: transform;
    min-height: 94px;
  }

  .admin-stat-card::before {
    content: '';
    position: absolute;
    right: -12px;
    bottom: -14px;
    width: 84px;
    height: 84px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--card-color, #94a3b8) 14%, #ffffff);
    opacity: 0.42;
    pointer-events: none;
    z-index: 0;
  }

  .admin-stat-card .bg-icon {
    position: absolute;
    right: 16px;
    bottom: 14px;
    width: 34px;
    height: 34px;
    opacity: 0.42;
    color: var(--card-color, #3b82f6);
    pointer-events: none;
    transform: none;
    z-index: 1;
  }

  .admin-stat-card .bg-icon svg {
    width: 100%;
    height: 100%;
    stroke-width: 1.8;
  }

  .admin-stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 14px -12px rgba(15, 23, 42, 0.28);
    border-color: color-mix(in srgb, var(--card-color, #94a3b8) 22%, #ffffff);
  }

  .stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    flex-shrink: 0;
  }

  .stat-icon svg {
    width: 20px;
    height: 20px;
  }

  .stat-content {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
    padding-left: 0;
    padding-right: 0px;
    position: relative;
    z-index: 2;
  }

  .stat-label {
    font-size: 14px;
    color: #475467;
    font-weight: 600;
    letter-spacing: 0.2px;
    max-width: 100%;
    line-height: 1.35;
  }

  .stat-number {
    font-size: 28px;

    line-height: 1.1;
    flex-shrink: 0;
  }

  .admin-stat-card:nth-child(1) .stat-number {
    color: #2563eb;
  }

  .admin-stat-card:nth-child(2) .stat-number {
    color: #16a34a;
  }

  .admin-stat-card:nth-child(3) .stat-number {
    color: #f59e0b;
  }

  .admin-stat-card:nth-child(4) .stat-number {
    color: #0891b2;
  }

  .admin-stat-card:nth-child(5) .stat-number {
    color: #ec4899;
  }

  .admin-stat-card:nth-child(6) .stat-number {
    color: #0d9488;
  }

  .admin-stat-card:nth-child(7) .stat-number {
    color: #dc2626;
  }

  .admin-stat-card:nth-child(8) .stat-number {
    color: #d946ef;
  }

  .admin-stat-card:nth-child(9) .stat-number {
    color: #4f46e5;
  }

  .admin-stat-card:nth-child(10) .stat-number {
    color: #65a30d;
  }

  .admin-stat-card:nth-child(1) {
    --card-color: #2563eb;
    --card-soft: #f3f7ff;
    --chip-bg: #f4f8ff;
    --chip-border: #bfd3ff;
  }

  .admin-stat-card:nth-child(2) {
    --card-color: #16a34a;
    --card-soft: #f2fcf6;
    --chip-bg: #f2fdf7;
    --chip-border: #bdebd1;
  }

  .admin-stat-card:nth-child(3) {
    --card-color: #f59e0b;
    --card-soft: #fff9ef;
    --chip-bg: #fffaf2;
    --chip-border: #ffe2b8;
  }

  .admin-stat-card:nth-child(4) {
    --card-color: #0891b2;
    --card-soft: #eefbff;
    --chip-bg: #f3fcff;
    --chip-border: #b9e7f5;
  }

  .admin-stat-card:nth-child(5) {
    --card-color: #ec4899;
    --card-soft: #fff4fa;
    --chip-bg: #fff5fa;
    --chip-border: #ffc5e2;
  }

  .admin-stat-card:nth-child(6) {
    --card-color: #0d9488;
    --card-soft: #eefbf8;
    --chip-bg: #f3fcfa;
    --chip-border: #bcebe3;
  }

  .admin-stat-card:nth-child(7) {
    --card-color: #dc2626;
    --card-soft: #fff3f4;
    --chip-bg: #fff4f5;
    --chip-border: #ffc5ca;
  }

  .admin-stat-card:nth-child(8) {
    --card-color: #d946ef;
    --card-soft: #fcf1ff;
    --chip-bg: #fdf4ff;
    --chip-border: #f3c3fd;
  }

  .admin-stat-card:nth-child(9) {
    --card-color: #4f46e5;
    --card-soft: #f2f2ff;
    --chip-bg: #f5f4ff;
    --chip-border: #cecaff;
  }

  .admin-stat-card:nth-child(10) {
    --card-color: #65a30d;
    --card-soft: #f7fde9;
    --chip-bg: #f9ffef;
    --chip-border: #d9f2a8;
  }

  .admin-stat-card:nth-child(1) .stat-icon {
    background: #edf4ff;
    color: #2563eb;
  }

  .admin-stat-card:nth-child(2) .stat-icon {
    background: #ecfbf2;
    color: #16a34a;
  }

  .admin-stat-card:nth-child(3) .stat-icon {
    background: #fff7ea;
    color: #f59e0b;
  }

  .admin-stat-card:nth-child(4) .stat-icon {
    background: #e9f8fd;
    color: #0891b2;
  }

  .admin-stat-card:nth-child(5) .stat-icon {
    background: #fdf2f8;
    color: #ec4899;
  }

  .admin-stat-card:nth-child(6) .stat-icon {
    background: #edf9f6;
    color: #0d9488;
  }

  .admin-stat-card:nth-child(7) .stat-icon {
    background: #fef2f2;
    color: #dc2626;
  }

  .admin-stat-card:nth-child(8) .stat-icon {
    background: #fdeeff;
    color: #d946ef;
  }

  .admin-stat-card:nth-child(9) .stat-icon {
    background: #eeedff;
    color: #4f46e5;
  }

  .admin-stat-card:nth-child(10) .stat-icon {
    background: #f3fbe6;
    color: #65a30d;
  }

  .license-hero-panel {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    border-radius: 16px;
    padding: 32px 40px;
    margin-bottom: 32px;
    color: #1e293b;
    position: relative;
    overflow: hidden;
    border: 1px solid #e2e8f0;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 40px;
    transition: all 0.3s ease;
  }

  .license-hero-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #3b82f6, #10b981, #8b5cf6);
  }

  @keyframes pulse-ring {
    0% {
      transform: scale(1);
      opacity: 0.8;
    }

    50% {
      transform: scale(1.2);
      opacity: 0.4;
    }

    100% {
      transform: scale(1.4);
      opacity: 0;
    }
  }

  @keyframes pulse-glow {
    0% {
      box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4);
    }

    70% {
      box-shadow: 0 0 0 15px rgba(59, 130, 246, 0);
    }

    100% {
      box-shadow: 0 0 0 0 rgba(59, 130, 246, 0);
    }
  }

  .license-badge-container {
    position: relative;
    flex-shrink: 0;
    width: 80px;
    height: 80px;
  }

  .license-badge-icon {
    width: 100%;
    height: 100%;
    background: #ffffff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid #e2e8f0;
    position: relative;
    z-index: 2;
    box-shadow:
      0 4px 12px rgba(0, 0, 0, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.8);
    transition: all 0.3s ease;
  }

  .license-badge-icon:hover {
    transform: scale(1.05);
    box-shadow:
      0 6px 16px rgba(0, 0, 0, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.8);
  }

  .license-badge-icon svg {
    width: 40px;
    height: 40px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
    stroke-width: 1.5;
  }

  .status-container-active .license-badge-icon {
    background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
    border-color: #86efac;
    animation: pulse-glow 2s ease-in-out infinite;
  }

  .status-container-active .license-badge-icon svg {
    color: #059669;
  }

  .status-container-trial .license-badge-icon {
    background: linear-gradient(135deg, #ffedd5 0%, #fed7aa 100%);
    border-color: #fdba74;
    animation: pulse-glow 2s ease-in-out infinite;
  }

  .status-container-trial .license-badge-icon svg {
    color: #c2410c;
  }

  .status-container-none .license-badge-icon {
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    border-color: #fca5a5;
  }

  .status-container-none .license-badge-icon svg {
    color: #991b1b;
  }

  .license-badge-container::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    border-radius: 50%;
    animation: pulse-ring 2s ease-out infinite;
    z-index: 1;
  }

  .status-container-active::after {
    background: rgba(16, 185, 129, 0.3);
  }

  .status-container-trial::after {
    background: rgba(249, 115, 22, 0.3);
  }

  .status-container-none::after {
    background: rgba(239, 68, 68, 0.3);
  }

  .license-status-tag {
    position: absolute;
    bottom: -4px;
    right: -16px;
    padding: 4px 12px;
    border-radius: 16px;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    display: inline-block;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    border: 2px solid white;
    z-index: 3;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }

  .status-trial {
    background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
  }

  .status-active {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  }

  .status-none {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  }

  .license-main-info {
    display: flex;
    align-items: center;
    gap: 24px;
    flex: 1;
  }

  .license-text1 h2 {
    font-size: 20px;
    font-weight: 800;
    color: #1e293b;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-left: none !important;
    padding-left: 0 !important;
  }

  .verified-badge-simple {
    font-size: 11px;
    color: #10b981;
    background: #f0fdf4;
    padding: 2px 10px;
    border-radius: 4px;
    border: 1px solid #dcfce7;
    font-weight: 600;
  }

  .license-text1 p {
    color: #64748b;
    font-size: 14px;
    line-height: 1.6;
    max-width: 400px;
  }

  .license-details-grid {
    display: flex;
    gap: 45px;
    background: #f8fafc;
    padding: 18px 35px;
    border-radius: 12px;
    border: 1px solid #f1f5f9;
    flex-shrink: 0;
  }

  .detail-item {
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .detail-label {
    font-size: 12px;
    color: #94a3b8;
    font-weight: 700;
    text-transform: uppercase;
    margin-bottom: 4px;
    letter-spacing: 0.5px;
  }

  .detail-value {
    font-size: 16px;
    font-weight: 700;
    color: #334155;
    white-space: nowrap;
  }

  .detail-value.highlight {
    color: #f97316;
  }

  @media (max-width: 1200px) {
    .license-hero-panel {
      flex-direction: column;
      align-items: flex-start;
      gap: 24px;
    }

    .license-details-grid {
      width: 100%;
      justify-content: space-between;
    }
  }

  .environment-info {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-top: 0px;
  }

  .environment-item {
    --env-color: var(--primary-color, #2563eb);
    --env-soft: var(--primary-opacity-10, #eef2ff);
    display: flex;
    flex-direction: column;
    padding: 14px 16px;
    background: linear-gradient(180deg, var(--env-soft, #f8fafc) 0%, #ffffff 100%);
    border-radius: 10px;
    border: 1px solid color-mix(in srgb, var(--env-color, #94a3b8) 22%, #ffffff);
    box-shadow: 0 8px 12px -12px rgba(15, 23, 42, 0.24);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    position: relative;
    overflow: hidden;
    will-change: transform;
    min-height: 94px;
  }

  .environment-item::before {
    content: '';
    position: absolute;
    right: -20px;
    bottom: -24px;
    width: 92px;
    height: 92px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--env-color, #94a3b8) 14%, #ffffff);
    opacity: 0.55;
    pointer-events: none;
  }

  .environment-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 14px -12px rgba(15, 23, 42, 0.28);
    border-color: color-mix(in srgb, var(--env-color, #94a3b8) 22%, #ffffff);
  }

  .environment-label {
    font-size: 13px;
    color: #475467;
    margin-bottom: 8px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
  }

  .environment-value {
    font-size: 22px;
    font-weight: 500;

  }

  .metrics-trend-card {
    padding-bottom: 18px;
  }

  .metrics-trend-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
  }

  .metrics-trend-subtitle {
    font-size: 13px;
    color: #64748b;
  }

  .metrics-trend-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
  }

  .metrics-trend-panel {
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 14px 14px 8px;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  }

  .metrics-trend-canvas-wrap {
    height: 330px;
    position: relative;
  }

  .metrics-trend-canvas-wrap canvas {
    width: 100% !important;
    height: 100% !important;
    opacity: 1;
    transition: opacity 0.18s ease;
  }

  .metrics-trend-panel.loading .metrics-trend-canvas-wrap canvas {
    opacity: 0;
  }

  .metrics-trend-loader {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    display: none;
    align-items: center;
    gap: 10px;
    color: #64748b;
    font-size: 14px;
    font-weight: 600;
  }

  .metrics-trend-panel.loading .metrics-trend-loader {
    display: inline-flex;
  }

  .metrics-trend-loader-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: #3b82f6;
    animation: metricsTrendPulse 1s ease-in-out infinite;
  }

  .metrics-trend-loader-dot:nth-child(2) {
    animation-delay: 0.18s;
  }

  .metrics-trend-loader-dot:nth-child(3) {
    animation-delay: 0.36s;
  }

  @keyframes metricsTrendPulse {

    0%,
    80%,
    100% {
      opacity: 0.3;
      transform: scale(0.7);
    }

    40% {
      opacity: 1;
      transform: scale(1);
    }
  }

  .admin-table.activities-manage td:nth-child(5) {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    max-width: 400px;
    display: table-cell !important;
    height: 30px;
  }

  .admin-table.activities-manage {
    table-layout: fixed !important;
    width: 100% !important;
    border-collapse: collapse !important;
    border-spacing: 0 !important;
  }

  .admin-table.activities-manage th:first-child,
  .admin-table.activities-manage td:first-child {
    width: 80px !important;
    min-width: 80px !important;
    max-width: 80px !important;
  }

  .admin-table.activities-manage th:nth-child(2),
  .admin-table.activities-manage td:nth-child(2) {
    width: 200px !important;
    min-width: 200px !important;
  }

  .admin-table.activities-manage th:nth-child(3),
  .admin-table.activities-manage td:nth-child(3) {
    width: 100px !important;
    min-width: 100px !important;
  }

  .admin-table.activities-manage th:nth-child(4),
  .admin-table.activities-manage td:nth-child(4) {
    width: 120px !important;
    min-width: 120px !important;
  }

  .admin-table.activities-manage th:nth-child(5),
  .admin-table.activities-manage td:nth-child(5) {
    width: calc(100% - 420px) !important;
    min-width: 300px !important;
    text-align: right !important;
  }

  .admin-table.activities-manage th,
  .admin-table.activities-manage td {
    padding: 0 20px !important;
    text-align: left !important;
    vertical-align: middle !important;
    border: none !important;
    border-bottom: 1px solid #e5e7eb !important;
    line-height: 75px !important;
    height: 75px !important;
    box-sizing: border-box !important;
    margin: 0 !important;
    overflow: hidden !important;
  }

  @media (max-width: 1100px) and (min-width: 769px) {
     .admin-stats-grid {
       grid-template-columns: repeat(3, 1fr);
     }

     .environment-info {
       grid-template-columns: repeat(2, 1fr);
       gap: 12px;
     }

     .environment-item {
       flex-direction: row;
       align-items: center;
       justify-content: space-between;
       padding: 12px 16px;
       min-height: auto;
     }

     .environment-label {
       margin-bottom: 0;
       flex: 0 0 auto;
     }

     .environment-value {
       text-align: right;
       flex: 1;
       min-width: 0;
       word-break: break-all;
     }

     .metrics-trend-grid {
       grid-template-columns: 1fr;
     }

    .license-style-2 .left p {
      display: none;
    }

    .license-style-2 .left {
      padding-top: 10px;
    }

    .license-style-2 .icon {
      width: 58px !important;
      height: 58px !important;
      border-radius: 50% !important;
    }
  }

  @media (max-width: 768px) {
    .environment-info {
      grid-template-columns: 1fr;
      gap: 12px;
    }

    .admin-stats-grid {
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: 10px;
    }

    .environment-item {
      --env-color: #2563eb;
      --env-soft: #eef4ff;
      flex-direction: row;
      align-items: center;
      justify-content: space-between;
      gap: 16px;
      padding: 12px 14px;
      min-height: auto;
    }

    .environment-label {
      font-size: 13px;
      margin-bottom: 0;
      text-transform: none;
      letter-spacing: 0;
      flex: 0 0 auto;
    }

    .environment-value {
      font-size: 16px;
      text-align: right;
      line-height: 1.35;
      flex: 1 1 auto;
      min-width: 0;
      word-break: break-word;
    }

    .environment-item::before {
      width: 70px;
      height: 70px;
      right: -18px;
      bottom: -20px;
      opacity: 0.38;
    }

    .metrics-trend-grid {
      grid-template-columns: 1fr;
    }

    .metrics-trend-canvas-wrap {
      height: 280px;
    }

    .admin-table.activities-manage th:nth-child(4),
    .admin-table.activities-manage td:nth-child(4) {
      display: none !important;
    }

    .admin-table.activities-manage {
      width: 100% !important;
      font-size: 14px !important;
      table-layout: auto !important;
      min-width: auto !important;
    }

    .admin-table.activities-manage th,
    .admin-table.activities-manage td {
      padding: 0 6px !important;
      font-size: 14px !important;
    }

    .admin-table.activities-manage td:last-child {
      min-width: 120px !important;
      max-width: 120px !important;
      text-align: right !important;
      white-space: nowrap !important;
    }
  }
</style>
<?php if ($license_data): ?>
  <style>
    .license-style-2 {
      background: #fef9f5;
      border-radius: 15px;
      overflow: hidden;
      box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
      border: 1px solid #f5ebe3;
      font-family: 'Microsoft YaHei', sans-serif;
      margin-bottom: 20px;
    }

    .license-style-2 .inner {
      padding: 26px 30px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      flex-wrap: wrap;
      gap: 24px;
    }

    .license-style-2 .left {
      display: flex;
      align-items: center;
      gap: 20px;
      flex: 1;
    }

    .license-style-2 .icon {
      width: 58px;
      height: 58px;
      background: #fff;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      box-shadow: 0 6px 15px rgba(255, 80, 0, 0.1);
      position: relative;
      z-index: 2;
      flex-shrink: 0;
    }

    .license-style-2 .icon::before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      border-radius: 50%;
      z-index: -1;
      animation: pulse-ring-v22 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
    }

    .license-style-2 .icon.active::before {
      background: rgba(255, 80, 0, 0.5);
    }

    .license-style-2 .icon.warning::before {
      background: rgba(255, 80, 0, 0.5);
    }

    .license-style-2 .icon.danger::before {
      background: rgba(239, 68, 68, 0.5);
    }

    @keyframes pulse-ring-v22 {
      0% {
        transform: scale(1);
        opacity: 0.6;
      }

      100% {
        transform: scale(1.6);
        opacity: 0;
      }
    }

    .license-style-2 .icon svg {
      width: 28px;
      height: 28px;
      color: #ff5000;
      position: relative;
      z-index: 3;
    }

    .license-style-2 h3 {
      font-size: 18px;
      font-weight: 700;
      color: #3d2a1f;
      margin-bottom: 6px;
      display: flex;
      align-items: center;
      gap: 12px;
      flex-wrap: wrap;
    }

    .license-style-2 p {
      font-size: 13px;
      color: #8b735f;
      margin: 0;
      margin-top: 8px;
    }

    .license-style-2 .badge {
      padding: 4px 12px;
      border-radius: 30px;
      font-size: 12px;
      font-weight: 600;
    }

    .license-style-2 .badge.active {
      background: #ff5000;
      color: #fff;
      position: relative;
      overflow: hidden;
    }

    .license-style-2 .badge.active::after {
      content: '';
      position: absolute;
      top: 0;
      left: -100%;
      width: 100%;
      height: 100%;
      background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
      animation: shine 2s infinite;
    }

    @keyframes shine {
      0% {
        left: -100%;
      }

      50%,
      100% {
        left: 100%;
      }
    }

    .license-style-2 .badge.warning {
      background: #fff0e0;
      color: #e65100;
    }

    .license-style-2 .badge.danger {
      background: #fce8e8;
      color: #c62828;
    }

    .license-style-2 .stats {
      display: flex;
      gap: 28px;
      padding: 12px 24px;
      border-radius: 50px;
      box-shadow: 0 2px 8px rgb(241 223 209)
    }

    .license-style-2 .stat {
      text-align: center;
    }

    .license-style-2 .stat-label {
      font-size: 11px;
      color: #a08c7a;
      margin-bottom: 5px;
    }

    .license-style-2 .stat-value {
      font-size: 14px;
      font-weight: 700;
      color: #836b57;
    }

    @media (max-width: 768px) {
      .license-style-2 .inner {
        padding: 20px;
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 20px;
        margin-top: 25px;
      }

      .license-style-2 .left {
        flex-direction: column;
        gap: 30px;
        flex: none;
        width: 100%;
      }

      .license-style-2 h3 {
        justify-content: center;
        font-size: 16px;
      }

      .license-style-2 p {
        font-size: 12px;
        margin-top: 5px;
      }

      .license-style-2 .stats {
        width: 100%;
        grid-template-columns: repeat(2, 1fr);
        display: grid;
        gap: 15px;
        padding: 18px;
        border-radius: 12px;
        box-shadow: none;
        border: 1px solid #f0f0f0;
      }

      .license-style-2 .stat {
        text-align: center;
      }

      .license-style-2 .stat-label {
        font-size: 10px;
        margin-bottom: 3px;
      }

      .license-style-2 .stat-value {
        font-size: 13px;
      }

      .license-style-2 .stats .stat:nth-child(5) {
        display: none;
      }

      .license-style-2 .icon {
        width: 58px !important;
        height: 58px !important;
        border-radius: 50% !important;
      }
    }
  </style>

  <div class="license-card-wrapper">
    <div class="license-current-style license-style-2">
      <div class="inner">
        <div class="left">
          <div class="icon <?php
                            if ($license_data['has_license']) echo 'active';
                            elseif ($license_data['in_trial']) echo 'warning';
                            else echo 'danger';
                            ?>">
            <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" fill="currentColor" style="width: 30px; height: 30px;">
              <path d="M566.446451 30.031087a467.343774 467.343774 0 0 0 234.783037 105.108804 711.977007 711.977007 0 0 0 109.012845 7.928207 31.592703 31.592703 0 0 1 31.472579 29.370403c3.964103 54.055956 1.561617 108.111913 2.522611 162.588304 0.660684 37.178486 0.54056 74.417033-1.861927 111.535457-6.426653 99.282773-22.763564 196.403308-66.909262 286.736817a518.937181 518.937181 0 0 1-184.991495 208.05537A755.462021 755.462021 0 0 1 523.862369 1022.017948a35.436683 35.436683 0 0 1-23.244061 0c-98.742214-34.235439-188.775412-82.8858-261.991202-159.044636C171.477596 792.820693 129.554199 709.334272 106.190013 615.817467A875.165933 875.165933 0 0 1 83.786822 473.59024C76.218989 380.433808 80.783714 287.217315 80.603527 194.000821a183.309754 183.309754 0 0 1 1.38143-18.979647 36.878175 36.878175 0 0 1 37.959294-31.712827A714.739867 714.739867 0 0 0 223.551501 135.260015 469.085577 469.085577 0 0 0 456.052175 31.592703 248.176902 248.176902 0 0 1 490.107428 6.006217a44.506071 44.506071 0 0 1 44.746319 0.54056A243.371928 243.371928 0 0 1 566.446451 30.031087zM155.320871 351.664027a960.274034 960.274034 0 0 0 3.723855 132.136782 687.291454 687.291454 0 0 0 32.793947 162.528243 440.135609 440.135609 0 0 0 136.641445 199.22623 601.642794 601.642794 0 0 0 176.582791 99.162649 20.661388 20.661388 0 0 0 15.496041-0.660684 658.221362 658.221362 0 0 0 127.992492-63.906153 446.742448 446.742448 0 0 0 183.850314-234.602851c28.229222-81.864743 35.37662-166.912781 38.019356-252.261129 1.681741-55.437386-1.861927-110.934835-1.681741-166.432284 0-7.267523-2.282363-9.730072-9.67001-10.150507a719.004282 719.004282 0 0 1-91.414628-10.931316 529.087688 529.087688 0 0 1-248.11684-117.841985 9.489823 9.489823 0 0 0-15.015544 0A527.105637 527.105637 0 0 1 388.662416 162.768491c-70.693178 33.754942-145.951082 48.650361-223.55141 53.455334-7.207461 0.480497-9.970321 2.522611-9.910259 9.970321 0.240249 41.923397 0.120124 83.666608 0.120124 125.469881z" />
              <path d="M362.054873 472.328934A37.839169 37.839169 0 0 1 391.725587 485.302364c21.021761 21.081823 42.043522 42.043522 63.00522 63.245469 6.006217 6.006217 9.489823 5.585782 15.19573 0Q549.749166 467.944396 629.932168 388.001642c15.075606-15.075606 32.073201-24.024869 60.062174-4.14429a29.670714 29.670714 0 0 1 4.804974 43.665201c-15.73629 17.718341-33.034196 33.99519-49.73148 50.752536L493.230661 629.99214c-21.322072 21.26201-41.022465 21.26201-62.404599 0-30.751833-30.691771-61.683852-61.263417-92.135374-92.195436-20.72145-21.021761-15.435979-52.374215 10.030383-62.945158a28.169159 28.169159 0 0 1 13.333802-2.522612z" />
            </svg>
          </div>
          <div>
            <h3><?php echo escape($project_identifier); ?>
              <?php if (!empty($license_data['has_license']) && !empty($license_data['server_error'])): ?>
                <span class="badge warning">云端异常</span>
              <?php elseif ($license_data['has_license']): ?>
                <span class="badge active">✓ 正版授权</span>
              <?php elseif ($license_data['in_trial']): ?>
                <span class="badge warning">⏱ 试用中</span>
              <?php else: ?>
                <span class="badge danger">⚠ 未授权</span>
              <?php endif; ?>
            </h3>
            <p>
              <?php if (!empty($license_data['has_license']) && !empty($license_data['server_error'])): ?>
                授权正常，当前授权服务器连接异常，系统正在使用本地缓存授权信息
              <?php elseif ($license_data['has_license']): ?>
                已激活官方授权，享受全功能与专业技术支持服务
              <?php elseif ($license_data['in_trial']): ?>
                试用期剩余 <?php echo format_license_duration($license_data['trial_seconds']); ?>，购买正式版解锁全部功能
              <?php else: ?>
                请购买官方授权以获取完整功能与安全更新保障
              <?php endif; ?>
            </p>
          </div>
        </div>
        <div class="stats">
          <div class="stat">
            <div class="stat-label">授权ID</div>
            <div class="stat-value">#<?php echo $license_data['id'] ?: '---'; ?></div>
          </div>
          <div class="stat">
            <div class="stat-label">授权类型</div>
            <div class="stat-value"><?php echo $license_data['license_type']; ?></div>
          </div>
          <div class="stat">
            <div class="stat-label">绑定域名</div>
            <div class="stat-value"><?php echo $license_data['domain']; ?></div>
          </div>
          <div class="stat">
            <div class="stat-label">到期时间</div>
            <div class="stat-value"><?php echo !empty($license_data['expired_at']) ? date('Y-m-d', strtotime($license_data['expired_at'])) : '-'; ?></div>
          </div>
          <div class="stat">
            <div class="stat-label">销售渠道</div>
            <div class="stat-value"><?php echo $agent_id > 0 ? '代理ID ' . $agent_id : '官方直营'; ?></div>
          </div>
        </div>
      </div>
    </div>
  </div>
<?php endif; ?>
<div class="admin-card" style="padding-bottom: 5px;">
  <h3 style="margin-bottom: 15px;">数据中心</h3>
  <div class="admin-stats-grid">
    <div class="admin-stat-card">
      <div class="bg-icon">
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
          <path d="M4 7h16M4 12h16M4 17h16" />
        </svg>
      </div>
      <div class="stat-content">
        <div class="stat-label">导航数量</div>
        <div class="stat-number"><?php echo $navigation_count; ?></div>
      </div>
    </div>
    <div class="admin-stat-card">
      <div class="bg-icon">
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
          <path d="M3 7h6v6H3V7zm12 0h6v6h-6V7zM3 17h6v4H3v-4zm12 0h6v4h-6v-4z" />
        </svg>
      </div>
      <div class="stat-content">
        <div class="stat-label">顶级栏目</div>
        <div class="stat-number"><?php echo $catgroup_count; ?></div>
      </div>
    </div>
    <div class="admin-stat-card">
      <div class="bg-icon">
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
          <path d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" />
        </svg>
      </div>
      <div class="stat-content">
        <div class="stat-label">子栏目数量</div>
        <div class="stat-number"><?php echo $category_count; ?></div>
      </div>
    </div>
    <div class="admin-stat-card">
      <div class="bg-icon">
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
          <path d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
        </svg>
      </div>
      <div class="stat-content">
        <div class="stat-label">文章总数</div>
        <div class="stat-number"><?php echo $article_count; ?></div>
      </div>
    </div>
    <div class="admin-stat-card">
      <div class="bg-icon">
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
          <path d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z" />
        </svg>
      </div>
      <div class="stat-content">
        <div class="stat-label">评论总数</div>
        <div class="stat-number"><?php echo $comment_count; ?></div>
      </div>
    </div>
    <div class="admin-stat-card">
      <div class="bg-icon">
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
          <path d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
        </svg>
      </div>
      <div class="stat-content">
        <div class="stat-label">举报总数</div>
        <div class="stat-number"><?php echo $report_count; ?></div>
      </div>
    </div>
    <div class="admin-stat-card">
      <div class="bg-icon">
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
          <path d="M16 11V7a4 4 0 00-8 0v4M5 9h14l1 12H4L5 9z" />
        </svg>
      </div>
      <div class="stat-content">
        <div class="stat-label">订单总数</div>
        <div class="stat-number"><?php echo $order_count; ?></div>
      </div>
    </div>
    <div class="admin-stat-card">
      <div class="bg-icon">
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
          <circle cx="11" cy="11" r="8" />
          <path d="M21 21l-4.35-4.35" />
        </svg>
      </div>
      <div class="stat-content">
        <div class="stat-label">搜索词</div>
        <div class="stat-number"><?php echo $search_count; ?></div>
      </div>
    </div>
    <div class="admin-stat-card">
      <div class="bg-icon">
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
          <path d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z" />
        </svg>
      </div>
      <div class="stat-content">
        <div class="stat-label">用户总数</div>
        <div class="stat-number"><?php echo $user_count; ?></div>
      </div>
    </div>
    <div class="admin-stat-card">
      <div class="bg-icon">
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
          <path d="M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z" />
        </svg>
      </div>
      <div class="stat-content">
        <div class="stat-label">TAG总数</div>
        <div class="stat-number"><?php echo $keyword_count; ?></div>
      </div>
    </div>
    <div class="admin-stat-card">
      <div class="bg-icon">
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
          <path d="M13 10V3L4 14h7v7l9-11h-7z" />
        </svg>
      </div>
      <div class="stat-content">
        <div class="stat-label">已安装插件</div>
        <div class="stat-number" id="async-plugin-count">加载中...</div>
      </div>
    </div>
    <div class="admin-stat-card">
      <div class="bg-icon">
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
          <path d="M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4" />
        </svg>
      </div>
      <div class="stat-content">
        <div class="stat-label">模板标签</div>
        <div class="stat-number"><?php echo $template_tag_count; ?></div>
      </div>
    </div>
  </div>
</div>
<div class="admin-card metrics-trend-card">
  <div class="metrics-trend-head">
    <h3 style="margin:0;">实时变化曲线</h3>
    <span class="metrics-trend-subtitle">最近 <?php echo $trend_days; ?> 天</span>
  </div>
  <div class="metrics-trend-grid">
    <div class="metrics-trend-panel">
      <div class="metrics-trend-canvas-wrap">
        <canvas id="trafficTrendChart"></canvas>
        <div class="metrics-trend-loader" id="trafficTrendLoader"><span class="metrics-trend-loader-dot"></span><span class="metrics-trend-loader-dot"></span><span class="metrics-trend-loader-dot"></span><span>加载中</span></div>
      </div>
    </div>
    <div class="metrics-trend-panel">
      <div class="metrics-trend-canvas-wrap">
        <canvas id="contentTrendChart"></canvas>
        <div class="metrics-trend-loader" id="contentTrendLoader"><span class="metrics-trend-loader-dot"></span><span class="metrics-trend-loader-dot"></span><span class="metrics-trend-loader-dot"></span><span>加载中</span></div>
      </div>
    </div>
  </div>
</div>
<div class="admin-card">
  <h3 style="margin-bottom: 15px;">环境信息</h3>
  <div class="environment-info">
    <div class="environment-item" id="async-file-info"> <span class="environment-label">网站文件数量</span> <span class="environment-value">加载中...</span> </div>
    <div class="environment-item"> <span class="environment-label">PHP 版本</span> <span class="environment-value"><?php echo $php_version; ?></span> </div>
    <div class="environment-item"> <span class="environment-label">程序版本</span> <span class="environment-value"><?php echo $version; ?></span> </div>
    <div class="environment-item"> <span class="environment-label">系统缓存时间</span> <span class="environment-value"><?php echo $cache_time_text; ?></span> </div>
    <div class="environment-item"> <span class="environment-label">MySQL 版本</span> <span class="environment-value"><?php echo $mysql_version ? $mysql_version : 'MySQL 服务不可用'; ?></span> </div>
    <div class="environment-item" id="async-db-size"> <span class="environment-label">数据库大小</span> <span class="environment-value">加载中...</span> </div>
    <div class="environment-item" id="async-db-charset"> <span class="environment-label">连接字符集</span> <span class="environment-value">加载中...</span> </div>
    <div class="environment-item" id="async-db-conn"> <span class="environment-label">最大连接数</span> <span class="environment-value">加载中...</span> </div>
  </div>
</div>
<?php


$recentActivities = getRecentActivities(8);
?>
<div class="admin-card">
  <h3>最近动态</h3>
  <br>
  <div class="table-container">
    <table class="admin-table activities-manage" style="table-layout: fixed;">
      <thead>
        <tr>
          <th style="width: 50px; text-align: center;">ID</th>
          <th style="width: 200px; text-align: center;">时间</th>
          <th style="width: 100px; text-align: center;">类型</th>
          <th style="width: 100px; text-align: center;">用户名</th>
          <th style="text-align: left;">动态内容</th>
        </tr>
      </thead>
      <tbody>
        <?php if (!empty($recentActivities)): ?>
          <?php foreach ($recentActivities as $activity): ?>
            <tr>
              <td><?php echo $activity['index']; ?></td>
              <td><?php echo date('Y-m-d H:i:s', strtotime($activity['time'])); ?></td>
              <td><?php echo $activity['type_name']; ?></td>
              <td><?php echo isset($activity['username']) ? $activity['username'] : '-'; ?></td>
              <td style="white-space: nowrap !important; overflow: hidden !important; text-overflow: ellipsis !important; max-width: 400px; display: table-cell !important; height: 30px;"><?php echo $activity['content']; ?></td>
            </tr>
          <?php endforeach; ?>
        <?php else: ?>
          <tr>
            <td colspan="5" style="text-align: center;">暂无动态数据</td>
          </tr>
        <?php endif; ?>
      </tbody>
    </table>
  </div>
</div>
<script>
  (function() {
    setTimeout(function() {
      fetch('/license.php?qk_ajax_verify=1', {
        method: 'GET',
        credentials: 'same-origin',
        headers: {
          'Accept': 'application/json'
        }
      }).catch(function() {});
    }, 300);

    var trendData = <?php echo json_encode($trend_payload, JSON_UNESCAPED_UNICODE); ?>;
    var trafficPanel = document.getElementById('trafficTrendChart') ? document.getElementById('trafficTrendChart').closest('.metrics-trend-panel') : null;
    var contentPanel = document.getElementById('contentTrendChart') ? document.getElementById('contentTrendChart').closest('.metrics-trend-panel') : null;
    if (trafficPanel) trafficPanel.classList.add('loading');
    if (contentPanel) contentPanel.classList.add('loading');
    var commonOptions = {
      responsive: true,
      maintainAspectRatio: false,
      interaction: {
        mode: 'index',
        intersect: false
      },
      plugins: {
        legend: {
          position: 'top',
          labels: {
            boxWidth: 10,
            boxHeight: 10,
            padding: 10,
            font: {
              size: 12,
              lineHeight: 1.1
            },
            usePointStyle: true,
            pointStyle: 'circle'
          }
        },
        tooltip: {
          backgroundColor: 'rgba(15,23,42,0.92)',
          padding: 10,
          titleFont: {
            size: 12
          },
          bodyFont: {
            size: 12
          }
        }
      },
      elements: {
        line: {
          tension: 0.35,
          borderWidth: 2.2
        },
        point: {
          radius: 2.5,
          hoverRadius: 4.5
        }
      },
      scales: {
        x: {
          grid: {
            color: 'rgba(148,163,184,0.16)'
          },
          ticks: {
            color: '#64748b'
          }
        },
        y: {
          beginAtZero: true,
          grid: {
            color: 'rgba(148,163,184,0.18)'
          },
          ticks: {
            precision: 0,
            color: '#64748b'
          }
        }
      }
    };

    function renderWithChartJs() {
      if (typeof Chart === 'undefined') return false;
      new Chart(document.getElementById('trafficTrendChart').getContext('2d'), {
        type: 'line',
        data: {
          labels: trendData.labels,
          datasets: [{
              label: 'PV',
              data: trendData.traffic.pv,
              borderColor: '#3b82f6',
              backgroundColor: 'rgba(59,130,246,0.14)',
              fill: true
            },
            {
              label: 'UV',
              data: trendData.traffic.uv,
              borderColor: '#22d3ee',
              backgroundColor: 'rgba(34,211,238,0.12)',
              fill: true
            },
            {
              label: '独立IP',
              data: trendData.traffic.ip,
              borderColor: '#2dd4bf',
              backgroundColor: 'rgba(45,212,191,0.12)',
              fill: true
            },
            {
              label: '蜘蛛访问',
              data: trendData.traffic.spider,
              borderColor: '#fbbf24',
              backgroundColor: 'rgba(251,191,36,0.12)',
              fill: true
            },
            {
              label: '会话数',
              data: trendData.traffic.session,
              borderColor: '#a78bfa',
              backgroundColor: 'rgba(167,139,250,0.12)',
              fill: true
            }
          ]
        },
        options: commonOptions
      });
      if (trafficPanel) trafficPanel.classList.remove('loading');
      new Chart(document.getElementById('contentTrendChart').getContext('2d'), {
        type: 'line',
        data: {
          labels: trendData.labels,
          datasets: [{
              label: '新增文章',
              data: trendData.content.posts,
              borderColor: '#34d399',
              backgroundColor: 'rgba(52,211,153,0.12)',
              fill: true
            },
            {
              label: '新增评论',
              data: trendData.content.comments,
              borderColor: '#6366f1',
              backgroundColor: 'rgba(99,102,241,0.12)',
              fill: true
            },
            {
              label: '新增用户',
              data: trendData.content.users,
              borderColor: '#f43f5e',
              backgroundColor: 'rgba(244,63,94,0.12)',
              fill: true
            },
            {
              label: '新增搜索词',
              data: trendData.content.search_terms,
              borderColor: '#38bdf8',
              backgroundColor: 'rgba(56,189,248,0.12)',
              fill: true
            },
            {
              label: '新增分享数',
              data: trendData.content.shares,
              borderColor: '#f59e0b',
              backgroundColor: 'rgba(245,158,11,0.12)',
              fill: true
            }
          ]
        },
        options: commonOptions
      });
      if (contentPanel) contentPanel.classList.remove('loading');
      return true;
    }
    if (renderWithChartJs()) return;
    var chartLib = document.createElement('script');
    chartLib.src = '/assets/js/Chart.js';
    chartLib.async = true;
    chartLib.onload = function() {
      renderWithChartJs();
    };
    chartLib.onerror = function() {
      if (trafficPanel) trafficPanel.classList.remove('loading');
      if (contentPanel) contentPanel.classList.remove('loading');
    };
    document.head.appendChild(chartLib);
  })();

  (function() {
    function loadMetricsData() {
      fetch('?page=metrics_ajax')
        .then(function(response) {
          return response.json();
        })
        .then(function(data) {
          var dbSizeEl = document.getElementById('async-db-size');
          var dbCharsetEl = document.getElementById('async-db-charset');
          var dbConnEl = document.getElementById('async-db-conn');
          var pluginCountEl = document.getElementById('async-plugin-count');
          var fileInfoEl = document.getElementById('async-file-info');

          if (dbSizeEl) {
            dbSizeEl.querySelector('.environment-value').textContent = data.db_size;
          }
          if (dbCharsetEl) {
            dbCharsetEl.querySelector('.environment-value').textContent = data.db_charset;
          }
          if (dbConnEl) {
            dbConnEl.querySelector('.environment-value').textContent = data.db_max_connections;
          }
          if (pluginCountEl) {
            pluginCountEl.textContent = data.plugin_count;
          }
          if (fileInfoEl) {
            fileInfoEl.querySelector('.environment-value').textContent = data.file_count + ' 个 (' + data.file_size + ')';
          }
        })
        .catch(function(error) {
          console.error('加载统计数据失败:', error);
        });
    }

    if (document.readyState === 'loading') {
      document.addEventListener('DOMContentLoaded', loadMetricsData);
    } else {
      loadMetricsData();
    }
  })();
</script>