/* JIMS Legend — FL511-style popover, top-right of map */

/* Legend trigger button (lives in the topbar) */
.legend-trigger {
  background: #1e2a5e;
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(11,29,81,.2);
  transition: background .15s ease;
}
.legend-trigger:hover { background: #2a3878; }
.legend-trigger.active { background: var(--coral); }
.legend-trigger svg { width: 16px; height: 16px; }

/* Legend popover panel */
.legend-panel {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 340px;
  max-height: calc(100vh - var(--topbar-h) - 32px);
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 6px 22px rgba(0,0,0,.18);
  z-index: 600;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  font-family: 'Inter', system-ui, sans-serif;
}
.legend-panel[hidden] { display: none !important; }

.legend-panel-head {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 10px 16px 4px;
}
.legend-clear {
  background: none;
  border: none;
  color: #2e7adc;
  font-size: 13px;
  cursor: pointer;
  padding: 4px 6px;
  font-weight: 500;
}
.legend-clear:hover { text-decoration: underline; }

.legend-body {
  padding: 4px 12px 12px;
  overflow-y: auto;
  flex: 1;
}

/* Legend row */
.legend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 4px;
  cursor: pointer;
  user-select: none;
  border-radius: 4px;
  transition: background .12s;
}
.legend-row:hover { background: #f5f7fb; }

.legend-checkbox {
  width: 18px;
  height: 18px;
  border: 1.5px solid #c8cfe0;
  border-radius: 3px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  flex-shrink: 0;
  transition: all .12s;
}
.legend-row.active .legend-checkbox {
  background: #6b46c1;
  border-color: #6b46c1;
}
.legend-row.active .legend-checkbox::after {
  content: '';
  width: 5px; height: 9px;
  border-right: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(45deg) translate(-1px, -1px);
}

/* Round colored pin icon (FL511 style) */
.legend-pin {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 13px;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0,0,0,.18);
  position: relative;
}
.legend-pin svg { width: 14px; height: 14px; }

.legend-label {
  flex: 1;
  font-size: 14px;
  color: #2d2d2d;
  font-weight: 400;
  line-height: 1.3;
}

/* Special: Traffic Speeds row with gradient bar */
.legend-traffic-speeds {
  padding-bottom: 4px;
}
.legend-speed-gradient {
  margin: 4px 0 14px 38px;
  height: 14px;
  border-radius: 2px;
  background: linear-gradient(to right,
    #1a1a1a 0%, #1a1a1a 18%,
    #5a1414 18%, #5a1414 32%,
    #b91c1c 32%, #b91c1c 46%,
    #dc2626 46%, #dc2626 60%,
    #fbbf24 60%, #fbbf24 78%,
    #16a34a 78%, #16a34a 100%);
}
.legend-speed-labels {
  margin: 2px 0 8px 38px;
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #6b7280;
}

/* Marker Clustering footer row */
.legend-cluster {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 4px 4px;
  margin-top: 4px;
  border-top: 1px solid #f0f2f7;
  font-size: 14px;
  color: #2d2d2d;
}
.legend-cluster-icon {
  width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 20px;
}
.legend-cluster-toggle {
  background: none; border: none; cursor: pointer;
  color: #2d2d2d; font: inherit; flex: 1; text-align: left;
}
.legend-help {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 1.5px solid #6b7280;
  color: #6b7280;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: help;
}

/* Section divider (when grouping inside legend) */
.legend-divider {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #9ca3af;
  font-weight: 600;
  padding: 12px 4px 4px;
  border-top: 1px solid #f0f2f7;
  margin-top: 4px;
}
.legend-divider:first-child { border-top: 0; margin-top: 0; padding-top: 4px; }

/* Tabs at top (Layers / Quick Actions / Uploads) */
.legend-tabs {
  display: flex;
  border-bottom: 1px solid #f0f2f7;
  padding: 0 12px;
  margin: 6px 0 4px;
}
.legend-tab {
  background: none;
  border: none;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-right: 2px;
}
.legend-tab.active { color: #1e2a5e; border-bottom-color: #1e2a5e; }

/* Quick Actions inside legend */
.legend-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 4px 12px 12px;
}
.legend-action {
  background: #f5f7fb;
  border: 1px solid #e6eaf2;
  border-radius: 8px;
  padding: 10px 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: #1e2a5e;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
}
.legend-action:hover { background: #fff; border-color: #1e2a5e; }
.legend-action .ic { width: 20px; height: 20px; }

/* Basemap pills inline in legend */
.legend-basemaps {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  padding: 4px 12px 12px;
}
.legend-basemap {
  border: 2px solid #e6eaf2; background: #f5f7fb;
  border-radius: 6px; padding: 8px; cursor: pointer;
  font-size: 12px; font-weight: 600; text-align: center;
  color: #2d2d2d;
}
.legend-basemap.active { border-color: #1e2a5e; background: #fff; }

/* Emergency mini-banner inside legend */
.legend-emergency {
  margin: 8px 12px;
  padding: 10px 12px;
  background: linear-gradient(135deg, #fef2f2, #fee2e2);
  border-left: 3px solid #dc2626;
  border-radius: 6px;
  font-size: 12px;
  display: none;
}
.legend-emergency.active { display: block; }
.legend-emergency b { display: block; color: #991b1b; font-size: 13px; margin-bottom: 2px; }
.legend-emergency button {
  margin-top: 6px; background: #dc2626; color: #fff; border: none;
  padding: 6px 12px; border-radius: 4px; font-size: 11px; font-weight: 600; cursor: pointer;
}

/* Info-page links — pinned footer of the legend panel */
.legend-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 3px;
  padding: 9px 12px;
  border-top: 1px solid #f0f2f7;
  background: #fafbfd;
  flex-shrink: 0;
}
.legend-foot a {
  font-size: 11.5px;
  font-weight: 600;
  color: #6b7280;
  text-decoration: none;
  padding: 3px 7px;
  border-radius: 5px;
  transition: background .12s, color .12s;
}
.legend-foot a:hover { background: #eef1f7; color: #1e2a5e; }

/* Mobile */
@media (max-width: 720px) {
  .legend-panel {
    width: calc(100vw - 24px);
    right: 12px; left: 12px;
    max-height: calc(100vh - var(--topbar-h) - 24px);
  }
}
@media (max-width: 600px) {
  /* icon-only legend trigger so the topbar fits small phones */
  .legend-trigger { padding: 8px 10px; gap: 0; font-size: 0; }
  .legend-trigger svg { width: 18px; height: 18px; }
}
