:root {
    --font-sans: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    --color-bg: #1a1a1f;
    --color-topbar: #111115;
    --color-text: #ccc;
    --color-border: #333;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font-sans); background: #000; color: var(--color-text); padding: 20px; }

/* Окно NLE */
.nle { display: grid; grid-template-rows: auto 1fr; height: 800px; border: 1px solid var(--color-border); border-radius: 8px; overflow: hidden; background: var(--color-bg); }

.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--color-topbar); border-bottom: 1px solid var(--color-border); }
.topbar-title { font-size: 14px; font-weight: 500; flex: 1; }

.tbtn { padding: 6px 12px; font-size: 12px; border: 1px solid #444; border-radius: 6px; background: #222; color: #ccc; cursor: pointer; transition: 0.2s;}
.tbtn:hover { background: #333; }
.tbtn-blue { background: #185FA5; color: #E6F1FB; border-color: #185FA5; }
.tbtn-blue:hover { background: #0C447C; }

/* Рабочая область */
.workspace { 
    display: flex; 
    flex-direction: row; 
    overflow: hidden; 
    width: 100%; 
    height: 100%; 
}

/* Задаем стартовые размеры для колонок, чтобы при загрузке они выглядели ровно */
.left-col { flex: 0 0 65%; min-width: 250px; }
.right-col { flex: 1 1 0; min-width: 250px; }

/* Левая колонка - Ноды */
.left-col { display: grid; grid-template-rows: auto 1fr; overflow: hidden; }
.label-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; background: var(--color-topbar); border-bottom: 1px solid #2a2a2a; font-size: 11px; color: #888; text-transform: uppercase; letter-spacing: 1px; }

.node-workspace {
    position: relative;
    overflow: hidden; /* Было auto, стало hidden */
    background: #111;
    width: 100%;
    height: 100%;
}

.node-connections {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    overflow: visible; /* МАГИЯ: разрешаем рисовать кабели за пределами окна */
    pointer-events: none;
	transition: none !important;	
}
.node-canvas {
    position: absolute;
    top: 0; left: 0;
    width: 3000px;
    height: 3000px;
	transition: none !important;
}

.tl-block { 
    position: absolute;
    width: 220px;
    height: 90px; 
    border-radius: 6px; 
    border: 2px solid rgba(255,255,255,0.1); /* Прозрачная рамка по умолчанию */
    cursor: grab; 
    padding: 8px 10px;
    color: #fff;
    /* УДАЛИЛИ background ОТСЮДА */
}
.tl-block.active { 
    border-color: #fff !important; 
    box-shadow: 0 0 15px rgba(255,255,255,0.3);
}

/* --- ПОРТЫ И ХИТБОКСЫ --- */
.port {
    width: 30px; 
    height: 30px; /* Огромный невидимый хитбокс для мыши */
    background: transparent;
    position: absolute;
    /* ⚡ ЕДИНАЯ ТОЧКА ПОРТА: фиксированно 45px от верха у ВСЕХ типов нод
       (совпадает с PORT_OFFSET_Y в uiConnections). Раньше было top:50%,
       из-за чего у высоких нод (видео, раскадровка с ячейками) точка
       уезжала вниз и провода не попадали в неё. */
    top: 45px;
    transform: translateY(-50%);
    cursor: crosshair;
    z-index: 10;
    pointer-events: auto; /* ⚡ ДОБАВЬ ЭТО, чтобы порты всегда ловили мышку */
}
/* Визуальная точка внутри хитбокса */
.port::after {
    content: '';
    position: absolute;
    width: 12px; height: 12px;
    background: #888;
    border: 2px solid #111;
    border-radius: 50%;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    transition: 0.15s ease;
}
.port:hover::after { 
    background: #fff; 
    transform: translate(-50%, -50%) scale(1.4); 
    box-shadow: 0 0 8px rgba(255,255,255,0.5);
}
.port-in { left: -15px; }
.port-out { right: -15px; }

.block-num { font-size: 11px; font-weight: bold; opacity: 0.7; margin-bottom: 4px; pointer-events: none;}
.block-title { font-size: 12px; font-weight: 600; line-height: 1.2; margin-bottom: auto; pointer-events: none;}
.block-chars {
    display: block !important;
    white-space: nowrap !important;      /* Запрещаем перенос на новую строку */
    overflow: hidden !important;         /* Прячем всё, что не влезло */
    text-overflow: ellipsis !important;  /* Добавляем три точки в конце */
    max-width: 180px;                    /* Ограничиваем ширину внутри ноды */
    height: 14px;                        /* Жестко фиксируем высоту одной строки */
    line-height: 14px;
}

/* Правая колонка - А4 */
.right-col { background: #f0ece6; display: flex; flex-direction: column; overflow: hidden; }
.canvas-header { padding: 8px 12px; background: var(--color-topbar); border-bottom: 1px solid #2a2a2a; display: flex; justify-content: space-between; align-items: center; font-size: 11px; color: #888; font-weight: 500; text-transform: uppercase; letter-spacing: 1px; }
.a4-scroll { overflow: hidden; flex: 1; min-height: 0; background: #999; }
.a4 { background: #fff; width: 100%; min-height: 100%; padding: 40px 30px; font-family: 'Courier New', monospace; font-size: 13px; line-height: 1.6; color: #222; border-radius: 4px; box-shadow: 0 4px 10px rgba(0,0,0,0.2);}

.doc-block { padding: 10px; border-left: 3px solid transparent; cursor: pointer; border-radius: 4px; margin-bottom: 10px; transition: 0.2s;}
.doc-block:hover { background: #f9f9f9; }
.doc-block.active { background: #EEF5FF; border-left-color: #185FA5; }


.doc-block-heading { font-weight: bold; font-size: 12px; margin-bottom: 8px; color: #000; }
.doc-block-body { font-size: 13px; color: #111; line-height: 1.5; white-space: pre-wrap; outline: none; }

/* Модальное окно импорта */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); display: none; justify-content: center; align-items: center; z-index: 100; }
.modal { background: var(--color-bg); padding: 20px; border-radius: 8px; width: 600px; border: 1px solid var(--color-border); }
.modal h3 { margin-bottom: 15px; font-size: 16px; color: #fff; }
.modal textarea { width: 100%; height: 300px; padding: 12px; background: #111; color: #ccc; border: 1px solid #333; border-radius: 4px; font-family: monospace; resize: none; margin-bottom: 15px; line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* Контекстное меню */
.context-menu {
    position: absolute;
    background: #1e1e24;
    border: 1px solid #333;
    border-radius: 6px;
    padding: 4px;
    min-width: 160px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    display: none; /* Скрыто по умолчанию */
    z-index: 1000;
    font-size: 12px;
}
.context-menu-item {
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 4px;
    color: #ccc;
    transition: 0.1s;
}
.context-menu-item:hover { background: #185FA5; color: #fff; }

.tl-block.bypassed {
    opacity: 0.4;
    filter: grayscale(0.8);
    text-decoration: line-through;
}

.menu-hint { opacity: 0.4; font-size: 10px; margin-left: 20px; }
.menu-sep { height: 1px; background: #333; margin: 4px 0; }
.has-submenu { position: relative; display: flex; justify-content: space-between; align-items: center; }
.has-submenu::after { content: '▶'; font-size: 8px; margin-left: 10px; opacity: 0.5; }

.submenu {
    display: none; 
    position: absolute;
    left: 100%; top: -5px; /* Чуть сдвинули вверх для ровности */
    margin-left: 2px;
}

/* ⚡ Показываем меню цвета ТОЛЬКО при наведении на пункт "Цвет (Label)" */
.has-submenu:hover .submenu {
    display: block;
}

.color-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 8px;
}

/* Рамка множественного выделения */
.marquee-selection {
    position: absolute;
    border: 1px solid #378ADD;
    background: rgba(55, 138, 221, 0.2);
    z-index: 1000;
    pointer-events: none;
    display: none;
}

/* Динамические рамки (Группы / Эпизоды) */
.node-group {
    position: absolute;
    border: 3px solid #185FA5;
    background: rgba(24, 95, 165, 0.08);
    border-radius: 12px;
    z-index: 1; 
    pointer-events: none; /* Пропускаем клики к нодам... */
    transition: background 0.2s, border-color 0.2s;
}
.node-group.active {
    border-color: #fff !important;
    box-shadow: 0 0 15px rgba(255,255,255,0.3);
}
.node-group-header {
    position: absolute;
    top: -30px;
    left: -3px; /* Выравниваем по границе рамки */
    right: -3px; /* Растягиваем на 100% */
    color: #fff;
    background: #185FA5;
    font-size: 14px;
    font-weight: bold;
    letter-spacing: 1px;
    padding: 6px 0;
    text-align: center; /* Центрируем текст */
    border-radius: 8px 8px 0 0;
    pointer-events: auto;
    cursor: grab;
    user-select: none;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.3);
}
.node-group-header:active { cursor: grabbing; }

/* ⚡ v206 (Денис: «перетащил — группа подсветилась, добавилась»). Пока нода
   висит над рамкой, рамка показывает, что примет её. */
.node-group.group-drop-target {
    border-color: #65dcb4 !important;
    background: rgba(101, 220, 180, 0.14);
    box-shadow: 0 0 0 2px rgba(101, 220, 180, 0.35), 0 0 24px rgba(101, 220, 180, 0.25);
}
.node-group.group-drop-target > .node-group-header {
    background: #65dcb4 !important;
    color: #0e1112;
}

/* Имя группы переименовывается двойным кликом: пока правят — курсор текстовый,
   выделение разрешено, а перетаскивание за заголовок не начинается. */
.node-group-header[contenteditable="true"] {
    cursor: text;
    user-select: text;
    outline: 2px solid rgba(255, 255, 255, 0.55);
    outline-offset: -2px;
}

.group-port {
    pointer-events: auto; /* Порты рамки тоже кликабельны */
}

.doc-episode-header {
    font-size: 18px;
    font-weight: 900;
    text-transform: uppercase;
    text-align: center;
    margin: 30px 0 15px 0;
    padding-bottom: 5px;
    border-bottom: 2px solid #185FA5;
    color: #185FA5;
}

/* Развилки сюжета в окне А4 */
.doc-fork-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    margin: -5px 0 25px 40px; /* Смещаем вправо, под основной текст блока */
    font-family: var(--font-sans);
}
.fork-label {
    font-size: 11px;
    color: #999;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.5px;
}
.fork-option {
    font-size: 12px;
    color: #666;
    cursor: pointer;
    padding-bottom: 2px;
    border-bottom: 1px dotted transparent; /* Убрали линию по умолчанию для чистоты */
    transition: all 0.2s;
    display: flex;
    align-items: center;
}

.fork-option:hover {
    color: #185FA5;
}

.fork-option.active {
    color: #111; /* Активный текст делаем контрастным черным */
    font-weight: 600;
}

/* ⚡ Стиль для бейджика v01, v02 ⚡ */
.fork-vnum {
    font-family: monospace;
    font-weight: 800;
    font-size: 12px; /* Чуть увеличили, так как это теперь единственная кнопка */
    color: #888;
    background: #e0e0e0;
    padding: 4px 8px; /* Сделали более "кликабельным" квадратиком */
    border-radius: 4px;
    /* margin-right: 6px; <--- УДАЛИЛИ отступ, он больше не нужен */
    transition: all 0.2s;
}

/* Раскрашиваем бейдж при наведении и активности */
.fork-option:hover .fork-vnum {
    background: rgba(24, 95, 165, 0.2);
    color: #185FA5;
}

.fork-option.active .fork-vnum {
    background: #185FA5;
    color: #fff;
    box-shadow: 0 2px 6px rgba(24, 95, 165, 0.4);
}

/* Порты для рамок */
.port-ext-in { left: -15px; }
.port-ext-out { right: -15px; }

/* Внутренние порты Эпизода (желтые) */
.port-int-out { left: 15px; border-color: #ffcc00; background: #222; }
.port-int-in { right: 15px; border-color: #ffcc00; background: #222; }
.port-int-out:hover::after, .port-int-in:hover::after { background: #ffcc00; }

/* Координаты для 4-х портов Эпизода */
.port-ext-in { left: -15px; }
.port-ext-out { right: -15px; }
.port-int-out { left: 15px; }
.port-int-in { right: 15px; }

/* Визуальное отличие внутренних портов (желтые) */
.port-int-out::after, .port-int-in::after { 
    border-color: #ffcc00; 
    background: #222; 
}
.port-int-out:hover::after, .port-int-in:hover::after { 
    background: #ffcc00; 
}

/* Подсветка редактируемого текста в А4 */
.doc-block-body[contenteditable="true"] {
    outline: none;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid transparent;
    transition: background 0.2s, border-color 0.2s;
    min-height: 20px; /* Чтобы пустой блок не схлопнулся */
}
/* Легкий фон, когда блок просто активен (выделен) */
.doc-block.active .doc-block-body[contenteditable="true"] {
    background: rgba(24, 95, 165, 0.08);
    border-color: rgba(55, 138, 221, 0.2);
}
/* Более яркий фон, когда курсор стоит внутри и ты пишешь текст */
.doc-block-body[contenteditable="true"]:focus {
    background: rgba(24, 95, 165, 0.15);
    border-color: #378ADD;
}

/* Подсветка редактируемого заголовка в А4 */
.doc-block-heading[contenteditable="true"] {
    outline: none;
    padding: 2px 8px;
    border-radius: 6px;
    border: 1px solid transparent;
    transition: background 0.2s, border-color 0.2s;
}
.doc-block.active .doc-block-heading[contenteditable="true"] {
    background: rgba(24, 95, 165, 0.08);
    border-color: rgba(55, 138, 221, 0.2);
}
.doc-block-heading[contenteditable="true"]:focus {
    background: rgba(24, 95, 165, 0.15);
    border-color: #378ADD;
}

/* ⚡ ПЛАВНАЯ ПОДСВЕТКА МОДУЛЕЙ НА ЛИСТЕ А4 */

.doc-module {
    transition: all 0.2s ease-in-out;
    border-radius: 6px;
    padding: 6px 10px;
    margin-left: -10px; /* Компенсируем отступ, чтобы текст не прыгнул вправо */
    margin-right: -10px;
    border: 1px solid transparent; /* Невидимая рамка, чтобы верстка не дергалась */
}

/* 1. Эффект при наведении мыши (Hover) */
.doc-module:hover {
    background-color: rgba(59, 130, 246, 0.04); /* Очень легкий серый фон */
    border-color: rgba(0, 0, 0, 0.05);
}

/* 2. Эффект при работе внутри модуля (когда стоит текстовый курсор) */
.doc-module:focus-within {
    background-color: rgba(59, 130, 246, 0.04); /* Легкая синева */
    border-color: rgba(59, 130, 246, 0.3); /* Аккуратная синяя рамка */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03); /* Мягкая тень для объема */
}

/* Опционально: прячем кнопку удаления (крестик), пока не навели мышку или не кликнули */
.doc-module .mod-a4-del {
    opacity: 0.5;
    transition: opacity 0.2s;
}

.doc-module:hover .mod-a4-del,
.doc-module:focus-within .mod-a4-del {
    opacity: 1;
}

/* ⚡ ПЛАВНАЯ ПОДСВЕТКА МОДУЛЕЙ НА ХОЛСТЕ (НОДЫ) */

.tl-module {
    /* Плавная анимация для тени, цвета и трансформации */
    transition: filter 0.2s ease-in-out, box-shadow 0.2s ease-in-out, transform 0.1s;
}

/* 1. Эффект при наведении мыши (Hover) */
.tl-module:hover {
    filter: brightness(1.5); /* Умно осветляет блок, не ломая твои синие/зеленые цвета */
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5); /* Делаем тень глубже, чтобы блок "всплывал" */
}

/* 2. Прячем кнопку удаления (крестик), пока не навели мышку (как на А4) */
.tl-module .node-mod-del {
    opacity: 0.5;
    transition: opacity 0.2s;
}

.tl-module:hover .node-mod-del {
    opacity: 1;
}

/* 3. Опционально: легкий эффект нажатия при перетаскивании */
.tl-module:active {
    transform: scale(0.98); /* Чуть-чуть сжимается при клике/драге */
    filter: brightness(0.9);
}

/* ⚡ ЭФФЕКТ ПОДСВЕТКИ МОДУЛЯ НА ХОЛСТЕ */
@keyframes module-focus-pulse {
    0% { box-shadow: 0 0 0 0 rgba(77, 166, 255, 0.8); }
    10% { box-shadow: 0 0 0 15px rgba(77, 166, 255, 0); }
    20% { box-shadow: 0 0 0 0 rgba(77, 166, 255, 0); }
}

.tl-module.active-focus {
    border-color: #4DA6FF !important;
    
    
}

/* ⚡ ЯРКАЯ ПОДСВЕТКА АКТИВНОГО МОДУЛЯ В А4 */
.doc-module.active-focus {
    background-color: rgba(59, 130, 246, 0.08) !important;
    border-color: rgba(59, 130, 246, 0.5) !important;
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.15);
    transform: translateX(4px);
}

/* ⚡ HOVER-FOCUS: зеркальная подсветка при наведении мыши (оба направления) */

/* Нода на нодовом холсте — при наведении мыши на соответствующий блок в А4 */
.tl-block.hover-focus {
    border-color: #22c55e !important;
    box-shadow: 0 0 0 2px rgba(34,197,94,0.4), 0 0 20px rgba(34,197,94,0.25) !important;
    transition: border-color 0.12s, box-shadow 0.12s;
}

/* Модуль на нодовом холсте — при наведении на соответствующий модуль в А4 */
.tl-module.hover-focus {
    border-color: #22c55e !important;
    box-shadow: 0 0 0 2px rgba(34,197,94,0.5), 0 4px 16px rgba(0,0,0,0.5) !important;
    filter: brightness(1.4);
    z-index: 200 !important;
    transition: border-color 0.12s, box-shadow 0.12s, filter 0.12s;
}

/* Блок в А4 — при наведении мыши на соответствующую ноду на холсте */
.doc-block.hover-focus,
.doc-page-node-wrapper.hover-focus {
    background: #edfff4 !important;
    border-left: 3px solid #22c55e !important;
    box-shadow: inset 3px 0 0 #22c55e;
    transition: background 0.12s, border-left-color 0.12s;
}

/* Модуль в А4 — при наведении мыши на соответствующий модуль на холсте */
.doc-module.hover-focus {
    background: rgba(34,197,94,0.09) !important;
    border-left: 3px solid #22c55e !important;
    box-shadow: 2px 0 0 #22c55e inset;
    transition: background 0.12s;
}

/* Плавный переход для всех состояний */
.doc-module {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-left: 3px solid transparent;
}

/* Пропускаем клики сквозь пустые места холста прямо к макаронинам */
#node-canvas {
    pointer-events: none; 
}
/* ⚡ Оставляем плотными ТОЛЬКО карточки нод. Эпизод теперь "пропускает" мышь ⚡ */
.tl-block {
    pointer-events: auto; 
}

/* Динамический ползунок-разделитель (Блендер-стайл) */
.resizer {
    width: 2px; /* Физическая ширина самой линии */
    background: rgba(255, 255, 255, 0.05); /* Едва заметный шов */
    cursor: col-resize;
    z-index: 100;
    position: relative;
    flex-shrink: 0;
    transition: background 0.15s;
    /* Увеличиваем зону клика невидимой рамкой, чтобы было легко попасть мышкой */
    border-left: 3px solid transparent;
    border-right: 3px solid transparent;
}

.resizer::before {
    content: '';
    display: block;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 1px;
    background: rgba(255, 255, 255, 0.12);
}

.resizer::after {
    content: '⋮';
    display: block;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 12px;
    color: rgba(255, 255, 255, 0.2);
    line-height: 1;
    pointer-events: none;
    transition: color 0.15s;
}

.resizer:hover::before, .resizer.dragging::before {
    background: rgba(66, 153, 225, 0.8);
    width: 2px;
}

.resizer:hover::after, .resizer.dragging::after {
    color: rgba(66, 153, 225, 0.9);
}

.resizer:hover, .resizer.dragging {
    background: rgba(66, 153, 225, 0.06);
    box-shadow: none; /* убираем старую тень */
}

/* Красивый разделитель в конце Эпизода */
.doc-episode-footer {
    margin: 25px 0 45px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.6;
}
.doc-episode-footer::before, .doc-episode-footer::after {
    content: "";
    flex: 1;
    border-bottom: 1px dashed #888;
    margin: 0 15px;
}
.doc-episode-footer-text {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: #888;
}

/* ⚡ ПАНЕЛЬ-СТОЛ ⚡ */
#a4-canvas {
    background-color: #1a1a1a;
    width: 100%;
    height: 100%;
    overflow-y: scroll; 
    overflow-x: hidden;
    padding: 60px 0; 
    box-sizing: border-box;
}

/* Обертка для масштабирования */
.a4-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
    padding-bottom: 60px;
}

/* ⚡ БЕСКОНЕЧНЫЙ ЛИСТ С РАЗМЕТКОЙ СТРАНИЦ ⚡ */
.a4-paper {
    width: 794px;         
    min-height: 1123px;   
    flex-shrink: 0;       
    background-color: #ffffff;
    color: #111111;
    /* Поля: Сверху, Справа, Снизу, Слева */
    padding: 95px 113px 95px 95px; 
    box-sizing: border-box;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6); 
    text-align: left;
    position: relative;
    
    /* УМНЫЙ РАЗДЕЛИТЕЛЬ: Тонкая серая линия ровно каждые 1123px (высота А4) */
    background-image: repeating-linear-gradient(
        to bottom,
        transparent,
        transparent calc(1123px - 2px),
        #d4d4d4 calc(1123px - 2px), 
        #d4d4d4 1123px
    );
}

.a4-content {
    width: 100%;
    display: flex;
    flex-direction: column;
}

.doc-block {
    margin-bottom: 20px;
    position: relative;
}

@media print {
    /* Прячем левое окно с нодами и кнопки */
    .left-col, .topbar, .resizer, .doc-fork { display: none !important; }
    
    /* Разворачиваем лист на 100% бумаги принтера */
    .right-col, #a4-canvas, .a4-paper {
        width: 100% !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        box-shadow: none !important;
        background: transparent !important;
    }

    /* Настраиваем физические поля для принтера */
    @page {
        size: A4;
        margin: 25mm 30mm 25mm 25mm; /* Те самые отступы! */
    }

    /* Запрещаем разрывать блок с репликой персонажа посередине */
    .doc-block { page-break-inside: avoid; }
}

/* Режим разрезанных листов */
#a4-canvas.paged-view .a4-paper {
    background-image: none; /* Убираем линию */
    background-color: transparent;
    box-shadow: none;
}

#a4-canvas.paged-view .doc-block {
    /* Блоки сами формируют "листы" за счет теней */
    background: #fff;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    padding: 20px;
    margin-bottom: 40px; /* Дырка между кусками текста */
}

.node-spline {
    transition: stroke 0.15s ease;
    pointer-events: stroke; /* Важно: реагируем только на саму линию */
}

.node-spline:hover {
    stroke: rgba(255,255,255,0.15) !important;
}

.block-time { 
    position: absolute;
    top: 8px;
    right: 10px;
    font-size: 10px; 
    font-family: monospace;
    font-weight: bold; 
    color: #ffcc00; /* Голливудский желтый */
    background: rgba(0, 0, 0, 0.4); 
    padding: 2px 5px; 
    border-radius: 4px; 
    pointer-events: none;
}

.tl-block, .node-group-header {
    background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.35)) !important;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1); /* Легкий блик сверху */
}
/* ═══════════════════════════════════════════════════════
   MODULE PORT — нижняя центральная точка сценарной ноды
═══════════════════════════════════════════════════════ */
.port-module-add {
    top: auto !important;
    bottom: -15px !important;
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%) !important;
    width: 26px;
    height: 26px;
    cursor: pointer;
}
.port-module-add::after {
    background: #555;
    width: 10px;
    height: 10px;
}
.port-module-add:hover::after {
    background: #fff;
    box-shadow: 0 0 6px rgba(255,255,255,0.6);
}

