/* ============================================
   GEOPORTAL FONATUR — Design System
   Paleta: GOB.mx / FONATUR
   ============================================ */

/* --- Tokens --- */
:root {
  --guinda: #235C4E;        /* Verde Pino, antes guinda */
  --guinda-dark: #1A443A;   /* Verde Oscuro, 10% más oscuro que 235C4E */
  --gold: #45BB64;          /* Verde Lima, antes oro */
  --gold-light: #5BD378;    /* Verde Lima Claro */
  --green: #45BB64;         /* Verde Lima, para marinas */
  --green-light: #5BD378;   /* Verde Lima Claro */
  --pti: #3B3B3B;           /* Carbón, para pti */
  --gray: #8A8D8F;          /* Gris ligeramente más neutro */
  --text: #3B3B3B;          /* Texto oscuro carbón */
  --text-secondary: #585858;/* Texto secundario */
  --bg: #EFE7DA;            /* Beige crema para app background */
  --white: #ffffff;
  --border: #DECFBA;        /* Borde derivado de EFE7DA un poco más oscuro */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.16);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --sidebar-w: 400px;
  --header-h: 130px;
}

/* --- Reset --- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html {
  -webkit-text-size-adjust: 100%;
}
body {
  font-family:
    "Lato",
    system-ui,
    -apple-system,
    sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  line-height: 1.5;
}
button {
  font: inherit;
  cursor: pointer;
  border: none;
  background: none;
}
img {
  max-width: 100%;
  display: block;
}

/* --- Layout --- */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-height: 100vh;
  width: 100%;
  overflow: hidden;
  isolation: isolate; /* Crea stacking context propio para todo el app */
}

/* --- Top Bar (horizontal) --- */
#sidebar {
  width: 100%;
  height: auto;
  min-height: var(--topbar-h, 100px);
  flex-shrink: 0;
  position: relative;
  background: var(--white);
  display: flex;
  flex-direction: row;
  align-items: stretch;
  flex-wrap: wrap;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.14);
  z-index: 900;
  overflow: hidden;
}

/* Header — columna izquierda del topbar */
.header {
  background: #212222;
  color: #fff;
  padding: 12px 20px;
  flex: 1 1 200px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-right: 3px solid var(--gold);
  border-bottom: 3px solid var(--gold);
}
.header::after {
  display: none; /* barra inferior reemplazada por borde derecho */
}
.header h1,
.header-title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 2px;
  text-align: left;
  margin: 0 0 4px 0;
  white-space: nowrap;
  color: #ffffff;
}
.header p {
  font-size: 11px;
  opacity: 0.85;
  font-weight: 300;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-stats {
  display: flex;
  gap: 12px;
  margin-top: 6px;
  font-size: 11px;
  opacity: 0.85;
}
.header-stat {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Especiales: Fonatur en la historia & Nuevo Fonatur */
.fona-specials-bar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  background: linear-gradient(120deg, #f9f6f0, #efe7dc);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.special-feature-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  padding: 5px 10px 5px 5px;
  cursor: pointer;
  transition: all 0.25s var(--ease);
  box-shadow: var(--shadow-sm);
  flex: 1 1 125px;
  text-align: left;
  position: relative;
  overflow: hidden;
}
.special-feature-btn:hover {
  border-color: var(--guinda);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  background: #fffdf9;
}
.special-feature-img {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
  border: 1px solid var(--gold);
  box-shadow: 0 2px 4px rgba(0,0,0,0.12);
}
.special-feature-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.special-feature-text small {
  font-size: 8.5px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--guinda);
  font-weight: 700;
  line-height: 1.1;
}
.special-feature-text strong {
  font-size: 11.5px;
  color: var(--text);
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.25;
}
.special-feature-zoom {
  margin-left: auto;
  font-size: 12px;
  color: var(--gray);
  opacity: 0.7;
  transition: transform 0.2s var(--ease), color 0.2s var(--ease);
}
.special-feature-btn:hover .special-feature-zoom {
  transform: scale(1.25);
  color: var(--guinda);
  opacity: 1;
}

/* Timeline — sección horizontal del topbar */
.timeline-control {
  background: linear-gradient(120deg, #faf8f5, #f0ece6);
  padding: 10px 16px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  flex: 2 1 200px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}
.timeline-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--guinda);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}
/* Año actual inline junto al label */
.timeline-label::after {
  content: attr(data-year);
  font-size: 13px;
  font-weight: 800;
  color: var(--guinda);
  letter-spacing: 0;
}
.timeline-slider {
  -webkit-appearance: none;
  width: 100%;
  height: 5px;
  border-radius: 3px;
  background: #d5cec3;
  outline: none;
}
.timeline-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--guinda);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(35, 92, 78, 0.45);
  transition: transform 0.2s var(--ease);
}
.timeline-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}
.timeline-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--guinda);
  border: none;
  box-shadow: 0 2px 8px rgba(35, 92, 78, 0.45);
}
.timeline-years {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: var(--gray);
}
/* Año actual: oculto (se muestra en el label::after via JS) */
.timeline-current {
  display: none;
}

