<?php
/**
 * SMM Paket Satış Scripti - Admin Panel Header
 * iyzico Ayarları + Popup Yönetimi + Telegram Bildirim + Destek + Bildirimler + Fake Bildirimler + Kayan Yazı
 * @version 2.8.0
 */

// Config dahil et
if (!defined('SITE_VERSION')) {
    require_once __DIR__ . '/../config.php';
}

// Admin kontrolü
if (!isLoggedIn() || !isAdmin()) {
    setFlash('error', 'Bu sayfaya erişim yetkiniz yok.');
    redirect(SITE_URL . '/giris.php');
    exit;
}

// Null-safe helper
function adminSafeGet($settings, $key, $default = '') {
    $value = $settings->get($key, $default);
    return $value !== null ? $value : $default;
}

// Bekleyen sipariş sayısı
try {
    $pendingOrders = $db->query("SELECT COUNT(*) FROM orders WHERE status = 'pending'")->fetchColumn();
    $paidOrders = $db->query("SELECT COUNT(*) FROM orders WHERE status = 'paid'")->fetchColumn();
    $totalPending = $pendingOrders + $paidOrders;
} catch (PDOException $e) {
    $pendingOrders = 0;
    $paidOrders = 0;
    $totalPending = 0;
}

// Aktif kupon sayısı
try {
    $activeCoupons = $db->query("SELECT COUNT(*) FROM coupons WHERE is_active = 1 AND (expires_at IS NULL OR expires_at > NOW())")->fetchColumn();
} catch (PDOException $e) {
    $activeCoupons = 0;
}

// Aktif popup sayısı
try {
    $activePopups = $db->query("SELECT COUNT(*) FROM popups WHERE is_active = 1 AND (end_date IS NULL OR end_date > NOW())")->fetchColumn();
} catch (PDOException $e) {
    $activePopups = 0;
}

// Aktif bildirim sayısı
try {
    $activeNotifications = $db->query("SELECT COUNT(*) FROM notifications WHERE is_active = 1")->fetchColumn();
} catch (PDOException $e) {
    $activeNotifications = 0;
}

// Fake bildirim durumu
try {
    $fakeNotifActive = $db->query("SELECT is_active FROM fake_notification_settings WHERE id = 1")->fetchColumn();
} catch (PDOException $e) {
    $fakeNotifActive = 0;
}

// Kayan yazı durumu
try {
    $marqueeActive = $db->query("SELECT is_active FROM marquee_settings WHERE id = 1")->fetchColumn();
} catch (PDOException $e) {
    $marqueeActive = 0;
}

// Bekleyen destek talebi sayısı
try {
    $openTickets = $db->query("SELECT COUNT(*) FROM support_tickets WHERE status IN ('open', 'waiting')")->fetchColumn();
} catch (PDOException $e) {
    $openTickets = 0;
}

// API bakiye uyarısı
$lowBalanceWarning = false;
try {
    $apiBalance = $db->query("SELECT balance FROM api_providers WHERE status = 'active' ORDER BY balance ASC LIMIT 1")->fetchColumn();
    if ($apiBalance !== false && $apiBalance < 50) {
        $lowBalanceWarning = true;
    }
} catch (PDOException $e) {}

// iyzico durumu
$iyzicoEnabled = false;
try {
    $iyzicoEnabled = $settings->get('iyzico_enabled', '0') === '1';
} catch (Exception $e) {}

$adminPageTitle = isset($adminPageTitle) ? $adminPageTitle : 'Dashboard';
$currentPage = basename($_SERVER['PHP_SELF']);

