/* ── Map View (CCI organizations) ── */

#map-view {
  display: none;
  flex-direction: column;
  height: calc(100vh - 52px);
  overflow: hidden;
  padding: 0;
}

#map-view.active {
  display: flex;
}

/* Toolbar */
.map-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.map-toolbar-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-right: 4px;
}

.map-toolbar-empty {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.map-toolbar-divider {
  width: 1px;
  height: 22px;
  background: var(--border-color);
  margin: 0 4px;
}

/* Toggle button (Only orgs with open deals) */
.map-toggle-btn {
  padding: 5px 14px;
  border-radius: 999px;
  border: 1.5px solid var(--border-color);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.map-toggle-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.map-toggle-btn.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

/* Category filter chips (double as the color legend in the toolbar) */
.map-cat-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.map-cat-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  border: 1.5px solid transparent;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s, border-color 0.15s, color 0.15s;
  opacity: 0.5;
}

.map-cat-chip.active {
  opacity: 1;
  border-color: var(--chip-color, var(--color-primary));
  color: var(--chip-color, var(--text-primary));
}

.map-cat-chip-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--chip-color, var(--color-primary));
}

/* Geocoding status bar */
.map-status-bar {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  background: var(--info-bg);
  color: var(--info-text);
  font-size: 0.8rem;
  flex-shrink: 0;
  border-bottom: 1px solid #bee3f8;
}

.map-status-bar.visible {
  display: flex;
}

.map-status-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--info-text);
  border-top-color: transparent;
  border-radius: 50%;
  animation: map-spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes map-spin {
  to { transform: rotate(360deg); }
}

/* Map body: contains canvas + overlays */
.map-body {
  flex: 1;
  position: relative;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

/* Map canvas */
#map-canvas {
  flex: 1;
  min-height: 0;
  height: 100%;
}

/* Leaflet popup content */
.map-popup-name {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.map-popup-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.map-popup-deals {
  margin-top: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
}

.map-popup-deals-none {
  font-weight: 500;
  color: var(--text-muted);
}

.map-popup-link {
  display: inline-block;
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--link-color);
  text-decoration: none;
  font-weight: 500;
}

.map-popup-link:hover {
  text-decoration: underline;
}

/* Legend (always visible, bottom-right) */
.map-legend {
  position: absolute;
  bottom: 24px;
  right: 10px;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  box-shadow: var(--shadow-md);
  min-width: 160px;
  max-height: 48%;
  overflow-y: auto;
}

.map-legend-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.map-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-primary);
  margin-bottom: 5px;
}

.map-legend-item:last-child {
  margin-bottom: 0;
}

.map-legend-label {
  flex: 1;
  min-width: 0;
}

.map-legend-count {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  flex-shrink: 0;
}

.map-legend-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Session geocode-cap note (bottom-left) */
.map-cap-note {
  position: absolute;
  bottom: 24px;
  left: 10px;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  box-shadow: var(--shadow-md);
  font-size: 0.75rem;
  color: var(--text-muted);
  max-width: 280px;
  line-height: 1.4;
}

/* Empty state */
.map-empty-state {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1000;
  text-align: center;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px 32px;
  box-shadow: var(--shadow-md);
  pointer-events: none;
}

.map-empty-state p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Shared map controls  (js/map-controls.js)
   Faithful port of the gridops-ft-aps Routing map toolset (routing.js
   addMapToolControls + the .rt-tip fast-tooltip CSS in routing.html).
   Applies to all four Leaflet maps: /map, pipeline map view, organizations
   map view, contacts map view. Top-right stack, one tool per .leaflet-bar
   (separate rounded boxes, Leaflet's default 10px control margins — same
   spacing as the donor): zoom (+/−, Leaflet default size), layers (basemap
   toggle), fit-to-view, box-zoom.
   ───────────────────────────────────────────────────────────────────────── */

/* Tool buttons — the donor's inline cssText, verbatim values:
   display:flex;align-items:center;justify-content:center;width:30px;
   height:30px;font-size:16px;text-decoration:none;color:#333;
   Background/hover/borders come from Leaflet's own .leaflet-bar styles,
   exactly as in the donor. Active state (#dbeafe) is set inline by JS,
   donor-style. */
.leaflet-bar a.mc-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  font-size: 16px;
  text-decoration: none;
  color: #333;
}
.leaflet-bar a.mc-btn svg {
  display: block;
}
/* Keyboard affordance (invisible until focused via keyboard; no donor look
   change on mouse use). */
.leaflet-bar a.mc-btn:focus-visible {
  outline: 2px solid var(--color-primary, #4f46e5);
  outline-offset: -2px;
}

/* Fast hover tooltip for map tool buttons (native title is ~1s slow) —
   donor's .rt-tip rules from routing.html, ported verbatim as .mc-tip.
   Bubble opens to the LEFT of the button, so it never overlaps the stack. */
.mc-tip { position: relative; }
.mc-tip::after {
  content: attr(data-tip);
  position: absolute; right: calc(100% + 8px); top: 50%; transform: translateY(-50%);
  background: #1f2937; color: #fff; font-size: 11px; line-height: 1.3; font-weight: 500;
  padding: 5px 8px; border-radius: 5px; box-shadow: 0 1px 5px rgba(0,0,0,0.3);
  width: max-content; max-width: 220px; white-space: normal; text-align: left;
  pointer-events: none; opacity: 0; transition: opacity 0.1s ease; z-index: 1200;
}
.mc-tip:hover::after { opacity: 1; transition-delay: 0.15s; }
/* Don't flash an empty bubble if a button has no tip text. */
.mc-tip[data-tip=""]::after { display: none; }
