<?php
// ── Handle POST BEFORE any HTML output ──────────────────────────────────────
if (session_status() === PHP_SESSION_NONE) session_start();
require_once __DIR__ . '/backend/config/database.php';

$loggedIn = isset($_SESSION['user_id']);
$userId   = $_SESSION['user_id'] ?? null;
$success  = false;
$error    = '';

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['place_order'])) {
    if (!$loggedIn) {
        header('Location: /stile-lpg/login.php?redirect=services');
        exit;
    }
  $db = getDB();

    $customKg  = trim($_POST['custom_kg'] ?? '');
    $productId = $_POST['product_id'] ?? '';
    $qty       = max(1, (int)($_POST['quantity'] ?? 1));
    $fulfillment = $_POST['fulfillment'] ?? 'delivery';
    $address   = trim($_POST['address'] ?? '');
    $phone     = trim($_POST['phone'] ?? '');
    $notes     = trim($_POST['notes'] ?? '');

    // Validate phone number
    if (!$phone) {
        $error = 'Phone number is required.';
        goto show_form;
    }

    // Resolve price and name
    if ($customKg && is_numeric($customKg)) {
        $price = round((float)$customKg * 550);
        $productName = "Custom {$customKg}kg LPG";
        $productId   = null;
    } else {
        $stmt = $db->prepare("SELECT id, name, price FROM products WHERE id=? AND is_active=1");
        $stmt->execute([$productId]);
        $product = $stmt->fetch(PDO::FETCH_ASSOC);
        if (!$product) { $error = 'Product not found.'; goto show_form; }
        $price = $product['price'];
        $productName = $product['name'];
    }

    $total = $price * $qty;
    $orderId = 'ord_' . bin2hex(random_bytes(8));

    try {
        $db->beginTransaction();
        $stmt = $db->prepare("INSERT INTO orders(id,user_id,total,payment_method,fulfillment,address,phone,notes,status,created_at)VALUES(?,?,?,?,?,?,?,?,?,NOW())");
        $stmt->execute([$orderId, $userId, $total, 'cod', $fulfillment, $address, $phone, $notes, 'pending']);

        $itemId = 'oi_' . bin2hex(random_bytes(8));
        $stmt = $db->prepare("INSERT INTO order_items(id,order_id,product_id,product_name,quantity,price)VALUES(?,?,?,?,?,?)");
        $stmt->execute([$itemId, $orderId, $productId, $productName, $qty, $price]);
        $db->commit();
        $success = true;
    } catch(Exception $e) {
        $db->rollBack();
        $error = 'Order failed. Please try again.';
    }
}

show_form:
// Fetch LPG products for display
$db = getDB();
$stmt = $db->prepare("SELECT id,name,price,description FROM products WHERE category='lpg' AND is_active=1 ORDER BY price ASC");
$stmt->execute();
$lpgProducts = $stmt->fetchAll(PDO::FETCH_ASSOC);

// ── Now output HTML ──────────────────────────────────────────────────────────
$pageTitle   = 'Services';
$currentPage = 'services';
require_once __DIR__ . '/backend/includes/head.php';
require_once __DIR__ . '/backend/includes/navbar.php';
?>

<!-- Hero -->
<section style="background:linear-gradient(145deg,#0f172a 0%,#1e293b 60%,#0f172a 100%);padding:5rem 0 4rem;position:relative;overflow:hidden">
  <div style="position:absolute;inset:0;background-image:radial-gradient(circle,rgba(255,255,255,.02) 1px,transparent 1px);background-size:28px 28px;pointer-events:none"></div>
  <div style="position:absolute;top:-80px;right:-80px;width:400px;height:400px;background:radial-gradient(circle,rgba(249,115,22,.18) 0%,transparent 70%);pointer-events:none"></div>
  <div style="max-width:860px;margin:0 auto;padding:0 1.5rem;text-align:center;position:relative">
    <div style="display:inline-flex;align-items:center;gap:.5rem;background:rgba(249,115,22,.15);border:1px solid rgba(249,115,22,.3);border-radius:50px;padding:.4rem 1.1rem;margin-bottom:1.75rem">
      <svg width="14" height="14" fill="none" stroke="#f97316" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M8.5 14.5A2.5 2.5 0 0011 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 11-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 002.5 3z"/></svg>
      <span style="color:#f97316;font-size:.78rem;font-weight:700;letter-spacing:.08em">LPG SERVICES</span>
    </div>
    <h1 style="color:#fff;font-weight:900;font-size:clamp(2rem,5vw,3rem);line-height:1.1;margin-bottom:1.25rem">
      Fast, Safe <span style="background:linear-gradient(90deg,#f97316,#fbbf24);-webkit-background-clip:text;-webkit-text-fill-color:transparent">LPG Delivery</span> to Your Door
    </h1>
    <p style="color:#94a3b8;font-size:1.05rem;line-height:1.7;max-width:560px;margin:0 auto">Order cooking gas cylinders online. Quick delivery, competitive rates, and trusted safety standards.</p>
  </div>
</section>

