/* ============================================================
   Verde Abitare: v5 mobile-first layer  (VA_V4 5.0.0)
   Reference: rich mainstream portal UX (immobiliare.it class).
   Loads after v4.css. Brand tokens only: no hardcoded colors.
   Sections:
   1. Form UX: placeholders, reserved-space inline errors
   2. Filters bottom sheet (mobile, html.js-v5 only)
   3. Map view mobile: fullscreen + floating list/map toggle
   4. Bottom nav polish + safe areas
   5. Sticky CTA bar on property detail (mobile)
   6. Promo popup (timed / exit-intent)
   7. Mobile polish: toolbar, chips, gallery snap
   ============================================================ */

/* ------------------------------------------------------------
   1. FORM UX: every field has a reserved error slot so the
   layout NEVER shifts during validation.
   ------------------------------------------------------------ */
::placeholder { color: var(--va-warm-light); opacity: 1; }

.va-field-l { position: relative; display: block; }

.va-field-l input,
.va-field-l textarea,
.va-field-l select {
    width: 100%;
    transition: border-color .15s ease, box-shadow .15s ease;
}

/* Reserved slot: always occupies its line, visible only on error */
.va-field-l__err,
.va-consent__err {
    display: block;
    min-height: 18px;              /* space reserved even when empty */
    margin-top: 3px;
    font-size: .6875rem;
    line-height: 1.35;
    color: var(--va-red);
    visibility: hidden;
}
.va-field-l.is-error .va-field-l__err,
.va-consent.is-error + .va-consent__err,
.va-consent.is-error .va-consent__err { visibility: visible; }

.va-field-l.is-error input,
.va-field-l.is-error textarea,
.va-field-l.is-error select {
    border-color: var(--va-red);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--va-red) 14%, transparent);
}
.va-field-l.is-ok input,
.va-field-l.is-ok textarea {
    border-color: var(--va-green);
}
.va-consent.is-error .va-check__box,
.va-consent.is-error input[type="checkbox"] { outline: 2px solid var(--va-red); outline-offset: 2px; border-radius: 3px; }

/* Form-level message: reserved height, no jump */
.va-cform__msg {
    min-height: 20px;
    margin: 6px 0 0;
    font-size: .75rem;
}
.va-cform__msg.is-error { color: var(--va-red); }
.va-cform__msg.is-ok    { color: var(--va-green); }

.va-cform button[type="submit"].is-busy { opacity: .6; pointer-events: none; }

/* ------------------------------------------------------------
   2. FILTERS BOTTOM SHEET: mobile only, JS-gated (html.js-v5)
   Without JS the v4 inline filters keep working untouched.
   ------------------------------------------------------------ */
.va-filters-trigger { display: none; }
.va-sheet__handle,
.va-sheet__head,
.va-sheet__foot,
.va-sheet__backdrop { display: none; }

