:root {
  --bg:       #0f172a;
  --surface:  #1e293b;
  --border:   #334155;
  --text:     #f1f5f9;
  --muted:    #94a3b8;
  --accent:   #3b82f6;
  --green:    #22c55e;
  --red:      #ef4444;
  --yellow:   #f59e0b;
  --radius:   8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Nav ─────────────────────────────────────────────────────── */
nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-brand { font-weight: 700; font-size: 18px; color: var(--text); }
.nav-brand span { color: var(--accent); }
.nav-links { display: flex; gap: 20px; }
.nav-links a { color: var(--muted); font-size: 13px; }
.nav-links a:hover { color: var(--text); text-decoration: none; }
.nav-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  padding: 7px 14px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: opacity .15s;
}
.btn:hover { opacity: .85; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ── Main container ──────────────────────────────────────────── */
.container { max-width: 1400px; margin: 0 auto; padding: 24px; }

/* ── Stats bar ───────────────────────────────────────────────── */
.stats-bar {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px;
  min-width: 150px;
  flex: 1;
}
.stat-card .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.stat-card .value { font-size: 22px; font-weight: 700; margin-top: 4px; }

/* ── Filters ─────────────────────────────────────────────────── */
.filters {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}
.filters input, .filters select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 7px 12px;
  font-size: 13px;
  outline: none;
}
.filters input:focus, .filters select:focus { border-color: var(--accent); }
.filters input { width: 220px; }
.filters select { min-width: 140px; }

/* ── Table ───────────────────────────────────────────────────── */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}
.table-wrap table { min-width: 900px; }
table { width: 100%; border-collapse: collapse; }
th {
  padding: 11px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: rgba(0,0,0,.15);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th:hover { color: var(--text); }
th .sort-arrow { opacity: .4; margin-left: 4px; }
th.sorted .sort-arrow { opacity: 1; color: var(--accent); }
td {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(51,65,85,.5);
  white-space: nowrap;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,.03); cursor: pointer; }
.ticker-cell { font-weight: 700; color: var(--accent); }
.muted { color: var(--muted); }