<!-- Main Content -->
<section style="max-width:1100px;margin:0 auto;padding:4rem 1.5rem;position:relative;z-index:1">

  <?php if($success): ?>
  <!-- Success state -->
  <div style="display:flex;align-items:center;justify-content:center;min-height:50vh">
    <div style="background:#fff;border-radius:24px;padding:3.5rem 2.5rem;max-width:480px;width:100%;text-align:center;box-shadow:0 8px 40px rgba(0,0,0,.1)">
      <div style="width:80px;height:80px;border-radius:50%;background:linear-gradient(135deg,#22c55e,#16a34a);display:flex;align-items:center;justify-content:center;margin:0 auto 1.5rem;box-shadow:0 8px 24px rgba(34,197,94,.35)">
        <svg width="40" height="40" fill="none" stroke="#fff" stroke-width="2.5" viewBox="0 0 24 24"><polyline stroke-linecap="round" stroke-linejoin="round" points="20 6 9 17 4 12"/></svg>
      </div>
      <h2 style="color:#0f172a;font-weight:900;font-size:1.6rem;margin:0 0 .75rem">Order Placed!</h2>
      <p style="color:#64748b;line-height:1.7;margin:0 0 2rem">Your LPG order has been received. We'll contact you to confirm delivery details.</p>
      <a href="/stile-lpg/services.php" class="btn-primary">Place Another Order</a>
    </div>
  </div>
  <?php else: ?>

  <div style="display:grid;grid-template-columns:1fr 380px;gap:2rem;align-items:start" class="services-main-grid">

    <!-- Order Form -->
    <div class="anim-fade-left" style="background:#fff;border-radius:24px;overflow:hidden;box-shadow:0 4px 32px rgba(0,0,0,.08);border:1px solid #f1f5f9">
      <div style="background:linear-gradient(135deg,#0f172a,#1e293b);padding:1.75rem 2rem;position:relative;overflow:hidden">
        <div style="position:absolute;top:-30px;right:-30px;width:120px;height:120px;background:radial-gradient(circle,rgba(249,115,22,.2) 0%,transparent 70%);pointer-events:none"></div>
        <div style="display:flex;align-items:center;gap:.75rem;position:relative">
          <div style="width:44px;height:44px;border-radius:12px;background:linear-gradient(135deg,#f97316,#fb923c);display:flex;align-items:center;justify-content:center">
            <svg width="22" height="22" fill="none" stroke="#fff" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M11 4H4a2 2 0 00-2 2v14a2 2 0 002 2h14a2 2 0 002-2v-7"/><path stroke-linecap="round" stroke-linejoin="round" d="M18.5 2.5a2.121 2.121 0 013 3L12 15l-4 1 1-4 9.5-9.5z"/></svg>
          </div>
          <div>
            <h2 style="color:#fff;font-weight:900;font-size:1.15rem;margin:0">Place Your Order</h2>
            <p style="color:#64748b;font-size:.78rem;margin:0">Fill in details below to order LPG</p>
          </div>
        </div>
      </div>

      <?php if($error): ?>
      <div class="alert alert-error" style="margin:1.5rem 2rem 0"><?= htmlspecialchars($error) ?></div>
      <?php endif; ?>

      <form method="POST" action="/stile-lpg/services.php" style="padding:2rem">

        <!-- Product selector -->
        <div style="margin-bottom:1.5rem">
          <label style="display:block;color:#475569;font-weight:700;font-size:.82rem;letter-spacing:.04em;text-transform:uppercase;margin-bottom:.6rem">Select Cylinder Size</label>
          <select name="product_id" id="product_select" class="input-field" style="border:2px solid #e2e8f0;border-radius:14px" onchange="document.getElementById('custom_kg').value=''">
            <option value="">Select a product…</option>
            <?php foreach($lpgProducts as $p): ?>
            <option value="<?= $p['id'] ?>" data-price="<?= $p['price'] ?>"><?= htmlspecialchars($p['name']) ?> — ₦<?= number_format($p['price']) ?></option>
            <?php endforeach; ?>
          </select>
        </div>

        <!-- Custom kg -->
        <!--<div style="margin-bottom:1.5rem">-->
        <!--  <label style="display:block;color:#475569;font-weight:700;font-size:.82rem;letter-spacing:.04em;text-transform:uppercase;margin-bottom:.6rem">Or Enter Custom Weight (kg)</label>-->
        <!--  <input type="number" name="custom_kg" id="custom_kg" min="1" placeholder="e.g. 25" class="input-field" style="border:2px solid #e2e8f0;border-radius:14px" oninput="document.getElementById('product_select').value='';updateTotal()">-->
        <!--  <p id="custom_price_hint" style="color:#f97316;font-size:.8rem;margin-top:.35rem;font-weight:600;display:none"></p>-->
        <!--</div>-->

        <!-- Fulfillment + Qty -->
        <div style="display:grid;grid-template-columns:1fr 1fr;gap:1rem;margin-bottom:1.5rem" class="form-row">
          <div>
            <label style="display:block;color:#475569;font-weight:700;font-size:.82rem;letter-spacing:.04em;text-transform:uppercase;margin-bottom:.6rem">Fulfillment</label>
            <select name="fulfillment" id="fulfillment" class="input-field" style="border:2px solid #e2e8f0;border-radius:14px" onchange="toggleAddress()">
              <option value="delivery">Delivery</option>
              <option value="pickup">Pickup</option>
            </select>
          </div>
          <div>
            <label style="display:block;color:#475569;font-weight:700;font-size:.82rem;letter-spacing:.04em;text-transform:uppercase;margin-bottom:.6rem">Quantity</label>
            <input type="number" name="quantity" id="qty" min="1" value="1" class="input-field" style="border:2px solid #e2e8f0;border-radius:14px" oninput="updateTotal()">
          </div>
        </div>

        <!-- Address -->
        <div id="address_row" style="margin-bottom:1.5rem">
          <label style="display:block;color:#475569;font-weight:700;font-size:.82rem;letter-spacing:.04em;text-transform:uppercase;margin-bottom:.6rem">Delivery Address</label>
          <input type="text" name="address" placeholder="Enter your full delivery address" class="input-field" style="border:2px solid #e2e8f0;border-radius:14px">
        </div>

        <!-- Phone Number -->
        <div style="margin-bottom:1.5rem">
          <label style="display:block;color:#475569;font-weight:700;font-size:.82rem;letter-spacing:.04em;text-transform:uppercase;margin-bottom:.6rem">Contact Number *</label>
          <input type="tel" name="phone" required placeholder="+234 800 000 0000" class="input-field" style="border:2px solid #e2e8f0;border-radius:14px" pattern="[0-9+\s\-()]+" title="Please enter a valid phone number (numbers only)" oninput="this.value = this.value.replace(/[^0-9+\s\-()]/g, '')">
        </div>

        <!-- Notes -->
        <div style="margin-bottom:1.75rem">
          <label style="display:block;color:#475569;font-weight:700;font-size:.82rem;letter-spacing:.04em;text-transform:uppercase;margin-bottom:.6rem">Notes (optional)</label>
          <textarea name="notes" placeholder="Any special instructions…" rows="3" class="input-field" style="border:2px solid #e2e8f0;border-radius:14px;resize:vertical"></textarea>
        </div>

        <!-- Total card -->
        <div style="background:linear-gradient(135deg,#fff7ed,#ffedd5);border:2px solid #fed7aa;border-radius:16px;padding:1.25rem 1.5rem;margin-bottom:1.25rem;display:flex;align-items:center;justify-content:space-between">
          <div>
            <div style="color:#92400e;font-size:.75rem;font-weight:700;letter-spacing:.06em;text-transform:uppercase">Order Total</div>
            <div id="total_display" style="color:#f97316;font-weight:900;font-size:1.8rem;letter-spacing:-.02em;line-height:1">₦0</div>
          </div>
          <div style="display:flex;align-items:center;gap:.4rem;background:#f0fdf4;border:1px solid #bbf7d0;border-radius:20px;padding:.4rem .9rem">
            <svg width="14" height="14" fill="none" stroke="#15803d" stroke-width="2" viewBox="0 0 24 24"><rect x="2" y="7" width="20" height="14" rx="2" ry="2"/><path stroke-linecap="round" stroke-linejoin="round" d="M16 7V5a2 2 0 00-2-2h-4a2 2 0 00-2 2v2"/><line x1="12" y1="12" x2="12" y2="16"/><line x1="10" y1="14" x2="14" y2="14"/></svg>
            <span style="color:#15803d;font-weight:700;font-size:.78rem">Pay on Delivery</span>
          </div>
        </div>

        <button type="submit" name="place_order" value="1" class="btn-primary" style="width:100%;padding:1rem;font-size:1rem;border-radius:14px;justify-content:center;box-shadow:0 6px 20px rgba(249,115,22,.4);display:flex;align-items:center;gap:.5rem">
          <svg width="18" height="18" fill="none" stroke="#fff" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M8.5 14.5A2.5 2.5 0 0011 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 11-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 002.5 3z"/></svg>
          Place Order Now
        </button>
      </form>
    </div>

    <!-- Side cards -->
    <div style="display:flex;flex-direction:column;gap:1.25rem" class="anim-fade-right">
      <!-- Why Order -->
      <div style="background:linear-gradient(135deg,#0f172a,#1e293b);border-radius:20px;overflow:hidden;box-shadow:0 4px 24px rgba(0,0,0,.15)">
        <div style="padding:1.5rem 1.5rem 1.25rem;border-bottom:1px solid rgba(255,255,255,.06)">
          <div style="display:flex;align-items:center;gap:.6rem">
            <div style="width:36px;height:36px;border-radius:10px;background:linear-gradient(135deg,#f97316,#fb923c);display:flex;align-items:center;justify-content:center">
              <svg width="18" height="18" fill="none" stroke="#fff" stroke-width="2" viewBox="0 0 24 24"><polygon stroke-linecap="round" stroke-linejoin="round" points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/></svg>
            </div>
            <h3 style="color:#fff;font-weight:800;font-size:1rem;margin:0">Why Order With Us?</h3>
          </div>
        </div>
        <div style="padding:1.25rem 1.5rem;display:flex;flex-direction:column;gap:.85rem">
          <?php $whys = [
            ['svg'=>'<svg width="16" height="16" fill="none" stroke="#f97316" stroke-width="2" viewBox="0 0 24 24"><rect x="1" y="3" width="15" height="13" rx="2"/><path stroke-linecap="round" stroke-linejoin="round" d="M16 8h4l3 5v3h-7V8z"/><circle cx="5.5" cy="18.5" r="2.5"/><circle cx="18.5" cy="18.5" r="2.5"/></svg>','color'=>'#f97316','title'=>'Same-Day Delivery','desc'=>'Order before 2PM for same-day delivery'],
            ['svg'=>'<svg width="16" height="16" fill="none" stroke="#22c55e" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></svg>','color'=>'#22c55e','title'=>'100% Safe & Certified','desc'=>'All cylinders are safety-checked'],
            ['svg'=>'<svg width="16" height="16" fill="none" stroke="#fbbf24" stroke-width="2" viewBox="0 0 24 24"><line x1="12" y1="1" x2="12" y2="23"/><path stroke-linecap="round" stroke-linejoin="round" d="M17 5H9.5a3.5 3.5 0 000 7h5a3.5 3.5 0 010 7H6"/></svg>','color'=>'#fbbf24','title'=>'Best Prices','desc'=>'Competitive rates, no hidden charges'],
            ['svg'=>'<svg width="16" height="16" fill="none" stroke="#60a5fa" stroke-width="2" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><polyline stroke-linecap="round" stroke-linejoin="round" points="12 6 12 12 16 14"/></svg>','color'=>'#60a5fa','title'=>'24/7 Support','desc'=>'Always here when you need us'],
          ];
          foreach($whys as $w): ?>
          <div style="display:flex;align-items:flex-start;gap:.75rem">
            <div style="width:32px;height:32px;border-radius:8px;background:rgba(255,255,255,.06);border:1px solid rgba(255,255,255,.08);display:flex;align-items:center;justify-content:center;flex-shrink:0"><?= $w['svg'] ?></div>
            <div>
              <div style="color:#f1f5f9;font-weight:700;font-size:.85rem"><?= $w['title'] ?></div>
              <div style="color:#64748b;font-size:.78rem;margin-top:.1rem"><?= $w['desc'] ?></div>
            </div>
          </div>
          <?php endforeach; ?>
        </div>
      </div>

      <!-- How It Works -->
      <div style="background:#fff;border:1px solid #e2e8f0;border-radius:20px;overflow:hidden;box-shadow:0 2px 12px rgba(0,0,0,.06)">
        <div style="background:linear-gradient(135deg,#fff7ed,#ffedd5);padding:1.25rem 1.5rem;border-bottom:1px solid #fed7aa">
          <div style="display:flex;align-items:center;gap:.6rem">
            <div style="width:36px;height:36px;border-radius:10px;background:linear-gradient(135deg,#f97316,#fb923c);display:flex;align-items:center;justify-content:center">
            <svg width="18" height="18" fill="none" stroke="#fff" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M21 16V8a2 2 0 00-1-1.73l-7-4a2 2 0 00-2 0l-7 4A2 2 0 003 8v8a2 2 0 001 1.73l7 4a2 2 0 002 0l7-4A2 2 0 0021 16z"/><polyline stroke-linecap="round" stroke-linejoin="round" points="3.27 6.96 12 12.01 20.73 6.96"/><line x1="12" y1="22.08" x2="12" y2="12"/></svg>
          </div>
            <h3 style="color:#92400e;font-weight:800;font-size:1rem;margin:0">How It Works</h3>
          </div>
        </div>
        <div style="padding:1.25rem 1.5rem;display:flex;flex-direction:column;gap:0">
          <?php $howSteps = [
            ['n'=>1,'title'=>'Choose your cylinder','desc'=>'Pick size or enter custom weight'],
            ['n'=>2,'title'=>'Place your order','desc'=>'Fill address and submit'],
            ['n'=>3,'title'=>'We confirm','desc'=>'Get a call to confirm details'],
            ['n'=>4,'title'=>'Delivered to you','desc'=>'Fast safe delivery'],
          ];
          foreach($howSteps as $i => $hs): ?>
          <div style="display:flex;gap:.85rem;padding-bottom:<?= $i < 3 ? '1rem' : '0' ?>;position:relative">
            <?php if($i < 3): ?><div style="position:absolute;left:13px;top:30px;width:2px;height:calc(100% - 6px);background:linear-gradient(to bottom,#fed7aa,#ffedd5)"></div><?php endif; ?>
            <div style="width:28px;height:28px;border-radius:50%;background:linear-gradient(135deg,#f97316,#fb923c);display:flex;align-items:center;justify-content:center;flex-shrink:0;z-index:1;box-shadow:0 2px 8px rgba(249,115,22,.3)">
              <span style="color:#fff;font-weight:800;font-size:.72rem"><?= $hs['n'] ?></span>
            </div>
            <div style="padding-top:.15rem">
              <div style="color:#0f172a;font-weight:700;font-size:.875rem"><?= $hs['title'] ?></div>
              <div style="color:#94a3b8;font-size:.78rem;margin-top:.1rem"><?= $hs['desc'] ?></div>
            </div>
          </div>
          <?php endforeach; ?>
        </div>
      </div>
    </div>
  </div>
  <?php endif; ?>
