:root {
  --ink: #0f1724;
  --muted: #5a6578;
  --line: rgba(15, 23, 36, 0.08);
  --line-strong: rgba(15, 23, 36, 0.14);
  --up: #0a9d5c;
  --down: #e04538;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --panel: rgba(255, 255, 255, 0.78);
  --surface: rgba(248, 250, 253, 0.92);
  --control-height: 2.25rem;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --panel-shadow: 0 1px 2px rgba(15, 23, 36, 0.04), 0 10px 32px rgba(15, 23, 36, 0.07);
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --display: "Syne", system-ui, sans-serif;
  --layout-max: 100%;
  --layout-gutter: 1.25rem;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: var(--mono);
  background: #bcc8d8;
}

body {
  position: relative;
  overflow-x: hidden;
}

button,
input,
select {
  border-radius: var(--radius-sm);
}

button,
input,
select {
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.16);
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 70% 55% at 12% -8%, rgba(37, 99, 235, 0.14), transparent 58%),
    radial-gradient(ellipse 55% 45% at 88% 4%, rgba(10, 157, 92, 0.1), transparent 52%),
    linear-gradient(165deg, #cdd7e4 0%, #b8c4d4 48%, #c5ceda 100%);
}

.atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background-image:
    linear-gradient(rgba(15, 23, 36, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 23, 36, 0.035) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: radial-gradient(ellipse 90% 80% at 50% 20%, #000 20%, transparent 75%);
}

.top {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1.5rem;
  padding: 1rem var(--layout-gutter);
  border-bottom: 1px solid rgba(255, 255, 255, 0.45);
  backdrop-filter: blur(16px) saturate(1.2);
  background: rgba(255, 255, 255, 0.55);
  box-shadow: 0 1px 0 rgba(15, 23, 36, 0.05);
}

.top-nav {
  display: flex;
  align-self: center;
  justify-self: center;
  align-items: center;
  gap: 0.2rem;
  padding: 0.22rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.55);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

.nav-item {
  position: relative;
  min-width: 5rem;
  padding: 0.42rem 0.95rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.nav-item::after {
  display: none;
}

.nav-item:hover {
  color: var(--ink);
  background: rgba(15, 23, 36, 0.05);
}

.nav-item.is-on {
  color: #f8fafc;
  font-weight: 600;
  background: linear-gradient(135deg, #1a2740 0%, #0f1724 100%);
  box-shadow: 0 2px 8px rgba(15, 23, 36, 0.18);
}

.nav-item.is-on::after {
  display: none;
}

.brand {
  display: flex;
  gap: 0.55rem;
  align-items: baseline;
  font-family: var(--display);
  letter-spacing: 0;
}

.brand-mark {
  font-weight: 800;
  font-size: 1.35rem;
}

.brand-sub {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--muted);
}

.meta {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.model-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  max-width: 18rem;
  min-width: 0;
  padding: 0.2rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.65);
  color: var(--ink);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.model-chip-label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.62rem;
}

.model-chip-sep {
  color: var(--muted);
}

#model-id {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
}

#model-trained {
  color: var(--muted);
}

.auth-btn {
  height: 1.85rem;
  padding: 0 0.75rem;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.85);
  color: var(--ink);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(15, 23, 36, 0.04);
}

.auth-btn:hover:not(:disabled) {
  border-color: rgba(31, 111, 235, 0.45);
  background: #fff;
}

.auth-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.auth-btn.is-logged {
  color: var(--up);
  border-color: rgba(10, 122, 75, 0.35);
}

.auth-btn-quiet {
  color: var(--muted);
  font-weight: 500;
}

.auth-btn-quiet:hover:not(:disabled) {
  color: var(--down);
  border-color: rgba(224, 69, 56, 0.35);
  background: #fff;
}

.login-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 1.25rem;
}

.login-modal[hidden] {
  display: none;
}

.login-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 24, 31, 0.42);
  backdrop-filter: blur(4px);
}

.login-modal-panel {
  position: relative;
  z-index: 1;
  width: min(22rem, 100%);
  padding: 1.25rem 1.35rem 1.35rem;
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: var(--radius-xl);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 24px 64px rgba(15, 23, 36, 0.2);
  animation: login-in 0.22s ease-out;
  overflow: hidden;
}

@keyframes login-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.login-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.login-modal-head h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.2rem;
  font-weight: 700;
}

.login-modal-head p {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.4;
}

