:root {
  --bg: #07111b;
  --surface: #0b1824;
  --surface-2: #0e1d2a;
  --surface-3: #122332;
  --border: #263746;
  --border-soft: #1d2d3b;
  --text: #f2f5f8;
  --muted: #8c9aaa;
  --muted-2: #617184;
  --violet: #7657f6;
  --violet-hi: #8b72ff;
  --violet-soft: rgba(118, 87, 246, 0.18);
  --green: #2ed6a1;
  --green-soft: rgba(46, 214, 161, 0.14);
  --red: #ff4f58;
  --red-soft: rgba(255, 79, 88, 0.13);
  --blue: #5c92ff;
  --orange: #ff9418;
  --radius: 8px;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
  --sans: Inter, "IBM Plex Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  font-family: var(--sans);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 320px; scrollbar-gutter: stable; background: var(--bg); }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
body.sheet-open { overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
button, select, input[type="range"] { cursor: pointer; }
button { border: 0; }
button:disabled { cursor: not-allowed; opacity: 0.5; }
button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible {
  outline: 2px solid var(--violet-hi);
  outline-offset: 2px;
}
.hidden { display: none !important; }
.positive { color: var(--green) !important; }
.negative { color: var(--red) !important; }

.studio-shell { min-height: 100vh; }

.topbar {
  height: 60px;
  display: grid;
  grid-template-columns: 230px minmax(390px, 1fr) auto;
  align-items: stretch;
  gap: 8px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  background: #06101a;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.035em;
  text-decoration: none;
}
.brand img { width: 38px; height: 38px; object-fit: contain; filter: drop-shadow(0 0 10px rgba(91, 156, 203, 0.22)); }

.main-nav { display: flex; align-items: stretch; gap: 12px; }
.nav-item {
  position: relative;
  min-width: 90px;
  padding: 2px 7px 0;
  color: var(--text);
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}
.nav-item::after {
  content: "";
  position: absolute;
  left: 7px;
  right: 7px;
  bottom: 3px;
  height: 3px;
  border-radius: 3px;
  background: transparent;
}
.nav-item:hover { color: #cfc5ff; }
.nav-item.active { color: #d4caff; }
.nav-item.active::after { background: var(--violet); }

.broker-controls { display: flex; align-items: center; gap: 10px; }
.broker-status {
  height: 40px;
  min-width: 228px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 12px;
  font-weight: 500;
}
.broker-status .fa-chevron-down { margin-left: auto; color: var(--muted); font-size: 9px; }
.status-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--green); box-shadow: 0 0 12px rgba(46, 214, 161, 0.35); }
.status-dot.offline { background: var(--red); box-shadow: none; }

.environment-switch {
  height: 44px;
  width: 272px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.environment {
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.045em;
}
.environment.active { background: var(--violet); box-shadow: 0 4px 15px rgba(118, 87, 246, 0.28); }
.environment.live-active { background: var(--red); box-shadow: 0 4px 15px rgba(255, 79, 88, 0.26); }

.icon-button {
  width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}
.icon-button:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }
.icon-button.active-filter { color: var(--violet-hi); background: var(--violet-soft); }
.info-button { width: 22px; }

.page-content {
  display: grid;
  grid-template-rows: minmax(0, 568px) minmax(250px, 285px);
  gap: 8px;
  padding: 8px;
  min-width: 0;
}

.page-content.coming-soon-page {
  grid-template-rows: 1fr;
  min-height: calc(100vh - 60px);
  align-items: center;
  justify-items: center;
}

.coming-soon {
  width: min(520px, 100%);
  padding: 48px 40px;
  text-align: center;
}

.coming-soon-eyebrow {
  margin: 0 0 10px;
  color: var(--violet-hi);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.coming-soon h1 {
  margin: 0 0 12px;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.coming-soon-copy {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

a.nav-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.setup-form {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 16px 22px;
  padding: 10px 14px 12px;
}
.setup-form .field { flex: 1 1 120px; }
.setup-form .date-field { flex: 1 1 240px; }
.setup-form .strategy-field { flex: 2 1 240px; }
.setup-form .primary-button { flex: 0 0 auto; margin-left: auto; }
.field { display: grid; gap: 6px; min-width: 0; color: var(--muted); font-size: 11px; }
/* Strategy select + Params button share one row under the label */
.strategy-field { grid-template-columns: minmax(0, 1fr) auto; align-items: end; column-gap: 6px; }
.strategy-field > span { grid-column: 1 / -1; }
.inline-settings {
  height: 37px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background-color: #0a1621;
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.inline-settings:hover { border-color: var(--violet); color: var(--violet); }
.field > span { padding-left: 1px; }
.field select, .field input {
  width: 100%;
  height: 37px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background-color: #0a1621;
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
}
.date-time-group { display: grid; grid-template-columns: 1.2fr 0.8fr; }
.date-time-group input { border-radius: 0; }
.date-time-group input:first-child { border-radius: 6px 0 0 6px; }
.date-time-group input:last-child { margin-left: -1px; border-radius: 0 6px 6px 0; }
.primary-button {
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 1px;
  border-radius: 6px;
  background: var(--violet);
  color: white;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(118, 87, 246, 0.2);
}
.primary-button:hover { background: var(--violet-hi); }

.notice {
  position: fixed;
  top: 68px;
  left: 50%;
  z-index: 50;
  transform: translateX(-50%);
  max-width: 560px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #102234;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.42);
  font-size: 12px;
}
.notice.error { color: #ffd7da; border-color: rgba(255, 79, 88, 0.5); }

.studio-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 314px;
  gap: 10px;
  min-width: 0;
  min-height: 0;
}
.studio-left { display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 8px; min-width: 0; min-height: 0; }

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(2, 8, 15, 0.62);
  backdrop-filter: blur(2px);
}
.settings-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 61;
  width: min(430px, calc(100vw - 24px));
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  padding: 18px;
  border-radius: 0;
  transform: translateX(105%);
  visibility: hidden;
  transition: transform 180ms ease, visibility 180ms;
}
.settings-drawer.open {
  transform: translateX(0);
  visibility: visible;
}
.settings-drawer > header,
.settings-drawer > footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.settings-drawer > header > div { min-width: 0; }
.settings-drawer > header .icon-button { flex: 0 0 auto; }
#strategySettingsHash {
  margin: 4px 0 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.settings-drawer > footer {
  justify-content: flex-end;
  flex-wrap: wrap;
}
.settings-drawer > footer button {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #0a1621;
  color: var(--text);
}
.settings-drawer > footer #applyStrategySettings {
  border-color: transparent;
  background: var(--violet);
}
.settings-groups {
  overflow-y: auto;
  margin: 12px -6px 8px 0;
  padding-right: 6px;
}
.settings-group {
  border-bottom: 1px solid var(--border);
}
.settings-group > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  list-style: none;
}
.settings-group > summary::-webkit-details-marker { display: none; }
.settings-group > summary::before {
  content: "›";
  margin-right: 8px;
  color: var(--muted);
  transform: rotate(0deg);
  transition: transform 120ms ease;
}
.settings-group[open] > summary::before { transform: rotate(90deg); }
.settings-group > summary span { flex: 1; }
.settings-group > summary small {
  min-width: 22px;
  padding: 2px 6px;
  border-radius: 10px;
  background: #132433;
  color: var(--muted);
  text-align: center;
}
.settings-group-fields { display: grid; gap: 9px; padding: 2px 0 14px; }
.strategy-field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 142px;
  align-items: center;
  gap: 6px 12px;
  color: var(--muted);
  font-size: 11px;
}
.strategy-field-row input,
.strategy-field-row select {
  width: 100%;
  min-width: 0;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #091621;
  color: var(--text);
}
.strategy-field-row.toggle input { width: 16px; height: 16px; justify-self: end; accent-color: var(--violet); }
.strategy-field-row > small { grid-column: 1 / -1; color: var(--muted); line-height: 1.35; }
.strategy-field-row [aria-invalid="true"] { border-color: var(--red); }

.chart-panel { display: grid; grid-template-rows: 35px 28px minmax(0, 1fr) 54px; }
.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 12px;
}
.instrument-title { display: flex; align-items: center; gap: 9px; min-width: 0; }
.instrument-title strong { font-size: 13px; font-weight: 500; white-space: nowrap; }
.ohlc { overflow: hidden; color: var(--green); font-family: var(--mono); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.chart-actions {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(7, 17, 27, 0.75);
}
.chart-actions .icon-button { width: 31px; height: 27px; }
.strategy-strip { display: flex; align-items: center; gap: 10px; padding: 0 12px; color: var(--muted); font-size: 11px; }
.strategy-strip .fa-ellipsis { margin-left: -3px; }
.chart-stage { position: relative; min-height: 0; background: #07131f; border-bottom: 1px solid var(--border); }
#replayChart { position: absolute; inset: 0; }
.chart-object-layers {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
}
.chart-object {
  position: absolute;
  box-sizing: border-box;
  pointer-events: none;
}
.chart-object-box { border: 1px solid var(--object-color, #34d399); }
.chart-object-segment {
  height: 0;
  border-top: 1px solid var(--object-color, #94a3b8);
}
.chart-object-label {
  max-width: 180px;
  transform: translate(5px, -50%);
  color: var(--object-color, #cbd5e1);
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1.2;
  white-space: nowrap;
  text-shadow: 0 1px 2px #07131f, 0 -1px 2px #07131f;
}
.chart-panel:fullscreen {
  width: 100vw;
  height: 100vh;
  border-radius: 0;
  grid-template-rows: 42px 32px minmax(0, 1fr) 58px;
  background: var(--surface);
}
.position-zones {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  overflow: hidden;
}
.position-zone {
  position: absolute;
  box-sizing: border-box;
  border-left: 1px solid transparent;
}
.position-zone.profit {
  background: rgba(38, 166, 154, 0.15);
  border-left-color: rgba(38, 166, 154, 0.55);
}
.position-zone.loss {
  background: rgba(239, 83, 88, 0.15);
  border-left-color: rgba(239, 83, 88, 0.55);
}
.position-zone-entry {
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  border-top: 1px solid rgba(196, 210, 224, 0.55);
  box-sizing: border-box;
}
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; z-index: 3; }

.replay-controls {
  display: grid;
  grid-template-columns: 82px 94px 82px 80px 105px minmax(130px, 1fr) 54px 126px;
  align-items: center;
  gap: 9px;
  padding: 8px 11px;
}
.control-button, .speed-control select {
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #0c1925;
  color: var(--text);
  font-size: 12px;
}
.control-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.control-button:hover, .control-button.active { border-color: rgba(139, 114, 255, 0.7); background: var(--violet-soft); }
.danger-control:hover { border-color: rgba(255, 79, 88, 0.6); background: var(--red-soft); }
.speed-control select { width: 100%; padding: 0 11px; }
.replay-state { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.violet-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--violet); box-shadow: 0 0 8px rgba(118, 87, 246, 0.45); }
#replayTimeline { width: 100%; min-width: 80px; accent-color: var(--violet); }
#progressPercent { color: #a78bfa; font-family: var(--mono); font-size: 15px; font-weight: 600; text-align: right; }
.replay-time { color: var(--muted); font-family: var(--mono); font-size: 10px; text-align: right; white-space: nowrap; }

.run-sidebar { display: grid; grid-template-rows: 202px minmax(0, 1fr); gap: 8px; min-height: 0; }
.panel-heading {
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
}
.panel-heading h2 { margin: 0; font-size: 12px; font-weight: 600; }
.stats-grid { height: calc(100% - 44px); display: grid; grid-template-columns: 1fr 1fr; }
.stats-grid > div { display: grid; align-content: center; gap: 8px; padding: 11px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.stats-grid > div:nth-child(even) { border-right: 0; }
.stats-grid > div:nth-child(n+3) { border-bottom: 0; }
.stats-grid span { color: var(--muted); font-size: 10px; }
.stats-grid strong { font-family: var(--mono); font-size: 20px; font-weight: 500; letter-spacing: -0.04em; }

.feed-panel { min-height: 0; }
.event-feed { height: calc(100% - 44px); margin: 0; padding: 7px 10px 9px; overflow: auto; list-style: none; }
.event-feed, .table-wrap { scrollbar-width: thin; scrollbar-color: #314657 transparent; }
.event-feed li {
  position: relative;
  display: grid;
  grid-template-columns: 55px 19px minmax(0, 1fr);
  gap: 6px;
  min-height: 43px;
  align-items: start;
}
.event-feed li:not(:last-child)::after { content: ""; position: absolute; left: 64px; top: 22px; bottom: -2px; width: 1px; background: #385060; }
.event-feed time { padding-top: 4px; color: var(--muted); font-family: var(--mono); font-size: 9px; }
.event-icon { position: relative; z-index: 1; width: 18px; height: 18px; display: grid; place-items: center; margin-top: 1px; border-radius: 50%; background: var(--surface); color: var(--green); font-size: 10px; }
.event-feed .order .event-icon { color: var(--blue); }
.event-feed .warning .event-icon { color: var(--orange); }
.event-feed p { display: grid; gap: 3px; margin: 0; min-width: 0; line-height: 1.15; }
.event-feed strong { overflow: hidden; font-size: 10px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.event-feed small { color: var(--muted); font-size: 9px; }

.results-grid { display: grid; grid-template-columns: 1.08fr 0.98fr; gap: 8px; min-width: 0; min-height: 0; }
.orders-panel, .equity-panel { min-height: 0; }
.table-wrap { height: calc(100% - 44px); padding: 0 10px 8px; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 9px; }
th, td { height: 33px; padding: 0 10px; border-bottom: 1px solid var(--border-soft); text-align: left; white-space: nowrap; }
th { position: sticky; top: 0; z-index: 1; background: #0b1824; color: var(--muted); font-size: 8px; font-weight: 500; }
td { font-family: var(--mono); color: #dfe6ed; }
tbody tr:hover { background: rgba(255, 255, 255, 0.02); }

.equity-panel { position: relative; display: grid; grid-template-rows: 44px 24px minmax(0, 1fr); }
.muted-icon { margin-right: auto; margin-left: -2px; color: var(--muted); font-size: 10px; }
.equity-legend { display: flex; align-items: center; gap: 16px; padding: 0 22px; color: var(--muted); font-size: 9px; }
.equity-legend span { display: inline-flex; align-items: center; gap: 6px; }
.equity-swatch, .drawdown-swatch { width: 8px; height: 8px; display: inline-block; background: var(--violet); }
.drawdown-swatch { background: var(--red); }
.equity-stage { position: relative; min-height: 0; padding: 0 6px 5px; }
#equityChart { width: 100%; height: 100%; display: block; }

@media (max-width: 1380px) {
  .topbar { grid-template-columns: 210px minmax(330px, 1fr) auto; }
  .broker-status { min-width: 190px; }
  .environment-switch { width: 210px; }
  .replay-controls { grid-template-columns: 72px 82px 72px 70px 94px minmax(100px, 1fr) 48px 108px; gap: 6px; }
  .page-content { grid-template-rows: auto auto; }
  .studio-main { grid-template-columns: 1fr; }
  .studio-left { min-height: 568px; }
  .run-sidebar { min-height: 320px; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
}

@media (max-width: 1180px) {
  .topbar { height: auto; min-height: 60px; grid-template-columns: 170px 1fr; }
  .main-nav { order: 3; grid-column: 1 / -1; height: 44px; }
  .broker-controls { justify-self: end; }
  .page-content { grid-template-rows: auto auto auto; }
  .chart-panel { min-height: 520px; }
  .results-grid { min-height: 500px; grid-template-columns: 1fr; }
  .orders-panel, .equity-panel { min-height: 250px; }
}

@media (max-width: 760px) {
  .topbar { grid-template-columns: 1fr; padding: 8px 12px; }
  .brand { justify-self: start; }
  .main-nav { width: 100%; overflow-x: auto; order: 2; }
  .nav-item { min-width: max-content; }
  .broker-controls { width: 100%; justify-self: stretch; display: grid; grid-template-columns: 1fr 1fr auto; }
  .broker-status { min-width: 0; }
  .environment-switch { width: auto; }
  .setup-form { gap: 10px; }
  .setup-form .field, .setup-form .date-field, .setup-form .strategy-field, .setup-form .primary-button { flex-basis: 100%; margin-left: 0; }
  .page-content { padding: 6px; }
  .studio-main { grid-template-columns: 1fr; }
  .settings-drawer { width: min(100vw, 430px); }
  .run-sidebar, .results-grid { grid-template-columns: 1fr; }
  .chart-panel { min-height: 540px; grid-template-rows: 35px 28px minmax(280px, 1fr) auto; }
  .replay-controls { grid-template-columns: repeat(4, 1fr); }
  .replay-state { grid-column: 1 / 2; }
  #replayTimeline { grid-column: 2 / -1; }
  .replay-time { grid-column: 2 / -1; }
  .ohlc { display: none; }
  .run-sidebar { min-height: 620px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.001ms !important; animation-duration: 0.001ms !important; }
}