/* Filters — sección horizontal */
.filter-chips {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  flex: 1.5 1 160px;
}
/* Fila interna de chips */
.filter-chips-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.filter-chip {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  border: 2px solid var(--border);
  background: var(--white);
  color: var(--text-secondary);
  transition: all 0.2s var(--ease);
  white-space: nowrap;
}
.filter-chip:hover {
  border-color: var(--guinda);
  color: var(--guinda);
}
.filter-chip.active {
  background: var(--guinda);
  color: #fff;
  border-color: var(--guinda);
}

/* Search — sección horizontal */
.search-container {
  padding: 10px 14px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  flex: 1.5 1 150px;
  display: flex;
  align-items: center;
}
.search-box {
  position: relative;
  width: 100%;
}
.search-input {
  width: 100%;
  padding: 9px 36px 9px 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  background: #fafafa;
  transition: all 0.25s var(--ease);
}
.search-input:focus {
  outline: none;
  border-color: var(--guinda);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(35, 92, 78, 0.1);
}
.search-input::placeholder {
  color: #aaa;
}
.search-icon {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #aaa;
  font-size: 15px;
}

/* Legend — sección horizontal */
.legend-live {
  padding: 10px 14px;
  flex: 2 1 250px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: linear-gradient(120deg, #faf8f5, #f5f0ea);
  border-bottom: 1px solid var(--border);
}
.legend-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--guinda);
  font-weight: 700;
  margin-bottom: 8px;
}
.legend-items {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
}
.legend-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  flex-shrink: 0;
}
.legend-dot--cip {
  background: var(--guinda);
}
.legend-dot--marina {
  background: var(--green);
}
.legend-dot--pti {
  background: var(--pti);
}
.legend-count {
  font-weight: 700;
  color: var(--guinda);
  font-size: 15px;
  min-width: 18px;
  text-align: center;
  transition: transform 0.3s var(--ease);
}
.legend-count.bump {
  animation: countBump 0.4s var(--ease);
}
@keyframes countBump {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.4);
  }
  100% {
    transform: scale(1);
  }
}

/* Sites list — oculta en topbar horizontal */
.sites-list {
  display: none;
}
.sites-list::-webkit-scrollbar {
  width: 6px;
}
.sites-list::-webkit-scrollbar-track {
  background: transparent;
}
.sites-list::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}
.sites-list::-webkit-scrollbar-thumb:hover {
  background: #aaa;
}

