/* Pagine Agenzie della v2: network (mappa e griglia), pagina Agenzia, home della singola agenzia.
   La lista immobili dell'agenzia riusa pages/list.css: qui solo l'intestazione dell'agenzia.
   Ombre solo su cio' che galleggia sulla mappa. */

@layer pages {
  .ag-page { padding-block: clamp(32px, 5vw, 72px) var(--section); }

  .ag-intro {
    & h1 { margin-top: 10px; font-size: var(--step-head); max-width: 22ch; }
    & .ag-lead { margin-top: 16px; max-width: 62ch; color: var(--ink-soft); }
  }

  /* ---------- Pagina Agenzia ---------- */
  .ag-pillars {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--gap);
    margin-top: var(--block);
  }
  .ag-pillar {
    padding: clamp(24px, 2.6vw, 36px);
    border-radius: var(--r-lg);
    background: var(--tint);

    & h2 { margin-top: 8px; font-size: var(--step-lead); }
    & p:last-child { margin-top: 12px; color: var(--ink-soft); }
  }

  /* ---------- Network: intestazione ---------- */
  .nw-intro {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 24px;
    flex-wrap: wrap;
  }
  .nw-count {
    display: inline-flex;
    align-items: baseline;
    gap: 10px;
    color: var(--ink-soft);

    & b { font-family: var(--display); font-size: var(--step-head); font-weight: 500; line-height: 1; color: var(--accent); }
  }

  /* ---------- Network: mappa ---------- */
  .nw-stage {
    position: relative;
    overflow: hidden;
    height: clamp(560px, 78vh, 820px);
    margin-top: clamp(24px, 3vw, 40px);
    border-radius: var(--r-lg);
    background: var(--tint-2);
  }
  /* maplibre-gl.css, fuori dai livelli, le da' position: relative: l'altezza viene dal contenitore */
  .nw-map { width: 100%; height: 100%; }

  /* ricerca, in alto a sinistra */
  .nw-find {
    position: absolute;
    top: 16px;
    left: 16px;
    z-index: 5;
    width: min(380px, calc(100% - 32px));
  }
  .nw-search {
    & input { padding-right: 44px; background: var(--ground); box-shadow: var(--shadow-menu); }
    & input:hover { box-shadow: var(--shadow-menu); }
    & input:focus { box-shadow: inset 0 0 0 2px var(--accent), var(--shadow-menu); }
    & input::-webkit-search-cancel-button { display: none; }
  }
  .nw-clear {
    position: absolute;
    top: 50%;
    right: 8px;
    translate: 0 -50%;
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 50%;
    background: none;
    color: var(--ink-soft);
    cursor: pointer;

    &[hidden] { display: none; }
    & .icon { width: 14px; height: 14px; }
    &:hover { background: var(--tint); }
  }
  .nw-results {
    max-height: 260px;
    margin-top: 8px;
    overflow: auto;
    border-radius: var(--r-md);
    background: var(--ground);
    box-shadow: var(--shadow-menu);

    & button {
      display: flex;
      align-items: center;
      gap: 12px;
      width: 100%;
      padding: 10px 12px;
      border: 0;
      background: none;
      color: var(--ink);
      font: 500 var(--step-small) var(--font);
      text-align: left;
      cursor: pointer;
    }
    & button:hover { background: var(--tint); }
    & small { display: block; color: var(--ink-soft); font-size: 12px; font-weight: 400; }
  }
  .nw-none { padding: 14px; font-size: var(--step-small); color: var(--ink-soft); }

  /* loghi: dentro un riquadro bianco; senza logo le iniziali */
  .nw-logo, .nw-mini {
    display: grid;
    place-items: center;
    flex: none;
    overflow: hidden;
    background: var(--ground);
    font-family: var(--display);
    font-weight: 600;

    & img { display: block; width: 100%; height: 100%; object-fit: contain; }
    &.is-initials { background: var(--accent-soft); color: var(--ink); }
  }
  .nw-mini { width: 34px; height: 34px; border-radius: var(--r-sm); font-size: 13px; }
  .nw-logo { width: 54px; height: 54px; border-radius: var(--r-sm); font-size: 18px; }

  /* scritta del volo */
  /* In basso a sinistra: la scritta del sorvolo e, alla sua destra, il pulsante per fermare il volo */
  .nw-status {
    position: absolute;
    left: 16px;
    bottom: 92px;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: calc(100% - 120px);
  }
  .nw-tour { flex: none; }
  .nw-ticker {
    min-width: 0;
    margin: 0;
    padding: 8px 16px;
    overflow: hidden;
    border-radius: var(--r-pill);
    background: var(--scrim);
    color: var(--on-ink);
    font-size: var(--step-small);
    white-space: nowrap;
    text-overflow: ellipsis;

    & b { font-weight: 600; }
  }

  /* carosello */
  .nw-rail {
    position: absolute;
    left: 16px;
    right: 88px;
    bottom: 16px;
    z-index: 5;
    overflow-x: auto;
    overflow-y: hidden;
    border-radius: var(--r-md);
    background: var(--ground);
    box-shadow: var(--shadow-menu);
    scrollbar-width: none;
    cursor: grab;

    &::-webkit-scrollbar { display: none; }
    &.drag { cursor: grabbing; }
    &.drag .nw-chip { pointer-events: none; }
  }
  .nw-track { display: flex; gap: 8px; width: max-content; padding: 8px; }
  .nw-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: none;
    height: 46px;
    padding: 0 14px 0 6px;
    border: 0;
    border-radius: var(--r-sm);
    background: var(--tint);
    color: var(--ink);
    font: 500 var(--step-small) var(--font);
    text-align: left;
    cursor: pointer;
    transition: background-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);

    &:hover { background: var(--tint-2); }
    &.on { box-shadow: inset 0 0 0 2px var(--select); }
    & b { display: block; max-width: 170px; overflow: hidden; font-weight: 600; line-height: 1.15; white-space: nowrap; text-overflow: ellipsis; }
    & small { font-size: 12px; font-weight: 500; color: var(--accent); }
  }

  /* comandi della mappa */
  .nw-ctrl {
    position: absolute;
    right: 16px;
    bottom: 16px;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
  }
  .nw-stack {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: var(--r-md);
    background: var(--ground);
    box-shadow: var(--shadow-menu);

    & button {
      display: grid;
      place-items: center;
      width: var(--field-h);
      height: var(--field-h);
      border: 0;
      background: none;
      color: var(--ink);
      cursor: pointer;
    }
    & button + button { box-shadow: inset 0 1px 0 var(--line); }
    & button:hover { background: var(--tint); }
    & .icon { width: 18px; height: 18px; }
    & svg path { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
  }
  .nw-tour {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: var(--field-h);
    padding: 0 16px;
    border: 0;
    border-radius: var(--r-pill);
    background: var(--ink);
    color: var(--on-ink);
    font: 500 var(--step-small) var(--font);
    white-space: nowrap;
    box-shadow: var(--shadow-menu);
    cursor: pointer;
    transition: background-color var(--dur-fast) var(--ease);

    &:hover { background: var(--accent); }
    & i { width: 8px; height: 8px; border-radius: 50%; background: var(--accent-soft); animation: nw-pulse 1.6s infinite var(--ease); }
    &.paused i { background: var(--line); animation: none; }
  }
  @keyframes nw-pulse { 50% { opacity: .35; } }

  /* card e punti sulla mappa */
  .nw-pin {
    cursor: pointer;
    transition: opacity var(--dur) var(--ease);
    will-change: transform;
    backface-visibility: hidden;

    &.is-hidden { display: none; }
    &.dim { opacity: .35; }
    &:hover { z-index: 9; }
    &.far .nw-pin-card { display: none; }
    &.far .nw-dot { display: block; }
    &.focus .nw-pin-card { box-shadow: 0 0 0 2px var(--accent), var(--shadow-pin); }
    &:hover .nw-pin-card { transform: translateY(-14px) scale(1.04); }
  }
  .nw-pin-card {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    width: 250px;
    padding: 10px 14px 10px 10px;
    border-radius: var(--r-md);
    background: var(--ground);
    box-shadow: var(--shadow-pin);
    transform: translateY(-14px);
    transform-origin: 50% 100%;
    transition: transform var(--dur-fast) var(--ease);
    backface-visibility: hidden;

    &::after {
      content: "";
      position: absolute;
      left: 50%;
      bottom: -7px;
      width: 14px;
      height: 14px;
      border-radius: 3px;
      background: var(--ground);
      transform: translateX(-50%) rotate(45deg);
    }
  }
  .nw-t {
    min-width: 0;

    & h3 { overflow: hidden; font-family: var(--font); font-size: 14px; font-weight: 600; letter-spacing: 0; line-height: 1.2; white-space: nowrap; text-overflow: ellipsis; }
    & p { margin-top: 2px; overflow: hidden; font-size: 12px; color: var(--ink-soft); white-space: nowrap; text-overflow: ellipsis; }
  }
  .nw-n { display: inline-block; margin-top: 4px; padding: 2px 8px; border-radius: var(--r-pill); background: var(--accent-soft); font-size: 12px; font-weight: 600; color: var(--ink); }
  .nw-dot {
    display: none;
    width: 16px;
    height: 16px;
    border: 3px solid var(--ground);
    border-radius: 50%;
    background: var(--accent);
    box-shadow: var(--shadow-pin);
  }

  /* scheda dell'agenzia scelta */
  .nw-sheet {
    position: absolute;
    left: 50%;
    bottom: 92px;
    z-index: 6;
    display: flex;
    align-items: center;
    gap: 16px;
    width: min(500px, calc(100% - 32px));
    padding: 18px;
    border-radius: var(--r-md);
    background: var(--ground);
    box-shadow: var(--shadow-menu);
    visibility: hidden;
    transform: translate(-50%, 200%);
    transition: transform var(--dur) var(--ease), visibility var(--dur);

    &.open { visibility: visible; transform: translate(-50%, 0); }
    & .nw-logo { width: 76px; height: 76px; font-size: 24px; }
    & h2 { padding-right: 36px; font-size: var(--step-lead); }
    & .nw-sc { margin-top: 2px; font-weight: 600; color: var(--accent); }
    & .btn { margin-top: 12px; }
  }
  .nw-sheet-body { min-width: 0; }
  .nw-x { position: absolute; top: 10px; right: 10px; width: 36px; height: 36px; }

  /* ---------- Network: tutte le agenzie ---------- */
  .nw-all {
    margin-top: var(--block);

    & > h2 { font-size: var(--step-head); }
  }
  .nw-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr));
    gap: var(--gap);
    margin: clamp(24px, 3vw, 40px) 0 0;
    padding: 0;
    list-style: none;
  }
  .nw-card {
    position: relative;
    display: grid;
    grid-template-columns: 88px minmax(0, 1fr);
    grid-template-rows: 1fr auto;
    gap: 16px 18px;
    padding: 20px;
    border-radius: var(--r-lg);
    background: var(--tint);
    transition: background-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);

    &.is-link:hover { background: var(--tint-2); box-shadow: inset 0 0 0 1.5px var(--accent); }
    & .nw-logo { width: 88px; height: 88px; border-radius: var(--r-md); font-size: var(--step-lead); }
    & h3 { font-size: var(--step-lead); font-weight: 500; line-height: 1.1; overflow-wrap: anywhere; }
    /* il nome copre tutta la card; i bottoni restano sopra */
    & h3 a { color: inherit; text-decoration: none; }
    & h3 a::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
    & .nw-actions { position: relative; }
  }
  .nw-stats {
    margin-top: 6px;
    font-size: var(--step-small);
    color: var(--ink-soft);

    & b { font-weight: 600; color: var(--accent); }
  }
  .nw-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    font-size: var(--step-small);
    color: var(--ink-soft);

    & .icon { flex: none; width: 15px; height: 15px; color: var(--accent); }
  }
  .nw-desc { margin-top: 10px; font-size: var(--step-small); color: var(--ink-soft); }
  .nw-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; align-self: end; }
  .nw-empty { margin-top: 16px; }

  /* ---------- Home della singola agenzia ---------- */
  .ag-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 24px clamp(24px, 4vw, 64px);
    align-items: start;
    padding-block: clamp(24px, 3vw, 40px);

    & h1 { margin-top: 6px; font-size: var(--step-head); }
    & .ag-lead { margin-top: 12px; max-width: 70ch; color: var(--ink-soft); }
  }
  .ag-contacts {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 16px;

    & .pill {
      display: inline-flex;
      align-items: center;
      gap: 8px;
      min-height: var(--control-h-sm);
      padding: 0 14px;
      border-radius: var(--r-pill);
      background: var(--tint);
      color: var(--ink);
      font-size: var(--step-small);
      font-weight: 500;
      text-decoration: none;
      overflow-wrap: anywhere;
    }
    & a.pill:hover { background: var(--tint-2); }
  }
  /* telefono, mappa aperta a tutto schermo (list.js): sopra restano solo testata e barra, come nella lista */
  body.show-map .ag-head { display: none; }

  /* ---------- Telefono e tablet ---------- */
  @media (max-width: 860px) {
    .ag-pillars { grid-template-columns: minmax(0, 1fr); }
  }
  @media (max-width: 700px) {
    .nw-stage { height: 76vh; min-height: 520px; }
    .nw-ticker { display: none; }
    .nw-rail { right: 16px; }
    .nw-ctrl { bottom: 92px; }
    .nw-sheet { bottom: 84px; }
    .nw-stage:has(.nw-sheet.open) :is(.nw-ctrl, .nw-status) { display: none; } /* la scheda copre i comandi: si tolgono finche' e' aperta */
    .nw-sheet .nw-logo { width: 54px; height: 54px; font-size: 18px; }
    .nw-pin-card { width: 200px; }
    .nw-pin-card .nw-logo { width: 44px; height: 44px; }
    .ag-head { grid-template-columns: minmax(0, 1fr); }
  }
  @media (prefers-reduced-motion: reduce) {
    .nw-tour i { animation: none; }
    .nw-sheet, .nw-pin-card { transition: none; }
  }
}
