/* ════════════════════════════════════════════════════════════════════
   PANORAMA MUNICIPAL — LAYOUT MOBILE (Android/iOS)
   ════════════════════════════════════════════════════════════════════
   Ativado por `html.is-mobile-pm` (set por assets/js/mobile-bridge.js
   via matchMedia (max-width: 980px)).

   Estratégia:
   - Mapa em full-screen como base (igual Google Maps / Waze)
   - Topbar 56px com hamburger + título + avatar
   - Sidebar global esquerda vira drawer ativado pelo hamburger
   - Painel direito CAMADAS/AÇÃO/RELATÓRIOS vira BOTTOM SHEET retrátil
     com 3 estados: collapsed (56px) / half (50dvh) / full (90dvh)
   - Botões flutuantes do mapa em row no rodapé
   - Modais full-screen
   ════════════════════════════════════════════════════════════════════ */

/* Hamburger no topbar — só visível em mobile */
.topbar-mobile-hamburger {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  border-radius: 10px;
  cursor: pointer;
  color: inherit;
  flex: none;
  margin-right: 4px;
  padding: 0;
}
.topbar-mobile-hamburger:hover { background: rgba(36,78,156,0.08); }
.topbar-mobile-hamburger:active { background: rgba(36,78,156,0.14); }

/* Handle do bottom sheet — só visível em mobile. Área de toque 52px (Android pref). */
.pm-sheet-handle {
  display: none;
  height: 52px;
  position: relative;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  flex: none;
  touch-action: none;
  background: #FFFFFF;
  border-radius: 18px 18px 0 0;
  border-bottom: 1px solid rgba(15, 35, 71, 0.06);
}
.pm-sheet-handle:active { cursor: grabbing; }
.pm-sheet-handle::before {
  content: "";
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: 44px;
  height: 5px;
  background: rgba(15, 35, 71, 0.28);
  border-radius: 3px;
  transition: background 0.18s, width 0.18s;
}
.pm-sheet-handle:hover::before { background: rgba(15, 35, 71, 0.50); }

/* Texto auxiliar dentro do handle (só mobile, só quando aberto) */
.pm-sheet-hint {
  display: none;
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  font-weight: 600;
  color: rgba(15, 35, 71, 0.65);
  letter-spacing: 0.3px;
  pointer-events: none;
}
html.is-mobile-pm.is-sheet-half .pm-sheet-hint,
html.is-mobile-pm.is-sheet-full .pm-sheet-hint {
  display: block;
}

/* Botão X — visível só quando o sheet está aberto (half ou full). Grande e claro. */
.pm-sheet-close {
  display: none;
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1.5px solid rgba(15, 35, 71, 0.18);
  background: #FFFFFF;
  color: #244E9C;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 2px 8px rgba(15, 35, 71, 0.10);
  z-index: 3;
}
.pm-sheet-close:hover {
  background: #F0F4FA;
  border-color: rgba(36, 78, 156, 0.40);
}
.pm-sheet-close:active {
  background: #E2EAF6;
  transform: translateY(-50%) scale(0.94);
}
html.is-mobile-pm.is-sheet-half .pm-sheet-close,
html.is-mobile-pm.is-sheet-full .pm-sheet-close {
  display: inline-flex;
}
/* Barra mais saliente quando aberto */
html.is-mobile-pm.is-sheet-half .pm-sheet-handle::before,
html.is-mobile-pm.is-sheet-full .pm-sheet-handle::before {
  background: #244E9C;
  width: 56px;
  top: 8px;
}

/* ════════════════════════════════════════════════════════════════════
   ATIVADO EM MOBILE (≤ 980px)
   ════════════════════════════════════════════════════════════════════ */
html.is-mobile-pm {
  /* Permite scroll natural onde precisar */
  -webkit-text-size-adjust: 100%;
}

html.is-mobile-pm body {
  overflow: hidden;
}

