/* ===========================================
   Cargill GeoDist - Estilos Personalizados
   Mobile-First PWA con Glassmorphism
   =========================================== */

/* Variables globales */
:root {
  --glass-bg: rgba(15, 23, 42, 0.72);
  --glass-border: rgba(255, 255, 255, 0.12);
  --glass-strong-bg: rgba(15, 23, 42, 0.88);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --marker-client: #34d399;
  --marker-prospect: #fbbf24;
}

/* Reset suave para PWA */
html, body, #map {
  height: 100%;
  width: 100%;
}

body {
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

/* Safe area para dispositivos con notch */
.pt-safe {
  padding-top: calc(1rem + var(--safe-top));
}

.pb-safe {
  padding-bottom: calc(1rem + var(--safe-bottom));
}

/* Componentes glassmorphism */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
}

.glass-strong {
  background: var(--glass-strong-bg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-top: 1px solid var(--glass-border);
}

.glass-card {
  background: rgba(30, 41, 59, 0.6);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Inputs y botones premium */
.input-field {
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.input-field::placeholder {
  color: rgba(148, 163, 184, 0.6);
}

.btn-primary {
  background: linear-gradient(135deg, #10b981 0%, #06b6d4 100%);
  transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.btn-primary:hover {
  filter: brightness(1.08);
  box-shadow: 0 10px 25px -5px rgba(16, 185, 129, 0.35);
}

.btn-primary:active {
  transform: scale(0.97);
}

/* ===============================
   Mapa - Tema oscuro minimalista
   =============================== */
#map {
  z-index: 0;
}

/* Filtro de brillo/saturación para tiles claros */
.leaflet-layer {
  filter: brightness(0.85) contrast(1.05) saturate(0.85);
}

/* Controles de Leaflet estilizados */
.leaflet-control-zoom {
  border: none !important;
  border-radius: 1rem !important;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35) !important;
}

.leaflet-control-zoom a {
  width: 36px !important;
  height: 36px !important;
  line-height: 36px !important;
  background: var(--glass-bg) !important;
  color: #e2e8f0 !important;
  border: 1px solid var(--glass-border) !important;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  font-size: 18px !important;
  transition: background 0.2s ease;
}

.leaflet-control-zoom a:hover {
  background: rgba(30, 41, 59, 0.9) !important;
  color: #fff !important;
}

.leaflet-control-attribution {
  background: rgba(15, 23, 42, 0.65) !important;
  color: #94a3b8 !important;
  font-size: 10px !important;
  backdrop-filter: blur(4px);
  border-top-left-radius: 8px;
}

.leaflet-control-attribution a {
  color: #cbd5e1 !important;
}

/* ===============================
   Marcadores personalizados
   =============================== */
.custom-marker {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  border: 2px solid rgba(255, 255, 255, 0.85);
}

.custom-marker::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: inherit;
  opacity: 0.45;
  filter: blur(6px);
  z-index: -1;
}

.custom-marker:hover,
.custom-marker:focus {
  transform: rotate(-45deg) scale(1.15);
  z-index: 1000 !important;
}

.custom-marker.client {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.custom-marker.client::after {
  background: #10b981;
}

.custom-marker.prospect {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
}

.custom-marker.prospect::after {
  background: #f59e0b;
}

.custom-marker-inner {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* Pulse animado en marcadores */
@keyframes marker-pulse {
  0% {
    transform: scale(1);
    opacity: 0.5;
  }
  70% {
    transform: scale(2.2);
    opacity: 0;
  }
  100% {
    transform: scale(2.2);
    opacity: 0;
  }
}

.custom-marker::before {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: inherit;
  opacity: 0.5;
  animation: marker-pulse 2.4s infinite;
  z-index: -1;
}

/* ===============================
   Bottom Sheet
   =============================== */
#bottom-sheet.open {
  transform: translateY(0);
}

#bottom-sheet.open + #sheet-overlay,
#sheet-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

/* ===============================
   Animaciones auxiliares
   =============================== */
@keyframes fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-fade-in {
  animation: fade-in 0.4s ease-out forwards;
}

/* ===============================
   Scrollbar minimalista
   =============================== */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.35);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.55);
}

/* ===============================
   Utilidades responsive
   =============================== */
@media (min-width: 768px) {
  #bottom-sheet > div {
    border-radius: 1.5rem 1.5rem 0 0;
  }
}

@media (max-width: 640px) {
  .leaflet-control-zoom {
    display: none;
  }
}

/* Modo oscuro del sistema ya aplicado por defecto */
@media (prefers-color-scheme: light) {
  /* Mantenemos tema oscuro consistente para la PWA */
  :root {
    --glass-bg: rgba(15, 23, 42, 0.78);
  }
}

/* ===============================
   Clusters de marcadores
   =============================== */
.marker-cluster .cluster-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50% !important;
  color: white;
  font-weight: 700;
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4), inset 0 1px 2px rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(4px);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.marker-cluster .cluster-marker:hover,
.marker-cluster .cluster-marker:focus {
  transform: scale(1.12);
  z-index: 1000 !important;
}

/* Animación de pulso en clusters */
.marker-cluster .cluster-marker::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: inherit;
  opacity: 0.4;
  filter: blur(6px);
  z-index: -1;
  animation: marker-pulse 2.4s infinite;
}

/* Anillo exterior sutil */
.marker-cluster .cluster-marker::after {
  content: '';
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.15);
  z-index: -2;
}

/* Reducir animaciones si el usuario lo solicita */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
