<?php
// Detect current page for active link highlighting
$current = basename($_SERVER['PHP_SELF']);
?>
<style>
/* Portal dropdown */
.portal-dropdown-wrap { position: relative; }
.portal-menu {
  display: none;
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(0,0,0,.14);
  padding: 8px;
  min-width: 240px;
  z-index: 99999;
  animation: portalFadeIn .18s ease;
}
.portal-menu.open { display: block; }
@keyframes portalFadeIn {
  from { opacity:0; transform:translateY(-6px); }
  to   { opacity:1; transform:translateY(0); }
}
.portal-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  text-decoration: none;
  color: #1e293b;
  transition: background .15s;
  cursor: pointer;
}
.portal-menu-item:hover { background: #f8fafc; color: #1e293b; }
.portal-menu-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-size: 15px;
}
.portal-menu-title { font-size: 13px; font-weight: 700; color: #0f172a; line-height: 1.3; }
.portal-menu-sub   { font-size: 11px; color: #64748b; margin-top: 1px; }
.portal-menu-divider { height: 1px; background: #f1f5f9; margin: 6px 4px; }

/* Global TM rule */
sup, .tm { font-weight: 400 !important; }

/* ===== NAVBAR ===== */
.site-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 9999;
  background: #fff;
  box-shadow: 0 2px 16px rgba(0,0,0,.08);
  transition: box-shadow .3s, background .3s;
  width: 100%;
}
.site-header.scrolled {
  box-shadow: 0 4px 28px rgba(0,0,0,.13);
}
.nav-wrap {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px;
  height: 68px;
  display: flex;
  align-items: center;
  width: 100%;
}

/* Logo (Desktop & Mobile) */
.nav-logo {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.nav-logo img {
  height: 46px;
  width: auto;
  object-fit: contain;
  display: block;
}

/* Nav links - Center Alignment for Desktop */
.nav-links {
  list-style: none;
  margin: 0 auto;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 4px;
}
.nav-links li a {
  display: block;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  color: #1e3a8a;
  text-decoration: none;
  border-radius: 8px;
  transition: color .2s, background .2s;
  white-space: nowrap;
}
.nav-links li a:hover,
.nav-links li a.active {
  color: #1d4ed8;
  background: #eff6ff;
}

/* CTA buttons - Right Alignment */
.nav-cta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  margin-left: auto;
}
.nav-btn-ghost {
  height: 38px;
  padding: 0 16px;
  border-radius: 20px;
  border: 1.5px solid #1d4ed8;
  background: transparent;
  color: #1d4ed8;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  display: flex;
  align-items: center;
  white-space: nowrap;
  transition: background .2s, color .2s;
  cursor: pointer;
}
.nav-btn-ghost:hover {
  background: #eff6ff;
  color: #1e40af;
}
.nav-btn-primary {
  height: 38px;
  padding: 0 18px;
  border-radius: 20px;
  border: none;
  background: linear-gradient(100deg, #1d4ed8, #3b82f6);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  display: flex;
  align-items: center;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(59,130,246,.35);
  transition: opacity .2s, box-shadow .2s;
  cursor: pointer;
}
.nav-btn-primary:hover {
  opacity: .9;
  box-shadow: 0 6px 20px rgba(59,130,246,.5);
  color: #fff;
}

/* Hamburger */
.nav-hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0; /* Zero padding to align properly on exact right */
  border-radius: 8px;
  transition: background .2s;
  flex-shrink: 0;
}
.nav-hamburger:hover { background: #eff6ff; }
.nav-hamburger span {
  display: block;
  height: 2px;
  background: #1e3a8a;
  border-radius: 2px;
  transition: transform .3s, opacity .3s, width .3s;
  width: 22px;
}
.nav-hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-hamburger.open span:nth-child(2) { opacity: 0; width: 0; }
.nav-hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Mobile drawer */
.nav-drawer {
  display: none;
  position: fixed;
  top: 68px; left: 0; right: 0;
  background: #fff;
  border-top: 1px solid #e2e8f0;
  box-shadow: 0 8px 32px rgba(0,0,0,.12);
  padding: 16px 20px 24px;
  z-index: 9998;
  flex-direction: column;
  gap: 4px;
  animation: drawerSlide .25s cubic-bezier(.16,1,.3,1);
}
.nav-drawer.open { display: flex; }
@keyframes drawerSlide {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.nav-drawer a {
  display: block;
  padding: 12px 14px;
  font-size: 15px;
  font-weight: 600;
  color: #1e3a8a;
  text-decoration: none;
  border-radius: 10px;
  transition: background .2s, color .2s;
}
.nav-drawer a:hover,
.nav-drawer a.active {
  background: #eff6ff;
  color: #1d4ed8;
}
.nav-drawer-divider {
  height: 1px;
  background: #e2e8f0;
  margin: 8px 0;
}
.nav-drawer-btns {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.nav-drawer-btns .nav-btn-ghost,
.nav-drawer-btns .nav-btn-primary {
  flex: 1;
  justify-content: center;
  height: 42px;
  font-size: 14px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .nav-links, .nav-cta { display: none; }
  .nav-hamburger { display: flex; }
  
  .site-header {
    padding: 0 !important;
  }
  .nav-wrap { 
    justify-content: space-between !important; 
    padding: 0 12px 0 0 !important; 
    margin: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    gap: 0 !important; 
  }
  .nav-logo {
    margin: 0 !important;
    padding: 0 0 0 12px !important;
  }
  .nav-logo img {
    object-position: left;
  }
  .nav-hamburger {
    margin: 0 8px 0 0 !important;
  }
}

@media (min-width: 901px) {
  .nav-drawer { display: none !important; }
  .nav-logo { margin-right: auto; }
}
</style>

<header class="site-header" id="siteHeader">
  <div class="nav-wrap">
    <!-- Logo (Zero Gap Extreme Left) -->
    <a class="nav-logo" href="index.php">
      <img src="<?= (strpos($current, '/') !== false ? '../' : '') ?>drm-healthlink-logo.png" alt="DRM HealthLink">
    </a>

    <!-- Desktop nav links (Centered) -->
    <ul class="nav-links">
      <li><a href="index.php#concept"   <?= $current==='index.php'?'class="active"':'' ?>>The Concept</a></li>
      <li><a href="index.php#kiosk"     >DRM CarePoint<sup class="tm">™</sup></a></li>
      <li><a href="index.php#tests"     >What We Test</a></li>
      <li><a href="solutions.php"       <?= $current==='solutions.php'?'class="active"':'' ?>>Solutions</a></li>
      <li><a href="contact.php"         <?= $current==='contact.php'?'class="active"':'' ?>>Contact</a></li>
    </ul>

    <!-- Desktop CTA (Right aligned) -->
    <div class="nav-cta">
      <!-- Portal Login Dropdown -->
      <div class="portal-dropdown-wrap" style="position:relative;">
        <button class="nav-btn-ghost" id="portalBtn" onclick="togglePortalMenu()" style="display:flex;align-items:center;gap:6px;">
          <i class="fas fa-user-circle" style="font-size:14px;"></i> Portal Login <i class="fas fa-chevron-down" id="portalChevron" style="font-size:10px;transition:transform .2s;"></i>
        </button>
        <div class="portal-menu" id="portalMenu">
          <a href="javascript:void(0)" onclick="openPortalModal('patientLoginModal')" class="portal-menu-item">
            <div class="portal-menu-icon" style="background:rgba(168,85,247,.12);border:1px solid rgba(168,85,247,.3);">
              <i class="far fa-user" style="color:#7c3aed;"></i>
            </div>
            <div>
              <div class="portal-menu-title">Patient Login</div>
              <div class="portal-menu-sub">Access your health records</div>
            </div>
          </a>
          <a href="javascript:void(0)" onclick="openPortalModal('doctorLoginModal')" class="portal-menu-item">
            <div class="portal-menu-icon" style="background:rgba(59,130,246,.12);border:1px solid rgba(59,130,246,.3);">
              <i class="fas fa-user-md" style="color:#1d4ed8;"></i>
            </div>
            <div>
              <div class="portal-menu-title">Doctor Login</div>
              <div class="portal-menu-sub">Manage your appointments</div>
            </div>
          </a>
          <div class="portal-menu-divider"></div>
          <a href="javascript:void(0)" onclick="openPortalModal('registerModal')" class="portal-menu-item">
            <div class="portal-menu-icon" style="background:rgba(16,185,129,.12);border:1px solid rgba(16,185,129,.3);">
              <i class="fas fa-user-plus" style="color:#059669;"></i>
            </div>
            <div>
              <div class="portal-menu-title">New Patient?</div>
              <div class="portal-menu-sub">Register for free</div>
            </div>
          </a>
        </div>
      </div>
      <a class="nav-btn-primary" href="contact.php">Partner With Us</a>
    </div>

    <!-- Hamburger (Zero Gap Extreme Right) -->
    <button class="nav-hamburger" id="navHamburger" aria-label="Menu">
      <span></span><span></span><span></span>
    </button>
  </div>
</header>

<!-- Mobile Portal Popup (Patient/Doctor choice) -->
<div id="mobPortalPopup" style="display:none;position:fixed;top:68px;left:0;right:0;z-index:99997;padding:0 16px;">
  <div style="background:#fff;border:1px solid #e2e8f0;border-radius:16px;box-shadow:0 16px 48px rgba(0,0,0,.18);padding:12px;animation:portalFadeIn .18s ease;">
    <div style="font-size:11px;font-weight:700;color:#64748b;text-transform:uppercase;letter-spacing:1px;padding:4px 8px 8px;">Choose Portal</div>
    <a href="javascript:void(0)" onclick="openPortalModal('patientLoginModal');closeMobPortalMenu();" style="display:flex;align-items:center;gap:12px;padding:10px 12px;border-radius:10px;text-decoration:none;color:#1e293b;transition:background .15s;" onmouseover="this.style.background='#f8fafc'" onmouseout="this.style.background=''">
      <div style="width:38px;height:38px;border-radius:10px;background:rgba(168,85,247,.12);border:1px solid rgba(168,85,247,.3);display:grid;place-items:center;flex-shrink:0;">
        <i class="far fa-user" style="color:#7c3aed;font-size:15px;"></i>
      </div>
      <div>
        <div style="font-size:13px;font-weight:700;color:#0f172a;">Patient Login</div>
        <div style="font-size:11px;color:#64748b;margin-top:1px;">Access your health records</div>
      </div>
    </a>
    <a href="javascript:void(0)" onclick="openPortalModal('doctorLoginModal');closeMobPortalMenu();" style="display:flex;align-items:center;gap:12px;padding:10px 12px;border-radius:10px;text-decoration:none;color:#1e293b;transition:background .15s;" onmouseover="this.style.background='#f8fafc'" onmouseout="this.style.background=''">
      <div style="width:38px;height:38px;border-radius:10px;background:rgba(59,130,246,.12);border:1px solid rgba(59,130,246,.3);display:grid;place-items:center;flex-shrink:0;">
        <i class="fas fa-user-md" style="color:#1d4ed8;font-size:15px;"></i>
      </div>
      <div>
        <div style="font-size:13px;font-weight:700;color:#0f172a;">Doctor Login</div>
        <div style="font-size:11px;color:#64748b;margin-top:1px;">Manage your appointments</div>
      </div>
    </a>
  </div>
</div>

<!-- Mobile Drawer -->
<div class="nav-drawer" id="navDrawer">
  <a href="index.php#concept">The Concept</a>
  <a href="index.php#kiosk">DRM CarePoint<sup class="tm">™</sup></a>
  <a href="index.php#tests">What We Test</a>
  <a href="solutions.php" <?= $current==='solutions.php'?'class="active"':'' ?>>Solutions</a>
  <a href="contact.php"    <?= $current==='contact.php'?'class="active"':'' ?>>Contact</a>
  <a href="javascript:void(0)" onclick="toggleMobPortalMenu()" id="mobPortalBtn"><i class="fas fa-user-circle" style="margin-right:8px;"></i>Portal Login</a>
  <div class="nav-drawer-divider"></div>
  <div class="nav-drawer-btns">
    <div style="display:flex;flex-direction:column;gap:8px;width:100%;">
      <a class="nav-btn-primary" style="justify-content:center;" href="contact.php">Partner With Us</a>
    </div>
  </div>
</div>

<!-- Navbar JS -->
<script>
(function(){
  var header  = document.getElementById('siteHeader');
  var burger  = document.getElementById('navHamburger');
  var drawer  = document.getElementById('navDrawer');

  window.addEventListener('scroll', function(){
    header.classList.toggle('scrolled', window.scrollY > 10);
  }, { passive: true });

  burger.addEventListener('click', function(){
    var open = drawer.classList.toggle('open');
    burger.classList.toggle('open', open);
    burger.setAttribute('aria-expanded', open);
  });

  document.addEventListener('click', function(e){
    if(!header.contains(e.target) && !drawer.contains(e.target)){
      drawer.classList.remove('open');
      burger.classList.remove('open');
    }
    // close portal menu on outside click
    var menu = document.getElementById('portalMenu');
    var btn  = document.getElementById('portalBtn');
    if(menu && btn && !btn.contains(e.target) && !menu.contains(e.target)){
      menu.classList.remove('open');
      document.getElementById('portalChevron').style.transform = '';
    }
  });

  drawer.querySelectorAll('a').forEach(function(a){
    a.addEventListener('click', function(){
      drawer.classList.remove('open');
      burger.classList.remove('open');
    });
  });
})();

function closeDrawer(){
  document.getElementById('navDrawer').classList.remove('open');
  document.getElementById('navHamburger').classList.remove('open');
}

function togglePortalMenu(){
  var menu = document.getElementById('portalMenu');
  var chevron = document.getElementById('portalChevron');
  var isOpen = menu.classList.toggle('open');
  chevron.style.transform = isOpen ? 'rotate(180deg)' : '';
}

function openPortalModal(id){
  var menu = document.getElementById('portalMenu');
  if(menu) menu.classList.remove('open');
  var chevron = document.getElementById('portalChevron');
  if(chevron) chevron.style.transform = '';
  closeMobPortalMenu();

  if(typeof bootstrap !== 'undefined' && document.getElementById(id)){
    new bootstrap.Modal(document.getElementById(id)).show();
  } else {
    window.location.href = 'index.php?open=' + id;
  }
}

function toggleMobPortalMenu(){
  var popup = document.getElementById('mobPortalPopup');
  var isOpen = popup.style.display === 'block';
  popup.style.display = isOpen ? 'none' : 'block';
}

function closeMobPortalMenu(){
  var popup = document.getElementById('mobPortalPopup');
  if(popup) popup.style.display = 'none';
}

// Close mob portal popup on outside click
document.addEventListener('click', function(e){
  var popup = document.getElementById('mobPortalPopup');
  var btn = document.getElementById('mobPortalBtn');
  if(popup && !popup.contains(e.target) && (!btn || !btn.contains(e.target))){
    popup.style.display = 'none';
  }
});
</script>