:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #f8f9fb;
  --text: #16181d;
  --muted: #646b78;
  --border: #e1e4ea;
  --accent: #2f5bd3;
  --accent-text: #ffffff;
  --long: #12825a;
  --long-bg: #e3f4ec;
  --short: #c7362f;
  --short-bg: #fbe7e5;
  --warn: #9a6200;
  --warn-bg: #fdf1d8;
  --grid: #eceef2;
  --line: #2f5bd3;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --panel: #171a21;
    --panel-2: #1c2029;
    --text: #e6e8ec;
    --muted: #949bab;
    --border: #2a2f3a;
    --accent: #6d8ff0;
    --accent-text: #0f1115;
    --long: #3ccf91;
    --long-bg: #12302a;
    --short: #ff6b62;
    --short-bg: #3a1c1b;
    --warn: #f0b44c;
    --warn-bg: #3a2d14;
    --grid: #232833;
    --line: #8aa6ff;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --panel: #171a21; --panel-2: #1c2029; --text: #e6e8ec; --muted: #949bab; --border: #2a2f3a;
  --accent: #6d8ff0; --accent-text: #0f1115; --long: #3ccf91; --long-bg: #12302a; --short: #ff6b62;
  --short-bg: #3a1c1b; --warn: #f0b44c; --warn-bg: #3a2d14; --grid: #232833; --line: #8aa6ff; --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
button, input, select { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.hidden { display: none !important; }

/* ---------- шапка ---------- */
header {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--panel); border-bottom: 1px solid var(--border);
}
header h1 { font-size: 15px; margin: 0; font-weight: 650; letter-spacing: .01em; }
header .spacer { flex: 1; }
.clock { font-variant-numeric: tabular-nums; color: var(--muted); }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
  max-width: 100%; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pill > span:last-child { overflow: hidden; text-overflow: ellipsis; }
.pill.run { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.pill.ok { background: var(--long-bg); color: var(--long); border-color: transparent; }
.pill.bad { background: var(--short-bg); color: var(--short); border-color: transparent; }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.run .dot { animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .25; } }

/* ---------- раскладка ---------- */
main {
  display: grid; gap: 16px; padding: 16px;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  grid-template-areas: "side view";
  max-width: 1500px; margin: 0 auto;
}
#side { grid-area: side; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
#view { grid-area: view; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
@media (max-width: 900px) {
  main { grid-template-columns: minmax(0, 1fr); grid-template-areas: "view" "side"; padding: 12px 12px 32px; gap: 12px; }
  header { padding: 8px 12px; gap: 8px; flex-wrap: nowrap; }
  header h1, header .spacer { display: none; }
  header .pill { flex: 1; }
  .clock { font-size: 12.5px; }
  header .btn { padding: 6px 10px; }
}

.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px; box-shadow: var(--shadow); min-width: 0;
}
.card h2 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  margin: 0 0 10px; font-weight: 650;
}
.card h3 { font-size: 13px; margin: 14px 0 8px; font-weight: 650; }
.card h3:first-of-type { margin-top: 0; }
.card h2.flush { margin: 0; }
.card h2 .plain { text-transform: none; letter-spacing: 0; font-weight: 500; }
.note { margin: 0 0 8px; font-size: 12.5px; }

/* ---------- заседание ---------- */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.countdown { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; margin: 2px 0 10px; }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 5px 6px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
td.r, th.r { text-align: right; }
tr:last-child td { border-bottom: 0; }
.scen tr.cons td { background: var(--panel-2); }
.scen td { white-space: nowrap; }
.side-long { color: var(--long); font-weight: 650; }
.side-short { color: var(--short); font-weight: 650; }
.side-none { color: var(--muted); }

