:root {
  color-scheme: dark;
  --bg: var(--app-bg, #09090b);
  --panel: var(--panel-bg, #101014);
  --panel-2: var(--panel-section, #141418);
  --surface: var(--panel-section, #141418);
  --field: var(--panel-field, #09090b);
  --ink: var(--panel-text, #fafafa);
  --muted: var(--panel-muted, #a1a1aa);
  --line: var(--panel-border, #27272a);
  --soft-line: rgba(161, 161, 170, 0.14);
  --green: #23b26d;
  --red: #ef5f5f;
  --blue: #4ea1ff;
  --amber: #f4b942;
  --shadow: none;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  min-width: 1120px;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
}

.app-shell {
  height: 100vh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: var(--header-bg, rgba(9, 9, 11, 0.92));
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  color: #f7fafc;
  font-size: 18px;
  font-weight: 760;
}

.brand-title {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.brand-title img {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  object-fit: cover;
}

h2 {
  color: #f7fafc;
  font-size: 13px;
  font-weight: 760;
}

.subtle {
  color: var(--muted);
  font-size: 12px;
}

.brand-block {
  display: grid;
  gap: 4px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.button,
.icon-button {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
  color: var(--ink);
  font-size: 17px;
  cursor: pointer;
}

.button {
  width: auto;
  padding: 0 11px;
  font-size: 12px;
  font-weight: 760;
}

.button.primary {
  border-color: #b88719;
  background: #f4b942;
  color: #12100a;
}

.button:disabled {
  cursor: default;
  opacity: 0.45;
}

.ticker-select,
.timeframe-select {
  min-width: 78px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 9px;
  outline: none;
  background: var(--field);
  color: var(--ink);
  font-size: 12px;
  font-weight: 680;
}

.ticker-select {
  min-width: 96px;
}

.nav-link {
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ink);
  background: var(--field);
  font-size: 12px;
  font-weight: 760;
  text-decoration: none;
}

.nav-link:hover,
.icon-button:hover {
  border-color: var(--control-ring, #3f3f46);
  background: var(--control-hover, #18181b);
}

.workspace {
  flex: 1;
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-columns: max-content minmax(620px, 1fr) 360px;
  gap: 12px;
  padding: 12px;
  overflow: hidden;
}

.bt-workspace {
  position: relative;
  grid-template-columns: 76px minmax(0, 1fr);
}

.bt-main-workspace {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(620px, 1fr) 360px;
  gap: 12px;
}

.bt-sidebar,
.chart-column,
.detail-panel {
  min-width: 0;
  background: rgba(11, 16, 23, 0.98);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.bt-sidebar {
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.sidebar-head {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 12px;
  border-bottom: 1px solid var(--soft-line);
  background: var(--surface);
}

.sidebar-actions {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.strategy-list {
  min-height: 0;
  overflow: auto;
  padding: 8px;
}

.strategy-row {
  width: 100%;
  min-height: 58px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.strategy-row:hover {
  border-color: var(--control-ring, #3f3f46);
  background: var(--control-hover, #18181b);
}

.strategy-row.active {
  border-color: rgba(244, 185, 66, 0.72);
  background: rgba(244, 185, 66, 0.1);
  box-shadow: inset 3px 0 0 var(--amber);
}

.strategy-row.invalid {
  opacity: 0.52;
}

.strategy-row-main {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.strategy-name {
  overflow: hidden;
  color: #f7fafc;
  font-size: 13px;
  font-weight: 760;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.strategy-meta {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.strategy-row-side {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
}

.valid-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  display: inline-block;
  background: var(--green);
}

.valid-dot.invalid {
  background: var(--red);
}

.chart-column {
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--soft-line);
  background: var(--surface);
}

.chart-stage {
  position: relative;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: minmax(0, 1fr) 136px;
}

.chart-controls {
  position: absolute;
  top: 10px;
  right: 66px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chart-controls .ticker-picker {
  width: min(300px, 42vw);
}

.legend {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: 12px;
}

.legend span,
#indicatorLegend {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.marker-legend {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

#indicatorLegend {
  flex-wrap: wrap;
  gap: 10px;
}

.legend-toggle {
  height: 24px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 0 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
}

.legend-toggle.active {
  color: var(--ink);
}

.legend-toggle:not(.active) {
  opacity: 0.42;
}

.legend-toggle:hover {
  border-color: var(--line);
  background: var(--field);
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

.swatch.candle {
  background: var(--green);
}

.swatch.sma {
  background: var(--amber);
}

.swatch.nav {
  background: var(--blue);
}

.swatch.marker.entry {
  width: 0;
  height: 0;
  border-radius: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 10px solid var(--green);
  background: transparent;
}

.swatch.marker.exit {
  width: 0;
  height: 0;
  border-radius: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 10px solid var(--red);
  background: transparent;
}

.swatch.marker.trigger {
  border-radius: 50%;
  background: #a78bfa;
}

.swatch.marker.risk {
  background: #fb7185;
}

.swatch.marker.fill {
  border-radius: 50%;
  background: var(--blue);
}

.price-chart,
.nav-chart {
  width: 100%;
  height: 100%;
  min-height: 0;
  min-width: 0;
  background: #080d14;
}

.nav-chart {
  border-top: 1px solid var(--soft-line);
}

.chart-menu {
  position: absolute;
  z-index: 30;
  min-width: 176px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--field);
}

.chart-menu[hidden] {
  display: none;
}

.chart-menu button {
  width: 100%;
  height: 30px;
  display: flex;
  align-items: center;
  border: 0;
  border-radius: 3px;
  padding: 0 9px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-size: 12px;
  text-align: left;
}

.chart-menu button:hover {
  background: #192435;
}

.detail-panel {
  min-height: 0;
  height: 100%;
  overflow: auto;
}

.detail-panel .collapse-section {
  border-bottom-color: var(--soft-line);
}

.detail-panel .collapse-body {
  overflow: visible;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.setting-field,
.setting-readout {
  min-height: 48px;
  display: grid;
  align-content: center;
  gap: 5px;
  padding: 8px;
  border: 1px solid var(--soft-line);
  border-radius: 4px;
  background: var(--surface);
}

.setting-field span,
.setting-readout span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 680;
}

.setting-field .control {
  width: 100%;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 7px;
  background: var(--field);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
}

.setting-readout strong {
  min-width: 0;
  overflow: hidden;
  color: #f7fafc;
  font-size: 13px;
  font-weight: 760;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-content: start;
  gap: 8px;
  overflow: visible;
  padding-right: 4px;
}

.bt-metrics-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 0;
  border-bottom: 0;
  background: transparent;
}

.bt-metrics-grid .metric-card {
  min-height: 56px;
}

.metric {
  min-height: 48px;
  padding: 8px;
  border: 1px solid var(--soft-line);
  border-radius: 4px;
  background: var(--surface);
}

.metric .label {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 680;
}

.metric .value {
  display: block;
  margin-top: 4px;
  color: #f7fafc;
  font-size: 15px;
  font-weight: 760;
}

.event-list,
.file-list,
.operation-list {
  display: grid;
  align-content: start;
  gap: 7px;
  margin-top: 12px;
  overflow: visible;
  padding-right: 4px;
}

.event,
.operation {
  display: grid;
  grid-template-columns: 68px 1fr auto;
  gap: 8px;
  align-items: center;
  min-height: 38px;
  padding: 8px;
  border: 1px solid var(--soft-line);
  border-radius: 4px;
  background: var(--surface);
  font-size: 12px;
}

.event[data-chart-bar] {
  cursor: pointer;
}

.event[data-chart-bar]:hover,
.event.chart-active {
  border-color: #4ea1ff;
  background: #121c2a;
}

.operation {
  grid-template-columns: 78px minmax(0, 1fr);
}

.event .kind,
.operation .kind {
  color: var(--amber);
  font-weight: 760;
  text-transform: uppercase;
}

.event .meta,
.operation .meta {
  color: var(--muted);
}

.event.entry,
.event.buy {
  border-left: 3px solid var(--green);
}

.event.exit,
.event.sell {
  border-left: 3px solid var(--red);
}

.event.fill {
  border-left: 3px solid var(--blue);
}

.event.trigger,
.operation.trigger {
  border-left: 3px solid #a78bfa;
}

.event.risk,
.event.risk_control,
.operation.risk {
  border-left: 3px solid #fb7185;
}

.operation.feature,
.operation.latent {
  border-left: 3px solid var(--amber);
}

.operation.account,
.operation.state {
  border-left: 3px solid #22d3c5;
}

.operation.execution,
.operation.policy {
  border-left: 3px solid var(--blue);
}

.compact .event {
  grid-template-columns: 54px 1fr;
}

.file-list {
  grid-template-columns: 78px 1fr;
  gap: 8px 10px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.file-list dt {
  color: #f7fafc;
  font-weight: 760;
}

.file-list dd {
  margin: 0;
  word-break: break-all;
}

@media (max-width: 1180px) {
  body {
    min-width: 0;
    height: auto;
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .workspace {
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .bt-workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .bt-main-workspace {
    grid-column: 1;
    grid-row: auto;
    grid-template-columns: minmax(0, 1fr);
    overflow: visible;
  }

  .bt-sidebar,
  .detail-panel,
  .chart-column {
    height: auto;
    min-height: auto;
  }

  .bt-sidebar {
    max-height: 320px;
  }

  .chart-column {
    grid-template-rows: auto 720px;
  }

  .detail-panel {
    display: block;
    overflow: visible;
  }

  .detail-panel .collapse-section {
    display: grid;
    overflow: visible;
  }

  .event-list,
  .operation-list {
    max-height: 260px;
  }
}

@media (max-width: 640px) {
  .topbar {
    height: auto;
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 10px 12px;
  }

  .toolbar {
    width: 100%;
    flex-wrap: wrap;
  }

  .toolbar > * {
    flex: 0 0 auto;
  }

  .workspace {
    padding: 10px;
  }

  .chart-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .legend {
    flex-wrap: wrap;
    gap: 10px;
  }

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

  .event {
    grid-template-columns: 58px minmax(0, 1fr);
  }

  .event > .meta:last-child {
    grid-column: 2;
  }
}
