<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Broker Portal — Admin</title>

  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/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">
  <link href="https://fonts.googleapis.com/css2?family=Syne:wght@400;600;700;800&family=JetBrains+Mono:wght@300;400;500&family=Manrope:wght@300;400;500;600;700&display=swap" rel="stylesheet">

  <style>
    /* ══ CSS VARIABLES ══ */
    :root {
      --yellow:        #f5c518;
      --yellow-bright: #ffe566;
      --yellow-dim:    #c9a010;
      --yellow-glass:  rgba(245,197,24,0.09);
      --yellow-glow:   rgba(245,197,24,0.22);
      --yellow-border: rgba(245,197,24,0.18);

      --dark-900: #0b0c0e;
      --dark-800: #101214;
      --dark-700: #161a20;
      --dark-600: #1c2028;
      --dark-500: #242933;
      --dark-400: #2e3441;

      --text-1: #edf0f7;
      --text-2: #8a90a6;
      --text-3: #4a5068;

      --red:     #ef4f4a;
      --green:   #3ecb77;
      --blue:    #4ca8f5;
      --orange:  #f5a020;

      --sw: 255px;   /* sidebar width */
      --nh: 62px;    /* navbar height */
      --r:  12px;    /* radius */
    }

    /* Light mode variables */
    :root.light-mode {
      --dark-900: #fafbfc;
      --dark-800: #f3f4f7;
      --dark-700: #ececf1;
      --dark-600: #e5e7ef;
      --dark-500: #dcdfe9;
      --dark-400: #d0d5e3;

      --text-1: #0f1419;
      --text-2: #525f7f;
      --text-3: #8a96b4;

      --yellow-glass:  rgba(245,197,24,0.15);
      --yellow-border: rgba(245,197,24,0.3);
    }

    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

    body {
      font-family: 'Manrope', sans-serif;
      background: var(--dark-900);
      color: var(--text-1);
      min-height: 100vh;
      padding-left: var(--sw);
      padding-top: var(--nh);
      transition: padding-left 0.3s ease, background 0.4s ease, color 0.4s ease;
      overflow-x: hidden;
    }

    /* Dot grid texture */
    body::before {
      content: '';
      position: fixed; inset: 0;
      background-image: radial-gradient(rgba(245,197,24,0.055) 1px, transparent 1px);
      background-size: 26px 26px;
      pointer-events: none;
      z-index: 0;
      transition: opacity 0.4s ease;
    }

    body.light-mode::before {
      background-image: radial-gradient(rgba(245,197,24,0.08) 1px, transparent 1px);
      opacity: 1;
    }

    ::-webkit-scrollbar { width: 4px; }
    ::-webkit-scrollbar-track { background: var(--dark-800); transition: background 0.4s ease; }
    ::-webkit-scrollbar-thumb { background: rgba(245,197,24,0.2); border-radius: 8px; transition: background 0.4s ease; }

    /* Collapsed */
    body.sidebar-collapsed { padding-left: 0; }
    body.sidebar-collapsed .sidebar { left: calc(-1 * var(--sw)); }
    body.sidebar-collapsed .top-navbar { left: 0 !important; }

    @media (max-width: 991px) {
      body { padding-left: 0; }
      .sidebar { left: calc(-1 * var(--sw)); }
      body.sidebar-open .sidebar { left: 0; }
      .top-navbar { left: 0 !important; }
    }
  </style>

  <!-- ══ NAVBAR STYLES ══ -->
  <style>
    :root.light-mode .top-navbar {
      background: rgba(250,251,252,0.96);
      box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    }

    .top-navbar {
      position: fixed;
      top: 0; left: var(--sw); right: 0;
      height: var(--nh);
      background: rgba(11,12,14,0.96);
      backdrop-filter: blur(20px);
      border-bottom: 1px solid var(--yellow-border);
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 26px;
      z-index: 900;
      transition: left 0.3s ease, background 0.4s ease, border-color 0.4s ease, box-shadow 0.4s ease;
    }

    .nb-left  { display: flex; align-items: center; gap: 14px; }
    .nb-right { display: flex; align-items: center; gap: 12px; }

    /* Theme toggle button */
    .theme-toggle-btn {
      background: var(--dark-600);
      border: 1px solid rgba(255,255,255,0.07);
      color: var(--text-2);
      width: 36px; height: 36px;
      border-radius: 9px;
      display: flex;
      align-items: center; justify-content: center;
      cursor: pointer;
      font-size: 0.88rem;
      transition: all 0.3s;
    }
    .theme-toggle-btn:hover { 
      border-color: var(--yellow); 
      color: var(--yellow);
      transform: scale(1.05);
    }

    /* Hamburger */
    .sidebar-toggle-btn {
      background: var(--dark-600);
      border: 1px solid rgba(255,255,255,0.07);
      color: var(--text-2);
      width: 36px; height: 36px;
      border-radius: 9px;
      display: none;
      align-items: center; justify-content: center;
      cursor: pointer;
      font-size: 0.88rem;
      transition: all 0.2s;
    }
    .sidebar-toggle-btn:hover { border-color: var(--yellow); color: var(--yellow); }
    @media (max-width: 991px) { .sidebar-toggle-btn { display: flex; } }

    /* Brand */
    .nb-brand {
      font-family: 'Syne', sans-serif;
      font-size: 1.18rem;
      font-weight: 800;
      color: var(--yellow);
      text-decoration: none;
      letter-spacing: -0.4px;
      display: flex;
      align-items: center;
      gap: 8px;
    }
    .nb-brand i { font-size: 1rem; }

    .nb-version {
      font-family: 'JetBrains Mono', monospace;
      font-size: 0.58rem;
      letter-spacing: 2px;
      text-transform: uppercase;
      background: var(--yellow-glass);
      border: 1px solid var(--yellow-border);
      color: var(--yellow-dim);
      padding: 2px 9px;
      border-radius: 20px;
    }

    /* Live chip */
    .live-chip {
      font-family: 'JetBrains Mono', monospace;
      font-size: 0.58rem;
      letter-spacing: 2px;
      text-transform: uppercase;
      background: rgba(62,203,119,0.09);
      border: 1px solid rgba(62,203,119,0.22);
      color: var(--green);
      padding: 4px 11px;
      border-radius: 20px;
      display: flex;
      align-items: center;
      gap: 6px;
    }
    .live-dot {
      width: 5px; height: 5px;
      border-radius: 50%;
      background: var(--green);
      animation: pulse 1.5s ease-in-out infinite;
    }
    @keyframes pulse {
      0%,100% { opacity: 1; transform: scale(1); }
      50%      { opacity: 0.3; transform: scale(0.8); }
    }
    @media (max-width: 768px) { .live-chip { display: none; } }

    /* Avatar + dropdown */
    .avatar-wrap { position: relative; }

    .admin-avatar {
      width: 36px; height: 36px;
      background: linear-gradient(135deg, var(--yellow) 0%, var(--yellow-dim) 100%);
      border-radius: 50%;
      display: flex; align-items: center; justify-content: center;
      font-family: 'Syne', sans-serif;
      font-weight: 800;
      font-size: 0.85rem;
      color: var(--dark-900);
      cursor: pointer;
      border: 2px solid rgba(245,197,24,0.3);
      transition: box-shadow 0.2s;
      user-select: none;
    }
    .admin-avatar:hover { box-shadow: 0 0 0 4px var(--yellow-glass); }

    .admin-drop {
      position: absolute;
      top: calc(100% + 10px);
      right: 0;
      background: var(--dark-700);
      border: 1px solid var(--yellow-border);
      border-radius: var(--r);
      min-width: 196px;
      overflow: hidden;
      box-shadow: 0 28px 64px rgba(0,0,0,0.65);
      opacity: 0;
      transform: translateY(8px) scale(0.96);
      transition: opacity 0.18s ease, transform 0.18s ease, background 0.4s ease, border-color 0.4s ease;
      pointer-events: none;
      z-index: 9999;
    }
    .admin-drop.open {
      opacity: 1;
      transform: translateY(0) scale(1);
      pointer-events: auto;
    }
    .drop-head {
      padding: 12px 16px;
      border-bottom: 1px solid rgba(255,255,255,0.05);
      background: var(--dark-600);
      transition: background 0.4s ease, border-color 0.4s ease;
    }
    .drop-head .dh-name {
      font-family: 'Syne', sans-serif;
      font-weight: 700;
      font-size: 0.86rem;
      color: var(--text-1);
      transition: color 0.4s ease;
    }
    .drop-head .dh-role {
      font-family: 'JetBrains Mono', monospace;
      font-size: 0.58rem;
      letter-spacing: 2px;
      color: var(--yellow-dim);
      text-transform: uppercase;
      margin-top: 2px;
      transition: color 0.4s ease;
    }
    .admin-drop a {
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 10px 16px;
      font-size: 0.83rem;
      color: var(--text-2);
      text-decoration: none;
      transition: background 0.15s, color 0.15s, background 0.4s ease, color 0.4s ease;
    }
    .admin-drop a i { width: 16px; font-size: 0.8rem; color: var(--text-3); transition: color 0.15s, color 0.4s ease; }
    .admin-drop a:hover { background: var(--yellow-glass); color: var(--yellow); }
    .admin-drop a:hover i { color: var(--yellow); }
    .admin-drop .drop-sep { height: 1px; background: rgba(255,255,255,0.05); margin: 3px 0; transition: background 0.4s ease; }
    .admin-drop .logout-link { color: var(--red); }
    .admin-drop .logout-link i { color: var(--red); }
    .admin-drop .logout-link:hover { background: rgba(239,79,74,0.09); color: var(--red); }
  </style>
