/* Reset e base */
* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  height: -webkit-fill-available; /* Para mobile browsers */
  margin: 0;
  padding: 0;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Mapa */
#map {
  width: 100%;
  height: 100vh;
  height: -webkit-fill-available; /* Para mobile browsers */
  position: absolute;
  inset: 0;
  z-index: 0;
}

/* Alpine.js cloak */
[x-cloak] {
  display: none !important;
}

/* Scroll customizado */
.custom-scrollbar::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.custom-scrollbar::-webkit-scrollbar-track {
  background: #1e293b;
  border-radius: 4px;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
  background: #475569;
  border-radius: 4px;
  transition: background 0.2s;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
  background: #64748b;
}

/* Animações customizadas */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideIn {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(0);
  }
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.animate-fade-in {
  animation: fadeIn 0.3s ease-out;
}

.animate-slide-in {
  animation: slideIn 0.3s ease-out;
}

/* Estilos do Leaflet customizados */
.leaflet-popup-content-wrapper {
  background: #1e293b;
  color: #f1f5f9;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.leaflet-popup-content {
  margin: 12px;
  font-size: 14px;
}

.leaflet-popup-tip {
  background: #1e293b;
}

.leaflet-container {
  background: #0f172a;
}

/* Marcadores customizados */
.leaflet-marker-icon {
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

/* Marcador de início (verde) */
.waypoint-marker.start {
  z-index: 1000 !important;
}

/* Marcador de fim (vermelho) */
.waypoint-marker.end {
  z-index: 1000 !important;
}

/* Setas de direção da rota */
.route-arrow {
  pointer-events: none;
  z-index: 500 !important;
}

.route-arrow div {
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.8);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}

/* Loading spinner */
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.animate-spin {
  animation: spin 1s linear infinite;
}

/* Toast notifications customizadas */
.toast {
  min-width: 300px;
  padding: 16px;
  border-radius: 12px;
  background: #1e293b;
  border: 1px solid #334155;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  animation: fadeIn 0.3s ease-out;
  margin-bottom: 12px;
}

.toast-success {
  border-left: 4px solid #10b981;
}

.toast-error {
  border-left: 4px solid #ef4444;
}

.toast-warning {
  border-left: 4px solid #f59e0b;
}

.toast-info {
  border-left: 4px solid #3b82f6;
}

/* Safe Area para dispositivos com notch (iPhone X+) */
.safe-area-top {
  padding-top: env(safe-area-inset-top);
}

.safe-area-bottom {
  padding-bottom: env(safe-area-inset-bottom);
  margin-bottom: env(safe-area-inset-bottom);
}

.safe-area-inset {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* Touch optimization */
.touch-manipulation {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

/* Responsividade Mobile */
@media (max-width: 768px) {
  /* Prevenir overflow horizontal */
  body, html {
    overflow-x: hidden !important;
    width: 100% !important;
    max-width: 100vw !important;
  }
  
  #app {
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
  }
  
  /* Prevenir zoom indesejado no input focus */
  input[type="text"],
  input[type="number"],
  textarea,
  select {
    font-size: 16px !important;
  }
  
  aside.mobile-panel {
    width: calc(100vw - 0.5rem) !important;
    max-width: calc(100vw - 0.5rem) !important;
    left: 0.25rem !important;
    right: 0.25rem !important;
    top: 3.5rem !important;
    transition: max-height 0.3s ease, transform 0.3s ease;
    box-sizing: border-box !important;
  }
  
  /* Ajustar para safe area */
  @supports (padding: env(safe-area-inset-left)) {
    aside.mobile-panel {
      left: max(0.25rem, env(safe-area-inset-left)) !important;
      right: max(0.25rem, env(safe-area-inset-right)) !important;
      width: calc(100vw - max(0.25rem, env(safe-area-inset-left)) - max(0.25rem, env(safe-area-inset-right))) !important;
      max-width: calc(100vw - max(0.25rem, env(safe-area-inset-left)) - max(0.25rem, env(safe-area-inset-right))) !important;
    }
  }
  
  /* Modo compacto mobile - apenas barra superior */
  aside.mobile-panel.mobile-compact {
    /* permitir que o conteúdo interno determine a altura quando necessário
       (evita corte em dispositivos com variações de safe-area e fontes maiores) */
    max-height: none !important;
    height: auto !important;
    overflow: visible !important;
    padding-bottom: env(safe-area-inset-bottom);
  }
  
  /* Modo expandido mobile - painel completo */
  aside.mobile-panel.mobile-expanded {
    max-height: calc(100vh - 3.5rem - env(safe-area-inset-bottom)) !important;
    height: auto !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
  }
  
  /* Esconder views no modo compacto */
  aside.mobile-panel.mobile-compact .mobile-expanded-view {
    display: none !important;
  }
  
  /* Mostrar view compacta */
  aside.mobile-panel.mobile-compact .mobile-compact-view {
    display: block !important;
  }

  /* Garantir altura mínima para o compact view e evitar que itens sejam cortados */
  .mobile-compact-view {
    min-height: 3.5rem !important;
    display: flex !important;
    align-items: center !important;
    gap: 0.5rem !important;
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
    box-sizing: border-box !important;
  }
  
  /* Esconder view compacta quando expandido */
  aside.mobile-panel.mobile-expanded .mobile-compact-view {
    display: none !important;
  }
  
  /* Header mobile mais compacto */
  header {
    padding: 0.5rem 0.75rem !important;
    min-height: 3.5rem;
  }
  
  header h1 {
    font-size: 0.875rem !important;
    line-height: 1.2;
  }
  
  /* Painel compacto mobile - ajustes finos */
  .mobile-compact-view {
    padding: 0.5rem !important;
    box-sizing: border-box !important;
  }
  
  .mobile-compact-view .text-sm {
    font-size: 0.75rem !important;
  }
  
  .mobile-compact-view .text-xs {
    font-size: 0.65rem !important;
  }
  
  /* Painel lateral mobile - evitar overflow */
  aside .p-4,
  aside .p-3 {
    padding: 0.75rem !important;
    box-sizing: border-box !important;
  }
  
  aside .mobile-expanded-view {
    box-sizing: border-box !important;
    overflow-x: hidden !important;
  }
  
  /* Botões mobile - garantir touch targets de 44px */
  aside button,
  button.touch-manipulation {
    padding: 0.75rem 1rem !important;
    font-size: 0.875rem !important;
    min-height: 44px !important;
    min-width: 44px !important;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }
  
  /* Modal mobile - melhor uso do espaço */
  .fixed.inset-0 {
    padding: 0.5rem !important;
    align-items: flex-end !important;
  }
  
  .fixed.inset-0 > div {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    border-radius: 1rem 1rem 0 0 !important;
  }
  
  /* Toast mobile - melhor posicionamento */
  #toast-container {
    bottom: 5rem !important;
    right: 0.5rem !important;
    left: 0.5rem !important;
    max-width: calc(100vw - 1rem) !important;
  }
  
  .toast {
    min-width: auto !important;
    width: 100% !important;
    padding: 12px !important;
    font-size: 0.875rem !important;
  }
  
  /* Mapa mobile - melhor touch e performance */
  #map {
    touch-action: pan-x pan-y pinch-zoom;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-overflow-scrolling: touch;
  }
  
  /* Lista de paradas mobile */
  .space-y-2 > * {
    margin-bottom: 0.5rem;
  }
  
  /* Grid de estatísticas mobile */
  .grid.grid-cols-2 {
    gap: 0.5rem !important;
  }
  
  .grid.grid-cols-2 > div {
    padding: 0.75rem !important;
  }
  
  .grid.grid-cols-2 .text-2xl {
    font-size: 1.25rem !important;
  }
  
  /* Inputs mobile - melhor área de toque */
  input[type="text"],
  input[type="number"] {
    min-height: 44px !important;
    padding: 0.75rem 1rem !important;
  }
  
  /* Botões de ação mobile */
  .mobile-expanded-view button {
    min-height: 44px !important;
    touch-action: manipulation;
  }
}