/* ═══════════════════════════════════════════════════════
   МОДУЛЬНЫЕ БЛОКИ на холсте (отдельные ноды под сценой)
═══════════════════════════════════════════════════════ */
.tl-module {
    position: absolute;
    width: 200px;
    min-height: 58px;
    border-radius: 6px;
    border: 1.5px solid rgba(255,255,255,0.1);
    color: #ccc;
    padding: 7px 10px 8px;
    cursor: grab;
    pointer-events: auto;
    font-size: 11px;
    line-height: 1.35;
    background-image: linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5));
    z-index: 10;
    user-select: none;
}
.tl-module.tl-module-dialog {
    border-color: rgba(49,130,206,0.45);
    background-color: rgba(16,32,58,0.95);
}
.tl-module.tl-module-action {
    border-color: rgba(56,161,105,0.45);
    background-color: rgba(16,42,28,0.95);
}

/* ── Страница А4: типы модулей ── */
.tl-module.tl-module-title {
    border-color: rgba(214,158,46,0.55);
    background-color: rgba(40,28,8,0.95);
}
.tl-module.tl-module-about {
    border-color: rgba(214,158,46,0.35);
    background-color: rgba(36,26,8,0.95);
}
.tl-module.tl-module-freetext {
    border-color: rgba(160,140,100,0.35);
    background-color: rgba(28,26,20,0.95);
}
.tl-module.tl-module-date,
.tl-module.tl-module-copyright {
    border-color: rgba(130,130,160,0.35);
    background-color: rgba(20,20,32,0.95);
}
.tl-module.active {
    border-color: #fff !important;
    box-shadow: 0 0 12px rgba(255,255,255,0.25);
}

