.back-link {
  color: var(--text-dim);
  text-decoration: none;
  margin-right: 4px;
}
.back-link:hover { color: var(--text); }
.sep { color: var(--panel-border); margin-right: 4px; }

.controls select {
  max-width: 220px;
}

.hidden { display: none !important; }

.paper-banner {
  background: #2a2308;
  color: #f0c96c;
  border-bottom: 1px solid #4a3d10;
  font-size: 12px;
  padding: 6px 16px;
  text-align: center;
}

.replay-banner {
  background: #211a3d;
  color: #b8a6ff;
  border-bottom: 1px solid #3d3070;
  font-size: 12px;
  padding: 6px 16px;
  text-align: center;
}
.replay-banner strong { color: #d7c9ff; letter-spacing: 0.4px; }

.replay-toggle-btn {
  background: #241c47;
  color: #b8a6ff;
  border: 1px solid #3d3070;
  border-radius: 5px;
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  margin-right: auto;
}
.replay-toggle-btn:hover { background: #2c2258; }
.replay-toggle-btn.active { background: #3d3070; color: #d7c9ff; }

.replay-bar {
  padding: 8px 10px;
  border-bottom: 1px solid var(--panel-border);
  background: #10151e;
  font-size: 12px;
}
.replay-setup, .replay-playback {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.replay-dt-label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
}
.replay-bar input[type="datetime-local"],
.replay-bar select {
  background: #1c2330;
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 5px;
  padding: 4px 6px;
  font-size: 12px;
}
.replay-bar button:not(.link-btn) {
  background: #241c47;
  color: #d7c9ff;
  border: 1px solid #3d3070;
  border-radius: 5px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.replay-bar button:not(.link-btn):hover { background: #2c2258; }
.replay-bar #replay-play-btn { min-width: 32px; }
.replay-status { color: #f0c96c; font-size: 11px; }
.replay-scrubber, #replay-scrubber { flex: 1; min-width: 120px; accent-color: #8a6fe8; }
.replay-position-label { color: var(--text-dim); font-size: 11px; white-space: nowrap; }
.link-btn.light { color: #d7c9ff; text-decoration: underline; background: none; border: none; cursor: pointer; font-size: 11px; padding: 0; }

.replay-tag {
  background: #3d3070;
  color: #d7c9ff;
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 10px;
  font-weight: 700;
}
.badge.replay { background: #3d3070; color: #d7c9ff; }

.trade-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 6px;
  padding: 6px;
  height: calc(100vh - 49px - 30px);
}

.trade-chart-col {
  display: flex;
  flex-direction: row;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  overflow: hidden;
  min-width: 0;
}

.trade-chart-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 0;
}

.chart-symbol-label {
  font-weight: 700;
  font-size: 14px;
  margin-right: 8px;
}

/* Drawing tools — a hand-built subset (trend line, horizontal line,
 * rectangle, fibonacci retracement, text, measure, magnet/lock/show-hide,
 * clear-all) drawn on a canvas overlaid on the chart. Lightweight
 * Charts itself ships no drawing UI, so this is custom; see
 * drawing_tools.js. Pitchfork, parallel channel, freehand brush, and
 * emoji stamps are intentionally left out to keep this shippable —
 * easy to add later following the same pattern. */
.drawing-toolbar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 4px;
  background: #10151e;
  border-right: 1px solid var(--panel-border);
  flex-shrink: 0;
}
.dt-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0;
}
.dt-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.dt-btn:hover { background: #1c2330; color: var(--text); }
.dt-btn.active { background: rgba(79, 140, 255, 0.18); border-color: var(--accent); color: var(--accent); }
.dt-btn.toggle.on { background: rgba(79, 140, 255, 0.18); border-color: var(--accent); color: var(--accent); }
.dt-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.dt-btn:disabled:hover { background: transparent; }
.dt-sep { width: 20px; height: 1px; background: var(--panel-border); margin: 4px 0; }

#drawing-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 4; /* above the chart's own canvas, below the order-line overlay's badges */
  cursor: crosshair;
}
#drawing-canvas.inert { pointer-events: none; cursor: default; }

.dt-text-input {
  position: absolute;
  z-index: 6;
  transform: translate(2px, -50%);
  background: #1c2330;
  border: 1px solid var(--accent);
  color: var(--text);
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 12px;
  min-width: 140px;
  outline: none;
}

/* Draggable target/stop-loss lines directly on the chart, TradingView-style. */
.order-line-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

.order-line-handle {
  position: absolute;
  left: 0;
  right: 70px; /* stay clear of the price axis so its native label reads cleanly */
  height: 16px;
  margin-top: -8px;
  cursor: ns-resize;
  pointer-events: auto;
}
.order-line-handle:hover { background: rgba(255, 255, 255, 0.04); }
.order-line-handle.dragging { background: rgba(255, 255, 255, 0.08); }

.order-line-badge {
  position: absolute;
  right: 76px;
  margin-top: -11px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 4px 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  color: #0e1117;
  white-space: nowrap;
  pointer-events: auto;
  cursor: ns-resize;
  user-select: none;
}
.order-line-badge.target { background: var(--green); }
.order-line-badge.stop { background: var(--red); }
.order-line-badge .qty-tag {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
  padding: 0 4px;
}
.order-line-badge .close-x {
  cursor: pointer;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
  width: 15px;
  height: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  line-height: 1;
}
.order-line-badge .close-x:hover { background: rgba(0, 0, 0, 0.4); }

.trade-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  min-height: 0;
}

.panel-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 12px;
  flex-shrink: 0;
}
.panel-card h3 {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}
.panel-card h3 .count {
  background: #1c2330;
  color: var(--text-dim);
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 600;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  padding: 3px 0;
  color: var(--text-dim);
}
.stat-row strong { color: var(--text); font-variant-numeric: tabular-nums; }
.stat-row.total { border-top: 1px solid var(--panel-border); margin-top: 4px; padding-top: 8px; }
.stat-row.total strong { font-size: 15px; }
.stat-row strong.pos { color: var(--green); }
.stat-row strong.neg { color: var(--red); }

.link-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 11px;
  text-decoration: underline;
  cursor: pointer;
  padding: 6px 0 0;
}
.link-btn:hover { color: var(--text); }

.side-toggle {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}
.side-btn {
  flex: 1;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  background: #1c2330;
  color: var(--text-dim);
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
}
.side-btn.buy.active { background: rgba(22, 199, 132, 0.18); border-color: var(--green); color: var(--green); }
.side-btn.sell.active { background: rgba(234, 57, 67, 0.18); border-color: var(--red); color: var(--red); }

.field {
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--text-dim);
}
.field em { font-style: normal; opacity: 0.7; }
.field input {
  display: block;
  width: 100%;
  margin-top: 3px;
  background: #1c2330;
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 5px;
  padding: 7px 8px;
  font-size: 13px;
  box-sizing: border-box;
}
.field input[readonly] { color: var(--text-dim); }