/* ── TOPBAR compacta ───────────────────────────────────────────── */
html.is-mobile-pm .topbar {
  height: 56px !important;
  min-height: 56px !important;
  padding: 0 10px !important;
  gap: 8px !important;
  padding-top: max(0px, env(safe-area-inset-top)) !important;
  height: calc(56px + env(safe-area-inset-top)) !important;
}
html.is-mobile-pm .topbar-mobile-hamburger {
  display: flex;
}
html.is-mobile-pm .topbar-left {
  gap: 6px !important;
  min-width: 0 !important;
  flex: 1 1 auto !important;
}
html.is-mobile-pm .topbar-pa-logo {
  display: none !important;
}
html.is-mobile-pm .topbar-title-divider {
  display: none !important;
}
html.is-mobile-pm .crumb {
  font-size: 15px !important;
  font-weight: 700 !important;
  line-height: 1.2 !important;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
html.is-mobile-pm .crumb-sub {
  display: none !important;
}
html.is-mobile-pm .topbar-center {
  display: none !important;
}
html.is-mobile-pm .topbar-right {
  gap: 4px !important;
  flex: none !important;
}
html.is-mobile-pm #btnTutu {
  display: none !important;
}
html.is-mobile-pm #btnNotif {
  width: 38px !important;
  height: 38px !important;
  padding: 0 !important;
}
html.is-mobile-pm #btnNotif .badge {
  font-size: 9px !important;
  min-width: 16px !important;
  height: 16px !important;
}
html.is-mobile-pm .user-btn {
  padding: 4px !important;
  gap: 0 !important;
  background: transparent !important;
  border: none !important;
}
html.is-mobile-pm .user-info,
html.is-mobile-pm .user-chevron {
  display: none !important;
}
html.is-mobile-pm .user-avatar {
  width: 36px !important;
  height: 36px !important;
}

/* ── SIDEBAR esquerda → drawer ─────────────────────────────────── */
html.is-mobile-pm .main {
  margin-left: 0 !important;
}
html.is-mobile-pm .sidebar,
html.is-mobile-pm .sidebar.collapsed {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  bottom: 0 !important;
  width: min(320px, 86vw) !important;
  max-width: 320px !important;
  z-index: 60 !important;
  transform: translateX(-102%);
  transition: transform 0.26s ease-out;
  box-shadow: 4px 0 30px rgba(15, 35, 71, 0.30);
  padding-top: max(0px, env(safe-area-inset-top)) !important;
}
html.is-mobile-pm .sidebar.open,
html.is-mobile-pm .sidebar.open.collapsed {
  transform: translateX(0) !important;
  width: min(320px, 86vw) !important;
}
/* Em mobile drawer aberto, força a apresentação expandida (mesmo se a classe .collapsed estiver presente, herdada do estado desktop) */
html.is-mobile-pm .sidebar.open .brand,
html.is-mobile-pm .sidebar.open.collapsed .brand {
  display: flex !important;
  flex: 1 !important;
}
html.is-mobile-pm .sidebar.open .brand-logo-img--light,
html.is-mobile-pm .sidebar.open.collapsed .brand-logo-img--light {
  display: block !important;
  max-width: 130px !important;
  height: auto !important;
}
html.is-mobile-pm .sidebar.open .brand-logo-img--dark,
html.is-mobile-pm .sidebar.open.collapsed .brand-logo-img--dark {
  display: none !important;
}
html[data-theme="dark"].is-mobile-pm .sidebar.open .brand-logo-img--dark,
html[data-theme="dark"].is-mobile-pm .sidebar.open.collapsed .brand-logo-img--dark {
  display: block !important;
}
html[data-theme="dark"].is-mobile-pm .sidebar.open .brand-logo-img--light,
html[data-theme="dark"].is-mobile-pm .sidebar.open.collapsed .brand-logo-img--light {
  display: none !important;
}
html.is-mobile-pm .sidebar.open .sb-search,
html.is-mobile-pm .sidebar.open.collapsed .sb-search {
  display: flex !important;
}
html.is-mobile-pm .sidebar.open .sb-section-title,
html.is-mobile-pm .sidebar.open.collapsed .sb-section-title {
  display: block !important;
}
html.is-mobile-pm .sidebar.open .nav-item,
html.is-mobile-pm .sidebar.open.collapsed .nav-item {
  justify-content: flex-start !important;
}
html.is-mobile-pm .sidebar.open .nav-item-text,
html.is-mobile-pm .sidebar.open.collapsed .nav-item-text,
html.is-mobile-pm .sidebar.open .nav-item-sub,
html.is-mobile-pm .sidebar.open.collapsed .nav-item-sub {
  display: block !important;
}
html.is-mobile-pm #sb-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 35, 71, 0.52);
  z-index: 55;
  opacity: 0;
  transition: opacity 0.22s;
}
html.is-mobile-pm.is-sidebar-open #sb-backdrop {
  display: block;
  opacity: 1;
}

