/* Global Styles for Full-Width PWA App */
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100dvh;
    overscroll-behavior: none;
    overflow: hidden;
    background-color: #E1D9D1; /* Colore base per evitare sfarfallii */
}

/* =========================================
   CONTROLLI IN ALTO A DESTRA (WRAPPER UNICO)
   ========================================= */
.top-right-controls {
    position: absolute;
    top: 15px;
    right: 15px;
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 12px;
    z-index: 1001;
    pointer-events: none; /* Lascia passare i tap sulla mappa */
}

.top-right-controls > * {
    pointer-events: auto; /* I singoli bottoni restano interattivi */
}

/* =========================================
   FAB MENU ATTIVITA'
   ========================================= */
.activity-fab-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.activity-fab {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid #7ba05b; /* Uniformato al pulsante ? */
    background-color: #ffffff;
    color: #333333;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
    z-index: 30;
    padding: 0;
}

.activity-fab.main-fab {
    background-color: #ffffff;
    color: #333333;
}

.activity-fab.sub-fab {
    background-color: #8A9A5B;
    color: #ffffff;
    border: 2px solid #ffffff; /* Stacco visivo per i sotto-menu */
}

.activity-fab:hover {
    transform: scale(1.05);
}

.activity-fab-cascade {
    position: absolute;
    top: 50px;
    right: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s ease;
    z-index: 1001;
    pointer-events: auto;
}

.activity-fab-cascade.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.trail-stat-icon {
    width: 18px;
    height: 18px;
    display: inline-block;
    vertical-align: middle;
    margin-right: 6px;
    object-fit: contain;
}

.trail-stats span {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    margin-right: 12px;
}

/* =========================================
   UI ASSISTENTE IA (Floating Widget & Blur)
   ========================================= */

/* 1. Effetto Apple Blur per il contenitore della mappa */
.map-blur-active {
    filter: blur(8px) brightness(0.85);
    transition: filter 0.4s ease, brightness 0.4s ease;
    pointer-events: none; /* Disabilita tap accidentali sulla mappa in background */
}

/* 2. Modulo Chat Overlay Interattivo per IA (Mobile First) */
#ai-chat-widget {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.95);
    width: 90%;
    max-width: 450px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 16px;
    padding: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#ai-chat-widget.is-visible {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}

.ai-chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center; /* keep button centered if needed, or flex-start if it looks better, let's keep center */
    border-bottom: 1px solid rgba(0,0,0,0.1);
    padding-bottom: 12px;
}

.ai-chat-title-wrapper {
    display: flex;
    flex-direction: column;
}

.ai-chat-title {
    font-family: 'Inter', sans-serif;
    font-size: 16px;
    font-weight: 700;
    color: #333;
    margin: 0;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
}

.ai-chat-subtitle {
    margin: 4px 0 0 0;
    font-size: 13px;
    color: #888;
    font-family: 'Inter', sans-serif;
    font-weight: 400;
}

.ai-close-btn {
    background: #f0ede9;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s ease;
}

.ai-close-btn:hover {
    background: #e5dfd9;
    color: #333;
}

/* =========================================
   LIVELLI BASE Z-INDEX (CORE)
   ========================================= */
.sentieri-sidebar,
.side-panel-esercenti,
.info-box-wrapper {
    z-index: 3000 !important;
}

/* =========================================
   LEAFLET POPUP OVERRIDES (DESKTOP)
   ========================================= */
@media (min-width: 1024px) {
    .leaflet-popup {
        max-width: 520px !important;
    }
    .leaflet-popup-content {
        width: 490px !important;
    }
}

/* =========================================
   INFO BOX OVERRIDES (TABLET LAYOUT)
   ========================================= */
@media (min-width: 768px) and (max-width: 1024px) {
    /* Mantiene l'info-box a tutta larghezza (come su mobile) quando la sidebar è contratta */
    .info-box-wrapper {
        right: 20px !important;
        width: auto !important;
        max-width: none !important;
    }
}

