@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --bg-primary: #0a0f1d;
  --bg-secondary: #0f172a;
  --bg-card: rgba(15, 23, 42, 0.75);
  --border-card: rgba(255, 255, 255, 0.08);
  --accent-red: #ef4444;
  --accent-amber: #f59e0b;
  --accent-blue: #3b82f6;
  --accent-purple: #a855f7;
  --accent-emerald: #10b981;
}

body {
  font-family: 'Plus Jakarta Sans', sans-serif;
  background-color: var(--bg-primary);
  color: #f1f5f9;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* Permitir seleção e edição total nos campos de pesquisa e texto */
input, textarea, [contenteditable="true"] {
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
  user-select: text;
}

.font-mono {
  font-family: 'JetBrains Mono', monospace;
}

/* Glassmorphism Card */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-card);
}

.glass-card:hover {
  border-color: rgba(255, 255, 255, 0.15);
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: #0f172a;
}
::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #475569;
}

/* Leaflet Map Responsive Overrides */
#map {
  width: 100%;
  height: 650px;
  min-height: 480px;
  max-height: 750px;
  border-radius: 1rem;
  z-index: 10;
}

#mapWrapper.is-fullscreen #map {
  max-height: none !important;
  min-height: 0 !important;
}

@media (max-width: 1024px) {
  #map {
    height: 540px;
    min-height: 440px;
  }
}

@media (max-width: 640px) {
  #map {
    height: min(520px, 66vh) !important;
    min-height: 380px !important;
    border-radius: 0.75rem;
  }
}

@media (max-width: 380px) {
  #map {
    height: 380px !important;
    min-height: 320px !important;
  }
}

/* Leaflet Popups - Responsive, Elegant Glassmorphism & Touch-Friendly */
.leaflet-popup {
  margin-bottom: 18px;
}

.leaflet-popup-content-wrapper {
  background: rgba(15, 23, 42, 0.96) !important;
  color: #f8fafc !important;
  border-radius: 1rem !important;
  border: 1px solid rgba(51, 65, 85, 0.85) !important;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.7), 0 8px 10px -6px rgba(0, 0, 0, 0.5) !important;
  backdrop-filter: blur(14px) !important;
  -webkit-backdrop-filter: blur(14px) !important;
  padding: 0 !important;
}

.leaflet-popup-content {
  margin: 12px 14px !important;
  line-height: 1.4 !important;
  max-height: 340px !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
}

.leaflet-popup-tip-container {
  overflow: visible;
}

.leaflet-popup-tip {
  background: #0f172a !important;
  border: 1px solid rgba(51, 65, 85, 0.85) !important;
}

/* Botão Fechar do Popup: Tamanho Grande e Táctil em Mobile */
.leaflet-container a.leaflet-popup-close-button {
  top: 8px !important;
  right: 8px !important;
  width: 28px !important;
  height: 28px !important;
  padding: 0 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  border-radius: 9999px !important;
  background: rgba(30, 41, 59, 0.95) !important;
  border: 1px solid rgba(71, 85, 105, 0.8) !important;
  color: #cbd5e1 !important;
  font-size: 16px !important;
  font-weight: 700 !important;
  line-height: 1 !important;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.4) !important;
  transition: all 0.15s ease !important;
  z-index: 100 !important;
  text-decoration: none !important;
  cursor: pointer !important;
}

.leaflet-container a.leaflet-popup-close-button:hover,
.leaflet-container a.leaflet-popup-close-button:active {
  background: #ef4444 !important;
  color: #ffffff !important;
  border-color: #ef4444 !important;
  transform: scale(1.08);
}

@media (max-width: 640px) {
  .leaflet-popup {
    max-width: calc(100vw - 28px) !important;
  }
  .leaflet-popup-content-wrapper {
    border-radius: 0.875rem !important;
  }
  .leaflet-popup-content {
    margin: 10px 12px !important;
    max-height: 250px !important;
    width: auto !important;
  }
  .leaflet-container a.leaflet-popup-close-button {
    width: 32px !important;
    height: 32px !important;
    font-size: 20px !important;
    top: 6px !important;
    right: 6px !important;
  }
}

/* Scrollbar fina para listas do painel de camadas e popups */
.custom-scrollbar::-webkit-scrollbar {
  width: 4px;
}
.custom-scrollbar::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.4);
}
.custom-scrollbar::-webkit-scrollbar-thumb {
  background: #475569;
  border-radius: 9999px;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
  background: #64748b;
}

/* Live Pulse Animation */
@keyframes pulse-ring {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.3); opacity: 0; }
  100% { transform: scale(0.95); opacity: 0; }
}

.pulse-circle {
  position: relative;
}

.pulse-circle::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  border-radius: 50%;
  border: 2px solid currentColor;
  animation: pulse-ring 2s infinite ease-out;
}

