<!DOCTYPE html>
<html lang="tr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo isset($title) ? $title . ' | Yönetim Paneli' : 'Yönetim Paneli'; ?></title>
    
    <link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    
    <script src="https://cdn.tailwindcss.com"></script>
    <script>
        tailwind.config = {
            prefix: 'tw-',
            theme: {
                extend: {
                    fontFamily: { sans: ['"Plus Jakarta Sans"', 'sans-serif'] },
                    colors: {
                        sidebar: {
                            bg: '#0f172a',      // Çok koyu lacivert
                            hover: '#1e293b',   // Hover rengi
                            border: '#1e293b',  // Çizgi rengi
                            text: '#94a3b8',    // Açık gri yazı (Okunaklı)
                            active: '#2563eb'   // Yeni tema mavisi
                        },
                        body: '#f8fafc'         // Ferah açık arka plan
                    }
                }
            }
        }
    </script>

    <style>
        body { font-family: 'Plus Jakarta Sans', sans-serif; background-color: #f8fafc; }
        
        /* Sidebar Temel Ayarlar */
        .sidebar-wrapper {
            background-color: #0f172a; 
            color: #94a3b8;
        }

        /* Link Stilleri */
        .nav-link {
            display: flex; align-items: center;
            padding: 12px 16px; margin-bottom: 8px;
            color: #94a3b8; 
            font-weight: 600; font-size: 0.95rem;
            border-radius: 12px; transition: all 0.2s ease-in-out;
            text-decoration: none;
            border: 1px solid transparent;
        }
        
        /* Hover Durumu */
        .nav-link:hover { 
            background-color: rgba(255, 255, 255, 0.05); 
            color: #ffffff; 
            transform: translateX(4px);
        }

        /* Aktif Menü Durumu */
        .nav-link.active {
            background: #2563eb; /* Parlak Tema Mavisi */
            color: #ffffff;
            box-shadow: 0 4px 15px rgba(37, 99, 235, 0.4); 
            border-color: #2563eb;
        }
        
        .nav-link i { 
            width: 24px; text-align: center; margin-right: 12px; font-size: 1.1rem; opacity: 0.9;
        }
        
        /* Menü Başlıkları */
        .nav-title {
            font-size: 0.7rem; text-transform: uppercase; letter-spacing: 2px;
            color: #475569; font-weight: 800; margin: 28px 0 12px 16px;
        }

        /* Offcanvas Mobil Arkaplanı */
        .offcanvas-lg { background-color: #0f172a !important; }
        
        /* Scrollbar Özel (Sadece Webkit için) */
        ::-webkit-scrollbar { width: 6px; height: 6px; }
        ::-webkit-scrollbar-track { background: transparent; }
        ::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
        ::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
    </style>
</head>
<body class="tw-h-screen tw-flex tw-overflow-hidden tw-bg-body">

    <div class="tw-fixed tw-top-0 tw-left-0 tw-w-full tw-h-16 tw-bg-sidebar-bg tw-text-white tw-flex tw-items-center tw-justify-between tw-px-4 tw-z-50 d-lg-none tw-shadow-lg">
        <div class="d-flex align-items-center">
            <div class="tw-w-8 tw-h-8 tw-bg-blue-600 tw-rounded-lg tw-flex tw-items-center tw-justify-center tw-mr-3">
                <i class="fa-solid fa-building-user tw-text-white tw-text-sm"></i>
            </div>
            <span class="tw-font-bold tw-text-lg">Yönetim Paneli</span>
        </div>
        <button class="btn btn-outline-light tw-border-0" type="button" data-bs-toggle="offcanvas" data-bs-target="#sidebarMenu">
            <i class="fa-solid fa-bars tw-text-2xl"></i>
        </button>
    </div>

    <div class="offcanvas-lg offcanvas-start sidebar-wrapper tw-w-72 tw-flex-shrink-0 tw-border-r tw-border-sidebar-border tw-h-full tw-flex tw-flex-col" tabindex="-1" id="sidebarMenu">
        
        <div class="tw-h-24 tw-flex tw-items-center tw-px-6 tw-border-b tw-border-sidebar-border">
            <div class="tw-w-12 tw-h-12 tw-bg-gradient-to-br tw-from-blue-600 tw-to-indigo-700 tw-rounded-xl tw-flex tw-items-center tw-justify-center tw-text-white tw-mr-4 tw-shadow-lg tw-shadow-blue-500/30">
                <i class="fa-solid fa-building-user tw-text-xl"></i>
            </div>
            <div>
                <h5 class="tw-font-black tw-text-white tw-mb-0 tw-text-lg tw-tracking-tight">EMLAK PANEL</h5>
                <p class="tw-text-[10px] tw-font-bold tw-text-blue-500 tw-mt-1 tw-uppercase tw-tracking-widest">Yönetim Sistemi v2.0</p>
            </div>
            <button type="button" class="btn-close btn-close-white ms-auto d-lg-none" data-bs-dismiss="offcanvas"></button>
        </div>

        <div class="tw-flex-1 tw-overflow-y-auto tw-p-5">
            
            <div class="nav-title">GENEL BAKIŞ</div>
            <a href="<?php echo BASE_URL; ?>/admin/dashboard" class="nav-link <?php echo ($active == 'dashboard') ? 'active' : ''; ?>">
                <i class="fa-solid fa-chart-pie"></i> Dashboard
            </a>
            <a href="<?php echo BASE_URL; ?>/admin/messages" class="nav-link <?php echo ($active == 'messages') ? 'active' : ''; ?>">
                <i class="fa-solid fa-envelope"></i> Mesajlar
                <span class="tw-ml-auto tw-bg-red-500 tw-text-white tw-text-[10px] tw-font-bold tw-px-2 tw-py-0.5 tw-rounded-full">Yeni</span>
            </a>

            <div class="nav-title">PORTFÖY YÖNETİMİ</div>
            <a href="<?php echo BASE_URL; ?>/admin/properties" class="nav-link <?php echo ($active == 'properties') ? 'active' : ''; ?>">
                <i class="fa-solid fa-house"></i> İlanlar
            </a>
            <a href="<?php echo BASE_URL; ?>/admin/property-import" class="nav-link <?php echo ($active == 'property-import') ? 'active' : ''; ?>">
                <i class="fa-solid fa-file-csv"></i> CSV İçe Aktar
            </a>
            <?php if (isset($_SESSION['role']) && $_SESSION['role'] === 'admin'): ?>
            <a href="<?php echo BASE_URL; ?>/admin/categories" class="nav-link <?php echo ($active == 'categories') ? 'active' : ''; ?>">
                <i class="fa-solid fa-tags"></i> Kategoriler
            </a>
            <?php endif; ?>
            <a href="<?php echo BASE_URL; ?>/admin/projects" class="nav-link <?php echo ($active == 'projects') ? 'active' : ''; ?>">
                <i class="fa-solid fa-city"></i> Projeler
            </a>

            <div class="nav-title">SİSTEM & AYARLAR</div>
            <?php if (isset($_SESSION['role']) && $_SESSION['role'] === 'admin'): ?>
            <a href="<?php echo BASE_URL; ?>/admin/users" class="nav-link <?php echo ($active == 'users') ? 'active' : ''; ?>">
                <i class="fa-solid fa-users"></i> Danışmanlar
            </a>
            <a href="<?php echo BASE_URL; ?>/admin/settings" class="nav-link <?php echo ($active == 'settings') ? 'active' : ''; ?>">
                <i class="fa-solid fa-sliders"></i> Site Ayarları
            </a>
            <?php endif; ?>

        </div>
        
        <div class="tw-p-5 tw-border-t tw-border-sidebar-border tw-bg-black/10">
            <div class="tw-flex tw-items-center tw-gap-4">
                <img src="https://ui-avatars.com/api/?name=<?php echo urlencode($_SESSION['admin_name'] ?? 'Admin'); ?>&background=2563eb&color=fff" class="tw-w-10 tw-h-10 tw-rounded-xl tw-shadow-md">
                <div class="tw-flex-1 tw-overflow-hidden">
                    <div class="tw-text-sm tw-font-bold tw-text-white tw-truncate"><?php echo $_SESSION['admin_name'] ?? 'Yönetici'; ?></div>
                    <a href="<?php echo BASE_URL; ?>/admin/logout" class="tw-text-xs tw-font-medium tw-text-red-400 hover:tw-text-red-300 hover:tw-underline tw-transition-colors">Çıkış Yap</a>
                </div>
            </div>
        </div>
    </div>

    <main class="tw-flex-1 tw-flex tw-flex-col tw-overflow-hidden tw-relative tw-pt-16 lg:tw-pt-0">
        
        <header class="tw-h-24 tw-hidden lg:tw-flex tw-items-center tw-justify-between tw-px-8 tw-bg-white/80 tw-backdrop-blur-md tw-border-b tw-border-gray-200 tw-z-30 tw-sticky tw-top-0">
            <div>
                <h2 class="tw-text-2xl tw-font-black tw-text-gray-900 tw-tracking-tight"><?php echo $title ?? 'Dashboard'; ?></h2>
                <p class="tw-text-sm tw-font-medium tw-text-gray-500 tw-mt-1 mb-0">Hoş geldiniz, sisteminiz sorunsuz çalışıyor.</p>
            </div>
            
            <div class="tw-flex tw-items-center tw-gap-4">
                <a href="<?php echo BASE_URL; ?>" target="_blank" class="btn tw-bg-gray-100 hover:tw-bg-gray-200 tw-text-gray-700 tw-font-bold tw-rounded-xl tw-px-5 tw-py-2.5 tw-transition-colors">
                    <i class="fa-solid fa-arrow-up-right-from-square tw-mr-2"></i> Siteyi Gör
                </a>
                <a href="<?php echo BASE_URL; ?>/admin/profile" class="btn tw-bg-blue-600 hover:tw-bg-blue-700 tw-text-white tw-font-bold tw-rounded-xl tw-px-5 tw-py-2.5 tw-shadow-md tw-shadow-blue-500/20 tw-transition-all hover:tw--translate-y-0.5">
                    <i class="fa-solid fa-user tw-mr-2"></i> Profilim
                </a>
            </div>
        </header>

        <div class="tw-flex-1 tw-overflow-y-auto tw-p-6 md:tw-p-8 tw-bg-[#f8fafc]">
            <div class="tw-max-w-[1600px] tw-mx-auto">
                <?php 
                    if (isset($viewContent)) {
                        require_once $viewContent;
                    } else {
                        echo '<div class="alert alert-danger shadow-sm border-0 rounded-4 fw-bold p-4">Hata: İlgili sayfa içeriği bulunamadı.</div>';
                    }
                ?>
            </div>
            
            <footer class="tw-mt-12 tw-text-center tw-text-gray-400 tw-text-sm tw-font-medium tw-py-6">
                &copy; <?php echo date('Y'); ?> Emlak Yönetim Paneli - Tüm hakları saklıdır.
            </footer>
        </div>

    </main>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>

</body>
</html>