/* ============================================================
   POI / PANORAMI / RISTORO PANEL - TABLET PORTRAIT OPTIMIZATION
   Risolve crop estremo immagini ed eccessiva lunghezza riga su tablet verticali
   ============================================================ */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {

    /* 1. Limita la larghezza del pannello e lo ancora a destra come drawer */
    .side-panel-esercenti {
        width: 520px !important;
        max-width: 85vw !important;
        right: -100% !important;
        box-shadow: -8px 0 25px rgba(0, 0, 0, 0.2) !important;
    }

    .side-panel-esercenti.open {
        right: 0 !important;
    }

    /* 2. Header / Hero image: proporzione 16:9 naturale (altezza dinamica ~292px a 520px) */
    .side-panel-esercenti .esercenti-header {
        height: auto !important;
        aspect-ratio: 16 / 9 !important;
    }

    .side-panel-esercenti .esercenti-header-img {
        width: 100% !important;
        height: 100% !important;
        object-fit: cover !important;
    }

    /* 3. Miniature galleria: proporzione classica fotografica 4:3 (evita fessure orizzontali) */
    .side-panel-esercenti .esercenti-gallery img {
        width: 100% !important;
        height: auto !important;
        aspect-ratio: 4 / 3 !important;
        object-fit: cover !important;
    }
}

/* =========================================
   INFO BOX OVERRIDES (DESKTOP LAYOUT)
   ========================================= */
@media (min-width: 1025px) {
    /* 1. Allargamento orizzontale del contenitore principale */
    .info-box-wrapper {
        right: auto !important;
        width: 600px !important;
        max-width: calc(100% - 40px) !important; /* Margine di sicurezza */
    }

    /* Assicurati che il box si ridimensioni dinamicamente e previeni scrollbar */
    .info-box.expanded {
        height: auto !important;
        min-height: min-content !important;
        overflow: hidden !important; /* Rimuove la scrollbar verticale */
    }

    /* 2. Distribuzione interna ottimizzata a due colonne per il contenuto espanso */
    .info-box.expanded .expanded-content {
        display: flex !important;
        flex-direction: row !important;
        align-items: stretch !important;
        gap: 20px !important;
    }

    /* Colonna sinistra: testo descrittivo fluido */
    .info-box.expanded .info-text {
        flex: 1 1 auto !important;
        padding-right: 20px !important;
        border-right: none !important; /* Separatore rimosso */
    }

    /* Colonna destra: Pulsanti allineati in basso */
    .info-box.expanded .action-buttons {
        flex: 0 0 160px !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
        margin-top: auto !important; /* Spinge il blocco in basso se il contenitore è alto */
        justify-content: flex-end !important; /* Allinea gli elementi in basso */
        border-left: none !important; /* Rimuove esplicitamente il separatore sinistro */
    }

    .info-box.expanded .btn-ai-info {
        width: 100% !important;
        height: auto !important; /* Mantiene l'altezza corretta del bottone */
        flex: 0 0 auto !important; /* Impedisce l'allungamento verticale (annulla il flex: 1 nativo) */
    }

    /* Spaziatura orizzontale ottimizzata per le statistiche */
    .info-box .trail-stats {
        justify-content: flex-start !important;
        gap: 25px !important;
    }
}

/* Styling for offline splash title spans */
body.is-offline .splash-title span {
    display: block;
}
body.is-offline .splash-title {
    text-align: center;
}

/* =========================================
   BOTTONE TOGGLE PARTNERS (#btn-luoghi)
   ========================================= */
