@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121c;
  --bg-card: rgba(18,18,28,0.85);
  --bg-card-hover: rgba(24,24,36,0.95);
  --accent-gold: #d4a853;
  --accent-emerald: #34d399;
  --accent-rose: #f43f5e;
  --accent-blue: #3b82f6;
  --accent-purple: #a78bfa;
  --accent-cyan: #22d3ee;
  --text-primary: #f0f0f5;
  --text-secondary: #a1a1aa;
  --text-muted: #6b7280;
  --glass-border: rgba(255,255,255,0.08);
  --glass-border-hover: rgba(255,255,255,0.15);
  --glass-blur: 16px;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-glow: 0 0 40px rgba(212,168,83,0.15);
  --shadow-card: 0 8px 32px rgba(0,0,0,0.3);
  --transition: 0.3s cubic-bezier(0.4,0,0.2,1);
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

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

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background:
    radial-gradient(ellipse 800px 600px at 10% 10%, rgba(99,102,241,0.08), transparent),
    radial-gradient(ellipse 600px 500px at 80% 20%, rgba(212,168,83,0.06), transparent),
    radial-gradient(ellipse 500px 400px at 50% 80%, rgba(52,211,153,0.04), transparent);
  pointer-events: none; z-index: 0;
}

.dashboard { position: relative; z-index: 1; max-width: 1500px; margin: 0 auto; padding: 24px 28px 80px; }

/* ── Animations ── */
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 8px rgba(212,168,83,0.2); }
  50% { box-shadow: 0 0 20px rgba(212,168,83,0.4); }
}
@keyframes countUp { from { opacity: 0; transform: scale(0.5); } to { opacity: 1; transform: scale(1); } }
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.animate-in { animation: fadeSlideUp 0.5s ease-out both; }

/* ── Header ── */
.header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 0 28px; border-bottom: 1px solid var(--glass-border); margin-bottom: 28px;
}
.header-title { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.02em; }
.header-title span { color: var(--accent-gold); }
.header-right { display: flex; align-items: center; gap: 16px; }
.last-updated { font-size: 0.8rem; color: var(--text-muted); }
.btn-scan {
  padding: 10px 20px; background: rgba(212,168,83,0.1); border: 1px solid rgba(212,168,83,0.3);
  color: var(--accent-gold); border-radius: var(--radius-sm); font-weight: 600; cursor: pointer;
  transition: var(--transition); display: flex; align-items: center; gap: 8px; font-size: 0.85rem;
}
.btn-scan:hover { background: rgba(212,168,83,0.2); transform: translateY(-1px); box-shadow: 0 4px 16px rgba(212,168,83,0.2); }
.btn-scan:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ── Pipeline Funnel ── */
.pipeline-container {
  margin-bottom: 32px;
}
.pipeline-header {
  display: flex; align-items: center; gap: 10px;
  font-size: 1.1rem; font-weight: 700; margin-bottom: 16px;
}
.pipeline-header::after { content: ''; flex: 1; height: 1px; background: var(--glass-border); }

.pipeline-funnel {
  display: flex; align-items: stretch; gap: 0; position: relative;
  background: var(--bg-card); border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg); padding: 20px 8px; overflow-x: auto;
  backdrop-filter: blur(var(--glass-blur));
}

.pipeline-stage {
  flex: 1; min-width: 110px; display: flex; flex-direction: column;
  align-items: center; text-align: center; position: relative;
  padding: 8px 6px; cursor: pointer; transition: var(--transition);
  border-radius: var(--radius-sm);
}
.pipeline-stage:hover { background: rgba(255,255,255,0.03); }
.pipeline-stage.active { background: rgba(212,168,83,0.08); }

.stage-icon {
  width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; margin-bottom: 8px; transition: var(--transition);
  border: 2px solid var(--glass-border); background: var(--bg-secondary);
}
.pipeline-stage.completed .stage-icon { border-color: var(--accent-emerald); color: var(--accent-emerald); }
.pipeline-stage.active .stage-icon { border-color: var(--accent-gold); color: var(--accent-gold); animation: pulse-glow 2s infinite; }
.pipeline-stage.empty .stage-icon { border-color: var(--accent-rose); color: var(--accent-rose); }

