/* Основной контейнер дерева */
.tree-container {
    width: 100%;
    height: calc(100vh - 200px);
    overflow: auto;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-radius: 12px;
    padding: 40px;
    position: relative;
    cursor: grab;
    user-select: none;
}

.tree-container:active {
    cursor: grabbing;
}

.tree-container {
    scroll-behavior: smooth;
}

.tree-container.dragging {
    scroll-behavior: auto;
}

/* Враппер для центрирования */
.tree-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 80px;
    min-width: max-content;
    padding: 20px;
    position: relative;
    transition: transform 0.2s ease-out;
}

/* Уровень дерева */
.tree-level {
    display: flex;
    justify-content: center;
    gap: 40px;
    position: relative;
    width: 100%;
}

/* Узел дерева */
.tree-node {
    position: relative;
    width: 480px;
    height: 100%;
    min-height: 0;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
    cursor: pointer;
    border: 2px solid transparent;
    display: flex;
    flex-direction: column;
}

.tree-node:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    border-color: #6366f1;
}

/* Заголовок узла */
.tree-node-header {
    padding: 11px 16px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    border-radius: 10px 10px 0 0;
}

.tree-node-title {
    font-weight: 600;
    font-size: 14px;
    color: white;
    margin: 0;
    flex: 1;
}

.tree-node-badge {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
}

