:root {
  --bg: #0d1117;
  --bg-2: #161b22;
  --bg-3: #21262d;
  --fg: #e6edf3;
  --fg-2: #7d8590;
  --accent: #2f81f7;
  --pos: #3fb950;
  --neg: #f85149;
  --strong: #f0883e;
  --border: #30363d;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

.app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 16px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

h1 { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; }
.subtitle { color: var(--fg-2); font-size: 13px; margin-top: 4px; }

.header-stats {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.stat {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 14px;
  min-width: 80px;
}
.stat-label { color: var(--fg-2); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 16px; font-weight: 600; margin-top: 2px; }

main {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 24px;
  flex: 1;
}

.history {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  height: fit-content;
}
.history-title { color: var(--fg-2); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; }
.history ul { list-style: none; }
.history li {
  display: flex;
  justify-content: space-between;
  padding: 6px 8px;
  cursor: pointer;
  border-radius: 4px;
  font-size: 12px;
}
.history li:hover { background: var(--bg-3); }
.history li.active { background: var(--accent); color: white; }
.history li .count { color: var(--fg-2); }
.history li.active .count { color: rgba(255, 255, 255, 0.8); }

.signals-pane {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

table.signals {
  width: 100%;
  border-collapse: collapse;
}
table.signals th, table.signals td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
table.signals th {
  background: var(--bg-3);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-2);
}
table.signals td.num, table.signals th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.signals td.rank { font-weight: 700; color: var(--accent); width: 40px; }
table.signals td.ticker { font-weight: 600; font-size: 14px; }
table.signals td.pos { color: var(--pos); }
table.signals td.neg { color: var(--neg); }
table.signals td.strong { color: var(--strong); font-weight: 600; }
table.signals tr:last-child td { border-bottom: none; }
table.signals tr:hover td { background: var(--bg-3); }

.empty, .loading, .error {
  padding: 60px 24px;
  text-align: center;
  color: var(--fg-2);
}
.error { color: var(--neg); }

footer {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  color: var(--fg-2);
  font-size: 12px;
  text-align: center;
}
footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* Status dots — yfinance + scan steps in pipeline sidebar */
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}
.dot-success  { background: var(--pos); }
.dot-failed   { background: var(--neg); }
.dot-running  { background: var(--strong); animation: pulse 1.6s infinite; }
.dot-missing  { background: var(--fg-2); opacity: 0.4; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.4; }
}

.legend {
  font-size: 10px;
  color: var(--fg-2);
  margin-bottom: 8px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.legend .dot { width: 6px; height: 6px; margin-right: 2px; }

.history li .dots { margin-right: 4px; }

/* Banner across the top of main content area */
.banner {
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 13px;
  border: 1px solid;
}
.banner-error {
  background: rgba(248, 81, 73, 0.1);
  border-color: var(--neg);
  color: var(--neg);
}
.banner-warn {
  background: rgba(240, 136, 62, 0.1);
  border-color: var(--strong);
  color: var(--strong);
}

/* Pipeline detail panel above the signals table */
.pipeline-detail {
  background: var(--bg-3);
  border-bottom: 1px solid var(--border);
  padding: 14px 18px;
}
.detail-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-2);
  margin-bottom: 10px;
}
.step-row {
  padding: 8px 0;
  border-top: 1px solid var(--border);
}
.step-row:first-of-type { border-top: none; }
.step-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.step-name {
  font-weight: 600;
  color: var(--fg);
  font-size: 12px;
}
.step-meta {
  color: var(--fg-2);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.step-error {
  color: var(--neg);
  font-size: 12px;
  background: rgba(248, 81, 73, 0.08);
  border-left: 3px solid var(--neg);
  padding: 4px 8px;
  margin: 6px 0;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.step-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 28px;
  margin-top: 4px;
  margin-left: 16px;
}
.metric {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.metric-value {
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
}
.metric-warn .metric-value { color: var(--neg); }
.metric-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-2);
}

/* Clickable signals row */
table.signals tr.clickable { cursor: pointer; }
table.signals tr.clickable:hover td { background: var(--bg-3); }
table.signals .hint {
  color: var(--accent);
  font-weight: 400;
  margin-left: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}
table.signals tr.clickable:hover .hint { opacity: 1; }

/* Modal — signal detail */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
}
.modal {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 100%;
  max-width: 760px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.modal-rank {
  font-size: 11px;
  font-weight: 500;
  color: var(--fg-2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.modal-subtitle {
  color: var(--fg-2);
  font-size: 12px;
  margin-top: 4px;
}
.close {
  background: none;
  border: none;
  color: var(--fg-2);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.close:hover { color: var(--fg); }

table.conditions {
  width: 100%;
  border-collapse: collapse;
}
table.conditions thead tr th {
  background: var(--bg-3);
  color: var(--fg-2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 10px;
  font-weight: 600;
  padding: 10px 24px;
  text-align: left;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
table.conditions tbody tr { border-bottom: 1px solid var(--border); }
table.conditions tbody tr:last-child { border-bottom: none; }
table.conditions td { padding: 8px 12px; vertical-align: middle; }
.cond-num {
  width: 32px;
  text-align: center;
  color: var(--fg-2);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  padding-left: 24px !important;
}
.cond-label {
  font-weight: 500;
  font-size: 13px;
  width: 35%;
}
.cond-detail {
  color: var(--fg-2);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.cond-status {
  width: 36px;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  padding-right: 24px !important;
}
.cond-pass .cond-status { color: var(--pos); }
.cond-fail .cond-status { color: var(--neg); }
.cond-fail .cond-label { color: var(--neg); }

.trade-plan {
  background: var(--bg-3);
  border-top: 1px solid var(--border);
  padding: 16px 24px;
}
.trade-plan-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-2);
  margin-bottom: 8px;
}
table.plan {
  width: 100%;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}
table.plan td { padding: 4px 0; }
table.plan td:last-child { text-align: right; font-weight: 600; }

@media (max-width: 768px) {
  main { grid-template-columns: 1fr; }
  .header-stats { width: 100%; }
  .pipeline-detail { flex-direction: column; gap: 8px; }
  .modal { max-width: 100%; }
  .modal-header { padding: 16px; }
  table.conditions thead tr th,
  .cond-num, .cond-status { padding-left: 12px !important; padding-right: 12px !important; }
}