.stage-label { font-size: 0.65rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; font-weight: 600; }
.stage-count {
  font-family: var(--font-mono); font-size: 1.2rem; font-weight: 700;
  animation: countUp 0.4s ease-out both;
}
.pipeline-stage.completed .stage-count { color: var(--accent-emerald); }
.pipeline-stage.active .stage-count { color: var(--accent-gold); }
.pipeline-stage.empty .stage-count { color: var(--accent-rose); }

.stage-arrow {
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 0.8rem; padding: 0 2px; flex-shrink: 0;
}
.stage-time { font-size: 0.6rem; color: var(--text-muted); margin-top: 2px; font-family: var(--font-mono); }

/* ── Pipeline Details Panel ── */
.pipeline-details {
  background: var(--bg-card); border: 1px solid var(--glass-border);
  border-radius: var(--radius-md); padding: 20px; margin-top: 12px;
  display: none; animation: fadeSlideUp 0.3s ease-out;
  backdrop-filter: blur(var(--glass-blur));
}
.pipeline-details.visible { display: block; }
.details-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.details-title { font-weight: 700; font-size: 1rem; display: flex; align-items: center; gap: 8px; }
.details-stats { display: flex; gap: 16px; font-size: 0.8rem; color: var(--text-secondary); }
.details-stats .stat { display: flex; align-items: center; gap: 4px; }
.details-stats .stat i { font-size: 0.7rem; }
.details-body { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.6; margin-bottom: 12px; }
.details-tickers { display: flex; flex-wrap: wrap; gap: 6px; }
.details-ticker-tag {
  padding: 3px 8px; border-radius: 4px; font-size: 0.7rem; font-family: var(--font-mono);
  background: rgba(255,255,255,0.05); color: var(--text-secondary); font-weight: 500;
}
.details-ticker-tag.passed { background: rgba(52,211,153,0.1); color: var(--accent-emerald); border: 1px solid rgba(52,211,153,0.2); }
.details-ticker-tag.rejected { background: rgba(244,63,94,0.1); color: var(--accent-rose); border: 1px solid rgba(244,63,94,0.2); text-decoration: line-through; }

.rejected-list { margin-top: 12px; }
.rejected-item {
  display: flex; align-items: flex-start; gap: 8px; padding: 6px 0;
  font-size: 0.78rem; border-bottom: 1px solid rgba(255,255,255,0.03);
}
.rejected-item:last-child { border-bottom: none; }
.rejected-item .ticker { font-family: var(--font-mono); color: var(--accent-rose); font-weight: 600; min-width: 80px; }
.rejected-item .reason { color: var(--text-muted); }

/* ── Stats Row ── */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 28px; }
.stat-card {
  background: var(--bg-card); border: 1px solid var(--glass-border); border-radius: var(--radius-md);
  padding: 16px 18px; backdrop-filter: blur(var(--glass-blur)); transition: var(--transition);
}
.stat-card:hover { border-color: var(--glass-border-hover); transform: translateY(-2px); }
.stat-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 6px; }
.stat-value { font-family: var(--font-mono); font-size: 1.4rem; font-weight: 700; }
.stat-value.gold { color: var(--accent-gold); }
.stat-value.green { color: var(--accent-emerald); }
.stat-value.blue { color: var(--accent-blue); }

/* ── Regime Banner ── */
.regime-banner {
  display: flex; gap: 16px; margin-bottom: 28px; flex-wrap: wrap;
}
.regime-card {
  flex: 1; min-width: 280px; background: var(--bg-card); border: 1px solid var(--glass-border);
  border-radius: var(--radius-md); padding: 16px 20px;
  backdrop-filter: blur(var(--glass-blur));
}
.regime-card-title { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 8px; }
.regime-badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px;
  border-radius: 20px; font-size: 0.8rem; font-weight: 600;
}
.regime-badge.bullish { background: rgba(52,211,153,0.15); color: var(--accent-emerald); border: 1px solid rgba(52,211,153,0.3); }
.regime-badge.bearish { background: rgba(244,63,94,0.15); color: var(--accent-rose); border: 1px solid rgba(244,63,94,0.3); }
.regime-badge.neutral { background: rgba(161,161,170,0.15); color: var(--text-secondary); border: 1px solid rgba(161,161,170,0.3); }
.regime-info { font-size: 0.8rem; color: var(--text-secondary); margin-top: 8px; line-height: 1.5; }