/* Site Card */
.site-card {
  background: #fff;
  border: 1px solid var(--border);
  border-left: 4px solid transparent;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: all 0.3s var(--ease);
  box-shadow: var(--shadow-sm);
  position: relative;
}
.site-card:hover {
  transform: translateX(4px);
  box-shadow: var(--shadow-md);
  border-left-color: var(--gold);
}
.site-card.active {
  border-left-color: var(--guinda);
  background: linear-gradient(135deg, #fdf6f8, #fff);
}

.card-img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 10px;
  transition: transform 0.5s var(--ease);
}
.site-card:hover .card-img {
  transform: scale(1.03);
}

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.site-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--guinda-dark);
  line-height: 1.3;
  margin-bottom: 4px;
}
.site-state {
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
}
.site-state::before {
  content: "📍";
  font-size: 13px;
}
.site-year {
  font-size: 11px;
  color: var(--gray);
  margin-top: 2px;
}
.site-badge {
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}
.site-badge--cip {
  background: var(--guinda);
  color: #fff;
}
.site-badge--marina {
  background: var(--green);
  color: #fff;
}
.site-badge--pti {
  background: var(--pti);
  color: #fff;
}
.site-badge--dtc {
  background: #e07a5f;
  color: #fff;
}
.site-badge--tm {
  background: #235C4E;
  border: 1px solid #45BB64;
  color: #fff;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--guinda);
  outline-offset: 2px;
}

.view-more-btn {
  margin-top: 8px;
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  background: var(--gold);
  color: #fff;
  transition: background 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.view-more-btn:hover {
  background: var(--guinda);
}

/* Popups: asegurar que ningún botón "Ver detalles" se mueva al pasar el cursor sobre él */
.leaflet-popup .view-more-btn,
.leaflet-popup .view-more-btn:hover {
  transform: none;
}
.gallery-popup-btn,
.gallery-popup-btn:hover {
  transform: translateX(-50%) !important;
}

/* Image wrap with button overlay */
.card-img-wrap {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  margin-bottom: 10px;
}
.card-img-wrap .card-img {
  margin-bottom: 0;
  border-radius: 8px;
  display: block;
}
.card-img-btn {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 0;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  opacity: 0;
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease) !important;
  transform: translateX(-50%) translateY(4px);
}
.card-img-wrap:hover .card-img-btn,
.site-card:hover .card-img-btn {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Toggle Sidebar — eliminado del diseño */
.toggle-sidebar {
  display: none;
}

/* Map controls */
.map-controls {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 800;
  transition: all 0.3s var(--ease);
}
.ctrl-btn {
  background: #fff;
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  box-shadow: var(--shadow-md);
  font-size: 13px;
  color: var(--text);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.25s var(--ease);
  white-space: nowrap;
}
.ctrl-btn:hover {
  background: var(--guinda);
  color: #fff;
  border-color: var(--guinda);
  transform: translateY(-2px);
}
.ctrl-btn--special {
  background: linear-gradient(135deg, #fffdf8, #f5efe3);
  border-color: var(--gold);
  color: var(--guinda);
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(35, 92, 78, 0.15);
}
.ctrl-btn--special:hover {
  background: var(--guinda);
  color: #fff;
  border-color: var(--guinda);
}

/* KMZ button variant */
.ctrl-btn--kmz {
  background: linear-gradient(135deg, #fffdf8, #f0ece6);
  border-color: #c9a85c;
  color: #7a5c1e;
  font-weight: 700;
}
.ctrl-btn--kmz:hover,
.ctrl-btn--kmz.active {
  background: #7a5c1e;
  color: #fff;
  border-color: #7a5c1e;
}

/* KMZ Panel — flotante sobre el mapa */
.kmz-panel {
  position: absolute;
  top: 16px;
  right: 160px; /* a la izquierda de los controles */
  width: 260px;
  background: #fff;
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  border: 1.5px solid var(--border);
  z-index: 850;
  overflow: hidden;
  animation: fadeSlideIn 0.22s var(--ease);
}
.kmz-panel[hidden] { display: none; }

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

.kmz-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 10px;
  background: linear-gradient(135deg, #7a5c1e, #a07828);
  color: #fff;
}
.kmz-panel-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.kmz-reload-btn {
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.4);
  color: #fff;
  border-radius: 8px;
  width: 28px;
  height: 28px;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s var(--ease);
}
.kmz-reload-btn:hover {
  background: rgba(255,255,255,0.35);
}
.kmz-reload-btn.spinning {
  animation: spin 0.7s linear;
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

.kmz-panel-body {
  max-height: 280px;
  overflow-y: auto;
  padding: 8px 0;
}
.kmz-panel-body::-webkit-scrollbar { width: 4px; }
.kmz-panel-body::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }

.kmz-empty {
  padding: 18px 16px;
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.6;
}
.kmz-empty code {
  background: #f3ede4;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11px;
}

.kmz-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  cursor: default;
  transition: background 0.15s var(--ease);
  border-bottom: 1px solid #f5f0ea;
}
.kmz-item:last-child { border-bottom: none; }
.kmz-item:hover { background: #fdf9f3; }
.kmz-item--active { background: #fdf6e9; }

.kmz-item-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,0.8);
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
.kmz-item-label {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kmz-item-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 7px;
  width: 28px;
  height: 28px;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease);
  flex-shrink: 0;
}
.kmz-item-btn:hover {
  background: #f0ece6;
  border-color: #c9a85c;
}

/* Map Legend (floating) */
.map-legend {
  position: absolute;
  bottom: 40px;
  right: 16px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  border-radius: 12px;
  padding: 14px 18px;
  box-shadow: var(--shadow-lg);
  z-index: 800;
  min-width: 180px;
}
.map-legend .legend-title {
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--gold);
}
.map-legend .legend-item {
  margin-bottom: 6px;
}

