/* НеЧат — Железобетонный каркас */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #f5f5f5;
    --block-bg: #e8e8e8;
    --panel-bg: #ffffff;
    --text: #333333;
    --text-muted: #888888;
    --accent: #6366f1;
    --border: #dddddd;
    --radius: 12px;
    --gap: 8px;
    --sidebar-width: 52px;
    --header-height: 56px;
}

html, body { height: 100%; overflow: hidden; }
body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    padding: var(--gap);
}

/* === ВЕРТИКАЛЬНАЯ РАСКЛАДКА === */
.app {
    display: flex;
    flex-direction: column;
    height: 100%;
    gap: var(--gap);
}

/* Шапка */
.header {
    height: var(--header-height);
    flex-shrink: 0;
    background: var(--block-bg);
    border-radius: var(--radius);
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 16px;
    font-weight: 600;
}

/* === ГОРИЗОНТАЛЬНАЯ РАСКЛАДКА === */
.body {
    flex: 1;
    display: flex;
    gap: var(--gap);
    min-height: 0;
}

/* Тулбар */
.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--block-bg);
    border-radius: var(--radius);
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.sidebar-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--panel-bg);
    color: var(--text);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.sidebar-btn:hover { border-color: var(--accent); background: #eef2ff; }
.sidebar-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

.sidebar-divider {
    width: 28px;
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

.sidebar-dynamic {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    flex: 1;
    overflow-y: auto;
}

/* === РАБОЧАЯ ОБЛАСТЬ === */
.main {
    flex: 1;
    display: flex;
    gap: var(--gap);
    min-width: 0;
}

/* Дирижёр (60%) */
.conductor {
    flex: 6.5;
    background: var(--block-bg);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Правая колонка (40%) */
.right-col {
    flex: 3.5;
    display: flex;
    flex-direction: column;
    gap: var(--gap);
    min-width: 0;
    overflow: hidden;
    height: 100%;
}

/* Планировщик (верхняя половина правой колонки) */
.planner {
    flex: 0 0 calc(100% - 310px);
    height: calc(100% - 310px);
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: var(--block-bg);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Терминал (нижняя половина правой колонки) */
.terminal {
    flex: 0 0 300px;
    min-height: 300px;
    height: 300px;
    overflow: hidden;
    background: #1e1e1e;
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
}

/* === ЗАГОЛОВКИ ПАНЕЛЕЙ === */
.panel-title {
    padding: 8px 16px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

/* === ПОЛЕ СООБЩЕНИЙ === */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

/* === ПОЛЕ ВВОДА === */
.chat-input-bar {
    border-top: 1px solid var(--border);
    padding: 10px;
    display: flex;
    gap: 8px;
}

.chat-input-bar textarea {
    flex: 1;
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    min-height: 40px;
    color: var(--text);
}

.chat-input-bar button {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    flex-shrink: 0;
}

.btn-send { background: var(--accent); color: white; }
.btn-attach { background: var(--panel-bg); border: 1px solid var(--border) !important; }

/* === ПЛАНИРОВЩИК === */
.planner-log {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding: 12px;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    line-height: 1.6;
    color: var(--text-muted);
}

/* === ТЕРМИНАЛ === */
.terminal-body {
    padding: 4px;
    height: 100%;
    box-sizing: border-box;
}

/* Убираем ресайз у textarea внутри xterm */

/* Прозрачное выделение в xterm */
.xterm .xterm-selection div {
    background: rgba(99, 102, 241, 0.3) !important;
    position: absolute;
}
.xterm-selection {
    position: absolute;
    top: 0;
    left: 0;
}







/* Скрыть измерительный элемент xterm.js */
.xterm-char-measure-element {
    position: absolute !important;
    left: -9999px !important;
    top: -9999px !important;
    visibility: hidden !important;
}

/* Скрыть вспомогательную textarea xterm.js */
.xterm-helper-textarea {
    z-index: 999 !important;
    opacity: 0.01 !important;
    position: absolute !important;
}

.toggle-label { display: flex; align-items: center; cursor: pointer; }
.toggle-label input { display: none; }
.toggle-slider {
    width: 36px; height: 20px; background: #ccc; border-radius: 10px;
    position: relative; transition: all 0.2s; margin-left: 8px;
}
.toggle-slider::after {
    content: ""; position: absolute; top: 2px; left: 2px;
    width: 16px; height: 16px; background: white; border-radius: 50%; transition: all 0.2s;
}
.toggle-label input:checked + .toggle-slider { background: #4ade80; }
.toggle-label input:checked + .toggle-slider::after { left: 18px; }

/* Сообщения чата */
.message-wrapper {
    display: flex;
    flex-direction: column;
    margin-bottom: 12px;
    padding: 0 12px;
}
.message-wrapper.message-user { align-items: flex-end; }
.message-wrapper.message-assistant { align-items: flex-start; }
.message-wrapper.message-system { 
    align-items: center;
    margin-bottom: 2px;
    padding: 0 8px;
}
.message-wrapper.message-system .message-bubble {
    padding: 2px 8px;
}
.message-bubble {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}
.message-label {
    font-size: 10px;
    font-weight: 600;
    margin-bottom: 2px;
    opacity: 0.6;
    letter-spacing: 0.3px;
    padding: 0 4px;
}

.message-bubble { white-space: pre-wrap !important; }

.terminal-body {
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.terminal-body::-webkit-scrollbar { display: none; }

/* Шестерёнки — индикатор работы системы (над окном ввода) */
.gears-indicator {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 6px 0;
    font-size: 16px;
    background: transparent;
}

.gears-indicator .gear {
    display: inline-block;
    animation: gear-spin 0.5s ease-in-out;
    animation-iteration-count: 1;
    opacity: 0.4;
}

.gears-indicator .gear.active {
    opacity: 1;
}

@keyframes gear-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Шестерёнки — индикатор работы системы */
.gears-row {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 8px 0;
    font-size: 18px;
}

.gears-row .gear {
    display: inline-block;
    animation: gear-spin 0.5s ease-in-out;
    animation-iteration-count: 1;
    opacity: 0.5;
}

.gears-row .gear.active {
    opacity: 1;
}

@keyframes gear-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
