<?php
 //superadmin/includes/header.php
// Set $page_title and $active_nav before including

if (!isset($_SESSION)) session_start();
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'super_admin') {
    header("Location: login.php"); exit;
}

include_once("db.php");

$uid = (int)$_SESSION['user_id'];
$u_stmt = $conn->prepare("SELECT name,email FROM users WHERE id=? AND role='super_admin'");
$u_stmt->bind_param("i", $uid);
$u_stmt->execute();
$__user = $u_stmt->get_result()->fetch_assoc();
if (!$__user) { session_destroy(); header("Location: login.php"); exit; }

$__name     = $__user['name'];
$__email    = $__user['email'];
$__initials = strtoupper(substr($__name,0,1)) . (strpos($__name,' ')!==false ? strtoupper(substr(strrchr($__name,' '),1,1)) : '');

// Platform stats for topbar
$total_restaurants = $conn->query("SELECT COUNT(*) FROM restaurants WHERE status=1")->fetch_row()[0];
$pending_orders    = $conn->query("SELECT COUNT(*) FROM orders WHERE order_status='pending'")->fetch_row()[0];

// Unresolved customer feedback (support_messages is created by the customer panel migration)
$open_feedback = 0;
if ($__fb = @$conn->query("SELECT COUNT(*) FROM support_messages WHERE status='open'")) {
    $open_feedback = (int)$__fb->fetch_row()[0];
}

// Super admin wallet balance for topbar
$__wallet_row = $conn->query("SELECT balance FROM wallets WHERE user_id={$uid} AND wallet_type='super_admin' LIMIT 1")->fetch_row();
$__wallet_balance = $__wallet_row ? (float)$__wallet_row[0] : 0.00;

$__page_title = $page_title ?? 'Dashboard';
$__active     = $active_nav ?? 'dashboard';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo htmlspecialchars($__page_title); ?> — Dabil Admin</title>
<link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
<style>
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
:root{
  --primary:#225AE3;--primary-dark:#1a47b8;--primary-light:#4f79ea;
  --primary-bg:#EEF3FD;--bg:#F5F7F8;--white:#FFFFFF;
  --text:#0F172A;--text-muted:#64748B;--text-light:#94A3B8;
  --border:#E2E8F0;--border-dark:#CBD5E1;
  --success:#10B981;--success-bg:#F0FDF4;
  --error:#EF4444;--error-bg:#FEF2F2;
  --warning:#F59E0B;--warning-bg:#FFFBEB;
  --info:#06B6D4;--info-bg:#ECFEFF;
  --sidebar-w:262px;--topbar-h:64px;
  --radius:12px;--radius-lg:16px;
  --shadow-sm:0 1px 3px rgba(0,0,0,.07);
  --shadow-md:0 4px 16px rgba(0,0,0,.08);
  --shadow-lg:0 8px 30px rgba(34,90,227,.14);
  --font:'Plus Jakarta Sans',sans-serif;
}
body{font-family:var(--font);background:var(--bg);color:var(--text);min-height:100vh}
a{text-decoration:none;color:inherit}
button{font-family:var(--font)}