.login-close {
  width: 2rem;
  height: 2rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.login-close:hover {
  color: var(--ink);
}

.login-qr-frame {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  width: min(16rem, 100%);
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(135deg, rgba(37, 99, 235, 0.08), transparent 42%),
    #fff;
  overflow: hidden;
}

.login-qr-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 0.75rem;
}

.login-qr-placeholder {
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
}

.login-qr-placeholder[hidden],
.login-qr-frame img[hidden] {
  display: none;
}

.login-hint {
  margin: 0.9rem 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.45;
}

.login-modal-actions {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 1.1rem;
}

.login-modal-actions .submit-btn {
  min-width: 6rem;
  height: 2.25rem;
  padding: 0 1rem;
}

.login-cancel {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: #b0b8c4;
}

.dot.is-live {
  background: var(--up);
  animation: pulse 1.8s ease-out infinite;
}

.dot.is-dead {
  background: var(--down);
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(10, 122, 75, 0.45);
  }
  100% {
    box-shadow: 0 0 0 10px rgba(10, 122, 75, 0);
  }
}

.stage {
  width: min(var(--layout-max), calc(100% - var(--layout-gutter) * 2));
  margin: 0 auto;
  padding: 1.75rem 0 3rem;
}

.workspace-view[hidden] {
  display: none;
}

.workspace-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.workspace-heading h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 2.25rem;
  line-height: 1.1;
}

.workspace-heading p {
  margin: 0.55rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.workspace-kicker {
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.45);
}

.hero-line h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 2.25rem;
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1.1;
}

.hero-title-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.85rem 1rem;
}

.hero-title-row .chips {
  align-self: center;
  padding-top: 0.15rem;
}

.hero-line p {
  margin: 0.55rem 0 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.55;
  letter-spacing: 0.01em;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding: 0.22rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.45);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.chip {
  min-height: 1.85rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.76rem;
  padding: 0.38rem 0.72rem;
  border-radius: calc(var(--radius-sm) + 1px);
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.chip:hover:not(:disabled):not(.is-on) {
  color: var(--ink);
  background: rgba(15, 23, 36, 0.06);
}

.chip.is-on {
  background: linear-gradient(135deg, #1a2740 0%, #0f1724 100%);
  color: #f8fafc;
  box-shadow: 0 2px 6px rgba(15, 23, 36, 0.16);
}

.chip.is-on:hover:not(:disabled) {
  color: #f8fafc;
  background: linear-gradient(135deg, #1a2740 0%, #0f1724 100%);
}

.chip-quiet {
  min-height: 1.75rem;
  padding: 0.28rem 0.55rem;
  font-size: 0.72rem;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
}

.chip-quiet:hover:not(:disabled) {
  border-color: var(--line-strong);
  background: #fff;
}

.trade-grid {
  margin-top: 1.15rem;
  display: grid;
  grid-template-columns: minmax(0, 2.4fr) minmax(300px, 1fr);
  gap: 1rem;
  align-items: stretch;
}

.history-grid {
  margin-top: 1rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  align-items: start;
}

.history-grid > .order-history-panel {
  margin-top: 0;
  min-width: 0;
}

.chart-panel,
.order-panel,
.backtest-panel,
.log-panel,
.order-history-panel {
  border: 1px solid rgba(255, 255, 255, 0.72);
  background: var(--panel);
  backdrop-filter: blur(16px) saturate(1.15);
  border-radius: var(--radius-lg);
  box-shadow: var(--panel-shadow);
  overflow: hidden;
}

.chart-head {
  display: grid;
  grid-template-columns: minmax(15rem, auto) 1fr;
  align-items: start;
  gap: 0.75rem 1.25rem;
  padding: 0.9rem 1.05rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.42) 0%, rgba(255, 255, 255, 0.08) 100%);
}

.chart-summary {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

.chart-identity {
  min-width: 0;
}

.chart-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.55rem 0.9rem;
  min-width: 0;
}

.chart-head strong {
  font-family: var(--display);
  font-size: 1.05rem;
}

.chart-head small {
  display: block;
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 0.72rem;
}

.live-price {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.live-price > span:first-child {
  font-weight: 600;
  font-size: 1.05rem;
}

.chg.up {
  color: var(--up);
}

.chg.down {
  color: var(--down);
}

.chart-legend {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  color: var(--muted);
  font-size: 0.66rem;
}

.chart-legend .leg {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.leg-line {
  width: 0.9rem;
  height: 2px;
  border-radius: 1px;
}

.leg-line.is-ema5 {
  background: #1f6feb;
}

.leg-line.is-ema13 {
  background: #b7791f;
}

.leg-vol {
  width: 0.55rem;
  height: 0.55rem;
  background: rgba(10, 122, 75, 0.55);
  border-radius: 1px;
  box-shadow: 2px 0 0 rgba(192, 57, 43, 0.55);
}

.chart-host {
  height: min(68vh, 580px);
  width: 100%;
  padding: 0.15rem 0.35rem 0.35rem;
}

.order-panel {
  display: flex;
  flex-direction: column;
  padding: 0;
  min-height: 0;
  height: 100%;
  position: sticky;
  top: 0.75rem;
}

.order-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.8rem 0.9rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.42) 0%, rgba(255, 255, 255, 0.08) 100%);
}

