:root {
  color-scheme: dark;
  --bg: #0d1117;
  --surface: #141a22;
  --surface-2: #19212b;
  --line: #27313d;
  --line-soft: #202a35;
  --text: #edf2f7;
  --muted: #8492a3;
  --green: #35c889;
  --red: #f06464;
  --blue: #5ea1ff;
  --yellow: #f1c75b;
  --cyan: #4cc9c0;
  --radius: 6px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

button, table { font: inherit; }

.topbar {
  min-height: 68px;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  background: #10151c;
}

.identity, .top-actions, .freshness, .range-control, .panel-heading, .legend,
.main-nav {
  display: flex;
  align-items: center;
}

.identity { gap: 12px; }
.mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid #3e8b78;
  border-radius: 6px;
  color: var(--green);
  font-weight: 800;
  background: #14251f;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 16px; line-height: 1.4; }
.identity p, .panel-heading p { color: var(--muted); font-size: 12px; margin-top: 2px; }
.top-actions { gap: 18px; }
.main-nav {
  align-self: stretch;
  gap: 3px;
}
.main-nav button,
.main-nav a {
  position: relative;
  min-width: 76px;
  display: grid;
  place-items: center;
  border: 0;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  text-decoration: none;
}
.main-nav button::after,
.main-nav a::after {
  content: "";
  position: absolute;
  right: 12px;
  bottom: -12px;
  left: 12px;
  height: 2px;
  background: transparent;
}
.main-nav button:hover,
.main-nav a:hover { color: var(--text); }
.main-nav button.active { color: var(--text); }
.main-nav button.active::after { background: var(--green); }
.freshness { gap: 7px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--yellow); }
.status-dot.good { background: var(--green); box-shadow: 0 0 0 3px rgb(53 200 137 / 10%); }
.status-dot.bad { background: var(--red); }

.range-control {
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0d1218;
}
.range-control button {
  min-width: 46px;
  height: 28px;
  border: 0;
  border-radius: 4px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}
