/* ======================
   Reset y configuración base
   ====================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  width: 100%;
  font-family: "Inter", system-ui, -apple-system, Segoe UI, Roboto, Helvetica,
    Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: #1f2937;
  overflow-x: hidden;
  position: relative;
}

/* ======================
   Contenedor del mapa
   ====================== */
#map {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1;
}

/* ======================
   Botón 3 puntos y Panel lateral
   ====================== */
.menu-button {
  position: fixed;
  top: 17px;
  left: 12px;
  z-index: 20;
  background: rgb(255, 255, 255);
  color: #000000;
  border: none;
  border-radius: 10px;
  width: 40px;
  height: 40px;
  font-size: 22px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.menu-button:hover {
  background: rgb(255, 255, 255);
}

/* Botón flotante del ojo para cargar notas */
.load-houses-button {
  position: fixed;
  top: 72px; /* Mejor separación del botón de menú */
  left: 12px; /* Misma posición horizontal que el botón de menú */
  z-index: 15;
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 50%;
  width: 42px; /* Ligeramente más grande */
  height: 42px; /* Ligeramente más grande */
  font-size: 16px; /* Tamaño de ícono apropiado */
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
  transition: all 0.3s ease;
  opacity: 0;
  transform: none;
}

.load-houses-button.show {
  opacity: 1;
  transform: none;
}

.load-houses-button:hover {
  background: #1d4ed8;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.4);
  transform: none;
}

.load-houses-button:active {
  transform: none;
}

.load-houses-button.loading {
  background: #6b7280;
  cursor: not-allowed;
}

.load-houses-button.loading::after {
  content: "";
  width: 20px;
  height: 20px;
  border: 2px solid #ffffff;
  border-top: 2px solid transparent;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  position: absolute;
}

.load-houses-button i {
  transition: transform 0.2s ease;
}

.load-houses-button:hover i {
  transform: scale(1.1);
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Responsive para el botón del ojo */
@media (max-width: 768px) {
  .load-houses-button {
    top: 75px; /* Más separación del botón de menú */
    left: 15px;
    width: 48px; /* Más grande en tablets */
    height: 48px;
    font-size: 18px;
  }
}

@media (max-width: 480px) {
  .load-houses-button {
    top: 70px; /* Buena separación en móviles */
    left: 12px;
    width: 44px; /* Más grande en móviles pequeños */
    height: 44px;
    font-size: 16px;
  }
}

.side-panel {
  position: fixed;
  top: 0;
  right: -320px; /* oculto por defecto */
  width: 320px;
  max-width: 86vw;
  height: 100vh;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(6px);
  box-shadow: -8px 0 30px rgba(0, 0, 0, 0.12);
  border-left: 1px solid #e5e7eb;
  z-index: 19; /* por debajo del botón */
  transition: right 0.25s ease-in-out;
  display: flex;
  flex-direction: column;
}
.side-panel.open {
  right: 0; /* visible */
}
.side-header {
  padding: 14px 16px;
  font-weight: 700;
  border-bottom: 1px solid #e5e7eb;
}
.top-list {
  padding: 8px 8px 16px;
  overflow-y: auto;
}
.top-item {
  display: flex;
  gap: 10px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid #e5e7eb;
  margin: 8px 0;
  cursor: pointer;
  background: #ffffff;
}
.top-item:hover {
  background: #f9fafb;
}
.top-rank {
  font-weight: 800;
  color: #2563eb;
  width: 24px;
  text-align: center;
}
.top-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.side-panel {
  display: flex;
  flex-direction: column;
  height: 100%; /* asegúrate de que el contenedor tenga altura definida */
}

.top-list {
  flex-grow: 1; /* empuja el contenido hacia arriba */
}

.support-note {
  padding: 10px;
  font-size: 14px;
  text-align: center;
  color: #555;
  border-top: 1px solid #ddd;
}

.support-note a {
  color: #e1306c; /* color oficial de Instagram */
  font-weight: bold;
  text-decoration: none;
}

.support-note a:hover {
  text-decoration: underline;
}

.top-title {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.top-desc {
  color: #6b7280;
  font-size: 12px;
  white-space: normal;
  max-height: 60px;
  overflow-y: auto;
}
.top-meta {
  color: #9ca3af;
  font-size: 12px;
}

/* ======================
   Marcadores (chips)
   ====================== */
.marker-chip {
  background: #111827;
  color: #fff;
  padding: 6px 10px;
  border-radius: 9999px;
  font-size: 13px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.12);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 92vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.marker-chip .emoji {
  font-size: 14px;
  flex-shrink: 0;
}
.marker-chip.highlight {
  outline: 2px solid #60a5fa;
}

/* ======================
   InfoWindow contenido - MEJORADO
   ====================== */
.gm-style .gm-style-iw,
.gm-style .gm-style-iw-c {
  max-width: 100vw !important;
  min-width: 0 !important;
  padding: 12px !important;
  border-radius: 12px !important;
}

.infowindow {
  width: clamp(
    300px,
    85vw,
    420px
  ); /* Ligeramente más ancho para mejor legibilidad */
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}
.infowindow .title {
  font-weight: 700;
  margin-bottom: 4px;
  font-size: 19px; /* Aumentado para mejor legibilidad */
  line-height: 1.4;
  word-wrap: break-word;
}
.infowindow .desc {
  color: #374151;
  white-space: pre-wrap;
  line-height: 1.6; /* Mejor interlineado */
  font-size: 16px; /* Aumentado para mejor legibilidad */
  overflow-wrap: anywhere;
  height: auto;
  overflow-y: auto;
  padding: 6px; /* Más espacio para mejor legibilidad */
  border-radius: 6px;
  max-height: none; /* Permitir que crezca según el contenido */
}

.infowindow .desc::-webkit-scrollbar {
  width: 6px;
}
.infowindow .desc::-webkit-scrollbar-thumb {
  border-radius: 10px;
}
.infowindow .actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.infowindow button {
  border: none;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  flex: 1;
  min-width: 0;
}
.infowindow .primary {
  background: #2563eb;
  color: white;
}
.infowindow .danger {
  background: #ef4444;
  color: white;
}

/* ======================
   Sección de Comentarios - MEJORADA
   ====================== */
.comments-section {
  border-top: 1px solid #e5e7eb;
  padding-top: 15px;
  max-height: 220px; /* Altura reducida para dar prioridad a la descripción */
  overflow-y: auto;
}

.comment {
  padding: 10px;
  margin-bottom: 10px;
  background: #f9fafb;
  border-radius: 8px;
  font-size: 14px;
}

/* ======================
   Formulario de comentarios COMPACTO - NUEVO
   ====================== */
.comment-form.quick-form {
  display: flex;
  flex-direction: row; /* Input y botón en la misma línea */
  gap: 8px;
  padding: 10px;
  align-items: center;
  margin-top: 12px;
  background: #f8f9fa;
  border-radius: 12px;
}

.comment-form.quick-form input {
  flex: 1; /* Ocupa todo el espacio disponible */
  padding: 10px 14px;
  border-radius: 20px; /* Bordes redondeados para coincidir con el botón */
  border: 1px solid #e5e7eb;
  font-size: 14px;
  font-family: inherit;
  margin: 0;
}

.comment-form.quick-form .actions {
  margin: 0;
  flex-shrink: 0; /* Evita que se reduzca */
}

#comment-submit {
  padding: 10px; /* Botón cuadrado pequeño */
  width: 40px;
  height: 40px;
  border-radius: 50%; /* Botón circular */
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px; /* Tamaño del icono */
}

/* Icono de enviar (puede reemplazarse con una imagen SVG) */
#comment-submit::before {
  content: "→";
}

/* ======================
   Formulario rápido
   ====================== */
.quick-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}
.quick-form input,
.quick-form textarea {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid #e5e7eb;
  font-size: 16px;
  font-family: inherit;
}
.quick-form textarea {
  min-height: 120px;
  resize: none;
}
.quick-form .row {
  display: flex;
  gap: 10px;
}

