:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #697383;
  --line: #dfe5ec;
  --blue: #1d67d2;
  --green: #0f8b5f;
  --red: #c64242;
  --amber: #b7791f;
  --soft-blue: #eef5ff;
  --soft-green: #effaf6;
  --shadow: 0 10px 28px rgba(27, 39, 55, 0.1);
  --input-bg: #ffffff;
  --chart-bg: #fbfcfd;
  --step-bg: #f8fafc;
  --track-bg: #e8edf3;
  --panel-soft: #f9fbfd;
  --row-bg: #fbfcfe;
  --row-hover: #f4f8fc;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1120;
  --panel: #111827;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --line: #334155;
  --blue: #60a5fa;
  --green: #34d399;
  --red: #f87171;
  --amber: #fbbf24;
  --soft-blue: #172554;
  --soft-green: #064e3b;
  --shadow: 0 16px 44px rgba(0, 0, 0, 0.3);
  --input-bg: #0f172a;
  --chart-bg: #111827;
  --step-bg: #0f172a;
  --track-bg: #1e293b;
  --panel-soft: #0d1626;
  --row-bg: #0f172a;
  --row-hover: #132036;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, "Microsoft YaHei", sans-serif;
  line-height: 1.45;
  transition: background-color 0.25s ease, color 0.25s ease;
}

.app-shell.is-hidden,
.loading-screen.is-hidden {
  display: none;
}

.loading-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
  background: radial-gradient(circle at 20% 20%, var(--soft-blue) 0, transparent 34%), var(--bg);
}

.loading-card {
  width: min(920px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: var(--shadow);
  animation: liftIn 0.28s ease both;
}

.loading-card h1 {
  margin-bottom: 10px;
}

.loading-card p {
  color: var(--muted);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 32px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(10px);
}

.topbar > div:first-child {
  flex: 0 0 auto;
  min-width: 260px;
}

.eyebrow,
.label {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 24px;
  white-space: nowrap;
}

h2 {
  font-size: 15px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  min-width: 0;
}

input,
select,
button {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  padding: 0 12px;
}

select {
  min-width: 110px;
}

button {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
  cursor: pointer;
  transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

button:hover {
  transform: translateY(-1px);
}

.ghost-button {
  background: transparent;
  color: var(--text);
  border-color: var(--line);
}

.ghost-button:hover {
  background: var(--panel-soft);
  border-color: color-mix(in srgb, var(--blue) 18%, var(--line));
}

.realtime-button.active {
  border-color: color-mix(in srgb, var(--green) 52%, var(--line));
  background: color-mix(in srgb, var(--green) 14%, var(--panel));
  color: var(--green);
}

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

.inline-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--input-bg);
  padding-left: 10px;
  color: var(--muted);
}

.inline-field input {
  width: 58px;
  border: 0;
  border-left: 1px solid var(--line);
  border-radius: 0 6px 6px 0;
}

main {
  width: min(1680px, 100%);
  margin: 0 auto;
  padding: 22px 32px 44px;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.panel,
.chart-panel,
.side-panel,
.news-panel,
.loading-panel,
.detail-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, background-color 0.25s ease;
  animation: fadeUp 0.24s ease both;
}

.panel:hover,
.detail-panel:hover,
.chart-panel:hover,
.side-panel:hover {
  border-color: color-mix(in srgb, var(--blue) 34%, var(--line));
  box-shadow: var(--shadow);
}

.panel {
  min-height: 132px;
  padding: 16px 18px;
}

.panel strong {
  display: block;
  font-size: 25px;
  line-height: 1.2;
  margin-bottom: 10px;
}

.panel p,
.side-panel p,
li {
  color: var(--muted);
  line-height: 1.55;
}

.recommendation strong {
  color: var(--blue);
}

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

.loading-head p {
  margin: 6px 0 0;
  color: var(--muted);
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  background: var(--track-bg);
  overflow: hidden;
}

.progress-bar {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--green));
  transition: width 0.3s ease;
}

.loading-steps {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.loading-step {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--step-bg);
  color: var(--text);
  min-width: 0;
}

.loading-step span {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--track-bg);
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.loading-step strong,
.loading-step em {
  display: block;
  font-style: normal;
}

.loading-step strong {
  font-size: 13px;
}

.loading-step em {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.loading-step.active {
  border-color: #98b7e4;
  background: var(--soft-blue);
}

.loading-step.done span {
  background: var(--green);
  color: #fff;
}

.workbench {
  display: grid;
  grid-template-columns: minmax(0, 2.25fr) minmax(320px, 0.75fr);
  gap: 16px;
  align-items: stretch;
  min-height: calc(100vh - 236px);
}

.chart-panel,
.news-panel,
.detail-panel {
  padding: 16px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 13px;
}

.chart-panel .section-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
}

