/* ── Map View ── */

#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-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(--header-bg);
  color: var(--header-bg);
}

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

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

/* Market group sub-filter (shown only in Market Groups mode) */
.map-mg-filters {
  display: none;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.map-mg-filters.visible {
  display: flex;
}

.map-mg-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  border: 1.5px solid transparent;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s, border-color 0.15s;
  opacity: 0.55;
}

.map-mg-chip.active {
  opacity: 1;
  border-color: currentColor;
}

.map-mg-chip-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.map-mg-chip[data-mg="K12"]           { color: #009cbd; }
.map-mg-chip[data-mg="K12"] .map-mg-chip-dot { background: #009cbd; }

.map-mg-chip[data-mg="C+C"]           { color: #b7791f; }
.map-mg-chip[data-mg="C+C"] .map-mg-chip-dot { background: #d69e2e; }

.map-mg-chip[data-mg="HE"]            { color: #6b46c1; }
.map-mg-chip[data-mg="HE"] .map-mg-chip-dot  { background: #805ad5; }

.map-mg-chip[data-mg="HE Student Life"] { color: #6b46c1; }
.map-mg-chip[data-mg="HE Student Life"] .map-mg-chip-dot { background: #805ad5; }

.map-mg-chip[data-mg="HE Academic"]   { color: #c53030; }
.map-mg-chip[data-mg="HE Academic"] .map-mg-chip-dot { background: #e53e3e; }

/* 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 + side panel */
.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 overrides */
.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-link {
  display: inline-block;
  margin-top: 6px;
  font-size: 0.78rem;
  color: var(--link-color);
  text-decoration: none;
  font-weight: 500;
}

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

.map-popup-badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  vertical-align: middle;
  margin-left: 4px;
}

.map-popup-badge.active   { background: var(--status-active-bg);    color: var(--status-active-text); }
.map-popup-badge.on-hold  { background: var(--status-on-hold-bg);   color: var(--status-on-hold-text); }
.map-popup-badge.completed{ background: var(--status-completed-bg); color: var(--status-completed-text); }
.map-popup-badge.archived { background: var(--status-archived-bg);  color: var(--status-archived-text); }

/* ── Side Panel ── */
.map-side-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: 320px;
  height: 100%;
  background: var(--bg-primary);
  border-left: 1px solid var(--border-color);
  box-shadow: -4px 0 16px rgba(0,0,0,0.08);
  z-index: 900;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.22s ease;
}

.map-side-panel.open {
  transform: translateX(0);
}

.map-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  background: var(--bg-secondary);
}

.map-panel-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-primary);
}

.map-panel-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.2rem;
  color: var(--text-muted);
  line-height: 1;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  transition: color 0.12s, background 0.12s;
}

.map-panel-close:hover {
  color: var(--text-primary);
  background: var(--border-color);
}

.map-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

/* Market group section */
.map-panel-mg-section {
  margin-bottom: 4px;
}

.map-panel-mg-heading {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px 4px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  position: sticky;
  top: 0;
  background: var(--bg-primary);
  z-index: 1;
}

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

.map-panel-mg-count {
  margin-left: auto;
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--bg-secondary);
  border-radius: 999px;
  padding: 1px 7px;
  color: var(--text-muted);
}

/* Project row */
.map-panel-project-row {
  padding: 8px 16px;
  border-bottom: 1px solid var(--border-color);
  transition: background 0.1s;
}

.map-panel-project-row:last-child {
  border-bottom: none;
}

.map-panel-project-row:hover {
  background: var(--bg-secondary);
}

.map-panel-project-name {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.map-panel-project-name a {
  color: var(--link-color);
  text-decoration: none;
}

.map-panel-project-name a:hover {
  text-decoration: underline;
}

.map-panel-project-meta {
  display: flex;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.map-panel-meta-label {
  font-weight: 600;
  color: var(--text-primary);
  min-width: 62px;
  flex-shrink: 0;
}

/* Client / contractor simple rows */
.map-panel-simple-row {
  padding: 8px 16px;
  border-bottom: 1px solid var(--border-color);
}

.map-panel-simple-row:last-child {
  border-bottom: none;
}

.map-panel-simple-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.map-panel-simple-loc {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.map-panel-empty {
  padding: 20px 16px;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  margin: 0;
}

/* Legend (market groups mode) */
.map-legend {
  display: none;
  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);
  pointer-events: none;
  min-width: 150px;
}

.map-legend.visible {
  display: block;
}

.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-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* 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;
}