// Admin menü grupları
$adminMenuGroups = [
    'main' => [
        'title' => '',
        'items' => [
            ['title' => 'Dashboard', 'url' => SITE_URL . '/admin/', 'icon' => 'fas fa-tachometer-alt', 'pages' => ['index.php']],
        ]
    ],
    'orders' => [
        'title' => 'Satış Yönetimi',
        'items' => [
            ['title' => 'Siparişler', 'url' => SITE_URL . '/admin/siparisler.php', 'icon' => 'fas fa-shopping-cart', 'pages' => ['siparisler.php', 'siparis-detay.php'], 'badge' => $totalPending > 0 ? $totalPending : null, 'badgeType' => 'danger'],
            ['title' => 'Paketler', 'url' => SITE_URL . '/admin/paketler.php', 'icon' => 'fas fa-box', 'pages' => ['paketler.php', 'paket-ekle.php', 'paket-duzenle.php']],
            ['title' => 'Kategoriler', 'url' => SITE_URL . '/admin/kategoriler.php', 'icon' => 'fas fa-folder', 'pages' => ['kategoriler.php']],
            ['title' => 'Kupon Kodları', 'url' => SITE_URL . '/admin/kuponlar.php', 'icon' => 'fas fa-ticket-alt', 'pages' => ['kuponlar.php', 'kupon-ekle.php', 'kupon-duzenle.php'], 'badge' => $activeCoupons > 0 ? $activeCoupons : null, 'badgeType' => 'success'],
        ]
    ],
    'support' => [
        'title' => 'Destek',
        'items' => [
            ['title' => 'Destek Talepleri', 'url' => SITE_URL . '/admin/destek-talepleri.php', 'icon' => 'fas fa-headset', 'pages' => ['destek-talepleri.php', 'destek-detay.php'], 'badge' => $openTickets > 0 ? $openTickets : null, 'badgeType' => 'warning'],
        ]
    ],
    'api' => [
        'title' => 'API Yönetimi',
        'items' => [
            ['title' => 'API Sağlayıcıları', 'url' => SITE_URL . '/admin/api-saglayicilar.php', 'icon' => 'fas fa-plug', 'pages' => ['api-saglayicilar.php', 'api-ekle.php', 'api-duzenle.php'], 'badge' => $lowBalanceWarning ? '!' : null, 'badgeType' => 'warning'],
        ]
    ],
    'users' => [
        'title' => 'Kullanıcılar',
        'items' => [
            ['title' => 'Kullanıcılar', 'url' => SITE_URL . '/admin/kullanicilar.php', 'icon' => 'fas fa-users', 'pages' => ['kullanicilar.php']],
        ]
    ],
    'finance' => [
        'title' => 'Finans',
        'items' => [
            ['title' => 'Banka Hesapları', 'url' => SITE_URL . '/admin/banka-hesaplari.php', 'icon' => 'fas fa-university', 'pages' => ['banka-hesaplari.php']],
            ['title' => 'iyzico Ayarları', 'url' => SITE_URL . '/admin/iyzico-ayarlari.php', 'icon' => 'fas fa-credit-card', 'pages' => ['iyzico-ayarlari.php'], 'badge' => $iyzicoEnabled ? 'Aktif' : null, 'badgeType' => 'success'],
        ]
    ],
    'content' => [
        'title' => 'İçerik',
        'items' => [
            ['title' => 'Kayan Yazı', 'url' => SITE_URL . '/admin/kayan-yazi.php', 'icon' => 'fas fa-text-width', 'pages' => ['kayan-yazi.php'], 'badge' => $marqueeActive ? 'Aktif' : null, 'badgeType' => 'success'],
            ['title' => 'Bildirimler', 'url' => SITE_URL . '/admin/bildirimler.php', 'icon' => 'fas fa-bell', 'pages' => ['bildirimler.php', 'bildirim-ekle.php', 'bildirim-duzenle.php'], 'badge' => $activeNotifications > 0 ? $activeNotifications : null, 'badgeType' => 'info'],
            ['title' => 'Fake Bildirimler', 'url' => SITE_URL . '/admin/fake-bildirimler.php', 'icon' => 'fas fa-comment-dots', 'pages' => ['fake-bildirimler.php'], 'badge' => $fakeNotifActive ? 'Aktif' : null, 'badgeType' => 'success'],
            ['title' => 'Popup Yönetimi', 'url' => SITE_URL . '/admin/popuplar.php', 'icon' => 'fas fa-window-restore', 'pages' => ['popuplar.php', 'popup-ekle.php', 'popup-duzenle.php'], 'badge' => $activePopups > 0 ? $activePopups : null, 'badgeType' => 'info'],
            ['title' => 'Sayfalar', 'url' => SITE_URL . '/admin/sayfalar.php', 'icon' => 'fas fa-file-alt', 'pages' => ['sayfalar.php']],
            ['title' => 'SSS', 'url' => SITE_URL . '/admin/sss.php', 'icon' => 'fas fa-question-circle', 'pages' => ['sss.php']],
        ]
    ],
    'settings' => [
        'title' => 'Ayarlar',
        'items' => [
            ['title' => 'Genel Ayarlar', 'url' => SITE_URL . '/admin/ayarlar.php', 'icon' => 'fas fa-cog', 'pages' => ['ayarlar.php']],
            ['title' => 'Tema Ayarları', 'url' => SITE_URL . '/admin/tema-ayarlari.php', 'icon' => 'fas fa-palette', 'pages' => ['tema-ayarlari.php']],
            ['title' => 'SMTP Ayarları', 'url' => SITE_URL . '/admin/smtp-ayarlari.php', 'icon' => 'fas fa-server', 'pages' => ['smtp-ayarlari.php']],
            ['title' => 'Telegram Bildirim', 'url' => SITE_URL . '/admin/telegram-ayarlari.php', 'icon' => 'fab fa-telegram', 'pages' => ['telegram-ayarlari.php']],
            ['title' => 'E-Posta Gönder', 'url' => SITE_URL . '/admin/eposta-gonder.php', 'icon' => 'fas fa-paper-plane', 'pages' => ['eposta-gonder.php']],
        ]
    ]
];