/* ======================
   Indicaciones flotantes
   ====================== */
.floating-hint {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(6px);
  border: 1px solid #e5e7eb;
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  z-index: 10;
  max-width: 92vw;
  text-align: center;
}
.floating-hint .hint-title {
  font-weight: 600;
  margin-bottom: 4px;
}
.floating-hint .hint-text {
  font-size: 13px;
  color: #6b7280;
}

/* ======================
   Botón de cerrar InfoWindow (Google Maps - legado)
   ====================== */
.gm-ui-hover-effect {
  top: 8px !important;
  right: 8px !important;
  width: 30px !important;
  height: 30px !important;
}
.gm-ui-hover-effect img {
  width: 18px !important;
  height: 18px !important;
}

/* ======================
   Mapbox Popup (nuevo)
   ====================== */
.mapboxgl-popup {
  max-width: none !important; /* evitar límite global por defecto */
}
.mapboxgl-popup-content {
  padding: 12px !important;
  border-radius: 12px !important;
  width: auto !important; /* permite que el contenido gestione el ancho */
  max-width: 440px !important; /* Aumentado para acomodar el nuevo diseño */
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}
/* Asegurar buena posición y clic cómodo del botón cerrar */
.mapboxgl-popup-close-button {
  font-size: 18px;
  right: 6px !important;
  top: 6px !important;
  width: 28px;
  height: 28px;
  border-radius: 6px;
}
.mapboxgl-popup-close-button:hover {
  background: rgba(0, 0, 0, 0.06);
}
/* Forzar scroll vertical solo en la sección de comentarios */
.mapboxgl-popup-content .infowindow {
  max-height: 70vh; /* Mayor altura para dar espacio a la descripción */
  overflow: visible; /* permitir que el contenido se expanda */
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
}
.mapboxgl-popup-content .comments-section {
  overflow-y: auto; /* scroll solo en comentarios */
  overscroll-behavior: contain;
  min-height: 0; /* permitir que se encoja */
  max-height: 220px; /* límite máximo para comentarios */
}
.mapboxgl-popup-content .comment-form {
  flex-shrink: 0; /* no se encoja */
  margin-top: 10px;
}