/* Marcador GPS de Localização do Utilizador */
@keyframes gps-beacon-pulse {
  0% { transform: scale(0.6); opacity: 0.9; }
  60% { opacity: 0.4; }
  100% { transform: scale(2.8); opacity: 0; }
}

.gps-marker-pulse {
  animation: gps-beacon-pulse 2s cubic-bezier(0, 0, 0.2, 1) infinite;
}

/* Sismo mais recente - Ondas de choque / Ripple Radar Multi-anel */
@keyframes sismo-shockwave {
  0% {
    transform: scale(0.6);
    opacity: 0.95;
    box-shadow: 0 0 0 0 currentColor;
  }
  60% {
    opacity: 0.6;
  }
  100% {
    transform: scale(3.8);
    opacity: 0;
    box-shadow: 0 0 16px 2px currentColor;
  }
}

@keyframes sismo-core-pulse {
  0%, 100% {
    transform: scale(1);
    filter: drop-shadow(0 0 4px currentColor);
  }
  50% {
    transform: scale(1.35);
    filter: drop-shadow(0 0 12px currentColor);
  }
}

.sismo-latest-container {
  position: relative;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  cursor: pointer;
  overflow: visible !important;
}

.sismo-latest-core {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: currentColor;
  border: 1.5px solid #ffffff;
  animation: sismo-core-pulse 1.6s ease-in-out infinite;
  z-index: 3;
}

.sismo-latest-wave {
  position: absolute;
  top: 0;
  left: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid currentColor;
  animation: sismo-shockwave 2.1s cubic-bezier(0.2, 0.6, 0.4, 1) infinite;
  pointer-events: none;
  z-index: 1;
}

.sismo-latest-wave.wave-2 {
  animation-delay: 0.7s;
}

.sismo-latest-wave.wave-3 {
  animation-delay: 1.4s;
}

.sismo-latest-badge {
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid currentColor;
  color: #ffffff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  z-index: 10;
}

/* Custom marker – limpa qualquer fundo de container Leaflet */
.custom-leaflet-marker {
  background: transparent !important;
  border: none !important;
  overflow: visible !important;
}

