:root {
  color-scheme: light;
  --bg: #f3f6fa;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --line: #d8e1ee;
  --line-strong: #98a2b3;
  --muted: #667085;
  --text: #101828;
  --red: #d92d20;
  --blue: #1570ef;
  --green: #12b76a;
  --amber: #e6a817;
  --shadow: 0 10px 26px rgb(15 23 42 / 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
  overflow-x: hidden;
  overflow-y: auto;
}

.shell {
  width: min(1880px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  overflow: visible;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 2px 8px;
}

.eyebrow {
  display: none;
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1,
h2,
p,
dl,
dt,
dd {
  margin: 0;
}

h1 {
  font-size: 1.42rem;
  line-height: 1.08;
}

h2 {
  font-size: 1.02rem;
  line-height: 1.2;
}

.statusline {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 3px rgb(230 168 23 / 0.16);
}

.dot.live {
  background: var(--green);
  box-shadow: 0 0 0 3px rgb(18 183 106 / 0.18);
}

.dot.offline {
  background: var(--red);
  box-shadow: 0 0 0 3px rgb(217 45 32 / 0.16);
}

.toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.segmentedButtons {
  display: inline-flex;
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid #c7d1df;
  border-radius: 7px;
  background: #fff;
}

.segmentedButtons button {
  min-width: 58px;
  height: 30px;
  border: 0;
  border-right: 1px solid #c7d1df;
  background: transparent;
  color: #344054;
  cursor: pointer;
  font: 800 0.82rem "Segoe UI", system-ui, sans-serif;
}

.segmentedButtons button:last-child {
  border-right: 0;
}

.segmentedButtons button:hover {
  background: #eef4ff;
}

.segmentedButtons button.active {
  background: #111827;
  color: #fff;
}

.rangeButtons button {
  min-width: 46px;
}

.toolbarNote {
  display: none;
  min-width: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.simulationControls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.simulationControls button,
.positionCloseBtn {
  min-height: 30px;
  border: 1px solid #c7d1df;
  border-radius: 7px;
  background: #fff;
  color: #344054;
  cursor: pointer;
  font: 900 0.78rem "Segoe UI", system-ui, sans-serif;
}

.simulationControls button {
  padding: 0 10px;
}

#simulationOpenLong {
  color: var(--red);
  border-color: #f7c7c0;
}

#simulationOpenShort {
  color: var(--blue);
  border-color: #bdd7ff;
}

.simulationControls button:hover,
.positionCloseBtn:hover {
  background: #eef4ff;
}

.simulationControls button:disabled,
.positionCloseBtn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.simulationMode {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 9px;
  border-radius: 999px;
  background: #ecfdf3;
  color: var(--green);
  font-size: 0.76rem;
  font-weight: 900;
}

.simulationMode.stopped {
  background: #f2f4f7;
  color: var(--muted);
}

.chartGrid {
  flex: 0 0 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 0.96fr) minmax(390px, 430px);
  gap: 12px;
  align-items: start;
}

.coinPanel {
  min-width: 0;
  min-height: 0;
  height: auto;
  display: grid;
  grid-template-rows: auto 560px auto auto;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.indicatorPanel {
  border-color: #cfd8e6;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
  grid-template-rows: auto 320px;
  padding: 10px;
}

.indicatorPanel .priceChart {
  height: 320px;
}

.indicatorCaption {
  min-height: 20px;
  margin-bottom: 6px;
  color: #344054;
  font-size: 0.78rem;
  font-weight: 900;
  line-height: 1.2;
}

.indicatorPanel .coinHeader,
.indicatorPanel .positionHistory,
.indicatorPanel .coinFooter {
  display: none;
}

.tradingPanel {
  grid-template-rows: auto auto 520px auto auto;
}

.tradingPanel .priceChart {
  height: 520px;
}

.simulationBoard {
  min-width: 0;
  padding: 9px;
  border: 1px solid #cbdcf0;
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #f7fbff 100%);
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.08);
}

.simulationBoardHeader {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 6px;
  margin-bottom: 6px;
  border-bottom: 1px solid #d8e4f2;
}

.simulationBoardHeader strong {
  display: block;
  color: #0f172a;
  font-size: 0.86rem;
  line-height: 1.2;
}

.simulationBoardHeader p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.64rem;
  line-height: 1.2;
}

.simulationBoardHeader span {
  flex: 0 0 auto;
  padding: 3px 6px;
  border-radius: 999px;
  background: #eaf2ff;
  color: #175cd3;
  font-size: 0.62rem;
  font-weight: 900;
  white-space: nowrap;
}

