* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: #0f1117;
  color: #e6e6e6;
}

header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 24px;
  padding: 12px 20px;
  border-bottom: 1px solid #262a34;
}

h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 600;
  color: #f2f2f2;
}

.tabs {
  display: flex;
  gap: 8px;
}

.tab {
  background: #1a1d27;
  color: #b8bcc8;
  border: 1px solid #2c3040;
  border-radius: 6px;
  padding: 6px 16px;
  font-size: 14px;
  cursor: pointer;
}

.tab:hover {
  background: #23273338;
  border-color: #3a3f52;
}

.tab.active {
  background: #2a5adf;
  border-color: #2a5adf;
  color: #fff;
}

.tab.disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.tab.disabled:hover {
  background: #1a1d27;
  border-color: #2c3040;
}

main {
  padding: 16px 20px;
}

#status {
  min-height: 20px;
  font-size: 13px;
  color: #9098a8;
  margin-bottom: 8px;
}

#status.error {
  color: #e5484d;
}

#layout {
  display: flex;
  align-items: stretch;
  gap: 16px;
}

#chart-wrap {
  position: relative;
  flex: 1 1 65%;
  min-width: 0;
}

#chart {
  width: 100%;
  height: calc(100vh - 140px);
  border: 1px solid #262a34;
  border-radius: 8px;
  overflow: hidden;
}

@media (max-width: 900px) {
  #layout {
    flex-direction: column;
  }

  .backtest-panel {
    flex-basis: auto;
    height: auto;
    max-height: 70vh;
  }
}

#ohlc-readout {
  position: absolute;
  top: 10px;
  left: 12px;
  z-index: 2;
  display: flex;
  gap: 12px;
  padding: 6px 10px;
  background: rgba(15, 17, 23, 0.72);
  border: 1px solid #262a34;
  border-radius: 6px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

#ohlc-readout .item {
  color: #9098a8;
}

#ohlc-readout .item .val {
  font-weight: 600;
}

#ohlc-readout.up .val { color: #ef5350; }
#ohlc-readout.down .val { color: #26a69a; }

.backtest-panel {
  flex: 1 1 35%;
  min-width: 340px;
  height: calc(100vh - 140px);
  padding: 16px;
  background: #161922;
  border: 1px solid #262a34;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
}

.backtest-header {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-bottom: 12px;
  flex: 0 0 auto;
}

.backtest-header h2 {
  font-size: 15px;
  margin: 0;
  color: #f2f2f2;
}

.backtest-session-tabs .tab {
  padding: 3px 10px;
  font-size: 12px;
}

.backtest-note {
  margin: 0;
  font-size: 12px;
  color: #7d8496;
  flex-basis: 100%;
}

.backtest-summary {
  font-size: 13px;
  color: #c7cbd6;
}

.backtest-summary b.pos { color: #26a69a; }
.backtest-summary b.neg { color: #ef5350; }

.backtest-table-wrap {
  overflow: auto;
  flex: 1 1 auto;
  min-height: 0;
}

.backtest-table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  font-size: 13px;
}

.backtest-table th,
.backtest-table td {
  text-align: right;
  padding: 6px 10px;
  border-bottom: 1px solid #1c1f2a;
  white-space: nowrap;
}

.backtest-table th:first-child,
.backtest-table td:first-child {
  text-align: left;
}

.backtest-table th {
  color: #7d8496;
  font-weight: 500;
  position: sticky;
  top: 0;
  background: #161922;
}

.backtest-table tr.trade-row {
  cursor: pointer;
}

.backtest-table tr.trade-row:hover {
  background: #1c2030;
}

.backtest-table td.pos { color: #26a69a; }
.backtest-table td.neg { color: #ef5350; }

.backtest-table td.reason {
  text-align: left;
  color: #9098a8;
  white-space: normal;
  min-width: 220px;
}

.backtest-day-tabs {
  flex: 0 0 auto;
  flex-wrap: nowrap;
  overflow-x: auto;
  margin-bottom: 12px;
  padding-bottom: 4px;
}

.backtest-day-tabs .tab {
  white-space: nowrap;
  font-size: 13px;
}

.backtest-day-tabs .tab .pos,
.backtest-day-tabs .tab .neg {
  font-weight: 700;
}
