<?php
// /htdocs/pages/home.php — REVENDA HOME v13.1.0
// The definitive OTA/PMS homepage — experience-led, AI-first, crypto-native, smart-enabled.
//
// Preserves all original contracts: searchAvailableProperties(), getFeaturedProperties(),
// getCategories(), getCountries(), getPropertyImageUrl(), getAmenityIconSafe(),
// safeStarRating(), formatCurrency(), toggleWishlist() API, AI recommendation flow,
// flatpickr date pickers.
//
// v13.1.0 additions:
//   • Full "Browse by stay type" grid — every category from getCategories()
//   • Curated landmark images per city (Sacré-Cœur, Skytree, Marina Bay Sands, etc.)
//     — no more duplicate Eiffel Tower for every destination
//   • "Smart properties" showcase — smart-room, voice concierge, robot delivery,
//     digital key, IoT, AI planner, NFT rewards

if (!defined('APP_START')) {
    http_response_code(403);
    exit('Direct access not allowed');
}

// ============================================
// AI ENGINE FAILSAFES
// ============================================
if (!function_exists('ai') && file_exists(__DIR__ . '/../includes/ai.php')) {
    require_once __DIR__ . '/../includes/ai.php';
}
if (!function_exists('ai_recommender') && file_exists(__DIR__ . '/../includes/AIRecommender.php')) {
    require_once __DIR__ . '/../includes/AIRecommender.php';
}

// ============================================
// HELPERS — preserved contract
// ============================================
if (!function_exists('getPropertyImageUrl')) {
    function getPropertyImageUrl($property) {
        if (!empty($property['image'])) {
            if (strpos($property['image'], 'http') === 0) return $property['image'];
            $path = __DIR__ . '/../../uploads/' . ltrim($property['image'], '/');
            if (file_exists($path)) return '/uploads/' . ltrim($property['image'], '/');
        }
        if (!empty($property['id']) && function_exists('getPropertyImages')) {
            $images = getPropertyImages($property['id']);
            if (!empty($images) && !empty($images[0]['file_path'])) {
                $path = __DIR__ . '/../../uploads/' . ltrim($images[0]['file_path'], '/');
                if (file_exists($path)) return '/uploads/' . ltrim($images[0]['file_path'], '/');
            }
        }
        $fallbacks = [
            'hotel'     => 'https://images.unsplash.com/photo-1566073771259-6a8506099945?w=800&h=600&fit=crop',
            'resort'    => 'https://images.unsplash.com/photo-1571003123894-1f0594d2b5d9?w=800&h=600&fit=crop',
            'villa'     => 'https://images.unsplash.com/photo-1613490493576-7fde63acd811?w=800&h=600&fit=crop',
            'apartment' => 'https://images.unsplash.com/photo-1522708323590-d24dbb6b0267?w=800&h=600&fit=crop',
            'lodge'     => 'https://images.unsplash.com/photo-1571896349842-33c89424de2d?w=800&h=600&fit=crop',
            'hostel'    => 'https://images.unsplash.com/photo-1555854877-bab0e564b8d5?w=800&h=600&fit=crop',
            'default'   => 'https://images.unsplash.com/photo-1566073771259-6a8506099945?w=800&h=600&fit=crop'
        ];
        $cat = strtolower($property['category_name'] ?? 'default');
        foreach ($fallbacks as $key => $url) {
            if (strpos($cat, $key) !== false) return $url;
        }
        return $fallbacks['default'];
    }
}

if (!function_exists('getAmenityIconSafe')) {
    function getAmenityIconSafe($amenity) {
        $icons = [
            'wifi' => 'fa-wifi', 'pool' => 'fa-swimming-pool', 'parking' => 'fa-parking',
            'air_conditioning' => 'fa-snowflake', 'breakfast' => 'fa-utensils',
            'gym' => 'fa-dumbbell', 'spa' => 'fa-spa', 'restaurant' => 'fa-utensils',
            'bar' => 'fa-glass-martini-alt', 'room_service' => 'fa-concierge-bell',
            'laundry' => 'fa-tshirt', 'pet_friendly' => 'fa-dog', 'family_rooms' => 'fa-users',
            'non_smoking' => 'fa-smoking-ban', '24h_front_desk' => 'fa-clock',
            'luggage_storage' => 'fa-suitcase', 'concierge' => 'fa-handshake',
            'free_shuttle' => 'fa-shuttle-van', 'airport_transfer' => 'fa-plane',
            'tour_desk' => 'fa-map', 'business_center' => 'fa-briefcase',
            'meeting_rooms' => 'fa-users-cog', 'wheelchair_accessible' => 'fa-wheelchair',
            'beach_access' => 'fa-umbrella-beach', 'water_sports' => 'fa-water',
        ];
        return $icons[$amenity] ?? 'fa-check-circle';
    }
}

if (!function_exists('safeStarRating')) {
    function safeStarRating($rating) {
        $rating = floatval($rating);
        $html = '';
        for ($i = 1; $i <= 5; $i++) {
            if ($i <= $rating) $html .= '<i class="fas fa-star"></i>';
            elseif ($i - 0.5 <= $rating) $html .= '<i class="fas fa-star-half-alt"></i>';
            else $html .= '<i class="far fa-star"></i>';
        }
        return $html;
    }
}

if (!function_exists('humanizeCount')) {
    function humanizeCount($n) {
        $n = (int)$n;
        if ($n >= 1000000) return number_format($n / 1000000, 1) . 'M+';
        if ($n >= 1000) return number_format($n) . 'K+';
        if ($n > 0) return (string)$n;
        return '0';
    }
}

if (!function_exists('homeActivityIcon')) {
    function homeActivityIcon($type, $category = '') {
        $t = strtolower($type ?: 'attraction');
        $c = strtolower($category ?: '');
        $map = [
            'attraction' => 'fa-landmark', 'restaurant' => 'fa-utensils', 'cafe' => 'fa-mug-hot',
            'bar' => 'fa-glass-martini-alt', 'nightlife' => 'fa-music', 'museum' => 'fa-landmark-dome',
            'gallery' => 'fa-palette', 'park' => 'fa-tree', 'beach' => 'fa-umbrella-beach',
            'nature' => 'fa-leaf', 'hiking' => 'fa-mountain', 'adventure' => 'fa-hiking',
            'experience' => 'fa-star', 'tour' => 'fa-route', 'shopping' => 'fa-shopping-bag',
            'market' => 'fa-store', 'spa' => 'fa-spa', 'entertainment' => 'fa-ticket',
            'landmark' => 'fa-monument', 'viewpoint' => 'fa-binoculars',
        ];
        return $map[$t] ?? $map[$c] ?? 'fa-map-pin';
    }
}

// ============================================
// NEW: PROPERTY TYPE / CATEGORY METADATA
// ============================================
if (!function_exists('homeCategoryMeta')) {
    /**
     * Given a category row (or name), return icon + gradient + tagline.
     * Falls back gracefully for unknown categories.
     */
    function homeCategoryMeta($category) {
        $name = strtolower(trim((string)(
            is_array($category) ? ($category['name'] ?? '') : $category
        )));

        $map = [
            'hotel'        => ['icon' => 'fa-hotel',           'color' => '#667eea', 'tag' => 'Full-service comfort'],
            'resort'       => ['icon' => 'fa-umbrella-beach',  'color' => '#00d4ff', 'tag' => 'Pools, beaches, all-inclusive'],
            'villa'        => ['icon' => 'fa-house-chimney',   'color' => '#f093fb', 'tag' => 'Private & spacious'],
            'apartment'    => ['icon' => 'fa-building',        'color' => '#00b894', 'tag' => 'Live like a local'],
            'lodge'        => ['icon' => 'fa-tree',            'color' => '#f6ad55', 'tag' => 'Rustic getaways'],
            'hostel'       => ['icon' => 'fa-bed',             'color' => '#b794f4', 'tag' => 'Budget-friendly'],
            'guesthouse'   => ['icon' => 'fa-house',           'color' => '#f5576c', 'tag' => 'Homely B&Bs'],
            'bed and breakfast' => ['icon' => 'fa-mug-hot',    'color' => '#ffd700', 'tag' => 'Breakfast included'],
            'b&b'          => ['icon' => 'fa-mug-hot',         'color' => '#ffd700', 'tag' => 'Breakfast included'],
            'cabin'        => ['icon' => 'fa-house-chimney-window','color' => '#00d4ff','tag' => 'Forest hideaways'],
            'cottage'      => ['icon' => 'fa-house-chimney',   'color' => '#f6ad55', 'tag' => 'Countryside charm'],
            'chalet'       => ['icon' => 'fa-mountain-sun',    'color' => '#00b894', 'tag' => 'Alpine retreats'],
            'motel'        => ['icon' => 'fa-car',             'color' => '#a3bffa', 'tag' => 'Road-trip friendly'],
            'inn'          => ['icon' => 'fa-wine-glass',      'color' => '#f093fb', 'tag' => 'Cozy heritage stays'],
            'boutique'     => ['icon' => 'fa-gem',             'color' => '#b794f4', 'tag' => 'Curated & stylish'],
            'penthouse'    => ['icon' => 'fa-building-user',   'color' => '#ffd700', 'tag' => 'Top-floor luxury'],
            'studio'       => ['icon' => 'fa-cube',            'color' => '#00d4ff', 'tag' => 'Smart small-space'],
            'loft'         => ['icon' => 'fa-warehouse',       'color' => '#f5576c', 'tag' => 'Open industrial'],
            'camping'      => ['icon' => 'fa-campground',      'color' => '#00b894', 'tag' => 'Under the stars'],
            'glamping'     => ['icon' => 'fa-tent',            'color' => '#f093fb', 'tag' => 'Luxury camping'],
            'treehouse'    => ['icon' => 'fa-tree',            'color' => '#00b894', 'tag' => 'Elevated stays'],
            'boat'         => ['icon' => 'fa-ship',            'color' => '#00d4ff', 'tag' => 'On the water'],
            'yacht'        => ['icon' => 'fa-sailboat',        'color' => '#a3bffa', 'tag' => 'Luxury at sea'],
            'houseboat'    => ['icon' => 'fa-ship',            'color' => '#00d4ff', 'tag' => 'Floating homes'],
            'farm stay'    => ['icon' => 'fa-tractor',         'color' => '#00b894', 'tag' => 'Rural escapes'],
            'country house'=> ['icon' => 'fa-house-chimney',   'color' => '#f6ad55', 'tag' => 'Wide open spaces'],
            'castle'       => ['icon' => 'fa-chess-rook',      'color' => '#b794f4', 'tag' => 'Royal treatment'],
            'palace'       => ['icon' => 'fa-crown',           'color' => '#ffd700', 'tag' => 'Historic grandeur'],
            'ryokan'       => ['icon' => 'fa-torii-gate',      'color' => '#f5576c', 'tag' => 'Japanese hospitality'],
            'riad'         => ['icon' => 'fa-mosque',          'color' => '#f6ad55', 'tag' => 'Moroccan courtyards'],
            'pension'      => ['icon' => 'fa-house',           'color' => '#a3bffa', 'tag' => 'European B&B'],
            'homestay'     => ['icon' => 'fa-people-roof',     'color' => '#f093fb', 'tag' => 'Stay with locals'],
            'condo'        => ['icon' => 'fa-building',        'color' => '#667eea', 'tag' => 'Full amenities'],
            'townhouse'    => ['icon' => 'fa-house-chimney',   'color' => '#00b894', 'tag' => 'Multi-level living'],
            'dorm'         => ['icon' => 'fa-bed',             'color' => '#a3bffa', 'tag' => 'Backpacker picks'],
            'suite'        => ['icon' => 'fa-crown',           'color' => '#ffd700', 'tag' => 'Elevated comfort'],
        ];

        foreach ($map as $key => $meta) {
            if ($name === $key || strpos($name, $key) !== false) return $meta;
        }

        // Generic fallback
        return [
            'icon' => 'fa-building',
            'color' => '#667eea',
            'tag' => 'Unique stay',
        ];
    }
}