.coinHeader {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  margin-bottom: 10px;
}

.tradingPanel .coinHeader {
  grid-template-columns: minmax(0, 1fr);
  margin-bottom: 6px;
}

.coinLabel {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  margin-bottom: 5px;
  padding: 0 8px;
  border: 1px solid #c7d1df;
  border-radius: 999px;
  background: #f8fafc;
  color: #344054;
  font-size: 0.75rem;
  font-weight: 900;
}

.chartMeta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
  height: 19px;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.coinStats {
  display: grid;
  grid-template-columns: minmax(145px, 0.9fr) minmax(112px, 0.7fr);
  gap: 6px;
  width: min(360px, 100%);
}

.tradingPanel .coinStats {
  display: none;
}

.coinStats div {
  min-width: 0;
  padding: 7px 9px;
  border: 1px solid #e4e7ec;
  border-radius: 7px;
  background: var(--panel-soft);
}

.coinStats dt {
  color: var(--muted);
  font-size: 0.72rem;
  white-space: nowrap;
}

.coinStats .primaryStat dt {
  line-height: 1.2;
  white-space: normal;
}

.coinStats > div:last-child {
  display: none;
  min-width: 0;
}

.coinStats dd {
  margin-top: 4px;
  font-size: 0.86rem;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.statBlock {
  display: grid;
  gap: 3px;
}

.statValue {
  display: block;
  color: inherit;
  font-size: 1.02rem;
  line-height: 1.08;
  font-variant-numeric: tabular-nums;
}

.statSub {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.positionLive {
  display: grid;
  gap: 3px;
  min-width: 0;
  font-size: 0.8rem;
  line-height: 1.16;
}

.positionCompact {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  width: 100%;
  white-space: nowrap;
}

.positionSide {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: max-content;
  min-width: 42px;
  height: 18px;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 0.66rem;
  font-weight: 900;
}

.positionSide.long {
  background: #fee4e2;
  color: var(--red);
}

.positionSide.short {
  background: #dbeafe;
  color: var(--blue);
}

.positionPnl {
  display: inline-flex;
  align-items: center;
  min-width: 102px;
  justify-content: flex-end;
  font-variant-numeric: tabular-nums;
}

.positionLine {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.positionMetrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 3px 6px;
  min-width: 0;
  max-width: 100%;
  color: #344054;
  font-size: 0.72rem;
  line-height: 1.2;
}

.positionMetrics span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.positionMetrics b {
  margin-right: 4px;
  color: var(--muted);
  font-weight: 800;
}

.positionStrip {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 4px;
  margin: -2px 0 6px;
  min-width: 0;
}

.positionSlot {
  min-width: 0;
  min-height: 44px;
  padding: 4px;
  border: 1px solid #d7e0ec;
  border-radius: 6px;
  background: #fbfcff;
}

.positionSlot.active {
  background: #fffdf7;
  border-color: #d9e2ef;
}

.positionSlotHead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  margin-bottom: 2px;
  min-width: 0;
}

.positionSlotHead strong {
  flex: 0 0 auto;
  color: #111827;
  font-size: 0.62rem;
  line-height: 1;
}

.positionSlotHead span {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.54rem;
  font-weight: 800;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.positionSlotBody {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.positionStripEmpty {
  color: var(--muted);
  font-size: 0.58rem;
  font-weight: 900;
}

.positionStrip .positionCompact {
  gap: 2px;
  overflow: hidden;
  font-size: 0.56rem;
  line-height: 1.05;
}

.positionStrip .positionSide {
  min-width: 28px;
  height: 14px;
  padding: 0 3px;
  font-size: 0.5rem;
}

.positionStrip .positionPnl {
  min-width: 48px;
  font-size: 0.55rem;
}

.positionStrip .positionMetrics {
  display: none;
}

.positionStrip .positionCloseBtn {
  min-height: 15px;
  padding: 0 4px;
  border-radius: 4px;
  font-size: 0.52rem;
}

.positionCloseBtn {
  min-height: 22px;
  padding: 0 7px;
  font-size: 0.68rem;
}

.markerLegend {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  align-items: center;
  position: absolute;
  z-index: 5;
  top: 3px;
  left: 5px;
  min-height: 0;
  padding: 1px 4px;
  border-radius: 4px;
  background: rgb(255 255 255 / 0.72);
  color: var(--muted);
  font-size: 0.58rem;
  font-weight: 700;
  line-height: 1;
  overflow: hidden;
  pointer-events: none;
  white-space: nowrap;
}

.legendItem {
  display: inline;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  white-space: nowrap;
}

.legendLong {
  color: var(--red);
}

.legendShort {
  color: var(--blue);
}

.legendClose {
  color: #667085;
}

.positionEmpty {
  color: var(--muted);
}

.simulationAccounts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 9px;
}

.simulationBoardCards {
  grid-template-columns: 1fr;
  gap: 6px;
  margin: 0;
}

.simulationAccountCard {
  min-width: 0;
  padding: 8px;
  border: 1px solid #dde6f2;
  border-radius: 7px;
  background: #fbfcff;
}

.simulationBoard .simulationAccountCard {
  position: relative;
  min-height: 84px;
  padding: 7px 82px 7px 9px;
  border-color: #c9daee;
  border-left: 3px solid #8fb7ea;
  border-radius: 6px;
  background: #ffffff;
  box-shadow: 0 3px 10px rgba(15, 23, 42, 0.04);
}

.simulationBoard .simulationAccountHead {
  gap: 6px;
  margin-bottom: 4px;
}

.simulationBoard .simulationAccountHead p {
  display: none;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
  margin-top: 1px;
  font-size: 0.6rem;
  line-height: 1.12;
}

.simulationBoard .simulationAccountHead strong {
  font-size: 0.78rem;
  line-height: 1.08;
}

.simulationBoard .simulationAccountState {
  min-width: 30px;
  padding: 2px 6px;
  font-size: 0.62rem;
}

.simulationAccountHead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.simulationAccountHead strong {
  display: block;
  font-size: 0.82rem;
  line-height: 1.15;
}

.simulationAccountHead p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.25;
}

.simulationAccountState {
  flex: 0 0 auto;
  min-width: 32px;
  padding: 2px 6px;
  border-radius: 999px;
  background: #ecfdf3;
  color: var(--green);
  font-size: 0.66rem;
  font-weight: 900;
  text-align: center;
}

.simulationAccountState.stopped {
  background: #f2f4f7;
  color: var(--muted);
}

.simulationAccountMetrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px 7px;
  font-size: 0.72rem;
  line-height: 1.25;
}

