/* ═══ POLYSTATS TERMINAL v2 ═══ */

/* ── Page Container ── */
#page-terminal.active {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--topbar-h));
  overflow: hidden;
  padding: 0;
  background: var(--bg);
  font-family: 'JetBrains Mono', monospace;
}

/* ══════════════════════════════════════════
   TOP BAR
══════════════════════════════════════════ */
.term-top {
  flex-shrink: 0;
  height: 42px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 0;
  overflow: hidden;
}
.term-top-group {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  border-right: 1px solid var(--border);
  height: 100%;
}
.term-top-group:first-child { padding-left: 0; }
.term-top-group:last-child  { border-right: none; }

.t-btc {
  font-size: 15px;
  font-weight: 700;
  color: var(--yellow);
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.t-mqs {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  white-space: nowrap;
}
.t-mqs.good { background: rgba(0,255,136,0.10); color: var(--green); border: 1px solid rgba(0,255,136,0.25); }
.t-mqs.warn { background: rgba(255,229,102,0.08); color: var(--yellow); border: 1px solid rgba(255,229,102,0.25); }
.t-mqs.bad  { background: rgba(255,68,102,0.08); color: var(--red); border: 1px solid rgba(255,68,102,0.25); }
.t-mqs-score { font-size: 13px; font-weight: 800; }

.t-balance {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}
.t-pnl {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.t-pnl.pos { color: var(--green); }
.t-pnl.neg { color: var(--red); }

.t-kv {
  display: flex;
  align-items: baseline;
  gap: 4px;
  white-space: nowrap;
}
.t-k { font-size: 9px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.8px; }
.t-v { font-size: 12px; font-weight: 600; color: var(--text); }
.t-v.g { color: var(--green); }
.t-v.r { color: var(--red); }
.t-v.c { color: var(--cyan); }
.t-v.y { color: var(--yellow); }
.t-v.m { color: var(--muted); }

.t-src-dot {
  width: 7px; height: 7px; border-radius: 50%;
  display: inline-block; flex-shrink: 0;
}
.t-src-dot.live { background: var(--green); box-shadow: 0 0 6px var(--green); animation: pulse 2s infinite; }
.t-src-dot.api  { background: var(--muted); }

/* Engine Status */
.t-engine {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  white-space: nowrap;
}
.t-engine.on {
  background: rgba(0,255,136,0.08);
  border: 1px solid rgba(0,255,136,0.2);
  color: var(--green);
}
.t-engine.off {
  background: rgba(255,68,102,0.06);
  border: 1px solid rgba(255,68,102,0.15);
  color: var(--red);
}
.t-engine-dot {
  width: 6px; height: 6px; border-radius: 50%;
  display: inline-block; flex-shrink: 0;
}
.t-engine.on .t-engine-dot {
  background: var(--green);
  box-shadow: 0 0 4px var(--green);
  animation: pulse 2.5s infinite;
}
.t-engine.off .t-engine-dot {
  background: var(--red);
}
.t-engine-label { font-size: 9px; }
.t-engine-err {
  font-size: 9px;
  font-weight: 700;
  color: var(--red);
  background: rgba(255,68,102,0.1);
  padding: 2px 6px;
  border-radius: 3px;
  cursor: help;
  letter-spacing: 0.5px;
}

/* ══════════════════════════════════════════
   BODY — Sidebar + Feed
══════════════════════════════════════════ */
.term-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* ══════════════════════════════════════════
   BOT SIDEBAR (overlay, hidden by default)
══════════════════════════════════════════ */
.term-sidebar {
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 220px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg2);
  z-index: 10;
  transform: translateX(-100%);
  transition: transform 0.18s ease;
  box-shadow: none;
}
.term-sidebar.open {
  transform: translateX(0);
  box-shadow: 4px 0 24px rgba(0,0,0,0.5);
}
.term-body { position: relative; }
.term-sidebar-head {
  height: 32px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.term-sidebar-close {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
  transition: color 0.12s;
}
.term-sidebar-close:hover { color: var(--text); }
.term-sidebar-title {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
}
.term-sidebar-badge {
  font-size: 10px;
  font-weight: 700;
  color: var(--green);
  background: rgba(0,255,136,0.10);
  padding: 1px 7px;
  border-radius: 10px;
}
.term-bots-scroll {
  flex: 1;
  overflow-y: auto;
}
.term-sidebar-foot {
  border-top: 1px solid var(--border);
  padding: 6px 8px;
  flex-shrink: 0;
}

/* ── Bot Row ── */
.brow {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  transition: background 0.1s;
}
.brow:hover { background: rgba(255,255,255,0.025); }
.brow.active { background: rgba(0,255,136,0.03); }

.brow-dot {
  width: 7px; height: 7px; border-radius: 50%;
  flex-shrink: 0;
}
.brow.active .brow-dot {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  animation: pulse 2.5s infinite;
}
.brow:not(.active) .brow-dot { background: rgba(255,255,255,0.12); }

.brow-info { flex: 1; min-width: 0; }
.brow-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}
.brow.active .brow-name { color: #e0f8ee; }
.brow-meta {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 2px;
}
.brow-wr {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
}
.brow-wr.hi { color: var(--green); }
.brow-wr.lo { color: var(--red); }
.brow-trades {
  font-size: 10px;
  color: var(--muted);
}

/* ── Bot Right Block ── */
.brow-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  flex-shrink: 0;
}
.brow-pnl {
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.brow-pnl.pos  { color: var(--green); }
.brow-pnl.neg  { color: var(--red); }
.brow-pnl.zero { color: var(--muted); }

.brow-btn {
  width: 26px; height: 20px;
  border-radius: 3px;
  background: transparent;
  cursor: pointer;
  font-size: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.12s;
  padding: 0;
  line-height: 1;
}
.brow:not(.active) .brow-btn {
  border: 1px solid rgba(0,255,136,0.35);
  color: var(--green);
}
.brow:not(.active) .brow-btn:hover {
  background: rgba(0,255,136,0.1);
  border-color: var(--green);
}
.brow.active .brow-btn {
  border: 1px solid rgba(255,68,102,0.35);
  color: var(--red);
}
.brow.active .brow-btn:hover {
  background: rgba(255,68,102,0.1);
  border-color: var(--red);
}

.brow-empty {
  padding: 28px 14px;
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}
.brow-create {
  width: 100%;
  padding: 7px;
  border: 1px dashed rgba(255,255,255,0.08);
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.5px;
}
.brow-create:hover {
  border-color: var(--cyan);
  color: var(--cyan);
  background: rgba(0,212,255,0.04);
}

/* ══════════════════════════════════════════
   MAIN AREA
══════════════════════════════════════════ */
.term-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ══════════════════════════════════════════
   TABS
══════════════════════════════════════════ */
.term-tabs {
  display: flex;
  align-items: stretch;
  height: 34px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 0;
}

/* Sidebar toggle button in tabs row */
.term-tab-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 38px;
  background: transparent;
  border: none;
  border-right: 1px solid var(--border);
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.12s;
  position: relative;
  flex-shrink: 0;
}
.term-tab-toggle:hover {
  color: var(--text);
  background: rgba(255,255,255,0.03);
}
.term-tab-toggle-icon { line-height: 1; }
.term-tab-toggle-badge {
  position: absolute;
  top: 4px; right: 4px;
  font-size: 8px;
  font-weight: 800;
  color: var(--green);
  display: none;
}
.term-tab-toggle-badge.has { display: block; }
.term-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 18px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.term-tab:hover {
  color: var(--text);
  background: rgba(255,255,255,0.02);
}
.term-tab.active {
  color: var(--cyan);
  border-bottom-color: var(--cyan);
}
.term-tab-badge {
  font-size: 9px;
  font-weight: 700;
  color: var(--muted);
  background: rgba(255,255,255,0.06);
  padding: 1px 5px;
  border-radius: 8px;
  min-width: 0;
}
.term-tab-badge:empty { display: none; }
.term-tab.active .term-tab-badge {
  color: var(--cyan);
  background: rgba(0,212,255,0.1);
}
.term-tab-badge.err {
  color: var(--red);
  background: rgba(255,68,102,0.12);
}

/* Feed Header */
.term-feed-head {
  height: 28px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  border-left: 2px solid transparent;
  background: var(--bg3);
  flex-shrink: 0;
}
.fh-col {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
}
.fh-time     { width: 58px; flex-shrink: 0; }
.fh-type     { width: 36px; flex-shrink: 0; }
.fh-status   { width: 68px; flex-shrink: 0; }
.fh-side     { width: 24px; flex-shrink: 0; }
.fh-price    { width: 80px; flex-shrink: 0; }
.fh-amount   { width: 56px; flex-shrink: 0; }
.fh-pnl      { width: 68px; flex-shrink: 0; }
.fh-bot      { flex: 1; min-width: 60px; }
.fh-log-msg  { flex: 1; min-width: 60px; }
.fh-evt-dir  { width: 90px; flex-shrink: 0; }
.fh-evt-edge { width: 70px; flex-shrink: 0; }
.fh-evt-conf { width: 60px; flex-shrink: 0; }
.fh-evt-btc  { width: 80px; flex-shrink: 0; }
.fh-evt-meta { flex: 1; min-width: 60px; }

/* Feed Scroll */
.term-feed {
  flex: 1;
  overflow-y: auto;
}
.feed-empty {
  padding: 48px 24px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.8;
}

/* ══════════════════════════════════════════
   DATE SEPARATOR
══════════════════════════════════════════ */
.feed-date-sep {
  padding: 6px 12px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
  border-top: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 2;
}

/* ══════════════════════════════════════════
   TYPE ICON (T / INF / WRN / ERR / E)
══════════════════════════════════════════ */
.frow-type {
  width: 36px;
  flex-shrink: 0;
}
.frow-type-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 16px;
  border-radius: 3px;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.5px;
}
.frow-type-icon.trade {
  background: rgba(168,85,247,0.12);
  color: var(--purple);
  border: 1px solid rgba(168,85,247,0.2);
}
.frow-type-icon.log-inf {
  background: rgba(0,212,255,0.08);
  color: var(--cyan);
  border: 1px solid rgba(0,212,255,0.15);
}
.frow-type-icon.log-warn {
  background: rgba(255,229,102,0.1);
  color: var(--yellow);
  border: 1px solid rgba(255,229,102,0.2);
}
.frow-type-icon.log-err {
  background: rgba(255,68,102,0.1);
  color: var(--red);
  border: 1px solid rgba(255,68,102,0.2);
}
.frow-type-icon.log-dbg {
  background: rgba(255,255,255,0.04);
  color: var(--muted);
  border: 1px solid rgba(255,255,255,0.06);
}
.frow-type-icon.event {
  background: rgba(0,255,136,0.08);
  color: var(--green);
  border: 1px solid rgba(0,255,136,0.15);
}

