<?php
/**
 * admin/includes/admin_header.php
 * শুধু HTML/CSS/JS output করে।
 * require_once এবং requireAdmin() এখানে নেই —
 * সেটা প্রতিটি page নিজে admin_bootstrap.php দিয়ে করে।
 */
if (!defined('IN_ADMIN')) {
    // Direct access থেকে রক্ষা
    require_once __DIR__ . '/admin_bootstrap.php';
}

$settings         = isset($settings) ? $settings : getAllSettings($pdo);
$siteName         = $settings['site_name'] ?? 'বাংলা শপ';
$adminName        = $_SESSION['user_name'] ?? 'Admin';
$currentAdminPage = basename($_SERVER['PHP_SELF']);

$pendingCount   = (int)$pdo->query("SELECT COUNT(*) FROM orders  WHERE status='pending'")->fetchColumn();
$pendingReviews = (int)$pdo->query("SELECT COUNT(*) FROM reviews WHERE status='pending'")->fetchColumn();

$navItems = [
    ['section'=>'প্রধান'],
    ['icon'=>'fa-tachometer-alt','label'=>'ড্যাশবোর্ড',    'file'=>'index.php',      'href'=>BASE_URL.'/admin/index.php'],
    ['section'=>'পণ্য'],
    ['icon'=>'fa-box',           'label'=>'পণ্যসমূহ',       'file'=>'products.php',   'href'=>BASE_URL.'/admin/products.php'],
    ['icon'=>'fa-tags',          'label'=>'ক্যাটেগরি',      'file'=>'categories.php', 'href'=>BASE_URL.'/admin/categories.php'],
    ['icon'=>'fa-warehouse',     'label'=>'স্টক ম্যানেজার', 'file'=>'stock.php',      'href'=>BASE_URL.'/admin/stock.php'],
    ['section'=>'বিক্রয়'],
    ['icon'=>'fa-shopping-cart', 'label'=>'অর্ডার',         'file'=>'orders.php',     'href'=>BASE_URL.'/admin/orders.php',  'badge'=>$pendingCount],
    ['icon'=>'fa-star',          'label'=>'রিভিউ',          'file'=>'reviews.php',    'href'=>BASE_URL.'/admin/reviews.php', 'badge'=>$pendingReviews],
    ['section'=>'অর্থায়ন'],
    ['icon'=>'fa-user-tie',      'label'=>'ইনভেস্টর',       'file'=>'investors.php',  'href'=>BASE_URL.'/admin/investors.php'],
    ['icon'=>'fa-file-invoice-dollar','label'=>'ব্যয়সমূহ', 'file'=>'expenses.php',   'href'=>BASE_URL.'/admin/expenses.php'],
    ['section'=>'সেটিংস'],
    ['icon'=>'fa-image',         'label'=>'ব্যানার',         'file'=>'banner.php',     'href'=>BASE_URL.'/admin/banner.php'],
    ['icon'=>'fa-bars',          'label'=>'মেনু',            'file'=>'menus.php',      'href'=>BASE_URL.'/admin/menus.php'],
    ['icon'=>'fa-cog',           'label'=>'সাইট সেটিংস',   'file'=>'settings.php',   'href'=>BASE_URL.'/admin/settings.php'],
];
?>
<!DOCTYPE html>
<html lang="bn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#111d37">
<title>অ্যাডমিন — <?= e($siteName) ?></title>
<link href="https://fonts.googleapis.com/css2?family=Hind+Siliguri:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
<style>
:root{
  --navy:#1A2A4F;--navy-light:#243560;--navy-dark:#111d37;
  --gold:#D4AF37;--gold-light:#e8c84e;--gold-dark:#b8932a;
  --white:#fff;--g100:#f3f2ef;--g200:#e8e6e1;
  --g400:#a09d96;--g600:#6b6860;--g800:#3a3835;
  --danger:#e53e3e;--success:#38a169;--warning:#d69e2e;
  --r:8px;--sh:0 2px 12px rgba(26,42,79,.09);
  --sh-md:0 4px 24px rgba(26,42,79,.14);
  --font:'Hind Siliguri',sans-serif;
  --sidebar-w:240px;--topbar-h:56px;
}
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
html{font-size:15px}
body{font-family:var(--font);background:var(--g100);color:var(--g800);min-height:100vh}
a{color:inherit;text-decoration:none}img{max-width:100%;height:auto;display:block}
/* OVERLAY */
.sidebar-overlay{display:none;position:fixed;inset:0;background:rgba(0,0,0,.55);z-index:199;backdrop-filter:blur(2px)}
.sidebar-overlay.open{display:block}
/* SIDEBAR */
.admin-sidebar{width:var(--sidebar-w);background:var(--navy-dark);display:flex;flex-direction:column;position:fixed;top:0;left:0;bottom:0;overflow-y:auto;overflow-x:hidden;z-index:200;transition:transform .28s ease;scrollbar-width:thin;scrollbar-color:rgba(255,255,255,.1) transparent}
@media(max-width:900px){.admin-sidebar{transform:translateX(-100%)}.admin-sidebar.open{transform:translateX(0)}}
.sidebar-brand{padding:18px 20px 14px;border-bottom:1px solid rgba(255,255,255,.08);flex-shrink:0}
.sidebar-brand .brand-name{font-size:1.1rem;font-weight:700;color:var(--gold);display:block}
.sidebar-brand .brand-sub{font-size:.72rem;color:rgba(255,255,255,.35);margin-top:2px}
.sidebar-section{padding:10px 0 4px}
.sidebar-section-title{font-size:.65rem;font-weight:700;color:rgba(255,255,255,.28);letter-spacing:1.6px;text-transform:uppercase;padding:0 20px 6px}
.sidebar-link{display:flex;align-items:center;gap:10px;padding:10px 20px;color:rgba(255,255,255,.62);font-size:.87rem;font-weight:500;transition:all .2s;border-left:3px solid transparent;position:relative}
.sidebar-link:hover,.sidebar-link.active{color:var(--gold);background:rgba(212,175,55,.08);border-left-color:var(--gold)}
.sidebar-link i{width:17px;text-align:center;font-size:.88rem;flex-shrink:0}
.nav-badge{margin-left:auto;background:var(--danger);color:#fff;font-size:.65rem;font-weight:700;min-width:18px;height:18px;border-radius:50px;display:flex;align-items:center;justify-content:center;padding:0 5px}
.sidebar-bottom{margin-top:auto;padding:14px 16px;border-top:1px solid rgba(255,255,255,.08);flex-shrink:0}
.sidebar-user{display:flex;align-items:center;gap:10px;color:rgba(255,255,255,.7);font-size:.84rem}
.sidebar-avatar{width:32px;height:32px;background:var(--gold);border-radius:50%;display:flex;align-items:center;justify-content:center;font-weight:700;color:var(--navy);font-size:.88rem;flex-shrink:0}
/* TOPBAR */
.admin-topbar{height:var(--topbar-h);background:#fff;display:flex;align-items:center;padding:0 16px;gap:12px;box-shadow:var(--sh);position:sticky;top:0;z-index:100}
.topbar-menu-btn{width:36px;height:36px;border:none;background:var(--g100);border-radius:var(--r);cursor:pointer;display:flex;align-items:center;justify-content:center;font-size:1rem;color:var(--navy);transition:all .2s;flex-shrink:0}
.topbar-menu-btn:hover{background:var(--navy);color:var(--gold)}
@media(min-width:901px){.topbar-menu-btn{display:none}}
.topbar-title{font-size:1.05rem;font-weight:700;color:var(--navy);flex:1;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}
.topbar-actions{display:flex;align-items:center;gap:8px;flex-shrink:0}
.topbar-btn{display:inline-flex;align-items:center;gap:5px;padding:6px 12px;border-radius:var(--r);font-family:var(--font);font-size:.82rem;font-weight:600;cursor:pointer;border:none;transition:all .2s;text-decoration:none;white-space:nowrap}
@media(max-width:480px){.topbar-btn .btn-label{display:none}}
.btn-navy{background:var(--navy);color:var(--gold)}.btn-navy:hover{background:var(--navy-light)}
.btn-gold{background:var(--gold);color:var(--navy)}.btn-gold:hover{background:var(--gold-light)}
.btn-red{background:var(--danger);color:#fff}.btn-red:hover{opacity:.85}
.btn-green{background:var(--success);color:#fff}.btn-green:hover{opacity:.85}
.btn-gray{background:var(--g200);color:var(--g800)}.btn-gray:hover{background:var(--g400);color:#fff}
/* LAYOUT */
.admin-wrapper{display:flex;min-height:100vh}
.admin-main{flex:1;display:flex;flex-direction:column;min-width:0;margin-left:var(--sidebar-w);transition:margin-left .28s ease}
@media(max-width:900px){.admin-main{margin-left:0}}
.admin-content{padding:20px 16px 40px;flex:1}
@media(min-width:600px){.admin-content{padding:24px 24px 48px}}
/* ADMIN FOOTER */
.admin-footer{background:var(--navy-dark);color:rgba(255,255,255,.4);text-align:center;font-size:.78rem;padding:16px;border-top:1px solid rgba(255,255,255,.06)}
.admin-footer a{color:var(--gold);margin:0 8px}
/* CARDS */
.card{background:#fff;border-radius:var(--r);box-shadow:var(--sh);margin-bottom:20px}
.card-header{padding:14px 18px;border-bottom:1px solid var(--g100);display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:10px}
.card-header h3{font-size:1rem;font-weight:700;color:var(--navy)}
.card-body{padding:18px}
/* STATS */
.stats-grid{display:grid;grid-template-columns:1fr 1fr;gap:14px;margin-bottom:20px}
@media(min-width:700px){.stats-grid{grid-template-columns:repeat(4,1fr)}}
.stat-card{background:#fff;border-radius:var(--r);padding:16px;box-shadow:var(--sh);border-left:4px solid var(--gold);display:flex;align-items:center;gap:14px}
.stat-icon{font-size:1.6rem;color:var(--gold);flex-shrink:0}
.stat-info .stat-value{font-size:1.4rem;font-weight:700;color:var(--navy)}
@media(min-width:600px){.stat-info .stat-value{font-size:1.6rem}}
.stat-info .stat-label{font-size:.78rem;color:var(--g600);margin-top:2px}
/* TABLE */
.table-wrap{overflow-x:auto;-webkit-overflow-scrolling:touch}
table{width:100%;border-collapse:collapse;font-size:.85rem;min-width:480px}
th{background:var(--navy);color:#fff;padding:10px 12px;text-align:left;font-weight:600;white-space:nowrap}
td{padding:10px 12px;border-bottom:1px solid var(--g100);vertical-align:middle}
tr:hover td{background:rgba(26,42,79,.02)}
.actions{display:flex;gap:6px;flex-wrap:wrap}
/* FORM */
.form-grid{display:grid;grid-template-columns:1fr;gap:16px}
@media(min-width:600px){.form-grid{grid-template-columns:1fr 1fr}}
.form-grid-3{display:grid;grid-template-columns:1fr;gap:16px}
@media(min-width:600px){.form-grid-3{grid-template-columns:1fr 1fr}}
@media(min-width:900px){.form-grid-3{grid-template-columns:1fr 1fr 1fr}}
.form-full{grid-column:1/-1}
.form-group{margin-bottom:16px}
.form-label{display:block;font-size:.86rem;font-weight:600;color:var(--navy);margin-bottom:5px}
.form-control{width:100%;padding:9px 12px;border:1.5px solid var(--g200);border-radius:var(--r);font-family:var(--font);font-size:.9rem;color:var(--g800);outline:none;transition:all .2s;background:#fff}
.form-control:focus{border-color:var(--gold);box-shadow:0 0 0 3px rgba(212,175,55,.12)}
.form-hint{font-size:.75rem;color:var(--g400);margin-top:4px}
.form-check{display:flex;align-items:center;gap:8px;margin-top:6px}
.form-check input[type=checkbox]{width:16px;height:16px;accent-color:var(--gold)}
/* ALERTS */
.alert{padding:11px 14px;border-radius:var(--r);margin-bottom:14px;font-size:.88rem;display:flex;align-items:center;gap:8px;flex-wrap:wrap}
.alert-success{background:rgba(56,161,105,.1);color:#276749;border:1px solid rgba(56,161,105,.25)}
.alert-error{background:rgba(229,62,62,.1);color:#c53030;border:1px solid rgba(229,62,62,.2)}
.alert-warning{background:rgba(214,158,46,.12);color:#975a16;border:1px solid rgba(214,158,46,.25)}
/* BADGES */
.badge{display:inline-block;padding:2px 9px;border-radius:50px;font-size:.73rem;font-weight:700}
.badge-pending{background:rgba(214,158,46,.15);color:var(--warning)}
.badge-processing{background:rgba(49,130,206,.15);color:#3182ce}
.badge-shipped{background:rgba(56,161,105,.12);color:var(--success)}
.badge-delivered{background:rgba(56,161,105,.2);color:#276749}
.badge-cancelled{background:rgba(229,62,62,.12);color:var(--danger)}
.badge-approved{background:rgba(56,161,105,.15);color:var(--success)}
.badge-rejected{background:rgba(229,62,62,.12);color:var(--danger)}
.badge-active{background:rgba(56,161,105,.15);color:var(--success)}
.badge-inactive{background:rgba(229,62,62,.12);color:var(--danger)}
/* MISC */
.variation-row{display:grid;grid-template-columns:1fr 1fr auto;gap:10px;align-items:end;margin-bottom:10px}
@media(min-width:600px){.variation-row{grid-template-columns:1fr 1fr 1fr auto}}
.btn-icon{width:32px;height:32px;border:none;border-radius:var(--r);cursor:pointer;display:flex;align-items:center;justify-content:center;font-size:.85rem;transition:all .2s}
.stock-low{color:var(--danger);font-weight:700}.stock-ok{color:var(--success);font-weight:700}
.thumb{width:42px;height:42px;object-fit:cover;border-radius:6px;background:var(--g100)}
.thumb-placeholder{width:42px;height:42px;background:var(--g100);border-radius:6px;display:flex;align-items:center;justify-content:center;color:var(--g400);font-size:1rem}
.toggle-switch{position:relative;width:44px;height:24px;display:inline-block}
.toggle-switch input{opacity:0;width:0;height:0}
.toggle-slider{position:absolute;inset:0;background:var(--g200);border-radius:50px;cursor:pointer;transition:.3s}
.toggle-slider:before{content:'';position:absolute;width:18px;height:18px;left:3px;bottom:3px;background:#fff;border-radius:50%;transition:.3s}
.toggle-switch input:checked+.toggle-slider{background:var(--success)}
.toggle-switch input:checked+.toggle-slider:before{transform:translateX(20px)}
.progress-bar-wrap{background:var(--g200);border-radius:50px;height:9px;overflow:hidden;min-width:70px}
.progress-bar{background:var(--gold);height:100%;border-radius:50px;transition:width .4s ease}
.share-table td{vertical-align:middle}
h2{font-size:1.2rem;font-weight:700;color:var(--navy);margin-bottom:18px}
@media(min-width:600px){h2{font-size:1.4rem}}
</style>
</head>
<body>
<div class="admin-wrapper">
<div class="sidebar-overlay" id="sidebarOverlay"></div>
<aside class="admin-sidebar" id="adminSidebar">
    <div class="sidebar-brand">
        <span class="brand-name"><?= e($siteName) ?></span>
        <span class="brand-sub">অ্যাডমিন প্যানেল</span>
    </div>
    <?php
    $inSection = false;
    foreach ($navItems as $item):
        if (isset($item['section'])):
            if ($inSection) echo '</div>';
            $inSection = true;
    ?>
        <div class="sidebar-section">
            <div class="sidebar-section-title"><?= $item['section'] ?></div>
    <?php else: ?>
        <a href="<?= $item['href'] ?>"
           class="sidebar-link <?= $currentAdminPage===$item['file']?'active':'' ?>">
            <i class="fas <?= $item['icon'] ?>"></i>
            <?= $item['label'] ?>
            <?php if (!empty($item['badge']) && $item['badge']>0): ?>
                <span class="nav-badge"><?= $item['badge'] ?></span>
            <?php endif; ?>
        </a>
    <?php endif; endforeach;
    if ($inSection) echo '</div>'; ?>
    <div class="sidebar-bottom">
        <div class="sidebar-user">
            <div class="sidebar-avatar"><?= mb_substr($adminName,0,1) ?></div>
            <div style="min-width:0;">
                <div style="font-weight:600;color:#fff;font-size:.84rem;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;"><?= e($adminName) ?></div>
                <a href="<?= BASE_URL ?>/logout.php" style="font-size:.73rem;color:rgba(255,255,255,.38);">লগআউট</a>
            </div>
        </div>
    </div>
</aside>
<div class="admin-main">
<div class="admin-topbar">
    <button class="topbar-menu-btn" id="sidebarToggle" aria-label="মেনু"><i class="fas fa-bars"></i></button>
    <div class="topbar-title" id="pageTitle">অ্যাডমিন</div>
    <div class="topbar-actions">
        <a href="<?= BASE_URL ?>/index.php" target="_blank" class="topbar-btn btn-gray">
            <i class="fas fa-external-link-alt"></i><span class="btn-label"> সাইট</span>
        </a>
        <a href="<?= BASE_URL ?>/logout.php" class="topbar-btn btn-red">
            <i class="fas fa-sign-out-alt"></i><span class="btn-label"> লগআউট</span>
        </a>
    </div>
</div>
<div class="admin-content">