.simulationAccountMetrics span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.simulationAccountMetrics b {
  margin-right: 4px;
  color: var(--muted);
  font-weight: 800;
}

.simulationAccountPosition {
  min-height: 28px;
  margin-top: 6px;
  font-size: 0.72rem;
}

.simulationNoPosition {
  color: var(--muted);
  font-weight: 800;
}

.simulationAccountActions {
  display: flex;
  gap: 5px;
  margin-top: 6px;
}

.simulationAccountActions button {
  min-height: 24px;
  padding: 0 7px;
  border: 1px solid #c7d1df;
  border-radius: 6px;
  background: #fff;
  color: #344054;
  cursor: pointer;
  font: 900 0.68rem "Segoe UI", system-ui, sans-serif;
}

.simulationAccountActions button[data-side="LONG"] {
  color: var(--red);
  border-color: #f7c7c0;
}

.simulationAccountActions button[data-side="SHORT"] {
  color: var(--blue);
  border-color: #bdd7ff;
}

.simulationAccountActions button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.simulationBoard .simulationAccountMetrics {
  gap: 2px 7px;
  font-size: 0.66rem;
  line-height: 1.14;
}

.simulationBoard .simulationAccountMetrics b {
  margin-right: 3px;
}

.simulationBoard .simulationAccountPosition {
  min-height: 18px;
  margin-top: 3px;
  font-size: 0.64rem;
}

.simulationBoard .simulationNoPosition {
  font-size: 0.66rem;
}

.simulationBoard .positionCompact {
  gap: 4px;
  line-height: 1.1;
  overflow: hidden;
}

.simulationBoard .positionSide {
  min-width: 38px;
  height: 17px;
  padding: 0 6px;
  font-size: 0.62rem;
}

.simulationBoard .positionPnl {
  min-width: 62px;
}

.simulationBoard .positionMetrics {
  display: none;
}

.simulationBoard .positionCloseBtn {
  min-height: 17px;
  padding: 0 5px;
  font-size: 0.6rem;
}

.simulationBoard .simulationAccountActions {
  position: absolute;
  right: 7px;
  bottom: 7px;
  width: 68px;
  flex-direction: column;
  gap: 4px;
  margin-top: 0;
}