// ============================================
// NEW: LANDMARK IMAGE MAP (per city)
// ============================================
if (!function_exists('homeDestinationImage')) {
    /**
     * Returns a landmark-flavoured image URL for a destination.
     * Order of preference:
     *   1. Curated landmark map (keyed by lowercase city name)
     *   2. $dest['hero_image'] from DB
     *   3. Unsplash featured query by city name
     */
    function homeDestinationImage($dest) {
        $city = strtolower(trim((string)($dest['name'] ?? '')));
        $country = strtolower(trim((string)($dest['country_name'] ?? '')));
        $key = $city . '|' . $country;

        // Curated landmark photos — every image is a distinctive landmark
        // for that specific city, not the same tower repeated.
        $landmarks = [
            // Europe
            'paris|france'          => 'https://images.unsplash.com/photo-1502602898657-3e91760cbb34?w=600&h=800&fit=crop', // Paris rooftops
            'london|united kingdom' => 'https://images.unsplash.com/photo-1513635269975-59663e0ac1ad?w=600&h=800&fit=crop', // Tower Bridge
            'rome|italy'            => 'https://images.unsplash.com/photo-1552832230-c0197dd311b5?w=600&h=800&fit=crop', // Colosseum
            'barcelona|spain'       => 'https://images.unsplash.com/photo-1583422409516-2895a77efded?w=600&h=800&fit=crop', // Sagrada Família
            'madrid|spain'          => 'https://images.unsplash.com/photo-1543783207-ec64e4d95325?w=600&h=800&fit=crop', // Plaza Mayor
            'amsterdam|netherlands'=> 'https://images.unsplash.com/photo-1534351590666-13e3e96b5017?w=600&h=800&fit=crop', // Canals
            'berlin|germany'        => 'https://images.unsplash.com/photo-1560969184-10fe8719e047?w=600&h=800&fit=crop', // Brandenburg Gate
            'munich|germany'        => 'https://images.unsplash.com/photo-1595867818082-083862f3d630?w=600&h=800&fit=crop', // Marienplatz
            'vienna|austria'        => 'https://images.unsplash.com/photo-1516550893923-42d28e5677af?w=600&h=800&fit=crop', // Schönbrunn
            'prague|czech republic' => 'https://images.unsplash.com/photo-1541849546-216549ae216d?w=600&h=800&fit=crop', // Charles Bridge
            'lisbon|portugal'       => 'https://images.unsplash.com/photo-1555881400-74d7acaacd8b?w=600&h=800&fit=crop', // Belém Tower
            'athens|greece'         => 'https://images.unsplash.com/photo-1555993539-1732b0258235?w=600&h=800&fit=crop', // Acropolis
            'santorini|greece'      => 'https://images.unsplash.com/photo-1570077188670-e3a8d69ac5ff?w=600&h=800&fit=crop', // Oia
            'mykonos|greece'        => 'https://images.unsplash.com/photo-1601581875309-fafbf2d3ed3a?w=600&h=800&fit=crop', // Windmills
            'venice|italy'          => 'https://images.unsplash.com/photo-1514890547357-a9ee288728e0?w=600&h=800&fit=crop', // Grand Canal
            'florence|italy'        => 'https://images.unsplash.com/photo-1543429776-2782fc8e1acd?w=600&h=800&fit=crop', // Duomo
            'milan|italy'           => 'https://images.unsplash.com/photo-1520440229-6469a149ac59?w=600&h=800&fit=crop', // Duomo di Milano
            'dublin|ireland'        => 'https://images.unsplash.com/photo-1549918864-48ac978761a4?w=600&h=800&fit=crop', // Ha'penny Bridge
            'edinburgh|united kingdom' => 'https://images.unsplash.com/photo-1506377247377-2a5b3b417ebb?w=600&h=800&fit=crop', // Edinburgh Castle
            'copenhagen|denmark'    => 'https://images.unsplash.com/photo-1513622470522-26c3c8a854bc?w=600&h=800&fit=crop', // Nyhavn
            'stockholm|sweden'      => 'https://images.unsplash.com/photo-1509356843151-3e7d96241e11?w=600&h=800&fit=crop', // Gamla Stan
            'oslo|norway'           => 'https://images.unsplash.com/photo-1520769669658-f07657f5a307?w=600&h=800&fit=crop', // Opera House
            'helsinki|finland'      => 'https://images.unsplash.com/photo-1552150890-3f7fa1e58f4f?w=600&h=800&fit=crop', // Helsinki Cathedral
            'reykjavik|iceland'     => 'https://images.unsplash.com/photo-1504829857797-ddff29c27927?w=600&h=800&fit=crop', // Hallgrímskirkja
            'zurich|switzerland'    => 'https://images.unsplash.com/photo-1515488764276-beab7607c1e6?w=600&h=800&fit=crop', // Lake Zurich
            'geneva|switzerland'    => 'https://images.unsplash.com/photo-1573108724029-4c46571d6490?w=600&h=800&fit=crop', // Jet d'Eau
            'brussels|belgium'      => 'https://images.unsplash.com/photo-1491557345352-5929e343eb89?w=600&h=800&fit=crop', // Grand Place
            'warsaw|poland'         => 'https://images.unsplash.com/photo-1607427293702-036933bbf746?w=600&h=800&fit=crop', // Old Town
            'budapest|hungary'      => 'https://images.unsplash.com/photo-1551867633-194f125bddfa?w=600&h=800&fit=crop', // Parliament
            'istanbul|turkey'       => 'https://images.unsplash.com/photo-1524231757912-21f4fe3a7200?w=600&h=800&fit=crop', // Hagia Sophia

            // Americas
            'new york|united states'    => 'https://images.unsplash.com/photo-1496442226666-8d4d0e62e6e9?w=600&h=800&fit=crop', // Manhattan skyline
            'los angeles|united states' => 'https://images.unsplash.com/photo-1515896769750-31548aa180ed?w=600&h=800&fit=crop', // Hollywood
            'san francisco|united states' => 'https://images.unsplash.com/photo-1501594907352-04cda38ebc29?w=600&h=800&fit=crop', // Golden Gate
            'chicago|united states'     => 'https://images.unsplash.com/photo-1494522855154-9297ac14b55f?w=600&h=800&fit=crop', // Bean
            'miami|united states'       => 'https://images.unsplash.com/photo-1506966953602-c20cc11f75e3?w=600&h=800&fit=crop', // South Beach
            'las vegas|united states'   => 'https://images.unsplash.com/photo-1502768040783-423da5fd5fa0?w=600&h=800&fit=crop', // Strip
            'washington|united states'  => 'https://images.unsplash.com/photo-1501466044931-62695aada8e9?w=600&h=800&fit=crop', // Capitol
            'boston|united states'      => 'https://images.unsplash.com/photo-1501979376754-2ff867a4f659?w=600&h=800&fit=crop', // Skyline
            'seattle|united states'     => 'https://images.unsplash.com/photo-1502175353174-a7a70e73b362?w=600&h=800&fit=crop', // Space Needle
            'toronto|canada'            => 'https://images.unsplash.com/photo-1517935706615-2717063c2225?w=600&h=800&fit=crop', // CN Tower
            'vancouver|canada'          => 'https://images.unsplash.com/photo-1559511260-66a654ae982a?w=600&h=800&fit=crop', // Mountains
            'montreal|canada'           => 'https://images.unsplash.com/photo-1519832979-6fa011b87667?w=600&h=800&fit=crop', // Old Port
            'mexico city|mexico'        => 'https://images.unsplash.com/photo-1518105779142-d975f22f1b0a?w=600&h=800&fit=crop', // Angel of Independence
            'cancun|mexico'             => 'https://images.unsplash.com/photo-1510097467424-192d713fd8b2?w=600&h=800&fit=crop', // Beach
            'havana|cuba'               => 'https://images.unsplash.com/photo-1500759285222-a95626b934cb?w=600&h=800&fit=crop', // Classic cars
            'rio de janeiro|brazil'     => 'https://images.unsplash.com/photo-1483729558449-99ef09a8c325?w=600&h=800&fit=crop', // Christ the Redeemer
            'sao paulo|brazil'          => 'https://images.unsplash.com/photo-1543059080-f9b1272213d5?w=600&h=800&fit=crop', // Skyline
            'buenos aires|argentina'    => 'https://images.unsplash.com/photo-1589909202802-8f4aadce1849?w=600&h=800&fit=crop', // Obelisk
            'lima|peru'                 => 'https://images.unsplash.com/photo-1531968455001-5c5272a41129?w=600&h=800&fit=crop', // Miraflores
            'santiago|chile'            => 'https://images.unsplash.com/photo-1478827387698-1527781a4887?w=600&h=800&fit=crop', // Andes backdrop

            // Asia
            'tokyo|japan'         => 'https://images.unsplash.com/photo-1540959733332-eab4deabeeaf?w=600&h=800&fit=crop', // Shibuya
            'kyoto|japan'         => 'https://images.unsplash.com/photo-1493976040374-85c8e12f0c0e?w=600&h=800&fit=crop', // Fushimi Inari
            'osaka|japan'         => 'https://images.unsplash.com/photo-1542051841857-5f90071e7989?w=600&h=800&fit=crop', // Dotonbori
            'seoul|south korea'   => 'https://images.unsplash.com/photo-1538485399081-7c8979b9c7d4?w=600&h=800&fit=crop', // Skyline
            'bangkok|thailand'    => 'https://images.unsplash.com/photo-1508009603885-50cf7c579365?w=600&h=800&fit=crop', // Grand Palace
            'chiang mai|thailand'=> 'https://images.unsplash.com/photo-1512553358915-11c0b1d1cc4b?w=600&h=800&fit=crop', // Temples
            'phuket|thailand'     => 'https://images.unsplash.com/photo-1589394815804-964ed0be2eb5?w=600&h=800&fit=crop', // Beach
            'bali|indonesia'      => 'https://images.unsplash.com/photo-1537996194471-e657df975ab4?w=600&h=800&fit=crop', // Rice terraces
            'jakarta|indonesia'   => 'https://images.unsplash.com/photo-1555899434-94d1368aa7af?w=600&h=800&fit=crop', // Skyline
            'singapore|singapore' => 'https://images.unsplash.com/photo-1525625293386-3f8f99389edd?w=600&h=800&fit=crop', // Marina Bay Sands
            'kuala lumpur|malaysia' => 'https://images.unsplash.com/photo-1596422846543-75c6fc197f07?w=600&h=800&fit=crop', // Petronas Towers
            'hong kong|china'     => 'https://images.unsplash.com/photo-1536599018102-9f803c140fc1?w=600&h=800&fit=crop', // Victoria Harbour
            'shanghai|china'      => 'https://images.unsplash.com/photo-1545893835-abaa50cbe628?w=600&h=800&fit=crop', // Bund
            'beijing|china'       => 'https://images.unsplash.com/photo-1508804185872-d7badad00f7d?w=600&h=800&fit=crop', // Great Wall
            'dubai|united arab emirates' => 'https://images.unsplash.com/photo-1512453979798-5ea266f8880c?w=600&h=800&fit=crop', // Burj Khalifa
            'abu dhabi|united arab emirates' => 'https://images.unsplash.com/photo-1512632578888-169bbbc64f33?w=600&h=800&fit=crop', // Grand Mosque
            'doha|qatar'          => 'https://images.unsplash.com/photo-1539475398918-9ac3ee88c54a?w=600&h=800&fit=crop', // Skyline
            'mumbai|india'        => 'https://images.unsplash.com/photo-1570168007204-dfb528c6958f?w=600&h=800&fit=crop', // Gateway of India
            'delhi|india'         => 'https://images.unsplash.com/photo-1587474260584-136574528ed5?w=600&h=800&fit=crop', // India Gate
            'jaipur|india'        => 'https://images.unsplash.com/photo-1599661046827-dacff0c0f09a?w=600&h=800&fit=crop', // Hawa Mahal
            'kathmandu|nepal'     => 'https://images.unsplash.com/photo-1544735716-392fe2489ffa?w=600&h=800&fit=crop', // Boudhanath
            'hanoi|vietnam'       => 'https://images.unsplash.com/photo-1509030450996-dd1a26dda07a?w=600&h=800&fit=crop', // Old Quarter
            'ho chi minh city|vietnam' => 'https://images.unsplash.com/photo-1583417319070-4a69db38a482?w=600&h=800&fit=crop', // Skyline
            'sydney|australia'    => 'https://images.unsplash.com/photo-1506973035872-a4ec16b8e8d9?w=600&h=800&fit=crop', // Opera House
            'melbourne|australia' => 'https://images.unsplash.com/photo-1514395462725-fb4566210144?w=600&h=800&fit=crop', // Skyline
            'auckland|new zealand'=> 'https://images.unsplash.com/photo-1509440159596-0249088772ff?w=600&h=800&fit=crop', // Sky Tower
            'queenstown|new zealand' => 'https://images.unsplash.com/photo-1589802829985-817e51171b92?w=600&h=800&fit=crop', // Lake Wakatipu

            // Africa & Middle East
            'cairo|egypt'         => 'https://images.unsplash.com/photo-1539650116574-75c0c6d73f6e?w=600&h=800&fit=crop', // Pyramids
            'marrakech|morocco'   => 'https://images.unsplash.com/photo-1597212618440-806262de4f6b?w=600&h=800&fit=crop', // Jemaa el-Fnaa
            'casablanca|morocco'  => 'https://images.unsplash.com/photo-1539020140153-e479b8c22e70?w=600&h=800&fit=crop', // Hassan II Mosque
            'cape town|south africa' => 'https://images.unsplash.com/photo-1580060839134-75a5edca2e99?w=600&h=800&fit=crop', // Table Mountain
            'johannesburg|south africa' => 'https://images.unsplash.com/photo-1553465528-5f8bde1a9d5e?w=600&h=800&fit=crop', // Skyline
            'nairobi|kenya'       => 'https://images.unsplash.com/photo-1611348586804-61bf6c080437?w=600&h=800&fit=crop', // Skyline
            'zanzibar|tanzania'   => 'https://images.unsplash.com/photo-1586861635167-e5223aadc9fe?w=600&h=800&fit=crop', // Stone Town
            'dar es salaam|tanzania' => 'https://images.unsplash.com/photo-1580060839134-75a5edca2e99?w=600&h=800&fit=crop', // Coast
            'serengeti|tanzania'  => 'https://images.unsplash.com/photo-1516426122078-c23e76319801?w=600&h=800&fit=crop', // Safari
            'kigali|rwanda'       => 'https://images.unsplash.com/photo-1611348586804-61bf6c080437?w=600&h=800&fit=crop', // Hills
            'addis ababa|ethiopia'=> 'https://images.unsplash.com/photo-1523805009345-7448845a9e53?w=600&h=800&fit=crop', // Skyline
            'lagos|nigeria'       => 'https://images.unsplash.com/photo-1572715402489-6b1f454d3b7f?w=600&h=800&fit=crop', // Lekki
            'accra|ghana'         => 'https://images.unsplash.com/photo-1580746738099-77fede9d3b40?w=600&h=800&fit=crop', // Independence Arch

            // Additional destinations that show up often
            'maldives|maldives'   => 'https://images.unsplash.com/photo-1514282401047-d79a71a590e8?w=600&h=800&fit=crop', // Overwater villas
            'mauritius|mauritius' => 'https://images.unsplash.com/photo-1544551763-46a013bb70d5?w=600&h=800&fit=crop', // Beach
            'seychelles|seychelles' => 'https://images.unsplash.com/photo-1589979199141-45afb8e7a8f5?w=600&h=800&fit=crop', // Granite boulders
            'moscow|russia'       => 'https://images.unsplash.com/photo-1513326738677-b964603b136d?w=600&h=800&fit=crop', // St Basil's
            'st petersburg|russia' => 'https://images.unsplash.com/photo-1556610961-2fecc5927173?w=600&h=800&fit=crop', // Hermitage
            'dubrovnik|croatia'   => 'https://images.unsplash.com/photo-1555990793-da11153b2c48?w=600&h=800&fit=crop', // Old Town walls
            'split|croatia'       => 'https://images.unsplash.com/photo-1555990793-da11153b2c48?w=600&h=800&fit=crop', // Diocletian's Palace
            'ljubljana|slovenia'  => 'https://images.unsplash.com/photo-1551868090-ebd4d0c9c0f2?w=600&h=800&fit=crop', // Triple Bridge
        ];

        if (isset($landmarks[$key])) {
            return $landmarks[$key];
        }

        // Try matching by city alone
        foreach ($landmarks as $k => $url) {
            $cityKey = explode('|', $k)[0];
            if ($cityKey === $city) return $url;
        }

        // Fall back to DB hero_image
        if (!empty($dest['hero_image'])) {
            return strpos($dest['hero_image'], 'http') === 0
                ? $dest['hero_image']
                : '/uploads/' . ltrim($dest['hero_image'], '/');
        }

        // Last resort: Unsplash search by city name
        $q = urlencode($city . ' city');
        return "https://source.unsplash.com/featured/600x800/?{$q}";
    }
}

