<?php
if (!defined('INSTALLED')) require_once dirname(__DIR__) . '/config/config.php';
require_once __DIR__ . '/functions.php';
startSecureSession();

$cartCount = getCartCount();
$currentPage = basename($_SERVER['PHP_SELF'], '.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= isset($pageTitle) ? e($pageTitle) . ' | ' : '' ?>Rig N Dig - Industrial Equipment Supplier</title>
<meta name="description" content="<?= isset($metaDesc) ? e($metaDesc) : e(setting('meta_description', "Pakistan's premier supplier of API 6A/6D standard industrial equipment, flanges, valves, and precision workshop services.")) ?>">
<meta name="keywords" content="<?= isset($pageKeywords) ? e($pageKeywords) : 'API 6A, API 6D, Industrial Equipment Pakistan, Flanges, Valves, Oil and Gas Spares, Rig N Dig' ?>">
<meta name="author" content="Rig N Dig">
<meta name="robots" content="<?= isset($metaRobots) ? e($metaRobots) : 'index, follow' ?>">

<!-- Open Graph / Facebook -->
<meta property="og:type" content="website">
<meta property="og:url" content="<?= e(SITE_URL . $_SERVER['REQUEST_URI']) ?>">
<meta property="og:title" content="<?= isset($pageTitle) ? e($pageTitle) . ' | ' : '' ?>Rig N Dig">
<meta property="og:description" content="<?= isset($metaDesc) ? e($metaDesc) : e(setting('meta_description')) ?>">
<meta property="og:image" content="<?= SITE_URL ?>assets/img/og-image.jpg">

<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:url" content="<?= e(SITE_URL . $_SERVER['REQUEST_URI']) ?>">
<meta property="twitter:title" content="<?= isset($pageTitle) ? e($pageTitle) . ' | ' : '' ?>Rig N Dig">
<meta property="twitter:description" content="<?= isset($metaDesc) ? e($metaDesc) : e(setting('meta_description')) ?>">
<meta property="twitter:image" content="<?= SITE_URL ?>assets/img/og-image.jpg">

<!-- Structured Data -->
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "Organization",
  "name": "Rig N Dig",
  "url": "<?= SITE_URL ?>",
  "logo": "<?= SITE_URL ?>uploads/<?= e(setting('logo')) ?>",
  "contactPoint": {
    "@type": "ContactPoint",
    "telephone": "<?= e(setting('phone')) ?>",
    "contactType": "customer service",
    "areaServed": "PK",
    "availableLanguage": ["English", "Urdu"]
  },
  "sameAs": [
    "<?= e(setting('facebook_url', '#')) ?>",
    "<?= e(setting('linkedin_url', '#')) ?>"
  ]
}
</script>

<link rel="canonical" href="<?= e(SITE_URL . $_SERVER['REQUEST_URI']) ?>">
<script src="https://cdn.tailwindcss.com"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800;900&display=swap" rel="stylesheet">
<link rel="stylesheet" href="/assets/css/style.css">
<script>
tailwind.config = {
  theme: {
    extend: {
      colors: {
        navy: { 950: '#030508', 900: '#0a0e1a', 800: '#111827', 700: '#1a1f2e', 600: '#1e2534', 500: '#2a3147' },
        orange: { 600: '#ff6b00', 500: '#ff7a15', 400: '#ff8c30' },
      },
      fontFamily: { sans: ['Outfit', 'sans-serif'] }
    }
  }
}
</script>
<style>
  :root {
    --pioneer-orange: #ff6b00;
  }

  body { -webkit-font-smoothing: antialiased; }

  /* COMPACT INDUSTRIAL HEADER */
  #site-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 100px;
    background: rgba(10, 14, 26, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    z-index: 100;
    transition: all 0.4s ease;
  }

  #site-header.scrolled {
    height: 80px;
    background: rgba(5, 7, 12, 0.95);
  }

  .nav-link {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(255,255,255,0.7);
    transition: all 0.3s ease;
    padding: 10px 15px;
    position: relative;
  }

  .nav-link:hover {
    color: #fff;
  }

  .nav-link.active {
    color: var(--pioneer-orange);
  }

  .nav-link.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 15px;
    right: 15px;
    height: 2px;
    background: var(--pioneer-orange);
    box-shadow: 0 0 10px var(--pioneer-orange);
  }

  /* DROPDOWN */
  .nav-dropdown {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: #0a0e1a;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom: 3px solid var(--pioneer-orange);
    width: 240px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    padding: 10px;
    border-radius: 0 0 12px 12px;
  }

  .group:hover .nav-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
  }

  .dropdown-item {
    display: block;
    padding: 10px 15px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: #9ca3af;
    transition: all 0.2s;
  }

  .dropdown-item:hover {
    background: rgba(255,107,0,0.1);
    color: #fff;
  }

  /* RFQ BUTTON */
  .rfq-btn {
    background: var(--pioneer-orange);
    color: #fff;
    padding: 10px 24px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition: all 0.3s;
    box-shadow: 0 10px 20px rgba(255, 107, 0, 0.2);
  }

  .rfq-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 30px rgba(255, 107, 0, 0.3);
  }

  /* LOGO */
  .site-logo img {
    height: 65px;
    width: auto;
    transition: all 0.4s ease;
  }
  #site-header.scrolled .site-logo img {
    height: 50px;
  }
