<?php
// Include permissions bootstrap at the top
require_once __DIR__ . '/auth_bootstrap.php';

// default.php — Landing dashboard after successful login
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}


// Simple auth gate
if (!isset($_SESSION['auth'])) {
header('Location: index.php');
exit;
}


$user = $_SESSION['auth'];
$name = $user['username'] ?? 'User';
$email = $user['email'] ?? '';
$role = $user['role'] ?? 'user';
$roleId = (int)($user['roleid'] ?? 0);
$isSuper = !empty($user['is_superadmin']);

?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>Ebonyi State Land Information Management System</title>
  <style>
:root{
/* DARK THEME (default) */
--bg:#0f172a; /* sidebar */
--bg-soft:#111827; /* header */
--panel:#0b1220; /* hover/panels */
--text:#e5e7eb; /* body text */
--muted:#9ca3af; /* secondary text */
--accent:#22c55e; /* emerald */
--accent-2:#60a5fa; /* blue */
--ring: rgba(34,197,94,.35);
--surface:#0b1020;
--content:#0b0f19;
--border:#1f2937;
--white:#ffffff;
--btn-bg:#0e1628;
--iframe-bg:#0a0f1a;
--app-bg: radial-gradient(1200px 600px at 10% -10%, rgba(34,197,94,.08), transparent 60%),
radial-gradient(1000px 500px at 110% 10%, rgba(96,165,250,.08), transparent 60%),
linear-gradient(180deg, #0b0f19 0%, #0b1220 100%);
--hover-fg: var(--white);
}
:root[data-theme="light"]{
/* LIGHT THEME OVERRIDES */
--bg:#f8fafc; /* sidebar */
--bg-soft:#ffffff; /* header */
--panel:#f1f5f9; /* hover/panels */
--text:#0f172a; /* body text */
--muted:#475569; /* secondary text */
--accent:#16a34a;
--accent-2:#2563eb;
--ring: rgba(37,99,235,.35);
--surface:#ffffff;
--content:#ffffff;
--border:#e5e7eb;
--white:#ffffff;
--btn-bg:#ffffff;
--iframe-bg:#ffffff;
--app-bg: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
--hover-fg: var(--text);
}


*{box-sizing:border-box}
html,body{height:100%}
body{
margin:0;
font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
color:var(--text);
background:var(--app-bg);
}
.app{
display:grid;
grid-template-columns: 300px 1fr;
grid-template-rows: 64px 1fr;
grid-template-areas:
"sidebar header"
"sidebar main";
height:100vh;
overflow:hidden;
}
header{
grid-area:header;
display:flex;align-items:center;gap:12px;justify-content:space-between;
padding:0 16px;
background:var(--bg-soft);
border-bottom:1px solid var(--border);
}
header .brand{display:flex;align-items:center;gap:12px}
header .brand img{height:36px;width:36px;border-radius:6px;object-fit:contain}
header .title{font-weight:700;letter-spacing:.2px}
header .actions{display:flex;gap:8px}
.btn{appearance:none;border:1px solid var(--border);background:var(--btn-bg);color:var(--text);padding:8px 12px;border-radius:10px;cursor:pointer}
.btn:hover{border-color:#2b3a55}


aside{
grid-area:sidebar;
background:var(--bg);
border-right:1px solid var(--border);
overflow:auto;
}
.sidebar-header{display:flex;align-items:center;gap:10px;padding:14px 16px;border-bottom:1px solid var(--border)}
.sidebar-header .dash-link{display:flex;align-items:center;gap:10px;text-decoration:none;color:var(--text);font-weight:800;width:100%}
.sidebar-header .dash-link img{height:34px;width:34px;border-radius:6px;object-fit:contain}
.sidebar-header .dash-link span{font-size:16px}
.sidebar-header .dept{font-size:12px;color:var(--muted)}


.nav{padding:12px}
.nav-section{
border:1px solid var(--border);
background:rgba(255,255,255,.02);
margin:10px 0;
border-radius:14px;
overflow:hidden;
}
.nav-title{
display:flex;align-items:center;gap:10px;justify-content:space-between;
padding:12px 14px;cursor:pointer;
font-weight:600;letter-spacing:.2px;
background:linear-gradient(180deg, rgba(255,255,255,.02), rgba(255,255,255,.00));
}
.nav-title:hover{background:rgba(255,255,255,.05)}
.nav-title .left{display:flex;align-items:center;gap:10px}
.icon{width:18px;height:18px;display:inline-block;flex:0 0 auto;opacity:.9}


.group{display:none;border-top:1px solid var(--border)}
.group.open{display:block}


.menu{list-style:none;margin:0;padding:6px 0}
.menu > li > a{
display:flex;justify-content:space-between;align-items:center;
gap:8px;padding:10px 14px;text-decoration:none;color:var(--text);
border-radius:10px;margin:4px 8px;
}
.menu > li > a:hover{background:var(--panel)}
.submenu{list-style:none;margin:0;padding:4px 0 8px 0;display:none}
.submenu.open{display:block}
.submenu a{display:block;padding:8px 14px 8px 32px;color:var(--muted);text-decoration:none;border-radius:8px;margin:2px 8px}
.submenu a:hover{background:var(--panel);color:var(--hover-fg)}


.active{outline:2px solid var(--ring);outline-offset:0}


main{grid-area:main;position:relative;height:100%;display:flex;flex-direction:column}
.statusbar{height:36px;display:flex;align-items:center;gap:12px;padding:0 12px;background:rgba(255,255,255,.02);border-top:1px solid var(--border)}
iframe#work-area{border:0;flex:1 1 auto;width:100%;height:100%;background:var(--iframe-bg)}


/* utility */
.tag{font-size:11px;padding:2px 6px;border-radius:999px;border:1px solid var(--border);color:var(--muted)}
/* dashboard icon */
.sidebar-header .dash-link .dash-ico{display:inline-flex;align-items:center;justify-content:center;width:20px;height:20px;color:var(--accent-2);opacity:.95}
.sidebar-header .dash-link .dash-ico svg{width:20px;height:20px;stroke:currentColor;fill:none;stroke-width:1.8;vector-effect:non-scaling-stroke}
/* dashboard icon (image) */
.sidebar-header .dash-link .dash-ico-img{display:inline-block;width:20px;height:20px;object-fit:contain;opacity:.95}
</style>
</head>
<body>
  <div class="app">
    <aside>
      <div class="sidebar-header">
        <a href="dashboard.php" target="work-area" class="dash-link" title="Go to dashboard">

<img src="images/icons/dashboard.png" alt="" class="dash-ico-img" />
<span>Dashboard</span>
</a>
      </div>

      <nav class="nav" id="side-nav">
        
          
        <!-- PROPERTY -->
        <?php if (canp('nav.property.*')): ?>
        <section class="nav-section" data-section="property">
          <div class="nav-title">
            <div class="left"><span class="icon">📍</span> Property</div>
            <span class="tag">core</span>
          </div>
          <div class="group">
            <ul class="menu">
              <li>
                <a href="#" data-toggle-submenu>Property</a>
                <ul class="submenu">
                  <?php if (canp('nav.property.create.new_property')): ?><li><a href="pages/property/create_property.php" target="work-area">Create Property</a></li><?php endif; ?>
                  <?php if (canp('nav.property.create.new_card_entry')): ?><li><a href="property/create_from_old.php" target="work-area">New Card Entry</a></li><?php endif; ?>
                </ul>
              </li>

              <?php if (canp('nav.property.search')): ?>
              <li>
                <a href="#" data-toggle-submenu>Property Search</a>
                <ul class="submenu">
                  <?php if (canp('nav.property.search.old')): ?><li><a href="property/property_search_P.php?type=0&s=~" target="work-area">Old Property Search</a></li><?php endif; ?>
                  <?php if (canp('nav.property.search.new')): ?><li><a href="pages/property/new_search.php" target="work-area">New Property Search</a></li><?php endif; ?>
                </ul>
              </li>
              <?php endif; ?>

              <?php if (canp('nav.property.view')): ?>
              <li>
                <a href="#" data-toggle-submenu>Property View</a>
                <ul class="submenu">
                  <?php if (canp('nav.property.view.old_card')): ?><li><a href="property/process_view.php" target="work-area">View Old Property Card</a></li><?php endif; ?>
                  <?php if (canp('nav.property.view.property')): ?><li><a href="property/process_property_view.php" target="work-area">View Property</a></li><?php endif; ?>
                  <?php if (canp('nav.property.view.all_survey')): ?><li><a href="property/view_search_survey.php" target="work-area">View All Survey</a></li><?php endif; ?>
                  <?php if (canp('nav.property.view.survey_description')): ?><li><a href="property/print_survey_description.php" target="work-area">View Survey Description</a></li><?php endif; ?>
                  <?php if (canp('nav.property.view.abstract_book')): ?><li><a href="registry/process_registration_view.php" target="work-area">View Abstract Book</a></li><?php endif; ?>
                  <?php if (canp('nav.property.view.card_manager')): ?><li><a href="property/process_view.php?edit=1&s=~" target="work-area">Property Card Manager</a></li><?php endif; ?>
                  <?php if (canp('nav.property.view.layout')): ?><li><a href="property/process_layout_view.php?edit=1&s=~" target="work-area">View Layout</a></li><?php endif; ?>
                </ul>
              </li>
              <?php endif; ?>

              <?php if (canp('nav.property.survey')): ?>
              <li>
                <a href="#" data-toggle-submenu>Survey Details</a>
                <ul class="submenu">
                  <?php if (canp('nav.property.survey.details')): ?><li><a href="property/process_edit_survey.php" target="work-area">Details of Survey</a></li><?php endif; ?>
                  <?php if (canp('nav.property.survey.access_road')): ?><li><a href="property/process_edit_access.php" target="work-area">Land Access Road</a></li><?php endif; ?>
                  <?php if (canp('nav.property.survey.add_details')): ?><li><a href="property/process_add_details.php" target="work-area">Land Survey Details</a></li><?php endif; ?>
                </ul>
              </li>
              <?php endif; ?>

              <?php if (canp('nav.property.beacon')): ?>
              <li>
                <a href="#" data-toggle-submenu>Beacon Details</a>
                <ul class="submenu">
                  <?php if (canp('nav.property.beacon.add_coordinates')): ?><li><a href="property/upload_coordinates.php" target="work-area">Add New Coordinates</a></li><?php endif; ?>
                  <?php if (canp('nav.property.beacon.view_register')): ?><li><a href="property/process_coordinate_view.php" target="work-area">View Coordinate Register</a></li><?php endif; ?>
                  <?php if (canp('nav.property.beacon.map_beacon')): ?><li><a href="property/upload_coordinates_B.php" target="work-area">Map Beacon Coordinate</a></li><?php endif; ?>
                  <?php if (canp('nav.property.beacon.map_file_beacon')): ?><li><a href="property/upload_coordinates_C.php" target="work-area">Map File Beacon Coordinate</a></li><?php endif; ?>
                </ul>
              </li>
              <?php endif; ?>

              <?php if (canp('nav.property.delete')): ?>
                <li><a href="property/process_delete.php" target="work-area">Delete</a></li>
              <?php endif; ?>
            </ul>
          </div>
        </section>
        <?php endif; ?>

        <!-- FILES -->
        <?php if (canp('nav.files.*')): ?>
        <section class="nav-section" data-section="files">
          <div class="nav-title"><div class="left"><span class="icon">🗂️</span> Files</div></div>
          <div class="group">
            <ul class="menu">
              <li>
                <a href="#" data-toggle-submenu>New File</a>
                <ul class="submenu">
                  <?php if (canp('nav.files.new.create_new')): ?><li><a href="pages/file/new_file.php" target="work-area">Create New</a></li><?php endif; ?>
                  <?php if (canp('nav.files.new.create_new_recert_record')): ?><li><a href="file/file_form_Rec2.php" target="work-area">Create New Recert Record</a></li><?php endif; ?>
                  <?php if (canp('nav.files.new.create_new_record')): ?><li><a href="file/file_form_Rec.php" target="work-area">Create New Record</a></li><?php endif; ?>
                  <?php if (canp('nav.files.new.create_from_property')): ?><li><a href="file/file_form_P.php" target="work-area">Create From Property</a></li><?php endif; ?>
                  <?php if (canp('nav.files.new.create_temporary')): ?><li><a href="file/file_form_L.php" target="work-area">Create Temporary File</a></li><?php endif; ?>
                  <?php if (canp('nav.files.new.create_secondary')): ?><li><a href="file/file_form_secondary.php" target="work-area">Create Secondary File</a></li><?php endif; ?>
                  <?php if (canp('nav.files.new.convert_temporary')): ?><li><a href="file/convert_file.php" target="work-area">Convert Temporary File</a></li><?php endif; ?>
                  <?php if (canp('nav.files.new.create_subfile')): ?><li><a href="file/file_form_S.php" target="work-area">Create Sub-File</a></li><?php endif; ?>
                  <?php if (canp('nav.files.new.reallocation')): ?><li><a href="file/reallocation_form.php" target="work-area">Reallocation File</a></li><?php endif; ?>
                  <?php if (canp('nav.files.new.renewal')): ?><li><a href="file/renewal_form.php" target="work-area">Renewal File</a></li><?php endif; ?>
                </ul>
              </li>

              <li>
                <a href="#" data-toggle-submenu>View Files</a>
                <ul class="submenu">
                  <?php if (canp('nav.files.view.all')): ?><li><a href="pages/file/view_file.php" target="work-area">View All</a></li><?php endif; ?>
                  <?php if (canp('nav.files.view.deeds')): ?><li><a href="pages/file/document_list.php" target="work-area">View Document Files</a></li><?php endif; ?>
                  <?php if (canp('nav.files.view.recert')): ?><li><a href="file/process_view_R.php" target="work-area">View Recertification Files</a></li><?php endif; ?>
                </ul>
              </li>

              <li>
                <a href="#" data-toggle-submenu>Snapshot</a>
                <ul class="submenu">
                  <?php if (canp('nav.files.snapshot.recert')): ?><li><a href="file/process_snapshot.php?print=y&s=~" target="work-area">Re-certification</a></li><?php endif; ?>
                  <?php if (canp('nav.files.snapshot.registry')): ?><li><a href="file/process_snapshot_D.php?print=y&s=~" target="work-area">Registry</a></li><?php endif; ?>
                </ul>
              </li>

              <li>
                <a href="file/process_movementype.php" target="work-area">File Movement</a>
                <ul class="submenu">
                  <?php if (canp('nav.files.movement.minute_file')): ?><li><a href="file/process_movementype.php?type=0&s=~" target="work-area">Minute File</a></li><?php endif; ?>
                  <?php if (canp('nav.files.movement.receive_file')): ?><li><a href="file/process_movementype.php?type=1&s=~" target="work-area">Recieve File</a></li><?php endif; ?>
                  <?php if (canp('nav.files.movement.view_log')): ?><li><a href="file/process_movement_view.php" target="work-area">View Movement Log</a></li><?php endif; ?>
                </ul>
              </li>

              <?php if (canp('nav.files.report')): ?><li><a href="file/report.php" target="work-area">Report</a></li><?php endif; ?>

              <li>
                <a href="file/process_recieve_file.php" target="work-area">Comment</a>
                <ul class="submenu">
                  <?php if (canp('nav.files.comment.comment_file')): ?><li><a href="file/process_comment_file.php" target="work-area">Comment File</a></li><?php endif; ?>
                  <?php if (canp('nav.files.comment.view_comments')): ?><li><a href="file/process_view_comments.php" target="work-area">View File Comments</a></li><?php endif; ?>
                </ul>
              </li>

              <li>
                <a href="file/process_delete.php" target="work-area">Delete</a>
                <ul class="submenu">
                  <?php if (canp('nav.files.delete.delete_file')): ?><li><a href="file/process_delete.php" target="work-area">Delete File</a></li><?php endif; ?>
                  <?php if (canp('nav.files.delete.view_deleted')): ?><li><a href="file/process_deleted_view.php" target="work-area">View Deleted Files</a></li><?php endif; ?>
                </ul>
              </li>

              <li>
                <a href="#" data-toggle-submenu>Caveat</a>
                <ul class="submenu">
                  <?php if (canp('nav.files.caveat.place')): ?><li><a href="registry/process_caveat.php" target="work-area">Place Caveat</a></li><?php endif; ?>
                  <?php if (canp('nav.files.caveat.view')): ?><li><a href="registry/process_caveat_view.php" target="work-area">View Caveat</a></li><?php endif; ?>
                  <?php if (canp('nav.files.caveat.cancel')): ?><li><a href="registry/process_cancel_caveat.php" target="work-area">Cancel Caveat</a></li><?php endif; ?>
                </ul>
              </li>
            </ul>
          </div>
        </section>
        <?php endif; ?>

        <!-- RECERTIFICATION -->
        <?php if (canp('nav.recert.*')): ?>
        <section class="nav-section" data-section="recertification">
          <div class="nav-title"><div class="left"><span class="icon">✅</span> Re‑Certification</div></div>
          <div class="group">
            <ul class="menu">
              <?php if (canp('nav.recert.checklist')): ?><li><a href="file/dochecklist.php" target="work-area">Checklist</a></li><?php endif; ?>
              <?php if (canp('nav.recert.validate_record')): ?><li><a href="validate/process_validate_record.php" target="work-area">Validate Record</a></li><?php endif; ?>

              <li>
                <a href="#" data-toggle-submenu>Print Draft</a>
                <ul class="submenu">
                  <?php if (canp('nav.recert.printdraft.instrument')): ?><li><a href="print/process_draft.php" target="work-area">Instrument</a></li><?php endif; ?>
                  <?php if (canp('nav.recert.printdraft.survey')): ?><li><a href="print/process_print_survey.php?type=draft" target="work-area">Survey</a></li><?php endif; ?>
                </ul>
              </li>

              <li>
                <a href="#" data-toggle-submenu>Validate</a>
                <ul class="submenu">
                  <?php if (canp('nav.recert.validate.draft_instrument')): ?><li><a href="validate/process_validate_draft.php" target="work-area">Draft Instrument</a></li><?php endif; ?>
                  <?php if (canp('nav.recert.validate.survey')): ?><li><a href="validate/process_validate_survey.php" target="work-area">Survey</a></li><?php endif; ?>
                </ul>
              </li>

              <li>
                <a href="#" data-toggle-submenu>Print Final</a>
                <ul class="submenu">
                  <?php if (canp('nav.recert.printf inal.instrument')): ?><li><a href="print/process_final.php?type=R&s=~" target="work-area">Instrument</a></li><?php endif; ?>
                  <?php if (canp('nav.recert.printfinal.registry_copy')): ?><li><a href="print/process_registry.php?type=R&s=~" target="work-area">Registry Copy</a></li><?php endif; ?>
                  <?php if (canp('nav.recert.printfinal.survey')): ?><li><a href="print/process_final_survey.php" target="work-area">Survey</a></li><?php endif; ?>
                </ul>
              </li>

              <li>
                <a href="#" data-toggle-submenu>Re‑Print</a>
                <ul class="submenu">
                  <?php if (canp('nav.recert.reprint.instrument')): ?><li><a href="print/process_reprint_instrument.php" target="work-area">Instrument</a></li><?php endif; ?>
                  <?php if (canp('nav.recert.reprint.survey')): ?><li><a href="print/process_reprint_survey.php" target="work-area">Survey</a></li><?php endif; ?>
                </ul>
              </li>

              <li>
                <a href="#" data-toggle-submenu>Reset</a>
                <ul class="submenu">
                  <?php if (canp('nav.recert.reset.checklist')): ?><li><a href="validate/process_reset_checklist.php" target="work-area">Checklist</a></li><?php endif; ?>
                  <?php if (canp('nav.recert.reset.validate_record')): ?><li><a href="validate/process_reset_record.php" target="work-area">Validate Record</a></li><?php endif; ?>
                  <?php if (canp('nav.recert.reset.print_draft')): ?><li><a href="validate/process_reset_print_draft.php" target="work-area">Print Draft Instrument</a></li><?php endif; ?>
                  <?php if (canp('nav.recert.reset.validate_instrument')): ?><li><a href="validate/process_reset_draft.php" target="work-area">Validate Instrument</a></li><?php endif; ?>
                  <?php if (canp('nav.recert.reset.validate_survey')): ?><li><a href="validate/process_reset_survey.php" target="work-area">Validate Survey</a></li><?php endif; ?>
                </ul>
              </li>

              <?php if (canp('nav.recert.execute')): ?><li><a href="validate/process_execute.php" target="work-area">Execute</a></li><?php endif; ?>
              <?php if (canp('nav.recert.dispatch')): ?><li><a href="validate/process_dispatch.php" target="work-area">Dispatch</a></li><?php endif; ?>
            </ul>
          </div>
        </section>
        <?php endif; ?>

        <!-- PAYMENT -->
        <?php if (canp('nav.payment.*')): ?>
        <section class="nav-section" data-section="payment">
          <div class="nav-title"><div class="left"><span class="icon">💳</span> Payment</div></div>
          <div class="group">
            <ul class="menu">
              <li>
                <a href="#" data-toggle-submenu>Ground Rent</a>
                <ul class="submenu">
                  <?php if (canp('nav.payment.groundrent.calculate')): ?><li><a href="payment/process_groundrent.php" target="work-area">Calculate Ground Rent</a></li><?php endif; ?>
                  <?php if (canp('nav.payment.groundrent.register')): ?><li><a href="payment/process_register_groundrent.php" target="work-area">Register Ground Rent</a></li><?php endif; ?>
                </ul>
              </li>

              <?php if (canp('nav.payment.invoice_poa')): ?><li><a href="payment/process_poa.php" target="work-area">Invoice for POA</a></li><?php endif; ?>

              <li>
                <a href="#" data-toggle-submenu>Register Payment</a>
                <ul class="submenu">
                  <?php if (canp('nav.payment.register.instrument_fees')): ?><li><a href="payment/process_register_payment.php?type=0&s=~" target="work-area">Register Instrument Fees</a></li><?php endif; ?>
                  <?php if (canp('nav.payment.register.property_search')): ?><li><a href="payment/process_register_payment.php?type=1&s=~" target="work-area">Register Property Search</a></li><?php endif; ?>
                </ul>
              </li>

              <li>
                <a href="#" data-toggle-submenu>View Payment</a>
                <ul class="submenu">
                  <?php if (canp('nav.payment.view.calculated_groundrent')): ?><li><a href="payment/process_groundrent_view.php" target="work-area">Calculated Ground Rent</a></li><?php endif; ?>
                  <?php if (canp('nav.payment.view.registered_groundrent')): ?><li><a href="payment/process_groundrentregister_view.php?type=draft" target="work-area">Registered Ground Rent</a></li><?php endif; ?>
                  <?php if (canp('nav.payment.view.registered_payments')): ?><li><a href="payment/process_payment_view.php?type=draft" target="work-area">Registered Payments</a></li><?php endif; ?>
                </ul>
              </li>
            </ul>
          </div>
        </section>
        <?php endif; ?>

        <!-- REGISTRY -->
        <?php if (canp('nav.registry.*')): ?>
        <section class="nav-section" data-section="registry">
          <div class="nav-title"><div class="left"><span class="icon">📑</span> Registry</div></div>
          <div class="group">
            <ul class="menu">
              <li>
                <a href="#" data-toggle-submenu>Instrument Transaction</a>
                <ul class="submenu">
                  <?php if (canp('nav.registry.transaction.convert_cofo')): ?><li><a href="registry/convert_transaction.php" target="work-area">Convert to CofO</a></li><?php endif; ?>
                  <?php if (canp('nav.registry.transaction.convert_surrender')): ?><li><a href="registry/convert_surrender.php" target="work-area">Convert Surrender</a></li><?php endif; ?>
                  <?php if (canp('nav.registry.transaction.process')): ?><li><a href="registry/instrument_transaction.php" target="work-area">Process Transaction</a></li><?php endif; ?>
                  <?php if (canp('nav.registry.transaction.record')): ?><li><a href="registry/record_transaction.php" target="work-area">Record Transactions</a></li><?php endif; ?>
                  <?php if (canp('nav.registry.transaction.view')): ?><li><a href="registry/process_transaction_view.php" target="work-area">View Transactions</a></li><?php endif; ?>
                  <?php if (canp('nav.registry.transaction.edit')): ?><li><a href="registry/process_transaction_edit.php" target="work-area">Edit Transactions</a></li><?php endif; ?>
                </ul>
              </li>

              <li>
                <a href="registry/process_detachment.php" target="work-area">Detach</a>
                <ul class="submenu">
                  <?php if (canp('nav.registry.detachment.record')): ?><li><a href="registry/process_record_detachment.php" target="work-area">Record Detachment</a></li><?php endif; ?>
                </ul>
              </li>

              <?php if (canp('nav.registry.stamping')): ?><li><a href="registry/process_stamping.php" target="work-area">Stamping</a></li><?php endif; ?>

              <li>
                <a href="#" data-toggle-submenu>Check</a>
                <ul class="submenu">
                  <?php if (canp('nav.registry.check.execute')): ?><li><a href="registry/process_execute_R.php" target="work-area">Check Execute</a></li><?php endif; ?>
                </ul>
              </li>

              <?php if (canp('nav.registry.execute')): ?><li><a href="registry/process_execute.php" target="work-area">Execute</a></li><?php endif; ?>
              <?php if (canp('nav.registry.dispatch')): ?><li><a href="registry/process_dispatch.php" target="work-area">Dispatch</a></li><?php endif; ?>

              <li>
                <a href="#" data-toggle-submenu>Reset</a>
                <ul class="submenu">
                  <?php if (canp('nav.registry.reset.detachment')): ?><li><a href="registry/process_reset.php?type=detachment&s=~" target="work-area">Detachment</a></li><?php endif; ?>
                  <?php if (canp('nav.registry.reset.stamping')): ?><li><a href="registry/process_reset.php?type=stamping&s=~" target="work-area">Stamping</a></li><?php endif; ?>
                  <?php if (canp('nav.registry.reset.check')): ?><li><a href="registry/process_reset.php?type=checking&s=~" target="work-area">Check</a></li><?php endif; ?>
                </ul>
              </li>
            </ul>
          </div>
        </section>
        <?php endif; ?>

        <!-- PRINT -->
        <?php if (canp('nav.print.*')): ?>
        <section class="nav-section" data-section="print">
          <div class="nav-title"><div class="left"><span class="icon">🖨️</span> Print Deeds</div></div>
          <div class="group">
            <ul class="menu">
              <li>
                <a href="#" data-toggle-submenu>Print Draft</a>
                <ul class="submenu">
                  <?php if (canp('nav.print.draft.instrument')): ?><li><a href="print/process_draft.php?type=D&s=~" target="work-area">Instrument</a></li><?php endif; ?>
                  <?php if (canp('nav.print.draft.surrender')): ?><li><a href="print/process_surrender.php?s=~" target="work-area">Surrender</a></li><?php endif; ?>
                  <?php if (canp('nav.print.draft.survey')): ?><li><a href="print/process_print_survey.php?type=draft&s=~" target="work-area">Survey</a></li><?php endif; ?>
                  <?php if (canp('nav.print.draft.complex_survey')): ?><li><a href="print/process_print_survey.php?complex=1&type=draft&s=~" target="work-area">Complex Survey</a></li><?php endif; ?>
                </ul>
              </li>

              <?php if (canp('nav.print.stamp')): ?><li><a href="print/process_final-stamp.php" target="work-area">Print Stamp</a></li><?php endif; ?>

              <li>
                <a href="#" data-toggle-submenu>Print Final</a>
                <ul class="submenu">
                  <?php if (canp('nav.print.final.instrument')): ?><li><a href="print/process_final.php?type=D&s=~" target="work-area">Instrument</a></li><?php endif; ?>
                  <?php if (canp('nav.print.final.renewal')): ?><li><a href="print/process_final-renewal.php?type=R&s=~" target="work-area">Renewal of Lease</a></li><?php endif; ?>
                  <?php if (canp('nav.print.final.registry_copy')): ?><li><a href="print/process_registry.php?type=D&s=~" target="work-area">Registry Copy</a></li><?php endif; ?>
                  <?php if (canp('nav.print.final.surrender_survey')): ?><li><a href="print/process_final_survey_S.php?type=D&s=~" target="work-area">Surrender Survey</a></li><?php endif; ?>
                  <?php if (canp('nav.print.final.survey')): ?><li><a href="print/process_final_survey.php" target="work-area">Survey</a></li><?php endif; ?>
                  <?php if (canp('nav.print.final.complex')): ?><li><a href="print/process_final_survey.php?complex=1&s=~" target="work-area">Complex Survey</a></li><?php endif; ?>
                </ul>
              </li>

              <li>
                <a href="#" data-toggle-submenu>Re‑Print</a>
                <ul class="submenu">
                  <?php if (canp('nav.print.reprint.instrument')): ?><li><a href="print/process_reprint_instrument.php" target="work-area">Instrument</a></li><?php endif; ?>
                  <?php if (canp('nav.print.reprint.survey')): ?><li><a href="print/process_reprint_survey.php" target="work-area">Survey</a></li><?php endif; ?>
                </ul>
              </li>

              <li>
                <a href="#" data-toggle-submenu>Reset Print</a>
                <ul class="submenu">
                  <?php if (canp('nav.print.reset.print_draft')): ?><li><a href="validate/process_reset_print_draft.php" target="work-area">Print Draft Instrument</a></li><?php endif; ?>
                  <?php if (canp('nav.print.reset.surrender')): ?><li><a href="validate/process_reset_surrender.php" target="work-area">Surrender</a></li><?php endif; ?>
                  <?php if (canp('nav.print.reset.print_stamp')): ?><li><a href="registry/process_reset.php?type=printing&s=~" target="work-area">Print Stamp</a></li><?php endif; ?>
                </ul>
              </li>
            </ul>
          </div>
        </section>
        <?php endif; ?>

        <!-- PLOTHOLDERS -->
        <?php if (canp('nav.plotholders.*')): ?>
        <section class="nav-section" data-section="plotholders">
          <div class="nav-title"><div class="left"><span class="icon">👥</span> Plot Holders</div></div>
          <div class="group">
            <ul class="menu">
              <?php if (canp('nav.plotholders.view')): ?><li><a href="plotholder/process_view.php" target="work-area">View Plot Holders</a></li><?php endif; ?>

              <li>
                <a href="#" data-toggle-submenu>Notify Plot Holders</a>
                <ul class="submenu">
                  <?php if (canp('nav.plotholders.notify.sms')): ?><li><a href="plotholder/sms_plotholder.php" target="work-area">SMS Plotholder</a></li><?php endif; ?>
                  <?php if (canp('nav.plotholders.notify.email')): ?><li><a href="plotholder/email_plotholder.php" target="work-area">Email Plotholder</a></li><?php endif; ?>
                </ul>
              </li>

              <?php if (canp('nav.plotholders.edit_cofo')): ?><li><a href="registry/process_editcofo.php" target="work-area">Edit Cofo</a></li><?php endif; ?>

              <li>
                <a href="#" data-toggle-submenu>View Others</a>
                <ul class="submenu">
                  <?php if (canp('nav.plotholders.viewothers.witness')): ?><li><a href="plotholder/process_view_witness.php" target="work-area">Witness</a></li><?php endif; ?>
                  <?php if (canp('nav.plotholders.viewothers.solicitor')): ?><li><a href="plotholder/process_view_solicitors.php" target="work-area">Solicitor</a></li><?php endif; ?>
                  <?php if (canp('nav.plotholders.viewothers.surety')): ?><li><a href="plotholder/process_view_surety.php" target="work-area">Surety</a></li><?php endif; ?>
                </ul>
              </li>

              <li>
                <a href="#" data-toggle-submenu>Broadcast</a>
                <ul class="submenu">
                  <?php if (canp('nav.plotholders.broadcast.sms_plotholders')): ?><li><a href="plotholder/bulk_sms_plotholders.php" target="work-area">Via SMS To Plotholders</a></li><?php endif; ?>
                  <?php if (canp('nav.plotholders.broadcast.email_plotholders')): ?><li><a href="plotholder/bulk_email_plotholders.php" target="work-area">Via Email To Plotholders</a></li><?php endif; ?>
                  <?php if (canp('nav.plotholders.broadcast.sms_solicitors')): ?><li><a href="plotholder/bulk_sms_solicitors.php" target="work-area">Via SMS To Solicitors</a></li><?php endif; ?>
                  <?php if (canp('nav.plotholders.broadcast.email_solicitors')): ?><li><a href="plotholder/bulk_email_solicitors.php" target="work-area">Via Email To Solicitors</a></li><?php endif; ?>
                </ul>
              </li>

              <?php if (canp('nav.plotholders.edit_record')): ?><li><a href="plotholder/process_edit_record.php" target="work-area">Edit Record</a></li><?php endif; ?>
            </ul>
          </div>
        </section>
        <?php endif; ?>

        <!-- SETTINGS -->
        <?php if (canp('nav.settings.*')): ?>
        <section class="nav-section" data-section="settings">
          <div class="nav-title"><div class="left"><span class="icon">⚙️</span> Setup</div></div>
          <div class="group">
            <ul class="menu">
              <?php if (canp('nav.settings.institution')): ?><li><a href="setup/institution-setting.php" target="work-area">Institution Settings</a></li><?php endif; ?>

              <li>
                <a href="#" data-toggle-submenu>Setup Parameters</a>
                <ul class="submenu">
                  <?php if (canp('nav.settings.params.groundrent_rate')): ?><li><a href="setup/setup_page.php?idcol=rentrateid&table=groundrent_rate&col=date,amount&coldesc=Year,Rate (per sq. meters)&s=~" target="work-area">Ground Rent Rate</a></li><?php endif; ?>
                  <?php if (canp('nav.settings.params.instrument')): ?><li><a href="setup/setup_page_category.php?idcol=instrumentid&table=instrument&col=instrumentname,shortname,level,certificate&coldesc=Name of Intrument,Short Name, Type,Print Certificate&order=iiss&source=instrument_level,yesno&s=~" target="work-area">Instrument</a></li><?php endif; ?>
                  <?php if (canp('nav.settings.params.landuse')): ?><li><a href="setup/setup_page.php?idcol=landuseid&table=landuse&col=landusename&coldesc=Land Use Type&s=~" target="work-area">Land Use</a></li><?php endif; ?>
                  <?php if (canp('nav.settings.params.layout')): ?><li><a href="setup/setup_page.php?idcol=layoutid&table=layout&col=layoutname,registrationcode&coldesc=Name of Layout,Registration Code&s=~" target="work-area">Layout</a></li><?php endif; ?>
                  <?php if (canp('nav.settings.params.benchmark')): ?><li><a href="setup/setup_page.php?idcol=id&table=benchmark&col=name,north,localEasting,localnorthing&coldesc=Name of Benchmark,North Description,Easting,Northing&s=~" target="work-area">Benchmark</a></li><?php endif; ?>
                  <?php if (canp('nav.settings.params.lga')): ?><li><a href="setup/setup_page.php?idcol=zoneid&table=townplanzone&col=zonename,shortcode&coldesc=Town Planining Zones,Short Code&s=~" target="work-area">LGA</a></li><?php endif; ?>
                  <?php if (canp('nav.settings.params.checklist')): ?><li><a href="setup/setup_page.php?idcol=itemid&table=checklistitems&col=itemdesc&coldesc=Description of Item&s=~" target="work-area">Check List</a></li><?php endif; ?>
                  <?php if (canp('nav.settings.params.poa_utilities')): ?><li><a href="setup/setup_page.php?idcol=utilityid&table=poautilities&col=utilityname,utilityamount&coldesc=Name of Utility,Amount&s=~" target="work-area">Power of Attoney</a></li><?php endif; ?>
                  <?php if (canp('nav.settings.params.rejection_reasons')): ?><li><a href="setup/setup_page.php?idcol=rejectionid&table=rejection_reasons&col=rejectiondesc&coldesc=Rejection Reason&s=~" target="work-area">Rejection Reasons</a></li><?php endif; ?>
                  <?php if (canp('nav.settings.params.revocation_reasons')): ?><li><a href="setup/setup_page.php?idcol=revocationid&table=revocation_reasons&col=revocationdesc&coldesc=Revocation Reason&s=~" target="work-area">Revocation Reasons</a></li><?php endif; ?>
                  <?php if (canp('nav.settings.params.destination')): ?><li><a href="setup/setup_page.php?idcol=id&table=destination&col=description&coldesc=Destination&s=~" target="work-area">Destination</a></li><?php endif; ?>
                  <?php if (canp('nav.settings.params.comments')): ?><li><a href="setup/setup_page.php?idcol=commentid&table=comments&col=commentdesc&coldesc=Comment&s=~" target="work-area">Comments</a></li><?php endif; ?>
                  <?php if (canp('nav.settings.params.movement_types')): ?><li><a href="setup/setup_page.php?idcol=id&table=movementypes&col=description&coldesc=Description&s=~" target="work-area">Movement Types</a></li><?php endif; ?>
                  <?php if (canp('nav.settings.params.fees')): ?><li><a href="setup/setup_page.php?idcol=feesid&table=fees&col=feesname&coldesc=Fees Name&s=~" target="work-area">Fees</a></li><?php endif; ?>
                  <?php if (canp('nav.settings.params.verge')): ?><li><a href="setup/setup_page.php?idcol=vergeid&table=verge&col=vergename&coldesc=Verge Name&s=~" target="work-area">Verge</a></li><?php endif; ?>
                  <?php if (canp('nav.settings.params.cofo_utilities')): ?><li><a href="setup/setup_page.php?idcol=id&table=cofoutilities&col=revision,descriptionlessthan,approvedby,officer,consent,premuim,nameofcommisioner,designationcommisioner,registrar,designregistrar,surveygeneral,designsurvey&coldesc=Revision Every,Description Less Than,Approved By,Officer,Consent,Premium,Name of Commisioner,Desgnation of Commisioner,Registrar,Designation of Registrar,Surveyor General,Designation of Surveyor General&s=~" target="work-area">CofO Utilities</a></li><?php endif; ?>
                  <?php if (canp('nav.settings.params.name_title')): ?><li><a href="setup/setup_page.php?idcol=titleid&table=nametitle&col=titlename&coldesc= Name of Title&s=~" target="work-area">Name Title</a></li><?php endif; ?>
                </ul>
              </li>

              <li>
                <a href="#" data-toggle-submenu>Access Management</a>
                <ul class="submenu">
                  <?php if (canp('nav.settings.access.users')): ?><li><a href="pages/setup/users.php" target="work-area">Users</a></li><?php endif; ?>
                  <?php if (canp('nav.settings.access.role_manager')): ?><li><a href="pages/setup/roles.php" target="work-area">Role Manager</a></li><?php endif; ?>
                  <?php if (canp('nav.settings.access.view_roles')): ?><li><a href="setup/view_roles.php" target="work-area">View Roles</a></li><?php endif; ?>
                  <?php if (canp('nav.settings.access.assign_roles')): ?><li><a href="setup/assign_roles.php" target="work-area">Assign Roles</a></li><?php endif; ?>
                </ul>
              </li>

              <li>
                <a href="#" data-toggle-submenu>Print Format</a>
                <ul class="submenu">
                  <?php if (canp('nav.settings.format.cofo')): ?><li><a href="setup/create_format.php" target="work-area">Cofo Format</a></li><?php endif; ?>
                  <?php if (canp('nav.settings.format.sublease')): ?><li><a href="setup/create_format_sublease.php" target="work-area">Sub-Lease Format</a></li><?php endif; ?>
                </ul>
              </li>

              <li>
                <a href="#" data-toggle-submenu>Logs</a>
                <ul class="submenu">
                  <?php if (canp('nav.settings.logs.access')): ?><li><a href="setup/process_view_access.php" target="work-area">Access Logs</a></li><?php endif; ?>
                  <?php if (canp('nav.settings.logs.reprint')): ?><li><a href="setup/process_view_reprint.php" target="work-area">Reprint Logs</a></li><?php endif; ?>
                </ul>
              </li>

              <?php if (canp('nav.settings.manual_backup')): ?><li><a href="setup/backup_page.php" target="work-area">Manual Backup</a></li><?php endif; ?>
              <?php if (canp('nav.settings.instrument_views')): ?><li><a href="setup/instrument_view.php" target="work-area">Instrument Views</a></li><?php endif; ?>
            </ul>
          </div>
        </section>
        <?php endif; ?>
      </nav>
    </aside>

    <header>
<div class="brand">

<div>
<div class="title">Ebonyi State Land Information Management System</div>
<div style="font-size:12px;color:var(--muted)">Secure. Modern. Responsive.</div>
</div>
</div>
<div class="actions">
<button class="btn" id="theme-toggle" title="Toggle theme">🌙 Dark</button>
<button class="btn" id="btn-refresh">Refresh</button>
<a class="btn" href="log_out.php">Log Out</a>
</div>
</header>

    <main>
      <iframe id="work-area" name="work-area" src="dashboard.php"></iframe>
      <div class="statusbar">
        <span id="status-text">Selected: None</span>
      </div>
    </main>
  </div>

  <script>
// Theme boot + toggle (persisted)
(function(){
try{
const saved = localStorage.getItem('theme');
const prefers = window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';
const theme = saved || prefers || 'dark';
document.documentElement.setAttribute('data-theme', theme);
}catch(e){}
})();
document.addEventListener('DOMContentLoaded', function(){
const btn = document.getElementById('theme-toggle');
if(btn){
const setLabel = ()=>{
const t = document.documentElement.getAttribute('data-theme') || 'dark';
btn.textContent = t === 'light' ? '🌙 Dark' : '☀️ Light';
btn.setAttribute('aria-label','Switch to ' + (t==='light'?'dark':'light') + ' mode');
};
setLabel();
btn.addEventListener('click', ()=>{
const t = document.documentElement.getAttribute('data-theme') || 'dark';
const next = t === 'light' ? 'dark' : 'light';
document.documentElement.setAttribute('data-theme', next);
try{ localStorage.setItem('theme', next); }catch(e){}
setLabel();
});
}
});


// Expand/collapse sections
document.querySelectorAll('.nav-title').forEach((title)=>{
title.addEventListener('click', ()=>{
const group = title.parentElement.querySelector('.group');
group.classList.toggle('open');
});
});


// Toggle submenus inside a section
document.querySelectorAll('[data-toggle-submenu]').forEach((t)=>{
t.addEventListener('click', (e)=>{
e.preventDefault();
const ul = t.nextElementSibling;
if(ul && ul.classList.contains('submenu')){
ul.classList.toggle('open');
}
})
})


// Highlight active link + update status bar
const iframe = document.getElementById('work-area');
const status = document.getElementById('status-text');


function markActive(el){
document.querySelectorAll('.menu a, .submenu a').forEach(a=>a.classList.remove('active'));
el.classList.add('active');
const label = el.textContent.trim();
status.textContent = 'Selected: ' + label;
}


document.querySelectorAll('a[target="work-area"]').forEach(a=>{
a.addEventListener('click', ()=> markActive(a));
});


// Refresh button reloads iframe
document.getElementById('btn-refresh').addEventListener('click', ()=>{
iframe.contentWindow.location.reload();
});


// Resize iframe to viewport height when window changes
const resize = ()=>{ iframe.style.height = (window.innerHeight - 64 - 36) + 'px'; };
window.addEventListener('resize', resize);
resize();


// Open first section by default
const first = document.querySelector('.nav-section .group');
if(first) first.classList.add('open');
</script>
</body>
</html>
