/* =====================================================================
   BORGHI ITALIA — style.css
   ===================================================================== */

/* --- Reset & base --- */
*, *::before, *::after { box-sizing: border-box; }

:root {
    --bi-green:    #1D9E75;
    --bi-green-dk: #0F6E56;
    --bi-amber:    #BA7517;
    --bi-blue:     #185FA5;
    --bi-gray:     #5F5E5A;
    --bi-gray-lt:  #F1EFE8;
    --bi-white:    #ffffff;
    --bi-radius:   10px;
    --bi-shadow:   0 2px 12px rgba(0,0,0,.08);
    --bi-font:     'Segoe UI', system-ui, sans-serif;
}

body { font-family: var(--bi-font); color: #2C2C2A; line-height: 1.6; }
a    { color: var(--bi-green); text-decoration: none; }
a:hover { color: var(--bi-green-dk); text-decoration: underline; }
img  { max-width: 100%; height: auto; display: block; }

/* --- Header --- */
.bi-header {
    background: var(--bi-white);
    border-bottom: 1px solid #e5e5e5;
    padding: .75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky; top: 0; z-index: 100;
}
.bi-logo { font-size: 1.3rem; font-weight: 700; color: var(--bi-green); }
.bi-logo span { color: var(--bi-amber); }

.bi-nav ul  { list-style: none; display: flex; gap: 1.5rem; margin: 0; padding: 0; }
.bi-nav a   { font-size: .9rem; color: var(--bi-gray); font-weight: 500; }
.bi-nav a:hover { color: var(--bi-green); text-decoration: none; }

/* --- Search bar globale --- */
.bi-search-wrap {
    max-width: 600px; margin: 0 auto 2rem;
    display: flex; gap: .5rem;
}
.bi-search-wrap input {
    flex: 1; padding: .65rem 1rem;
    border: 1.5px solid #d3d1c7; border-radius: 24px;
    font-size: .95rem;
}
.bi-search-wrap input:focus { outline: none; border-color: var(--bi-green); }
.bi-search-wrap button {
    padding: .65rem 1.4rem; background: var(--bi-green);
    color: #fff; border: none; border-radius: 24px;
    cursor: pointer; font-size: .9rem;
}
.bi-search-wrap button:hover { background: var(--bi-green-dk); }

/* --- Hero borgo --- */
.bi-borgo-hero { position: relative; border-radius: var(--bi-radius); overflow: hidden; margin-bottom: 2rem; }
.bi-borgo-hero img { width: 100%; height: 400px; object-fit: cover; }
.bi-borgo-hero-overlay {
    position: absolute; bottom: 0; left: 0; right: 0;
    background: linear-gradient(transparent, rgba(0,0,0,.65));
    padding: 2rem 1.5rem 1.2rem; color: #fff;
}
.bi-borgo-hero-overlay h1 { font-size: 2rem; margin: 0 0 .4rem; }
.bi-tag-regione, .bi-views-badge {
    display: inline-block; font-size: .8rem;
    padding: .25rem .7rem; border-radius: 20px; margin-right: .5rem;
}
.bi-tag-regione  { background: var(--bi-green); }
.bi-views-badge  { background: rgba(255,255,255,.25); backdrop-filter: blur(4px); }

/* --- Layout 2 colonne borgo --- */
.bi-borgo-body {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 2rem;
    align-items: start;
}
@media (max-width: 768px) {
    .bi-borgo-body { grid-template-columns: 1fr; }
}

/* --- Blocchi contenuto --- */
.bi-block { margin-bottom: 2rem; }
.bi-block h2 {
    font-size: 1.15rem; font-weight: 600;
    border-left: 4px solid var(--bi-green);
    padding-left: .6rem; margin-bottom: .8rem;
}

/* --- Card grid --- */
.bi-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: .75rem;
}
.bi-mini-card {
    border: 1px solid #e5e5e5; border-radius: var(--bi-radius);
    overflow: hidden; color: #2C2C2A;
    transition: transform .2s, box-shadow .2s;
}
.bi-mini-card:hover { transform: translateY(-3px); box-shadow: var(--bi-shadow); }
.bi-mini-card img   { width: 100%; height: 100px; object-fit: cover; }
.bi-mini-card span  { display: block; padding: .5rem .6rem; font-size: .85rem; font-weight: 500; }

