html {
  font-size: 14px;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}

html {
  position: relative;
  min-height: 100%;
}

body {
  margin-bottom: 60px;
}

.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder {
  color: var(--bs-secondary-color);
  text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder {
  text-align: start;
}

/* Глобальный сеточный каркас приложения */
        
    .main-layout { 
        display: flex; 
        width: 100vw; 
        height: calc(100vh - 70px); 
        margin-left: calc(-50vw + 50%); 
        margin-right: calc(-50vw + 50%); 
        overflow: hidden;
    }

    .inspector { 
        width: 320px; 
        min-width: 320px; 
        height: 100%; 
        z-index: 10; 
        transition: margin-right 0.3s ease; /* Для будущего плавного скрытия */
    }

    .inspector.collapsed {
        margin-right: -320px;
    }

    .sidebar { width: 260px; min-width: 260px; height: 100%; border-right: 1px solid #3c3c3c; z-index: 10; }
    .chat-area { flex-grow: 1; height: 100%; overflow: hidden; background-color: #fcfcfc; }
    
    /* Элементы сайдбара */
    .chat-sidebar-item { cursor: pointer; transition: background 0.2s; color: #ced4da; font-size: 0.9rem; }
    .chat-sidebar-item:hover { background-color: #343a40; color: #fff; }
    .chat-sidebar-item.active { background-color: #0d6efd; color: #fff; font-weight: bold; }
    .chat-title { pointer-events: none; }

    /* Сообщения чата */
    .chat-msg { max-width: 85%; padding: 12px 16px; border-radius: 10px; font-size: 15px; word-break: break-word; }
    .msg-user { background-color: #e9ecef; align-self: flex-end; color: #212529; border-bottom-right-radius: 2px; }
    .msg-ai { background-color: #f8f9fa; align-self: flex-start; color: #212529; border: 1px solid #dee2e6; border-bottom-left-radius: 2px; }
    
    .reply-text p:last-child { margin-bottom: 0; }
    .katex-display { margin: 0.5em 0; overflow-x: auto; overflow-y: hidden; }

    /* Стилизация блоков кода под VS Code */
    .code-container { border: 1px solid #3c3c3c; margin: 15px 0; border-radius: 6px; overflow: hidden; display: flex; flex-direction: column; }
    .code-header { background-color: #2d2d2d !important; color: #bbbbbb !important; font-size: 0.8rem; border-bottom: 1px solid #3c3c3c; }
    .code-container pre { background: #1e1e1e !important; margin: 0 !important; padding: 14px !important; overflow-x: auto; }
    .code-container code { font-family: 'Consolas', 'Fira Code', monospace !important; text-shadow: none !important; color: #fff; }

    /* Индикатор загрузки "Бот думает..." */
    .typing-indicator { display: flex; align-self: flex-start; background-color: #f8f9fa; border: 1px solid #dee2e6; padding: 12px 16px; border-radius: 10px; border-bottom-left-radius: 2px; gap: 5px; }

    /* Сворачиваемые мысли модели */
    .thought-toggle {
        transition: background-color 0.2s ease;
    }
    .thought-toggle:hover {
        background-color: rgba(255, 193, 7, 0.15) !important;
    }
    .thought-body {
        max-height: 300px;
        overflow-y: auto;
    }
    .typing-dot { width: 8px; height: 8px; background-color: #6c757d; border-radius: 50%; animation: pulse 1.4s infinite ease-in-out both; }
    .typing-dot:nth-child(2) { animation-delay: 0.2s; }
    .typing-dot:nth-child(3) { animation-delay: 0.4s; }
    #userInput {
        resize: none; /* Запрещаем пользователю вручную растягивать поле за угол */
        overflow-y: auto; /* Появится скролл, только если текст превысит наши максимальные 250px */
    }

    .agent-card:hover { transform: translateY(-2px); border-color: #0d6efd !important; background-color: #f8f9fa !important; }
    .agent-card.active { border-color: #0d6efd !important; background-color: #e7f1ff !important; box-shadow: 0 0 0 2px rgba(13,110,253,.25) !important; }
    .agents-bar::-webkit-scrollbar { height: 4px; }
    .agents-bar::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }
    
    .agents-bar { 
    display: flex; 
    gap: 12px; 
    margin-bottom: 1rem; 
    overflow-x: auto; 
    overflow-y: hidden;
    padding-bottom: 8px; 
    flex-shrink: 0; /* 👈 Запрещает сжимать панель по высоте */
    }

    /* Явно запрещаем карточкам сжиматься по ширине внутри скролла */
    .agent-card { 
        cursor: pointer; 
        min-width: 220px; 
        max-width: 220px; 
        flex-shrink: 0; /* 👈 Запрещает сжимать карточку */
        transition: all 0.2s ease-in-out; 
        border-color: #dee2e6 !important; 
    }

    @keyframes pulse { 0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; } 40% { transform: scale(1); opacity: 1; } }

    /* ===== Редактор пайплайнов ===== */
    .pipeline-editor-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.6);
        z-index: 9998;
        display: flex;
        flex-direction: column;
    }

    .editor-header {
        height: 50px;
        flex-shrink: 0;
    }

    .nodes-canvas {
        position: relative;
        overflow: auto;
        background-color: #1a1a2e;
        background-image: radial-gradient(circle, #2a2a4a 1px, transparent 1px);
        background-size: 20px 20px;
    }

    .edges-svg {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        pointer-events: auto;
        z-index: 5;
    }

    .edges-svg path {
        pointer-events: stroke;
        cursor: pointer;
        fill: none;
    }

    .agent-node-card {
        width: 240px !important;
        min-height: 100px;
        z-index: 10;
        cursor: move;
        user-select: none;
        transition: box-shadow 0.15s;
    }

    .agent-node-card:hover {
        box-shadow: 0 0 0 2px #0d6efd;
    }

    .node-port {
        width: 14px;
        height: 14px;
        background: #fff;
        border: 2px solid #0d6efd;
        border-radius: 50%;
        cursor: crosshair;
        transition: all 0.15s;
    }

    .node-port:hover {
        transform: scale(1.4);
        background: #0d6efd;
    }

    .port-input {
        margin: 0 auto;
        margin-bottom: 6px;
    }

    .port-output {
        margin: 6px auto 0;
    }

    /* Инспектор связок (правая панель) */
    .edge-inspector {
        border-left: 1px solid #444;
        overflow-y: auto;
        transition: transform 0.25s ease;
    }

    /* Инспектор ноды (левая панель) */
    .node-inspector {
        border-right: 1px solid #444;
        overflow-y: auto;
        transition: transform 0.25s ease;
    }

    .node-inspector .form-range::-webkit-slider-thumb {
        background: #0dcaf0;
    }

    .node-inspector .form-range::-moz-range-thumb {
        background: #0dcaf0;
    }

    /* Debug модальное окно */
    #debugModal > div,
    #createPipelineModal > div {
        border: 1px solid #444;
    }

    /* ========================================================================
       СВЕТАЯ ТЕМА — МОДАЛКИ РЕДАКТОРОВ (инструменты main + детали, пайплайн,
       debug). Они были всегда тёмными (хардкод Bootstrap bg-dark/text-light +
       карточки/инпуты bg-secondary), не подхватывая светлую тему. Класс
       .theme-modal задан ТОЛЬКО на этих модалках (не на чат-консоли воркбена —
       она остаётся тёмной!). В светлой теме — светлый фон/карточки/текст +
       читаемые акценты; в тёмной (default и data-theme=dark) — без изменений.
       ====================================================================== */
    html[data-theme="light"] .theme-modal {
        background-color: var(--l-surface) !important;
        color: var(--l-text) !important;
        border: 1px solid var(--l-border) !important;
    }
    html[data-theme="light"] .theme-modal .text-light {
        color: var(--l-text) !important;
    }
    html[data-theme="light"] .theme-modal .text-muted {
        color: var(--l-muted) !important;
    }
    html[data-theme="light"] .theme-modal .bg-secondary {
        background-color: var(--l-surface-2) !important;
        color: var(--l-text) !important;
    }
    html[data-theme="light"] .theme-modal .text-warning {
        color: #b45309 !important; /* янтарный — читаем на светлом (был жёлтый) */
    }
    html[data-theme="light"] .theme-modal .text-info {
        color: #0e7490 !important; /* циан — читаем на светлом (был бирюзовый) */
    }
    /* Консоль debug внутри модалки — читаемая на светлом (была тёмной) */
    html[data-theme="light"] .theme-modal .debug-message-item {
        background-color: var(--l-surface-2) !important;
        border-color: var(--l-border) !important;
    }
    html[data-theme="light"] .theme-modal .debug-message-header {
        background-color: var(--l-surface) !important;
        border-bottom-color: var(--l-border) !important;
    }
    html[data-theme="light"] .theme-modal .debug-message-content {
        background-color: var(--l-surface-2) !important;
        color: var(--l-text) !important;
    }
    html[data-theme="light"] .theme-modal .debug-section-title {
        color: var(--l-text) !important;
        border-bottom-color: var(--l-border) !important;
    }
    /* Модалка «Новый пайплайн»: её оверлей делит класс .pipeline-editor-overlay с
       fullscreen-редактором, и theme.css §3 делает его в лайте сплошным белым —
       тогда белая коробка модалки на нём не читается. Даём полупрозрачное затемнение
       (как у Tools) — коробка (белая) чётко выделяется. Scoped по id, fullscreen не тронут. */
    html[data-theme="light"] #createPipelineModal {
        background: rgba(17, 24, 39, 0.55) !important;
    }

    /* Селектор роли в карточке */
    .agent-role-select {
        pointer-events: auto;
    }

    /* Кнопки в карточке */
    .debug-node-btn:hover { color: #ffc107 !important; text-shadow: 0 0 4px #ffc107; }
    .settings-node-btn:hover { color: #0dcaf0 !important; text-shadow: 0 0 4px #0dcaf0; }
    .delete-node-btn:hover { color: #dc3545 !important; text-shadow: 0 0 4px #dc3545; }

    /* Селектор пайплайнов — читаемый текст */
    #pipelineSelector {
        background-color: #2d2d2d !important;
        color: #e0e0e0 !important;
        border-color: #555 !important;
    }

    #pipelineSelector option {
        background-color: #2d2d2d !important;
        color: #e0e0e0 !important;
    }

    /* ==================== Debug Timeline ==================== */
    .debug-timeline {
        position: relative;
        padding-left: 30px;
    }

    .debug-timeline::before {
        content: '';
        position: absolute;
        left: 10px;
        top: 0;
        bottom: 0;
        width: 2px;
        background: rgba(255, 255, 255, 0.15);
    }

    .debug-timeline-item {
        position: relative;
        margin-bottom: 12px;
        cursor: pointer;
    }

    .debug-timeline-dot {
        position: absolute;
        left: -24px;
        top: 6px;
        width: 12px;
        height: 12px;
        border-radius: 50%;
        background: #ffc107;
        border: 2px solid #0d6efd;
        z-index: 2;
    }

    .debug-timeline-content {
        background: rgba(255, 255, 255, 0.05);
        border-radius: 8px;
        padding: 10px 12px;
        border: 1px solid rgba(255, 255, 255, 0.1);
        transition: background 0.2s;
    }

    .debug-timeline-content:hover {
        background: rgba(255, 255, 255, 0.1);
    }

    .debug-timeline-header {
        display: flex;
        align-items: center;
        gap: 8px;
        font-size: 0.85rem;
    }

    .debug-agent-badge {
        display: inline-block;
        padding: 2px 8px;
        border-radius: 4px;
        font-size: 0.8rem;
        font-weight: 600;
        font-family: monospace;
    }

    .debug-agent-source {
        background: rgba(13, 110, 253, 0.25);
        color: #90cdfa;
        border: 1px solid rgba(13, 110, 253, 0.4);
    }

    .debug-agent-target {
        background: rgba(40, 167, 69, 0.25);
        color: #75c97a;
        border: 1px solid rgba(40, 167, 69, 0.4);
    }

    .debug-call-detail {
        margin-top: 10px;
        padding-top: 10px;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    .debug-call-field {
        margin-bottom: 10px;
    }

    .debug-pre {
        margin: 4px 0 0 0;
        padding: 8px;
        background: rgba(0, 0, 0, 0.3);
        border-radius: 4px;
        font-size: 0.78rem;
        font-family: monospace;
        white-space: pre-wrap;
        word-break: break-word;
        color: #f8f9fa;
        border: 1px solid rgba(255, 255, 255, 0.08);
    }

    .debug-response-pre {
        border-left: 3px solid #28a745;
    }

    /* Debug tab buttons */
    #debugTabNode,
    #debugTabHistory {
        transition: all 0.2s;
    }

    #debugTabNode.active {
        background: #ffc107 !important;
        color: #000 !important;
        border-color: #ffc107 !important;
    }

    #debugTabHistory.active {
        background: #0dcaf0 !important;
        color: #000 !important;
        border-color: #0dcaf0 !important;
    }

    /* T4: 3-я вкладка «Окно агентов» — тот же паттерн (уникальный id) */
    #debugTabAgent {
        transition: all 0.2s;
    }

    #debugTabAgent.active {
        background: #0d6efd !important;
        color: #fff !important;
        border-color: #0d6efd !important;
    }

    /* ===== Service messages (system notifications) ===== */
    .service-message {
        align-self: center;
        max-width: 90%;
        padding: 8px 16px;
        margin: 6px 0;
        font-size: 13px;
        font-family: 'Consolas', 'Fira Code', monospace;
        border-radius: 6px;
        text-align: center;
        animation: fadeInService 0.3s ease-in;
    }

    .service-message.info {
        background-color: #e7f1ff;
        color: #0747a7;
        border: 1px solid #b6d4fe;
    }

    .service-message.warning {
        background-color: #fff3cd;
        color: #664d03;
        border: 1px solid #ffecb5;
    }

    .service-message.error {
        background-color: #f8d7da;
        color: #842029;
        border: 1px solid #f5c2c7;
    }

    .service-message.success {
        background-color: #d1e7dd;
        color: #0f5132;
        border: 1px solid #badbcc;
    }

    @keyframes fadeInService {
        from {
            opacity: 0;
            transform: translateY(-10px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
