* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d1117;
  --bg-card: #161b22;
  --bg-card-hover: #1c2128;
  --border: #30363d;
  --text: #c9d1d9;
  --text-muted: #8b949e;
  --green: #26a69a;
  --red: #ef5350;
  --orange: #f0883e;
  --blue: #58a6ff;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.brand .logo { font-size: 22px; }
.brand .title { font-weight: 600; font-size: 16px; }
.brand .subtitle { color: var(--text-muted); font-family: var(--mono); font-size: 12px; }

.bot-status {
  font-family: var(--mono);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.bot-status.alive { color: var(--green); border-color: var(--green); }
.bot-status.dead { color: var(--red); border-color: var(--red); }

.grid {
  display: grid;
  gap: 16px;
  padding: 16px 24px;
  max-width: 1600px;
  margin: 0 auto;
}

.candle-clock {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 18px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 18px;
  align-items: center;
}
.candle-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  white-space: nowrap;
}
.candle-label {
  color: var(--text-muted);
  font-size: 12px;
}
.candle-label strong { color: var(--text); }
.candle-elapsed {
  color: var(--green);
  font-weight: 600;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  margin-left: 4px;
}
.candle-divider { color: var(--text-muted); }
.candle-total {
  color: var(--text-muted);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.candle-progress {
  height: 8px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}
.candle-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #26a69a 0%, #58a6ff 100%);
  width: 0%;
  transition: width 0.4s ease;
}
.candle-next {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}
.candle-next strong {
  color: var(--orange);
  font-variant-numeric: tabular-nums;
}

@media (max-width: 900px) {
  .candle-clock {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .candle-next { text-align: center; }
}

.stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.card-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.card-value {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 600;
}

.position-controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
}
.position-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
  font-family: var(--mono);
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.position-card.empty { color: var(--text-muted); justify-content: center; }
.position-card .pnl-pos { color: var(--green); }
.position-card .pnl-neg { color: var(--red); }

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

.btn {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
}
.btn:hover:not(:disabled) { background: var(--bg-card-hover); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.danger { color: var(--red); border-color: var(--red); }
.btn.danger:hover:not(:disabled) { background: rgba(239, 83, 80, 0.1); }
.btn.warning { color: var(--orange); border-color: var(--orange); }
.btn.warning:hover:not(:disabled) { background: rgba(240, 136, 62, 0.1); }
.btn.success { color: var(--green); border-color: var(--green); }
.btn.success:hover:not(:disabled) { background: rgba(38, 166, 154, 0.1); }

.settings-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
}
.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 8px;
}
.settings-header h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 600;
}
.settings-hint {
  text-transform: none;
  letter-spacing: normal;
  font-weight: 400;
  color: var(--text-muted);
  font-size: 11px;
  margin-left: 6px;
}
.settings-status {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-muted);
}
.settings-status.ok { color: var(--green); }
.settings-status.err { color: var(--red); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px 20px;
  margin-bottom: 14px;
}
.form-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.form-row label {
  font-size: 12px;
  color: var(--text);
  font-weight: 500;
}
.form-row input[type="number"] {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 13px;
  outline: none;
}
.form-row input[type="number"]:focus { border-color: var(--blue); }
.form-help {
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.3;
}

.form-row-toggle { gap: 6px; }
.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}
.switch input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.switch-slider {
  position: relative;
  width: 38px;
  height: 22px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.switch-slider::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: left 0.15s, background 0.15s;
}
.switch input:checked + .switch-slider {
  background: rgba(38, 166, 154, 0.2);
  border-color: var(--green);
}
.switch input:checked + .switch-slider::after {
  left: 18px;
  background: var(--green);
}
.switch-label {
  font-size: 13px;
  color: var(--text);
}

.settings-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

@media (max-width: 1100px) {
  .form-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .form-grid { grid-template-columns: 1fr; }
}

.form-grid-3 {
  grid-template-columns: 1fr 1fr auto !important;
  align-items: end;
}
.form-row .select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 13px;
  outline: none;
}
.form-row .select:focus { border-color: var(--blue); }
.form-row .select:disabled { opacity: 0.5; cursor: not-allowed; }