.order-head h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.05rem;
}

.order-head p {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.68rem;
}

.mode-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.22rem;
  min-width: 7.5rem;
  padding: 0.22rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.45);
}

.mode-btn {
  min-height: 1.85rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.72rem;
  padding: 0.38rem 0.35rem;
  border-radius: calc(var(--radius-sm) + 1px);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.mode-btn.is-on {
  background: rgba(15, 23, 36, 0.08);
  color: var(--ink);
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 36, 0.12);
}

.mode-btn[data-mode="live"].is-on {
  background: rgba(224, 69, 56, 0.12);
  color: var(--down);
  box-shadow: inset 0 0 0 1px rgba(224, 69, 56, 0.28);
}

.order-form {
  display: grid;
  gap: 0.7rem;
  padding: 0.85rem;
}

.order-form label {
  display: grid;
  gap: 0.3rem;
}

.order-form label > span {
  font-size: 0.66rem;
  letter-spacing: 0;
  text-transform: uppercase;
  color: var(--muted);
}

.order-form input,
.order-form select {
  height: var(--control-height);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  font: inherit;
  font-size: 0.82rem;
  padding: 0 0.65rem;
  width: 100%;
  box-shadow: inset 0 1px 2px rgba(15, 23, 36, 0.03);
}

.dir-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.22rem;
  padding: 0.22rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.45);
}

.auto-symbol-chips {
  justify-content: stretch;
}

.auto-symbol-chips .chip {
  flex: 1;
  min-width: 0;
  justify-content: center;
}

.dir-btn {
  height: var(--control-height);
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 0.82rem;
  padding: 0 0.5rem;
  border-radius: calc(var(--radius-sm) + 1px);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.dir-btn.is-long.is-on {
  background: rgba(10, 157, 92, 0.14);
  color: var(--up);
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(10, 157, 92, 0.28);
}

.dir-btn.is-short.is-on {
  background: rgba(224, 69, 56, 0.12);
  color: var(--down);
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(224, 69, 56, 0.26);
}

.order-actions {
  display: grid;
  gap: 0.55rem;
}

.auto-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.55rem;
}

.auto-row > span {
  font-size: 0.66rem;
  letter-spacing: 0;
  text-transform: uppercase;
  color: var(--muted);
}

.switch {
  position: relative;
  width: 2.55rem;
  height: 1.4rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(20, 24, 31, 0.12);
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease;
}

.switch-thumb {
  position: absolute;
  top: 50%;
  left: 0.16rem;
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 50%;
  background: #f4f7fb;
  transform: translateY(-50%);
  transition: transform 0.18s ease;
  box-shadow: 0 1px 2px rgba(20, 24, 31, 0.18);
}

.switch[aria-checked="true"],
.switch.is-on {
  background: var(--ink);
  border-color: var(--ink);
}

.switch[aria-checked="true"] .switch-thumb,
.switch.is-on .switch-thumb {
  transform: translate(1.05rem, -50%);
}

.switch[data-mode-live="true"][aria-checked="true"] {
  background: var(--down);
  border-color: var(--down);
}

.submit-btn {
  min-height: 2.5rem;
  border: 0;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #1a2740 0%, #0f1724 100%);
  color: #f8fafc;
  font: inherit;
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: 0;
  padding: 0.7rem 0.85rem;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(15, 23, 36, 0.18);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.submit-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(15, 23, 36, 0.22);
}

.submit-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.paper-panel {
  margin-top: auto;
  padding: 0.75rem 0.85rem 0.9rem;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.35);
}

