/**
 * ═══════════════════════════════════════════════════════════════════════════
 *  МОДАЛЬНОЕ ОКНО ПОСТРОЕНИЯ МАРШРУТОВ — ПОЛНЫЙ РЕДИЗАЙН v2.0
 *  ═══════════════════════════════════════════════════════════════════════════
 */

/* ── Основная модалка ── */
.build-modal {
    max-width: 760px !important;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25),
                0 0 0 1px rgba(0, 0, 0, 0.05);
    overflow: hidden;
}

/* ── Заголовок ── */
.bm-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
    flex-shrink: 0;
}
.bm-header-text { flex: 1; min-width: 0; }

.bm-icon {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--accent), #3a6fd6);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(var(--accent-rgb, 79, 140, 247), 0.3);
}
.bm-icon.spinning i { animation: spin 1.2s linear infinite; }
.bm-icon.success {
    background: linear-gradient(135deg, var(--success), #34d399);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}
.bm-icon.danger {
    background: linear-gradient(135deg, var(--danger), #f87171);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.bm-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 4px;
    line-height: 1.2;
}
.bm-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 0;
    min-height: 18px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Сводная строка (ETP · TT · Method · Cache) ── */
.bm-summary-row {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 8px 12px;
    margin-bottom: 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    font-size: 12px;
    color: var(--text-secondary);
    flex-shrink: 0;
}
.bm-summary-row i { font-size: 11px; margin-right: 4px; opacity: 0.7; }
.bm-summary-row b { color: var(--text-primary); font-weight: 600; }
.bm-summary-divider {
    width: 1px;
    height: 16px;
    background: var(--border-light);
}

/* ── Прогресс-бар ── */
.bm-progress-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-shrink: 0;
}
.bm-bar {
    flex: 1;
    height: 10px;
    background: var(--bg-tertiary);
    border-radius: 5px;
    overflow: hidden;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}
.bm-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #7eb3ff);
    border-radius: 5px;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    width: 0%;
    position: relative;
}
.bm-bar-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    animation: shimmer 2s infinite;
}
.bm-bar-fill.success {
    background: linear-gradient(90deg, var(--success), #34d399);
}
.bm-bar-fill.danger {
    background: linear-gradient(90deg, var(--danger), #f87171);
}
.bm-pct {
    font-size: 13px;
    font-weight: 700;
    color: var(--accent);
    min-width: 40px;
    text-align: right;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* ── Этапы (горизонтальная полоска) ── */
.bm-stages-bar {
    display: flex;
    align-items: center;
    gap: 0;
    margin-bottom: 12px;
    padding: 4px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    flex-shrink: 0;
}
.bm-stage-ico {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    background: var(--bg-tertiary);
    transition: all 0.3s;
}

/* ── Карточка текущего ЭТП ── */
.bm-current-etp {
    display: none;
    padding: 12px 16px;
    margin-bottom: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    flex-shrink: 0;
    animation: fadeIn 0.3s ease-out;
}
.bm-current-etp.visible { display: block; }

/* ── Кнопка свернуть ── */
.bm-minimize-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px 10px;
    font-size: 13px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    flex-shrink: 0;
}
.bm-minimize-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* ── Панели лога/итога (5F.2 Этап 3: вкладки удалены, остались 2 панели) ── */
.bm-tab-panels {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
.bm-tab-panel {
    display: none;
    flex: 1;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    border: 1px solid var(--border-light);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    background: var(--bg-card);
}
.bm-tab-panel.active {
    display: flex;
}

/* ── Лог (главный элемент) ── */
.bm-log {
    flex: 1;
    overflow-y: auto;
    padding: 10px 12px;
    background: var(--bg-primary);
    font-family: ui-monospace, 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
    font-size: 12px;
    line-height: 1.6;
    min-height: 200px;
    max-height: 300px;
}

/* ── Разделитель ЭТП в логе ── */
.bm-log-etp-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    margin: 4px 0;
    border-bottom: 1px solid var(--border-light);
    font-weight: 600;
    color: var(--text-primary);
    font-size: 12px;
}
.bm-log-etp-header:first-child { margin-top: 0; }
.bm-log-etp-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.bm-log-etp-status {
    margin-left: auto;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    background: var(--bg-tertiary);
    color: var(--text-muted);
}
.bm-log-etp-header.done .bm-log-etp-status {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}
.bm-log-etp-header.warn .bm-log-etp-status {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}
.bm-log-etp-header.error .bm-log-etp-status {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

/* ── Строка лога ── */
.bm-log-entry {
    display: flex;
    gap: 8px;
    align-items: baseline;
    padding: 2px 0;
    animation: logFadeIn 0.2s ease-out;
}
@keyframes logFadeIn {
    from { opacity: 0; transform: translateX(-10px); }
    to { opacity: 1; transform: translateX(0); }
}
.bm-log-time {
    color: var(--text-muted);
    flex-shrink: 0;
    min-width: 38px;
    font-size: 11px;
    opacity: 0.7;
}
.bm-log-ico {
    flex-shrink: 0;
    font-size: 10px;
    width: 14px;
    text-align: center;
}
.bm-log-msg {
    color: var(--text-secondary);
    word-break: break-word;
    flex: 1;
}
.bm-log-ok    .bm-log-ico { color: var(--success); }
.bm-log-ok    .bm-log-msg { color: var(--success); }
.bm-log-warn  .bm-log-ico { color: var(--warning); }
.bm-log-warn  .bm-log-msg { color: var(--warning); }
.bm-log-error .bm-log-ico { color: var(--danger); }
.bm-log-error .bm-log-msg { color: var(--danger); font-weight: 600; }
.bm-log-api   .bm-log-ico { color: #38bdf8; }
.bm-log-api   .bm-log-msg { color: #38bdf8; }
.bm-log-algo  .bm-log-ico { color: var(--accent); }
.bm-log-algo  .bm-log-msg { color: var(--accent); }
.bm-log-geo   .bm-log-ico { color: #38bdf8; }
.bm-log-geo   .bm-log-msg { color: #38bdf8; }
.bm-log-limit .bm-log-ico { color: #f97316; }
.bm-log-limit .bm-log-msg { color: #f97316; }
.bm-log-info  .bm-log-ico { color: var(--text-muted); }

/* Отступ для под-сообщений */
.bm-log-indent {
    padding-left: 20px;
    border-left: 2px solid var(--border-light);
    margin-left: 4px;
}

/* ── Итоговый результат ── */
#bmPanelResult {
    overflow-y: auto;
}
.bm-result {
    padding: 16px;
    border-radius: 0;
    font-size: 12px;
    animation: fadeIn 0.4s ease-out;
    min-height: 200px;
    max-height: 300px;
    overflow-y: auto;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.bm-result.success {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.1), rgba(16, 185, 129, 0.05));
    border: 1px solid rgba(16, 185, 129, 0.2);
}
.bm-result.danger {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.1), rgba(239, 68, 68, 0.05));
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: var(--danger);
}
.bm-result-lbl {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ── Footer ── */
.bm-footer {
    margin-top: 12px;
    text-align: center;
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-shrink: 0;
}

/* ── Мини-виджет прогресса ── */
.bm-mini-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1001;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    min-width: 240px;
    animation: slideInRight 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transition: all 0.2s;
}
.bm-mini-widget:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.2);
}
.bm-mini-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), #7eb3ff);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}
.bm-mini-icon i { animation: spin 1.2s linear infinite; }
.bm-mini-info { flex: 1; min-width: 0; }
.bm-mini-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 6px;
}
.bm-mini-bar {
    height: 5px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
}
.bm-mini-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #7eb3ff);
    border-radius: 3px;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    width: 0%;
}
.bm-mini-pct {
    font-size: 14px;
    font-weight: 700;
    color: var(--accent);
    min-width: 40px;
    text-align: right;
}
.bm-mini-expand {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    font-size: 14px;
    transition: color 0.2s;
}
.bm-mini-expand:hover { color: var(--accent); }
.bm-mini-widget.success .bm-mini-icon {
    background: linear-gradient(135deg, var(--success), #34d399);
}
.bm-mini-widget.success .bm-mini-icon i { animation: none; }
.bm-mini-widget.success .bm-mini-pct { color: var(--success); }
.bm-mini-widget.success .bm-mini-bar-fill {
    background: linear-gradient(90deg, var(--success), #34d399);
}

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ── Адаптивность ── */
@media (max-width: 600px) {
    .build-modal {
        max-width: 100% !important;
        max-height: 100vh;
        margin: 0;
        border-radius: 0;
    }
    .bm-stages-bar {
        flex-wrap: wrap;
    }
    .bm-stage-item {
        flex: none;
        width: 50%;
    }
    .bm-result-stats {
        flex-direction: column;
    }
    .bm-result-stat {
        border-right: none;
        border-bottom: 1px solid var(--border-light);
    }
    .bm-summary-row {
        flex-wrap: wrap;
        gap: 8px;
    }
    .bm-summary-divider {
        display: none;
    }
}

/* ── Анимация спиннера ── */
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
@keyframes slideDown {
    from { opacity: 0; max-height: 0; }
    to { opacity: 1; max-height: 500px; }
}

/* ============================================================
 * D10 (2026-05-20): экран резолва underloaded ЭТП
 * ============================================================ */
.d10-screen {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 16px;
    font-size: 14px;
    color: #1f2937;
}

.d10-stats {
    display: flex;
    gap: 24px;
    padding: 12px 16px;
    background: #f9fafb;
    border-radius: 8px;
}
.d10-stat-val {
    font-size: 22px;
    font-weight: 700;
    line-height: 1;
}
.d10-stat-lbl {
    font-size: 11px;
    color: #6b7280;
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.d10-bulk {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.d10-bulk-lbl {
    font-size: 12px;
    color: #6b7280;
    margin-right: 4px;
}
.d10-bulk-btn {
    padding: 6px 10px;
    font-size: 12px;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    cursor: pointer;
    color: #374151;
    transition: all 0.15s;
}
.d10-bulk-btn:hover { border-color: #6b7280; background: #f9fafb; }
.d10-bulk-merge:hover { border-color: #0ea5e9; color: #0369a1; }
.d10-bulk-delete:hover { border-color: #dc2626; color: #b91c1c; }

.d10-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 50vh;
    overflow-y: auto;
    padding-right: 4px;
}
.d10-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 14px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.d10-card:hover {
    border-color: #9ca3af;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.d10-card[data-action="delete"] { border-left: 3px solid #ef4444; }
.d10-card[data-action="merge"]  { border-left: 3px solid #0ea5e9; }
.d10-card[data-action="keep"]   { border-left: 3px solid #d1d5db; }

.d10-card-info { flex: 1; min-width: 0; }
.d10-card-name {
    font-weight: 600;
    font-size: 14px;
    color: #111827;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.d10-card-meta {
    margin-top: 4px;
    font-size: 12px;
    color: #6b7280;
}
.d10-akb {
    display: inline-block;
    padding: 2px 8px;
    background: #fef3c7;
    color: #92400e;
    border-radius: 4px;
    font-weight: 600;
}
.d10-neighbor {
    margin-top: 4px;
    font-size: 12px;
    color: #4b5563;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.d10-neighbor-none { color: #9ca3af; font-style: italic; }
.d10-dist {
    margin-left: 6px;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
}
.d10-dist-ok  { background: #dcfce7; color: #166534; }
.d10-dist-far { background: #fee2e2; color: #991b1b; }

.d10-seg {
    display: flex;
    flex-shrink: 0;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    overflow: hidden;
    background: #fff;
}
.d10-seg-btn {
    padding: 8px 14px;
    font-size: 12px;
    font-weight: 500;
    background: transparent;
    border: none;
    border-right: 1px solid #e5e7eb;
    cursor: pointer;
    color: #6b7280;
    transition: all 0.15s;
    white-space: nowrap;
}
.d10-seg-btn:last-child { border-right: none; }
.d10-seg-btn:hover:not(.is-disabled):not(.is-active) {
    background: #f9fafb;
    color: #111827;
}
.d10-seg-keep.is-active   { background: #f3f4f6; color: #111827; }
.d10-seg-merge.is-active  { background: #0ea5e9; color: #fff; }
.d10-seg-delete.is-active { background: #ef4444; color: #fff; }
.d10-seg-btn.is-disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.d10-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding-top: 12px;
    border-top: 1px solid #e5e7eb;
}
.d10-btn {
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    border: 1px solid transparent;
}
.d10-btn-ghost {
    background: #fff;
    border-color: #d1d5db;
    color: #6b7280;
}
.d10-btn-ghost:hover { background: #f9fafb; color: #111827; }
.d10-btn-primary {
    background: #2563eb;
    color: #fff;
}
.d10-btn-primary:hover { background: #1d4ed8; }
.d10-btn-primary:disabled { background: #9ca3af; cursor: not-allowed; }
