/* Card annuncio: una sola per home, mappa e "simili" della scheda.
   Foto 4:3 con badge, preferito, logo agenzia e frecce; sotto prezzo, titolo (tutta la card e' cliccabile), indirizzo, dati.
   .listings = griglia di card; .listings.row = fila scorrevole (simili). */

@layer components {
  .listings {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 290px), 1fr));
    gap: 28px var(--gap);
    margin: 0;
    padding: 0;
    list-style: none;

    &.row {
      display: flex;
      overflow-x: auto;
      scroll-snap-type: x mandatory;
      scrollbar-width: none;
      padding-bottom: 8px;

      & > * { flex: 0 0 calc((100% - 3 * var(--gap)) / 4); min-width: 250px; scroll-snap-align: start; }
    }
  }
  @media (max-width: 1080px) {
    .listings.row > * { flex-basis: calc((100% - var(--gap)) / 2); }
  }
  @media (max-width: 640px) {
    .listings.row > * { flex-basis: 78%; min-width: 0; }
  }

  .listing {
    position: relative;
    min-width: 0;

    /* ---------- Foto ---------- */
    & .media {
      position: relative;
      aspect-ratio: 4 / 3;
      border-radius: var(--r-md);
      overflow: hidden;
      background: var(--tint-2);
    }
    /* velo in basso: tiene leggibili i pallini e il logo */
    & .media::after {
      content: "";
      position: absolute;
      inset: auto 0 0;
      height: 40%;
      background: linear-gradient(transparent, color-mix(in srgb, var(--shade) 35%, transparent));
      pointer-events: none;
    }
    & .ph {
      position: absolute;
      inset: 0;
      width: 100%;
      height: 100%;
      object-fit: cover;
      opacity: 0;
      transition: opacity .45s var(--ease), scale var(--dur-slow) var(--ease);
    }
    & .ph.on { opacity: 1; }
    /* annuncio senza foto */
    & .no-photo { position: absolute; inset: 0; display: grid; place-items: center; color: var(--ink-soft); }
    & .no-photo .icon { width: 40px; height: 40px; stroke-width: 1.4; }
    &:hover .ph.on { scale: 1.04; }

    /* badge in basso, a destra del logo agenzia (52 px + i margini); senza logo partono dal bordo */
    & .badges { position: absolute; left: 12px; bottom: 12px; z-index: 2; max-width: calc(100% - 24px); align-items: flex-end; }
    & .fav { position: absolute; right: 12px; top: 12px; z-index: 3; }

    & .media:has(.agency-logo) .badges { left: 72px; max-width: calc(100% - 84px); }

    /* cosa c'e' in piu' nella scheda: icone con il suggerimento (sopra il link che copre la card) */
    & .card-features { position: absolute; left: 12px; top: 12px; z-index: 3; display: flex; gap: 6px; }
    & .card-feature {
      position: relative;
      display: grid;
      place-items: center;
      width: 32px;
      height: 32px;
      border-radius: 50%;
      border: 2px solid var(--on-ink);
      background: var(--accent);
      color: var(--on-ink);
      cursor: help;
    }
    & .card-feature .icon { width: 16px; height: 16px; }
    & .card-feature:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
    & .card-feature::after {
      content: attr(data-tip);
      position: absolute;
      left: 0;
      top: calc(100% + 6px);
      padding: 5px 10px;
      border-radius: var(--r-pill);
      background: var(--ink);
      color: var(--on-ink);
      font-size: 12px;
      font-weight: 500;
      white-space: nowrap;
      pointer-events: none;
      opacity: 0;
      translate: 0 -3px;
      transition: opacity var(--dur-fast) var(--ease), translate var(--dur-fast) var(--ease);
    }
    & .card-feature:is(:hover, :focus)::after { opacity: 1; translate: 0 0; }

    & .agency-logo {
      position: absolute;
      left: 12px;
      bottom: 12px;
      z-index: 2;
      width: 52px;
      height: 52px;
      padding: 5px;
      border-radius: 14px;
      background: var(--ground);
    }
    & .agency-logo img { width: 100%; height: 100%; object-fit: contain; border-radius: 9px; }

    /* frecce tra le foto: compaiono al passaggio, sempre visibili sui touch */
    & .nav-ph {
      position: absolute;
      top: 50%;
      z-index: 3;
      translate: 0 -50%;
      display: grid;
      place-items: center;
      width: 34px;
      height: 34px;
      padding: 0;
      border: 0;
      border-radius: 50%;
      background: color-mix(in srgb, var(--ground) 92%, transparent);
      color: var(--ink);
      cursor: pointer;
      opacity: 0;
      transition: opacity var(--dur-fast) var(--ease), scale var(--dur-fast) var(--ease);
    }
    & .nav-ph .icon { width: 14px; height: 14px; stroke-width: 2.2; }
    & .nav-ph.prev { left: 10px; }
    & .nav-ph.next { right: 10px; }
    & .nav-ph:hover { scale: 1.08; }
    &:hover .nav-ph, & .nav-ph:focus-visible { opacity: 1; }

    & .dots { position: absolute; left: 50%; bottom: 14px; z-index: 2; translate: -50% 0; display: flex; gap: 5px; }
    & .dots i { width: 6px; height: 6px; border-radius: var(--r-pill); background: color-mix(in srgb, var(--on-ink) 60%, transparent); transition: width var(--dur) var(--ease), background-color var(--dur) var(--ease); }
    & .dots i.on { width: 16px; background: var(--on-ink); }

    /* ---------- Testo ---------- */
    & .body { display: grid; gap: 4px; padding: 14px 4px 0; }

    & .price {
      display: flex;
      align-items: baseline;
      flex-wrap: wrap;
      gap: 4px 10px;
      font-family: var(--display);
      font-size: var(--step-lead);
      font-weight: 500;
      letter-spacing: -.01em;
      line-height: 1.2;
      font-variant-numeric: tabular-nums;
    }
    /* Prezzo a sinistra, cuore a destra: sopra il link della card (z-index 3) */
    & .price-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
    & .price-row .card-fav { position: relative; top: auto; right: auto; z-index: 3; flex: none; margin-block: -4px; } /* non e' sulla foto: niente scarto di .fav */
    & .price :is(s, small) { font-family: var(--font); font-size: var(--step-small); font-weight: 400; color: var(--ink-soft); letter-spacing: 0; }

    & h3 {
      font-family: var(--font);
      font-size: var(--step-body);
      font-weight: 500;
      line-height: 1.35;
      letter-spacing: 0;
      display: -webkit-box;
      -webkit-line-clamp: 1;
      -webkit-box-orient: vertical;
      overflow: hidden;
    }
    & h3 a { text-decoration: none; }
    /* tutta la card porta alla scheda; preferito e frecce restano sopra (z-index 3) */
    & h3 a::after { content: ""; position: absolute; inset: 0; z-index: 1; border-radius: var(--r-md); }
    & h3 a:focus-visible { outline: none; }
    &:has(h3 a:focus-visible) { outline: 3px solid var(--accent); outline-offset: 6px; border-radius: var(--r-md); }

    & .addr {
      display: flex;
      align-items: center;
      gap: 6px;
      min-width: 0;
      font-size: var(--step-small);
      color: var(--ink-soft);
      white-space: nowrap;
    }
    & .addr .icon { width: 14px; height: 14px; stroke-width: 2; color: var(--accent); }
    & .addr span { overflow: hidden; text-overflow: ellipsis; }

    & .facts {
      display: flex;
      flex-wrap: wrap;
      gap: 6px 14px;
      margin-top: 8px;
      padding-top: 10px;
      box-shadow: inset 0 1px 0 var(--tint-2);
      font-size: var(--step-small);
    }
    & .facts span { display: inline-flex; align-items: center; gap: 6px; }
    & .facts .icon { width: 16px; height: 16px; stroke-width: 1.7; color: var(--ink-soft); }
    /* lista: porta alla scheda, mentre il clic sulla card mostra l'immobile sulla mappa (sopra il link che copre la card) */
    & .facts .card-open {
      position: relative;
      z-index: 3;
      display: inline-flex;
      align-items: center;
      gap: 6px;
      min-height: 28px;
      margin-left: auto;
      padding: 0 10px;
      border-radius: var(--r-pill);
      background: var(--accent);
      color: var(--on-ink);
      font-size: 12px;
      text-decoration: none;
      font-weight: 600;
      white-space: nowrap;
      cursor: pointer;
    }
    & .facts .card-open:hover { background: var(--ink); }
    & .facts .card-open .icon { color: inherit; }
    & .facts .card-open:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
    & .facts .card-open .icon { width: 13px; height: 13px; }

    /* evidenziata dalla mappa */
    &.is-hot .media { box-shadow: 0 0 0 3px var(--accent); }
    /* aperta sulla mappa: piu' spessa del passaggio del mouse */
    &.is-picked .media { box-shadow: 0 0 0 6px var(--accent); }
  }

  /* da tablet in su: icone piu' grandi */
  @media (min-width: 641px) {
    .listing .card-features { gap: 8px; }
    .listing .card-feature { width: 44px; height: 44px; box-shadow: var(--shadow-menu); }
    .listing .card-feature .icon { width: 22px; height: 22px; }
    .listing .card-feature::after { font-size: 13px; }
  }

  @media (hover: none) {
    .listing .nav-ph { opacity: 1; }
  }
  @media (prefers-reduced-motion: reduce) {
    .listing .ph { transition: none; }
  }

  /* card risultato (components/result_card.html): il nome dell'agenzia quando manca il logo */
  .listing.result { border-radius: var(--r-md); transition: transform var(--dur) var(--ease); }
  .listing.result .agency-name { font-size: var(--step-small); color: var(--ink-soft); }
}
