// Centralized tours dataset (expandable)
const TOURS = [
  {
    id: 'maasai-mara',
    title: 'Maasai Mara Classic Safari',
    region: 'Safari & Nature',
    nights: 3,
    hero: 'https://upload.wikimedia.org/wikipedia/commons/7/75/Three_zebras_in_Masai_Mara_National_Park%2C_Kenya.jpg',
    gallery: [
      'https://upload.wikimedia.org/wikipedia/commons/9/9c/Syncerus_caffer_in_the_Maasai_Mara_Game_Reserve_01.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/9/9c/Syncerus_caffer_in_the_Maasai_Mara_Game_Reserve_01.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/9/9c/Syncerus_caffer_in_the_Maasai_Mara_Game_Reserve_01.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/9/9c/Syncerus_caffer_in_the_Maasai_Mara_Game_Reserve_01.jpg'
    ],
    short: 'Witness abundant wildlife in the legendary Maasai Mara ecosystem.',
    long: `The Maasai Mara Classic Safari takes you into the heart of one of Africa's most famous conservation areas. Over three immersive days you'll explore sweeping savannahs, winding rivers and prime game-viewing habitats with experienced local guides. Expect close encounters with the Big Five, abundant plains game and prolific birdlife.\n\nWe work with trusted camps that blend comfort with authenticity. Each day is tailored to maximise sightings — morning and afternoon game drives bookend relaxing midday breaks. Optional hot-air balloon safari and cultural visits to Maasai communities can be added to enrich the experience.`,
    highlights: ['Big Five sightings','Hot-air balloon option','Authentic tented camps']
  },
  {
    id: 'tsavo-west',
    title: 'Tsavo West Adventure',
    region: 'Safari & Nature',
    nights: 2,
    hero: 'https://upload.wikimedia.org/wikipedia/commons/d/d7/View_of_the_Tsavo_River_in_Tsavo_West_National_Park_%28edited%29.jpg',
    gallery: [
      'https://upload.wikimedia.org/wikipedia/commons/9/98/Tsavo_West%2C_Kenya_%2853341812222%29.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/9/98/Tsavo_West%2C_Kenya_%2853341812222%29.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/9/98/Tsavo_West%2C_Kenya_%2853341812222%29.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/9/98/Tsavo_West%2C_Kenya_%2853341812222%29.jpg'
    ],
    short: 'Rolling plains, volcanic ridges and the famed Mzima Springs.',
    long: `Tsavo West presents dramatic landscapes and varied habitats ideal for wildlife viewing. Highlights include the crystal-clear Mzima Springs, prehistoric rock formations and excellent predator sightings.\n\nExpect guided game drives across open plains and visits to scenic viewpoints. Comfortable lodge or tented-camp options are available, providing a true bush experience.`,
    highlights: ['Mzima Springs','Scenic viewpoints','Great predator sightings']
  },
  {
    id: 'lake-nakuru',
    title: 'Lake Nakuru Birding & Rhino Walk',
    region: 'Safari & Nature',
    nights: 1,
    hero: 'https://upload.wikimedia.org/wikipedia/commons/1/1d/Le%C3%B3n_%28Panthera_leo%29%2C_parque_nacional_del_lago_Nakuru%2C_Kenia%2C_2024-05-18%2C_DD_59.jpg',
    gallery: [
      'https://upload.wikimedia.org/wikipedia/commons/1/1d/Le%C3%B3n_%28Panthera_leo%29%2C_parque_nacional_del_lago_Nakuru%2C_Kenia%2C_2024-05-18%2C_DD_59.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/1/1d/Le%C3%B3n_%28Panthera_leo%29%2C_parque_nacional_del_lago_Nakuru%2C_Kenia%2C_2024-05-18%2C_DD_59.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/1/1d/Le%C3%B3n_%28Panthera_leo%29%2C_parque_nacional_del_lago_Nakuru%2C_Kenia%2C_2024-05-18%2C_DD_59.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/1/1d/Le%C3%B3n_%28Panthera_leo%29%2C_parque_nacional_del_lago_Nakuru%2C_Kenia%2C_2024-05-18%2C_DD_59.jpg'
    ],
    short: 'World-class birding and rhino conservation zones.',
    long: `Lake Nakuru National Park is famed for its birdlife and rhino sanctuary. The shallow lake attracts thousands of flamingos in favourable seasons and creates spectacular colours across the shoreline.\n\nGuided walks and game drives focus on birdwatching and conservation; ideal for nature photographers and travellers seeking a short, wildlife-packed excursion.`,
    highlights: ['Flamingo viewing','Rhino sanctuary','Birdwatching trails']
  },
  {
    id: 'samburu',
    title: 'Samburu Drylands Safari',
    region: 'Safari & Nature',
    nights: 3,
    hero: 'https://upload.wikimedia.org/wikipedia/commons/6/6a/Samburu_National_Reserve%2C_Kenya-26December2012.jpg',
    gallery: [
      'https://upload.wikimedia.org/wikipedia/commons/5/5d/Samburu_%28%D1%81%D0%B0%D0%BC%D0%B1%D1%83%D1%80%D1%83%29.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/5/5d/Samburu_%28%D1%81%D0%B0%D0%BC%D0%B1%D1%83%D1%80%D1%83%29.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/5/5d/Samburu_%28%D1%81%D0%B0%D0%BC%D0%B1%D1%83%D1%80%D1%83%29.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/5/5d/Samburu_%28%D1%81%D0%B0%D0%BC%D0%B1%D1%83%D1%80%D1%83%29.jpg'
    ],
    short: 'Unique dry-country species including the reticulated giraffe and gerenuk.',
    long: `Samburu Reserve on the banks of the Ewaso Ng'iro river hosts species adapted to the arid north. Expect rare sightings such as Grevy's zebra, Somali ostrich and the long-necked gerenuk.\n\nDaily game drives and riverine walks reveal a contrasting ecosystem to the southern parks; cultural visits to local Samburu communities add depth to the experience.`,
    highlights: ['Rare northern species','River wildlife','Cultural visits']
  },
  {
    id: 'ol-pejeta',
    title: 'Ol Pejeta Conservancy Experience',
    region: 'Safari & Nature',
    nights: 2,
    hero: 'https://upload.wikimedia.org/wikipedia/commons/e/e2/Ceratotherium_simum_cottoni_-Ol_Pejeta_Conservancy%2C_Kenya.jpg',
    gallery: [
      'https://upload.wikimedia.org/wikipedia/commons/f/fa/Ol_Pejeta_%2817121231701%29.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/f/fa/Ol_Pejeta_%2817121231701%29.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/f/fa/Ol_Pejeta_%2817121231701%29.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/f/fa/Ol_Pejeta_%2817121231701%29.jpg'
    ],
    short: 'Conservation-led conservancy famed for rhino protection and chimpanzee sanctuary.',
    long: `Ol Pejeta is a model of modern conservation, home to black rhinos and the Sweetwaters Chimpanzee Sanctuary. The conservancy offers close-up conservation experiences and high-quality game viewing in a secure environment.\n\nGuests can learn about anti-poaching work, visit the chimp sanctuary and enjoy guided drives across rolling plains.`,
    highlights: ['Rhino conservation','Chimpanzee sanctuary','Education visits']
  },
  {
    id: 'nairobi-np',
    title: 'Nairobi National Park Half-Day',
    region: 'Safari & Nature',
    nights: 0,
    hero: 'https://upload.wikimedia.org/wikipedia/commons/3/33/Gyps_rueppellii_-Nairobi_National_Park%2C_Kenya-8-4c.jpg',
    gallery: [
      'https://upload.wikimedia.org/wikipedia/commons/3/3c/Kori_Bustard%2C_Nairobi_NP%2C_Kenya_%284431233209%29.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/3/3c/Kori_Bustard%2C_Nairobi_NP%2C_Kenya_%284431233209%29.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/3/3c/Kori_Bustard%2C_Nairobi_NP%2C_Kenya_%284431233209%29.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/3/3c/Kori_Bustard%2C_Nairobi_NP%2C_Kenya_%284431233209%29.jpg'
    ],
    short: 'A unique park within easy reach of Nairobi city.',
    long: `Nairobi National Park offers dramatic contrasts — wildlife with a skyline view. Perfect for travellers with limited time, the park supports resident populations of lion, giraffe and rhino and provides an accessible introduction to Kenyan wildlife.\n\nCity-based safaris can be paired with Nairobi attractions and conservation centres for a compact wildlife experience.`,
    highlights: ['Close to Nairobi','Great for short visits','Conservation education']
  },
  {
    id: 'meru',
    title: 'Meru Wilderness Safari',
    region: 'Safari & Nature',
    nights: 3,
    hero: 'https://upload.wikimedia.org/wikipedia/commons/c/c4/Meru_National_Park%2C_Kenya.jpg',
    gallery: [
      'https://upload.wikimedia.org/wikipedia/commons/5/56/Mus%C3%A9e_Guimet_-_Le_Monde_vu_d%27Asie_-_Cosmogramme_avec_le_Mont_Meru_-_gradient.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/5/56/Mus%C3%A9e_Guimet_-_Le_Monde_vu_d%27Asie_-_Cosmogramme_avec_le_Mont_Meru_-_gradient.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/5/56/Mus%C3%A9e_Guimet_-_Le_Monde_vu_d%27Asie_-_Cosmogramme_avec_le_Mont_Meru_-_gradient.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/5/56/Mus%C3%A9e_Guimet_-_Le_Monde_vu_d%27Asie_-_Cosmogramme_avec_le_Mont_Meru_-_gradient.jpg'
    ],
    short: 'Remote, regenerating ecosystems and rich biodiversity.',
    long: `Meru National Park is a recovering wilderness with a fascinating conservation story. The park offers solitude, varied habitats and excellent birdlife; it is an ideal choice for guests seeking quieter, authentic bush experiences.\n\nGuided walks and drives explore riverine corridors and open plains where iconic wildlife are often seen without the crowds found elsewhere.`,
    highlights: ['Remote wilderness','Birding','Quiet game drives']
  },
  {
    id: 'aberdare',
    title: 'Aberdare Highlands Retreat',
    region: 'Safari & Nature',
    nights: 1,
    hero: 'https://upload.wikimedia.org/wikipedia/commons/6/6a/Aberdare_Ranges.jpg',
    gallery: [
      'https://upload.wikimedia.org/wikipedia/commons/b/b5/Aberdare_Canal_near_Aberdare_-_geograph.org.uk_-_4950653.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/b/b5/Aberdare_Canal_near_Aberdare_-_geograph.org.uk_-_4950653.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/b/b5/Aberdare_Canal_near_Aberdare_-_geograph.org.uk_-_4950653.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/b/b5/Aberdare_Canal_near_Aberdare_-_geograph.org.uk_-_4950653.jpg'
    ],
    short: 'Misty forests, waterfalls and highland wildlife.',
    long: `The Aberdare Range combines montane forests, deep valleys and rich birdlife. Visitors often enjoy lodge-based wildlife viewing, forest walks and visits to scenic waterfalls.\n\nAberdare also offers heritage stays and opportunities to observe elusive species in a cool, high-altitude setting.`,
    highlights: ['Forest walks','Waterfalls','Cool highland climate']
  },
  {
    id: 'mount-kenya',
    title: 'Mount Kenya Scenic Visit',
    region: 'Safari & Nature',
    nights: 2,
    hero: 'https://upload.wikimedia.org/wikipedia/commons/9/98/Mount_Kenya_National_Park_%2854249088307%29.jpg',
    gallery: [
      'https://upload.wikimedia.org/wikipedia/commons/d/d6/Mount_Kenya_National_Park.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/d/d6/Mount_Kenya_National_Park.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/d/d6/Mount_Kenya_National_Park.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/d/d6/Mount_Kenya_National_Park.jpg'
    ],
    short: 'High-mountain scenery and alpine flora.',
    long: `Mount Kenya, a UNESCO World Heritage site, offers dramatic alpine scenery and unique flora. This scenic visit focuses on lower-altitude day walks, wildlife viewing and cultural interactions in nearby highland communities.\n\nFor climbers, guided summit attempts are available but require acclimatisation and separate planning.`,
    highlights: ['Alpine scenery','Day walks','Cultural visits']
  },
  {
    id: 'hells-gate',
    title: 'Hell\'s Gate Active Day',
    region: 'Safari & Nature',
    nights: 0,
    hero: 'https://upload.wikimedia.org/wikipedia/commons/5/54/Hell%27s_Gate_Gorge_%282294202692%29.jpg',
    gallery: [
      'https://upload.wikimedia.org/wikipedia/commons/3/37/Gate_of_Hell_%281953%29_Press_Photo_of_Machiko_Ky%C5%8D_and_Kazuo_Hasegawa.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/3/37/Gate_of_Hell_%281953%29_Press_Photo_of_Machiko_Ky%C5%8D_and_Kazuo_Hasegawa.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/3/37/Gate_of_Hell_%281953%29_Press_Photo_of_Machiko_Ky%C5%8D_and_Kazuo_Hasegawa.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/3/37/Gate_of_Hell_%281953%29_Press_Photo_of_Machiko_Ky%C5%8D_and_Kazuo_Hasegawa.jpg'
    ],
    short: 'Hiking, cycling and dramatic gorges near Naivasha.',
    long: `Hell's Gate is famous for its dramatic gorges, geothermal features and active outdoor pursuits. The park is ideal for hiking, rock-climbing and cycling through spectacular scenery.\n\nCombine with nearby Lake Naivasha boat trips and local cultural visits for a full-day adventure.`,
    highlights: ['Cycling & hiking','Gorges & cliffs','Boat trips nearby']
  },
  {
    id: 'ngare-ndare',
    title: 'Ngare Ndare Forest Walk & Canopy',
    region: 'Safari & Nature',
    nights: 0,
    hero: 'https://upload.wikimedia.org/wikipedia/commons/f/ff/Ngare_Ndare_Natural_Waters.jpg',
    gallery: [
      'images/placeholder.svg',
      'images/placeholder.svg',
      'images/placeholder.svg',
      'images/placeholder.svg'
    ],
    short: 'Enchanted forest pools, waterfalls and a canopy walk.',
    long: `Ngare Ndare Forest is an intimate conservation area with flowing streams, natural pools and a canopy walkway. Perfect for day trips from the central highlands, the forest offers swimming pools, birdwatching and short guided hikes.\n\nLocal community projects support sustainable tourism and ensure the area remains a peaceful retreat for nature lovers.`,
    highlights: ['Canopy walk','Natural pools','Community conservation']
  },
  {
    id: 'mount-longonot',
    title: 'Mount Longonot Crater Hike',
    region: 'Safari & Nature',
    nights: 0,
    hero: 'https://upload.wikimedia.org/wikipedia/commons/9/95/Mount_Longonot_Kenya_2.jpg',
    gallery: [
      'https://upload.wikimedia.org/wikipedia/commons/d/d2/Onychognathus_morio%2C_Mount_Longonot%2C_Kenya_1.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/d/d2/Onychognathus_morio%2C_Mount_Longonot%2C_Kenya_1.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/d/d2/Onychognathus_morio%2C_Mount_Longonot%2C_Kenya_1.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/d/d2/Onychognathus_morio%2C_Mount_Longonot%2C_Kenya_1.jpg'
    ],
    short: 'Steep crater rim hike with outstanding Rift Valley views.',
    long: `Mount Longonot is a popular volcanic hike offering panoramic views of the Great Rift Valley. The crater rim trail is steep but rewarding, providing excellent opportunities for photography and wildlife spotting in the surrounding grasslands.`,
    highlights: ['Crater rim hike','Rift Valley views','Day-hike friendly']
  },
  {
    id: 'menengai',
    title: 'Menengai Crater Visit',
    region: 'Safari & Nature',
    nights: 0,
    hero: 'https://upload.wikimedia.org/wikipedia/commons/4/4d/Menengai_crater%2CNakuru_kenya.jpg',
    gallery: [
      'https://upload.wikimedia.org/wikipedia/commons/3/37/Dumpsite%2C_compost_site_and_drying_shed_of_MEWAREMA_%285792530963%29.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/3/37/Dumpsite%2C_compost_site_and_drying_shed_of_MEWAREMA_%285792530963%29.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/3/37/Dumpsite%2C_compost_site_and_drying_shed_of_MEWAREMA_%285792530963%29.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/3/37/Dumpsite%2C_compost_site_and_drying_shed_of_MEWAREMA_%285792530963%29.jpg'
    ],
    long: `Menengai Crater is a broad shield-volcano caldera offering dramatic rim walks and geological interest. A short, invigorating visit rewards with wide vistas and unique volcanic landforms.\n\nLocal guides provide context on volcanic formation and offer safe routes for rim exploration; this visit is a great addition to itineraries centred in the Rift Valley.`,
    short: 'Exploration of a dramatic volcanic caldera.',
    long: `Menengai Crater is a broad shield-volcano caldera offering dramatic rim walks and geological interest. A short, invigorating visit rewards with wide vistas and unique volcanic landforms.`,
    highlights: ['Volcanic landscapes','Short rim walks','Geological interest']
  },
  {
    id: 'chyulu-hills',
    title: 'Chyulu Hills Eco-Visit',
    region: 'Safari & Nature',
    nights: 1,
    hero: 'https://upload.wikimedia.org/wikipedia/commons/0/09/Tsavo_West_National_Park%2C_Kenya_%2853493414096%29.jpg',
    gallery: [
      'https://upload.wikimedia.org/wikipedia/commons/2/27/Chyulu_Hills_and_Shetani_Lava_Flow_in_Kenya_01.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/2/27/Chyulu_Hills_and_Shetani_Lava_Flow_in_Kenya_01.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/2/27/Chyulu_Hills_and_Shetani_Lava_Flow_in_Kenya_01.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/2/27/Chyulu_Hills_and_Shetani_Lava_Flow_in_Kenya_01.jpg'
    ],
    short: 'Lava flows, caves and scenic walking trails.',
    long: `The Chyulu Hills offer rolling volcanic landscapes, lava tubes and a quieter wilderness experience. Guided walks and community visits introduce guests to the region's geology and unique ecology.\n\nThis area is ideal for travellers seeking low-impact adventure: walking, picnicking and visiting community-run projects that support conservation and local livelihoods.`,
    highlights: ['Lava tubes','Walking trails','Off-the-beaten-path']
  },
  {
    id: 'diani-beach',
    title: 'Diani Beach Relaxation',
    region: 'Coastal & Beach',
    nights: 4,
    hero: 'https://upload.wikimedia.org/wikipedia/commons/8/83/Diani_Beach_-_December_2023.jpg',
    gallery: [
      'https://upload.wikimedia.org/wikipedia/commons/0/06/Diani_Beach%2C_Kenya.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/0/06/Diani_Beach%2C_Kenya.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/0/06/Diani_Beach%2C_Kenya.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/0/06/Diani_Beach%2C_Kenya.jpg'
    ],
    short: 'White-sand beaches, turquoise waters and world-class snorkeling.',
    long: `Diani Beach offers palm-lined white sand beaches and a relaxed coastal pace. The package includes beachfront accommodation and snorkelling trips to nearby reefs.\n\nPerfect for travellers looking to unwind after a safari, Diani mixes laid-back luxury with warm hospitality and superb watersports.`,
    highlights: ['Beachfront hotels','Snorkelling & diving','Relaxed seaside atmosphere']
  },
  {
    id: 'lamu',
    title: 'Lamu Island Cultural Escape',
    region: 'Coastal & Beach',
    nights: 3,
    hero: 'https://upload.wikimedia.org/wikipedia/commons/4/49/Lamu%2C_Lamu_Island%2C_Kenya.jpg',
    gallery: [
      'https://upload.wikimedia.org/wikipedia/commons/f/f9/A_photo_of_Lamu_Field.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/f/f9/A_photo_of_Lamu_Field.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/f/f9/A_photo_of_Lamu_Field.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/f/f9/A_photo_of_Lamu_Field.jpg'
    ],
    short: 'UNESCO Old Town, Swahili culture and relaxed island life.',
    long: `Lamu Island is a car-free haven with rich Swahili architecture and a relaxed pace. Guests explore narrow lanes, historic houses and pristine nearby beaches.\n\nCultural walking tours and dhow trips make this an immersive coastal cultural experience.`,
    highlights: ['UNESCO heritage','Dhow trips','Car-free streets']
  },
  {
    id: 'watamu',
    title: 'Watamu Marine Snorkel & Beach',
    region: 'Coastal & Beach',
    nights: 3,
    hero: 'https://upload.wikimedia.org/wikipedia/commons/4/44/Watamu_Marine_Park_%26_Mida_Creek.jpg',
    gallery: [
      'https://upload.wikimedia.org/wikipedia/commons/8/8c/Watamu_beach_Kenya_Sunset.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/8/8c/Watamu_beach_Kenya_Sunset.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/8/8c/Watamu_beach_Kenya_Sunset.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/8/8c/Watamu_beach_Kenya_Sunset.jpg'
    ],
    short: 'Marine reserve with coral reefs, snorkeling and marine conservation.',
    long: `Watamu Marine National Park protects spectacular coral reefs and offers excellent snorkelling and diving. This package focuses on marine activities, conservation visits and relaxation on sheltered beaches.`,
    highlights: ['Coral reefs','Snorkelling','Marine conservation']
  },
  {
    id: 'malindi',
    title: 'Malindi & Coastal Heritage',
    region: 'Coastal & Beach',
    nights: 2,
    hero: 'https://upload.wikimedia.org/wikipedia/commons/2/2d/Malindi_beach_Kenya.jpg',
    gallery: [
      'https://upload.wikimedia.org/wikipedia/commons/e/e6/Piazza_dell%27elefante_a_Malindi_-_panoramio.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/e/e6/Piazza_dell%27elefante_a_Malindi_-_panoramio.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/e/e6/Piazza_dell%27elefante_a_Malindi_-_panoramio.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/e/e6/Piazza_dell%27elefante_a_Malindi_-_panoramio.jpg'
    ],
    short: 'Historic coastal town with beaches and monuments.',
    long: `Malindi mixes cultural heritage with seaside relaxation. Visit historic sites such as the Vasco da Gama Pillar and enjoy nearby marine parks for snorkelling and fishing excursions.`,
    highlights: ['Historic sites','Beaches','Marine activities']
  },
  {
    id: 'mombasa-marine',
    title: 'Mombasa Marine Park Snorkel',
    region: 'Coastal & Beach',
    nights: 1,
    hero: 'https://upload.wikimedia.org/wikipedia/commons/c/c5/Wooden_boat_off-shore_in_Mombasa%27s_Marine_Park.jpg',
    gallery: [
      'https://upload.wikimedia.org/wikipedia/commons/c/c5/Wooden_boat_off-shore_in_Mombasa%27s_Marine_Park.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/c/c5/Wooden_boat_off-shore_in_Mombasa%27s_Marine_Park.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/c/c5/Wooden_boat_off-shore_in_Mombasa%27s_Marine_Park.jpg',
      'https://upload.wikimedia.org/wikipedia/commons/c/c5/Wooden_boat_off-shore_in_Mombasa%27s_Marine_Park.jpg'
    ],
    short: 'Coral reefs and historic Mombasa coastline.',
    long: `Mombasa Marine Park protects nearshore reefs ideal for snorkelling and day-trip excursions. Combine with visits to Fort Jesus and Mombasa Old Town for a balanced cultural and marine experience.`,
    highlights: ['Coral reefs','Fort Jesus & Old Town','Day trips']
  }
];

