/* budget.css — Стили для нового бюджета (budget.js).
 *
 * Подключи этот файл после projectInfo.css. Использует те же CSS-переменные
 * (--ui-bg-input, --ui-border, --ui-accent, --ui-radius-sm, --ui-text-muted,
 * --ui-text-dim, --ui-font-mono), что и основная тема.
 *
 * Старые классы (pi-budget-summary, pi-summary-card, pi-budget-params,
 * pi-rates-grid, pi-rate-*, pi-pct-input, pi-field, pi-input, pi-btn) —
 * переиспользуются как есть, здесь не дублируются.
 */

/* ─── Контейнер новой вкладки ──────────────────────────────────── */
.pi-budget-v2 .pi-budget-section {
    margin-top: 22px;
}

/* ─── Верхняя панель: шаблон / валюта / налог / резерв ─────────── */
.pi-budget-top {
    display: flex;
    flex-wrap: wrap; /* Магия: разрешаем перенос на новую строку */
    gap: 16px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-sm);
    margin-bottom: 20px;
    align-items: flex-end; /* Выравнивание всех элементов по нижней границе */
}

/* Базовый сброс для полей */
.pi-budget-top .pi-field {
    margin: 0 !important;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

/* Раздаем пропорции: flex: [grow] [shrink] [basis]
  grow - тянуться ли, shrink - сжиматься ли, basis - идеальный стартовый размер 
*/

/* 1. Шаблон: забирает всё свободное место, но не сжимается меньше 200px */
.pi-budget-top .pi-field:nth-child(1) { 
    flex: 3 1 200px; 
} 

/* 2. Кнопка сохранения: строго свой размер контента */
.pi-budget-top .pi-field:nth-child(2) { 
    flex: 0 0 max-content; 
} 

/* 3. Валюта: тянется, минимально 110px */
.pi-budget-top .pi-field:nth-child(3) { 
    flex: 1 1 110px; 
} 

/* 4 и 5. Налог и резерв: базово 85px. Разрешаем немного тянуться (чтобы не было дыр, если они упадут на отдельную строку), но ограничиваем max-width, чтобы не стали гигантскими */
.pi-budget-top .pi-field:nth-child(4),
.pi-budget-top .pi-field:nth-child(5) { 
    flex: 1 1 85px; 
    max-width: 140px; 
}

/* ─── Переключатель режимов: Клиент / Внутренний / Дельта ──────── */
.pi-budget-modes {
    display: flex;
    gap: 0;
    background: var(--ui-bg-input);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-sm);
    padding: 4px;
    margin-bottom: 18px;
}