/* Footer */
.footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(6px);
  padding: 8px 20px;
  font-size: 11px;
  color: var(--gray);
  display: flex;
  justify-content: space-between;
  z-index: 800;
  border-top: 1px solid var(--border);
  pointer-events: none;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  padding: 20px;
}
.modal-overlay.active {
  display: flex;
}
.modal {
  background: #fff;
  border-radius: 16px;
  max-width: 580px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.3s var(--ease);
}
@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(24px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.modal-head {
  background: linear-gradient(135deg, var(--guinda), var(--guinda-dark));
  color: #fff;
  padding: 24px;
  border-radius: 16px 16px 0 0;
  position: relative;
}
.modal-head h2 {
  font-size: 20px;
  font-weight: 700;
}
.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 22px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s var(--ease);
}
.modal-close:hover {
  background: rgba(255, 255, 255, 0.35);
  transform: rotate(90deg);
}
.modal-carousel {
  width: 100%;
  height: 260px;
  position: relative;
  overflow: hidden;
}
.modal-carousel img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  opacity: 0;
  transition: opacity 0.5s ease;
}
.modal-carousel img.active {
  opacity: 1;
}
.carousel-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  transition: background 0.2s;
}
.carousel-nav:hover {
  background: rgba(0, 0, 0, 0.7);
}
.carousel-nav.prev {
  left: 10px;
}
.carousel-nav.next {
  right: 10px;
}
.carousel-dots {
  display: flex;
  gap: 6px;
  justify-content: center;
  padding: 10px 0;
}
.carousel-dots .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ccc;
  cursor: pointer;
  transition: all 0.2s var(--ease);
}
.carousel-dots .dot.active {
  background: var(--guinda);
  transform: scale(1.3);
}
.modal-body {
  padding: 24px;
}
.modal-section {
  margin-bottom: 20px;
}
.modal-section h3 {
  color: var(--guinda);
  font-size: 16px;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--gold);
}
.modal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.modal-item {
  background: var(--bg);
  padding: 12px;
  border-radius: 8px;
}
.modal-label {
  font-size: 10px;
  color: var(--gray);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}
.modal-value {
  font-size: 15px;
  font-weight: 700;
  color: var(--guinda-dark);
}