@media (max-width: 768px) {

    html.js-v5 .va-filters-trigger {
        display: inline-flex;
        align-items: center;
        gap: 7px;
        width: 100%;
        justify-content: center;
        padding: 12px 16px;
        margin-bottom: 12px;
        border: 1px solid var(--va-border);
        border-radius: var(--va-r, 10px);
        background: var(--va-white);
        color: var(--va-dark);
        font-size: .8125rem;
        font-weight: 600;
        box-shadow: var(--va-shadow);
        cursor: pointer;
    }
    html.js-v5 .va-filters-trigger__count {
        min-width: 20px; height: 20px;
        display: inline-flex; align-items: center; justify-content: center;
        border-radius: 999px;
        background: var(--va-sage);
        color: #FDFBF7;
        font-size: .6875rem;
        padding: 0 6px;
    }
    html.js-v5 .va-filters-trigger__count[hidden] { display: none; }

    /* The existing form becomes the sheet */
    html.js-v5 .va-filters {
        position: fixed;
        left: 0; right: 0; bottom: 0;
        z-index: 1200;
        margin: 0;
        max-height: 88dvh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        background: var(--va-cream);
        border-radius: 18px 18px 0 0;
        box-shadow: var(--va-shadow-lg);
        padding: 10px 16px calc(84px + env(safe-area-inset-bottom));
        transform: translateY(105%);
        transition: transform .28s cubic-bezier(.32,.72,.24,1);
        visibility: hidden;
    }
    html.js-v5 .va-filters.is-open { transform: translateY(0); visibility: visible; }

    /* Drag handle + sheet header (injected by JS) */
    html.js-v5 .va-sheet__handle {
        display: block;
        width: 40px; height: 4px;
        border-radius: 999px;
        background: var(--va-border);
        margin: 4px auto 10px;
    }
    html.js-v5 .va-sheet__head {
        display: flex; align-items: center; justify-content: space-between;
        margin-bottom: 10px;
    }
    html.js-v5 .va-sheet__title {
        font-family: var(--va-font-body);
        font-weight: 600;
        font-size: 1.0625rem;
        color: var(--va-dark);
    }
    html.js-v5 .va-sheet__close {
        border: none; background: var(--va-stone-light);
        width: 32px; height: 32px; border-radius: 50%;
        display: flex; align-items: center; justify-content: center;
        color: var(--va-warm); cursor: pointer;
        font-size: 1rem; line-height: 1;
    }

    /* Filters: griglia compatta 2x2 dentro il foglio (Tipologia+Zona, Prezzo+Dimensioni. Solo Contratto, REF e apply restano larghezza piena) */
    html.js-v5 .va-filters__row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        align-items: stretch;
        gap: 10px;
    }
    html.js-v5 .va-filters__row > .va-seg,
    html.js-v5 .va-filters__row > .va-filters__ref,
    html.js-v5 .va-filters__row > .va-filters__apply {
        grid-column: 1 / -1;
    }
    /* v7.52: pannello tendina in overlay (absolute) invece che nel flusso.
       Prima era position:static ma conservava min-width:260px da v4.css: la colonna
       della griglia si allargava e spingeva tutto il layout fuori schermo. */
    /* v7.57: pannello ancorato alla RIGA filtri: larghezza piena da bordo a bordo
       e scroll interno, cosi la lista opzioni non resta tagliata dal foglio filtri. */
    html.js-v5 .va-filters__row { position: relative; }
    html.js-v5 .va-filters .va-pop { position: static; }
    html.js-v5 .va-filters .va-pop__panel {
        position: absolute;
        top: calc(100% + 8px);
        left: 0;
        right: 0;
        width: auto;
        min-width: 0;
        max-width: none;
        max-height: 50vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        box-shadow: var(--va-shadow-lg);
        border: 1px solid var(--va-border);
        z-index: 60;
    }
    html.js-v5 .va-filters .va-pop__toggle { width: 100%; justify-content: space-between; }
    html.js-v5 .va-filters__ref { width: 100%; }
    html.js-v5 .va-filters__ref input { width: 100%; min-height: 46px; }
    html.js-v5 .va-filters__apply { width: 100%; justify-content: center; }

    /* Sticky sheet footer: apply + reset */
    html.js-v5 .va-sheet__foot {
        position: fixed;
        left: 0; right: 0; bottom: 0;
        z-index: 1201;
        display: none;
        gap: 10px;
        align-items: center;
        padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
        background: var(--va-white);
        border-top: 1px solid var(--va-border);
    }
    html.js-v5 .va-filters.is-open ~ .va-sheet__foot,
    html.js-v5 .va-sheet__foot.is-open { display: flex; }
    html.js-v5 .va-sheet__reset {
        border: none; background: none;
        color: var(--va-warm);
        font-size: .8125rem;
        text-decoration: underline;
        cursor: pointer;
        white-space: nowrap;
    }
    html.js-v5 .va-sheet__apply { flex: 1; padding: 13px; font-size: .875rem; }

    /* Backdrop */
    html.js-v5 .va-sheet__backdrop {
        display: block;
        position: fixed; inset: 0;
        z-index: 1199;
        background: rgba(20,22,15,0.45);
        opacity: 0;
        pointer-events: none;
        transition: opacity .25s ease;
    }
    html.js-v5 .va-sheet__backdrop.is-open { opacity: 1; pointer-events: auto; }

    html.js-v5 body.va-sheet-lock { overflow: hidden; }
}

/* ------------------------------------------------------------
   3. MAP VIEW: mobile fullscreen + floating toggle pill
   ------------------------------------------------------------ */
