/* tg-trader admin — dark, dense, data-first (design.md §12 base + components). */
:root {
  --bg:#0d1117; --panel:#161b22; --panel-2:#11161d;
  --line:#21262d; --line-strong:#30363d;
  --fg:#c9d1d9; --muted:#8b949e; --dim:#6e7681;
  --pos:#3fb950; --neg:#f85149; --zero:#8b949e; --warn:#d29922;
  --pos-soft:#56d364; --neg-soft:#e5747a;
  --is:#388bfd; --oos:#db8a2b;
  --mom:#58a6ff; --mrv:#bc8cff;
  --accent:#1f6feb; --accent-hover:#2a7bff;
  --r-sm:6px; --r-md:8px;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, "Courier New", monospace;
}
* { box-sizing:border-box; }
body {
  margin:0; padding:0; background:var(--bg); color:var(--fg);
  font:14px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color:var(--mom); text-decoration:none; }
a:hover { text-decoration:underline; }
h1 { font-size:20px; font-weight:600; margin:0 0 6px; }
h2 { font-size:15px; font-weight:600; margin:28px 0 8px; }
h2 .n { color:var(--muted); font-weight:400; }
.meta { color:var(--muted); font-size:13px; margin-bottom:4px; max-width:70em; }
.meta b { color:var(--fg); font-weight:600; }
.sub, .legend { color:var(--dim); font-size:12px; margin:0 0 10px; }
code { font-family:var(--mono); color:var(--fg); }

/* layout: top bar + content column */
.topbar {
  display:flex; align-items:center; gap:18px;
  padding:10px 24px; background:var(--panel);
  border-bottom:1px solid var(--line-strong);
}
.brand { font-weight:600; letter-spacing:.02em; color:var(--fg); }
.nav { display:flex; gap:14px; flex:1; }
.nav a { color:var(--muted); font-size:13px; padding:2px 0; }
.nav a:hover { color:var(--fg); text-decoration:none; }
.nav a.active { color:var(--fg); border-bottom:2px solid var(--accent); }
.topbar form { margin:0; }
main { padding:24px; max-width:1400px; }
/* The «Трейдинг» card carries the widest table (14-col active positions +
   editable «Канал» picker); give it more room than the default cap — and a
   narrower gutter than the rest of the site — so it fits a laptop window
   without the horizontal scroll (see .pos-tbl). Narrow viewports still fall
   back to the table-wrap's scroll. */
main[data-nav="traders"] { max-width:1760px; padding:24px 12px; }

/* flashes */
.flash { border-radius:var(--r-sm); padding:8px 12px; margin:0 0 14px;
  font-size:13px; border-left:2px solid var(--line-strong); background:var(--panel-2); }
