:root {
  color-scheme: dark;
  --bg: #141816;
  --bg-elevated: #1b211e;
  --bg-panel: #1f2622;
  --bg-soft: #252d29;
  --line: #36413b;
  --line-strong: #4a5750;
  --text: #eef2ed;
  --text-soft: #aab5ae;
  --text-dim: #7f8b84;
  --green: #4ec89d;
  --green-soft: rgba(78, 200, 157, 0.12);
  --amber: #d0a74b;
  --amber-soft: rgba(208, 167, 75, 0.14);
  --red: #db6d58;
  --red-soft: rgba(219, 109, 88, 0.12);
  --teal: #63b6be;
  --teal-soft: rgba(99, 182, 190, 0.12);
  --shadow: 0 18px 48px rgba(6, 10, 8, 0.34);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top right, rgba(78, 200, 157, 0.08), transparent 32%),
    radial-gradient(circle at bottom left, rgba(208, 167, 75, 0.08), transparent 28%),
    var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans", "Aptos", "Segoe UI", sans-serif;
  overflow-x: hidden;
}

body {
  letter-spacing: 0;
}

button,
input,
textarea,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
}

.topbar,
.workspace-band {
  width: 100%;
  padding-left: 24px;
  padding-right: 24px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.9fr);
  gap: 24px;
  align-items: start;
  padding-top: 28px;
  padding-bottom: 20px;
  background: linear-gradient(180deg, rgba(20, 24, 22, 0.96) 0%, rgba(20, 24, 22, 0.82) 75%, rgba(20, 24, 22, 0) 100%);
  backdrop-filter: blur(16px);
}

.brand-block h1,
.panel-head h2 {
  margin: 0;
  line-height: 1.05;
}

.brand-block h1 {
  font-size: 36px;
  max-width: 12ch;
}

.eyebrow,
.panel-kicker {
  margin: 0 0 10px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.subcopy {
  margin: 14px 0 0;
  max-width: 56ch;
  color: var(--text-soft);
  line-height: 1.5;
}

.command-bar {
  display: grid;
  gap: 16px;
  justify-items: end;
}

.status-cluster {
  display: grid;
  gap: 10px;
  width: 100%;
}

.status-pill {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(31, 38, 34, 0.78);
}

.status-pill strong {
  min-width: 0;
  text-align: right;
  overflow-wrap: anywhere;
}

.status-pill strong,
.metric-value,
.detail-stat strong,
.summary-row strong,
.context-matrix strong {
  font-size: 15px;
}

.status-label,
.metric-label,
.detail-stat span,
.summary-row span,
.spark-head span,
.context-matrix span {
  color: var(--text-dim);
  font-size: 12px;
  text-transform: uppercase;
}

.status-pill.positive {
  border-color: rgba(78, 200, 157, 0.35);
}

.status-pill.neutral {
  border-color: rgba(99, 182, 190, 0.24);
}

.status-pill.accent {
  border-color: rgba(208, 167, 75, 0.28);
}

.analyze-button {
  min-width: 180px;
  height: 46px;
  border: 1px solid rgba(78, 200, 157, 0.48);
  border-radius: 6px;
  background: linear-gradient(180deg, rgba(78, 200, 157, 0.18), rgba(78, 200, 157, 0.08));
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.analyze-button:hover {
  transform: translateY(-1px);
  border-color: rgba(78, 200, 157, 0.68);
}

.analyze-button:disabled {
  cursor: not-allowed;
  opacity: 0.76;
  border-color: rgba(74, 87, 80, 0.72);
  background: linear-gradient(180deg, rgba(54, 65, 59, 0.45), rgba(54, 65, 59, 0.18));
}

.workspace {
  display: grid;
  gap: 24px;
  padding-bottom: 32px;
}

.metrics-grid,
.secondary-grid {
  display: grid;
  gap: 16px;
}

.metrics-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.metric-tile,
.panel {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(31, 38, 34, 0.96), rgba(27, 33, 30, 0.98));
  box-shadow: var(--shadow);
}

.metric-tile {
  padding: 18px;
  border-radius: var(--radius);
  min-height: 124px;
  display: grid;
  gap: 12px;
  align-content: start;
}

.metric-button {
  width: 100%;
  text-align: left;
  color: inherit;
  cursor: pointer;
}

.metric-anchor {
  text-decoration: none;
}

.metric-button:hover {
  border-color: rgba(99, 182, 190, 0.48);
}

.metric-button:focus-visible,
.info-marker:focus-visible {
  outline: 2px solid rgba(99, 182, 190, 0.68);
  outline-offset: 2px;
}

.metric-note,
.panel-caption {
  margin: 0;
  color: var(--text-soft);
  line-height: 1.45;
}

.label-with-info,
.table-heading-with-info {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.table-heading-with-info {
  justify-content: center;
}

.info-marker {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  padding: 0;
  border: 1px solid rgba(99, 182, 190, 0.4);
  border-radius: 50%;
  background: rgba(99, 182, 190, 0.08);
  color: var(--teal);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  cursor: help;
}

.info-marker::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 10px);
  transform: translateX(-50%);
  width: 220px;
  padding: 10px 12px;
  border: 1px solid rgba(74, 87, 80, 0.96);
  border-radius: 6px;
  background: rgba(19, 23, 21, 0.98);
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.45;
  white-space: normal;
  text-transform: none;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
  z-index: 20;
}

