/* ==========================================================================
   Igapó Things - Stations Map Stylesheet
   ========================================================================== */

/* Layout & Containers */
.map-page-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 0 0 1.5rem 0;
  min-height: calc(100vh - 140px);
}

/* Interactive Count Badge Button */
.count-badge-btn {
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all var(--transition-fast);
}

.count-badge-btn:hover {
  color: var(--primary-color);
  background: var(--bg-card);
  border-color: var(--border-hover);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.12);
}

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

/* Auto Refresh & Controls Select */
.control-label-group {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.select-pill {
  appearance: none;
  -webkit-appearance: none;
  background-color: var(--bg-input);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
  background-size: 14px 14px;
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.4rem 2.1rem 0.4rem 0.75rem;
  font-size: 0.82rem;
  font-family: var(--font-sans);
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition-fast), background-color var(--transition-fast);
}

.select-pill:focus, .select-pill:hover {
  border-color: var(--border-hover);
}

/* Map Content Viewport & Split Layout */
.map-stage-container {
  position: relative;
  width: 100%;
  height: calc(100vh - 230px);
  min-height: 550px;
  display: flex;
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.map-viewport-wrapper {
  position: relative;
  flex: 1;
  height: 100%;
  width: 100%;
  z-index: 1;
}

#stationsMap {
  width: 100%;
  height: 100%;
  background: #e5e9ec;
}

/* Leaflet Tile Pane Filter */
#stationsMap .leaflet-tile-pane {
  filter: saturate(1.1) brightness(0.98);
}

/* Leaflet Zoom & Controls Customization */
.leaflet-top.leaflet-right {
  top: 1rem;
  right: 1rem;
}

.leaflet-bar,
.leaflet-touch .leaflet-bar {
  background-color: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  background-clip: padding-box;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.leaflet-bar a,
.leaflet-touch .leaflet-bar a {
  background-color: transparent;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-subtle);
  border-radius: 0;
  transition: background-color var(--transition-fast), color var(--transition-fast);
  width: 32px;
  height: 32px;
  line-height: 32px;
}

.leaflet-bar a:first-child,
.leaflet-touch .leaflet-bar a:first-child {
  border-top-left-radius: calc(var(--radius-md) - 1px);
  border-top-right-radius: calc(var(--radius-md) - 1px);
}

.leaflet-bar a:last-child,
.leaflet-touch .leaflet-bar a:last-child {
  border-bottom: none;
  border-bottom-left-radius: calc(var(--radius-md) - 1px);
  border-bottom-right-radius: calc(var(--radius-md) - 1px);
}

.leaflet-bar a:focus,
.leaflet-touch .leaflet-bar a:focus {
  background-color: transparent;
  color: var(--text-primary);
}

.leaflet-bar a:hover,
.leaflet-bar a:focus-visible,
.leaflet-touch .leaflet-bar a:hover,
.leaflet-touch .leaflet-bar a:focus-visible {
  background-color: rgba(99, 102, 241, 0.1);
  color: var(--primary-color);
}

.leaflet-bar a.leaflet-disabled,
.leaflet-bar a.leaflet-disabled:hover,
.leaflet-touch .leaflet-bar a.leaflet-disabled,
.leaflet-touch .leaflet-bar a.leaflet-disabled:hover {
  background-color: transparent;
  color: var(--text-muted);
  opacity: 0.55;
  cursor: default;
}

/* Stations Floating Sidebar Panel */
.stations-sidebar {
  position: absolute;
  top: 1rem;
  left: 1rem;
  bottom: 1rem;
  width: 340px;
  max-width: calc(100% - 2rem);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transition: transform var(--transition-normal);
  overflow: hidden;
}

.stations-sidebar.collapsed {
  transform: translateX(calc(-100% + 46px));
}

.stations-sidebar-header {
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.5);
}

