:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-strong: #111827;
  --text: #111827;
  --muted: #5f6b7a;
  --border: #d7dde5;
  --blue: #2563eb;
  --green: #0f8b5f;
  --amber: #b7791f;
  --red: #c2413b;
  --teal: #0f766e;
  --shadow: 0 14px 34px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

button,
select {
  font: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px clamp(18px, 4vw, 48px);
  background: var(--surface-strong);
  color: #fff;
  border-bottom: 4px solid var(--green);
}

.topbar h1,
.section-title h2,
.detail-header h2 {
  margin: 0;
  line-height: 1.15;
}

.topbar h1 {
  font-size: clamp(26px, 3vw, 38px);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.topbar .eyebrow {
  color: #8de0c6;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(78px, 1fr));
  min-width: 172px;
  padding: 4px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
}

.segment,
.refresh-button {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

.segment {
  color: rgba(255, 255, 255, 0.78);
  background: transparent;
}

.segment.active {
  color: var(--surface-strong);
  background: #fff;
}

.refresh-button {
  padding: 0 16px;
  color: #fff;
  background: var(--blue);
}

main {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 22px clamp(14px, 3vw, 40px) 44px;
}

.page-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 0 12px;
  scrollbar-width: thin;
}

.page-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.page-tab.active {
  border-color: var(--surface-strong);
  background: var(--surface-strong);
  color: #fff;
}

.page-view {
  display: none;
}

.page-view.active {
  display: block;
}

.overview-section {
  padding: clamp(16px, 3vw, 26px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.main-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.main-title-row .section-title {
  margin-bottom: 0;
}

.data-chip-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.data-chip-row span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #f7f9fb;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.data-chip-row strong {
  color: var(--text);
}

.main-meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--border);
}

.main-meta span {
  display: grid;
  gap: 6px;
  min-height: 68px;
  padding: 12px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.main-meta strong {
  color: var(--text);
  font-size: 16px;
  line-height: 1.25;
}

.top-market-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 18px;
}

.market-top-card {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.market-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.market-card-head h3,
.directory-head h3 {
  margin: 0;
  font-size: clamp(21px, 2.4vw, 28px);
  line-height: 1.2;
}

.market-card-head a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--blue);
  font-size: 13px;
  font-weight: 850;
  text-decoration: none;
  white-space: nowrap;
}

.top-stock-list {
  display: grid;
  gap: 10px;
}

.top-stock-button {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) minmax(82px, auto);
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 78px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f7f9fb;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.top-stock-button:hover {
  border-color: var(--blue);
  background: #eef5ff;
}

.rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-strong);
  color: #fff;
  font-weight: 900;
}

.top-stock-main,
.top-stock-score {
  display: grid;
  gap: 4px;
}

.top-stock-main strong {
  font-size: 17px;
  line-height: 1.25;
}

.top-stock-main small,
.top-stock-score small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.25;
}

.top-stock-score {
  justify-items: end;
  text-align: right;
}

.top-stock-score strong {
  color: var(--green);
  font-size: 24px;
  line-height: 1;
}

.directory-head {
  margin-top: 22px;
}

