/**
 * Localizador de agencias — mapa full-bleed + tarjeta flotante (estilo Google Maps)
 * Mobile: pantalla partida (mapa arriba + panel abajo a todo ancho) | Desktop: panel izquierdo flotante
 */

:root {
  --agencias-rojo: #d32f2f;
  --agencias-rojo-hover: #b71c1c;
  --agencias-rojo-soft: rgba(211, 47, 47, 0.12);
  --agencias-verde: #2e7d32;
  --agencias-sombra-card: 0 0.4rem 0.6rem rgba(0, 0, 0, 0.06),
    0 1.2rem 2.8rem rgba(0, 0, 0, 0.12);
  --agencias-radio-card: 1.2rem;
  /* Pestaña activa (línea inferior), estilo referencia */
  --agencias-tab-naranja: #ff7900;
  --agencias-tab-texto-inactivo: #9aa0a6;
  --agencias-tab-texto-activo: #1c2633;
}

/* --- Screen reader only --- */
.agencias-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --- Leaflet --- */
.agencias-leaflet-divicon {
  background: transparent !important;
  border: none !important;
}

.agencias-marker-badge {
  width: var(--agencias-marker-size, 38px);
  height: var(--agencias-marker-size, 38px);
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0.4rem 1.2rem rgba(0, 0, 0, 0.25);
  transition: transform 0.18s ease;
}

.agencias-marker-badge--agencia {
  background: #E91D26;
}

.agencias-marker-badge--agente {
  background: #F15A24;
}

.agencias-marker-badge--active {
  transform: scale(1.12);
}

.agencias-marker-badge__icon {
  filter: brightness(0) invert(1);
  width: 56%;
  height: 56%;
  object-fit: contain;
  display: block;
}

.agencias-leaflet-img {
  display: block;
  width: auto;
  height: auto;
  filter: drop-shadow(0 0.2rem 0.45rem rgba(0, 0, 0, 0.28));
  transform-origin: center bottom;
}

.agencias-leaflet-img--agente {
  filter: hue-rotate(105deg) saturate(1.65) brightness(0.92)
    drop-shadow(0 0.2rem 0.45rem rgba(0, 0, 0, 0.28));
}

.agencias-leaflet-img--active {
  transform: scale(1.12);
}

.leaflet-container {
  font-family: "Istok Web", system-ui, -apple-system, sans-serif;
  background: #e8e8e8;
}

/* Controles zoom a la derecha (no compiten con el panel izquierdo) */
.agencias-map .leaflet-top.leaflet-left {
  top: 0.8rem;
  left: auto;
  right: 0.8rem;
}

.agencias-map .leaflet-control-zoom {
  border: none !important;
  border-radius: 0.8rem !important;
  box-shadow: 0 0.2rem 1rem rgba(0, 0, 0, 0.15) !important;
  overflow: hidden;
}

.agencias-map .leaflet-control-zoom a {
  width: 3.4rem !important;
  height: 3.4rem !important;
  line-height: 3.4rem !important;
  font-size: 1.8rem !important;
}

