:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel2: #1c2330;
  --border: #2a3140;
  --text: #d7dee8;
  --muted: #8b97a7;
  --accent: #4ea1ff;
  --pos: #3fb950;
  --neg: #f85149;
  --warn: #d29922;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 16px; }
.topbar nav { display: flex; align-items: center; gap: 16px; }
.who { color: var(--muted); }
.badge { font-size: 10px; padding: 2px 6px; border-radius: 4px; margin-left: 8px; vertical-align: middle; }
.badge.testnet { background: #1f6feb33; color: #6cb6ff; border: 1px solid #1f6feb; }
.badge.live { background: #f8514922; color: #ff7b72; border: 1px solid #f85149; }

.container { max-width: 1600px; margin: 24px auto; padding: 0 20px; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 24px; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.flash.error { background: #f8514922; border: 1px solid var(--neg); color: #ff9a92; }
.flash.ok { background: #3fb95022; border: 1px solid var(--pos); color: #7ee787; }

.auth-card {
  max-width: 380px; margin: 60px auto; background: var(--panel);
  border: 1px solid var(--border); border-radius: 12px; padding: 28px;
}
.auth-card h1 { margin-top: 0; }

label { display: block; margin: 12px 0; color: var(--muted); font-size: 13px; }
input, select {
  width: 100%; margin-top: 4px; padding: 9px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: #0b0f15; color: var(--text); font-size: 14px;
}
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
label.check input { width: auto; margin: 0; }
label.check.warn { color: #ffce6e; }
small.muted { font-weight: 400; }

button {
  cursor: pointer; border: 1px solid var(--border); background: var(--panel2);
  color: var(--text); padding: 9px 16px; border-radius: 8px; font-size: 14px;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #04101e; font-weight: 600; }
button.danger { background: transparent; border-color: var(--neg); color: var(--neg); }
button.small { padding: 4px 10px; font-size: 12px; }
button.link { background: none; border: none; color: var(--muted); padding: 0; }
.inline { display: inline; }
.mt { margin-top: 12px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin: 18px 0; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.card-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.card-value { font-size: 24px; font-weight: 700; margin-top: 6px; }
.card-sub { color: var(--muted); font-size: 12px; margin-top: 4px; }

.shadow-lab { padding: 16px; }
.shadow-lab-head { align-items: flex-start; }
.parity-line {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  border: 1px solid var(--border);
}
.parity-line.ok { color: var(--pos); background: #3fb95018; border-color: #3fb95066; }
.parity-line.warn { color: var(--warn); background: #d2992218; border-color: #d2992266; }
.shadow-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.shadow-card {
  min-height: 260px;
  background: #111720;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.shadow-card.main { border-color: var(--accent); box-shadow: inset 0 0 0 1px #4ea1ff44; }
.shadow-card.gain { background: linear-gradient(180deg, #132018 0%, #111720 46%); }
.shadow-card.loss { background: linear-gradient(180deg, #211515 0%, #111720 46%); }
.shadow-card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.shadow-rank {
  color: var(--text);
  background: #263142;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 700;
}
.shadow-kind {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .06em;
}
.shadow-card h3 {
  margin: 0;
  font-size: 14px;
  line-height: 1.25;
  min-height: 34px;
}
.shadow-start {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.25;
}
.shadow-start strong {
  color: var(--text);
  font-weight: 700;
}
.shadow-equity { font-size: 20px; font-weight: 800; line-height: 1.1; }
.shadow-pnl { font-size: 13px; font-weight: 700; }
.shadow-spark {
  color: var(--accent);
  height: 44px;
  border: 1px solid #253044;
  border-radius: 8px;
  background: #0d1117;
  overflow: hidden;
}
.shadow-card.gain .shadow-spark { color: var(--pos); }
.shadow-card.loss .shadow-spark { color: var(--neg); }
.shadow-spark svg { width: 100%; height: 44px; display: block; }
.shadow-spark-empty { height: 44px; background: repeating-linear-gradient(90deg, #151b25, #151b25 4px, #111720 4px, #111720 8px); opacity: .7; }
.shadow-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px 8px;
  color: var(--muted);
  font-size: 11px;
}
.shadow-metrics strong { color: var(--text); font-weight: 700; }
.shadow-card p {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  margin: auto 0 0;
}

.research-head { align-items: flex-start; }
.research-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.research-kpis div {
  background: #111720;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}
.research-kpis span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.research-kpis strong { display: block; margin-top: 4px; font-size: 20px; }
.research-grid {
  display: grid;
  grid-template-columns: minmax(260px, 1.2fr) repeat(2, minmax(220px, 1fr));
  gap: 14px;
  margin: 10px 0 14px;
}
.research-grid.compact { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.research-panel h3 { margin: 10px 0 8px; font-size: 13px; color: var(--text); }
.research-list { margin: 0; padding-left: 18px; color: var(--muted); }
.research-list li { margin: 5px 0; }
.research-table { font-size: 12px; }
.research-table th,
.research-table td { padding: 6px 8px; white-space: nowrap; }
.historical-panel h3 { margin: 10px 0 8px; font-size: 13px; color: var(--text); }
.historical-progress { margin: 6px 0 14px; }
.historical-progress-bar {
  height: 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #0d1117;
  overflow: hidden;
}
.historical-progress-bar span {
  display: block;
  height: 100%;
  min-width: 2px;
  background: linear-gradient(90deg, var(--accent), var(--pos));
}
.historical-progress-line {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 18px; margin: 16px 0; }
.panel h2 { margin: 0 0 12px; font-size: 16px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.panel-head h2 { margin: 0; }

.strategy-list { margin: 10px 0; padding-left: 20px; }
.strategy-list li { margin: 8px 0; font-size: 14px; line-height: 1.5; }

.status-bar {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--neg);
  border-radius: 12px; padding: 14px 18px;
}
.status-bar.on { border-left-color: var(--pos); }
.status-bar .actions { display: flex; align-items: center; gap: 12px; }
.mode { color: var(--muted); margin-left: 12px; font-size: 12px; }
.run-mode {
  display: inline-flex; align-items: center; margin-left: 12px; padding: 4px 10px;
  border-radius: 6px; font-size: 12px; font-weight: 800; letter-spacing: .04em;
}
.run-mode.paper { background: #1f6feb33; color: #9dccff; border: 1px solid #1f6feb; }
.run-mode.live { background: #f8514933; color: #ff9a92; border: 1px solid var(--neg); }
.warn-link { color: var(--warn); }

.pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 700; }
.pill.on { background: #3fb95022; color: var(--pos); border: 1px solid var(--pos); }
.pill.off { background: #f8514922; color: var(--neg); border: 1px solid var(--neg); }
.pill.warn { background: #d2992222; color: var(--warn); border: 1px solid var(--warn); }

.pipeline-panel h3 { margin: 0 0 4px; font-size: 13px; color: var(--text); }
.pipeline-flow {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin: 10px 0 14px;
}
.pipeline-step {
  min-height: 126px;
  background: #111720;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pipeline-step.ready,
.pipeline-step.complete,
.pipeline-step.running { border-color: #3fb95066; }
.pipeline-step.waiting { border-color: #d2992266; }
.pipeline-step.error { border-color: #f8514966; }
.pipeline-step-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}
.pipeline-index {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: #263142;
  color: var(--text);
  font-size: 11px;
  font-weight: 800;
}
.pipeline-title {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pipeline-step strong {
  display: block;
  font-size: 20px;
  line-height: 1.15;
}
.pipeline-step p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.pipeline-dataset {
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.pipeline-dataset-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.pipeline-kpis { margin-top: 10px; }
.pipeline-prefetch .research-kpis strong {
  font-size: 16px;
  overflow-wrap: anywhere;
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
.table-wrap { width: 100%; overflow-x: auto; }
.positions-table th, .positions-table td { white-space: nowrap; }
.positions-table .table-actions { text-align: right; padding-right: 0; }
.candidates-table th,
.candidates-table td { white-space: nowrap; }
.factor-table th,
.factor-table td { white-space: nowrap; }

.pos { color: var(--pos); }
.neg { color: var(--neg); }
.muted { color: var(--muted); }

.spark { width: 100%; height: 60px; display: block; }

.equity-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.equity-now { font-size: 20px; font-weight: 700; }
.equity-wrap { position: relative; }
.equity-cursor { position: absolute; top: 0; width: 1px; height: 60px; background: var(--muted); opacity: .5; display: none; pointer-events: none; }
.equity-dot { position: absolute; width: 7px; height: 7px; margin: -3.5px 0 0 -3.5px; border-radius: 50%; background: var(--accent); display: none; pointer-events: none; }
.equity-tip {
  position: absolute; top: -6px; transform: translate(-50%, -100%);
  background: var(--panel2); border: 1px solid var(--border); border-radius: 6px;
  padding: 3px 7px; font-size: 11px; white-space: nowrap; display: none;
  pointer-events: none; z-index: 5;
}

.log { list-style: none; margin: 0; padding: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.log li { padding: 3px 0; border-bottom: 1px solid #1c222d; }
.log .ts { color: var(--muted); margin-right: 8px; }
.log .lvl-error { color: #ff9a92; }
.log .lvl-warn { color: #ffce6e; }
.log .lvl-trade { color: #7ee787; }

fieldset { border: 1px solid var(--border); border-radius: 10px; margin: 14px 0; padding: 14px; }
legend { color: var(--muted); padding: 0 6px; font-size: 12px; text-transform: uppercase; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 4px 16px; }

/* clickable candidate symbol */
.token-link { background: none; border: none; color: var(--accent); padding: 0; font: inherit; cursor: pointer; }
.token-link:hover { text-decoration: underline; }

/* inline token detail (expands in a row below the clicked one) */
.token-detail-row td { background: #0b0f15; padding: 16px; white-space: normal; }
.token-detail h3 { margin: 0 0 8px; }
.token-stats { display: flex; flex-wrap: wrap; gap: 18px; font-size: 13px; margin-bottom: 12px; }
.chart-block { margin: 14px 0; }
.chart-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.chart { width: 100%; height: 120px; display: block; background: #11161f; border: 1px solid var(--border); border-radius: 8px; }

@media (max-width: 920px) {
  .pipeline-flow { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .topbar,
  .status-bar,
  .panel-head,
  .pipeline-dataset-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .status-bar .actions { flex-wrap: wrap; }
  .pipeline-flow { grid-template-columns: 1fr; }
}