document.addEventListener('DOMContentLoaded',()=>{
  populateFeatured();
  populateToursGrid();
  populateTourSelect();
  handleInquiryForm();
  initGalleryLightbox();
  handleTourDetailsPage();
});

function populateFeatured(){
  const el = document.getElementById('featured-grid');
  if(!el) return;
  TOURS.slice(0,4).forEach(t=>{
    const card = document.createElement('div');card.className='card';
    card.innerHTML = `<img src="${t.hero}" alt="${t.title}"><h3 class="tour-title">${t.title}</h3><p class="tour-meta">${t.short}</p><a class="btn" href="tour-details.html?tour=${t.id}">View</a>`;
    el.appendChild(card);
  });
}

function populateToursGrid(){
  const el = document.getElementById('tours-grid');
  if(!el) return;
  TOURS.forEach(t=>{
    const card = document.createElement('div');card.className='card';
    card.innerHTML = `<img src="${t.hero}" alt="${t.title}"><h3 class="tour-title">${t.title}</h3><p class="tour-meta">${t.nights} nights</p><p>${t.short}</p><div style="margin-top:.6rem"><a class="btn" href="tour-details.html?tour=${t.id}">Details</a></div>`;
    el.appendChild(card);
  });
}

function populateTourSelect(){
  const sel = document.getElementById('tour-select');
  if(!sel) return;
  TOURS.forEach(t=>{
    const o = document.createElement('option');o.value=t.title;o.textContent=t.title;sel.appendChild(o);
  });
}