/* ══════════════════════════════════════════
   FEED ROW — TRADE
══════════════════════════════════════════ */
.frow {
  display: flex;
  align-items: center;
  padding: 0 12px;
  height: 28px;
  border-bottom: 1px solid rgba(255,255,255,0.025);
  font-size: 11px;
  animation: frowIn 0.2s ease;
}
.frow:hover { background: rgba(255,255,255,0.025); }
.frow.is-new { animation: frowNew 0.5s ease; }

.frow-trade.won   { border-left: 2px solid var(--green); }
.frow-trade.lost  { border-left: 2px solid var(--red); }
.frow-trade.open  { border-left: 2px solid var(--cyan); }
.frow-trade.be    { border-left: 2px solid rgba(255,255,255,0.12); }
.frow-trade.skip  { border-left: 2px solid transparent; opacity: 0.45; }

.frow-time {
  width: 58px; flex-shrink: 0;
  color: var(--muted);
  font-size: 10px;
}
.frow-status {
  width: 68px; flex-shrink: 0;
}
.frow-status-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.frow-status-badge.won  { color: var(--green); }
.frow-status-badge.lost { color: var(--red); }
.frow-status-badge.open { color: var(--cyan); }
.frow-status-badge.be   { color: var(--muted); }
.frow-status-badge.skip { color: var(--muted); }

