/* ============ MAPA 360 — MapLibre + MapTiler, estilo sidebar (Mavis 360°) ============ */

:root {
  --m360-brand: var(--cor-primaria, #2563eb);
  --m360-line: #e5e7eb;
  --m360-ink: #0f172a;
  --m360-muted: #64748b;
  --m360-bg: #ffffff;
  --m360-bg-soft: #f8fafc;
  --m360-shadow: 0 10px 24px rgba(2, 6, 23, .10);
  --m360-radius: 14px;
  --m360-sidebar-w: 380px;
  --m360-topbar-h: 0px; /* ajustado se a nav tiver altura fixa própria */
}

.m360 {
  position: relative;
  display: grid;
  grid-template-columns: var(--m360-sidebar-w) 1fr;
  height: calc(100vh - var(--m360-topbar-h));
  min-height: 480px;
  background: var(--m360-bg);
  font-family: system-ui, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--m360-ink);
  transition: grid-template-columns .25s ease;
}
.m360.has-panel {
  grid-template-columns: var(--m360-sidebar-w) 1fr var(--m360-panel-w, 304px);
}

/* ---------------- SIDEBAR ---------------- */
.m360-sidebar {
  position: relative;
  z-index: 20;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--m360-line);
  background: var(--m360-bg);
  overflow: hidden;
}
.m360-sidebar-inner {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  overflow-y: auto;
  height: 100%;
}
.m360-handle {
  display: none;
}

.m360-search {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--m360-line);
  border-radius: 10px;
  padding: 0 10px;
  background: var(--m360-bg-soft);
}
.m360-search svg { flex: none; color: var(--m360-muted); }
.m360-search input {
  flex: 1;
  border: none;
  background: transparent;
  height: 42px;
  font-size: 14px;
  color: var(--m360-ink);
  outline: none;
}
.m360-perto-btn {
  flex: none;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--m360-muted);
  cursor: pointer;
}
.m360-perto-btn:hover { background: var(--m360-bg); color: var(--m360-ink); }
.m360-perto-btn.is-active {
  background: var(--m360-brand);
  border-color: var(--m360-brand);
  color: #fff;
}
.m360-perto-btn.is-loading { opacity: .55; cursor: wait; }

.m360-filtros-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}
.m360-filtros-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--m360-line);
  border-radius: 10px;
  background: var(--m360-bg);
  color: var(--m360-ink);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  flex: 1 1 auto;
  min-width: 0;
}
.m360-filtros-toggle:hover { border-color: var(--m360-brand); }
/* Só aparece quando há algum filtro ativo (chip, busca, "perto de mim" ou
   dentro de uma rota) — deixa claro pro visitante que o mapa está filtrado
   e dá um jeito rápido de voltar ao estado normal. */
.m360-filtros-limpar {
  flex: none;
  height: 38px;
  padding: 0 12px;
  border: 1px dashed var(--m360-brand);
  border-radius: 10px;
  background: transparent;
  color: var(--m360-brand);
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
}
.m360-filtros-limpar:hover { background: color-mix(in srgb, var(--m360-brand) 8%, transparent); }
.m360-filtros-count {
  background: var(--m360-brand);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  padding: 3px 7px;
  border-radius: 999px;
}

.m360-filtros {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--m360-line);
  border-radius: 10px;
  background: var(--m360-bg-soft);
}
.m360-filtro-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--m360-line);
  background: #fff;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--m360-ink);
  cursor: pointer;
  user-select: none;
  transition: transform .06s ease, box-shadow .15s ease;
}
.m360-filtro-chip:active { transform: translateY(1px); }
.m360-filtro-chip .dot {
  width: 9px; height: 9px; border-radius: 50%; flex: none;
}
.m360-filtro-chip.is-active {
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 10px rgba(2, 6, 23, .18);
}
.m360-filtro-chip .n {
  font-weight: 700;
  opacity: .85;
}
/* Chips de camada (Eventos/Rotas/Pontos de apoio/Serviços) — mesma pílula dos
   chips de categoria, com borda tracejada pra diferenciar à primeira vista
   ("isso liga uma camada inteira", não filtra dentro das empresas). */
.m360-filtro-camada {
  border-style: dashed;
}

.m360-contador {
  font-size: 12.5px;
  color: var(--m360-muted);
  font-weight: 600;
  padding: 0 2px;
}

