* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0e0e11;
  --bg2: #16161a;
  --bg3: #1c1c22;
  --bg4: #222229;
  --border: rgba(255,255,255,0.07);
  --border2: rgba(255,255,255,0.13);
  --text: #e8e8ec;
  --text2: #8b8b9a;
  --text3: #50505c;
  --green: #22c55e;
  --green-bg: rgba(34,197,94,0.1);
  --red: #ef4444;
  --red-bg: rgba(239,68,68,0.1);
  --accent: #7c6af7;
  --accent-bg: rgba(124,106,247,0.12);
  --up-wick: #22c55e;
  --dn-wick: #ef4444;
}
html, body { height: 100%; background: var(--bg); color: var(--text); font-family: 'Inter', system-ui, sans-serif; font-size: 12px; -webkit-font-smoothing: antialiased; overflow: hidden; }
#app { display: flex; flex-direction: column; height: 100vh; }

/* ── HEADER ── */
#header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; border-bottom: 1px solid var(--border);
  background: var(--bg2); flex-shrink: 0; gap: 12px;
}
.logo { font-size: 14px; font-weight: 700; letter-spacing: -0.5px; white-space: nowrap; font-family: 'Inter', sans-serif; display: inline-flex; align-items: center; gap: 6px; }
.logo-icon { width: 18px; height: 18px; display: block; }
.logo span { color: var(--accent); }
#ticker-bar {
  display: flex; gap: 0; overflow: hidden; flex: 1;
  align-items: stretch; height: 26px;
}
.tk { display: flex; gap: 5px; align-items: center; padding: 0 10px; border-left: 1px solid var(--border); font-size: 11px; white-space: nowrap; cursor: pointer; }
.tk:hover { background: var(--bg3); }
.tk.active { background: var(--accent-bg); }
.tk-sym { color: var(--text3); }
.tk-val { font-weight: 600; font-size: 11.5px; letter-spacing: -0.2px; }
.pos { color: var(--green) !important; }
.neg { color: var(--red)   !important; }
#header-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
#status {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--green); box-shadow: 0 0 6px rgba(34,197,94,0.5);
  transition: background 0.2s, box-shadow 0.2s;
}
#status.err { background: var(--red); box-shadow: 0 0 6px rgba(239,68,68,0.5); }
#btn-ref {
  font-size: 11px; padding: 3px 10px; border-radius: 5px;
  border: 1px solid var(--border2); background: var(--bg3);
  color: var(--text2); cursor: pointer; font-family: inherit; white-space: nowrap;
}
#btn-ref:hover { background: var(--border2); color: var(--text); }
#btn-ref:disabled { opacity: 0.4; cursor: default; }

/* ── BODY SPLIT ── */
#body { display: flex; flex: 1; overflow: hidden; }

/* ── TOOL SIDEBAR ── */
#tool-sidebar {
  width: 36px; flex-shrink: 0; background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center;
  padding: 6px 0; gap: 2px; z-index: 10;
}
.tool-btn {
  width: 28px; height: 28px; border-radius: 5px; border: none;
  background: transparent; color: var(--text3); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; position: relative; transition: background 0.1s, color 0.1s;
}
.tool-btn:hover { background: var(--bg3); color: var(--text2); }
.tool-btn.on { background: var(--accent-bg); color: var(--accent); }
.tool-btn[title]:hover::after {
  content: attr(title); position: absolute; left: 38px; top: 50%;
  transform: translateY(-50%); background: var(--bg3); color: var(--text);
  font-size: 11px; font-family: 'Inter', sans-serif; white-space: nowrap;
  padding: 4px 8px; border-radius: 4px; border: 1px solid var(--border2);
  pointer-events: none; z-index: 100;
}
.tool-sep { width: 20px; height: 1px; background: var(--border); margin: 3px 0; flex-shrink: 0; }
#drawing-canvas { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
#interact-canvas { position: absolute; inset: 0; z-index: 4; }
#resizer {
  width: 5px; flex-shrink: 0; background: var(--border);
  cursor: col-resize; position: relative; z-index: 20;
  transition: background 0.15s;
}
#resizer:hover, #resizer.dragging { background: var(--accent); }
#resizer::after {
  content: ''; position: absolute; inset: 0 -4px;
}

