<!-- HEADER -->
<header class="header">
  <div class="container-header">
    <!-- Sidebar toggle -->
    <div class="sidebar-toggle" onclick="toggleSidebar()">
      <i class="fa fa-bars"></i>
    </div>

    <!-- Logo + Text -->
    <a href="dashboard.php" class="logo">
      <img src="https://www.gniotips.in/img/logo-footer.png" alt="Logo" class="logo-img">
      <span class="logo-text">Grievance Management System</span>
    </a>

    <!-- Right menu -->
    <div class="top-menu">
      <ul class="nav">
        <li>
          <span id="welcome-msg" class="welcome-msg"></span>
        </li>
        <li>
          <span id="current-time" class="clock"></span>
        </li>
        <li>
          <a class="logout-btn" href="logout.php">
            <i class="fa fa-sign-out-alt"></i> Logout
          </a>
        </li>
      </ul>
    </div>
  </div>
</header>

<!-- CSS -->
<style>
.header {
  background: linear-gradient(90deg, #ff7d19, #ff4500);
  color: #fff;
  padding: 0.5rem 1rem;
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
  position: fixed;
  width: 100%;
  top: 0;
  z-index: 1000;
}

.container-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  text-decoration: none;
  color: #fff;
  font-size: 1.2rem;
  font-weight: 600;
}

.logo-img {
  height: 40px;
  margin-right: 10px;
}

.logo-text {
  letter-spacing: 1px;
}

.sidebar-toggle {
  cursor: pointer;
  font-size: 1.5rem;
  margin-right: 1rem;
}

.top-menu .nav {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
}

.top-menu .nav li {
  margin-left: 1.5rem;
  display: flex;
  align-items: center;
}

.clock, .welcome-msg {
  font-weight: 600;
  font-size: 1.2rem;
}

.logout-btn {
  display: flex;
  align-items: center;
  padding: 0.4rem 0.8rem;
  background-color: #e65c00;
  color: #fff;
  border-radius: 4px;
  text-decoration: none;
  font-weight: 500;
  transition: background-color 0.3s;
}

.logout-btn i {
  margin-right: 0.4rem;
}

.logout-btn:hover {
  background-color: #cc5200;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
  .container-header {
    flex-wrap: wrap;
  }
  .top-menu {
    margin-top: 0.5rem;
  }
  .clock, .welcome-msg {
    font-size: 1rem;
  }
}
</style>

<!-- JS -->
<script>
// Sidebar toggle function
function toggleSidebar() {
  document.body.classList.toggle('sidebar-collapsed');
}

// Real-time clock & dynamic welcome message
function updateHeader() {
  const now = new Date();
  const hours = now.getHours();
  const timeString = now.toLocaleTimeString('en-IN', { hour12: true });
  document.getElementById('current-time').textContent = timeString;

  let greeting = '';
  if(hours >= 5 && hours < 12) greeting = 'Good Morning';
  else if(hours >= 12 && hours < 16) greeting = 'Good Afternoon';
  else if(hours >= 16 && hours < 20) greeting = 'Good Evening';
  else greeting = 'Good Night';

  document.getElementById('welcome-msg').textContent = `${greeting}, <?php echo $fullName; ?>`;
}

// Update every second
setInterval(updateHeader, 1000);
updateHeader();
</script>