</head>
<body>

<!-- ══════════════ NAVBAR ══════════════ -->
<header class="top-navbar">
  <div class="nb-left">
    <button class="sidebar-toggle-btn" id="sidebarToggleBtn">
      <i class="fas fa-bars"></i>
    </button>
    <a href="index.php" class="nb-brand">
      <i class="fas fa-chart-line"></i> BrokerPortal
    </a>
    <span class="nb-version">Admin</span>
  </div>

  <div class="nb-right">
    <div class="live-chip"><span class="live-dot"></span> Live</div>

    <button class="theme-toggle-btn" id="themeToggleBtn" title="Toggle dark/light mode">
      <i class="fas fa-sun"></i>
    </button>

    <div class="avatar-wrap">
      <div class="admin-avatar" id="avatarBtn">A</div>
      <div class="admin-drop" id="adminDrop">
        <div class="drop-head">
          <div class="dh-name">Administrator</div>
          <div class="dh-role">Super Admin</div>
        </div>
        <a href="admin-profile.php"><i class="fas fa-user-circle"></i> My Profile</a>
        <a href="admin-change-password.php"><i class="fas fa-lock"></i> Change Password</a>
        <div class="drop-sep"></div>
        <a href="logout.php" class="logout-link"><i class="fas fa-sign-out-alt"></i> Logout</a>
      </div>
    </div>
  </div>