.node-mod-header {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 10px;
    font-weight: 700;
    color: #888;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
}
.mod-ic  { font-size: 11px; flex-shrink: 0; }
.mod-char { color: #ddd; text-transform: uppercase; font-size: 10px; }
.mod-emotion { color: #666; font-style: italic; font-size: 10px; font-weight: 400; }
.node-mod-line {
    font-size: 10px;
    color: #777;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-style: italic;
}
.node-mod-del {
    margin-left: auto;
    background: none;
    border: none;
    color: #444;
    cursor: pointer;
    font-size: 13px;
    padding: 0 2px;
    line-height: 1;
    flex-shrink: 0;
    transition: color 0.15s;
}
.node-mod-del:hover { color: #ff6b6b; }

/* ═══════════════════════════════════════════════════════
   А4 — МОДУЛИ ДИАЛОГА И ДЕЙСТВИЯ
═══════════════════════════════════════════════════════ */
.doc-module {
    margin: 10px 0 6px 0;
    position: relative;
}

/* Диалог: стандартный сценарный формат (всё по центру) */
.doc-module-dialog {
    padding: 0 120px;  /* было 80px, увеличили чтобы реплика была уже */
    text-align: center;
}
.mod-a4-character {
    display: block;
    width: 100%;
    text-align: center;
    font-weight: bold;
    text-transform: uppercase;
    font-size: 13px;
    letter-spacing: 1px;
    outline: none;
    padding: 2px 4px;
    border-radius: 3px;
    border: 1px solid transparent;
    background: transparent;
    font-family: 'Courier New', monospace;
    color: #111;
    transition: background 0.15s, border-color 0.15s;
}
.mod-a4-character:focus {
    background: rgba(24,95,165,0.07);
    border-color: rgba(55,138,221,0.35);
}
.mod-a4-emotion {
    display: block;
    width: 100%;
    text-align: center;
    font-style: italic;
    font-size: 12px;
    color: #555;
    outline: none;
    padding: 1px 4px;
    border-radius: 3px;
    border: 1px solid transparent;
    background: transparent;
    font-family: 'Courier New', monospace;
    transition: background 0.15s, border-color 0.15s;
}
.mod-a4-emotion:focus {
    background: rgba(24,95,165,0.07);
    border-color: rgba(55,138,221,0.35);
}
.mod-a4-line {
    display: block;
    width: 100%;
    text-align: center;
    font-size: 13px;
    line-height: 1.65;
    outline: none;
    padding: 4px;
    border-radius: 3px;
    border: 1px solid transparent;
    white-space: pre-wrap;
    background: transparent;
    font-family: 'Courier New', monospace;
    color: #111;
    transition: background 0.15s, border-color 0.15s;
}
.mod-a4-line:focus {
    background: rgba(24,95,165,0.07);
    border-color: rgba(55,138,221,0.35);
}

/* Действие: полная ширина, как обычный абзац */
.doc-module-action {
    margin-top: 8px;  /* отступ от реплики выше */
}
.mod-a4-action {
    display: block;
    width: 100%;
    font-size: 13px;
    line-height: 1.6;
    outline: none;
    padding: 4px 6px;
    border-radius: 3px;
    border: 1px solid transparent;
    white-space: pre-wrap;
    background: transparent;
    font-family: 'Courier New', monospace;
    color: #222;
    transition: background 0.15s, border-color 0.15s;
}
.mod-a4-action:focus {
    background: rgba(24,95,165,0.07);
    border-color: rgba(55,138,221,0.35);
}

/* Кнопка удаления модуля (появляется при hover) */
.mod-a4-del {
    position: absolute;
    top: 2px;
    right: -22px;
    background: none;
    border: none;
    color: #bbb;
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
    padding: 2px 4px;
}
.doc-module:hover .mod-a4-del { opacity: 1; }
.mod-a4-del:hover { color: #ff6b6b; }

/* Меню добавления модуля */
.module-add-menu { font-family: var(--font-sans); }

/* ⚡ ФИКС: Элегантное обрезание текста (Троеточие) на холсте */

/* 1. Заголовок самой ноды (чтобы не становился 2-3 строчным) */
.block-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    display: block;
}

/* 2. Шапка модуля (чтобы Имя и Эмоция не вылезали за края) */
.node-mod-header {
    display: flex;
    align-items: center;
    width: 100%;
    overflow: hidden;
    padding-right: 18px; /* Оставляем защитную зону для крестика удаления */
    box-sizing: border-box;
}

/* Имя персонажа */
.mod-char {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 50%; /* Ограничиваем имя, чтобы осталось место для эмоции */
    flex-shrink: 0;
}

/* Эмоция (сжимается и обрезается первой) */
.mod-emotion {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0; /* ⚡ Обязательно для работы ellipsis внутри flex-контейнера */
}

/* 3. Текст реплики или действия внутри модуля */
.node-mod-line {
    display: -webkit-box;
    -webkit-line-clamp: 1; /* Строго 1 строка текста */
    -webkit-box-orient: vertical;
    overflow: hidden; /* Прячем всё, что не влезло (включая переносы от Enter) */
    word-break: break-word; /* Аккуратно рвем длинные слова */
    width: 100%;
    box-sizing: border-box;
    
    /* ⚡ ГЛАВНЫЙ ФИКС: Жесткий физический барьер высоты */
    max-height: 1.2em; 
    line-height: 1.2em; 
    white-space: normal !important; /* Сбрасываем любые случайные переносы */
}
.context-menu-item.menu-item-disabled { opacity: 0.35; cursor: default !important; pointer-events: none; }

/* ⚡ Служебный хром не должен выделяться как текст */
.node-workspace, .imgcanvas-toolbar, .player-toolbar,
.imgcanvas-timeline, .canvas-header, #video-workspace .vid-bar {
    user-select: none;
    -webkit-user-select: none;
}

/* ⚡ Запрет выделения текста на А4-холсте вне редактируемых полей.
   Выделение работает только внутри contenteditable (при наборе текста). */
#a4-canvas {
    user-select: none;
    -webkit-user-select: none;
}
#a4-canvas [contenteditable="true"] {
    user-select: text;
    -webkit-user-select: text;
    cursor: text;
}