// ============================================
// NEW: SMART FEATURES CATALOG
// ============================================
if (!function_exists('homeSmartFeatures')) {
    function homeSmartFeatures() {
        return [
            [
                'icon' => 'fa-microchip',
                'title' => 'Smart Room Controls',
                'desc' => 'Lights, thermostat, curtains, TV — controlled from your phone or voice.',
                'page' => 'smart-room',
                'color' => '#667eea',
                'tag' => 'IoT',
            ],
            [
                'icon' => 'fa-key',
                'title' => 'Digital Room Key',
                'desc' => 'Unlock your door from your phone. No plastic cards. No front desk queue.',
                'page' => 'smart-key',
                'color' => '#00d4ff',
                'tag' => 'NFC',
            ],
            [
                'icon' => 'fa-microphone-lines',
                'title' => 'Voice Concierge',
                'desc' => 'Ask for towels, book a taxi, or set a wake-up call — just speak.',
                'page' => 'voice-concierge',
                'color' => '#f093fb',
                'tag' => 'AI Voice',
            ],
            [
                'icon' => 'fa-robot',
                'title' => 'Robot Delivery',
                'desc' => 'Room service, extra amenities, even laundry — delivered by our bots.',
                'page' => 'robot-concierge',
                'color' => '#00b894',
                'tag' => 'Autonomous',
            ],
            [
                'icon' => 'fa-video',
                'title' => 'Live Video Tours',
                'desc' => 'Walk through a property in real time with the host before you book.',
                'page' => 'video-call',
                'color' => '#f6ad55',
                'tag' => 'WebRTC',
            ],
            [
                'icon' => 'fa-wand-magic-sparkles',
                'title' => 'AI Trip Planner',
                'desc' => 'An itinerary built from real activities, tuned to your travel style.',
                'page' => 'trip-planner',
                'color' => '#b794f4',
                'tag' => 'AI',
            ],
            [
                'icon' => 'fa-bitcoin-sign',
                'title' => 'Crypto & Fiat Payments',
                'desc' => 'Pay with card, bank transfer, or crypto — your money, your way.',
                'page' => 'checkout',
                'color' => '#ffd700',
                'tag' => 'Web3',
            ],
            [
                'icon' => 'fa-gift',
                'title' => 'Loyalty & Rewards',
                'desc' => 'Earn points on every stay, referral, and review. Redeem for free nights.',
                'page' => 'user-achievements',
                'color' => '#f5576c',
                'tag' => 'Rewards',
            ],
        ];
    }
}

// ============================================
// FILTER INPUTS
// ============================================
$search      = $_GET['search'] ?? '';
$categoryId  = intval($_GET['category'] ?? 0);
$countryId   = intval($_GET['country'] ?? 0);
$cityId      = intval($_GET['city'] ?? 0);
$checkIn     = $_GET['check_in'] ?? date('Y-m-d', strtotime('+1 day'));
$checkOut    = $_GET['check_out'] ?? date('Y-m-d', strtotime('+2 days'));
$guests      = intval($_GET['guests'] ?? 2);
$rooms       = intval($_GET['rooms'] ?? 1);
$minPrice    = floatval($_GET['min_price'] ?? 0);
$maxPrice    = floatval($_GET['max_price'] ?? 5000);
$starRating  = intval($_GET['star_rating'] ?? 0);
$sort        = $_GET['sort'] ?? 'relevance';
$instantBook = isset($_GET['instant_book']);
$hasActiveFilters = $search || $categoryId || $countryId || $cityId || $instantBook || $starRating || $minPrice > 0;

$filters = [
    'search'       => $search,
    'category'     => $categoryId,
    'country'      => $countryId,
    'city'         => $cityId,
    'min_price'    => $minPrice,
    'max_price'    => $maxPrice,
    'star_rating'  => $starRating,
    'instant_book' => $instantBook,
    'sort'         => $sort,
    'limit'        => 50
];

// ============================================
// DATA FETCH
// ============================================
$properties = searchAvailableProperties($filters);
$featured   = getFeaturedProperties(6);
$categories = getCategories();
$countries  = getCountries();

if (empty($featured)) {
    $featured = getProperties(['limit' => 6, 'sort' => 'newest']);
}

// ============================================
// LIVE STATS
// ============================================
$stats = ['properties' => 0, 'countries' => 0, 'cities' => 0, 'activities' => 0, 'guests' => 0, 'rating' => 0.0];

try {
    $__db = db();
    $stats['properties'] = (int)($__db->fetchOne("SELECT COUNT(*) AS c FROM properties WHERE is_active = 1")['c'] ?? 0);
    $stats['countries']  = (int)($__db->fetchOne("SELECT COUNT(*) AS c FROM destinations WHERE type = 'country' AND is_active = 1")['c'] ?? 0);
    $stats['cities']     = (int)($__db->fetchOne("SELECT COUNT(*) AS c FROM destinations WHERE type = 'city' AND is_active = 1")['c'] ?? 0);
    $stats['activities'] = (int)($__db->fetchOne("SELECT COUNT(*) AS c FROM activities WHERE is_active = 1")['c'] ?? 0);
    $stats['guests']     = (int)($__db->fetchOne("SELECT COUNT(DISTINCT user_id) AS c FROM bookings WHERE status IN ('completed','checked_out','checked_in','confirmed')")['c'] ?? 0);
    $row = $__db->fetchOne("SELECT AVG(average_rating) AS avg_rating FROM properties WHERE is_active = 1 AND average_rating > 0");
    $stats['rating'] = round((float)($row['avg_rating'] ?? 0), 1);
} catch (Throwable $e) {
    error_log('home.php stats query failed: ' . $e->getMessage());
}

// ============================================
// TOP DESTINATIONS
// ============================================
$topDestinations = [];
try {
    $topDestinations = db()->fetchAll(
        "SELECT d.id, d.name, d.country_name, d.flag_emoji, d.hero_image,
                (SELECT COUNT(*) FROM properties p WHERE p.city_id = d.id AND p.is_active = 1 LIMIT 1) AS property_count
         FROM destinations d
         WHERE d.is_active = 1 AND d.type = 'city'
         HAVING property_count > 0
         ORDER BY property_count DESC, d.popularity_score DESC
         LIMIT 10"
    );
    if (!is_array($topDestinations)) $topDestinations = [];
} catch (Throwable $e) {}

// ============================================
// EXPERIENCE CATEGORIES
// ============================================
$experienceCategories = [];
try {
    $rows = db()->fetchAll(
        "SELECT a.category, COUNT(*) AS c, a.type
         FROM activities a
         WHERE a.is_active = 1 AND a.category IS NOT NULL AND a.category != ''
         GROUP BY a.category
         ORDER BY c DESC
         LIMIT 12"
    );
    foreach ($rows as $r) {
        $cat = $r['category'] ?: 'experience';
        $experienceCategories[] = [
            'slug'  => $cat,
            'label' => ucfirst(str_replace('_', ' ', $cat)),
            'count' => (int)$r['c'],
            'icon'  => homeActivityIcon($r['type'] ?? '', $cat),
        ];
    }
} catch (Throwable $e) {}

if (empty($experienceCategories)) {
    $experienceCategories = [
        ['slug' => 'attraction', 'label' => 'Attractions', 'count' => 0, 'icon' => 'fa-landmark'],
        ['slug' => 'restaurant', 'label' => 'Dining',      'count' => 0, 'icon' => 'fa-utensils'],
        ['slug' => 'nature',     'label' => 'Nature',      'count' => 0, 'icon' => 'fa-leaf'],
        ['slug' => 'museum',     'label' => 'Museums',     'count' => 0, 'icon' => 'fa-landmark-dome'],
    ];
}

// ============================================
// FEATURED ACTIVITIES
// ============================================
$featuredActivities = [];
try {
    $featuredActivities = db()->fetchAll(
        "SELECT a.id, a.name, a.name_local, a.slug, a.type, a.category, a.subcategory,
                a.description, a.image, a.rating, a.review_count,
                a.price_from, a.price_currency, a.duration_minutes,
                a.destination_id,
                d.name AS destination_name, d.flag_emoji
         FROM activities a
         LEFT JOIN destinations d ON a.destination_id = d.id
         WHERE a.is_active = 1
         ORDER BY a.popularity_score DESC, a.rating DESC
         LIMIT 6"
    );
    if (!is_array($featuredActivities)) $featuredActivities = [];
} catch (Throwable $e) {}

// ============================================
// RECENTLY VIEWED
// ============================================
$recentlyViewed = [];
if (session_status() === PHP_SESSION_ACTIVE && !empty($_SESSION['recently_viewed'])) {
    $ids = array_slice((array)$_SESSION['recently_viewed'], 0, 4);
    $ids = array_filter(array_map('intval', $ids));
    if (!empty($ids)) {
        try {
            $place = implode(',', array_fill(0, count($ids), '?'));
            $rows = db()->fetchAll(
                "SELECT p.id, p.name, p.slug, p.min_price_per_night, p.featured_image, p.image,
                        p.average_rating, p.total_reviews, p.city_id,
                        ci.name AS city_name, co.name AS country_name, co.flag_emoji
                 FROM properties p
                 LEFT JOIN destinations ci ON p.city_id = ci.id
                 LEFT JOIN destinations co ON p.country_id = co.id
                 WHERE p.id IN ($place) AND p.is_active = 1
                 LIMIT 4",
                $ids
            );
            if (is_array($rows)) $recentlyViewed = $rows;
        } catch (Throwable $e) {}
    }
}

// Smart features
$smartFeatures = homeSmartFeatures();

// ============================================
// HEADER
// ============================================
require_once __DIR__ . '/../includes/header.php';
?>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>

