<!DOCTYPE html>
<html lang="en" class="scroll-smooth">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Mount Kenya Expeditions | Guided Tours & Trekking Packages</title>
  <meta name="description" content="Discover professionally guided Mount Kenya expeditions—Sirimon, Chogoria, Naro Moru & more. All-inclusive, KWS-certified, with expert high-altitude logistics." />
  
  <link rel="canonical" href="<?= base_url('tours') ?>" />
  
  <link rel="stylesheet" href="<?= base_url('css/uno.css') ?>" />
</head>
<body class="font-sans bg-light text-muted antialiased min-h-screen flex flex-col pt-28 selection:bg-secondary selection:text-white">

  <?= $this->include('App\Modules\Frontend\Views\partials\_safety_bar') ?>
  <?= $this->include('App\Modules\Frontend\Views\partials\_nav') ?>

  <script type="application/ld+json">
  {
    "@context": "https://schema.org",
    "@type": "WebPage",
    "name": "Mount Kenya Expeditions",
    "description": "Professionally guided Mount Kenya tours with all-inclusive permits, certified guides, and full logistical support.",
    "url": "<?= base_url('tours') ?>",
    "mainEntity": {
      "@type": "ItemList",
      "itemListElement": [
        <?php 
          $items = is_array($tours) ? array_slice($tours, 0, 10) : []; 
          $count = count($items);
          foreach ($items as $index => $tour): 
        ?>
        {
          "@type": "ListItem",
          "position": <?= $index + 1 ?>,
          "item": {
            "@type": "TouristTrip",
            "name": "<?= esc($tour['title']) ?>",
            "description": "<?= esc(strip_tags($tour['description'])) ?>",
            "url": "<?= base_url('tours/' . $tour['slug']) ?>",
            "offers": {
              "@type": "Offer",
              "priceCurrency": "USD",
              "price": "<?= (float)$tour['price_usd'] ?>",
              "availability": "https://schema.org/InStock"
            }
          }
        }<?= ($index < $count - 1) ? ',' : '' ?>
        <?php endforeach; ?>
      ]
    }
  }
  </script>

  <main class="flex-grow w-full relative z-10">
    <div class="bg-light min-h-screen font-sans pb-24 text-navy">
      <header class="bg-surface pt-16 pb-8 border-b border-border">
        <div class="container mx-auto px-6">
          <div class="mb-6">
            <a href="<?= base_url('/') ?>" class="inline-flex items-center gap-2 text-[11px] font-bold uppercase tracking-widest text-navy hover:text-secondary transition-colors group">
              <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="group-hover:-translate-x-0.5 transition-transform">
                <path d="m12 19-7-7 7-7" />
                <path d="M19 12H5" />
              </svg>
              Back to Home
            </a>
          </div>

          <nav aria-label="Breadcrumb" class="flex mb-6 text-[9px] font-black uppercase tracking-[0.3em]">
            <ol class="flex items-center gap-3 list-none p-0 m-0">
              <li>
                <a href="<?= base_url('/') ?>" class="text-secondary hover:underline transition-all">Home</a>
              </li>
              <li class="text-muted/30 select-none" aria-hidden="true">/</li>
              <li class="text-muted">Tours</li>
            </ol>
          </nav>

          <div class="max-w-2xl">
            <h1 class="text-4xl md:text-5xl font-black uppercase tracking-tighter leading-[0.9] mb-3">
              Mount Kenya <span class="text-secondary">Expeditions</span>
            </h1>
            <p class="text-muted text-sm font-medium leading-relaxed">
              Professionally guided, all-inclusive treks with certified high-altitude teams. Choose your route, difficulty, and summit date.
            </p>
          </div>
        </div>
      </header>

      <section class="container mx-auto px-6 py-12">
        <?php if (empty($tours)): ?>
          <div class="py-24 text-center border-2 border-dashed border-border rounded-3xl">
            <p class="text-muted italic text-lg">No expeditions are currently scheduled. Check back soon!</p>
          </div>
        <?php else: ?>
          <div class="grid gap-8">
            <?php foreach ($tours as $tour): ?>
              <?php
                $images = !empty($tour['images']) ? json_decode($tour['images'], true) : [];
                $firstImage = !empty($images) ? $images[0] : null;
                $diff = strtolower($tour['difficulty']);
                $difficultyLabel = match($diff) {
                  'beginner' => 'Standard',
                  'intermediate' => 'Challenging',
                  'advanced' => 'Elite',
                  default => 'Standard'
                };
              ?>

              <article class="group bg-surface rounded-3xl border border-border/50 flex flex-col md:flex-row overflow-hidden hover:border-secondary/40 hover:shadow-xl transition-all duration-500">
                <div class="md:w-80 h-60 md:h-auto shrink-0 relative overflow-hidden bg-border/20">
                  <?php if ($firstImage): ?>
                    <img 
                      src="<?= esc(base_url('assets/uploads/tours/' . $firstImage)) ?>" 
                      alt="<?= esc($tour['title']) ?> — Guided Mount Kenya Trek" 
                      loading="lazy"
                      class="w-full h-full object-cover grayscale group-hover:grayscale-0 group-hover:scale-105 transition-all duration-700"
                    >
                  <?php else: ?>
                    <div class="w-full h-full flex items-center justify-center text-muted/60 text-sm font-bold">Expedition Image</div>
                  <?php endif; ?>

                  <div class="absolute top-4 left-4">
                    <span class="bg-primary/90 backdrop-blur-sm text-white text-[9px] font-black uppercase tracking-widest px-3 py-1.5 rounded">
                      <?= strtoupper(substr($tour['slug'] ?? 'EXPEDITION', 0, 8)) ?>
                    </span>
                  </div>
                </div>

                <div class="flex-1 p-6 flex flex-col">
                  <div class="flex flex-wrap gap-x-6 gap-y-3 mb-5 text-sm">
                    <div><span class="text-muted text-xs">Duration:</span> <span class="font-bold text-navy"><?= esc($tour['duration_days']) ?> Days</span></div>
                    <div><span class="text-muted text-xs">Grade:</span> <span class="font-bold text-secondary"><?= $difficultyLabel ?></span></div>
                  </div>

                  <h2 class="text-2xl font-black text-navy mb-3 group-hover:text-secondary transition-colors">
                    <?= esc($tour['title']) ?>
                  </h2>

                  <p class="text-muted mb-6 flex-grow line-clamp-2">
                    <?= esc(strip_tags($tour['description'])) ?>
                  </p>

                  <div class="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
                    <div>
                      <span class="text-muted text-xs block mb-1">From</span>
                      <span class="text-xl md:text-2xl font-black text-navy">USD <?= number_format((float)$tour['price_usd']) ?></span>
                    </div>
                    <a 
                      href="<?= base_url('tours/' . $tour['slug']) ?>" 
                      aria-label="View full details for <?= esc($tour['title']) ?>"
                      class="px-6 py-3 bg-secondary text-white font-bold text-[11px] uppercase tracking-widest rounded-full hover:bg-accent transition-colors shadow hover:shadow-md whitespace-nowrap"
                    >
                      View Details
                    </a>
                  </div>
                </div>
              </article>
            <?php endforeach; ?>
          </div>

          <?php if (isset($pagination) && $pagination): ?>
            <nav aria-label="Pagination" class="mt-12 flex justify-center">
              <ul class="flex items-center gap-1 list-none">
                <?php if ($pagination['has_previous']): ?>
                  <li>
                    <a href="<?= base_url("tours?page={$pagination['previous']}") ?>" 
                       class="w-10 h-10 flex items-center justify-center rounded-full border border-border text-navy hover:bg-primary/5 hover:text-secondary transition-colors"
                       aria-label="Previous page">
                      <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                        <polyline points="15 18 9 12 15 6" />
                      </svg>
                    </a>
                  </li>
                <?php endif; ?>

                <?php foreach ($pagination['links'] as $page => $url): ?>
                  <li>
                    <a 
                      href="<?= $url ?>" 
                      class="w-10 h-10 flex items-center justify-center rounded-full <?= $page == $pagination['current'] ? 'bg-secondary text-white' : 'border border-border text-navy hover:bg-primary/5' ?> transition-colors"
                      aria-label="<?= $page == $pagination['current'] ? "Current page, page $page" : "Go to page $page" ?>"
                      aria-current="<?= $page == $pagination['current'] ? 'page' : false ?>"
                    >
                      <?= $page ?>
                    </a>
                  </li>
                <?php endforeach; ?>

                <?php if ($pagination['has_next']): ?>
                  <li>
                    <a href="<?= base_url("tours?page={$pagination['next']}") ?>" 
                       class="w-10 h-10 flex items-center justify-center rounded-full border border-border text-navy hover:bg-primary/5 hover:text-secondary transition-colors"
                       aria-label="Next page">
                      <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                        <polyline points="9 18 15 12 9 6" />
                      </svg>
                    </a>
                  </li>
                <?php endif; ?>
              </ul>
            </nav>
          <?php endif; ?>

        <?php endif; ?>
      </section>
    </div>
  </main>

  <?= $this->include('App\Modules\Frontend\Views\partials\_footer') ?>

</body>
</html>