/* =====================================================================
   ⚡ АНКЕТА ПЕРСОНАЖА (characterProfile.js)
   ===================================================================== */

#char-profile-overlay {
    position: fixed;
    inset: 0;
    z-index: 10001;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.cp-modal {
    background: #161b27;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 16px;
    width: 660px;
    max-width: calc(100vw - 32px);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 24px 80px rgba(0,0,0,0.7);
    font-family: sans-serif;
}

/* ── Шапка ── */
.cp-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px 20px 16px;
    flex-shrink: 0;
}
.cp-avatar {
    width: 52px; height: 52px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px; font-weight: 700;
    font-family: 'Courier New', monospace;
    flex-shrink: 0;
}
.cp-header-info { flex: 1; min-width: 0; }
.cp-name {
    font-family: 'Courier New', monospace;
    font-size: 18px; font-weight: 700;
    letter-spacing: 1px;
    margin-bottom: 8px;
}
.cp-meta-row {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.cp-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    align-self: flex-start;
    flex-shrink: 0;
}

.cp-merge-btn {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.5);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 7px;
    white-space: nowrap;
    transition: color .15s, background .15s, border-color .15s;
    font-family: inherit;
}
.cp-merge-btn:hover {
    color: #c4b5fd;
    background: rgba(139,92,246,0.15);
    border-color: rgba(139,92,246,0.4);
}