<style>
:root {
    --grad: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --grad-cyan: linear-gradient(135deg, #00d4ff 0%, #00b894 100%);
    --grad-pink: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --grad-gold: linear-gradient(135deg, #ffd700 0%, #f6ad55 100%);
    --glass: rgba(255,255,255,0.04);
    --border: rgba(255,255,255,0.08);
    --text-dim: #a0aec0;
    --text-hi: #a3bffa;
    --green: #00b894;
    --red: #f5576c;
    --orange: #f6ad55;
    --blue: #00d4ff;
    --purple: #b794f4;
    --pink: #f093fb;
    --gold: #ffd700;
    --bg: #0f0c29;
}

.home-page {
    background: var(--bg);
    color: white;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    -webkit-font-smoothing: antialiased;
    line-height: 1.55;
    overflow-x: hidden;
}
.home-page .hp-container { max-width: 1280px; margin: 0 auto; padding: 0 20px; }

/* ============================================
   HERO
   ============================================ */
.hp-hero {
    min-height: 90vh;
    padding: 120px 0 60px;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    background: linear-gradient(155deg, #0f0c29 0%, #1a1a2e 40%, #24243e 100%);
}
.hp-hero-bg { position: absolute; inset: 0; pointer-events: none; z-index: 0; }
.hp-hero-bg::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(102,126,234,0.06) 1px, transparent 1px),
        linear-gradient(90deg, rgba(102,126,234,0.06) 1px, transparent 1px);
    background-size: 40px 40px;
    mask-image: radial-gradient(circle at 50% 40%, black 20%, transparent 75%);
    -webkit-mask-image: radial-gradient(circle at 50% 40%, black 20%, transparent 75%);
}
.hp-orb {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    animation: hpFloat 20s infinite ease-in-out;
}
.hp-orb-1 { top: -220px; right: -180px; width: 620px; height: 620px;
    background: radial-gradient(circle, rgba(102,126,234,0.35), transparent 70%); }
.hp-orb-2 { bottom: -180px; left: -160px; width: 480px; height: 480px;
    background: radial-gradient(circle, rgba(240,147,251,0.22), transparent 70%);
    animation-direction: reverse; animation-duration: 26s; }
.hp-orb-3 { top: 40%; left: 50%; transform: translate(-50%, -50%);
    width: 380px; height: 380px;
    background: radial-gradient(circle, rgba(0,212,255,0.15), transparent 70%);
    animation-duration: 32s; }
@keyframes hpFloat {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(40px, -40px) scale(1.08); }
    50% { transform: translate(-25px, 25px) scale(0.94); }
    75% { transform: translate(25px, -25px) scale(1.04); }
}

.hp-hero-content {
    position: relative; z-index: 1;
    max-width: 1180px; margin: 0 auto; padding: 0 20px; width: 100%;
    text-align: center;
}

.hp-badge {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 8px 18px; border-radius: 50px;
    background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.12);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    font-size: 12px; font-weight: 800;
    text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--text-hi); margin-bottom: 22px; position: relative;
}
.hp-badge .dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--green); animation: hpPulse 2s infinite;
}
@keyframes hpPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(1.4); }
}

.hp-title {
    font-size: clamp(38px, 6vw, 76px);
    font-weight: 900; line-height: 1.02;
    letter-spacing: -0.035em;
    margin: 0 0 20px;
    background: linear-gradient(135deg, #fff 0%, #a3bffa 45%, #f093fb 100%);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}
.hp-title em {
    font-style: normal;
    background: var(--grad-pink);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hp-live-line {
    display: inline-flex; align-items: center; gap: 10px;
    padding: 8px 18px; border-radius: 50px;
    background: rgba(0,184,148,0.1); border: 1px solid rgba(0,184,148,0.3);
    color: #81e6d9; font-size: 12.5px; font-weight: 700;
    margin-bottom: 16px;
    font-family: 'SF Mono', Monaco, monospace;
}
.hp-live-line .live-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--green); animation: hpPulse 1.6s infinite;
}

.hp-subtitle {
    font-size: 17px; color: #cbd5e0;
    max-width: 640px; margin: 0 auto 34px; line-height: 1.65;
}
.hp-subtitle strong { color: white; font-weight: 800; }

.hp-trust {
    display: flex; justify-content: center;
    gap: 8px; flex-wrap: wrap; margin-bottom: 34px;
}
.hp-trust-item {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 14px; border-radius: 50px;
    background: rgba(255,255,255,0.04); border: 1px solid var(--border);
    color: #cbd5e0; font-size: 11.5px; font-weight: 700;
}
.hp-trust-item i { color: var(--blue); font-size: 11px; }

.hp-search {
    background: rgba(255,255,255,0.05);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 22px; padding: 14px;
    max-width: 1140px; margin: 0 auto 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.hp-search-grid {
    display: grid;
    grid-template-columns: 2.2fr 1fr 1fr 0.9fr 0.9fr auto;
    gap: 8px; align-items: end;
}
.hp-search-field { position: relative; }
.hp-search-field label {
    display: flex; align-items: center; gap: 5px;
    font-size: 10px; font-weight: 800;
    text-transform: uppercase; letter-spacing: 0.06em;
    color: var(--text-hi); margin-bottom: 6px; padding-left: 4px;
}
.hp-search-field label i { font-size: 10px; }
.hp-search-field input,
.hp-search-field select {
    width: 100%; padding: 14px 16px;
    background: rgba(0,0,0,0.25);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px; color: white;
    font-size: 14px; font-family: inherit; outline: none;
    height: 52px; transition: all 0.2s;
    -webkit-appearance: none; box-sizing: border-box;
}
.hp-search-field input::placeholder { color: rgba(160,174,192,0.55); }
.hp-search-field input:focus,
.hp-search-field select:focus {
    border-color: #667eea; background: rgba(0,0,0,0.4);
    box-shadow: 0 0 0 3px rgba(102,126,234,0.2);
}
.hp-search-field select option { background: #1a1a2e; color: white; }

.hp-search-submit {
    padding: 0 26px; height: 52px;
    background: var(--grad-pink); color: white;
    border: none; border-radius: 12px;
    font-weight: 800; font-size: 14px; cursor: pointer; font-family: inherit;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    transition: all 0.2s;
    box-shadow: 0 8px 24px rgba(240,147,251,0.35);
    text-transform: uppercase; letter-spacing: 0.04em;
    white-space: nowrap; min-width: 140px;
}
.hp-search-submit:hover { transform: translateY(-2px); box-shadow: 0 12px 32px rgba(240,147,251,0.5); }

.hp-quick-filters {
    display: flex; flex-wrap: wrap; gap: 8px;
    justify-content: center; max-width: 1140px; margin: 0 auto;
}
.hp-chip {
    padding: 8px 16px; border-radius: 50px;
    background: rgba(255,255,255,0.05); border: 1px solid var(--border);
    color: #cbd5e0; font-size: 12px; font-weight: 700;
    text-decoration: none;
    display: inline-flex; align-items: center; gap: 6px;
    transition: all 0.2s;
}
.hp-chip:hover {
    background: rgba(255,255,255,0.1); color: white;
    transform: translateY(-2px); border-color: rgba(102,126,234,0.4);
}
.hp-chip.active {
    background: var(--grad); border-color: transparent;
    color: white; box-shadow: 0 6px 18px rgba(102,126,234,0.35);
}

.hp-ai-prompt {
    display: inline-flex; align-items: center; gap: 10px;
    padding: 10px 18px; border-radius: 50px;
    background: linear-gradient(135deg, rgba(240,147,251,0.1), rgba(102,126,234,0.08));
    border: 1px solid rgba(240,147,251,0.3);
    color: #e9d8fd; font-size: 12.5px; font-weight: 700;
    margin-top: 24px; text-decoration: none; transition: all 0.2s;
}
.hp-ai-prompt:hover {
    background: linear-gradient(135deg, rgba(240,147,251,0.18), rgba(102,126,234,0.14));
    color: white; transform: translateY(-2px);
}
.hp-ai-prompt i { color: var(--pink); font-size: 13px; }

/* ============================================
   SECTIONS
   ============================================ */
.hp-section { padding: 70px 0; position: relative; }
.hp-section-alt {
    background: rgba(255,255,255,0.015);
    border-top: 1px solid rgba(255,255,255,0.04);
    border-bottom: 1px solid rgba(255,255,255,0.04);
}
.hp-section-head { text-align: center; margin-bottom: 44px; }
.hp-section-eyebrow {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 6px 14px; border-radius: 50px;
    background: rgba(102,126,234,0.12); border: 1px solid rgba(102,126,234,0.3);
    color: var(--text-hi); font-size: 11px; font-weight: 800;
    text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 14px;
}
.hp-section-title {
    font-size: clamp(26px, 3.5vw, 38px);
    font-weight: 900; line-height: 1.15;
    letter-spacing: -0.02em; margin: 0 0 12px;
    background: linear-gradient(135deg, #fff, #a3bffa);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}
.hp-section-sub {
    color: var(--text-dim); font-size: 15px;
    max-width: 640px; margin: 0 auto; line-height: 1.6;
}

/* ============================================
   STATS STRIP
   ============================================ */
.hp-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.hp-stat {
    background: var(--glass); border: 1px solid var(--border);
    border-radius: 16px; padding: 22px 20px; text-align: center;
    position: relative; overflow: hidden; transition: all 0.25s;
}
.hp-stat::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0;
    height: 3px; background: var(--grad); opacity: 0.7;
}
.hp-stat:hover {
    transform: translateY(-4px); border-color: rgba(102,126,234,0.4);
    background: rgba(255,255,255,0.05);
}
.hp-stat .hp-stat-icon {
    width: 44px; height: 44px; border-radius: 12px;
    margin: 0 auto 12px;
    display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.hp-stat .hp-stat-value {
    font-size: 34px; font-weight: 900;
    font-family: 'SF Mono', Monaco, monospace; line-height: 1;
    background: linear-gradient(135deg, #fff, #a3bffa);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text; margin-bottom: 6px;
}
.hp-stat .hp-stat-label {
    font-size: 11px; color: var(--text-dim);
    text-transform: uppercase; letter-spacing: 0.06em; font-weight: 800;
}

/* ============================================
   STAY TYPES (all categories)
   ============================================ */
.hp-types-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 12px;
}
.hp-type {
    background: var(--glass); border: 1px solid var(--border);
    border-radius: 16px; padding: 18px 16px 16px;
    text-decoration: none; color: white;
    display: flex; flex-direction: column; gap: 10px;
    transition: all 0.25s;
    position: relative; overflow: hidden;
}
.hp-type::before {
    content: ''; position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px; opacity: 0;
    transition: opacity 0.25s;
    background: currentColor;
}
.hp-type:hover {
    transform: translateY(-5px);
    border-color: currentColor;
    background: rgba(255,255,255,0.05);
    box-shadow: 0 16px 40px rgba(0,0,0,0.35);
}
.hp-type:hover::before { opacity: 1; }
.hp-type .hp-type-icon {
    width: 46px; height: 46px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
    transition: transform 0.25s;
}
.hp-type:hover .hp-type-icon { transform: scale(1.1); }
.hp-type .hp-type-name {
    font-size: 14px; font-weight: 800;
    line-height: 1.25;
    margin: 0;
}
.hp-type .hp-type-tag {
    font-size: 11px; color: var(--text-dim);
    line-height: 1.4;
    margin: 0;
}
.hp-type .hp-type-count {
    font-size: 10px; color: var(--text-dim);
    font-family: 'SF Mono', Monaco, monospace;
    margin-top: auto;
    padding-top: 8px;
    border-top: 1px solid rgba(255,255,255,0.05);
    display: flex; align-items: center; gap: 6px;
}
.hp-type .hp-type-count i { color: currentColor; opacity: 0.7; }

/* ============================================
   DESTINATIONS (with landmarks)
   ============================================ */
.hp-dest-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}
.hp-dest-card {
    aspect-ratio: 3 / 4;
    border-radius: 20px;
    overflow: hidden;
    position: relative;
    text-decoration: none;
    color: inherit;
    transition: all 0.3s;
    background: #1a1a2e;
}
.hp-dest-card:hover {
    transform: translateY(-6px);
    box-shadow: 0 20px 50px rgba(0,0,0,0.4);
}
.hp-dest-card img {
    width: 100%; height: 100%;
    object-fit: cover; position: absolute; inset: 0;
    transition: transform 0.6s;
}
.hp-dest-card:hover img { transform: scale(1.08); }
.hp-dest-card::after {
    content: ''; position: absolute; inset: 0;
    background: linear-gradient(180deg, rgba(0,0,0,0.05) 30%, rgba(15,12,41,0.92) 100%);
    z-index: 1;
}
.hp-dest-info {
    position: absolute; bottom: 0; left: 0; right: 0;
    padding: 18px 18px 20px; z-index: 2;
}
.hp-dest-info .hp-dest-name {
    font-size: 17px; font-weight: 900;
    color: white; margin-bottom: 3px; line-height: 1.2;
    display: flex; align-items: center; gap: 6px;
}
.hp-dest-info .hp-dest-meta {
    font-size: 11.5px; color: #cbd5e0;
    display: flex; align-items: center; gap: 6px;
    font-family: 'SF Mono', Monaco, monospace;
    font-weight: 700;
}

/* ============================================
   EXPERIENCES
   ============================================ */
.hp-exp-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
}
.hp-exp {
    background: var(--glass); border: 1px solid var(--border);
    border-radius: 16px; padding: 20px 14px;
    text-align: center; text-decoration: none; color: white;
    transition: all 0.25s; position: relative; overflow: hidden;
}
.hp-exp:hover {
    transform: translateY(-4px);
    border-color: rgba(240,147,251,0.4);
    background: rgba(240,147,251,0.06);
}
.hp-exp .ico {
    width: 46px; height: 46px;
    border-radius: 12px;
    background: rgba(240,147,251,0.12); color: var(--pink);
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 10px; font-size: 17px;
    transition: all 0.25s;
}
.hp-exp:hover .ico { transform: scale(1.1); background: rgba(240,147,251,0.2); }
.hp-exp .label { font-size: 13px; font-weight: 800; margin-bottom: 3px; }
.hp-exp .count {
    font-size: 10.5px; color: var(--text-dim);
    font-family: 'SF Mono', Monaco, monospace;
}

/* ============================================
   SMART FEATURES SHOWCASE
   ============================================ */
.hp-smart-section {
    padding: 80px 0;
    position: relative;
    background:
        radial-gradient(700px 320px at 50% 0%, rgba(240,147,251,0.10), transparent 70%),
        radial-gradient(700px 320px at 50% 100%, rgba(0,212,255,0.08), transparent 70%);
}
.hp-smart-section .hp-section-eyebrow {
    background: linear-gradient(135deg, rgba(240,147,251,0.14), rgba(102,126,234,0.14));
    border-color: rgba(240,147,251,0.35);
    color: var(--pink);
}
.hp-smart-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 14px;
}
.hp-smart {
    background: var(--glass);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 22px 20px;
    text-decoration: none;
    color: inherit;
    display: flex; flex-direction: column;
    gap: 12px;
    transition: all 0.28s;
    position: relative;
    overflow: hidden;
}
.hp-smart::before {
    content: '';
    position: absolute;
    top: -80px; right: -80px;
    width: 180px; height: 180px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(240,147,251,0.10), transparent 70%);
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}
.hp-smart:hover {
    transform: translateY(-5px);
    border-color: rgba(240,147,251,0.4);
    background: rgba(255,255,255,0.05);
    box-shadow: 0 20px 44px rgba(0,0,0,0.4);
}
.hp-smart:hover::before { opacity: 1; }
.hp-smart .hp-smart-top {
    display: flex; align-items: center; gap: 12px;
    position: relative; z-index: 1;
}
.hp-smart .hp-smart-icon {
    width: 46px; height: 46px;
    border-radius: 13px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    transition: transform 0.25s;
}
.hp-smart:hover .hp-smart-icon { transform: scale(1.1); }
.hp-smart .hp-smart-tag {
    font-size: 9.5px; font-weight: 800;
    text-transform: uppercase; letter-spacing: 0.08em;
    padding: 3px 9px; border-radius: 50px;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    color: var(--text-dim);
    margin-left: auto;
}
.hp-smart .hp-smart-title {
    font-size: 15.5px; font-weight: 800;
    color: white;
    line-height: 1.3;
    margin: 0;
    position: relative; z-index: 1;
}
.hp-smart .hp-smart-desc {
    font-size: 12.5px; color: var(--text-dim);
    line-height: 1.55;
    margin: 0;
    position: relative; z-index: 1;
    flex: 1;
}
.hp-smart .hp-smart-cta {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 11.5px; font-weight: 800;
    color: var(--text-hi);
    text-transform: uppercase; letter-spacing: 0.05em;
    margin-top: 4px;
    position: relative; z-index: 1;
    transition: gap 0.2s;
}
.hp-smart:hover .hp-smart-cta { gap: 10px; color: white; }

/* ============================================
   PROPERTY CARDS
   ============================================ */
.hp-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
    gap: 22px;
}
.hp-card {
    background: var(--glass); border: 1px solid var(--border);
    border-radius: 20px; overflow: hidden;
    transition: all 0.3s; display: flex; flex-direction: column;
    position: relative;
}
.hp-card:hover {
    transform: translateY(-6px);
    border-color: rgba(102,126,234,0.4);
    box-shadow: 0 24px 60px rgba(0,0,0,0.4);
    background: rgba(255,255,255,0.05);
}
.hp-card-img {
    height: 220px; position: relative; overflow: hidden;
    background: #1a1a2e; flex-shrink: 0;
}
.hp-card-img img {
    width: 100%; height: 100%; object-fit: cover;
    transition: transform 0.6s; display: block;
}
.hp-card:hover .hp-card-img img { transform: scale(1.06); }
.hp-card-badges {
    position: absolute; top: 14px; left: 14px;
    display: flex; flex-direction: column; gap: 6px; z-index: 2;
}
.hp-badge {
    padding: 5px 12px; border-radius: 50px;
    font-size: 10px; font-weight: 800;
    text-transform: uppercase; letter-spacing: 0.05em;
    color: white;
    display: inline-flex; align-items: center; gap: 4px;
    backdrop-filter: blur(6px); width: fit-content;
}
.hp-badge.featured { background: linear-gradient(135deg, rgba(240,147,251,0.95), rgba(245,87,108,0.95)); }
.hp-badge.instant  { background: linear-gradient(135deg, rgba(0,212,255,0.95), rgba(0,184,148,0.95)); color: #0a0a1a; }
.hp-badge.star     { background: linear-gradient(135deg, rgba(255,215,0,0.95), rgba(246,173,85,0.95)); color: #0a0a1a; }

.hp-wishlist {
    position: absolute; top: 14px; right: 14px;
    width: 38px; height: 38px; border-radius: 50%;
    background: rgba(0,0,0,0.6); backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.15);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: all 0.2s;
    color: white; font-size: 15px; z-index: 3;
    padding: 0;
}
.hp-wishlist:hover {
    background: rgba(245,87,108,0.85);
    border-color: rgba(245,87,108,0.9);
    transform: scale(1.08); color: white;
}

.hp-card-body {
    padding: 18px 20px 14px;
    flex: 1; display: flex; flex-direction: column;
}
.hp-card-name {
    font-size: 16px; font-weight: 800;
    color: white; text-decoration: none;
    line-height: 1.35; margin-bottom: 5px;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden; min-height: 43px;
    transition: color 0.2s;
}
.hp-card-name:hover { color: var(--text-hi); }
.hp-card-loc {
    font-size: 12px; color: var(--text-dim);
    display: flex; align-items: center; gap: 5px;
    margin-bottom: 10px;
}
.hp-card-loc i { color: var(--red); font-size: 11px; }
.hp-card-rating {
    display: flex; align-items: center; gap: 8px;
    font-size: 12px; margin-bottom: 12px; flex-wrap: wrap;
}
.hp-card-rating .stars { color: var(--gold); letter-spacing: 1px; font-size: 11px; }
.hp-card-rating .count { color: var(--text-dim); font-family: 'SF Mono', Monaco, monospace; font-size: 11px; }
.hp-card-rating .score {
    padding: 2px 8px; border-radius: 6px;
    background: var(--grad-cyan); color: #0a0a1a;
    font-size: 11px; font-weight: 800;
    display: inline-flex; align-items: center; gap: 3px;
}
.hp-card-rating .score i { font-size: 10px; }

.hp-card-amenities {
    display: flex; flex-wrap: wrap; gap: 5px;
    margin-top: auto; padding-top: 10px;
    border-top: 1px solid rgba(255,255,255,0.04);
}
.hp-amenity {
    font-size: 10.5px; padding: 3px 9px; border-radius: 50px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.06);
    color: #cbd5e0; font-weight: 600;
    display: inline-flex; align-items: center; gap: 4px;
}
.hp-amenity i { font-size: 9px; color: var(--text-hi); }