function isMenuActive($pages) {
    global $currentPage;
    return in_array($currentPage, $pages);
}

// Tema bilgisi
$themeColor = isset($theme['primary_color']) ? $theme['primary_color'] : '#6366f1';
$themeSecondary = isset($theme['secondary_color']) ? $theme['secondary_color'] : '#8b5cf6';

// hexToRgb fonksiyonu kontrolü
if (!function_exists('hexToRgb')) {
    function hexToRgb($hex) {
        $hex = ltrim($hex, '#');
        if (strlen($hex) == 3) {
            $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
        }
        $r = hexdec(substr($hex, 0, 2));
        $g = hexdec(substr($hex, 2, 2));
        $b = hexdec(substr($hex, 4, 2));
        return "$r, $g, $b";
    }
}
?>
<!DOCTYPE html>
<html lang="tr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, user-scalable=yes">
    <meta name="theme-color" content="#0f172a">
    <meta name="robots" content="noindex, nofollow">
    <title><?php echo clean($adminPageTitle); ?> - Admin | <?php echo clean(SITE_NAME); ?></title>
    
    <?php 
    $favicon = adminSafeGet($settings, 'site_favicon');
    if ($favicon): 
    ?>
    <link rel="icon" href="<?php echo SITE_URL . '/' . $favicon; ?>">
    <?php endif; ?>
    
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
    
    <style>
    :root {
        --primary: <?php echo $themeColor; ?>;
        --secondary: <?php echo $themeSecondary; ?>;
        --primary-rgb: <?php echo hexToRgb($themeColor); ?>;
        --secondary-rgb: <?php echo hexToRgb($themeSecondary); ?>;
        --gradient: linear-gradient(135deg, var(--primary), var(--secondary));
        --sidebar-width: 260px;
        --header-height: 65px;
        --bg-dark: #0f172a;
        --bg-darker: #0a0f1a;
        --bg-card: #1e293b;
        --bg-hover: #334155;
        --text-primary: #f8fafc;
        --text-secondary: #94a3b8;
        --text-muted: #64748b;
        --border-color: rgba(255,255,255,0.08);
        --success: #10b981;
        --warning: #f59e0b;
        --danger: #ef4444;
        --info: #3b82f6;
    }

    * { margin: 0; padding: 0; box-sizing: border-box; }

    body {
        font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
        background: var(--bg-dark);
        color: var(--text-primary);
        min-height: 100vh;
        overflow-x: hidden;
        line-height: 1.5;
    }

    a { text-decoration: none; color: inherit; }

    ::-webkit-scrollbar { width: 6px; height: 6px; }
    ::-webkit-scrollbar-track { background: transparent; }
    ::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 3px; }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: var(--sidebar-width);
        height: 100%;
        height: 100dvh;
        background: var(--bg-darker);
        border-right: 1px solid var(--border-color);
        z-index: 1000;
        display: flex;
        flex-direction: column;
        transition: transform 0.3s ease;
    }

    .sidebar-header {
        flex-shrink: 0;
        padding: 18px 20px;
        border-bottom: 1px solid var(--border-color);
        display: flex;
        align-items: center;
        justify-content: space-between;
        min-height: var(--header-height);
        background: rgba(0,0,0,0.2);
    }

    .sidebar-logo {
        display: flex;
        align-items: center;
        gap: 10px;
        font-size: 18px;
        font-weight: 800;
        color: #fff;
    }

    .sidebar-logo i { 
        font-size: 22px;
        color: var(--primary);
    }
    
    .sidebar-logo img { 
        height: 32px;
        object-fit: contain;
    }

    .sidebar-close {
        display: none;
        background: var(--bg-hover);
        border: none;
        color: var(--text-secondary);
        width: 36px;
        height: 36px;
        border-radius: 8px;
        font-size: 18px;
        cursor: pointer;
        align-items: center;
        justify-content: center;
    }

    .sidebar-close:hover {
        background: var(--danger);
        color: #fff;
    }

    .sidebar-nav {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        padding: 15px 12px;
        min-height: 0;
    }

    .nav-group {
        margin-bottom: 20px;
    }

    .nav-group:last-child {
        margin-bottom: 0;
    }

    .nav-group-title {
        font-size: 10px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 1px;
        color: var(--text-muted);
        padding: 0 12px;
        margin-bottom: 8px;
    }

    .nav-item { 
        margin-bottom: 2px; 
    }

    .nav-link {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 11px 14px;
        border-radius: 10px;
        color: var(--text-secondary);
        font-weight: 500;
        font-size: 14px;
        transition: all 0.2s ease;
        position: relative;
    }

    .nav-link:hover {
        background: var(--bg-hover);
        color: var(--text-primary);
    }

    .nav-link.active {
        background: rgba(var(--primary-rgb), 0.15);
        color: var(--primary);
    }

    .nav-link.active::before {
        content: '';
        position: absolute;
        left: 0;
        top: 50%;
        transform: translateY(-50%);
        width: 3px;
        height: 50%;
        background: var(--primary);
        border-radius: 0 3px 3px 0;
    }

    .nav-link i { 
        width: 20px; 
        text-align: center; 
        font-size: 15px;
        flex-shrink: 0;
    }

    .nav-link span:not(.badge) {
        flex: 1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .nav-link .badge {
        padding: 3px 8px;
        border-radius: 20px;
        font-size: 10px;
        font-weight: 700;
        flex-shrink: 0;
    }

    .nav-link .badge.badge-danger {
        background: var(--danger);
        color: #fff;
    }

    .nav-link .badge.badge-warning {
        background: var(--warning);
        color: #000;
    }

    .nav-link .badge.badge-success {
        background: var(--success);
        color: #fff;
    }

    .nav-link .badge.badge-info {
        background: var(--info);
        color: #fff;
    }

    .sidebar-footer {
        flex-shrink: 0;
        padding: 12px;
        border-top: 1px solid var(--border-color);
        background: rgba(0,0,0,0.2);
    }

    .sidebar-user {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 10px 12px;
        background: var(--bg-hover);
        border-radius: 10px;
    }

    .sidebar-avatar {
        width: 38px;
        height: 38px;
        background: var(--gradient);
        border-radius: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 700;
        color: #fff;
        font-size: 15px;
        flex-shrink: 0;
    }

    .sidebar-user-info {
        flex: 1;
        min-width: 0;
    }

    .sidebar-user-info h6 {
        font-size: 13px;
        font-weight: 600;
        margin: 0;
        color: var(--text-primary);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .sidebar-user-info span {
        font-size: 11px;
        color: var(--text-muted);
    }

    .sidebar-user-actions {
        display: flex;
        gap: 4px;
        flex-shrink: 0;
    }

    .sidebar-user-actions a {
        width: 30px;
        height: 30px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 6px;
        color: var(--text-muted);
        transition: all 0.2s;
        font-size: 13px;
    }

    .sidebar-user-actions a:hover {
        background: var(--bg-card);
        color: var(--text-primary);
    }

    .sidebar-user-actions a.logout:hover {
        background: rgba(239, 68, 68, 0.15);
        color: var(--danger);
    }

    .main {
        margin-left: var(--sidebar-width);
        min-height: 100vh;
        min-height: 100dvh;
        display: flex;
        flex-direction: column;
    }

    .header {
        height: var(--header-height);
        background: rgba(30, 41, 59, 0.95);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border-bottom: 1px solid var(--border-color);
        padding: 0 20px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        position: sticky;
        top: 0;
        z-index: 100;
        gap: 15px;
        flex-shrink: 0;
    }

    .header-left {
        display: flex;
        align-items: center;
        gap: 15px;
        flex: 1;
        min-width: 0;
    }

    .menu-toggle {
        display: none;
        background: var(--bg-hover);
        border: none;
        color: var(--text-primary);
        width: 40px;
        height: 40px;
        border-radius: 10px;
        font-size: 18px;
        cursor: pointer;
        flex-shrink: 0;
        align-items: center;
        justify-content: center;
    }

    .page-title {
        font-size: 18px;
        font-weight: 700;
        margin: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .header-right {
        display: flex;
        align-items: center;
        gap: 10px;
        flex-shrink: 0;
    }

    .header-btn {
        position: relative;
        width: 40px;
        height: 40px;
        background: var(--bg-hover);
        border: 1px solid var(--border-color);
        border-radius: 10px;
        color: var(--text-secondary);
        font-size: 16px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.2s;
    }

    .header-btn:hover {
        background: rgba(var(--primary-rgb), 0.15);
        border-color: rgba(var(--primary-rgb), 0.3);
        color: var(--primary);
    }

    .header-btn .badge {
        position: absolute;
        top: -4px;
        right: -4px;
        min-width: 18px;
        height: 18px;
        background: var(--danger);
        border-radius: 50%;
        font-size: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #fff;
        font-weight: 700;
        border: 2px solid var(--bg-card);
    }

    .header-btn.warning .badge {
        background: var(--warning);
        color: #000;
    }

    .btn-site {
        background: var(--gradient);
        color: #fff;
        border: none;
        padding: 10px 18px;
        border-radius: 10px;
        font-weight: 600;
        font-size: 13px;
        display: flex;
        align-items: center;
        gap: 8px;
        transition: all 0.2s;
        white-space: nowrap;
    }

    .btn-site:hover {
        transform: translateY(-2px);
        box-shadow: 0 5px 20px rgba(var(--primary-rgb), 0.4);
        color: #fff;
    }

    .content {
        flex: 1;
        padding: 20px;
    }

    .card {
        background: var(--bg-card);
        border: 1px solid var(--border-color);
        border-radius: 16px;
    }

    .card-header {
        padding: 18px 22px;
        border-bottom: 1px solid var(--border-color);
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 12px;
    }

    .card-title {
        font-size: 16px;
        font-weight: 600;
        margin: 0;
        display: flex;
        align-items: center;
        gap: 10px;
    }

    .card-title i { 
        color: var(--primary);
    }

    .card-body { padding: 22px; }

    .btn-primary-custom {
        background: var(--gradient);
        border: none;
        color: #fff;
        padding: 11px 22px;
        border-radius: 10px;
        font-weight: 600;
        font-size: 14px;
        display: inline-flex;
        align-items: center;
        gap: 8px;
        transition: all 0.2s;
        white-space: nowrap;
        cursor: pointer;
    }

    .btn-primary-custom:hover {
        transform: translateY(-2px);
        box-shadow: 0 5px 20px rgba(var(--primary-rgb), 0.4);
        color: #fff;
    }

    .btn-secondary-custom {
        background: var(--bg-hover);
        border: 1px solid var(--border-color);
        color: var(--text-primary);
        padding: 11px 22px;
        border-radius: 10px;
        font-weight: 600;
        font-size: 14px;
        display: inline-flex;
        align-items: center;
        gap: 8px;
        transition: all 0.2s;
        cursor: pointer;
    }

    .btn-secondary-custom:hover {
        background: var(--bg-card);
        color: var(--text-primary);
    }

    .btn-danger-custom {
        background: rgba(239, 68, 68, 0.15);
        border: 1px solid rgba(239, 68, 68, 0.3);
        color: var(--danger);
        padding: 11px 22px;
        border-radius: 10px;
        font-weight: 600;
        font-size: 14px;
        display: inline-flex;
        align-items: center;
        gap: 8px;
        cursor: pointer;
        transition: all 0.2s;
    }

    .btn-danger-custom:hover {
        background: var(--danger);
        color: #fff;
    }

    .btn-success-custom {
        background: rgba(16, 185, 129, 0.15);
        border: 1px solid rgba(16, 185, 129, 0.3);
        color: var(--success);
        padding: 11px 22px;
        border-radius: 10px;
        font-weight: 600;
        font-size: 14px;
        display: inline-flex;
        align-items: center;
        gap: 8px;
        cursor: pointer;
        transition: all 0.2s;
    }

    .btn-success-custom:hover {
        background: var(--success);
        color: #fff;
    }

    .btn-info-custom {
        background: rgba(59, 130, 246, 0.15);
        border: 1px solid rgba(59, 130, 246, 0.3);
        color: var(--info);
        padding: 11px 22px;
        border-radius: 10px;
        font-weight: 600;
        font-size: 14px;
        display: inline-flex;
        align-items: center;
        gap: 8px;
        cursor: pointer;
        transition: all 0.2s;
    }

    .btn-info-custom:hover {
        background: var(--info);
        color: #fff;
    }

    .btn-warning-custom {
        background: rgba(245, 158, 11, 0.15);
        border: 1px solid rgba(245, 158, 11, 0.3);
        color: var(--warning);
        padding: 11px 22px;
        border-radius: 10px;
        font-weight: 600;
        font-size: 14px;
        display: inline-flex;
        align-items: center;
        gap: 8px;
        cursor: pointer;
        transition: all 0.2s;
    }

    .btn-warning-custom:hover {
        background: var(--warning);
        color: #000;
    }

    .btn-sm {
        padding: 8px 16px;
        font-size: 13px;
    }

    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table {
        color: var(--text-primary);
        margin: 0;
        white-space: nowrap;
    }

    .table thead th {
        background: rgba(0,0,0,0.15);
        border-bottom: 1px solid var(--border-color);
        padding: 13px 16px;
        font-weight: 600;
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        color: var(--text-muted);
    }

    .table tbody td {
        padding: 14px 16px;
        border-bottom: 1px solid var(--border-color);
        vertical-align: middle;
    }

    .table tbody tr:hover { 
        background: rgba(var(--primary-rgb), 0.03); 
    }

    .table tbody tr:last-child td {
        border-bottom: none;
    }

    .form-label {
        font-weight: 600;
        color: var(--text-primary);
        margin-bottom: 8px;
        font-size: 14px;
    }

    .form-control, .form-select {
        background: var(--bg-dark);
        border: 1px solid var(--border-color);
        border-radius: 10px;
        padding: 12px 16px;
        color: var(--text-primary);
        font-size: 14px;
        transition: all 0.2s;
    }

    .form-control:focus, .form-select:focus {
        background: var(--bg-dark);
        border-color: var(--primary);
        box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.15);
        color: var(--text-primary);
        outline: none;
    }

    .form-control::placeholder { color: var(--text-muted); }

    .form-check-input {
        background-color: var(--bg-dark);
        border-color: var(--border-color);
    }

    .form-check-input:checked {
        background-color: var(--primary);
        border-color: var(--primary);
    }

    .form-check-input:focus {
        box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.15);
    }

    .status-badge {
        display: inline-flex;
        align-items: center;
        gap: 5px;
        padding: 5px 12px;
        border-radius: 20px;
        font-size: 11px;
        font-weight: 600;
    }

    .status-pending { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
    .status-paid { background: rgba(59, 130, 246, 0.15); color: #3b82f6; }
    .status-processing { background: rgba(139, 92, 246, 0.15); color: #8b5cf6; }
    .status-completed { background: rgba(16, 185, 129, 0.15); color: #10b981; }
    .status-cancelled { background: rgba(239, 68, 68, 0.15); color: #ef4444; }
    .status-refunded { background: rgba(107, 114, 128, 0.15); color: #6b7280; }
    .status-open { background: rgba(59, 130, 246, 0.15); color: #3b82f6; }
    .status-answered { background: rgba(16, 185, 129, 0.15); color: #10b981; }
    .status-waiting { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
    .status-closed { background: rgba(107, 114, 128, 0.15); color: #6b7280; }

    .alert {
        border: none;
        border-radius: 12px;
        padding: 14px 18px;
        font-size: 14px;
        display: flex;
        align-items: center;
        gap: 10px;
    }

    .alert-success { background: rgba(16, 185, 129, 0.15); color: #10b981; }
    .alert-danger { background: rgba(239, 68, 68, 0.15); color: #ef4444; }
    .alert-warning { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
    .alert-info { background: rgba(59, 130, 246, 0.15); color: #3b82f6; }

    .flash-container {
        position: fixed;
        top: 80px;
        right: 20px;
        z-index: 9999;
        max-width: calc(100% - 40px);
        width: 380px;
    }

    .dropdown-menu {
        background: var(--bg-card);
        border: 1px solid var(--border-color);
        border-radius: 12px;
        padding: 8px;
        box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    }

    .dropdown-item {
        color: var(--text-secondary);
        padding: 10px 14px;
        border-radius: 8px;
        font-size: 13px;
    }

    .dropdown-item:hover { 
        background: var(--bg-hover); 
        color: var(--text-primary); 
    }

    .dropdown-divider { border-color: var(--border-color); }

    .modal-content {
        background: var(--bg-card);
        border: 1px solid var(--border-color);
        border-radius: 16px;
        color: var(--text-primary);
    }

    .modal-header {
        border-bottom: 1px solid var(--border-color);
        padding: 18px 22px;
    }

    .modal-title {
        font-size: 17px;
        font-weight: 700;
        display: flex;
        align-items: center;
        gap: 10px;
    }

    .modal-title i { color: var(--primary); }
    .modal-body { padding: 22px; }
    .modal-footer { border-top: 1px solid var(--border-color); padding: 14px 22px; }

    .btn-close {
        filter: invert(1) grayscale(100%) brightness(200%);
        opacity: 0.5;
    }

    .btn-close:hover { opacity: 1; }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.6);
        z-index: 999;
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
    }

    .sidebar-overlay.show { display: block; }

    @media (max-width: 991px) {
        .sidebar {
            transform: translateX(-100%);
            width: 280px;
        }

        .sidebar.show {
            transform: translateX(0);
        }

        .sidebar-close { 
            display: flex; 
        }

        .main { margin-left: 0; }

        .menu-toggle { 
            display: flex; 
        }

        .btn-site span { display: none; }
        .btn-site { padding: 10px 12px; }

        .flash-container {
            top: 75px;
            right: 15px;
            left: 15px;
            width: auto;
        }
    }

    @media (max-width: 768px) {
        .header { 
            padding: 0 15px;
            height: 60px;
        }

        .content { padding: 15px; }
        
        .page-title { font-size: 16px; }
        
        .card-header {
            padding: 15px 18px;
        }

        .card-body { padding: 18px; }
    }

    @media (max-width: 576px) {
        .header-right {
            gap: 6px;
        }

        .header-btn {
            width: 36px;
            height: 36px;
            font-size: 14px;
        }

        .menu-toggle {
            width: 36px;
            height: 36px;
        }

        .btn-site {
            width: 36px;
            height: 36px;
            padding: 0;
            justify-content: center;
        }

        .btn-primary-custom, .btn-secondary-custom {
            padding: 10px 16px;
            font-size: 13px;
        }

        .card-header {
            flex-direction: column;
            align-items: flex-start;
        }
    }

    .text-truncate-2 {
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .text-muted { color: var(--text-muted) !important; }
    .text-primary { color: var(--primary) !important; }
    .text-success { color: var(--success) !important; }
    .text-warning { color: var(--warning) !important; }
    .text-danger { color: var(--danger) !important; }
    .text-info { color: var(--info) !important; }

    .empty-state {
        text-align: center;
        padding: 50px 20px;
    }

    .empty-state i {
        font-size: 50px;
        color: var(--text-muted);
        opacity: 0.3;
        margin-bottom: 15px;
    }

    .empty-state h4 {
        font-size: 18px;
        margin-bottom: 8px;
    }

    .empty-state p {
        color: var(--text-secondary);
        margin-bottom: 20px;
    }

    .form-text {
        color: var(--text-muted);
        font-size: 12px;
    }

    .input-group-text {
        background: var(--bg-hover);
        border: 1px solid var(--border-color);
        color: var(--text-secondary);
    }

    .nav-tabs {
        border-bottom: 1px solid var(--border-color);
    }

    .nav-tabs .nav-link {
        color: var(--text-secondary);
        border: none;
        padding: 12px 20px;
        font-weight: 500;
    }

    .nav-tabs .nav-link:hover {
        color: var(--text-primary);
        border: none;
    }

    .nav-tabs .nav-link.active {
        color: var(--primary);
        background: transparent;
        border: none;
        border-bottom: 2px solid var(--primary);
    }

    .tab-content {
        padding-top: 20px;
    }

    .badge-lg {
        padding: 6px 12px;
        font-size: 12px;
    }

    .avatar-sm {
        width: 32px;
        height: 32px;
        border-radius: 8px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 600;
        font-size: 12px;
    }

    .avatar-md {
        width: 40px;
        height: 40px;
        border-radius: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 600;
        font-size: 14px;
    }

    .avatar-lg {
        width: 50px;
        height: 50px;
        border-radius: 12px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 700;
        font-size: 18px;
    }
    </style>
</head>
<body>

<div class="sidebar-overlay" id="sidebarOverlay"></div>

<aside class="sidebar" id="sidebar">
    <div class="sidebar-header">
        <a href="<?php echo SITE_URL; ?>/admin/" class="sidebar-logo">
            <?php 
            $logo = adminSafeGet($settings, 'site_logo');
            if ($logo): 
            ?>
                <img src="<?php echo SITE_URL . '/' . $logo; ?>" alt="<?php echo clean(SITE_NAME); ?>">
            <?php else: ?>
                <i class="fas fa-bolt"></i>
                <span><?php echo clean(SITE_NAME); ?></span>
            <?php endif; ?>
        </a>
        <button class="sidebar-close" id="sidebarClose">
            <i class="fas fa-times"></i>
        </button>
    </div>

    <nav class="sidebar-nav">
        <?php foreach ($adminMenuGroups as $groupKey => $group): ?>
        <div class="nav-group">
            <?php if (!empty($group['title'])): ?>
            <div class="nav-group-title"><?php echo $group['title']; ?></div>
            <?php endif; ?>
            
            <?php foreach ($group['items'] as $item): ?>
            <div class="nav-item">
                <a href="<?php echo $item['url']; ?>" class="nav-link <?php echo isMenuActive($item['pages']) ? 'active' : ''; ?>">
                    <i class="<?php echo $item['icon']; ?>"></i>
                    <span><?php echo $item['title']; ?></span>
                    <?php if (!empty($item['badge'])): ?>
                        <span class="badge badge-<?php echo $item['badgeType'] ?? 'danger'; ?>"><?php echo $item['badge']; ?></span>
                    <?php endif; ?>
                </a>
            </div>
            <?php endforeach; ?>
        </div>
        <?php endforeach; ?>
    </nav>

    <div class="sidebar-footer">
        <div class="sidebar-user">
            <div class="sidebar-avatar">
                <?php echo strtoupper(mb_substr($_SESSION['user_name'] ?? 'A', 0, 1, 'UTF-8')); ?>
            </div>
            <div class="sidebar-user-info">
                <h6><?php echo clean($_SESSION['user_name'] ?? 'Admin'); ?></h6>
                <span>Yönetici</span>
            </div>
            <div class="sidebar-user-actions">
                <a href="<?php echo SITE_URL; ?>" target="_blank" title="Siteyi Gör">
                    <i class="fas fa-external-link-alt"></i>
                </a>
                <a href="<?php echo SITE_URL; ?>/admin/?cikis=1" class="logout" title="Çıkış">
                    <i class="fas fa-sign-out-alt"></i>
                </a>
            </div>
        </div>
    </div>
</aside>

<main class="main">
    <header class="header">
        <div class="header-left">
            <button class="menu-toggle" id="menuToggle">
                <i class="fas fa-bars"></i>
            </button>
            <h1 class="page-title"><?php echo clean($adminPageTitle); ?></h1>
        </div>
        
        <div class="header-right">
            <?php if ($lowBalanceWarning): ?>
            <a href="<?php echo SITE_URL; ?>/admin/api-saglayicilar.php" class="header-btn warning" title="Düşük API Bakiyesi!">
                <i class="fas fa-exclamation-triangle"></i>
                <span class="badge">!</span>
            </a>
            <?php endif; ?>
            
            <?php if ($openTickets > 0): ?>
            <a href="<?php echo SITE_URL; ?>/admin/destek-talepleri.php" class="header-btn warning" title="<?php echo $openTickets; ?> Bekleyen Destek Talebi">
                <i class="fas fa-headset"></i>
                <span class="badge"><?php echo $openTickets; ?></span>
            </a>
            <?php endif; ?>
            
            <?php if ($totalPending > 0): ?>
            <a href="<?php echo SITE_URL; ?>/admin/siparisler.php?status=pending" class="header-btn" title="<?php echo $pendingOrders; ?> Bekleyen, <?php echo $paidOrders; ?> Ödendi">
                <i class="fas fa-bell"></i>
                <span class="badge"><?php echo $totalPending; ?></span>
            </a>
            <?php endif; ?>
            
            <a href="<?php echo SITE_URL; ?>" target="_blank" class="btn-site" title="Siteyi Görüntüle">
                <i class="fas fa-external-link-alt"></i>
                <span>Siteyi Gör</span>
            </a>
        </div>
    </header>

    <?php if ($flash = getFlash()): ?>
    <div class="flash-container">
        <div class="alert alert-<?php echo $flash['type'] === 'error' ? 'danger' : $flash['type']; ?> alert-dismissible fade show">
            <i class="fas fa-<?php echo $flash['type'] === 'success' ? 'check-circle' : 'exclamation-circle'; ?>"></i>
            <span><?php echo $flash['message']; ?></span>
            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
        </div>
    </div>
    <?php endif; ?>

    <div class="content">