.cp-close {
    background: none; border: none;
    color: rgba(255,255,255,0.35);
    font-size: 20px; cursor: pointer;
    padding: 4px 8px; border-radius: 6px;
    align-self: flex-start;
    transition: color .15s, background .15s;
}
.cp-close:hover { color: #fff; background: rgba(255,255,255,0.08); }

/* Пол */
.cp-gender-group { display: flex; gap: 4px; }
.cp-gender-btn {
    display: flex; align-items: center; justify-content: center;
    width: 32px; height: 28px;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    color: rgba(255,255,255,0.45);
    transition: all .15s;
}
.cp-gender-btn input { display: none; }
.cp-gender-btn:hover { border-color: rgba(255,255,255,0.4); color: #fff; }

/* Инпуты */
.cp-input {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 6px;
    color: #e2e8f0;
    font-size: 12px;
    padding: 5px 10px;
    outline: none;
    transition: border-color .15s;
}
.cp-input:focus { border-color: rgba(255,255,255,0.35); }
.cp-age { width: 80px; }
.cp-select {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 6px;
    color: #e2e8f0;
    font-size: 12px;
    padding: 5px 8px;
    outline: none;
    cursor: pointer;
}
.cp-select:focus { border-color: rgba(255,255,255,0.35); }

/* ── Тело ── */
.cp-body {
    flex: 1;
    overflow-y: auto;
    padding: 0 20px 20px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.cp-section {
    margin-top: 16px;
}
.cp-section-row { display: flex; gap: 12px; }
.cp-half { flex: 1; min-width: 0; }
.cp-section-label {
    font-size: 10px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: rgba(255,255,255,0.28);
    margin-bottom: 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}
.cp-textarea {
    width: 100%;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    color: #e2e8f0;
    font-size: 13px;
    font-family: sans-serif;
    padding: 10px 12px;
    resize: none;
    outline: none;
    line-height: 1.5;
    transition: border-color .15s;
    box-sizing: border-box;
}
.cp-textarea:focus { border-color: rgba(255,255,255,0.3); }

/* Черты */
.cp-traits-wrap {}
.cp-traits { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; min-height: 28px; }
.cp-trait-chip {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 8px 3px 10px;
    border: 1px solid; border-radius: 20px;
    font-size: 12px;
}
.cp-trait-add-row { }
.cp-trait-input { width: 200px; }

/* Чип-кнопка удаления */
.cp-chip-del {
    background: none; border: none;
    font-size: 10px; cursor: pointer;
    opacity: .5; padding: 0 2px;
    color: inherit; line-height: 1;
}
.cp-chip-del:hover { opacity: 1; }

/* Взаимоотношения */
.cp-relations { display: flex; flex-direction: column; gap: 10px; }
.cp-rel-block { display: flex; flex-direction: column; gap: 4px; }
.cp-rel-label {
    font-size: 11px; font-weight: 600;
    margin-bottom: 2px;
}
/* Чипы появляются только когда есть контент — no min-height */
.cp-rel-chips {
    display: flex; flex-wrap: wrap; gap: 6px;
}
.cp-rel-chips:empty { display: none; }
.cp-rel-chip {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 8px 3px 10px;
    border: 1px solid; border-radius: 20px;
    font-size: 12px;
    font-family: 'Courier New', monospace;
}
.cp-rel-empty { font-size: 11px; color: rgba(255,255,255,0.25); }
.cp-rel-select { font-size: 11px; }

/* ── Кнопка анкеты на чипе аналитики ── */
.an-chip-profile {
    display: inline-flex;
    align-items: center;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 11px;
    padding: 0 2px 0 4px;
    opacity: 0;
    transition: opacity .15s;
    vertical-align: middle;
    line-height: 1;
    color: inherit;
}
.an-chip:hover .an-chip-profile { opacity: 0.7; }
.an-chip-profile:hover { opacity: 1 !important; }

/* ⚡ Фикс: читаемый текст в нативных select-дропдаунах анкеты персонажа */
.cp-select,
.cp-select option {
    background: #1e2535;
    color: #e2e8f0;
}
.cp-rel-select option { color: #e2e8f0; background: #1e2535; }

/* ── Фото персонажа ── */
.cp-avatar-wrap {
    position: relative;
    width: 64px; height: 64px;
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
    overflow: hidden;
    border: 2px solid rgba(255,255,255,0.1);
    transition: border-color .2s;
}
.cp-avatar-wrap:hover { border-color: rgba(255,255,255,0.35); }
.cp-avatar-wrap:hover .cp-avatar-overlay { opacity: 1; }

.cp-avatar-img {
    width: 100%; height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}
.cp-avatar-placeholder {
    width: 100%; height: 100%;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 26px; font-weight: 700;
    font-family: 'Courier New', monospace;
    /* Переопределяем размеры от .cp-avatar чтобы не конфликтовало */
    min-width: unset; min-height: unset;
    flex-shrink: unset;
}
/* Внутри обёртки .cp-avatar не должен иметь фиксированный размер */
.cp-avatar-wrap .cp-avatar {
    width: 100%; height: 100%; font-size: 26px;
}
.cp-avatar-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.5);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    opacity: 0;
    transition: opacity .2s;
}
/* Старый .cp-avatar (без обёртки) — оставляем для совместимости */
.cp-avatar {
    width: 52px; height: 52px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px; font-weight: 700;
    font-family: 'Courier New', monospace;
    flex-shrink: 0;
}

/* ── Навигация между персонажами ── */
.cp-nav {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    margin-right: 8px;
}
.cp-nav-btn {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.12);
    color: #e2e8f0;
    border-radius: 7px;
    width: 30px; height: 30px;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    transition: background .15s, opacity .15s;
    display: flex; align-items: center; justify-content: center;
}
.cp-nav-btn:hover:not(:disabled) { background: rgba(255,255,255,0.14); }
.cp-nav-btn:disabled { opacity: 0.25; cursor: default; }
.cp-nav-pos {
    font-size: 11px;
    color: rgba(255,255,255,0.35);
    white-space: nowrap;
    min-width: 32px;
    text-align: center;
    font-family: sans-serif;
}

/* ── Двухколоночный макет анкеты ── */
.cp-modal {
    /* Переопределяем ширину и направление */
    width: 860px !important;
    flex-direction: row !important;
    max-height: 88vh !important;
}

/* ── Сайдбар ── */
.cp-sidebar {
    width: 168px;
    flex-shrink: 0;
    background: rgba(0,0,0,0.2);
    border-right: 1px solid rgba(255,255,255,0.07);
    overflow-y: auto;
    padding: 12px 8px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.08) transparent;
}
.cp-sidebar-group-label {
    font-size: 9px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: rgba(255,255,255,0.22);
    padding: 0 6px 6px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    margin-bottom: 4px;
}
.cp-sidebar-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 8px;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: background .15s;
    margin-bottom: 2px;
}
.cp-sidebar-item:hover { background: rgba(255,255,255,0.06); }
.cp-sidebar-item.active { cursor: default; }
.cp-sidebar-avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700;
    font-family: 'Courier New', monospace;
    flex-shrink: 0;
    overflow: hidden;
}
.cp-sidebar-name {
    font-size: 11px;
    font-family: 'Courier New', monospace;
    color: rgba(255,255,255,0.55);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 600;
    letter-spacing: 0.5px;
}
.cp-sidebar-item.active .cp-sidebar-name { font-weight: 700; }