.hp-card-footer {
    display: flex; justify-content: space-between; align-items: center;
    gap: 12px; padding: 14px 20px 18px;
    border-top: 1px solid rgba(255,255,255,0.04);
}
.hp-price {
    font-size: 20px; font-weight: 900;
    color: var(--text-hi);
    font-family: 'SF Mono', Monaco, monospace;
    line-height: 1.1;
}
.hp-price small { font-size: 11px; color: var(--text-dim); font-weight: 600; font-family: inherit; }
.hp-price-next {
    font-size: 10.5px; color: var(--blue); margin-top: 2px;
    font-family: 'SF Mono', Monaco, monospace;
    display: flex; align-items: center; gap: 4px;
}
.hp-cta {
    padding: 10px 18px; border-radius: 11px;
    background: var(--grad); color: white;
    font-size: 12.5px; font-weight: 800;
    text-decoration: none;
    display: inline-flex; align-items: center; gap: 6px;
    transition: all 0.2s; white-space: nowrap;
    box-shadow: 0 6px 18px rgba(102,126,234,0.35);
    text-transform: uppercase; letter-spacing: 0.04em;
}
.hp-cta:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 26px rgba(102,126,234,0.5);
    color: white;
}

/* ============================================
   ACTIVITIES
   ============================================ */
.hp-act-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 18px;
}
.hp-act-card {
    background: var(--glass); border: 1px solid var(--border);
    border-radius: 18px; overflow: hidden;
    text-decoration: none; color: inherit;
    display: flex; flex-direction: column;
    transition: all 0.3s;
}
.hp-act-card:hover {
    transform: translateY(-4px);
    border-color: rgba(240,147,251,0.4);
    box-shadow: 0 16px 42px rgba(0,0,0,0.35);
}
.hp-act-img {
    height: 170px; position: relative; overflow: hidden;
    background: var(--grad-pink);
}
.hp-act-img img {
    width: 100%; height: 100%; object-fit: cover;
    transition: transform 0.5s; display: block;
}
.hp-act-card:hover .hp-act-img img { transform: scale(1.06); }
.hp-act-img .placeholder {
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    font-size: 44px; color: rgba(255,255,255,0.6);
}
.hp-act-img::after {
    content: ''; position: absolute; inset: 0;
    background: linear-gradient(180deg, transparent 55%, rgba(15,12,41,0.7));
    pointer-events: none;
}
.hp-act-badge {
    position: absolute; bottom: 12px; left: 12px;
    padding: 4px 11px; border-radius: 50px;
    background: rgba(0,0,0,0.7); backdrop-filter: blur(8px);
    color: white; font-size: 10px; font-weight: 800;
    text-transform: uppercase; letter-spacing: 0.05em;
    display: inline-flex; align-items: center; gap: 5px;
    z-index: 2; border: 1px solid rgba(255,255,255,0.1);
}
.hp-act-badge i { color: var(--text-hi); font-size: 9px; }
.hp-act-body { padding: 14px 16px 16px; flex: 1; display: flex; flex-direction: column; }
.hp-act-name {
    font-size: 15px; font-weight: 800;
    color: white; line-height: 1.35; margin-bottom: 4px;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden; min-height: 41px;
}
.hp-act-meta {
    display: flex; gap: 10px; flex-wrap: wrap;
    font-size: 11.5px; color: var(--text-dim); margin-bottom: 10px;
}
.hp-act-meta span { display: inline-flex; align-items: center; gap: 4px; }
.hp-act-meta i { color: var(--text-hi); font-size: 10px; }
.hp-act-rating { color: var(--gold); font-weight: 800; font-family: 'SF Mono', Monaco, monospace; }
.hp-act-footer {
    display: flex; justify-content: space-between; align-items: center;
    padding-top: 10px; margin-top: auto;
    border-top: 1px solid rgba(255,255,255,0.05);
}
.hp-act-price {
    font-size: 15px; font-weight: 900;
    color: var(--text-hi);
    font-family: 'SF Mono', Monaco, monospace;
}
.hp-act-price .free { color: var(--green); }
.hp-act-price small { font-size: 10px; color: var(--text-dim); font-family: inherit; font-weight: 600; }
.hp-act-arrow {
    width: 30px; height: 30px; border-radius: 9px;
    background: rgba(240,147,251,0.15);
    border: 1px solid rgba(240,147,251,0.3);
    color: var(--pink);
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; transition: all 0.2s;
}
.hp-act-card:hover .hp-act-arrow {
    background: var(--grad-pink);
    border-color: transparent; color: white;
}

/* ============================================
   CTA SECTION
   ============================================ */
.hp-cta-section {
    padding: 80px 20px; text-align: center;
    background:
        radial-gradient(600px 300px at 50% 0%, rgba(240,147,251,0.15), transparent 70%),
        radial-gradient(600px 300px at 50% 100%, rgba(102,126,234,0.15), transparent 70%);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}
