.custom-legend {
  position: absolute;
  right: 10px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.legend-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  color: #555;
  line-height: 1.4;
  border-radius: 2px;
  transition: color 0.2s;
  position: relative;
  letter-spacing: -1px;
}

.legend-btn:focus-visible {
  outline: 2px solid black;
  outline-offset: 2px;
}

/* 預設：bar 實心矩形 */
.legend-btn .legend-btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 25px;
  height: 14px;
  flex-shrink: 0;
}

/* bar：實心矩形 */
.legend-btn[data-series-type="bar"] .legend-btn-icon::after {
  content: '';
  display: block;
  width: 25px;
  height: 14px;
  border-radius: 4px;
  background-color: var(--legend-color, #ccc);
}

/* line：橫線 + 中間圓點 */
.legend-btn[data-series-type="line"] .legend-btn-icon::before {
  content: '';
  display: block;
  position: absolute;
  width: 27px;
  height: 2px;
  background-color: var(--legend-color, #ccc);
  border-radius: 1px;
}
.legend-btn[data-series-type="line"] .legend-btn-icon::after {
  content: '';
  display: block;
  position: relative;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background-color: var(--legend-color, #ccc);
  z-index: 1;
}

/* 未選取狀態 */
.legend-btn:not(.active) {
  color: #bbb;
}

.legend-btn:not(.active) .legend-btn-icon::after,
.legend-btn:not(.active) .legend-btn-icon::before {
  background-color: #ccc !important;
  box-shadow: none !important;
}

.legend-btn:not(.active) .legend-btn-label {
  text-decoration-color: #bbb;
}

@media (max-width: 768px) {
  .custom-legend {
    position: relative;
    right: auto;
    top: 82px;
    width: 100%;
    justify-content: flex-end;
    margin-top: 12px;
  }

  .legend-btn {
    padding: 4px 8px;
  }
}
