<?php
/**
 * turkiye-nufusu.php - aahaber.com "Türkiye Nüfusu (CANLI)" Gösterge Paneli
 * 
 * Worldometer (worldometers.info/tr/dunya-nufusu/turkiye-nufusu/) gerçek zamanlı verileri:
 * Canlı nüfus saati, tarihsel nüfus verileri (1950-2026), nüfus tahminleri (2025-2050)
 * ve Türkiye'deki en kalabalık 70 şehir istatistiği.
 */

$json_path = __DIR__ . '/data/turkiye_nufus_data.json';
$turkey_data = [];
if (file_exists($json_path)) {
    $raw = @file_get_contents($json_path);
    $turkey_data = json_decode($raw, true) ?: [];
}

$history_table = $turkey_data['tables']['historical'] ?? ['headers' => [], 'rows' => []];
$forecast_table = $turkey_data['tables']['forecast'] ?? ['headers' => [], 'rows' => []];
$cities_table = $turkey_data['tables']['cities'] ?? ['headers' => [], 'rows' => []];

$page_title = "Türkiye Nüfusu (CANLI) — Rakamlarla Dünya — aahaber.com";
$page_desc = "Türkiye'nin anlık canlı nüfus saati, 2026 nüfus göstergeleri, 1950'den günümüze nüfus değişimi, gelecek tahminleri ve en kalabalık 70 şehrin nüfusu aahaber.com'da.";
$page_keywords = "türkiye nüfusu canlı, türkiye nüfus saati, türkiye nüfusu 2026, worldometer türkiye, türkiye demografi, türkiye en kalabalık şehirler, türkiye nüfus tahminleri";
$page_active = "turkiye-nufusu";
$body_class = "turkiye-nufusu-page";

$extra_css = ['turkiye_nufusu.css?v=1.1'];
$extra_js = ['turkiye_nufusu.js?v=1.1'];

require_once __DIR__ . '/ust.php';
?>