/* ── LEFT: CHART PANEL ── */
#chart-panel {
  display: flex; flex-direction: column; width: var(--chart-w, 80%);
  border-right: none; flex-shrink: 0; min-width: 200px;
}
#chart-toolbar {
  display: flex; align-items: center; gap: 0;
  border-bottom: 1px solid var(--border); background: var(--bg2);
  padding: 0; flex-shrink: 0; height: 34px;
}
#chart-symbol {
  padding: 0 14px; font-size: 13px; font-weight: 700; letter-spacing: -0.3px;
  color: var(--text); border-right: 1px solid var(--border);
  height: 100%; display: flex; align-items: center; min-width: 110px; gap: 6px;
}
#chart-chg { font-size: 11px; font-weight: 600; }
#tf-btns { display: flex; }
.tf-btn {
  padding: 0 10px; height: 34px; font-size: 11px; font-family: inherit;
  border: none; border-right: 1px solid var(--border);
  background: transparent; color: var(--text3); cursor: pointer;
}
.tf-btn:hover { background: var(--bg3); color: var(--text2); }
.tf-btn.on { background: var(--accent-bg); color: var(--accent); }


#chart-wrap { flex: 1; position: relative; overflow: hidden; }
#chart-canvas { position: absolute; inset: 0; }
#chart-loading {
  position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; background: var(--bg); font-size: 13px; color: var(--text3);
}
.spinner { width: 24px; height: 24px; border: 2px solid var(--border2); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; margin-right: 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

#chart-crosshair {
  position: absolute; inset: 0; pointer-events: none;
}

/* ── RIGHT: SCREENER ── */
#screener { display: flex; flex-direction: column; width: var(--scr-w, 20%); overflow: hidden; min-width: 160px; max-width: 600px; }
#scr-controls {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px;
  border-bottom: 1px solid var(--border); background: var(--bg2); flex-shrink: 0; flex-wrap: wrap;
}
#search {
  font-family: inherit; font-size: 11px; padding: 3px 8px; border-radius: 4px;
  border: 1px solid var(--border2); background: var(--bg3); color: var(--text); flex: 1; outline: none; min-width: 80px;
}
#search:focus { border-color: var(--accent); }
#search::placeholder { color: var(--text3); }
#sort-sel {
  font-family: inherit; font-size: 10px; padding: 3px 6px; border-radius: 4px;
  border: 1px solid var(--border2); background: var(--bg3); color: var(--text2); outline: none; cursor: pointer;
}
#btn-fav-filter {
  font-family: inherit; font-size: 12px; padding: 2px 8px; border-radius: 4px;
  border: 1px solid var(--border2); background: var(--bg3); color: var(--text3);
  cursor: pointer; line-height: 1; transition: all 0.1s;
}
#btn-fav-filter:hover { color: #f59e0b; border-color: #f59e0b; }
#btn-fav-filter.on { background: rgba(245,158,11,0.12); color: #f59e0b; border-color: #f59e0b; }
#scr-count { font-size: 10px; color: var(--text3); white-space: nowrap; }
#col-toggles {
  display: flex; gap: 4px; padding: 4px 8px; flex-wrap: wrap;
  border-bottom: 1px solid var(--border); background: var(--bg); flex-shrink: 0;
}
.col-toggle {
  font-size: 10px; padding: 2px 7px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border2); background: transparent; color: var(--text3);
  font-family: inherit; transition: all 0.1s; white-space: nowrap;
}
.col-toggle.on { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }
.col-toggle:hover { color: var(--text2); border-color: var(--border2); }