.frow-side {
  width: 24px; flex-shrink: 0;
  font-size: 12px; font-weight: 700;
}
.frow-side.up { color: var(--green); }
.frow-side.dn { color: var(--red); }

.frow-price {
  width: 80px; flex-shrink: 0;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.frow-price .exit { color: var(--muted); font-size: 10px; }

.frow-amount {
  width: 56px; flex-shrink: 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.frow-pnl {
  width: 68px; flex-shrink: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.frow-pnl.pos { color: var(--green); }
.frow-pnl.neg { color: var(--red); }

.frow-bot {
  flex: 1; min-width: 60px;
  overflow: hidden;
}
.frow-bot-tag {
  display: inline-block;
  max-width: 100%;
  font-size: 10px;
  color: var(--purple);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

/* ══════════════════════════════════════════
   FEED ROW — LOG
══════════════════════════════════════════ */
.frow-log {
  border-left: 2px solid transparent;
}
.frow-log.lvl-err { border-left-color: var(--red); }
.frow-log.lvl-warn { border-left-color: var(--yellow); }
.frow-log.lvl-inf { border-left-color: rgba(0,212,255,0.3); }
.frow-log.lvl-dbg { border-left-color: rgba(255,255,255,0.06); opacity: 0.6; }

.frow-log-msg {
  flex: 1;
  min-width: 0;
  color: var(--text);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.frow-log.lvl-err .frow-log-msg { color: var(--red); }
.frow-log.lvl-warn .frow-log-msg { color: var(--yellow); }
.frow-log.lvl-dbg .frow-log-msg { color: var(--muted); }

/* ══════════════════════════════════════════
   FEED ROW — EVENT
══════════════════════════════════════════ */
.frow-event {
  border-left: 2px solid rgba(0,255,136,0.15);
}
.frow-evt-dir {
  width: 90px; flex-shrink: 0;
  font-weight: 700;
  font-size: 11px;
}
.frow-evt-dir.up { color: var(--green); }
.frow-evt-dir.dn { color: var(--red); }

.frow-evt-edge {
  width: 70px; flex-shrink: 0;
  font-size: 10px;
  color: var(--muted);
}
.frow-evt-edge .hi { color: var(--cyan); font-weight: 700; }

.frow-evt-conf {
  width: 60px; flex-shrink: 0;
  font-size: 10px;
  font-weight: 600;
}
.frow-evt-conf.g { color: var(--green); }
.frow-evt-conf.y { color: var(--yellow); }
.frow-evt-conf.m { color: var(--muted); }

.frow-evt-btc {
  width: 80px; flex-shrink: 0;
  font-size: 10px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.frow-evt-meta {
  font-size: 10px;
  color: var(--muted);
  margin-right: 10px;
}
.frow-evt-trades {
  font-size: 10px;
  font-weight: 600;
  color: var(--cyan);
  flex-shrink: 0;
}

/* ══════════════════════════════════════════
   EXPANDED DETAIL
══════════════════════════════════════════ */
.frow-detail {
  padding: 4px 12px 6px 70px;
  font-size: 10px;
  color: var(--muted);
  border-bottom: 1px solid rgba(255,255,255,0.025);
  line-height: 1.5;
  display: none;
}
.frow-detail.visible {
  display: block;
  animation: frowIn 0.15s ease;
}
.frow-detail .reason { color: rgba(200,230,240,0.45); font-style: italic; }
.frow-detail .hi { color: var(--cyan); }

/* ══════════════════════════════════════════
   ANIMATIONS
══════════════════════════════════════════ */
@keyframes frowIn {
  from { opacity: 0; transform: translateX(-4px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes frowNew {
  0%   { opacity: 0; background: rgba(0,212,255,0.06); }
  50%  { background: rgba(0,212,255,0.06); }
  100% { opacity: 1; background: transparent; }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ══════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════ */
@media (max-width: 900px) {
  .fh-amount, .frow-amount { display: none; }
  .term-tab { padding: 0 12px; font-size: 10px; }
  .frow-evt-btc, .fh-evt-btc { display: none; }
  .frow-evt-meta { display: none; }
}
@media (max-width: 680px) {
  .fh-price, .frow-price { display: none; }
  .frow-evt-edge, .fh-evt-edge { display: none; }
  .term-tab { padding: 0 8px; font-size: 9px; }
  .term-tab-badge { font-size: 8px; }
  .t-engine-label { display: none; }
  .term-sidebar { width: 100%; }
}
@media (max-width: 480px) {
  .term-top { padding: 0 8px; }
  .term-top-group { padding: 0 8px; gap: 6px; }
  .t-btc { font-size: 13px; }
  .t-mqs { padding: 2px 6px; }
  .fh-pnl, .frow-pnl { width: 56px; }
  .fh-bot, .frow-bot { display: none; }
  .frow-evt-conf, .fh-evt-conf { display: none; }
}