/* ── Основной контент ── */
.cp-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
/* ── Рамка эпизода при печати ───────────────────────────────── */
@media print {
    .doc-episode-wrapper {
        border-color: #333 !important;
        page-break-inside: auto;
        break-inside: auto;
    }

    .doc-episode-header-tab {
        background: #333 !important;
        color: #fff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

/* ════════════════════════════════════════════════════════════
   ЕДИНЫЙ ДРОПДАУН — .ui-dropdown / .ui-dropdown-item
   Используй для ВСЕХ всплывающих списков в проекте.
   ════════════════════════════════════════════════════════════ */

.ui-dropdown {
    position: fixed;
    z-index: 9999;
    background: var(--ui-bg-deep);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius);
    box-shadow: var(--ui-shadow);
    padding: 4px;
    min-width: 160px;
    overflow: hidden;
    font-family: var(--ui-font);
    font-size: 13px;
    color: var(--ui-text);
}

/* Вариант с прокруткой (для длинных списков) */
.ui-dropdown.scrollable {
    max-height: 280px;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Разделитель внутри дропдауна */
.ui-dropdown-sep {
    height: 1px;
    background: var(--ui-border);
    margin: 4px 0;
}

/* Поле поиска внутри дропдауна */
.ui-dropdown-search {
    width: 100%;
    box-sizing: border-box;
    padding: 5px 8px;
    margin-bottom: 4px;
    background: var(--ui-bg-input);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-sm);
    color: var(--ui-text);
    font-size: 11px;
    font-family: var(--ui-font);
    outline: none;
    transition: border-color 0.15s;
}
.ui-dropdown-search:focus { border-color: var(--ui-border-focus); }

/* Строка-пункт */
.ui-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: var(--ui-radius-sm);
    cursor: pointer;
    color: var(--ui-text);
    font-size: 12px;
    transition: background 0.1s;
    white-space: nowrap;
    user-select: none;
}
.ui-dropdown-item:hover,
.ui-dropdown-item.active {
    background: rgba(255, 255, 255, 0.07);
    color: #fff;
}
.ui-dropdown-item.active {
    background: rgba(72, 130, 126, 0.2);
    color: #fff;
}

/* Иконка слева в пункте */
.ui-dropdown-item-icon {
    flex-shrink: 0;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Двухстрочный пункт (label + subtitle) */
.ui-dropdown-item-label { font-weight: 600; line-height: 1.3; }
.ui-dropdown-item-sub   { font-size: 11px; color: var(--ui-text-dim); margin-top: 1px; }

/* Подсказка горячей клавиши справа */
.ui-dropdown-item-hint {
    margin-left: auto;
    font-size: 10px;
    opacity: 0.4;
    font-family: var(--ui-font-mono);
}

/* Пустой результат поиска */
.ui-dropdown-empty {
    padding: 6px 8px;
    font-size: 11px;
    color: var(--ui-text-muted);
}

/* ── char-autocomplete ───────────────────────────────────────
   Автодополнение имени персонажа (a4Utils.js)              */
.char-autocomplete {
    position: fixed;
    z-index: 9999;
    background: var(--ui-bg-deep);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius);
    box-shadow: var(--ui-shadow);
    padding: 4px;
    min-width: 180px;
    overflow: hidden;
    font-family: var(--ui-font);
}

.char-ac-item {
    padding: 6px 10px;
    border-radius: var(--ui-radius-sm);
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: background 0.1s;
    white-space: nowrap;
}
.char-ac-item:hover,
.char-ac-item.active {
    background: rgba(72, 130, 126, 0.2);
}

/* ── heading-autocomplete ───────────────────────────────────
   Автодополнение заголовка сцены — стили перенесены
   из a4Renderer.css (там оставлены как алиасы)             */
.heading-autocomplete {
    position: fixed;
    z-index: 9999;
    background: var(--ui-bg-deep);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius);
    box-shadow: var(--ui-shadow);
    padding: 4px 0;
    min-width: 180px;
    max-width: 320px;
    overflow: hidden;
}

.hac-row {
    padding: 5px 12px;
    font-family: var(--ui-font-mono);
    font-size: 11px;
    color: var(--ui-text);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-radius: var(--ui-radius-sm);
    transition: background 0.1s;
}
.hac-row:hover,
.hac-row.active {
    background: rgba(72, 130, 126, 0.2);
    color: #fff;
}