/* SIDEBAR */
.sidebar{position:fixed;top:0;left:0;width:var(--sidebar-w);height:100vh;background:var(--white);border-right:1px solid var(--border);display:flex;flex-direction:column;z-index:200;transition:transform .3s cubic-bezier(.4,0,.2,1)}
.sidebar-brand{padding:0 20px;height:var(--topbar-h);display:flex;align-items:center;gap:10px;border-bottom:1px solid var(--border);flex-shrink:0}
.brand-icon{width:36px;height:36px;background:var(--primary);border-radius:10px;display:flex;align-items:center;justify-content:center;flex-shrink:0}
.brand-icon svg{width:18px;height:18px;stroke:#fff;fill:none}
.brand-name{font-size:1.1rem;font-weight:800;letter-spacing:-0.02em;color:var(--primary)}
.brand-tag{font-size:.6rem;font-weight:700;text-transform:uppercase;letter-spacing:.1em;color:var(--white);background:var(--primary);padding:2px 7px;border-radius:20px;margin-left:auto}

.sidebar-scroll{flex:1;overflow-y:auto;padding:16px 12px}
.sidebar-scroll::-webkit-scrollbar{width:4px}
.sidebar-scroll::-webkit-scrollbar-thumb{background:var(--border);border-radius:4px}
.nav-section{margin-bottom:24px}
.nav-label{font-size:.65rem;font-weight:700;text-transform:uppercase;letter-spacing:.12em;color:var(--text-light);padding:0 12px;margin-bottom:6px}
.nav-item{display:flex;align-items:center;gap:10px;padding:10px 12px;border-radius:10px;cursor:pointer;transition:all .18s;color:var(--text-muted);font-size:.85rem;font-weight:500;margin-bottom:2px;position:relative}
.nav-item:hover{background:var(--bg);color:var(--text)}
.nav-item.active{background:var(--primary-bg);color:var(--primary);font-weight:700}
.nav-item.active::before{content:'';position:absolute;left:0;top:20%;bottom:20%;width:3px;background:var(--primary);border-radius:0 3px 3px 0;margin-left:-12px}
.nav-item svg{width:18px;height:18px;flex-shrink:0}
.nav-badge{margin-left:auto;background:var(--error);color:#fff;font-size:.65rem;padding:2px 7px;border-radius:20px;font-weight:700}
.nav-badge.blue{background:var(--primary)}
.nav-badge.green{background:var(--success)}

.sidebar-footer{border-top:1px solid var(--border);padding:16px 12px;flex-shrink:0}
/* Wallet pill in sidebar footer */
.wallet-pill{display:flex;align-items:center;gap:10px;padding:10px 12px;border-radius:10px;background:linear-gradient(135deg,#225AE3,#4f79ea);margin-bottom:10px;cursor:pointer;transition:opacity .2s}
.wallet-pill:hover{opacity:.9}
.wallet-pill-icon{width:32px;height:32px;border-radius:8px;background:rgba(255,255,255,.2);display:flex;align-items:center;justify-content:center;flex-shrink:0}
.wallet-pill-icon svg{width:15px;height:15px;stroke:#fff;fill:none}
.wallet-pill-info{flex:1;overflow:hidden}
.wallet-pill-label{font-size:.65rem;font-weight:600;color:rgba(255,255,255,.75);text-transform:uppercase;letter-spacing:.08em}
.wallet-pill-amount{font-size:.95rem;font-weight:800;color:#fff;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.user-pill{display:flex;align-items:center;gap:10px;padding:10px 12px;border-radius:10px;background:var(--bg)}
.avatar{width:34px;height:34px;border-radius:50%;background:var(--primary);display:flex;align-items:center;justify-content:center;font-size:.75rem;font-weight:800;color:#fff;flex-shrink:0}
.user-details{flex:1;overflow:hidden}
.user-details .uname{font-size:.82rem;font-weight:700;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.user-details .uemail{font-size:.7rem;color:var(--text-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

/* TOPBAR */
.topbar{position:fixed;top:0;left:var(--sidebar-w);right:0;height:var(--topbar-h);background:var(--white);border-bottom:1px solid var(--border);display:flex;align-items:center;justify-content:space-between;padding:0 28px;z-index:100;transition:left .3s}
.topbar-left{display:flex;align-items:center;gap:12px}
.hamburger{display:none;background:none;border:none;cursor:pointer;padding:6px;border-radius:8px;color:var(--text-muted)}
.hamburger svg{width:20px;height:20px;stroke:currentColor;fill:none}
.page-label{font-size:1rem;font-weight:700;letter-spacing:-0.01em}
.topbar-right{display:flex;align-items:center;gap:12px}
.topbar-stat{display:flex;align-items:center;gap:7px;background:var(--bg);border:1.5px solid var(--border);border-radius:24px;padding:6px 14px 6px 10px}
.topbar-stat svg{width:15px;height:15px;stroke:var(--primary);fill:none;flex-shrink:0}
.topbar-stat span{font-size:.78rem;font-weight:700;color:var(--text)}
.topbar-wallet{display:flex;align-items:center;gap:7px;background:var(--primary-bg);border:1.5px solid rgba(34,90,227,.2);border-radius:24px;padding:6px 14px 6px 10px;cursor:pointer;transition:all .2s;text-decoration:none}
.topbar-wallet:hover{background:var(--primary);border-color:var(--primary)}
.topbar-wallet:hover svg,.topbar-wallet:hover span{stroke:#fff!important;color:#fff!important}
.topbar-wallet svg{width:15px;height:15px;stroke:var(--primary);fill:none;flex-shrink:0}
.topbar-wallet span{font-size:.78rem;font-weight:700;color:var(--primary)}
.topbar-avatar{width:36px;height:36px;border-radius:50%;background:var(--primary);display:flex;align-items:center;justify-content:center;font-size:.75rem;font-weight:800;color:#fff;cursor:pointer}

/* LAYOUT */
.layout{display:flex;min-height:100vh}
.main-content{margin-left:var(--sidebar-w);margin-top:var(--topbar-h);flex:1;padding:28px;min-height:calc(100vh - var(--topbar-h))}

/* CARDS */
.card{background:var(--white);border-radius:var(--radius-lg);border:1px solid var(--border);box-shadow:var(--shadow-sm)}
.card-header{padding:18px 22px;border-bottom:1px solid var(--border);display:flex;align-items:center;justify-content:space-between;gap:12px}
.card-header h3{font-size:.95rem;font-weight:700}
.card-body{padding:20px 22px}

/* BUTTONS */
.btn{display:inline-flex;align-items:center;justify-content:center;gap:8px;border-radius:10px;border:none;cursor:pointer;font-family:var(--font);font-weight:600;transition:all .2s}
.btn-primary{background:var(--primary);color:#fff;box-shadow:var(--shadow-lg)}
.btn-primary:hover{background:var(--primary-dark);transform:translateY(-1px)}
.btn-secondary{background:var(--bg);color:var(--text);border:1.5px solid var(--border)}
.btn-secondary:hover{background:var(--border)}
.btn-danger{background:var(--error);color:#fff}
.btn-danger:hover{background:#dc2626;transform:translateY(-1px)}
.btn-success{background:var(--success);color:#fff}
.btn-success:hover{background:#059669;transform:translateY(-1px)}
.btn-sm{padding:7px 12px;font-size:.78rem}
.btn-md{padding:10px 20px;font-size:.875rem}
.btn-lg{padding:13px 24px;font-size:.9rem}
.btn-block{width:100%}
.btn svg{width:15px;height:15px;stroke:currentColor;fill:none}

/* BADGES */
.badge{padding:3px 10px;border-radius:20px;font-size:.72rem;font-weight:700;display:inline-flex;align-items:center;gap:4px}
.badge-success{background:var(--success-bg);color:var(--success)}
.badge-warning{background:var(--warning-bg);color:var(--warning)}
.badge-error{background:var(--error-bg);color:var(--error)}
.badge-primary{background:var(--primary-bg);color:var(--primary)}
.badge-info{background:var(--info-bg);color:var(--info)}
.badge-muted{background:var(--bg);color:var(--text-muted)}

/* TABLE */
.data-table{width:100%;border-collapse:collapse}
.data-table th{text-align:left;padding:10px 16px;font-size:.7rem;font-weight:700;text-transform:uppercase;letter-spacing:.08em;color:var(--text-muted);background:var(--bg);border-bottom:1px solid var(--border)}
.data-table td{padding:13px 16px;font-size:.84rem;border-bottom:1px solid var(--border)}
.data-table tr:last-child td{border-bottom:none}
.data-table tbody tr:hover td{background:var(--bg)}

/* ALERTS */
.alert{padding:12px 16px;border-radius:10px;font-size:.82rem;font-weight:500;display:flex;align-items:center;gap:10px;margin-bottom:18px}
.alert svg{width:16px;height:16px;stroke:currentColor;fill:none;flex-shrink:0}
.alert-success{background:var(--success-bg);color:var(--success);border:1px solid #BBF7D0}
.alert-error{background:var(--error-bg);color:var(--error);border:1px solid #FECACA}
.alert-warning{background:var(--warning-bg);color:var(--warning);border:1px solid #FDE68A}
.alert-info{background:var(--primary-bg);color:var(--primary);border:1px solid rgba(34,90,227,.2)}

/* FORM */
.form-group{margin-bottom:18px}
.form-group label{display:block;font-size:.7rem;font-weight:700;text-transform:uppercase;letter-spacing:.1em;color:var(--text-muted);margin-bottom:7px}
.form-control{width:100%;height:46px;border:1.5px solid var(--border);border-radius:10px;background:var(--bg);padding:0 14px;font-size:.875rem;color:var(--text);font-family:var(--font);outline:none;transition:all .2s}
.form-control:focus{border-color:var(--primary);background:var(--white);box-shadow:0 0 0 3px rgba(34,90,227,.1)}
.form-control::placeholder{color:var(--text-light)}
textarea.form-control{height:auto;padding:12px 14px;resize:vertical}
select.form-control{cursor:pointer}

/* MODAL */
.modal-backdrop{display:none;position:fixed;inset:0;background:rgba(0,0,0,.5);z-index:500;backdrop-filter:blur(3px);align-items:center;justify-content:center;padding:20px}
.modal-backdrop.open{display:flex}
.modal{background:var(--white);border-radius:20px;width:100%;max-width:500px;max-height:calc(100vh - 40px);overflow-y:auto;box-shadow:0 20px 60px rgba(0,0,0,.2);animation:modalIn .25s ease}
.modal-header{padding:22px 24px;border-bottom:1px solid var(--border);display:flex;align-items:center;justify-content:space-between}
.modal-header h3{font-size:1rem;font-weight:800}
.modal-close{background:none;border:none;cursor:pointer;width:32px;height:32px;border-radius:8px;display:flex;align-items:center;justify-content:center;color:var(--text-muted);transition:background .2s}
.modal-close:hover{background:var(--bg)}
.modal-close svg{width:18px;height:18px;stroke:currentColor;fill:none}
.modal-body{padding:24px}
.modal-footer{padding:16px 24px;border-top:1px solid var(--border);display:flex;gap:10px;justify-content:flex-end}
@keyframes modalIn{from{opacity:0;transform:translateY(12px) scale(.98)}to{opacity:1;transform:none}}

/* OVERLAY */
.overlay{display:none;position:fixed;inset:0;background:rgba(0,0,0,.4);z-index:199;backdrop-filter:blur(2px)}
.overlay.active{display:block}

/* MOBILE */
@media(max-width:1024px){
  .sidebar{transform:translateX(-100%)}
  .sidebar.open{transform:translateX(0)}
  .topbar{left:0}
  .main-content{margin-left:0}
  .hamburger{display:flex}
}
@media(max-width:640px){
  .main-content{padding:20px 16px}
  .page-label{display:none}
  .topbar-stat{display:none}
}

/* ANIMATIONS */
@keyframes fadeUp{from{opacity:0;transform:translateY(14px)}to{opacity:1;transform:none}}
@keyframes fadeIn{from{opacity:0}to{opacity:1}}
.anim-up{animation:fadeUp .4s ease both}
@keyframes spin{to{transform:rotate(360deg)}}

/* ── Responsive patch: fluid inline grids, tables & modals on small screens ── */
img,video,canvas{max-width:100%}
@media(max-width:900px){
  [style*="grid-template-columns:repeat(4"]{grid-template-columns:repeat(2,1fr)!important}
}
@media(max-width:768px){
  [style*="grid-template-columns:repeat(3"]{grid-template-columns:repeat(2,1fr)!important}
  .data-table{font-size:.82rem}
  .data-table th,.data-table td{padding:10px 12px;white-space:nowrap}
}
@media(max-width:560px){
  [style*="grid-template-columns:repeat(4"],
  [style*="grid-template-columns:repeat(3"],
  [style*="grid-template-columns:repeat(2"]{grid-template-columns:1fr!important}
  .modal-footer{flex-wrap:wrap}
  .modal-footer .btn,.modal-footer button{flex:1 1 auto}
}
</style>
</head>
<body>
<div class="overlay" id="overlay" onclick="closeSidebar()"></div>

<aside class="sidebar" id="sidebar">
  <div class="sidebar-brand">
    <img src="assets/img/dlogo.png" alt="Dabil" style="height:30px;width:auto;display:block">
    <span class="brand-tag">Admin</span>
  </div>

  <div class="sidebar-scroll">
    <div class="nav-section">
      <div class="nav-label">Overview</div>
      <a href="dashboard.php" class="nav-item <?php echo $__active==='dashboard'?'active':''; ?>">
        <svg viewBox="0 0 24 24" stroke-width="2" fill="none" stroke="currentColor" stroke-linecap="round"><rect x="3" y="3" width="7" height="7" rx="1"/><rect x="14" y="3" width="7" height="7" rx="1"/><rect x="14" y="14" width="7" height="7" rx="1"/><rect x="3" y="14" width="7" height="7" rx="1"/></svg>
        Dashboard
      </a>
    </div>

    <div class="nav-section">
      <div class="nav-label">Management</div>
      <a href="restaurants.php" class="nav-item <?php echo $__active==='restaurants'?'active':''; ?>">
        <svg viewBox="0 0 24 24" stroke-width="2" fill="none" stroke="currentColor" stroke-linecap="round"><path d="M3 11l19-9-9 19-2-8-8-2z"/></svg>
        Restaurants
        <?php if($total_restaurants>0): ?><span class="nav-badge blue"><?php echo $total_restaurants; ?></span><?php endif; ?>
      </a>
      <a href="users.php" class="nav-item <?php echo $__active==='users'?'active':''; ?>">
        <svg viewBox="0 0 24 24" stroke-width="2" fill="none" stroke="currentColor" stroke-linecap="round"><path d="M17 21v-2a4 4 0 00-4-4H5a4 4 0 00-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 00-3-3.87M16 3.13a4 4 0 010 7.75"/></svg>
        All Users
      </a>
      <a href="organizations.php" class="nav-item <?php echo in_array($__active,['organizations','organization_view','organization_edit'])?'active':''; ?>">
        <svg viewBox="0 0 24 24" stroke-width="2" fill="none" stroke="currentColor" stroke-linecap="round"><path d="M3 9l9-7 9 7v11a2 2 0 01-2 2H5a2 2 0 01-2-2z"/><polyline points="9 22 9 12 15 12 15 22"/></svg>
        Organisations
        <?php
        $__org_count = $conn->query("SELECT COUNT(*) FROM organizations WHERE status='active'")->fetch_row()[0] ?? 0;
        if ($__org_count > 0): ?><span class="nav-badge blue"><?php echo $__org_count; ?></span><?php endif; ?>
      </a>
      <a href="orders.php" class="nav-item <?php echo $__active==='orders'?'active':''; ?>">
        <svg viewBox="0 0 24 24" stroke-width="2" fill="none" stroke="currentColor" stroke-linecap="round"><path d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2"/><rect x="9" y="3" width="6" height="4" rx="1"/><path d="M9 12h6M9 16h4"/></svg>
        All Orders
        <?php if($pending_orders>0): ?><span class="nav-badge"><?php echo $pending_orders; ?></span><?php endif; ?>
      </a>
      <a href="feedback.php" class="nav-item <?php echo $__active==='feedback'?'active':''; ?>">
        <svg viewBox="0 0 24 24" stroke-width="2" fill="none" stroke="currentColor" stroke-linecap="round"><path d="M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"/></svg>
        Feedback
        <?php if($open_feedback>0): ?><span class="nav-badge"><?php echo $open_feedback; ?></span><?php endif; ?>
      </a>
      <a href="app_feedback.php" class="nav-item <?php echo $__active==='app_feedback'?'active':''; ?>">
        <svg viewBox="0 0 24 24" stroke-width="2" fill="none" stroke="currentColor" stroke-linecap="round"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/></svg>
        App Feedback
      </a>
    </div>

    <div class="nav-section">
      <div class="nav-label">Finance</div>
      <a href="my_wallet.php" class="nav-item <?php echo $__active==='my_wallet'?'active':''; ?>">
        <svg viewBox="0 0 24 24" stroke-width="2" fill="none" stroke="currentColor" stroke-linecap="round"><path d="M21 12V7H5a2 2 0 010-4h15a1 1 0 011 1v4"/><path d="M3 5v14a2 2 0 002 2h16v-5"/><path d="M18 12a2 2 0 000 4h4v-4z"/></svg>
        My Wallet
        <span class="nav-badge green" style="font-size:.6rem;padding:2px 6px">₦<?php echo number_format($__wallet_balance,0); ?></span>
      </a>
      <a href="transactions.php" class="nav-item <?php echo $__active==='transactions'?'active':''; ?>">
        <svg viewBox="0 0 24 24" stroke-width="2" fill="none" stroke="currentColor" stroke-linecap="round"><path d="M7 20V4l10 16V4M4 10h16M4 14h16"/></svg>
        Transactions
      </a>
      <a href="withdrawals.php" class="nav-item <?php echo $__active==='withdrawals'?'active':''; ?>">
        <svg viewBox="0 0 24 24" stroke-width="2" fill="none" stroke="currentColor" stroke-linecap="round"><path d="M12 5v14m-7-7l7 7 7-7"/></svg>
        Withdrawals
      </a>
    </div>

    <div class="nav-section">
      <div class="nav-label">Account</div>
      <a href="profile.php" class="nav-item <?php echo $__active==='profile'?'active':''; ?>">
        <svg viewBox="0 0 24 24" stroke-width="2" fill="none" stroke="currentColor" stroke-linecap="round"><path d="M20 21v-2a4 4 0 00-4-4H8a4 4 0 00-4 4v2"/><circle cx="12" cy="7" r="4"/></svg>
        My Profile
      </a>
      <a href="logout.php" class="nav-item" style="color:var(--error)">
        <svg viewBox="0 0 24 24" stroke-width="2" fill="none" stroke="currentColor" stroke-linecap="round"><path d="M9 21H5a2 2 0 01-2-2V5a2 2 0 012-2h4"/><polyline points="16 17 21 12 16 7"/><line x1="21" y1="12" x2="9" y2="12"/></svg>
        Logout
      </a>
    </div>
  </div>

  <div class="sidebar-footer">
    <!-- Wallet quick view -->
    <a href="my_wallet.php" class="wallet-pill">
      <div class="wallet-pill-icon">
        <svg viewBox="0 0 24 24" stroke-width="2" stroke-linecap="round"><path d="M21 12V7H5a2 2 0 010-4h15a1 1 0 011 1v4"/><path d="M3 5v14a2 2 0 002 2h16v-5"/><path d="M18 12a2 2 0 000 4h4v-4z"/></svg>
      </div>
      <div class="wallet-pill-info">
        <div class="wallet-pill-label">Platform Wallet</div>
        <div class="wallet-pill-amount">₦<?php echo number_format($__wallet_balance,2); ?></div>
      </div>
      <svg viewBox="0 0 24 24" stroke-width="2" stroke-linecap="round" style="width:14px;height:14px;stroke:rgba(255,255,255,.6);fill:none;flex-shrink:0"><path d="M5 12h14M12 5l7 7-7 7"/></svg>
    </a>
    <div class="user-pill">
      <div class="avatar"><?php echo $__initials; ?></div>
      <div class="user-details">
        <div class="uname"><?php echo htmlspecialchars($__name); ?></div>
        <div class="uemail">Super Admin</div>
      </div>
    </div>
  </div>
</aside>

<header class="topbar">
  <div class="topbar-left">
    <button class="hamburger" onclick="toggleSidebar()">
      <svg viewBox="0 0 24 24" stroke-width="2" stroke-linecap="round"><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="18" x2="21" y2="18"/></svg>
    </button>
    <span class="page-label"><?php echo htmlspecialchars($__page_title); ?></span>
  </div>
  <div class="topbar-right">
    <div class="topbar-stat">
      <svg viewBox="0 0 24 24" stroke-width="2" stroke-linecap="round"><path d="M3 11l19-9-9 19-2-8-8-2z"/></svg>
      <span><?php echo $total_restaurants; ?> Restaurants</span>
    </div>
    <?php if($pending_orders > 0): ?>
    <a href="orders.php?status=pending" class="topbar-stat" style="border-color:rgba(239,68,68,.3);background:var(--error-bg)">
      <svg viewBox="0 0 24 24" stroke-width="2" stroke-linecap="round" style="stroke:var(--error)"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>
      <span style="color:var(--error)"><?php echo $pending_orders; ?> Pending</span>
    </a>
    <?php endif; ?>
    <!-- Wallet balance shortcut in topbar -->
    <a href="my_wallet.php" class="topbar-wallet">
      <svg viewBox="0 0 24 24" stroke-width="2" stroke-linecap="round"><path d="M21 12V7H5a2 2 0 010-4h15a1 1 0 011 1v4"/><path d="M3 5v14a2 2 0 002 2h16v-5"/><path d="M18 12a2 2 0 000 4h4v-4z"/></svg>
      <span>₦<?php echo number_format($__wallet_balance,0); ?></span>
    </a>
    <div class="topbar-avatar"><?php echo $__initials; ?></div>
  </div>
</header>

<div class="layout">
<main class="main-content">
