/* Терминал: экран /terminal, вкладка «Терминал» в панели чата, раздел админки «Терминалы».
   Стили самого xterm.js - из static/vendor (без изменений). Цвета терминала - переменные --term-* ниже:
   их читает js/mod/terminal.js и следит за сменой темы. */
@import url("../vendor/xterm-6.0.0.css");

:root {
  --term-bg: var(--surface);
  --term-fg: var(--ink);
  --term-cursor: var(--ink);
  --term-selection: #bdff1299;
  --term-contrast: 4.5;            /* на светлом фоне xterm сам темнит слишком бледный цвет программы */
  --term-black: #121411;
  --term-red: #b42318;
  --term-green: #2c7a1b;
  --term-yellow: #8f5b00;
  --term-blue: #1d5fc4;
  --term-magenta: #8b3db0;
  --term-cyan: #0b7a84;
  --term-white: #8a8f85;
  --term-bright-black: #6b7067;
  --term-bright-red: #d0352a;
  --term-bright-green: #4c6d00;
  --term-bright-yellow: #a45a00;
  --term-bright-blue: #2a73d9;
  --term-bright-magenta: #a24fc7;
  --term-bright-cyan: #0f8f99;
  --term-bright-white: #3a3e37;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --term-bg: var(--sunken);
    --term-fg: var(--ink);
    --term-cursor: var(--accent);
    --term-selection: #bdff1240;
    --term-contrast: 1;
    --term-black: #2a2e27;
    --term-red: #ff7a6b;
    --term-green: #9ad94f;
    --term-yellow: #f0b04a;
    --term-blue: #6ea8fe;
    --term-magenta: #cf8cf5;
    --term-cyan: #5ccfd6;
    --term-white: #c9ccc3;
    --term-bright-black: #6b7067;
    --term-bright-red: #ff9b8f;
    --term-bright-green: #bdff12;
    --term-bright-yellow: #ffd27a;
    --term-bright-blue: #9cc4ff;
    --term-bright-magenta: #e2b3ff;
    --term-bright-cyan: #8ee6ea;
    --term-bright-white: #f6f7f3;
  }
}

:root[data-theme="dark"] {
  --term-bg: var(--sunken);
  --term-fg: var(--ink);
  --term-cursor: var(--accent);
  --term-selection: #bdff1240;
  --term-contrast: 1;
  --term-black: #2a2e27;
  --term-red: #ff7a6b;
  --term-green: #9ad94f;
  --term-yellow: #f0b04a;
  --term-blue: #6ea8fe;
  --term-magenta: #cf8cf5;
  --term-cyan: #5ccfd6;
  --term-white: #c9ccc3;
  --term-bright-black: #6b7067;
  --term-bright-red: #ff9b8f;
  --term-bright-green: #bdff12;
  --term-bright-yellow: #ffd27a;
  --term-bright-blue: #9cc4ff;
  --term-bright-magenta: #e2b3ff;
  --term-bright-cyan: #8ee6ea;
  --term-bright-white: #f6f7f3;
}

/* --- экран /terminal ------------------------------------------------------------------------------------- */
.term-switch { display: flex; gap: 2px; flex: none; }
.term-switch a {
  padding: 6px 10px; border-radius: var(--radius-sm); color: var(--muted); text-decoration: none;
  font-size: 13.5px; white-space: nowrap;
}
.term-switch a:hover { background: var(--sunken); color: var(--ink); }
.term-switch a.on { background: var(--sunken); color: var(--ink); font-weight: 500; }

