/* =============================================================================
   GeoKeyla — lo propio de este sistema (mapa, popups, editor de fotos).
   Lo general (colores, fuentes, cabecera, tarjetas, tablas, botones, claro/oscuro)
   viene de keyla-tema.css, el kit de diseño de Farmacias Keyla, que se carga antes.
   ============================================================================= */
:root {
  /* Colores de los pines del mapa (paleta del Manual de Marca) */
  --pin-propia: var(--marca-verde);       /* #009294, cruz blanca */
  --pin-franquicia: var(--marca-amarillo); /* #FFDB00, cruz oscura */
  --pin-competencia: #b91c1c;             /* rojo del semáforo; la cruz lleva el color de su cadena */
  --pin-otros: #66716f;                   /* gris «sin datos» */
}

/* Los enlaces a una sección (#detalle) no quedan tapados por la cabecera fija */
[id] { scroll-margin-top: 84px; }

/* Las etiquetas de formulario siguen el color del tema (Leaflet y Bootstrap las pintan fijas) */
.form-label, .modal-title, label { color: var(--text-main); }
.form-label { font-weight: 500; }

.modal-content { border-radius: .9rem; box-shadow: var(--shadow); }
.modal-header, .modal-footer { border-color: var(--border-color); }
.modal-title { font-family: var(--font-display); font-weight: 700; }

/* ---------- Mapa ---------- */
#map {
  width: 100%;
  height: 72vh;
  min-height: 420px;
  border-radius: .9rem;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow);
}
.leaflet-container { font-family: var(--font-body); }

/* Popups, selector de capas y controles del mapa con los colores del tema
   (Leaflet los pinta siempre blancos: en modo oscuro el texto claro quedaba sobre blanco) */
.leaflet-container .leaflet-popup-content-wrapper,
.leaflet-container .leaflet-popup-tip {
  background: var(--bg-surface) !important;
  color: var(--text-main) !important;
}
.leaflet-container .leaflet-popup-content-wrapper { border-radius: .8rem; box-shadow: var(--shadow); }
.leaflet-control-layers {
  background: var(--bg-surface) !important;
  color: var(--text-main) !important;
  border-radius: .6rem !important;
  box-shadow: var(--shadow) !important;
}
.leaflet-control-layers-toggle { background-color: var(--bg-surface) !important; }
:root[data-theme="dark"] .leaflet-control-layers-toggle { filter: invert(1); }
.leaflet-control-layers label, .leaflet-control-layers span { color: var(--text-main) !important; }
.leaflet-control-layers-separator { border-top: 1px solid var(--border-color) !important; }
/* .leaflet-container delante: leaflet.css se carga después de este archivo (en la página del mapa) */
.leaflet-container .leaflet-bar a, .leaflet-container .leaflet-bar a:hover { background-color: var(--bg-surface); color: var(--text-main); border-color: var(--border-color); }
.leaflet-container .leaflet-bar a:hover { background-color: var(--keyla-teal-soft); }
.leaflet-container .leaflet-bar { border-radius: .6rem; box-shadow: var(--shadow); border: 1px solid var(--border-color); }
.leaflet-container .leaflet-bar a:first-child { border-top-left-radius: .6rem; border-top-right-radius: .6rem; }
.leaflet-container .leaflet-bar a:last-child { border-bottom-left-radius: .6rem; border-bottom-right-radius: .6rem; }
:root[data-theme="dark"] .leaflet-control-attribution { background: rgba(13, 20, 26, .8); color: var(--text-muted); }

/* Filtros arriba del mapa: píldoras como .kv-chip del kit */
.map-legend { display: flex; flex-wrap: wrap; gap: .4rem; font-size: .8rem; }
.map-legend .legend-item {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  padding: .25rem .75rem;
  color: var(--text-main);
  font-weight: 700;
  cursor: pointer;
  transition: opacity .15s, background .15s;
}
.map-legend .legend-item:hover { border-color: var(--keyla-teal); background: var(--keyla-teal-soft); }
.map-legend .legend-item.inactive { opacity: .45; }
.map-legend .legend-item.inactive .dot { filter: grayscale(1); }
.map-legend .dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; }
.map-legend .caret { margin-left: 2px; }
.dot-propia { background: var(--pin-propia); }
.dot-franquicia { background: var(--pin-franquicia); box-shadow: inset 0 0 0 1px rgba(15, 42, 40, .35); }
.dot-competencia { background: var(--pin-competencia); }
.dot-otros { background: var(--pin-otros); }

/* Chips de cadenas de competencia (filtro por marca) */
.map-legend-cadenas { justify-content: flex-end; }
.map-legend-cadenas .legend-item .dot { width: 12px; height: 12px; border: 1px solid rgba(255, 255, 255, .7); }