.manual-order-section {
  display: contents;
}
.manual-order-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
}
.manual-order-form {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
}
.manual-order-controls {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}
.side-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.side-toggle input[type="radio"] { display: none; }
.side-toggle label {
  padding: 8px 16px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  transition: all 0.15s;
  user-select: none;
}
.side-toggle input:checked + label.side-buy {
  background: rgba(38, 166, 154, 0.18);
  color: var(--green);
}
.side-toggle input:checked + label.side-sell {
  background: rgba(239, 83, 80, 0.18);
  color: var(--red);
}
#manual-notional {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 13px;
  outline: none;
}
#manual-notional:focus { border-color: var(--blue); }
.manual-order-help {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

.kill-switch-card {
  background: rgba(239, 83, 80, 0.08);
  border: 1px solid var(--red);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: center;
}
.kill-switch-title {
  color: var(--red);
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.kill-switch-help {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}
.btn-kill {
  background: var(--red);
  color: white;
  border: none;
  padding: 12px 18px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: all 0.15s;
}
.btn-kill:hover { background: #d83a37; transform: scale(1.02); }
.btn-kill:active { transform: scale(0.98); }

@media (max-width: 900px) {
  .form-grid-3 { grid-template-columns: 1fr !important; }
  .manual-order-grid { grid-template-columns: 1fr; }
  .manual-order-controls { grid-template-columns: 1fr; }
}

.chart-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}
.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 0 4px;
  flex-wrap: wrap;
  gap: 8px;
}
.chart-title { font-weight: 600; font-size: 14px; }
.chart-tools { display: flex; align-items: center; gap: 8px; }
.tools-label { color: var(--text-muted); font-size: 12px; }
.chart-tools .select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-family: var(--mono);
  font-size: 13px;
}
.chart { width: 100%; height: 480px; }

.bottom {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 16px;
}

.trades-section, .log-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}

.trades-section h3, .log-section h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
  font-weight: 600;
}

.table-wrap { overflow-x: auto; }

.trades-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 12px;
}
.trades-table th, .trades-table td {
  padding: 8px 10px;
  text-align: right;
  border-bottom: 1px solid var(--border);
}
.trades-table th:first-child, .trades-table td:first-child,
.trades-table th:nth-child(2), .trades-table td:nth-child(2),
.trades-table th:nth-child(8), .trades-table td:nth-child(8) {
  text-align: left;
}
.trades-table th { color: var(--text-muted); font-weight: 500; }
.trades-table tr:last-child td { border-bottom: none; }
.pnl-pos { color: var(--green); }
.pnl-neg { color: var(--red); }

.log-pre {
  font-family: var(--mono);
  font-size: 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  height: 380px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text-muted);
}

@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .position-controls { grid-template-columns: 1fr; }
  .controls { justify-content: flex-end; }
  .bottom { grid-template-columns: 1fr; }
  .chart { height: 380px; }
}

.bt-results { display: contents; }
.bt-verdict {
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  padding: 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
}
.bt-verdict.ok { color: var(--green); border-color: var(--green); }
.bt-verdict.warn { color: var(--orange); border-color: var(--orange); }
.bt-verdict.err { color: var(--red); border-color: var(--red); }

.bt-metrics-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
}
@media (max-width: 1100px) { .bt-metrics-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 700px) { .bt-metrics-grid { grid-template-columns: repeat(2, 1fr); } }

.bt-detail-pre {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-muted);
}
.bt-detail-pre strong { color: var(--text); }

.just-list {
  list-style: none;
  padding: 0;
  margin: 8px 0 0 0;
}
.just-list li {
  padding: 6px 0 6px 18px;
  position: relative;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.4;
  border-bottom: 1px solid var(--border);
}
.just-list li:last-child { border-bottom: none; }
.just-list li::before {
  content: '•';
  position: absolute;
  left: 4px;
  color: var(--blue);
}

.rec-strategy {
  font-size: 16px;
  font-weight: 600;
  color: var(--green);
  padding: 10px 12px;
  background: rgba(38, 166, 154, 0.08);
  border: 1px solid var(--green);
  border-radius: 8px;
  margin-top: 8px;
}
.rec-config-title {
  margin-top: 14px;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.rec-config {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  margin-top: 6px;
  overflow-x: auto;
}
.rec-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
}

.ind-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 12px;
}
.ind-table tr td {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.ind-table tr:last-child td { border-bottom: none; }

.btn-small {
  padding: 4px 10px !important;
  font-size: 11px !important;
}