function handleInquiryForm(){
  const form = document.getElementById('inquiry-form');
  if(!form) return;
  form.addEventListener('submit',(e)=>{
    e.preventDefault();
    const tour = document.getElementById('tour-select').value;
    const name = document.getElementById('cust-name').value;
    const phone = document.getElementById('cust-phone').value;
    const email = document.getElementById('cust-email').value;
    const date = document.getElementById('travel-date').value;
    const pax = document.getElementById('pax').value;
    const msg = document.getElementById('cust-message').value;
    const whatsappNumber = '254700562686';
    const lines = [];
    if (tour && tour.toString().trim()) lines.push(`Tour: ${tour}`);
    if (name && name.toString().trim()) lines.push(`Name: ${name}`);
    if (phone && phone.toString().trim()) lines.push(`Phone: ${phone}`);
    if (email && email.toString().trim()) lines.push(`Email: ${email}`);
    if (date && date.toString().trim()) lines.push(`Date: ${date}`);
    if (pax && pax.toString().trim()) lines.push(`Pax: ${pax}`);
    if (msg && msg.toString().trim()) lines.push(`Message: ${msg}`);
    // encode full message (preserves new lines)
    const text = encodeURIComponent(lines.join('\n'));
    const url = `https://wa.me/${whatsappNumber}?text=${text}`;
    window.open(url,'_blank');
  });
}

