/**
 * fta-cause-tree-constructor.css
 * Стили для визуального конструктора дерева причин отказов FTA
 */

/* ── Оверлей модального окна ── */
.fta-ctc-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity .2s ease;
}
.fta-ctc-overlay.visible { opacity: 1; }

/* ── Контейнер модального окна ── */
.fta-ctc-modal {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 40px rgba(0,0,0,.25);
    display: flex;
    flex-direction: column;
    width: 92vw;
    max-width: 1280px;
    height: 88vh;
    overflow: hidden;
}

/* ── Заголовок ── */
.fta-ctc-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    background: linear-gradient(135deg, #1e3a5f 0%, #2d6a9f 100%);
    color: #fff;
    flex-shrink: 0;
}
.fta-ctc-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    flex: 1;
}
.fta-ctc-header-icon { font-size: 18px; opacity: .85; }
.fta-ctc-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    opacity: .8;
    transition: opacity .15s, background .15s;
}
.fta-ctc-close:hover { opacity: 1; background: rgba(255,255,255,.15); }

/* ── Тело (2 колонки) ── */
.fta-ctc-body {
    display: grid;
    grid-template-columns: 320px 1fr;
    flex: 1;
    overflow: hidden;
}

/* ── Левая панель: поиск и добавление причин ── */
.fta-ctc-sidebar {
    border-right: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #f9fafb;
}
.fta-ctc-sidebar-title {
    padding: 10px 14px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: #6b7280;
    border-bottom: 1px solid #e5e7eb;
    background: #fff;
    flex-shrink: 0;
}
.fta-ctc-search {
    padding: 10px 14px;
    border-bottom: 1px solid #e5e7eb;
    background: #fff;
    flex-shrink: 0;
}
.fta-ctc-search input {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 13px;
    outline: none;
    box-sizing: border-box;
    transition: border-color .15s;
}
.fta-ctc-search input:focus { border-color: #3b82f6; }

.fta-ctc-failures-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px 8px 10px;
}

