:root {
  --bg: #f6f7f8;
  --ink: #17202a;
  --muted: #6d7680;
  --line: #d8dee5;
  --panel: #ffffff;
  --panel-soft: #f9fafb;
  --gain: #c73a3a;
  --loss: #16805f;
  --accent: #2459a6;
  --warn: #a65f00;
  --shadow: 0 12px 30px rgba(28, 39, 52, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: "Avenir Next", "Helvetica Neue", Arial, sans-serif;
}

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

button,
select,
input,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
}

button {
  padding: 0.5rem 0.85rem;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

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

select,
input,
textarea {
  width: 100%;
  padding: 0.68rem 0.75rem;
}

textarea {
  resize: vertical;
}

.shell {
  width: min(1540px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 26px 0 44px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  align-items: stretch;
  margin-bottom: 18px;
}

.eyebrow,
.muted {
  color: var(--muted);
  font-size: 0.86rem;
}

.eyebrow {
  margin: 0 0 8px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(2.2rem, 4vw, 4.6rem);
  line-height: 0.98;
}

h2 {
  margin-bottom: 0;
  font-size: 1.05rem;
}

h3 {
  margin-bottom: 0;
  font-size: 0.96rem;
}

.subtitle {
  max-width: 780px;
  color: #3d4650;
  font-size: 1.02rem;
}

.panel,
.status-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel,
.status-card {
  min-width: 0;
  padding: 16px;
}

.status-card strong {
  display: block;
  margin: 8px 0;
  font-size: 1.8rem;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tab.is-active {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.flash {
  min-height: 1.3rem;
}

.workspace {
  display: none;
}

.workspace.is-active {
  display: block;
}

.workspace-grid {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 18px;
}

.live-grid {
  display: grid;
  grid-template-columns: 420px minmax(340px, 520px) minmax(0, 1fr);
  gap: 18px;
}

.stock-grid {
  display: grid;
  grid-template-columns: minmax(360px, 520px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.pattern-grid {
  display: grid;
  grid-template-columns: minmax(360px, 460px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.stock-grid > .panel:nth-child(n + 3) {
  grid-column: 1 / -1;
}

.stack {
  display: grid;
  gap: 18px;
}

.content-grid {
  display: grid;
  grid-template-columns: 320px 420px minmax(0, 1fr);
  gap: 18px;
}

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

.panel-title.compact {
  margin-bottom: 6px;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
  min-width: 0;
}

.live-controls {
  grid-template-columns: minmax(0, 1fr) 150px minmax(0, 1.2fr);
}

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

.field {
  display: grid;
  gap: 6px;
}

.wide-field {
  grid-column: 1 / -1;
}

.stock-controls .actions {
  grid-column: 1 / -1;
}

.field span,
.toggle span {
  color: var(--muted);
  font-size: 0.8rem;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
}

.toggle input {
  width: auto;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.actions button {
  white-space: nowrap;
}

.summary-strip {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 10px;
}

.metric,
.item-card,
.signal-node,
.flow-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.metric {
  padding: 12px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.metric strong {
  display: block;
  margin-top: 5px;
  font-size: 1.08rem;
}

.list {
  display: grid;
  gap: 10px;
  max-height: 820px;
  overflow: auto;
  padding-right: 4px;
}

.item-card,
.signal-node {
  width: 100%;
  padding: 12px;
  text-align: left;
}

.item-card.active,
.signal-node.active {
  border-color: var(--accent);
  background: #eef4ff;
}

.row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.18rem 0.52rem;
  color: #fff;
  background: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.pill.hot,
.pill.completed {
  background: var(--gain);
}

.pill.running,
.pill.loading {
  background: var(--accent);
}

.pill.failed {
  background: var(--warn);
}

.gain {
  color: var(--gain);
}

.loss {
  color: var(--loss);
}

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

.chart-wrap {
  margin-top: 16px;
}

.equity-chart {
  min-height: 230px;
}

.equity-chart svg {
  width: 100%;
  height: 230px;
}

.detail-head {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.flow {
  display: grid;
  gap: 12px;
}

.flow-card {
  padding: 12px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

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

.table th {
  color: var(--muted);
  font-weight: 600;
}

.raw-json {
  overflow: auto;
  max-height: 360px;
  padding: 12px;
  border-radius: 8px;
  color: #f7fbff;
  background: #1d2733;
  font-size: 0.78rem;
}

.prompt-box {
  overflow: auto;
  min-height: 460px;
  max-height: 720px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #182230;
  background: #fbfcfd;
  font-size: 0.84rem;
  line-height: 1.55;
  white-space: pre-wrap;
}

@media (max-width: 1320px) {
  .workspace-grid,
  .live-grid,
  .content-grid,
  .stock-grid,
  .pattern-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .hero,
  .metrics,
  .detail-head,
  .control-grid,
  .live-controls,
  .stock-controls {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 680px) {
  .shell {
    width: min(100vw - 20px, 1540px);
    padding-top: 14px;
  }
}

.history-layout {
  min-width: 0;
  background: var(--panel);
  border-top: 2px solid var(--accent);
}

.history-section {
  min-width: 0;
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.history-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  align-items: end;
}

.history-controls .field,
.history-search,
.history-section .panel-title > * {
  min-width: 0;
}

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

.history-stat span,
.history-stat strong {
  display: block;
  overflow-wrap: anywhere;
}

.history-stat strong { margin-top: 6px; font-size: 1.2rem; }
.history-stat span { color: var(--muted); font-size: 0.82rem; }
.history-jobs { display: grid; gap: 10px; }
.history-job { min-width: 0; border: 1px solid var(--line); border-radius: 6px; padding: 12px; }
.history-job progress { width: 100%; height: 12px; margin-top: 8px; accent-color: var(--accent); }
.history-job details { margin-top: 8px; }
.history-job li { margin: 4px 0; overflow-wrap: anywhere; }
.history-job .actions { margin-top: 10px; }
.history-search { display: flex; gap: 8px; }
.history-search input { min-width: 0; max-width: 260px; }
.history-search button { flex-shrink: 0; white-space: nowrap; min-width: 64px; }
#history-chart svg { display: block; height: 170px; }
.history-pagination { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 12px; }
.table-scroll { overflow-x: auto; max-width: 100%; }
.history-bars { max-height: 420px; overflow-y: auto; }
.history-bars thead { position: sticky; top: 0; background: var(--panel); }
.history-section .table { white-space: nowrap; }
.history-section .stock-link { padding: 3px 0; color: var(--accent); background: transparent; border: 0; }
.history-section .stock-link:hover { text-decoration: underline; }
.history-section [hidden] { display: none !important; }
.history-section .panel-title { flex-wrap: wrap; }

@media (max-width: 900px) {
  .history-controls,
  .history-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .history-section { padding: 14px; }
  .history-controls { grid-template-columns: minmax(0, 1fr); }
  .history-list-title { align-items: stretch; flex-direction: column; }
  .history-search input { max-width: none; }
  .history-pagination { align-items: flex-start; flex-direction: column; }
}

/* 选股规则面板 */
.rules-panel {
  margin-top: 10px;
}

.rules-grid {
  display: grid;
  gap: 10px;
}

.rules-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
}

.rules-row .toggle {
  min-height: 0;
}

.radio {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.radio input {
  width: auto;
  accent-color: var(--accent);
}

.inline-field {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.inline-field span {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.inline-field input {
  width: 96px;
}

.is-hidden {
  display: none !important;
}

/* ---- 定时任务页 + 回测规则面板（步骤 13 新增） ---- */
.scheduler-layout {
  display: grid;
  grid-template-columns: 440px 1fr;
  gap: 16px;
  align-items: start;
}

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

.rules-details {
  margin-top: 10px;
  border: 1px solid var(--border, #d8dee5);
  border-radius: 8px;
  padding: 10px 12px;
}

.rules-details summary {
  cursor: pointer;
  color: var(--muted, #6d7680);
  font-size: 13px;
}

.rules-details .control-grid {
  margin-top: 10px;
}

.small {
  font-size: 12px;
}

.pill.ok,
.pill.completed { background: #e8f3ec; color: #16805f; }
.pill.warn,
.pill.partial { background: #fdf3e4; color: #b8860b; }
.pill.bad,
.pill.failed,
.pill.interrupted { background: #fdecec; color: #c73a3a; }
.pill.muted,
.pill.skipped { background: #f1f3f5; color: #6d7680; }

.resend-button {
  margin-top: 6px;
}

#schedule-runs details summary {
  cursor: pointer;
  color: var(--muted, #6d7680);
  font-size: 13px;
  margin-top: 6px;
}

@media (max-width: 900px) {
  .scheduler-layout {
    grid-template-columns: 1fr;
  }
}
