<?php
$menu = $menu ?? '';
$nama = $_SESSION['nama'] ?? '';
$initial = strtoupper(substr($nama,0,1));
?>

<style>
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600;700&display=swap');

:root{
    --green-50:#f0fdf4;
    --green-100:#dcfce7;
    --green-200:#bbf7d0;
    --green-500:#22c55e;
    --green-600:#16a34a;
    --green-700:#15803d;

    --sidebar-w:250px;
    --topbar-h:60px;

    --surface:#f8fafc;
    --surface-1:#ffffff;

    --text-dark:#111827;
    --text-muted:#6b7280;
}

body{
    overflow-x:hidden;
}

/* =========================
   OVERLAY MOBILE
========================= */

.sidebar-overlay{
    position:fixed;
    inset:0;
    background:rgba(0,0,0,.35);
    z-index:150;
    opacity:0;
    visibility:hidden;
    transition:.3s;
}

.sidebar-overlay.show{
    opacity:1;
    visibility:visible;
}

/* =========================
   SIDEBAR
========================= */

.sidebar{
    position:fixed;
    left:0;
    top:0;
    width:var(--sidebar-w);
    height:100vh;
    background:#fff;
    border-right:1px solid var(--green-100);
    z-index:200;
    display:flex;
    flex-direction:column;
    transition:.3s;
    box-shadow:0 2px 12px rgba(0,0,0,.05);
}

.sidebar-brand{
    padding:24px 18px;
    text-align:center;
    border-bottom:1px solid var(--green-100);
    background:linear-gradient(
        180deg,
        #f0fdf4 0%,
        #ffffff 100%
    );
    position:relative;
}

.sidebar-brand-icon{
    width:55px;
    height:55px;
    border-radius:15px;
    background:linear-gradient(
        135deg,
        var(--green-600),
        var(--green-500)
    );
    display:flex;
    align-items:center;
    justify-content:center;
    color:#fff;
    font-size:24px;
    margin:auto;
    margin-bottom:10px;
}

.sidebar-brand-name{
    font-size:.9rem;
    font-weight:700;
    color:var(--green-700);
    letter-spacing:.08em;
    text-transform:uppercase;
}

.sidebar-brand-role{
    font-size:.7rem;
    color:var(--text-muted);
}

.sidebar-close{
    display:none;
    position:absolute;
    top:15px;
    right:15px;
    width:30px;
    height:30px;
    border:none;
    border-radius:8px;
    cursor:pointer;
    background:#f3f4f6;
}

/* =========================
   MENU
========================= */

.sidebar-nav{
    flex:1;
    padding:15px 10px;
    overflow-y:auto;
}

.nav-section-label{
    font-size:.7rem;
    text-transform:uppercase;
    color:#9ca3af;
    padding:0 10px;
    margin-bottom:10px;
}

.sidebar-nav a{
    display:flex;
    align-items:center;
    gap:10px;
    padding:10px 12px;
    border-radius:10px;
    margin-bottom:4px;
    color:#374151;
    text-decoration:none;
    transition:.2s;
}

.sidebar-nav a:hover{
    background:#f0fdf4;
    color:#15803d;
}

.sidebar-nav a.active{
    background:#dcfce7;
    border-left:4px solid #16a34a;
    color:#166534;
    font-weight:600;
}

.sidebar-nav a:hover{
    background:var(--green-50);
    color:var(--green-700);
}

.sidebar-nav a.active{
    background:var(--green-50);
    color:var(--green-700);
    border:1px solid var(--green-200);
    font-weight:600;
}

.sidebar-nav a.active::before{
    content:'';
    position:absolute;
    left:0;
    top:20%;
    bottom:20%;
    width:4px;
    background:var(--green-600);
    border-radius:0 4px 4px 0;
}

.nav-icon{
    width:30px;
    height:30px;
    border-radius:8px;
    background:#f0fdf4;
    display:flex;
    align-items:center;
    justify-content:center;
    font-size:14px;
    flex-shrink:0;
}

/* =========================
   FOOTER
========================= */

.sidebar-footer{
    padding:15px;
    border-top:1px solid var(--green-100);
}

.sidebar-footer a{
    display:flex;
    align-items:center;
    gap:12px;
    padding:12px;
    border-radius:10px;
    color:#dc2626;
    text-decoration:none;
}

