* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #22313f;
  background: #f4f6f8;
}

button,
select,
a {
  font: inherit;
}

.app-shell {
  width: min(1520px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 20px 0 32px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  color: #fff;
  background: #253241;
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(29, 42, 56, 0.15);
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
  line-height: 1.2;
}

.brand p {
  margin: 6px 0 0;
  color: #cbd6e1;
  font-size: 12px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

.date-control {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #dbe5ef;
  font-size: 12px;
}

.date-control select {
  height: 34px;
  padding: 0 34px 0 10px;
  border: 1px solid #d8e0e7;
  border-radius: 6px;
  color: #22313f;
  background: #fff;
}

.date-badge strong {
  display: inline-flex;
  align-items: center;
  height: 34px;
  padding: 0 10px;
  color: #22313f;
  background: #fff;
  border: 1px solid #d8e0e7;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.tool-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 12px;
  color: #22313f;
  background: #fff;
  border: 1px solid #fff;
  border-radius: 6px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 550;
}

.tool-button.ghost {
  color: #eef4fa;
  background: transparent;
  border-color: rgba(255, 255, 255, 0.34);
}

.tool-button svg,
.modal-close svg {
  width: 16px;
  height: 16px;
}

.chart-section,
.table-section {
  margin-top: 14px;
  padding: 16px;
  background: #fff;
  border: 1px solid #e4e9ef;
  border-radius: 8px;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}

.section-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
}

.section-head p,
.legend-note,
.table-tools {
  margin: 4px 0 0;
  color: #6f7f8f;
  font-size: 12px;
}

.chart {
  width: 100%;
  height: 620px;
}

.trend-chart {
  width: 100%;
  height: 420px;
}

.trend-controls,
.modal-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

.trend-controls label,
.modal-controls label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #6f7f8f;
  font-size: 12px;
}

.trend-controls select,
.modal-controls select {
  height: 30px;
  padding: 0 26px 0 8px;
  color: #22313f;
  background: #fff;
  border: 1px solid #d8e0e7;
  border-radius: 6px;
}

.range-buttons {
  display: none;
  align-items: center;
  gap: 0;
  min-height: 30px;
  border: 1px solid #d8e0e7;
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
}

.range-buttons button {
  height: 30px;
  min-width: 44px;
  padding: 0 10px;
  color: #536474;
  background: transparent;
  border: 0;
  border-right: 1px solid #d8e0e7;
  cursor: pointer;
  font-size: 12px;
}

.range-buttons button:last-child {
  border-right: 0;
}

.range-buttons button.active {
  color: #fff;
  background: #253241;
  font-weight: 650;
}

.legend-note {
  text-align: center;
}

.table-wrap {
  overflow: auto;
  border-top: 1px solid #edf1f5;
}

.table-wrap.compact {
  max-height: 360px;
}

table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
  font-size: 12px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 10px 6px;
  color: #687887;
  background: #fff;
  border-bottom: 2px solid #e9eef3;
  text-align: left;
  font-size: 10px;
  font-weight: 550;
  cursor: pointer;
  user-select: none;
}

th:first-child,
th:last-child {
  cursor: default;
}

th.num,
td.num {
  text-align: right;
}

th.sorted {
  color: #c0392b;
}

.sort-arrow {
  margin-left: 2px;
  opacity: 0.45;
  font-size: 9px;
}

th.sorted .sort-arrow {
  opacity: 1;
}

td {
  padding: 6px;
  border-bottom: 1px solid #f0f3f6;
}

tbody tr:hover {
  background: #f8fafc;
}

.code {
  color: #6f7f8f;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 10px;
}

.name {
  font-weight: 560;
}

.detail-link {
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: rgba(37, 50, 65, 0.24);
  text-underline-offset: 3px;
}

.detail-link:hover {
  color: #1f5ea8;
  background: #eef4fa;
}

.up-strong {
  color: #b8322a;
}

.up {
  color: #d94a40;
}

.down {
  color: #1f8a55;
}

.down-strong {
  color: #14633c;
}

.nan {
  color: #a5b0bb;
}

.bar-cell {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
}

.metric-cell {
  cursor: pointer;
}

.metric-cell:hover {
  background: #eef4fa;
}

.metric-cell.empty {
  cursor: default;
}

.metric-cell.empty:hover {
  background: transparent;
}

.score-text {
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}

.score-low {
  color: #1d7f4f;
}

.score-mid {
  color: #9a6a13;
}

.score-high {
  color: #b8322a;
}

.score-muted {
  color: #9aa7b5;
}

.bar {
  display: inline-block;
  height: 10px;
  min-width: 3px;
  max-width: 88px;
  border-radius: 2px;
}

.sparkline {
  margin-top: 2px;
  vertical-align: middle;
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.sparkline:hover {
  background: #edf2f7;
}

.roe-cell {
  min-width: 92px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(20, 28, 38, 0.48);
}

.modal-overlay.show {
  display: flex;
}

.modal-box {
  position: relative;
  width: min(720px, 96vw);
  max-height: 86vh;
  padding: 20px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 18px 60px rgba(20, 28, 38, 0.24);
}

.modal-box h3 {
  margin: 0 36px 12px 0;
  font-size: 16px;
}

.modal-controls {
  justify-content: space-between;
  margin-bottom: 8px;
}

#modal-subtitle {
  color: #6f7f8f;
  font-size: 12px;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  color: #7a8794;
  background: #f3f6f9;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

#modal-chart {
  width: 100%;
  height: 420px;
}

.detail-modal-box {
  width: min(1480px, 98vw);
  max-height: 94vh;
  overflow: auto;
}

.detail-subtitle {
  margin: -4px 36px 12px 0;
  color: #6f7f8f;
  font-size: 12px;
}

.detail-view {
  display: none;
}

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

.detail-chart-grid {
  display: grid;
  grid-template-columns: minmax(420px, 0.84fr) minmax(620px, 1.16fr);
  gap: 14px;
}

.detail-chart {
  width: 100%;
  height: 620px;
  border: 1px solid #edf1f5;
  border-radius: 8px;
}

.detail-tabs {
  display: inline-flex;
  margin-bottom: 10px;
}

.detail-table-wrap {
  max-height: 660px;
}

.detail-table-wrap td,
.detail-table-wrap th {
  padding: 7px 8px;
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100vw - 24px, 1520px);
    padding-top: 12px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar {
    justify-content: flex-start;
  }

  .chart {
    height: 520px;
  }

  .trend-chart {
    height: 380px;
  }

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

  .detail-chart {
    height: 360px;
  }
}

@media (max-width: 560px) {
  .tool-button,
  .date-control select,
  .date-badge strong {
    width: 100%;
  }

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

  .range-buttons {
    width: 100%;
  }

  .range-buttons button {
    flex: 1;
    min-width: 0;
  }

  .chart {
    height: 460px;
  }

  .trend-chart {
    height: 360px;
  }
}