</header>

<script>
  // Theme toggle functionality
  const themeToggleBtn = document.getElementById('themeToggleBtn');
  const htmlElement = document.documentElement;
  
  // Load saved theme preference
  const savedTheme = localStorage.getItem('adminTheme') || 'dark';
  if (savedTheme === 'light') {
    htmlElement.classList.add('light-mode');
    themeToggleBtn.innerHTML = '<i class="fas fa-moon"></i>';
  }
  
  // Toggle theme
  themeToggleBtn?.addEventListener('click', () => {
    const isLight = htmlElement.classList.toggle('light-mode');
    const newTheme = isLight ? 'light' : 'dark';
    localStorage.setItem('adminTheme', newTheme);
    
    // Update icon
    themeToggleBtn.innerHTML = isLight 
      ? '<i class="fas fa-moon"></i>' 
      : '<i class="fas fa-sun"></i>';
  });

  // Avatar dropdown
  const _ab = document.getElementById('avatarBtn');
  const _ad = document.getElementById('adminDrop');
  _ab?.addEventListener('click', e => { e.stopPropagation(); _ad.classList.toggle('open'); });
  document.addEventListener('click', () => _ad?.classList.remove('open'));

  // Sidebar toggle
  document.getElementById('sidebarToggleBtn')?.addEventListener('click', () => {
    if (window.innerWidth <= 991) {
      document.body.classList.toggle('sidebar-open');
    } else {
      document.body.classList.toggle('sidebar-collapsed');
    }
  });
</script>