.stations-sidebar-title {
  font-family: var(--font-display);
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.stations-sidebar-toggle {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.stations-sidebar-toggle:hover {
  background: var(--bg-input);
  color: var(--text-primary);
}

.stations-sidebar-toggle svg {
  transition: transform var(--transition-normal);
}

.stations-sidebar.collapsed .stations-sidebar-toggle svg {
  transform: rotate(180deg);
}

.stations-list-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

/* Station Card Item in Sidebar */
.station-item-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.75rem 0.85rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  position: relative;
  min-width: 0;
  overflow: hidden;
}

.station-item-card:hover {
  border-color: var(--border-hover);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.1);
  transform: translateY(-1px);
}

.station-item-card.active-selected {
  border-color: var(--primary-color);
  background: rgba(99, 102, 241, 0.04);
  box-shadow: 0 0 0 2px var(--primary-color);
}

.station-item-top {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

.station-item-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
  margin: 0;
}

.station-item-coords-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  min-width: 0;
}

.station-item-coords {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.station-item-coords.no-gps {
  color: var(--accent-amber);
}

.sidebar-iaq-badge {
  font-size: 0.66rem;
  line-height: 1.3;
  padding: 0.12rem 0.4rem;
  border-radius: var(--radius-sm);
  box-shadow: none;
  flex-shrink: 0;
}

.sidebar-iaq-badge .iaq-dot {
  width: 5px;
  height: 5px;
}

.station-item-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-subtle);
  padding-top: 0.4rem;
  margin-top: 0.2rem;
}

.station-item-time,
.popup-time {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.station-item-time svg,
.popup-time svg {
  opacity: 0.7;
  flex-shrink: 0;
}

/* Custom Leaflet Marker */
.map-radar-marker {
  position: relative;
  width: 28px;
  height: 28px;
  margin-left: -14px;
  margin-top: -14px;
}

.map-radar-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  transform: translate(-50%, -50%);
  background: var(--primary-color, #6366f1);
  border: 2.5px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s ease;
}

.map-radar-dot.has-data {
  background: #10b981;
}

.map-radar-marker:hover .map-radar-dot {
  transform: translate(-50%, -50%) scale(1.3);
}

/* Custom Leaflet Popup */
.leaflet-popup-content-wrapper {
  background: rgba(255, 255, 255, 0.96) !important;
  backdrop-filter: blur(20px) !important;
  -webkit-backdrop-filter: blur(20px) !important;
  border: 1px solid var(--border-subtle) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.04) !important;
  padding: 0 !important;
  overflow: hidden;
}

.leaflet-popup-content {
  margin: 0 !important;
  padding: 1.05rem 1.25rem !important;
  font-family: var(--font-sans) !important;
  color: var(--text-primary) !important;
  line-height: 1.4 !important;
  min-width: 280px;
  max-width: 380px;
  width: 360px;
}

.leaflet-popup-tip {
  background: rgba(255, 255, 255, 0.96) !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1) !important;
}

/* Custom Popup Close Button */
.leaflet-container a.leaflet-popup-close-button,
.leaflet-popup-close-button {
  position: absolute !important;
  top: 0.75rem !important;
  right: 0.75rem !important;
  width: 24px !important;
  height: 24px !important;
  padding: 0 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  font-family: inherit !important;
  font-size: 1.15rem !important;
  font-weight: 400 !important;
  line-height: 1 !important;
  color: var(--text-muted) !important;
  background: rgba(0, 0, 0, 0.04) !important;
  border: 1px solid var(--border-subtle) !important;
  border-radius: 50% !important;
  text-decoration: none !important;
  cursor: pointer !important;
  z-index: 20 !important;
  box-sizing: border-box !important;
  transition: all var(--transition-fast) !important;
}

.leaflet-container a.leaflet-popup-close-button span,
.leaflet-popup-close-button span {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  top: -1px;
}

.leaflet-container a.leaflet-popup-close-button:hover,
.leaflet-popup-close-button:hover {
  color: var(--text-primary) !important;
  background: rgba(0, 0, 0, 0.08) !important;
  border-color: rgba(0, 0, 0, 0.15) !important;
  transform: scale(1.08) !important;
}

