:root {
  --bg: #0b0e14;
  --bg-2: #11151d;
  --panel: #151a24;
  --panel-2: #1a202c;
  --line: #232a37;
  --text: #e6edf3;
  --muted: #7d8590;
  --green: #3fb950;
  --red: #f85149;
  --blue: #58a6ff;
  --yellow: #d29922;
  --violet: #bc8cff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
  position: sticky; top: 0; z-index: 10;
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.logo { color: var(--blue); font-size: 20px; }
.subtitle { color: var(--muted); font-weight: 400; margin-left: 4px; }

.status { display: flex; align-items: center; gap: 8px; color: var(--muted); font-family: ui-monospace, monospace; font-size: 12px; }
.sep { opacity: 0.4; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.on { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot.off { background: var(--red); }

main { max-width: 1400px; margin: 0 auto; padding: 20px 24px 80px; }

.engines { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 16px; }
.engine-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 18px;
}
.engine-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.engine-head h3 { margin: 0; font-size: 15px; }
.engine-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; font-family: ui-monospace, monospace; }

.pill {
  padding: 2px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; text-transform: uppercase;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--line);
}
.pill.running { background: rgba(63, 185, 80, 0.15); color: var(--green); border-color: transparent; }
.pill.starting { background: rgba(88, 166, 255, 0.15); color: var(--blue); border-color: transparent; }
.pill.stopped { background: rgba(248, 81, 73, 0.15); color: var(--red); border-color: transparent; }

.grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 14px; margin-bottom: 16px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.panel-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
}
.panel-head h3 { margin: 0; font-size: 13px; letter-spacing: 0.3px; text-transform: uppercase; color: var(--muted); }

.count { background: var(--panel-2); padding: 2px 8px; border-radius: 4px; font-family: ui-monospace, monospace; font-size: 11px; color: var(--muted); }

/* Symbol cards */
.symbols-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; padding: 14px; }
.sym-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  transition: border-color 0.15s;
}
.sym-card.up { border-color: rgba(63, 185, 80, 0.4); }
.sym-card.down { border-color: rgba(248, 81, 73, 0.4); }
.sym-name { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.sym-price { font-family: ui-monospace, monospace; font-size: 18px; font-weight: 600; }
.sym-price.up { color: var(--green); }
.sym-price.down { color: var(--red); }
.sym-meta { display: flex; justify-content: space-between; margin-top: 6px; font-size: 11px; color: var(--muted); font-family: ui-monospace, monospace; }
.sym-badge { font-size: 10px; padding: 1px 6px; border-radius: 4px; }
.sym-badge.buy { background: rgba(63, 185, 80, 0.15); color: var(--green); }
.sym-badge.sell { background: rgba(248, 81, 73, 0.15); color: var(--red); }
.sym-badge.none { color: var(--muted); }

/* Feed */
.feed { max-height: 560px; }
.feed-list { flex: 1; overflow-y: auto; padding: 6px 0; font-family: ui-monospace, monospace; font-size: 12px; }
.feed-item { padding: 6px 16px; border-left: 3px solid transparent; display: flex; gap: 10px; }
.feed-item:hover { background: rgba(255,255,255,0.02); }
.feed-time { color: var(--muted); flex-shrink: 0; width: 72px; }
.feed-type { flex-shrink: 0; width: 70px; font-weight: 600; text-transform: uppercase; font-size: 10px; }
.feed-msg { flex: 1; word-break: break-word; }

.feed-item.order { border-left-color: var(--blue); }
.feed-item.order .feed-type { color: var(--blue); }
.feed-item.signal { border-left-color: var(--yellow); }
.feed-item.signal .feed-type { color: var(--yellow); }
.feed-item.status { border-left-color: var(--violet); }
.feed-item.status .feed-type { color: var(--violet); }
.feed-item.error, .feed-item.order_failed { border-left-color: var(--red); }
.feed-item.error .feed-type, .feed-item.order_failed .feed-type { color: var(--red); }
.feed-item.tick { border-left-color: var(--muted); opacity: 0.7; }
.feed-item.tick .feed-type { color: var(--muted); }

.filter { display: flex; gap: 12px; color: var(--muted); font-size: 11px; }
.filter label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }

/* Trades table */
.trades table { width: 100%; border-collapse: collapse; font-family: ui-monospace, monospace; font-size: 12px; }
.trades th, .trades td { padding: 8px 16px; text-align: left; border-bottom: 1px solid var(--line); }
.trades th { color: var(--muted); font-weight: 500; text-transform: uppercase; font-size: 11px; letter-spacing: 0.3px; background: var(--bg-2); }
.trades tr.buy td:nth-child(4) { color: var(--green); font-weight: 600; }
.trades tr.sell td:nth-child(4) { color: var(--red); font-weight: 600; }
.trades tr.dry { opacity: 0.75; }
.trades tr.failed td { color: var(--red); }

.stats { display: flex; gap: 14px; font-size: 12px; color: var(--muted); font-family: ui-monospace, monospace; }
.stats b { color: var(--text); margin-left: 4px; }

/* Engine P&L block */
.engine-pnl {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 4px;
  font-family: ui-monospace, monospace; font-size: 12px;
}
.pnl-row { display: flex; justify-content: space-between; }
.pnl-row.small { font-size: 11px; color: var(--muted); }
.pnl-label { color: var(--muted); }
.pnl-val { color: var(--text); font-weight: 600; }
.pnl-val.up { color: var(--green); }
.pnl-val.down { color: var(--red); }

/* P&L column in trades table */
.trades td.status-cell.won { color: var(--green); font-weight: 600; }
.trades td.status-cell.lost { color: var(--red); font-weight: 600; }
.trades td.status-cell.open { color: var(--blue); font-style: italic; }
.trades td.up { color: var(--green); font-weight: 600; }
.trades td.down { color: var(--red); font-weight: 600; }
.trades tr.status-open { opacity: 0.85; }
#stat-net.up { color: var(--green); }
#stat-net.down { color: var(--red); }

/* Self-learning insights panel */
.insights { margin-bottom: 18px; }
.insights .hint { color: var(--muted); font-size: 11px; font-family: ui-monospace, monospace; }
.insights table { width: 100%; border-collapse: collapse; font-family: ui-monospace, monospace; font-size: 12px; }
.insights th, .insights td { padding: 7px 14px; text-align: left; border-bottom: 1px solid var(--line); }
.insights th { color: var(--muted); font-weight: 500; text-transform: uppercase; font-size: 11px; letter-spacing: 0.3px; background: var(--bg-2); }
.insights td.up { color: var(--green); }
.insights td.down { color: var(--red); }
.insights td.dim { color: var(--muted); }
.insights td.gate-on { color: var(--green); font-weight: 600; }
.insights td.gate-off { color: var(--red); font-weight: 700; }
.insights tr.bucket-paused { background: rgba(248, 81, 73, 0.06); }
.insights tr.bucket-paused td:first-child { border-left: 2px solid var(--red); }
.insights tr.bucket-live td:first-child { border-left: 2px solid var(--green); }
.insights tr.bucket-exploring td:first-child { border-left: 2px solid var(--yellow); }
.insights td.status-live { color: var(--green); font-weight: 600; }
.insights td.status-paused { color: var(--red); font-weight: 700; }
.insights td.status-exploring { color: var(--yellow); font-weight: 500; font-style: italic; }
.insights-sub { margin: 14px 0 4px 0; padding-left: 4px; }
.insights-sub h4 { margin: 0; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 500; }

@media (max-width: 900px) {
  .engines, .grid { grid-template-columns: 1fr; }
}
