/* Base legend style */
.legend {
  position: absolute;
  width: max-content;    /* width adjusts automatically to content */
  background: rgba(255, 255, 255, 0.9); /* semi-transparent background */
  font-family: Arial, sans-serif;
  border-radius: 3px;
  padding: 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
  line-height: 18px;
  overflow: auto;
  z-index: 1000;
  white-space: nowrap; /* prevent line breaks unless necessary */
}

/* Color box inside legend */
.legend i {
  width: 14px;
  height: 14px;
  display: inline-block;
  vertical-align: middle;
  margin-right: 8px;
  border: 1px solid;
}

/* Label text */
.legend span {
  vertical-align: middle;
}

/* Positioning: all four corners, width grows naturally */
.legend.bottom-left {
  bottom: 0px;
  left: 0px;
  margin-bottom: 40px;
  margin-left: 10px;
}

.legend.bottom-right {
  bottom: 0px;
  right: 0;
  margin-bottom: 50px;
  margin-right: 10px;
}

.legend.top-left {
  top: 0px;
  left: 0px;
  margin-top: 10px;
  margin-left: 50px;
}

.legend.top-right {
  top: 0px;
  right: 0px;
  margin-top: 60px;
  margin-right: 10px;
}

.legend.left {
  top: 50%;            /* move it halfway down the container */
  left: 0;             /* stick to left edge */
  transform: translateY(-50%); /* pull it up by half its own height */
  margin-left: 10px;   /* padding from the left edge */
}

.legend.right {
  top: 50%;            /* move it halfway down the container */
  right: 0;             /* stick to left edge */
  transform: translateY(-50%); /* pull it up by half its own height */
  margin-right: 10px;   /* padding from the left edge */
}

.legend.top {
  top: 0px;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 10px;
}

.legend.bottom {
  bottom: 0px;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 10px;
}