/* --- Shell página --- */
.body-agencias {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.body-agencias .agencias-locator {
  flex: 1;
  position: relative;
  display: block;
  width: 100%;
  min-height: min(72rem, calc(100dvh - 16rem));
  min-height: min(72rem, calc(100vh - 16rem));
}

/* Mapa ocupa todo el área del main */
.agencias-map-wrap {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
}

.agencias-map {
  width: 100%;
  height: 100%;
  min-height: 32rem;
}

/* Botón flotante móvil */
.agencias-toggle-list {
  display: none;
  position: absolute;
  left: 50%;
  bottom: 1.2rem;
  transform: translateX(-50%);
  z-index: 30;
  padding: 1rem 1.6rem;
  font-family: inherit;
  font-size: 1.4rem;
  font-weight: 700;
  color: #fff;
  background: var(--agencias-rojo);
  border: none;
  border-radius: 999px;
  box-shadow: 0 0.4rem 1.8rem rgba(0, 0, 0, 0.22);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.agencias-toggle-list:hover {
  background: var(--agencias-rojo-hover);
}

.agencias-toggle-list:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

.agencias-toggle-list:active {
  transform: translateX(-50%) scale(0.98);
}

/* Capa sobre el mapa: aloja .contenedor; el panel queda a la izquierda de esa retícula */
.agencias-panel-layer {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

.agencias-panel-layer__inner {
  height: 100%;
  position: relative;
  pointer-events: none;
}

/* ========== Panel flotante (tarjeta blanca sobre el mapa) ========== */
.agencias-panel {
  position: absolute;
  left: 0;
  right: auto;
  z-index: 1;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
  max-width: 40rem;
  max-height: min(56rem, calc(100dvh - 10rem));
  max-height: min(56rem, calc(100vh - 10rem));
  margin: 0;
  top: 1.2rem;
  background: #fff;
  border-radius: var(--agencias-radio-card);
  box-shadow: var(--agencias-sombra-card);
  overflow: hidden;
  transition: max-height 0.35s ease, box-shadow 0.25s ease;
}

/* Mobile: vista partida — mapa arriba, panel abajo fijo en el viewport; scroll solo en la lista */
@media (max-width: 767px) {
  /* Una pantalla: sin scroll del body; el listado hace scroll interno */
  .body-agencias {
    height: 100dvh;
    height: 100vh;
    max-height: 100dvh;
    overflow: hidden;
  }

  .body-agencias .header-contenedor {
    flex-shrink: 0;
  }

  .body-agencias .agencias-locator {
    min-height: 0 !important;
  }

  /* Main ocupa todo el espacio bajo el header */
  .body-agencias > main.agencias-locator {
    flex: 1;
    width: 100%;
    min-height: 0;
    position: relative;
    overflow: hidden;
  }

  /* Mapa: ~44% de alto; panel ~56% */
  .agencias-map-wrap {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 56%;
    z-index: 1;
    overflow: hidden;
  }

  .agencias-map {
    min-height: 0;
    height: 100%;
  }

  /* Panel: franja inferior (~56%); contenido con scroll interno */
  .agencias-panel-layer {
    position: absolute;
    top: 44%;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2;
    min-height: 0;
    pointer-events: auto;
    border-top: 1px solid #e8eaed;
    background: #f5f5f5;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .agencias-panel-layer__inner.contenedor {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 0;
    height: 100%;
    min-height: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    pointer-events: auto;
    overflow: hidden;
  }

  .agencias-panel {
    position: relative;
    left: auto;
    top: auto;
    right: auto;
    bottom: auto;
    width: 100%;
    max-width: none;
    max-height: none;
    height: 100%;
    min-height: 0;
    flex: 1;
    margin: 0;
    border-radius: 0;
    box-shadow: 0 -0.2rem 1rem rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .agencias-toggle-list {
    display: none !important;
  }

  .agencias-panel-inner {
    padding: 1.2rem 1.2rem 0.7rem;
    padding-bottom: calc(0.7rem + env(safe-area-inset-bottom, 0));
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .agencias-panel-head {
    flex-shrink: 0;
  }

  .agencias-list-wrap {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding-bottom: 0.6rem;
  }

  .agencias-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  .agencias-search-wrap {
    padding: 0.95rem 1.2rem;
  }

  .agencias-search {
    font-size: 1.55rem;
  }

  .agencias-tabs__btn {
    padding-top: 0.82rem;
    padding-bottom: 0.92rem;
    font-size: 1.35rem;
  }

  .agencias-card {
    padding-top: 1.25rem;
    padding-bottom: 1.25rem;
  }

  .agencias-card-title {
    font-size: 1.6rem;
    line-height: 1.25;
  }

  .agencias-card-address {
    font-size: 1.28rem;
    line-height: 1.3;
  }

  .agencias-card-meta {
    font-size: 1.35rem;
  }

  .agencias-card-link {
    min-height: 4.4rem;
    font-size: 1.35rem;
  }

  .agencias-card-type {
    font-size: 1.35rem;
  }
}

/* Tablet y desktop: panel a la izquierda dentro de .contenedor */
@media (min-width: 768px) {
  .agencias-panel {
    top: 1.6rem;
    bottom: 1.6rem;
    width: min(100%, 38rem);
    max-width: 40rem;
    max-height: none;
    height: auto;
  }

  .agencias-toggle-list {
    display: none !important;
  }

  .agencias-search-wrap {
    padding: 0.9rem 1.25rem;
  }

  .agencias-search {
    font-size: 1.6rem;
  }

  .agencias-tabs__btn {
    font-size: 1.45rem;
    padding-top: 0.82rem;
    padding-bottom: 0.92rem;
  }

  .agencias-card {
    padding-top: 1.3rem;
    padding-bottom: 1.3rem;
  }

  .agencias-card-title {
    font-size: 1.65rem;
  }

  .agencias-card-address {
    font-size: 1.22rem;
  }

  .agencias-card-meta {
    font-size: 1.28rem;
  }
}

@media (min-width: 1025px) {
  .agencias-panel {
    top: 2rem;
    bottom: 2rem;
    width: min(100%, 40rem);
    max-width: 40rem;
    border-radius: 1.4rem;
  }

  .agencias-card {
    border-radius: 0.8rem;
  }

  .agencias-card-link {
    transition: background 0.22s ease, color 0.22s ease, transform 0.18s ease;
  }

  .agencias-card-link:hover {
    transform: translateY(-1px);
  }
}

.agencias-panel-inner {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  padding: 1.4rem 1.4rem 0.8rem;
  overflow: hidden;
}

@media (min-width: 768px) {
  .agencias-panel-inner {
    padding: 1.8rem 1.6rem 1rem;
  }
}

.agencias-panel-head {
  flex-shrink: 0;
}

.agencias-search-wrap {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.8rem 1.2rem;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 999px;
  box-shadow: 0 0.1rem 0.4rem rgba(0, 0, 0, 0.05);
  margin-bottom: 0;
}

/* Buscador como bloque separado (primero dentro del panel) */
.agencias-search-block {
  margin-bottom: 1.1rem;
}

.agencias-tabs-block {
  margin-bottom: 0.9rem;
}

/* buscar.svg usa trazos blancos: máscara + color */
.agencias-search-icon {
  width: 1.8rem;
  height: 1.8rem;
  flex-shrink: 0;
  background-color: #757575;
  -webkit-mask-image: url("../img/iconos/buscar.svg");
  mask-image: url("../img/iconos/buscar.svg");
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
}

.agencias-search {
  flex: 1;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 1.5rem;
  min-width: 0;
  color: #212121;
}

.agencias-search::placeholder {
  color: #9e9e9e;
}

.agencias-search:focus {
  outline: none;
}

.agencias-search-wrap:focus-within {
  border-color: var(--agencias-rojo);
  box-shadow: 0 0 0 0.2rem var(--agencias-rojo-soft);
}

/* Pestañas horizontales (Todos | Agencias | Agentes) */
.agencias-tabs {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 0.2rem;
  margin: 0;
  padding: 0;
  border-bottom: 1px solid #e8eaed;
}

.agencias-tabs__btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-width: 0;
  padding: 0.75rem 0.35rem 0.85rem;
  margin: 0;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 1.4rem;
  font-weight: 500;
  line-height: 1.2;
  color: var(--agencias-tab-texto-inactivo);
  cursor: pointer;
  position: relative;
  border-bottom: 0.35rem solid transparent;
  margin-bottom: -1px;
  transition: color 0.2s ease, border-color 0.2s ease, font-weight 0.15s ease;
}

.agencias-tabs__btn:hover:not(.is-active) {
  color: #5f6368;
}

.agencias-tabs__btn.is-active {
  color: var(--agencias-tab-texto-activo);
  font-weight: 700;
  border-bottom-color: var(--color-rojo);
}

.agencias-tabs__btn:focus-visible {
  outline: 2px solid var(--color-rojo);
  outline-offset: 2px;
  border-radius: 0.4rem 0.4rem 0 0;
}

.agencias-tabs__label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.agencias-tabs__icon {
  width: 2.2rem;
  height: 2.2rem;
  object-fit: contain;
  flex-shrink: 0;
}

/* Iconos a tono con texto inactivo */
.agencias-tabs__btn:not(.is-active) .agencias-tabs__icon {
  filter: grayscale(100%) brightness(0.62) opacity(0.95);
}

.agencias-tabs__btn.is-active .agencias-tabs__icon {
  filter: none;
  opacity: 1;
}

@media (max-width: 380px) {
  .agencias-tabs__btn {
    font-size: 1.2rem;
    padding-left: 0.2rem;
    padding-right: 0.2rem;
  }

  .agencias-tabs__icon {
    width: 1.7rem;
    height: 1.7rem;
  }
}

.agencias-geolocate {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
  padding: 0.55rem 1rem;
  font-family: inherit;
  font-size: 1.3rem;
  font-weight: 600;
  color: #424242;
  background: #fafafa;
  border: 1px solid #e0e0e0;
  border-radius: 0.8rem;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.agencias-geolocate:hover {
  border-color: var(--agencias-rojo);
  background: #fff8f8;
}

.agencias-geolocate:focus-visible {
  outline: 2px solid var(--agencias-rojo);
  outline-offset: 2px;
}

.agencias-geolocate:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.agencias-geolocate-icon {
  width: 1.8rem;
  height: 2rem;
  flex-shrink: 0;
  background: url("../img/iconos/ubicacion-agencia.svg") center / contain no-repeat;
}

.agencias-list-wrap {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0 -0.4rem;
  padding: 0 0.4rem 0.8rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.agencias-list {
  flex: 1 1 auto;
  min-height: 10rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 0.6rem;
  scroll-behavior: smooth;
}

.agencias-list::-webkit-scrollbar {
  width: 0.5rem;
}

.agencias-list::-webkit-scrollbar-thumb {
  background: #bdbdbd;
  border-radius: 999px;
}

.agencias-empty {
  margin: 1.2rem 0;
  color: #757575;
  font-size: 1.4rem;
  text-align: center;
}

/* --- Tarjetas resultado (compactas, mock) --- */
.agencias-card {
  padding: 1.2rem 0.4rem;
  border-bottom: 1px solid #eeeeee;
  cursor: pointer;
  border-radius: 0.6rem;
  transition: background 0.2s ease;
}

.agencias-card:last-child {
  border-bottom: none;
}

.agencias-card:hover {
  background: #fafafa;
}

.agencias-card:focus-visible {
  outline: 2px solid var(--agencias-rojo);
  outline-offset: 2px;
}

.agencias-card.is-active {
  background: #fff5f5;
  box-shadow: inset 0.3rem 0 0 var(--agencias-rojo);
  /* Aumenta el padding para que la línea roja no "toque" el contenido */
  padding-left: 0.85rem;
}

.agencias-card-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.agencias-card-pin {
  width: 2.1rem;
  height: 2.3rem;
  margin-top: 0;
  flex-shrink: 0;
  background: url("../img/iconos/agencias.svg") center / contain no-repeat;
  filter: drop-shadow(0 0.1rem 0.2rem rgba(0, 0, 0, 0.15));
}

.agencias-card[data-tipo="Agente"] .agencias-card-pin {
  background: url("../img/iconos/agente.svg") center / contain no-repeat;
}

.agencias-card-head-text {
  flex: 1;
  min-width: 0;
}

.agencias-card-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: #212121;
  line-height: 1.3;
}

.agencias-card-dist {
  font-size: 1.15rem;
  font-style: italic;
  color: #9e9e9e;
  white-space: nowrap;
  flex-shrink: 0;
  padding-top: 0.15rem;
}

.agencias-card-address {
  margin: 0 0 0.35rem;
  padding-left: 2.8rem;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #757575;
  line-height: 1.35;
}

.agencias-card-meta {
  margin: 0.15rem 0;
  font-size: 1.25rem;
  color: #616161;
  padding-left: 2.8rem;
}

.agencias-card-meta-item {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
}

.agencias-card-meta--horario::before,
.agencias-card-meta--tel::before {
  content: "";
  flex-shrink: 0;
  margin-top: 0.15rem;
  background: center / contain no-repeat;
}

.agencias-card-meta--horario::before {
  width: 1.6rem;
  height: 1.6rem;
  background-image: url("../img/iconos/horario-agencias.svg");
  opacity: 0.9;
}

.agencias-card-meta--tel::before {
  width: 1.4rem;
  height: 1.4rem;
  background-image: url("../img/iconos/whatsapp-agencias.svg");
  opacity: 0.95;
}

.agencias-card-wa {
  font-weight: 700;
  color: var(--color-parrafos);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

.agencias-card-wa:hover {
  color: var(--color-parrafos);
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.agencias-card-wa:focus-visible {
  outline: 2px solid var(--agencias-rojo);
  outline-offset: 2px;
  border-radius: 0.2rem;
}

.agencias-card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.75rem;
  padding-left: 2.8rem;
}

.agencias-card-link {
  display: inline-flex;
  align-items: center;
  padding: 0.5rem 2.5rem;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--color-rojo);
  text-decoration: none;
  background: #fff;
  border: 1px solid var(--color-rojo);
  border-radius: 2rem;
  transition: background 0.2s, color 0.2s;
  min-height: 4rem;
}

.agencias-card-link::after {
  content: "";
  display: inline-block;
  width: 1.4rem;
  height: 1.2rem;
  margin-left: 0.35rem;
  background: url("../img/iconos/flecha-como-llegar.svg") center / contain no-repeat;
  flex-shrink: 0;
}

.agencias-card-link:hover {
  background: var(--agencias-rojo);
  color: #fff;
}

.agencias-card-link:hover::after,
.agencias-card-link:focus-visible::after {
  filter: brightness(0) invert(1);
}

.agencias-card-link:focus-visible {
  outline: 2px solid var(--agencias-rojo);
  outline-offset: 2px;
}

.agencias-card-type {
  font-size: 1.25rem;
  font-weight: 700;
  color: #212121;
}

@media (min-width: 768px) {
  .agencias-card:hover {
    background: #f5f5f5;
  }

  .agencias-card.is-active:hover {
    background: #fff5f5;
  }
}

.body-agencias main.agencias-locator + footer,
.body-agencias .footer {
  flex-shrink: 0;
}

/* Leaflet popup (Cómo llegar): aumentar tamaño de textos */
.agencias-map .leaflet-popup-content {
  margin: 0;
  padding: 1.2rem 1.4rem;
  font-size: 1.45rem;
  line-height: 1.35;
  color: var(--color-negro);
}

.agencias-map .leaflet-popup-content strong {
  font-size: 1.7rem;
}

.agencias-map .leaflet-popup-content small {
  font-size: 1.35rem;
}

.agencias-map .leaflet-popup-content a {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--color-rojo);
  text-decoration: none;
}

.agencias-map .leaflet-popup-content a:hover {
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

@media (max-width: 767px) {
  .agencias-map .leaflet-popup-content {
    padding: 1rem 1.15rem;
    font-size: 1.22rem;
    line-height: 1.32;
  }

  .agencias-map .leaflet-popup-content strong {
    font-size: 1.4rem;
  }

  .agencias-map .leaflet-popup-content small {
    font-size: 1.12rem;
  }

  .agencias-map .leaflet-popup-content a {
    font-size: 1.22rem;
  }
}
