/* Self-contained design system (no framework). Fintech dark theme.
   All brand/layout lives here; templates stay markup-only (req 5). */

/* ---------- tokens ---------- */
:root {
  --bg: #0f1420;
  --surface: #161c2c;
  --surface-2: #1b2336;
  --border: #232c40;
  --text: #e6ebf5;
  --muted: #94a2bd;
  --brand: #2d7ff9;
  --brand-2: #7b5cff;
  --green: #4ade80;
  --amber: #fbbf24;
  --red: #f87171;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 8px 30px -16px rgba(0, 0, 0, 0.8);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, monospace;
}

/* ---------- reset ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}
* {
  margin: 0;
}
html {
  -webkit-text-size-adjust: 100%;
  overflow-y: scroll;
}
body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(123, 92, 255, 0.18), transparent 60%),
    radial-gradient(1000px 500px at -10% 0%, rgba(45, 127, 249, 0.18), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
}
a {
  color: var(--brand);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
img {
  max-width: 100%;
  height: auto;
  display: block;
}
button,
input,
select {
  font: inherit;
  color: inherit;
}

/* ---------- layout ---------- */
.container {
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2rem;
}

/* ---------- footer ---------- */
.site-footer {
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2.5rem;
  border-top: 1px solid var(--border);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.footer-disclaimer {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.5;
  max-width: 600px;
  margin: 0 auto;
}
.footer-links {
  font-size: 0.82rem;
}
.footer-copy {
  color: var(--muted);
  font-size: 0.72rem;
  opacity: 0.6;
}

/* ---------- hero ---------- */
.hero {
  display: flex;
  align-items: flex-start;
  gap: 1.25rem;
  margin: 0.5rem 0 1.5rem;
  padding: 2rem 1.75rem;
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(45, 127, 249, 0.22), rgba(123, 92, 255, 0.12));
  border: 1px solid rgba(123, 92, 255, 0.25);
  box-shadow: 0 10px 40px -12px rgba(45, 127, 249, 0.35);
}
.hero-logo {
  flex-shrink: 0;
  width: 72px;
  height: 72px;
  border-radius: 18px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}
