/* coppice-web, ревизия 50 (этапы A–D) и 52 (этап E). Без сборки; темы — токенами. */
:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #eef1f5;
  --text: #1b2230;
  --muted: #5d6778;
  --line: #d9dee6;
  --accent: #2459c9;
  --good: #1d7a45;
  --warn: #9a6400;
  --bad: #b3261e;
  --good-bg: #e3f3ea;
  --warn-bg: #fbf0dc;
  --bad-bg: #fbe4e2;
  --muted-bg: #eceff3;
  --radius: 8px;
  --side: 280px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  /* график (этап B): свечи, три слоя коробок, план, позиция, уровни */
  --c-up: #1d8a4a; --c-down: #c8372d; --c-hist: #8a8f98; --c-actual: #1f6fd1; --c-forecast: #8a55c9;
  --c-entry: #1f6fd1; --c-stop: #c8372d; --c-target: #1d8a4a; --c-position: #d9730d; --c-level: #8a6d1f;
  --c-price: #2a3140;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1318;
    --panel: #161b22;
    --panel-2: #1d242d;
    --text: #e3e8ef;
    --muted: #8d98a8;
    --line: #2a323d;
    --accent: #6d9cff;
    --good: #5cc98a;
    --warn: #e0b04f;
    --bad: #ff7a70;
    --good-bg: #16301f;
    --warn-bg: #33290f;
    --bad-bg: #3a1714;
    --muted-bg: #232a33;
    --c-up: #4cc38a; --c-down: #ff6b61; --c-hist: #7d8794; --c-actual: #5b9dff; --c-forecast: #b48cf2;
    --c-entry: #5b9dff; --c-stop: #ff6b61; --c-target: #4cc38a; --c-position: #ffa24c; --c-level: #d8b65a;
    --c-price: #d5dbe4;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1318; --panel: #161b22; --panel-2: #1d242d; --text: #e3e8ef; --muted: #8d98a8;
  --line: #2a323d; --accent: #6d9cff; --good: #5cc98a; --warn: #e0b04f; --bad: #ff7a70;
  --good-bg: #16301f; --warn-bg: #33290f; --bad-bg: #3a1714; --muted-bg: #232a33;
  --c-up: #4cc38a; --c-down: #ff6b61; --c-hist: #7d8794; --c-actual: #5b9dff; --c-forecast: #b48cf2;
  --c-entry: #5b9dff; --c-stop: #ff6b61; --c-target: #4cc38a; --c-position: #ffa24c; --c-level: #d8b65a;
  --c-price: #d5dbe4;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-wrap: anywhere;
}
h1, h2, h3 { margin: 0 0 8px; font-weight: 600; }
h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
h3 { font-size: 12px; color: var(--muted); margin-top: 12px; }
button { font: inherit; cursor: pointer; }
.muted { color: var(--muted); }

/* --- шапка --- */
.top {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px;
  padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; }
.spacer { flex: 1 1 auto; }
.clock { font-family: var(--mono); color: var(--muted); font-size: 12px; }
.fresh { font-size: 12px; color: var(--muted); }
.menu { display: none; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  border-radius: var(--radius); padding: 2px 10px; }
.logout { margin: 0; }
.hbtn { border: 1px solid var(--line); background: var(--panel-2); color: var(--text); border-radius: var(--radius);
  padding: 2px 12px; font-size: 13px; }