function initGalleryLightbox(){
  const grid = document.getElementById('gallery-grid');
  if(!grid) return;
  // Build a simple gallery from all tour gallery images
  TOURS.forEach(t=>{
    // render only unique gallery images to avoid duplicates
    Array.from(new Set(t.gallery)).forEach(src=>{
      const card=document.createElement('div');card.className='card';
      card.innerHTML=`<img src="${src}" alt="${t.title}"><p class="tour-title">${t.title}</p>`;
      const imgEl = card.querySelector('img');
      imgEl.tabIndex = 0;
      imgEl.style.cursor = 'zoom-in';
      imgEl.addEventListener('click',()=>openLightbox(src));
      imgEl.addEventListener('keydown',(ev)=>{ if(ev.key==='Enter' || ev.key===' ') { ev.preventDefault(); openLightbox(src); } });
      grid.appendChild(card);
    })
  });
  const lightbox = document.getElementById('lightbox');
  if(!lightbox) return;
  const closeBtn = lightbox.querySelector('.lightbox-close');
  closeBtn.addEventListener('click',closeLightbox);
  // Close when clicking backdrop (outside image)
  lightbox.addEventListener('click',(e)=>{
    if(e.target === lightbox) closeLightbox();
  });
}

let _lastFocusedEl = null;
function openLightbox(src){
  const lb = document.getElementById('lightbox');
  const img = lb.querySelector('.lightbox-img');
  img.src = src;
  lb.setAttribute('aria-hidden','false');
  lb.setAttribute('role','dialog');
  lb.setAttribute('aria-modal','true');
  lb.style.display='flex';
  _lastFocusedEl = document.activeElement;
  const closeBtn = lb.querySelector('.lightbox-close');
  closeBtn.focus();
  document.body.style.overflow = 'hidden';
  document.addEventListener('keydown', _lightboxKeyHandler);
}