#generatedAt {
  text-align: right;
}

.realtime-status {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  white-space: nowrap;
}

.realtime-status.active {
  border-color: color-mix(in srgb, var(--green) 35%, var(--line));
  color: var(--green);
  background: color-mix(in srgb, var(--green) 10%, var(--panel));
}

.market-chart {
  width: 100%;
  height: clamp(540px, calc(100vh - 268px), 780px);
  min-height: 460px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--chart-bg);
  overflow: hidden;
}

.side-panel {
  padding: 18px;
  max-height: clamp(520px, calc(100vh - 280px), 760px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.side-panel section + section {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.side-panel section {
  min-height: 0;
}

.side-panel section:first-child {
  flex: 1 1 auto;
  overflow: auto;
  padding-right: 4px;
}

.side-panel section:nth-child(2) {
  flex: 0 0 auto;
  max-height: 240px;
  overflow: auto;
  padding-right: 4px;
}

.reasoning-box {
  color: var(--muted);
}

.reasoning-box summary {
  cursor: pointer;
  color: var(--text);
  font-weight: 700;
}

.reasoning-box pre {
  max-height: 190px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 10px 0 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--step-bg);
  color: var(--muted);
  font: 12px/1.5 Consolas, "Segoe UI", monospace;
}

.llm-report {
  color: var(--text);
  line-height: 1.55;
}

.llm-report h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.llm-report p {
  margin: 8px 0;
}

.llm-report ul {
  margin-top: 10px;
}

.llm-report li {
  color: var(--text);
}

ul {
  margin: 10px 0 0;
  padding-left: 18px;
}

.details-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(210px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.metric-list {
  display: grid;
  grid-template-columns: minmax(110px, 0.9fr) minmax(0, 1.1fr);
  gap: 10px 14px;
  margin: 0;
}

.metric-list dt {
  color: var(--muted);
}

.metric-list dd {
  margin: 0;
  text-align: right;
  font-weight: 700;
}

.news-panel {
  margin-top: 16px;
}

.backtest-panel {
  margin-top: 16px;
  padding: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  animation: fadeUp 0.24s ease both;
}

.backtest-panel > .section-head {
  margin: 0;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 82%, var(--bg));
}

.mini-button {
  height: 30px;
  padding: 0 10px;
  font-size: 13px;
}

.backtest-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 16px 18px 10px;
  margin: 0;
}

.backtest-stat {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px 14px;
  background: var(--panel-soft);
}

.backtest-stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.backtest-stat strong {
  font-size: 20px;
}

.history-list {
  display: grid;
  gap: 0;
  max-height: 520px;
  overflow: auto;
  padding: 0 18px 18px;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}

.history-item summary {
  display: grid;
  grid-template-columns: minmax(120px, 0.8fr) minmax(0, 1.5fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  cursor: pointer;
}

.history-item summary span,
.history-item summary em {
  color: var(--muted);
  font-style: normal;
  font-size: 13px;
}

.history-item summary strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item.correct {
  border-color: color-mix(in srgb, var(--green) 48%, var(--line));
}

.history-item.wrong {
  border-color: color-mix(in srgb, var(--red) 42%, var(--line));
}

.history-item.pending {
  border-color: color-mix(in srgb, var(--amber) 34%, var(--line));
}


.metric-list.compact {
  padding: 0 14px 14px;
  font-size: 13px;
}

.history-empty {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--panel-soft);
}

.history-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 68px;
  padding: 6px;
  border: 1px solid var(--line);
  border-bottom-width: 0;
  background: var(--row-bg);
  transition: background-color 0.16s ease, border-color 0.16s ease;
}

.history-row:first-child {
  border-radius: 8px 8px 0 0;
}

.history-row:last-child {
  border-bottom-width: 1px;
  border-radius: 0 0 8px 8px;
}

.history-row:only-child {
  border-radius: 8px;
}

.history-row:hover {
  background: var(--row-hover);
  border-color: color-mix(in srgb, var(--blue) 20%, var(--line));
}

.history-open {
  display: grid;
  grid-template-columns: minmax(140px, 0.85fr) minmax(0, 1.6fr) minmax(180px, 0.85fr);
  gap: 14px;
  align-items: center;
  width: 100%;
  min-height: 54px;
  padding: 10px 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-align: left;
  box-shadow: none;
}

.history-open:hover {
  background: transparent;
  box-shadow: none;
}

.history-open span,
.history-open em {
  color: var(--muted);
  font-style: normal;
  font-size: 13px;
}

.history-open strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
}

.history-delete {
  width: 58px;
  height: 34px;
  padding: 0;
  border-color: var(--line);
  background: color-mix(in srgb, var(--panel) 88%, var(--bg));
  color: var(--muted);
  font-size: 12px;
}

