/* ═══════════════════════════════════════════════════════
   Deep Value Screener — Professional Financial Dashboard
   ═══════════════════════════════════════════════════════ */

:root {
  --bg-primary: #0d1117;
  --bg-card: #161b22;
  --bg-card-hover: #1c2333;
  --bg-header: #010409;
  --border: #30363d;
  --border-light: #21262d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent: #0f3460;
  --accent-light: #1a4a7a;
  --green: #4ade80;
  --green-dim: #22543d;
  --red: #f87171;
  --red-dim: #7f1d1d;
  --yellow: #fbbf24;
  --yellow-dim: #78350f;
  --orange: #fb923c;
  --blue: #60a5fa;
  --purple: #a78bfa;
  --cyan: #22d3ee;
  --warning: #e94560;
  --font-mono: 'SF Mono', 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --radius: 8px;
  --radius-sm: 4px;
}

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

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Top Bar ──────────────────────────────────────────── */

.top-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  backdrop-filter: blur(12px);
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.timestamp {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.index-tabs {
  display: flex;
  gap: 2px;
}

.tab {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.5rem 1.2rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
  letter-spacing: 0.05em;
}

.tab:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.tab.active {
  background: var(--accent);
  color: #fff;
}

/* ── Loading / Error States ───────────────────────────── */

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 60vh;
  color: var(--text-muted);
  gap: 1rem;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error-state {
  text-align: center;
  padding: 4rem 2rem;
}

.error-msg {
  color: var(--red);
  font-size: 1rem;
}

/* ── Pipeline Bar ─────────────────────────────────────── */

.pipeline-bar {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.pipeline-step {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.pipeline-arrow {
  color: var(--text-muted);
}

.pipeline-num {
  color: var(--text-primary);
  font-weight: 600;
}

/* ── Main Grid ────────────────────────────────────────── */

.dashboard {
  padding: 1rem 1.5rem 2rem;
  max-width: 1600px;
  margin: 0 auto;
}

.main-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 1rem;
  align-items: start;
}

.col-left {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.col-right {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: sticky;
  top: 72px;
}

/* ── Cards ────────────────────────────────────────────── */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
}

.card-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ── Data Tables ──────────────────────────────────────── */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  white-space: nowrap;
}

.data-table th {
  text-align: left;
  padding: 0.5rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  position: relative;
}

.data-table th.num {
  text-align: right;
}

.data-table th:hover {
  color: var(--text-secondary);
}

.data-table th.sorted-asc::after { content: ' \25B2'; font-size: 0.65rem; }
.data-table th.sorted-desc::after { content: ' \25BC'; font-size: 0.65rem; }

.data-table td {
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
}

.data-table td.num {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

.data-table tbody tr {
  transition: background 0.1s;
}

.data-table tbody tr:hover {
  background: var(--bg-card-hover);
}

.data-table tfoot td {
  font-weight: 700;
  border-top: 2px solid var(--border);
  border-bottom: none;
  color: var(--text-primary);
}

/* ── Ticker Cell ──────────────────────────────────────── */

.ticker {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.9rem;
  letter-spacing: 0.02em;
}

.sector-tag {
  font-size: 0.7rem;
  color: var(--text-muted);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Score Bar ────────────────────────────────────────── */

.score-cell {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  justify-content: flex-end;
}

.score-bar {
  width: 50px;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.score-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}

.score-num {
  font-family: var(--font-mono);
  font-weight: 600;
  min-width: 32px;
  text-align: right;
}

/* ── Weight Bar (position table) ──────────────────────── */

.weight-cell {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  justify-content: flex-end;
}

.weight-bar {
  width: 40px;
  height: 5px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.weight-bar-fill {
  height: 100%;
  background: var(--blue);
  border-radius: 3px;
}

/* ── Color Utilities ──────────────────────────────────── */

.positive { color: var(--green); }
.negative { color: var(--red); }
.neutral { color: var(--text-secondary); }
.warning { color: var(--yellow); }

/* ── Risk Card ────────────────────────────────────────── */

.sharpe-display {
  text-align: center;
  padding: 1rem 0;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border-light);
}

.sharpe-label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.sharpe-value {
  font-family: var(--font-mono);
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.sharpe-good { color: var(--green); }
.sharpe-ok { color: var(--yellow); }
.sharpe-poor { color: var(--red); }

.risk-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.risk-stat {
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
}

.risk-stat-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.15rem;
}

.risk-stat-value {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 600;
}

.risk-meta {
  margin-top: 0.75rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ── Score Legend ──────────────────────────────────────── */

.score-legend {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Value Trap Card ──────────────────────────────────── */

.trap-badge {
  background: var(--warning);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  font-family: var(--font-mono);
}

.trap-breakdown {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.trap-type-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  padding: 0.3rem 0;
}

.trap-type-name {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.trap-type-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.trap-type-count {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-secondary);
}

.expand-btn {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.8rem;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  width: 100%;
  transition: all 0.15s;
}

.expand-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.trap-detail {
  margin-top: 0.75rem;
}

.trap-table .trap-type-tag {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.trap-tag-momentum { background: var(--orange); color: #000; }
.trap-tag-altman_z { background: var(--red); color: #fff; }
.trap-tag-dividend_trap { background: var(--yellow); color: #000; }
.trap-tag-forward_pe_revision { background: var(--purple); color: #fff; }
.trap-tag-legacy { background: var(--text-muted); color: var(--bg-primary); }

.trap-reason {
  max-width: 250px;
  white-space: normal;
  font-size: 0.75rem;
  color: var(--text-secondary);
  line-height: 1.3;
}

/* ── Footer ───────────────────────────────────────────── */

.footer {
  max-width: 1600px;
  margin: 0 auto;
  padding: 1rem 1.5rem 2rem;
  border-top: 1px solid var(--border-light);
}

.glossary {
  margin-bottom: 1rem;
}

.glossary summary {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.5rem 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.glossary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.4rem 2rem;
  padding: 0.75rem 0;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.glossary-grid strong {
  font-family: var(--font-mono);
  color: var(--text-primary);
  margin-right: 0.3rem;
}

.attribution {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
}

/* ── Responsive ───────────────────────────────────────── */

@media (max-width: 1024px) {
  .main-grid {
    grid-template-columns: 1fr;
  }

  .col-right {
    position: static;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
  }
}

@media (max-width: 768px) {
  html { font-size: 13px; }

  .top-bar {
    flex-direction: column;
    height: auto;
    padding: 0.75rem 1rem;
    gap: 0.5rem;
  }

  .top-bar-left {
    width: 100%;
    justify-content: space-between;
  }

  .index-tabs {
    width: 100%;
    justify-content: stretch;
  }

  .tab {
    flex: 1;
    text-align: center;
  }

  .dashboard {
    padding: 0.75rem;
  }

  .col-right {
    grid-template-columns: 1fr;
  }

  .risk-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 480px) {
  .logo { font-size: 0.95rem; }
  .tab { padding: 0.4rem 0.8rem; font-size: 0.8rem; }
}

/* ── Animations ───────────────────────────────────────── */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.card {
  animation: fadeIn 0.3s ease-out both;
}

.col-left .card:nth-child(1) { animation-delay: 0.05s; }
.col-left .card:nth-child(2) { animation-delay: 0.1s; }
.col-right .card:nth-child(1) { animation-delay: 0.08s; }
.col-right .card:nth-child(2) { animation-delay: 0.12s; }
.col-right .card:nth-child(3) { animation-delay: 0.16s; }