/* ── SOURCE-SWITCHER (Mapa/ATLAS/IBGE/TSE) — scroll horizontal ─ */
html.is-mobile-pm .source-switcher {
  overflow-x: auto !important;
  overflow-y: hidden !important;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  flex-wrap: nowrap !important;
  padding: 8px 12px !important;
  gap: 6px !important;
  scrollbar-width: none;
}
html.is-mobile-pm .source-switcher::-webkit-scrollbar {
  display: none;
}
html.is-mobile-pm .source-btn {
  flex: 0 0 auto !important;
  scroll-snap-align: start;
  padding: 8px 14px !important;
  font-size: 13px !important;
  white-space: nowrap;
  min-height: 38px;
}

/* ── PM-MAP-LAYOUT → mapa full + bottom sheet ──────────────────── */
html.is-mobile-pm .pm-map-layout {
  flex-direction: column !important;
  position: relative;
  gap: 0 !important;
}
html.is-mobile-pm .pm-map-sidebar-edge-toggle {
  display: none !important;
}
html.is-mobile-pm .pm-map-area {
  flex: 1 1 auto !important;
  width: 100% !important;
  min-height: 0 !important;
  position: relative !important;
  overflow: hidden;
}

/* Painel direito → bottom sheet */
html.is-mobile-pm .pm-map-sidebar {
  position: absolute !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  top: auto !important;
  width: 100% !important;
  max-width: 100% !important;
  flex: none !important;
  height: 88dvh !important;
  max-height: 88dvh !important;
  border-radius: 18px 18px 0 0 !important;
  border: none !important;
  background: #FFFFFF !important;
  box-shadow: 0 -10px 30px rgba(15, 35, 71, 0.18) !important;
  transform: translateY(calc(100% - 52px));
  transition: transform 0.28s cubic-bezier(0.4, 0.0, 0.2, 1);
  z-index: 30;
  display: flex;
  flex-direction: column;
  padding: 0 !important;
  margin: 0 !important;
  overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom);
}
/* Fechado: só o handle (sem abas visíveis) */
html.is-mobile-pm:not(.is-sheet-half):not(.is-sheet-full) .pm-map-sidebar .pm-sb-tabs,
html.is-mobile-pm:not(.is-sheet-half):not(.is-sheet-full) .pm-map-sidebar .pm-sb-panel {
  display: none !important;
}
html.is-mobile-pm.is-sheet-half .pm-map-sidebar {
  transform: translateY(50%);
}
html.is-mobile-pm.is-sheet-half .pm-map-sidebar .pm-sb-tabs,
html.is-mobile-pm.is-sheet-full .pm-map-sidebar .pm-sb-tabs {
  display: flex !important;
}
html.is-mobile-pm.is-sheet-half .pm-map-sidebar .pm-sb-panel.active,
html.is-mobile-pm.is-sheet-full .pm-map-sidebar .pm-sb-panel.active {
  display: block !important;
}
html.is-mobile-pm.is-sheet-full .pm-map-sidebar {
  transform: translateY(0);
}

/* Handle visível só em mobile no topo do sheet */
html.is-mobile-pm .pm-map-sidebar .pm-sheet-handle {
  display: block;
}

/* Tabs do sheet — sempre visíveis e arrastáveis */
html.is-mobile-pm .pm-sb-tabs {
  flex-wrap: nowrap !important;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 4px 12px 0 !important;
  gap: 4px !important;
  position: sticky;
  top: 0;
  background: #FFFFFF;
  z-index: 2;
}
html.is-mobile-pm .pm-sb-tabs::-webkit-scrollbar {
  display: none;
}
html.is-mobile-pm .pm-sb-tab {
  flex: 0 0 auto !important;
  white-space: nowrap;
  padding: 8px 12px !important;
  font-size: 12.5px !important;
  min-height: 38px;
}

/* Conteúdo do painel rola dentro do sheet */
html.is-mobile-pm .pm-sb-panel {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 16px !important;
  padding-bottom: calc(20px + env(safe-area-inset-bottom)) !important;
}

/* Grid de categorias em 2 cols mobile */
html.is-mobile-pm .pm-cat-grid {
  grid-template-columns: 1fr 1fr !important;
  gap: 8px !important;
}

/* Lista de camadas com mais respiração */
html.is-mobile-pm .pm-layers-card {
  margin-top: 12px;
}
html.is-mobile-pm .pm-layers-list {
  max-height: none !important;
}

/* ── Botões flutuantes do mapa — TODOS visíveis, layout compacto ─ */