.history-delete:hover {
  border-color: color-mix(in srgb, var(--red) 28%, var(--line));
  color: var(--red);
  background: color-mix(in srgb, var(--red) 8%, var(--panel));
}

.history-detail {
  margin-top: 0;
  border-top: 1px solid var(--line);
  padding: 18px;
  background: color-mix(in srgb, var(--panel) 88%, var(--bg));
}

.history-detail.is-hidden {
  display: none;
}

.history-chart {
  width: 100%;
  height: clamp(420px, 54vh, 620px);
  min-height: 360px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--chart-bg);
  overflow: hidden;
  margin-bottom: 14px;
}

.history-detail .metric-list.compact {
  padding: 0;
  grid-template-columns: repeat(3, minmax(96px, 0.72fr) minmax(0, 1fr));
  gap: 8px;
}

.history-detail .metric-list.compact dt,
.history-detail .metric-list.compact dd {
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.history-detail .metric-list.compact dt {
  border-radius: 6px 0 0 6px;
  color: var(--muted);
}

.history-detail .metric-list.compact dd {
  border-left: 0;
  border-radius: 0 6px 6px 0;
  text-align: left;
}

.history-loading {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--chart-bg);
}

.news-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.news-item {
  display: flex;
  min-height: 174px;
  flex-direction: column;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  color: var(--text);
  text-decoration: none;
  background: linear-gradient(180deg, var(--panel) 0%, color-mix(in srgb, var(--panel) 88%, var(--bg)) 100%);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.news-item:hover {
  border-color: #9cb8df;
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.news-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 10px;
}

.news-meta span {
  max-width: 46%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.news-title {
  color: var(--text);
  font-weight: 800;
  line-height: 1.35;
}

.news-content {
  margin: 10px 0 12px;
  color: var(--muted);
  line-height: 1.5;
  max-height: 82px;
  overflow: hidden;
}

.news-content p {
  margin: 0 0 8px;
}

.news-content ul,
.news-content ol {
  margin: 0;
  padding-left: 18px;
}

.news-action {
  margin-top: auto;
  color: var(--blue);
  font-weight: 700;
  font-size: 13px;
}

.news-empty {
  grid-column: 1 / -1;
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: color-mix(in srgb, var(--panel) 88%, var(--bg));
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes liftIn {
  from {
    opacity: 0;
    transform: scale(0.985) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@media (max-width: 1180px) {
  .summary-grid,
  .details-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .loading-steps,
  .news-list,
  .backtest-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  .topbar,
  .controls {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    position: static;
    padding: 16px;
  }

  h1 {
    font-size: 20px;
  }

  input,
  select,
  button,
  .inline-field {
    width: 100%;
  }

  .inline-field input {
    flex: 1;
  }

  main {
    padding: 12px;
  }

  .summary-grid,
  .workbench,
  .details-grid,
  .loading-steps,
  .news-list {
    grid-template-columns: 1fr;
  }

  .summary-grid {
    gap: 10px;
    margin-bottom: 10px;
  }

  .panel {
    min-height: auto;
    padding: 14px;
  }

  .panel strong {
    font-size: 21px;
  }

  .workbench {
    min-height: auto;
    gap: 12px;
  }

  .chart-panel,
  .news-panel,
  .backtest-panel,
  .detail-panel,
  .side-panel {
    padding: 12px;
  }

  .market-chart {
    height: min(70vh, 520px);
    min-height: 360px;
  }

  .side-panel {
    max-height: none;
    overflow: visible;
  }

  .side-panel section:first-child,
  .side-panel section:nth-child(2) {
    max-height: 260px;
    overflow: auto;
  }

  .metric-list {
    grid-template-columns: minmax(88px, 0.9fr) minmax(0, 1.1fr);
    gap: 8px 10px;
    font-size: 13px;
  }

  .news-item {
    min-height: auto;
  }

  .history-item summary {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .history-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .history-open {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .history-delete {
    width: 100%;
    height: 40px;
  }

  .history-detail .metric-list.compact {
    grid-template-columns: minmax(88px, 0.85fr) minmax(0, 1.15fr);
  }

  .loading-screen {
    padding: 14px;
  }

  .loading-card {
    padding: 18px;
  }
}

@media (max-width: 520px) {
  .market-chart {
    height: 390px;
    min-height: 340px;
  }

  .loading-steps {
    gap: 6px;
  }

  .loading-step {
    padding: 8px;
  }

  .section-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .chart-panel .section-head {
    display: flex;
  }

  .realtime-status,
  #generatedAt {
    justify-self: stretch;
    text-align: left;
    white-space: normal;
  }

  .backtest-stats {
    grid-template-columns: 1fr;
  }

  .history-chart {
    height: 390px;
    min-height: 340px;
  }
}