.pi-budget-mode {
    flex: 1;
    padding: 10px 14px;
    background: transparent;
    border: none;
    color: var(--ui-text-dim);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border-radius: calc(var(--ui-radius-sm) - 2px);
    transition: background 0.15s, color 0.15s;
}
.pi-budget-mode:hover { color: #fff; }
.pi-budget-mode.active {
    background: var(--ui-accent);
    color: #fff;
}

/* ─── Клиентская панель ────────────────────────────────────────── */
.pi-budget-client {
    padding: 14px;
    background: rgba(135, 184, 196, 0.05);  /* лёгкий бирюзовый отлив */
    border: 1px solid rgba(135, 184, 196, 0.18);
    border-radius: var(--ui-radius-sm);
    margin-bottom: 18px;
}
.pi-budget-client .pi-section-title { margin-top: 0; }
.pi-budget-client .pi-budget-params {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

/* ─── Раскрывающийся заголовок (для блока ставок) ──────────────── */
.pi-collapsible {
    cursor: pointer;
    user-select: none;
    transition: color 0.15s;
}
.pi-collapsible:hover { color: var(--ui-accent); }

/* ─── Таймлайн пропорций ───────────────────────────────────────── */
.pi-tl-bar {
    display: flex;
    height: 80px;
    border-radius: var(--ui-radius-sm);
    overflow: hidden;
    border: 1px solid var(--ui-border);
}

.pi-tl-segment {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 8px 12px;
    color: #fff;
    min-width: 0;
    border-right: 1px solid rgba(0, 0, 0, 0.25);
    transition: filter 0.15s;
}
.pi-tl-segment:last-child { border-right: none; }
.pi-tl-segment:hover { filter: brightness(1.15); }

.pi-tl-label {
    font-size: 10px;
    letter-spacing: 1px;
    text-transform: uppercase;
    opacity: 0.85;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pi-tl-share {
    font-family: var(--ui-font-mono);
    font-size: 16px;
    font-weight: 700;
    margin-top: 2px;
}

.pi-tl-amount {
    font-family: var(--ui-font-mono);
    font-size: 11px;
    opacity: 0.9;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pi-stage-block {
    margin-top: 14px;
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-sm);
    overflow: hidden;
}

.pi-stage-header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 12px 16px !important;
    margin: 0 !important; /* Убиваем старые кривые отрицательные отступы из JS */
    background: rgba(255, 255, 255, 0.03) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05) !important;
    min-height: 48px;
}

/* Жестко фиксируем контейнеры внутри шапки */
.pi-stage-header > span:first-child,
.pi-stage-header > span:last-child {
    display: flex !important;
    align-items: center !important;
}

/* Расстояния: левая группа (чекбокс, точка, название) и правая (сумма, шеврон) */
.pi-stage-header > span:first-child { gap: 12px !important; }
.pi-stage-header > span:last-child { gap: 16px !important; }

/* Чекбокс: жестко центрируем и убираем артефакты baseline */
.pi-stage-check {
    margin: 0 !important;
    padding: 0 !important;
    width: 16px !important;
    height: 16px !important;
    display: block !important; 
    cursor: pointer;
    flex-shrink: 0;
    accent-color: var(--ui-accent, #3182ce);
}

/* Цветной маркер */
.pi-stage-color {
    width: 10px !important; /* Чуть изящнее */
    height: 10px !important;
    border-radius: 50% !important;
    display: block !important;
    flex-shrink: 0;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.2); /* Легкий объем */
}

/* Обёртка названия */
.pi-stage-name-wrap {
    display: flex !important;
    align-items: center !important;
}

/* Название: оптическое выравнивание */
.pi-stage-name {
    font-size: 13px !important;
    font-weight: 700 !important;
    letter-spacing: 0.5px !important;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.95) !important;
    line-height: 1 !important; /* Срезаем невидимую высоту строки */
    margin-top: 1px !important; /* Оптическая компенсация (чтобы казалось ровно по центру кружка) */
}

/* Сумма: оптическое выравнивание */
.pi-stage-sum {
    font-family: var(--ui-font-mono, monospace) !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    color: rgba(255, 255, 255, 0.9) !important;
    line-height: 1 !important;
    margin-top: 2px !important; /* Компенсация моноширинного шрифта */
}

/* ─── Строка позиции ───────────────────────────────────────────── */
.pi-pos-row {
    display: grid;
    grid-template-columns: 24px minmax(160px, 1.7fr) minmax(220px, 1.3fr) 16px minmax(110px, auto) minmax(110px, 0.7fr) 28px;
    gap: 8px;
    align-items: center;
    padding: 6px 14px;
    font-size: 12.5px;
    transition: background 0.1s;
}
.pi-pos-row:hover { background: rgba(255, 255, 255, 0.025); }

.pi-pos-row.pi-pos-dim {
    opacity: 0.45;
}
.pi-pos-row.pi-pos-dim .pi-pos-name-span,
.pi-pos-row.pi-pos-dim .pi-pos-amount {
    text-decoration: line-through;
    text-decoration-color: rgba(255, 255, 255, 0.4);
}

.pi-pos-check {
    accent-color: var(--ui-accent);
    cursor: pointer;
    margin: 0;
    justify-self: center;
}

.pi-pos-name-cell { min-width: 0; }

