:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #eef1f4;
  color: #1b2430;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  max-width: 100%;
  overflow-x: hidden;
}

button,
input,
select,
.button-link {
  font: inherit;
}

.shell {
  min-height: 100vh;
  padding: 24px;
}

.toolbar,
.workspace,
.log-panel,
.result-panel,
.mainline-panel {
  width: 100%;
  max-width: 1880px;
  margin: 0 auto;
}

.toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  font-weight: 700;
}

h2 {
  font-size: 16px;
  font-weight: 700;
}

p,
#statusText,
#resultMeta {
  color: #667085;
  font-size: 14px;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

button {
  border: 1px solid #c8d0d9;
  background: #ffffff;
  color: #1b2430;
  border-radius: 6px;
  padding: 9px 14px;
  cursor: pointer;
}

button:hover,
.button-link:hover {
  border-color: #8793a2;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid #c8d0d9;
  background: #ffffff;
  color: #1b2430;
  border-radius: 6px;
  padding: 9px 14px;
  text-decoration: none;
}

button:disabled {
  cursor: wait;
  opacity: 0.6;
}

button.primary {
  border-color: #0f766e;
  background: #0f766e;
  color: #ffffff;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  align-items: stretch;
  height: 560px;
}

.panel,
.history,
.log-panel,
.result-panel,
.mainline-panel {
  background: #ffffff;
  border: 1px solid #d7dde5;
  border-radius: 8px;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  min-height: 0;
  overflow: hidden;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: #344054;
  font-size: 13px;
  font-weight: 600;
}

input,
select {
  width: 100%;
  border: 1px solid #c8d0d9;
  border-radius: 6px;
  background: #ffffff;
  color: #111827;
  padding: 9px 10px;
  min-height: 38px;
}

input:focus,
select:focus {
  outline: 2px solid #99f6e4;
  border-color: #0f766e;
}

.checks {
  grid-column: 1 / -1;
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
}

.checks label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 500;
}

.checks input {
  width: 16px;
  min-height: 16px;
}

.history {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 100%;
}

.history-head,
.log-head,
.result-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid #e4e8ee;
}

#historyCount {
  color: #667085;
  font-size: 12px;
}

.history-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.history-item {
  width: 100%;
  border: 0;
  border-left: 4px solid transparent;
  border-bottom: 1px solid #edf0f4;
  border-radius: 0;
  text-align: left;
  padding: 12px 16px;
}

.history-item.active {
  border-left-color: #0f766e;
  background: #e6fffb;
}

.history-item.active .history-title {
  color: #0f4f49;
}

.history-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
}

.history-sub {
  margin-top: 4px;
  color: #667085;
  font-size: 12px;
  line-height: 1.4;
}

.result-panel {
  margin-top: 16px;
  overflow: hidden;
  min-width: 0;
}

.mainline-panel {
  margin-top: 16px;
  overflow: hidden;
  min-width: 0;
}

.mainline-panel.embedded {
  width: 100%;
  max-width: none;
  margin: 0;
  border: 0;
  border-bottom: 1px solid #d7dde5;
  border-radius: 0;
}

.mainline-formula {
  padding: 9px 16px;
  border-bottom: 1px solid #e4e8ee;
  background: #f8fafc;
  color: #475467;
  font-size: 12px;
}

.mainline-formula summary {
  width: fit-content;
  color: #344054;
  font-weight: 700;
  cursor: pointer;
}

.mainline-formula p {
  margin-top: 7px;
  line-height: 1.5;
}

.mainline-table-wrap,
.history-result .mainline-table-wrap {
  min-height: 0;
  max-height: 390px;
  flex: none;
}

#mainlineTable {
  width: 100%;
  table-layout: fixed;
  font-size: 12px;
}

#mainlineTable th,
#mainlineTable td {
  padding: 9px 8px;
  white-space: normal;
  overflow-wrap: anywhere;
}

#mainlineTable th:nth-child(1),
#mainlineTable td:nth-child(1) {
  width: 5%;
}

#mainlineTable th:nth-child(2),
#mainlineTable td:nth-child(2) {
  width: 15%;
}

#mainlineTable th:nth-child(3),
#mainlineTable td:nth-child(3) {
  width: 8%;
}

#mainlineTable th:nth-child(4),
#mainlineTable td:nth-child(4) {
  width: 8%;
}

#mainlineTable .mainline-stage {
  font-weight: 700;
}

#mainlineTable tr.mainline-stage-主升 td {
  background: #ecfdf3;
  color: #05603a;
}

#mainlineTable tr.mainline-stage-确认 td {
  background: #eff8ff;
  color: #175cd3;
}

#mainlineTable tr.mainline-stage-观察 td {
  background: #fffaeb;
  color: #854a0e;
}

#mainlineTable tr.mainline-stage-过热 td {
  background: #fff4ed;
  color: #9c2a10;
}

#mainlineTable tr.mainline-stage-退潮 td {
  color: #667085;
}

.log-panel {
  overflow: hidden;
}

.form-log {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: none;
  margin: 0;
}

#logMeta {
  color: #667085;
  font-size: 12px;
}