.hp-cta-title {
    font-size: clamp(28px, 4vw, 44px);
    font-weight: 900; letter-spacing: -0.02em;
    margin: 0 0 12px;
    background: linear-gradient(135deg, #fff, #a3bffa);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}
.hp-cta-sub {
    color: var(--text-dim); font-size: 16px;
    max-width: 560px; margin: 0 auto 32px; line-height: 1.6;
}
.hp-cta-buttons { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.hp-btn-primary,
.hp-btn-secondary {
    padding: 15px 32px; border-radius: 14px;
    font-size: 14px; font-weight: 800;
    text-decoration: none;
    display: inline-flex; align-items: center; gap: 8px;
    transition: all 0.25s;
    text-transform: uppercase; letter-spacing: 0.04em;
}
.hp-btn-primary {
    background: var(--grad); color: white;
    box-shadow: 0 10px 30px rgba(102,126,234,0.4);
}
.hp-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 16px 40px rgba(102,126,234,0.55);
    color: white;
}
.hp-btn-secondary {
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    color: #cbd5e0;
}
.hp-btn-secondary:hover {
    background: rgba(255,255,255,0.1);
    color: white;
    border-color: rgba(102,126,234,0.4);
    transform: translateY(-2px);
}

/* ============================================
   NO RESULTS / RECENT
   ============================================ */
.hp-no-results {
    text-align: center; padding: 60px 20px;
    background: var(--glass);
    border: 1px dashed var(--border);
    border-radius: 20px;
}
.hp-no-results .ico-wrap {
    width: 82px; height: 82px; border-radius: 50%;
    background: rgba(102,126,234,0.12);
    border: 1px solid rgba(102,126,234,0.3);
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 20px; font-size: 32px; color: var(--text-hi);
}
.hp-no-results h3 { font-size: 20px; font-weight: 800; margin: 0 0 8px; }
.hp-no-results p {
    color: var(--text-dim); font-size: 14px;
    max-width: 480px; margin: 0 auto 24px; line-height: 1.6;
}

.hp-recent-scroll {
    display: flex; gap: 14px; overflow-x: auto;
    padding-bottom: 12px; scrollbar-width: thin;
}
.hp-recent-scroll::-webkit-scrollbar { height: 6px; }
.hp-recent-scroll::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1); border-radius: 3px;
}
.hp-recent-card {
    flex: 0 0 240px;
    background: var(--glass); border: 1px solid var(--border);
    border-radius: 14px; overflow: hidden;
    text-decoration: none; color: inherit;
    transition: all 0.25s;
}
.hp-recent-card:hover {
    transform: translateY(-4px);
    border-color: rgba(102,126,234,0.4);
}
.hp-recent-card img { width: 100%; height: 130px; object-fit: cover; display: block; }
.hp-recent-card .info { padding: 12px 14px; }
.hp-recent-card .name {
    font-size: 13.5px; font-weight: 800; color: white;
    margin-bottom: 3px; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
}
.hp-recent-card .loc {
    font-size: 11px; color: var(--text-dim);
    display: flex; align-items: center; gap: 4px; margin-bottom: 6px;
}
.hp-recent-card .loc i { color: var(--red); font-size: 10px; }
.hp-recent-card .price {
    font-size: 14px; font-weight: 900;
    color: var(--text-hi);
    font-family: 'SF Mono', Monaco, monospace;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 968px) {
    .hp-search-grid { grid-template-columns: 1fr 1fr; }
    .hp-search-submit { grid-column: span 2; }
    .hp-hero { min-height: auto; padding: 100px 0 40px; }
    .hp-section { padding: 50px 0; }
}
@media (max-width: 640px) {
    .hp-hero { padding: 90px 0 40px; }
    .hp-search { padding: 12px; border-radius: 18px; }
    .hp-search-grid { grid-template-columns: 1fr; }
    .hp-search-submit { grid-column: span 1; width: 100%; }
    .hp-title { font-size: 34px; }
    .hp-subtitle { font-size: 15px; }
    .hp-section-title { font-size: 24px; }
    .hp-types-grid { grid-template-columns: repeat(2, 1fr); }
    .hp-type { padding: 14px 12px; }
    .hp-type .hp-type-icon { width: 38px; height: 38px; font-size: 15px; }
    .hp-type .hp-type-name { font-size: 12.5px; }
    .hp-dest-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .hp-exp-grid { grid-template-columns: repeat(3, 1fr); }
    .hp-exp { padding: 16px 10px; }
    .hp-exp .ico { width: 38px; height: 38px; font-size: 14px; }
    .hp-exp .label { font-size: 11px; }
    .hp-smart-grid { grid-template-columns: 1fr; }
    .hp-grid { grid-template-columns: 1fr; }
    .hp-act-grid { grid-template-columns: 1fr; }
    .hp-stats { grid-template-columns: repeat(2, 1fr); }
    .hp-cta-buttons { flex-direction: column; }
    .hp-btn-primary, .hp-btn-secondary { width: 100%; justify-content: center; }
    .hp-recent-card { flex: 0 0 200px; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
    .hp-orb { animation: none; }
    .hp-live-line .live-dot, .hp-badge .dot { animation: none; }
}
</style>

<div class="home-page">

<!-- ============================================
     HERO
     ============================================ -->
<section class="hp-hero">
    <div class="hp-hero-bg">
        <div class="hp-orb hp-orb-1"></div>
        <div class="hp-orb hp-orb-2"></div>
        <div class="hp-orb hp-orb-3"></div>
    </div>

    <div class="hp-hero-content">

        <div class="hp-badge">
            <span class="dot"></span>
            <i class="fas fa-bolt" style="color: var(--blue);"></i>
            Revenda · Crypto-native hospitality
        </div>

        <h1 class="hp-title">
            Stay anywhere.<br>
            Pay <em>any way</em>.
        </h1>

        <?php if ($stats['properties'] > 0): ?>
            <div class="hp-live-line">
                <span class="live-dot"></span>
                <?= number_format($stats['properties']) ?> properties ·
                <?= number_format($stats['cities']) ?> cities ·
                <?= number_format($stats['activities']) ?> experiences live now
            </div>
        <?php endif; ?>

        <p class="hp-subtitle">
            Book hotels, resorts, villas, and one-of-a-kind experiences with
            <strong>fiat or crypto</strong>. AI-curated stays. Instant confirmation.
            Rooms controlled by voice. Your next stay, reimagined.
        </p>

        <div class="hp-trust">
            <span class="hp-trust-item"><i class="fas fa-shield-alt"></i> Verified properties</span>
            <span class="hp-trust-item"><i class="fas fa-bolt"></i> Instant booking</span>
            <span class="hp-trust-item"><i class="fab fa-bitcoin"></i> Pay with crypto</span>
            <span class="hp-trust-item"><i class="fas fa-robot"></i> Smart rooms</span>
        </div>

        <form action="/" method="GET" class="hp-search" id="hpSearchForm">
            <input type="hidden" name="page" value="home">

            <div class="hp-search-grid">
                <div class="hp-search-field">
                    <label><i class="fas fa-search"></i> Where to?</label>
                    <input type="text" name="search"
                           placeholder="City, property name, or activity…"
                           value="<?= htmlspecialchars($search) ?>"
                           autocomplete="off">
                </div>

                <div class="hp-search-field">
                    <label><i class="fas fa-calendar-check"></i> Check-in</label>
                    <input type="text" name="check_in" class="flatpickr"
                           placeholder="Select"
                           value="<?= htmlspecialchars($checkIn) ?>"
                           data-type="checkin">
                </div>

                <div class="hp-search-field">
                    <label><i class="fas fa-calendar-xmark"></i> Check-out</label>
                    <input type="text" name="check_out" class="flatpickr"
                           placeholder="Select"
                           value="<?= htmlspecialchars($checkOut) ?>"
                           data-type="checkout">
                </div>

                <div class="hp-search-field">
                    <label><i class="fas fa-user-group"></i> Guests</label>
                    <select name="guests">
                        <?php for ($i = 1; $i <= 20; $i++): ?>
                            <option value="<?= $i ?>" <?= $guests == $i ? 'selected' : '' ?>><?= $i ?></option>
                        <?php endfor; ?>
                    </select>
                </div>

                <div class="hp-search-field">
                    <label><i class="fas fa-door-open"></i> Rooms</label>
                    <select name="rooms">
                        <?php for ($i = 1; $i <= 10; $i++): ?>
                            <option value="<?= $i ?>" <?= $rooms == $i ? 'selected' : '' ?>><?= $i ?></option>
                        <?php endfor; ?>
                    </select>
                </div>

                <button type="submit" class="hp-search-submit">
                    <i class="fas fa-search"></i> Search
                </button>
            </div>
        </form>

        <div class="hp-quick-filters">
            <a href="?instant_book=1" class="hp-chip <?= $instantBook ? 'active' : '' ?>">
                <i class="fas fa-bolt"></i> Instant Book
            </a>
            <a href="?star_rating=4" class="hp-chip <?= $starRating == 4 ? 'active' : '' ?>">
                <i class="fas fa-star" style="color: var(--gold);"></i> 4★ & up
            </a>
            <a href="/?page=activities" class="hp-chip">
                <i class="fas fa-compass"></i> Experiences
            </a>
            <a href="/?page=smart-room" class="hp-chip">
                <i class="fas fa-microchip"></i> Smart Rooms
            </a>
            <?php if ($hasActiveFilters): ?>
                <a href="/" class="hp-chip active">
                    <i class="fas fa-rotate-left"></i> Reset
                </a>
            <?php endif; ?>
        </div>

        <a href="/?page=trip-planner" class="hp-ai-prompt">
            <i class="fas fa-wand-magic-sparkles"></i>
            Let AI plan my trip →
        </a>

    </div>
</section>

<!-- ============================================
     LIVE STATS
     ============================================ -->
<?php if (!$hasActiveFilters): ?>
<section class="hp-section">
    <div class="hp-container">
        <div class="hp-stats">
            <div class="hp-stat">
                <div class="hp-stat-icon" style="background: rgba(102,126,234,0.15); color: var(--text-hi);">
                    <i class="fas fa-hotel"></i>
                </div>
                <div class="hp-stat-value"><?= humanizeCount($stats['properties']) ?></div>
                <div class="hp-stat-label">Properties</div>
            </div>
            <div class="hp-stat">
                <div class="hp-stat-icon" style="background: rgba(0,212,255,0.15); color: var(--blue);">
                    <i class="fas fa-globe-americas"></i>
                </div>
                <div class="hp-stat-value"><?= number_format($stats['countries']) ?></div>
                <div class="hp-stat-label">Countries</div>
            </div>
            <div class="hp-stat">
                <div class="hp-stat-icon" style="background: rgba(240,147,251,0.15); color: var(--pink);">
                    <i class="fas fa-city"></i>
                </div>
                <div class="hp-stat-value"><?= number_format($stats['cities']) ?></div>
                <div class="hp-stat-label">Destinations</div>
            </div>
            <div class="hp-stat">
                <div class="hp-stat-icon" style="background: rgba(246,173,85,0.15); color: var(--orange);">
                    <i class="fas fa-compass"></i>
                </div>
                <div class="hp-stat-value"><?= humanizeCount($stats['activities']) ?></div>
                <div class="hp-stat-label">Experiences</div>
            </div>
        </div>
    </div>
</section>
<?php endif; ?>

<!-- ============================================
     BROWSE BY STAY TYPE — every category
     ============================================ -->
<?php if (!$hasActiveFilters && !empty($categories)): ?>
<section class="hp-section hp-section-alt">
    <div class="hp-container">
        <div class="hp-section-head">
            <div class="hp-section-eyebrow">
                <i class="fas fa-layer-group"></i> Every kind of stay
            </div>
            <h2 class="hp-section-title">Browse by stay type</h2>
            <p class="hp-section-sub">
                From budget hostels to private castles — every accommodation type we support.
            </p>
        </div>

        <div class="hp-types-grid">
            <?php foreach ($categories as $cat):
                $meta = homeCategoryMeta($cat);
            ?>
                <a href="?category=<?= (int)$cat['id'] ?>"
                   class="hp-type"
                   style="color: <?= htmlspecialchars($meta['color']) ?>;">
                    <div class="hp-type-icon"
                         style="background: <?= htmlspecialchars($meta['color']) ?>22; color: <?= htmlspecialchars($meta['color']) ?>;">
                        <i class="fas <?= htmlspecialchars($meta['icon']) ?>"></i>
                    </div>
                    <div>
                        <div class="hp-type-name"><?= htmlspecialchars($cat['name'] ?? 'Stay') ?></div>
                        <div class="hp-type-tag"><?= htmlspecialchars($meta['tag']) ?></div>
                    </div>
                    <div class="hp-type-count">
                        <i class="fas fa-arrow-right"></i> Explore
                    </div>
                </a>
            <?php endforeach; ?>
        </div>
    </div>
</section>
<?php endif; ?>

<!-- ============================================
     TRENDING DESTINATIONS — with real landmarks
     ============================================ -->
<?php if (!$hasActiveFilters && !empty($topDestinations)): ?>
<section class="hp-section">
    <div class="hp-container">
        <div class="hp-section-head">
            <div class="hp-section-eyebrow">
                <i class="fas fa-fire"></i> Trending destinations
            </div>
            <h2 class="hp-section-title">Where travelers are going</h2>
            <p class="hp-section-sub">
                Real properties in real cities — browse our most-booked destinations.
            </p>
        </div>

        <div class="hp-dest-grid">
            <?php foreach ($topDestinations as $d):
                $heroImg = homeDestinationImage($d);
            ?>
                <a href="/?page=properties&city=<?= (int)$d['id'] ?>" class="hp-dest-card">
                    <img src="<?= htmlspecialchars($heroImg) ?>"
                         alt="<?= htmlspecialchars($d['name']) ?>"
                         loading="lazy"
                         onerror="this.onerror=null; this.src='https://images.unsplash.com/photo-1502602898657-3e91760cbb34?w=600&h=800&fit=crop';">
                    <div class="hp-dest-info">
                        <div class="hp-dest-name">
                            <span><?= htmlspecialchars($d['flag_emoji'] ?? '📍') ?></span>
                            <?= htmlspecialchars($d['name']) ?>
                        </div>
                        <div class="hp-dest-meta">
                            <i class="fas fa-hotel"></i>
                            <?= (int)$d['property_count'] ?> propert<?= (int)$d['property_count'] === 1 ? 'y' : 'ies' ?>
                        </div>
                    </div>
                </a>
            <?php endforeach; ?>
        </div>
    </div>
</section>
<?php endif; ?>

<!-- ============================================
     SMART FEATURES SHOWCASE
     ============================================ -->
<?php if (!$hasActiveFilters): ?>
<section class="hp-smart-section">
    <div class="hp-container">
        <div class="hp-section-head">
            <div class="hp-section-eyebrow">
                <i class="fas fa-microchip"></i> Only on Revenda
            </div>
            <h2 class="hp-section-title">A stay that thinks with you</h2>
            <p class="hp-section-sub">
                Every property on Revenda can be upgraded with smart-room hardware, voice control,
                robot delivery, and AI planning. These are the features no other OTA offers.
            </p>
        </div>

        <div class="hp-smart-grid">
            <?php foreach ($smartFeatures as $sf): ?>
                <a href="/?page=<?= urlencode($sf['page']) ?>" class="hp-smart">
                    <div class="hp-smart-top">
                        <div class="hp-smart-icon"
                             style="background: <?= htmlspecialchars($sf['color']) ?>22; color: <?= htmlspecialchars($sf['color']) ?>;">
                            <i class="fas <?= htmlspecialchars($sf['icon']) ?>"></i>
                        </div>
                        <span class="hp-smart-tag"><?= htmlspecialchars($sf['tag']) ?></span>
                    </div>
                    <h3 class="hp-smart-title"><?= htmlspecialchars($sf['title']) ?></h3>
                    <p class="hp-smart-desc"><?= htmlspecialchars($sf['desc']) ?></p>
                    <span class="hp-smart-cta">
                        Explore <i class="fas fa-arrow-right"></i>
                    </span>
                </a>
            <?php endforeach; ?>
        </div>
    </div>
</section>
<?php endif; ?>

<!-- ============================================
     BROWSE BY EXPERIENCE
     ============================================ -->
<?php if (!$hasActiveFilters && !empty($experienceCategories)): ?>
<section class="hp-section hp-section-alt">
    <div class="hp-container">
        <div class="hp-section-head">
            <div class="hp-section-eyebrow">
                <i class="fas fa-compass"></i> Beyond the room
            </div>
            <h2 class="hp-section-title">Browse by experience</h2>
            <p class="hp-section-sub">
                Food tours, museums, nature, nightlife — real activities near your stay.
            </p>
        </div>

        <div class="hp-exp-grid">
            <?php foreach ($experienceCategories as $exp): ?>
                <a href="/?page=activities&category=<?= urlencode($exp['slug']) ?>" class="hp-exp">
                    <div class="ico">
                        <i class="fas <?= htmlspecialchars($exp['icon']) ?>"></i>
                    </div>
                    <div class="label"><?= htmlspecialchars($exp['label']) ?></div>
                    <?php if ($exp['count'] > 0): ?>
                        <div class="count"><?= number_format($exp['count']) ?> activit<?= $exp['count'] === 1 ? 'y' : 'ies' ?></div>
                    <?php endif; ?>
                </a>
            <?php endforeach; ?>
        </div>
    </div>
</section>
<?php endif; ?>

<!-- ============================================
     SEARCH RESULTS (when filters active)
     ============================================ -->
<?php if ($hasActiveFilters): ?>
<section class="hp-section">
    <div class="hp-container">

        <div style="display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 16px; margin-bottom: 28px;">
            <div>
                <h2 style="font-size: 26px; font-weight: 900; margin: 0 0 4px;">
                    <?= !empty($search) ? 'Results for "' . htmlspecialchars($search) . '"' : 'Available properties' ?>
                </h2>
                <div style="font-size: 13.5px; color: var(--text-dim);">
                    <strong style="color: white;"><?= count($properties) ?></strong> propert<?= count($properties) === 1 ? 'y' : 'ies' ?> found
                    <?php if ($checkIn && $checkOut): ?>
                        · <?= date('M j', strtotime($checkIn)) ?> – <?= date('M j', strtotime($checkOut)) ?>
                    <?php endif; ?>
                </div>
            </div>

            <div style="display: flex; align-items: center; gap: 8px;">
                <label style="font-size: 12px; color: var(--text-dim); font-weight: 700;">Sort:</label>
                <select onchange="window.location.href=this.value"
                        style="padding: 8px 32px 8px 14px; background: rgba(255,255,255,0.05); border: 1px solid var(--border); border-radius: 10px; color: white; font-size: 13px; outline: none; min-width: 180px;">
                    <?php
                    $sortOptions = [
                        'relevance'  => 'Relevance',
                        'price_asc'  => 'Price: Low → High',
                        'price_desc' => 'Price: High → Low',
                        'rating'     => 'Top Rated',
                        'popularity' => 'Most Popular',
                        'newest'     => 'Newest',
                    ];
                    foreach ($sortOptions as $key => $label):
                        $url = '?' . http_build_query(array_merge($_GET, ['sort' => $key]));
                    ?>
                        <option value="<?= htmlspecialchars($url) ?>" <?= $sort === $key ? 'selected' : '' ?>>
                            <?= htmlspecialchars($label) ?>
                        </option>
                    <?php endforeach; ?>
                </select>
            </div>
        </div>

        <?php if (!empty($properties)): ?>
            <div class="hp-grid">
                <?php foreach ($properties as $property):
                    $imageUrl = getPropertyImageUrl($property);
                    $rating = function_exists('getAverageRating')
                        ? getAverageRating($property['id'])
                        : ['average' => $property['average_rating'] ?? 0, 'total' => $property['total_reviews'] ?? 0];
                    $amenities = json_decode($property['amenities'] ?? '[]', true);
                    if (!is_array($amenities)) $amenities = [];
                    $displayAmenities = array_slice($amenities, 0, 4);
                ?>
                    <article class="hp-card">
                        <div class="hp-card-img">
                            <a href="/?page=property&slug=<?= urlencode($property['slug'] ?? '') ?>" style="display:block;width:100%;height:100%;">
                                <img src="<?= htmlspecialchars($imageUrl) ?>"
                                     alt="<?= htmlspecialchars($property['name'] ?? 'Property') ?>"
                                     loading="lazy"
                                     onerror="this.onerror=null; this.src='https://images.unsplash.com/photo-1566073771259-6a8506099945?w=800&h=600&fit=crop';">
                            </a>
                            <div class="hp-card-badges">
                                <?php if (!empty($property['is_featured'])): ?>
                                    <span class="hp-badge featured"><i class="fas fa-crown"></i> Featured</span>
                                <?php endif; ?>
                                <?php if (!empty($property['is_instant_bookable'])): ?>
                                    <span class="hp-badge instant"><i class="fas fa-bolt"></i> Instant</span>
                                <?php endif; ?>
                                <?php if (($property['star_rating'] ?? 0) >= 4): ?>
                                    <span class="hp-badge star"><i class="fas fa-star"></i> <?= (int)$property['star_rating'] ?>★</span>
                                <?php endif; ?>
                            </div>
                            <button type="button" class="hp-wishlist"
                                    onclick="toggleWishlist(<?= (int)($property['id'] ?? 0) ?>, this)"
                                    aria-label="Save">
                                <i class="far fa-heart"></i>
                            </button>
                        </div>

                        <div class="hp-card-body">
                            <a href="/?page=property&slug=<?= urlencode($property['slug'] ?? '') ?>" class="hp-card-name">
                                <?= htmlspecialchars($property['name'] ?? 'Property') ?>
                            </a>
                            <div class="hp-card-loc">
                                <i class="fas fa-map-marker-alt"></i>
                                <?= htmlspecialchars(trim(($property['city_name'] ?? '') . ', ' . ($property['country_name'] ?? ''), ', ')) ?>
                                <?= htmlspecialchars($property['flag_emoji'] ?? '') ?>
                            </div>
                            <div class="hp-card-rating">
                                <?php if (($rating['average'] ?? 0) > 0): ?>
                                    <span class="score"><i class="fas fa-star"></i> <?= number_format((float)$rating['average'], 1) ?></span>
                                <?php endif; ?>
                                <span class="stars"><?= safeStarRating($rating['average'] ?? 0) ?></span>
                                <?php if (($rating['total'] ?? 0) > 0): ?>
                                    <span class="count">(<?= (int)$rating['total'] ?>)</span>
                                <?php endif; ?>
                            </div>

                            <?php if (!empty($displayAmenities)): ?>
                                <div class="hp-card-amenities">
                                    <?php foreach ($displayAmenities as $amenity): ?>
                                        <span class="hp-amenity">
                                            <i class="fas <?= getAmenityIconSafe($amenity) ?>"></i>
                                            <?= htmlspecialchars(ucfirst(str_replace('_', ' ', $amenity))) ?>
                                        </span>
                                    <?php endforeach; ?>
                                    <?php if (count($amenities) > 4): ?>
                                        <span class="hp-amenity">+<?= count($amenities) - 4 ?></span>
                                    <?php endif; ?>
                                </div>
                            <?php endif; ?>
                        </div>

                        <div class="hp-card-footer">
                            <div>
                                <div class="hp-price">
                                    <?= formatCurrency($property['min_price_per_night'] ?? 0) ?>
                                    <small>/ night</small>
                                </div>
                                <?php if (!empty($property['next_available'])): ?>
                                    <div class="hp-price-next">
                                        <i class="fas fa-check-circle"></i> Next available <?= date('M j', strtotime($property['next_available'])) ?>
                                    </div>
                                <?php endif; ?>
                            </div>
                            <a href="/?page=property&slug=<?= urlencode($property['slug'] ?? '') ?>" class="hp-cta">
                                View <i class="fas fa-arrow-right"></i>
                            </a>
                        </div>
                    </article>
                <?php endforeach; ?>
            </div>
        <?php else: ?>
            <div class="hp-no-results">
                <div class="ico-wrap"><i class="fas fa-search"></i></div>
                <h3>No properties match your search</h3>
                <p>Try adjusting your dates, guests, or filters. Or explore our trending destinations below.</p>
                <a href="/" class="hp-btn-primary">
                    <i class="fas fa-rotate-left"></i> Reset all filters
                </a>
            </div>
        <?php endif; ?>
    </div>
</section>
<?php endif; ?>

<!-- ============================================
     FEATURED PROPERTIES
     ============================================ -->
<?php if (!$hasActiveFilters && !empty($featured)): ?>
<section class="hp-section">
    <div class="hp-container">
        <div class="hp-section-head">
            <div class="hp-section-eyebrow">
                <i class="fas fa-crown" style="color: var(--gold);"></i> Handpicked for you
            </div>
            <h2 class="hp-section-title">Featured stays</h2>
            <p class="hp-section-sub">
                Curated by our team — luxury resorts, boutique villas, and unforgettable lodges.
            </p>
        </div>

        <div class="hp-grid">
            <?php foreach ($featured as $property):
                $imageUrl = getPropertyImageUrl($property);
                $rating = function_exists('getAverageRating')
                    ? getAverageRating($property['id'])
                    : ['average' => $property['average_rating'] ?? 0, 'total' => $property['total_reviews'] ?? 0];
                $amenities = json_decode($property['amenities'] ?? '[]', true);
                if (!is_array($amenities)) $amenities = [];
                $displayAmenities = array_slice($amenities, 0, 3);
            ?>
                <article class="hp-card">
                    <div class="hp-card-img">
                        <a href="/?page=property&slug=<?= urlencode($property['slug'] ?? '') ?>" style="display:block;width:100%;height:100%;">
                            <img src="<?= htmlspecialchars($imageUrl) ?>"
                                 alt="<?= htmlspecialchars($property['name'] ?? 'Property') ?>"
                                 loading="lazy"
                                 onerror="this.onerror=null; this.src='https://images.unsplash.com/photo-1566073771259-6a8506099945?w=800&h=600&fit=crop';">
                        </a>
                        <div class="hp-card-badges">
                            <?php if (!empty($property['is_featured'])): ?>
                                <span class="hp-badge featured"><i class="fas fa-crown"></i> Featured</span>
                            <?php endif; ?>
                            <?php if (!empty($property['is_instant_bookable'])): ?>
                                <span class="hp-badge instant"><i class="fas fa-bolt"></i> Instant</span>
                            <?php endif; ?>
                        </div>
                        <button type="button" class="hp-wishlist"
                                onclick="toggleWishlist(<?= (int)($property['id'] ?? 0) ?>, this)"
                                aria-label="Save">
                            <i class="far fa-heart"></i>
                        </button>
                    </div>
                    <div class="hp-card-body">
                        <a href="/?page=property&slug=<?= urlencode($property['slug'] ?? '') ?>" class="hp-card-name">
                            <?= htmlspecialchars($property['name'] ?? 'Property') ?>
                        </a>
                        <div class="hp-card-loc">
                            <i class="fas fa-map-marker-alt"></i>
                            <?= htmlspecialchars(trim(($property['city_name'] ?? '') . ', ' . ($property['country_name'] ?? ''), ', ')) ?>
                            <?= htmlspecialchars($property['flag_emoji'] ?? '') ?>
                        </div>
                        <div class="hp-card-rating">
                            <?php if (($rating['average'] ?? 0) > 0): ?>
                                <span class="score"><i class="fas fa-star"></i> <?= number_format((float)$rating['average'], 1) ?></span>
                            <?php endif; ?>
                            <span class="stars"><?= safeStarRating($rating['average'] ?? 0) ?></span>
                            <?php if (($rating['total'] ?? 0) > 0): ?>
                                <span class="count">(<?= (int)$rating['total'] ?>)</span>
                            <?php endif; ?>
                        </div>
                        <?php if (!empty($displayAmenities)): ?>
                            <div class="hp-card-amenities">
                                <?php foreach ($displayAmenities as $amenity): ?>
                                    <span class="hp-amenity">
                                        <i class="fas <?= getAmenityIconSafe($amenity) ?>"></i>
                                        <?= htmlspecialchars(ucfirst(str_replace('_', ' ', $amenity))) ?>
                                    </span>
                                <?php endforeach; ?>
                            </div>
                        <?php endif; ?>
                    </div>
                    <div class="hp-card-footer">
                        <div class="hp-price">
                            <?= formatCurrency($property['min_price_per_night'] ?? 0) ?>
                            <small>/ night</small>
                        </div>
                        <a href="/?page=property&slug=<?= urlencode($property['slug'] ?? '') ?>" class="hp-cta">
                            View <i class="fas fa-arrow-right"></i>
                        </a>
                    </div>
                </article>
            <?php endforeach; ?>
        </div>
    </div>
</section>
<?php endif; ?>

<!-- ============================================
     FEATURED ACTIVITIES
     ============================================ -->
<?php if (!$hasActiveFilters && !empty($featuredActivities)): ?>
<section class="hp-section hp-section-alt">
    <div class="hp-container">
        <div class="hp-section-head">
            <div class="hp-section-eyebrow">
                <i class="fas fa-star" style="color: var(--pink);"></i> Experiences worth flying for
            </div>
            <h2 class="hp-section-title">Top-rated activities</h2>
            <p class="hp-section-sub">
                Hand-picked experiences from our global catalogue — book ahead, skip the queue.
            </p>
        </div>

        <div class="hp-act-grid">
            <?php foreach ($featuredActivities as $act):
                $actImg = '';
                if (!empty($act['image'])) {
                    $actImg = strpos($act['image'], 'http') === 0
                        ? $act['image']
                        : '/uploads/' . ltrim($act['image'], '/');
                }
                $actPrice = (float)($act['price_from'] ?? 0);
                $isFree = $actPrice <= 0;
                $duration = (int)($act['duration_minutes'] ?? 0);
                $durationLabel = '';
                if ($duration > 0) {
                    $durationLabel = $duration < 60
                        ? $duration . 'm'
                        : floor($duration / 60) . 'h' . ($duration % 60 ? ' ' . ($duration % 60) . 'm' : '');
                }
            ?>
                <a href="/?page=activity&slug=<?= urlencode($act['slug'] ?? '') ?>" class="hp-act-card">
                    <div class="hp-act-img">
                        <?php if ($actImg): ?>
                            <img src="<?= htmlspecialchars($actImg) ?>" alt="<?= htmlspecialchars($act['name'] ?? '') ?>" loading="lazy"
                                 onerror="this.style.display='none'; this.nextElementSibling.style.display='flex';">
                            <div class="placeholder" style="display:none;">
                                <i class="fas <?= homeActivityIcon($act['type'] ?? '', $act['category'] ?? '') ?>"></i>
                            </div>
                        <?php else: ?>
                            <div class="placeholder">
                                <i class="fas <?= homeActivityIcon($act['type'] ?? '', $act['category'] ?? '') ?>"></i>
                            </div>
                        <?php endif; ?>
                        <span class="hp-act-badge">
                            <i class="fas <?= homeActivityIcon($act['type'] ?? '', $act['category'] ?? '') ?>"></i>
                            <?= htmlspecialchars(ucfirst(str_replace('_', ' ', $act['type'] ?: ($act['category'] ?: 'Attraction')))) ?>
                        </span>
                    </div>
                    <div class="hp-act-body">
                        <div class="hp-act-name"><?= htmlspecialchars($act['name'] ?? '') ?></div>
                        <div class="hp-act-meta">
                            <?php if (!empty($act['rating'])): ?>
                                <span class="hp-act-rating"><i class="fas fa-star"></i> <?= number_format((float)$act['rating'], 1) ?></span>
                            <?php endif; ?>
                            <?php if ($durationLabel): ?>
                                <span><i class="fas fa-clock"></i> <?= htmlspecialchars($durationLabel) ?></span>
                            <?php endif; ?>
                            <?php if (!empty($act['destination_name'])): ?>
                                <span><i class="fas fa-map-pin"></i> <?= htmlspecialchars($act['destination_name']) ?></span>
                            <?php endif; ?>
                        </div>
                        <div class="hp-act-footer">
                            <div class="hp-act-price">
                                <?php if ($isFree): ?>
                                    <span class="free">Free</span>
                                <?php else: ?>
                                    $<?= number_format($actPrice, 0) ?>
                                    <small> from</small>
                                <?php endif; ?>
                            </div>
                            <div class="hp-act-arrow"><i class="fas fa-arrow-right"></i></div>
                        </div>
                    </div>
                </a>
            <?php endforeach; ?>
        </div>
    </div>
</section>
<?php endif; ?>

<!-- ============================================
     RECENTLY VIEWED
     ============================================ -->
<?php if (!$hasActiveFilters && !empty($recentlyViewed)): ?>
<section class="hp-section">
    <div class="hp-container">
        <div class="hp-section-head">
            <div class="hp-section-eyebrow">
                <i class="fas fa-clock-rotate-left"></i> Pick up where you left off
            </div>
            <h2 class="hp-section-title">Recently viewed</h2>
        </div>

        <div class="hp-recent-scroll">
            <?php foreach ($recentlyViewed as $p):
                $img = '';
                if (!empty($p['featured_image'])) {
                    $img = '/uploads/' . ltrim($p['featured_image'], '/');
                } elseif (!empty($p['image'])) {
                    $img = strpos($p['image'], 'http') === 0 ? $p['image'] : '/uploads/' . ltrim($p['image'], '/');
                } else {
                    $img = 'https://images.unsplash.com/photo-1566073771259-6a8506099945?w=400&h=300&fit=crop';
                }
            ?>
                <a href="/?page=property&slug=<?= urlencode($p['slug'] ?? '') ?>" class="hp-recent-card">
                    <img src="<?= htmlspecialchars($img) ?>" alt="<?= htmlspecialchars($p['name'] ?? '') ?>" loading="lazy"
                         onerror="this.src='https://images.unsplash.com/photo-1566073771259-6a8506099945?w=400&h=300&fit=crop';">
                    <div class="info">
                        <div class="name"><?= htmlspecialchars($p['name'] ?? '') ?></div>
                        <div class="loc">
                            <i class="fas fa-map-marker-alt"></i>
                            <?= htmlspecialchars($p['city_name'] ?? '') ?>
                        </div>
                        <div class="price"><?= formatCurrency($p['min_price_per_night'] ?? 0) ?></div>
                    </div>
                </a>
            <?php endforeach; ?>
        </div>
    </div>
</section>
<?php endif; ?>

<!-- ============================================
     CTA — LIST YOUR PROPERTY
     ============================================ -->
<section class="hp-cta-section">
    <div class="hp-container">
        <h2 class="hp-cta-title">Host on Revenda</h2>
        <p class="hp-cta-sub">
            Reach travelers worldwide with a crypto-native booking engine.
            No hidden fees. AI pricing. Smart-room integrations built in.
        </p>
        <div class="hp-cta-buttons">
            <a href="/?page=register" class="hp-btn-primary">
                <i class="fas fa-plus-circle"></i> List your property
            </a>
            <a href="/?page=about" class="hp-btn-secondary">
                <i class="fas fa-info-circle"></i> Learn more
            </a>
        </div>
    </div>
</section>

<!-- ============================================
     AI RECOMMENDATIONS
     ============================================ -->
<?php
if (isLoggedIn() && !$hasActiveFilters):
    $recommended = [];
    try {
        if (function_exists('ai_recommender')) {
            $recommended = ai_recommender((int)$_SESSION['user_id'])->recommendProperties(6);
        } elseif (function_exists('ai')) {
            $recommended = ai()->getRecommendations((int)$_SESSION['user_id'], 6);
        }
    } catch (Throwable $e) {
        error_log('Home recommendations failed: ' . $e->getMessage());
    }
    if (!empty($recommended)):
?>
<section class="hp-section">
    <div class="hp-container">
        <div class="hp-section-head">
            <div class="hp-section-eyebrow">
                <i class="fas fa-wand-magic-sparkles"></i> AI-curated
            </div>
            <h2 class="hp-section-title">Recommended for you</h2>
            <p class="hp-section-sub">
                Based on your past searches, bookings, and travel style.
            </p>
        </div>

        <div class="hp-grid">
            <?php foreach ($recommended as $p):
                $img = !empty($p['image'])
                    ? (strpos($p['image'], 'http') === 0 ? $p['image'] : '/uploads/' . ltrim($p['image'], '/'))
                    : 'https://images.unsplash.com/photo-1566073771259-6a8506099945?w=800&h=600&fit=crop';
            ?>
                <article class="hp-card">
                    <div class="hp-card-img">
                        <a href="/?page=property&slug=<?= urlencode($p['slug'] ?? '') ?>" style="display:block;width:100%;height:100%;">
                            <img src="<?= htmlspecialchars($img) ?>" alt="<?= htmlspecialchars($p['name'] ?? '') ?>" loading="lazy"
                                 onerror="this.src='https://images.unsplash.com/photo-1566073771259-6a8506099945?w=800&h=600&fit=crop';">
                        </a>
                        <div class="hp-card-badges">
                            <span class="hp-badge" style="background: var(--grad-pink);">
                                <i class="fas fa-wand-magic-sparkles"></i> AI Pick
                            </span>
                        </div>
                    </div>
                    <div class="hp-card-body">
                        <a href="/?page=property&slug=<?= urlencode($p['slug'] ?? '') ?>" class="hp-card-name">
                            <?= htmlspecialchars($p['name'] ?? '') ?>
                        </a>
                        <div class="hp-card-loc">
                            <i class="fas fa-map-marker-alt"></i>
                            <?= htmlspecialchars(trim(($p['city_name'] ?? '') . ', ' . ($p['country_name'] ?? ''), ', ')) ?>
                        </div>
                    </div>
                    <div class="hp-card-footer">
                        <div class="hp-price">
                            <?= formatCurrency($p['min_price_per_night'] ?? 0) ?>
                            <small>/ night</small>
                        </div>
                        <a href="/?page=property&slug=<?= urlencode($p['slug'] ?? '') ?>" class="hp-cta">
                            View <i class="fas fa-arrow-right"></i>
                        </a>
                    </div>
                </article>
            <?php endforeach; ?>
        </div>
    </div>
</section>
<?php
    endif;
endif;
?>

</div><!-- /.home-page -->

<!-- ============================================
     SCRIPTS
     ============================================ -->
<script>
document.addEventListener('DOMContentLoaded', function () {
    const today = new Date();
    const tomorrow = new Date(today);
    tomorrow.setDate(tomorrow.getDate() + 1);

    let checkOutPicker;

    flatpickr('.flatpickr[data-type="checkin"]', {
        minDate: today,
        dateFormat: 'Y-m-d',
        defaultDate: '<?= htmlspecialchars($checkIn) ?>',
        onChange: function (selectedDates, dateStr) {
            if (dateStr && checkOutPicker) {
                const minDate = new Date(dateStr);
                minDate.setDate(minDate.getDate() + 1);
                checkOutPicker.set('minDate', minDate);
                const cur = checkOutPicker.selectedDates[0];
                if (!cur || cur <= minDate) {
                    const nd = new Date(minDate);
                    nd.setDate(nd.getDate() + 1);
                    checkOutPicker.setDate(nd);
                }
            }
        }
    });

    checkOutPicker = flatpickr('.flatpickr[data-type="checkout"]', {
        minDate: tomorrow,
        dateFormat: 'Y-m-d',
        defaultDate: '<?= htmlspecialchars($checkOut) ?>'
    });

    document.querySelectorAll('#hpSearchForm select[name="guests"], #hpSearchForm select[name="rooms"]').forEach(function (el) {
        el.addEventListener('change', function () {
            document.getElementById('hpSearchForm').submit();
        });
    });
});

window.toggleWishlist = function (propertyId, button) {
    if (!propertyId) return;
    const icon = button.querySelector('i');

    fetch('/?page=api-wishlist', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'X-Requested-With': 'XMLHttpRequest'
        },
        credentials: 'same-origin',
        body: JSON.stringify({ property_id: propertyId })
    })
    .then(function (r) { return r.json(); })
    .then(function (data) {
        if (data.success) {
            if (data.action === 'added') {
                icon.classList.replace('far', 'fas');
                icon.style.color = '#e53e3e';
                button.style.background = 'rgba(245,87,108,0.85)';
            } else {
                icon.classList.replace('fas', 'far');
                icon.style.color = '';
                button.style.background = '';
            }
        } else if (data.requires_login) {
            window.location.href = '/?page=login';
        }
    })
    .catch(function (err) { console.error('Wishlist error:', err); });
};
</script>

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