/* Иерархический классификатор блоков справочника (v0.27.0). Общий
   компонент App.renderFolderTree используется в трёх UI-точках:
   1. админ-страница «Узлы / Upstream / Tail / Service»
   2. модалка «+ Новые блоки» в проекте (multi-select tristate)
   3. picker блока в редакторе шаблонов (single-select)
*/

.ftree {
  display: flex;
  flex-direction: column;
  font-size: 14px;
  line-height: 1.4;
}

.ftree__row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px 8px;
  border-radius: var(--radius);
  min-height: 32px;
  user-select: none;
}

.ftree__row:hover {
  background: var(--color-bg, #fafafa);
}

.ftree__row[data-selected="true"] {
  background: rgba(37, 99, 235, 0.08);
}

/* Глубина: каждый уровень — 18px отступа слева через CSS-переменную */
.ftree__row {
  padding-left: calc(8px + var(--ftree-depth, 0) * 18px);
}

.ftree__chevron {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-fg-muted, #6b7280);
  font-size: 11px;
  transition: transform 0.12s ease;
  flex-shrink: 0;
}

.ftree__chevron[aria-expanded="true"] {
  transform: rotate(90deg);
}

.ftree__chevron--leaf {
  visibility: hidden;
}

.ftree__cb {
  width: 16px;
  height: 16px;
  cursor: pointer;
  flex-shrink: 0;
  margin: 0;
}

.ftree__cb[disabled] {
  cursor: not-allowed;
  opacity: 0.5;
}

.ftree__icon {
  font-size: 16px;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
}

.ftree__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ftree__name--folder {
  font-weight: 500;
}

.ftree__name--match {
  background: rgba(245, 158, 11, 0.18);
  border-radius: 3px;
  padding: 0 2px;
  margin: 0 -2px;
}

.ftree__count {
  color: var(--color-fg-muted, #6b7280);
  font-size: 12px;
  flex-shrink: 0;
}

.ftree__deleted-badge {
  font-size: 11px;
  color: var(--color-danger, #dc2626);
  background: rgba(220, 38, 38, 0.08);
  padding: 1px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

.ftree__slot {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

.ftree__slot-link {
  font-size: 0.85em;
  color: var(--color-text, #333);
  text-decoration: none;
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid var(--color-border, #ddd);
  background: var(--color-surface-1, #fafafa);
  white-space: nowrap;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.ftree__slot-link:hover,
.ftree__slot-link:focus-visible {
  background: var(--color-surface-2, #eaeaea);
  border-color: var(--color-text-muted, #999);
}

.ftree__actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.ftree__row:hover .ftree__actions,
.ftree__row:focus-within .ftree__actions {
  opacity: 1;
}

.ftree__actions button {
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  padding: 3px 6px;
  font-size: 13px;
  color: var(--color-fg-muted, #6b7280);
}

.ftree__actions button:hover {
  background: var(--color-card, #fff);
  border-color: var(--color-border, #e5e7eb);
  color: var(--color-fg, #1f2937);
}

.ftree__children {
  display: flex;
  flex-direction: column;
}

.ftree__children[hidden] {
  display: none;
}

.ftree__empty {
  padding: 12px;
  color: var(--color-fg-muted, #6b7280);
  font-style: italic;
  text-align: center;
}

/* Поиск-инпут над деревом */
.ftree-search {
  position: relative;
  margin-bottom: var(--space-3);
}

.ftree-search__input {
  width: 100%;
  padding: 8px 32px 8px 12px;
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
}

.ftree-search__clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-fg-muted, #6b7280);
  font-size: 16px;
  padding: 4px;
  display: none;
}

.ftree-search--has-text .ftree-search__clear {
  display: inline-flex;
}

/* Inline-rename для папки в админке */
.ftree__rename-input {
  flex: 1;
  border: 1px solid var(--color-primary, #2563eb);
  border-radius: var(--radius);
  padding: 4px 8px;
  font-size: 14px;
  font-family: inherit;
}

/* Mobile — увеличенные тач-таргеты */
@media (max-width: 640px) {
  .ftree__row {
    min-height: 40px;
    padding: 8px;
    padding-left: calc(8px + var(--ftree-depth, 0) * 14px);
  }
  .ftree__chevron,
  .ftree__cb {
    width: 24px;
    height: 24px;
  }
  .ftree__actions {
    opacity: 1; /* всегда видны */
  }
  .ftree__actions button {
    padding: 6px 8px;
  }
}