/* ── Biblia: sidebar role group label / drop zone ─────────────── */
.pb-sidebar-group-label {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--ui-text-muted);
    padding: 8px 10px 4px;
    user-select: none;
    transition: background 0.15s, color 0.15s;
}
.pb-sidebar-group-label.pb-drop-hover {
    background: rgba(72,130,126,0.15);
    color: var(--ui-accent);
    border-radius: var(--ui-radius-sm);
}

/* Drag handle in sidebar item */
.pb-si-drag-handle {
    font-size: 13px;
    color: var(--ui-text-muted);
    cursor: grab;
    margin-right: 2px;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.15s;
}
.pb-sidebar-item:hover .pb-si-drag-handle { opacity: 1; }

/* ── Biblia chars: role group wrapper (drag-and-drop zone) ───────── */
.pb-role-group {
    border-radius: var(--ui-radius-sm);
    transition: background 0.15s;
    padding-bottom: 2px;
}
.pb-role-group.pb-drop-hover {
    background: rgba(72, 130, 126, 0.1);
    outline: 1px dashed var(--ui-accent);
}
.pb-role-group .pb-sidebar-group-label {
    cursor: default;
    padding: 7px 10px 4px;
}

/* ⚡ Подсветка провода при наведении ноды (вставка между нодами) */
.node-spline.wire-insert-target {
    stroke: rgba(135, 184, 196, 0.45) !important;
    cursor: alias !important;
}

/* ⚡ Категории в подменю создания нод (стиль группировки как в node-редакторах) */
.context-menu-category {
    padding: 7px 12px 3px;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255,255,255,0.32);
    pointer-events: none;
    user-select: none;
}
.context-menu .submenu .context-menu-category:first-child { padding-top: 6px; }
.context-menu-separator {
    height: 1px;
    margin: 4px 8px;
    background: rgba(255,255,255,0.08);
}

