/**
 * Map CSS - Map-specific styles
 * Company Map UK
 */

/* ============================================
   Map Container
   ============================================ */
.map-container {
  width: 100%;
  height: 100%;
  position: relative;
  background: var(--gray-100);
}

/* MapLibre overrides */
.maplibregl-canvas {
  outline: none;
}

.maplibregl-ctrl-attrib {
  font-size: 10px;
  background-color: rgba(255, 255, 255, 0.8);
}

/* ============================================
   Postcode Search Box
   ============================================ */
.postcode-search-container {
  position: absolute;
  top: var(--space-4);
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-controls);
  width: 100%;
  max-width: 500px;
  padding: 0 var(--space-4);
}

.postcode-search-box {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(20px);
  transition: all var(--transition-fast);
  margin-right: 40px;
}

.postcode-search-box:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light), var(--shadow-lg);
}

.postcode-search-box .search-icon {
  position: absolute;
  left: var(--space-3);
  color: var(--text-muted);
  pointer-events: none;
  flex-shrink: 0;
}

.postcode-search-input {
  width: 100%;
  padding: var(--space-3) var(--space-10) var(--space-3) var(--space-10);
  background: transparent;
  border: none;
  outline: none;
  font-size: var(--text-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
}

.postcode-search-input::placeholder {
  color: var(--text-muted);
}

.postcode-clear-btn {
  position: absolute;
  right: var(--space-2);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  border-radius: var(--radius);
  transition: all var(--transition-fast);
  background: transparent;
  border: none;
  cursor: pointer;
}

.postcode-clear-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Autocomplete Suggestions Dropdown */
.postcode-suggestions {
  position: absolute;
  top: calc(100% + var(--space-2));
  left: 0;
  right: 0;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xl);
  backdrop-filter: blur(20px);
  max-height: 300px;
  overflow-y: auto;
  z-index: 10;
}

.postcode-suggestion-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3);
  cursor: pointer;
  transition: background-color var(--transition-fast);
  border-bottom: 1px solid var(--border-color);
}

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

.postcode-suggestion-item:hover,
.postcode-suggestion-item.selected {
  background: var(--bg-hover);
}

.postcode-suggestion-item .suggestion-icon {
  flex-shrink: 0;
}

/* Postcode icon (house) - Blue */
.postcode-suggestion-item .postcode-icon {
  color: var(--color-primary);
}

/* Place icon (pin) - Green/Teal */
.postcode-suggestion-item .place-icon {
  color: #10b981; /* Green for places */
}

.postcode-suggestion-item .suggestion-text {
  font-size: var(--text-sm);
  color: var(--text-primary);
  font-weight: var(--font-medium);
}

/* Different font for postcodes vs places */
.postcode-suggestion-item.postcode-item .suggestion-text {
  font-family: var(--font-mono);
}

.postcode-suggestion-item.place-item .suggestion-text {
  font-family: var(--font-sans);
}