/* Aviso «modo admin» sobre el mapa */
.mapa-aviso { font-size: .85rem; margin-bottom: .6rem; }

.farmacia-popup h6 { margin-bottom: 2px; color: var(--text-main); font-family: var(--font-display); font-weight: 700; }
.farmacia-popup .badge-tipo { font-size: .7rem; }
.farmacia-popup .popup-campo { font-size: .8rem; margin-top: 3px; }
.farmacia-popup .popup-etiqueta { font-weight: 600; color: var(--text-muted); }
.farmacia-popup .popup-foto { width: 100%; max-height: 130px; object-fit: cover; border-radius: .5rem; margin-bottom: 6px; display: block; }
.farmacia-popup .popup-mascota { width: 34px; height: 34px; object-fit: contain; flex-shrink: 0; }

.foto-miniatura { width: 90px; height: 90px; object-fit: cover; border-radius: .5rem; border: 1px solid var(--border-color); }

.keyla-marker { background: transparent !important; border: none !important; }

/* Las capas de referencia de Esri traen el texto en negro (pensado para
   fondos claros); sobre satélite se invierte para que quede blanco */
.etiquetas-blancas { filter: invert(1) contrast(1.15); }

/* Buscador sobre el mapa */
.keyla-search {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: .7rem;
  padding: 4px;
  box-shadow: var(--shadow);
}
.keyla-search input {
  border: 1.5px solid var(--border-color);
  border-radius: .55rem;
  padding: 6px 8px 6px 30px;
  font-size: .85rem;
  width: 230px;
  background: var(--bg-surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2366716f' stroke-width='2.5' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-4-4'/%3E%3C/svg%3E") no-repeat 9px center;
  color: var(--text-main);
}
.keyla-search input:focus { outline: none; border-color: var(--keyla-teal); }
.keyla-search-resultados {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: .6rem;
  box-shadow: var(--shadow);
  margin-top: 4px;
  max-height: 240px;
  overflow-y: auto;
  z-index: 1000;
}
.keyla-search-resultados.show { display: block; }
.keyla-search-item {
  padding: 7px 10px;
  font-size: .82rem;
  cursor: pointer;
  color: var(--text-main);
  border-bottom: 1px solid var(--border-color);
}
.keyla-search-item:last-child { border-bottom: none; }
.keyla-search-item:hover { background: var(--keyla-teal-soft); }

/* Etiquetas con nombre y distancia sobre las líneas del radio */
.radio-tip { font-size: .72rem; padding: 1px 5px; background: var(--bg-surface); color: var(--text-main); border: 1px solid var(--border-color); border-radius: .4rem; }
.radio-tip::before { display: none; }

/* ---------- Editor de recorte de fotos (recorte.js) ---------- */
.kc-overlay { position: fixed; inset: 0; z-index: 2000; background: rgba(0, 0, 0, .72); display: flex; align-items: center; justify-content: center; padding: 12px; }
.kc-box { background: var(--bg-surface); color: var(--text-main); border: 1px solid var(--border-color); border-radius: .9rem; padding: 14px; max-width: 100%; box-shadow: var(--shadow); }
.kc-title { font-family: var(--font-display); font-weight: 700; font-size: 1.1rem; margin-bottom: 8px; }
.kc-tools { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.kc-tools .btn.active { background: var(--keyla-teal); border-color: var(--keyla-teal); color: var(--sobre-teal); }
.kc-stage { position: relative; margin: 0 auto; user-select: none; touch-action: none; }
.kc-view { display: block; }
.kc-rect { position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 9999px rgba(0, 0, 0, .55); cursor: move; touch-action: none; }
.kc-rect i { position: absolute; width: 18px; height: 18px; background: var(--marca-aquamarine); border: 2px solid #fff; border-radius: 50%; }
.kc-rect i[data-h="nw"] { left: -10px; top: -10px; cursor: nwse-resize; }
.kc-rect i[data-h="ne"] { right: -10px; top: -10px; cursor: nesw-resize; }
.kc-rect i[data-h="sw"] { left: -10px; bottom: -10px; cursor: nesw-resize; }
.kc-rect i[data-h="se"] { right: -10px; bottom: -10px; cursor: nwse-resize; }
.kc-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }

/* Bitácora de auditoría: detalle JSON de cada registro */
.auditoria-detalle { max-width: 520px; max-height: 260px; overflow: auto; white-space: pre-wrap; word-break: break-word;
  font-size: .72rem; background: var(--bg-muted); color: var(--text-main); border: 1px solid var(--border-color);
  border-radius: .5rem; padding: 6px; margin: 4px 0 0; }

@media (max-width: 575.98px) {
  #map { height: 64vh; min-height: 360px; }
  .keyla-search input { width: 170px; }
}