/* ⚡ Контекст из Библии в карточке ИИ-агента: чипы + ручное прикрепление */
.ai-bible-context { padding: 6px 2px 0; display: flex; flex-direction: column; gap: 6px; }
.ai-bible-tip { font-size: 9px; line-height: 1.4; color: rgba(255,255,255,0.35); }
.ai-bible-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.ai-bible-chip {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 6px 2px 2px; border-radius: 11px;
    background: rgba(135,184,196,0.12); border: 1px solid rgba(135,184,196,0.3);
    font-size: 10px; color: #cfe6ec; max-width: 100%;
}
.ai-bible-chip.manual { background: rgba(226,184,92,0.12); border-color: rgba(226,184,92,0.35); color: #f0dcae; }
.ai-chip-av {
    width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0;
    background-size: cover; background-position: center; background-repeat: no-repeat;
}
.ai-chip-av.ph {
    display: flex; align-items: center; justify-content: center;
    background: rgba(255,255,255,0.15); font-size: 8px; font-weight: 700; color: #fff;
}
.ai-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 120px; }
.ai-chip-n {
    background: rgba(0,0,0,0.3); border-radius: 8px; padding: 0 5px;
    font-size: 8px; font-weight: 700; flex-shrink: 0;
}
.ai-chip-x { cursor: pointer; opacity: 0.6; font-weight: 700; padding: 0 2px; }
.ai-chip-x:hover { opacity: 1; }
.ai-bible-add {
    align-self: flex-start; padding: 3px 10px; border-radius: 6px;
    border: 1px dashed rgba(255,255,255,0.2); background: transparent;
    color: rgba(255,255,255,0.5); cursor: pointer; font-family: inherit;
    font-size: 10px; font-weight: 700;
}
.ai-bible-add:hover { border-color: var(--ui-accent,#87b8c4); color: var(--ui-accent,#87b8c4); }

/* Меню выбора сущностей для прикрепления */
.ai-bible-attach-menu {
    position: fixed; z-index: 9500; min-width: 220px; max-height: 340px; overflow-y: auto;
    background: var(--ui-bg-deep,#15151a); border: 1px solid rgba(255,255,255,0.12);
    border-radius: 10px; padding: 6px; box-shadow: 0 16px 40px rgba(0,0,0,0.55);
    font-family: 'Manrope', sans-serif;
}
.ai-bam-cat {
    padding: 6px 8px 3px; font-size: 9px; font-weight: 800; letter-spacing: 0.06em;
    text-transform: uppercase; color: rgba(255,255,255,0.3);
}
.ai-bam-item {
    display: flex; align-items: center; gap: 8px; padding: 6px 8px;
    border-radius: 6px; cursor: pointer; font-size: 12px; color: #ededf0;
}
.ai-bam-item:hover { background: rgba(255,255,255,0.07); }
.ai-bam-item.on { background: rgba(135,184,196,0.1); }
.ai-bam-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-bam-check { color: var(--ui-accent,#87b8c4); font-weight: 700; width: 12px; }
.ai-bam-empty { padding: 14px 10px; font-size: 11px; color: rgba(255,255,255,0.4); text-align: center; }

/* ⚡ Строка фильтра в подменю создания нод */
.context-menu-filter { padding: 4px 6px 6px; }
.context-menu-filter input {
    width: 100%; box-sizing: border-box; padding: 6px 9px;
    border-radius: 6px; border: 1px solid rgba(255,255,255,0.12);
    background: rgba(255,255,255,0.05); color: #ededf0;
    font-family: inherit; font-size: 12px; outline: none;
}
.context-menu-filter input:focus { border-color: var(--ui-accent,#87b8c4); }

/* ⚡ D-2: бейдж оценки/фактической стоимости генерации видео */
.vai-price-badge { font-size: 11px; color: var(--text-dim, #8a8a9a); text-align: center; min-height: 14px; margin: -4px 0 4px; }

/* ⚡ Фикс №3 (Денис): плиточная сетка референсов — витрина, не picker */
.vai-ref-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; margin: 4px 0; }
.vai-ref-tile { position: relative; border-radius: 4px; overflow: hidden; border: 1px solid #333; }
.vai-ref-tile img { width: 100%; height: 64px; object-fit: cover; display: block; }
.vai-ref-tile-cap { font-size: 9px; padding: 2px 4px; opacity: 0.7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* ⚡ Баг «5 рефов → 3 плитки»: подключение без кадра — честная заглушка, не молчаливое выпадение */
.vai-ref-tile.noimg { border-style: dashed; opacity: 0.75; }
.vai-ref-tile-ph { height: 64px; display: flex; align-items: center; justify-content: center; font-size: 9px; color: var(--text-dim, #8a8a9a); text-align: center; padding: 0 4px; }
.vai-ref-count { font-weight: 600; }
/* ⚡ п.3: заметка нейросети на реф-плитке — кнопка на hover, точка-индикатор, компактный попап */
.vai-ref-tile { position: relative; }
.vai-ref-note-btn { position: absolute; top: 3px; right: 3px; width: 18px; height: 18px; display: none;
    align-items: center; justify-content: center; border: none; border-radius: 4px; cursor: pointer;
    background: rgba(10,10,14,0.75); color: var(--accent, #87b8c4); padding: 0; }
.vai-ref-tile:hover .vai-ref-note-btn { display: inline-flex; }
.vai-ref-note-btn.has { display: inline-flex; }
.vai-ref-note-btn.has::after { content: ''; position: absolute; top: -2px; right: -2px; width: 6px; height: 6px;
    border-radius: 50%; background: var(--accent, #87b8c4); }
.vai-ref-note-pop { position: fixed; z-index: 99999; width: 240px;
    background: rgba(28,28,30,0.95); backdrop-filter: blur(12px);
    border: 1px solid var(--border, rgba(255,255,255,0.08)); border-radius: 8px; padding: 8px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.6), 0 0 0 1px rgba(0,0,0,0.2); }
.vai-ref-note-head { font-size: 10px; font-weight: 700; letter-spacing: 0.04em; opacity: 0.8;
    margin-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vai-ref-note-pop textarea { width: 100%; resize: vertical; font-size: 11px; background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1); border-radius: 4px; color: inherit; padding: 5px 6px; box-sizing: border-box; }
.vai-ref-note-row { display: flex; gap: 6px; margin-top: 5px; }
.vai-ref-note-row button { flex: 1; font-size: 10px; padding: 4px 6px; border-radius: 4px; border: none; cursor: pointer;
    background: var(--accent, #87b8c4); color: #10131a; font-weight: 700; }
.vai-ref-note-row button.ghost { background: rgba(255,255,255,0.08); color: inherit; font-weight: 500; }
/* ⚡ Drag ноды: глушим выделение текста и текстовую каретку ВЕЗДЕ (заголовки
   нод несут свои cursor:text/user-select — инлайн-стиль body их не перебивает) */
body.node-dragging, body.node-dragging * { user-select: none !important; cursor: grabbing !important; }

/* ⚡ D-3: бейдж цены (доллары) перед кнопками генерации image-ноды */
.aig-price-badge { display: inline-flex; align-items: center; gap: 2px; font-size: 10px; color: var(--text-dim, #8a8a9a); margin-right: 6px; }
.aig-price-badge .aig-price-ic { opacity: 0.7; }

/* ⚡ SVG-иконки цены (не эмодзи) — общий стиль для бейджей D-1/D-2/D-3 */
.vai-price-badge { display: inline-flex; align-items: center; justify-content: center; gap: 4px; font-size: 11px; color: var(--text-dim, #8a8a9a); min-height: 16px; margin: -4px 0 4px; }
.vai-price-ic, .aig-price-ic, .nrb-price-ic { display: inline-flex; opacity: 0.75; }
.vai-price-ic svg, .aig-price-ic svg, .nrb-price-ic svg { display: block; }
.nrb-price { display: inline-flex; align-items: center; gap: 3px; margin-left: 6px; font-size: 11px; opacity: 0.85; }

/* ═══ v055.1: ЖУРНАЛ ГЕНЕРАЦИЙ — ЛЕВЫЙ ДОК ═══════════════════════════════
   Панель живёт ВНУТРИ .node-workspace (position:relative, overflow:hidden),
   поэтому прижимается к её левому краю и обрезается вместе с ней. Снизу
   останавливается выше зум-контрола (#graph-zoom-control: bottom 14px, h 28px).
   ════════════════════════════════════════════════════════════════════════ */
/* Кнопка живёт в рабочей области, в одном стилистическом ряду с
   #graph-zoom-control (те же 14px от края, фон, скругление, blur).
   Правило `.label-row { display:flex }` убрано: этот класс используется и
   другими шапками, и журнал не должен менять их вёрстку ради себя. */
.gj-btn {
    position: absolute; left: 14px; top: 14px; z-index: 46;
    width: 30px; height: 30px; padding: 0;
    display: inline-flex; align-items: center; justify-content: center;
    background: rgba(20,20,24,0.85); border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px; backdrop-filter: blur(6px);
    color: rgba(255,255,255,0.55); cursor: pointer;
    transition: background 0.14s, color 0.14s,
                transform 0.22s cubic-bezier(0.22, 0.61, 0.36, 1);
}
.gj-btn:hover { background: rgba(38,38,44,0.92); color: rgba(255,255,255,0.95); }
/* ⚡ v058: кнопка НЕ ДВИГАЕТСЯ при открытии. Раньше она отъезжала на ширину
   дока — и указатель, только что по ней кликнувший, оказывался над пустотой:
   чтобы закрыть, приходилось вести мышь через всю панель. Теперь панель
   выпадает ИЗ-ПОД кнопки, а кнопка остаётся точкой возврата на месте клика.
   Открытое состояние показывается подсветкой, а не перемещением. */
.gj-btn.shifted { color: #fff; border-color: rgba(255,255,255,0.22); background: rgba(38,38,44,0.94); }

.gj-dock {
    /* ⚡ v058: top под кнопкой (14px отступ + 30px кнопка + 8px зазор), а не 0 —
       панель раскрывается из-под неё, кнопка остаётся видимой и кликабельной. */
    position: absolute; left: 0; top: 52px; bottom: 52px; width: 264px; z-index: 45;
    border-radius: 0 10px 10px 0;
    display: flex; flex-direction: column;
    background: rgba(17,18,22,0.93); backdrop-filter: blur(10px);
    border-right: 1px solid rgba(255,255,255,0.09);
    color: #e8e8ea; font-size: 12px; font-family: 'Manrope', sans-serif;
    transform: translateY(-8px) scaleY(0.985); transform-origin: top left;
    opacity: 0; pointer-events: none;
    transition: transform 0.19s cubic-bezier(0.22, 0.61, 0.36, 1), opacity 0.16s;
}
.gj-dock.open { transform: translateY(0) scaleY(1); opacity: 1; pointer-events: auto; }

.gj-head { display: flex; align-items: center; padding: 12px 12px 10px; }
.gj-title { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; opacity: 0.5; }
.gj-close { margin-left: auto; background: none; border: 0; color: rgba(255,255,255,0.4); font-size: 17px; cursor: pointer; line-height: 1; padding: 0 2px; }
.gj-close:hover { color: #fff; }

.gj-tabs { display: flex; gap: 3px; padding: 0 10px 9px; }
.gj-tab {
    flex: 1; padding: 5px 2px; border-radius: 5px; cursor: pointer; white-space: nowrap;
    background: transparent; border: 1px solid transparent; color: rgba(255,255,255,0.45);
    font-family: inherit; font-size: 9px; letter-spacing: 0.05em;
}
.gj-tab:hover { background: rgba(255,255,255,0.06); }
.gj-tab.active { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.15); color: #fff; }
.gj-count { margin-left: 4px; opacity: 0.45; }

.gj-body { overflow-y: auto; padding: 4px 6px; flex: 1 1 auto; }
.gj-body::-webkit-scrollbar { width: 6px; }
.gj-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.13); border-radius: 3px; }

/* Узкий док: миниатюра слева, две строки текста, цена и время под именем. */
.gj-row { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px; }
.gj-row:hover { background: rgba(255,255,255,0.06); }
.gj-dead { opacity: 0.4; }
.gj-thumb {
    width: 44px; height: 28px; flex: 0 0 44px; border-radius: 4px; overflow: hidden;
    background: rgba(255,255,255,0.07); display: flex; align-items: center; justify-content: center;
    color: rgba(255,255,255,0.3); font-size: 11px;
}
.gj-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gj-main { flex: 1 1 auto; min-width: 0; }
.gj-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 11.5px; }
.gj-sub { font-size: 9.5px; opacity: 0.42; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.gj-right { text-align: right; flex: 0 0 auto; }
.gj-cost { font-size: 11px; font-variant-numeric: tabular-nums; }
.gj-cost-unknown { opacity: 0.3; }
.gj-time { font-size: 9.5px; opacity: 0.35; margin-top: 1px; font-variant-numeric: tabular-nums; }

.gj-empty { padding: 34px 12px; text-align: center; opacity: 0.35; font-size: 11px; }
.gj-foot { padding: 8px 12px; border-top: 1px solid rgba(255,255,255,0.07); text-align: right; opacity: 0.65; font-size: 11px; font-variant-numeric: tabular-nums; }