.sidebar-footer a:hover{
    background:#fef2f2;
}

/* =========================
   CONTENT
========================= */

.content{
    margin-left:var(--sidebar-w);
    min-height:100vh;
    background:#f8fafc;
}

/* =========================
   TOPBAR
========================= */

.topbar{
    height:var(--topbar-h);
    background:#fff;
    border-bottom:1px solid var(--green-100);
    display:flex;
    justify-content:space-between;
    align-items:center;
    padding:0 25px;
}

.topbar-left{
    display:flex;
    align-items:center;
    gap:12px;
}

.sidebar-toggle{
    display:none;
    width:38px;
    height:38px;
    border:none;
    border-radius:8px;
    background:var(--green-50);
    cursor:pointer;
}

.topbar-title{
    font-size:1rem;
    font-weight:700;
}

.topbar-user{
    display:flex;
    align-items:center;
    gap:10px;
    background:var(--green-50);
    border:1px solid var(--green-100);
    border-radius:999px;
    padding:6px 14px;
}

.topbar-avatar{
    width:30px;
    height:30px;
    border-radius:50%;
    background:var(--green-600);
    color:#fff;
    display:flex;
    align-items:center;
    justify-content:center;
    font-weight:700;
}

.badge-role{
    color:var(--green-700);
    font-size:.75rem;
    font-weight:600;
}

/* =========================
   MOBILE
========================= */

@media(max-width:768px){

    .sidebar{
        transform:translateX(-100%);
    }

    .sidebar.open{
        transform:translateX(0);
    }

    .sidebar-close{
        display:block;
    }

    .sidebar-toggle{
        display:block;
    }

    .content{
        margin-left:0;
    }

    .topbar{
        padding:0 15px;
    }

    .topbar-title{
        font-size:.9rem;
    }

    .badge-role{
        display:none;
    }
}
</style>

<div class="sidebar-overlay" id="sidebarOverlay"></div>

<div class="sidebar" id="sidebar">

    <div class="sidebar-brand">

        <button class="sidebar-close" id="sidebarClose">
            ✕
        </button>

        <div class="sidebar-brand-icon">
            🏢
        </div>

        <div class="sidebar-brand-name">
            Direktur
        </div>

        <div class="sidebar-brand-role">
            Panel Manajemen
        </div>

    </div>

    <div class="sidebar-nav">

        <div class="nav-section-label">
            Menu Utama
        </div>

        <a href="dashboard.php" class="<?= $menu=='dashboard' ? 'active' : '' ?>">
            <span class="nav-icon">📊</span>
            Dashboard
        </a>
        <a href="users.php" class="<?= ($menu ?? '') == 'users'      ? 'active' : '' ?>">
          <span class="nav-icon">👤</span> Data User
        </a>

        <a href="monitoring.php" class="<?= $menu=='monitoring' ? 'active' : '' ?>">
            <span class="nav-icon">👁️</span>
            Monitoring
        </a>

        <a href="laporan.php" class="<?= $menu=='laporan' ? 'active' : '' ?>">
            <span class="nav-icon">📈</span>
            Laporan
        </a>

        <a href="checklist.php" class="<?= $menu=='checklist' ? 'active' : '' ?>">
            <span class="nav-icon">📝</span>
            Checklist
        </a>

        <a href="persetujuan_checklist.php" class="<?= $menu=='persetujuan' ? 'active' : '' ?>">
            <span class="nav-icon">✅</span>
            Persetujuan Checklist
        </a>

        <a href="/checklist_harian_harita/direktur/urgent_list.php">
            🚨 Urgent
        </a>

    </div>

    <div class="sidebar-footer">
        <a href="../logout.php">
            <span class="nav-icon">🚪</span>
            Logout
        </a>
    </div>

</div>

<div class="content">

    <div class="topbar">

        <div class="topbar-left">

            <button class="sidebar-toggle" id="sidebarToggle">
                ☰
            </button>

            <div class="topbar-title">
                <?= $judul ?? 'Dashboard' ?>
            </div>

        </div>

        <div class="topbar-user">

            <div class="topbar-avatar">
                <?= $initial ?>
            </div>

            <span>
                <?= htmlspecialchars($nama) ?>
            </span>

        </div>

    </div>

    <div class="container-fluid p-3">