@media (max-width: 768px) {
    .va-mapswitch {
        position: fixed;
        left: 50%;
        bottom: calc(68px + env(safe-area-inset-bottom));
        transform: translateX(-50%);
        z-index: 1100;
        display: none;
        align-items: center;
        gap: 6px;
        padding: 10px 18px;
        border: none;
        border-radius: 999px;
        background: var(--va-ink);
        color: #FDFBF7;
        font-size: .8125rem;
        font-weight: 600;
        box-shadow: var(--va-shadow-lg);
        cursor: pointer;
    }
    body.post-type-archive-immobile .va-mapswitch { display: inline-flex; }

    .va-search__stage[data-view="map"] .va-search__map {
        position: fixed;
        top: 0; left: 0; right: 0;
        bottom: var(--va-bnh, calc(64px + env(safe-area-inset-bottom)));
        height: auto;
        z-index: 1050;
        border-radius: 0;
    }
    .va-search__stage[data-view="map"] #va-results { display: none; }
}

/* ------------------------------------------------------------
   4. BOTTOM NAV: safe areas, touch targets, active state
   ------------------------------------------------------------ */
@media (max-width: 768px) {
    .va-bottomnav {
        padding-bottom: env(safe-area-inset-bottom);
        backdrop-filter: blur(8px);
    }
    .va-bottomnav__item {
        min-height: 48px;
        justify-content: center;
        gap: 2px;
    }
    .va-bottomnav__item.is-active {
        color: var(--va-sage);
        font-weight: 600;
    }
    .va-bottomnav__item.is-active svg { stroke-width: 2.4; }

    body { /* padding-bottom removed */ }
}

/* ------------------------------------------------------------
   5. STICKY CTA BAR: property detail, mobile only
   ------------------------------------------------------------ */
.va-ctabar { display: none; }