.paper-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
}

.paper-head strong {
  font-family: var(--display);
  font-size: 0.88rem;
}

.paper-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.paper-metrics .metric {
  display: grid;
  gap: 0.12rem;
  padding: 0.55rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.55);
}

.paper-metrics .metric span {
  font-size: 0.62rem;
  letter-spacing: 0;
  text-transform: uppercase;
  color: var(--muted);
}

.paper-metrics .metric strong {
  font-size: 0.88rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.paper-note {
  margin: 0.55rem 0 0;
  font-size: 0.68rem;
  line-height: 1.4;
  color: var(--muted);
}

.paper-panel.is-live-hidden {
  display: none;
}

.order-result {
  margin: 0;
  padding: 0.55rem 0.85rem 0.75rem;
  border-top: 1px solid var(--line);
  background: rgba(15, 23, 36, 0.03);
  border-radius: 0;
  font-size: 0.66rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 120px;
  overflow: auto;
}

.order-history-panel {
  overflow-x: auto;
}

.order-history-head,
.order-history-row {
  display: grid;
  gap: 0.55rem;
  align-items: center;
  padding: 0.45rem 0.85rem;
  font-variant-numeric: tabular-nums;
}

.order-history-head,
.order-history-row {
  grid-template-columns: minmax(7rem, 1.2fr) minmax(4rem, 0.7fr) minmax(2.5rem, 0.45fr) minmax(3rem, 0.55fr) minmax(4.5rem, 0.85fr) minmax(4.5rem, 0.85fr) minmax(3.5rem, 0.65fr) minmax(4rem, 0.75fr);
}

.order-history-row {
  margin: 0 0.45rem;
  padding: 0.42rem 0.65rem;
  border: 0;
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  transition: background 0.12s ease;
}

.order-history-row:nth-child(even) {
  background: rgba(15, 23, 36, 0.025);
}

.order-history-row:hover {
  background: var(--accent-soft);
}

.order-history-row .is-countdown {
  color: var(--accent);
  font-weight: 600;
}

.order-history-head {
  margin: 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: rgba(255, 255, 255, 0.35);
}

.order-history-list {
  max-height: min(22rem, 42vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.35rem 0.2rem 0.45rem;
}

.order-history-row .is-pass {
  color: var(--up);
}

.order-history-row .is-fail {
  color: var(--down);
}

.order-history-row .is-muted {
  color: var(--muted);
}

.order-history-row .is-long {
  color: var(--up);
}

.order-history-row .is-short {
  color: var(--down);
}

.order-history-empty {
  margin: 0;
  padding: 1rem 0.85rem;
  color: var(--muted);
  font-size: 0.72rem;
}

@media (max-width: 760px) {
  .order-history-head {
    display: none;
  }

  .order-history-row {
    grid-template-columns: 1fr 1fr;
    gap: 0.25rem 0.75rem;
    padding: 0.65rem 0.85rem;
  }

  .order-history-row span:nth-child(1) {
    grid-column: 1 / -1;
    color: var(--muted);
    font-size: 0.68rem;
  }

  .order-history-row span:nth-child(6),
  .order-history-row span:nth-child(7) {
    font-weight: 600;
  }
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem 0.95rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.42) 0%, rgba(255, 255, 255, 0.08) 100%);
}

.panel-head h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.panel-head p {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.4;
}

.backtest-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(7.5rem, 1fr)) auto;
  gap: 0.45rem;
  align-items: end;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--line);
}

.backtest-page-panel {
  width: 100%;
}

.backtest-page-panel .backtest-controls {
  max-width: none;
}

.backtest-controls label {
  display: grid;
  gap: 0.2rem;
  min-width: 0;
}