#scr-table-wrap { flex: 1; overflow-y: auto; overflow-x: hidden; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
thead { position: sticky; top: 0; z-index: 5; }
thead th {
  background: var(--bg2); padding: 4px 6px; font-size: 9px; font-weight: 500;
  color: var(--text3); text-align: right; border-bottom: 1px solid var(--border2);
  cursor: pointer; user-select: none; white-space: nowrap;
}
thead th:first-child { text-align: left; }
thead th:hover { color: var(--text2); }
thead th.on { color: var(--accent); }
.arr { font-size: 8px; margin-left: 1px; }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: rgba(255,255,255,0.025); }
tbody tr.sel td { background: var(--accent-bg) !important; }
tbody td {
  padding: 3px 6px; text-align: right; border-bottom: 1px solid var(--border);
  color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  line-height: 1.9; font-size: 11px; font-variant-numeric: tabular-nums;
}
tbody td:first-child { text-align: left; color: var(--text); font-weight: 600; font-size: 11px; }
.fav-star {
  display: inline-block; width: 14px; margin-right: 3px;
  color: var(--text3); cursor: pointer; user-select: none;
  font-size: 12px; line-height: 1; transition: color 0.1s;
}
.fav-star:hover { color: #f59e0b; }
.fav-star.on { color: #f59e0b; }
.sym-q { font-size: 8px; color: var(--text3); }
.pill { display: inline-block; padding: 1px 5px; border-radius: 3px; font-size: 10px; font-weight: 600; }
.pp { background: var(--green-bg); color: var(--green); }
.pn { background: var(--red-bg);   color: var(--red); }
.p0 { background: var(--bg4); color: var(--text3); }
.bar-bg { display: inline-block; width: 22px; height: 2px; background: var(--border2); border-radius: 1px; vertical-align: middle; margin-left: 3px; overflow: hidden; }
.bar-fg { height: 100%; background: rgba(124,106,247,0.5); border-radius: 1px; }

#scr-loading { padding: 30px 0; text-align: center; color: var(--text3); font-size: 12px; }
#scr-err { display: none; padding: 20px 10px; color: var(--red); font-size: 11px; text-align: center; line-height: 1.6; }

/* ── FOOTER ── */
#footer {
  padding: 4px 14px; border-top: 1px solid var(--border);
  display: flex; justify-content: space-between;
  font-size: 10px; color: var(--text3); flex-shrink: 0; background: var(--bg2);
}

/* Scrollbar */
::-webkit-scrollbar { width: 4px; height: 4px; }
.col-hidden { display: none !important; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }/* ── КНОПКА КЕЙСА В ШАПКЕ ── */
#btn-case {
  font-family: inherit; font-size: 11px; padding: 3px 10px; border-radius: 5px;
  border: 1px solid var(--border2); background: var(--bg3);
  color: var(--text2); cursor: pointer; white-space: nowrap;
}
#btn-case:hover { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }
#btn-case.on { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }

/* ── МОДАЛКА ── */
.modal-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
}
.modal {
  background: var(--bg2); border: 1px solid var(--border2); border-radius: 8px;
  width: 540px; max-width: 92vw; max-height: 80vh; display: flex; flex-direction: column;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 14px; font-weight: 600; }
.modal-close {
  background: none; border: none; color: var(--text2); font-size: 22px;
  cursor: pointer; line-height: 1; padding: 0 4px;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 12px 16px; overflow-y: auto; }

