/**
 * Tags Tree - Ultra Compact Design
 * Оптимизация для максимальной информационной плотности
 * Стиль: Hunter Config (каждый пиксель важен)
 */

/* ============================================================================
   БАЗОВЫЕ СТИЛИ - КОМПАКТНЫЕ РАЗМЕРЫ
   ============================================================================ */

.tree-item {
    display: flex;
    align-items: center;
    height: 28px;
    padding: var(--space-1) var(--space-2);
    font-size: var(--font-sm);
    line-height: 1.2;
    cursor: pointer;
    transition: all 0.15s ease;
    border-left: 3px solid transparent;
    position: relative;
}

.tree-item:hover {
    background: rgba(255, 255, 255, 0.05);
    transform: translateX(2px);
}

.tree-item.selected {
    background: rgba(33, 150, 243, 0.15);
    border-left-color: #2196F3;
}

/* ============================================================================
   ИЕРАРХИЯ - ВИЗУАЛЬНЫЕ УРОВНИ
   ============================================================================ */

.tree-item.level-0 {
    padding-left: var(--space-2);
    font-weight: var(--weight-medium);
}

.tree-item.level-1 {
    padding-left: 24px;  /* +16px indent */
    font-size: var(--font-xs);
}

.tree-item.level-2 {
    padding-left: 40px;  /* +32px indent */
    font-size: var(--font-xs);
    color: rgba(255, 255, 255, 0.85);
}

.tree-item.level-3 {
    padding-left: 56px;  /* +48px indent */
    font-size: var(--font-2xs);
    color: rgba(255, 255, 255, 0.75);
}

/* ============================================================================
   ЦВЕТОВАЯ СХЕМА ПО КАТЕГОРИЯМ
   ============================================================================ */

/* .tag-region removed — CONFLICT with badge-v2.css (border-left-color override) */
/* .tag-country removed — CONFLICT with badge-v2.css (duplicates tag category styling) */

.tag-city {
    border-left-color: #FF9800;  /* Оранжевый - города */
}

.tag-language {
    border-left-color: #9C27B0;  /* Фиолетовый - языки */
}

.tag-action {
    border-left-color: #F44336;  /* Красный - действия */
}

.tag-risk {
    border-left-color: #FFC107;  /* Желтый - риски */
}

.tag-canonical {
    border-left-color: #757575;  /* Серый - canonical */
}

/* ============================================================================
   CANONICAL КАТЕГОРИИ - РАСШИРЕННАЯ ЦВЕТОВАЯ СХЕМА
   ============================================================================ */

.tag-communication {
    border-left-color: #2196F3;  /* Синий - коммуникации */
}

.tag-finance {
    border-left-color: #4CAF50;  /* Зеленый - финансы */
}

.tag-marketing {
    border-left-color: #9C27B0;  /* Фиолетовый - маркетинг */
}

.tag-data {
    border-left-color: #FF5722;  /* Оранжево-красный - данные */
}

.tag-adult {
    border-left-color: #E91E63;  /* Розовый - взрослый контент */
}

.tag-technical {
    border-left-color: #607D8B;  /* Серо-голубой - техническое */
}

/* ============================================================================
   ЭЛЕМЕНТЫ СТРОКИ - КОМПАКТНАЯ РАСКЛАДКА
   ============================================================================ */

.tree-item .expand-icon {
    width: 16px;
    min-width: 16px;
    text-align: center;
    font-size: var(--font-xs);
    color: rgba(255, 255, 255, 0.5);
    margin-right: var(--space-1);
}

.tree-item .icon {
    width: 18px;
    min-width: 18px;
    text-align: center;
    font-size: var(--font-base);
    margin-right: 6px;
}

.tree-item .name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: var(--space-2);
}

.tree-item .count {
    min-width: 40px;
    text-align: right;
    font-size: var(--font-xs);
    color: rgba(255, 255, 255, 0.6);
    font-weight: var(--weight-medium);
    margin-right: 6px;
}

/* ============================================================================
   КАТЕГОРИИ - ЗАГОЛОВКИ
   ============================================================================ */

.tree-category {
    margin-bottom: var(--space-1);
}

.category-header {
    display: flex;
    align-items: center;
    height: 32px;
    padding: 6px var(--space-2);
    font-size: var(--font-base);
    font-weight: var(--weight-semi);
    cursor: pointer;
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-xs);
    transition: all 0.15s ease;
}