#btn-luoghi {
    background-color: var(--accent-color, #8A9A5B);
    color: #ffffff;
    border: 2px solid var(--accent-color, #8A9A5B);
    white-space: nowrap;
    opacity: 1;
}

#btn-luoghi:hover {
    background-color: var(--accent-color, #72804b);
    color: #ffffff;
    border-color: var(--accent-color, #72804b);
}

#btn-luoghi.is-outline {
    background-color: var(--surface-color, #F8F5F0);
    color: var(--accent-color, #8A9A5B);
    border: 2px solid var(--accent-color, #8A9A5B);
    white-space: nowrap;
    opacity: 1;
}

#btn-luoghi.is-outline:hover {
    background-color: var(--surface-color, #F8F5F0);
    color: var(--accent-color, #8A9A5B);
    border-color: var(--accent-color, #8A9A5B);
}

/* =========================================
   VISIBILITA' BOTTONI DESKTOP VS MOBILE
   ========================================= */
@media (min-width: 768px) {
    #btn-download-map {
        display: none !important;
    }

    /* Layout a due colonne per desktop (da 768px in su) */
    .info-box.expanded .expanded-content {
        display: flex !important;
        flex-direction: row !important;
        gap: 20px !important;
    }

    .info-box.expanded .info-text {
        flex: 1 !important;
        min-width: 0 !important; /* Previene il blowout con testi lunghi */
    }

    .info-box.expanded .action-buttons {
        min-width: 160px !important;
        flex: 0 0 160px !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
        border-left: none !important; /* Rimuove esplicitamente il separatore sinistro */
    }
}

@media (max-width: 767px) {
    #btn-migliora {
        display: none !important;
    }
}

/* =========================================
   MARKER BUSSOLA OFFLINE
   ========================================= */
.compass-marker-container {
    background: transparent;
    border: none;
}

.compass-arrow-img {
    transition: transform 0.2s ease-out;
    transform-origin: center center;
    will-change: transform;
    display: block;
}

/* ============================================================
   STILI OVERLAY RICERCA IN TEMPO REALE (#search-overlay)
   ============================================================ */

@media (max-width: 480px) {
    .top-right-controls {
        gap: 8px !important;
        right: 10px !important;
    }
}

.search-fab {
    color: #333333;
}

.search-fab i {
    font-size: 16px;
    color: #333333;
}

/* Contenitore Fullscreen dell'Overlay */
.search-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100dvh;
    background-color: #F8F5F0;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1), transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.25s;
}

.search-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    transform: translateY(15px);
    pointer-events: none;
}

/* Header di Ricerca (Input + Tasto Chiudi [X]) */
.search-overlay-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 16px 12px 16px;
    background-color: #E1D9D1;
    border-bottom: 1px solid #C8BFB5;
    flex-shrink: 0;
}

.search-input-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

.search-input-icon {
    position: absolute;
    left: 14px;
    color: #666666;
    font-size: 15px;
    pointer-events: none;
}

#search-overlay-input {
    width: 100%;
    height: 44px;
    padding: 0 40px 0 42px;
    border-radius: 22px;
    border: 1px solid #C8BFB5;
    background-color: #ffffff;
    font-size: 16px;
    color: #333333;
    font-family: inherit;
    outline: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    transition: border-color 0.2s, box-shadow 0.2s;
}

#search-overlay-input:focus {
    border-color: #8A9A5B;
    box-shadow: 0 0 0 3px rgba(138, 154, 91, 0.25);
}

.search-clear-btn {
    position: absolute;
    right: 12px;
    background: transparent;
    border: none;
    color: #888888;
    font-size: 16px;
    cursor: pointer;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.search-clear-btn:hover {
    color: #333333;
}

.search-clear-btn.hidden {
    display: none !important;
}

/* Bottone Chiudi Overlay [X] */
.search-close-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background-color: #ffffff;
    color: #333333;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
    transition: background-color 0.2s, transform 0.2s;
    flex-shrink: 0;
}

.search-close-btn:hover {
    background-color: #f0ebe5;
    transform: scale(1.05);
}

/* Barra Chip Categorie Scorrevole */
.search-chip-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background-color: #F8F5F0;
    border-bottom: 1px solid #E6E1DC;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-shrink: 0;
}

.search-chip-bar::-webkit-scrollbar {
    display: none;
}

.search-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 20px;
    border: 1px solid #C8BFB5;
    background-color: #ffffff;
    color: #333333;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    flex-shrink: 0;
}

.search-chip i {
    color: #8A9A5B;
    transition: color 0.2s;
}

.search-chip.active {
    background-color: #8A9A5B;
    color: #ffffff;
    border-color: #7A8A4B;
}

.search-chip.active i {
    color: #ffffff;
}

/* Area Scorrimento Risultati */
.search-results-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    background-color: #ffffff;
    border-radius: 12px;
    border: 1px solid #E6E1DC;
    box-shadow: 0 2px 5px rgba(0,0,0,0.03);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.search-result-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.08);
    border-color: #8A9A5B;
}

.search-result-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background-color: #F8F5F0;
    border: 1px solid #C8BFB5;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: #8A9A5B;
    flex-shrink: 0;
}

.search-result-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.search-result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.search-result-title {
    font-size: 15px;
    font-weight: 600;
    color: #333333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-result-tag {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 10px;
    background-color: #E1D9D1;
    color: #444444;
    flex-shrink: 0;
}

.search-result-desc {
    font-size: 13px;
    color: #666666;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.4;
}

.search-no-results {
    text-align: center;
    padding: 40px 20px;
    color: #666666;
    font-size: 15px;
}