.status-band {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.status-band > div {
  min-height: 82px;
  padding: 16px;
  background: var(--surface);
}

.label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.status-band strong {
  display: block;
  font-size: clamp(16px, 2vw, 22px);
  line-height: 1.2;
  word-break: keep-all;
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.overview-card {
  min-height: 92px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f7f9fb;
}

.overview-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.overview-card strong {
  display: block;
  margin-top: 10px;
  font-size: clamp(17px, 2vw, 24px);
  line-height: 1.25;
}

.page-directory {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.page-directory a {
  display: grid;
  min-height: 112px;
  padding: 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  text-decoration: none;
  transition:
    border-color 160ms ease,
    transform 160ms ease;
}

.page-directory a:hover {
  border-color: var(--blue);
  transform: translateY(-1px);
}

.page-directory span {
  color: var(--green);
  font-size: 12px;
  font-weight: 900;
}

.page-directory strong {
  margin-top: 8px;
  font-size: 17px;
  line-height: 1.35;
}

.page-directory small {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.45;
}

.macro-section,
.backtest-section,
.snapshot-section,
.detail-section,
.news-section {
  margin-top: 20px;
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.macro-section p {
  max-width: 980px;
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.macro-snapshot {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.macro-summary {
  color: var(--text);
  font-weight: 700;
  line-height: 1.5;
}

.macro-score-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.macro-score,
.macro-indicator {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f7f9fb;
}

.macro-score {
  min-height: 66px;
  padding: 11px;
}

.macro-score span,
.macro-indicator span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.macro-score strong {
  display: block;
  margin-top: 4px;
  font-size: 22px;
}

.macro-indicator-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.macro-indicator {
  min-height: 112px;
  padding: 12px;
}

.macro-indicator strong,
.macro-indicator em,
.macro-indicator small {
  display: block;
}

.macro-indicator strong {
  margin-top: 7px;
  font-size: 15px;
  line-height: 1.3;
}

.macro-indicator em {
  margin-top: 8px;
  font-size: 19px;
  font-style: normal;
  font-weight: 850;
}

.macro-indicator small {
  margin-top: 7px;
  color: var(--muted);
  line-height: 1.35;
}

.section-title {
  margin-bottom: 16px;
}

.section-title h2,
.detail-header h2 {
  font-size: clamp(20px, 2.2vw, 28px);
}

.section-title.with-filter,
.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

#industryFilter {
  min-height: 38px;
  max-width: 220px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 10px;
}

.backtest-controls {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 10px;
}

.backtest-controls label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.backtest-controls select {
  min-height: 38px;
  min-width: 92px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 10px;
}

.backtest-button {
  min-height: 38px;
  padding: 0 16px;
  border: 0;
  border-radius: 6px;
  background: var(--green);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
}

.snapshot-button {
  min-height: 38px;
  padding: 0 16px;
  border: 0;
  border-radius: 6px;
  background: var(--blue);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
}

.snapshot-button:disabled {
  cursor: progress;
  opacity: 0.68;
}

.backtest-button:disabled {
  cursor: progress;
  opacity: 0.68;
}

.backtest-summary,
.snapshot-summary {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
}

.snapshot-summary {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.backtest-metric,
.snapshot-metric {
  min-height: 76px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f7f9fb;
}

.backtest-metric span,
.snapshot-metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.backtest-metric strong,
.snapshot-metric strong {
  display: block;
  margin-top: 8px;
  font-size: 22px;
  line-height: 1.15;
}

.backtest-metric.positive strong,
.positive-text {
  color: var(--green);
}

.backtest-metric.negative strong,
.negative-text {
  color: var(--red);
}

.backtest-benchmarks,
.backtest-notes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.benchmark-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid #bce3d8;
  border-radius: 999px;
  background: #effbf7;
  color: #0b6f4d;
  font-size: 13px;
  font-weight: 800;
}

.backtest-periods {
  display: grid;
  gap: 1px;
  overflow: hidden;
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--border);
}

.period-head,
.period-row {
  display: grid;
  grid-template-columns: 1.1fr 1.6fr repeat(3, minmax(74px, 0.5fr));
  gap: 1px;
  align-items: stretch;
}

.period-head span,
.period-row span,
.period-row strong {
  display: block;
  padding: 10px;
  background: #fff;
  line-height: 1.35;
}

.period-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.period-row span,
.period-row strong {
  font-size: 13px;
}

.snapshot-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.snapshot-card {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.snapshot-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.snapshot-card-head strong,
.snapshot-card-head small,
.snapshot-card-head span {
  display: block;
}

.snapshot-card-head small {
  margin-top: 4px;
  color: var(--muted);
}

.snapshot-card-head > span {
  min-width: 96px;
  color: var(--green);
  font-weight: 900;
  text-align: right;
}

.snapshot-tags,
.snapshot-stocks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.snapshot-tags span,
.snapshot-stocks span {
  min-height: 24px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #eef1f5;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.snapshot-tags span.ok {
  background: #eaf8f2;
  color: #0b6f4d;
}

.snapshot-stocks span {
  background: #eef5ff;
  color: #174ea6;
}

.warning-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.warning-chip {
  padding: 7px 10px;
  border: 1px solid #f2d7a2;
  border-radius: 999px;
  background: #fff8e9;
  color: #815a16;
  font-size: 13px;
}

.source-chip {
  border-color: #bce3d8;
  background: #effbf7;
  color: #0b6f4d;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.86fr) minmax(420px, 1.14fr);
  gap: 20px;
  margin-top: 20px;
  align-items: start;
}

.panel-page {
  margin-top: 20px;
}

.panel {
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.industry-list,
.stock-list,
.news-list {
  display: grid;
  gap: 12px;
}

.industry-card,
.stock-card,
.news-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.industry-card {
  padding: 16px;
}

.industry-head,
.stock-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.industry-card h3,
.stock-card h3,
.detail-grid h3 {
  margin: 0;
  font-size: 17px;
  line-height: 1.35;
}

.industry-card p {
  margin: 8px 0 12px;
  color: var(--muted);
  line-height: 1.55;
}

.score {
  min-width: 58px;
  text-align: right;
  font-weight: 800;
  color: var(--green);
}

.score-bar {
  height: 8px;
  overflow: hidden;
  background: #edf1f5;
  border-radius: 999px;
}

.score-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--green), var(--blue));
}

.mini-bars {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.mini-bar {
  display: grid;
  grid-template-columns: 76px minmax(70px, 1fr) 42px;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.mini-track {
  height: 6px;
  background: #edf1f5;
  border-radius: 999px;
  overflow: hidden;
}

.mini-fill {
  height: 100%;
  width: 0;
  background: var(--teal);
}

.stock-card {
  width: 100%;
  padding: 0;
  text-align: left;
  cursor: pointer;
  transition:
    border-color 160ms ease,
    transform 160ms ease;
}

.stock-card:hover,
.stock-card.active {
  border-color: var(--blue);
  transform: translateY(-1px);
}

.stock-card-inner {
  padding: 15px;
}

.stock-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #eef5ff;
  color: #174ea6;
  font-size: 12px;
  font-weight: 700;
}

.tag.role {
  background: #eaf8f2;
  color: #0b6f4d;
}

.tag.decision {
  background: #111827;
  color: #fff;
}

.tag.risk {
  background: #fff4ed;
  color: #9a3412;
}

.stock-scores {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.stock-scores div {
  min-height: 54px;
  padding: 8px;
  background: #f7f9fb;
  border-radius: 6px;
}

.stock-scores span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.stock-scores strong {
  display: block;
  margin-top: 3px;
  font-size: 17px;
}

.score-pill {
  min-width: 128px;
  padding: 10px 12px;
  text-align: center;
  border-radius: 8px;
  background: var(--surface-strong);
  color: #fff;
  font-size: 22px;
  font-weight: 900;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1fr;
  gap: 22px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.metric-grid div {
  min-height: 66px;
  padding: 10px;
  background: #f7f9fb;
  border: 1px solid #edf1f5;
  border-radius: 6px;
}

.metric-grid dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.metric-grid dd {
  margin: 6px 0 0;
  font-size: 18px;
  font-weight: 850;
}

.plain-list {
  display: grid;
  gap: 9px;
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.5;
}

.risk-list li::marker {
  color: var(--red);
}

.news-section {
  margin-bottom: 28px;
}

.news-card {
  display: block;
  padding: 14px 16px;
  color: var(--text);
  text-decoration: none;
}

.news-card:hover {
  border-color: var(--blue);
}

.news-card strong {
  display: block;
  line-height: 1.45;
}

.news-card span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.empty-state {
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  background: #fbfcfd;
}

.loading {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: none;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface-strong);
  color: #fff;
  box-shadow: var(--shadow);
}

.loading.visible {
  display: block;
}

@media (max-width: 980px) {
  .topbar,
  .main-title-row,
  .section-title.with-filter,
  .detail-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar {
    width: 100%;
    justify-content: space-between;
  }

  .status-band,
  .dashboard-grid,
  .detail-grid,
  .macro-score-grid,
  .macro-indicator-grid,
  .main-meta,
  .top-market-grid,
  .overview-grid,
  .page-directory,
  .backtest-summary,
  .snapshot-summary,
  .period-head,
  .period-row {
    grid-template-columns: 1fr;
  }

}

@media (max-width: 620px) {
  .toolbar,
  .stock-scores,
  .metric-grid {
    grid-template-columns: 1fr 1fr;
  }

  .toolbar {
    display: grid;
  }

  .segmented {
    min-width: 0;
  }

  .refresh-button {
    width: 100%;
  }

  .status-band {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .page-tabs {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    overflow-x: visible;
  }

  .page-tab {
    min-height: 36px;
    padding: 0 6px;
    font-size: 12px;
  }

  .data-chip-row {
    justify-content: flex-start;
  }

  .top-stock-button {
    grid-template-columns: 30px minmax(0, 1fr);
  }

  .top-stock-score {
    grid-column: 2;
    justify-items: start;
    text-align: left;
  }

  .overview-section,
  .macro-section,
  .backtest-section,
  .snapshot-section,
  .detail-section,
  .news-section,
  .panel {
    padding: 16px;
  }
}
