<?php ob_start();
$pageNow = $_GET['page'] ?? 'dashboard';

// ── Selalu ambil data admin terbaru dari DB (bukan hanya session) ──
// Supaya perubahan nama/role langsung tampil tanpa harus re-login
$namaAdmin = $_SESSION['admin_nama'] ?? 'Admin';
$roleAdmin = $_SESSION['admin_role'] ?? '';
$fotoAdmin = null;
if (!empty($_SESSION['admin_id'])) {
    try {
        $__adminRow = $pdo->prepare("SELECT nama_lengkap, role, foto FROM admin WHERE id=? LIMIT 1");
        $__adminRow->execute([$_SESSION['admin_id']]);
        $__adminData = $__adminRow->fetch();
        if ($__adminData) {
            $namaAdmin = $__adminData['nama_lengkap'];
            $roleAdmin = $__adminData['role'];
            $fotoAdmin = $__adminData['foto'] ?? null;
            // Perbarui session agar konsisten
            $_SESSION['admin_nama'] = $namaAdmin;
            $_SESSION['admin_role'] = $roleAdmin;
        }
    } catch(Exception $e) {}
}

// ── Ambil data sekolah dari pengaturan ──
$_setting = [];
try {
    $__rows = $pdo->query("SELECT kunci,nilai FROM pengaturan")->fetchAll();
    foreach($__rows as $__r) $_setting[$__r['kunci']] = $__r['nilai'];
} catch(Exception $e) {}
$_namaSekolah = $_setting['nama_sekolah']  ?? 'SPP Admin';
$_subSekolah  = $_setting['alamat_sekolah'] ?? 'Sistem Pembayaran';
$_logoFile    = $_setting['logo_sekolah']   ?? '';
$_rootDir     = str_replace('\\\\','/',dirname(__DIR__));
$_logoAbs     = $_rootDir.'/uploads/logo/'.$_logoFile;
$_logoUrl     = 'uploads/logo/'.$_logoFile;
$_hasLogo     = $_logoFile && file_exists($_logoAbs);

$nav = [
    'dashboard'      => ['label'=>'Dashboard',      'sub'=>'Ringkasan & statistik'],
    'siswa'          => ['label'=>'Data Siswa',     'sub'=>'Kelola data murid'],
    'kelas'          => ['label'=>'Kelas',          'sub'=>'Manajemen data kelas'],
    'riwayat_siswa'  => ['label'=>'Riwayat Siswa',  'sub'=>'Histori naik & pindah kelas'],
    'alumni'         => ['label'=>'Data Alumni',    'sub'=>'Siswa kelas XII yang lulus'],
    'laporan'        => ['label'=>'Laporan',         'sub'=>'Cetak laporan SPP'],
];
if (isRole('superadmin','admin')) {
    $nav['users']      = ['label'=>'Users Siswa',  'sub'=>'Akun login siswa'];
    $nav['pengaturan'] = ['label'=>'Pengaturan',   'sub'=>'Konfigurasi sistem'];
    $nav['admin']      = ['label'=>'Kelola Admin', 'sub'=>'Manajemen admin'];
}

$pageLabels = [
    'dashboard'     =>'Dashboard',    'siswa'          =>'Data Siswa',
    'kelas'         =>'Manajemen Kelas',
    'riwayat_siswa' =>'Riwayat Siswa', 'alumni'        =>'Data Alumni',
    'tagihan'       =>'Tagihan SPP',  'pembayaran'    =>'Pembayaran',
    'riwayat'       =>'Riwayat',      'users'         =>'Users Siswa',
    'laporan'       =>'Laporan SPP',  'pengaturan'    =>'Pengaturan',
    'admin'         =>'Kelola Admin'
];

$svgIcons = [
    'dashboard'  => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="7" height="7" rx="1.5"/><rect x="14" y="3" width="7" height="7" rx="1.5"/><rect x="14" y="14" width="7" height="7" rx="1.5"/><rect x="3" y="14" width="7" height="7" rx="1.5"/></svg>',
    'siswa'      => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></svg>',
    'kelas'      => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/><polyline points="9 22 9 12 15 12 15 22"/></svg>',
    'alumni'        => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M22 10v6M2 10l10-5 10 5-10 5z"/><path d="M6 12v5c3 3 9 3 12 0v-5"/><circle cx="12" cy="21" r="1"/></svg>',
    'riwayat_siswa' => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/><line x1="10" y1="9" x2="8" y2="9"/></svg>',
    'tagihan'    => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/></svg>',
    'pembayaran' => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="1" y="4" width="22" height="16" rx="2"/><line x1="1" y1="10" x2="23" y2="10"/></svg>',
    'riwayat'    => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>',
    'users'      => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg>',
    'pengaturan' => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>',
    'admin'      => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></svg>',
    'logout'     => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/><polyline points="16 17 21 12 16 7"/><line x1="21" y1="12" x2="9" y2="12"/></svg>',
    'menu'       => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="15" y2="12"/><line x1="3" y1="18" x2="21" y2="18"/></svg>',
    'calendar'   => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="18" rx="2"/><line x1="16" y1="2" x2="16" y2="6"/><line x1="8" y1="2" x2="8" y2="6"/><line x1="3" y1="10" x2="21" y2="10"/></svg>',
    'laporan'    => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/><line x1="10" y1="9" x2="8" y2="9"/></svg>',
    'search'     => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>',
];

