:host {
  display: block;
}

.hb-tree-select {
  position: relative;
  width: 100%;
  font-size: var(--hb-font-size-base);
  color: var(--hb-color-text);
  box-sizing: border-box;
}

.hb-tree-select__input-wrapper {
  display: flex;
  align-items: center;
  height: var(--hb-size-default, 32px);
  padding: 0 var(--hb-spacing-sm);
  border: 1px solid var(--hb-input-border-color, var(--hb-color-border));
  border-radius: var(--hb-input-radius, var(--hb-border-radius-sm));
  background-color: var(--hb-color-bg-container);
  cursor: pointer;
  transition: border-color var(--hb-transition-duration, 0.2s);
  box-sizing: border-box;
}

.hb-tree-select__input-wrapper:hover {
  border-color: var(--hb-input-hover-border-color, var(--hb-color-primary));
}

.hb-tree-select--open .hb-tree-select__input-wrapper {
  border-color: var(--hb-input-focus-border-color, var(--hb-color-primary));
}

.hb-tree-select--disabled .hb-tree-select__input-wrapper {
  background-color: var(--hb-color-fill-tertiary);
  cursor: not-allowed;
  opacity: 0.6;
}

.hb-tree-select__display {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  user-select: none;
}

.hb-tree-select__display--placeholder {
  color: var(--hb-input-placeholder-color, var(--hb-color-text-placeholder));
}

.hb-tree-select__suffix {
  display: inline-flex;
  align-items: center;
  gap: var(--hb-spacing-xxs);
  color: var(--hb-color-text-tertiary);
}

.hb-tree-select__clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  font-size: 12px;
  border-radius: 50%;
  color: var(--hb-color-text-tertiary);
  background-color: var(--hb-color-fill);
  cursor: pointer;
}

.hb-tree-select__clear:hover {
  color: var(--hb-color-text-secondary);
}

.hb-tree-select__arrow-icon {
  font-size: 10px;
  transition: transform var(--hb-transition-duration, 0.2s);
}

.hb-tree-select__arrow-icon--open {
  transform: rotate(180deg);
}

.hb-tree-select__dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  width: 100%;
  max-height: 280px;
  overflow-y: auto;
  padding: var(--hb-spacing-xxs);
  background-color: var(--hb-color-bg-elevated);
  border: 1px solid var(--hb-color-border-secondary);
  border-radius: var(--hb-border-radius-sm);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
  box-sizing: border-box;
  z-index: 1050;
}

.hb-tree-select__empty {
  padding: var(--hb-spacing-md);
  text-align: center;
  color: var(--hb-color-text-tertiary);
  font-size: var(--hb-font-size-sm);
}

.hb-tree-select__tree,
.hb-tree-select__children {
  list-style: none;
  margin: 0;
  padding: 0;
}

.hb-tree-select__node {
  list-style: none;
  white-space: nowrap;
}

.hb-tree-select__node-content {
  display: flex;
  align-items: center;
  gap: var(--hb-spacing-xxs);
  height: 28px;
  padding-right: var(--hb-spacing-xs);
  border-radius: var(--hb-border-radius-sm);
  cursor: pointer;
  transition: background-color var(--hb-transition-duration, 0.2s);
  box-sizing: border-box;
}

.hb-tree-select__node-content:hover {
  background-color: var(--hb-color-fill-tertiary);
}

.hb-tree-select__node-content--selected {
  background-color: var(--hb-color-primary-bg);
  color: var(--hb-color-primary);
  font-weight: 500;
}

.hb-tree-select__node-content--checked {
  background-color: var(--hb-color-primary-bg);
}

.hb-tree-select__node--disabled > .hb-tree-select__node-content {
  cursor: not-allowed;
  opacity: 0.5;
}

.hb-tree-select__node--disabled > .hb-tree-select__node-content:hover {
  background-color: transparent;
}

.hb-tree-select__switcher {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--hb-color-text-tertiary);
}

.hb-tree-select__arrow {
  font-size: 10px;
  display: inline-block;
  transition: transform var(--hb-transition-duration, 0.2s);
}

.hb-tree-select__arrow--expanded {
  transform: rotate(90deg);
}

.hb-tree-select__checkbox {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border: 1px solid var(--hb-color-border);
  border-radius: var(--hb-border-radius-xs, 2px);
  background-color: var(--hb-color-bg-container);
  color: #fff;
  font-size: 11px;
  line-height: 1;
  flex-shrink: 0;
  transition: all var(--hb-transition-duration, 0.2s);
}

.hb-tree-select__checkbox:hover:not(.hb-tree-select__checkbox--disabled) {
  border-color: var(--hb-color-primary);
}

.hb-tree-select__checkbox--checked {
  background-color: var(--hb-color-primary);
  border-color: var(--hb-color-primary);
}

.hb-tree-select__checkbox--disabled {
  cursor: not-allowed;
}

.hb-tree-select__title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  user-select: none;
}