.suggestion-loading,
.suggestion-empty,
.suggestion-error {
  padding: var(--space-4);
  text-align: center;
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.suggestion-error {
  color: var(--color-error);
}

/* ============================================
   Map Controls
   ============================================ */
.map-controls {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: var(--z-controls);
}

/* ============================================
   Map Loading State
   ============================================ */
.map-loading {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  z-index: var(--z-controls);
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.map-loading.hidden {
  opacity: 0;
  pointer-events: none;
}

.map-loading.gone {
  display: none;
}

.loading-status {
  margin-top: var(--space-4);
  color: var(--text-primary);
  font-size: var(--text-base);
  font-weight: var(--font-medium);
}

.loading-dots::after {
  content: '';
  animation: loading-dots 1.5s steps(4, end) infinite;
}

@keyframes loading-dots {
  0%   { content: ''; }
  25%  { content: '.'; }
  50%  { content: '..'; }
  75%  { content: '...'; }
  100% { content: ''; }
}

.loading-stats {
  margin-top: var(--space-4);
  text-align: center;
  min-height: 48px;
  max-width: 400px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading-stat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-size: var(--text-base);
  color: var(--text-muted);
  transition: opacity 0.4s ease;
  margin: 0;
}

.loading-stat.fade-out {
  opacity: 0;
}

.loading-stat .material-icons {
  font-size: 18px;
  color: var(--color-primary);
}

/* ============================================
   deck.gl Markers (WebGL-rendered)
   ============================================ */
/*
 * Note: Markers are rendered via deck.gl ScatterplotLayer (GPU-accelerated)
 * No DOM elements needed - everything is WebGL canvas
 * Styling is handled in js/map.js via layer configuration
 */

/* ============================================
   Map Popup (Glassmorphic Style - matches hero map)
   ============================================ */
.maplibregl-popup {
  z-index: 20;
}

.maplibregl-popup-content {
  background: var(--bg-panel) !important;
  border: none !important;
  border-radius: 8px !important;
  box-shadow: var(--shadow-floating) !important;
  backdrop-filter: blur(20px) !important;
  color: var(--text-primary) !important;
  padding: 0 !important;
}

.maplibregl-popup-close-button {
  font-size: 20px;
  padding: var(--space-2);
  color: var(--text-muted);
}

.maplibregl-popup-close-button:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.popup-content {
  padding: var(--space-3);
}

.popup-stats {
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

.popup-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: var(--space-xs);
}

.maplibregl-popup-tip {
  border-top-color: var(--bg-panel) !important;
  border-bottom-color: var(--bg-panel) !important;
}

.popup-meta {
  color: var(--text-secondary);
  font-size: var(--text-xs);
  margin-bottom: var(--space-2);
}

.popup-action {
  display: inline-block;
  margin-top: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--color-primary);
  color: white;
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  border: none;
  border-radius: var(--radius-sm);
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.popup-action:hover {
  background: var(--color-primary-hover);
}

/* ============================================
   Map Overlay Info
   ============================================ */
.map-overlay-info {
  position: absolute;
  bottom: var(--space-4);
  left: var(--space-4);
  background: rgba(255, 255, 255, 0.95);
  padding: var(--space-3);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  z-index: 10;
  max-width: 300px;
}

.map-overlay-info.hidden {
  display: none;
}

/* ============================================
   Zoom Level Indicator
   ============================================ */
.zoom-indicator {
  position: absolute;
  bottom: var(--space-4);
  left: var(--space-4);
  background: rgba(255, 255, 255, 0.95);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  font-size: var(--text-sm);
  font-family: var(--font-mono);
  color: var(--text-secondary);
  z-index: 10;
  pointer-events: none;
  font-weight: var(--font-medium);
}

.zoom-indicator span {
  color: var(--color-primary);
  font-weight: var(--font-semibold);
}

/* ============================================
   Responsive Map
   ============================================ */
@media (max-width: 768px) {
  /* Postcode Search - Stack above map on mobile */
  .postcode-search-container {
    top: var(--space-2);
    max-width: calc(100% - var(--space-8));
    padding: 0 var(--space-2);
  }

  .postcode-search-input {
    font-size: 14px;
    padding: var(--space-2) var(--space-8) var(--space-2) var(--space-8);
  }

  .postcode-search-box .search-icon {
    left: var(--space-2);
    width: 16px;
    height: 16px;
  }

  .postcode-clear-btn {
    right: var(--space-1);
    width: 24px;
    height: 24px;
  }

  /* Map Controls */
  .map-controls {
    top: var(--space-2);
    right: var(--space-2);
    gap: var(--space-1);
  }

  .control-btn {
    width: 36px;
    height: 36px;
  }

  .map-overlay-info {
    bottom: var(--space-2);
    left: var(--space-2);
    max-width: 200px;
  }
}

/* ============================================================
   Industry (SIC) filter — full-height left sidebar + tag tree
   ============================================================ */
.industry-toggle {
  position: absolute;
  top: var(--space-4);
  left: var(--space-4);
  z-index: calc(var(--z-controls) + 1);
  display: inline-flex; align-items: center; gap: var(--space-2);
  background: var(--bg-panel); color: var(--text-primary);
  border: 1px solid var(--border-color); border-radius: var(--radius, 8px);
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-sans); font-size: 14px; font-weight: 500;
  cursor: pointer; box-shadow: var(--shadow, 0 1px 3px rgba(0, 0, 0, .12));
}
.industry-toggle .material-icons { font-size: 18px; }

.industry-filter__badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  background: var(--color-primary); color: #fff;
  border-radius: 9px; font-size: 12px; font-weight: 600;
}

