<?php
// admin/partials/admin_header.php
// Requires: session already started, admin logged in check done
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= isset($adminPageTitle) ? sanitize($adminPageTitle) . ' | ' : '' ?>Admin Panel</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css"/>
    <style>
        body { background: #f0f2f5; font-family: 'Segoe UI', sans-serif; }
        .sidebar { width: 260px; min-height: 100vh; background: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%); position: fixed; top: 0; left: 0; z-index: 100; box-shadow: 3px 0 15px rgba(0,0,0,.2); }
        .sidebar-brand { padding: 24px 20px; border-bottom: 1px solid rgba(255,255,255,.1); }
        .sidebar-brand h5 { color: white; margin: 0; font-weight: 700; }
        .sidebar-nav { padding: 16px 0; }
        .sidebar-nav a { display: flex; align-items: center; gap: 12px; padding: 12px 24px; color: rgba(255,255,255,.7); text-decoration: none; transition: all .2s; border-left: 3px solid transparent; }
        .sidebar-nav a:hover, .sidebar-nav a.active { color: white; background: rgba(255,255,255,.08); border-left-color: #0d6efd; }
        .sidebar-nav a i { width: 18px; text-align: center; }
        .sidebar-nav .nav-section { padding: 16px 24px 6px; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: rgba(255,255,255,.35); }
        .main-content { margin-left: 260px; min-height: 100vh; }
        .topbar { background: white; padding: 12px 30px; box-shadow: 0 2px 8px rgba(0,0,0,.08); display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 50; }
        .topbar-title { font-weight: 700; font-size: 1.1rem; color: #1a1a2e; margin: 0; }
        .content-area { padding: 30px; }
        .stat-card { background: white; border-radius: 12px; padding: 24px; box-shadow: 0 2px 12px rgba(0,0,0,.06); border: none; }
        .stat-card .stat-icon { width: 54px; height: 54px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.4rem; }
        .table-card { background: white; border-radius: 12px; box-shadow: 0 2px 12px rgba(0,0,0,.06); overflow: hidden; }
        .table-card .card-header { background: white; border-bottom: 1px solid #f0f2f5; padding: 18px 24px; font-weight: 700; font-size: 1rem; }
        .btn-action { padding: 5px 12px; font-size: .82rem; border-radius: 6px; }
        .product-thumb { width: 50px; height: 50px; object-fit: contain; border-radius: 6px; background: #f8f9fa; }
        .badge-status { padding: 5px 10px; border-radius: 20px; font-size: .75rem; font-weight: 600; }
        @media (max-width: 768px) {
            .sidebar { transform: translateX(-100%); }
            .main-content { margin-left: 0; }
        }
    </style>
</head>
<body>

<!-- Sidebar -->
<div class="sidebar">
    <div class="sidebar-brand">
        <h5><i class="fas fa-shopping-bag me-2 text-primary"></i>Electro Admin</h5>
        <small style="color:rgba(255,255,255,.4);">Management Panel</small>
    </div>
    <nav class="sidebar-nav">
        <div class="nav-section">Main</div>
        <a href="<?= SITE_URL ?>/admin/index.php" class="<?= (basename($_SERVER['PHP_SELF']) === 'index.php' && strpos($_SERVER['REQUEST_URI'], 'admin') !== false) ? 'active' : '' ?>">
            <i class="fas fa-tachometer-alt"></i> Dashboard
        </a>
        <div class="nav-section">Products</div>
        <a href="<?= SITE_URL ?>/admin/products.php" class="<?= basename($_SERVER['PHP_SELF']) === 'products.php' ? 'active' : '' ?>">
            <i class="fas fa-box"></i> All Products
        </a>
        <a href="<?= SITE_URL ?>/admin/product_add.php" class="<?= basename($_SERVER['PHP_SELF']) === 'product_add.php' ? 'active' : '' ?>">
            <i class="fas fa-plus-circle"></i> Add Product
        </a>
        <div class="nav-section">Settings</div>
        <a href="<?= SITE_URL ?>/admin/phones.php" class="<?= basename($_SERVER['PHP_SELF']) === 'phones.php' ? 'active' : '' ?>">
            <i class="fas fa-phone"></i> Phone Numbers
        </a>
        <a href="<?= SITE_URL ?>/admin/settings.php" class="<?= basename($_SERVER['PHP_SELF']) === 'settings.php' ? 'active' : '' ?>">
            <i class="fas fa-cog"></i> Site Settings
        </a>
        <a href="<?= SITE_URL ?>/admin/change_password.php" class="<?= basename($_SERVER['PHP_SELF']) === 'change_password.php' ? 'active' : '' ?>">
            <i class="fas fa-key"></i> Change Password
        </a>
        <div class="nav-section">Communications</div>
        <a href="<?= SITE_URL ?>/admin/contact_messages.php" class="<?= basename($_SERVER['PHP_SELF']) === 'contact_messages.php' ? 'active' : '' ?>">
            <i class="fas fa-envelope"></i> Contact Messages
        </a>
        <div class="nav-section">Website</div>
        <a href="<?= SITE_URL ?>/" target="_blank">
            <i class="fas fa-external-link-alt"></i> View Website
        </a>
        <a href="<?= SITE_URL ?>/admin/logout.php">
            <i class="fas fa-sign-out-alt"></i> Logout
        </a>
    </nav>
</div>

<!-- Main Content -->
<div class="main-content">
    <!-- Topbar -->
    <div class="topbar">
        <h6 class="topbar-title"><?= isset($adminPageTitle) ? sanitize($adminPageTitle) : 'Dashboard' ?></h6>
        <div class="d-flex align-items-center gap-3">
            <small class="text-muted">Welcome, <strong><?= sanitize($_SESSION['admin_username'] ?? 'Admin') ?></strong></small>
            <a href="<?= SITE_URL ?>/admin/logout.php" class="btn btn-sm btn-outline-danger">
                <i class="fas fa-sign-out-alt me-1"></i>Logout
            </a>
        </div>
    </div>
    <div class="content-area">