function closeLightbox(){
  const lb = document.getElementById('lightbox');
  lb.setAttribute('aria-hidden','true');
  lb.style.display='none';
  document.body.style.overflow = '';
  const img = lb.querySelector('.lightbox-img');
  img.src = '';
  document.removeEventListener('keydown', _lightboxKeyHandler);
  if(_lastFocusedEl && _lastFocusedEl.focus) _lastFocusedEl.focus();
}

function _lightboxKeyHandler(e){
  if(e.key === 'Escape') closeLightbox();
  // trap tab inside lightbox
  if(e.key === 'Tab'){
    const lb = document.getElementById('lightbox');
    const focusable = lb.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
    if(focusable.length===0) return;
    const first = focusable[0];
    const last = focusable[focusable.length-1];
    if(e.shiftKey && document.activeElement === first){ e.preventDefault(); last.focus(); }
    else if(!e.shiftKey && document.activeElement === last){ e.preventDefault(); first.focus(); }
  }
}

function handleTourDetailsPage(){
  const root = document.getElementById('tour-detail-root');
  if(!root) return;
  const params = new URLSearchParams(window.location.search);
  const id = params.get('tour');
  const t = TOURS.find(x=>x.id===id);
  if(!t){root.innerHTML='<p>Tour not found.</p>';return}
  const uniqueGallery = Array.from(new Set(t.gallery));
  const galleryHtml = uniqueGallery.map(s=>`<img src="${s}" alt="${t.title}" style="width:100%;height:120px;object-fit:cover;margin-bottom:.5rem;border-radius:6px">`).join('');
  root.innerHTML = `
    <div class="tour-layout">
      <div>
        <article>
          <h1>${t.title}</h1>
          <p class="tour-meta">${t.nights} nights • ${t.priceGuide || ''}</p>
          <img src="${t.hero}" alt="${t.title}" style="width:100%;max-height:420px;object-fit:cover;border-radius:8px;margin:1rem 0">
          <p>${t.long}</p>
          <h3>Highlights</h3>
          <ul>${t.highlights.map(h=>`<li>${h}</li>`).join('')}</ul>
          <h3>Gallery</h3>
          <div class="gallery-grid">${galleryHtml}</div>
        </article>
      </div>
      <aside class="booking-card">
        <h4>Book this tour</h4>
        <p class="muted">Quick inquiry by WhatsApp</p>
        <div class="form-row"><label>Name</label><input id="bk-name" placeholder="Your name"></div>
        <div class="form-row"><label>Phone</label><input id="bk-phone" placeholder="Phone number"></div>
        <div class="form-row"><label>Date</label><input id="bk-date" type="date"></div>
        <div class="form-row"><label>Pax</label><select id="bk-pax"><option>1</option><option>2</option><option>3</option><option>4+</option></select></div>
        <div class="form-row"><label>Message</label><textarea id="bk-msg" rows="3" placeholder="Any preferences or questions"></textarea></div>
        <div style="margin-top:.6rem"><a id="bk-wa" class="btn-whatsapp" href="#">Contact on WhatsApp</a></div>
      </aside>
    </div>
  `;

  // booking card behaviour
  const bkBtn = document.getElementById('bk-wa');
  if(bkBtn){
    bkBtn.addEventListener('click',(e)=>{
      e.preventDefault();
      const name = document.getElementById('bk-name').value||'';
      const phone = document.getElementById('bk-phone').value||'';
      const date = document.getElementById('bk-date').value||'';
      const pax = document.getElementById('bk-pax').value||'';
      const msg = document.getElementById('bk-msg').value||'';
      const lines = [];
      lines.push(`Tour: ${t.title}`);
      if(name.trim()) lines.push(`Name: ${name}`);
      if(phone.trim()) lines.push(`Phone: ${phone}`);
      if(date.trim()) lines.push(`Date: ${date}`);
      if(pax.trim()) lines.push(`Pax: ${pax}`);
      if(msg.trim()) lines.push(`Message: ${msg}`);
      const whatsappNumber = '254700562686';
      const text = encodeURIComponent(lines.join('\n'));
      const url = `https://wa.me/${whatsappNumber}?text=${text}`;
      window.open(url,'_blank');
    });
  }
}

