/* ============================================================
   MAP.CSS — Overrides de MapLibre GL JS y herramientas del mapa
   ============================================================

   PROYECTO: Visor Promigas — Titulaciones Prediales
   EMPRESA:  AHG Ingeniero S.A.S.
   ============================================================ */


/* ============================================================
   CONTENEDOR DEL MAPA
   ============================================================ */
.map-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
}


/* ============================================================
   OVERRIDES MAPLIBRE
   ============================================================ */

/* Fondo del lienzo mientras cargan los tiles */
.maplibregl-canvas-container { background: #0d1420; }

/* Ocultar la atribución por defecto (no relevante para este visor) */
.maplibregl-ctrl-attrib { display: none !important; }

/* Botones de zoom */
.maplibregl-ctrl-zoom-in,
.maplibregl-ctrl-zoom-out {
  background-color: #1a2235 !important;
  border-color: #2a3552 !important;
  color: #f1f5f9 !important;
}

.maplibregl-ctrl-zoom-in:hover,
.maplibregl-ctrl-zoom-out:hover {
  background-color: #1f2a40 !important;
}

/* Contenedor de controles MapLibre */
.maplibregl-ctrl-group {
  background: #1a2235 !important;
  border: 1px solid #2a3552 !important;
  border-radius: 8px !important;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important;
}

/* Separador entre botones de zoom */
.maplibregl-ctrl-group button + button {
  border-top: 1px solid #2a3552 !important;
}

/* Popup genérico */
.maplibregl-popup-content {
  background: #1a2235 !important;
  color: #f1f5f9 !important;
  border: 1px solid #2a3552 !important;
  border-radius: 8px !important;
  padding: 10px 14px !important;
  font-family: 'DM Sans', sans-serif !important;
  font-size: 13px !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4) !important;
}

.maplibregl-popup-tip { display: none; }

.maplibregl-popup-close-button {
  color: #64748b !important;
  font-size: 16px !important;
  right: 6px !important;
  top: 4px !important;
}