.m360-lista {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  flex: 1;
  padding-right: 2px;
}
.m360-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--m360-line);
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
  text-align: left;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.m360-item:hover, .m360-item:focus-visible {
  border-color: var(--m360-brand);
  box-shadow: var(--m360-shadow);
  outline: none;
}
.m360-item.is-selected {
  border-color: var(--m360-brand);
  background: color-mix(in srgb, var(--m360-brand) 6%, #fff);
  box-shadow: inset 3px 0 0 var(--m360-brand); /* distingue do :hover, que só muda a borda */
}
.m360-item-thumb {
  width: 52px; height: 52px; border-radius: 10px;
  object-fit: cover; flex: none; background: var(--m360-bg-soft);
}
.m360-item-thumb.placeholder {
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}
.m360-item-body { min-width: 0; }
.m360-item-nome {
  font-weight: 700; font-size: 13.5px; color: var(--m360-ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.m360-item-cat {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px; font-weight: 600; color: var(--m360-muted);
  margin-top: 2px;
}
.m360-item-dist {
  font-weight: 700;
  color: var(--m360-brand);
  white-space: nowrap;
}
.m360-lista-vazio {
  padding: 24px 8px;
  text-align: center;
  color: var(--m360-muted);
  font-size: 13px;
}

.m360-voltar-rotas {
  display: block;
  width: 100%;
  padding: 8px;
  margin-bottom: 4px;
  border: 1px dashed var(--m360-line);
  border-radius: 10px;
  background: transparent;
  color: var(--m360-muted);
  font-weight: 600;
  font-size: 12.5px;
  text-align: center;
  cursor: pointer;
}
.m360-voltar-rotas:hover, .m360-voltar-rotas:focus-visible {
  border-color: var(--m360-brand);
  color: var(--m360-brand);
  outline: none;
}

/* ---------------- MAPA ---------------- */
.m360-map-wrap {
  position: relative;
  height: 100%;
}
#m360-map {
  position: absolute;
  inset: 0;
}

.m360-legend {
  position: absolute;
  right: 12px;
  bottom: 28px;
  z-index: 10;
  max-width: 220px;
  max-height: 45vh;
  overflow-y: auto;
  padding: 10px 12px;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: saturate(180%) blur(6px);
  border: 1px solid var(--m360-line);
  border-radius: 12px;
  box-shadow: var(--m360-shadow);
  font-size: 12px;
}
.m360-legend-title {
  font-weight: 700;
  color: var(--m360-ink);
  margin-bottom: 6px;
}
.m360-legend-item {
  display: flex; align-items: center; gap: 8px;
  padding: 2px 0;
  color: var(--m360-muted);
}
.m360-legend-item .dot {
  width: 10px; height: 10px; border-radius: 50%; flex: none;
}
.m360-legend-sep {
  height: 1px;
  background: var(--m360-line);
  margin: 8px 0 6px;
}

/* ---------------- PAINEL LATERAL (detalhe do atrativo) ---------------- */
.m360-panel {
  position: relative;
  z-index: 15;
  display: none;
  flex-direction: column;
  border-left: 1px solid var(--m360-line);
  background: var(--m360-bg);
  overflow-y: auto;
}
.m360-panel:not([hidden]) { display: flex; }

.m360-panel-close {
  position: absolute;
  top: 12px; right: 12px;
  z-index: 2;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border: none;
  border-radius: 50%;
  background: rgba(15, 23, 42, .55);
  color: #fff;
  cursor: pointer;
}
.m360-panel-close:hover { background: rgba(15, 23, 42, .75); }

.m360-panel-hero {
  height: 220px;
  flex: none;
  background: var(--m360-bg-soft) center/cover no-repeat;
}

.m360-panel-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  /* Sem flex:none o corpo encolhe quando a viewport é baixa (ex.: DevTools aberto)
     e esmaga o conteúdo das abas até altura ~0. O painel já tem overflow-y:auto,
     então o excesso vira scroll em vez de sumir. */
  flex: none;
}

.m360-panel-badge {
  display: inline-flex;
  align-self: flex-start;
  font-size: 11.5px;
  font-weight: 700;
  color: #fff;
  padding: 3px 10px;
  border-radius: 999px;
}

.m360-panel-titulo {
  margin: 0;
  font-size: 19px;
  line-height: 1.25;
  color: var(--m360-ink);
}

.m360-panel-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--m360-line);
  margin-top: 4px;
}
.m360-panel-tab {
  border: none;
  background: transparent;
  padding: 8px 4px;
  margin-bottom: -1px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--m360-muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
}
.m360-panel-tab.is-active {
  color: var(--m360-brand);
  border-bottom-color: var(--m360-brand);
}
.m360-panel-tab + .m360-panel-tab { margin-left: 14px; }

