/**
 * Geolocation UI Components
 * Estilos para filtros de ubicación y badges de distancia
 * Mobile-first design con accesibilidad
 */

/* ============================================
   FILTRO DE GEOLOCALIZACIÓN
   ============================================ */

.geolocation-filter {
  margin: 15px 0;
  padding: 16px;
  background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
  border-radius: 12px;
  border: 2px solid #e9ecef;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
}

.geolocation-filter:hover {
  border-color: var(--sp-color-primary);
  box-shadow: 0 4px 12px rgba(25, 135, 84, 0.1);
}

/* Container del filtro */
.filter-container {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

/* Toggle switch mejorado */
.filter-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  color: #212529;
  user-select: none;
  transition: color 0.2s ease;
  min-height: 44px; /* Touch target accesible */
}

.filter-toggle:hover {
  color: var(--sp-color-primary);
}

.filter-toggle input[type="checkbox"] {
  width: 22px;
  height: 22px;
  cursor: pointer;
  margin: 0;
  accent-color: var(--sp-color-primary);
}

.toggle-icon {
  font-size: 20px;
  line-height: 1;
  transition: transform 0.3s ease;
}

.filter-toggle:hover .toggle-icon {
  transform: scale(1.1);
}

.toggle-text {
  flex: 1;
  line-height: 1.4;
}

