
        <?php
        // Basit sürüm kontrolü: admin ana sayfa açılışında kontrol et, yeni sürüm varsa uyarı göster
        try {
            $adminLang = m_get_session('admin_lang') ?: 'tr';
            $currentVersion = general_settings('app_version', $adminLang) ?: '1.0.0';
            $manifestUrl = defined('UPDATE_MANIFEST_URL') ? UPDATE_MANIFEST_URL : '';
            $latestVersion = null; $hasUpdate = false;
            if ($manifestUrl) {
                $resp = @m_url_get($manifestUrl);
                $data = @json_decode($resp, true);
                if (is_array($data) && !empty($data['latest'])) {
                    $latestVersion = (string) $data['latest'];
                    $hasUpdate = version_compare($latestVersion, $currentVersion, '>');
                }
            }
        } catch (Exception $e) { $hasUpdate = false; }
        ?>

    

        <div class="row">
            <div class="col-xxl-5">
                <div class="d-flex flex-column">
                    <div class="row">
                          <div class="col-12">
                <div class="card">
                    <div class="card-body p-0">
                        <?php if (!empty($hasUpdate) && !empty($latestVersion)) { ?>
                            <div class="alert alert-warning border-0 rounded-0 m-0 d-flex align-items-center" role="alert">
                                <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-alert-triangle text-warning me-2 icon-sm"><path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"></path><line x1="12" y1="9" x2="12" y2="13"></line><line x1="12" y1="17" x2="12.01" y2="17"></line></svg>
                                <div class="flex-grow-1 text-truncate">
                                    <?= lang('updates.card.alert_message', ['latest' => $latestVersion, 'current' => $currentVersion], 'Yeni sürüm mevcut: ' . htmlspecialchars($latestVersion) . ' (mevcut: ' . htmlspecialchars($currentVersion) . ')') ?>
                                </div>
                                <div class="flex-shrink-0">
                                    <a href="<?= ADMIN_URL ?>/updates/lists" class="text-reset text-decoration-underline"><b><?= lang('updates.card.upgrade_button', [], 'Güncellemeler') ?></b></a>
                                </div>
                            </div>
                            <div class="row align-items-end">
                                <div class="col-sm-8">
                                    <div class="p-3">
                                        <p class="fs-16 lh-base"><?= lang('updates.card.cta_title', [], 'Güncellemeler sayfasından sürümü uygulayabilirsiniz.') ?></p>
                                        <div class="mt-3">
                                            <a href="<?= ADMIN_URL ?>/updates/lists" class="btn btn-success"><?= lang('updates.card.cta_button', [], 'Güncelleme Sayfasına Git') ?></a>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-sm-4">
                                    <div class="px-3">
                                        <img src="assets/images/user-illustarator-2.png" class="img-fluid" alt="">
                                    </div>
                                </div>
                            </div>
                        <?php } else { ?>
                            <div class="alert alert-success border-0 rounded-0 m-0 d-flex align-items-center" role="alert">
                                <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-check-circle text-success me-2 icon-sm"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path><polyline points="22 4 12 14.01 9 11.01"></polyline></svg>
                                <div class="flex-grow-1 text-truncate">
                                    <?= lang('updates.card.alert_no_update', ['current' => $currentVersion], 'Sistem güncel (mevcut: ' . htmlspecialchars($currentVersion) . ')') ?>
                                </div>
                                <div class="flex-shrink-0">
                                    <a href="<?= ADMIN_URL ?>/updates/lists" class="text-reset text-decoration-underline"><b><?= lang('updates.card.upgrade_button', [], 'Güncellemeler') ?></b></a>
                                </div>
                            </div>
                        <?php } ?>
                    </div>
                </div>
            </div>
                        <div class="col-12">
                            <div class="card">
                                <div class="card-body p-0">
                                    <?php $matomo = get_matomo_dashboard_data(m_get_session('admin_lang') ?: 'tr', 900); ?>
                                    <?php if (!$matomo) { ?>
                                    <div class="alert alert-warning border-0 rounded-0 m-0" role="alert">
                                        <?=lang('analytics_widget_not_configured', [], 'Analitik yapılandırılmamış veya erişilemiyor.')?>
                                    </div>
                                    <?php } ?>

                                    <div class="row align-items-end">
                                        <div class="col-sm-8">
                                            <div class="p-3">
                                                <p class="fs-17 lh-base mb-2"><?=lang('analytics_widget_title', [], 'Son 7 Gün Özeti')?></p>
                                                <div class="d-flex gap-4 align-items-end flex-wrap">
                                                    <div>
                                                        <div class="text-muted"><?=lang('analytics_visits', [], 'Ziyaret')?></div>
                                                        <h4 class="mb-0"><?= isset($matomo['totals']['visits']) ? (int)$matomo['totals']['visits'] : 0 ?></h4>
                                                    </div>
                                                    <div>
                                                        <div class="text-muted"><?=lang('analytics_actions', [], 'Görüntüleme')?></div>
                                                        <h4 class="mb-0"><?= isset($matomo['totals']['actions']) ? (int)$matomo['totals']['actions'] : 0 ?></h4>
                                                    </div>
                                                    <div>
                                                        <div class="text-muted"><?=lang('analytics_bounce_rate', [], 'Hemen Çıkma Oranı')?></div>
                                                        <h4 class="mb-0"><?= isset($matomo['metrics']['bounceRatePct']) ? (float)$matomo['metrics']['bounceRatePct'] : 0 ?>%</h4>
                                                    </div>
                                                    <div>
                                                        <div class="text-muted"><?=lang('analytics_avg_time_on_site', [], 'Ort. Oturum Süresi')?></div>
                                                        <h4 class="mb-0"><?php $sec = isset($matomo['metrics']['avgTimeSeconds']) ? (int)$matomo['metrics']['avgTimeSeconds'] : 0; $m=floor($sec/60); $s=$sec%60; echo sprintf('%02d:%02d',$m,$s); ?></h4>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-sm-4">
                                            <div class="px-3">
                                                <img src="assets/images/user-illustarator-2.png" class="img-fluid" alt="">
                                            </div>
                                        </div>
                                    </div>
                                </div> <!-- end card-body-->
                            </div>
                        </div> <!-- end col-->
                    </div> <!-- end row-->



                    <div class="row">
                        <div class="col-xl-4">
                            <?php $liveCountries = get_matomo_live_countries(30, m_get_session('admin_lang') ?: 'tr', 30); ?>
                            <div class="card card-height-100">
                                <div class="card-header align-items-center d-flex">
                                    <h4 class="card-title mb-0 flex-grow-1"><?=lang('analytics_countries', [], 'Ülkeler (Anlık 30 dk)')?></h4>
                                </div>
                                <div class="card-body">
                                    <div class="table-responsive table-card">
                                        <table class="table table-borderless table-centered align-middle table-nowrap mb-1">
                                            <thead class="text-muted border-dashed border border-start-0 border-end-0 bg-light-subtle">
                                                <tr>
                                                    <th><?=lang('analytics_country', [], 'Ülke')?></th>
                                                    <th class="text-end"><?=lang('analytics_visits', [], 'Ziyaret')?></th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                            <?php if (!empty($liveCountries)) { foreach ($liveCountries as $row) { ?>
                                                <tr>
                                                    <td><?= htmlspecialchars($row['label']) ?></td>
                                                    <td class="text-end"><?= (int) $row['nb_visits'] ?></td>
                                                </tr>
                                            <?php } } else { ?>
                                                <tr><td colspan="2" class="text-muted text-center py-4"><?=lang('analytics_no_data', [], 'Veri yok')?></td></tr>
                                            <?php } ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="col-xl-4">
                            <?php $liveDevices = get_matomo_live_devices(30, m_get_session('admin_lang') ?: 'tr', 30); ?>
                            <div class="card card-height-100">
                                <div class="card-header align-items-center d-flex">
                                    <h4 class="card-title mb-0 flex-grow-1"><?=lang('analytics_devices', [], 'Cihazlar (Anlık 30 dk)')?></h4>
                                </div>
                                <div class="card-body">
                                    <div class="table-responsive table-card">
                                        <table class="table table-borderless table-centered align-middle table-nowrap mb-1">
                                            <thead class="text-muted border-dashed border border-start-0 border-end-0 bg-light-subtle">
                                                <tr>
                                                    <th><?=lang('analytics_device', [], 'Cihaz')?></th>
                                                    <th class="text-end"><?=lang('analytics_visits', [], 'Ziyaret')?></th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                            <?php if (!empty($liveDevices)) { foreach ($liveDevices as $row) { ?>
                                                <tr>
                                                    <td><?= htmlspecialchars($row['label']) ?></td>
                                                    <td class="text-end"><?= (int) $row['nb_visits'] ?></td>
                                                </tr>
                                            <?php } } else { ?>
                                                <tr><td colspan="2" class="text-muted text-center py-4"><?=lang('analytics_no_data', [], 'Veri yok')?></td></tr>
                                            <?php } ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="col-xl-4">
                            <?php $liveRefs = get_matomo_live_referrers(30, m_get_session('admin_lang') ?: 'tr', 30); ?>
                            <div class="card card-height-100">
                                <div class="card-header align-items-center d-flex">
                                    <h4 class="card-title mb-0 flex-grow-1"><?=lang('analytics_referrers', [], 'Kaynaklar (Anlık 30 dk)')?></h4>
                                </div>
                                <div class="card-body">
                                    <div class="table-responsive table-card">
                                        <table class="table table-borderless table-centered align-middle table-nowrap mb-1">
                                            <thead class="text-muted border-dashed border border-start-0 border-end-0 bg-light-subtle">
                                                <tr>
                                                    <th><?=lang('analytics_referrer_type', [], 'Tür')?></th>
                                                    <th class="text-end"><?=lang('analytics_visits', [], 'Ziyaret')?></th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                            <?php if (!empty($liveRefs)) { foreach ($liveRefs as $row) { ?>
                                                <tr>
                                                    <td><?= htmlspecialchars($row['label']) ?></td>
                                                    <td class="text-end"><?= (int) $row['nb_visits'] ?></td>
                                                </tr>
                                            <?php } } else { ?>
                                                <tr><td colspan="2" class="text-muted text-center py-4"><?=lang('analytics_no_data', [], 'Veri yok')?></td></tr>
                                            <?php } ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div> <!-- end row-->

                    <div class="row">
                        <div class="col-md-6">
                            <div class="card card-animate">
                                <div class="card-body">
                                    <div class="d-flex justify-content-between">
                                        <div>
                                            <p class="fw-medium text-muted mb-0"><?=lang('analytics_visits', [], 'Ziyaret')?></p>
                                            <h2 class="mt-4 ff-secondary fw-semibold"><?= isset($matomo['totals']['visits']) ? (int)$matomo['totals']['visits'] : 0 ?></h2>
                                            <p class="mb-0 text-muted">&nbsp;</p>
                                        </div>
                                        <div>
                                            <div class="avatar-sm flex-shrink-0">
                                                            <span class="avatar-title bg-info-subtle rounded-circle fs-2">
                                                                <i data-feather="users" class="text-info"></i>
                                                            </span>
                                            </div>
                                        </div>
                                    </div>
                                </div><!-- end card body -->
                            </div> <!-- end card-->
                        </div> <!-- end col-->

                        <div class="col-md-6">
                            <div class="card card-animate">
                                <div class="card-body">
                                    <div class="d-flex justify-content-between">
                                        <div>
                                            <p class="fw-medium text-muted mb-0"><?=lang('analytics_actions', [], 'Görüntüleme')?></p>
                                            <h2 class="mt-4 ff-secondary fw-semibold"><?= isset($matomo['totals']['actions']) ? (int)$matomo['totals']['actions'] : 0 ?></h2>
                                            <p class="mb-0 text-muted">&nbsp;</p>
                                        </div>
                                        <div>
                                            <div class="avatar-sm flex-shrink-0">
                                                            <span class="avatar-title bg-info-subtle rounded-circle fs-2">
                                                                <i data-feather="activity" class="text-info"></i>
                                                            </span>
                                            </div>
                                        </div>
                                    </div>
                                </div><!-- end card body -->
                            </div> <!-- end card-->
                        </div> <!-- end col-->
                    </div> <!-- end row-->

                    <div class="row">
                        <div class="col-md-12">
                            <?php $live = get_matomo_live_counters(30, m_get_session('admin_lang') ?: 'tr', 30); ?>
                            <div class="card">
                                <div class="card-header align-items-center d-flex">
                                    <h4 class="card-title mb-0 flex-grow-1"><?=lang('analytics_live_last30', [], 'Anlık (Son 30 dk)')?> </h4>
                                </div>
                                <div class="card-body">
                                    <div class="d-flex gap-5">
                                        <div>
                                            <div class="text-muted"><?=lang('analytics_visitors', [], 'Tekil Ziyaretçi')?></div>
                                            <h4 class="mb-0"><?= (int)($live['visitors'] ?? 0) ?></h4>
                                        </div>
                                        <div>
                                            <div class="text-muted"><?=lang('analytics_visits', [], 'Ziyaret')?></div>
                                            <h4 class="mb-0"><?= (int)($live['visits'] ?? 0) ?></h4>
                                        </div>
                                        <div>
                                            <div class="text-muted"><?=lang('analytics_actions', [], 'Görüntüleme')?></div>
                                            <h4 class="mb-0"><?= (int)($live['actions'] ?? 0) ?></h4>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div> <!-- end row-->

                    <!-- Canlı Site Dili (30dk) ve Güvenlik Widget'ı -->
                    <div class="row">
                        <div class="col-md-6">
                            <?php $liveDim = get_matomo_live_site_languages(30, m_get_session('admin_lang') ?: 'tr', 30, 1); ?>
                            <div class="card">
                                <div class="card-header align-items-center d-flex">
                                    <h4 class="card-title mb-0 flex-grow-1"><?=lang('analytics_languages_site', [], 'Dil Dağılımı (Site Dili)')?> — 30m</h4>
                                </div>
                                <div class="card-body">
                                    <div class="table-responsive table-card">
                                        <table class="table table-borderless table-centered align-middle table-nowrap mb-1">
                                            <thead class="text-muted border-dashed border border-start-0 border-end-0 bg-light-subtle">
                                                <tr>
                                                    <th><?=lang('analytics_language', [], 'Dil')?></th>
                                                    <th class="text-end"><?=lang('analytics_visits', [], 'Ziyaret')?></th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php if (!empty($liveDim)) { foreach ($liveDim as $row) { ?>
                                                    <tr>
                                                        <td><?= htmlspecialchars($row['label']) ?></td>
                                                        <td class="text-end"><?= (int) $row['nb_visits'] ?></td>
                                                    </tr>
                                                <?php } } else { ?>
                                                    <tr><td colspan="2" class="text-muted text-center py-4"><?=lang('analytics_no_data', [], 'Veri yok')?></td></tr>
                                                <?php } ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <?php $refs = get_matomo_referrers_data(m_get_session('admin_lang') ?: 'tr', 120); ?>
                            <div class="card">
                                <div class="card-header align-items-center d-flex">
                                    <h4 class="card-title mb-0 flex-grow-1"><?=lang('analytics_referrers', [], 'Kaynaklar')?></h4>
                                </div>
                                <div class="card-body">
                                <div class="table-responsive table-card">
                                    <table class="table table-borderless table-centered align-middle table-nowrap mb-1">
                                        <thead class="text-muted border-dashed border border-start-0 border-end-0 bg-light-subtle">
                                            <tr>
                                                <th><?=lang('analytics_referrer_type', [], 'Tür')?></th>
                                                <th class="text-end"><?=lang('analytics_visits', [], 'Ziyaret')?></th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <?php if (!empty($refs['types'])) { foreach ($refs['types'] as $row) { ?>
                                                <tr>
                                                    <td><?= htmlspecialchars($row['label']) ?></td>
                                                    <td class="text-end"><?= (int) $row['nb_visits'] ?></td>
                                                </tr>
                                            <?php } } else { ?>
                                                <tr><td colspan="2" class="text-muted text-center py-4"><?=lang('analytics_no_data', [], 'Veri yok')?></td></tr>
                                            <?php } ?>
                                            </tbody>
                                        </table>
                                    </div>
                                    <div class="table-responsive table-card">
                                       <table class="table table-borderless table-centered align-middle table-nowrap mb-1">
                                        <thead class="text-muted border-dashed border border-start-0 border-end-0 bg-light-subtle">
                                            <tr>
                                                <th><?=lang('analytics_website', [], 'Web Sitesi')?></th>
                                                <th class="text-end"><?=lang('analytics_visits', [], 'Ziyaret')?></th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <?php if (!empty($refs['websites'])) { foreach ($refs['websites'] as $row) { ?>
                                                <tr>
                                                    <td><?= htmlspecialchars($row['label']) ?></td>
                                                    <td class="text-end"><?= (int) $row['nb_visits'] ?></td>
                                                </tr>
                                            <?php } } else { ?>
                                                <tr><td colspan="2" class="text-muted text-center py-4"><?=lang('analytics_no_data', [], 'Veri yok')?></td></tr>
                                            <?php } ?>
                                            </tbody>
                                        </table>
                                        </div>
                                            </div>
                                        </div>
                                    </div>
                       
                    </div> <!-- end row -->

                    <div class="row">
                        <div class="col-md-6">
                            <?php $devices = get_matomo_device_types_data(m_get_session('admin_lang') ?: 'tr', 120); ?>
                            <div class="card">
                                <div class="card-header align-items-center d-flex">
                                    <h4 class="card-title mb-0 flex-grow-1"><?=lang('analytics_devices', [], 'Cihazlara Göre')?></h4>
                                </div>
                                <div class="card-body">
                                    <div class="table-responsive table-card">
                                      <table class="table table-borderless table-centered align-middle table-nowrap mb-1">
                                        <thead class="text-muted border-dashed border border-start-0 border-end-0 bg-light-subtle">
                                            <tr>
                                                <th><?=lang('analytics_device', [], 'Cihaz')?></th>
                                                <th class="text-end"><?=lang('analytics_visits', [], 'Ziyaret')?></th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <?php if (!empty($devices)) { foreach ($devices as $row) { ?>
                                                <tr>
                                                    <td><?= htmlspecialchars($row['label']) ?></td>
                                                    <td class="text-end"><?= (int) $row['nb_visits'] ?></td>
                                                </tr>
                                            <?php } } else { ?>
                                                <tr><td colspan="2" class="text-muted text-center py-4"><?=lang('analytics_no_data', [], 'Veri yok')?></td></tr>
                                            <?php } ?>
                                            </tbody>
                                        </table>
                                        </div>
                                            </div>
                                        </div>
                                    </div>
                            <div class="col-md-6 g-2">
                            <?php $demoEvents = get_matomo_events_top_names('Form','Submit', m_get_session('admin_lang') ?: 'tr', 120, 10); ?>
                            <div class="card">
                                <div class="card-header align-items-center d-flex">
                                    <h4 class="card-title mb-0 flex-grow-1"><?=lang('analytics_goals_demo', [], 'Dönüşüm: Demo Formu')?></h4>
                                </div>
                                <div class="card-body">
                                    <div class="table-responsive table-card">
                                        <table class="table table-borderless table-centered align-middle table-nowrap mb-1">
                                            <thead class="text-muted border-dashed border border-start-0 border-end-0 bg-light-subtle">
                                                <tr>
                                                    <th><?=lang('analytics_event', [], 'Etkinlik')?></th>
                                                    <th class="text-end"><?=lang('analytics_events', [], 'Olay')?></th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php if (!empty($demoEvents)) { foreach ($demoEvents as $row) { ?>
                                                    <tr>
                                                        <td><?= htmlspecialchars($row['label']) ?></td>
                                                        <td class="text-end"><?= (int) $row['nb_events'] ?></td>
                                                    </tr>
                                                <?php } } else { ?>
                                                    <tr><td colspan="2" class="text-muted text-center py-4"><?=lang('analytics_no_data', [], 'Veri yok')?></td></tr>
                                                <?php } ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                       
                        
                        <div class="col-md-6">
                            <?php $err404 = get_matomo_events_top_names('Error','404', m_get_session('admin_lang') ?: 'tr', 120, 10); ?>
                            <div class="card">
                                <div class="card-header align-items-center d-flex">
                                    <h4 class="card-title mb-0 flex-grow-1"><?=lang('analytics_404_pages', [], 'En Çok 404 URL')?></h4>
                                </div>
                                <div class="card-body">
                                    <div class="table-responsive table-card">
                                        <table class="table table-borderless table-centered align-middle table-nowrap mb-1">
                                            <thead class="text-muted border-dashed border border-start-0 border-end-0 bg-light-subtle">
                                                <tr>
                                                    <th><?=lang('analytics_page', [], 'Sayfa')?></th>
                                                    <th class="text-end"><?=lang('analytics_events', [], 'Olay')?></th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php if (!empty($err404)) { foreach ($err404 as $row) { ?>
                                                    <tr>
                                                        <td><?= htmlspecialchars($row['label']) ?></td>
                                                        <td class="text-end"><?= (int) $row['nb_events'] ?></td>
                                                    </tr>
                                                <?php } } else { ?>
                                                    <tr><td colspan="2" class="text-muted text-center py-4"><?=lang('analytics_no_data', [], 'Veri yok')?></td></tr>
                                                <?php } ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div> <!-- end row-->

                    <!-- Goals: Demo form submissions (last 7 days via Events) -->
                    <div class="row"></div> <!-- end row -->
                </div>
            </div> <!-- end col-->

            <div class="col-xxl-7">
                <div class="row">
                    <div class="col-xl-6">
                        <div class="card card-height-100">
                            <div class="card-header align-items-center d-flex">
                                <h4 class="card-title mb-0 flex-grow-1"><?=lang('analytics_top_pages', [], 'En İyi Sayfalar')?></h4>
                            </div><!-- end card header -->

                            <!-- card body -->
                            <div class="card-body">
                                <div class="table-responsive table-card">
                                    <table class="table table-borderless table-centered align-middle table-nowrap mb-1">
                                        <thead class="text-muted border-dashed border border-start-0 border-end-0 bg-light-subtle">
                                        <tr>
                                            <th><?=lang('analytics_page', [], 'Sayfa')?></th>
                                            <th class="text-end" style="width: 120px;"><?=lang('analytics_visits', [], 'Ziyaret')?></th>
                                            <th class="text-end" style="width: 140px;"><?=lang('analytics_actions', [], 'Görüntüleme')?></th>
                                        </tr>
                                        </thead>
                                        <tbody class="border-0">
                                        <?php if (!empty($matomo['topPages'])) { foreach ($matomo['topPages'] as $row) { ?>
                                            <tr>
                                                <td><?= htmlspecialchars($row['label']) ?></td>
                                                <td class="text-end"><?= (int) $row['nb_visits'] ?></td>
                                                <td class="text-end"><?= (int) $row['nb_hits'] ?></td>
                                        </tr>
                                        <?php } } else { ?>
                                            <tr><td colspan="3" class="text-muted text-center py-4"><?=lang('analytics_no_data', [], 'Veri yok')?></td></tr>
                                        <?php } ?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                            <!-- end card body -->
                        </div><!-- end card -->
                    </div><!-- end col -->

                    <div class="col-xl-3">
                        <div class="card card-height-100">
                            <div class="card-header align-items-center d-flex">
                                <h4 class="card-title mb-0 flex-grow-1"><?=lang('analytics_languages_browser', [], 'Dil Dağılımı (Tarayıcı)')?></h4>
                            </div>
                            <div class="card-body">
                                <div>
                                    <div class="table-responsive table-card">
                                    <table class="table table-borderless table-centered align-middle table-nowrap mb-1">
                                        <thead class="text-muted border-dashed border border-start-0 border-end-0 bg-light-subtle">
                                                <tr>
                                                <th><?=lang('analytics_language', [], 'Dil')?></th>
                                                <th class="text-end"><?=lang('analytics_visits', [], 'Ziyaret')?></th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <?php if (!empty($matomo['languages'])) { foreach ($matomo['languages'] as $row) { ?>
                                                <tr>
                                                    <td><?= htmlspecialchars($row['label']) ?></td>
                                                    <td class="text-end"><?= (int) $row['nb_visits'] ?></td>
                                                </tr>
                                            <?php } } else { ?>
                                                <tr><td colspan="2" class="text-muted text-center py-4"><?=lang('analytics_no_data', [], 'Veri yok')?></td></tr>
                                            <?php } ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div><!-- end card body -->
                        </div><!-- end card -->
                    </div> <!-- end col-->

            <div class="col-xl-3">
                        <?php $dimLang = get_matomo_language_dimension(m_get_session('admin_lang') ?: 'tr', 120); ?>
                        <div class="card card-height-100">
                            <div class="card-header align-items-center d-flex">
                                <h4 class="card-title mb-0 flex-grow-1"><?=lang('analytics_languages_site', [], 'Dil Dağılımı (Site Dili)')?></h4>
                            </div>
                            <div class="card-body">
                                <div>
                                    <div class="table-responsive table-card">
                                    <table class="table table-borderless table-centered align-middle table-nowrap mb-1">
                                        <thead class="text-muted border-dashed border border-start-0 border-end-0 bg-light-subtle">
                                                <tr>
                                                <th><?=lang('analytics_language', [], 'Dil')?></th>
                                                <th class="text-end"><?=lang('analytics_visits', [], 'Ziyaret')?></th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <?php if (!empty($dimLang)) { foreach ($dimLang as $row) { ?>
                                                <tr>
                                                    <td><?= htmlspecialchars($row['label']) ?></td>
                                                    <td class="text-end"><?= (int) $row['nb_visits'] ?></td>
                                                </tr>
                                            <?php } } else { ?>
                                                <tr><td colspan="2" class="text-muted text-center py-4"><?=lang('analytics_no_data', [], 'Veri yok')?></td></tr>
                                            <?php } ?>
                                            </tbody>
                                        </table>
                            </div>
                        </div>
                    </div><!-- end card body -->
                </div><!-- end card -->
                    </div> <!-- end col-->

                    <div class="col-xl-12">
                        <?php $country = get_matomo_country_map_data(m_get_session('admin_lang') ?: 'tr', 120); ?>
                <div class="card card-height-100">
                    <div class="card-header align-items-center d-flex">
                                <h4 class="card-title mb-0 flex-grow-1"><?=lang('analytics_countries', [], 'Ülkeler (Son 7 Gün)')?></h4>
                            </div>
                    <div class="card-body">
                                <style>
                                /* jsVectorMap/jVectorMap tooltip fix: bazı temalar tooltip'i fixed/bottom:0 yapıyor */
                                .jvm-tooltip, .jsvmap-tooltip {
                                    position: absolute !important;
                                    bottom: auto !important;
                                    right: auto !important;
                                    width: auto !important;
                                    max-width: 320px;
                                    padding: 6px 8px;
                                    border-radius: 4px;
                                    background: rgba(0,0,0,.8);
                                    color: #fff;
                                    border: 0;
                                    box-shadow: 0 2px 6px rgba(0,0,0,.2);
                                    white-space: nowrap;
                                    z-index: 2000 !important;
                                    pointer-events: none;
                                }
                                /* Olası kırpılmaları engelle */
                                #matomo-country-map, #matomo-country-map .jsvmap-container { overflow: visible !important; }
                                </style>
                                <div id="matomo-country-map" style="height: 320px" data-colors='["--vz-primary"]'></div>
                                <div class="table-responsive table-card mt-3">
                                    <table class="table table-borderless table-sm table-centered align-middle table-nowrap mb-1">
                                        <thead class="text-muted border-dashed border border-start-0 border-end-0 bg-light-subtle">
                                        <tr>
                                            <th><?=lang('analytics_country', [], 'Ülke')?></th>
                                            <th class="text-end" style="width: 120px;"><?=lang('analytics_visits', [], 'Ziyaret')?></th>
                                </tr>
                                        </thead>
                                        <tbody class="border-0" id="matomo-country-top">
                                        <?php if (!empty($country['top'])) { foreach ($country['top'] as $row) { ?>
                                            <tr>
                                                <td><?= htmlspecialchars($row['label']) ?></td>
                                                <td class="text-end"><?= (int) $row['nb_visits'] ?></td>
                                </tr>
                                        <?php } } else { ?>
                                            <tr><td colspan="2" class="text-muted text-center py-4"><?=lang('analytics_no_data', [], 'Veri yok')?></td></tr>
                                        <?php } ?>
                                </tbody>
                            </table>
                        </div>
                    </div><!-- end card body -->
                </div><!-- end card -->
                        <script>
                        document.addEventListener('DOMContentLoaded', function(){
                          try{
                            var data = <?php echo json_encode($country && isset($country['series']) ? $country['series'] : []); ?>;
                            if (window.jsVectorMap && document.getElementById('matomo-country-map')){
                              var mapObj = new jsVectorMap({
                                map: 'world_merc', selector: '#matomo-country-map', zoomOnScroll: false, zoomButtons: true,
                                series: { regions: [{ values: data, scale: ['#e0ecf9', '#2b6cb0'], normalizeFunction: 'linear' }] },
                                regionStyle: { initial: { fill: '#dfe7f1' } },
                                onRegionTooltipShow: function(arg1, arg2){
                                  // Support both signatures: (tooltip, code) or (code, tooltip)
                                  var tooltip = (arg1 && typeof arg1.text === 'function') ? arg1 : arg2;
                                  var code = (arg1 && typeof arg1 === 'string') ? arg1 : arg2;
                                  if (code && typeof code !== 'string' && tooltip && typeof code.text === 'function') {
                                    // jVectorMap style (event, label, code)
                                    code = arg2;
                                  }
                                  if (!tooltip || !code) return;
                                  var upper = (code || '').toString().toUpperCase();
                                  var visits = (data && (data[upper] || data[code])) || 0;
                                  var name = (mapObj && mapObj.getRegionName) ? mapObj.getRegionName(code) : tooltip.text();
                                  var labelCountry = '<?=lang('analytics_country', [], 'Ülke')?>';
                                  var labelVisits = '<?=lang('analytics_visits', [], 'Ziyaret')?>';
                                  try { tooltip.text(labelCountry + ': ' + name + ' | ' + labelVisits + ': ' + visits); } catch(e) {}
                                }
                              });
                              // Hide tooltip when leaving the map area
                              var container = document.getElementById('matomo-country-map');
                              if (container) {
                                var hideTip = function(){
                                  var tip = container.querySelector('.jsvmap-tooltip') || container.querySelector('.jvm-tooltip') || document.querySelector('.jvm-tooltip');
                                  if (tip) { tip.style.display = 'none'; tip.classList.remove('active'); }
                                };
                                container.addEventListener('mouseleave', hideTip);
                                container.addEventListener('touchend', hideTip);
                                container.addEventListener('blur', hideTip);
                                document.addEventListener('scroll', hideTip, true);
                              }
                              // Zoom butonlarını görünür/hizalı yap
                              var zIn = document.querySelector('#matomo-country-map .jsvmap-zoom-in') || document.querySelector('#matomo-country-map .jvm-zoomin');
                              var zOut = document.querySelector('#matomo-country-map .jsvmap-zoom-out') || document.querySelector('#matomo-country-map .jvm-zoomout');
                              [zIn, zOut].forEach(function(btn){
                                if(!btn) return;
                                btn.style.position='absolute';
                                btn.style.right='10px';
                                btn.style.width='28px';
                                btn.style.height='28px';
                                btn.style.lineHeight='28px';
                                btn.style.borderRadius='6px';
                                btn.style.background='#fff';
                                btn.style.boxShadow='0 1px 3px rgba(0,0,0,.2)';
                                btn.style.color='#34495e';
                                btn.style.border='1px solid #e5e7eb';
                                btn.style.textAlign='center';
                                btn.style.fontWeight='600';
                                btn.style.cursor='pointer';
                              });
                              if (zIn) { zIn.style.top='10px'; }
                              if (zOut) { zOut.style.top='46px'; }
                            }
                          }catch(e){}
                        });
                        </script>
                    </div>
                     <div class="col-md-12">
                            <div class="card">
                                <div class="card-header align-items-center d-flex">
                                    <h4 class="card-title mb-0 flex-grow-1">
                                        <i class="fas fa-shield-alt text-success me-2"></i>
                                        <?= lang('security_dashboard', [], 'Güvenlik Durumu') ?>
                                    </h4>
                                    <div class="flex-shrink-0">
                                        <a href="<?= ADMIN_URL ?>/security_dashboard" class="btn btn-sm btn-outline-primary">
                                            <i class="fas fa-chart-line me-1"></i>
                                            <?= lang('security_detailed_view', [], 'Detaylı Görünüm') ?>
                                        </a>
                                    </div>
                                </div>
                                <div class="card-body">
                                    <?php 
                                    // Güvenlik dashboard verilerini al
                                    $security_data = m_get_security_dashboard();
                                    $security_score = $security_data['system_security_score'] ?? 100;
                                    $active_alerts = $security_data['active_alerts'] ?? 0;
                                    $total_events = $security_data['total_security_events_today'] ?? 0;
                                    $failed_logins = $security_data['failed_login_attempts_today'] ?? 0;
                                    $blocked_ips = $security_data['blocked_ips_today'] ?? 0;
                                    ?>
                                    
                                    <!-- Güvenlik Skoru ve Alarmlar -->
                                    <div class="row mb-3">
                                        <div class="col-md-6">
                                            <div class="d-flex align-items-center">
                                                <div class="flex-shrink-0">
                                                    <div class="avatar-sm">
                                                        <div class="avatar-title bg-<?= $security_score >= 80 ? 'success' : ($security_score >= 60 ? 'warning' : 'danger') ?> rounded-circle">
                                                            <i class="fas fa-shield-alt text-white"></i>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="flex-grow-1 ms-3">
                                                    <h5 class="mb-1"><?= lang('security_score', [], 'Güvenlik Skoru') ?></h5>
                                                    <div class="progress" style="height: 6px;">
                                                        <div class="progress-bar bg-<?= $security_score >= 80 ? 'success' : ($security_score >= 60 ? 'warning' : 'danger') ?>" 
                                                             role="progressbar" style="width: <?= $security_score ?>%"></div>
                                                    </div>
                                                    <small class="text-muted"><?= $security_score ?>/100</small>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-6">
                                            <div class="d-flex align-items-center">
                                                <div class="flex-shrink-0">
                                                    <div class="avatar-sm">
                                                        <div class="avatar-title bg-<?= $active_alerts > 0 ? 'danger' : 'success' ?> rounded-circle">
                                                            <i class="fas fa-bell text-white"></i>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="flex-grow-1 ms-3">
                                                    <h5 class="mb-1"><?= lang('active_alerts', [], 'Aktif Alarmlar') ?></h5>
                                                    <h4 class="mb-0 text-<?= $active_alerts > 0 ? 'danger' : 'success' ?>"><?= $active_alerts ?></h4>
                                                    <small class="text-muted"><?= $active_alerts > 0 ? lang('security_alerts_active', [], 'Dikkat gerektiren alarmlar var') : lang('security_no_alerts', [], 'Aktif alarm yok') ?></small>
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                    <!-- Güvenlik İstatistikleri -->
                                    <div class="row">
                                        <div class="col-md-4">
                                            <div class="text-center p-3 border rounded">
                                                <div class="avatar-sm mx-auto mb-3">
                                                    <div class="avatar-title bg-info rounded-circle">
                                                        <i class="fas fa-calendar-day text-white"></i>
                                                    </div>
                                                </div>
                                                <h4 class="mb-1"><?= $total_events ?></h4>
                                                <p class="text-muted mb-0"><?= lang('security_events_today', [], 'Bugünkü Olaylar') ?></p>
                                            </div>
                                        </div>
                                        <div class="col-md-4">
                                            <div class="text-center p-3 border rounded">
                                                <div class="avatar-sm mx-auto mb-3">
                                                    <div class="avatar-title bg-warning rounded-circle">
                                                        <i class="fas fa-times-circle text-white"></i>
                                                    </div>
                                                </div>
                                                <h4 class="mb-1"><?= $failed_logins ?></h4>
                                                <p class="text-muted mb-0"><?= lang('failed_login_attempts', [], 'Başarısız Girişler') ?></p>
                                            </div>
                                        </div>
                                        <div class="col-md-4">
                                            <div class="text-center p-3 border rounded">
                                                <div class="avatar-sm mx-auto mb-3">
                                                    <div class="avatar-title bg-danger rounded-circle">
                                                        <i class="fas fa-ban text-white"></i>
                                                    </div>
                                                </div>
                                                <h4 class="mb-1"><?= $blocked_ips ?></h4>
                                                <p class="text-muted mb-0"><?= lang('blocked_ips', [], 'Bloklu IP\'ler') ?></p>
                                            </div>
                                        </div>
                                    </div>

                                    <!-- Son Güvenlik Olayları -->
                                    <?php if (!empty($security_data['recent_events'])) { ?>
                                    <div class="mt-4">
                                        <h6 class="mb-3"><?= lang('recent_security_events', [], 'Son Güvenlik Olayları') ?></h6>
                                        <div class="table-responsive">
                                            <table class="table table-sm table-borderless">
                                                <tbody>
                                                    <?php foreach (array_slice($security_data['recent_events'], 0, 3) as $event) { ?>
                                                    <tr>
                                                        <td style="width: 40px;">
                                                            <div class="avatar-xs">
                                                                <div class="avatar-title bg-<?= $event['event_type'] == 'successful_login' ? 'success' : ($event['event_type'] == 'failed_login' ? 'warning' : 'info') ?> rounded-circle">
                                                                    <i class="fas fa-<?= $event['event_type'] == 'successful_login' ? 'check' : ($event['event_type'] == 'failed_login' ? 'times' : 'info') ?> text-white" style="font-size: 10px;"></i>
                                                                </div>
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div>
                                                                <h6 class="mb-0"><?= ucfirst(str_replace('_', ' ', $event['event_type'])) ?></h6>
                                                                <small class="text-muted"><?= $event['ip_address'] ?> • <?= date('H:i', strtotime($event['created_at'])) ?></small>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                    <?php } ?>
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                    <?php } ?>
                                </div>
                            </div>
                        </div>
                </div> <!-- end row-->
            </div><!-- end col -->
        </div> <!-- end row-->



        