/* Mobile muito pequeno */
@media (max-width: 480px) {
  aside.mobile-panel {
    width: calc(100vw - 0.5rem) !important;
    max-width: calc(100vw - 0.5rem) !important;
    left: 0.25rem !important;
    right: 0.25rem !important;
    border-radius: 0.75rem !important;
    max-height: calc(100vh - 3.5rem - env(safe-area-inset-bottom)) !important;
    box-sizing: border-box !important;
  }
  
  @supports (padding: env(safe-area-inset-left)) {
    aside.mobile-panel {
      left: max(0.25rem, env(safe-area-inset-left)) !important;
      right: max(0.25rem, env(safe-area-inset-right)) !important;
      width: calc(100vw - max(0.25rem, env(safe-area-inset-left)) - max(0.25rem, env(safe-area-inset-right))) !important;
      max-width: calc(100vw - max(0.25rem, env(safe-area-inset-left)) - max(0.25rem, env(safe-area-inset-right))) !important;
    }
  }
  
  aside.mobile-panel.mobile-expanded {
    max-height: calc(100vh - 3.5rem - env(safe-area-inset-bottom)) !important;
  }
  
  header {
    padding: 0.5rem !important;
  }
  
  header h1 {
    font-size: 0.875rem !important;
  }
  
  .mobile-compact-view {
    padding: 0.4rem !important;
  }
  
  /* Textos menores em telas muito pequenas */
  .text-sm {
    font-size: 0.8125rem !important;
  }
  
  .text-xs {
    font-size: 0.6875rem !important;
  }
  
  /* Botões ainda menores em telas pequenas mas mantendo 44px mínimo */
  button {
    padding: 0.625rem 0.875rem !important;
  }
}

/* Landscape mobile */
@media (max-width: 768px) and (orientation: landscape) {
  aside.mobile-panel.mobile-expanded {
    max-height: calc(100vh - 3.5rem - env(safe-area-inset-bottom)) !important;
  }
  
  header {
    padding: 0.375rem 0.75rem !important;
    min-height: 3rem;
  }
  
  .fixed.inset-0 {
    padding: 0.25rem !important;
    align-items: center !important;
  }
}

/* Melhorias de acessibilidade */
button:focus-visible,
input:focus-visible {
  outline: 2px solid #10b981;
  outline-offset: 2px;
}

/* Transições suaves - otimizadas para performance mobile */
* {
  transition-property: color, background-color, border-color, transform, opacity;
  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
  transition-duration: 150ms;
}

/* Efeitos de hover melhorados - desabilitar em mobile para performance */
@media (hover: hover) {
  button:hover:not(:disabled) {
    transform: translateY(-1px);
  }
}

button:active {
  transform: translateY(0) scale(0.98);
}

/* Melhorias de performance mobile */
@media (max-width: 768px) {
  * {
    /* Reduzir animações em mobile para melhor performance */
    transition-duration: 120ms;
  }
  
  /* Desabilitar transform em hover para melhor performance */
  button:hover {
    transform: none !important;
  }
  
  button:active {
    transform: scale(0.96) !important;
    opacity: 0.9;
  }
}

/* Gradientes animados */
@keyframes gradient {
  0%, 100% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
}

.bg-gradient-animated {
  background-size: 200% 200%;
  animation: gradient 3s ease infinite;
}

