/* Map layout */
.mapa-layout {
  display: flex;
  height: calc(100vh - 60px);
  margin-top: 60px;
}

/* Sidebar */
.mapa-sidebar {
  width: 320px;
  flex-shrink: 0;
  background: var(--color-branco);
  border-right: 1px solid var(--color-verde-muted);
  overflow-y: auto;
  z-index: 10;
  display: flex;
  flex-direction: column;
}

/* Desktop: collapsible sidebar */
@media (min-width: 768px) {
  .mapa-sidebar {
    transition: width 300ms ease;
  }

  .mapa-sidebar.collapsed {
    width: 0;
    overflow: hidden;
  }

  .mapa-sidebar:not(.collapsed) {
    overflow-y: auto;
  }

  .sidebar-toggle {
    position: fixed;
    left: 320px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 56px;
    background: var(--color-verde-escuro);
    color: white;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1600;
    transition: left 300ms ease, background var(--transition-fast);
    font-size: 14px;
    font-weight: 700;
    border: none;
    user-select: none;
  }

  .sidebar-toggle:hover {
    background: var(--color-verde-medio);
  }
}

@media (max-width: 767px) {
  .sidebar-toggle {
    display: none;
  }
}

.mapa-sidebar__section {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-fundo-alt);
}

.mapa-sidebar__section-title {
  font-size: var(--text-sm);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-texto-muted);
  margin-bottom: var(--space-3);
}

/* Rota cards */
.rota-card {
  border: 1px solid var(--color-verde-muted);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-2);
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow var(--transition-fast);
}

.rota-card:hover {
  box-shadow: var(--shadow-sm);
}

.rota-card.active {
  box-shadow: var(--shadow-md);
  border-color: transparent;
}

.rota-card__header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
}

.rota-card__color {
  width: 12px;
  height: 12px;
  border-radius: var(--radius-pill);
  flex-shrink: 0;
}

.rota-card__name {
  flex: 1;
  font-weight: 600;
  font-size: var(--text-sm);
}

.rota-card__duration {
  font-size: var(--text-xs);
  color: var(--color-texto-muted);
  white-space: nowrap;
}

.rota-card__body {
  display: none;
  padding: var(--space-3) var(--space-4);
  background: var(--color-fundo);
  border-top: 1px solid var(--color-verde-muted);
}

.rota-card.active .rota-card__body {
  display: block;
}

.rota-card__descricao {
  font-size: var(--text-sm);
  color: var(--color-texto-muted);
  margin-bottom: var(--space-3);
}

.rota-card__pontos-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.rota-card__ponto-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  opacity: 0;
  transform: translateY(8px);
  transition: all 200ms ease;
}

.rota-card__ponto-item.visible {
  opacity: 1;
  transform: translateY(0);
}

.rota-card__ponto-num {
  width: 20px;
  height: 20px;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

/* Category badges */
.categorias-filter {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.categoria-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 600;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  background: var(--color-fundo-alt);
  color: var(--color-texto-muted);
  min-height: 32px;
}

.categoria-badge:hover {
  border-color: currentColor;
}

.categoria-badge.active {
  color: white;
}

/* Points list */
.pontos-list {
  display: flex;
  flex-direction: column;
}

.ponto-list-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--color-fundo-alt);
  cursor: pointer;
  text-decoration: none;
  color: var(--color-texto);
  transition: background var(--transition-fast);
}

.ponto-list-item:hover {
  background: var(--color-fundo-alt);
  text-decoration: none;
}

.ponto-list-item__dot {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-pill);
  flex-shrink: 0;
}

.ponto-list-item__name {
  flex: 1;
  font-size: var(--text-sm);
  font-weight: 500;
}

.ponto-list-item__cat {
  font-size: var(--text-xs);
  color: var(--color-texto-muted);
}

/* Map container */
.mapa-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.mapa-placeholder {
  width: 100%;
  height: 100%;
  background: var(--color-bege);
  border: 2px dashed var(--color-verde-medio);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: var(--space-3);
  color: var(--color-texto-muted);
  font-size: var(--text-lg);
}

#mapa-leaflet {
  width: 100%;
  height: 100%;
}

/* Leaflet popup customization */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-md) !important;
  font-family: var(--font-body) !important;
  padding: 0 !important;
}

.leaflet-popup-content {
  margin: 0 !important;
  width: auto !important;
}

.mapa-popup {
  padding: var(--space-4);
  min-width: 200px;
}

.mapa-popup__nome {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  margin-bottom: var(--space-2);
}

.mapa-popup__badges {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin-bottom: var(--space-3);
}