.maplibregl-popup-close-button:hover { color: #f1f5f9 !important; }

/* Dejar respirar el contenido a la derecha del botón de cerrar */
.maplibregl-popup-content { padding-right: 22px !important; }


/* ============================================================
   POPUP INFORMATIVO DE CAPAS (.map-popup)
   ============================================================
   Estructura generada por buildPopupHTML() en js/map.js:
     .map-popup
       .map-popup-head  → .map-popup-title + .map-popup-badge
       .map-popup-sub   → subtítulo (tipo, gasoducto, etc.)
       .map-popup-grid  → filas .map-popup-row (key/val)
   ============================================================ */
.map-popup {
  min-width: 180px;
  max-width: 260px;
}

.map-popup-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.map-popup-title {
  font-size: 13.5px;
  font-weight: 700;
  color: #f1f5f9;
  line-height: 1.25;
}

.map-popup-badge {
  flex-shrink: 0;
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.map-popup-sub {
  margin-top: 2px;
  font-size: 11.5px;
  color: #94a3b8;
  line-height: 1.3;
}

.map-popup-grid {
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px solid #2a3552;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.map-popup-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.map-popup-key {
  font-size: 11.5px;
  color: #94a3b8;
  flex-shrink: 0;
}

.map-popup-val {
  font-size: 12px;
  font-weight: 600;
  color: #e2e8f0;
  text-align: right;
}


/* ============================================================
   SELECTOR DE BASEMAP
   ============================================================ */
/* Selector de basemap: arriba a la derecha, horizontal */
.basemap-switcher {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: row;
  gap: 4px;
  z-index: 10;
}

.basemap-btn {
  padding: 6px 12px;
  background: #1a2235;
  border: 1px solid #2a3552;
  border-radius: 6px;
  color: #94a3b8;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.basemap-btn:hover  { background: #1f2a40; color: #f1f5f9; }
.basemap-btn.active { background: #0066cc; border-color: #0066cc; color: white; }


/* ============================================================
   HERRAMIENTAS DE MEDICIÓN
   ============================================================ */
.measure-tools {
  position: absolute;
  bottom: 120px;
  right: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 10;
}

.measure-btn {
  width: 36px;
  height: 36px;
  background: #1a2235;
  border: 1px solid #2a3552;
  border-radius: 8px;
  color: #94a3b8;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.measure-btn:hover  { background: #1f2a40; color: #f1f5f9; }
.measure-btn.active { background: #0066cc; border-color: #0066cc; color: white; }

/* Resultado de medición */
.measure-result {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: #1a2235;
  border: 1px solid #2a3552;
  border-radius: 20px;
  padding: 7px 16px 7px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 600;
  color: #f1f5f9;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  z-index: 10;
  font-family: 'JetBrains Mono', monospace;
}

.measure-result.hidden { display: none; }

.measure-close-btn {
  background: none;
  border: none;
  color: #64748b;
  cursor: pointer;
  font-size: 14px;
  padding: 0;
  line-height: 1;
}

.measure-close-btn:hover { color: #f1f5f9; }


/* ============================================================
   MOBILE (< 768px) — Overrides de controles flotantes
   ============================================================
   Estrategia: en móvil mandamos TODOS los controles flotantes a la
   mitad superior del mapa. Así nada queda contra la URL bar de
   Safari iOS (que se come ~60 px abajo) ni contra el home indicator.

   Layout móvil del mapa:
   ┌───────────────────────────────────────────┐
   │ [Satélite|Calles|Apagar]         [📏]    │  ← top (10 px)
   │                                  [⬜]    │
   │                                           │
   │                                  [ + ]   │  ← MapLibre zoom
   │              MAPA                [ - ]   │     (top:80 px aprox)
   │                                  [ ⊙ ]   │  ← geolocate
   │                                           │
   │                                           │
   └───────────────────────────────────────────┘
   ============================================================ */
@media (max-width: 768px) {

  /* Basemap chips: top-izquierda del mapa, alineados horizontalmente.
     Respetan safe-area-inset-left para iPhones en landscape. */
  .basemap-switcher {
    top: 10px !important;
    left: calc(10px + env(safe-area-inset-left)) !important;
    right: auto !important;
    bottom: auto !important;
    flex-direction: row;
    gap: 4px;
  }
  .basemap-btn {
    padding: 8px 10px;
    font-size: 12px;
    min-height: 36px;          /* área de toque cómoda */
  }

  /* Measure tools: arriba a la derecha del mapa. Stack vertical compacto. */
  .measure-tools {
    top: 10px !important;
    right: calc(10px + env(safe-area-inset-right)) !important;
    bottom: auto !important;
    flex-direction: column;
    gap: 6px;
  }
  .measure-btn {
    width: 40px;
    height: 40px;
    font-size: 18px;
  }

  /* Controles nativos de MapLibre (zoom + geolocate): los movemos de
     bottom-right a top-right para que NUNCA queden contra la URL bar
     de Safari iOS. Se ubican debajo de measure-tools (~110 px de offset
     deja espacio para los dos botones de 40 px + gap).

     MapLibre los agrega en orden: NavigationControl primero (zoom in/out),
     luego GeolocateControl. Cada uno es un .maplibregl-ctrl-group separado
     dentro de .maplibregl-ctrl-bottom-right. */
  .maplibregl-ctrl-bottom-right {
    top: 110px !important;
    bottom: auto !important;
    right: calc(10px + env(safe-area-inset-right)) !important;
    /* Stack vertical natural en MapLibre (ya lo es) */
  }
  /* bottom-left por si algún control se renderiza ahí (no es el caso hoy
     pero deja la base preparada). */
  .maplibregl-ctrl-bottom-left {
    top: 110px !important;
    bottom: auto !important;
    left: calc(10px + env(safe-area-inset-left)) !important;
  }
  /* Botones de zoom/geolocate más grandes en móvil (área táctil cómoda) */
  .maplibregl-ctrl-group button {
    width: 40px !important;
    height: 40px !important;
  }

  /* Resultado de medición: pequeño chip en top-center bajo el topbar.
     Respeta también home indicator si por algún motivo cae al fondo. */
  .measure-result {
    top: 60px !important;
    bottom: auto !important;
    font-size: 12px;
    padding: 6px 12px;
    max-width: calc(100vw - 24px);
  }
}