/* Top-right: "Dados municipais" + 3 mode-triggers (tipo/SV/tráfego) em row */
html.is-mobile-pm .pm-map-corner-top-right {
  top: 8px !important;
  right: 8px !important;
  left: auto !important;
  gap: 4px !important;
  flex-wrap: nowrap !important;
  flex-direction: row !important;
  align-items: center !important;
  max-width: calc(100vw - 16px);
}
html.is-mobile-pm #pmMapModeTrigger {
  padding: 7px 10px !important;
  font-size: 11.5px !important;
  min-height: 36px !important;
  max-width: 46vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
html.is-mobile-pm .pm-maptype-wrap,
html.is-mobile-pm #pmMapTypeTrigger,
html.is-mobile-pm #pmStreetViewTrigger,
html.is-mobile-pm #pmTrafficFlowTrigger {
  width: 36px !important;
  min-width: 36px !important;
  height: 36px !important;
  min-height: 36px !important;
  padding: 0 !important;
  border-radius: 10px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  font-size: 0 !important;
}
html.is-mobile-pm .pm-maptype-wrap > * {
  width: 100% !important;
  height: 100% !important;
}

html.is-mobile-pm .pm-pegman-btn-figure {
  width: 30px !important;
  height: 30px !important;
}

/* Right column: TODOS os tools (location, opacidade, régua, zoom +/-, busca, share, fullscreen) */
html.is-mobile-pm .pm-map-corner-right {
  top: 8px !important;
  transform: none !important;
  bottom: auto !important;
  right: 8px !important;
  left: auto !important;
  flex-direction: column !important;
  gap: 5px !important;
  align-items: center;
  max-height: calc(100% - 88px);
  overflow-y: hidden;
  overflow-x: hidden;
  scrollbar-width: none;
  padding: 2px 0;
}
html.is-mobile-pm .pm-map-corner-right::-webkit-scrollbar {
  display: none;
}
html.is-mobile-pm .pm-map-corner-right > * {
  width: 36px !important;
  min-width: 36px !important;
  max-width: 36px !important;
  height: 36px !important;
  min-height: 36px !important;
  max-height: 36px !important;
  padding: 0 !important;
  border-radius: 999px !important;
  flex: none !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
}
html.is-mobile-pm .pm-map-zoom-pill {
  flex-direction: column !important;
  width: 36px !important;
  min-width: 36px !important;
  max-width: 36px !important;
  height: 66px !important;
  min-height: 66px !important;
  max-height: 66px !important;
  gap: 0 !important;
  padding: 1px !important;
  border-radius: 999px !important;
  align-items: center !important;
  overflow: visible !important;
}
html.is-mobile-pm .pm-map-zoom-pill > * {
  width: 34px !important;
  min-width: 34px !important;
  height: 32px !important;
  min-height: 32px !important;
  padding: 0 !important;
  flex: none !important;
  border-radius: 999px !important;
}
html.is-mobile-pm .pm-map-zoom-pill .pm-map-zoom-divider {
  display: none !important;
}

/* Bottom corner: SÓ chips de camadas ativas (distance e coords escondidos) */
html.is-mobile-pm .pm-map-corner-bottom {
  position: absolute !important;
  left: 8px !important;
  right: 60px !important; /* deixa espaço pros botões da direita não sobreporem */
  bottom: 100px !important;
  gap: 6px !important;
  flex-direction: column !important;
  align-items: stretch !important;
}
html.is-mobile-pm .pm-map-distance-card,
html.is-mobile-pm .pm-map-coords-card {
  display: none !important;
}
html.is-mobile-pm .pm-active-bar {
  width: 100% !important;
  max-width: 100% !important;
  flex-wrap: nowrap !important;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 7px 11px !important;
  scrollbar-width: none;
  font-size: 11.5px !important;
}
html.is-mobile-pm .pm-active-bar::-webkit-scrollbar {
  display: none;
}

