<?php
require_once __DIR__ . '/../../config/secure_bootstrap.php';
$site_name = getSettingValue('site_name', $pdo);
?>
<!DOCTYPE html>
<html lang="id">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title><?= e($_ENV['APP_NAME']) ?> - Admin Panel</title>

  <!-- Bootstrap & FontAwesome CDN -->
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
  <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css" rel="stylesheet">

  <!-- SweetAlert2 -->
  <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

  <style>
    :root {
      --hijau: #084D36;
      --coklat: #CC9933;
      --cream: #FFFF99;
    }

    body {
      background-color: #f7f9f8;
      font-family: 'Segoe UI', sans-serif;
      overflow-x: hidden;
    }

    /* ===== SIDEBAR ===== */
    .sidebar {
      width: 250px;
      height: 100vh;
      position: fixed;
      left: 0;
      top: 0;
      background-color: var(--hijau);
      color: #fff;
      transition: all 0.3s ease;
      z-index: 999;
    }

    .sidebar.collapsed {
      width: 70px;
    }

    .sidebar-header {
      padding: 20px;
      background: rgba(0,0,0,0.2);
      text-align: center;
      border-bottom: 1px solid rgba(255,255,255,0.1);
      transition: all 0.3s ease;
    }

    .sidebar-header h4 {
      margin: 0;
      font-size: 1.3rem;
      white-space: nowrap;
    }

    .sidebar-header small {
      display: block;
      font-size: 0.8rem;
      opacity: 0.8;
    }

    .sidebar.collapsed .sidebar-header h4,
    .sidebar.collapsed .sidebar-header small {
      display: none;
    }

    .sidebar.collapsed .sidebar-header::before {
      content: "\f132";
      font-family: "Font Awesome 6 Free";
      font-weight: 900;
      font-size: 1.5rem;
      color: var(--cream);
      display: inline-block;
    }

    /* Menu List */
    .sidebar ul {
      list-style: none;
      padding: 0;
      margin: 0;
    }

    .sidebar ul li a {
      display: flex;
      align-items: center;
      padding: 12px 20px;
      color: #fff;
      text-decoration: none;
      transition: all 0.3s ease;
      white-space: nowrap;
      position: relative;
    }

    .sidebar ul li a:hover,
    .sidebar ul li a.active {
      background-color: var(--coklat);
      color: #fff;
    }

    .sidebar ul li a i {
      min-width: 25px;
      text-align: center;
      font-size: 1.1rem;
      margin-right: 10px;
      transition: margin 0.3s;
    }

    .sidebar.collapsed ul li a span {
      display: none;
    }

    .sidebar.collapsed ul li a i {
      margin-right: 0;
      font-size: 1.3rem;
    }

    /* Tooltip on collapsed mode */
    .sidebar.collapsed ul li a::after {
      content: attr(data-title);
      position: absolute;
      left: 80px;
      background: var(--hijau);
      color: #fff;
      padding: 5px 10px;
      border-radius: 5px;
      font-size: 0.85rem;
      opacity: 0;
      visibility: hidden;
      transition: all 0.2s;
      white-space: nowrap;
    }

    .sidebar.collapsed ul li a:hover::after {
      opacity: 1;
      visibility: visible;
      left: 75px;
      z-index: 1000;
    }

    /* ===== TOPBAR ===== */
    .topbar {
      height: 60px;
      background: #fff;
      padding: 0 20px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      position: fixed;
      left: 250px;
      right: 0;
      top: 0;
      border-bottom: 2px solid var(--coklat);
      transition: all 0.3s ease;
      z-index: 998;
    }

    .sidebar.collapsed ~ .topbar {
      left: 70px;
    }

    .topbar .toggle-btn {
      background: none;
      border: none;
      font-size: 1.5rem;
      color: var(--hijau);
    }

    .topbar .user-info {
      display: flex;
      align-items: center;
      gap: 10px;
      font-weight: 500;
    }

    /* ===== MAIN CONTENT ===== */
    .main-content {
      margin-left: 250px;
      padding: 80px 25px 40px;
      transition: all 0.3s ease;
    }

    .sidebar.collapsed ~ .main-content {
      margin-left: 70px;
    }

    /* ===== MOBILE ===== */
    @media (max-width: 992px) {
      .sidebar {
        left: -250px;
      }
      .sidebar.active {
        left: 0;
      }
      .topbar {
        left: 0;
      }
      .main-content {
        margin-left: 0;
      }
    }

    .overlay {
      display: none;
      position: fixed;
      top: 0; left: 0; right: 0; bottom: 0;
      background: rgba(0,0,0,0.4);
      z-index: 998;
    }

    .overlay.active {
      display: block;
    }
    
    /* submenu styling */
