:root {
  --bg: #111318;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #303642;
  --text: #f5f7fb;
  --muted: #9aa3b2;
  --amber: #f59e0b;
  --green: #26a69a;
  --red: #ef5350;
  --blue: #60a5fa;
  --purple: #8b5cf6;
  --shadow: 0 18px 55px rgba(0, 0, 0, .26);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 20% 10%, rgba(245, 158, 11, .12), transparent 28%),
    radial-gradient(circle at 80% 80%, rgba(96, 165, 250, .1), transparent 30%),
    var(--bg);
}
.login-shell {
  width: min(420px, calc(100vw - 32px));
}
.login-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(23, 26, 33, .96);
  box-shadow: var(--shadow);
  padding: 26px;
}
.login-brand {
  margin-bottom: 24px;
}
.login-form {
  display: grid;
  gap: 14px;
}
.login-form label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}
.login-form input {
  height: 42px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: #12151b;
  color: var(--text);
  padding: 0 12px;
  outline: none;
}
.login-form input:focus {
  border-color: var(--amber);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, .15);
}
.login-error {
  color: var(--red);
  background: rgba(239, 83, 80, .08);
  border: 1px solid rgba(239, 83, 80, .35);
  border-radius: 7px;
  padding: 9px 11px;
  font-size: 13px;
}
button, select, input { font: inherit; }
button, select { cursor: pointer; }

.topbar {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(17, 19, 24, .96);
  position: sticky;
  top: 0;
  z-index: 10;
}
.connection-banner {
  position: fixed;
  top: 78px;
  left: 50%;
  transform: translate(-50%, -12px);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(760px, calc(100vw - 28px));
  padding: 10px 14px;
  border: 1px solid rgba(245, 158, 11, .45);
  border-radius: 8px;
  background: rgba(31, 26, 15, .96);
  color: #f8e7bd;
  box-shadow: var(--shadow);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
}
.connection-banner.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
.connection-banner strong {
  color: var(--amber);
  white-space: nowrap;
}
.connection-banner span {
  color: #e8d6ad;
  font-size: 13px;
  overflow-wrap: anywhere;
}
.global-loader {
  position: fixed;
  top: 74px;
  right: 24px;
  z-index: 35;
  min-width: 170px;
  height: 36px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border: 1px solid rgba(96, 165, 250, .35);
  border-radius: 8px;
  background: rgba(18, 22, 30, .92);
  color: #cfe3ff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.global-loader.show {
  opacity: 1;
  transform: translateY(0);
}
.global-loader span {
  color: #cfe3ff;
  font-size: 13px;
}
.global-loader-bar {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(96, 165, 250, .24);
  border-top-color: var(--blue);
  animation: spin .78s linear infinite;
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(245, 158, 11, .42);
  color: var(--amber);
  font-weight: 800;
  border-radius: 8px;
  background: #1f1a0f;
}
.brand-title { font-weight: 800; font-size: 17px; white-space: nowrap; }
.brand-subtitle { color: var(--muted); font-size: 12px; margin-top: 3px; }
.top-controls, .inline-controls { display: flex; align-items: center; gap: 10px; }
.model-label { color: var(--muted); font-size: 13px; }
.model-select, .filter-input {
  height: 38px;
  border-radius: 7px;
  border: 1px solid var(--line);
  color: var(--text);
  background: #151820;
  padding: 0 12px;
  outline: none;
}
.model-select { min-width: 220px; }
.model-select.small { min-width: 150px; }
.filter-input { min-width: 220px; }
.filter-input.wide { min-width: 340px; width: min(460px, 52vw); }
.model-select:focus, .filter-input:focus { border-color: var(--amber); box-shadow: 0 0 0 3px rgba(245, 158, 11, .15); }
.logout-link {
  color: var(--muted);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 12px;
  font-size: 13px;
  background: #151820;
}
.logout-link:hover {
  color: var(--text);
  border-color: var(--amber);
}
.ghost-button, .time-button {
  height: 38px;
  border-radius: 7px;
  border: 1px solid var(--line);
  color: var(--text);
  background: #1a1e27;
  padding: 0 14px;
  transition: background .2s ease, border-color .2s ease;
}
.ghost-button:hover, .time-button:hover, .time-button.active { border-color: var(--amber); background: #241f14; }
.primary-button {
  height: 40px;
  border-radius: 7px;
  border: 1px solid rgba(245, 158, 11, .62);
  color: #151008;
  background: var(--amber);
  padding: 0 16px;
  font-weight: 760;
}
.primary-button:disabled {
  cursor: not-allowed;
  opacity: .58;
}

.layout { display: grid; grid-template-columns: 184px 1fr; min-height: calc(100vh - 72px); }
.sidebar {
  border-right: 1px solid var(--line);
  padding: 18px 12px;
  background: #12151b;
}
.nav-item {
  width: 100%;
  height: 40px;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  text-align: left;
  padding: 0 14px;
  margin-bottom: 6px;
  transition: background .2s ease, color .2s ease;
}
.nav-item:hover, .nav-item.active { color: var(--text); background: #20242e; }
.content { padding: 20px; overflow: hidden; }
.panel { display: none; }
.panel.active { display: block; }

.hero-grid {
  display: grid;
  grid-template-columns: 1.5fr repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}
.pnl-card, .metric-card, .surface {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.pnl-card { padding: 20px; min-height: 132px; }
.metric-card { padding: 18px; min-height: 132px; }
.metric-label { color: var(--muted); font-size: 13px; }
.metric-value { margin-top: 10px; font-size: 38px; font-weight: 800; line-height: 1; }
.metric-number { margin-top: 18px; font-size: 28px; font-weight: 760; }
.metric-delta { margin-top: 10px; font-size: 16px; font-weight: 700; }
.positive { color: var(--green); }
.negative { color: var(--red); }
.market-up { color: var(--red); }
.market-down { color: var(--green); }

.movers-surface {
  margin-bottom: 14px;
}
.movers-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.mover-title {
  font-weight: 800;
  margin: 4px 0 10px;
}
.mover-list {
  display: grid;
  gap: 8px;
}
.mover-row {
  width: 100%;
  min-height: 64px;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #1b2029;
  color: var(--text);
  text-align: left;
}
.mover-row:hover {
  border-color: var(--amber);
  background: #222717;
}
.mover-rank {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: #10141b;
  color: var(--muted);
  font-weight: 800;
}
.mover-name {
  display: grid;
  gap: 4px;
  min-width: 0;
}
.mover-name strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}
.mover-name em,
.mover-numbers em {
  color: var(--muted);
  font-style: normal;
  font-size: 12px;
}
.mover-numbers {
  display: grid;
  justify-items: end;
  gap: 4px;
  min-width: 112px;
}
.mover-pnl {
  font-size: 17px;
  font-weight: 850;
}
.mover-pct {
  font-size: 12px;
}

.two-column { display: grid; grid-template-columns: 1fr 1.2fr; gap: 14px; }
.surface { padding: 16px; }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}
.section-head.compact { margin-bottom: 8px; }
.section-head h2, .stock-info h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.25;
}
.section-head p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}
.model-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.model-stats div, .info-grid div {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 7px;
  padding: 12px;
}
.model-stats span, .info-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}
.model-stats strong, .info-grid strong { font-size: 17px; }
.mini-chart { height: 240px; width: 100%; }
.data-table {
  height: calc(100vh - 180px);
  min-height: 440px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.chart-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}