.industry-sidebar {
  position: absolute; top: 0; bottom: 0; left: 0;
  z-index: var(--z-controls);
  width: 320px; max-width: 85vw;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg, 0 10px 30px rgba(0, 0, 0, .18));
  display: flex; flex-direction: column;
  padding: var(--space-3);
  font-family: var(--font-sans);
  transform: translateX(-100%);
  transition: transform .22s ease;
}
.industry-sidebar.is-open { transform: translateX(0); }
.industry-sidebar__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-2); color: var(--text-primary); font-size: 15px;
}
.industry-sidebar__actions { display: flex; align-items: center; gap: var(--space-2); }
.industry-sidebar__clear {
  background: none; border: none; color: var(--color-primary);
  font-size: 13px; cursor: pointer; padding: 2px 4px;
}
.industry-sidebar__close {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; display: inline-flex; padding: 2px;
}
.industry-sidebar__close .material-icons { font-size: 20px; }
.industry-sidebar__note {
  margin: var(--space-1) 0 var(--space-2);
  font-size: 12px; color: var(--text-muted);
}
.industry-sidebar__tree { flex: 1; overflow-y: auto; font-size: 14px; }

.ift-node {}
.ift-row { display: flex; align-items: center; gap: 2px; padding: 1px 0; }
.ift-caret {
  background: none; border: none; cursor: pointer; padding: 0;
  color: var(--text-muted); font-size: 18px; width: 20px; height: 20px;
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
}
.ift-caret--leaf { visibility: hidden; }
.ift-label {
  display: flex; align-items: center; gap: var(--space-2);
  cursor: pointer; flex: 1; min-width: 0; color: var(--text-primary); padding: 2px 0;
}
.ift-label input { cursor: pointer; flex: 0 0 auto; width: 18px; height: 18px; accent-color: var(--color-primary); }
.ift-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ift-count { color: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums; flex: 0 0 auto; }
.ift-children { margin-left: var(--space-5); border-left: 1px solid var(--border-color); padding-left: var(--space-2); }

.stat-filtered { color: var(--color-primary); font-weight: 600; }

.industry-active {
  display: flex; align-items: center; gap: var(--space-2);
  margin: var(--space-2) 0 var(--space-1);
  font-size: 14px; color: var(--text-primary); cursor: pointer;
  font-weight: 500;
}
.industry-active input { cursor: pointer; width: 18px; height: 18px; accent-color: var(--color-primary); }

/* Mobile: drop the industry launcher onto its own row BELOW the full-width search,
   so it doesn't overlap the search box. Placed after the base .industry-toggle rule
   so this override actually wins the cascade. */
@media (max-width: 768px) {
  .industry-toggle {
    top: calc(var(--space-2) + 52px);
    left: var(--space-2);
  }
}

/* Filtered-view loading overlay — covers the map while the server recomputes the
   filtered dots for a new viewport, so the user never sees a half-baked partial map.
   Kept lightweight: a translucent backdrop + a small spinner card. */
.map-filter-loading {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 12, 16, 0.35);
  backdrop-filter: blur(1px);
  pointer-events: none;   /* let the user keep panning/zooming underneath */
}
.map-filter-loading[hidden] { display: none; }
.mfl-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--surface-elevated, #1b1f27);
  color: #fff;
  border: 1px solid var(--border-color, rgba(255,255,255,0.12));
  border-radius: var(--radius-md, 8px);
  box-shadow: var(--shadow-lg, 0 8px 24px rgba(0,0,0,0.4));
  font-size: 14px;
  font-weight: 500;
  max-width: 80%;
}
.mfl-spinner {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.25);
  border-top-color: var(--color-primary, #22d3ee);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.map-filter-loading.is-error .mfl-spinner { display: none; }
.map-filter-loading.is-error .mfl-card { border-color: var(--color-warning, #f59e0b); }

/* Non-alarming "zoom in" nudge shown when a filtered viewport is too big to draw dots
   cleanly (the base map stays visible underneath). Distinct from the error state. */
.map-filter-loading.is-hint .mfl-spinner { display: none; }
.map-filter-loading.is-hint .mfl-card { border-color: var(--color-primary, #22d3ee); }