/* ── Signals Table ── */
.section-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 16px; display: flex; align-items: center; gap: 10px; }
.section-title::after { content: ''; flex: 1; height: 1px; background: var(--glass-border); }

.table-container {
  background: var(--bg-card); border: 1px solid var(--glass-border); border-radius: var(--radius-lg);
  backdrop-filter: blur(var(--glass-blur)); overflow-x: auto; margin-bottom: 32px;
}
.data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.data-table th {
  text-align: left; padding: 14px 16px; color: var(--text-muted); font-weight: 600;
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em;
  border-bottom: 1px solid var(--glass-border); position: sticky; top: 0; background: var(--bg-secondary);
}
.data-table td { padding: 14px 16px; border-bottom: 1px solid rgba(255,255,255,0.03); vertical-align: top; }
.data-table tr { cursor: pointer; transition: var(--transition); }
.data-table tr:hover td { background: rgba(255,255,255,0.02); }
.data-table tr.expanded td { background: rgba(212,168,83,0.03); }
.mono { font-family: var(--font-mono); }
.positive { color: var(--accent-emerald); }
.negative { color: var(--accent-rose); }

.ticker-cell { display: flex; flex-direction: column; gap: 2px; }
.ticker-name { font-weight: 700; font-size: 0.95rem; }
.ticker-sector { font-size: 0.65rem; color: var(--text-muted); }

/* ── Badges ── */
.badge {
  padding: 4px 8px; border-radius: 6px; font-size: 0.7rem; font-weight: 600;
  background: rgba(255,255,255,0.05); color: var(--text-secondary); white-space: nowrap;
}
.badge.gold { background: rgba(212,168,83,0.15); color: var(--accent-gold); border: 1px solid rgba(212,168,83,0.3); }
.badge.green { background: rgba(52,211,153,0.15); color: var(--accent-emerald); border: 1px solid rgba(52,211,153,0.2); }
.badge.blue { background: rgba(59,130,246,0.15); color: var(--accent-blue); border: 1px solid rgba(59,130,246,0.2); }

/* ── Narrative / Reason Detail Panel ── */
.narrative-row td {
  padding: 0 !important; border-bottom: 1px solid rgba(255,255,255,0.05) !important;
}
.narrative-container {
  padding: 16px 24px 20px; background: rgba(0,0,0,0.2);
  border-left: 3px solid var(--accent-gold);
}
.narrative-section { margin-bottom: 12px; }
.narrative-section:last-child { margin-bottom: 0; }
.narrative-heading {
  font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--accent-gold); margin-bottom: 6px; display: flex; align-items: center; gap: 6px;
}
.narrative-heading i { font-size: 0.7rem; }
.narrative-body { font-size: 0.8rem; color: var(--text-secondary); line-height: 1.7; }
.narrative-metric { font-family: var(--font-mono); font-weight: 600; color: var(--text-primary); }
.narrative-metric.gold { color: var(--accent-gold); }
.narrative-tag {
  display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 0.7rem;
  background: rgba(255,255,255,0.05); font-weight: 500;
}
.narrative-source { font-size: 0.7rem; color: var(--text-muted); }
.narrative-sentiment { font-weight: 600; }
.narrative-sentiment.positive { color: var(--accent-emerald); }
.narrative-sentiment.negative { color: var(--accent-rose); }
.narrative-sentiment.neutral { color: var(--text-secondary); }

/* ── Expand indicator ── */
.expand-indicator { color: var(--text-muted); font-size: 0.8rem; transition: var(--transition); }
.expanded .expand-indicator { transform: rotate(90deg); color: var(--accent-gold); }