.search-box { position: relative; }
.search-results {
  position: absolute;
  top: 44px;
  left: 0;
  width: 100%;
  max-height: 280px;
  overflow: auto;
  background: #151820;
  border: 1px solid var(--line);
  border-radius: 8px;
  z-index: 20;
  display: none;
}
.search-result {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.search-result:hover { background: #242933; }
.chart-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 14px; }
.chart-surface { min-width: 0; position: relative; }
.kline-chart { height: 520px; width: 100%; }
.volume-chart { height: 120px; width: 100%; margin-top: 6px; }
.loading-overlay {
  position: absolute;
  inset: 126px 16px 142px;
  z-index: 8;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  border: 1px solid rgba(245, 158, 11, .3);
  border-radius: 8px;
  background: rgba(17, 19, 24, .78);
  backdrop-filter: blur(6px);
  color: var(--text);
  text-align: center;
}
.loading-overlay.show { display: flex; }
.loading-overlay strong { font-size: 15px; }
.loading-overlay span {
  color: var(--muted);
  font-size: 12px;
}
.loading-spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(245, 158, 11, .22);
  border-top-color: var(--amber);
  animation: spin .78s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.stock-info { align-self: start; }
.info-grid { display: grid; grid-template-columns: 1fr; gap: 8px; }
.stock-info-strip {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  margin-bottom: 12px;
}
.stock-info-strip strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stock-info-strip [data-field="行情状态"] strong,
.stock-info-strip [data-field="快照时间"] strong,
.stock-info-strip [data-field="数据源"] strong {
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.28;
  font-size: 13px;
}
.stock-info-strip [data-field="市场阶段"] strong {
  color: var(--amber);
}
.stock-info-strip .live-price {
  color: var(--text);
  font-size: 28px;
  font-weight: 860;
  line-height: 1.05;
}
.stock-info-strip [data-field="涨跌幅"] strong {
  font-size: 24px;
  font-weight: 820;
}
.ticker-number {
  display: inline-block !important;
  align-items: baseline;
  gap: 0;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  white-space: nowrap;
}
.value-slide {
  animation: valueSlide .24s ease;
}
@keyframes valueSlide {
  0% { opacity: .72; transform: translateY(4px); }
  100% { opacity: 1; transform: translateY(0); }
}
.digit-window {
  display: inline-block;
  width: .62em;
  height: 1em;
  overflow: hidden;
  line-height: 1em;
  vertical-align: -0.08em;
}
.digit-stack {
  display: block;
  transition: transform .36s cubic-bezier(.2, .8, .2, 1);
  will-change: transform;
}
.digit-stack span {
  display: block;
  height: 1em;
  line-height: 1em;
  text-align: center;
}
.ticker-char {
  display: inline-block;
  min-width: .28em;
}
.flash-up {
  animation: priceFlashRed .52s ease;
}
.flash-down {
  animation: priceFlashGreen .52s ease;
}
@keyframes priceFlashRed {
  0% { background: rgba(239, 83, 80, .42); box-shadow: 0 0 0 0 rgba(239, 83, 80, .28); }
  100% { background: transparent; box-shadow: none; }
}
@keyframes priceFlashGreen {
  0% { background: rgba(38, 166, 154, .42); box-shadow: 0 0 0 0 rgba(38, 166, 154, .28); }
  100% { background: transparent; box-shadow: none; }
}
.recommend-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
  max-height: 290px;
  overflow: auto;
  margin: 10px 0 18px;
}
.recommend-item {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 7px;
  padding: 9px 10px;
  text-align: left;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 8px;
}
.recommend-item:hover,
.recommend-item.active {
  border-color: var(--amber);
  background: #242515;
}
.recommend-item strong { font-size: 13px; }
.recommend-item span { color: var(--muted); font-size: 12px; }
.recommend-item .recommend-pnl { grid-column: 2; grid-row: 1 / span 2; align-self: center; font-weight: 700; }