$navGroups = [
    'UTAMA'     => ['dashboard', 'kelas'],
    'DATA SISWA'=> ['_siswa_group'],
    'TAGIHAN'   => ['_tagihan_group'],
    'LAPORAN'   => ['laporan'],
    'MANAJEMEN' => ['_manajemen_group'],
];
?>
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= e($_namaSekolah) ?> — <?= $pageLabels[$pageNow] ?? ucfirst($pageNow) ?></title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:opsz,wght@9..40,300;9..40,400;9..40,500;9..40,600;9..40,700&family=DM+Mono:wght@400;500&family=Fraunces:opsz,wght@9..144,600;9..144,700&display=swap" rel="stylesheet">
<style>
:root {
  --bg:       #F4F6FB;
  --bg2:      #FFFFFF;
  --bg3:      #EEF1F8;
  --surface:  #FFFFFF;
  --surface2: #F0F4FF;
  --surface3: #E4EAFF;
  --border:   rgba(99,116,175,.13);
  --border2:  rgba(99,116,175,.25);
  --text:     #1A2035;
  --text2:    #5A6A8A;
  --text3:    #9AAAC8;
  --indigo:       #4F6EF7;
  --indigo-light: #EEF1FF;
  --indigo-mid:   rgba(79,110,247,.15);
  --indigo-glow:  rgba(79,110,247,.25);
  --candy-purple: #7C3AED;
  --candy-pink:   #EC4899;
  --sb-bg:      #1E2D4E;
  --sb-bg2:     #253660;
  --sb-active:  #2E4070;
  --sb-text:    rgba(255,255,255,.85);
  --sb-text2:   rgba(255,255,255,.45);
  --sb-border:  rgba(255,255,255,.08);
  --green:   #22C55E;  --green-dim:  rgba(34,197,94,.12);
  --amber:   #F59E0B;  --amber-dim:  rgba(245,158,11,.12);
  --red:     #EF4444;  --red-dim:    rgba(239,68,68,.12);
  --blue:    #3B82F6;  --blue-dim:   rgba(59,130,246,.12);
  --violet:  #8B5CF6;  --violet-dim: rgba(139,92,246,.12);
  --teal:    #14B8A6;  --teal-dim:   rgba(20,184,166,.12);
  --orange:  #F97316;  --orange-dim: rgba(249,115,22,.12);
  --sidebar-w: 252px;
  --topbar-h:  60px;
  --r:    12px;
  --r-sm:  8px;
  --r-xs:  6px;
  --radius:   12px;
  --radius-sm: 8px;
  --shadow:    0 1px 4px rgba(30,45,78,.07), 0 4px 16px rgba(30,45,78,.06);
  --shadow-md: 0 4px 20px rgba(30,45,78,.10);
  --shadow-lg: 0 8px 40px rgba(30,45,78,.14);
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body { font-family: 'DM Sans', sans-serif; background: var(--bg); color: var(--text); display: flex; min-height: 100vh; font-size: 14px; line-height: 1.5; }
a { text-decoration: none; color: inherit; }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ═══ SIDEBAR ═══ */
.sidebar { width: var(--sidebar-w); background: var(--sb-bg); position: fixed; top: 0; left: 0; height: 100%; display: flex; flex-direction: column; z-index: 100; box-shadow: 2px 0 20px rgba(30,45,78,.18); transition: transform .28s cubic-bezier(.4,0,.2,1); }
.sidebar::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 180px; background: linear-gradient(180deg, rgba(79,110,247,.18) 0%, transparent 100%); pointer-events: none; border-radius: 0; }
.sidebar-brand { padding: 20px 18px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--sb-border); position: relative; z-index: 1; }
.brand-mark { width: 40px; height: 40px; border-radius: 12px; flex-shrink: 0; background: linear-gradient(135deg, #4F6EF7, #6C8DFF); display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 16px rgba(79,110,247,.45); }
.brand-mark svg { width: 19px; height: 19px; color: #fff; stroke-width: 2; }
.brand-name { font-family: 'Fraunces', serif; font-size: 16px; font-weight: 700; color: #fff; letter-spacing: -.2px; line-height: 1.1; }
.brand-sub { font-size: 10.5px; color: var(--sb-text2); margin-top: 2px; letter-spacing: .3px; }
.sidebar-nav { flex: 1; padding: 14px 10px 10px; overflow-y: auto; position: relative; z-index: 1; }
.nav-section { font-size: 9.5px; font-weight: 600; letter-spacing: 1.4px; text-transform: uppercase; color: var(--sb-text2); padding: 10px 10px 5px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--r-sm); color: var(--sb-text); font-size: 13px; font-weight: 500; cursor: pointer; transition: all .18s; margin-bottom: 2px; text-decoration: none; position: relative; }
.nav-item:hover { background: var(--sb-bg2); }
.nav-item:hover .nav-icon { color: #7AAEFF; }
.nav-item.active { background: var(--sb-active); font-weight: 600; color: #fff; }
.nav-item.active::before { content: ''; position: absolute; left: 0; top: 22%; bottom: 22%; width: 3px; border-radius: 0 3px 3px 0; background: linear-gradient(to bottom, #7AAEFF, #4F6EF7); box-shadow: 0 0 10px rgba(79,110,247,.6); }
.nav-item.active .nav-icon { color: #A5BFFF; }
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; color: var(--sb-text2); transition: color .18s; }
.nav-icon svg { width: 100%; height: 100%; display: block; }
.nav-kelas-badge { margin-left: auto; background: rgba(79,110,247,.25); color: #A5BFFF; border-radius: 99px; font-size: 9.5px; font-weight: 700; padding: 1px 7px; min-width: 20px; text-align: center; line-height: 1.6; transition: background .18s; }
.nav-item.active .nav-kelas-badge { background: rgba(255,255,255,.2); color: #fff; }

/* ─── Footer — PERSIS dari kode asli ─── */
.sidebar-footer { padding: 12px 10px 16px; border-top: 1px solid var(--sb-border); position: relative; z-index: 1; }
.user-card { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--r-sm); background: rgba(255,255,255,.07); border: 1px solid var(--sb-border); cursor: default; transition: background .18s; overflow: hidden; }
.user-card:hover { background: rgba(255,255,255,.10); }
.user-avatar { width: 33px; height: 33px; border-radius: 9px; flex-shrink: 0; background: linear-gradient(135deg, #4F6EF7, #818CF8); display: flex; align-items: center; justify-content: center; font-family: 'Fraunces', serif; font-size: 14px; font-weight: 700; color: #fff; }
.user-info { flex: 1; min-width: 0; overflow: hidden; }
.user-name { font-size: 12.5px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 10px; color: var(--sb-text2); margin-top: 1px; text-transform: capitalize; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; background: #4ADE80; box-shadow: 0 0 7px rgba(74,222,128,.7); }

/* ═══ TOPBAR ═══ */
.topbar { margin-left: var(--sidebar-w); height: var(--topbar-h); background: var(--bg2); padding: 0 24px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 50; box-shadow: 0 1px 8px rgba(30,45,78,.07); }
.topbar-left  { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 6px; }
.topbar-icon { width: 34px; height: 34px; border-radius: var(--r-sm); flex-shrink: 0; background: var(--indigo-light); display: flex; align-items: center; justify-content: center; color: var(--indigo); }
.topbar-icon svg { width: 15px; height: 15px; }
.topbar-crumb-root { font-size: 12px; color: var(--text3); }
.topbar-crumb-sep  { color: var(--text3); font-size: 12px; padding: 0 4px; }
.topbar-crumb-page { font-size: 13.5px; font-weight: 600; color: var(--text); }
.topbar-kelas-chip { display: none; align-items: center; gap: 5px; background: #EDE9FE; border: 1px solid #C4B5FD; color: #5B21B6; border-radius: var(--r-xs); padding: 4px 10px; font-size: 11.5px; font-weight: 600; }
<?php if($pageNow === 'kelas'): ?>.topbar-kelas-chip { display: flex; }<?php endif ?>
.topbar-chip { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text2); font-weight: 500; background: var(--bg3); border: 1px solid var(--border); padding: 5px 11px; border-radius: var(--r-xs); }
.topbar-chip svg { width: 12px; height: 12px; color: var(--text3); }
.topbar-sep { width: 1px; height: 20px; background: var(--border2); margin: 0 4px; }
.topbar-hi { font-size: 12.5px; color: var(--text2); padding: 0 6px; }
.topbar-hi strong { color: var(--text); }
.btn-logout { display: flex; align-items: center; gap: 7px; background: transparent; border: 1px solid var(--border2); color: var(--text2); padding: 6px 14px; border-radius: var(--r-xs); font-size: 12.5px; font-weight: 500; cursor: pointer; transition: all .18s; font-family: 'DM Sans', sans-serif; }
.btn-logout svg { width: 13px; height: 13px; transition: transform .2s; }
.btn-logout:hover { background: var(--red-dim); color: var(--red); border-color: rgba(239,68,68,.3); }
.btn-logout:hover svg { transform: translateX(2px); }
.btn-hamburger { display: none; background: var(--bg3); border: 1px solid var(--border); width: 34px; height: 34px; border-radius: var(--r-sm); align-items: center; justify-content: center; cursor: pointer; color: var(--text2); }
.btn-hamburger svg { width: 17px; height: 17px; }

/* ═══ CONTENT ═══ */
.content { margin-left: var(--sidebar-w); flex: 1; padding: 26px 26px 48px; animation: contentIn .32s cubic-bezier(.4,0,.2,1) both; min-width: 0; }
@keyframes contentIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ═══ CARDS ═══ */
.card { background: var(--surface); border-radius: var(--r); padding: 22px; border: 1px solid var(--border); margin-bottom: 20px; box-shadow: var(--shadow); transition: box-shadow .2s, border-color .2s; }
.card:hover { border-color: var(--border2); box-shadow: var(--shadow-md); }
.card-title { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 18px; display: flex; align-items: center; gap: 8px; }

/* ═══ STATS ═══ */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: 14px; margin-bottom: 22px; }
.stat { background: var(--surface); border-radius: var(--r); padding: 20px; border: 1px solid var(--border); box-shadow: var(--shadow); position: relative; overflow: hidden; transition: transform .2s, box-shadow .2s; animation: statIn .4s cubic-bezier(.4,0,.2,1) both; }
.stat::after { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; opacity: 0; transition: opacity .2s; }
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat:hover::after { opacity: 1; }
@keyframes statIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
.stat:nth-child(1){animation-delay:.04s}.stat:nth-child(2){animation-delay:.08s}.stat:nth-child(3){animation-delay:.12s}.stat:nth-child(4){animation-delay:.16s}
.stat-icon { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; margin-bottom: 14px; }
.stat-icon svg { width: 18px; height: 18px; }
.stat-val { font-family: 'DM Mono', monospace; font-size: 28px; font-weight: 500; color: var(--text); line-height: 1; margin-bottom: 5px; letter-spacing: -1px; }
.stat-label { font-size: 12px; color: var(--text2); font-weight: 400; }

/* ═══ BADGES & PILLS ═══ */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: var(--r-xs); font-size: 11.5px; font-weight: 600; }
.badge-success { background: var(--green-dim);  color: #16A34A; border: 1px solid rgba(34,197,94,.2); }
.badge-warning { background: var(--amber-dim);  color: #B45309; border: 1px solid rgba(245,158,11,.2); }
.badge-danger  { background: var(--red-dim);    color: #DC2626; border: 1px solid rgba(239,68,68,.2); }
.badge-info    { background: var(--blue-dim);   color: #2563EB; border: 1px solid rgba(59,130,246,.2); }
.badge-teal    { background: var(--teal-dim);   color: #0D9488; border: 1px solid rgba(20,184,166,.2); }
.pill { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 99px; font-size: 11.5px; font-weight: 500; }
.pill-purple { background: var(--violet-dim); color: #7C3AED; }
.pill-blue   { background: var(--blue-dim);   color: #2563EB; }
.pill-orange { background: var(--orange-dim); color: #C2410C; }
.pill-green  { background: var(--green-dim);  color: #15803D; }
.pill-pink   { background: rgba(236,72,153,.1); color: #BE185D; }
.pill-teal   { background: var(--teal-dim);   color: #0F766E; }

/* ═══ BUTTONS ═══ */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 16px; border-radius: var(--r-xs); font-size: 13px; font-weight: 500; border: none; cursor: pointer; transition: all .18s; font-family: 'DM Sans', sans-serif; white-space: nowrap; }
.btn svg { width: 14px; height: 14px; }
.btn-primary { background: linear-gradient(135deg, #4F6EF7, #6C8DFF); color: #fff; font-weight: 600; box-shadow: 0 2px 10px rgba(79,110,247,.35); }
.btn-primary:hover { box-shadow: 0 4px 16px rgba(79,110,247,.45); transform: translateY(-1px); filter: brightness(1.05); }
.btn-success { background: linear-gradient(135deg, #16A34A, #22C55E); color: #fff; font-weight: 600; box-shadow: 0 2px 10px rgba(34,197,94,.3); }
.btn-success:hover { transform: translateY(-1px); filter: brightness(1.05); }
.btn-danger { background: linear-gradient(135deg, #DC2626, #F87171); color: #fff; font-weight: 600; box-shadow: 0 2px 10px rgba(239,68,68,.3); }
.btn-danger:hover { transform: translateY(-1px); filter: brightness(1.05); }
.btn-outline { background: transparent; color: var(--text2); border: 1px solid var(--border2); }
.btn-outline:hover { background: var(--surface2); color: var(--text); border-color: var(--border2); }
.btn-sm { padding: 5px 11px; font-size: 12px; border-radius: var(--r-xs); }

/* ═══ TABLE ═══ */
table { width: 100%; border-collapse: collapse; }
thead tr { border-bottom: 1px solid var(--border); }
th { padding: 10px 15px; text-align: left; font-size: 10.5px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; color: var(--text3); background: var(--bg); white-space: nowrap; }
td { padding: 12px 15px; font-size: 13.5px; border-bottom: 1px solid var(--border); color: var(--text); }
tbody tr { transition: background .12s; }
tbody tr:hover td { background: var(--surface2); }
tbody tr:last-child td { border-bottom: none; }

/* ═══ FORMS ═══ */
.form-group { margin-bottom: 15px; }
label { display: block; font-size: 11px; font-weight: 600; color: var(--text3); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .7px; }
input, select, textarea { width: 100%; padding: 9px 13px; border: 1.5px solid var(--border2); border-radius: var(--r-xs); font-size: 13.5px; font-family: 'DM Sans', sans-serif; transition: all .18s; outline: none; background: var(--bg3); color: var(--text); }
input:focus, select:focus, textarea:focus { border-color: var(--indigo); box-shadow: 0 0 0 3px rgba(79,110,247,.12); background: #fff; }
input::placeholder { color: var(--text3); }
select option { background: #fff; color: var(--text); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ═══ AVATAR ═══ */
.avatar { width: 34px; height: 34px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; font-family: 'Fraunces', serif; font-weight: 700; font-size: 13px; color: #fff; }

/* ═══ MODAL ═══ */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(20,30,60,.45); backdrop-filter: blur(6px); z-index: 200; align-items: center; justify-content: center; padding: 20px; }
.modal-overlay.open { display: flex; animation: mFadeIn .18s ease; }
@keyframes mFadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal { background: var(--surface); border-radius: 16px; width: 500px; max-width: calc(100vw - 32px); max-height: 92vh; overflow-y: auto; overflow-x: hidden; border: 1px solid var(--border2); box-shadow: 0 20px 60px rgba(20,30,78,.2); animation: mSlideUp .22s cubic-bezier(.4,0,.2,1); word-break: break-word; }
@keyframes mSlideUp { from { opacity: 0; transform: translateY(20px) scale(.97); } to { opacity: 1; transform: translateY(0) scale(1); } }
.modal-header { padding: 18px 20px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; border-radius: 16px 16px 0 0; }
.modal-header h3 { font-size: 15px; font-weight: 600; color: var(--text); }
.modal-body    { padding: 18px 20px; }
.modal-footer  { padding: 14px 20px; display: flex; gap: 9px; justify-content: flex-end; border-top: 1px solid var(--border); }
.modal-close { background: var(--bg3); border: 1px solid var(--border); width: 28px; height: 28px; border-radius: 7px; font-size: 14px; cursor: pointer; color: var(--text3); display: flex; align-items: center; justify-content: center; transition: .18s; }
.modal-close:hover { background: var(--red-dim); color: var(--red); border-color: rgba(239,68,68,.3); }

/* ═══ TOOLBAR & SEARCH ═══ */
.toolbar { display: flex; gap: 9px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.search-box { position: relative; flex: 1; min-width: 200px; }
.search-box input { padding-left: 36px; background: var(--surface); }
.search-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; color: var(--text3); pointer-events: none; }

/* ═══ PAGE HEADER ═══ */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; flex-wrap: wrap; gap: 12px; }
.page-header-title { font-family: 'Fraunces', serif; font-size: 22px; font-weight: 700; color: var(--text); letter-spacing: -.3px; }
.page-header-sub { font-size: 13px; color: var(--text3); margin-top: 3px; }

/* ═══ EMPTY STATE ═══ */
.empty-state { text-align: center; padding: 52px 20px; }
.empty-state-icon { width: 60px; height: 60px; border-radius: 16px; background: var(--indigo-light); border: 1px solid rgba(79,110,247,.15); display: flex; align-items: center; justify-content: center; margin: 0 auto 16px; color: var(--indigo); }
.empty-state-icon svg { width: 26px; height: 26px; }
.empty-state h4 { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.empty-state p  { font-size: 13px; color: var(--text3); }

/* ═══ NAV DROPDOWN ═══ */
.nav-dropdown { position: relative; }
.nav-dropdown-toggle {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--r-sm);
  color: var(--sb-text); font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all .18s; margin-bottom: 2px;
  text-decoration: none; position: relative; width: 100%;
  background: transparent; border: none; font-family: 'DM Sans', sans-serif;
}
.nav-dropdown-toggle:hover { background: var(--sb-bg2); }
.nav-dropdown-toggle:hover .nav-icon { color: #7AAEFF; }
.nav-dropdown-toggle.active { background: var(--sb-active); font-weight: 600; color: #fff; }
.nav-dropdown-toggle.active::before { content: ''; position: absolute; left: 0; top: 22%; bottom: 22%; width: 3px; border-radius: 0 3px 3px 0; background: linear-gradient(to bottom, #7AAEFF, #4F6EF7); box-shadow: 0 0 10px rgba(79,110,247,.6); }
.nav-dropdown-toggle.active .nav-icon { color: #A5BFFF; }
.nav-dropdown-arrow {
  margin-left: auto; width: 14px; height: 14px; color: var(--sb-text2);
  transition: transform .22s cubic-bezier(.4,0,.2,1); flex-shrink: 0;
}
.nav-dropdown-arrow svg { width: 100%; height: 100%; display: block; }
.nav-dropdown.open .nav-dropdown-arrow { transform: rotate(180deg); }
.nav-dropdown-menu {
  overflow: hidden;
  max-height: 0;
  transition: max-height .26s cubic-bezier(.4,0,.2,1), opacity .22s;
  opacity: 0;
  padding-left: 14px;
}
.nav-dropdown.open .nav-dropdown-menu { max-height: 300px; opacity: 1; }
.nav-sub-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 12px; border-radius: var(--r-sm);
  color: var(--sb-text2); font-size: 12.5px; font-weight: 500;
  cursor: pointer; transition: all .15s; margin-bottom: 1px;
  text-decoration: none; position: relative;
}
.nav-sub-item::before {
  content: ''; position: absolute; left: -2px; top: 50%; transform: translateY(-50%);
  width: 1.5px; height: 60%; background: rgba(255,255,255,.12); border-radius: 99px;
}
.nav-sub-item:hover { background: var(--sb-bg2); color: #fff; }
.nav-sub-item:hover .nav-sub-dot { background: #7AAEFF; }
.nav-sub-item.active { background: rgba(79,110,247,.2); color: #A5BFFF; font-weight: 600; }
.nav-sub-item.active .nav-sub-dot { background: #4F6EF7; box-shadow: 0 0 6px rgba(79,110,247,.7); }
.nav-sub-dot { width: 6px; height: 6px; border-radius: 50%; background: rgba(255,255,255,.25); flex-shrink: 0; transition: background .15s; }
.nav-sub-icon { width: 15px; height: 15px; flex-shrink: 0; color: inherit; opacity: .7; }
.nav-sub-icon svg { width: 100%; height: 100%; display: block; }
.summary-bar { background: linear-gradient(135deg, #F0F4FF, #E8EDFF); border: 1px solid rgba(79,110,247,.2); border-radius: var(--r); padding: 13px 18px; display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 8px; }
.summary-bar-text   { font-weight: 500; color: var(--indigo); font-size: 13.5px; }
.summary-bar-amount { font-family: 'DM Mono', monospace; font-weight: 500; color: var(--indigo); font-size: 15.5px; letter-spacing: -.5px; }

/* ═══ INFO GRID ═══ */
.info-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 12px; margin-bottom: 20px; }
.info-box { border-radius: var(--r-sm); padding: 14px; text-align: center; border: 1px solid var(--border); background: var(--bg); }
.info-box-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .8px; color: var(--text3); margin-bottom: 6px; }
.info-box-val { font-family: 'DM Mono', monospace; font-size: 16px; font-weight: 500; letter-spacing: -.5px; }

/* ═══ UTILITIES ═══ */
.surface2 { background: var(--surface2); }

/* ═══ TOAST ═══ */
#toastBox { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { background: var(--text); color: #fff; padding: 11px 18px; border-radius: 10px; font-size: 13px; font-weight: 500; box-shadow: 0 4px 20px rgba(20,30,60,.22); animation: toastIn .28s cubic-bezier(.4,0,.2,1) both; max-width: 360px; pointer-events: auto; }
@keyframes toastIn { from { opacity:0; transform:translateY(12px) scale(.96); } to { opacity:1; transform:translateY(0) scale(1); } }

/* ═══ MOBILE ═══ */
.sb-overlay { display: none; position: fixed; inset: 0; background: rgba(20,30,60,.5); z-index: 99; backdrop-filter: blur(3px); }
@media(max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(30,45,78,.3); }
  .sb-overlay.open { display: block; }
  .topbar { margin-left: 0; padding: 0 16px; }
  .content { margin-left: 0; padding: 18px 14px 48px; }
  .btn-hamburger { display: flex; }
  .topbar-hi, .topbar-chip, .topbar-sep, .topbar-kelas-chip { display: none !important; }
  .info-grid { grid-template-columns: 1fr 1fr; }
  .form-row  { grid-template-columns: 1fr; }
}
</style>
</head>
<body>

<div class="sb-overlay" id="sbOverlay" onclick="sbToggle()"></div>
<div id="toastBox"></div>

<!-- ═══ SIDEBAR ═══ -->
<aside class="sidebar" id="sidebar">
  <div class="sidebar-brand">
    <?php if($_hasLogo): ?>
      <img src="<?= e($_logoUrl) ?>" alt="logo"
           style="width:38px;height:38px;border-radius:10px;object-fit:contain;background:rgba(255,255,255,.12);padding:4px;border:1px solid rgba(255,255,255,.15);flex-shrink:0"
           onerror="this.style.display='none';document.getElementById('sbFallback').style.display='flex'">
      <span id="sbFallback" style="display:none" class="brand-mark"><?= $svgIcons['admin'] ?></span>
    <?php else: ?>
      <div class="brand-mark"><?= $svgIcons['admin'] ?></div>
    <?php endif ?>
    <div style="min-width:0">
      <div class="brand-name" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:168px"><?= e($_namaSekolah) ?></div>
      <div class="brand-sub">Sistem Pembayaran</div>
    </div>
  </div>

  <nav class="sidebar-nav">
    <?php
    $_jumlahKelas = 0;
    try { $_jumlahKelas = (int)$pdo->query("SELECT COUNT(*) FROM kelas WHERE status='aktif'")->fetchColumn(); } catch(Exception $e) {}
    $_jumlahAlumni = 0;
    try { $_jumlahAlumni = (int)$pdo->query("SELECT COUNT(*) FROM alumni")->fetchColumn(); } catch(Exception $e) {}
    ?>
    <?php foreach($navGroups as $gLabel => $keys): ?>
    <div class="nav-section"><?= $gLabel ?></div>
    <?php foreach($keys as $k):
      if(!isset($nav[$k]) && $k !== '_tagihan_group' && $k !== '_siswa_group' && $k !== '_manajemen_group') continue;

      /* ── SISWA DROPDOWN GROUP ── */
      if ($k === '_siswa_group'):
        $siswaPages    = ['siswa','riwayat_siswa','alumni'];
        $isSiswaActive = in_array($pageNow, $siswaPages);
        $isSiswaOpen   = $isSiswaActive;
      ?>
      <div class="nav-dropdown <?= $isSiswaOpen ? 'open' : '' ?>" id="navSiswaGroup">
        <button class="nav-dropdown-toggle <?= $isSiswaActive ? 'active' : '' ?>"
                onclick="navDropToggle('navSiswaGroup')">
          <span class="nav-icon">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></svg>
          </span>
          <span>Data Siswa</span>
          <span class="nav-dropdown-arrow">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg>
          </span>
        </button>
        <div class="nav-dropdown-menu">
          <a href="index.php?page=siswa" class="nav-sub-item <?= $pageNow==='siswa'?'active':'' ?>">
            <span class="nav-sub-dot"></span>
            <span class="nav-sub-icon">
              <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/></svg>
            </span>
            <span>Data Siswa</span>
          </a>
          <a href="index.php?page=riwayat_siswa" class="nav-sub-item <?= $pageNow==='riwayat_siswa'?'active':'' ?>">
            <span class="nav-sub-dot"></span>
            <span class="nav-sub-icon">
              <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/><line x1="10" y1="9" x2="8" y2="9"/></svg>
            </span>
            <span>Riwayat Siswa</span>
          </a>
          <a href="index.php?page=alumni" class="nav-sub-item <?= $pageNow==='alumni'?'active':'' ?>">
            <span class="nav-sub-dot"></span>
            <span class="nav-sub-icon">
              <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M22 10v6M2 10l10-5 10 5-10 5z"/><path d="M6 12v5c3 3 9 3 12 0v-5"/></svg>
            </span>
            <span>Data Alumni<?php if($_jumlahAlumni > 0): ?> <span class="nav-kelas-badge" style="background:rgba(139,92,246,.3);color:#DDD6FE;margin-left:4px"><?= $_jumlahAlumni ?></span><?php endif ?></span>
          </a>
        </div>
      </div>
      <?php continue; endif;

      /* ── MANAJEMEN DROPDOWN GROUP ── */
      if ($k === '_manajemen_group'):
        $manajemenPages   = ['pengaturan','admin','users'];
        $isMnjActive = in_array($pageNow, $manajemenPages);
        $isMnjOpen   = $isMnjActive;
      ?>
      <div class="nav-dropdown <?= $isMnjOpen ? 'open' : '' ?>" id="navManjGroup">
        <button class="nav-dropdown-toggle <?= $isMnjActive ? 'active' : '' ?>"
                onclick="navDropToggle('navManjGroup')">
          <span class="nav-icon">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></svg>
          </span>
          <span>Manajemen</span>
          <span class="nav-dropdown-arrow">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg>
          </span>
        </button>
        <div class="nav-dropdown-menu">
          <!-- Pengaturan -->
          <a href="index.php?page=pengaturan" class="nav-sub-item <?= $pageNow==='pengaturan'?'active':'' ?>">
            <span class="nav-sub-dot"></span>
            <span class="nav-sub-icon">
              <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>
            </span>
            <span>Pengaturan</span>
          </a>
          <!-- Kelola Admin -->
          <a href="index.php?page=admin" class="nav-sub-item <?= $pageNow==='admin'?'active':'' ?>">
            <span class="nav-sub-dot"></span>
            <span class="nav-sub-icon">
              <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></svg>
            </span>
            <span>Kelola Admin</span>
          </a>
          <!-- Users Siswa -->
          <a href="index.php?page=users" class="nav-sub-item <?= $pageNow==='users'?'active':'' ?>">
            <span class="nav-sub-dot"></span>
            <span class="nav-sub-icon">
              <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg>
            </span>
            <span>Users Siswa</span>
          </a>
        </div>
      </div>
      <?php continue; endif;
      if ($k === '_tagihan_group'):
        $tagihanPages = ['tagihan','pembayaran','riwayat'];
        $isTagActive  = in_array($pageNow, $tagihanPages);
        $isOpen       = $isTagActive;
      ?>
      <div class="nav-dropdown <?= $isOpen ? 'open' : '' ?>" id="navTagihanGroup">
        <button class="nav-dropdown-toggle <?= $isTagActive ? 'active' : '' ?>"
                onclick="navDropToggle('navTagihanGroup')">
          <span class="nav-icon">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
              <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/>
              <polyline points="14 2 14 8 20 8"/>
              <line x1="16" y1="13" x2="8" y2="13"/>
              <line x1="16" y1="17" x2="8" y2="17"/>
            </svg>
          </span>
          <span>Tagihan SPP</span>
          <span class="nav-dropdown-arrow">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg>
          </span>
        </button>
        <div class="nav-dropdown-menu">
          <!-- Tagihan -->
          <a href="index.php?page=tagihan" class="nav-sub-item <?= $pageNow==='tagihan'?'active':'' ?>">
            <span class="nav-sub-dot"></span>
            <span class="nav-sub-icon">
              <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
                <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/>
                <polyline points="14 2 14 8 20 8"/>
                <line x1="16" y1="13" x2="8" y2="13"/>
                <line x1="16" y1="17" x2="8" y2="17"/>
              </svg>
            </span>
            <span>Tagihan SPP</span>
          </a>
          <!-- Pembayaran -->
          <a href="index.php?page=pembayaran" class="nav-sub-item <?= $pageNow==='pembayaran'?'active':'' ?>">
            <span class="nav-sub-dot"></span>
            <span class="nav-sub-icon">
              <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
                <rect x="1" y="4" width="22" height="16" rx="2"/>
                <line x1="1" y1="10" x2="23" y2="10"/>
              </svg>
            </span>
            <span>Pembayaran</span>
          </a>
          <!-- Riwayat -->
          <a href="index.php?page=riwayat" class="nav-sub-item <?= $pageNow==='riwayat'?'active':'' ?>">
            <span class="nav-sub-dot"></span>
            <span class="nav-sub-icon">
              <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
                <circle cx="12" cy="12" r="10"/>
                <polyline points="12 6 12 12 16 14"/>
              </svg>
            </span>
            <span>Riwayat</span>
          </a>
        </div>
      </div>
      <?php continue; endif;

      $isActive = ($pageNow === $k);
    ?>
    <a href="index.php?page=<?= $k ?>" class="nav-item<?= $isActive?' active':'' ?>">
      <span class="nav-icon"><?= $svgIcons[$k] ?? $svgIcons['dashboard'] ?></span>
      <span><?= $nav[$k]['label'] ?></span>
      <?php if($k === 'kelas' && $_jumlahKelas > 0): ?>
        <span class="nav-kelas-badge"><?= $_jumlahKelas ?></span>
      <?php endif ?>
      <?php if($k === 'alumni' && $_jumlahAlumni > 0): ?>
        <span class="nav-kelas-badge" style="background:rgba(139,92,246,.3);color:#DDD6FE"><?= $_jumlahAlumni ?></span>
      <?php endif ?>
    </a>
    <?php endforeach; endforeach ?>
  </nav>

  <div class="sidebar-footer" style="padding:12px 10px 16px;border-top:1px solid rgba(255,255,255,.08);position:relative;z-index:1;background:transparent;width:100%;box-sizing:border-box">
    <div style="display:flex;flex-direction:row;align-items:center;gap:10px;padding:10px 12px;border-radius:8px;background:rgba(255,255,255,.07);border:1px solid rgba(255,255,255,.08);overflow:hidden;width:100%;box-sizing:border-box">
      <?php
        $__fotoDir  = str_replace('\\','/',dirname(__DIR__)).'/uploads/foto_admin/';
        $__fotoUrl  = 'uploads/foto_admin/';
        $__hasFoto  = $fotoAdmin && file_exists($__fotoDir.$fotoAdmin);
      ?>
      <?php if($__hasFoto): ?>
        <img src="<?= e($__fotoUrl.$fotoAdmin) ?>" alt="foto"
             style="width:33px;height:33px;min-width:33px;max-width:33px;max-height:33px;border-radius:9px;object-fit:cover;flex-shrink:0;border:1.5px solid rgba(255,255,255,.2)">
      <?php else: ?>
        <div style="width:33px;height:33px;min-width:33px;max-width:33px;border-radius:9px;background:linear-gradient(135deg,#4F6EF7,#818CF8);display:flex;flex-direction:row;align-items:center;justify-content:center;font-size:14px;font-weight:700;color:#fff;flex-shrink:0"><?= mb_strtoupper(mb_substr($namaAdmin,0,1)) ?></div>
      <?php endif ?>
      <div style="flex:1;min-width:0;overflow:hidden">
        <div style="font-size:12.5px;font-weight:600;color:#ffffff;white-space:nowrap;overflow:hidden;text-overflow:ellipsis"><?= e($namaAdmin) ?></div>
        <div style="font-size:10px;color:rgba(255,255,255,.5);margin-top:1px;text-transform:capitalize"><?= e($roleAdmin) ?></div>
      </div>
      <div style="width:7px;height:7px;min-width:7px;border-radius:50%;flex-shrink:0;background:#4ADE80;box-shadow:0 0 7px rgba(74,222,128,.7)"></div>
    </div>
  </div>
</aside>

<!-- ═══ MAIN ═══ -->
<div style="flex:1;display:flex;flex-direction:column;min-width:0">

<header class="topbar">
  <div class="topbar-left">
    <button class="btn-hamburger" onclick="sbToggle()"><?= $svgIcons['menu'] ?></button>
    <div class="topbar-icon"><?= $svgIcons[$pageNow] ?? $svgIcons['dashboard'] ?></div>
    <div style="display:flex;align-items:center;gap:3px">
      <span class="topbar-crumb-root"><?= e($_namaSekolah) ?></span>
      <span class="topbar-crumb-sep">/</span>
      <span class="topbar-crumb-page"><?= $pageLabels[$pageNow] ?? ucfirst($pageNow) ?></span>
    </div>
    <?php if($pageNow === 'kelas'): ?>
    <div class="topbar-kelas-chip" style="margin-left:8px">
      🏫 <?= $_jumlahKelas ?> kelas aktif
    </div>
    <?php endif ?>
    <?php if($pageNow === 'siswa'): ?>
    <a href="index.php?page=kelas"
       style="margin-left:8px;display:inline-flex;align-items:center;gap:5px;
              background:#EDE9FE;border:1px solid #C4B5FD;color:#5B21B6;
              border-radius:6px;padding:4px 10px;font-size:11.5px;font-weight:600;
              text-decoration:none;transition:background .15s"
       onmouseover="this.style.background='#DDD6FE'"
       onmouseout="this.style.background='#EDE9FE'">
      🏫 Kelola Kelas
    </a>
    <?php endif ?>
  </div>
  <div class="topbar-right">
    <div class="topbar-chip">
      <?= $svgIcons['calendar'] ?>
      <?php $hari=['Min','Sen','Sel','Rab','Kam','Jum','Sab']; echo $hari[date('w')].', '.date('d M Y'); ?>
    </div>
    <div class="topbar-sep"></div>
    <span class="topbar-hi">Halo, <strong><?= e($namaAdmin) ?></strong></span>
    <div class="topbar-sep"></div>
    <a href="index.php?page=logout">
      <button class="btn-logout"><?= $svgIcons['logout'] ?> Keluar</button>
    </a>
  </div>
</header>

<main class="content">

<script>
/* ── Nav Dropdown Toggle ── */
function navDropToggle(id) {
  var el = document.getElementById(id);
  if (el) el.classList.toggle('open');
}

/* ── Sidebar toggle ── */
function sbToggle() {
  document.getElementById('sidebar').classList.toggle('open');
  document.getElementById('sbOverlay').classList.toggle('open');
}

/* ── Modal helpers ── */
function openModal(id) {
  var el = document.getElementById(id);
  if (el) { el.classList.add('open'); document.body.style.overflow = 'hidden'; }
}
function closeModal(id) {
  var el = document.getElementById(id);
  if (el) { el.classList.remove('open'); document.body.style.overflow = ''; }
}
document.addEventListener('click', function(e) {
  if (e.target.classList.contains('modal-overlay')) {
    e.target.classList.remove('open');
    document.body.style.overflow = '';
  }
});
document.addEventListener('keydown', function(e) {
  if (e.key === 'Escape') {
    document.querySelectorAll('.modal-overlay.open').forEach(function(m) {
      m.classList.remove('open');
    });
    document.body.style.overflow = '';
  }
});

/* ── Toast helper ── */
function showToast(msg, duration) {
  duration = duration || 3200;
  var box  = document.getElementById('toastBox');
  var t    = document.createElement('div');
  t.className   = 'toast';
  t.textContent = msg;
  box.appendChild(t);
  setTimeout(function() {
    t.style.transition = 'opacity .3s, transform .3s';
    t.style.opacity    = '0';
    t.style.transform  = 'translateY(8px)';
    setTimeout(function() { t.remove(); }, 320);
  }, duration);
}
</script>