/* --- Tags --- */
.bi-tag-list { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.bi-tag-list li a {
    display: inline-block; padding: .3rem .8rem;
    background: #E6F1FB; color: var(--bi-blue);
    border-radius: 20px; font-size: .8rem;
}

/* --- Eventi --- */
.bi-evento-row { display: flex; gap: 1rem; padding: .75rem 0; border-bottom: 1px solid #e5e5e5; }
.bi-evento-date {
    min-width: 80px; font-size: .8rem; font-weight: 600;
    color: var(--bi-amber); text-transform: uppercase;
}

/* --- Sidebar borgo --- */
.bi-borgo-sidebar { position: sticky; top: 80px; }
.bi-btn-primary {
    display: block; text-align: center;
    background: var(--bi-green); color: #fff !important;
    padding: .8rem 1rem; border-radius: var(--bi-radius);
    font-weight: 600; margin-bottom: 1rem;
    transition: background .2s;
}
.bi-btn-primary:hover { background: var(--bi-green-dk); text-decoration: none; }

.bi-info-box {
    border: 1px solid #e5e5e5; border-radius: var(--bi-radius);
    overflow: hidden; margin-bottom: 1rem;
}
.bi-info-row {
    display: flex; justify-content: space-between;
    padding: .6rem .9rem; font-size: .875rem;
    border-bottom: 1px solid #f0f0f0;
}
.bi-info-row:last-child { border-bottom: none; }
.bi-info-row span  { color: var(--bi-gray); }
.bi-info-row strong { color: #2C2C2A; text-align: right; max-width: 60%; }

/* --- Ranking --- */
.bi-ranking { border: 1px solid #e5e5e5; border-radius: var(--bi-radius); overflow: hidden; }
.bi-rank-item {
    display: flex; align-items: center; gap: .75rem;
    padding: .6rem .9rem; border-bottom: 1px solid #f0f0f0;
    font-size: .875rem;
}
.bi-rank-item:last-child { border-bottom: none; }
.bi-rank-num { font-size: 1.1rem; font-weight: 700; min-width: 24px; color: var(--bi-gray); }
.bi-rank-item a { flex: 1; color: #2C2C2A; }
.bi-rank-views { font-size: .75rem; color: var(--bi-gray); }

/* --- Breadcrumb --- */
.bi-breadcrumb { font-size: .85rem; color: var(--bi-gray); margin-bottom: 1rem; }
.bi-breadcrumb a { color: var(--bi-green); }

/* --- Archive borghi --- */
.bi-archive-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1.25rem;
}
.bi-archive-card {
    border: 1px solid #e5e5e5; border-radius: var(--bi-radius);
    overflow: hidden; transition: transform .2s, box-shadow .2s;
}
.bi-archive-card:hover { transform: translateY(-4px); box-shadow: var(--bi-shadow); }
.bi-archive-card img { width: 100%; height: 180px; object-fit: cover; }
.bi-archive-card-body { padding: .9rem 1rem; }
.bi-archive-card-body h3 { font-size: 1rem; margin: 0 0 .3rem; }
.bi-archive-card-body p  { font-size: .85rem; color: var(--bi-gray); margin: 0 0 .5rem; }

/* --- Filtri categoria --- */
.bi-filter-bar { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1.5rem; }
.bi-filter-btn {
    padding: .4rem .9rem; border: 1.5px solid #d3d1c7;
    border-radius: 20px; font-size: .85rem; cursor: pointer;
    background: #fff; color: var(--bi-gray);
    transition: all .2s;
}
.bi-filter-btn.active,
.bi-filter-btn:hover { background: var(--bi-green); color: #fff; border-color: var(--bi-green); }

/* --- Mappa globale --- */
#bi-mappa { border-radius: var(--bi-radius); overflow: hidden; }

/* --- Footer --- */
.bi-footer {
    background: #2C2C2A; color: #B4B2A9;
    padding: 2.5rem 1.5rem 1.5rem;
    margin-top: 4rem;
}
.bi-footer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 2rem; margin-bottom: 2rem;
}
.bi-footer h4 { color: #fff; font-size: .95rem; margin-bottom: .75rem; }
.bi-footer ul { list-style: none; padding: 0; margin: 0; }
.bi-footer ul li { margin-bottom: .4rem; }
.bi-footer a { color: #B4B2A9; font-size: .875rem; }
.bi-footer a:hover { color: var(--bi-green); }
.bi-footer-bottom {
    border-top: 1px solid #444; padding-top: 1rem;
    font-size: .8rem; text-align: center;
}

/* =====================================================================
   main.js (incluso qui come commento per semplicità — salvare in assets/main.js)

   document.addEventListener('DOMContentLoaded', function () {

     // --- Mappa globale Leaflet ---
     var mapEl = document.getElementById('bi-mappa');
     if (mapEl && typeof BI !== 'undefined' && BI.borghi.length) {
       var map = L.map('bi-mappa').setView([41.9, 12.5], 6);
       L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
         { attribution: '© OpenStreetMap' }).addTo(map);
       BI.borghi.forEach(function (b) {
         L.marker([parseFloat(b.lat), parseFloat(b.lng)])
           .addTo(map)
           .bindPopup('<a href="' + b.url + '">' + b.title + '</a>');
       });
     }

     // --- Ricerca AJAX ---
     var searchInput = document.getElementById('bi-search-input');
     var resultsEl   = document.getElementById('bi-search-results');
     if (!searchInput) return;

     var debounce;
     searchInput.addEventListener('input', function () {
       clearTimeout(debounce);
       var q = this.value.trim();
       if (q.length < 2) { resultsEl.innerHTML = ''; return; }
       debounce = setTimeout(function () {
         jQuery.post(BI.ajaxurl, {
           action: 'bi_search',
           nonce:  BI.nonce,
           query:  q
         }, function (res) {
           if (!res.success || !res.data.length) {
             resultsEl.innerHTML = '<p>Nessun risultato.</p>'; return;
           }
           resultsEl.innerHTML = res.data.map(function (item) {
             return '<div class="bi-search-result">'
               + '<a href="' + item.url + '"><strong>' + item.title + '</strong></a>'
               + '<span class="bi-tag">' + item.type + '</span>'
               + '<p>' + item.excerpt + '</p></div>';
           }).join('');
         });
       }, 350);
     });

     // --- Filtro per categoria (archivio) ---
     document.querySelectorAll('.bi-filter-btn').forEach(function (btn) {
       btn.addEventListener('click', function () {
         document.querySelectorAll('.bi-filter-btn').forEach(function (b) {
           b.classList.remove('active');
         });
         this.classList.add('active');
         var cat = this.dataset.cat;
         document.querySelectorAll('.bi-archive-card').forEach(function (card) {
           card.style.display = (cat === 'tutti' || card.dataset.cat === cat) ? '' : 'none';
         });
       });
     });

   });
   ===================================================================== */