/* Selector de radio */
.radius-selector {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: white;
  border-radius: 8px;
  border: 1px solid #dee2e6;
  transition: all 0.3s ease;
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.radius-selector label {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: #495057;
  white-space: nowrap;
}

.radius-select {
  padding: 8px 12px;
  border: 1px solid #ced4da;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  color: #212529;
  background-color: white;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 100px;
  min-height: 44px; /* Touch target */
}

.radius-select:hover {
  border-color: var(--sp-color-primary);
}

.radius-select:focus {
  outline: none;
  border-color: var(--sp-color-primary);
  box-shadow: 0 0 0 3px rgba(25, 135, 84, 0.1);
}

/* Hint de ubicación */
.filter-hint {
  margin: 12px 0 0 0;
  padding: 12px 16px;
  background: linear-gradient(135deg, #fff3cd 0%, #fff9e6 100%);
  border-left: 4px solid #ffc107;
  border-radius: 8px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  line-height: 1.5;
  box-shadow: 0 2px 6px rgba(255, 193, 7, 0.1);
  animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.hint-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.hint-text {
  flex: 1;
  color: #856404;
  font-weight: 500;
}

/* ============================================
   BADGES DE DISTANCIA
   ============================================ */

.distance-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  margin-left: 8px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  transition: all 0.2s ease;
  white-space: nowrap;
  line-height: 1;
}

.distance-badge:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

/* Enlace clickeable a Google Maps */
.distance-badge-link {
  text-decoration: none;
  cursor: pointer;
}

.distance-badge-link:hover {
  text-decoration: none;
  opacity: 0.9;
}

.distance-badge-link:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.distance-badge-link:focus-visible {
  outline: 3px solid var(--sp-color-primary);
  outline-offset: 3px;
}

.badge-icon {
  font-size: 14px;
  line-height: 1;
}

.badge-text {
  font-variant-numeric: tabular-nums;
}

/* Colores por distancia - Verde para cercanos */
.distance-badge[data-distance^="0."] {
  background: linear-gradient(135deg, #d4edda, #c3e6cb);
  color: #155724;
  border: 1px solid #b1dfbb;
}

/* Amarillo para distancias medias (1-5 km) */
.distance-badge[data-distance^="1."],
.distance-badge[data-distance^="2."],
.distance-badge[data-distance^="3."],
.distance-badge[data-distance^="4."],
.distance-badge[data-distance^="5."] {
  background: linear-gradient(135deg, #fff3cd, #ffe8a1);
  color: #856404;
  border: 1px solid #ffd68f;
}

/* Rojo para distancias lejanas (6+ km) */
.distance-badge[data-distance^="6."],
.distance-badge[data-distance^="7."],
.distance-badge[data-distance^="8."],
.distance-badge[data-distance^="9."],
.distance-badge[data-distance*="1"],
.distance-badge[data-distance*="2"] {
  background: linear-gradient(135deg, #f8d7da, #f1c0c3);
  color: #721c24;
  border: 1px solid #f5c2c7;
}

/* ============================================
   INDICADOR DE MÁS CERCANO
   ============================================ */

.closest-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: linear-gradient(135deg, #ffc107, #ffb300);
  color: #000;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 800;
  box-shadow: 0 3px 10px rgba(255, 193, 7, 0.4);
  animation: pulse 2s ease-in-out infinite;
  margin-bottom: 8px;
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 3px 10px rgba(255, 193, 7, 0.4);
  }
  50% {
    transform: scale(1.05);
    box-shadow: 0 5px 15px rgba(255, 193, 7, 0.6);
  }
}

.closest-indicator::before {
  content: '⭐';
  font-size: 16px;
}

/* ============================================
   ESTADO VACÍO - SIN RESULTADOS CERCANOS
   ============================================ */

.no-results-nearby {
  padding: 32px 24px;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border-radius: 16px;
  border: 2px dashed #dee2e6;
  text-align: center;
  margin: 24px 0;
  animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.no-results-nearby p {
  font-size: 16px;
  color: #495057;
  margin: 0 0 16px 0;
  font-weight: 500;
}

.no-results-nearby button {
  padding: 12px 24px;
  background: linear-gradient(135deg, var(--sp-color-primary), #157347);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(25, 135, 84, 0.3);
  min-height: 44px; /* Touch target */
}

.no-results-nearby button:hover {
  background: linear-gradient(135deg, #157347, #0f5132);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(25, 135, 84, 0.4);
}

.no-results-nearby button:active {
  transform: translateY(0);
}

/* ============================================
   RESPONSIVE - MOBILE FIRST
   ============================================ */

/* Móvil pequeño */
@media (max-width: 374px) {
  .filter-container {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .filter-toggle {
    width: 100%;
    justify-content: flex-start;
  }

  .radius-selector {
    width: 100%;
    justify-content: space-between;
  }

  .radius-select {
    flex: 1;
  }

  .distance-badge {
    font-size: 12px;
    padding: 5px 10px;
    margin-left: 4px;
  }
}

/* Tablet */
@media (min-width: 576px) {
  .geolocation-filter {
    padding: 20px;
  }

  .filter-toggle {
    font-size: 16px;
  }

  .distance-badge {
    font-size: 14px;
    padding: 7px 14px;
  }

  .no-results-nearby {
    padding: 40px 32px;
  }

  .no-results-nearby p {
    font-size: 18px;
  }
}

/* Desktop */
@media (min-width: 768px) {
  .geolocation-filter {
    padding: 24px;
    border-radius: 16px;
  }

  .filter-container {
    gap: 24px;
  }

  .distance-badge {
    font-size: 15px;
    padding: 8px 16px;
  }
}

/* ============================================
   ACCESIBILIDAD
   ============================================ */

/* Focus visible para navegación por teclado */
.filter-toggle input[type="checkbox"]:focus-visible {
  outline: 3px solid var(--sp-color-primary);
  outline-offset: 3px;
}

.radius-select:focus-visible {
  outline: 3px solid var(--sp-color-primary);
  outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .geolocation-filter,
  .radius-selector,
  .filter-hint,
  .distance-badge,
  .closest-indicator,
  .no-results-nearby {
    animation: none;
    transition: none;
  }

  .filter-toggle:hover .toggle-icon,
  .distance-badge:hover,
  .no-results-nearby button:hover {
    transform: none;
  }
}

/* High contrast mode */
@media (prefers-contrast: high) {
  .geolocation-filter {
    border: 3px solid #212529;
  }

  .radius-selector,
  .radius-select {
    border: 2px solid #212529;
  }

  .distance-badge {
    border-width: 2px;
    box-shadow: none;
  }

  .no-results-nearby {
    border: 3px dashed #212529;
  }
}

/* Print styles */
@media print {
  .geolocation-filter,
  .no-results-nearby button {
    display: none;
  }

  .distance-badge {
    box-shadow: none;
    border: 1px solid #212529;
  }
}

/* ============================================
   DISTANCE BADGE SIMPLE - NUEVO DISEÑO MINIMALISTA
   ============================================ */

.distance-badge-simple {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.5rem;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
  transition: all 0.2s ease;
  cursor: default;
  line-height: 1;
  border: 1px solid transparent;
}

.distance-badge-simple .distance-icon {
  width: 11px;
  height: 11px;
  opacity: 0.8;
  flex-shrink: 0;
}

.distance-badge-simple .distance-text {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.distance-badge-simple .closest-star {
  display: inline-block; /* Forzar display - fix bug de invisibilidad */
  width: 14px;
  height: 14px;
  margin-left: 0.25rem;
  flex-shrink: 0;
  animation: twinkle 1.5s ease-in-out infinite;
}

@keyframes twinkle {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.1); }
}

/* ============================================
   BADGE DE DISTANCIA - SIMPLE Y DISCRETO
   Solo muestra la distancia, NO indica si es bueno o malo
   El único destacado es el "MÁS CERCANO" (ver abajo)
   ============================================ */

/* Badge neutral para todas las distancias */
.distance-badge-simple {
  background: rgba(107, 114, 128, 0.08);
  color: #4b5563;
  border-color: rgba(107, 114, 128, 0.2);
}

.distance-badge-simple .distance-icon {
  color: #6b7280;
  opacity: 0.7;
}

/* Sin colores graduales - todas las distancias usan el mismo estilo neutral */
.distance-badge-simple.very-close,
.distance-badge-simple.close,
.distance-badge-simple.far,
.distance-badge-simple.very-far {
  /* Todos heredan el estilo neutral de arriba */
  background: rgba(107, 114, 128, 0.08);
  color: #4b5563;
  border-color: rgba(107, 114, 128, 0.2);
}

.distance-badge-simple.very-close .distance-icon,
.distance-badge-simple.close .distance-icon,
.distance-badge-simple.far .distance-icon,
.distance-badge-simple.very-far .distance-icon {
  color: #6b7280;
  opacity: 0.7;
}

/* ============================================
   🏆 MÁS CERCANO - EL ÚNICO DESTACADO (GANADOR)
   Verde SuperPrecio + Estrella Dorada
   Este es el ÚNICO badge con color - el resto es neutral
   ============================================ */

.distance-badge-simple.closest {
  background: linear-gradient(135deg, rgba(19, 98, 19, 0.15), rgba(19, 98, 19, 0.10));
  border: 2px solid #136213;
  box-shadow: 0 3px 12px rgba(19, 98, 19, 0.25);
  font-weight: 700;
  color: #0a4a0a;
  animation: highlight-pulse 2s ease-in-out infinite;
}

@keyframes highlight-pulse {
  0%, 100% {
    box-shadow: 0 3px 12px rgba(19, 98, 19, 0.25);
  }
  50% {
    box-shadow: 0 4px 16px rgba(19, 98, 19, 0.35);
  }
}

.distance-badge-simple.closest .distance-icon {
  color: #136213;
  opacity: 1;
}

.distance-badge-simple.closest .closest-star {
  color: #fbbf24; /* Estrella dorada - indica "ganador" */
  filter: drop-shadow(0 1px 2px rgba(251, 191, 36, 0.5));
}

/* Efecto hover sutil (no clickeable, pero visual feedback) */
.distance-badge-simple:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.distance-badge-simple.closest:hover {
  box-shadow: 0 3px 10px rgba(19, 98, 19, 0.2);
}

/* ============================================
   RESPONSIVE - MOBILE FIRST (Badge Simple)
   ============================================ */

/* Móvil pequeño */
@media (max-width: 374px) {
  .distance-badge-simple {
    font-size: 0.65rem;
    padding: 0.2rem 0.4rem;
    gap: 0.2rem;
  }

  .distance-badge-simple .distance-icon {
    width: 9px;
    height: 9px;
  }

  .distance-badge-simple .closest-star {
    width: 12px;
    height: 12px;
  }
}

/* Tablet y superior */
@media (min-width: 576px) {
  .distance-badge-simple {
    font-size: 0.75rem;
    padding: 0.3rem 0.6rem;
  }

  .distance-badge-simple .distance-icon {
    width: 12px;
    height: 12px;
  }

  .distance-badge-simple .closest-star {
    width: 16px;
    height: 16px;
  }
}

/* Desktop */
@media (min-width: 768px) {
  .distance-badge-simple {
    font-size: 0.8rem;
    padding: 0.35rem 0.7rem;
  }
}

/* ============================================
   ACCESIBILIDAD (Badge Simple)
   ============================================ */

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .distance-badge-simple,
  .distance-badge-simple:hover,
  .distance-badge-simple .closest-star {
    animation: none;
    transform: none;
  }
}

/* High contrast mode */
@media (prefers-contrast: high) {
  .distance-badge-simple {
    border-width: 2px;
    background: #f3f4f6;
    color: #000000;
    border-color: #6b7280;
  }

  /* Solo el más cercano tiene color en high contrast */
  .distance-badge-simple.closest {
    background: #136213;
    color: #ffffff;
    border-color: #0a4a0a;
    border-width: 3px;
  }
}

/* ========================================
   ESTRELLA EN PRICE-BOX (Más Cercano)
   ======================================== */

/* Price-box con estrella - más cercano globalmente */
.price-box {
  position: relative; /* Necesario para posicionar la estrella absoluta */
}

.price-box.closest-market {
  border-color: #136213; /* Verde SuperPrecio */
  box-shadow: 0 2px 8px rgba(19, 98, 19, 0.15);
}

/* Estrella dorada + distancia SOBRE el borde superior derecho del card - como badge pegado */
.closest-star-badge {
  position: absolute;
  top: -8px;
  right: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  background: white;
  padding: 2px 4px;
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  z-index: 10;
  pointer-events: none; /* No interferir con clicks del price-box */
  border: 1px solid #fbbf24; /* Borde dorado para destacar sobre el borde del card */
}

.closest-star-badge svg {
  display: block;
  width: 12px;
  height: 12px;
  color: #fbbf24; /* Dorado */
  filter: drop-shadow(0 0.5px 1px rgba(251, 191, 36, 0.4));
  animation: twinkle 1.5s ease-in-out infinite;
}

/* Texto de distancia visible - verde corporativo */
.badge-distance {
  font-size: 7px;
  font-weight: 700;
  color: #136213; /* Verde SuperPrecio */
  line-height: 1;
  white-space: nowrap;
  letter-spacing: -0.02em;
}

/* Animación sutil */
@keyframes twinkle {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(0.95); }
}

/* Responsive: Badge más compacto en mobile */
@media (max-width: 576px) {
  .closest-star-badge {
    padding: 2px 3px;
    gap: 0px;
    top: -6px;
    right: 8px;
  }

  .closest-star-badge svg {
    width: 10px;
    height: 10px;
  }

  .badge-distance {
    font-size: 6px;
  }
}

/* Print styles */
@media print {
  .distance-badge-simple {
    box-shadow: none;
    border: 1px solid currentColor;
  }

  .distance-badge-simple .closest-star {
    display: none;
  }

  .closest-star-badge {
    display: none;
  }
}