</section>

<!-- COMPREHENSIVE SERVICES SECTION -->
<section style="background:linear-gradient(135deg,#f8fafc 0%,#f1f5f9 100%);padding:5rem 0;position:relative;overflow:hidden">
  <div style="position:absolute;inset:0;background-image:radial-gradient(circle,rgba(249,115,22,.03) 1px,transparent 1px);background-size:24px 24px;pointer-events:none"></div>
  
  <div style="max-width:1200px;margin:0 auto;padding:0 1.5rem;position:relative">
    <!-- Section Header -->
    <div style="text-align:center;margin-bottom:4rem" class="anim-fade-up">
      <div style="display:inline-flex;align-items:center;gap:.5rem;background:rgba(249,115,22,.1);border:1px solid rgba(249,115,22,.25);border-radius:50px;padding:.5rem 1.25rem;margin-bottom:1.5rem">
        <svg width="16" height="16" fill="none" stroke="#f97316" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M21 13.255A23.931 23.931 0 0112 15c-3.183 0-6.22-.62-9-1.745M16 6V4a2 2 0 00-2-2h-4a2 2 0 00-2 2v2m4 6h.01M5 20h14a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"/></svg>
        <span style="color:#f97316;font-size:.85rem;font-weight:700;letter-spacing:.06em">COMPLETE ENERGY SOLUTIONS</span>
      </div>
      <h2 style="font-size:clamp(2rem,4vw,2.75rem);font-weight:900;color:#0f172a;margin-bottom:1rem;line-height:1.15">Our Full Range of Services</h2>
      <p style="color:#64748b;font-size:1.05rem;line-height:1.7;max-width:680px;margin:0 auto">From residential gas delivery to industrial infrastructure, Stiles Energy Resources provides end-to-end energy solutions tailored to your needs.</p>
    </div>

    <!-- Services Grid -->
    <div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(340px,1fr));gap:2rem">
      
      <!-- Service 1: Oil Services and Procurement -->
      <div class="service-card anim-fade-up" style="background:#fff;border-radius:20px;padding:2rem;border:1px solid #e2e8f0;box-shadow:0 4px 24px rgba(0,0,0,.06);transition:all .3s ease">
        <div style="display:flex;align-items:flex-start;gap:1rem;margin-bottom:1.25rem">
          <div style="width:56px;height:56px;border-radius:14px;background:linear-gradient(135deg,#f97316,#fb923c);display:flex;align-items:center;justify-content:center;flex-shrink:0;box-shadow:0 6px 20px rgba(249,115,22,.3)">
            <svg width="28" height="28" fill="none" stroke="#fff" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M21 13.255A23.931 23.931 0 0112 15c-3.183 0-6.22-.62-9-1.745M16 6V4a2 2 0 00-2-2h-4a2 2 0 00-2 2v2m4 6h.01M5 20h14a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"/></svg>
          </div>
          <div>
            <span style="display:inline-block;background:#fff7ed;color:#ea580c;padding:.25rem .65rem;border-radius:20px;font-size:.7rem;font-weight:700;letter-spacing:.05em;margin-bottom:.5rem">SERVICE 01</span>
            <h3 style="color:#0f172a;font-weight:800;font-size:1.25rem;margin:0;line-height:1.3">Oil Services and Procurement</h3>
          </div>
        </div>
        <p style="color:#64748b;font-size:.95rem;line-height:1.75;margin:0">Provision of end-to-end sourcing and supply of petroleum products and related equipment. This includes vendor sourcing, bulk purchasing, logistics coordination, and timely delivery to meet industrial and commercial demand efficiently.</p>
      </div>

      <!-- Service 2: Gas Stations -->
      <div class="service-card anim-fade-up" style="background:#fff;border-radius:20px;padding:2rem;border:1px solid #e2e8f0;box-shadow:0 4px 24px rgba(0,0,0,.06);transition:all .3s ease;animation-delay:.1s">
        <div style="display:flex;align-items:flex-start;gap:1rem;margin-bottom:1.25rem">
          <div style="width:56px;height:56px;border-radius:14px;background:linear-gradient(135deg,#2563eb,#3b82f6);display:flex;align-items:center;justify-content:center;flex-shrink:0;box-shadow:0 6px 20px rgba(37,99,235,.3)">
            <svg width="28" height="28" fill="none" stroke="#fff" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"/></svg>
          </div>
          <div>
            <span style="display:inline-block;background:#eff6ff;color:#1e40af;padding:.25rem .65rem;border-radius:20px;font-size:.7rem;font-weight:700;letter-spacing:.05em;margin-bottom:.5rem">SERVICE 02</span>
            <h3 style="color:#0f172a;font-weight:800;font-size:1.25rem;margin:0;line-height:1.3">Gas Stations</h3>
          </div>
        </div>
        <p style="color:#64748b;font-size:.95rem;line-height:1.75;margin:0">Development, operation, and management of retail and commercial gas stations. Focused on safe dispensing, customer accessibility, and compliance with regulatory standards while ensuring consistent product availability.</p>
      </div>

      <!-- Service 3: CNG and LNG -->
      <div class="service-card anim-fade-up" style="background:#fff;border-radius:20px;padding:2rem;border:1px solid #e2e8f0;box-shadow:0 4px 24px rgba(0,0,0,.06);transition:all .3s ease;animation-delay:.2s">
        <div style="display:flex;align-items:flex-start;gap:1rem;margin-bottom:1.25rem">
          <div style="width:56px;height:56px;border-radius:14px;background:linear-gradient(135deg,#16a34a,#22c55e);display:flex;align-items:center;justify-content:center;flex-shrink:0;box-shadow:0 6px 20px rgba(22,163,74,.3)">
            <svg width="28" height="28" fill="none" stroke="#fff" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M13 10V3L4 14h7v7l9-11h-7z"/></svg>
          </div>
          <div>
            <span style="display:inline-block;background:#f0fdf4;color:#15803d;padding:.25rem .65rem;border-radius:20px;font-size:.7rem;font-weight:700;letter-spacing:.05em;margin-bottom:.5rem">SERVICE 03</span>
            <h3 style="color:#0f172a;font-weight:800;font-size:1.25rem;margin:0;line-height:1.3">CNG and LNG Solutions</h3>
          </div>
        </div>
        <p style="color:#64748b;font-size:.95rem;line-height:1.75;margin:0">Supply and infrastructure support for Compressed Natural Gas (CNG) and Liquefied Natural Gas (LNG). Includes distribution systems, storage solutions, and conversion support for cleaner and cost-effective energy alternatives.</p>
      </div>

      <!-- Service 4: LPG Assemblies -->
      <div class="service-card anim-fade-up" style="background:#fff;border-radius:20px;padding:2rem;border:1px solid #e2e8f0;box-shadow:0 4px 24px rgba(0,0,0,.06);transition:all .3s ease;animation-delay:.3s">
        <div style="display:flex;align-items:flex-start;gap:1rem;margin-bottom:1.25rem">
          <div style="width:56px;height:56px;border-radius:14px;background:linear-gradient(135deg,#7c3aed,#a855f7);display:flex;align-items:center;justify-content:center;flex-shrink:0;box-shadow:0 6px 20px rgba(124,58,237,.3)">
            <svg width="28" height="28" fill="none" stroke="#fff" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M8.5 14.5A2.5 2.5 0 0011 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 11-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 002.5 3z"/></svg>
          </div>
          <div>
            <span style="display:inline-block;background:#f5f3ff;color:#6d28d9;padding:.25rem .65rem;border-radius:20px;font-size:.7rem;font-weight:700;letter-spacing:.05em;margin-bottom:.5rem">SERVICE 04</span>
            <h3 style="color:#0f172a;font-weight:800;font-size:1.25rem;margin:0;line-height:1.3">LPG Assemblies & Accessories</h3>
          </div>
        </div>
        <p style="color:#64748b;font-size:.95rem;line-height:1.75;margin:0">Sales, installation, and maintenance of LPG systems including stoves, burners, cylinders, and accessories. Ensures safety, efficiency, and suitability for both residential and commercial users.</p>
      </div>

      <!-- Service 5: Skid Construction -->
      <div class="service-card anim-fade-up" style="background:#fff;border-radius:20px;padding:2rem;border:1px solid #e2e8f0;box-shadow:0 4px 24px rgba(0,0,0,.06);transition:all .3s ease;animation-delay:.4s">
        <div style="display:flex;align-items:flex-start;gap:1rem;margin-bottom:1.25rem">
          <div style="width:56px;height:56px;border-radius:14px;background:linear-gradient(135deg,#dc2626,#ef4444);display:flex;align-items:center;justify-content:center;flex-shrink:0;box-shadow:0 6px 20px rgba(220,38,38,.3)">
            <svg width="28" height="28" fill="none" stroke="#fff" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M19.428 15.428a2 2 0 00-1.022-.547l-2.387-.477a6 6 0 00-3.86.517l-.318.158a6 6 0 01-3.86.517L6.05 15.21a2 2 0 00-1.806.547M8 4h8l-1 1v5.172a2 2 0 00.586 1.414l5 5c1.26 1.26.367 3.414-1.415 3.414H4.828c-1.782 0-2.674-2.154-1.414-3.414l5-5A2 2 0 009 10.172V5L8 4z"/></svg>
          </div>
          <div>
            <span style="display:inline-block;background:#fef2f2;color:#b91c1c;padding:.25rem .65rem;border-radius:20px;font-size:.7rem;font-weight:700;letter-spacing:.05em;margin-bottom:.5rem">SERVICE 05</span>
            <h3 style="color:#0f172a;font-weight:800;font-size:1.25rem;margin:0;line-height:1.3">Skid Construction & Setup</h3>
          </div>
        </div>
        <p style="color:#64748b;font-size:.95rem;line-height:1.75;margin:0">Design, fabrication, and installation of modular skid systems for fuel storage and dispensing. Ideal for industrial and remote operations requiring compact, mobile, and efficient fuel solutions.</p>
      </div>

      <!-- Service 6: Oil and Gas Services -->
      <div class="service-card anim-fade-up" style="background:#fff;border-radius:20px;padding:2rem;border:1px solid #e2e8f0;box-shadow:0 4px 24px rgba(0,0,0,.06);transition:all .3s ease;animation-delay:.5s">
        <div style="display:flex;align-items:flex-start;gap:1rem;margin-bottom:1.25rem">
          <div style="width:56px;height:56px;border-radius:14px;background:linear-gradient(135deg,#d97706,#f59e0b);display:flex;align-items:center;justify-content:center;flex-shrink:0;box-shadow:0 6px 20px rgba(217,119,6,.3)">
            <svg width="28" height="28" fill="none" stroke="#fff" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"/><path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/></svg>
          </div>
          <div>
            <span style="display:inline-block;background:#fffbeb;color:#92400e;padding:.25rem .65rem;border-radius:20px;font-size:.7rem;font-weight:700;letter-spacing:.05em;margin-bottom:.5rem">SERVICE 06</span>
            <h3 style="color:#0f172a;font-weight:800;font-size:1.25rem;margin:0;line-height:1.3">Oil & Gas Services</h3>
          </div>
        </div>
        <p style="color:#64748b;font-size:.95rem;line-height:1.75;margin:0">Integrated support services across the oil and gas sector, including equipment sourcing, technical support, maintenance services, and supply chain solutions tailored to client needs.</p>
      </div>

      <!-- Service 7: LPG Sales / Distribution -->
      <div class="service-card anim-fade-up" style="background:#fff;border-radius:20px;padding:2rem;border:1px solid #e2e8f0;box-shadow:0 4px 24px rgba(0,0,0,.06);transition:all .3s ease;animation-delay:.6s">
        <div style="display:flex;align-items:flex-start;gap:1rem;margin-bottom:1.25rem">
          <div style="width:56px;height:56px;border-radius:14px;background:linear-gradient(135deg,#0891b2,#06b6d4);display:flex;align-items:center;justify-content:center;flex-shrink:0;box-shadow:0 6px 20px rgba(8,145,178,.3)">
            <svg width="28" height="28" fill="none" stroke="#fff" stroke-width="2" viewBox="0 0 24 24"><rect x="1" y="3" width="15" height="13" rx="2"/><path stroke-linecap="round" stroke-linejoin="round" d="M16 8h4l3 3v5h-7V8z"/><circle cx="5.5" cy="18.5" r="2.5"/><circle cx="18.5" cy="18.5" r="2.5"/></svg>
          </div>
          <div>
            <span style="display:inline-block;background:#ecfeff;color:#0e7490;padding:.25rem .65rem;border-radius:20px;font-size:.7rem;font-weight:700;letter-spacing:.05em;margin-bottom:.5rem">SERVICE 07</span>
            <h3 style="color:#0f172a;font-weight:800;font-size:1.25rem;margin:0;line-height:1.3">LPG Sales & 24/7 Delivery</h3>
          </div>
        </div>
        <p style="color:#64748b;font-size:.95rem;line-height:1.75;margin:0">Retail and bulk LPG supply with a strong distribution network offering reliable and round-the-clock home delivery services, ensuring convenience and uninterrupted access for customers.</p>
      </div>

      <!-- Service 8: Commercial Central Gas Systems -->
      <div class="service-card anim-fade-up" style="background:#fff;border-radius:20px;padding:2rem;border:1px solid #e2e8f0;box-shadow:0 4px 24px rgba(0,0,0,.06);transition:all .3s ease;animation-delay:.7s">
        <div style="display:flex;align-items:flex-start;gap:1rem;margin-bottom:1.25rem">
          <div style="width:56px;height:56px;border-radius:14px;background:linear-gradient(135deg,#db2777,#ec4899);display:flex;align-items:center;justify-content:center;flex-shrink:0;box-shadow:0 6px 20px rgba(219,39,119,.3)">
            <svg width="28" height="28" fill="none" stroke="#fff" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"/></svg>
          </div>
          <div>
            <span style="display:inline-block;background:#fce7f3;color:#be185d;padding:.25rem .65rem;border-radius:20px;font-size:.7rem;font-weight:700;letter-spacing:.05em;margin-bottom:.5rem">SERVICE 08</span>
            <h3 style="color:#0f172a;font-weight:800;font-size:1.25rem;margin:0;line-height:1.3">Commercial Central Gas Systems</h3>
          </div>
        </div>
        <p style="color:#64748b;font-size:.95rem;line-height:1.75;margin:0">Design and installation of centralized gas pipeline systems for large facilities like hotels, schools, hostels, and hospitals. Enhances efficiency, safety, and cost management through structured gas distribution and industrial storage solutions.</p>
      </div>

      <!-- Service 9: Estates Central Gas Station -->
      <div class="service-card anim-fade-up" style="background:#fff;border-radius:20px;padding:2rem;border:1px solid #e2e8f0;box-shadow:0 4px 24px rgba(0,0,0,.06);transition:all .3s ease;animation-delay:.8s">
        <div style="display:flex;align-items:flex-start;gap:1rem;margin-bottom:1.25rem">
          <div style="width:56px;height:56px;border-radius:14px;background:linear-gradient(135deg,#0d9488,#14b8a6);display:flex;align-items:center;justify-content:center;flex-shrink:0;box-shadow:0 6px 20px rgba(13,148,136,.3)">
            <svg width="28" height="28" fill="none" stroke="#fff" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"/></svg>
          </div>
          <div>
            <span style="display:inline-block;background:#f0fdfa;color:#115e59;padding:.25rem .65rem;border-radius:20px;font-size:.7rem;font-weight:700;letter-spacing:.05em;margin-bottom:.5rem">SERVICE 09</span>
            <h3 style="color:#0f172a;font-weight:800;font-size:1.25rem;margin:0;line-height:1.3">Estates Gas Reticulation</h3>
          </div>
        </div>
        <p style="color:#64748b;font-size:.95rem;line-height:1.75;margin:0">Development of centralized gas supply and reticulation systems within residential estates. Provides a safe, efficient, and scalable gas distribution network for multiple housing units from a single source.</p>
      </div>
    </div>

    <!-- Call to Action -->
    <div class="anim-scale" style="margin-top:4rem;background:linear-gradient(135deg,#0f172a,#1e293b);border-radius:24px;padding:3rem 2.5rem;text-align:center;position:relative;overflow:hidden;box-shadow:0 8px 40px rgba(0,0,0,.15)">
      <div style="position:absolute;top:-60px;right:-60px;width:240px;height:240px;background:radial-gradient(circle,rgba(249,115,22,.15) 0%,transparent 70%);pointer-events:none"></div>
      <div style="position:relative;z-index:1">
        <h3 style="color:#fff;font-weight:900;font-size:1.8rem;margin-bottom:1rem">Need a Custom Energy Solution?</h3>
        <p style="color:#94a3b8;font-size:1.05rem;line-height:1.7;max-width:600px;margin:0 auto 2rem">Our team of experts is ready to design and implement tailored energy infrastructure for your specific requirements.</p>
        <div style="display:flex;gap:1rem;justify-content:center;flex-wrap:wrap">
          <a href="/stile-lpg/contact.php" class="btn-primary" style="padding:1rem 2rem;font-size:1rem;border-radius:14px;box-shadow:0 6px 24px rgba(249,115,22,.4)">
            Contact Our Team
            <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/></svg>
          </a>
          <a href="tel:+2348000000000" style="display:inline-flex;align-items:center;gap:.6rem;background:rgba(255,255,255,.1);border:2px solid rgba(255,255,255,.2);color:#fff;padding:1rem 2rem;border-radius:14px;font-weight:700;text-decoration:none;font-size:1rem;transition:all .3s ease">
            <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 16.92v3a2 2 0 01-2.18 2 19.79 19.79 0 01-8.63-3.07A19.5 19.5 0 013.07 9.81 19.79 19.79 0 01.06 1.18 2 2 0 012 0h3a2 2 0 012 1.72 12.84 12.84 0 00.7 2.81 2 2 0 01-.45 2.11L6.09 7.91a16 16 0 006 6l1.27-1.27a2 2 0 012.11-.45 12.84 12.84 0 002.81.7A2 2 0 0122 14z"/></svg>
            Call Us Now
          </a>
        </div>
      </div>
    </div>
  </div>