.category-header:hover {
    background: rgba(255, 255, 255, 0.08);
}

.category-header .expand-icon {
    width: 18px;
    min-width: 18px;
    text-align: center;
    margin-right: 6px;
    font-size: var(--font-xs);
    color: rgba(255, 255, 255, 0.6);
}

.category-header .category-icon {
    width: 20px;
    min-width: 20px;
    text-align: center;
    font-size: var(--font-md);
    margin-right: var(--space-2);
}

.category-header .category-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.category-header .category-count {
    min-width: 50px;
    text-align: right;
    font-size: var(--font-xs);
    color: rgba(255, 255, 255, 0.5);
    font-weight: var(--weight-medium);
}

/* ============================================================================
   DATA-TABLE-V2 GROUPED VIEW (F1) — neutralize legacy flex on table rows
   ----------------------------------------------------------------------------
   The grouped tree now renders as a real <table class="data-table-v2"> with
   <tbody class="tree-category"> groups, <tr class="category-header"> headers,
   and <tr class="tree-item"> rows. Legacy .tree-item / .category-header rules
   (here + analytics.css) set display:flex, which collapses table layout and
   breaks column alignment vs <thead>. The 3-class + element specificity below
   beats the 2-class legacy rules regardless of stylesheet load order.
   (.category-children rules removed here — admin-tags no longer emits that
   class; the leads TagsTreeFilter sidebar still does, styled by its own
   complete .category-children rules in leads-clean.css.)
   ============================================================================ */
.tags-grouped-container table.data-table-v2 tr.tree-item,
.tags-grouped-container table.data-table-v2 tr.category-header {
    display: table-row;
    padding: 0;
    margin: 0;
    height: auto;
}

.tags-grouped-container table.data-table-v2 tr.tree-item:hover {
    transform: none;
}

/* ============================================================================
   SCROLLBAR - ТОНКИЙ
   ============================================================================ */

.filter-tree::-webkit-scrollbar {
    width: 6px;
}

.filter-tree::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.filter-tree::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-sm);
}

.filter-tree::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ============================================================================
   КОНТЕЙНЕР ДЕРЕВА - растёт под контент
   ============================================================================ */

.filter-tree {
    /* Без ограничений - контент растёт вниз */
}

/* ============================================================================
   АНИМАЦИЯ КЛИКА
   ============================================================================ */

.tree-item.clicking {
    transform: scale(0.98);
    background: rgba(33, 150, 243, 0.2);
}

/* ============================================================================
   ПОИСК - ПОДСВЕТКА
   ============================================================================ */

.tree-item.highlight {
    background: rgba(255, 193, 7, 0.15);
    animation: highlight-pulse 0.5s ease;
}

@keyframes highlight-pulse {
    0%, 100% {
        background: rgba(255, 193, 7, 0.15);
    }
    50% {
        background: rgba(255, 193, 7, 0.3);
    }
}

/* ============================================================================
   АДАПТИВНОСТЬ - МЕДИА-ЗАПРОСЫ
   ============================================================================ */

@media (max-width: 768px) {
    .tree-item {
        height: 32px;
        padding: 6px var(--space-2);
        font-size: var(--font-base);
    }

    .tree-item.level-1 {
        padding-left: 20px;
    }

    .tree-item.level-2 {
        padding-left: 36px;
    }
}

@media (min-width: 1400px) {
    /* На больших экранах можно еще компактнее */
    .tree-item {
        height: 26px;
        padding: 3px var(--space-2);
        font-size: var(--font-xs);
    }

    .category-header {
        height: 30px;
        padding: 5px var(--space-2);
        font-size: var(--font-sm);
    }
}

/* ============================================================================
   ACCESSIBILITY - A11Y
   ============================================================================ */

.tree-item:focus,
.category-header:focus {
    outline: 2px solid #2196F3;
    outline-offset: -2px;
}

.tree-item[aria-checked="true"]::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: #2196F3;
}

/* ============================================================================
   LOADING STATE
   ============================================================================ */

.tree-item.loading {
    opacity: 0.5;
    pointer-events: none;
}

.tree-item.loading::after {
    content: '⏳';
    margin-left: auto;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