.info-marker:hover::after,
.info-marker:focus-visible::after {
  opacity: 1;
}

.ranking-table .info-marker::after {
  bottom: auto;
  top: calc(100% + 10px);
  z-index: 40;
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(320px, 0.9fr);
  gap: 20px;
  align-items: start;
}

.option-board-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  align-items: start;
}

.panel {
  border-radius: var(--radius);
  overflow: hidden;
}

.ranking-panel,
.ranking-panel .panel-head,
.ranking-table,
.ranking-table thead,
.ranking-table th {
  overflow: visible;
}

.ranking-panel,
.ranking-table th {
  position: relative;
}

.ranking-panel {
  z-index: 2;
}

.ranking-panel .table-wrap {
  position: relative;
  overflow-x: auto;
  overflow-y: visible;
  z-index: 3;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2 {
  font-size: 22px;
}

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

.ranking-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
  min-width: 760px;
}

.option-table {
  min-width: 820px;
}

.compact-ranking-panel .panel-caption {
  max-width: 48ch;
}

.ranking-table th,
.ranking-table td {
  padding: 14px 16px;
  border-bottom: 1px solid rgba(54, 65, 59, 0.78);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

.ranking-table th {
  color: var(--text-dim);
  font-size: 12px;
  text-transform: uppercase;
  background: rgba(21, 26, 23, 0.72);
}

.ranking-row {
  cursor: pointer;
  transition: background 140ms ease;
}

.ranking-row:hover,
.ranking-row.active {
  background: rgba(99, 182, 190, 0.08);
}

.skeleton-row {
  cursor: default;
}

.skeleton-row:hover {
  background: transparent;
}

.skeleton-line {
  display: block;
  width: min(100%, 120px);
  height: 14px;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.06) 0%,
    rgba(255, 255, 255, 0.16) 45%,
    rgba(255, 255, 255, 0.06) 90%
  );
  background-size: 240% 100%;
  animation: shimmer 1.15s ease-in-out infinite;
}

.skeleton-row td:nth-child(2) .skeleton-line,
.skeleton-row td:nth-child(7) .skeleton-line {
  width: 160px;
}

.is-api-loading .metric-value,
.detail-panel.is-loading .summary-row strong,
.detail-panel.is-loading .detail-stat strong {
  color: transparent;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.06) 0%,
    rgba(255, 255, 255, 0.14) 45%,
    rgba(255, 255, 255, 0.06) 90%
  );
  background-size: 240% 100%;
  animation: shimmer 1.15s ease-in-out infinite;
}

@keyframes shimmer {
  0% {
    background-position: 120% 0;
  }
  100% {
    background-position: -120% 0;
  }
}

.empty-row {
  cursor: default;
}

.empty-row:hover {
  background: transparent;
}

.ranking-table .empty-row td {
  padding: 22px 20px;
  white-space: normal;
}

.table-empty-state {
  display: grid;
  gap: 8px;
  max-width: 760px;
}

.table-empty-title {
  font-size: 16px;
  line-height: 1.25;
}

.table-empty-message {
  color: var(--text-soft);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.progress-state {
  padding: 4px 0;
}

.progress-state .table-empty-title {
  color: var(--green);
}

.rank-badge {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  color: var(--text);
  background: rgba(20, 24, 22, 0.7);
  font-weight: 700;
}

.stock-cell {
  display: grid;
  gap: 4px;
}

.ranking-table td:nth-child(2) .stock-name,
.ranking-table td:last-child .bias-note {
  white-space: normal;
}

.stock-symbol {
  font-size: 15px;
  font-weight: 700;
}

.stock-name,
.bias-note {
  color: var(--text-soft);
  font-size: 13px;
}

.confidence-cell {
  display: grid;
  gap: 6px;
  width: 92px;
  margin: 0 auto;
}

.confidence-bar {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.confidence-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--amber), var(--green));
}

.value-up {
  color: var(--green);
}

.value-down {
  color: var(--red);
}

.detail-panel {
  display: grid;
  align-content: start;
  min-width: 0;
}

.detail-panel.is-empty .detail-hero,
.detail-panel.is-empty .spark-panel,
.detail-panel.is-empty .detail-grid {
  display: none;
}

.detail-panel.is-empty .reason-block {
  padding-top: 20px;
}

.detail-panel.is-empty .reason-block h3 {
  margin-bottom: 10px;
}

.detail-panel.is-empty .reason-list {
  padding: 14px 16px;
  border: 1px solid rgba(219, 109, 88, 0.28);
  border-radius: 6px;
  background: rgba(219, 109, 88, 0.08);
  list-style: none;
  overflow-wrap: anywhere;
}