.simulationBoard .simulationAccountActions button {
  width: 100%;
  min-height: 19px;
  padding: 0 4px;
  border-radius: 5px;
  font-size: 0.6rem;
}

.simulationTag {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  background: #eef4ff;
  color: #344054;
  font-size: 0.68rem;
  font-weight: 900;
}

.positive {
  color: var(--red);
}

.negative {
  color: var(--blue);
}

.neutral {
  color: var(--muted);
}

.chartFrame {
  position: relative;
  min-height: 0;
  height: 520px;
}

.tradingPanel .chartFrame {
  height: 520px;
}

.indicatorPanel .chartFrame {
  height: 320px;
}

.priceChart {
  display: block;
  width: 100%;
  min-height: 0;
  height: 100%;
  contain: layout paint;
  border-top: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line-strong);
  background: linear-gradient(180deg, #ffffff 0%, #fbfcff 100%);
}

.positionHistory {
  min-height: 0;
  margin-top: 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcff;
  overflow: hidden;
}

.historyHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 34px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  color: #344054;
  font-size: 0.82rem;
}

.historyHeader span {
  color: var(--muted);
  font-weight: 800;
}

.historyList {
  max-height: none;
  overflow: visible;
  overscroll-behavior: auto;
}

.historyEmpty {
  padding: 18px 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

.historyRow {
  display: grid;
  gap: 5px;
  padding: 8px 10px;
  border-bottom: 1px solid #e9eef5;
  font-size: 0.78rem;
}

.historyRow:last-child {
  border-bottom: 0;
}

.historyRow.open {
  background: #fffaf0;
}

.historyMain,
.historyPrices {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex-wrap: wrap;
}

.historyMain span,
.historyPrices span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.sideBadge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  height: 22px;
  border-radius: 999px;
  font-weight: 900;
  font-size: 0.72rem;
}

.sideBadge.long {
  background: #fee4e2;
  color: var(--red);
}

.sideBadge.short {
  background: #dbeafe;
  color: var(--blue);
}

.chartEmpty,
.fatalError {
  display: grid;
  place-items: center;
  min-height: 320px;
  padding: 18px;
  color: var(--muted);
  font-size: 0.92rem;
  text-align: center;
}

.fatalError {
  grid-column: 1 / -1;
  border: 1px solid #fecdca;
  border-radius: 8px;
  background: #fffbfa;
  color: #b42318;
}

.coinFooter {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 38px;
  padding-top: 9px;
  color: var(--muted);
  font-size: 0.8rem;
  overflow-wrap: anywhere;
}

a[href*="tradingview.com"] {
  display: none !important;
}

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

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

  .chartGrid {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .coinPanel {
    min-height: 600px;
    height: auto;
    grid-template-rows: auto auto 500px auto auto;
  }

  .tradingPanel {
    grid-template-rows: auto auto 500px auto auto;
  }

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

  .chartFrame {
    min-height: 500px;
    height: 500px;
  }

  .priceChart {
    min-height: 500px;
    height: 500px;
  }

  .indicatorPanel {
    min-height: 366px;
    grid-template-rows: auto 320px;
  }

  .indicatorPanel .priceChart {
    min-height: 320px;
    height: 320px;
  }

  .indicatorPanel .chartFrame {
    min-height: 320px;
    height: 320px;
  }
}

@media (max-width: 760px) {
  .shell {
    padding: 12px;
  }

  .topbar,
  .toolbar,
  .coinHeader,
  .coinFooter {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar {
    display: flex;
  }

  .toolbar {
    flex-wrap: wrap;
  }

  .toolbarNote {
    flex-basis: 100%;
  }

  .coinHeader {
    display: flex;
  }

  .coinStats {
    width: 100%;
    grid-template-columns: 1fr;
  }

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

  .simulationBoard {
    padding: 10px;
  }

  .coinStats > div:last-child {
    min-width: 0;
  }

  .coinPanel {
    min-height: 560px;
    grid-template-rows: auto auto 400px auto auto;
  }

  .tradingPanel {
    grid-template-rows: auto auto 400px auto auto;
  }

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

  .chartFrame {
    min-height: 400px;
    height: 400px;
  }

  .priceChart {
    min-height: 400px;
    height: 400px;
  }

  .indicatorPanel {
    min-height: 306px;
    grid-template-rows: auto 260px;
  }

  .indicatorPanel .priceChart {
    min-height: 260px;
    height: 260px;
  }

  .indicatorPanel .chartFrame {
    min-height: 260px;
    height: 260px;
  }

  .coinFooter {
    display: flex;
  }
}