/* Gallery special modal — full image, no chrome */
.modal--gallery {
  background: transparent;
  box-shadow: none;
  border-radius: 0;
  overflow: visible;
  max-width: none;
  width: auto;
  max-height: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal--gallery .modal-head { display: none; }
.modal--gallery .modal-body { display: none; }
.modal--gallery .carousel-dots { display: none; }

/* Gallery carousel: just the image, no fixed size */
.modal--gallery .modal-carousel {
  position: static;
  height: auto;
  background: transparent;
  overflow: visible;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal--gallery .modal-carousel img {
  width: auto;
  height: auto;
  max-width: min(90vw, 880px);
  max-height: 80vh;
  position: static;
  border-radius: 10px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
  opacity: 0;
  display: none;
  transition: opacity 0.25s ease;
}
.modal--gallery .modal-carousel img.active {
  display: block;
  opacity: 1;
}

/* ===== Gallery overlay controls ===== */
/* Container spans the full overlay via position:fixed */
.gal-controls {
  position: fixed;
  inset: 0;
  pointer-events: none; /* pass clicks through to overlay close */
  z-index: 2010;
}

/* All individual buttons restore pointer events */
.gal-btn {
  position: absolute;
  pointer-events: all;
  background: rgba(0,0,0,0.55);
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.15s;
  backdrop-filter: blur(6px);
}
.gal-btn:hover {
  background: rgba(0,0,0,0.82);
  transform: scale(1.08);
}

/* Close — top right */
.gal-close {
  top: 18px;
  right: 18px;
  width: 44px;
  height: 44px;
  font-size: 24px;
}

/* Ampliar — top right, below close */
.gal-expand {
  top: 70px;
  right: 18px;
  width: 44px;
  height: 44px;
  font-size: 19px;
}

/* Prev arrow — left center */
.gal-prev {
  top: 50%;
  left: 18px;
  transform: translateY(-50%);
  width: 52px;
  height: 52px;
  font-size: 30px;
  border-radius: 50%;
}
.gal-prev:hover { transform: translateY(-50%) scale(1.08); }

/* Next arrow — right center */
.gal-next {
  top: 50%;
  right: 18px;
  transform: translateY(-50%);
  width: 52px;
  height: 52px;
  font-size: 30px;
  border-radius: 50%;
}
.gal-next:hover { transform: translateY(-50%) scale(1.08); }

/* Counter — top left */
.gal-counter {
  position: absolute;
  pointer-events: none;
  top: 20px;
  left: 20px;
  background: rgba(0,0,0,0.5);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 5px 14px;
  border-radius: 20px;
  backdrop-filter: blur(4px);
  font-family: "Lato", system-ui, sans-serif;
}

/* Dots — bottom center */
.gal-dots {
  position: absolute;
  pointer-events: all;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 9px;
  background: rgba(0,0,0,0.45);
  padding: 7px 16px;
  border-radius: 24px;
  backdrop-filter: blur(4px);
}
.gal-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255,255,255,0.4);
  cursor: pointer;
  transition: all 0.2s var(--ease);
  border: none;
}
.gal-dot.active {
  background: #fff;
  transform: scale(1.3);
}

/* Leaflet overrides */
.leaflet-popup-content-wrapper {
  border-radius: 12px !important;
  box-shadow: var(--shadow-lg) !important;
  padding: 0 !important;
}
.leaflet-popup-content {
  margin: 0 !important;
  min-width: 220px;
}
.leaflet-popup-tip {
  display: none;
}
.popup-card {
  padding: 0;
}
.popup-card .popup-img {
  width: 100%;
  height: 130px;
  object-fit: cover;
  border-radius: 12px 12px 0 0;
}
.popup-card .popup-body {
  padding: 14px;
}
.popup-card .popup-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--guinda-dark);
  margin-bottom: 6px;
}
.popup-card .popup-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.popup-card .popup-badge {
  padding: 3px 8px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.popup-card .popup-badge--cip {
  background: var(--guinda);
  color: #fff;
}
.popup-card .popup-badge--marina {
  background: var(--green);
  color: #fff;
}
.popup-card .popup-badge--pti {
  background: var(--pti);
  color: #fff;
}
.popup-card .popup-year {
  font-size: 12px;
  color: var(--gray);
}
.popup-card .popup-desc {
  font-size: 12px;
  color: var(--text);
  line-height: 1.5;
}

/* Marker animations */
.marker-highlight .marker-pin {
  animation: markerPulse 1s infinite;
}
@keyframes markerPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(157, 36, 73, 0.5);
  }
  70% {
    box-shadow: 0 0 0 14px rgba(157, 36, 73, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(157, 36, 73, 0);
  }
}
.custom-marker {
  background: transparent !important;
  border: none !important;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--gray);
}
.empty-state .icon {
  font-size: 48px;
  margin-bottom: 12px;
}

