<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Hawaii Travel Podcast & Newsletter</title>
    <meta name="description" content="Your friendly guide to planning the perfect Hawaiian island trip. Evergreen travel tips, local picks, and deals across Oahu, Maui, Big Island, and Kauai.">
    <link rel="icon" type="image/png" href="assets/favicon.png">
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Alfa+Slab+One&family=Poppins:wght@400;500;600;700;800&display=swap" rel="stylesheet">
    <style>
        * { margin: 0; padding: 0; box-sizing: border-box; }
        html { scroll-behavior: smooth;  }
        body { background: #FBF2E3; font-family: 'Poppins', sans-serif; color: #1E2A2E; }
        a { color: #F2653D; text-decoration: none; }
        a:hover { color: #D94E2B; }
        ::selection { background: #F2653D; color: #FBF2E3; }

        /* NAV */
        .nav { position: sticky; top: 0; z-index: 50; background: #0B2E3D; box-shadow: 0 2px 12px rgba(0,0,0,0.25); }
        .nav-inner { display: flex; align-items: center; justify-content: space-between; padding: 14px 40px; }
        .nav-brand { display: flex; align-items: center; gap: 12px; margin-right: 24px; }
        .nav-icon { width: 38px; height: 38px; border-radius: 50%; background: #F2653D; display: flex; align-items: center; justify-content: center; font-family: 'Alfa Slab One', serif; color: #0B2E3D; font-size: 15px; flex-shrink: 0; }
        .nav-title { font-family: 'Alfa Slab One', serif; color: #FBF2E3; font-size: 16px; letter-spacing: 0.3px; line-height: 1.2; white-space: nowrap; }
        .nav-title span { color: #E8AD53; font-size: 12px; letter-spacing: 1.5px; }
        .nav-links { display: flex; align-items: center; gap: 22px; }
        .nav-links a { color: #FBF2E3; font-weight: 600; font-size: 14px; white-space: nowrap; }
        .nav-links a:hover { color: #E8AD53; }
        .nav-links .subscribe-btn { background: #F2653D; color: #FBF2E3; padding: 10px 22px; border-radius: 24px; font-weight: 700; font-size: 14px; }
        .nav-links .subscribe-btn:hover { background: #D94E2B; color: #FBF2E3; }
        .nav-hamburger { display: none; background: none; border: 2px solid #E8AD53; color: #E8AD53; width: 40px; height: 40px; border-radius: 8px; font-size: 20px; cursor: pointer; }
        .nav-mobile { display: none; flex-direction: column; gap: 2px; padding: 6px 18px 18px; border-top: 1px solid rgba(255,255,255,0.1); }
        .nav-mobile.open { display: flex; }
        .nav-mobile a { color: #FBF2E3; font-weight: 600; font-size: 15px; padding: 12px 0; }
        .nav-mobile a:hover { color: #E8AD53; }
        .nav-mobile .subscribe-btn { background: #F2653D; color: #FBF2E3; padding: 12px 22px; border-radius: 24px; font-weight: 700; font-size: 15px; text-align: center; margin-top: 8px; }

        /* BANNER */
        .banner-wrap { width: 100%; background: #0B2E3D; }
        .banner-wrap img { width: 100%; height: auto; display: block; }
        .scallop-dark { height: 22px; background: #0B2E3D; background-image: radial-gradient(circle at 11px 22px, #FBF2E3 11px, transparent 11.5px); background-size: 22px 22px; background-position: 0 1px; }
        .scallop-orange { height: 22px; margin-top: 20px; background: #F2653D; background-image: radial-gradient(circle at 11px 22px, #FBF2E3 11px, transparent 11.5px); background-size: 22px 22px; background-position: 0 1px; }

        /* MAIN GRID */
        .main-grid { max-width: 1160px; margin: 0 auto; padding: 44px 40px 10px; display: grid; grid-template-columns: 1fr 320px; gap: 40px; }

        /* STORIES */
        .stories-header { display: flex; align-items: baseline; gap: 14px; margin-bottom: 22px; border-bottom: 3px solid #F2653D; padding-bottom: 12px; }
        .stories-title { font-family: 'Alfa Slab One', serif; font-size: 26px; color: #0B2E3D; }
        .stories-date { font-size: 13px; color: #7A6A55; font-weight: 600; }

        .story-card { padding: 22px 0; border-bottom: 1px solid rgba(11,46,61,0.12); }
        .story-tag { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
        .story-tag-dot { width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0; }
        .story-tag-label { font-size: 11px; font-weight: 700; letter-spacing: 1.5px; text-transform: uppercase; }
        .story-headline { font-family: 'Alfa Slab One', serif; font-size: 19px; color: #0B2E3D; margin-bottom: 8px; line-height: 1.3; }
        .story-body { font-size: 15px; line-height: 1.6; color: #3B3229; }

        /* PARTNER AD BLOCK (in newsletter) */
        .partner-ad-block { margin: 36px 0; background: #12495A; border-radius: 14px; padding: 28px 30px; position: relative; overflow: hidden; }
        .partner-ad-block::after { content: ''; position: absolute; top: -40px; right: -40px; width: 140px; height: 140px; border-radius: 50%; background: rgba(232,173,83,0.15); }
        .partner-ad-badge { display: inline-block; background: #E8AD53; color: #12495A; font-weight: 800; font-size: 11px; letter-spacing: 1.5px; padding: 5px 12px; border-radius: 3px; margin-bottom: 14px; }
        .partner-ad-inner { display: flex; gap: 22px; align-items: center; flex-wrap: wrap; }
        .partner-ad-logo { width: 74px; height: 74px; border-radius: 10px; background: #FBF2E3; display: flex; align-items: center; justify-content: center; font-family: 'Alfa Slab One', serif; color: #12495A; font-size: 22px; flex-shrink: 0; overflow: hidden; }
        .partner-ad-logo img { width: 74px; height: 74px; object-fit: contain; }
        .partner-ad-content { flex: 1; min-width: 220px; }
        .partner-ad-name { font-family: 'Alfa Slab One', serif; color: #FBF2E3; font-size: 19px; margin-bottom: 6px; }
        .partner-ad-desc { color: #D9E7EA; font-size: 14px; line-height: 1.6; }
        .partner-ad-link { background: #F2653D; color: #FBF2E3; padding: 11px 22px; border-radius: 24px; font-weight: 700; font-size: 14px; white-space: nowrap; display: inline-block; }
        .partner-ad-link:hover { background: #D94E2B; color: #FBF2E3; }
        .partner-ad-contact { color: #B9C7CB; font-size: 13px; margin-top: 10px; line-height: 1.6; }

        .read-full-link { text-align: center; margin: 30px 0 10px; }
        .read-full-link a { font-family: 'Alfa Slab One', serif; font-size: 15px; color: #0B2E3D; border: 2px solid #0B2E3D; padding: 12px 26px; border-radius: 24px; display: inline-block; }
        .read-full-link a:hover { background: #0B2E3D; color: #FBF2E3; }

        /* SIDEBAR */
        .sidebar { position: sticky; top: 90px; height: fit-content; }
        .sidebar-box { background: #FFFDF8; border: 2px solid #0B2E3D; border-radius: 14px; padding: 26px; box-shadow: 6px 6px 0 #E8AD53; }
        .sidebar-title { font-family: 'Alfa Slab One', serif; font-size: 19px; color: #0B2E3D; margin-bottom: 8px; }
        .sidebar-desc { font-size: 14px; color: #3B3229; line-height: 1.6; margin-bottom: 18px; }
        .sidebar-box input[type="email"] { width: 100%; box-sizing: border-box; padding: 12px 14px; border-radius: 8px; border: 1.5px solid #C9BBA3; font-size: 14px; font-family: 'Poppins', sans-serif; margin-bottom: 12px; }
        .sidebar-box input[type="email"]:focus { outline: none; border-color: #F2653D; }
        .sidebar-box button { width: 100%; padding: 13px; background: #F2653D; color: #FBF2E3; border: none; border-radius: 8px; font-family: 'Poppins', sans-serif; font-weight: 700; font-size: 15px; cursor: pointer; }
        .sidebar-box button:hover { background: #D94E2B; }
        .sidebar-count { font-size: 12px; color: #7A6A55; margin-top: 10px; text-align: center; }

        /* PODCAST SECTION */
        .podcast-section { background: #F2653D; padding: 50px 40px; }
        .podcast-inner { max-width: 1160px; margin: 0 auto; }
        .podcast-heading { font-family: 'Alfa Slab One', serif; font-size: 26px; color: #FBF2E3; margin-bottom: 26px; }
        .podcast-player { background: #FFFDF8; border-radius: 16px; padding: 26px; display: flex; gap: 26px; flex-wrap: wrap; align-items: center; }
        .podcast-cover { width: 150px; height: 150px; border-radius: 12px; object-fit: cover; flex-shrink: 0; box-shadow: 0 6px 18px rgba(0,0,0,0.2); }
        .podcast-info { flex: 1; min-width: 240px; }
        .podcast-meta { font-size: 12px; font-weight: 700; letter-spacing: 1.5px; color: #7A6A55; text-transform: uppercase; margin-bottom: 6px; }
        .podcast-episode-title { font-family: 'Alfa Slab One', serif; font-size: 20px; color: #0B2E3D; margin-bottom: 14px; }
        .podcast-captivate { width: 100%; border-radius: 12px; overflow: hidden; margin-bottom: 20px; }
        .podcast-open-btn { background: #0B2E3D; color: #FBF2E3; padding: 12px 24px; border-radius: 24px; font-weight: 700; font-size: 14px; white-space: nowrap; display: inline-block; }
        .podcast-open-btn:hover { background: #1a4a5e; color: #FBF2E3; }
        .podcast-episodes { margin-top: 18px; }
        .podcast-ep-row { display: flex; align-items: center; gap: 16px; padding: 12px 18px; background: rgba(255,253,248,0.9); border-radius: 8px; margin-bottom: 8px; }
        .podcast-ep-num { font-family: 'Alfa Slab One', serif; font-size: 14px; color: #F2653D; width: 28px; }
        .podcast-ep-title { flex: 1; font-size: 14px; color: #0B2E3D; font-weight: 600; }
        .podcast-ep-duration { font-size: 12px; color: #7A6A55; }

        /* FEATURED PARTNERS */
        .partners-section { max-width: 1160px; margin: 0 auto; padding: 54px 40px; }
        .partners-heading { font-family: 'Alfa Slab One', serif; font-size: 26px; color: #0B2E3D; margin-bottom: 8px; }
        .partners-subtitle { font-size: 14px; color: #7A6A55; margin-bottom: 26px; }
        .partners-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 22px; }
        .partner-card { background: #FFFDF8; border: 1.5px dashed #C9BBA3; border-radius: 12px; padding: 22px; position: relative; }
        .partner-card:hover { border-color: #E8AD53; }
        .partner-badge { position: absolute; top: 14px; right: 14px; background: #E8AD53; color: #0B2E3D; font-size: 10px; font-weight: 800; letter-spacing: 1px; padding: 3px 9px; border-radius: 3px; }
        .partner-logo { width: 52px; height: 52px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-family: 'Alfa Slab One', serif; color: #FBF2E3; font-size: 18px; margin-bottom: 14px; overflow: hidden; }
        .partner-logo img { width: 52px; height: 52px; object-fit: contain; }
        .partner-name { font-family: 'Alfa Slab One', serif; font-size: 16px; color: #0B2E3D; margin-bottom: 6px; }
        .partner-desc { font-size: 13px; color: #3B3229; line-height: 1.6; margin-bottom: 12px; }
        .partner-link { font-size: 13px; font-weight: 700; }

        /* DIRECTORY */
        .directory-section { background: #0B2E3D; padding: 50px 40px; }
        .directory-inner { max-width: 760px; margin: 0 auto; text-align: center; }
        .directory-heading { font-family: 'Alfa Slab One', serif; font-size: 24px; color: #FBF2E3; margin-bottom: 8px; }
        .directory-subtitle { font-size: 14px; color: #B9C7CB; margin-bottom: 22px; }
        .directory-search { display: flex; flex-wrap: wrap; background: #FFFDF8; border-radius: 24px; padding: 10px 10px 10px 20px; align-items: center; gap: 10px; }
        .directory-search input { flex: 1; border: none; outline: none; font-size: 14px; font-family: 'Poppins', sans-serif; padding: 10px 0; background: transparent; min-width: 200px; }
        .directory-search button { background: #F2653D; color: #FBF2E3; border: none; padding: 12px 24px; border-radius: 24px; font-weight: 700; font-size: 14px; cursor: pointer; }
        .directory-search button:hover { background: #D94E2B; }
        .directory-results { max-width: 760px; margin: 0 auto; padding: 0 40px; }
        .directory-results-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; margin-top: 24px; padding-bottom: 30px; }
        .directory-card { background: rgba(255,253,248,0.08); border: 1px solid rgba(255,255,255,0.1); border-radius: 10px; padding: 18px 20px; text-align: left; }
        .directory-card h3 { font-family: 'Alfa Slab One', serif; font-size: 15px; color: #FBF2E3; margin-bottom: 4px; }
        .directory-card .dir-category { font-size: 12px; color: #E8AD53; font-weight: 600; margin-bottom: 6px; }
        .directory-card .dir-island { font-size: 11px; color: #B9C7CB; margin-bottom: 6px; }
        .directory-card .dir-details { font-size: 12px; color: #B9C7CB; line-height: 1.6; }

        /* FOOTER */
        .footer { background: #0B2E3D; border-top: 1px solid rgba(255,255,255,0.1); padding: 26px 40px; text-align: center; }
        .footer-tagline { font-size: 13px; color: #B9C7CB; }
        .footer-legal { font-size: 12px; color: #7A8B90; margin-top: 10px; }
        .footer-legal a { color: #E8AD53; }
        .footer-legal a:hover { color: #F2653D; }

        /* RESPONSIVE */
        @media (max-width: 760px) {
            .nav-inner { padding: 12px 18px; }
            .nav-links { display: none; }
            .nav-hamburger { display: flex; align-items: center; justify-content: center; }
            .main-grid { grid-template-columns: 1fr; padding: 32px 18px 10px; }
            .podcast-section { padding: 20px 18px 40px; }
            .partners-section { padding: 36px 18px; }
            .directory-section { padding: 20px 18px 40px; }
            .directory-results { padding: 0 18px; }
            .footer { padding: 26px 18px; }
            .partner-ad-inner { flex-direction: column; align-items: flex-start; }
        }
    </style>
</head>
<body>

    <!-- NAV -->
    <nav class="nav">
        <div class="nav-inner">
            <div class="nav-brand">
                <div class="nav-icon">HI</div>
                <div class="nav-title">HAWAII TRAVEL PODCAST<br><span>&amp; NEWSLETTER</span></div>
            </div>
            <div class="nav-links">
                <a href="#stories">Home</a>
                <a href="#stories">Newsletter</a>
                <a href="#podcast">Podcast</a>
                <a href="#partners">Partners</a>
                <a href="#directory">Directory</a>
                <a href="archive.html">Archive</a>
                <a href="#signup" class="subscribe-btn">Subscribe Free</a>
            </div>
            <button class="nav-hamburger" onclick="toggleMenu()" aria-label="Menu">&#9776;</button>
        </div>
        <div class="nav-mobile" id="mobile-menu">
            <a href="#stories" onclick="toggleMenu()">Home</a>
            <a href="#stories" onclick="toggleMenu()">Newsletter</a>
            <a href="#podcast" onclick="toggleMenu()">Podcast</a>
            <a href="#partners" onclick="toggleMenu()">Partners</a>
            <a href="#directory" onclick="toggleMenu()">Directory</a>
            <a href="archive.html" onclick="toggleMenu()">Archive</a>
            <a href="#signup" onclick="toggleMenu()" class="subscribe-btn">Subscribe Free</a>
        </div>
    </nav>

    <!-- BANNER -->
    <div class="banner-wrap">
        <img src="assets/banner-final.jpg" alt="Hawaii Travel Podcast & Newsletter, established 2012">
    </div>
    <div class="scallop-dark"></div>

    <!-- MAIN CONTENT -->
    <div class="main-grid" id="stories">
        <!-- STORIES COLUMN -->
        <div>
            <div class="stories-header">
                <div class="stories-title">This Week in the Islands</div>
                <div class="stories-date" id="newsletter-date">July 24, 2026</div>
            </div>
            <div id="newsletter-stories"></div>

        </div>

        <!-- SIDEBAR -->
        <aside class="sidebar" id="signup">
            <div class="sidebar-box">
                <div class="sidebar-title">Join the 'Ohana</div>
                <div class="sidebar-desc">Island tips, deal alerts, and the new episode &mdash; straight to your inbox.</div>
                <input type="email" id="signup-email" placeholder="you@example.com">
                <input type="text" id="signup-website" name="website" tabindex="-1" autocomplete="off" aria-hidden="true" style="position:absolute; left:-9999px; width:1px; height:1px; opacity:0;">
                <button onclick="handleSubscribe()">Subscribe Free</button>
                <div class="sidebar-count">Join 2,400+ future island-goers</div>
                <div id="signup-message" style="display:none; margin-top:10px; padding:12px; border-radius:8px; text-align:center; font-weight:600; font-size:14px;"></div>
            </div>
        </aside>
    </div>

    <!-- SCALLOP DIVIDER -->
    <div class="scallop-orange"></div>

    <!-- PODCAST -->
    
    <!-- FEATURED PARTNERS -->
    <section class="partners-section" id="partners">
        <div class="partners-heading">Featured Businesses</div>
        <div class="partners-subtitle">Handpicked spots across the islands</div>
        <div class="partners-grid" id="partners-grid"></div>
    </section>

    <!-- DIRECTORY -->
    <section class="directory-section" id="directory">
        <div class="directory-inner">
            <div class="directory-heading">Find Something Fun</div>
            <div class="directory-subtitle">Search restaurants, tours, stays, and shops across the islands — plus past newsletter stories.</div>
            <div class="directory-search">
                <input type="text" id="directory-search-input" placeholder="Try 'snorkel', 'Kauai', 'rental car', 'poke'..." onkeyup="if(event.key==='Enter')handleUnifiedSearch()">
                <button onclick="handleUnifiedSearch()">Search</button>
            </div>
        </div>
        <div class="directory-results" id="directory-results"></div>
    </section>

    <!-- FOOTER -->
    <footer class="footer">
        <div class="footer-tagline">Hawaii Travel Podcast &amp; Newsletter is your friendly guide to planning the perfect island trip. Mahalo for reading.</div>
        <div class="footer-legal">&copy; 2026 Hawaii Travel Podcast / JENDANCO LLC &nbsp;|&nbsp; <a href="privacy.html">Privacy</a> &nbsp;|&nbsp; <a href="terms.html">Terms</a></div>
    </footer>

    <!-- DATA FILES -->
    <script src="businesses-1786301268.js"></script>
    <script>try { fetch('check-schedule.php').catch(function(){}); } catch(e) {}</script>
    <script src="newsletter-content-1786296091.js"></script>

    <script>
        // ============================================
        // ISLAND COLORS
        // ============================================
        const islandColors = {
            'Kauai': '#1E7A82',
            'Maui': '#F2653D',
            'Big Island': '#8A4B2E',
            'Oahu': '#E8AD53',
            'All Islands': '#12495A',
            'Reader Q&A': '#7A6A55',
            'General': '#12495A'
        };

        function getIslandColor(island) {
            return islandColors[island] || '#12495A';
        }

        // ============================================
        // MOBILE MENU
        // ============================================
        function toggleMenu() {
            document.getElementById('mobile-menu').classList.toggle('open');
        }

        // ============================================
        // LOAD BUSINESSES
        // ============================================
        function loadBusinesses() {
            return typeof businesses !== 'undefined' ? businesses : [];
        }

        // ============================================
        // NEWSLETTER CONTENT
        // ============================================
        function loadNewsletterContent() {
            if (typeof newsletterContent === 'undefined') return;

            const dateEl = document.getElementById('newsletter-date');
            if (newsletterContent.date) dateEl.textContent = newsletterContent.date;

            const container = document.getElementById('newsletter-stories');
            container.innerHTML = '';

            if (newsletterContent.items && newsletterContent.items.length > 0) {
                newsletterContent.items.forEach(function(item) {
                    if (item.type === 'editorial') {
                        var color = getIslandColor(item.island || 'General');
                        var html = '<div class="story-card">' +
                            '<div class="story-tag">' +
                                '<div class="story-tag-dot" style="background:' + color + ';"></div>' +
                                '<div class="story-tag-label" style="color:' + color + ';">' + (item.island || 'General') + '</div>' +
                            '</div>' +
                            '<div class="story-headline">' + item.title + '</div>' +
                            '<div class="story-body">' + item.description + '</div>' +
                        '</div>';
                        container.insertAdjacentHTML('beforeend', html);
                    } else if (item.type === 'partner') {
                        var logoClass = item.logo ? '' : '';
                        var logoContent = item.logo ? '<img src="' + item.logo + '" alt="' + item.name + '">' : (item.name ? item.name.split(' ').map(function(w){return w[0];}).join('').substring(0,2).toUpperCase() : '');
                        var html = '<div class="partner-ad-block">' +
                            '<div class="partner-ad-badge">FEATURED PARTNER</div>' +
                            '<div class="partner-ad-inner">' +
                                '<div class="partner-ad-logo">' + logoContent + '</div>' +
                                '<div class="partner-ad-content">' +
                                    '<div class="partner-ad-name">' + item.name + '</div>' +
                                    '<div class="partner-ad-desc">' + item.description + '</div>' +
                                    (item.phone || item.address ? '<div class="partner-ad-contact">' + (item.address ? '📍 ' + item.address + '<br>' : '') + (item.phone ? '📞 ' + item.phone : '') + '</div>' : '') +
                                '</div>' +
                                (item.website ? '<a href="' + item.website + '" target="_blank" class="partner-ad-link">Visit Website</a>' : '') +
                            '</div>' +
                        '</div>';
                        container.insertAdjacentHTML('beforeend', html);
                    }
                });
            }
        }

        // ============================================
        // FEATURED PARTNERS GRID
        // ============================================
        function displayFeaturedPartners() {
            var allBusinesses = loadBusinesses();
            var sponsors = allBusinesses.filter(function(b) {
                return (b.tier === 'Partner' || b.tier === 'Premier' || b.tier === 'Featured') && b.active !== false;
            });

            var grid = document.getElementById('partners-grid');
            grid.innerHTML = '';

            sponsors.forEach(function(business) {
                var color = getIslandColor(business.island || 'General');
                var logoContent = business.logo ?
                    '<img src="' + business.logo + '" alt="' + business.name + '">' :
                    business.name.split(' ').map(function(w){return w[0];}).join('').substring(0,2).toUpperCase();

                var card = document.createElement('div');
                card.className = 'partner-card';
                card.innerHTML =
                    '<div class="partner-badge">PARTNER</div>' +
                    '<div class="partner-logo" style="background:' + color + ';">' + logoContent + '</div>' +
                    '<div class="partner-name">' + business.name + '</div>' +
                    '<div class="partner-desc">' + (business.tagline || business.category || '') + '</div>' +
                    (business.island ? '<div style="font-size:11px; color:#7A6A55; margin-bottom:8px;">📍 ' + business.island + '</div>' : '') +
                    (business.website ? '<a href="' + business.website + '" target="_blank" class="partner-link">Visit Website &rarr;</a>' : '');
                grid.appendChild(card);
            });

            if (sponsors.length === 0) {
                grid.innerHTML = '<div style="text-align:center; padding:40px; color:#7A6A55;">Partner spots coming soon.</div>';
            }
        }

        // ============================================
        // UNIFIED SEARCH (businesses + newsletter archive)
        // ============================================
        function handleUnifiedSearch() {
            var query = document.getElementById('directory-search-input').value.toLowerCase().trim();
            var allBusinesses = loadBusinesses();
            var resultsDiv = document.getElementById('directory-results');

            if (!query) {
                resultsDiv.innerHTML = '';
                return;
            }

            // Search businesses
            var bizResults = allBusinesses.filter(function(b) {
                return b.name.toLowerCase().includes(query) ||
                    (b.category && b.category.toLowerCase().includes(query)) ||
                    (b.island && b.island.toLowerCase().includes(query)) ||
                    (b.description && b.description.toLowerCase().includes(query));
            });

            bizResults.sort(function(a, b) {
                var tierOrder = { 'Partner': 0, 'Premier': 0, 'Featured': 1, 'Basic': 2 };
                return (tierOrder[a.tier] || 99) - (tierOrder[b.tier] || 99);
            });

            var bizHTML = '';
            if (bizResults.length > 0) {
                bizHTML = '<div style="margin-bottom:8px;"><span style="font-family:\'Alfa Slab One\', serif; font-size:16px; color:#FBF2E3;">Businesses</span> <span style="font-size:12px; color:#B9C7CB;">(' + bizResults.length + ' found)</span></div>';
                bizHTML += '<div class="directory-results-grid">';
                bizResults.forEach(function(b) {
                    var isPartner = b.tier === 'Partner' || b.tier === 'Premier';
                    bizHTML += '<div class="directory-card"' + (isPartner ? ' style="border-color:#E8AD53; background:rgba(232,173,83,0.1);"' : '') + '>' +
                        (isPartner ? '<div style="font-size:10px; font-weight:800; color:#E8AD53; letter-spacing:1px; margin-bottom:6px;">PARTNER</div>' : '') +
                        '<h3>' + b.name + '</h3>' +
                        '<div class="dir-category">' + (b.category || '') + '</div>' +
                        (b.island ? '<div class="dir-island">📍 ' + b.island + '</div>' : '') +
                        '<div class="dir-details">' +
                            (b.address ? b.address + '<br>' : '') +
                            (b.phone ? b.phone : '') +
                        '</div>' +
                        (b.website && isPartner ? '<div style="margin-top:8px;"><a href="' + b.website + '" target="_blank" style="color:#F2653D; font-size:12px; font-weight:700;">Visit Website &rarr;</a></div>' : '') +
                    '</div>';
                });
                bizHTML += '</div>';
            }

            // Search newsletter archive
            fetch('load-archive.php?search=' + encodeURIComponent(query))
                .then(function(r) { return r.json(); })
                .then(function(result) {
                    var archiveHTML = '';
                    if (result.success && result.archives && result.archives.length > 0) {
                        archiveHTML = '<div style="margin-top:28px; margin-bottom:8px;"><span style="font-family:\'Alfa Slab One\', serif; font-size:16px; color:#FBF2E3;">Past Newsletters</span> <span style="font-size:12px; color:#B9C7CB;">(' + result.archives.length + ' found)</span></div>';
                        archiveHTML += '<div class="directory-results-grid">';
                        result.archives.forEach(function(a) {
                            var headlines = a.headlines.slice(0, 3).map(function(h) { return '• ' + h; }).join('<br>');
                            archiveHTML += '<div class="directory-card" style="cursor:pointer;" onclick="window.location.href=\'archive.html?date=' + a.fileDate + '\'">' +
                                '<div style="font-size:10px; font-weight:800; color:#E8AD53; letter-spacing:1px; margin-bottom:6px;">NEWSLETTER</div>' +
                                '<h3>' + a.displayDate + '</h3>' +
                                '<div class="dir-category">' + a.storyCount + ' stories</div>' +
                                '<div class="dir-details" style="margin-top:6px;">' + headlines + '</div>' +
                            '</div>';
                        });
                        archiveHTML += '</div>';
                    }

                    if (bizResults.length === 0 && (!result.archives || result.archives.length === 0)) {
                        resultsDiv.innerHTML = '<div style="text-align:center; padding:30px; color:#B9C7CB;">No results for "' + query + '"</div>';
                    } else {
                        resultsDiv.innerHTML = bizHTML + archiveHTML;
                    }
                })
                .catch(function() {
                    // If archive fetch fails, still show business results
                    if (bizResults.length === 0) {
                        resultsDiv.innerHTML = '<div style="text-align:center; padding:30px; color:#B9C7CB;">No results for "' + query + '"</div>';
                    } else {
                        resultsDiv.innerHTML = bizHTML;
                    }
                });
        }

        // ============================================
        // SUBSCRIBE
        // ============================================
        function handleSubscribe() {
            var email = document.getElementById('signup-email').value.trim();
            var msgEl = document.getElementById('signup-message');

            if (!email || !email.includes('@')) {
                msgEl.style.display = 'block';
                msgEl.style.background = '#fee2e2';
                msgEl.style.color = '#991b1b';
                msgEl.textContent = 'Please enter a valid email address.';
                return;
            }

            // Send to subscribe.php (which fires GHL webhook)
            fetch('subscribe.php', {
                method: 'POST',
                headers: { 'Content-Type': 'application/json' },
                body: JSON.stringify({
                    email: email,
                    website: document.getElementById('signup-website').value
                })
            }).then(function(r) {
                return r.json();
            }).then(function(res) {
                msgEl.style.display = 'block';
                if (res && res.ok) {
                    msgEl.style.background = '#d1fae5';
                    msgEl.style.color = '#065f46';
                    msgEl.textContent = 'You\'re in. Your first tips are on the way.';
                    document.getElementById('signup-email').value = '';
                } else {
                    msgEl.style.background = '#fee2e2';
                    msgEl.style.color = '#991b1b';
                    msgEl.textContent = (res && res.error) ? res.error : 'Something went wrong. Please try again.';
                }
            }).catch(function() {
                msgEl.style.display = 'block';
                msgEl.style.background = '#fee2e2';
                msgEl.style.color = '#991b1b';
                msgEl.textContent = 'Connection error. Please try again.';
            });
        }

        // ============================================
        // INITIALIZE
        // ============================================
        document.addEventListener('DOMContentLoaded', function() {
            loadNewsletterContent();
            displayFeaturedPartners();
        });
    </script>
</body>
</html>