.pi-pos-name-span,
.pi-pos-name {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.pi-pos-name-span { padding: 4px 0; }

.pi-pos-name {
    width: 100%;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    padding: 4px 6px;
    color: inherit;
    font: inherit;
}
.pi-pos-name:hover  { border-color: var(--ui-border); }
.pi-pos-name:focus  { border-color: var(--ui-accent); background: var(--ui-bg-input); outline: none; }

.pi-pos-calc {
    display: flex;
    gap: 4px;
    align-items: center;
    color: var(--ui-text-dim);
    font-family: var(--ui-font-mono);
    font-size: 12px;
    min-width: 0;
}

.pi-pos-num,
.pi-pos-unit {
    width: auto;
    min-width: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    padding: 3px 5px;
    color: inherit;
    font-family: var(--ui-font-mono);
    font-size: 12px;
    text-align: right;
}
.pi-pos-num { width: 56px; }
.pi-pos-unit { width: 60px; text-align: left; }
.pi-pos-num:hover, .pi-pos-unit:hover { border-color: var(--ui-border); }
.pi-pos-num:focus, .pi-pos-unit:focus { border-color: var(--ui-accent); background: var(--ui-bg-input); outline: none; }

.pi-pos-num-span,
.pi-pos-unit-span {
    color: var(--ui-text-dim);
    font-family: var(--ui-font-mono);
    font-size: 12px;
}
.pi-pos-num-span { display: inline-block; min-width: 24px; text-align: right; }

.pi-pos-mul { color: var(--ui-text-muted); }

.pi-pos-eq {
    color: var(--ui-text-muted);
    font-family: var(--ui-font-mono);
    text-align: center;
}

.pi-pos-amount {
    font-family: var(--ui-font-mono);
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    text-align: right;
    white-space: nowrap;
}

.pi-pos-override-cell { min-width: 0; }

.pi-pos-override {
    width: 100%;
    background: var(--ui-bg-input);
    border: 1px solid transparent;
    border-radius: 4px;
    padding: 4px 8px;
    color: var(--ui-text-dim);
    font-family: var(--ui-font-mono);
    font-size: 11.5px;
    text-align: right;
}
.pi-pos-override:hover { border-color: var(--ui-border); }
.pi-pos-override:focus {
    border-color: #c17c2a;
    background: rgba(193, 124, 42, 0.08);
    color: #fff;
    outline: none;
}
.pi-pos-override:not(:placeholder-shown) {
    color: #c17c2a;
    font-weight: 600;
}

.pi-pos-remove {
    width: 24px;
    height: 24px;
    background: transparent;
    border: 1px solid transparent;
    color: var(--ui-text-muted);
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.15s;
}
.pi-pos-remove:hover {
    background: rgba(194, 90, 90, 0.15);
    border-color: rgba(194, 90, 90, 0.35);
    color: #c25a5a;
}

/* ─── Итоги ────────────────────────────────────────────────────── */
.pi-budget-totals {
    margin-top: 24px;
    padding: 16px 20px;
    background: var(--ui-bg-input);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-sm);
}

.pi-tot-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 6px 0;
    font-size: 13px;
    color: var(--ui-text-dim);
}

.pi-tot-row b {
    font-family: var(--ui-font-mono);
    font-weight: 600;
    color: #fff;
}

.pi-tot-row.pi-tot-faded { opacity: 0.6; }

.pi-tot-row.pi-tot-secondary {
    font-size: 12px;
    border-top: 1px dashed rgba(255, 255, 255, 0.08);
    margin-top: 6px;
    padding-top: 10px;
}

.pi-tot-row.pi-tot-grand {
    border-top: 1px solid var(--ui-border);
    margin-top: 8px;
    padding-top: 14px;
    font-size: 15px;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.pi-tot-row.pi-tot-grand b {
    font-size: 22px;
    color: var(--ui-accent);
}

/* ─── Дельта ───────────────────────────────────────────────────── */
.pi-stage-deltas {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.pi-stage-delta {
    padding: 12px 14px;
    background: var(--ui-bg-input);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-sm);
}

.pi-stage-delta.pi-delta-margin {
    border-color: rgba(74, 124, 89, 0.4);
    background: rgba(74, 124, 89, 0.08);
}
.pi-stage-delta.pi-delta-risk {
    border-color: rgba(194, 90, 90, 0.4);
    background: rgba(194, 90, 90, 0.08);
}

.pi-delta-table {
    margin-top: 12px;
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-sm);
    overflow: hidden;
}

.pi-delta-header {
    display: grid;
    grid-template-columns: 26px 50px 1fr 110px 110px 110px 60px;
    gap: 10px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.04);
    font-size: 10px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--ui-text-muted);
    border-bottom: 1px solid var(--ui-border);
}