.backtest-controls label span {
  color: var(--muted);
  font-size: 0.62rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

.backtest-controls select,
.backtest-controls input,
.run-backtest {
  height: var(--control-height);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  font: inherit;
  font-size: 0.74rem;
  padding: 0 0.6rem;
  width: 100%;
}

.run-backtest {
  border-color: transparent;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #1a2740 0%, #0f1724 100%);
  color: #f8fafc;
  cursor: pointer;
  width: auto;
  min-width: 3.6rem;
  padding-inline: 0.75rem;
  box-shadow: 0 2px 8px rgba(15, 23, 36, 0.16);
}

.run-backtest:disabled {
  cursor: wait;
  opacity: 0.65;
}

.backtest-state {
  padding: 0.55rem 0.85rem;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.4;
}

.backtest-state[data-state="profit"] {
  color: var(--up);
  background: rgba(10, 122, 75, 0.07);
}

.backtest-state[data-state="loss"],
.backtest-state[data-state="error"] {
  color: var(--down);
  background: rgba(192, 57, 43, 0.06);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.metric-grid[hidden] {
  display: none;
}

.metric-grid > .metric {
  min-width: 0;
  padding: 0.65rem 0.75rem;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.metric-grid > .metric:nth-child(3n) {
  border-right: 0;
}

.metric-grid > .metric:nth-last-child(-n + 3) {
  border-bottom: 0;
}

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

.metric strong {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.metric strong.positive {
  color: var(--up);
}

.metric strong.negative {
  color: var(--down);
}

.metric small {
  margin-top: 0.12rem;
}

.equity-panel {
  border-top: 1px solid var(--line);
}

.equity-panel[hidden] {
  display: none;
}

.equity-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.85rem 0.25rem;
}

.equity-head strong {
  display: block;
  font-size: 0.78rem;
}

.equity-head small {
  display: block;
  margin-top: 0.1rem;
  color: var(--muted);
  font-size: 0.62rem;
}

.equity-legend {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--muted);
  font-size: 0.62rem;
}

.leg-swatch {
  width: 0.75rem;
  height: 0.2rem;
  background: var(--accent);
}

.leg-swatch.is-zero {
  background: rgba(20, 24, 31, 0.28);
  height: 1px;
}

.equity-host {
  height: min(32vh, 320px);
  margin: 0 0.25rem 0.45rem;
}

.backtest-note {
  margin: 0;
  padding: 0 0.85rem 0.7rem;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.45;
}

.backtest-history-panel {
  margin-top: 1rem;
}

.backtest-history-head,
.backtest-history-row {
  display: grid;
  grid-template-columns: minmax(6.5rem, 1.2fr) minmax(4.5rem, 0.8fr) minmax(3rem, 0.55fr) minmax(3rem, 0.55fr) minmax(4rem, 0.7fr) minmax(4.5rem, 0.85fr) minmax(3.5rem, 0.65fr);
  gap: 0.55rem;
  align-items: center;
  padding: 0.45rem 0.85rem;
  font-variant-numeric: tabular-nums;
}

.backtest-history-head {
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.backtest-history-list {
  max-height: min(22rem, 42vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.35rem 0.2rem 0.45rem;
}

.backtest-history-row {
  width: calc(100% - 0.9rem);
  margin: 0 0.45rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease;
}

.backtest-history-row:nth-child(even) {
  background: rgba(15, 23, 36, 0.025);
}

.backtest-history-row:hover,
.backtest-history-row.is-on {
  background: var(--accent-soft);
}

.backtest-history-row.is-on {
  box-shadow: inset 3px 0 0 var(--accent);
}

.backtest-history-row .is-pass {
  color: var(--up);
}

.backtest-history-row .is-fail {
  color: var(--down);
}

.backtest-history-empty {
  margin: 0;
  padding: 1rem 0.85rem;
  color: var(--muted);
  font-size: 0.72rem;
}

@media (max-width: 760px) {
  .backtest-history-head {
    display: none;
  }

  .backtest-history-row {
    grid-template-columns: 1fr 1fr;
    gap: 0.25rem 0.75rem;
    padding: 0.65rem 0.85rem;
  }

  .backtest-history-row span:nth-child(1) {
    grid-column: 1 / -1;
    color: var(--muted);
    font-size: 0.68rem;
  }
}

.log-panel {
  display: flex;
  flex-direction: column;
  height: clamp(20rem, 42vh, 25rem);
  max-height: calc(100dvh - 2rem);
  min-height: 0;
  overflow: hidden;
  margin-top: 1rem;
}

.log-body {
  flex: 1 1 0;
  height: auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding: 0.55rem 0.75rem 0.75rem;
  font-size: 0.7rem;
  line-height: 1.45;
  background:
    linear-gradient(180deg, rgba(15, 23, 36, 0.03) 0%, rgba(15, 23, 36, 0.015) 100%);
}

.log-row {
  display: grid;
  grid-template-columns: 4.2rem 3.6rem 1fr;
  gap: 0.4rem;
  padding: 0.28rem 0.45rem;
  margin-bottom: 0.15rem;
  border: 0;
  border-radius: var(--radius-sm);
  transition: background 0.12s ease;
}

.log-row:hover {
  background: rgba(37, 99, 235, 0.06);
}

.log-row .msg {
  min-width: 0;
  overflow-wrap: anywhere;
}

.log-body::-webkit-scrollbar,
.order-result::-webkit-scrollbar,
.order-history-list::-webkit-scrollbar,
.backtest-history-list::-webkit-scrollbar {
  width: 6px;
}

.log-body::-webkit-scrollbar-thumb,
.order-result::-webkit-scrollbar-thumb,
.order-history-list::-webkit-scrollbar-thumb,
.backtest-history-list::-webkit-scrollbar-thumb {
  border: 0;
  border-radius: 999px;
  background: rgba(15, 23, 36, 0.18);
}

.log-row time,
.log-row .lvl {
  color: var(--muted);
}

.log-row.is-signal .lvl {
  color: var(--accent);
}

.log-row.is-order .lvl {
  color: var(--up);
}

.log-row.is-warn .lvl {
  color: #b7791f;
}

.log-row.is-error .lvl {
  color: var(--down);
}

.footnote {
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 0.75rem;
}

@media (min-width: 1280px) {
  .chart-host {
    height: min(72vh, 640px);
  }

  .log-panel {
    height: clamp(22rem, 38vh, 28rem);
  }

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

  .metric-grid > .metric:nth-child(3n) {
    border-right: 1px solid var(--line);
  }

  .metric-grid > .metric:nth-child(6n) {
    border-right: 0;
  }

  .metric-grid > .metric:nth-last-child(-n + 3) {
    border-bottom: 1px solid var(--line);
  }

  .metric-grid > .metric:nth-last-child(-n + 6) {
    border-bottom: 0;
  }
}

@media (max-width: 1020px) {
  .log-panel {
    height: 19rem;
  }
}

@media (max-width: 960px) {
  .trade-grid {
    grid-template-columns: 1fr;
  }

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

  .order-panel {
    position: static;
    height: auto;
  }

  .chart-host {
    height: 320px;
  }

  .chart-legend {
    display: none;
  }

  .chart-head {
    grid-template-columns: 1fr;
  }

  .chart-tools {
    justify-content: flex-start;
  }
}

@media (max-width: 720px) {
  :root {
    --layout-gutter: 0.75rem;
  }

  .stage {
    padding-top: 1.25rem;
  }

  .top {
    grid-template-columns: 1fr auto;
    gap: 0.85rem 1rem;
    padding: 1rem var(--layout-gutter);
  }

  .top-nav {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
    justify-self: stretch;
    border-top: none;
    padding-top: 0;
    margin-top: 0.15rem;
  }

  .nav-item {
    flex: 1;
    min-height: 2.25rem;
  }

  .nav-item::after {
    display: none;
  }

  .hero-line h1 {
    font-size: 1.75rem;
  }

  .workspace-heading {
    align-items: flex-start;
  }

  .workspace-heading h1 {
    font-size: 1.75rem;
  }

  .workspace-kicker {
    display: none;
  }

  .meta #auth-label {
    display: none;
  }

  .model-chip {
    max-width: 11rem;
  }

  .model-chip-label,
  .model-chip-sep,
  #model-trained {
    display: none;
  }

  .chart-summary {
    align-items: flex-start;
    justify-content: space-between;
  }

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

  .backtest-controls .run-backtest {
    grid-column: 1 / -1;
  }

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

  .metric-grid > .metric:nth-child(3n) {
    border-right: 1px solid var(--line);
  }

  .metric-grid > .metric:nth-child(even) {
    border-right: 0;
  }

  .metric-grid > .metric:nth-last-child(-n + 3) {
    border-bottom: 1px solid var(--line);
  }

  .metric-grid > .metric:nth-last-child(-n + 2) {
    border-bottom: 0;
  }

  .log-row {
    grid-template-columns: 3.8rem 1fr;
  }

  .log-row .lvl {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .dot.is-live {
    animation: none;
  }
}

/* Compact workstation layout */
:root {
  --ink: #18202c;
  --muted: #697386;
  --line: #e2e6ec;
  --line-strong: #cbd2dc;
  --panel: #ffffff;
  --surface: #f6f7f9;
  --layout-max: 1920px;
  --layout-gutter: 0.75rem;
  --radius: 6px;
  --radius-lg: 8px;
  --radius-xl: 8px;
  --panel-shadow: 0 1px 2px rgba(24, 32, 44, 0.04);
  --display: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html,
body {
  background: #eef1f4;
}

.atmosphere {
  display: none;
}

.top {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 3.5rem;
  padding: 0.65rem var(--layout-gutter);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
  box-shadow: none;
}

.brand-mark {
  font-size: 1.05rem;
}

.brand-sub {
  font-size: 0.7rem;
}

.top-nav,
.chips,
.mode-row,
.dir-row {
  border-color: var(--line);
  background: #f4f6f8;
  box-shadow: none;
}

.top-nav {
  padding: 0.18rem;
  border-radius: var(--radius);
}

.nav-item {
  min-width: 5.5rem;
  padding: 0.42rem 0.85rem;
  border-radius: 4px;
}

.nav-item.is-on,
.chip.is-on,
.submit-btn,
.run-backtest {
  background: #18263d;
  box-shadow: none;
}

.meta {
  gap: 0.55rem;
  font-size: 0.72rem;
}

.stage {
  padding: 0.85rem 0 2rem;
}

.hero-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 3.7rem;
  gap: 1rem;
  margin-bottom: 0.75rem;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: #fff;
}

.hero-copy {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

.hero-title-row {
  flex-wrap: nowrap;
  gap: 0.75rem;
}

.hero-line h1 {
  font-size: 1.25rem;
  white-space: nowrap;
}

.hero-line p {
  margin: 0;
  font-size: 0.7rem;
}

.hero-title-row .chips {
  padding-top: 0.18rem;
}

.market-status {
  max-width: 38rem;
  text-align: right;
  line-height: 1.35;
}

.trade-grid {
  grid-template-columns: minmax(0, 1fr) 22rem;
  align-items: stretch;
  gap: 0.75rem;
  margin-top: 0;
}

.chart-panel,
.order-panel,
.backtest-panel,
.log-panel,
.order-history-panel {
  border-color: var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  backdrop-filter: none;
  box-shadow: var(--panel-shadow);
}

.chart-head,
.order-head,
.panel-head {
  background: #fafbfc;
}

.chart-head {
  min-height: 3.65rem;
  padding: 0.65rem 0.8rem;
}

.chart-panel {
  display: flex;
  flex-direction: column;
}

.chart-host {
  flex: 1 1 auto;
  height: clamp(400px, calc(100dvh - 20rem), 440px);
  padding: 0.15rem 0.25rem 0.25rem;
}

.order-panel {
  position: sticky;
  top: 4.35rem;
  height: 100%;
}

.order-head {
  padding: 0.7rem 0.8rem;
}

.runtime-status {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.runtime-status-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  min-height: 2.8rem;
  padding: 0.45rem 0.7rem;
  border-right: 1px solid var(--line);
}

.runtime-status-item:last-child {
  border-right: 0;
}

.runtime-status-item.is-current {
  background: #f3f6fa;
  box-shadow: inset 3px 0 0 var(--accent);
}

.runtime-status-item[data-mode="live"].is-current {
  background: rgba(224, 69, 56, 0.05);
  box-shadow: inset 3px 0 0 var(--down);
}

.runtime-mode {
  min-width: 0;
  color: var(--muted);
  font-size: 0.64rem;
  white-space: nowrap;
}

.runtime-current {
  margin-left: 0.2rem;
  color: var(--accent);
  font-size: 0.58rem;
  font-weight: 600;
  visibility: hidden;
}

[data-mode="live"] .runtime-current {
  color: var(--down);
}

.runtime-status-item.is-current .runtime-current {
  visibility: visible;
}

.runtime-value {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--muted);
  font-size: 0.65rem;
  white-space: nowrap;
}

.runtime-state-dot {
  width: 0.42rem;
  height: 0.42rem;
  border-radius: 50%;
  background: #aeb6c2;
}

.runtime-status-item[data-state="on"] .runtime-value {
  color: var(--up);
}

.runtime-status-item[data-state="on"] .runtime-state-dot {
  background: var(--up);
}

.runtime-status-item[data-mode="live"][data-state="on"] .runtime-value {
  color: var(--down);
}

.runtime-status-item[data-mode="live"][data-state="on"] .runtime-state-dot {
  background: var(--down);
}

.runtime-status-item[data-state="unknown"] .runtime-value {
  color: #9a6919;
}

.runtime-status-item[data-state="unknown"] .runtime-state-dot {
  background: #b7791f;
}

.order-form {
  gap: 0.65rem;
  padding: 0.75rem 0.8rem 0.8rem;
}

.order-actions {
  grid-template-columns: minmax(7rem, 0.7fr) minmax(9rem, 1.3fr);
  align-items: end;
  gap: 0.65rem;
}

.auto-row {
  min-height: 2.5rem;
}

.paper-panel {
  flex: 1 1 auto;
  margin-top: 0;
  padding: 0.7rem 0.8rem 0.8rem;
  background: #fafbfc;
}

.paper-metrics {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.paper-metrics .metric {
  min-width: 0;
  padding: 0.5rem;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: #fff;
}

.paper-metrics .metric:last-child {
  border-right: 0;
}

.paper-metrics .metric strong {
  overflow: hidden;
  text-overflow: ellipsis;
}

.activity-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(20rem, 0.85fr);
  align-items: stretch;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.history-grid {
  display: grid;
  grid-template-columns: 1fr;
  align-items: stretch;
  height: 500px;
  gap: 0.75rem;
  margin-top: 0;
}

.order-history-list {
  max-height: 11.5rem;
}

.log-panel {
  height: 500px;
  max-height: none;
  margin-top: 0;
}

.log-body {
  min-height: 18rem;
  background: #fbfcfd;
}

.workspace-heading {
  margin-bottom: 0.75rem;
  padding: 0.2rem 0;
}

.workspace-heading h1 {
  font-size: 1.45rem;
}

.workspace-heading p {
  margin-top: 0.3rem;
}

.workspace-kicker {
  border-radius: var(--radius-sm);
  background: #fff;
}

.backtest-history-panel {
  margin-top: 0.75rem;
}

@media (max-width: 1180px) {
  .activity-grid {
    grid-template-columns: 1fr;
  }

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

}

@media (max-width: 960px) {
  .trade-grid {
    grid-template-columns: 1fr;
  }

  .order-panel {
    position: static;
    height: auto;
  }

  .paper-panel {
    flex: none;
  }

  .paper-metrics {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .chart-host {
    height: 420px;
  }
}

@media (max-width: 760px) {
  .history-grid {
    grid-template-columns: 1fr;
  }

  .hero-line,
  .hero-copy {
    align-items: flex-start;
  }

  .hero-line {
    flex-direction: column;
    gap: 0.4rem;
  }

  .hero-copy {
    width: 100%;
    justify-content: space-between;
  }

  .hero-copy > p {
    display: none;
  }

  .market-status {
    max-width: none;
    text-align: left;
  }
}

@media (max-width: 720px) {
  .top {
    padding-block: 0.65rem;
  }

  .stage {
    padding-top: 0.65rem;
  }

  .hero-line h1,
  .workspace-heading h1 {
    font-size: 1.2rem;
  }

  .chart-host {
    height: 360px;
  }

  .chart-summary {
    align-items: center;
  }

  .order-actions {
    grid-template-columns: 1fr;
  }

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

  .paper-metrics .metric:nth-child(2) {
    border-right: 0;
  }

  .paper-metrics .metric:nth-child(-n + 2) {
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 420px) {
  .meta #clock,
  .meta #ws-label {
    display: none;
  }

  .hero-title-row {
    width: 100%;
    justify-content: space-between;
  }

  .chart-head {
    gap: 0.5rem;
  }

  .chart-tools .chips {
    width: 100%;
  }

  .chart-tools .chip {
    flex: 1;
    padding-inline: 0.35rem;
  }
}

.toast-host {
  position: fixed;
  top: 1rem;
  left: 50%;
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  width: min(26rem, calc(100vw - 1.5rem));
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 28px rgba(15, 23, 36, 0.14);
  color: var(--ink);
  font-size: 0.78rem;
  line-height: 1.4;
  opacity: 0;
  transform: translateY(-0.4rem);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.is-in {
  opacity: 1;
  transform: translateY(0);
}

.toast.is-out {
  opacity: 0;
  transform: translateY(-0.25rem);
}

.toast.is-warn {
  border-color: rgba(183, 121, 31, 0.28);
  background: #fff8eb;
}

.toast.is-error {
  border-color: rgba(224, 69, 56, 0.28);
  background: #fff1ef;
  color: #9f2d24;
}
