:root {
  --header-h: 64px;
  --sidebar-w: 390px;
  --green: #10b981;
  --green-dark: #059669;
  --green-deep: #047857;
  --ink: #0d2b22;
  --ink-deep: #061c15;
  --text: #33514a;
  --muted: #7b9088;
  --bg: #eef4f0;
  --card: #ffffff;
  --border: #dde8e2;
  --radius: 16px;
  --shadow: 0 8px 24px rgba(6, 28, 21, 0.10);
  --shadow-lg: 0 18px 48px rgba(6, 28, 21, 0.18);
  --red: #ef4444;
  --orange: #f59e0b;
  --blue: #3b82f6;
  --purple: #9333ea;
  --font: 'Inter', 'Segoe UI', system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body { overflow: hidden; }

/* ---------- Header ---------- */
.app-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 18px;
  background: linear-gradient(115deg, #061c15 0%, #0b3b2a 55%, #0f5a3c 100%);
  color: #fff;
  box-shadow: 0 4px 20px rgba(6, 28, 21, 0.35);
  position: relative;
  z-index: 1001;
}

.app-header::after {
  content: '';
  position: absolute;
  inset: 0 0 -1px 0;
  background: linear-gradient(90deg, rgba(52, 211, 153, 0.0), rgba(52, 211, 153, 0.55), rgba(52, 211, 153, 0.0));
  height: 2px;
  bottom: 0;
  top: auto;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-logo {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  padding: 7px;
  background: linear-gradient(135deg, #34d399, #059669);
  border-radius: 13px;
  box-shadow: 0 6px 14px rgba(5, 150, 105, 0.45);
  filter: drop-shadow(0 0 6px rgba(52, 211, 153, 0.35));
}

.brand-text h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.3px;
  white-space: nowrap;
  background: linear-gradient(90deg, #ffffff, #a7f3d0);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-text p {
  margin: 2px 0 0;
  font-size: 11.5px;
  font-weight: 500;
  opacity: 0.82;
  letter-spacing: 0.4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

.ocm-indicator {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.6px;
  background: rgba(52, 211, 153, 0.18);
  border: 1px solid rgba(52, 211, 153, 0.5);
  color: #a7f3d0;
  padding: 5px 10px;
  border-radius: 999px;
}

.ocm-indicator.hidden { display: none; }

.btn {
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 15px;
  border-radius: 999px;
  transition: transform 0.08s ease, background 0.15s ease, box-shadow 0.15s ease, color 0.15s ease;
}

.btn:active { transform: scale(0.96); }

.btn-primary {
  background: linear-gradient(135deg, #34d399, #10b981);
  color: #052e1f;
  box-shadow: 0 6px 16px rgba(16, 185, 129, 0.4);
}
.btn-primary:hover { box-shadow: 0 8px 20px rgba(16, 185, 129, 0.55); filter: brightness(1.04); }

.btn-ghost {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(6px);
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.22); }

.btn-link {
  border: none;
  background: none;
  color: var(--green-dark);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: color 0.15s ease;
}
.btn-link:hover { color: var(--green-deep); text-decoration: underline; }

/* ---------- Layout ---------- */
.layout {
  display: flex;
  height: calc(100vh - var(--header-h));
}

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.map-wrap { position: relative; flex: 1 1 auto; min-width: 0; }

#map { width: 100%; height: 100%; background: #e2ece6; z-index: 0; }

/* ---------- Sidebar: búsqueda y estadísticas ---------- */
.search-wrap {
  position: relative;
  margin: 14px 16px 10px;
  z-index: 1100;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 14px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  color: var(--muted);
  box-shadow: 0 3px 10px rgba(6, 28, 21, 0.06);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-box:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.14);
}

.search-box input {
  border: none;
  outline: none;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  flex: 1 1 auto;
  min-width: 0;
  background: transparent;
}

.search-locate {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #34d399, #059669);
  padding: 7px 12px;
  border-radius: 999px;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(5, 150, 105, 0.4), 0 0 0 3px rgba(16, 185, 129, 0.15);
  transition: transform 0.12s ease, box-shadow 0.15s ease, filter 0.15s ease;
  animation: locatePulse 2.4s ease-in-out infinite;
}

.search-locate:hover {
  filter: brightness(1.07);
  box-shadow: 0 6px 16px rgba(5, 150, 105, 0.5), 0 0 0 4px rgba(16, 185, 129, 0.2);
  transform: translateY(-1px);
}

.search-locate:active { transform: scale(0.95); }
.search-locate svg { flex: 0 0 auto; }

@keyframes locatePulse {
  0%, 100% { box-shadow: 0 4px 12px rgba(5, 150, 105, 0.4), 0 0 0 3px rgba(16, 185, 129, 0.15); }
  50% { box-shadow: 0 4px 14px rgba(5, 150, 105, 0.6), 0 0 0 6px rgba(16, 185, 129, 0.24); }
}

/* ---------- Sugerencias de búsqueda ---------- */
.search-suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 1100;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  max-height: 340px;
  overflow-y: auto;
  scrollbar-width: thin;
}

.search-suggestions.hidden { display: none; }

.suggest-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  font: inherit;
  padding: 9px 12px;
  cursor: pointer;
  color: var(--ink);
  border-bottom: 1px solid #eef3f0;
}

.suggest-item:last-child { border-bottom: none; }

.suggest-item:hover,
.suggest-item.active { background: #f0faf5; }

.suggest-icon {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--green-dark);
}

.suggest-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.suggest-main {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.suggest-sub {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.suggest-brand {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
}

mark.hl {
  background: rgba(16, 185, 129, 0.18);
  color: var(--green-deep);
  border-radius: 3px;
  padding: 0 1px;
}

.suggest-empty {
  padding: 16px 14px;
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

.quick-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 0 16px 12px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 9px 6px;
  text-align: center;
  box-shadow: 0 2px 6px rgba(6, 28, 21, 0.04);
}

.stat-num {
  display: block;
  font-size: 19px;
  font-weight: 800;
  color: var(--ink);
  line-height: 1.1;
}

.stat-label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-top: 3px;
}

.stat-card.rapida .stat-num { color: var(--red); }
.stat-card.semi .stat-num { color: var(--orange); }
.stat-card.lenta .stat-num { color: var(--blue); }

/* ---------- Filtros ---------- */
.filter-group { padding: 5px 16px; }

.group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.group-header h3 {
  margin: 8px 0 7px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}

.group-chev {
  background: none;
  border: 0;
  padding: 0;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  cursor: pointer;
  transition: transform 0.2s ease, color 0.14s ease, background 0.14s ease;
}

.group-chev:hover { color: var(--green-deep); background: rgba(5, 150, 105, 0.08); }

.filter-group.collapsed .group-chev,
.legend.collapsed .group-chev { transform: rotate(-90deg); }
.filter-group.collapsed .chips { display: none; }
.legend.collapsed .legend-body { display: none; }
.legend.collapsed .legend-head { margin-bottom: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.14s ease;
  box-shadow: 0 1px 3px rgba(6, 28, 21, 0.04);
}

.chip:hover { border-color: var(--green); color: var(--green-deep); transform: translateY(-1px); }

.chip.active {
  background: linear-gradient(135deg, #10b981, #059669);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 10px rgba(5, 150, 105, 0.35);
}

.chip .count { opacity: 0.7; font-weight: 500; margin-left: 4px; }
.chip.active .count { opacity: 0.85; }

.segmented { display: flex; flex-wrap: wrap; gap: 6px; }

.segmented button {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.14s ease;
}

.segmented button:hover { border-color: var(--green); transform: translateY(-1px); }

.segmented button.active {
  background: linear-gradient(135deg, #34d399, #10b981);
  border-color: transparent;
  color: #052e1f;
  box-shadow: 0 4px 10px rgba(16, 185, 129, 0.35);
}

/* ---------- Resultados ---------- */
.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 8px;
  border-top: 1px solid var(--border);
}

.results-header span { font-size: 12.5px; font-weight: 700; color: var(--ink); }

.station-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 4px 14px 14px;
  scrollbar-width: thin;
  scrollbar-color: #c3d6cc transparent;
}

.station-list::-webkit-scrollbar { width: 8px; }
.station-list::-webkit-scrollbar-thumb { background: #c3d6cc; border-radius: 8px; }
.station-list::-webkit-scrollbar-track { background: transparent; }

.station-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 9px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(6, 28, 21, 0.05);
  transition: transform 0.14s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.station-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: rgba(16, 185, 129, 0.45);
}

.station-card .name {
  font-weight: 700;
  font-size: 14px;
  color: var(--ink);
  margin: 0 0 4px;
  line-height: 1.3;
}

.station-card .meta {
  font-size: 12px;
  color: var(--muted);
  margin: 2px 0;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.badge {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.4px;
  padding: 3px 9px;
  border-radius: 999px;
  color: #fff;
  text-transform: uppercase;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.12);
}

.badge.brand { background: #0f3d30; }
.badge.rapida { background: var(--red); }
.badge.semi { background: var(--orange); }
.badge.lenta { background: var(--blue); }
.badge.public { background: var(--green-deep); }
.badge.private { background: var(--purple); }

.station-card .connectors {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 9px;
}

.conn-tag {
  font-size: 11px;
  font-weight: 600;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 3px 8px;
  border-radius: 8px;
}

.conn-tag b { color: var(--ink); }

.empty-state {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 30px 12px;
  line-height: 1.5;
}

/* ---------- Sidebar footer ---------- */
.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  font-size: 12px;
  color: var(--muted);
  background: var(--card);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.sidebar-footer b { color: var(--ink); }

/* ---------- Status banner ---------- */
.status-banner {
  position: absolute;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: rgba(6, 28, 21, 0.92);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  z-index: 900;
  max-width: 90%;
  display: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.status-banner.show { display: block; animation: bannerIn 0.2s ease; }

@keyframes bannerIn {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.status-banner.error { background: rgba(185, 38, 30, 0.95); }
.status-banner.success { background: rgba(5, 150, 105, 0.95); }

/* ---------- Leyenda ---------- */
.legend {
  position: absolute;
  right: 12px;
  top: 12px;
  z-index: 900;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  font-size: 11.5px;
  max-height: calc(100% - 90px);
  overflow-y: auto;
  min-width: 150px;
  scrollbar-width: thin;
}

.legend h4 {
  margin: 0 0 8px;
  font-size: 10.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
}

.legend-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.legend-head h4 { margin: 0; }

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  color: var(--text);
  white-space: nowrap;
  font-weight: 500;
}

.legend-swatch {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.18);
  flex: 0 0 auto;
}

/* ---------- Marcadores personalizados ---------- */
.ev-marker { background: transparent; border: none; }

.ev-dot {
  display: block;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2.5px solid #fff;
  box-shadow: 0 0 0 1.5px rgba(0, 0, 0, 0.14), 0 3px 8px rgba(0, 0, 0, 0.3);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.ev-marker:hover .ev-dot {
  transform: scale(1.3);
  box-shadow: 0 0 0 1.5px rgba(0, 0, 0, 0.14), 0 4px 12px rgba(0, 0, 0, 0.35), 0 0 12px rgba(255, 255, 255, 0.4);
}

/* ---------- Clusters ---------- */
.marker-cluster { background: transparent; }

.marker-cluster div {
  width: 34px !important;
  height: 34px !important;
  margin-left: 0 !important;
  margin-top: 0 !important;
  line-height: 34px !important;
  font-weight: 800;
  font-size: 13px;
  font-family: var(--font);
  color: #fff;
  background: linear-gradient(135deg, #34d399, #059669);
  border: 2.5px solid #fff;
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(5, 150, 105, 0.45), 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.marker-cluster-small div { background: linear-gradient(135deg, #6ee7b7, #10b981); }
.marker-cluster-medium div { background: linear-gradient(135deg, #34d399, #059669); }
.marker-cluster-large div { background: linear-gradient(135deg, #059669, #065f46); }

.marker-cluster span { line-height: 34px !important; }

/* ---------- Popup ---------- */
.leaflet-popup-content-wrapper {
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

.leaflet-popup-tip {
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

.leaflet-popup-content {
  font-family: var(--font);
  min-width: 230px;
  max-width: 300px;
  margin: 16px 18px;
}

.you-here {
  position: relative;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #2563eb;
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.6), 0 2px 6px rgba(0, 0, 0, 0.3);
}

.you-here::after {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 2px solid rgba(37, 99, 235, 0.55);
  animation: you-ping 1.6s ease-out infinite;
}

@keyframes you-ping {
  0% { transform: scale(0.6); opacity: 1; }
  100% { transform: scale(2.6); opacity: 0; }
}

.popup h3 {
  margin: 0 0 2px;
  font-size: 15px;
  font-weight: 800;
  color: var(--ink);
  line-height: 1.3;
}

.popup .popup-op { font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }

.popup .popup-row {
  font-size: 12.5px;
  color: var(--text);
  margin: 4px 0;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.popup .popup-row.muted { color: var(--muted); font-size: 11px; }

.popup-badges { display: flex; gap: 6px; margin: 7px 0; flex-wrap: wrap; }

/* Popup compacto (estilo PlugShare) */
.popup-compact { max-width: 240px; }

.popup-compact-head {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 4px;
}

.popup-compact-head h3 { margin: 0; font-size: 14px; line-height: 1.25; flex: 1 1 auto; min-width: 0; }

.popup-count {
  font-size: 13px;
  color: var(--text);
  margin: 2px 0 6px;
}

.popup-count b { font-weight: 800; color: var(--ink); }

.popup-detail-link {
  display: block;
  text-align: center;
  font-size: 13px !important;
  font-weight: 800 !important;
  color: var(--green-dark) !important;
  background: #eef8f3;
  border-radius: 8px;
  padding: 7px 10px;
  margin-bottom: 6px;
  border: none !important;
  transition: background 0.15s ease;
}

.popup-detail-link:hover { background: #d6f0e2; }

/* Favoritos */
.popup-fav {
  flex: 0 0 auto;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 2px;
  line-height: 1;
  transition: color 0.15s ease, transform 0.15s ease;
}
.popup-fav:hover { color: #ef4444; transform: scale(1.15); }

.card-fav {
  position: absolute;
  top: 6px;
  right: 6px;
  background: none;
  border: none;
  color: #c3d6cc;
  cursor: pointer;
  padding: 2px;
  line-height: 1;
  z-index: 1;
  transition: color 0.15s ease, transform 0.15s ease;
}
.station-card.fav .card-fav { color: #ef4444; }
.card-fav:hover { color: #ef4444; transform: scale(1.2); }

.station-card { position: relative; }

.fav-toggle {
  width: 100%;
  justify-content: flex-start;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
}
.fav-toggle.active { background: #fef2f2; color: #dc2626; border-color: #fca5a5; }

.detail-fav-row { margin: 4px 0 10px; }
.detail-fav-btn svg { vertical-align: -2px; margin-right: 4px; }

.popup-sec {
  font-size: 10.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  margin: 11px 0 5px;
  padding-top: 9px;
  border-top: 1px solid var(--border);
}

.conn-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 6px 10px;
  margin: 4px 0;
}

.conn-qty {
  font-weight: 800;
  font-size: 11px;
  background: #0f3d30;
  color: #fff;
  border-radius: 7px;
  padding: 2px 7px;
  min-width: 27px;
  text-align: center;
}

.conn-kw { font-weight: 700; color: var(--ink); }
.conn-cur {
  margin-left: auto;
  font-size: 10px;
  font-weight: 800;
  color: #fff;
  border-radius: 7px;
  padding: 2px 7px;
  background: linear-gradient(135deg, #10b981, #059669);
}

.popup-links { margin-top: 12px; display: flex; gap: 10px; flex-wrap: wrap; }

.popup a {
  font-size: 12px;
  font-weight: 700;
  color: var(--green-dark);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s ease;
}

.popup a:hover { border-color: var(--green-dark); }

/* ---------- Fotos y vista de referencia ---------- */
.photo-gallery { margin-bottom: 6px; }

.photo-main-link { display: block; border: none !important; }

.photo-main {
  display: block;
  width: 100%;
  height: 190px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #e6ece8;
}

.photo-thumbs {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.photo-thumb {
  flex: 0 0 56px;
  width: 56px;
  height: 44px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: pointer;
  opacity: 0.8;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.photo-thumb:hover { opacity: 1; transform: translateY(-1px); }

.sv-embed {
  display: block;
  width: 100%;
  height: 210px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #e6ece8;
}

.photo-actions {
  display: flex;
  gap: 8px;
  margin: 6px 0 10px;
}

.photo-actions .btn {
  flex: 1 1 auto;
  padding: 8px 10px;
  font-size: 12px;
}

/* ---------- Controles del mapa ---------- */
.leaflet-bar {
  border: none !important;
  border-radius: 12px !important;
  box-shadow: var(--shadow) !important;
  overflow: hidden;
}

.leaflet-bar a {
  width: 34px !important;
  height: 34px !important;
  line-height: 34px !important;
  border-bottom: 1px solid var(--border) !important;
  color: var(--ink) !important;
  font-family: var(--font);
}

.leaflet-bar a:hover { background: #f2faf6 !important; }
.leaflet-bar a.leaflet-disabled { color: #c3d6cc !important; }

.leaflet-control-attribution {
  font-size: 10px !important;
  background: rgba(255, 255, 255, 0.75) !important;
  backdrop-filter: blur(4px);
  border-radius: 8px 0 0 0;
}

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(6, 28, 21, 0.55);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 16px;
}

.modal.hidden { display: none; }

.modal-card {
  background: #fff;
  border-radius: 20px;
  padding: 26px;
  width: 100%;
  max-width: 460px;
  position: relative;
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
  animation: modalIn 0.22s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.modal-card h2 { margin: 0 0 10px; font-size: 19px; font-weight: 800; color: var(--ink); }

.modal-card p { font-size: 13px; line-height: 1.55; color: var(--text); margin: 8px 0; }

.modal-card a { color: var(--green-dark); font-weight: 700; }

.modal .btn-ghost {
  background: #eef3f0;
  color: var(--ink);
  border: 1px solid var(--border);
}

.modal .btn-ghost:hover { background: #e0eae4; }

.modal-subtitle {
  margin: 20px 0 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}

.supa-status {
  font-size: 13px;
  line-height: 1.5;
  border-radius: 12px;
  padding: 11px 13px;
  margin: 8px 0 4px;
}

.supa-status code { background: rgba(255, 255, 255, 0.6); padding: 1px 5px; border-radius: 5px; font-size: 12px; }

.supa-status.ok { background: #e6f7ee; border: 1px solid #b8e7cf; color: #0a5c36; }
.supa-status.warn { background: #fff7e6; border: 1px solid #f3ddb0; color: #7a5200; }

.modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  border: none;
  background: #eef3f0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 17px;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
  transition: background 0.15s ease, color 0.15s ease;
}

.modal-close:hover { background: var(--ink); color: #fff; }

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  margin: 14px 0 6px;
}

#ocmKeyInput {
  width: 100%;
  padding: 11px 13px;
  font: inherit;
  font-size: 13px;
  border: 1.5px solid var(--border);
  border-radius: 11px;
  outline: none;
  color: var(--ink);
  background: var(--bg);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#ocmKeyInput:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.14);
  background: #fff;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.modal-note {
  margin-top: 16px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 11px;
  line-height: 1.5;
}

/* ---------- Especificaciones a pantalla completa (móvil) ---------- */
.station-detail {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.station-detail.hidden { display: none; }

.station-detail-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

.station-detail-title {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
}

.station-detail-title h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  color: var(--ink);
  line-height: 1.3;
}

.station-detail-swatch {
  flex: 0 0 auto;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.15);
}

.station-detail-close {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: var(--bg);
  color: var(--ink);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.station-detail-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 16px;
}

.station-detail-foot {
  display: flex;
  gap: 10px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: var(--card);
}

.station-detail-foot .btn {
  flex: 1 1 auto;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Botón centrar en mi ubicación ---------- */
.map-center-btn {
  position: absolute;
  z-index: 1000;
  bottom: 16px;
  right: 12px;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--green-dark);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.14s ease, background 0.15s ease;
}

.map-center-btn:hover { background: #eefaf4; }
.map-center-btn:active { transform: scale(0.94); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .brand-text p { display: none; }

  .layout { flex-direction: column-reverse; overflow: auto; }

  .sidebar {
    width: 100%;
    flex: none;
    height: auto;
    max-height: 55vh;
    border-right: none;
    border-top: 1px solid var(--border);
  }

  .map-wrap { height: 45vh; flex: none; }

  .station-list { max-height: 40vh; }
}

@media (max-width: 560px) {
  .header-actions .btn-ghost { display: none; }
  .app-header { padding: 0 10px; }
  .quick-stats { margin: 0 10px 10px; }
  .search-wrap { margin: 12px 10px 8px; }
  .search-locate span { display: none; }
  .search-locate { padding: 8px 10px; }
}

/* ---------- Barra de rutas ---------- */
:root { --route-h: 62px; }

.layout {
  height: calc(100vh - var(--header-h) - var(--route-h));
}

.route-bar {
  height: var(--route-h);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 8px 16px 10px;
  box-shadow: 0 2px 10px rgba(6, 28, 21, 0.06);
  position: relative;
  z-index: 1000;
}

.route-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 1 0;
  min-width: 0;
}

.route-field label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
}

.route-input-wrap { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1; }

.route-input {
  flex: 1 1 0;
  min-width: 0;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: 11px;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--bg);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.route-input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.14);
  background: #fff;
}

.route-icon-btn {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid var(--border);
  border-radius: 11px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s ease;
}

.route-icon-btn:hover {
  border-color: var(--green);
  color: var(--green-deep);
  background: #eefaf4;
}

.route-icon-btn:active { transform: scale(0.94); }

.route-icon-btn.swap { background: var(--card); }

.route-field.route-radio { flex: 0 0 auto; }

.route-radius-select {
  padding: 8px 10px;
  border: 1.5px solid var(--border);
  border-radius: 11px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  background: var(--bg);
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.route-radius-select:focus { border-color: var(--green); }

.route-go { white-space: nowrap; align-self: center; }

.route-clear {
  white-space: nowrap;
  align-self: center;
  background: #eef3f0;
  color: var(--ink);
  border: 1px solid var(--border);
}

.route-clear:hover { background: #e0eae4; }

/* ---------- Resumen de ruta ---------- */
.route-summary {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-left: 4px solid var(--green);
  border-radius: 13px;
  padding: 9px 14px;
  box-shadow: var(--shadow);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  max-width: calc(100% - 40px);
}

.route-summary.hidden { display: none; }

.route-summary svg { flex: 0 0 auto; color: var(--green-dark); }

.route-summary .btn-link { flex: 0 0 auto; }

.route-summary .btn-link.active {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  padding: 4px 10px;
  border-radius: 999px;
  text-decoration: none;
}

.route-summary .btn-link.active:hover { filter: brightness(1.05); }

/* ---------- Marcador resaltado en ruta ---------- */
.badge.en-ruta {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.25);
}

.station-card.in-route {
  border-color: rgba(16, 185, 129, 0.5);
  box-shadow: 0 0 0 1px rgba(16, 185, 129, 0.3), var(--shadow);
}

@media (max-width: 1100px) {
  .route-bar { flex-wrap: wrap; height: auto; }
  .layout { height: calc(100vh - var(--header-h)); }
  .route-field.route-radio { flex: 1 1 120px; }
}

@media (max-width: 560px) {
  .route-field { flex: 1 1 100%; }
  .route-go, .route-clear { flex: 1 1 auto; align-self: auto; }
  .route-summary { top: 8px; flex-wrap: wrap; justify-content: center; }
}

/* ---------- App móvil: bottom sheet + FAB ---------- */
.sheet-bar,
.sheet-close,
.fab { display: none; }

html, body { -webkit-tap-highlight-color: transparent; }

.station-card, .chip, .btn, .segmented button, .search-locate, .route-icon-btn {
  -webkit-user-select: none;
  user-select: none;
}

@media (max-width: 768px) {
  :root { --header-h: 52px; }

  html, body { height: 100%; }

  body {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100dvh;
  }

  .app-header { height: 52px; flex: 0 0 auto; padding: 0 12px; }
  .app-header .btn { padding: 7px 10px; font-size: 12px; }
  .brand-logo { width: 32px; height: 32px; padding: 6px; }
  .brand-text h1 { font-size: 16px; }
  .brand-text p { display: none; }
  .ocm-indicator { display: none; }

  /* Barra de ruta: dos filas, todo visible, sin scroll horizontal */
  .route-bar {
    flex-wrap: wrap;
    align-items: center;
    height: auto;
    gap: 8px;
    padding: 8px 12px 10px;
    overflow: visible;
  }
  .route-field { flex: 1 1 130px; min-width: 0; }
  .route-field.route-radio { flex: 0 0 auto; }
  .route-field label { display: none; }
  .route-input-wrap { flex: 1 1 auto; min-width: 0; }
  .route-input { width: 100%; flex: 1 1 auto; padding: 7px 9px; font-size: 12.5px; }
  .route-icon-btn { width: 36px; height: 36px; }
  .route-radius-select { padding: 8px 8px; font-size: 12.5px; }
  .route-go, .route-clear { align-self: center; padding: 8px 10px; font-size: 12.5px; }

  /* Layout: el mapa ocupa todo el área; abajo va la hoja que se despliega */
  .layout {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
  }
  .map-wrap { position: absolute; inset: 0; height: 100%; z-index: 1; }
  #map { height: 100%; width: 100%; }

  /* Hoja inferior arrastrable: el asa queda siempre visible y se despliega */
  .sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1100;
    width: 100%;
    height: var(--sheet-h, 76px);
    min-height: 76px;
    max-height: 92dvh;
    border-radius: 18px 18px 0 0;
    border-right: none;
    border-top: 1px solid var(--border);
    box-shadow: 0 -10px 34px rgba(6, 28, 21, 0.22);
    transform: none;
    transition: height 0.3s cubic-bezier(0.32, 0.72, 0.28, 1);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    touch-action: pan-y;
  }

  body.sheet-dragging .sidebar { transition: none; }

  .sheet-bar {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 8px 12px 10px;
    cursor: grab;
    touch-action: none;
    border-bottom: 1px solid var(--border);
    background: var(--card);
    border-radius: 18px 18px 0 0;
    flex: 0 0 auto;
    user-select: none;
  }
  .sheet-bar:active { cursor: grabbing; }
  .sheet-handle {
    display: block;
    width: 44px;
    height: 5px;
    border-radius: 999px;
    background: #c8d4cd;
    flex: 0 0 auto;
  }
  .sheet-info { display: flex; align-items: center; gap: 8px; width: 100%; }
  .sheet-count {
    flex: 1 1 auto;
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: 0.2px;
  }
  .sheet-toggle {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: rgba(16, 185, 129, 0.12);
    color: var(--green-dark);
    cursor: pointer;
    transition: transform 0.25s ease;
  }
  body.sheet-full .sheet-toggle { transform: rotate(180deg); }
  .sheet-close { display: none; }

  /* Contenido de la hoja */
  .sidebar .search-wrap { margin: 10px 12px 8px; }
  .search-box { padding: 9px 12px; }
  .search-locate { padding: 6px 10px; font-size: 11.5px; }
  .quick-stats { margin: 0 12px 8px; gap: 5px; }
  .stat-card { padding: 5px 4px; border-radius: 10px; }
  .stat-num { font-size: 15px; }
  .filter-group { padding: 2px 12px; }
  .filter-group h3 { margin: 4px 0 4px; font-size: 9.5px; }
  .chips { gap: 4px; }
  .chip { padding: 3px 7px; font-size: 10px; }
  .segmented button { padding: 5px 8px; font-size: 11px; }
  .results-header { padding: 6px 12px 5px; }
  .results-header span { font-size: 12px; }
  .station-card { padding: 12px 14px; }
  .search-suggestions { max-height: 240px; }
  .station-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 4px 12px 12px;
  }

  .sidebar-footer { display: none; }
  .fab { display: none; }

  /* Leyenda abajo del control de zoom; botón centrar arriba a la derecha */
  .legend {
    left: 10px;
    right: auto;
    top: 78px;
    bottom: auto;
    max-height: 36vh;
    min-width: 130px;
    padding: 10px 12px;
  }

  .map-center-btn {
    top: 10px;
    right: 10px;
    bottom: auto;
  }

  .route-summary { max-width: calc(100% - 20px); font-size: 12px; }
}

@media (max-width: 380px) {
  .route-field { flex: 1 1 118px; }
  .quick-stats { grid-template-columns: repeat(4, 1fr); gap: 4px; }
  .stat-num { font-size: 14px; }
}