/* Map container — flex:1 llena el resto de la pantalla bajo el panel */
.map-wrapper {
  flex: 1;
  min-height: 0;  /* crítico en flex-column para que Leaflet obtenga alto real */
  position: relative;
  z-index: 1; /* Contexto de apilamiento propio, por debajo del sidebar */
  width: 100%;
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  /* Forzar captura de eventos de ratón en toda el área del mapa */
  pointer-events: auto;
}

.leaflet-container {
  width: 100% !important;
  height: 100% !important;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  /* NO touch-action aquí — Leaflet lo gestiona internamente en sus propios elementos */
}

.leaflet-container:active,
.leaflet-dragging .leaflet-container,
.leaflet-dragging .leaflet-grab,
.leaflet-container.leaflet-drag-target {
  cursor: grabbing !important;
}

/* Solo desactivar user-drag nativo del navegador en tiles para evitar arrastre de imagen */
.leaflet-tile,
.leaflet-tile-pane img {
  -webkit-user-drag: none;
  user-drag: none;
  -webkit-user-select: none;
  user-select: none;
  /* NO pointer-events:none — necesario para que Leaflet gestione los eventos de las capas */
}

/* --- Responsive: Mobile --- */
@media (max-width: 768px) {
  :root {
    --topbar-h: auto; /* en móvil el topbar se adapta al contenido */
  }
  #sidebar {
    flex-direction: column;
    height: auto;
    max-height: 65vh;
    overflow-y: auto;
  }
  /* Secciones verticales en móvil */
  .header { min-width: unset; border-right: none; border-bottom: 3px solid var(--gold); }
  .fona-specials-bar { border-right: none; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
  .legend-live { border-bottom: 1px solid var(--border); }
  .timeline-control { border-right: none; border-bottom: 1px solid var(--border); }
  .filter-chips { border-right: none; border-bottom: 1px solid var(--border); }
  .search-container { border-right: none; border-bottom: 1px solid var(--border); }

  .map-controls {
    top: 16px;
    right: 12px;
  }
  .map-legend {
    bottom: 20px;
    right: 10px;
    max-width: 170px;
  }
  .modal {
    max-width: 95%;
    max-height: 90vh;
  }
}