.range-control button:hover { color: var(--text); }
.range-control button.active { color: #fff; background: #2a3542; }
.icon-command {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted);
  background: #111820;
  cursor: pointer;
}
.icon-command:hover { color: var(--text); border-color: #405064; }

main { padding: 18px 24px 28px; max-width: 1800px; margin: 0 auto; }
.kpis {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.kpis article {
  min-width: 0;
  padding: 14px 16px;
  border-right: 1px solid var(--line);
}
.kpis article:last-child { border-right: 0; }
.kpis span, .kpis small { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpis span { font-size: 12px; }
.kpis strong { display: block; margin: 7px 0 5px; font-size: 21px; line-height: 1; }
.kpis small { font-size: 11px; }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 14px;
  margin-top: 14px;
}
.charts { display: grid; gap: 14px; min-width: 0; }
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.panel-heading {
  min-height: 54px;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
}
h2 { font-size: 13px; line-height: 1.4; }
h3 { font-size: 12px; color: var(--muted); }
.legend { gap: 14px; color: var(--muted); font-size: 11px; }
.legend i { display: inline-block; width: 15px; height: 2px; margin-right: 5px; vertical-align: middle; }
.legend .binance { background: var(--green); }
.legend .okx { background: var(--blue); }

.canvas-wrap {
  position: relative;
  height: 260px;
  padding: 8px 10px 8px 6px;
  overflow: hidden;
}
.compact-chart .canvas-wrap { height: 162px; }
canvas { width: 100%; height: 100%; display: block; }
.chart-panel canvas {
  cursor: grab;
  touch-action: none;
}
.chart-panel canvas.dragging { cursor: grabbing; }
.range-control .chart-command {
  min-width: 28px;
  padding-inline: 7px;
  color: var(--muted);
  font-size: 15px;
}
.range-control .chart-command:hover { color: var(--text); }
.range-control .return-live {
  min-width: 30px;
  color: var(--green);
  font-size: 16px;
}
.empty-state {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
}

.signal-panel { min-height: 100%; }
.badge {
  padding: 4px 7px;
  border: 1px solid #4a6076;
  border-radius: 4px;
  color: #b9d3ee;
  background: #1d2b39;
  font-size: 10px;
  font-weight: 700;
}
.score-gauge { padding: 22px 16px 12px; }
.gauge-track { position: relative; height: 8px; border-radius: 4px; background: linear-gradient(90deg, #763e46, #2b3139 50%, #245b4c); }
.gauge-center { position: absolute; left: 50%; top: -4px; width: 1px; height: 16px; background: #8492a3; }
.gauge-fill { position: absolute; left: 50%; top: 1px; height: 6px; background: var(--green); }
.gauge-marker { position: absolute; left: 50%; top: -4px; width: 2px; height: 16px; background: #fff; transform: translateX(-1px); }
.gauge-labels { display: flex; justify-content: space-between; margin-top: 8px; color: var(--muted); font-size: 10px; }

.market-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: 2px 14px 16px;
  border: 1px solid var(--line-soft);
}
.market-grid div { padding: 10px; border-right: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); }
.market-grid div:nth-child(2n) { border-right: 0; }
.market-grid div:nth-last-child(-n+2) { border-bottom: 0; }
dt { color: var(--muted); font-size: 11px; }
dd { margin: 5px 0 0; font-variant-numeric: tabular-nums; font-weight: 650; }

.meter-list { display: grid; gap: 13px; padding: 0 14px 18px; }
.meter-label { display: flex; justify-content: space-between; margin-bottom: 5px; font-size: 11px; color: var(--muted); }
.meter-label strong { color: var(--text); font-weight: 600; }
.meter { position: relative; height: 5px; overflow: hidden; background: #2a313a; border-radius: 3px; }
.meter::after { content: ""; position: absolute; left: 50%; top: 0; width: 1px; height: 100%; background: #5b6571; }
.meter i { position: absolute; left: 50%; top: 0; height: 100%; width: 0; background: var(--green); }

.order-state { margin-top: auto; padding: 14px; border-top: 1px solid var(--line-soft); background: #111820; }
.order-state div { margin: 7px 0 3px; font-weight: 650; }
.order-state small { color: var(--green); }

.lower-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 14px;
  margin-top: 14px;
}
.table-wrap { position: relative; min-height: 222px; overflow: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { padding: 10px 14px; border-bottom: 1px solid var(--line-soft); text-align: left; font-size: 11px; }
th { position: sticky; top: 0; z-index: 1; color: var(--muted); background: #151c24; font-weight: 500; }
td { color: #c8d0da; font-variant-numeric: tabular-nums; }
.numeric { text-align: right; }
.table-empty { display: grid; min-height: 166px; place-items: center; color: var(--muted); font-size: 12px; }
.side-long, .positive { color: var(--green) !important; }
.side-short, .negative { color: var(--red) !important; }

.model-panel { padding-bottom: 14px; }
.progress { height: 6px; margin: 18px 14px; overflow: hidden; border-radius: 3px; background: #29323c; }
.progress i { display: block; width: 0; height: 100%; background: var(--blue); transition: width 300ms ease; }
.model-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 0 14px 16px; }
.health-list { border-top: 1px solid var(--line-soft); padding: 9px 14px 0; }
.health-list div { display: flex; justify-content: space-between; padding: 6px 0; color: var(--muted); font-size: 11px; }
.health-list strong { color: var(--text); }

.signal-long { color: var(--green); }
.signal-short { color: var(--red); }
.signal-neutral { color: var(--muted); }

#toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(360px, calc(100vw - 36px));
  padding: 10px 12px;
  border: 1px solid #75484c;
  border-radius: 6px;
  color: #ffd4d4;
  background: #341f24;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease;
}
#toast.show { opacity: 1; }

.view-page { display: block; }
.page-title {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 14px;
  padding: 0 2px;
  border-bottom: 1px solid var(--line);
}
.page-title h2 { font-size: 18px; }
.page-title p { margin-top: 5px; color: var(--muted); font-size: 12px; }
.badge.warning {
  color: #efd38a;
  border-color: #685829;
  background: #2c2718;
}
.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(360px, 0.8fr);
  gap: 14px;
}
.settings-panel, .readiness-panel, .system-health-panel { min-height: 470px; }
.connection-status {
  padding: 4px 7px;
  border: 1px solid #5f4547;
  border-radius: 4px;
  color: #e5a5a8;
  background: #2b1c20;
  font-size: 10px;
  font-weight: 700;
}
.connection-status.connected {
  color: #8cddb8;
  border-color: #315c4d;
  background: #172820;
}
.settings-form {
  display: grid;
  gap: 15px;
  padding: 18px 16px;
}
.settings-form label { display: grid; gap: 6px; }
.settings-form label > span { color: var(--muted); font-size: 11px; }
.settings-form input, .settings-form select {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 5px;
  outline: 0;
  color: var(--text);
  background: #10161d;
  padding: 0 11px;
}
.settings-form input:focus, .settings-form select:focus {
  border-color: #477d70;
  box-shadow: 0 0 0 2px rgb(53 200 137 / 8%);
}
.field-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-actions { display: flex; gap: 8px; padding-top: 3px; }
.primary-command, .secondary-command {
  min-height: 36px;
  padding: 0 14px;
  border-radius: 5px;
  cursor: pointer;
}
.primary-command {
  border: 1px solid #399579;
  color: #071b14;
  background: var(--green);
  font-weight: 700;
}
.secondary-command {
  border: 1px solid var(--line);
  color: var(--text);
  background: #18212b;
}
.secondary-command.danger-command {
  color: #f0a8ac;
  border-color: #654044;
  background: #2b1c20;
}
.primary-command:disabled, .secondary-command:disabled { opacity: .55; cursor: wait; }
.test-result {
  margin: 0 16px 16px;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: 5px;
  color: var(--muted);
  background: #111820;
  font-size: 12px;
  line-height: 1.6;
}
.test-result.success { color: #98dfbd; border-color: #315847; }
.test-result.error { color: #f0a8ac; border-color: #654044; }
.demo-execution-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 0 16px 16px;
  padding: 13px 12px;
  border-top: 1px solid var(--line-soft);
  background: #111820;
}
.demo-execution-control strong,
.demo-execution-control span { display: block; }
.demo-execution-control strong { font-size: 12px; }
.demo-execution-control span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
}
.gate-list { margin: 0; padding: 8px 14px 16px; list-style: none; }
.gate-list li {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  align-items: center;
  gap: 9px;
  min-height: 44px;
  border-bottom: 1px solid var(--line-soft);
}
.gate-list li:last-child { border-bottom: 0; }
.gate-list i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #59636f;
}
.gate-list span { color: #c7d0da; font-size: 12px; }
.gate-list strong { color: var(--muted); font-size: 10px; font-weight: 600; }
.gate-list li.passed i { background: var(--green); }
.gate-list li.passed strong { color: var(--green); }
.gate-list li.failed i { background: var(--red); }
.gate-list li.failed strong { color: var(--red); }
.risk-config-panel { margin-top: 14px; }
.risk-config-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  margin: 0;
}
.risk-config-grid div {
  padding: 15px 16px;
  border-right: 1px solid var(--line-soft);
}
.risk-config-grid div:last-child { border-right: 0; }
.system-details { margin: 0; padding: 8px 14px 16px; }
.system-details div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 43px;
  border-bottom: 1px solid var(--line-soft);
}
.system-details div:last-child { border-bottom: 0; }

.history-title { align-items: flex-end; padding-bottom: 12px; }
.history-controls, .segmented {
  display: flex;
  align-items: center;
}
.history-controls { gap: 10px; flex-wrap: wrap; }
.segmented {
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0d1218;
}
.segmented button {
  min-width: 42px;
  height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 4px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}
.segmented button:hover { color: var(--text); }
.segmented button.active {
  color: var(--text);
  background: #2a3542;
}
.history-kpis {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}
.history-kpis article {
  min-width: 0;
  padding: 15px 16px;
  border-right: 1px solid var(--line);
}
.history-kpis article:last-child { border-right: 0; }
.history-kpis span, .history-kpis small {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-kpis strong {
  display: block;
  margin: 7px 0 5px;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}
.history-layout {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}
.history-table-wrap { min-height: 260px; max-height: 390px; }
.history-orders-wrap { min-height: 300px; max-height: 520px; }
.history-summary-panel > .panel-heading span,
.history-orders-panel > .panel-heading span {
  color: var(--muted);
  font-size: 11px;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #0b0f14;
}
.login-shell {
  width: min(940px, 100%);
  min-height: 540px;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, .85fr);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: 0 24px 80px rgb(0 0 0 / 38%);
}
.login-market {
  display: flex;
  flex-direction: column;
  padding: 28px;
  border-right: 1px solid var(--line);
  background: #10171e;
}
.login-brand { display: flex; align-items: center; gap: 11px; }
.login-brand strong, .login-brand span { display: block; }
.login-brand strong { font-size: 14px; }
.login-brand span { margin-top: 3px; color: var(--muted); font-size: 10px; }
.market-visual {
  margin: auto 0;
  padding: 16px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: #0d1319;
}
.market-heading, .market-ticks, .login-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.market-heading span { color: var(--muted); font-size: 10px; }
.market-heading strong { font-size: 11px; }
#login-chart { width: 100%; height: 220px; margin: 12px 0; }
.market-ticks { color: #536171; font-size: 9px; }
.login-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 46px;
}
.login-kicker { color: var(--green); font-size: 10px; font-weight: 800; }
.login-copy h1 { margin-top: 10px; font-size: 27px; }
.login-copy p { margin-top: 7px; color: var(--muted); font-size: 12px; }
#login-form { display: grid; gap: 16px; margin-top: 32px; }
#login-form label { display: grid; gap: 7px; }
#login-form label span { color: var(--muted); font-size: 11px; }
#login-form input {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 5px;
  outline: 0;
  color: var(--text);
  background: #0f151c;
  padding: 0 12px;
}
#login-form input:focus { border-color: var(--green); }
.login-submit {
  height: 42px;
  margin-top: 4px;
  border: 1px solid #399579;
  border-radius: 5px;
  color: #071b14;
  background: var(--green);
  font-weight: 800;
  cursor: pointer;
}
.login-submit:disabled { opacity: .65; }
.login-error { min-height: 18px; color: #ef9297; font-size: 11px; }
.login-foot {
  margin-top: 40px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 10px;
}
.login-foot span:first-child { display: flex; align-items: center; gap: 7px; }

@media (max-width: 1050px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpis article:nth-child(3) { border-right: 0; }
  .kpis article:nth-child(-n+3) { border-bottom: 1px solid var(--line); }
  .workspace, .lower-grid { grid-template-columns: 1fr; }
  .signal-panel, .model-panel { min-height: auto; }
  .settings-grid { grid-template-columns: 1fr; }
  .history-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .history-kpis article:nth-child(3) { border-right: 0; }
  .history-kpis article:nth-child(-n+3) { border-bottom: 1px solid var(--line); }
  .risk-config-grid { grid-template-columns: repeat(3, 1fr); }
  .risk-config-grid div:nth-child(3) { border-right: 0; }
  .risk-config-grid div:nth-child(-n+3) { border-bottom: 1px solid var(--line-soft); }
  .main-nav { order: 3; width: 100%; height: 38px; justify-content: center; }
  .topbar { flex-wrap: wrap; }
}

@media (max-width: 650px) {
  .topbar { align-items: flex-start; padding: 12px 14px; }
  .top-actions { align-items: flex-end; flex-direction: column; gap: 8px; }
  .identity p { max-width: 170px; white-space: normal; }
  main { padding: 12px 10px 22px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpis article, .kpis article:nth-child(3) { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
  .kpis article:nth-child(2n) { border-right: 0; }
  .kpis article:last-child { grid-column: 1 / -1; border-bottom: 0; }
  .canvas-wrap { height: 220px; }
  .compact-chart .canvas-wrap { height: 150px; }
  .legend { display: none; }
  .range-control button { min-width: 40px; }
  .main-nav { order: 4; overflow-x: auto; justify-content: flex-start; }
  .main-nav button, .main-nav a { min-width: 86px; height: 34px; }
  .main-nav button::after, .main-nav a::after { bottom: -2px; }
  .field-pair { grid-template-columns: 1fr; }
  .history-title { align-items: flex-start; flex-direction: column; }
  .history-controls { width: 100%; justify-content: space-between; }
  .history-controls .segmented {
    max-width: 100%;
    overflow-x: auto;
  }
  .history-kpis { grid-template-columns: 1fr 1fr; }
  .history-kpis article,
  .history-kpis article:nth-child(3) {
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
  }
  .history-kpis article:nth-child(2n) { border-right: 0; }
  .history-kpis article:last-child {
    grid-column: 1 / -1;
    border-right: 0;
    border-bottom: 0;
  }
  .settings-panel, .readiness-panel, .system-health-panel { min-height: auto; }
  .risk-config-grid { grid-template-columns: 1fr 1fr; }
  .risk-config-grid div, .risk-config-grid div:nth-child(3) {
    border-right: 1px solid var(--line-soft);
    border-bottom: 1px solid var(--line-soft);
  }
  .risk-config-grid div:nth-child(2n) { border-right: 0; }
  .login-body { padding: 12px; }
  .login-shell { grid-template-columns: 1fr; min-height: 0; }
  .login-market { display: none; }
  .login-panel { min-height: 520px; padding: 32px 24px; }
}