/* FAB mobile */
.fab-mapa {
  display: none;
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  width: 56px;
  height: 56px;
  border-radius: var(--radius-pill);
  background: var(--color-verde-escuro);
  color: white;
  box-shadow: var(--shadow-lg);
  align-items: center;
  justify-content: center;
  z-index: 1500;
  transition: transform var(--transition-fast);
}

.fab-mapa:hover {
  transform: scale(1.05);
}

.fab-mapa svg {
  width: 24px;
  height: 24px;
}

/* Bottom sheet — mobile */
@media (max-width: 767px) {
  .mapa-layout {
    flex-direction: column;
    position: relative;
  }

  .mapa-sidebar {
    width: 100%;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 45vh;
    border-right: none;
    border-top: 1px solid var(--color-verde-muted);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    z-index: 1200;
    transform: translateY(calc(100% - 52px));
    transition: transform 350ms cubic-bezier(0.32, 0.72, 0, 1);
    box-shadow: var(--shadow-lg);
    overflow-y: auto;
  }

  .mapa-sidebar.expanded {
    height: 72vh;
    transform: translateY(0);
  }

  .mapa-sidebar__handle {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: var(--space-3) 0 var(--space-2);
    cursor: grab;
    flex-shrink: 0;
    min-height: 44px;
  }

  .mapa-sidebar__handle-bar {
    width: 40px;
    height: 4px;
    background: var(--color-verde-muted);
    border-radius: var(--radius-pill);
  }

  .mapa-container {
    height: calc(100vh - 60px);
    position: relative;
  }

  .fab-mapa {
    display: flex;
    bottom: 80px;
  }

  /* Bigger touch targets on mobile */
  .rota-card__header {
    padding: var(--space-4);
    min-height: 52px;
  }

  .ponto-list-item {
    min-height: 52px;
  }

  .categoria-badge {
    min-height: 40px;
    padding: var(--space-2) var(--space-3);
  }
}

/* Loading splash */
.mapa-splash {
  position: absolute;
  inset: 0;
  z-index: 800;
  background: var(--color-fundo);
  display: flex;
  align-items: center;
  justify-content: center;
}

.mapa-splash__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
}

.mapa-splash__logo {
  animation: splash-pulse 1.6s ease-in-out infinite;
}

.mapa-splash__text {
  font-size: var(--text-sm);
  color: var(--color-texto-muted);
  font-weight: 500;
}

.mapa-splash__dots {
  display: flex;
  gap: var(--space-2);
}

.mapa-splash__dots span {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--color-verde-medio);
  animation: splash-dot 1.2s ease-in-out infinite;
}

.mapa-splash__dots span:nth-child(2) { animation-delay: 0.2s; }
.mapa-splash__dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes splash-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%       { transform: scale(1.06); opacity: 0.85; }
}

@keyframes splash-dot {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40%            { transform: translateY(-6px); opacity: 1; }
}


/* Visit order badge — shown on pins when route is active */
.visit-badge {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: white;
  border: 2px solid white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.45);
  z-index: 10;
  pointer-events: none;
  animation: badge-pop 450ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes badge-pop {
  0%   { transform: scale(0) rotate(-15deg); opacity: 0; }
  100% { transform: scale(1) rotate(0deg);   opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .visit-badge { animation: none; }
}

/* Pin pulse animation */
@keyframes pin-pulse {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.35); }
  100% { transform: scale(1); }
}

.pin-pulsing {
  animation: pin-pulse 600ms ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .pin-pulsing { animation: none; }
  .mapa-sidebar { transition: none; }
  .mapa-splash__logo { animation: none; }
  .mapa-splash__dots span { animation: none; opacity: 1; }
}

/* Skeleton for sidebar */
.skeleton-item {
  height: 48px;
  margin-bottom: var(--space-2);
}

.skeleton-rota {
  height: 56px;
}

/* Maintenance pin pulse */
.pin-manutencao {
  animation: pin-manutencao-pulse 2s ease-in-out infinite;
}

@keyframes pin-manutencao-pulse {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(245,158,11,0)); }
  50%       { filter: drop-shadow(0 0 6px rgba(245,158,11,0.7)); }
}

@media (prefers-reduced-motion: reduce) {
  .pin-manutencao { animation: none; }
}

/* Maintenance badge in sidebar list */
.ponto-list-item--manutencao {
  background: rgba(245,158,11,0.06);
}

.ponto-list-item--manutencao:hover {
  background: rgba(245,158,11,0.12);
}

.ponto-list-item__status-badge {
  font-size: var(--text-xs);
  font-weight: 600;
  flex-shrink: 0;
}

/* Popup maintenance warning */
.mapa-popup__manutencao {
  background: #FEF3C7;
  color: #92400E;
  font-size: var(--text-xs);
  font-weight: 600;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-3);
}
