:root {
  --bg: #0b0e14;
  --bg-2: #11151d;
  --bg-3: #1a1f2b;
  --border: #232938;
  --text: #e7ecf3;
  --muted: #8b94a7;
  --accent: #11c27f;
  --accent-2: #0ea968;
  --red: #ef5757;
  --amber: #f0b849;
  --blue: #4f8cff;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* ---------- TOPBAR ---------- */
.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 24px;
  padding: 12px 20px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  background: var(--accent);
  color: #000;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 6px;
  font-family: var(--mono);
  letter-spacing: 1px;
}
.title { font-weight: 600; font-size: 15px; }

.pill {
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.pill-shadow { background: rgba(240,184,73,0.15); color: var(--amber); border: 1px solid rgba(240,184,73,0.3); }
.pill-live { background: rgba(239,87,87,0.15); color: var(--red); border: 1px solid rgba(239,87,87,0.3); }
.pill-ok { background: rgba(17,194,127,0.15); color: var(--accent); border: 1px solid rgba(17,194,127,0.3); }
.pill-bad { background: rgba(239,87,87,0.15); color: var(--red); border: 1px solid rgba(239,87,87,0.3); }
.pill-muted { background: var(--bg-3); color: var(--muted); border: 1px solid var(--border); }

.top-stats {
  display: flex;
  gap: 28px;
  justify-content: flex-start;
  flex-wrap: wrap;
}
.stat { display: flex; flex-direction: column; }
.stat label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
.stat span { font-weight: 600; font-family: var(--mono); font-size: 15px; }
.stat span.good { color: var(--accent); }
.stat span.bad { color: var(--red); }

.top-actions { display: flex; gap: 8px; }

/* ---------- BUTTONS ---------- */
.btn {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: #222a3b; }
.btn:active { transform: translateY(1px); }
.btn.active { background: var(--accent); color: #000; border-color: var(--accent); }
.btn-sm { padding: 4px 8px; font-size: 12px; }
.btn-primary { background: var(--accent); color: #000; border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { background: var(--accent-2); }
.btn-danger { background: #301518; border-color: #4a1f23; color: var(--red); }
.btn-danger:hover { background: #3d1a20; }
.btn-danger.halted { background: var(--red); color: #fff; border-color: var(--red); }
.btn-chip { padding: 4px 10px; font-size: 11px; border-radius: 999px; color: var(--muted); }
.btn-chip:hover { color: var(--text); }

/* ---------- MAIN GRID ---------- */
.grid {
  display: grid;
  grid-template-columns: 360px 1fr 380px;
  gap: 16px;
  padding: 16px;
  max-width: 1800px;
  margin: 0 auto;
}
@media (max-width: 1280px) {
  .grid { grid-template-columns: 320px 1fr; }
  .panel-copilot { grid-column: 1 / -1; }
}
@media (max-width: 820px) {
  .grid { grid-template-columns: 1fr; }
  .top-stats { gap: 14px; }
}

/* ---------- PANELS ---------- */
.panel {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  min-height: 200px;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.panel-header h2 { margin: 0; font-size: 14px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.panel-controls { display: flex; gap: 6px; align-items: center; }

select {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 12px;
}

.sse-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--muted);
  transition: background 0.2s, box-shadow 0.2s;
}
.sse-dot.on { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.sse-dot.stale { background: var(--amber); }

/* ---------- SIGNAL LIST ---------- */
.panel-feed { display: flex; flex-direction: column; max-height: calc(100vh - 120px); }
.signal-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
}
.signal-list::-webkit-scrollbar { width: 8px; }
.signal-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.sig {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
  animation: flash 0.6s ease-out;
}
.sig:hover { border-color: #334059; }
.sig.selected { border-color: var(--accent); background: rgba(17,194,127,0.06); }
@keyframes flash {
  from { background: rgba(17,194,127,0.18); }
  to { background: var(--bg-3); }
}

.sig-row1 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.sig-pair { font-weight: 700; font-family: var(--mono); font-size: 15px; }
.sig-side { font-family: var(--mono); font-size: 11px; padding: 2px 6px; border-radius: 4px; }
.sig-side.up { color: var(--accent); background: rgba(17,194,127,0.12); }
.sig-side.down { color: var(--red); background: rgba(239,87,87,0.12); }
.sig-edge { font-family: var(--mono); font-weight: 600; }
.sig-edge.pos { color: var(--accent); }
.sig-edge.neg { color: var(--red); }

.sig-row2 {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 11px;
  font-family: var(--mono);
}

/* ---------- TRADE TABLE ---------- */
.table-wrap { overflow-x: auto; }
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.tbl th, .tbl td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
}
.tbl th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
}
.tbl tbody tr { cursor: pointer; }
.tbl tbody tr:hover { background: rgba(255,255,255,0.02); }
.pnl.pos { color: var(--accent); }
.pnl.neg { color: var(--red); }
.status-open { color: var(--blue); }
.status-closed { color: var(--muted); }
.status-failed { color: var(--red); }

/* ---------- COPILOT ---------- */
.panel-copilot { display: flex; flex-direction: column; max-height: calc(100vh - 120px); }
.copilot-context {
  padding: 8px 10px;
  background: var(--bg-3);
  border-radius: 6px;
  font-size: 12px;
  margin-bottom: 10px;
}
.copilot-chat {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
  min-height: 200px;
  max-height: 420px;
}
.copilot-chat::-webkit-scrollbar { width: 8px; }
.copilot-chat::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.bubble {
  padding: 8px 12px;
  border-radius: 10px;
  max-width: 95%;
  font-size: 13px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.bubble.user { align-self: flex-end; background: var(--bg-3); border: 1px solid var(--border); }
.bubble.bot { align-self: flex-start; background: rgba(17,194,127,0.06); border: 1px solid rgba(17,194,127,0.18); }
.bubble.meta { font-size: 10px; color: var(--muted); align-self: flex-end; font-family: var(--mono); margin-top: -4px; }

.copilot-input-row {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}
.copilot-input-row textarea {
  flex: 1;
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  resize: none;
}
.copilot-input-row textarea:focus { outline: 1px solid var(--accent); }

.copilot-suggest {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

/* ---------- AUDIT ---------- */
.audit-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 11px;
}
.audit-item {
  display: flex;
  gap: 8px;
  padding: 3px 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.audit-item .ts { color: var(--muted); width: 58px; flex: none; }
.audit-item .ev { color: var(--blue); width: 140px; flex: none; overflow: hidden; text-overflow: ellipsis; }
.audit-item .dt { color: var(--muted); flex: 1; overflow: hidden; text-overflow: ellipsis; }

/* ---------- MODAL ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: min(720px, 92vw);
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 14px; }
.modal-card pre {
  margin: 0;
  padding: 16px;
  overflow: auto;
  font-size: 12px;
  font-family: var(--mono);
  color: var(--text);
  background: var(--bg);
}

/* ---------- TOAST ---------- */
.toast {
  position: fixed;
  bottom: 20px; right: 20px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  z-index: 30;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.hidden { opacity: 0; transform: translateY(6px); pointer-events: none; }
.toast.success { border-color: var(--accent); }
.toast.error { border-color: var(--red); }

/* ---------- MISC ---------- */
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
canvas#equity-chart { width: 100%; max-width: 100%; display: block; }