.hero-text {
  flex: 1;
  min-width: 0;
}
.hero h1 {
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin-bottom: 0.35rem;
  padding-bottom: 0.1em;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero p {
  color: var(--muted);
}

/* ---------- search toolbar ---------- */
.toolbar {
  margin-bottom: 1rem;
}
.toolbar input[type="search"] {
  width: 100%;
  padding: 0.7rem 1rem;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  outline: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.toolbar input[type="search"]::placeholder {
  color: var(--muted);
}
.toolbar input[type="search"]:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(45, 127, 249, 0.2);
}
/* chips row (Sort + Sector buttons): mobile only - desktop uses table headers */
.chips-row {
  display: none;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.6rem;
}
.sort-pop {
  position: relative;
}
.sort-pop > summary {
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.sort-pop > summary::-webkit-details-marker {
  display: none;
}
/* direction arrow on the Sort button (border triangle, no glyphs) */
.sort-pop > summary::after {
  content: "";
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
}
.sort-pop > summary[data-dir="asc"]::after {
  border-bottom: 5px solid currentColor;
}
.sort-pop > summary[data-dir="desc"]::after {
  border-top: 5px solid currentColor;
}

/* backdrop behind mobile bottom-sheets (shown via JS removing [hidden]) */
.sheet-backdrop {
  display: none;
}
@keyframes sheet-up {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.chip.active {
  color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  border-color: transparent;
}
/* direction arrow on the active chip (border triangle, no glyphs) */
.chip[aria-sort="ascending"]::after,
.chip[aria-sort="descending"]::after {
  content: "";
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
}
.chip[aria-sort="ascending"]::after {
  border-bottom: 5px solid currentColor;
}
.chip[aria-sort="descending"]::after {
  border-top: 5px solid currentColor;
}

/* ---------- table ---------- */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
th,
td {
  text-align: left;
  padding: 0.7rem 1rem;
}
tbody tr + tr {
  border-top: 1px solid var(--border);
}

/* column titles: clickable to sort */
.cols th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-2);
  text-transform: uppercase;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.cols th:hover {
  color: var(--text);
}
.th-label {
  vertical-align: middle;
}
/* sort arrow drawn with borders (no glyphs), only on the active column */
.cols th .th-label::after {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 0.4rem;
  vertical-align: middle;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  opacity: 0;
}
.cols th[aria-sort="ascending"] .th-label::after {
  border-bottom: 5px solid currentColor;
  opacity: 0.9;
}
.cols th[aria-sort="descending"] .th-label::after {
  border-top: 5px solid currentColor;
  opacity: 0.9;
}

/* data rows */
.stock-row {
  cursor: pointer;
  transition: background 0.12s ease;
}
.stock-row:hover {
  background: rgba(45, 127, 249, 0.08);
}
.c-rank {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--muted);
  text-align: right;
  min-width: 2rem;
}
.th-rank {
  text-align: right;
}
.c-name {
  font-weight: 600;
}
.c-ticker {
  font-family: var(--mono);
  color: var(--muted);
}
.stock-summary {
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.6;
}

/* non-sortable column header */
.cols th.th-static {
  cursor: default;
}
.cols th.th-static:hover {
  color: var(--muted);
}

/* ---------- per-column bar charts (one series each) ---------- */
.chart {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 34px;
  min-width: 70px;
}
.bar {
  flex: 1;
  min-height: 1px;
  border-radius: 1px 1px 0 0;
}
.bar-0 {
  background: var(--brand);
}
.bar-1 {
  background: var(--brand-2);
}
.bar-2 {
  background: var(--green);
}
.bar-missing {
  opacity: 0.2;
}
.bar-negative {
  background: var(--red);
}

/* ---------- stock-page histograms ---------- */
.charts {
  margin-top: 1.75rem;
}
.charts h2 {
  font-size: 1rem;
  font-weight: 700;
  margin: 1.5rem 0 0.6rem;
}

/* chart color tokens (overridden per metric via JS) */
:root {
  --ch-rev:    #2d7ff9;
  --ch-earn:   #7b5cff;
  --ch-div:    #4ade80;
  --ch-payout: #22d3ee;
  --ch-trend:  #fbbf24;
  --ch-neg:    #f87171;
  --ch-grid:   rgba(148, 162, 189, 0.14);
}

/* outer container */
.chart-lg {
  position: relative;
  height: 320px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

/* inner chart wrapper */
.ch {
  position: relative;
  height: 100%;
}

/* bars flex row (above the value gridlines, below the trend/line overlay) */
.ch-bars {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: stretch;
  gap: 2px;
  height: 100%;
  padding: 0 8px;
}

/* x-axis baseline: full-width line at the plot floor, just above the year labels (14px row) */
.ch-bars::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 14px;
  height: 1px;
  background: #52627c;
  opacity: 0.6;
  pointer-events: none;
}

/* one column per year: 18px yoy / 1fr plot / 14px year */
.ch-slot {
  display: grid;
  grid-template-rows: 18px 1fr 14px;
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
  cursor: default;
}

.ch-yoy {
  align-self: center;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  white-space: nowrap;
}
.ch-yp { color: #4ade80; }
.ch-yn { color: #f87171; }

/* plot area: simple positioned container; JS sets top/height on all children in px */
.ch-plot {
  position: relative;
  min-height: 0;
}

/* year-boundary divider: sits in the 2px gap left of each slot (all but the first) */
.ch-slot:not(:first-child) .ch-plot::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -1px;
  width: 1px;
  background: var(--ch-grid);
  pointer-events: none;
}

/* zero line: top = --zy (px from top of plot, set by JS) */
.ch-zl {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--zy, 100%);
  height: 1px;
  background: #52627c;
  opacity: 0.6;
}

/* annual bar: top/height/border-radius set inline by JS in px */
.ch-ab {
  position: absolute;
  left: 0;
  right: 0;
  background: linear-gradient(180deg, var(--ch-slot-color, var(--ch-rev)), color-mix(in srgb, var(--ch-slot-color, var(--ch-rev)) 70%, #000));
  box-shadow: 0 0 10px color-mix(in srgb, var(--ch-slot-color, var(--ch-rev)) 30%, transparent);
  transition: filter 100ms ease;
}

/* negative bar: red gradient, grows downward from zero line */
.ch-ab.ch-neg {
  background: linear-gradient(180deg, var(--ch-neg), #b83b55);
  box-shadow: 0 0 10px color-mix(in srgb, var(--ch-neg) 30%, transparent);
}

/* annual-quarter-bar: transparent frame around quarterly sub-bars */
.ch-aqb {
  border: 1px solid color-mix(in srgb, var(--ch-slot-color, var(--ch-rev)) 60%, #fff);
  background: color-mix(in srgb, var(--ch-slot-color, var(--ch-rev)) 18%, transparent);
  box-shadow: none;
}

/* negative frame uses ch-neg color */
.ch-aqb.ch-neg {
  border-color: color-mix(in srgb, var(--ch-neg) 60%, #fff);
  background: color-mix(in srgb, var(--ch-neg) 18%, transparent);
}

/* quarter grid: positioned absolutely with top+height set inline by JS */
.ch-qg {
  position: absolute;
  left: 1px;
  right: 1px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  z-index: 1;
}

/* positive quarter grid: segments grow from the bottom upward */
.ch-qg-pos {
  align-items: end;
}

/* negative quarter grid: segments grow from the top downward */
.ch-qg-neg {
  align-items: start;
}

/* quarter segment: height set inline by JS in px */
.ch-qs {
  display: block;
  min-height: 2px;
}

.ch-qg-pos .ch-qs { align-self: end; }
.ch-qg-neg .ch-qs { align-self: start; }

.ch-qs:nth-child(1) { background: color-mix(in srgb, var(--ch-slot-color, var(--ch-rev)) 90%, #fff); }
.ch-qs:nth-child(2) { background: color-mix(in srgb, var(--ch-slot-color, var(--ch-rev)) 75%, #fff); }
.ch-qs:nth-child(3) { background: color-mix(in srgb, var(--ch-slot-color, var(--ch-rev)) 85%, #000); }
.ch-qs:nth-child(4) { background: color-mix(in srgb, var(--ch-slot-color, var(--ch-rev)) 60%, #fff); }

.ch-qs.ch-qneg {
  background: repeating-linear-gradient(135deg, #f87171 0 3px, #b83b55 3px 6px);
}

.ch-qph { visibility: hidden; }

/* missing-data marker: top set inline by JS to land at zero line */
.ch-mm {
  position: absolute;
  left: 20%;
  right: 20%;
  height: 2px;
  background: #46536a;
}

/* year label */
.ch-yr {
  align-self: end;
  color: var(--muted);
  font-size: 12px;
  line-height: 16px;
  text-align: center;
}

/* slot hover */
.ch-slot:hover .ch-ab { filter: brightness(1.3); }

/* plot-area SVG overlays (18px from top, 14px from bottom): value gridlines behind the
   bars, trend/line on top */
.ch-trend,
.ch-grid {
  position: absolute;
  inset: 18px 0 14px;
  width: 100%;
  height: calc(100% - 32px);
  overflow: visible;
  pointer-events: none;
}
.ch-grid { z-index: 0; }
.ch-trend { z-index: 2; }

.ch-tl {
  fill: none;
  stroke: var(--ch-trend);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 0 3px color-mix(in srgb, var(--ch-trend) 50%, transparent));
}

/* CAGR badge */
.ch-badge {
  position: absolute;
  z-index: 3;
  transform: translate(-50%, -50%);
  color: var(--ch-trend);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  line-height: 1;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 4px;
  padding: 2px 5px;
  pointer-events: none;
}

/* ---------- payout ratio line chart ---------- */

/* connected line (one polyline per non-null run); shares the .ch-trend overlay box */
.ch-line {
  fill: none;
  stroke: var(--ch-slot-color, var(--ch-div));
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 0 3px color-mix(in srgb, var(--ch-slot-color, var(--ch-div)) 40%, transparent));
}

/* horizontal value gridlines */
.ch-grid-h {
  stroke: var(--ch-grid);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

/* dashed 100% reference line */
.ch-ref {
  stroke: var(--ch-neg);
  stroke-width: 1;
  stroke-dasharray: 4 4;
  vector-effect: non-scaling-stroke;
}

/* dot layer: same inset as .ch-trend so dots line up with the polyline */
.ch-dots {
  position: absolute;
  z-index: 3;
  inset: 18px 0 14px;
  pointer-events: none;
}

/* data point: HTML span (not SVG) to stay round under the stretched viewBox */
.ch-dot {
  position: absolute;
  width: 8px;
  height: 8px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--ch-slot-color, var(--ch-div));
  box-shadow: 0 0 6px color-mix(in srgb, var(--ch-slot-color, var(--ch-div)) 50%, transparent);
  pointer-events: auto;
}

/* right-edge value labels, hanging just below their gridline */
.ch-axis-label {
  position: absolute;
  right: 6px;
  transform: translateY(2px);
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.ch-axis-label.ch-axis-100 {
  color: var(--ch-neg);
}

/* empty-state text when no year has a payout ratio */
.ch-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ---------- score badges ---------- */
.badge {
  display: inline-block;
  min-width: 2.5rem;
  text-align: center;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.badge-high {
  background: rgba(34, 197, 94, 0.18);
  color: var(--green);
  border: 1px solid rgba(34, 197, 94, 0.35);
}
.badge-mid {
  background: rgba(245, 158, 11, 0.16);
  color: var(--amber);
  border: 1px solid rgba(245, 158, 11, 0.35);
}
.badge-low {
  background: rgba(239, 68, 68, 0.16);
  color: var(--red);
  border: 1px solid rgba(239, 68, 68, 0.35);
}

/* ---------- sector filter: popup shared by a header funnel + a mobile chip ---------- */
.sector-filter {
  position: relative;
}
.sector-filter > summary {
  list-style: none;
  cursor: pointer;
}
.sector-filter > summary::-webkit-details-marker {
  display: none;
}

/* header trigger: compact funnel icon */
.sector-filter.icon {
  display: inline-block;
  vertical-align: middle;
  margin-right: 0.4rem;
}
.sector-filter.icon > summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 8px;
  color: var(--muted);
  border: 1px solid transparent;
}
.sector-filter.icon > summary:hover {
  color: var(--text);
  background: rgba(45, 127, 249, 0.12);
}
.sector-filter.icon.active > summary {
  color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
}

/* mobile trigger: a chip (summary uses the .chip styling) */
.chip-sector.active > summary {
  color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  border-color: transparent;
}
.sector-menu,
.pop-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 20;
  min-width: 12rem;
  max-height: 16rem;
  overflow-y: auto;
  padding: 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 16px 40px -12px rgba(0, 0, 0, 0.85);
}
.sector-option,
.pop-option {
  width: 100%;
  text-align: left;
  white-space: nowrap;
  padding: 0.4rem 0.6rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 0.85rem;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 500;
  cursor: pointer;
}
.sector-option:hover,
.pop-option:hover {
  background: rgba(45, 127, 249, 0.12);
}
.sector-option[aria-selected="true"],
.pop-option[aria-selected="true"] {
  background: rgba(45, 127, 249, 0.2);
  font-weight: 700;
  color: #fff;
}

/* ---------- load more ---------- */
.load-more {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding-bottom: 0.5rem;
}
.lm-status {
  color: var(--muted);
  font-size: 0.85rem;
}
.lm-btn {
  padding: 0.65rem 2rem;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  border: none;
  color: #fff;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.lm-btn:hover {
  opacity: 0.88;
  transform: translateY(-1px);
}

/* ---------- stock page ---------- */
/* ---------- stock KPI grid ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  margin: 1.25rem 0;
  max-width: 480px;
}
.kpi-wide {
  grid-column: 1 / -1;
}
.kpi {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.7rem;
}
.kpi-label {
  display: block;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.kpi-value {
  display: block;
  margin-top: 0.2rem;
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.kpi-value.pos { color: var(--green); }
.kpi-value.neg { color: var(--red); }
.kpi-value.kpi-text {
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.35;
}
.kpi-sub {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.85rem;
}
@media (max-width: 520px) {
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
.market-snapshot {
  margin-top: 1.5rem;
}
.market-snapshot h2 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.6rem;
}
.market-snapshot iframe {
  display: block;
  width: 100%;
  height: 215px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
/* TradingView stacks the stats below the price once the iframe drops under ~700px wide. */
@media (max-width: 820px) {
  .market-snapshot iframe {
    height: 300px;
  }
}
/* ---------- sector page stats ---------- */
.sector-stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.75rem;
  margin: 1.25rem 0;
  padding: 0;
}
.sector-stats > div {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 0.75rem 1.25rem;
}
.sector-stats dt {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}
.sector-stats dd {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0;
}

/* ---------- sector page table ---------- */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.sector-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.875rem;
  margin: 1.5rem 0;
}
.sector-table th,
.sector-table td {
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}
.sector-table .td-name {
  white-space: normal;
  word-break: break-word;
}
.sector-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  /* headers wrap so the 7-column table fits narrow tablets without scrolling */
  white-space: normal;
}
.sector-table tbody tr:hover {
  background: rgba(45, 127, 249, 0.06);
}
.sector-table .td-rank {
  color: var(--muted);
  width: 1%;
}
.sector-table .td-ticker {
  font-family: var(--mono);
  color: var(--muted);
}

/* ---------- homepage browse by sector ---------- */
.browse-sectors {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.browse-sectors h2 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}
.sectors-grid {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}
.sectors-grid a {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.75rem 1rem;
  background: var(--surface-2);
  border-radius: 8px;
  text-decoration: none;
  transition: background 0.15s;
  height: 100%;
  box-sizing: border-box;
}
.sectors-grid a:hover {
  background: rgba(45, 127, 249, 0.12);
}
.sec-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--fg);
}
.sec-count {
  font-size: 0.78rem;
  color: var(--muted);
}
.sec-top {
  margin-top: auto;
  padding-top: 0.4rem;
  align-self: flex-start;
}

.related-stocks {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.related-stocks h2 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}
.peers-grid {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-auto-rows: 1fr;
  gap: 0.75rem;
}
.peers-grid a {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.75rem 1rem;
  background: var(--surface-2);
  border-radius: 8px;
  text-decoration: none;
  transition: background 0.15s;
  height: 100%;
  box-sizing: border-box;
}
.peers-grid li {
  display: contents;
}
.peers-grid a .peer-score {
  margin-top: auto;
  padding-top: 0.5rem;
}
.peers-grid a:hover {
  background: rgba(45, 127, 249, 0.12);
}
.peer-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--fg);
  line-height: 1.3;
}
.peer-ticker {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
}
.peer-score {
  margin-top: 0.3rem;
  align-self: flex-start;
}
.updated-at {
  font-size: 0.85em;
}
.methodology-link {
  font-size: 0.85rem;
  color: var(--muted);
}

/* ---------- stock page ---------- */
article {
  margin-top: 1rem;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
article > nav {
  margin-bottom: 1rem;
}
article header {
  margin-bottom: 1.25rem;
}
article h1 {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}
article h1 small {
  font-family: var(--mono);
  font-size: 0.55em;
  font-weight: 600;
  color: var(--muted);
}
article header p {
  color: var(--muted);
}
article img {
  border-radius: var(--radius-sm);
  margin: 0 0 1.25rem;
}

article nav a {
  color: var(--muted);
}

/* ---------- methodology page ---------- */
.methodology section {
  margin-top: 2rem;
}
.methodology h2 {
  font-size: 1.2rem;
  font-weight: 800;
  margin-bottom: 0.6rem;
}
.methodology h3 {
  font-size: 1rem;
  font-weight: 700;
  margin: 1.25rem 0 0.5rem;
}
.methodology p,
.methodology ul {
  color: var(--muted);
  line-height: 1.7;
  margin-bottom: 0.75rem;
}
.methodology ul {
  padding-left: 1.25rem;
}
.methodology code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.35em;
}
.meth-table {
  margin: 0.75rem 0 1rem;
  font-size: 0.9rem;
}
.meth-table th {
  color: var(--text);
}
.meth-table td {
  color: var(--muted);
}

/* ---------- mobile: cards + reachable sector filter ---------- */
@media (max-width: 640px) {
  .peers-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .sector-stats {
    grid-template-columns: repeat(2, 1fr);
  }
  .sector-table .th-hide-mob,
  .sector-table .td-hide-mob {
    display: none;
  }
  .sector-table thead {
    display: none;
  }
  .sector-table tbody tr {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
  }
  .sector-table tbody td {
    padding: 0;
    border-bottom: none;
  }
  .sector-table .td-rank {
    flex-shrink: 0;
    width: 2rem;
    text-align: right;
    font-size: 0.8rem;
  }
  .sector-table .td-name {
    flex: 1;
    min-width: 0;
    font-size: 0.9rem;
  }
  .sector-table td:nth-child(4) {
    flex-shrink: 0;
  }
  .container {
    width: auto;
    max-width: none;
    padding-right: 1rem;
    padding-left: 1rem;
  }
  .hero {
    padding: 1.5rem;
    gap: 1rem;
  }
  .hero-logo {
    width: 52px;
    height: 52px;
    border-radius: 13px;
  }
  .chips-row {
    display: flex;
  }

  /* popups become bottom-sheets: full-width, slide up, large tap targets */
  .sheet-backdrop:not([hidden]) {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 30;
    background: rgba(0, 0, 0, 0.55);
  }
  body.sheet-open {
    overflow: hidden;
  }
  .js-popup[open] > .pop-menu,
  .js-popup[open] > .sector-menu {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    z-index: 40;
    min-width: 0;
    max-height: 75vh;
    border-radius: 18px 18px 0 0;
    padding: 0.4rem 0.75rem calc(1.25rem + env(safe-area-inset-bottom));
    box-shadow: 0 -12px 40px -10px rgba(0, 0, 0, 0.8);
    animation: sheet-up 0.22s ease;
  }
  /* grab handle + title */
  .js-popup[open] > .pop-menu::before,
  .js-popup[open] > .sector-menu::before {
    display: block;
    text-align: center;
    font-weight: 700;
    color: var(--muted);
    padding: 1rem 0 0.75rem;
    margin-bottom: 0.4rem;
    border-bottom: 1px solid var(--border);
    border-top: 4px solid var(--border); /* doubles as a grab-handle cue */
    border-radius: 3px 3px 0 0;
  }
  .sort-pop[open] > .pop-menu::before {
    content: "Sort by";
  }
  .chip-sector[open] > .sector-menu::before {
    content: "Filter by sector";
  }
  .js-popup[open] .pop-option,
  .js-popup[open] .sector-option {
    padding: 0.95rem 1rem;
    font-size: 1rem;
    border-radius: 12px;
  }
  table {
    display: block;
    background: transparent;
    border: 0;
    box-shadow: none;
    overflow: visible;
  }
  thead {
    display: block;
  }
  /* column titles hidden on mobile; sorting + sector filter live in the chips row */
  .cols {
    display: none;
  }
  tbody {
    display: block;
  }
  tbody tr + tr {
    border-top: 0;
  }

  /* card shell */
  .stock-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto auto auto auto;
    gap: 0.1rem 0.4rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 0.75rem;
    padding: 0.55rem 0.75rem;
    width: auto;
  }

  /* all cells: reset the default block/grid from tbody td rule */
  .stock-row td {
    display: block;
    width: auto;
    padding: 0;
    min-width: 0;
  }
  .stock-row td::before { display: none; }

  /* Rank: hidden on mobile */
  .stock-row .c-rank { display: none; }

  /* Name: spans col 1+2, row 1 */
  .stock-row td:nth-child(2) {
    grid-column: 1 / 3;
    grid-row: 1;
    align-self: center;
    overflow-wrap: anywhere;
  }

  /* Ticker: col 1, row 2 */
  .stock-row td:nth-child(3) {
    grid-column: 1;
    grid-row: 2;
    font-size: 0.8rem;
    color: var(--muted);
    font-family: var(--mono);
  }

  /* Sector: col 2, row 2 — prefixed with separator */
  .stock-row td:nth-child(4) {
    grid-column: 2;
    grid-row: 2;
    font-size: 0.8rem;
    color: var(--muted);
    align-self: center;
  }
  .stock-row td:nth-child(4)::before {
    content: "· ";
    display: inline;
  }

  /* Score badge: col 3, rows 1+2 — centered on the right */
  .stock-row td:nth-child(5) {
    grid-column: 3;
    grid-row: 1 / 3;
    align-self: center;
    justify-self: end;
  }

  /* Charts: full width with label | bar layout */
  .stock-row td:nth-child(6) { grid-column: 1 / -1; grid-row: 3; }
  .stock-row td:nth-child(7) { grid-column: 1 / -1; grid-row: 4; }
  .stock-row td:nth-child(8) { grid-column: 1 / -1; grid-row: 5; }
  .stock-row td:nth-child(6),
  .stock-row td:nth-child(7),
  .stock-row td:nth-child(8) {
    display: grid;
    grid-template-columns: minmax(5rem, 2fr) minmax(0, 3fr);
    gap: 0.5rem;
    align-items: center;
    padding: 0.15rem 0;
  }
  .stock-row td:nth-child(6)::before,
  .stock-row td:nth-child(7)::before,
  .stock-row td:nth-child(8)::before {
    display: block;
    content: attr(data-label);
    font-weight: 700;
    color: var(--muted);
    font-size: 0.8rem;
  }

  .chart {
    width: 100%;
    min-width: 0;
    height: 51px;
  }
  .chart-lg {
    height: 264px;
  }
  .market-snapshot iframe {
    height: 330px;
  }
  .badge {
    max-width: 100%;
  }
}

/* ---------- tablet: catalog as a two-column card grid ---------- */
/* Mirrors the phone card layout (max-width: 640 block) but lays the cards out
   two-up. Scoped to #catalog so other tables (sector, methodology) are untouched
   at this width. Sorting/filtering uses the chip popups (default dropdowns here). */
@media (min-width: 641px) and (max-width: 1023px) {
  /* catalog table -> card grid */
  #catalog {
    display: block;
    background: transparent;
    border: 0;
    box-shadow: none;
    overflow: visible;
  }
  #catalog thead {
    display: block;
  }
  #catalog .cols {
    display: none;
  }
  #catalog tbody {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    align-items: start;
  }
  #catalog tbody tr + tr {
    border-top: 0;
  }

  /* sort + sector chips replace the clickable column headers */
  .chips-row {
    display: flex;
  }

  /* card shell (same structure as the phone layout) */
  .stock-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto auto auto auto;
    gap: 0.1rem 0.4rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.55rem 0.75rem;
    width: auto;
  }
  .stock-row td {
    display: block;
    width: auto;
    padding: 0;
    min-width: 0;
  }
  .stock-row td::before { display: none; }
  .stock-row .c-rank { display: none; }
  .stock-row td:nth-child(2) {
    grid-column: 1 / 3;
    grid-row: 1;
    align-self: center;
    overflow-wrap: anywhere;
  }
  .stock-row td:nth-child(3) {
    grid-column: 1;
    grid-row: 2;
    font-size: 0.8rem;
    color: var(--muted);
    font-family: var(--mono);
  }
  .stock-row td:nth-child(4) {
    grid-column: 2;
    grid-row: 2;
    font-size: 0.8rem;
    color: var(--muted);
    align-self: center;
  }
  .stock-row td:nth-child(4)::before {
    content: "\00B7\00A0";
    display: inline;
  }
  .stock-row td:nth-child(5) {
    grid-column: 3;
    grid-row: 1 / 3;
    align-self: center;
    justify-self: end;
  }
  .stock-row td:nth-child(6) { grid-column: 1 / -1; grid-row: 3; }
  .stock-row td:nth-child(7) { grid-column: 1 / -1; grid-row: 4; }
  .stock-row td:nth-child(8) { grid-column: 1 / -1; grid-row: 5; }
  .stock-row td:nth-child(6),
  .stock-row td:nth-child(7),
  .stock-row td:nth-child(8) {
    display: grid;
    grid-template-columns: minmax(5rem, 2fr) minmax(0, 3fr);
    gap: 0.5rem;
    align-items: center;
    padding: 0.15rem 0;
  }
  .stock-row td:nth-child(6)::before,
  .stock-row td:nth-child(7)::before,
  .stock-row td:nth-child(8)::before {
    display: block;
    content: attr(data-label);
    font-weight: 700;
    color: var(--muted);
    font-size: 0.8rem;
  }
  .chart {
    width: 100%;
    min-width: 0;
    height: 51px;
  }
}