/* --- Pantalla Grande Vertical Totem / Kiosk (Samsung Flip 55" Vertical) --- */
@media (orientation: portrait) and (min-width: 769px) {
  :root {
    --topbar-h: auto;
  }

  body {
    font-size: 18px;
    user-select: none;
    -webkit-user-select: none;
  }

  /* === Touch Feedback & Optimization === */
  button,
  .filter-chip,
  .special-feature-btn,
  .site-card,
  .dtc-nav,
  .modal-nav,
  .modal-close,
  .ctrl-btn {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  button:active,
  .filter-chip:active,
  .special-feature-btn:active,
  .ctrl-btn:active {
    transform: scale(0.96) !important;
    opacity: 0.92;
  }

  /* === Topbar horizontal === */

  /* Header */
  .header {
    padding: 20px 28px;
    min-width: 280px;
  }
  .header h1,
  .header-title {
    font-size: 26px;
    letter-spacing: 3px;
    text-align: left;
  }
  .header p {
    font-size: 14px;
  }
  .header-stats {
    font-size: 14px;
    margin-top: 8px;
    gap: 16px;
  }

  /* Especiales: Fonatur en la historia & Nuevo Fonatur */
  .fona-specials-bar {
    padding: 12px 18px;
    gap: 12px;
  }
  .special-feature-btn {
    padding: 8px 14px 8px 8px;
    min-height: 56px;
    border-radius: 12px;
  }
  .special-feature-img {
    width: 48px;
    height: 48px;
    border-radius: 8px;
  }
  .special-feature-text small {
    font-size: 10px;
  }
  .special-feature-text strong {
    font-size: 13.5px;
  }
  .special-feature-zoom {
    font-size: 16px;
  }

  /* Timeline */
  .timeline-control {
    padding: 14px 22px;
    gap: 8px;
  }
  .timeline-label {
    font-size: 12px;
  }
  .timeline-label::after {
    font-size: 18px;
  }
  .timeline-slider {
    height: 10px;
  }
  .timeline-slider::-webkit-slider-thumb {
    width: 36px;
    height: 36px;
  }
  .timeline-slider::-moz-range-thumb {
    width: 36px;
    height: 36px;
  }
  .timeline-years {
    font-size: 12px;
  }

  /* Filter chips táctiles */
  .filter-chips {
    padding: 14px 20px;
    gap: 8px;
  }
  .filter-chips-row {
    gap: 8px;
  }
  .filter-chip {
    padding: 10px 20px;
    font-size: 15px;
    font-weight: 700;
    border-radius: 24px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Search */
  .search-input {
    padding: 14px 40px 14px 16px;
    font-size: 16px;
    border-radius: 12px;
  }
  .search-icon {
    font-size: 18px;
    right: 16px;
  }

  /* Legend */
  .legend-live {
    padding: 14px 22px;
  }
  .legend-item {
    font-size: 15px;
  }
  .legend-dot {
    width: 16px;
    height: 16px;
  }
  .legend-count {
    font-size: 18px;
  }

  /* Map controls táctiles */
  .map-controls {
    top: 24px;
    right: 24px;
    gap: 12px;
  }
  .ctrl-btn {
    padding: 16px 24px;
    font-size: 17px;
    border-radius: 14px;
    min-height: 54px;
  }

  /* Leaflet Zoom control enlargement for 55" touch */
  .leaflet-control-zoom {
    border-radius: 14px !important;
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2) !important;
    border: 2px solid var(--border) !important;
  }
  .leaflet-control-zoom-in,
  .leaflet-control-zoom-out {
    width: 48px !important;
    height: 48px !important;
    line-height: 48px !important;
    font-size: 24px !important;
    font-weight: bold !important;
  }

  /* Leaflet Tooltips & Labels */
  .dtc-label {
    font-size: 13px !important;
    padding: 5px 12px !important;
    border-radius: 8px !important;
  }

  /* Popups del mapa */
  .leaflet-popup-content-wrapper {
    border-radius: 16px !important;
  }
  .fonatur-station-popup .leaflet-popup-content {
    min-width: 340px !important;
  }
  .spc-cover {
    height: 140px;
  }
  .spc-title {
    font-size: 22px !important;
  }
  .spc-subtitle {
    font-size: 13px;
  }
  .spc-info-item {
    font-size: 15px;
  }
  .spc-body p {
    font-size: 14px !important;
  }
  .view-more-btn {
    padding: 14px 22px;
    font-size: 16px;
    border-radius: 10px;
  }

  /* DTC Popups */
  .dtc-carousel {
    height: 200px;
  }
  .dtc-nav {
    width: 38px;
    height: 38px;
    font-size: 26px;
  }
  .dtc-dot {
    width: 10px;
    height: 10px;
  }
  .dtc-badge {
    font-size: 12px !important;
    padding: 5px 12px !important;
  }

  /* Modal */
  .modal {
    max-width: 860px;
    border-radius: 24px;
    padding: 28px;
  }
  .modal-head h2 {
    font-size: 28px;
  }
  .modal-close {
    width: 48px;
    height: 48px;
    font-size: 30px;
    line-height: 48px;
  }
  .modal-carousel {
    height: 440px;
  }
  .modal-nav {
    width: 48px;
    height: 48px;
    font-size: 28px;
  }
  .modal-section h3 {
    font-size: 22px;
  }
  .modal-item {
    padding: 20px;
  }
  .modal-label {
    font-size: 13px;
  }
  .modal-value {
    font-size: 20px;
  }
}

/* --- TREN MAYA STATION POPUP --- */
.fonatur-station-popup .leaflet-popup-content-wrapper {
  padding: 0;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.fonatur-station-popup .leaflet-popup-content {
  margin: 0;
  width: 100% !important; 
}
.fonatur-station-popup .leaflet-popup-tip-container {
  margin-top: -1px;
}
.station-popup-card {
  display: flex;
  flex-direction: column;
  background: #fff;
}
.spc-cover {
  height: 110px;
  background-size: cover;
  background-position: center;
  position: relative;
  border-bottom: 3px solid var(--gold);
}
.spc-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(35, 92, 78, 0.2), rgba(35, 92, 78, 0.8));
  display: flex;
  align-items: flex-end;
  padding: 12px;
}
.spc-badge {
  background: var(--gold);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  box-shadow: var(--shadow-sm);
}
.spc-body {
  padding: 16px;
  background: var(--bg);
}
.spc-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--guinda);
  margin-bottom: 2px;
  line-height: 1.2;
}
.spc-subtitle {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 1px;
  margin-bottom: 12px;
}
.spc-info-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #fff;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.spc-info-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  color: var(--text);
  line-height: 1.4;
}
.spc-icon {
  font-size: 14px;
  flex-shrink: 0;
  margin-top: 2px;
}
.spc-text strong {
  color: var(--guinda-dark);
}