/* Custom badge styling */
.badge-red {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.badge-amber {
  background: rgba(245, 158, 11, 0.15);
  color: #fcd34d;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-blue {
  background: rgba(59, 130, 246, 0.15);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.badge-purple {
  background: rgba(168, 85, 247, 0.15);
  color: #d8b4fe;
  border: 1px solid rgba(168, 85, 247, 0.3);
}

.badge-green {
  background: rgba(16, 185, 129, 0.15);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

/* Marcadores Meteorológicos IPMA e Polígonos Iluminados (Estilo da Imagem) */
.ipma-polygon-beacon-container {
  position: relative;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: visible !important;
}

.ipma-beacon-halo-outer {
  position: absolute;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background-color: var(--ipma-color, #eab308);
  opacity: 0.28;
  animation: ipma-beacon-pulse 2s ease-out infinite;
}

.ipma-beacon-halo-mid {
  position: absolute;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: var(--ipma-color, #eab308);
  opacity: 0.5;
}

.ipma-beacon-core {
  position: relative;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background-color: var(--ipma-color, #eab308);
  border: 2px solid #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 14px var(--ipma-color, #eab308);
  color: #0f172a; /* Ícone escuro como no exemplo do utilizador */
  font-size: 13px;
  font-weight: 900;
  z-index: 5;
  transition: transform 0.2s ease;
}

.ipma-polygon-beacon-container:hover .ipma-beacon-core {
  transform: scale(1.15);
}

@keyframes ipma-beacon-pulse {
  0% { transform: scale(0.8); opacity: 0.45; }
  50% { transform: scale(1.4); opacity: 0.15; }
  100% { transform: scale(0.8); opacity: 0.45; }
}

.ipma-polygon-banner {
  position: absolute;
  top: 36px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  background-color: var(--ipma-color, #eab308);
  color: #0f172a;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 10px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 6px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.7);
  pointer-events: none;
  z-index: 10;
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.ipma-weather-polygon {
  filter: drop-shadow(0 0 6px var(--ipma-color, #eab308));
  pointer-events: none !important; /* Cliques passam 100% diretos para os marcadores e mapa por baixo */
}

/* Marcadores de Qualidade do Ar (Open-Meteo) */
.air-quality-marker {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #ffffff;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.6);
  cursor: pointer;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.air-quality-marker:hover {
  transform: scale(1.22);
  z-index: 9999 !important;
}

/* Marcadores de Dados Hidrográficos (Open-Meteo Flood / Copernicus) */
.hidro-marker {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #ffffff;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.6);
  cursor: pointer;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.hidro-marker:hover {
  transform: scale(1.22);
  z-index: 9999 !important;
}

/* Marcadores de Radiação Gama (OpenRadiation / Safecast / RADNET) */
.radiacao-marker {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #ffffff;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.6);
  cursor: pointer;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.radiacao-marker:hover {
  transform: scale(1.22);
  z-index: 9999 !important;
}

/* Marcadores de Barras e Agitação Marítima (Instituto Hidrográfico / AMN) */
.barra-marker {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #ffffff;
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.7);
  cursor: pointer;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.barra-marker:hover {
  transform: scale(1.25);
  z-index: 9999 !important;
}

/* Marcadores de Infraestruturas Elétricas e Centrais (REN) */
.energia-marker {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #ffffff;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.7);
  cursor: pointer;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.energia-marker:hover {
  transform: scale(1.25);
  z-index: 9999 !important;
}

/* Utilitários para ecrãs pequenos e mobile */
.no-scrollbar::-webkit-scrollbar {
  display: none !important;
}
.no-scrollbar {
  -ms-overflow-style: none !important;
  scrollbar-width: none !important;
  -webkit-overflow-scrolling: touch;
}

.nav-tab {
  white-space: nowrap !important;
  user-select: none;
  min-width: 0;
  transition: all 0.15s ease-in-out;
}

.nav-tab span {
  white-space: nowrap;
}

@media (max-width: 1023px) {
  .nav-tab {
    padding-left: 0.85rem !important;
    padding-right: 0.85rem !important;
    padding-top: 0.55rem !important;
    padding-bottom: 0.55rem !important;
    font-size: 0.78rem !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
    background: rgba(15, 23, 42, 0.85) !important;
    border: 1px solid rgba(51, 65, 85, 0.75) !important;
    border-radius: 0.75rem !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25) !important;
  }

  .nav-tab.active {
    background: #dc2626 !important;
    border-color: #ef4444 !important;
    color: #ffffff !important;
    box-shadow: 0 4px 14px rgba(220, 38, 38, 0.4) !important;
  }
}

@media (max-width: 640px) {
  .nav-tab {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
    padding-top: 0.5rem !important;
    padding-bottom: 0.5rem !important;
    font-size: 0.74rem !important;
  }

  .glass-card {
    padding: 0.75rem !important;
    border-radius: 1rem !important;
  }
}

/* Modo Ecrã Inteiro do Mapa (Imersivo estilo App em Qualquer Resolução) */
#mapWrapper.is-fullscreen {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  height: 100dvh !important;
  max-width: 100vw !important;
  max-height: 100vh !important;
  max-height: 100dvh !important;
  z-index: 99999 !important;
  border-radius: 0 !important;
  border: none !important;
  padding: 0 !important;
  margin: 0 !important;
  background: #0a0f1d !important;
  box-shadow: none !important;
  overflow: hidden !important;
}

/* Forçar o #map e todos os containers do Leaflet a ocuparem 100% da janela em fullscreen */
#mapWrapper.is-fullscreen #map,
#mapWrapper.is-fullscreen #map.leaflet-container,
#mapWrapper.is-fullscreen .leaflet-container {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100% !important;
  height: 100% !important;
  max-height: none !important;
  min-height: 100% !important;
  border-radius: 0 !important;
  margin: 0 !important;
  z-index: 1 !important;
}

/* Botões de Ação DENTRO do Mapa ancorados ao canto inferior direito com garantia z-index */
#mapWrapper.is-fullscreen .floating-map-actions {
  position: absolute !important;
  bottom: calc(3rem + env(safe-area-inset-bottom, 0px)) !important;
  right: calc(1rem + env(safe-area-inset-right, 0px)) !important;
  z-index: 999999 !important;
}

#mapWrapper.is-fullscreen #layersPanelWrapper {
  position: absolute !important;
  top: calc(0.75rem + env(safe-area-inset-top, 0px)) !important;
  left: calc(0.75rem + env(safe-area-inset-left, 0px)) !important;
  z-index: 999999 !important;
}

/* Estilo das Atribuições / Contributors do Leaflet - 100% Legíveis e Completas */
.leaflet-bottom.leaflet-right {
  max-width: 100% !important;
  pointer-events: auto;
}

.leaflet-control-attribution {
  background: rgba(10, 15, 29, 0.85) !important;
  color: #94a3b8 !important;
  font-size: 9.5px !important;
  line-height: 1.3 !important;
  padding: 3px 8px !important;
  border-top-left-radius: 6px !important;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.35);
  white-space: normal !important; /* Permite quebrar em linhas no telemóvel para mostrar tudo */
  text-align: right !important;
}

.leaflet-control-attribution a {
  color: #38bdf8 !important;
  text-decoration: underline !important;
}



/* Ajuste do container Leaflet */
#mapWrapper.is-fullscreen .leaflet-container {
  width: 100% !important;
  height: 100% !important;
}


