:root {
  color-scheme: dark;
  font-family: Inter, system-ui, sans-serif;
  background: #090e15;
  color: #edf2fa;
  --chart-bg: #090e15;
  --chart-grid: #17202d;
  --chart-text: #aab5c5;
  --chart-up: #26a69a;
  --chart-down: #ef5350;
  --chart-sma5: #4da3ff;
  --chart-sma10: #34d399;
  --chart-sma20: #f0b90b;
  --chart-sma60: #ff8a3d;
  --chart-vwap: #bb86fc;
  --chart-overlay: #f0b90b;
}
* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; }
body { overflow: hidden; }
main {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  overflow: hidden;
}
.setup, .controls, .chart-toolbar, .chart-legend, .trade-sidebar, .trading-console-details { background: #101722; border-color: #253247; }
.setup, .controls { padding: 12px 18px; display: flex; align-items: center; gap: 12px; }
.pill { border: 1px solid #3a4960; padding: 4px 8px; border-radius: 999px; font-size: 11px; }
.setup { border-bottom: 1px solid #253247; min-width: 0; }
.setup label { display: grid; gap: 4px; font-size: 11px; color: #8796aa; flex: 0 0 auto; }
.setup input, .setup select, .trade-entry input { background: #0a111b; color: #edf2fa; border: 1px solid #35455d; border-radius: 6px; padding: 7px; }
.setup > span { font-size: 11px; color: #748297; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-status { margin-left: auto; display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex: 0 0 auto; padding-left: 14px; border-left: 1px solid #253247; }
.session-status b { font-size: 12px; }
.session-status span:not(.pill) { color: #8d9bad; font-size: 11px; }
button { background: #172233; color: #edf2fa; border: 1px solid #35455d; border-radius: 7px; padding: 8px 12px; cursor: pointer; }
button.primary, button.active { background: #255ddd; border-color: #4879e8; }
button.buy { background: #123d31; border-color: #237a60; color: #b9f5df; }
button.sell { background: #4a2027; border-color: #8b3948; color: #ffd0d7; }
button.armed { color: #f0b90b; border-color: #f0b90b; box-shadow: 0 0 0 1px rgba(240,185,11,.2) inset; }
button:disabled { opacity: .4; cursor: default; }
.workspace {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 0;
  grid-template-rows: auto auto minmax(0, 1fr);
  grid-template-areas:
    "toolbar toolbar"
    "legend legend"
    "plot sidebar";
  overflow: hidden;
  background: #090e15;
  transition: grid-template-columns .18s ease;
}
.workspace.trades-open { grid-template-columns: minmax(0, 1fr) minmax(340px, 400px); }
.chart-toolbar { grid-area: toolbar; position: relative; z-index: 2; }
.chart-legend { grid-area: legend; position: relative; z-index: 2; }
.plot-area { grid-area: plot; min-width: 0; min-height: 0; overflow: hidden; background: #090e15; }
.chart-toolbar {
  min-width: 0;
  padding: 4px 8px;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  border-bottom: 1px solid #253247;
}
.chart-toolbar::-webkit-scrollbar { display: none; }
.tool-group { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; white-space: nowrap; }
.tool-group span { margin-right: 2px; color: #748297; font-size: 10px; line-height: 1; text-transform: uppercase; letter-spacing: .08em; }
.chart-toolbar button { padding: 4px 7px; border-radius: 5px; font-size: 11px; line-height: 1.2; }
.indicator-pick { display: flex; align-items: center; gap: 2px; }
.fv-context-menu { position: fixed; z-index: 1000; min-width: 168px; background: #172233; border: 1px solid #35455d; border-radius: 6px; padding: 6px; display: flex; flex-direction: column; gap: 3px; box-shadow: 0 6px 20px rgba(0,0,0,.4); }
.fv-menu-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 3px 6px; font-size: 11px; color: #aab5c5; }
.fv-menu-row select { background: #0a111b; color: #edf2fa; border: 1px solid #35455d; border-radius: 4px; padding: 2px 4px; font-size: 11px; }
.fv-menu-row input[type="checkbox"] { cursor: pointer; }
.fv-menu-divider { height: 1px; background: #253247; margin: 3px 2px; }
.fv-color-swatch { width: 20px; height: 20px; padding: 0; border: 1px solid #35455d; border-radius: 4px; cursor: pointer; }
.fv-color-swatch:hover { border-color: #5b6b85; }
.fv-color-popup { position: fixed; z-index: 1001; display: grid; grid-template-columns: repeat(6, 20px); gap: 6px; background: #172233; border: 1px solid #35455d; border-radius: 6px; padding: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.4); }
.fv-color-swatch-item { width: 20px; height: 20px; padding: 0; border: 1px solid #35455d; border-radius: 4px; cursor: pointer; }
.fv-color-swatch-item:hover { border-color: #5b6b85; transform: scale(1.08); }
.fv-color-swatch-item.selected { border-color: #edf2fa; border-width: 2px; }
.fv-color-swatch-item.fv-color-custom { background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); padding: 0; }
.fv-context-menu button.fv-menu-action { background: none; border: none; color: #edf2fa; text-align: left; padding: 6px 12px; font-size: 12px; border-radius: 4px; cursor: pointer; }
.fv-context-menu button.fv-menu-action:hover { background: #255ddd; }
.fv-text-editor { position: fixed; z-index: 1000; min-width: 60px; max-width: 260px; background: #101722; border: 1px solid; border-radius: 4px; padding: 3px 6px; font-size: 12px; color: #edf2fa; outline: none; transform: translate(-2px, -2px); }
.chart-legend { padding: 5px 14px; min-height: 25px; color: #aab5c5; border-bottom: 1px solid #1b2635; font: 11px/1.3 ui-monospace, SFMono-Regular, Consolas, monospace; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#chart { min-width: 0; min-height: 0; width: 100%; height: 100%; }
.trade-sidebar {
  grid-area: sidebar;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-left: 1px solid #253247;
  display: grid;
  grid-template-rows: 112px minmax(0, 1fr) 44px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease;
}
.workspace.trades-open .trade-sidebar { opacity: 1; pointer-events: auto; }
.trade-summary {
  height: 112px;
  min-height: 112px;
  max-height: 112px;
  overflow: hidden;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
  border-bottom: 1px solid #253247;
}
.trade-summary div { display: grid; gap: 1px; }
.trade-summary div:nth-last-child(2), .trade-summary div:last-child { padding-top: 4px; border-top: 1px solid #253247; }
.trade-summary span { color: #748297; font-size: 10px; text-transform: uppercase; letter-spacing: .05em; }
.trade-summary strong { font-size: 13px; font-variant-numeric: tabular-nums; }
.trade-table-wrap { min-height: 0; overflow: auto; }
.trade-table { width: 100%; border-collapse: collapse; font-size: 11px; font-variant-numeric: tabular-nums; }
.trade-table th { position: sticky; top: 0; z-index: 1; background: #101722; color: #748297; text-align: right; padding: 7px 8px; border-bottom: 1px solid #253247; }
.trade-table th:nth-child(1), .trade-table th:nth-child(2) { text-align: left; }
.trade-table td { padding: 7px 8px; border-bottom: 1px solid #1a2534; text-align: right; }
.trade-table td:nth-child(1), .trade-table td:nth-child(2) { text-align: left; }
.trade-table tr.trade-row { cursor: pointer; }
.trade-table tr.trade-row:hover, .trade-table tr.trade-row.selected { background: #172233; }
.trade-table .buy-text { color: #6fd6b5; }
.trade-table .sell-text { color: #ff8f9e; }
.trade-empty td { color: #748297; text-align: center !important; padding: 18px; }
.trade-ledger-toolbar {
  height: 44px;
  min-height: 44px;
  max-height: 44px;
  display: flex;
  flex: 0 0 44px;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  padding: 0 10px;
  overflow: hidden;
  border-top: 1px solid #253247;
}
.trade-ledger-toolbar button { padding: 6px 10px; font-size: 11px; }
.controls {
  border-top: 1px solid #253247;
  flex: 0 0 auto;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  flex-wrap: wrap;
  row-gap: 8px;
  white-space: nowrap;
  scrollbar-width: none;
  justify-content: space-between;
}
.controls::-webkit-scrollbar { display: none; }
.replay-controls, .transport, .speeds, .trade-entry {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  align-items: center;
  white-space: nowrap;
}
.replay-controls { flex: 0 0 auto; min-width: max-content; }
.transport, .speeds { flex: 0 0 auto; }
.speeds { margin-left: 6px; }
.trade-entry { margin-left: auto; flex: 0 0 auto; min-width: max-content; padding-left: 14px; border-left: 1px solid #253247; }
.speeds span, .trade-entry span { font-size: 11px; color: #8190a4; margin-right: 4px; }
#speed-slider {
  width: 110px;
  height: 4px;
  margin: 0;
  accent-color: #668fe8;
  cursor: pointer;
}
#speed-value {
  font-size: 11px;
  color: #edf2fa;
  min-width: 30px;
  text-align: right;
}
.trade-entry span:first-child { text-transform: uppercase; letter-spacing: .06em; color: #6f7f95; }
.trade-entry input { width: 58px; padding: 7px 6px; }
.trade-entry select { background: #0a111b; color: #edf2fa; border: 1px solid #35455d; border-radius: 6px; padding: 7px 6px; font: inherit; }
.trade-field { display: inline-flex; align-items: center; gap: 4px; }
.trade-field[hidden] { display: none; }
.trade-field > span { margin-right: 0; }
#trade-limit, #trade-stop, #trade-take-profit, #trade-stop-loss { width: 74px; }
.trade-bracket-check { gap: 5px; padding-left: 4px; }
.trade-bracket-check input[type="checkbox"] { width: 14px; height: 14px; accent-color: #668fe8; }
.auto-flatten-field { gap: 5px; padding-left: 4px; white-space: nowrap; }
.auto-flatten-field input[type="checkbox"] { width: 14px; height: 14px; accent-color: #668fe8; }
#trades-toggle[aria-pressed="true"], #console-toggle[aria-pressed="true"] { border-color: #668fe8; color: #b8cbff; }
.trade-table th:nth-child(3), .trade-table td:nth-child(3) { text-align: left; }
/* Working orders share the fills table but are not history: they sit on top,
   dimmed and rule-separated, and their last cell carries a cancel button
   instead of a realized P&L. */
.order-row { background: #141d2a; color: #aab5c5; }
.order-row:last-of-type td { border-bottom: 1px solid #35455d; }
.order-row .order-mark { color: #748297; }
.order-row.triggered .order-mark { color: #e6b25a; }
/* A bracket leg is one half of an OCO pair: filling it cancels its sibling. */
.order-row.bracket-leg .order-mark { color: #8fb3ff; }
.order-row .order-type, .order-row .order-price { white-space: nowrap; }
.order-row .order-price { text-align: right; }
.order-row td:last-child { padding-left: 0; width: 28px; }
.order-cancel {
  background: none;
  border: 1px solid #35455d;
  border-radius: 4px;
  color: #8190a4;
  cursor: pointer;
  font-size: 10px;
  line-height: 1;
  padding: 3px 5px;
}
.order-cancel:hover { border-color: #ff8f9e; color: #ff8f9e; }
.trading-console-details {
  min-height: 0;
  max-height: 160px;
  overflow: auto;
  border-top: 1px solid #253247;
}
.trading-console-details[hidden] { display: none; }
.trade-detail {
  min-height: 72px;
  max-height: 160px;
  overflow: auto;
  padding: 10px 18px;
  color: #9cacbd;
  font: 11px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
  white-space: pre-line;
}
#error { min-height: 24px; flex: 0 0 auto; background: #101722; color: #ff7e7e; padding: 4px 18px; font-size: 12px; }
.pnl-positive { color: #6fd6b5 !important; }
.pnl-negative { color: #ff8f9e !important; }
@media (max-width: 1100px) {
  .setup { flex-wrap: wrap; }
  .session-status { margin-left: 0; border-left: 0; padding-left: 0; width: 100%; justify-content: flex-start; }
  .workspace.trades-open { grid-template-columns: minmax(0, 1fr) minmax(300px, 340px); }
  .controls { gap: 8px; }
}
@media (max-width: 850px) {
  .setup { align-items: flex-start; overflow-x: auto; }
  .workspace.trades-open {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto minmax(0, 1fr) minmax(220px, 38vh);
    grid-template-areas:
      "toolbar"
      "legend"
      "plot"
      "sidebar";
  }
  .workspace.trades-open .trade-sidebar { border-left: 0; border-top: 1px solid #253247; }
  .controls { overflow-x: auto; }
  .replay-controls, .trade-entry { flex: 0 0 auto; }
}