.submenu {
  display: none;
  list-style: none;
  padding-left: 20px;
}
.has-submenu.open > .submenu {
  display: block;
}
.submenu a {
  display: block;
  padding: 6px 10px;
  color: #ddd;
  font-size: 0.9rem;
}
.submenu a.active {
  color: #00b894;
  font-weight: 600;
}
.submenu-caret {
  float: right;
  transition: 0.3s;
}
.has-submenu.open .submenu-caret {
  transform: rotate(90deg);
}
  </style>
</head>
<body>

<!-- Sidebar -->
<div class="sidebar" id="sidebar">
  <div class="sidebar-header">
    <h4><i class="fa-solid fa-shield-halved me-2"></i>LPM UNIRU</h4>
    <small>Admin Panel</small>
  </div>

  <ul>
    <!-- Dashboard -->
    <li>
      <a href="index.php" class="<?= basename($_SERVER['PHP_SELF'])=='index.php'?'active':'' ?>">
        <i class="fa-solid fa-gauge"></i><span>Dashboard</span>
      </a>
    </li>

    <!-- SPMI (submenu) -->
    <li class="has-submenu <?= in_array(basename($_SERVER['PHP_SELF']), [
      'spmi_cycles.php',
      'spmi_standards.php',
      'spmi_ppepp.php',
      'spmi_actions.php',
      'spmi_evidences.php'
    ]) ? 'active open' : '' ?>">
      <a href="#" class="submenu-toggle">
        <i class="fa-solid fa-recycle"></i><span>SPMI (PPEPP)</span>
        <i class="fa-solid fa-angle-right submenu-caret"></i>
      </a>
      <ul class="submenu">
        <li><a href="spmi_cycles.php" class="<?= basename($_SERVER['PHP_SELF'])=='spmi_cycles.php'?'active':'' ?>">
          <i class="fa-regular fa-circle me-2"></i>Siklus SPMI</a></li>
        <li><a href="spmi_standards.php" class="<?= basename($_SERVER['PHP_SELF'])=='spmi_standards.php'?'active':'' ?>">
          <i class="fa-regular fa-circle me-2"></i>Standar Mutu</a></li>
        <li><a href="spmi_ppepp.php" class="<?= basename($_SERVER['PHP_SELF'])=='spmi_ppepp.php'?'active':'' ?>">
          <i class="fa-regular fa-circle me-2"></i>Tahapan PPEPP</a></li>
        <li><a href="spmi_actions.php" class="<?= basename($_SERVER['PHP_SELF'])=='spmi_actions.php'?'active':'' ?>">
          <i class="fa-regular fa-circle me-2"></i>Peningkatan Mutu</a></li>
        <li><a href="spmi_evidences.php" class="<?= basename($_SERVER['PHP_SELF'])=='spmi_evidences.php'?'active':'' ?>">
          <i class="fa-regular fa-circle me-2"></i>Bukti SPMI</a></li>
      </ul>
    </li>

    <!-- Dokumen Mutu -->
    <!--<li class="has-submenu <?= in_array(basename($_SERVER['PHP_SELF']), ['dokumen.php','dokumen_version.php']) ? 'active open' : '' ?>">-->
    <!--  <a href="#" class="submenu-toggle">-->
    <!--    <i class="fa-solid fa-folder-open"></i><span>Dokumen Mutu</span>-->
    <!--    <i class="fa-solid fa-angle-right submenu-caret"></i>-->
    <!--  </a>-->
    <!--  <ul class="submenu">-->
    <!--    <li><a href="dokumen.php" class="<?= basename($_SERVER['PHP_SELF'])=='dokumen.php'?'active':'' ?>">-->
    <!--      <i class="fa-regular fa-circle me-2"></i>Daftar Dokumen</a></li>-->
    <!--    <li><a href="dokumen_version.php" class="<?= basename($_SERVER['PHP_SELF'])=='dokumen_version.php'?'active':'' ?>">-->
    <!--      <i class="fa-regular fa-circle me-2"></i>Versi Dokumen</a></li>-->
    <!--  </ul>-->
    <!--</li>-->
    
    <!-- Dokumen Mutu -->
    <li>
      <a href="dokumen.php" class="<?= basename($_SERVER['PHP_SELF'])=='dokumen.php'?'active':'' ?>" data-title="Dokumen">
        <i class="fa-regular fa-circle me-2"></i><span>Dokumen</span>
      </a>
    </li>
    
    <!-- pengumuman -->
    <li>
      <a href="pengumuman.php" class="<?= basename($_SERVER['PHP_SELF'])=='pengumuman.php'?'active':'' ?>" data-title="Pengumuman">
        <i class="fa-solid fa-bullhorn me-2"></i><span>Pengumuman</span>
      </a>
    </li>

    <!-- Kegiatan Mutu -->
    <li>
      <a href="kegiatan.php" class="<?= basename($_SERVER['PHP_SELF'])=='kegiatan.php'?'active':'' ?>">
        <i class="fa-solid fa-calendar-days"></i><span>Kegiatan</span>
      </a>
    </li>

    <!-- Audit Mutu Internal -->
    <li>
      <a href="audit.php" class="<?= basename($_SERVER['PHP_SELF'])=='audit.php'?'active':'' ?>">
        <i class="fa-solid fa-clipboard-check"></i><span>Audit Mutu Internal</span>
      </a>
    </li>

    <!-- Akreditasi -->
    <li>
      <a href="akreditasi.php" class="<?= basename($_SERVER['PHP_SELF'])=='akreditasi.php'?'active':'' ?>">
        <i class="fa-solid fa-award"></i><span>SPME</span>
      </a>
    </li>
    
    <!-- Profil -->
    <li>
      <a href="profil.php" class="<?= basename($_SERVER['PHP_SELF'])=='profil.php'?'active':'' ?>">
        <i class="fas fa-building"></i><span>Profile LPM</span>
      </a>
    </li>

    <!-- Berita -->
    <li>
      <a href="berita.php" class="<?= basename($_SERVER['PHP_SELF'])=='berita.php'?'active':'' ?>">
        <i class="fa-solid fa-newspaper"></i><span>Berita</span>
      </a>
    </li>

    <!-- Pengguna -->
    <li>
      <a href="users.php" class="<?= basename($_SERVER['PHP_SELF'])=='users.php'?'active':'' ?>">
        <i class="fa-solid fa-users"></i><span>Pengguna</span>
      </a>
    </li>

    <!-- Pengaturan -->
    <li>
      <a href="settings.php" class="<?= basename($_SERVER['PHP_SELF'])=='settings.php'?'active':'' ?>">
        <i class="fa-solid fa-gear"></i><span>Pengaturan</span>
      </a>
    </li>

    <!-- Logout -->
    <li><a href="#" id="logoutBtn">
      <i class="fa-solid fa-right-from-bracket"></i><span>Keluar</span></a></li>
  </ul>
</div>

  <!-- Overlay (mobile) -->
  <div class="overlay" id="overlay"></div>

  <!-- Topbar -->
  <div class="topbar" id="topbar">
    <button class="toggle-btn" id="toggleSidebar"><i class="fa-solid fa-bars"></i></button>
    <div class="user-info">
      <i class="fa-solid fa-user-circle text-warning"></i>
      <?= e($_SESSION['full_name']) ?>
    </div>
  </div>

  <!-- Main Content -->
  <main class="main-content">