.m360-panel-pane { padding-top: 4px; flex: none; }

.m360-panel-desc {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.55;
  color: #334155;
}

/* Ponto/serviço/evento: horário, telefone, WhatsApp, endereço — os dados que
   os popups antigos mostravam, agora dentro do painel lateral unificado. */
.m360-panel-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  margin: 8px 0 0;
  font-size: 13px;
}
.m360-panel-meta dt {
  color: var(--m360-muted);
  font-weight: 600;
}
.m360-panel-meta dd {
  margin: 0;
  color: var(--m360-ink);
}
.m360-panel-meta a {
  color: var(--m360-brand);
  text-decoration: none;
}
.m360-panel-meta a:hover { text-decoration: underline; }

.m360-panel-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.m360-panel-actions a {
  flex: 1 1 auto;
  text-align: center;
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  padding: 10px 12px;
  border-radius: 10px;
}
.m360-panel-actions .btn-detalhes { background: var(--m360-brand); color: #fff; }
.m360-panel-actions .btn-chegar { background: #fff; color: var(--m360-ink); border: 1px solid var(--m360-line); }

.m360-panel-fotos {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.m360-panel-fotos img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 10px;
  background: var(--m360-bg-soft);
  cursor: pointer;
}
.m360-panel-fotos-vazio {
  grid-column: 1 / -1;
  padding: 20px 4px;
  text-align: center;
  color: var(--m360-muted);
  font-size: 13px;
}

.m360-panel-videos {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.m360-video-card {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 10px;
  overflow: hidden;
  background: var(--m360-bg-soft);
  cursor: pointer;
}
.m360-video-card img,
.m360-video-card-fallback {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.m360-video-card-fallback {
  background: linear-gradient(135deg, #1e293b, #0f172a);
}
.m360-video-play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: #fff;
}
.m360-video-play::before {
  content: '';
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  position: absolute;
}
.m360-video-play::after {
  content: '';
  position: relative;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 7px 0 7px 11px;
  border-color: transparent transparent transparent #fff;
  margin-left: 3px;
}

.m360-panel-pano {
  position: relative; /* ancora Voltar/controles de vídeo quando movidos pra dentro em tela cheia */
  width: 100%;
  height: 260px;
  min-height: 260px;
  flex: none;
  border-radius: 10px;
  overflow: hidden;
  background: #0f172a;
}
.m360-panel-pano .pnlm-load-box { color: #fff; }

/* Posicionado relativo ao pane (não ao box do pano) de propósito: o Pannellum
   assume dono do innerHTML de #m360-panel-pano a cada troca de cena, e um
   controle filho dele seria apagado junto. Como irmão, sobrevive. */
.m360-pane-com-pano { position: relative; }
.m360-video-controls {
  position: absolute;
  right: 20px;
  bottom: 20px;
  z-index: 5;
  display: flex;
  gap: 6px;
}
.m360-video-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(15, 23, 42, .65);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.m360-video-btn:hover { background: rgba(15, 23, 42, .85); }

/* Independente de a cena ser foto ou vídeo — some sozinho quando não há
   passo anterior pra voltar (primeira cena do tour). */
.m360-voltar-btn {
  position: absolute;
  left: 20px;
  top: 20px;
  z-index: 5;
  padding: 7px 12px;
  border-radius: 999px;
  border: none;
  background: rgba(15, 23, 42, .65);
  color: #fff;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}
.m360-voltar-btn:hover { background: rgba(15, 23, 42, .85); }

/* ---------------- POPUP ---------------- */
.m360-popup { min-width: 220px; max-width: 260px; }
.m360-popup img {
  width: 100%; height: 120px; object-fit: cover;
  border-radius: 8px; display: block; margin-bottom: 8px;
}
.m360-popup h3 {
  margin: 0 0 4px; font-size: 14.5px; color: var(--m360-ink);
}
.m360-popup .m360-popup-badge {
  display: inline-block;
  font-size: 11px; font-weight: 700; color: #fff;
  padding: 2px 8px; border-radius: 999px; margin-bottom: 6px;
}
.m360-popup p {
  margin: 0 0 10px; font-size: 12.5px; color: #334155; line-height: 1.4;
}
.m360-popup .m360-popup-actions {
  display: flex; gap: 8px; flex-wrap: wrap;
}
.m360-popup .m360-popup-actions a {
  flex: 1 1 auto;
  text-align: center;
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
  padding: 7px 10px;
  border-radius: 8px;
}
.m360-popup .btn-detalhes {
  background: var(--m360-brand); color: #fff;
}
.m360-popup .btn-chegar {
  background: #fff; color: var(--m360-ink); border: 1px solid var(--m360-line);
}

.maplibregl-popup-content {
  border-radius: 12px !important;
  box-shadow: var(--m360-shadow) !important;
  padding: 12px !important;
}

/* ---------------- RESPONSIVO (bottom sheet) ---------------- */
@media (max-width: 900px) {
  :root { --m360-sidebar-h-peek: 78px; --m360-sidebar-h-half: 55vh; --m360-sidebar-h-full: 88vh; }

  .m360 {
    display: block;
    height: calc(100vh - var(--m360-topbar-h));
    position: relative;
    overflow: hidden;
  }
  .m360-map-wrap { position: absolute; inset: 0; z-index: 1; }

  .m360-sidebar {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    z-index: 30;
    height: var(--m360-sidebar-h-full);
    max-height: 92vh;
    border-right: none;
    border-top: 1px solid var(--m360-line);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 24px rgba(2, 6, 23, .18);
    transform: translateY(calc(100% - var(--m360-sidebar-h-peek)));
    transition: transform .25s ease;
    touch-action: none;
  }
  .m360-sidebar.is-half { transform: translateY(calc(100% - var(--m360-sidebar-h-half))); }
  .m360-sidebar.is-full { transform: translateY(0); }

  .m360-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 26px;
    flex: none;
    border: none;
    background: transparent;
    cursor: grab;
  }
  .m360-handle span {
    width: 40px; height: 4px; border-radius: 999px;
    background: var(--m360-line);
  }

  .m360-sidebar-inner { padding: 4px 14px 14px; }

  .m360-legend { display: none; }

  /* Painel de detalhe vira tela cheia por cima do mapa no mobile */
  .m360.has-panel { grid-template-columns: none; }
  .m360-panel {
    position: absolute;
    inset: 0;
    z-index: 40;
    border-left: none;
  }
  .m360-panel-hero { height: 42vw; min-height: 180px; }
}

/* ---------------- CARROSSEL DE FOTOS (tela cheia) ---------------- */
.m360-lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, .92);
  display: flex;
  align-items: center;
  justify-content: center;
}
.m360-lightbox[hidden] { display: none; }

.m360-lightbox-img {
  max-width: 88vw;
  max-height: 86vh;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}

.m360-lightbox-close,
.m360-lightbox-nav {
  position: absolute;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.m360-lightbox-close:hover,
.m360-lightbox-nav:hover { background: rgba(255, 255, 255, .24); }

.m360-lightbox-close {
  top: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
}

.m360-lightbox-nav {
  top: 50%;
  transform: translateY(-50%);
  width: 46px;
  height: 46px;
}
.m360-lightbox-prev { left: 16px; }
.m360-lightbox-next { right: 16px; }

.m360-lightbox-contador {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, .85);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .02em;
}

@media (max-width: 600px) {
  .m360-lightbox-img { max-width: 94vw; max-height: 78vh; }
  .m360-lightbox-nav { width: 38px; height: 38px; }
  .m360-lightbox-prev { left: 8px; }
  .m360-lightbox-next { right: 8px; }
}

/* ---------------- MODAL DE VÍDEO (tela cheia) ---------------- */
.m360-video-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, .92);
  display: flex;
  align-items: center;
  justify-content: center;
}
.m360-video-modal[hidden] { display: none; }

.m360-video-modal-body {
  width: min(88vw, 960px);
  aspect-ratio: 16 / 9;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
  background: #000;
}
.m360-video-modal-body iframe,
.m360-video-modal-body video {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}
.m360-video-modal-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.m360-video-modal-fallback a {
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  text-decoration: underline;
}

.m360-video-modal-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.m360-video-modal-close:hover { background: rgba(255, 255, 255, .24); }

@media (max-width: 600px) {
  .m360-video-modal-body { width: 94vw; }
}