/* ── Scan Progress Overlay ── */
.scan-progress {
  display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(10,10,15,0.85); z-index: 9998; backdrop-filter: blur(8px);
  justify-content: center; align-items: center;
}
.scan-progress.active { display: flex; }
.progress-card {
  background: var(--bg-secondary); border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg); padding: 40px 48px; text-align: center;
  max-width: 420px; width: 90%; box-shadow: 0 16px 64px rgba(0,0,0,0.5);
}
.progress-spinner { font-size: 2.5rem; color: var(--accent-gold); margin-bottom: 16px; }
.progress-title { font-size: 1.2rem; font-weight: 700; margin-bottom: 8px; }
.progress-step { font-size: 0.85rem; color: var(--text-secondary); }
.progress-bar-track {
  width: 100%; height: 4px; background: rgba(255,255,255,0.05);
  border-radius: 2px; margin-top: 16px; overflow: hidden;
}
.progress-bar-fill {
  height: 100%; background: linear-gradient(90deg, var(--accent-gold), var(--accent-emerald));
  border-radius: 2px; width: 0%; transition: width 0.5s ease;
  background-size: 200% 100%; animation: shimmer 2s linear infinite;
}

/* ── Chat Panel ── */
.chat-fab {
  position: fixed; bottom: 28px; right: 28px; width: 56px; height: 56px;
  border-radius: 50%; background: linear-gradient(135deg, var(--accent-gold), #b8892a);
  border: none; color: var(--bg-primary); cursor: pointer; box-shadow: 0 4px 24px rgba(212,168,83,0.4);
  z-index: 9999; display: flex; align-items: center; justify-content: center; font-size: 1.5rem;
  transition: all 0.3s ease;
}
.chat-fab:hover { transform: scale(1.1); }

.chat-panel {
  position: fixed; bottom: 28px; right: 28px; width: 420px; height: 600px;
  background: var(--bg-secondary); border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg); box-shadow: 0 16px 64px rgba(0,0,0,0.5);
  z-index: 10000; display: flex; flex-direction: column; overflow: hidden;
  transform: scale(0.5) translateY(100px); opacity: 0; pointer-events: none;
  transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1); transform-origin: bottom right;
}
.chat-panel.open { transform: scale(1) translateY(0); opacity: 1; pointer-events: all; }

.chat-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 18px; border-bottom: 1px solid var(--glass-border);
  background: rgba(212,168,83,0.05);
}
.chat-title { font-weight: 700; color: var(--text-primary); }
.chat-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1.2rem; }

.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.chat-msg { display: flex; gap: 8px; max-width: 90%; }
.chat-msg-user { align-self: flex-end; flex-direction: row-reverse; }
.chat-msg-bot { align-self: flex-start; }
.chat-bubble { padding: 12px 16px; border-radius: 14px; font-size: 0.85rem; line-height: 1.5; }
.chat-msg-user .chat-bubble { background: linear-gradient(135deg, var(--accent-gold), #b8892a); color: var(--bg-primary); border-bottom-right-radius: 4px; font-weight: 500; }
.chat-msg-bot .chat-bubble { background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border); color: var(--text-primary); border-bottom-left-radius: 4px; }

.chat-input-area { padding: 16px; border-top: 1px solid var(--glass-border); display: flex; gap: 8px; }
.chat-input {
  flex: 1; padding: 12px 16px; background: var(--bg-card); border: 1px solid var(--glass-border);
  border-radius: var(--radius-md); color: var(--text-primary); font-family: var(--font-body);
  outline: none; transition: var(--transition);
}
.chat-input:focus { border-color: var(--accent-gold); }
.chat-send {
  background: var(--accent-gold); color: var(--bg-primary); border: none; border-radius: var(--radius-md);
  padding: 0 16px; cursor: pointer; font-weight: 700; transition: var(--transition);
}
.chat-send:hover { background: #e9c06a; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ── Responsive ── */
@media (max-width: 768px) {
  .dashboard { padding: 16px 12px 80px; }
  .header { flex-direction: column; gap: 12px; align-items: flex-start; }
  .pipeline-funnel { padding: 12px 4px; }
  .pipeline-stage { min-width: 80px; }
  .regime-banner { flex-direction: column; }
}