.order-warning {
  font-size: 11px;
  color: #f0c96c;
  min-height: 14px;
  margin-bottom: 6px;
}

.place-btn {
  width: 100%;
  padding: 10px;
  border-radius: 6px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}
.place-btn:hover { filter: brightness(1.1); }
.place-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.list-empty {
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
  padding: 10px 0;
}

.position-row, .history-row {
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 8px;
  margin-bottom: 6px;
  font-size: 12px;
}
.position-row .row-top, .history-row .row-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.position-row .sym { font-weight: 700; }
.badge {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 6px;
}
.badge.buy { background: rgba(22, 199, 132, 0.18); color: var(--green); }
.badge.sell { background: rgba(234, 57, 67, 0.18); color: var(--red); }
.badge.target { background: rgba(22, 199, 132, 0.18); color: var(--green); }
.badge.stop { background: rgba(234, 57, 67, 0.18); color: var(--red); }
.badge.manual { background: #1c2330; color: var(--text-dim); }

.position-row .row-meta, .history-row .row-meta {
  color: var(--text-dim);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px;
}
.position-row .pnl { font-weight: 700; font-variant-numeric: tabular-nums; }
.add-level { color: var(--accent); text-decoration: none; }
.add-level:hover { text-decoration: underline; }
.row-hint { color: var(--text-dim); font-size: 10px; font-style: italic; margin: 4px 0 2px; }
.pnl.pos { color: var(--green); }
.pnl.neg { color: var(--red); }
.pnl.zero { color: var(--text-dim); }

.close-btn {
  background: #1c2330;
  border: 1px solid var(--panel-border);
  color: var(--text-dim);
  border-radius: 4px;
  font-size: 11px;
  padding: 3px 8px;
  cursor: pointer;
  margin-top: 6px;
  width: 100%;
}
.close-btn:hover { color: var(--text); border-color: var(--accent); }

@media (max-width: 900px) {
  .trade-layout { grid-template-columns: 1fr; height: auto; }
  .trade-panel { overflow-y: visible; }
}

@media (max-width: 560px) {
  .controls select { max-width: 130px; }
  .chart-symbol-label { display: none; } /* redundant with the topbar's own symbol picker on a narrow screen */
  .replay-setup, .replay-playback { row-gap: 6px; }
  .drawing-toolbar { padding: 4px 2px; gap: 1px; }
  .dt-btn { width: 28px; height: 28px; }
  .dt-btn svg { width: 15px; height: 15px; }
  .dt-sep { width: 16px; }
}