.retrain-grid {
  display: grid;
  grid-template-columns: 1.4fr repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}
.retrain-hero, .retrain-card { min-height: 138px; }
.retrain-card {
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.retrain-card span {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 12px;
}
.retrain-card strong {
  font-size: 22px;
  line-height: 1.25;
}
.retrain-detail { margin-top: 14px; }
.detail-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.detail-list div {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 7px;
  padding: 12px;
  min-height: 74px;
}
.detail-list span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}
.detail-list strong {
  font-size: 16px;
  line-height: 1.35;
}
.note-block {
  color: var(--muted);
  line-height: 1.7;
  font-size: 14px;
  white-space: pre-line;
}
.status-pill {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
}
.status-pill.ok { color: var(--green); border-color: rgba(38, 166, 154, .45); background: rgba(38, 166, 154, .08); }
.status-pill.warn { color: var(--amber); border-color: rgba(245, 158, 11, .5); background: rgba(245, 158, 11, .08); }
.status-pill.error { color: var(--red); border-color: rgba(239, 83, 80, .5); background: rgba(239, 83, 80, .08); }
.automation-grid {
  display: grid;
  grid-template-columns: 1fr 1.1fr 1.2fr;
  gap: 14px;
  margin-bottom: 14px;
}
.automation-card {
  min-height: 132px;
}
.automation-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 10px;
}
.automation-card strong {
  display: block;
  font-size: 20px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.automation-card p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
  margin: 10px 0 0;
  overflow-wrap: anywhere;
}
.compact-table {
  height: calc(100vh - 360px);
  min-height: 360px;
}
.task-status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-weight: 700;
  font-size: 12px;
}
.task-status.ok { color: var(--green); background: rgba(38, 166, 154, .1); }
.task-status.running { color: var(--blue); background: rgba(96, 165, 250, .1); }
.task-status.warn, .task-status.pending { color: var(--amber); background: rgba(245, 158, 11, .1); }
.task-status.error { color: var(--red); background: rgba(239, 83, 80, .1); }
.ai-layout {
  display: grid;
  grid-template-columns: minmax(320px, .62fr) minmax(0, 1.38fr);
  gap: 14px;
}
.ai-input-surface, .ai-output-surface { min-height: 520px; }
.ai-prompt {
  width: 100%;
  min-height: 250px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #12151b;
  color: var(--text);
  padding: 13px 14px;
  line-height: 1.55;
  outline: none;
}
.ai-prompt:focus { border-color: var(--amber); box-shadow: 0 0 0 3px rgba(245, 158, 11, .15); }
.ai-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}
.ai-hint {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ai-rules { margin-top: 14px; }
.ai-chat {
  height: 460px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #12151b;
  padding: 14px;
}
.chat-message {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}
.chat-message.user { justify-items: end; }
.chat-message.assistant, .chat-message.system { justify-items: start; }
.chat-bubble {
  max-width: min(860px, 92%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 13px;
  line-height: 1.65;
  font-size: 14px;
  overflow-wrap: anywhere;
}
.chat-message.user .chat-bubble {
  background: #272113;
  border-color: rgba(245, 158, 11, .35);
}
.chat-message.assistant .chat-bubble {
  background: #181d25;
}
.chat-message.system .chat-bubble {
  background: #131820;
  color: var(--muted);
}
.chat-bubble h1, .chat-bubble h2, .chat-bubble h3 {
  margin: 8px 0 6px;
  line-height: 1.3;
}
.chat-bubble h1 { font-size: 18px; }
.chat-bubble h2 { font-size: 16px; }
.chat-bubble h3 { font-size: 15px; }
.chat-bubble p { margin: 7px 0; }
.chat-bubble ul, .chat-bubble ol { margin: 7px 0 7px 20px; padding: 0; }
.chat-bubble code {
  background: #0d1015;
  border: 1px solid #29313d;
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 12px;
}
.chat-bubble pre {
  background: #0d1015;
  border: 1px solid #29313d;
  border-radius: 7px;
  padding: 10px;
  overflow: auto;
}
.tool-card {
  width: min(860px, 92%);
  border: 1px solid #333b48;
  background: #151a22;
  border-radius: 8px;
  margin: 10px 0 14px;
  overflow: hidden;
}
.tool-card summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 13px;
  color: #dce3ee;
  font-weight: 720;
}
.tool-card summary::-webkit-details-marker { display: none; }
.tool-icon {
  width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  border: 1px solid #3c4654;
  border-radius: 6px;
  color: var(--muted);
}
.tool-meta {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}
.tool-detail {
  border-top: 1px solid #2b3340;
  padding: 11px 13px;
  white-space: pre-wrap;
  color: #cbd5e1;
  font-size: 12px;
  line-height: 1.55;
  max-height: 340px;
  overflow: auto;
}
.ai-files-head { margin-top: 14px; }
.file-list {
  min-height: 70px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 10px;
}
.file-link {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--blue);
  text-decoration: none;
  border-bottom: 1px solid #303642;
  padding: 8px 0;
  font-size: 13px;
}
.file-link:last-child { border-bottom: 0; }
.file-link span:last-child { color: var(--muted); }
.ai-raw-surface { margin-top: 14px; }
.ai-raw-surface summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 700;
}
.ai-raw-surface p {
  color: var(--muted);
  margin: 8px 0 12px;
  font-size: 13px;
}
.ai-raw {
  height: 250px;
  overflow: auto;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d1015;
  color: #b8c0cc;
  padding: 12px;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.is-hidden { display: none !important; }

.tabulator {
  background: var(--panel);
  border: 0;
  color: var(--text);
  font-size: 13px;
}
.tabulator .tabulator-header { background: #20242e; border-bottom: 1px solid var(--line); }
.tabulator-row { background: #171a21; border-bottom: 1px solid #272d38; }
.tabulator-row:nth-child(even) { background: #191d25; }
.tabulator-row .tabulator-cell { border-right: 1px solid #262c36; }
.long-text {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: flex; gap: 6px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 10px; }
  .nav-item { min-width: 92px; text-align: center; margin-bottom: 0; }
  .hero-grid, .two-column, .chart-layout, .retrain-grid, .detail-list, .ai-layout, .automation-grid { grid-template-columns: 1fr; }
  .stock-info-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { align-items: flex-start; height: auto; padding: 14px; flex-direction: column; }
  .top-controls { width: 100%; flex-wrap: wrap; }
  .model-select { flex: 1; min-width: 180px; }
  .filter-input.wide { width: 100%; min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