/* ======================
   Responsive
   ====================== */
@media (max-width: 1024px) {
  .infowindow {
    width: clamp(280px, 80vw, 380px);
  }
}

@media (max-width: 768px) {
  .infowindow {
    width: 82vw;
    gap: 10px;
  }
  .infowindow .title {
    font-size: 18px;
  }
  .infowindow .desc {
    font-size: 15px;
    padding: 5px;
  }
  .infowindow button {
    padding: 12px 10px;
    font-size: 13px;
  }
  .comments-section {
    max-height: 180px;
  }
  .comment-form.quick-form {
    flex-direction: row; /* Mantener en fila incluso en móviles */
    padding: 8px;
  }
  .comment-form.quick-form input {
    padding: 8px 12px;
    font-size: 14px;
  }
  #comment-submit {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }
  .quick-form input,
  .quick-form textarea {
    padding: 10px;
    font-size: 15px;
  }
  .quick-form textarea {
    min-height: 100px;
  }
  .floating-hint {
    padding: 10px 14px;
  }
  .floating-hint .hint-title {
    font-size: 15px;
  }
  .floating-hint .hint-text {
    font-size: 12px;
    display: none;
  }
}

@media (max-width: 480px) {
  .infowindow {
    margin-top: 20px;
    width: 80vw;
  }
  .infowindow .title {
    font-size: 17px;
  }
  .infowindow .desc {
    font-size: 14px;
    line-height: 1.5;
  }
  .infowindow button {
    padding: 10px 8px;
    font-size: 12px;
  }
  .comments-section {
    max-height: 160px;
  }
  .comment-form.quick-form {
    padding: 6px;
  }
  .comment-form.quick-form input {
    padding: 6px 10px;
    font-size: 13px;
  }
  #comment-submit {
    width: 32px;
    height: 32px;
    font-size: 14px;
  }
  .quick-form textarea {
    min-height: 80px;
  }
  .marker-chip {
    font-size: 12px;
    padding: 5px 8px;
  }
}

/* ======================
   Prevenir zoom en inputs iOS
   ====================== */
@media screen and (max-width: 768px) {
  input,
  textarea {
    font-size: 16px !important;
  }
}

/* ======================
   Estilos para Emojis
   ====================== */
.emoji-section {
  border-top: 1px solid #e5e7eb;
  margin-top: 10px;
  padding-top: 10px;
}

.emoji-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  color: #6b7280;
  text-align: center;
}

.emoji-grid {
  display: flex;
  flex-direction: row;
  gap: 6px;
  margin-bottom: 8px;
  overflow-x: auto;
  padding: 4px 0;
}

.emoji-btn {
  width: 60px;
  height: 50px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #ffffff;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  padding: 4px;
  flex-shrink: 0;
  gap: 2px;
}

.emoji-icon {
  font-size: 20px;
  line-height: 1;
}

.emoji-label {
  font-size: 10px;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.emoji-btn:hover {
  background: #f9fafb;
  border-color: #d1d5db;
  transform: scale(1.05);
}

.emoji-btn:active {
  transform: scale(0.95);
}

.emoji-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.emoji-btn:disabled .emoji-label {
  color: #9ca3af;
}

/* Estilos responsivos para emojis */
@media (max-width: 768px) {
  .emoji-btn {
    width: 50px;
    height: 42px;
    padding: 3px;
  }

  .emoji-icon {
    font-size: 18px;
  }

  .emoji-label {
    font-size: 9px;
  }

  .emoji-grid {
    gap: 4px;
    padding: 2px 0;
  }
}

@media (max-width: 480px) {
  .emoji-btn {
    width: 45px;
    height: 38px;
    padding: 2px;
  }

  .emoji-icon {
    font-size: 16px;
  }

  .emoji-label {
    font-size: 8px;
  }

  .emoji-grid {
    gap: 3px;
  }
}

.emoji-status {
  font-size: 12px;
  color: #6b7280;
  text-align: center;
}

/* Estilos para marcadores de emoji en el mapa */
.emoji-marker {
  font-size: 24px;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
  user-select: none;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.emoji-marker:hover {
  transform: scale(1.1);
}

/* ======================
   Export Section
   ====================== */
.export-section {
  padding: 12px 16px;
  border-top: 1px solid #e5e7eb;
  background: #f9fafb;
}

.export-title {
  font-size: 14px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 8px;
  text-align: center;
}

.export-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.export-btn {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #ffffff;
  color: #374151;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.export-btn:hover {
  background: #f3f4f6;
  border-color: #9ca3af;
}

.export-btn:active {
  transform: scale(0.98);
}

.export-btn i {
  font-size: 11px;
}

/* Responsive adjustments for export buttons */
@media (max-width: 768px) {
  .export-section {
    padding: 10px 12px;
  }

  .export-title {
    font-size: 13px;
  }

  .export-btn {
    padding: 6px 8px;
    font-size: 11px;
  }
}