.hbtn[aria-pressed="true"] { border-color: var(--accent); background: var(--accent); color: #fff; }
.logout button { border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  border-radius: var(--radius); padding: 3px 12px; }
.pill { border-radius: 999px; padding: 2px 10px; font-size: 12px; white-space: nowrap;
  background: var(--muted-bg); color: var(--text); }
[data-tone="good"] { background: var(--good-bg); color: var(--good); }
[data-tone="warn"] { background: var(--warn-bg); color: var(--warn); }
[data-tone="bad"]  { background: var(--bad-bg);  color: var(--bad); }
[data-tone="muted"] { background: var(--muted-bg); color: var(--muted); }
/* ревизия 55: «к сведению» (сетап, модель пропустила бы) — не зелёный: зелёный
   остаётся за деньгами и свечами, цвет — за отклонениями */
[data-tone="info"] { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }

/* --- раскладка --- */
.layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: var(--side) minmax(0, 1fr);
  /* Центр — своей высоты, низ — сразу под ним; левая колонка длиннее обоих,
     и растянутая первая строка оставляла бы дыру между графиком и таблицами. */
  grid-template-rows: auto auto 1fr;
  grid-template-areas: "side pos" "side center" "side bottom";
  gap: 12px; padding: 12px 16px; min-width: 0;
}
/* ревизия 55 (W1 п. 2): от 1440 px позиции — правой колонкой */
@media (min-width: 1440px) {
  .layout { grid-template-columns: var(--side) minmax(0, 1fr) minmax(340px, 400px);
    grid-template-rows: auto 1fr; grid-template-areas: "side center pos" "side bottom pos"; }
  .positions-panel { position: sticky; top: 56px; max-height: calc(100vh - 110px); overflow-y: auto; }
}
.side { grid-area: side; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.center { grid-area: center; min-width: 0; align-self: start; }
.bottom { grid-area: bottom; min-width: 0; }
.card, .stub { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stub { color: var(--muted); height: 100%; display: flex; flex-direction: column; justify-content: center;
  align-items: center; text-align: center; border-style: dashed; min-height: 120px; }
.stub h2 { color: var(--text); }
body.stale .center, body.stale .side .card { opacity: .72; }
/* ревизия 55: демон молчит — зелёного нет нигде (ни у денег, ни у итогов): его никто не проверяет */
body.stale [data-tone="good"], body.stale .table-wrap tr[data-tone="good"] td { color: var(--muted) !important; }

/* --- вкладки сессий --- */
.tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.tab { border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: var(--radius); padding: 4px 10px; display: inline-flex; gap: 6px; align-items: center; max-width: 100%; }
.tab[aria-selected="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot[data-tone="good"] { background: var(--good); }
.dot[data-tone="warn"] { background: var(--warn); }
.dot[data-tone="bad"] { background: var(--bad); }

/* --- карточка сессии и строки «ключ: значение» --- */
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 3px 10px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.kv dd[data-tone] { background: none; font-weight: 600; }

/* --- монитор подключений --- */
.links { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.link { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; background: var(--panel-2); }
.link-head { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.link-name { font-weight: 600; }
.link-meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.link[data-open] { cursor: pointer; }
/* ревизия 55 (Б13): соединение в норме — одна строка */
.link.compact { padding: 4px 8px; background: none; }
.link.compact .link-name { font-weight: 500; }
.link-brief { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.link[data-open]:hover, .link[data-open]:focus-visible { border-color: var(--accent); outline: none; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card-head h2 { margin-bottom: 8px; }

/* --- бокс «инструменты» (ревизия 52) --- */
.instruments { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.instrument { width: 100%; text-align: left; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel-2); color: var(--text); padding: 6px 8px; display: flex; flex-direction: column; gap: 2px; }
.instrument:hover { border-color: var(--accent); }
.instrument[aria-current="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.inst-head { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; }
.inst-verdict { margin-left: auto; font-size: 12px; border-radius: 999px; padding: 0 8px; }
.inst-verdict:not([data-tone]) { color: var(--muted); }
.inst-meta { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.feed { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; font-size: 12px; }
.feed li { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 2px 8px; padding: 3px 0;
  border-bottom: 1px solid var(--line); }
.feed time { font-family: var(--mono); color: var(--muted); }
.feed .t-warn { color: var(--warn); }
.feed .t-good { color: var(--good); }
.feed .t-bad { color: var(--bad); }

/* --- центр: график (этап B) --- */
.chart-panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 10px 6px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.chart-bar { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; min-width: 0; }
.chart-session { font: inherit; padding: 3px 6px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel-2); color: var(--text); }
.itabs { display: flex; gap: 4px; overflow-x: auto; flex: 1 1 260px; min-width: 0; scrollbar-width: thin;
  padding-bottom: 2px; }
.itab { border: 1px solid var(--line); background: var(--panel-2); color: var(--text); border-radius: var(--radius);
  padding: 3px 10px; white-space: nowrap; flex: none; font-variant-numeric: tabular-nums; }
.itab[aria-selected="true"] { border-color: var(--accent); background: var(--panel); box-shadow: inset 0 0 0 1px var(--accent); }
.segs { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; flex: none; }
.seg { border: 0; border-right: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 3px 10px; }
.seg:last-child { border-right: 0; }
.seg[aria-pressed="true"] { background: var(--accent); color: #fff; }
.seg:disabled { color: var(--muted); cursor: not-allowed; opacity: .6; }
.layers-box { position: relative; flex: none; }
.layers-box summary { cursor: pointer; list-style: none; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 3px 10px; background: var(--panel-2); }
.layers-box summary::-webkit-details-marker { display: none; }
.layers-box[open] summary { border-color: var(--accent); }
.layers { position: absolute; right: 0; top: calc(100% + 4px); z-index: 15; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; display: grid; gap: 4px;
  min-width: 190px; box-shadow: 0 6px 18px rgba(0, 0, 0, .18); }
.layer { display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.swatch { width: 14px; height: 10px; border-radius: 2px; border: 2px solid var(--muted); flex: none; }
.layer-historical .swatch { border-color: var(--c-hist); }
.layer-actual .swatch { border-color: var(--c-actual); background: color-mix(in srgb, var(--c-actual) 20%, transparent); }
.layer-forecast .swatch { border-color: var(--c-forecast); border-style: dashed; }
.layer-levels .swatch { border: 0; border-top: 2px dotted var(--c-level); height: 0; }
.layer-plan .swatch { border: 0; border-top: 2px dashed var(--c-entry); height: 0; }
.layer-position .swatch { border-color: var(--c-position); border-radius: 50%; width: 10px; }
.layer-trades .swatch { border: 0; border-top: 2px solid var(--c-up); height: 0; }
.chart-meta { display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 12px; font-variant-numeric: tabular-nums; }
/* Высота графика — от окна, а не от соседней колонки: колонка слева длинная,
   и растянутый по ней график уходил бы за нижний край экрана. */
.chart-plot { flex: none; height: clamp(360px, calc(100vh - 230px), 1100px); min-width: 0; }
.chart-empty { height: 100%; display: flex; align-items: center; justify-content: center; color: var(--muted);
  border: 1px dashed var(--line); border-radius: var(--radius); padding: 16px; text-align: center; }
.chart-note p { margin: 2px 0; font-size: 12px; }
.warn-line { color: var(--bad); }
.stock-panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px;
  min-width: 0; }

/* --- вью центра (ревизия 52): рынок, инструмент, шлюзы --- */
.view-panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px;
  min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.view-panel h3 { margin: 12px 0 2px; }
.view-head { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }
.view-title { margin: 0; text-transform: none; letter-spacing: 0; color: var(--text); font-size: 16px; }
.kv-wide { grid-template-columns: max-content minmax(0, 1fr); max-width: 720px; }
.gw-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; background: var(--panel-2);
  display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.gw-card .table-wrap { background: var(--panel); }
.gw-title { margin: 0; font-size: 14px; color: var(--text); }
.gw-sub { margin-top: 6px; padding-top: 8px; border-top: 1px solid var(--line); }
.link-button.sym { font-weight: 600; }
.table-wrap.market td:nth-last-child(2) { white-space: normal; min-width: 180px; }
.link-button.close-pos:disabled { color: var(--muted); text-decoration: none; cursor: not-allowed; }
.levels { display: flex; flex-direction: column; line-height: 1.3; }
.confirm-summary { padding: 6px 8px; border-radius: var(--radius); background: var(--panel-2); border: 1px solid var(--line);
  font-variant-numeric: tabular-nums; font-weight: 600; }
.stock-frame-box, .stock-bar { scroll-margin-top: 56px; }

/* --- ревизия 54: сводка системы и виджет модели --- */
.model-slot:not([hidden]) { margin-top: 8px; }
.digest-line { margin: 2px 0 4px; font-weight: 600; }
.model-actions { flex-wrap: wrap; margin: 6px 0 2px; }
.fi { display: flex; flex-direction: column; gap: 3px; max-width: 760px; }
.fi-row { display: grid; grid-template-columns: minmax(96px, 150px) minmax(0, 1fr) 64px; gap: 8px; align-items: center;
  font-size: 12.5px; font-variant-numeric: tabular-nums; }
.fi-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 12px; }
.fi-track { height: 12px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.fi-bar { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.fi-val { text-align: right; color: var(--muted); }
.hist { display: flex; align-items: flex-end; gap: 3px; height: 140px; max-width: 760px; padding: 4px 0 0;
  border-bottom: 1px solid var(--line); }
.hist-col { flex: 1 1 0; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end;
  align-items: stretch; position: relative; }
.hist-zero { border-left: 2px dashed var(--muted); padding-left: 1px; }
.hist-bar { display: block; background: var(--muted); border-radius: 2px 2px 0 0; min-height: 0; }
.hist-bar[data-tone="good"] { background: var(--good); }
.hist-n { font-size: 10.5px; color: var(--muted); text-align: center; line-height: 1.2; font-variant-numeric: tabular-nums; }
.hist-axis { display: flex; justify-content: space-between; max-width: 760px; font-size: 11.5px; color: var(--muted); }
.table-wrap.expected td:nth-child(4), .table-wrap.expected td:nth-child(5) { white-space: normal; min-width: 200px; }
.table-wrap.digest-market td:last-child { white-space: normal; min-width: 200px; }

/* --- низ: вкладки и таблицы (этап C) --- */
.bottom { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px;
  min-width: 0; align-self: start; scroll-margin-top: 56px; }
.btabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 8px;
  scrollbar-width: thin; }
.btab { border: 0; border-bottom: 2px solid transparent; background: none; color: var(--muted); padding: 5px 10px;
  white-space: nowrap; flex: none; }
.btab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.bpanel { min-width: 0; }
.bpanel h3 { margin: 12px 0 4px; }
.table-wrap { overflow-x: auto; max-width: 100%; border: 1px solid var(--line); border-radius: var(--radius); }
.table-wrap table { border-collapse: collapse; width: 100%; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.table-wrap th { text-align: left; font-weight: 600; color: var(--muted); background: var(--panel-2);
  padding: 5px 8px; white-space: nowrap; position: sticky; top: 0; }
.table-wrap td { padding: 4px 8px; border-top: 1px solid var(--line); white-space: nowrap; }
.table-wrap tr[data-tone], .table-wrap td[data-tone] { background: none; }
.table-wrap tr[data-tone="good"] td, .table-wrap td[data-tone="good"] { color: var(--good); }
.table-wrap tr[data-tone="bad"] td, .table-wrap td[data-tone="bad"] { color: var(--bad); }
.table-wrap tr[data-tone="warn"] td, .table-wrap td[data-tone="warn"] { color: var(--warn); }
.table-wrap tr[data-tone="muted"] td, .table-wrap td[data-tone="muted"] { color: var(--muted); }
.table-wrap tr[data-tone="info"] td, .table-wrap td[data-tone="info"] { color: var(--accent); }
/* ревизия 55 (Б7): числа — вправо, цифры равной ширины */
.table-wrap th.num, .table-wrap td.num { text-align: right; font-variant-numeric: tabular-nums; }
.code { text-decoration: underline dotted var(--line); text-underline-offset: 3px; }
.act.close-pos { padding: 2px 10px; color: var(--bad); white-space: nowrap; }
.act.close-pos:disabled { color: var(--muted); }
.with-total tbody tr:last-child td { font-weight: 600; border-top: 2px solid var(--line); }
.journal td:last-child { white-space: normal; min-width: 240px; }
.row-actions { display: flex; gap: 8px; }
.tnote { margin: 4px 0; font-size: 12px; }
.t-muted { color: var(--muted); }
.t-warn { color: var(--warn); }
.t-bad { color: var(--bad); }
.small { font-size: 12px; }
.field { font: inherit; padding: 3px 6px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel-2); color: var(--text); max-width: 100%; }
.journal-bar, .train-form, .stock-bar { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center;
  margin: 4px 0 8px; }
.stock-bar h2 { margin: 0; flex: 1 1 auto; }
.joblog pre, .stock-report pre { margin: 4px 0 0; padding: 8px; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius); max-height: 260px; overflow: auto; font: 12px/1.35 var(--mono); white-space: pre-wrap; }
.offer { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; padding: 8px 10px; margin: 0 0 8px;
  border-radius: var(--radius); border: 1px solid var(--line); }
.offer[data-tone] { color: var(--text); }

/* --- действия: кнопки, окно подтверждения, сообщения --- */
.act { border: 1px solid var(--line); background: var(--panel-2); color: var(--text); border-radius: var(--radius);
  padding: 4px 12px; }
.act:hover:not(:disabled) { border-color: var(--accent); }
.act:disabled { color: var(--muted); cursor: not-allowed; opacity: .6; }
.act.danger { color: var(--bad); }
.act-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.link-button { border: 0; background: none; color: var(--accent); padding: 0; text-decoration: underline; }
.link-button.danger { color: var(--bad); }
body.acting .act, body.acting .link-button { pointer-events: none; opacity: .6; }
dialog.confirm { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--text);
  width: min(560px, calc(100vw - 32px)); padding: 16px; box-shadow: 0 10px 40px rgba(0, 0, 0, .35); }
dialog.confirm::backdrop { background: rgba(0, 0, 0, .45); }
dialog.confirm h2 { text-transform: none; letter-spacing: 0; color: var(--text); font-size: 16px; }
dialog.confirm p { margin: 6px 0; }
pre.command { margin: 4px 0 12px; padding: 10px; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius); font: 13px/1.4 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.confirm-buttons { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.confirm-buttons button { border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  border-radius: var(--radius); padding: 6px 14px; }
.confirm-buttons .danger-fill { background: var(--bad); border-color: var(--bad); color: #fff; }
.toast { position: fixed; right: 16px; bottom: 16px; z-index: 40; display: flex; flex-direction: column; gap: 6px;
  max-width: min(460px, calc(100vw - 32px)); }
.toast-item { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 32px 8px 10px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); position: relative; font-size: 13px; }
.toast-item[data-tone="good"] { border-color: var(--good); background: var(--panel); color: var(--text); }
.toast-item[data-tone="bad"] { border-color: var(--bad); background: var(--panel); color: var(--text); }
.toast-item[data-tone="warn"] { border-color: var(--warn); background: var(--panel); color: var(--text); }
.toast-close { position: absolute; right: 6px; top: 4px; border: 0; background: none; color: var(--muted); font-size: 16px; }

/* --- режим исполнения (этап D): карточка сессии и строка сводки позиций --- */
.exec-slot:not(:empty) { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); }
.exec { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.exec-head { margin: 0; }
.exec-segs { display: flex; flex-wrap: wrap; max-width: 100%; }
.exec-segs .seg { flex: 1 1 auto; padding: 4px 8px; }
.exec-segs .seg[aria-pressed="true"]:disabled { opacity: 1; color: #fff; cursor: default; }
.exec-lines { display: flex; flex-direction: column; gap: 2px; font-size: 12.5px; }
.exec-pending { border-radius: var(--radius); padding: 1px 6px; align-self: flex-start; }
.exec-summary { display: flex; flex-direction: column; gap: 6px; margin: 4px 0 8px; }
.exec-row { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 6px 8px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2); }
.exec-row .exec-segs { flex: 0 1 auto; }
.exec-row .exec-lines { flex-direction: row; flex-wrap: wrap; gap: 2px 10px; }
.exec-title { font-weight: 600; font-size: 12.5px; }
.confirm-note { padding: 4px 8px; border-radius: var(--radius); }
.confirm-check { display: flex; gap: 8px; align-items: center; margin: 8px 0; font-weight: 600; }
.confirm-check input { width: 18px; height: 18px; margin: 0; }
.toast-item { white-space: pre-line; }

/* --- акции (этап C) --- */
.stock-head p { margin: 2px 0; font-size: 12.5px; }
.stock-state { margin: 0 0 8px; padding: 3px 8px; border-radius: var(--radius); display: inline-block; }
.stock-frame { width: 100%; height: clamp(420px, 78vh, 1200px); border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); }
/* ревизия 55 (Б12): страница дня — белая сама по себе (script/chart/stock_page.py);
   в тёмной теме фрейм переворачивается по яркости, оттенки сохраняются */
:root[data-theme="dark"] .stock-frame { filter: invert(0.9) hue-rotate(180deg); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .stock-frame { filter: invert(0.9) hue-rotate(180deg); }
}
.stock-report { margin-top: 10px; }
.stock-report summary { cursor: pointer; color: var(--muted); }

/* --- подвал: строка состояния источников (ревизия 55, W1 п. 3) --- */
.foot { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 5px 16px; color: var(--muted);
  font-size: 12px; border-top: 1px solid var(--line); background: var(--panel); position: sticky; bottom: 0; z-index: 15; }
.sb { border-radius: 999px; padding: 1px 8px; background: var(--muted-bg); white-space: nowrap; }
.sb[data-tone="bad"], .sb[data-tone="warn"] { font-weight: 600; }
[data-tone="stale"] { background: var(--muted-bg); color: var(--muted); font-style: italic; }
.foot-meta { margin-left: auto; }

/* --- шапка: полоса итога (ревизия 55, W1 п. 1) --- */
.strip { display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; }
.strip-item { border-radius: var(--radius); padding: 2px 8px; font-size: 13px; white-space: nowrap;
  font-variant-numeric: tabular-nums; border: 1px solid var(--line); background: var(--panel-2); }
.strip-item[data-tone="good"] { color: var(--good); background: var(--panel-2); }
.strip-item[data-tone="bad"] { color: var(--bad); background: var(--panel-2); }
.s-state { font-weight: 600; font-size: 13px; }
.s-state[data-tone="muted"] { color: var(--text); }
.popover { position: fixed; right: 16px; top: 52px; z-index: 35; width: min(420px, calc(100vw - 32px));
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .3); max-height: calc(100vh - 80px); overflow-y: auto; }
.popover h2 { text-transform: none; letter-spacing: 0; color: var(--text); font-size: 15px; }
.signals-kinds { display: flex; flex-direction: column; gap: 4px; margin: 4px 0 8px; }
.check { display: flex; gap: 8px; align-items: center; min-height: 28px; }
.check input { width: 18px; height: 18px; margin: 0; }
.t-info { color: var(--accent); }

/* --- позиции всегда на экране (ревизия 55, W1 п. 2) --- */
.positions-panel { grid-area: pos; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 10px; min-width: 0; align-self: start; scroll-margin-top: 56px; }
.pos-top { display: flex; align-items: baseline; gap: 8px; justify-content: space-between; }
.pos-title { margin: 0 0 4px; }
.pos-note { font-size: 12px; }
.pos-note[data-tone="stale"] { background: none; }
.pos-grid { display: flex; flex-direction: column; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.pos-row { display: grid; align-items: center; gap: 2px 8px; padding: 3px 0; border-top: 1px solid var(--line); }
.pos-head { color: var(--muted); font-weight: 600; border-top: 0; }
.pc { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pc-qty, .pc-entry, .pc-stop, .pc-now, .pc-pnl, .pc-r, .pc-risk, .pc-close { text-align: right; }
.pc[data-tone="good"] { color: var(--good); background: none; }
.pc[data-tone="bad"] { color: var(--bad); background: none; }
.pc.flash { animation: flash 1s ease-out; }
@keyframes flash { from { background: color-mix(in srgb, var(--accent) 30%, transparent); } to { background: transparent; } }
.pos-total { margin-top: 4px; padding-top: 4px; border-top: 2px solid var(--line); font-weight: 600;
  font-variant-numeric: tabular-nums; }
/* полоса над графиком (уже 1440 px): все колонки в строку */
.pos-row { grid-template-columns: 90px 70px 64px 64px 74px 74px 74px 80px 64px 84px minmax(0, 1fr); }
.pos-row:not(:has(.pc-session)) { grid-template-columns: 70px 64px 64px 74px 74px 74px 80px 64px 84px minmax(0, 1fr); }
.pos-row:not(:has(.pc-close)) { grid-template-columns: 90px 70px 64px 64px 74px 74px 74px 80px 64px 84px; }
.pos-row:not(:has(.pc-session)):not(:has(.pc-close)) { grid-template-columns: 70px 64px 64px 74px 74px 74px 80px 64px 84px; }
/* правая колонка: три строки на позицию */
@media (min-width: 1440px) {
  .pos-row, .pos-row:not(:has(.pc-session)), .pos-row:not(:has(.pc-close)),
  .pos-row:not(:has(.pc-session)):not(:has(.pc-close)) {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: "symbol side qty pnl" "session stop now r" "entry risk close close"; padding: 5px 0; }
  .pos-head { display: none; }
  .pc-symbol { grid-area: symbol; } .pc-side { grid-area: side; } .pc-qty { grid-area: qty; }
  .pc-pnl { grid-area: pnl; font-weight: 600; } .pc-session { grid-area: session; color: var(--muted); }
  .pc-stop { grid-area: stop; } .pc-now { grid-area: now; } .pc-r { grid-area: r; }
  .pc-entry { grid-area: entry; text-align: left; } .pc-risk { grid-area: risk; } .pc-close { grid-area: close; }
  .pc-entry::before { content: "вход "; color: var(--muted); } .pc-stop::before { content: "стоп "; color: var(--muted); }
  .pc-now::before { content: "цена "; color: var(--muted); } .pc-risk::before { content: "риск "; color: var(--muted); }
}

/* --- дежурный экран телефона (ревизия 55, W1 п. 5) --- */
.duty { display: none; }

/* --- вход --- */
.login-body { justify-content: center; align-items: center; padding: 16px; }
.login { width: 100%; max-width: 360px; }
.login-form { display: flex; flex-direction: column; gap: 10px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.login-form input[type="password"] { font: inherit; padding: 8px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--bg); color: var(--text); width: 100%; }
.login-form button { padding: 8px; border: 0; border-radius: var(--radius); background: var(--accent); color: #fff; }
.login-note { margin: 0; color: var(--bad); }
.login-foot { margin: 0; color: var(--muted); font-size: 12px; }

/* --- телефон: колонка выдвижная, от 360 px без горизонтальной прокрутки --- */
@media (max-width: 820px) {
  .menu { display: inline-block; }
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto; grid-template-areas: "duty" "pos" "center" "bottom";
    padding: 8px 16px; }
  /* шапка — одна строка: меню, имя, состояние, выход; числа — на дежурном экране */
  .top { flex-wrap: nowrap; }
  .strip, #h-market, #h-digest, #h-theme, #h-signals, .clock, .spacer { display: none; }
  .s-state { overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1 1 auto; }
  .duty { display: flex; grid-area: duty; flex-direction: column; gap: 2px; background: var(--panel);
    border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
  .duty-state { font-size: 17px; font-weight: 700; padding: 2px 6px; border-radius: var(--radius); margin-bottom: 4px; }
  .duty-state[data-tone="muted"] { background: none; color: var(--text); }
  .duty-row { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 0 8px; align-items: baseline;
    padding: 3px 0; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
  .duty-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
  .duty-value { font-size: 18px; font-weight: 700; }
  .duty-value[data-tone], .duty-extra[data-tone] { background: none; }
  .duty-value[data-tone="good"] { color: var(--good); } .duty-value[data-tone="bad"] { color: var(--bad); }
  .duty-extra { grid-column: 2; font-size: 13px; color: var(--muted); }
  .duty-extra[data-tone="good"] { color: var(--good); } .duty-extra[data-tone="bad"] { color: var(--bad); }
  .duty-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 8px; }
  .duty-button { min-height: 44px; font-weight: 600; }
  /* позиции — карточками */
  .pos-head { display: none; }
  .pos-row, .pos-row:not(:has(.pc-session)), .pos-row:not(:has(.pc-close)),
  .pos-row:not(:has(.pc-session)):not(:has(.pc-close)) {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: "symbol side qty" "pnl r session" "entry stop now" "risk close close";
    padding: 8px 0; gap: 4px 8px; }
  .pc-symbol { grid-area: symbol; font-size: 15px; } .pc-side { grid-area: side; } .pc-qty { grid-area: qty; }
  .pc-pnl { grid-area: pnl; font-size: 16px; font-weight: 700; text-align: left; } .pc-r { grid-area: r; font-size: 15px; }
  .pc-session { grid-area: session; color: var(--muted); text-align: right; }
  .pc-entry { grid-area: entry; text-align: left; } .pc-stop { grid-area: stop; } .pc-now { grid-area: now; }
  .pc-risk { grid-area: risk; text-align: left; } .pc-close { grid-area: close; }
  .pc-entry::before { content: "вход "; color: var(--muted); } .pc-stop::before { content: "стоп "; color: var(--muted); }
  .pc-now::before { content: "цена "; color: var(--muted); } .pc-risk::before { content: "риск "; color: var(--muted); }
  .pc-close .act { min-height: 44px; min-width: 44px; width: 100%; }
  .foot { position: static; }
  .foot-meta { margin-left: 0; }
  .side {
    position: fixed; top: 0; left: 0; bottom: 0; width: min(88vw, 320px); z-index: 30;
    background: var(--bg); padding: 12px; overflow-y: auto;
    transform: translateX(-105%); transition: transform .18s ease-out;
  }
  .side.open { transform: none; box-shadow: 0 0 24px rgba(0, 0, 0, .35); }
  .scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 25; }
  .top { padding: 6px 12px; }
  .clock { order: 10; width: 100%; }
  .chart-panel { padding: 6px; }
  .chart-plot { height: 62vh; min-height: 320px; }
  .itabs { flex-basis: 100%; order: 1; }
  .layers { right: auto; left: 0; }
  .bottom { padding: 6px; }
  .act-grid { grid-template-columns: 1fr 1fr; }
  .stock-frame { height: 70vh; }
  .view-panel { padding: 6px; }
  /* ревизия 54: на телефоне «ключ: значение» сводки и модели — в одну колонку */
  #digest-panel .kv, #model-panel .kv { grid-template-columns: minmax(0, 1fr); gap: 0; }
  #digest-panel .kv dt, #model-panel .kv dt { font-size: 12px; margin-top: 6px; }
  .fi-row { grid-template-columns: minmax(84px, 120px) minmax(0, 1fr) 52px; gap: 6px; }
  .gw-card { padding: 8px; }
}
@media (prefers-reduced-motion: reduce) { .side { transition: none; } }

/* === ревизия 57: телефон (≤ 820 px) — вкладки низа, карточки таблиц, цели касания === */
/* Десктоп (ширины > 820 px) не затрагивается: все правила — только в этом блоке,
   плюс невидимый атрибут data-label на ячейках (util.js). */
@media (max-width: 820px) {
  /* --- шапка: имя и «Выход» не переносятся, состояние ужимается с многоточием --- */
  .top .brand { flex: none; white-space: nowrap; }
  .logout button { white-space: nowrap; }

  /* --- 1. Нижние вкладки: липкая панель у нижнего края, любой вид — в одно касание --- */
  .btabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 18; margin: 0;
    border-top: 1px solid var(--line); border-bottom: 0;
    background: var(--panel); box-shadow: 0 -2px 10px rgba(0, 0, 0, .14);
    padding: 4px 8px calc(4px + env(safe-area-inset-bottom)); gap: 6px;
    justify-content: flex-start;
  }
  .btab {
    flex: 1 1 0; min-width: 0; min-height: 44px; border: 1px solid transparent; border-bottom: 0;
    border-radius: var(--radius); font-size: 13px; padding: 6px 8px; color: var(--muted);
    text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .btab[aria-selected="true"] {
    color: var(--text); border-color: var(--line); border-bottom: 0;
    background: var(--panel-2); font-weight: 600;
  }
  /* чтобы липкая панель не закрывала подвал — отодвигаем его содержимое выше */
  .foot { padding-bottom: calc(8px + 48px + env(safe-area-inset-bottom)); }

  /* --- 2 + 4. Тяжёлые таблицы — карточки «по строке на запись» (как позиции) --- */
  .table-wrap { overflow-x: visible; border: 0; border-radius: 0; background: none; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: auto; }
  .table-wrap thead { display: none; }
  .table-wrap tr {
    border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel);
    margin-bottom: 8px; padding: 4px 10px;
  }
  .table-wrap tr:last-child { margin-bottom: 0; }
  .table-wrap td {
    display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline;
    gap: 2px 12px; border-top: 0; padding: 5px 0; white-space: normal; text-align: right; min-width: 0;
  }
  .table-wrap td + td { border-top: 1px dashed var(--line); }
  .table-wrap td::before {
    content: attr(data-label); color: var(--muted); font-weight: 600; text-align: left;
    white-space: normal; flex: 0 1 auto; margin-right: auto;
  }
  .table-wrap td[data-label=""]::before, .table-wrap td:not([data-label])::before { content: none; }
  .table-wrap td .act, .table-wrap td .link-button { margin-left: auto; }
  /* строка итога статистики — выделенная карточка */
  .with-total tbody tr:last-child { border-width: 2px; }
  .with-total tbody tr:last-child td { border-top: 1px dashed var(--line); font-weight: 600; }
  .with-total tbody tr:last-child td:first-child { border-top: 0; }
  /* ширины отдельных ячеек из десктопных правил карточке не нужны */
  .table-wrap.market td:nth-last-child(2), .table-wrap.expected td:nth-child(4),
  .table-wrap.expected td:nth-child(5), .table-wrap.digest-market td:last-child,
  .journal td:last-child { min-width: 0; }

  /* --- 3. Панель графика: кнопки под палец, высота разумная --- */
  .chart-plot { height: 54vh; min-height: 300px; }
  .chart-bar { gap: 8px 8px; }
  .itab, .seg, .layers-box summary, .chart-session { min-height: 44px; display: inline-flex; align-items: center; }
  .segs { align-items: stretch; }
  .segs .seg { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; }
  .chart-meta, .chart-note p { font-size: 12.5px; }

  /* --- 5. Виджет модели: важность признаков и гистограмма p --- */
  .fi { max-width: none; }
  .hist, .hist-axis { max-width: none; }
  .hist { overflow-x: auto; }
  .hist-col { min-width: 24px; }
  .hist-n { font-size: 12px; }
  .hist-axis { font-size: 12px; }

  /* --- 6. Цели касания ≥ 44 px и шрифт ≥ 12 px для всего нажимаемого --- */
  .menu { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px;
    font-size: 20px; padding: 2px 6px; }
  .tab { min-height: 44px; }
  .act, .field, .hbtn, .chart-session, .link-button.sym { min-height: 44px; }
  .act-grid .act, .journal-bar .act, .train-form .act, .stock-bar .act, .model-actions .act { min-height: 44px; }
  .check { min-height: 44px; }
  .confirm-buttons button { min-height: 44px; }
  .instrument { padding: 8px; }
  .small, .link-meta, .inst-meta, .pos-note, .foot { font-size: 12px; }

  /* --- 7. Боковой отступ и запрет горизонтальной прокрутки страницы --- */
  .layout { padding-left: 16px; padding-right: 16px; }
  .view-panel, .chart-panel, .bottom, .stock-panel, .positions-panel, .duty { max-width: 100%; }
  .stock-frame { width: 100%; }
}