</style>
<?php if (setting('google_analytics_id')): ?>
<script async src="https://www.googletagmanager.com/gtag/js?id=<?= e(setting('google_analytics_id')) ?>"></script>
<script>window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}gtag('js',new Date());gtag('config','<?= e(setting('google_analytics_id')) ?>');</script>
<?php endif; ?>
<script>
window.CSRF_TOKEN = '<?= csrfToken() ?>';
window.SITE_URL = '<?= SITE_URL ?>';
</script>
</head>
<body class="bg-navy-900 text-gray-100">

<header id="site-header">
  <div class="max-w-[1440px] mx-auto px-6 h-full flex items-center justify-between">
    
    <!-- Logo -->
    <a href="/" class="site-logo">
      <?php $siteLogo = setting('logo'); ?>
      <?php if ($siteLogo): ?>
        <img src="<?= rtrim(SITE_URL, '/') ?>/uploads/<?= e($siteLogo) ?>" alt="Rig N Dig">
      <?php else: ?>
        <span class="text-2xl font-black italic tracking-tighter">RIG <span class="text-orange-500">N</span> DIG</span>
      <?php endif; ?>
    </a>

    <!-- Nav -->
    <nav class="hidden lg:flex items-center gap-2">
      <a href="/" class="nav-link <?= $currentPage==='index' ? 'active' : '' ?>">Home</a>
      <a href="/shop.php" class="nav-link <?= $currentPage==='shop' ? 'active' : '' ?>">Assets</a>
      <a href="/services.php" class="nav-link <?= $currentPage==='services' ? 'active' : '' ?>">Precision</a>
      <a href="/industries.php" class="nav-link <?= $currentPage==='industries' ? 'active' : '' ?>">Sectors</a>
      
      <div class="relative group">
        <div class="nav-link flex items-center gap-1 cursor-pointer">
            Protocol <svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M19 9l-7 7-7-7"/></svg>
        </div>
        <div class="nav-dropdown">
            <a href="/certifications.php" class="dropdown-item">Certificates</a>
            <a href="/track-order.php" class="dropdown-item">Track Order</a>
            <a href="/projects.php" class="dropdown-item">Portfolio</a>
            <a href="/about.php" class="dropdown-item">Company Bio</a>
            <a href="/contact.php" class="dropdown-item">Contact Hub</a>
        </div>
      </div>
    </nav>

    <!-- Right Side -->
    <div class="flex items-center gap-6">
        <div class="hidden xl:block text-right">
            <div class="text-[9px] font-bold text-gray-500 uppercase tracking-widest leading-none mb-1">Status</div>
            <div class="text-[10px] font-black text-green-500 flex items-center gap-1.5 justify-end">
                <span class="w-1.5 h-1.5 bg-green-500 rounded-full animate-pulse"></span> ONLINE
            </div>
        </div>

        <a href="/quote-cart.php" class="rfq-btn flex items-center gap-2">
            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"/></svg>
            <span>RFQ PANEL</span>
        </a>

        <button id="menu-trigger" class="lg:hidden text-white">
            <svg class="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2.5" d="M4 6h16M4 12h16M4 18h16"/></svg>
        </button>
    </div>
  </div>
</header>

<div class="h-[100px]"></div>

<script>
  window.addEventListener('scroll', () => {
    const header = document.getElementById('site-header');
    if (window.scrollY > 50) {
      header.classList.add('scrolled');
    } else {
      header.classList.remove('scrolled');
    }
  });
</script>

<?php if (!empty($_SESSION['flash'])): foreach ($_SESSION['flash'] as $type => $msg): unset($_SESSION['flash'][$type]); ?>
<div class="max-w-7xl mx-auto px-6 pt-4">
  <div class="<?= $type === 'success' ? 'bg-green-600/10 border-green-500/50 text-green-400' : 'bg-red-600/10 border-red-500/50 text-red-400' ?> border rounded-xl p-4 flex justify-between items-center">
    <div class="text-xs font-bold uppercase tracking-widest"><?= e($msg) ?></div>
    <button onclick="this.parentElement.parentElement.remove()">✕</button>
  </div>
</div>
<?php endforeach; endif; ?>