.flash.ok  { border-left-color:var(--pos); color:var(--pos-soft); }
.flash.err { border-left-color:var(--neg); color:var(--neg-soft); background:#2a210f; }

/* tables (design.md §6) */
.table-wrap { border:1px solid var(--line); border-radius:var(--r-md);
  background:var(--panel-2); overflow:auto; }
/* a nested detail table (e.g. «Сводная» → per-channel positions) sizes to its own
   content instead of stretching to the full card width, so its columns pack left rather
   than gaping apart; overflow:auto still scrolls it when it is wider than the cell. */
.table-wrap--inline { width:fit-content; max-width:100%; }
.table-wrap--inline table { width:auto; }
table { border-collapse:collapse; width:100%; font-size:12.5px; }
thead th { position:sticky; top:0; z-index:2; background:var(--panel);
  color:var(--muted); font-weight:600; text-align:right; white-space:nowrap;
  padding:6px 10px; border-bottom:1px solid var(--line-strong); }
tbody td { padding:5px 10px; border-bottom:1px solid var(--line);
  white-space:nowrap; text-align:right; vertical-align:middle; }
tbody tr:hover td { background:var(--panel); }
tr.active-row td { background:#16243b; }
tr.active-row td:first-child { box-shadow:inset 3px 0 0 var(--is); }
td.t, th.t { text-align:left; }
/* Totals row, pinned at the TOP of the body in every table that has one («Сводная»,
   both position tables, each channel disclosure): a long list must not make the reader
   scroll to its own total. Footer-like emphasis, with a thicker rule BELOW to separate
   it from the data rows. No tfoot rules live here — nothing renders one any more. */
tr.sum-total td { font-weight:600; border-bottom:2px solid var(--line-strong); }
tr.sum-total td.t { color:var(--muted); }
/* sortable column header: reads as the muted header text, accents on hover */
th .sort-link { color:inherit; white-space:nowrap; }
th .sort-link:hover { color:var(--accent); }
th .sort-link .arrow { font-size:10px; }
th .sort-link .arrow.off { color:var(--dim); }
.num { font-family:var(--mono); font-variant-numeric:tabular-nums; font-feature-settings:"tnum"; }
.muted { color:var(--dim); }
.key { font-weight:600; }
/* «Символ / сторона» — one cell, two facts: the ticker is meaningless without the
   side, and splitting them cost a column in the widest table on the site. */
.sym { display:inline-flex; gap:7px; align-items:baseline; }
/* Two timestamps stacked in one cell («Закрыта / открыта»): the close leads (it is
   the feed's order), the open sits under it as reference. Overrides the default
   single-line row rhythm — used only where a column carries a genuine pair. */
.stack { line-height:1.25; }
.stack .b { font-size:11px; color:var(--dim); }

/* Таблицы позиций («Активные» / «Закрытые» / раскрывашка канала в «Сводной») —
   самые широкие на сайте: 14 колонок активных позиций не влезали в карточку на
   ноутбучном окне (~1390 px) и уезжали в горизонтальный скролл. Плотный режим
   (мельче шрифт, паддинги, бейджи + узкий select канала) снимает ~260 px и
   укладывает таблицу в карточку; на узких окнах скролл остаётся как запас. */
.pos-tbl { font-size:12px; }
.pos-tbl thead th, .pos-tbl tbody td { padding:5px 6px; }
.pos-tbl .badge { font-size:10px; letter-spacing:.02em; padding:1px 5px; }
.pos-tbl .chan-pick select.cell-input { max-width:16em; }
/* «Сменить» ужат до иконки — подпись повторялась в каждой строке; ширину забрал select. */
.chan-pick .chan-apply { padding:3px 7px; line-height:1.25; }
/* У закрытых колонок меньше и запас ширины есть — канал показываем шире (названия
   каналов длинные, а в закрытой таблице это единственный текстовый признак источника). */
.pos-tbl--closed .chan-pick select.cell-input { max-width:20em; }
/* Колонка-поглотитель: table{width:100%} размазывает лишнюю ширину по ВСЕМ
   колонкам (у закрытых позиций содержимое узкое → всё разъезжается, а даты
   отрывались от своей шапки). width:100% на одной колонке отдаёт весь запас ей
   одной, остальные пакуются по содержимому. */
.pos-tbl th.grow { width:100%; }

/* badges */
.badge { display:inline-block; text-transform:uppercase; font-size:11px;
  letter-spacing:.04em; padding:1px 6px; border-radius:var(--r-sm);
  border:1px solid var(--line-strong); }
.badge--ok    { color:var(--pos); border-color:var(--pos); }
.badge--bad   { color:var(--neg); border-color:var(--neg); }
.badge--warn  { color:var(--warn); border-color:var(--warn); }
.badge--muted { color:var(--muted); }
.badge--dim   { color:var(--dim); }
.mark.good { color:var(--pos); } .mark.bad { color:var(--neg); }

/* cards / key-value */
.card { border:1px solid var(--line); border-radius:var(--r-md);
  background:var(--panel-2); padding:14px 16px; margin:0 0 16px; max-width:680px; }
.kv { display:grid; grid-template-columns:max-content 1fr; gap:4px 16px; font-size:13px; }
.kv dt { color:var(--muted); }
.kv dd { margin:0; color:var(--fg); }

/* forms */
.controls { display:flex; flex-wrap:wrap; gap:8px; align-items:center; margin:12px 0; }
form.inline { display:inline; margin:0; }
label { font-size:12px; color:var(--muted); display:block; margin:8px 0 2px; }
input[type=text], input[type=password], input[type=number], select {
  background:var(--panel-2); color:var(--fg);
  border:1px solid var(--line-strong); border-radius:var(--r-sm);
  padding:6px 10px; font-size:13px; font-family:inherit; min-width:220px; }
input:focus, select:focus { outline:none; border-color:var(--accent); }
/* compact input for editable table cells (per-channel trading params) */
input.cell-input { min-width:0; width:6.5em; padding:3px 6px; font-size:12px; text-align:right; }
/* compact <select> for a table cell (channel «Модель»): the input.cell-input rule above
   doesn't reach <select>, and the .chan-pick variant is scoped to that wrapper, so without
   this the select would inherit the 220px form min-width and blow out the column. */
select.cell-input { min-width:0; width:auto; max-width:9em; padding:3px 6px; font-size:12px; }
/* editable «Канал» cell: compact select + «Сменить» button on one line. Own display
   rule (not form.inline) so the flex layout actually applies; margin:0 replaces the
   form default; vertical-align keeps it centred in the row. */
.chan-pick { display:inline-flex; gap:4px; align-items:center; margin:0; vertical-align:middle; max-width:100%; }
.chan-pick select.cell-input { min-width:0; width:auto; max-width:10em; padding:3px 6px; font-size:12px;
  text-overflow:ellipsis; }
.form-row { display:flex; flex-wrap:wrap; gap:14px; align-items:flex-end; }
.form-field { display:flex; flex-direction:column; }
.hint { color:var(--dim); font-size:12px; margin-top:6px; }
/* channel hints editor (в раскрывашке «Отслеживаемые»): the project has no other
   <textarea>, and the global input rule lists only input[type=…]/select, so without an
   explicit rule the field renders as a light system box on the dark theme. Tokens from
   design.md §12 (--panel-2 is named the textarea surface). */
.hints-form { margin-top:12px; max-width:640px; }
.code-out { width:100%; resize:vertical; padding:8px 10px; box-sizing:border-box;
  background:var(--panel-2); color:var(--fg); border:1px solid var(--line-strong);
  border-radius:var(--r-md); font:12.5px/1.5 var(--mono); font-variant-numeric:tabular-nums; }
.code-out:focus { outline:none; border-color:var(--accent); }

/* buttons */
button, .btn { background:var(--panel); color:var(--fg); border:1px solid var(--line-strong);
  border-radius:var(--r-sm); padding:6px 12px; font-size:13px; cursor:pointer; font-family:inherit; }
button:hover, .btn:hover { background:var(--line); }
button.primary { background:var(--accent); border-color:var(--accent); color:#fff; font-weight:600; }
button.primary:hover { background:var(--accent-hover); }
button.danger { color:var(--neg); border-color:var(--neg); }
button.danger:hover { background:#2a210f; }
button.small { padding:3px 8px; font-size:12px; }

/* callout */
.callout-warn { color:var(--warn); font-size:12px; line-height:1.6; white-space:pre-wrap;
  border-left:2px solid var(--warn); padding:8px 12px; background:#2a210f;
  border-radius:0 var(--r-sm) var(--r-sm) 0; font-family:var(--mono); margin:8px 0; }

/* login */
.login-wrap { max-width:340px; margin:8vh auto 0; }
.login-wrap input { width:100%; min-width:0; }
.login-wrap button { width:100%; margin-top:14px; }

/* expandable dialog rows (Диалоги) — click a row to reveal a detail spoiler.
   The caret lives in a real <button> (caret-btn): the keyboard/AT-facing
   control that owns aria-expanded; the row click is a mouse convenience and
   carries no ARIA role. */
tr.dlg-row { cursor:pointer; }
tr.dlg-row.expanded td { background:#16243b; }
tr.dlg-row.expanded td:first-child { box-shadow:inset 3px 0 0 var(--is); }
.caret-btn { background:none; border:0; padding:0; margin:0; cursor:pointer;
  color:inherit; font:inherit; line-height:1; vertical-align:baseline; }
.caret-btn:focus-visible { outline:2px solid var(--accent); outline-offset:1px;
  border-radius:var(--r-sm); }
.caret { display:inline-block; width:1em; margin-right:4px; color:var(--dim);
  font-size:10px; transition:transform .12s ease; }
tr.dlg-row.expanded .caret { transform:rotate(90deg); color:var(--mom); }
/* Direct child only (`> td`): the detail's left-accent/padding/background must style the
   single spanning detail cell, NOT leak onto the cells of any table nested inside it
   (e.g. «Сводная» → per-channel positions), which would draw a blue inset line down every
   nested column and left-align its numbers. */
tr.dlg-detail > td { text-align:left; white-space:normal;
  background:var(--panel-2); padding:10px 14px 12px 22px;
  box-shadow:inset 3px 0 0 var(--is); }
tr.dlg-detail:hover > td { background:var(--panel-2); }
.kv--detail { max-width:560px; }
.kv--detail dd .badge { vertical-align:baseline; }

/* two-column detail: technical fields beside the neural-run result (Все сообщения).
   Columns wrap on narrow viewports. */
.detail-cols { display:flex; flex-wrap:wrap; gap:28px; align-items:flex-start; }
.detail-cols > section { flex:1 1 320px; min-width:0; }
.detail-cols > section h2:first-child { margin-top:0; }

/* «Прогоны» run-detail: outcome + one-line «почему», audit-metric tiles, error banner.
   Reuses the detail-cols/kv/prov skeleton; only the tiles/head/banner are new. */
.run-head { display:flex; flex-wrap:wrap; align-items:baseline; gap:8px 12px; margin:0 0 10px; }
.run-why { color:var(--fg); font-size:13px; }
.run-tiles { display:flex; flex-wrap:wrap; gap:8px; margin:0 0 12px; }
.run-tile { flex:0 1 auto; min-width:88px; padding:6px 10px; background:var(--panel-2);
  border:1px solid var(--line); border-radius:var(--r-sm); }
.run-tile-k { display:block; color:var(--dim); font-size:11px; text-transform:uppercase;
  letter-spacing:.02em; margin-bottom:2px; }
.run-tile-v { display:block; font-size:15px; color:var(--fg); }
.run-error { border-left:3px solid var(--neg); background:var(--panel-2);
  padding:6px 10px; border-radius:0 var(--r-sm) var(--r-sm) 0; margin:0 0 10px; }

/* watch toggle (★) — narrow trailing column; the cell carries data-no-toggle so
   clicking the star never expands the spoiler (see static/app.js). */
.watch-th { text-align:center; width:1%; }
td.watch-cell { text-align:center; width:1%; }
.watch-btn { background:none; border:none; padding:2px 8px; line-height:1;
  font-size:15px; color:var(--dim); cursor:pointer; border-radius:var(--r-sm); }
.watch-btn:hover { color:var(--warn); background:var(--line); }
.watch-btn.on { color:var(--warn); }

/* signal toggle (Прогон column) */
.signal-toggle { background:none; border:1px solid var(--line-strong); color:var(--dim);
  padding:2px 8px; font-size:12px; border-radius:var(--r-sm); cursor:pointer; font-family:inherit; }
.signal-toggle.on { color:var(--pos); border-color:var(--pos); }
.signal-toggle:hover { background:var(--line); }

/* native <dialog> modal (backfill) */
dialog.modal { background:var(--panel); color:var(--fg); border:1px solid var(--line-strong);
  border-radius:var(--r-md); padding:18px 20px; max-width:440px; width:90%; }
dialog.modal::backdrop { background:rgba(0,0,0,.5); }
dialog.modal h2 { margin-top:0; }
dialog.modal label { display:block; }
.modal-actions { display:flex; gap:8px; justify-content:flex-end; margin-top:16px; }
label.radio { display:inline-flex; align-items:center; gap:6px; font-size:13px; color:var(--fg);
  margin-right:14px; }
label.radio input { min-width:0; }
/* compact signal-type acceptance checkboxes: per-channel «Приём» cell (О·З·Д·С±Т) and
   the trader-defaults seed row. Overrides the block `label` rule so several sit inline. */
label.chk { display:inline-flex; align-items:center; gap:3px; margin:0 6px 0 0;
  font-size:12px; color:var(--muted); white-space:nowrap; cursor:pointer; }
label.chk input { min-width:0; margin:0; }
.chk-row { display:flex; flex-wrap:wrap; gap:6px 12px; margin-top:2px; }

/* pagination */
.pager { display:flex; gap:8px; align-items:center; margin:14px 0; font-size:13px; }

/* trader-card section tabs (Трейдинг → карточка): a horizontal switcher in place
   of stacked sections. Progressive enhancement — the bar is hidden until app.js
   adds .js-tabs (without JS every panel stacks; see the <noscript> in the
   template). Styled like the top nav: an underline-rail with one active tab. */
.tabs { display:none; }
.tabbed.js-tabs .tabs {
  display:flex; flex-wrap:wrap; gap:2px;
  border-bottom:1px solid var(--line-strong); margin:18px 0 0;
}
.tab {
  background:none; border:0; border-bottom:2px solid transparent; border-radius:0;
  color:var(--muted); font-size:13px; font-weight:600; line-height:1;
  padding:9px 14px; margin-bottom:-1px; cursor:pointer;
  display:inline-flex; align-items:center; gap:7px;
}
.tab:hover { background:var(--panel); color:var(--fg); }
.tab[aria-selected="true"] { color:var(--fg); border-bottom-color:var(--accent); }
.tab:focus-visible { outline:2px solid var(--accent); outline-offset:-2px; border-radius:var(--r-sm); }
.tab-count {
  font-size:11px; font-weight:600; color:var(--muted);
  background:var(--panel); border:1px solid var(--line-strong); border-radius:999px;
  padding:0 6px; min-width:1.7em; text-align:center;
}
.tab[aria-selected="true"] .tab-count { color:var(--fg); border-color:var(--line-strong); }
/* When tabs are live the panel owns the top spacing, so drop the first heading's
   margin (h2 default is 28px top, which would double the gap under the bar). */
.tabbed.js-tabs .tab-panel { padding-top:16px; }
.tabbed.js-tabs .tab-panel > :first-child { margin-top:0; }

/* «Все сообщения» auto-refresh toggle (newest view only). inline-flex + center +
   gap align the checkbox with its «авто» label text; it also overrides the global
   block-level label default above (the .controls flex row already lays it out). */
.live-toggle { display:inline-flex; align-items:center; gap:5px; margin:0;
  color:var(--muted); font-size:12px; cursor:pointer; }
.live-toggle input { margin:0; cursor:pointer; }
.live-status { font-size:12px; color:var(--dim); min-width:8ch; }

/* messages (Все сообщения) — deleted rows are struck through, not hidden. */
tr.dlg-row.deleted .msg-text { text-decoration:line-through; color:var(--dim); }
/* The text preview is the only wrapping column. Every other tbody td is nowrap
   (date/channel/status), so without this a long one-line preview forces the table
   past its container and shoves the Статус column off-screen. overflow-wrap:anywhere
   also lets the column shrink (breaking long URLs) so the table fits width:100%. */
.msg-text { white-space:normal; overflow-wrap:anywhere; }

/* runs (Прогоны) — the «Сообщение» snippet is the only wrapping column (same
   reason as .msg-text above): the journal has 10 columns and every other tbody
   td is nowrap, so a one-line snippet would force the table past the viewport.
   Wrapping + a width cap lets the column shrink so the table fits width:100%. */
td.run-msg { white-space:normal; overflow-wrap:anywhere; max-width:30ch; }
.msg-full { white-space:pre-wrap; word-break:break-word; max-width:70em;
  margin:0 0 6px; color:var(--fg); }
.media-item { margin:4px 0; }
.msg-thumb { max-width:220px; max-height:220px; border-radius:var(--r-sm);
  border:1px solid var(--line-strong); display:block; }

/* signals — raw LLM JSON spoiler */
details summary { cursor:pointer; font-size:12px; color:var(--muted); margin:6px 0; }
/* signals — provenance spoiler: secondary run metadata collapsed under the
   extracted fields (auto-opened on extraction errors). Hairline sets it apart. */
details.prov { border-top:1px solid var(--line); margin-top:12px; padding-top:2px; }
.raw-json { white-space:pre-wrap; word-break:break-word; max-width:70em; font-family:var(--mono);
  font-size:12px; color:var(--muted); background:var(--bg); border:1px solid var(--line);
  border-radius:var(--r-sm); padding:8px 10px; margin:6px 0; max-height:320px; overflow:auto; }