.detail-tag {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--teal-soft);
  color: var(--teal);
  font-size: 12px;
  font-weight: 700;
}

.detail-hero {
  display: grid;
  grid-template-columns: minmax(140px, 168px) minmax(0, 1fr);
  gap: 18px;
  padding: 22px 20px;
  align-items: center;
}

.confidence-ring {
  position: relative;
  width: 148px;
  aspect-ratio: 1;
  margin: 0 auto;
}

.ring-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-track,
.ring-progress {
  fill: none;
  stroke-width: 12;
}

.ring-track {
  stroke: rgba(255, 255, 255, 0.08);
}

.ring-progress {
  stroke: var(--green);
  stroke-linecap: round;
  stroke-dasharray: 289;
  stroke-dashoffset: 86;
  transition: stroke-dashoffset 240ms ease;
}

.ring-value {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  transform: translateY(-2px);
}

.ring-value strong {
  font-size: 32px;
  line-height: 1;
}

.ring-value span {
  color: var(--text-soft);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  line-height: 1.1;
  white-space: nowrap;
}

.detail-summary {
  display: grid;
  gap: 10px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(54, 65, 59, 0.72);
  align-items: baseline;
}

.spark-panel,
.reason-block,
.detail-grid {
  padding-left: 20px;
  padding-right: 20px;
}

.spark-panel {
  padding-bottom: 16px;
}

.spark-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.sparkline {
  width: 100%;
  height: 120px;
  border-radius: 6px;
  background:
    linear-gradient(180deg, rgba(99, 182, 190, 0.08), rgba(99, 182, 190, 0)),
    rgba(15, 18, 16, 0.5);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding-bottom: 18px;
}

.detail-stat {
  padding: 14px;
  border: 1px solid rgba(54, 65, 59, 0.8);
  border-radius: 6px;
  background: rgba(20, 24, 22, 0.68);
  min-height: 80px;
  display: grid;
  align-content: start;
  gap: 10px;
}

.reason-block {
  padding-bottom: 22px;
}

.reason-block h3 {
  margin: 0 0 12px;
  font-size: 16px;
}

.reason-list {
  margin: 0;
  padding-left: 18px;
  color: var(--text-soft);
  line-height: 1.55;
}

.reason-source {
  color: var(--teal);
  font-weight: 700;
  text-decoration: none;
}

.reason-source:hover {
  text-decoration: underline;
}

.universe-panel {
  display: grid;
  gap: 0;
  scroll-margin-top: 120px;
}

.universe-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 18px 20px 8px;
}

.universe-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 12px 20px 22px;
}

.universe-chip {
  min-height: 78px;
  padding: 14px;
  border: 1px solid rgba(54, 65, 59, 0.82);
  border-radius: 6px;
  background: rgba(20, 24, 22, 0.65);
  display: grid;
  gap: 8px;
  align-content: start;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease;
}

.universe-chip:hover {
  border-color: rgba(99, 182, 190, 0.48);
  background: rgba(99, 182, 190, 0.08);
}

.universe-empty-state {
  grid-column: 1 / -1;
  min-height: 96px;
  padding: 18px 20px;
  border: 1px solid rgba(54, 65, 59, 0.82);
  border-radius: 6px;
  background: rgba(20, 24, 22, 0.65);
  display: grid;
  gap: 8px;
  align-content: center;
}

.universe-empty-state span {
  color: var(--text-soft);
  line-height: 1.45;
}

.universe-chip.is-ranked {
  border-color: rgba(78, 200, 157, 0.48);
  background: rgba(78, 200, 157, 0.1);
}

.universe-symbol-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.universe-symbol {
  font-size: 14px;
  font-weight: 700;
}

.universe-sector,
.universe-state {
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.45;
}

.universe-rank-pill {
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(78, 200, 157, 0.16);
  color: var(--green);
  font-size: 11px;
  font-weight: 700;
}

.confidence-column {
  text-align: center;
}

.confidence-column strong {
  display: block;
  text-align: center;
}

@media (max-width: 1280px) {
  .topbar,
  .main-grid,
  .option-board-grid {
    grid-template-columns: 1fr;
  }

  .command-bar {
    justify-items: stretch;
  }
}

@media (max-width: 1120px) {
  .topbar,
  .metrics-grid {
    grid-template-columns: 1fr;
  }

  .universe-summary,
  .universe-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .detail-hero {
    grid-template-columns: 1fr;
  }

  .confidence-ring {
    width: 160px;
  }
}

@media (max-width: 760px) {
  .topbar,
  .workspace-band {
    padding-left: 16px;
    padding-right: 16px;
  }

  .brand-block h1 {
    font-size: 28px;
  }

  .panel-head {
    flex-direction: column;
  }

  .detail-grid,
  .universe-summary,
  .universe-list {
    grid-template-columns: 1fr;
  }
}
