* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  background: #0d1117;
  color: #c9d1d9;
  font-family: 'Segoe UI', Tahoma, sans-serif;
  font-size: 14px;
  display: flex;
  flex-direction: column;
}
#app { flex: 1; display: flex; flex-direction: column; min-height: 0; min-width: 0; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  background: #161b22; border-bottom: 1px solid #21262d;
  padding: 12px 20px;
  flex-shrink: 0;
}
.topbar .brand { font-weight: 700; font-size: 16px; color: #e6edf3; }
.topbar .spacer { flex: 1; }
.topbar a { color: #58a6ff; text-decoration: none; }
.topbar a:hover { text-decoration: underline; }
.topbar button {
  background: #21262d; border: 1px solid #30363d; color: #c9d1d9;
  padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.topbar button:hover { background: #30363d; }

.login-wrap {
  flex: 1; display: flex; align-items: center; justify-content: center;
}
.login-card {
  background: #161b22; border: 1px solid #30363d; border-radius: 12px;
  padding: 28px 36px; min-width: 320px;
}
.login-card h2 { margin-bottom: 18px; color: #e6edf3; }
.login-card input {
  width: 100%; padding: 9px 12px; border-radius: 6px;
  background: #0d1117; border: 1px solid #30363d; color: #e6edf3; font-size: 14px;
  margin-bottom: 12px;
}
.login-card input:focus { outline: none; border-color: #58a6ff; }
.login-card button {
  width: 100%; padding: 10px; background: #238636; color: #fff;
  border: none; border-radius: 6px; cursor: pointer; font-weight: 600;
}
.login-card button:hover { background: #2ea043; }
.login-card .err { color: #f85149; font-size: 12px; margin-bottom: 8px; min-height: 16px; }

.runs-page { padding: 20px; flex: 1; overflow-y: auto; min-height: 0; }
.runs-page h1 { color: #e6edf3; margin-bottom: 18px; font-size: 22px; }
.runs-table {
  width: 100%; border-collapse: collapse;
  background: #161b22; border-radius: 8px; overflow: hidden;
}
.runs-table th {
  background: #0d1117; color: #8b949e; text-align: left;
  padding: 10px 14px; border-bottom: 1px solid #30363d; font-weight: 600;
  font-size: 12px; text-transform: uppercase; letter-spacing: .5px;
}
.runs-table td { padding: 12px 14px; border-bottom: 1px solid #21262d; }
.runs-table tr:last-child td { border-bottom: none; }
.runs-table tr:hover { background: #1c2128; cursor: pointer; }
.runs-table .profit-pos { color: #3fb950; font-weight: 600; }
.runs-table .profit-neg { color: #f85149; font-weight: 600; }
.runs-table .note-input {
  background: transparent; border: 1px solid transparent; color: #8b949e;
  padding: 4px 6px; border-radius: 4px; width: 100%; font-size: 13px;
}
.runs-table .note-input:hover { border-color: #30363d; }
.runs-table .note-input:focus { outline: none; border-color: #58a6ff; background: #0d1117; color: #e6edf3; }
.runs-table .delbtn {
  background: transparent; border: none; color: #8b949e; cursor: pointer; font-size: 16px;
}
.runs-table .delbtn:hover { color: #f85149; }

/* ===== Run page: full-viewport split ===== */
.run-page {
  display: flex;
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}
.run-sidebar {
  width: 320px;
  min-width: 320px;
  max-width: 320px;
  background: #161b22;
  border-right: 1px solid #21262d;
  overflow-y: auto;
  padding: 16px;
  flex-shrink: 0;
}
.run-main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.run-title {
  color: #e6edf3;
  padding: 14px 20px;
  border-bottom: 1px solid #21262d;
  font-size: 18px;
  font-weight: 600;
  flex-shrink: 0;
}
.run-title .run-source {
  color: #8b949e; margin-left: 12px; font-size: 13px; font-weight: 400;
}

.chart-host {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  position: relative;
  padding: 8px;
  overflow: hidden;
}
.chart-host .uplot { width: 100% !important; }

/* ===== Backtest cards ===== */
.bt-card {
  background: #0d1117; border: 1px solid #21262d; border-radius: 8px;
  padding: 12px; margin-bottom: 10px;
  transition: border-color .15s;
}
.bt-card:hover { border-color: #30363d; }
.bt-card .bt-header {
  display: flex; align-items: center; gap: 8px; margin-bottom: 8px;
}
.bt-card .bt-color {
  width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0;
}
.bt-card .bt-name {
  font-weight: 600; color: #e6edf3; flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bt-card .eyebtn {
  background: transparent; border: none; cursor: pointer; padding: 2px;
  color: #8b949e;
}
.bt-card .eyebtn.off { color: #484f58; }
.bt-card .eyebtn:hover { color: #58a6ff; }

/* Profit — primary, large */
.bt-card .bt-profit {
  font-size: 20px; font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: .3px;
}
.bt-profit.pos { color: #3fb950; }
.bt-profit.neg { color: #f85149; }

/* Primary metrics row: WinRate / MaxDD / Trades */
.bt-card .bt-metrics-primary {
  display: flex; gap: 8px; margin-bottom: 8px;
}
.bt-card .bt-metric {
  flex: 1;
  background: #010409;
  border: 1px solid #21262d;
  border-radius: 6px;
  padding: 6px 8px;
  text-align: center;
}
.bt-card .bt-metric-lbl {
  display: block;
  font-size: 10px; color: #8b949e;
  text-transform: uppercase; letter-spacing: .5px;
  margin-bottom: 2px;
}
.bt-card .bt-metric-val {
  font-size: 13px; font-weight: 600; color: #e6edf3;
}
.bt-card .bt-metric-val.neg { color: #f85149; }

.bt-card .bt-note {
  width: 100%; background: transparent; border: 1px solid #30363d;
  color: #c9d1d9; padding: 4px 6px; border-radius: 4px; font-size: 12px;
  margin-top: 4px;
}
.bt-card .bt-note:focus { outline: none; border-color: #58a6ff; }

.add-btn {
  width: 100%; background: #238636; color: white;
  border: none; padding: 10px; border-radius: 6px; cursor: pointer;
  font-weight: 600; margin-bottom: 12px;
}
.add-btn:hover { background: #2ea043; }

/* ===== Modals ===== */
.modal-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal {
  background: #161b22; border: 1px solid #30363d; border-radius: 10px;
  padding: 20px; width: 600px; max-height: 85vh; overflow-y: auto;
}
.modal-report { width: 720px; }
.modal h3 {
  color: #e6edf3; margin-bottom: 14px; display: flex; align-items: center; gap: 10px;
}
.modal h4.modal-section {
  color: #8b949e; margin: 16px 0 8px; font-size: 12px;
  text-transform: uppercase; letter-spacing: .8px;
}
.modal .modal-color {
  display: inline-block; width: 14px; height: 14px; border-radius: 4px;
}
.modal .close-btn {
  background: #21262d; border: 1px solid #30363d; color: #c9d1d9;
  padding: 6px 14px; border-radius: 6px; cursor: pointer; margin-top: 14px;
}
.modal .add-run-row { padding: 8px 0; border-bottom: 1px solid #21262d; }
.modal .add-run-name { font-weight: 600; color: #e6edf3; }
.modal .add-bt-row {
  display: flex; align-items: center; gap: 8px; padding: 4px 0 4px 16px;
  font-size: 13px;
}
.modal .add-bt-row input { margin-right: 4px; }

.report-pre {
  background: #010409; border: 1px solid #21262d; border-radius: 6px;
  padding: 12px 14px; font-family: 'Cascadia Code', 'Consolas', monospace;
  font-size: 12px; color: #c9d1d9; white-space: pre-wrap;
  max-height: 50vh; overflow-y: auto;
}

.live-tag {
  display: inline-block; padding: 2px 8px; background: #1f6feb; color: white;
  border-radius: 10px; font-size: 11px; font-weight: 600; margin-left: 8px;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .55; }
}

.empty-msg {
  text-align: center; padding: 40px; color: #8b949e;
}

/* ===== Chart tooltip ===== */
.chart-tooltip {
  position: absolute; top: 0; left: 0;
  background: rgba(22, 27, 34, .96);
  border: 1px solid #30363d;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  pointer-events: none;
  z-index: 50;
  box-shadow: 0 4px 16px rgba(0,0,0,.6);
  min-width: 180px;
  will-change: transform;
}
.chart-tooltip .tt-time {
  color: #8b949e; font-size: 11px; margin-bottom: 6px;
  border-bottom: 1px solid #21262d; padding-bottom: 4px;
}
.chart-tooltip .tt-row {
  display: flex; align-items: center; gap: 6px;
  padding: 2px 0;
}
.chart-tooltip .tt-dot {
  width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0;
}
.chart-tooltip .tt-label {
  flex: 1; color: #c9d1d9;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 200px;
}
.chart-tooltip .tt-val {
  font-weight: 600;
}
.chart-tooltip .tt-val.pos { color: #3fb950; }
.chart-tooltip .tt-val.neg { color: #f85149; }
