/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d1117;
  --surface:   #161b22;
  --surface2:  #21262d;
  --border:    #30363d;
  --text:      #e6edf3;
  --muted:     #8b949e;
  --green:     #2ea043;
  --red:       #f85149;
  --yellow:    #d29922;
  --blue:      #58a6ff;
  --purple:    #a371f7;
  --radius:    8px;
  --nav-h:     52px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
strong { font-weight: 600; }

/* ── Navigation ───────────────────────────────────────────────────────────── */
.topnav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}

.brand {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}
.brand:hover { text-decoration: none; color: var(--blue); }

.nav-links { display: flex; gap: 4px; }
.nav-links a {
  padding: 6px 14px;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 500;
  transition: color 0.15s, background 0.15s;
}
.nav-links a:hover { color: var(--text); background: var(--surface2); text-decoration: none; }
.nav-links a.active { color: var(--text); background: var(--surface2); }

/* ── Page layout ──────────────────────────────────────────────────────────── */
.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 24px 48px;
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 1.4rem;
  font-weight: 700;
}

.last-updated {
  font-size: 0.8rem;
  color: var(--muted);
}

.empty-state {
  text-align: center;
  padding: 64px 24px;
  color: var(--muted);
}

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

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-bull { background: rgba(46,160,67,0.15);  color: #3fb950; border: 1px solid rgba(46,160,67,0.3); }
.badge-bear { background: rgba(248,81,73,0.15);  color: #ff7b72; border: 1px solid rgba(248,81,73,0.3); }

.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
}
.status-inside    { background: rgba(46,160,67,0.15);  color: #3fb950; }
.status-approaching { background: rgba(210,153,34,0.15); color: #e3b341; }

/* ── Score pill ───────────────────────────────────────────────────────────── */
.score-pill {
  display: inline-block;
  min-width: 36px;
  text-align: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.85rem;
}
.score-high { background: rgba(46,160,67,0.2);  color: #3fb950; }
.score-mid  { background: rgba(210,153,34,0.2); color: #e3b341; }
.score-low  { background: rgba(139,148,158,0.2);color: var(--muted); }

/* ── Signals table ────────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.signals-table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
}

.signals-table thead tr {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.signals-table th {
  padding: 10px 16px;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.signals-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--surface2);
  vertical-align: middle;
}

.signals-table tbody tr:last-child td { border-bottom: none; }
.signals-table tbody tr:hover { background: var(--surface); }

.col-ticker { font-size: 0.9rem; }
.col-time   { font-size: 0.8rem; min-width: 90px; }
.col-score  { min-width: 70px; }
.col-chart  { text-align: right; }

.chart-link {
  font-size: 0.8rem;
  color: var(--blue);
  opacity: 0.7;
  white-space: nowrap;
}
.chart-link:hover { opacity: 1; text-decoration: none; }

/* ── Chart page ───────────────────────────────────────────────────────────── */
.chart-page { max-width: 100%; padding: 0; }

.chart-back {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  background: var(--surface);
}
.chart-back a { color: var(--muted); }
.chart-back a:hover { color: var(--text); text-decoration: none; }
.chart-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.chart-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  height: calc(100vh - var(--nav-h) - 49px);
  min-height: 480px;
}

#chart {
  width: 100%;
  height: 100%;
}

.no-chart {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 8px;
  color: var(--muted);
  background: var(--surface);
}

.signal-panel {
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 0;
}

.panel-section {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.panel-section h3 {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 10px;
}

.score-row {
  display: flex;
  align-items: center;
  gap: 20px;
}

.big-score {
  font-size: 2.4rem;
  font-weight: 700;
  line-height: 1;
  color: var(--blue);
}

.score-details {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.8rem;
  color: var(--muted);
}
.score-details strong { color: var(--text); }

.pivot-table, .level-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.pivot-table th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  padding: 0 0 6px;
  font-size: 0.72rem;
  text-transform: uppercase;
}
.pivot-table td, .level-table td {
  padding: 4px 6px 4px 0;
  vertical-align: top;
}
.pivot-table td:first-child { width: 28px; }

.prz-row td { color: var(--blue); }

.level-table td:first-child { color: var(--muted); width: 80px; }
.level-sl { color: var(--red) !important; }
.level-tp { color: var(--blue) !important; }

/* ── Sentiment page ───────────────────────────────────────────────────────── */
.sentiment-page { max-width: 960px; }

.composite-section {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 40px;
  margin-bottom: 32px;
  padding: 32px 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.composite-gauge-wrap {
  flex-shrink: 0;
  text-align: center;
  min-width: 200px;
}

.gauge-lg { width: 220px; height: 130px; }
.gauge-sm { width: 160px; height: 96px; }

.gauge-reading {
  margin-top: -4px;
  text-align: center;
}
.gauge-reading.sm { margin-top: -2px; }

.gauge-value {
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1;
}
.gauge-reading.sm .gauge-value { font-size: 1.5rem; }

.gauge-label {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 2px;
}
.gauge-reading.sm .gauge-label { font-size: 0.72rem; }

.gauge-na {
  width: 160px;
  height: 96px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.8rem;
}

.composite-meta { flex: 1; }
.meta-date { font-size: 1.1rem; font-weight: 600; margin-bottom: 8px; }
.meta-desc { color: var(--muted); font-size: 0.85rem; line-height: 1.6; }

.source-cards-row {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 40px;
  flex-wrap: wrap;
}

.source-card {
  flex: 0 0 280px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 20px 20px;
  text-align: center;
}

.source-gauge-wrap { margin-bottom: 8px; }

.source-name {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 6px;
}

.source-reasoning {
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--muted);
}

.history-section { margin-top: 8px; }
.history-section h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.78rem;
}

.history-chart-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  height: 240px;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 800px) {
  .chart-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 360px auto;
    height: auto;
  }
  .signal-panel {
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .composite-section {
    flex-direction: column;
    gap: 20px;
    text-align: center;
  }
  .source-cards-row {
    flex-direction: column;
    align-items: center;
  }
  .source-card { flex: 0 0 auto; width: 100%; max-width: 320px; }
}

@media (max-width: 480px) {
  .topnav { padding: 0 16px; }
  .page   { padding: 20px 16px 40px; }
}
