:root {
  color-scheme: light;
  --bg: #f5f7f4;
  --surface: #ffffff;
  --surface-2: #eef3ed;
  --text: #1d2520;
  --muted: #657066;
  --line: #d9e1d7;
  --green: #17803b;
  --green-2: #0f5f2b;
  --red: #b3261e;
  --amber: #9a6500;
  --ink: #263128;
  --shadow: 0 10px 24px rgba(34, 51, 38, 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",
    "Microsoft YaHei", sans-serif;
}

button,
input {
  font: inherit;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(26px, 4vw, 42px);
  font-weight: 780;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
  letter-spacing: 0;
}

.topbar p,
.section-title span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
}

.primary-btn {
  min-width: 156px;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font-weight: 760;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.primary-btn:disabled {
  cursor: progress;
  opacity: 0.72;
}

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

.secondary-btn {
  min-width: 118px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 720;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.secondary-btn:disabled {
  cursor: progress;
  opacity: 0.72;
}

.control-band {
  display: grid;
  grid-template-columns: repeat(6, minmax(116px, 1fr));
  gap: 10px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.control-band label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.control-band span {
  color: var(--muted);
  font-size: 12px;
}

.control-band input[type="number"] {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  color: var(--ink);
  background: #fbfcfa;
}

.control-band input[type="number"]:focus-visible {
  outline: 2px solid rgba(23, 128, 59, 0.25);
  border-color: var(--green);
}

.toggle {
  align-content: end;
  grid-template-columns: 18px 1fr;
  column-gap: 8px;
  padding-bottom: 7px;
}

.toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.toggle span {
  font-size: 13px;
  color: var(--ink);
}

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

.status-grid div,
.best-card,
.risk-section,
.tables,
.review-section,
.learning-section,
.best-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.status-grid div {
  padding: 14px;
}

.status-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.status-grid strong {
  display: block;
  margin-top: 5px;
  font-size: 26px;
}

.best-section,
.review-section,
.learning-section,
.tables,
.risk-section {
  padding: 14px;
  margin-top: 14px;
}

.review-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.review-summary span {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
}

.review-summary strong {
  color: var(--ink);
  font-size: 14px;
}

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

.learning-grid > div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: var(--surface-2);
}

.learning-grid span,
.learning-grid small {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.learning-grid strong {
  display: block;
  margin: 4px 0;
  font-size: 18px;
}

.learning-decision {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.review-wrap {
  margin-top: 4px;
}

.review-table {
  min-width: 1120px;
}

.empty-line {
  color: var(--muted);
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

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

.best-card {
  padding: 12px;
  box-shadow: none;
}

.best-card.actionable {
  border-color: rgba(23, 128, 59, 0.62);
  box-shadow: inset 0 3px 0 var(--green);
}

.best-card.observe-only {
  border-color: rgba(154, 101, 0, 0.4);
}

.execution-badge {
  display: inline-block;
  margin: 3px 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 760;
  white-space: nowrap;
}

.execution-badge.actionable {
  border-color: rgba(23, 128, 59, 0.45);
  background: #e8f5eb;
  color: var(--green-2);
}

.execution-badge.observe-only {
  border-color: rgba(154, 101, 0, 0.4);
  background: #fff6df;
  color: #714a00;
}

.best-card header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.rank {
  color: var(--green-2);
  font-weight: 800;
}

.stock-name {
  font-weight: 760;
}

.stock-code {
  color: var(--muted);
  font-size: 12px;
}

.score {
  flex: 0 0 auto;
  font-size: 20px;
  font-weight: 820;
  white-space: nowrap;
}

.card-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 10px 0;
}

.card-metrics span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.card-metrics strong {
  display: block;
  margin-top: 2px;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.chip {
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 7px;
  color: var(--ink);
  background: var(--surface-2);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.tab {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 14px;
  background: #fbfcfa;
  color: var(--ink);
  cursor: pointer;
}

.tab.active {
  border-color: var(--green);
  background: #e7f3ea;
  color: var(--green-2);
  font-weight: 760;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 1480px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
  background: #fbfcfa;
  position: sticky;
  top: 0;
}

tbody tr:hover {
  background: #fbfcfa;
}

td.reason-cell {
  min-width: 260px;
}

td.timing-cell {
  min-width: 240px;
  line-height: 1.45;
}

.timing {
  margin: 7px 0;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.45;
}

.subtle {
  color: var(--muted);
  font-size: 11px;
}

.positive {
  color: var(--red);
}

.negative {
  color: var(--green-2);
}

.risk-text {
  color: var(--amber);
}

.rejects {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.reject-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 12px;
}

.empty-state {
  min-height: 70px;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  display: flex;
}

.error {
  color: var(--red);
}

@media (max-width: 1100px) {
  .control-band {
    grid-template-columns: repeat(3, minmax(116px, 1fr));
  }

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

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

@media (max-width: 720px) {
  .shell {
    width: min(100vw - 18px, 680px);
    padding-top: 10px;
  }

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

  .primary-btn {
    width: 100%;
  }

  .actions,
  .secondary-btn {
    width: 100%;
  }

  .control-band,
  .status-grid,
  .best-grid {
    grid-template-columns: 1fr;
  }

  .learning-grid {
    grid-template-columns: 1fr;
  }

  .section-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .execution-badge {
    white-space: normal;
  }
}