@media (max-width: 768px) {
    body.single-immobile .va-ctabar {
        position: fixed;
        left: 0; right: 0;
        bottom: var(--va-bnh, calc(64px + env(safe-area-inset-bottom)));
        z-index: 1090;
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 10px 14px;
        background: var(--va-white);
        border-top: 1px solid var(--va-border);
        box-shadow: 0 -4px 16px rgba(20,22,15,0.08);
    }
    .va-ctabar__price {
        font-family: var(--va-font-body);
        font-weight: 600;
        font-size: .9rem;
        color: var(--va-dark);
        margin-right: auto;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        min-width: 0;
    }
    .va-ctabar__btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        min-height: 42px;
        padding: 0 14px;
        border-radius: var(--va-r, 10px);
        font-size: .8125rem;
        font-weight: 600;
        text-decoration: none;
        border: 1px solid var(--va-sage);
        color: var(--va-sage);
        background: var(--va-white);
    }
    .va-ctabar__btn--primary { background: var(--va-sage); color: #FDFBF7; }
    .va-ctabar__btn { -webkit-tap-highlight-color: transparent; }
    .va-ctabar__btn:visited, .va-ctabar__btn:active, .va-ctabar__btn:focus { color: var(--va-sage); }
    .va-ctabar__btn--primary:visited, .va-ctabar__btn--primary:active, .va-ctabar__btn--primary:focus { color: #FDFBF7; }

    /* keep content clear of the bar */
    body.single-immobile .va-main { padding-bottom: 70px; }
}

/* ------------------------------------------------------------
   6. PROMO POPUP: desktop modal / mobile bottom card
   ------------------------------------------------------------ */
.va-promo {
    position: fixed;
    inset: 0;
    z-index: 1300;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.va-promo.is-open { display: flex; }
.va-promo__backdrop {
    position: absolute; inset: 0;
    background: rgba(20,22,15,0.55);
}
.va-promo__card {
    position: relative;
    width: 100%;
    max-width: 420px;
    background: var(--va-cream);
    border-radius: var(--va-r, 10px);
    overflow: hidden;
    box-shadow: var(--va-shadow-lg);
    animation: va-promo-in .3s cubic-bezier(.32,.72,.24,1);
}
@keyframes va-promo-in { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }

.va-promo__media { position: relative; aspect-ratio: 16/9; background: var(--va-stone-light); }
.va-promo__media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.va-promo__kicker {
    position: absolute;
    left: 12px; bottom: 12px;
    background: var(--va-gold);
    color: #FDFBF7;
    font-size: .625rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    padding: 4px 9px;
    border-radius: 4px;
}
.va-promo__body { padding: 18px 20px 20px; }
.va-promo__title {
    font-family: var(--va-font-body);
    font-weight: 600;
    font-size: 1.375rem;
    line-height: 1.15;
    color: var(--va-dark);
    margin: 0 0 6px;
}
.va-promo__text { font-size: .8125rem; color: var(--va-warm); margin: 0 0 14px; }
.va-promo__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.va-promo__close {
    position: absolute;
    top: 10px; right: 10px;
    width: 32px; height: 32px;
    border: none; border-radius: 50%;
    background: rgba(20,22,15,0.55);
    color: #FDFBF7;
    font-size: 1rem; line-height: 1;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}

@media (max-width: 560px) {
    .va-promo { align-items: flex-end; padding: 0; }
    .va-promo__card {
        max-width: none;
        border-radius: 18px 18px 0 0;
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ------------------------------------------------------------
   7. MOBILE POLISH: toolbar, chips, gallery, tap targets
   ------------------------------------------------------------ */
@media (max-width: 768px) {
    /* v7.9.258: niente piu scroll orizzontale - due righe pulite */
    .va-search__toolbar {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
        row-gap: 10px;
    }
    .va-search__left { width: 100%; order: 1; display: flex; align-items: center; gap: 10px; flex-wrap: nowrap; }
    .va-search__count { flex-shrink: 0; white-space: nowrap; }
    .va-search__left .va-pop--sort { min-width: 0; flex-shrink: 1; }
    .va-search__left .va-pop__toggle { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .va-search__views { order: 2; margin-left: 0; }
    #va-save-search { order: 3; margin-left: auto; white-space: nowrap; }

    .va-filters__active {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        gap: 6px;
        scrollbar-width: none;
    }
    .va-filters__active::-webkit-scrollbar { display: none; }

    /* Detail gallery: swipe with snap */
    .va-gallery__thumbs { scroll-snap-type: x mandatory; }
    .va-gallery__thumb-btn { scroll-snap-align: start; }

    .va-btn, .va-pop__toggle, .va-view, .va-seg__btn { min-height: 42px; }
}

/* Accessibility floor */
:focus-visible { outline: 2px solid var(--va-sage); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
    .va-filters, .va-promo__card, .va-sheet__backdrop { transition: none !important; animation: none !important; }
}
/* v7.9.258: vista Lista mobile - card orizzontale con thumb stretta 110px, niente piu bug spazio */
@media (max-width: 640px) {
    .va-search__stage[data-view="list"] .va-pcard { display: grid; grid-template-columns: 152px 1fr; align-items: stretch; }
    .va-search__stage[data-view="list"] .va-pcard__media { aspect-ratio: auto; height: 100%; min-height: 0; min-width: 0; width: 100%; align-self: stretch; }
    .va-search__stage[data-view="list"] .va-pcard__arr,
    .va-search__stage[data-view="list"] .va-pcard__dots { display: none !important; }
    .va-search__stage[data-view="list"] .va-pcard__save { width: 26px; height: 26px; top: 6px; right: 6px; }
    .va-search__stage[data-view="list"] .va-pcard__badges { max-width: 104px; }
    .va-search__stage[data-view="list"] .va-pcard__badges .va-badge { font-size: .58rem; padding: 3px 7px; }
    .va-search__stage[data-view="list"] .va-pcard__body { padding: 10px 12px; gap: 3px; }
    .va-search__stage[data-view="list"] .va-pcard__title { font-size: .92rem; }
    .va-search__stage[data-view="list"] .va-pcard__kicker { font-size: .64rem; }
    .va-search__stage[data-view="list"] .va-pcard__price { font-size: 1.05rem; }
    .va-search__stage[data-view="list"] .va-pcard__specs { gap: 4px; }
    .va-search__stage[data-view="list"] .va-spec { font-size: .68rem; padding: 3px 6px; }
    .va-search__stage[data-view="list"] .va-pcard__excerpt { display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; font-size: .74rem; line-height: 1.35; color: var(--va-warm-light, #A39A8C); margin: 2px 0 0; }
    .va-search__stage[data-view="list"] .va-pcard__foot { margin-top: 4px; padding-top: 6px; }
    .va-search__stage[data-view="list"] .va-pcard__days { font-size: .66rem; }
    .va-search__stage[data-view="list"] .va-pcard__compare { display: none; }
}


/* v7.9.258: stesso layout pulito a 2 righe anche su tablet (769-1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    .va-search__toolbar { display: flex; flex-wrap: wrap; gap: 10px; row-gap: 10px; }
    .va-search__left { width: 100%; order: 1; display: flex; align-items: center; gap: 10px; }
    .va-search__views { order: 2; margin-left: 0; }
    #va-save-search { order: 3; margin-left: auto; }
}

@media (max-width: 768px) {
    /* Riduce il grosso spazio vuoto sopra il bottone Filtri in /properties/ da mobile: era 48px ereditato da .va-section desktop */
    .va-search.va-section { padding-top: 14px; }
}

/* v7.59: filtri drill-down mobile */
@media (max-width: 767px) {
	html.js-v5 .va-filters.is-drill .va-filters__row > *:not(.is-drill):not(:has(.va-pop.is-drill)) { display: none !important; }
	html.js-v5 .va-filters.is-drill .va-pop.is-drill { width: 100%; }
	html.js-v5 .va-filters.is-drill .va-pop.is-drill .va-pop__toggle { width: 100%; pointer-events: none; }
	html.js-v5 .va-filters.is-drill .va-pop.is-drill .va-pop__panel { position: static !important; max-height: none !important; width: 100% !important; border: 0 !important; box-shadow: none !important; padding: 8px 0 0 !important; overflow: visible !important; }
	.va-filters__back { flex: 1 1 100%; justify-content: center; }
	body:has(.va-filters.is-drill) .va-sheet__foot > *:not(.va-filters__back) { display: none !important; }
}
/* v7.61: in drill-down la riga filtri passa a colonna singola: il filtro aperto usa il 100% */
html.js-v5 .va-filters.is-drill .va-filters__row { grid-template-columns: 1fr !important; }
/* v7.62: simbolo euro largo come le icone SVG degli altri filtri */
.va-pop__cur { display: inline-flex; width: 14px; justify-content: center; flex: 0 0 14px; }
/* v7.62: in drill il pannello eredita lo sfondo del foglio (ok light e dark) */
html.js-v5 .va-filters.is-drill .va-pop.is-drill .va-pop__panel { background: transparent !important; }
/* v7.63: barra verde di avanzamento anche sullo slider singolo (Terreno minimo) */
.va-single__input { background: linear-gradient(to right, var(--va-sage) 0, var(--va-sage) var(--va-p, 0%), var(--va-border) var(--va-p, 0%), var(--va-border) 100%) !important; }
/* v7.69: chip filtri attivi su una riga sola, scorrevole, senza andare a capo */
@media (max-width: 767px) {
	#va-active-chips { display: flex; flex-wrap: nowrap; overflow-x: auto; gap: 6px; scrollbar-width: none; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
	#va-active-chips::-webkit-scrollbar { display: none; }
	#va-active-chips .va-chip { white-space: nowrap; flex: 0 0 auto; font-size: .74rem; padding: 6px 11px; gap: 5px; }
}
/* v7.70: in drill-down la lista opzioni non ha piu il tetto dei 260px pensato per la
   tendina: cresce col contenuto, cosi non resta il vuoto sotto le chip. */
html.js-v5 .va-filters.is-drill .va-pop.is-drill .va-pop__options--scroll { max-height: 46vh !important; overflow-y: auto !important; overscroll-behavior: contain; }
/* v7.71: in drill-down il foglio non scorre piu (era la seconda scrollbar e il vuoto
   sotto): scorre solo la lista opzioni, che ha gia il suo max-height. */
html.js-v5 .va-filters.is-drill { overflow-y: hidden !important; max-height: 88dvh; }
/* v7.72: in drill il foglio si dimensiona sul contenuto: niente area vuota residua */
html.js-v5 .va-filters.is-drill { height: auto !important; min-height: 0 !important; }
html.js-v5 .va-filters.is-drill .va-filters__row { min-height: 0 !important; }
html.js-v5 .va-filters.is-drill .va-pop.is-drill .va-pop__panel { min-height: 0 !important; height: auto !important; }
/* v7.73: la lista comuni scorre solo dentro se stessa, mai trascinando il foglio */
html.js-v5 .va-filters.is-drill { overscroll-behavior: contain; }