/* ── Score badges ────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .3px;
}
.badge-strong-buy { background: #14532d; color: #86efac; }
.badge-buy        { background: #1e3a5f; color: #93c5fd; }
.badge-watchlist  { background: #451a03; color: #fde68a; }
.badge-hold       { background: #431407; color: #fdba74; }
.badge-caution    { background: #450a0a; color: #fca5a5; }
.badge-avoid      { background: #3b0a0a; color: #f87171; }

.pos { color: var(--green); }
.neg { color: var(--red); }

/* ── Pagination ──────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
}
.page-btn {
  padding: 5px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
}
.page-btn:disabled { opacity: .4; cursor: default; }
.page-btn.active { background: var(--accent); border-color: var(--accent); }

/* ── Stock detail ────────────────────────────────────────────── */
.breadcrumb { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.breadcrumb a { color: var(--muted); }

.stock-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  display: flex;
  gap: 32px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.stock-title .ticker { font-size: 32px; font-weight: 800; }
.stock-title .company-name { color: var(--muted); font-size: 15px; margin-top: 2px; }
.stock-title .tags { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.tag {
  background: rgba(59,130,246,.15);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
}
.stock-price { text-align: right; margin-left: auto; }
.stock-price .price-val { font-size: 28px; font-weight: 700; }
.stock-price .mkt-cap { color: var(--muted); font-size: 13px; margin-top: 4px; }

.score-big {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border-radius: var(--radius);
  padding: 16px 24px;
  min-width: 120px;
  border: 1px solid var(--border);
}
.score-big .score-num { font-size: 36px; font-weight: 800; }
.score-big .score-label { font-size: 12px; font-weight: 600; margin-top: 4px; letter-spacing: .5px; }

/* ── Grid layouts ────────────────────────────────────────────── */
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 20px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; margin-bottom: 20px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  margin-bottom: 14px;
}

/* ── Key metrics grid ────────────────────────────────────────── */
.metrics-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.metric {
  background: var(--bg);
  border-radius: 6px;
  padding: 10px 14px;
  border: 1px solid var(--border);
}
.metric .m-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.metric .m-value { font-size: 17px; font-weight: 700; margin-top: 3px; }

/* ── Valuation cards ─────────────────────────────────────────── */
.val-card { text-align: center; }
.val-card .model-name { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 8px; }
.val-card .fair-value { font-size: 24px; font-weight: 800; }
.val-card .upside { font-size: 16px; font-weight: 700; margin-top: 4px; }
.val-card .signal { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* ── Chart ───────────────────────────────────────────────────── */
.chart-container { position: relative; height: 260px; }

/* ── News ────────────────────────────────────────────────────── */
.news-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.news-item:last-child { border-bottom: none; }
.news-sentiment {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}
.news-content .news-title { font-size: 13px; line-height: 1.4; }
.news-content .news-meta { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ── Loading / empty ─────────────────────────────────────────── */
.loading { text-align: center; padding: 60px; color: var(--muted); }
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; padding: 48px; color: var(--muted); }

/* ── Score breakdown ─────────────────────────────────────────── */
.score-category { margin-bottom: 20px; }
.score-cat-header {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 8px;
}
.score-cat-name  { font-weight: 600; font-size: 13px; min-width: 160px; }
.score-cat-weight { color: var(--muted); font-size: 11px; min-width: 60px; }
.score-cat-bar   { flex: 1; height: 8px !important; }
.score-cat-pts   { font-weight: 700; font-size: 13px; min-width: 44px; text-align: right; }
.score-items     { margin-left: 8px; }
.score-item {
  display: flex; align-items: center; gap: 8px;
  margin: 4px 0; font-size: 12px;
}
.score-item-label { width: 160px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.score-bar-track  { flex: 1; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.score-bar-fill   { height: 100%; border-radius: 3px; transition: width .4s; }
.score-item-val   { width: 70px; text-align: right; color: var(--text); }
.score-item-pts   { width: 36px; text-align: right; color: var(--muted); font-size: 11px; }

/* ── Distribution page ───────────────────────────────────────── */
.dist-link { text-decoration: none; color: inherit; cursor: pointer; transition: background .15s; padding: 2px 4px; border-radius: 4px; }
.dist-link:hover { background: rgba(59,130,246,.08); text-decoration: none; }
.threshold-card.dist-link:hover { background: var(--bg); }
.dist-bar-row { display: flex; align-items: center; gap: 10px; margin: 6px 0; font-size: 13px; }
.dist-bar-label { width: 80px; color: var(--muted); text-align: right; font-size: 12px; }
.dist-bar-track { flex: 1; height: 18px; background: var(--border); border-radius: 4px; overflow: hidden; }
.dist-bar-fill  { height: 100%; border-radius: 4px; background: var(--accent); transition: width .4s; }
.dist-bar-count { width: 50px; color: var(--text); font-size: 12px; }
.threshold-cards { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.threshold-card  {
  flex: 1; min-width: 160px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 16px; text-align: center;
}
.threshold-card .t-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.threshold-card .t-count { font-size: 28px; font-weight: 700; color: var(--text); }
.threshold-card .t-pct   { font-size: 13px; color: var(--accent); }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 900px) {
  .grid-3 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .stock-header { flex-direction: column; }
  .stock-price { text-align: left; margin-left: 0; }
}
@media (max-width: 600px) {
  .container { padding: 16px; }
  .grid-2, .grid-4 { grid-template-columns: 1fr; }
  .stats-bar .stat-card { min-width: 130px; }
}

.nav-toggle { display: none; }   /* hamburger removed — links wrap instead */

/* ── Mobile (phones) ─────────────────────────────────────────── */
@media (max-width: 760px) {
  /* Single-line top bar; the links scroll horizontally (swipe) */
  nav { flex-wrap: nowrap; height: 56px; padding: 0 14px; gap: 12px; align-items: center; }
  .nav-links {
    flex: 1 1 auto;
    min-width: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    white-space: nowrap;
    gap: 18px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .nav-links::-webkit-scrollbar { display: none; }
  .nav-links a { flex: 0 0 auto; font-size: 13px; }
  .nav-right { flex: 0 0 auto; margin-left: 8px; }

  .container { padding: 14px; }
  h2 { font-size: 20px; }

  /* Denser cards + cells on small screens */
  .stat-card { min-width: 120px; padding: 12px 14px; }
  .stat-card .value { font-size: 18px; }
  .card { padding: 14px; }
  th, td { padding: 9px 10px; }

  /* Filters: each control grows to fill the row instead of overflowing */
  .filters { gap: 8px; }
  .filters input, .filters select { flex: 1 1 140px; min-width: 0; }
}
