/* Scheda immobile (prototipo «Immobile»): galleria, riepilogo, sezioni del corpo con la colonna dell'agente,
   richiesta, riquadro promo, simili, barra mobile. Sotto 768px galleria a carosello; sotto 1100px una colonna. */
@layer sections {
  .property {
    --property-accent: var(--text-brand);
    --property-wrap: calc(var(--container) + 2 * var(--gutter));
  }

  /* In affitto il prezzo è rosso, come nel catalogo */
  .property--affitto { --property-accent: var(--accent-rent); }

  /* Galleria */
  .property-gallery {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: var(--property-wrap);
    margin: 0 auto;
    padding: clamp(16px, 1.6vw, 24px) var(--gutter) 0;
  }

  .property-gallery__bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 16px;
  }

  .property-gallery__back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-brand);
    font-size: var(--fs-small);
    font-weight: var(--fw-semibold);
    text-decoration: none;
    &:hover { color: var(--text-brand); text-decoration: underline; }
  }

  .property-gallery__frame {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius-lg);
    background: var(--surface-soft);
  }

  /* Carosello (mobile e annunci con poche foto): overflow-y hidden + padding-bottom 4px (CLAUDE.md §9) */
  .property-gallery__track {
    position: relative;
    display: flex;
    margin: 0;
    padding: 0;
    overflow-x: auto;
    overflow-y: hidden;
    list-style: none;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
  }

  .property-gallery__slide {
    flex: 0 0 100%;
    aspect-ratio: 4 / 3;
    max-height: 480px;
    scroll-snap-align: start;
    @media (min-width: 768px) { aspect-ratio: auto; height: clamp(300px, 34vw, 480px); }
  }

  .property-gallery__slide--video { display: none; }

  .property-gallery__photo,
  .property-gallery__video {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
    cursor: zoom-in;
  }

  .property-gallery__video { cursor: pointer; }

  .property-gallery__img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .property-gallery__badge,
  .property-gallery__stamp {
    position: absolute;
    top: 16px;
    left: 16px;
    pointer-events: none;
  }

  .property-gallery__badge { padding: 6px 14px; font-size: var(--fs-caption); }

  .property-gallery__stamp {
    padding: 6px 14px;
    border-radius: var(--radius-xs);
    background: var(--action-primary);
    color: var(--text-inverse);
    font-size: var(--fs-caption);
    font-weight: var(--fw-bold);
    letter-spacing: .06em;
    text-transform: uppercase;
    box-shadow: 2px 2px 0 var(--surface-brand);
    transform: rotate(-3deg);
  }

  .property-gallery__arrow {
    --icon-btn-border: transparent;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
  }

  .property-gallery__arrow--prev { left: 16px; }
  .property-gallery__arrow--next { right: 16px; }

  .property-gallery__count {
    position: absolute;
    right: 16px;
    bottom: 16px;
    padding: 6px 12px;
    border-radius: var(--radius-xs);
    background: var(--surface-overlay);
    color: var(--text-inverse);
    font-size: var(--fs-caption);
    font-weight: var(--fw-semibold);
    pointer-events: none;
  }

  .property-gallery__video-btn {
    position: absolute;
    left: 16px;
    bottom: 16px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: var(--hit-min);
    padding: 0 16px 0 5px;
    border-radius: var(--radius-pill);
    background: var(--surface-brand);
    color: var(--text-inverse);
    font-size: var(--fs-small);
    font-weight: var(--fw-semibold);
    text-decoration: none;
    &:hover { background: var(--surface-brand-deep); color: var(--text-inverse); }
    & .property-gallery__play-icon { width: 34px; height: 34px; }
  }

  .property-gallery__play {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: rgba(30, 26, 63, .18);
  }

  .property-gallery__play-icon {
    display: grid;
    place-items: center;
    width: 68px;
    height: 68px;
    border-radius: var(--radius-pill);
    background: var(--action-accent);
    color: var(--text-brand);
    & .icon { fill: currentColor; }
  }

  .property-gallery__play-label {
    padding: 6px 14px;
    border-radius: var(--radius-pill);
    background: var(--surface-page);
    color: var(--text-brand);
    font-size: var(--fs-small);
    font-weight: var(--fw-bold);
  }

  .property-gallery__all {
    position: absolute;
    right: 16px;
    bottom: 16px;
    display: none;
    align-items: center;
    gap: 8px;
    min-height: 48px;
    padding: 0 20px;
    border: 0;
    border-radius: var(--radius-pill);
    background: var(--surface-page);
    color: var(--text-brand);
    font: inherit;
    font-weight: var(--fw-semibold);
    box-shadow: var(--shadow-on-image);
    cursor: pointer;
    &:hover { background: var(--surface-soft); }
  }

  /* Mosaico (da 768px, con abbastanza foto): la lista diventa una griglia, le foto in più si vedono nella lightbox */
  @media (min-width: 768px) {
    .property-gallery__frame--mosaic .property-gallery__track,
    .property-gallery__frame--video .property-gallery__track {
      display: grid;
      gap: 8px;
      height: clamp(300px, 30vw, 440px);
      overflow: hidden;
      padding: 0;
    }

    .property-gallery__frame--mosaic .property-gallery__track { grid-template: 1fr 1fr / 2fr 1fr 1fr; }
    .property-gallery__frame--video .property-gallery__track { grid-template: 1.9fr 1fr / minmax(0, 1.6fr) minmax(0, .5fr) minmax(0, .5fr); }

    .property-gallery__frame--mosaic .property-gallery__slide,
    .property-gallery__frame--video .property-gallery__slide { height: auto; max-height: none; min-height: 0; }

    .property-gallery__frame--mosaic .property-gallery__slide:first-child,
    .property-gallery__frame--video .property-gallery__slide:first-child { grid-row: 1 / 3; }

    .property-gallery__frame--video .property-gallery__slide--video { display: block; grid-column: 2 / 4; }

    /* Meno di 5 foto (o di 3 con il video): le celle che ci sono si allargano, il mosaico resta */
    .property-gallery__frame--mosaic.property-gallery__frame--n2 .property-gallery__track,
    .property-gallery__frame--mosaic.property-gallery__frame--n3 .property-gallery__track { grid-template: 1fr 1fr / 2fr 1fr; }
    .property-gallery__frame--mosaic:is(.property-gallery__frame--n2, .property-gallery__frame--n4) .property-gallery__slide:nth-child(2) { grid-row: 1 / 3; }
    .property-gallery__frame--video.property-gallery__frame--n1 .property-gallery__track { grid-template: 1fr / minmax(0, 1.6fr) minmax(0, 1fr); }
    .property-gallery__frame--video.property-gallery__frame--n1 .property-gallery__slide:first-child { grid-row: auto; }
    .property-gallery__frame--video.property-gallery__frame--n1 .property-gallery__slide--video { grid-column: auto; }
    .property-gallery__frame--video.property-gallery__frame--n2 .property-gallery__slide:nth-child(3) { grid-column: 2 / 4; }

    .property-gallery__frame--mosaic .property-gallery__slide:nth-child(n + 6),
    .property-gallery__frame--video .property-gallery__slide:nth-child(n + 5) { display: none; }

    .property-gallery__frame--mosaic :is(.property-gallery__arrow, .property-gallery__count),
    .property-gallery__frame--video :is(.property-gallery__arrow, .property-gallery__count, .property-gallery__video-btn) { display: none; }

    .property-gallery__frame--mosaic .property-gallery__all,
    .property-gallery__frame--video .property-gallery__all { display: inline-flex; }
  }

  /* Corpo: contenuto + colonna dell'agente (sticky da 1100px) */
  .property-main {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
    gap: clamp(24px, 3vw, 48px);
    max-width: var(--property-wrap);
    margin: 0 auto;
    padding: clamp(20px, 2vw, 28px) var(--gutter) clamp(56px, 6vw, 88px);

    @media (min-width: 1100px) { grid-template-columns: minmax(0, 1fr) 380px; }
  }

  .property-main__content {
    display: flex;
    flex-direction: column;
    gap: clamp(36px, 3.6vw, 52px);
    min-width: 0;
  }

  .property-main__aside {
    display: flex;
    flex-direction: column;
    gap: 16px;
    @media (min-width: 1100px) { position: sticky; top: calc(var(--header-h) + 24px); }
  }

  /* Riepilogo */
  .property-summary {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: clamp(20px, 2.2vw, 32px);
    border-radius: var(--radius-lg);
    background: var(--surface-soft);
  }

  .property-summary__chips { display: flex; flex-wrap: wrap; gap: 8px; }

  .property-summary__chip {
    padding: 5px 12px;
    border-radius: var(--radius-xs);
    background: var(--surface-page);
    color: var(--text-brand);
    font-size: var(--fs-caption);
    font-weight: var(--fw-semibold);
  }

  .property-summary__head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px 32px;
  }

  .property-summary__titles {
    display: flex;
    flex: 1 1 360px;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
  }

  .property-summary__title {
    margin: 0;
    color: var(--text-strong);
    font-size: var(--fs-h1-page);
    font-weight: var(--fw-regular);
    line-height: var(--lh-snug);
    letter-spacing: -0.02em;
    text-wrap: balance;
  }

  .property-summary__place {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    color: var(--text-muted);
    font-size: var(--fs-label);
    & .icon { flex: none; }
  }

  .property-summary__price {
    margin: 0;
    color: var(--property-accent);
    font-family: var(--font-display);
    font-size: var(--fs-price-lg);
    font-weight: var(--fw-semibold);
    line-height: var(--lh-tight);
    letter-spacing: -0.02em;
    white-space: nowrap;
  }

  /* Caratteristiche chiave: celle separate da 1px (lo sfondo della griglia fa da filetto) */
  .property-summary__key {
    display: grid;
    grid-auto-columns: minmax(0, auto);
    grid-auto-flow: column;
    gap: 1px;
    width: fit-content;
    max-width: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: var(--border-default);
    list-style: none;

    /* Su schermi stretti due righe da tre: sei celle in una riga non stanno in 360px */
    @media (max-width: 599px) { grid-auto-flow: row; grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100%; }
  }

  .property-summary__fact,
  .property-summary__plan {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(6px, .7vw, 10px);
    min-width: 0;
    padding: clamp(10px, 1.1vw, 14px) clamp(10px, 1.6vw, 22px);
    background: var(--surface-page);
    text-align: center;

    @media (max-width: 999px) { flex-direction: column; padding-inline: 6px; }
  }

  .property-summary__fact--plan { padding: 0; }

  .property-summary__plan {
    width: 100%;
    height: 100%;
    background: var(--surface-cream);
    color: var(--text-brand);
    text-decoration: none;
    transition: background-color var(--dur-fast);
    &:hover { background: var(--surface-highlight); color: var(--text-brand); }
    & .property-summary__icon { background: var(--surface-page); }
  }

  .property-summary__icon {
    flex: none;
    display: grid;
    place-items: center;
    width: clamp(30px, 2.5vw, 36px);
    height: clamp(30px, 2.5vw, 36px);
    border-radius: var(--radius-pill);
    background: var(--surface-soft);
    color: var(--text-brand);
  }

  .property-summary__value {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    color: var(--text-strong);
    font-family: var(--font-display);
    font-size: clamp(18px, 1.5vw, 22px);
    font-weight: var(--fw-semibold);
    line-height: 1.1;
    @media (max-width: 999px) { align-items: center; }
  }

  .property-summary__unit {
    color: var(--text-muted);
    font-family: var(--font-body);
    font-size: var(--fs-micro);
    font-weight: var(--fw-regular);
    white-space: nowrap;
  }

  /* Sezioni del corpo */
  .property-section {
    display: flex;
    flex-direction: column;
    gap: 18px;
    scroll-margin-top: calc(var(--header-h) + 24px);
  }

  .property-section__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 16px;
  }

  .property-section__head--baseline { align-items: baseline; }

  .property-section__title {
    margin: 0;
    color: var(--text-brand);
    font-size: var(--fs-h3);
    font-weight: var(--fw-regular);
    line-height: var(--lh-snug);
    letter-spacing: -0.02em;
  }

  .property-section__note { margin: 0; color: var(--text-muted); font-size: var(--fs-small); }

  .property-section__highlights,
  .property-section__features {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .property-section__description {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 14px;
    color: var(--text-body);
    font-size: var(--fs-body);
    text-wrap: pretty;

    & > * { margin: 0; }
    &.is-collapsed { max-height: 150px; overflow: hidden; }
    &.is-collapsed::after {
      content: "";
      position: absolute;
      inset: auto 0 0;
      height: 80px;
      background: linear-gradient(rgba(255, 255, 255, 0), var(--surface-page));
      pointer-events: none;
    }
  }

  .property-section__more {
    align-self: flex-start;
    padding: 0;
    border: 0;
    background: none;
    color: var(--text-brand);
    font: inherit;
    font-size: var(--fs-label);
    font-weight: var(--fw-semibold);
    text-decoration: underline;
    text-underline-offset: 4px;
    cursor: pointer;
  }

  .property-section__details {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
    column-gap: 32px;
    margin: 0;
  }

  .property-section__detail {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border-default);
    font-size: var(--fs-ui);

    & dt { color: var(--text-muted); }
    & dd { margin: 0; color: var(--text-strong); font-weight: var(--fw-semibold); text-align: right; }
  }

  .property-section__plan {
    display: block;
    aspect-ratio: 16 / 10;
    overflow: hidden;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    background: var(--surface-page);
    cursor: zoom-in;

    & img { width: 100%; height: 100%; object-fit: contain; }
  }

  /* Mappa: pin sull'indirizzo o cerchio sulla zona */
  .area-map {
    --area-map-color: var(--text-brand);
    height: clamp(280px, 26vw, 380px);
    overflow: hidden;
    border-radius: var(--radius-lg);
    background: var(--surface-soft);
    isolation: isolate;
    &.is-failed { display: none; }
  }

  /* La goccia ruota dentro l'icona: sull'icona la rotazione si sommerebbe al transform con cui Leaflet la posiziona */
  .area-map__drop {
    position: absolute;
    top: 2px;
    left: 3px;
    width: 24px;
    height: 24px;
    border: 3px solid var(--text-inverse);
    border-radius: 50% 50% 50% 0;
    background: var(--area-map-color);
    box-shadow: var(--shadow-float);
    rotate: -45deg;
  }

  /* «Perché scegliere OnlyHouse» */
  .why-us {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 24px;
    border-radius: var(--radius-lg);
    background: var(--surface-soft);
  }

  .why-us__title { margin: 0; color: var(--text-brand); font-family: var(--font-display); font-size: var(--fs-title); }

  .why-us__list { display: flex; flex-direction: column; gap: 14px; margin: 0; padding: 0; list-style: none; }

  .why-us__item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    line-height: 1.3;
  }

  .why-us__check {
    flex: none;
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-pill);
    background: var(--action-accent);
    color: var(--text-brand);
  }

  .why-us__name { display: block; padding-top: 4px; color: var(--text-strong); font-size: var(--fs-ui); font-weight: var(--fw-semibold); }
  .why-us__text { display: block; color: var(--text-muted); font-size: var(--fs-small); }

  /* Richiesta */
  .property-request {
    padding: var(--section-y-sm) var(--gutter);
    background: var(--surface-brand);
    color: var(--text-inverse);
    scroll-margin-top: var(--header-h);
  }

  .property-request__inner {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
    gap: clamp(28px, 4vw, 64px);
    max-width: var(--container);
    margin: 0 auto;
    @media (min-width: 1100px) { grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr); }
  }

  .property-request__intro { display: flex; flex-direction: column; gap: 20px; }

  .property-request__title {
    margin: 0;
    color: var(--text-inverse);
    font-size: var(--fs-h2-page);
    font-weight: var(--fw-regular);
    line-height: var(--lh-heading);
    letter-spacing: var(--ls-h2);
    text-wrap: balance;
  }

  .property-request__text { max-width: 480px; margin: 0; color: var(--text-on-dark-muted); font-size: var(--fs-body); }

  .property-request__item {
    display: flex;
    align-items: center;
    gap: 14px;
    max-width: 440px;
    padding: 12px;
    border-radius: 20px;
    background: var(--surface-on-dark);
  }

  .property-request__thumb {
    flex: none;
    width: 88px;
    height: 72px;
    border-radius: var(--radius-sm);
    object-fit: cover;
  }

  .property-request__item-text { display: flex; flex-direction: column; min-width: 0; margin: 0; line-height: 1.3; }
  .property-request__item-title { font-size: var(--fs-ui); font-weight: var(--fw-semibold); }
  .property-request__item-meta { color: var(--text-on-dark-muted); font-size: var(--fs-small); }

  /* Riquadro promo e simili */
  .property-promo {
    max-width: var(--property-wrap);
    margin: 0 auto;
    padding: var(--section-y) var(--gutter) 0;
  }

  .property-similar {
    max-width: var(--property-wrap);
    margin: 0 auto;
    padding: var(--section-y-sm) var(--gutter) var(--section-y);
  }

  .property-similar__head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: clamp(24px, 2.4vw, 32px);
  }

  .property-similar__title {
    margin: 0;
    color: var(--text-brand);
    font-size: var(--fs-h1-catalog);
    font-weight: var(--fw-regular);
    line-height: var(--lh-heading);
    letter-spacing: var(--ls-h2);
  }

  .property-similar__all { color: var(--text-brand); font-size: var(--fs-label); font-weight: var(--fw-semibold); }

  .property-similar__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr));
    gap: 20px;
    margin: 0;
    padding: 0;
    list-style: none;

    & > li { display: flex; }
    & .card-immobile { flex: 1; }
  }

  /* Barra mobile: Chiama, WhatsApp, Prenota */
  .action-bar,
  .action-bar__spacer { display: none; }

  @media (max-width: 767px) {
    .action-bar__spacer { display: block; height: 80px; }

    .action-bar {
      position: fixed;
      inset: auto 0 0;
      z-index: 60;
      display: grid;
      grid-template-columns: 52px 52px 1fr;
      gap: 8px;
      height: 80px;
      padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
      border-top: 1px solid var(--border-default);
      background: var(--surface-page);
      box-shadow: 0 -8px 24px rgba(61, 53, 126, .08);
    }
  }

  .action-bar__icon {
    display: grid;
    place-items: center;
    border-radius: var(--radius-pill);
    color: var(--text-brand);
    &:hover { color: var(--text-brand); }
  }

  .action-bar__icon--call { border: 1.5px solid var(--border-strong); }
  .action-bar__icon--whatsapp { background: var(--action-accent); }

  .action-bar__cta {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-pill);
    background: var(--action-secondary);
    color: var(--text-inverse);
    font-size: var(--fs-label);
    font-weight: var(--fw-semibold);
    text-decoration: none;
    &:hover { background: var(--action-secondary-hover); color: var(--text-inverse); }
  }
}