.fta-ctc-group {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #fff;
    margin-bottom: 8px;
    overflow: hidden;
}
.fta-ctc-group-header {
    width: 100%;
    border: 0;
    background: #f8fafc;
    display: flex;
    align-items: center;
    gap: 8px;
    text-align: left;
    padding: 8px 10px;
    cursor: pointer;
}
.fta-ctc-group-arrow {
    color: #6b7280;
    font-size: 11px;
    transition: transform .15s;
}
.fta-ctc-group.expanded .fta-ctc-group-arrow { transform: rotate(90deg); }
.fta-ctc-group-head-text { min-width: 0; flex: 1; }
.fta-ctc-group-system {
    font-size: 12px;
    font-weight: 600;
    color: #1f2937;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.fta-ctc-group-function {
    font-size: 11px;
    color: #6b7280;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}
.fta-ctc-group-count {
    background: #e5e7eb;
    color: #374151;
    border-radius: 999px;
    font-size: 11px;
    padding: 2px 7px;
}
.fta-ctc-group-body {
    display: none;
    border-top: 1px solid #e5e7eb;
}
.fta-ctc-group.expanded .fta-ctc-group-body { display: block; }

.fta-ctc-group .fta-ctc-failure-item {
    padding-left: 26px;
}

/* Элемент списка причин */
.fta-ctc-failure-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 14px;
    cursor: pointer;
    border-bottom: 1px solid #f3f4f6;
    transition: background .12s;
    user-select: none;
}
.fta-ctc-failure-item:hover { background: #eff6ff; }
.fta-ctc-failure-item.already-added { opacity: .45; cursor: default; }
.fta-ctc-failure-item .fi-icon {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #dbeafe;
    color: #1d4ed8;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    flex-shrink: 0;
    margin-top: 1px;
}
.fta-ctc-failure-item .fi-info { flex: 1; min-width: 0; }
.fta-ctc-failure-item .fi-name {
    font-size: 13px;
    font-weight: 500;
    color: #111827;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.fta-ctc-failure-item .fi-meta {
    font-size: 11px;
    color: #9ca3af;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}
.fta-ctc-failure-item .fi-add-btn {
    background: #3b82f6;
    color: #fff;
    border: none;
    border-radius: 5px;
    padding: 4px 9px;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background .12s;
}
.fta-ctc-failure-item .fi-add-btn:hover { background: #2563eb; }
.fta-ctc-failure-item.already-added .fi-add-btn {
    background: #d1d5db;
    color: #6b7280;
    cursor: default;
}
.fta-ctc-group .fta-ctc-failure-item:last-child { border-bottom: 0; }

/* ── Правая панель: дерево ── */
.fta-ctc-tree-area {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.fta-ctc-tree-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-bottom: 1px solid #e5e7eb;
    background: #fff;
    flex-shrink: 0;
    flex-wrap: wrap;
}
.fta-ctc-tree-toolbar label {
    font-size: 12px;
    font-weight: 600;
    color: #374151;
    white-space: nowrap;
}
.ctc-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 11px;
    border: 1px solid #d1d5db;
    border-radius: 5px;
    background: #fff;
    font-size: 12px;
    cursor: pointer;
    color: #374151;
    transition: background .12s, border-color .12s;
    white-space: nowrap;
}
.ctc-btn:hover { background: #f3f4f6; border-color: #9ca3af; }
.ctc-btn.primary { background: #3b82f6; color: #fff; border-color: #3b82f6; }
.ctc-btn.primary:hover { background: #2563eb; }
.ctc-btn.danger { background: #ef4444; color: #fff; border-color: #ef4444; }
.ctc-btn.danger:hover { background: #dc2626; }
.ctc-btn.success { background: #10b981; color: #fff; border-color: #10b981; }
.ctc-btn.success:hover { background: #059669; }
.ctc-btn.warn { background: #f59e0b; color: #fff; border-color: #f59e0b; }
.ctc-btn.warn:hover { background: #d97706; }

.ctc-sep { width: 1px; height: 22px; background: #e5e7eb; flex-shrink: 0; }

/* Дерево (прокручиваемое) */
.fta-ctc-tree-canvas {
    flex: 1;
    overflow: auto;
    padding: 20px 16px;
    background: #fff;
}
.fta-ctc-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #9ca3af;
    font-size: 14px;
    gap: 10px;
    text-align: center;
}
.fta-ctc-empty i { font-size: 40px; opacity: .4; }

/* ── Узлы дерева ── */
.ctc-tree-root { display: flex; flex-direction: column; align-items: center; }

.ctc-node-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

/* Карточка узла */
.ctc-node {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    border-radius: 8px;
    border: 2px solid transparent;
    cursor: pointer;
    user-select: none;
    min-width: 160px;
    max-width: 280px;
    transition: box-shadow .15s, border-color .15s, transform .1s;
    z-index: 1;
}
.ctc-node:hover { transform: translateY(-1px); }
.ctc-node.selected { outline: 3px solid #3b82f6; outline-offset: 2px; }

/* Типы узлов */
.ctc-node.gate-node {
    background: #fffbeb;
    border-color: #f59e0b;
    box-shadow: 0 1px 4px rgba(245,158,11,.2);
}
.ctc-node.gate-node:hover { box-shadow: 0 3px 10px rgba(245,158,11,.3); }

.ctc-node.event-node {
    background: #eff6ff;
    border-color: #3b82f6;
    box-shadow: 0 1px 4px rgba(59,130,246,.15);
}
.ctc-node.event-node:hover { box-shadow: 0 3px 10px rgba(59,130,246,.25); }

.ctc-node.root-node {
    background: #fef3c7;
    border-color: #d97706;
    box-shadow: 0 2px 8px rgba(217,119,6,.2);
    font-weight: 600;
    cursor: default;
    min-width: 200px;
}

/* Иконка типа */
.ctc-node-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    flex-shrink: 0;
}
.gate-node .ctc-node-icon { background: #fde68a; color: #92400e; }
.event-node .ctc-node-icon { background: #bfdbfe; color: #1e40af; }
.root-node .ctc-node-icon { background: #fcd34d; color: #78350f; }

/* Символ вентиля */
.ctc-gate-badge {
    background: #f59e0b;
    color: #fff;
    border-radius: 4px;
    padding: 1px 6px;
    font-size: 11px;
    font-weight: 700;
    margin-left: 2px;
}

/* Текст узла */
.ctc-node-text { flex: 1; min-width: 0; }
.ctc-node-name {
    font-size: 13px;
    font-weight: 500;
    color: #1f2937;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}
.ctc-node-sub {
    font-size: 10px;
    color: #9ca3af;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Кнопки действий у узла */
.ctc-node-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity .15s;
}
.ctc-node:hover .ctc-node-actions { opacity: 1; }
.ctc-node.selected .ctc-node-actions { opacity: 1; }
.ctc-action-btn {
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .12s;
}
.ctc-action-btn.del { background: #fee2e2; color: #dc2626; }
.ctc-action-btn.del:hover { background: #dc2626; color: #fff; }
.ctc-action-btn.add-child { background: #dcfce7; color: #16a34a; }
.ctc-action-btn.add-child:hover { background: #16a34a; color: #fff; }
.ctc-action-btn.change-gate { background: #fef3c7; color: #d97706; }
.ctc-action-btn.change-gate:hover { background: #d97706; color: #fff; }

/* ── Вертикальные и горизонтальные соединители ── */
.ctc-connector-v {
    width: 2px;
    background: #cbd5e1;
    min-height: 20px;
    flex-shrink: 0;
}
.ctc-children-row {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 0;
    position: relative;
}
/* Горизонтальная линия над детьми */
.ctc-h-line {
    position: absolute;
    top: 0;
    height: 2px;
    background: #cbd5e1;
    pointer-events: none;
}
/* Вертикальная линия от горизонтальной до дочернего узла */
.ctc-child-col {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.ctc-child-col > .ctc-connector-v { min-height: 16px; }

/* ── Зона дропа ── */
.ctc-drop-zone {
    min-width: 80px;
    min-height: 34px;
    border: 2px dashed #93c5fd;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    color: #93c5fd;
    transition: background .15s, border-color .15s;
    margin: 4px;
}
.ctc-drop-zone.drag-over {
    background: #eff6ff;
    border-color: #3b82f6;
    color: #3b82f6;
}

/* ── Drag handle ── */
.ctc-drag-handle {
    cursor: grab;
    color: #9ca3af;
    font-size: 12px;
    padding: 0 2px;
}
.ctc-drag-handle:active { cursor: grabbing; }

/* Dragging state */
.ctc-node-group.dragging { opacity: .4; }
.ctc-node-group.drag-target > .ctc-node {
    box-shadow: 0 0 0 3px #3b82f6;
}

/* ── Контекстное меню ── */
.ctc-context-menu {
    position: fixed;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,.15);
    z-index: 10100;
    min-width: 190px;
    padding: 4px 0;
    font-size: 13px;
}
.ctc-ctx-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    cursor: pointer;
    color: #374151;
    transition: background .1s;
}
.ctc-ctx-item:hover { background: #f3f4f6; }
.ctc-ctx-item.danger { color: #dc2626; }
.ctc-ctx-item.danger:hover { background: #fee2e2; }
.ctc-ctx-sep { height: 1px; background: #e5e7eb; margin: 3px 0; }

/* ── Диалог выбора типа вентиля ── */
.ctc-gate-picker {
    position: fixed;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    box-shadow: 0 4px 24px rgba(0,0,0,.18);
    z-index: 10200;
    padding: 12px;
    min-width: 240px;
}
.ctc-gate-picker h4 {
    margin: 0 0 10px;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
}
.ctc-gate-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}
.ctc-gate-opt {
    padding: 8px 10px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    cursor: pointer;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    transition: background .12s, border-color .12s;
    background: #f9fafb;
    color: #374151;
}
.ctc-gate-opt:hover { background: #fffbeb; border-color: #f59e0b; color: #92400e; }
.ctc-gate-opt.active { background: #fef3c7; border-color: #d97706; color: #92400e; }
.ctc-gate-opt-label { font-size: 10px; color: #9ca3af; font-weight: 400; margin-top: 2px; }

/* ── Нижний футер ── */
.fta-ctc-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
    flex-shrink: 0;
    gap: 12px;
}
.fta-ctc-footer-info {
    font-size: 12px;
    color: #6b7280;
}
.fta-ctc-footer-actions { display: flex; gap: 8px; }

/* ── Анимация добавления ── */
@keyframes ctcNodeIn {
    from { opacity: 0; transform: scale(.85) translateY(-8px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}
.ctc-node-group.new-node { animation: ctcNodeIn .2s ease; }

/* ── Вероятность ── */
.ctc-prob-badge {
    font-size: 10px;
    color: #6b7280;
    background: #f3f4f6;
    border-radius: 4px;
    padding: 1px 5px;
    margin-left: 4px;
    flex-shrink: 0;
}