</section>

<style>
@media(max-width:900px){.services-main-grid{grid-template-columns:1fr!important}}
@media(max-width:600px){.form-row{grid-template-columns:1fr!important}}
.service-card:hover{transform:translateY(-8px);box-shadow:0 12px 40px rgba(0,0,0,.12)!important;border-color:#f97316!important}
</style>

<script>
const NGN_PER_KG = 550;
const products = <?= json_encode($lpgProducts) ?>;

function updateTotal() {
  const customKg = parseFloat(document.getElementById('custom_kg')?.value) || 0;
  const qty      = parseInt(document.getElementById('qty')?.value) || 1;
  const hint     = document.getElementById('custom_price_hint');
  let total = 0;

  if(customKg > 0) {
    total = Math.round(customKg * NGN_PER_KG * qty);
    if(hint) {
      hint.style.display = 'block';
      hint.textContent = '≈ ₦' + Math.round(customKg * NGN_PER_KG).toLocaleString() + ' at ₦' + NGN_PER_KG + '/kg';
    }
  } else {
    if(hint) hint.style.display = 'none';
    const sel = document.getElementById('product_select');
    if(sel && sel.selectedIndex >= 0) {
      const selectedId = sel.value;
      if(selectedId && products && products.length > 0) {
        const product = products.find(p => p.id === selectedId);
        if(product) {
          total = parseFloat(product.price) * qty;
        }
      }
    }
  }
  const display = document.getElementById('total_display');
  if(display) {
    display.textContent = '₦' + total.toLocaleString();
  }
}

function toggleAddress() {
  const row = document.getElementById('address_row');
  const fulfillment = document.getElementById('fulfillment');
  if(row && fulfillment) {
    row.style.display = fulfillment.value === 'delivery' ? 'block' : 'none';
  }
}

// Initialize on page load
window.addEventListener('DOMContentLoaded', function() {
  const productSelect = document.getElementById('product_select');
  const qtyInput = document.getElementById('qty');
  
  if(productSelect) {
    productSelect.addEventListener('change', updateTotal);
  }
  if(qtyInput) {
    qtyInput.addEventListener('input', updateTotal);
  }
  
  // Initial update
  setTimeout(updateTotal, 100);
});
</script>

<?php require_once __DIR__ . '/backend/includes/footer.php'; ?>