.leaflet-container a.leaflet-popup-close-button:active,
.leaflet-popup-close-button:active {
  transform: scale(0.94) !important;
}

.popup-channel-header {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.65rem;
  margin-bottom: 0.65rem;
  padding-right: 1.75rem;
}

.popup-badges-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.popup-iaq-badge {
  font-size: 0.68rem;
  line-height: 1.4;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-sm);
  box-shadow: none;
}

.popup-iaq-badge .iaq-dot {
  width: 6px;
  height: 6px;
}

.popup-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.popup-title a {
  color: inherit;
  text-decoration: none;
}

.popup-title a:hover {
  color: var(--primary-color);
}

.popup-coords-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
}

.popup-readings-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.4rem;
  margin: 0.65rem 0;
  max-height: 160px;
  overflow-y: auto;
}

.popup-reading-card {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.5rem;
  display: flex;
  flex-direction: column;
}

.popup-reading-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.popup-reading-val {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-primary);
}

.popup-loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem 0.5rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.spinner-tiny {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(99, 102, 241, 0.2);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: mapSpin 0.8s linear infinite;
}

@keyframes mapSpin {
  to { transform: rotate(360deg); }
}

.popup-footer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border-subtle);
  padding-top: 0.65rem;
  margin-top: 0.65rem;
  gap: 0.5rem;
}

/* Ensure high contrast and standardized sizing for popup action button */
.popup-footer-row .btn-primary,
.leaflet-container .leaflet-popup-content a.btn-primary,
.leaflet-popup-content a.btn-primary {
  height: 36px !important;
  min-height: 36px !important;
  max-height: 36px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 0.45rem !important;
  padding: 0 0.75rem !important;
  font-size: 0.8rem !important;
  font-weight: 600 !important;
  border-radius: var(--radius-sm) !important;
  box-sizing: border-box !important;
  line-height: 1 !important;
  color: #ffffff !important;
  background-color: var(--primary-color) !important;
  text-decoration: none !important;
  box-shadow: 0 3px 10px rgba(99, 102, 241, 0.35) !important;
}

.popup-footer-row .btn-primary svg,
.leaflet-container .leaflet-popup-content a.btn-primary svg,
.leaflet-popup-content a.btn-primary svg {
  stroke: #ffffff !important;
  flex-shrink: 0;
}

.popup-footer-row .btn-primary span,
.leaflet-container .leaflet-popup-content a.btn-primary span {
  color: #ffffff !important;
}

.popup-footer-row .btn-primary:hover,
.leaflet-container .leaflet-popup-content a.btn-primary:hover,
.leaflet-popup-content a.btn-primary:hover {
  color: #ffffff !important;
  background-color: var(--primary-hover) !important;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.5) !important;
  transform: translateY(-1px);
}

.popup-updated-time {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Empty State Overlay */
.map-empty-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 500;
  background: var(--bg-card);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: 2rem;
  text-align: center;
  max-width: 400px;
  box-shadow: var(--shadow-modal);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

/* Nav Active Link Indicator */
.nav-link-active {
  background: var(--bg-secondary) !important;
  color: var(--primary-color) !important;
  font-weight: 600 !important;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08) !important;
}

/* Responsive adjustments */
@media (max-width: 900px) {
  .map-stage-container {
    height: 70vh;
    min-height: 480px;
  }

  .stations-sidebar {
    width: 290px;
  }
}

@media (max-width: 640px) {
  .leaflet-popup-content {
    min-width: 250px;
    max-width: calc(100vw - 40px);
    width: auto;
  }

  .stations-sidebar {
    top: auto;
    left: 0.5rem;
    right: 0.5rem;
    bottom: 0.5rem;
    width: auto;
    max-width: none;
    max-height: 40vh;
  }

  .stations-sidebar.collapsed {
    transform: translateY(calc(100% - 44px));
  }

  .stations-sidebar-toggle svg {
    transform: rotate(270deg);
  }

  .stations-sidebar.collapsed .stations-sidebar-toggle svg {
    transform: rotate(90deg);
  }
}