/* Esconde overlay direito + chips quando o sheet está aberto, pra evitar sobreposição */
html.is-mobile-pm.is-sheet-half .pm-map-corner-bottom,
html.is-mobile-pm.is-sheet-full .pm-map-corner-bottom,
html.is-mobile-pm.is-sheet-half .pm-map-corner-right,
html.is-mobile-pm.is-sheet-full .pm-map-corner-right,
html.is-mobile-pm.is-sheet-full .pm-map-corner-top-right {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
html.is-mobile-pm .pm-map-corner-bottom,
html.is-mobile-pm .pm-map-corner-right,
html.is-mobile-pm .pm-map-corner-top-right {
  transition: opacity 0.2s;
}

/* ── MODAIS aninhados no painel → full-screen mobile ──────────── */
html.is-mobile-pm .pm-modal-backdrop.open {
  align-items: stretch !important;
  padding: 0 !important;
}
html.is-mobile-pm .pm-modal-backdrop.open > .pm-modal {
  max-width: 100% !important;
  width: 100% !important;
  height: 100dvh !important;
  max-height: 100dvh !important;
  border-radius: 0 !important;
  margin: 0 !important;
  display: flex;
  flex-direction: column;
}
html.is-mobile-pm .pm-modal-head {
  padding-top: max(14px, env(safe-area-inset-top)) !important;
  position: sticky;
  top: 0;
  background: #FFFFFF;
  z-index: 2;
}
html.is-mobile-pm .pm-modal-body {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(20px + env(safe-area-inset-bottom)) !important;
}

/* Drawer existente vira full width em mobile */
html.is-mobile-pm .drawer {
  width: 100% !important;
  max-width: 100% !important;
}

/* User menu dropdown vira full width centrado */
html.is-mobile-pm .user-menu.open {
  right: 8px !important;
  left: 8px !important;
  width: auto !important;
  max-width: calc(100% - 16px) !important;
}

/* Footer estático some no mobile (já é redundante) */
html.is-mobile-pm .pm-app-footer {
  display: none !important;
}

/* Tutu chatbot — esconde quando sheet aberto */
html.is-mobile-pm.is-sheet-half .tutu-popup,
html.is-mobile-pm.is-sheet-full .tutu-popup {
  opacity: 0;
  pointer-events: none;
}

/* Inputs e selects mobile-friendly */
html.is-mobile-pm input[type="text"],
html.is-mobile-pm input[type="search"],
html.is-mobile-pm input[type="email"],
html.is-mobile-pm input[type="password"],
html.is-mobile-pm input[type="tel"],
html.is-mobile-pm input[type="number"],
html.is-mobile-pm select,
html.is-mobile-pm textarea {
  font-size: 16px !important; /* evita zoom automático iOS */
  min-height: 44px;
}

/* Touch targets — botões com pelo menos 36px */
html.is-mobile-pm button:not(.pm-sheet-handle):not(.pm-sb-tab):not(.source-btn) {
  min-height: 36px;
}

/* Quando o sheet está full, esconde o handle (já tem padding superior) */
html.is-mobile-pm.is-sheet-full .pm-sheet-handle::before {
  background: rgba(15, 35, 71, 0.12);
}

/* ── Telefones MUITO pequenos (≤ 380px) — compactação adicional ─ */
@media (max-width: 380px) {
  html.is-mobile-pm .topbar {
    padding: 0 6px !important;
  }
  html.is-mobile-pm .crumb {
    font-size: 14px !important;
  }
  html.is-mobile-pm #btnNotif {
    display: none !important; /* libera espaço */
  }
  html.is-mobile-pm .source-btn {
    font-size: 12.5px !important;
    padding: 7px 12px !important;
  }
  html.is-mobile-pm .pm-map-corner-right > * {
    width: 32px !important;
    min-width: 32px !important;
    max-width: 32px !important;
    height: 32px !important;
    min-height: 32px !important;
    max-height: 32px !important;
  }
  html.is-mobile-pm .pm-map-zoom-pill {
    width: 32px !important;
    min-width: 32px !important;
    max-width: 32px !important;
    height: 60px !important;
    min-height: 60px !important;
    max-height: 60px !important;
  }
  html.is-mobile-pm .pm-map-zoom-pill > * {
    width: 30px !important;
    min-width: 30px !important;
    height: 29px !important;
    min-height: 29px !important;
  }
}

/* ── Landscape em phones — sheet menor e handle mais discreto ── */
@media (max-width: 900px) and (max-height: 520px) and (orientation: landscape) {
  html.is-mobile-pm .pm-map-sidebar {
    height: 96dvh !important;
    max-height: 96dvh !important;
    transform: translateY(calc(100% - 56px));
  }
  html.is-mobile-pm.is-sheet-half .pm-map-sidebar {
    transform: translateY(40%);
  }
  html.is-mobile-pm .topbar {
    height: 48px !important;
    min-height: 48px !important;
    height: calc(48px + env(safe-area-inset-top)) !important;
  }
}
