/* ===========================================
   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);
}

/* 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, #00723a 0%, #008544 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(0, 133, 68, 0.35);
}

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

/* ===============================
   Chips de filtro
   =============================== */
.filter-chip {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: #cbd5e1;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.5rem 0.9rem;
  border-radius: 9999px;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.filter-chip:hover {
  background: rgba(255, 255, 255, 0.1);
}

.filter-chip:active {
  transform: scale(0.96);
}

.filter-chip.active {
  background: linear-gradient(135deg, #10b981 0%, #06b6d4 100%);
  border-color: transparent;
  color: #fff;
}

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

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

/* Controles de MapLibre estilizados */
.maplibregl-ctrl-group {
  background: transparent !important;
  border: none !important;
  border-radius: 1rem !important;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35) !important;
}

.maplibregl-ctrl-group button {
  width: 36px !important;
  height: 36px !important;
  background: var(--glass-bg) !important;
  border: 1px solid var(--glass-border) !important;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: background 0.2s ease;
}

.maplibregl-ctrl-group button:hover {
  background: rgba(30, 41, 59, 0.9) !important;
}

.maplibregl-ctrl-icon {
  filter: invert(1) brightness(1.6);
}

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

.maplibregl-ctrl-attrib a {
  color: #cbd5e1 !important;
}

/* ===============================
   Marcadores personalizados (DOM, animados)
   =============================== */
/* Elemento exterior: es el que MapLibre posiciona directamente vía su
   propio transform. No debe llevar transform/opacity propios. */
.marker-anim {
  cursor: pointer;
}

.marker-anim:hover {
  z-index: 1000;
}

.custom-marker,
.marker-cluster {
  transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.22s ease;
}

/* Estado inicial (antes de la animación de entrada) y de salida */
.marker-anim:not(.marker-in) .custom-marker,
.marker-anim.marker-out .custom-marker {
  opacity: 0;
  transform: rotate(-45deg) scale(0.35);
}

.marker-anim:not(.marker-in) .marker-cluster,
.marker-anim.marker-out .marker-cluster {
  opacity: 0;
  transform: scale(0.35);
}

.marker-anim.marker-out .custom-marker,
.marker-anim.marker-out .marker-cluster {
  transition: transform 0.2s ease-in, opacity 0.2s ease-in;
}

.custom-marker {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg) scale(1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  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);
}

.custom-marker.new {
  background: linear-gradient(135deg, #33ba7a 0%, #008544 100%);
}

.custom-marker.new::after {
  background: #33ba7a;
}

.custom-marker.recovered {
  background: linear-gradient(135deg, #2dd4bf 0%, #0d9488 100%);
}

.custom-marker.recovered::after {
  background: #2dd4bf;
}

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

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

.custom-marker.lost {
  background: linear-gradient(135deg, #fb7185 0%, #e11d48 100%);
}

.custom-marker.lost::after {
  background: #fb7185;
}

/* Icono interior grande: el pictograma (🏪 PDV / 🚜 Productor) ocupa la
   mayor parte del pin para que el tipo de establecimiento se lea de un
   vistazo, sin depender de sutilezas de forma. */
.custom-marker-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2);
  transform: rotate(45deg);
  font-size: 17px;
  line-height: 1;
}

/* Pulso animado en marcadores individuales */
@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;
}

/* ===============================
   Clústeres de marcadores
   =============================== */
.marker-cluster {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  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);
}

.marker-cluster:hover,
.marker-cluster:focus {
  transform: scale(1.12);
}

.marker-cluster.new {
  background: linear-gradient(135deg, #008544 0%, #33ba7a 100%);
}

.marker-cluster.recovered {
  background: linear-gradient(135deg, #0d9488 0%, #2dd4bf 100%);
}

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

.marker-cluster.lost {
  background: linear-gradient(135deg, #e11d48 0%, #fb7185 100%);
}

.marker-cluster.mixed {
  background: linear-gradient(135deg, #008544 0%, #fbbf24 100%);
}

.marker-cluster::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;
}

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

/* ===============================
   Bottom Sheet
   =============================== */
#bottom-sheet.open,
#filter-sheet.open,
#stats-sheet.open,
#ficha-sheet.open,
#ticket-sheet.open,
#inbox-sheet.open,
#action-sheet.open {
  transform: translateY(0);
}

#sheet-overlay.open,
#filter-overlay.open,
#stats-overlay.open,
#ficha-overlay.open,
#ticket-overlay.open,
#inbox-overlay.open,
#action-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

/* ===============================
   Toast / notificaciones
   Estado oculto y visible explícitos: no dependen de utilidades translate
   compuestas ni del alto del mensaje (un toast de 2 líneas antes quedaba
   parcialmente visible dentro del viewport).
   =============================== */
#toast {
  transform: translate(-50%, -0.75rem);
  opacity: 0;
  pointer-events: none;
  transition: transform 300ms ease, opacity 300ms ease;
}

#toast.toast-visible {
  transform: translate(-50%, 0);
  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) {
  .maplibregl-ctrl-bottom-right {
    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);
  }
}

/* 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;
  }
}