#queryLog {
  flex: 1;
  min-height: 0;
  margin: 0;
  overflow: auto;
  padding: 12px 16px;
  background: #111827;
  color: #e5e7eb;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.table-wrap {
  overflow-x: hidden;
  overflow-y: auto;
  max-height: calc(100vh - 600px);
  min-height: 260px;
  min-width: 0;
  max-width: 100%;
}

.history-page {
  width: 100%;
  max-width: 1880px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 16px;
  height: calc(100vh - 116px);
  min-height: 560px;
}

.history-full,
.history-result {
  min-height: 0;
}

.history-result {
  margin-top: 0;
  display: flex;
  flex-direction: column;
}

.history-result .table-wrap {
  flex: 1;
  max-height: none;
}

.query-summary {
  display: flex;
  gap: 10px 18px;
  flex-wrap: wrap;
  padding: 10px 16px;
  border-bottom: 1px solid #edf0f4;
  color: #667085;
  font-size: 12px;
}

.score-formula {
  padding: 10px 16px 12px;
  border-bottom: 1px solid #e4e8ee;
  background: #f8fafc;
  color: #475467;
  font-size: 12px;
}

.score-formula summary {
  width: fit-content;
  color: #344054;
  font-weight: 700;
  cursor: pointer;
}

.score-formula-lines {
  display: grid;
  gap: 4px;
  margin-top: 8px;
}

.score-formula-lines p {
  margin: 0;
  line-height: 1.55;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(96px, 1fr)) repeat(2, minmax(112px, 1fr));
  gap: 10px;
  padding: 14px 16px;
  background: #fbfcfe;
  border-bottom: 1px solid #edf0f4;
}

.summary-card {
  display: grid;
  gap: 6px;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid #e4e8ee;
  border-radius: 6px;
  background: #ffffff;
}

.summary-card span {
  color: #667085;
  font-size: 12px;
  line-height: 1;
}

.summary-card strong {
  color: #111827;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
}

.summary-card.positive strong {
  color: #047857;
}

.summary-card.negative strong {
  color: #b42318;
}

table {
  width: 100%;
  max-width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  border-bottom: 1px solid #edf0f4;
  padding: 8px 7px;
  text-align: right;
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f7f9fb;
  color: #344054;
  font-weight: 700;
  line-height: 1.25;
  white-space: normal;
  word-break: keep-all;
}

td {
  line-height: 1.35;
  white-space: nowrap;
}

tr.sell-limit-down td {
  background: #fff1f0;
  color: #7a271a;
}

tr.sell-limit-down td:last-child,
tr.sell-limit-down td:nth-last-child(2) {
  font-weight: 700;
}

th.text-cell,
td.text-cell {
  text-align: left;
}

th.col-board,
td.col-board {
  width: 8%;
}

th.col-board-change,
td.col-board-change {
  width: 7%;
}

th.col-score,
td.col-score {
  width: 7%;
}

th.col-code,
td.col-code {
  width: 6%;
}

th.col-name,
td.col-name {
  width: 10%;
}

th.col-industry,
td.col-industry {
  width: 11%;
}

th.col-date,
td.col-date {
  width: 9%;
}

th.col-price,
td.col-price {
  width: 6%;
}

th.col-pct,
td.col-pct {
  width: 7%;
}

th.col-turnover,
td.col-turnover {
  width: 7%;
}

th.col-amount,
td.col-amount {
  width: 7%;
}

th.col-window-change,
td.col-window-change {
  width: 8%;
}

th.col-profit,
td.col-profit {
  width: 7%;
}

.backtest-table th.col-code,
.backtest-table td.col-code {
  width: 7%;
}

.backtest-table th.col-name,
.backtest-table td.col-name {
  width: 10%;
}

.backtest-table th.col-industry,
.backtest-table td.col-industry {
  width: 10%;
}

.backtest-table th.col-date,
.backtest-table td.col-date {
  width: 8%;
}

.backtest-table th.col-small-number,
.backtest-table td.col-small-number {
  width: 5%;
}

.backtest-table th.col-price,
.backtest-table td.col-price,
.backtest-table th.col-pct,
.backtest-table td.col-pct,
.backtest-table th.col-amount,
.backtest-table td.col-amount {
  width: 8%;
}

.merged-cell {
  background: #fbfcfe;
  border-bottom-color: #d7dde5;
  font-weight: 600;
}

.result-panel tbody tr.board-leader > td:not(.merged-cell) {
  background: #fff7d6;
  color: #4a3b00;
  font-weight: 600;
}

.result-panel tbody tr.recommended-stock > td,
.result-panel tbody tr.recommended-stock > td.merged-cell {
  background: #fff0f0;
  color: #7f1d1d;
}

.result-panel tbody tr.recommended-stock > td.col-recommendation {
  font-weight: 700;
}

th.col-recommendation,
td.col-recommendation {
  width: 7%;
}

.empty {
  padding: 36px;
  text-align: center;
  color: #667085;
}

@media (max-width: 980px) {
  .shell {
    padding: 16px;
  }

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

  .actions {
    justify-content: stretch;
  }

  .actions button {
    flex: 1;
  }

  .actions .button-link {
    flex: 1;
  }

  .workspace {
    grid-template-columns: 1fr;
    height: auto;
    width: 100%;
  }

  .history-page {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
    width: 100%;
  }

  .history-full {
    height: 360px;
  }

  .form-grid {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }
}

@media (max-width: 560px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 22px;
  }
}