.pi-delta-row {
    display: grid;
    grid-template-columns: 26px 50px 1fr 110px 110px 110px 60px;
    gap: 10px;
    padding: 8px 14px;
    align-items: center;
    font-size: 12.5px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.pi-delta-row:last-child { border-bottom: none; }

.pi-delta-row.pi-delta-margin { background: rgba(74, 124, 89, 0.06); }
.pi-delta-row.pi-delta-risk   { background: rgba(194, 90, 90, 0.06); }

.pi-delta-icon { text-align: center; }
.pi-delta-stage {
    font-size: 10px;
    color: var(--ui-text-muted);
    letter-spacing: 1px;
    text-transform: uppercase;
}
.pi-delta-name { color: #fff; }

.pi-delta-num {
    font-family: var(--ui-font-mono);
    text-align: right;
    color: var(--ui-text-dim);
    white-space: nowrap;
}

.pi-delta-bold {
    font-weight: 700;
    color: #fff;
}

.pi-delta-row.pi-delta-margin .pi-delta-bold { color: #6fa67c; }
.pi-delta-row.pi-delta-risk   .pi-delta-bold { color: #d97a7a; }

.pi-delta-pct {
    font-family: var(--ui-font-mono);
    font-size: 11px;
    color: var(--ui-text-muted);
    text-align: right;
}

/* Итог дельты — расцветка по знаку маржи */
.pi-delta-summary .pi-tot-row.pi-tot-grand.pi-delta-margin b { color: #6fa67c; }
.pi-delta-summary .pi-tot-row.pi-tot-grand.pi-delta-risk   b { color: #d97a7a; }


/* ════════════════════════════════════════════════════════════════
   ⚡ NEW v3 — УЛЬТРАКОМПАКТНАЯ ШАПКА БЮДЖЕТА
   ════════════════════════════════════════════════════════════════ */

/* Перебиваем жирные отступы, заданные через JS */
.pi-budget-sticky-header {
    padding: 16px 20px 12px 20px !important;
    margin-bottom: 16px !important;
}

/* Уплотняем табы */
.pi-budget-tabs-bar {
    margin-bottom: 12px !important;
    padding-bottom: 10px;
}

/* Заголовок «Распределение бюджета» */
.pi-bh {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
}

.pi-bh-caption {
    font-size: 9px;
    color: rgba(255,255,255,0.3);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    font-weight: 600;
}

.pi-bh-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    flex-wrap: nowrap; /* ⚡ Запрет на перенос строк — шапка всегда тонкая */
    gap: 12px;
}

/* ── Тонкая текстовая статистика (без фонов) ── */
.pi-bh-stats {
    display: flex;
    gap: 18px; /* Сделали отступы между колонками чуть больше для воздуха */
    align-items: flex-end; /* Выравниваем по нижнему краю */
    background: transparent;
    border: none;
    padding: 0;
    margin: 0;
}

.pi-bh-stat {
    display: flex;
    flex-direction: column; /* ⚡ Ставим текст над цифрой */
    align-items: flex-start;
    gap: 4px; /* Отступ между подписью и значением */
}

.pi-bh-stat-lbl {
    font-size: 8px; /* Уменьшили подпись, как у сумм справа */
    color: rgba(255, 255, 255, 0.3);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0;
    font-weight: 500;
    line-height: 1;
}

/* ⚡ Убираем двоеточие, так как элементы теперь друг под другом */
.pi-bh-stat-lbl::after { 
    display: none; 
}

.pi-bh-stat-val {
    font-size: 13px; /* Сделали цифры чуть крупнее и заметнее */
    font-family: var(--ui-font-mono, monospace);
    font-weight: 500;
    color: rgba(255, 255, 255, 0.7);
    line-height: 1;
}

.pi-bh-info {
    opacity: 0.2;
    font-size: 11px;
    cursor: help;
    align-self: center; /* Центрируем иконку по вертикали */
    margin-left: -6px;
}
.pi-bh-info:hover { opacity: 0.8; }

/* ── Компактные суммы справа ── */
.pi-bh-totals {
    display: flex;
    align-items: flex-end;
    gap: 16px;
    margin-left: auto;
}

.pi-bh-tot-list {
    display: flex;
    gap: 14px;
    align-items: flex-end;
}

.pi-bh-tot {
    display: flex;
    flex-direction: column;
    gap: 2px;
    text-align: right;
}

.pi-bh-tot-lbl {
    font-size: 8px;
    color: rgba(255,255,255,0.3);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pi-bh-tot-val {
    font-size: 12px;
    font-family: var(--ui-font-mono, monospace);
    font-weight: 500;
    color: rgba(255,255,255,0.7);
}

/* Главный Итог */
.pi-bh-grand {
    padding-left: 14px;
    border-left: 1px solid rgba(255,255,255,0.1);
    display: flex;
    flex-direction: column;
    gap: 2px;
    text-align: right;
    justify-content: flex-end;
}

.pi-bh-grand-lbl {
    font-size: 9px;
    color: rgba(255,255,255,0.4);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.pi-bh-grand-val {
    font-size: 22px; /* Уменьшили с 28px */
    font-family: var(--ui-font-mono, monospace);
    font-weight: 600;
    color: #fff;
    line-height: 1;
    letter-spacing: 0.5px;
}

/* ── Более узкий интерактивный таймлайн ── */
.pi-tl-wrap {
    position: relative;
    margin-top: 4px;
}

.pi-tl-bar2 {
    height: 44px; /* Сплюснули "колбасу" (было 60px) */
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    width: 100%;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.1);
    position: relative;
    user-select: none;
}

.pi-tl-seg2 {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    padding: 0 10px;
    color: #fff;
    overflow: hidden;
    box-sizing: border-box;
    border-right: 1px solid rgba(0,0,0,0.2);
    cursor: pointer;
    transition: filter 0.12s;
    min-width: 0;
    position: relative;
}
.pi-tl-seg2:last-child { border-right: none; }
.pi-tl-seg2:hover { filter: brightness(1.12); }
.pi-tl-seg2.is-static { cursor: default; opacity: 0.9; }
.pi-tl-seg2.is-active-sub {
    box-shadow: inset 0 -3px 0 rgba(255,255,255,0.7);
}

.pi-tl-seg2 .pi-tl-lbl {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.85;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.pi-tl-seg2 .pi-tl-pct {
    font-family: var(--ui-font-mono);
    font-size: 12px; /* Сделали цифры процентов аккуратнее */
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.pi-tl-seg2 .pi-tl-amt {
    font-family: var(--ui-font-mono);
    font-size: 10px; /* Уменьшили размер сумм в плашке */
    opacity: 0.92;
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    font-variant-numeric: tabular-nums;
}

/* Перетягиваемый разделитель между двумя сегментами */
.pi-tl-handle {
    width: 8px;
    margin-left: -4px;
    margin-right: -4px;
    cursor: ew-resize;
    z-index: 5;
    position: relative;
    flex-shrink: 0;
    background: transparent;
}
.pi-tl-handle::before {
    content: '';
    position: absolute;
    inset: 0;
    width: 2px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255,255,255,0);
    transition: background 0.15s, box-shadow 0.15s;
    border-radius: 1px;
}
.pi-tl-handle:hover::before,
.pi-tl-handle.is-active::before {
    background: rgba(255,255,255,0.85);
    box-shadow: 0 0 0 1px rgba(0,0,0,0.5), 0 0 8px rgba(255,255,255,0.4);
}

/* Глобальный курсор пока тянем */
body.pi-tl-dragging,
body.pi-tl-dragging * {
    cursor: ew-resize !important;
    user-select: none !important;
}

/* Подсказка под таймлайном */
.pi-tl-hint {
    font-size: 9px;
    color: rgba(255,255,255,0.25);
    margin-top: 6px;
    text-align: center;
    letter-spacing: 0.5px;
}
.pi-tl-hint kbd {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 3px;
    padding: 1px 4px;
    font-size: 8.5px;
    font-family: var(--ui-font-mono);
    color: rgba(255,255,255,0.5);
}

/* ── Sub-таймлайн (раскрытие по правому клику) ──────────────── */
.pi-tl-sub {
    margin-top: 10px;
    background: rgba(0,0,0,0.42);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 8px;
    padding: 12px 14px 14px;
    animation: pi-tl-sub-in 0.18s ease;
}
@keyframes pi-tl-sub-in {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.pi-tl-sub-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    gap: 12px;
}

.pi-tl-sub-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    font-weight: 600;
    color: rgba(255,255,255,0.85);
    letter-spacing: 1px;
    text-transform: uppercase;
}

.pi-tl-sub-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.pi-tl-sub-sum {
    color: #fff;
    font-family: var(--ui-font-mono);
    font-size: 12px;
    margin-left: 8px;
    letter-spacing: 0.5px;
    text-transform: none;
    opacity: 0.85;
}

.pi-tl-sub-close {
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.5);
    cursor: pointer;
    font-size: 14px;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.15s;
}
.pi-tl-sub-close:hover {
    color: #fff;
    background: rgba(255,255,255,0.06);
}

.pi-tl-sub-bar {
    height: 40px; /* Немного уменьшили и этот бар */
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    width: 100%;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08);
    user-select: none;
    position: relative;
}

.pi-tl-sub-seg {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 0 8px;
    color: #fff;
    overflow: hidden;
    box-sizing: border-box;
    border-right: 1px solid rgba(0,0,0,0.28);
    cursor: pointer;
    min-width: 0;
    transition: filter 0.12s;
}
.pi-tl-sub-seg:hover { filter: brightness(1.18); }
.pi-tl-sub-seg:last-child { border-right: none; }
.pi-tl-sub-seg.is-static { cursor: default; }

.pi-tl-sub-seg .pi-tl-sub-lbl {
    font-size: 9px;
    opacity: 0.95;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    font-weight: 500;
}
.pi-tl-sub-seg .pi-tl-sub-amt {
    font-family: var(--ui-font-mono);
    font-size: 11px;
    font-weight: 700;
    opacity: 0.95;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    font-variant-numeric: tabular-nums;
}

.pi-tl-sub-handle {
    width: 8px;
    margin-left: -4px;
    margin-right: -4px;
    cursor: ew-resize;
    z-index: 5;
    position: relative;
    flex-shrink: 0;
}
.pi-tl-sub-handle::before {
    content: '';
    position: absolute;
    inset: 0;
    width: 2px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255,255,255,0);
    transition: background 0.15s;
    border-radius: 1px;
}
.pi-tl-sub-handle:hover::before,
.pi-tl-sub-handle.is-active::before {
    background: rgba(255,255,255,0.85);
    box-shadow: 0 0 0 1px rgba(0,0,0,0.5), 0 0 8px rgba(255,255,255,0.4);
}

/* Флэш на блок этапа после двойного клика */
.pi-stage-block.pi-stage-flash {
    animation: pi-stage-flash 1s ease;
}
@keyframes pi-stage-flash {
    0%   { box-shadow: 0 0 0 0 rgba(72, 130, 126, 0); }
    25%  { box-shadow: 0 0 0 3px rgba(72, 130, 126, 0.85); }
    100% { box-shadow: 0 0 0 0 rgba(72, 130, 126, 0); }
}

/* Скролл-таргеты не должны прятаться под sticky-шапкой */
.pi-stage-block { scroll-margin-top: 280px; }
.pi-stage-block { transition: transform 0.18s cubic-bezier(.4,0,.2,1); }
.pi-stage-block.is-dragging { opacity: 0.25; box-shadow: none !important; }
.pi-tl-expand-head { display:flex; align-items:center; gap:8px; padding:4px 8px 4px 4px; font-size:11px; color:var(--ui-text); }
.pi-tl-expand-head b { flex:1; }
.pi-tl-bar2--expanded { border-radius:6px; overflow:hidden; }

/* ── bc-panel: адаптивный дизайн блока целевого бюджета и метрик ─── */
.bc-panel { 
    display: flex; 
    flex-wrap: wrap; 
    gap: 16px; 
    align-items: start; /* Изменил на start, чтобы блоки не растягивались по высоте друг друга */
    margin-top: 4px; 
    width: 100%; 
}

.bc-fit-block { 
    flex: 0 0 260px; /* Зажимаем блок бюджета жестко на 260px, как в твоем дизайне */
    display: flex; 
    flex-direction: column; 
    justify-content: flex-start; 
    background: rgba(49,130,206,0.08); 
    border: 1px solid rgba(49,130,206,0.25); 
    border-radius: 10px; 
    padding: 14px 14px 10px; 
}
.bc-fit-label { font-size: 10px; font-weight: 600; letter-spacing: 0.08em; color: #63b3ed; margin-bottom: 8px; text-transform: uppercase; }
.bc-fit-row { display: flex; gap: 6px; align-items: center; }
.bc-fit-input { flex: 1; font-size: 18px !important; font-weight: 500; letter-spacing: 0.02em; padding: 8px 10px !important; }
.bc-fit-clear { flex-shrink: 0; width: 28px; height: 28px; border-radius: 6px; border: none; background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.5); cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 12px; transition: 0.15s; }
.bc-fit-clear:hover { background: rgba(255,80,80,0.2); color: #fc8181; }
.bc-fit-hint { font-size: 10px; color: rgba(255,255,255,0.3); margin-top: 8px; line-height: 1.4; }

.bc-metrics { 
    flex: 1 1 400px; /* Занимает оставшееся пространство, но сами плашки внутри будут ограничены */
    min-width: 0; 
    display: flex; 
    flex-direction: column; 
    gap: 8px; 
}
.bc-no-source { font-size: 11px; color: rgba(255,255,255,0.28); display: flex; align-items: center; gap: 6px; padding: 2px 0 4px; }

/* ── Сетка плашек метрик: выравнивание по левому краю ── */
.bc-metrics-grid { 
    display: flex; 
    flex-wrap: wrap; 
    gap: 8px; 
    width: 100%; 
    justify-content: flex-start; /* Всегда прижимаем плашки влево */
}

/* ── Сама плашка: убрали grow, зафиксировали ширину ── */
.bc-metric { 
    flex: 0 1 110px;  /* Уменьшили базовую ширину (было 125px) */
    min-width: 95px;  /* Разрешаем сжиматься сильнее (было 110px) */
    max-width: 130px; /* Ограничиваем растяжение */
    background: rgba(255,255,255,0.04); 
    border: 1px solid rgba(255,255,255,0.07); 
    border-radius: 8px; 
    padding: 8px 8px; /* Сделали боковые отступы чуть меньше */
    cursor: pointer; 
    transition: background 0.15s, border-color 0.15s; 
    user-select: none; 
}

.bc-metric:hover { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.15); }
.bc-metric.bc-metric-active { border-color: #63b3ed; background: rgba(49,130,206,0.1); }
.bc-metric-label { 
    font-size: 9px; 
    text-transform: uppercase; 
    letter-spacing: 0.07em; 
    color: rgba(255,255,255,0.35); 
    margin-bottom: 5px; 
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis; 
}

/* Уплотняем сами цифры, чтобы они не выпадали из сузившейся плашки */
.bc-metric-val { 
    display: flex; 
    align-items: center; 
    gap: 4px; /* Чуть сблизили точку и цифру */
    font-size: 14px; /* Сделали шрифт на 1px меньше для аккуратности */
    font-weight: 500; 
}
.bc-metric-dot { font-size: 8px; flex-shrink: 0; }

/* ── Строка кастомного ввода тоже должна быть аккуратной и не растягиваться на километр ── */
.bc-override-row { 
    display: flex; 
    align-items: center; 
    gap: 8px; 
    margin-top: 10px; 
    background: rgba(49,130,206,0.08); 
    border: 1px solid rgba(49,130,206,0.25); 
    border-radius: 8px; 
    padding: 8px 12px; 
    max-width: 660px; /* Ограничиваем общую ширину строки переопределения */
}
.bc-override-label { font-size: 11px; color: #63b3ed; white-space: nowrap; min-width: 110px; }
.bc-override-input { flex: 1; }

.pi-stage-block.stage-drop-above { box-shadow: 0 -3px 0 0 #63b3ed; }
.pi-stage-block.stage-drop-below { box-shadow: 0 3px 0 0 #63b3ed; }
.pi-stage-block.stage-nudge-up   { transform: translateY(-6px); }
.pi-stage-block.stage-nudge-down { transform: translateY( 6px); }
.pi-stage-drag-handle { user-select: none; }
.pi-pos-row      { scroll-margin-top: 320px; }

/* ─── Жесткая фиксация строк таблицы бюджета в одну линию ─── */

/* Запрещаем перенос строк для самой строки и заголовка */
.pi-pos-row,
.pi-budget-grid-header {
    white-space: nowrap !important;
    align-items: center !important; /* Гарантируем выравнивание по центру вертикали */
}

/* Все ячейки внутри строки не должны ломаться на несколько линий */
.pi-pos-row > div,
.pi-budget-grid-header > div,
.pi-grid-cell {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

/* Принудительно запрещаем инпутам переносить текст и ломать высоту */
.pi-pos-row input.pi-grid-input,
.pi-pos-row input.pi-input {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    /* Если строки всё равно скачут по высоте, можно жестко зафиксировать высоту инпута */
    height: 28px !important; 
    min-height: 28px !important;
}

/* Имя позиции (название) тоже обрезаем с многоточием, если оно супер-длинное */
.pi-grid-name {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}