/* Карточка кейса */
.case-item {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px;
  margin-bottom: 8px; cursor: pointer; transition: all 0.1s;
}
.case-item:hover { border-color: var(--accent); background: var(--accent-bg); }
.case-item-name { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.case-item-meta { font-size: 11px; color: var(--text3); }
.case-item-desc { font-size: 11px; color: var(--text2); margin-top: 6px; line-height: 1.4; }

/* Сетка статистики */
.summary-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.sm-card {
  background: var(--bg3); border-radius: 6px; padding: 10px 12px;
  border: 1px solid var(--border);
}
.sm-label { font-size: 10px; color: var(--text3); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.sm-val { font-size: 16px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }

/* ── REPLAY-ПАНЕЛЬ ── */
#case-bar {
  display: flex; align-items: center; gap: 16px; padding: 8px 14px;
  border-top: 1px solid var(--accent); background: var(--bg2);
  flex-shrink: 0; font-size: 11px;
}
.cb-section { display: flex; align-items: center; gap: 6px; }
.cb-info { flex: 1; justify-content: center; color: var(--text2); font-variant-numeric: tabular-nums; }
.cb-info #cb-name { font-weight: 600; color: var(--text); }
#cb-play, .cb-step, .cb-speed, #cb-exit {
  font-family: inherit; font-size: 11px; padding: 4px 10px; border-radius: 4px;
  border: 1px solid var(--border2); background: var(--bg3); color: var(--text2);
  cursor: pointer; line-height: 1;
}
#cb-play { padding: 4px 14px; font-size: 12px; }
.cb-speed.on { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }
.cb-speed-label, .cb-balance-label { color: var(--text3); margin-left: 4px; }
#cb-balance { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
#cb-pnl-live { font-weight: 600; font-variant-numeric: tabular-nums; }
#cb-exit { color: var(--red); border-color: var(--red); }
#cb-exit:hover { background: var(--red-bg); }

/* ── ТОРГОВАЯ ПАНЕЛЬ ── */
#trade-panel {
  position: fixed; right: 14px; top: 60px; width: 220px;
  background: var(--bg2); border: 1px solid var(--border2); border-radius: 8px;
  padding: 10px; z-index: 100; font-size: 11px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
.tp-head { font-size: 12px; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.tp-row { margin-bottom: 8px; }
.tp-label { color: var(--text3); display: block; margin-bottom: 3px; font-size: 10px; }
.tp-row input {
  width: 100%; font-family: inherit; font-size: 12px; padding: 5px 8px;
  border-radius: 4px; border: 1px solid var(--border2); background: var(--bg3);
  color: var(--text); outline: none;
}
.tp-row input:focus { border-color: var(--accent); }
.tp-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tp-sltp { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tp-rr {
  font-size: 10px; color: var(--text3); text-align: center;
  padding: 4px; margin-bottom: 8px; background: var(--bg3); border-radius: 4px;
}
.tp-rr.good { color: var(--green); }
.tp-rr.bad { color: var(--red); }
.tp-btn {
  font-family: inherit; font-size: 12px; font-weight: 600; padding: 8px;
  border-radius: 4px; border: none; cursor: pointer; color: #fff;
}
.tp-long { background: var(--green); }
.tp-long:hover { background: #15803d; }
.tp-short { background: var(--red); }
.tp-short:hover { background: #b91c1c; }
.tp-pos-card {
  background: var(--bg3); border-radius: 4px; padding: 8px; margin-bottom: 6px;
  border-left: 3px solid var(--accent);
}
.tp-pos-side { font-size: 11px; font-weight: 700; margin-bottom: 4px; }
.tp-pos-line { font-size: 10px; color: var(--text2); margin-bottom: 2px; font-variant-numeric: tabular-nums; }
.tp-pos-line span { color: var(--text); font-weight: 500; }
#tp-close-btn {
  width: 100%; font-family: inherit; font-size: 11px; font-weight: 600; padding: 6px;
  border-radius: 4px; border: 1px solid var(--border2); background: var(--bg3);
  color: var(--text); cursor: pointer;
}
#tp-close-btn:hover { background: var(--border2); }
#tp-trades-list { max-height: 180px; overflow-y: auto; }
.trade-row {
  font-size: 10px; padding: 4px 6px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; gap: 6px;
  font-variant-numeric: tabular-nums;
}
.trade-row.win { color: var(--green); }
.trade-row.loss { color: var(--red); }