/* Gallery image-only popup */
.gallery-station-popup .leaflet-popup-content-wrapper {
  padding: 0 !important;
  border-radius: 12px !important;
  overflow: hidden;
}
.gallery-station-popup .leaflet-popup-content {
  margin: 0 !important;
  width: 100% !important;
}
.gallery-popup {
  position: relative;
  line-height: 0;
}
.gallery-popup-img {
  width: 100%;
  height: auto;
  display: block;
}
.gallery-popup-btn {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
  z-index: 10;
}

/* --- DTC POINT LABELS (Tooltips permanentes) --- */
.dtc-label {
  background: rgba(255, 255, 255, 0.92) !important;
  border: none !important;
  box-shadow: 0 2px 6px rgba(0,0,0,0.18) !important;
  border-radius: 6px !important;
  padding: 3px 8px !important;
  font-size: 10px !important;
  font-weight: 600 !important;
  font-family: "Lato", system-ui, sans-serif !important;
  white-space: nowrap !important;
  pointer-events: none !important;
  line-height: 1.3 !important;
}
.dtc-label::before {
  display: none !important;
}
.dtc-label--pm { color: #c0583e !important; }
.dtc-label--mm { color: #4a8a6e !important; }
.dtc-label--mk { color: #b08a30 !important; }
.dtc-label--tm { color: #235C4E !important; }
.dtc-label--mich { color: #7c3aed !important; }

/* --- DTC POPUP CARD --- */
.dtc-popup-card {
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
}

/* Carrusel */
.dtc-carousel {
  position: relative;
  overflow: hidden;
  height: 155px;
  background: #1a1a1a;
}
.dtc-slides {
  height: 100%;
  position: relative;
}
.dtc-slide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
.dtc-slide.active {
  opacity: 1;
}

/* Botones prev/next */
.dtc-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0,0,0,0.45);
  color: #fff;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  transition: background 0.2s;
  padding: 0;
}
.dtc-nav:hover { background: rgba(0,0,0,0.7); }
.dtc-nav-prev { left: 8px; }
.dtc-nav-next { right: 8px; }

/* Dots */
.dtc-dots {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 5px;
  z-index: 10;
}
.dtc-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255,255,255,0.45);
  cursor: pointer;
  transition: background 0.2s;
}
.dtc-dot.active { background: #fff; }

/* Badge flotante sobre el carrusel */
.dtc-badge {
  position: absolute;
  bottom: 28px;
  left: 12px;
  z-index: 10;
  font-size: 10px !important;
}

/* Popup wrapper override para DTC */
.dtc-station-popup .leaflet-popup-content-wrapper {
  padding: 0 !important;
  border-radius: 12px !important;
  overflow: hidden;
}
.dtc-station-popup .leaflet-popup-content {
  margin: 0 !important;
  width: 100% !important;
}