.term-live { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.term-live > .loading { padding: 24px; }
.term-bar {
  display: flex; align-items: center; gap: 10px; min-width: 0; padding: 8px 16px;
  border-bottom: 1px solid var(--line); background: var(--raised);
}
.term-tabs { display: flex; gap: 4px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: thin; }
.term-tab {
  display: flex; align-items: center; flex: none; max-width: 220px; min-width: 0;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--raised);
}
.term-tab.on { background: var(--surface); border-color: var(--line-strong); box-shadow: inset 0 -2px 0 var(--ink); }
.term-tab.ended { opacity: .6; }
.term-tab-main {
  display: flex; align-items: center; gap: 6px; min-width: 0; height: 30px; padding: 0 4px 0 10px;
  border: 0; background: none; color: var(--ink-2); cursor: pointer;
}
.term-tab.on .term-tab-main { color: var(--ink); }
.term-tab-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.term-tab-x {
  display: grid; place-items: center; flex: none; width: 26px; height: 26px; margin-right: 2px; padding: 0;
  border: 0; border-radius: 5px; background: none; color: var(--muted); cursor: pointer;
}
.term-tab-x:hover { background: var(--sunken); color: var(--ink); }
.term-new { display: flex; align-items: center; gap: 6px; flex: none; min-width: 0; }
.term-new .select { width: auto; max-width: 240px; height: 30px; }
.term-stage { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 12px 16px 16px; }
.term-stage > .empty-card { margin: auto 0; }

/* --- один терминал ------------------------------------------------------------------------------------------- */
.term-view { flex: 1; min-height: 0; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.term-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.term-title { min-width: 0; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.term-cwd { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.term-head .btn { flex: none; }
.term-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--line-strong); }
.term-dot.ok { background: var(--ok); }
.term-dot.wait { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .term-dot.wait { animation: none; } }
.term-banner { padding: 8px 12px; }
/* Рамка отдельно от host: FitAddon меряет родителя .xterm целиком, рамка и отступы у него ломали бы подгонку. */
.term-frame {
  flex: 1; min-height: 160px; min-width: 0; display: flex; overflow: hidden;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--term-bg);
}
.term-host { flex: 1; min-width: 0; min-height: 0; position: relative; }
.term-host .xterm { height: 100%; padding: 6px 0 6px 8px; }
.term-host .xterm .xterm-viewport { background-color: var(--term-bg); }   /* у xterm.css там черный */

/* Клавиши, которых нет на экранной клавиатуре: только на телефоне и планшете. */
.term-keys { display: none; gap: 4px; flex: none; overflow-x: auto; scrollbar-width: none; }
.term-keys::-webkit-scrollbar { display: none; }
.term-keys button {
  flex: none; min-width: 40px; height: 34px; padding: 0 10px; cursor: pointer; touch-action: manipulation;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink);
  font: 500 13px/1 var(--mono);
}
.term-keys button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* --- вкладка в панели чата ----------------------------------------------------------------------------------- */
.term-chat { height: 100%; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.term-chat .term-view { min-height: 280px; }
.term-chat .term-frame { min-height: 200px; }
.term-view.compact .term-label { display: none; }
.term-view.compact .term-title { max-width: none; flex: 0 1 auto; }
.term-chat-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 12.5px; }

/* --- записи -------------------------------------------------------------------------------------------------- */
.term-note { margin: 0; flex: 1; min-width: 0; }
.term-link {
  padding: 0; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer;
  text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px;
}
.term-link:hover { text-decoration-color: var(--ink); }
.term-filter { gap: 4px; padding-right: 4px; }
.term-filter button {
  display: grid; place-items: center; width: 18px; height: 18px; padding: 0;
  border: 0; border-radius: 50%; background: none; color: inherit; cursor: pointer;
}
.term-filter button:hover { background: var(--line); }
.term-records td { overflow-wrap: anywhere; }
.modal.term-record { width: min(960px, 100%); }
.term-log {
  margin: 0; max-height: min(60vh, 640px); overflow: auto; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--term-bg); color: var(--term-fg);
  font: 12.5px/1.45 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere;
}

/* --- узкие экраны -------------------------------------------------------------------------------------------- */
@media (max-width: 760px), (hover: none) and (pointer: coarse) {
  .term-keys { display: flex; }
}
@media (max-width: 760px) {
  .term-switch a { padding: 6px 8px; }
  .term-bar { flex-wrap: wrap; padding: 8px 12px; }
  .term-tabs { flex-basis: 100%; }
  .term-tabs:empty { display: none; }
  .term-new { flex: 1; }
  .term-new .select { flex: 1; max-width: none; }
  .term-stage { padding: 8px 8px 10px; }
  .term-cwd, .term-label { display: none; }
  .term-title { max-width: none; flex: 0 1 auto; }
  .term-tab { max-width: 180px; }
}