.tree-node-body {
    padding: 12px 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.tree-node-preview {
    font-size: 13px;
    color: #64748b;
    line-height: 1.45;
    margin: 0 0 10px 0;
    max-height: 40px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* Превью изображения */
.tree-node-image {
    width: 100%;
    height: 90px;
    object-fit: cover;
    border-radius: 6px;
    margin-bottom: 10px;
}

/* Кнопки узла */
.tree-node-buttons {
    display: flex;
    gap: 8px;
    margin-top: auto;
}

.tree-node-btn {
    flex: 1;
    padding: 8px;
    border: 1px solid #e2e8f0;
    background: white;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.tree-node-btn:hover {
    background: #f8fafc;
    border-color: #6366f1;
    color: #6366f1;
}

/* Индикатор дочерних кнопок */
.tree-node-children-indicator {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border: 1px solid #bae6fd;
    color: #0369a1;
    padding: 7px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    margin-top: 8px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.tree-node:hover .tree-node-children-indicator {
    background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
    color: white;
    border-color: #0284c7;
    transform: scale(1.02);
}

/* Первый узел (start_message) */
.tree-level[data-level="0"] .tree-node {
    border: 3px solid #6366f1;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.3);
}

.tree-level[data-level="0"] .tree-node-header {
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
}

/* Статусы */
.status-active {
    background: #10b981;
}

.status-inactive {
    background: #ef4444;
}

/* Скроллбар */
.tree-container::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

.tree-container::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 10px;
}

.tree-container::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

.tree-container::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Пустое состояние */
.tree-empty {
    text-align: center;
    padding: 80px 20px;
    color: #94a3b8;
}

.tree-empty-icon {
    font-size: 64px;
    margin-bottom: 20px;
}

.tree-empty-text {
    font-size: 18px;
    font-weight: 500;
}

/* Ветка дерева */
.tree-branch {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 60px;
    position: relative;
}

/* Обёртка узла */
.tree-node-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 60px;
    position: relative;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Контейнер дочерних узлов */
.tree-children {
    display: flex;
    justify-content: center;
    gap: 40px;
    flex-wrap: wrap;
    max-width: 100%;
    align-items: stretch;
    max-height: 10000px;
    opacity: 1;
    overflow: hidden;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: top center;
    transform: scaleY(1);
    position: relative;
    padding-top: 60px;
}

.tree-children.collapsed {
    max-height: 0;
    opacity: 0;
    pointer-events: none;
    margin: 0;
    padding: 0;
    transform: scaleY(0);
}

.tree-children.collapsed .tree-node-wrapper {
    display: inline-block;
    width: 0;
    overflow: hidden;
    transition: width 0.4s ease;
}

/* Уровень 2 */
.tree-level[data-level="2"] {
    display: flex;
    justify-content: center;
    gap: 80px;
    flex-wrap: wrap;
    align-items: flex-start;
}

.tree-level[data-level="2"] .tree-branch {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* === ВІЗУАЛЬНІ ЛІНІЇ === */

/* Вертикальна лінія вниз від будь-якого блоку */
.tree-node-wrapper>.tree-node::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    height: 60px;
    background: linear-gradient(180deg, #cbd5e1 0%, transparent 100%);
    z-index: 1;
}

/* Спеціальна лінія від start_message */
.tree-node[data-key="start_message"]::after {
    width: 3px;
    height: 80px;
    background: linear-gradient(180deg, #6366f1 0%, #cbd5e1 100%) !important;
}


/* Горизонтальна лінія між дітьми */
.tree-children::before {
    content: '';
    position: absolute;
    top: 0;
    left: 10%;
    right: 10%;
    height: 2px;
    background: #cbd5e1;
    z-index: 0;
}

/* Вертикальні лінії до кожної дитини */
.tree-children>.tree-node-wrapper::before {
    content: '';
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    height: 30px;
    background: #cbd5e1;
    z-index: 0;
}

/* Ховаємо лінії коли згорнуто */
.tree-children.collapsed::before,
.tree-children.collapsed>.tree-node-wrapper::before {
    display: none;
}

.tree-node-wrapper.collapsed>.tree-node::after {
    display: none;
}

/* Ховаємо лінію якщо немає дітей */
.tree-node-wrapper:not(:has(.tree-children))>.tree-node::after {
    display: none;
}

/* === КНОПКА СВОРАЧИВАНИЯ === */

.toggle-icon {
    transition: transform 0.3s ease;
}

.tree-node-btn:has(.toggle-icon) {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border-color: #bae6fd;
    color: #0369a1;
}

.tree-node-btn:has(.toggle-icon):hover {
    background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
    border-color: #0284c7;
    color: white;
}

.tree-node-wrapper.collapsed .tree-node-children-indicator {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border-color: #fcd34d;
    color: #d97706;
}

.tree-node-wrapper.collapsed .tree-node-children-indicator::before {
    content: '▶ ';
}

/* === ПАНЕЛЬ ЗУМА === */

.zoom-controls {
    position: fixed;
    bottom: 40px;
    left: 40px;
    background: white;
    border-radius: 10px;
    padding: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 1000;
}

.zoom-btn {
    width: 32px;
    height: 32px;
    border: 1px solid #e2e8f0;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: #64748b;
}

.zoom-btn svg {
    width: 16px;
    height: 16px;
}

.zoom-btn:hover {
    background: #f8fafc;
    border-color: #6366f1;
    color: #6366f1;
}

.zoom-btn:active {
    transform: scale(0.95);
}

.zoom-slider-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 6px 0;
}

.zoom-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 90px;
    height: 4px;
    background: linear-gradient(to right, #e2e8f0 0%, #e2e8f0 100%);
    border-radius: 2px;
    outline: none;
    transform: rotate(-90deg);
    margin: 40px 0;
}

.zoom-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(99, 102, 241, 0.3);
    transition: all 0.2s;
}

.zoom-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 4px 8px rgba(99, 102, 241, 0.4);
}

.zoom-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px rgba(99, 102, 241, 0.3);
    transition: all 0.2s;
}

.zoom-slider::-moz-range-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 4px 8px rgba(99, 102, 241, 0.4);
}

.zoom-label {
    font-size: 11px;
    font-weight: 600;
    color: #6366f1;
    min-width: 38px;
    text-align: center;
}

.zoom-controls::before {
    content: 'Ctrl + колесико';
    position: absolute;
    bottom: 100%;
    left: 0;
    margin-bottom: 6px;
    font-size: 9px;
    color: #94a3b8;
    text-align: center;
    white-space: pre-line;
    line-height: 1.3;
    padding: 3px 6px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 4px;
}