/* ---------- запуск ---------- */
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.row label { color: var(--muted); font-size: 12.5px; }
select, input[type=number], input[type=text], input[type=password] {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 7px;
  padding: 6px 8px; min-height: 34px;
}
input[type=number] { width: 84px; }
input[type=text] { width: 96px; text-transform: uppercase; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--panel-2); padding: 6px 10px; cursor: pointer; min-height: 34px; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent); color: var(--accent-text); }
.btn {
  border: 1px solid var(--border); background: var(--panel-2); border-radius: 8px;
  padding: 7px 14px; min-height: 36px; cursor: pointer; font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.danger { background: var(--short); color: #fff; border-color: transparent; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.wide { width: 100%; }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 12.5px; color: var(--muted); }
.sep { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }
.msg { font-size: 12.5px; margin-top: 6px; min-height: 1em; }
.msg.err { color: var(--short); }

/* ---------- архив ---------- */
.runs { list-style: none; padding: 0; margin: 0; max-height: 420px; overflow: auto; }
.runs li {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 8px;
  padding: 8px 6px; border-bottom: 1px solid var(--border); cursor: pointer; border-radius: 6px;
}
.runs li:hover { background: var(--panel-2); }
.runs li.sel { background: var(--panel-2); outline: 1px solid var(--accent); }
.runs .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.runs .d { color: var(--muted); font-size: 12px; }
.runs .res { text-align: right; font-size: 12.5px; font-variant-numeric: tabular-nums; }

/* ---------- прогон ---------- */
.run-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.run-head .title { font-size: 16px; font-weight: 650; margin: 0; flex: 1; min-width: 200px; }
.steps { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 12px; }
.steps span {
  font-size: 12px; padding: 3px 8px; border-radius: 6px; background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--border);
}
.steps span.done { color: var(--text); }
.steps span.cur { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 650; }

.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.fact { background: var(--panel-2); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.fact .k { color: var(--muted); font-size: 12px; }
.fact .v { font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.fact .s { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.fact.long .v { color: var(--long); }
.fact.short .v { color: var(--short); }

.chart-wrap { position: relative; height: 320px; }
@media (max-width: 900px) { .chart-wrap { height: 240px; } }
#chart { width: 100%; height: 100%; display: block; }
.chart-bar { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.chart-bar .spacer { flex: 1; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 14px; height: 0; border-top: 2px solid; vertical-align: middle; margin-right: 4px; }

.feed { list-style: none; margin: 0; padding: 0; max-height: 460px; overflow: auto; }
.feed li { display: grid; grid-template-columns: 92px 1fr; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.feed li:last-child { border-bottom: 0; }
.feed .tx { overflow-wrap: anywhere; min-width: 0; }
.feed .tm { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; line-height: 1.3; }
.feed .tm b { display: block; color: var(--text); font-weight: 600; font-size: 12.5px; }
.feed li.good .tx { color: var(--long); }
.feed li.bad .tx { color: var(--short); }
.feed li.warn .tx { color: var(--warn); }
.feed li.key .tx { font-weight: 650; }

.checks td { overflow-wrap: anywhere; }
.checks td:first-child { width: 22px; text-align: center; font-weight: 700; }
.checks td:nth-child(2) { overflow-wrap: normal; min-width: 7.5em; }
.checks td:nth-child(3) { white-space: nowrap; }
@media (max-width: 600px) { .checks td:nth-child(3) { display: none; } }
.st-OK { color: var(--long); }
.st-ВНИМАНИЕ { color: var(--warn); }
.st-ОШИБКА { color: var(--short); }
.verdict { margin-top: 8px; font-weight: 650; }

pre.console {
  margin: 0; max-height: 360px; overflow: auto; background: var(--panel-2); border-radius: 8px;
  padding: 10px; font: 12px/1.45 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere;
}
details summary { cursor: pointer; color: var(--muted); font-weight: 600; }
details[open] summary { margin-bottom: 10px; }

.md h1 { font-size: 17px; margin: 0 0 8px; }
.md h2 { font-size: 14px; margin: 14px 0 6px; text-transform: none; letter-spacing: 0; color: var(--text); }
.md ul { margin: 4px 0; padding-left: 20px; }
.md table { margin: 6px 0; display: block; overflow-x: auto; }
.md p { margin: 6px 0; }

.empty { color: var(--muted); padding: 30px 0; text-align: center; }

/* ---------- вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; }
.login h1 { font-size: 18px; margin: 0; }
.login input { width: 100%; font-size: 16px; }

/* ---------- тренажёр ---------- */
#train-date { width: 100%; }
.desk-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px; }
.desk-head h2 { flex: 1; }
.vclock { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.vclock small { font-size: 12px; color: var(--muted); font-weight: 500; margin-left: 6px; }
.trade-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin-top: 10px; }
.btn.trade { min-height: 48px; font-size: 16px; }
.btn.trade.long { background: var(--long); color: #fff; border-color: transparent; }
.btn.trade.short { background: var(--short); color: #fff; border-color: transparent; }
.desk-pos { margin-top: 10px; font-variant-numeric: tabular-nums; font-size: 15px; }
.desk-pos b.pos-long { color: var(--long); }
.desk-pos b.pos-short { color: var(--short); }
.reveal { font-size: 15px; margin: 0 0 10px; }
.desk-news { border-left: 3px solid var(--accent); background: var(--panel-2); border-radius: 6px; padding: 8px 10px; margin: 6px 0 10px; }
.desk-news.release { border-left-color: var(--warn); }
.desk-news .when { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.desk-news b { display: block; }
.result td:first-child { color: var(--muted); }
.result .good { color: var(--long); font-weight: 650; }
.result .bad { color: var(--short); font-weight: 650; }
.feed li.news .tx b { display: block; }
.feed li.news .tx a { color: var(--accent); font-size: 12px; overflow-wrap: anywhere; }
.feed li.mine .tx { color: var(--accent); font-weight: 600; }