<div class="tn-page-container">

  <!-- 1. BREADCRUMB -->
  <div class="tn-breadcrumb">
    <a href="index.php">Ana Sayfa</a>
    <span class="sep">/</span>
    <a href="dunya.php">Rakamlarla Dünya</a>
    <span class="sep">/</span>
    <span class="current">Türkiye Nüfusu (CANLI)</span>
  </div>

  <!-- 2. ÜST BAŞLIK VE CANLI ROZET ŞERİDİ -->
  <div class="tn-header-banner">
    <div class="tn-header-top">
      <div class="tn-live-badge">
        <span class="tn-pulse-dot"></span>
        <span>CANLI NÜFUS SAATİ</span>
      </div>

      <div class="tn-source-pill">
        <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><line x1="2" y1="12" x2="22" y2="12"></line><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"></path></svg>
        <span>Worldometer & Birleşmiş Milletler (BM / UN DESA)</span>
      </div>
    </div>

    <h1 class="tn-main-title">
      <span class="tn-flag-icon">
        <svg width="34" height="23" viewBox="0 0 1200 800">
          <rect width="1200" height="800" fill="#E30A17"/>
          <circle cx="425" cy="400" r="200" fill="#ffffff"/>
          <circle cx="475" cy="400" r="160" fill="#E30A17"/>
          <polygon points="583.33,400 706.77,440.11 659.77,319.89 659.77,480.11 706.77,359.89" fill="#ffffff"/>
        </svg>
      </span>
      <span>Türkiye Nüfusu</span>
      <span style="font-size: 1.1rem; font-weight: 600; color: #e11d48; background: rgba(225,29,72,0.1); padding: 0.2rem 0.6rem; border-radius: 6px;">CANLI</span>
    </h1>
    <p class="tn-main-subtitle">
      Worldometer ve Birleşmiş Milletler Nüfus Bölümü resmi projeksiyonları temelinde Türkiye nüfusunun anlık saniyelik artışı, demografik göstergeleri, tarihsel gelişimi ve 70 kentsel alan nüfusları.
    </p>
  </div>

  <!-- 3. HERO: TÜRKİYE CANLI NÜFUS GÖREV KONTROL KARTI -->
  <div class="tn-hero-card">
    <div class="tn-hero-bg-glow"></div>

    <div class="tn-hero-header">
      <div class="tn-hero-badge">
        <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path><circle cx="9" cy="7" r="4"></circle><path d="M23 21v-2a4 4 0 0 0-3-3.87"></path><path d="M16 3.13a4 4 0 0 1 0 7.75"></path></svg>
        <span>Mevcut Türkiye Nüfusu Saati</span>
      </div>

      <div class="tn-hero-timestamp">
        <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><polyline points="12 6 12 12 16 14"></polyline></svg>
        <span>Son Senkronizasyon: <strong id="tnHeroTimestamp" style="color: #ffffff;">CANLI</strong></span>
      </div>
    </div>

    <div class="tn-hero-center">
      <div class="tn-hero-label">TÜRKİYE'NİN ŞU ANKİ TAHMİNİ NÜFUSU</div>
      <div class="tn-hero-counter" id="tnHeroCounter">87.964.272</div>
      <div class="tn-hero-subtext">
        <span>2026 Yıl Ortası Nüfusu: <strong>87.926.082</strong></span>
        <span>•</span>
        <span class="tn-hero-pill">Dünya Sıralaması: #18</span>
        <span>•</span>
        <span class="tn-hero-pill">Dünya Payı: %1,06</span>
      </div>
    </div>

    <!-- Alt İkincil Sayaçlar -->
    <div class="tn-hero-secondary-grid">
      <div class="tn-sec-box">
        <div class="tn-sec-box-title">Bugün Artan Net Nüfus</div>
        <div class="tn-sec-box-value" id="tnHeroSecToday" style="color: #4ade80;">+384</div>
        <div class="tn-sec-box-note">Gece yarısından bu yana net nüfus artışı</div>
      </div>

      <div class="tn-sec-box">
        <div class="tn-sec-box-title">Bu Yılki Net Nüfus Artışı</div>
        <div class="tn-sec-box-value" id="tnHeroSecYear" style="color: #38bdf8;">+196.482</div>
        <div class="tn-sec-box-note">1 Ocak'tan bu yana net nüfus artışı</div>
      </div>

      <div class="tn-sec-box">
        <div class="tn-sec-box-title">Net Nüfus Değişim Hızı</div>
        <div class="tn-sec-box-value" style="color: #facc15;">~131 Saniyede 1</div>
        <div class="tn-sec-box-note">Yılda ortalama +240.656 kişilik net büyüme</div>
      </div>
    </div>
  </div>

  <!-- 4. ÖZET GÖSTERGELER (KEY INDICATORS) -->
  <div class="tn-section-heading">
    <div>
      <h2>
        <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="#e11d48" stroke-width="2.2"><path d="M3 3v18h18"></path><path d="m19 9-5 5-4-4-3 3"></path></svg>
        Temel Demografik Göstergeler (2026)
      </h2>
      <p>Birleşmiş Milletler ve Dünya İstatistik Kurumu verilerine göre Türkiye demografi özeti.</p>
    </div>
  </div>

  <div class="tn-metrics-grid">
    <!-- 1. Yıl Ortası Nüfus -->
    <div class="tn-metric-card">
      <div class="tn-metric-icon tn-icon-rose">
        <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path><circle cx="9" cy="7" r="4"></circle></svg>
      </div>
      <div class="tn-metric-info">
        <div class="tn-metric-label">2026 Yıl Ortası Nüfusu</div>
        <div class="tn-metric-val">87.926.082</div>
        <div class="tn-metric-sub">Projeksiyon tahmini</div>
      </div>
    </div>

    <!-- 2. Yıllık Değişim -->
    <div class="tn-metric-card">
      <div class="tn-metric-icon tn-icon-green">
        <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="23 6 13.5 15.5 8.5 10.5 1 18"></polyline><polyline points="17 6 23 6 23 12"></polyline></svg>
      </div>
      <div class="tn-metric-info">
        <div class="tn-metric-label">Yıllık Nüfus Değişimi</div>
        <div class="tn-metric-val">+%0,27</div>
        <div class="tn-metric-sub">Yılda +240.656 kişi</div>
      </div>
    </div>

    <!-- 3. Dünya Sıralaması -->
    <div class="tn-metric-card">
      <div class="tn-metric-icon tn-icon-amber">
        <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="8" r="7"></circle><polyline points="8.21 13.89 7 23 12 20 17 23 15.79 13.88"></polyline></svg>
      </div>
      <div class="tn-metric-info">
        <div class="tn-metric-label">Dünya Sıralaması</div>
        <div class="tn-metric-val">18. Sıra</div>
        <div class="tn-metric-sub">237 ülke & bölge arasında</div>
      </div>
    </div>

    <!-- 4. Dünya Payı -->
    <div class="tn-metric-card">
      <div class="tn-metric-icon tn-icon-blue">
        <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"></path></svg>
      </div>
      <div class="tn-metric-info">
        <div class="tn-metric-label">Dünya Nüfusundaki Payı</div>
        <div class="tn-metric-val">%1,06</div>
        <div class="tn-metric-sub">8,3 milyarlık dünyada</div>
      </div>
    </div>

    <!-- 5. Nüfus Yoğunluğu -->
    <div class="tn-metric-card">
      <div class="tn-metric-icon tn-icon-purple">
        <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect><line x1="9" y1="3" x2="9" y2="21"></line><line x1="15" y1="3" x2="15" y2="21"></line><line x1="3" y1="9" x2="21" y2="9"></line><line x1="3" y1="15" x2="21" y2="15"></line></svg>
      </div>
      <div class="tn-metric-info">
        <div class="tn-metric-label">Nüfus Yoğunluğu</div>
        <div class="tn-metric-val">114 Kişi / km²</div>
        <div class="tn-metric-sub">Mil kare başına 296 kişi</div>
      </div>
    </div>

    <!-- 6. Kara Alanı -->
    <div class="tn-metric-card">
      <div class="tn-metric-icon tn-icon-indigo">
        <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="1 6 1 22 8 18 16 22 23 18 23 2 16 6 8 2 1 6"></polygon><line x1="8" y1="2" x2="8" y2="18"></line><line x1="16" y1="6" x2="16" y2="22"></line></svg>
      </div>
      <div class="tn-metric-info">
        <div class="tn-metric-label">Toplam Kara Alanı</div>
        <div class="tn-metric-val">769.630 km²</div>
        <div class="tn-metric-sub">297.156 mil kare</div>
      </div>
    </div>

    <!-- 7. Kentsel Nüfus -->
    <div class="tn-metric-card">
      <div class="tn-metric-icon tn-icon-teal">
        <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 21h18"></path><path d="M5 21V7l8-4v18"></path><path d="M19 21V11l-6-4"></path><path d="M9 9h1"></path><path d="M9 13h1"></path><path d="M9 17h1"></path></svg>
      </div>
      <div class="tn-metric-info">
        <div class="tn-metric-label">Kentsel Nüfus Oranı</div>
        <div class="tn-metric-val">%77,5</div>
        <div class="tn-metric-sub">68.123.315 kişi şehirlerde</div>
      </div>
    </div>

    <!-- 8. Ortanca Yaş & Doğurganlık -->
    <div class="tn-metric-card">
      <div class="tn-metric-icon tn-icon-orange">
        <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><polyline points="12 6 12 12 14 14"></polyline></svg>
      </div>
      <div class="tn-metric-info">
        <div class="tn-metric-label">Ortanca Yaş / Doğurganlık</div>
        <div class="tn-metric-val">33,9 Yıl</div>
        <div class="tn-metric-sub">TFR: 1,62 çocuk / kadın</div>
      </div>
    </div>
  </div>

  <!-- 5. İNTERAKTİF GRAFİK & DEMOGRAFİK GÖRSELLEŞTİRME -->
  <div class="tn-visual-grid">
    <!-- Sol: 1950 - 2026 Tarihsel Nüfus Grafiği -->
    <div class="tn-visual-card">
      <div class="tn-card-header">
        <div>
          <h3 class="tn-card-title">
            <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="#e11d48" stroke-width="2"><polyline points="22 12 18 12 15 21 9 3 6 12 2 12"></polyline></svg>
            Türkiye Nüfusunun Tarihsel Gelişimi (1950 - 2026)
          </h3>
          <p class="tn-card-subtitle">21 milyondan 88 milyona 76 yıllık nüfus artış seyri</p>
        </div>
      </div>

      <div class="tn-chart-container">
        <div class="tn-chart-tooltip" id="chartTooltip"></div>
        <svg class="tn-chart-svg" viewBox="0 0 800 240" preserveAspectRatio="none">
          <defs>
            <linearGradient id="tnAreaGrad" x1="0" y1="0" x2="0" y2="1">
              <stop offset="0%" stop-color="#e11d48" stop-opacity="0.35"/>
              <stop offset="100%" stop-color="#e11d48" stop-opacity="0.0"/>
            </linearGradient>
          </defs>

          <!-- Izgara Çizgileri -->
          <g class="tn-chart-grid">
            <line x1="40" y1="30" x2="780" y2="30"/>
            <line x1="40" y1="80" x2="780" y2="80"/>
            <line x1="40" y1="130" x2="780" y2="130"/>
            <line x1="40" y1="180" x2="780" y2="180"/>
          </g>

          <!-- SVG Alan Dolgusu -->
          <path class="tn-chart-area" d="M 50 195 L 140 183 L 230 162 L 320 137 L 410 109 L 500 85 L 590 63 L 680 43 L 760 35 L 760 205 L 50 205 Z" />

          <!-- SVG Çizgi -->
          <path class="tn-chart-line" d="M 50 195 L 140 183 L 230 162 L 320 137 L 410 109 L 500 85 L 590 63 L 680 43 L 760 35" />

          <!-- Veri Noktaları (Hoverable Dots) -->
          <g class="tn-chart-dots">
            <circle cx="50" cy="195" r="4.5" data-year="1950" data-pop="21.408.411"/>
            <circle cx="140" cy="183" r="4.5" data-year="1960" data-pop="28.329.898"/>
            <circle cx="230" cy="162" r="4.5" data-year="1970" data-pop="36.142.062"/>
            <circle cx="320" cy="137" r="4.5" data-year="1980" data-pop="45.362.486"/>
            <circle cx="410" cy="109" r="4.5" data-year="1990" data-pop="55.087.491"/>
            <circle cx="500" cy="85" r="4.5" data-year="2000" data-pop="64.113.547"/>
            <circle cx="590" cy="63" r="4.5" data-year="2010" data-pop="73.195.345"/>
            <circle cx="680" cy="43" r="4.5" data-year="2020" data-pop="84.680.273"/>
            <circle cx="760" cy="35" r="5.5" data-year="2026" data-pop="87.926.082"/>
          </g>

          <!-- Eksen Etiketleri -->
          <g class="tn-chart-labels">
            <text x="50" y="225" text-anchor="middle">1950</text>
            <text x="140" y="225" text-anchor="middle">1960</text>
            <text x="230" y="225" text-anchor="middle">1970</text>
            <text x="320" y="225" text-anchor="middle">1980</text>
            <text x="410" y="225" text-anchor="middle">1990</text>
            <text x="500" y="225" text-anchor="middle">2000</text>
            <text x="590" y="225" text-anchor="middle">2010</text>
            <text x="680" y="225" text-anchor="middle">2020</text>
            <text x="760" y="225" text-anchor="middle" font-weight="bold" fill="#e11d48">2026</text>
          </g>
        </svg>
      </div>
    </div>

    <!-- Sağ: Demografik Dağılım Kartı -->
    <div class="tn-visual-card">
      <div class="tn-card-header">
        <div>
          <h3 class="tn-card-title">
            <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="#0ea5e9" stroke-width="2"><path d="M21.21 15.89A10 10 0 1 1 8 2.83"></path><path d="M22 12A10 10 0 0 0 12 2v10z"></path></svg>
            Demografik Yapı & Şehirleşme
          </h3>
          <p class="tn-card-subtitle">Kentsel vs Kırsal oran ve yaş dinamikleri</p>
        </div>
      </div>

      <div class="tn-demo-stack">
        <!-- Kentsel vs Kırsal -->
        <div>
          <div class="tn-demo-item-label">
            <span>Kentsel Nüfus (%77,5)</span>
            <span style="color: var(--text-muted);">Kırsal (%22,5)</span>
          </div>
          <div class="tn-progress-track">
            <div class="tn-progress-fill-urban" style="width: 77.5%;"></div>
            <div class="tn-progress-fill-rural" style="width: 22.5%;"></div>
          </div>
          <div style="display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--text-muted); margin-top: 0.25rem;">
            <span>68.123.315 Kişi</span>
            <span>19.802.767 Kişi</span>
          </div>
        </div>

        <!-- Ortanca Yaş Değişimi -->
        <div class="tn-stat-strip">
          <div>
            <div class="tn-stat-strip-title">Ortanca Yaş Eğilimi</div>
            <div style="font-size: 0.75rem; color: var(--text-muted);">1950: 19,8 yıl ➔ 2026: 33,9 yıl</div>
          </div>
          <div class="tn-stat-strip-val" style="color: #e11d48;">33,9 Yıl</div>
        </div>

        <!-- Doğurganlık Hızı -->
        <div class="tn-stat-strip">
          <div>
            <div class="tn-stat-strip-title">Toplam Doğurganlık Hızı (TFR)</div>
            <div style="font-size: 0.75rem; color: var(--text-muted);">Nüfus yenilenme eşiği: 2,10</div>
          </div>
          <div class="tn-stat-strip-val" style="color: #f59e0b;">1,62</div>
        </div>

        <!-- Zirve Nüfus Tahmini -->
        <div class="tn-stat-strip">
          <div>
            <div class="tn-stat-strip-title">Tahmini Zirve Nüfus (2045)</div>
            <div style="font-size: 0.75rem; color: var(--text-muted);">2045 yılında tepe noktası</div>
          </div>
          <div class="tn-stat-strip-val" style="color: #10b981;">91,39 Milyon</div>
        </div>
      </div>
    </div>
  </div>

  <!-- 6. VERİ TABLOLARI VE TAB GEÇİŞLERİ -->
  <div class="tn-tabs-container">
    <div class="tn-tabs-bar">
      <button class="tn-tab-btn active" data-target="tabCities">
        <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 21h18"></path><path d="M5 21V7l8-4v18"></path><path d="M19 21V11l-6-4"></path></svg>
        En Büyük Şehirler (70 Kentsel Alan)
      </button>

      <button class="tn-tab-btn" data-target="tabHistory">
        <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><polyline points="12 6 12 12 16 14"></polyline></svg>
        Tarihsel Nüfus (1950 - 2026)
      </button>

      <button class="tn-tab-btn" data-target="tabForecast">
        <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="23 6 13.5 15.5 8.5 10.5 1 18"></polyline><polyline points="17 6 23 6 23 12"></polyline></svg>
        Gelecek Projeksiyonları (2025 - 2050)
      </button>
    </div>

    <div class="tn-tab-content">

      <!-- TAB 1: ŞEHİRLER (70 Kentsel Alan) -->
      <div class="tn-tab-pane active" id="tabCities">
        <div class="tn-table-search-bar">
          <div class="tn-search-input-wrap">
            <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>
            <input type="text" id="citySearchInput" class="tn-search-input" placeholder="Şehir veya bölge ara (örn: İstanbul, İzmir, Bursa...)" autocomplete="off">
          </div>
          <div class="tn-table-count" id="cityFilteredCount">70 şehirden 70 tanesi gösteriliyor</div>
        </div>

        <div class="tn-table-wrap">
          <table class="tn-data-table">
            <thead>
              <tr>
                <th style="width: 70px;">Sıra</th>
                <th>Kentsel Alan / Şehir</th>
                <th>Tahmini Nüfus (2025)</th>
                <th>Türkiye Nüfusundaki Payı</th>
              </tr>
            </thead>
            <tbody id="cityTableBody">
              <?php 
              $cities = $cities_table['rows'] ?? [];
              $turkeyTotal = 87926082;
              foreach ($cities as $cRow): 
                $rank = $cRow[0] ?? '';
                $cityName = $cRow[1] ?? '';
                $popStr = $cRow[2] ?? '';
                $cleanNum = (float)str_replace('.', '', $popStr);
                $pct = $turkeyTotal > 0 ? round(($cleanNum / $turkeyTotal) * 100, 2) : 0;
                $rankClass = '';
                if ($rank == '1') $rankClass = 'tn-rank-top1';
                elseif ($rank == '2') $rankClass = 'tn-rank-top2';
                elseif ($rank == '3') $rankClass = 'tn-rank-top3';
              ?>
                <tr data-city="<?= htmlspecialchars(mb_strtolower($cityName, 'UTF-8')) ?>">
                  <td>
                    <span class="tn-rank-badge <?= $rankClass ?>">#<?= htmlspecialchars($rank) ?></span>
                  </td>
                  <td>
                    <strong><?= htmlspecialchars($cityName) ?></strong>
                  </td>
                  <td>
                    <strong style="color: var(--text-main);"><?= htmlspecialchars($popStr) ?></strong>
                  </td>
                  <td>
                    <div class="tn-city-bar-cell">
                      <div class="tn-city-pct-bar">
                        <div class="tn-city-pct-fill" style="width: <?= min(100, $pct * 5.5) ?>%;"></div>
                      </div>
                      <span style="font-size: 0.8rem; color: var(--text-muted); font-weight: 600;">%<?= number_format($pct, 2, ',', '.') ?></span>
                    </div>
                  </td>
                </tr>
              <?php endforeach; ?>
            </tbody>
          </table>
        </div>
      </div>

      <!-- TAB 2: TARİHSEL NÜFUS -->
      <div class="tn-tab-pane" id="tabHistory">
        <div class="tn-table-search-bar">
          <div>
            <strong style="font-size: 1.05rem; color: var(--text-main);">1950'den 2026'ya Türkiye Nüfusu</strong>
            <div style="font-size: 0.8rem; color: var(--text-muted);">Birleşmiş Milletler Nüfus Bölümü (UN DESA) resmi verileri</div>
          </div>
          <div class="tn-table-count">Toplam <?= count($history_table['rows'] ?? []) ?> dönem</div>
        </div>

        <div class="tn-table-wrap">
          <table class="tn-data-table">
            <thead>
              <tr>
                <?php foreach (($history_table['headers'] ?? []) as $th): ?>
                  <th><?= htmlspecialchars($th) ?></th>
                <?php endforeach; ?>
              </tr>
            </thead>
            <tbody>
              <?php foreach (($history_table['rows'] ?? []) as $rIndex => $row): ?>
                <?php $isHighlighted = ($row[0] === '2026' || $row[0] === '2025'); ?>
                <tr class="<?= $isHighlighted ? 'tn-highlight-row' : '' ?>">
                  <?php foreach ($row as $cIndex => $col): ?>
                    <td>
                      <?php if ($cIndex === 0 && $isHighlighted): ?>
                        <strong><?= htmlspecialchars($col) ?></strong>
                        <span style="font-size: 0.72rem; padding: 0.1rem 0.35rem; background: #e11d48; color: #fff; border-radius: 4px; margin-left: 0.3rem;">GÜNCEL</span>
                      <?php else: ?>
                        <?= htmlspecialchars($col) ?>
                      <?php endif; ?>
                    </td>
                  <?php endforeach; ?>
                </tr>
              <?php endforeach; ?>
            </tbody>
          </table>
        </div>
      </div>

      <!-- TAB 3: GELECEK TAHMİNLERİ (2025 - 2050) -->
      <div class="tn-tab-pane" id="tabForecast">
        <div class="tn-table-search-bar">
          <div>
            <strong style="font-size: 1.05rem; color: var(--text-main);">2025 - 2050 Nüfus Tahmini ve Projeksiyonları</strong>
            <div style="font-size: 0.8rem; color: var(--text-muted);">BM orta doğurganlık varyantı tahminleri (Zirve: 2045 yılında ~91,39 milyon)</div>
          </div>
          <div class="tn-table-count">Toplam <?= count($forecast_table['rows'] ?? []) ?> projeksiyon yılı</div>
        </div>

        <div class="tn-table-wrap">
          <table class="tn-data-table">
            <thead>
              <tr>
                <?php foreach (($forecast_table['headers'] ?? []) as $th): ?>
                  <th><?= htmlspecialchars($th) ?></th>
                <?php endforeach; ?>
              </tr>
            </thead>
            <tbody>
              <?php foreach (($forecast_table['rows'] ?? []) as $row): ?>
                <tr>
                  <?php foreach ($row as $cIndex => $col): ?>
                    <td>
                      <?php if ($cIndex === 0 && $col === '2045'): ?>
                        <strong><?= htmlspecialchars($col) ?></strong>
                        <span style="font-size: 0.72rem; padding: 0.1rem 0.35rem; background: #10b981; color: #fff; border-radius: 4px; margin-left: 0.3rem;">ZİRVE</span>
                      <?php else: ?>
                        <?= htmlspecialchars($col) ?>
                      <?php endif; ?>
                    </td>
                  <?php endforeach; ?>
                </tr>
              <?php endforeach; ?>
            </tbody>
          </table>
        </div>
      </div>

    </div>
  </div>

  <!-- 7. METODOLOJİ VE BİLGİ KARTI -->
  <div class="tn-info-card">
    <div class="tn-info-icon">
      <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>
    </div>
    <div class="tn-info-body">
      <h3>Worldometer & Birleşmiş Milletler Veri Metodolojisi</h3>
      <p>
        <strong>Canlı Nüfus Sayacı:</strong> Gösterilen anlık Türkiye nüfusu, Birleşmiş Milletler Ekonomik ve Sosyal İşler Dairesi (UN DESA) Nüfus Bölümü'nün en son yayınladığı <em>World Population Prospects</em> veri setine ve Türkiye İstatistik Kurumu (TÜİK) Adrese Dayalı Nüfus Kayıt Sistemi (ADNKS) eğilimlerine dayalı matematiksel üstel büyüme modeli ile gerçek zamanlı hesaplanmaktadır.
      </p>
      <p>
        <strong>Yıl Ortası Nüfusu:</strong> Nüfus biliminde uluslararası standart olarak her takvim yılının 1 Temmuz tarihi "yıl ortası nüfusu" olarak kabul edilir. Tarihsel ve tahmin tabloları bu standarda göre derlenmiştir.
      </p>
    </div>
  </div>

  <!-- 8. BAĞLANTI ŞERİDİ (NAV FOOTER) -->
  <div class="tn-nav-footer">
    <div>
      <span style="font-size: 0.88rem; color: var(--text-muted);">Küresel ölçekteki tüm canlı sayaçları incelemek ister misiniz?</span>
    </div>
    <div style="display: flex; gap: 0.75rem; flex-wrap: wrap;">
      <a href="dunya.php" class="tn-btn-primary">
        <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><line x1="2" y1="12" x2="22" y2="12"></line><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"></path></svg>
        Rakamlarla Dünya (Tüm İstatistikler)
      </a>
      <a href="haberler.php" class="tn-btn-outline">
        <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M19 20H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v12a2 2 0 0 0 2 2h0a2 2 0 0 0 2-2V8"></path></svg>
        Son Dakika Haberleri
      </a>
    </div>
  </div>

</div>

<?php
require_once __DIR__ . '/alt.php';
?>
