/* ==========================================================================
   TradingView Position Drawing Toolbar, SVG Layers, Drag Handles & Badges
   ========================================================================== */

/* TradingView Position Drawing Toolbar */
.chart-pos-toolbar {
  pointer-events: auto;
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(18, 21, 26, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 3px 6px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  user-select: none;
  -webkit-user-select: none;
  max-width: calc(100vw - 20px);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.chart-pos-toolbar::-webkit-scrollbar {
  display: none;
}

@media (max-width: 480px) {
  .chart-pos-toolbar {
    max-width: calc(100vw - 12px);
    gap: 4px;
    padding: 2px 4px;
  }
  .tv-pos-btn {
    padding: 0 7px;
    font-size: 10px;
    height: 22px;
  }
  .pos-hud-stat {
    font-size: 9.5px;
  }
}

.tv-pos-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 24px;
  padding: 0 9px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font-ui);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
}

.tv-pos-btn .pos-icon {
  font-size: 9px;
}

.tv-pos-btn.tv-pos-long {
  background: rgba(14, 203, 129, 0.15);
  border-color: rgba(14, 203, 129, 0.45);
  color: var(--color-bull);
}
.tv-pos-btn.tv-pos-long:hover, .tv-pos-btn.tv-pos-long:active, .tv-pos-btn.tv-pos-long.active {
  background: var(--color-bull);
  color: #0b0e11;
  box-shadow: 0 0 10px rgba(14, 203, 129, 0.45);
}

.tv-pos-btn.tv-pos-short {
  background: rgba(246, 70, 93, 0.15);
  border-color: rgba(246, 70, 93, 0.45);
  color: var(--color-bear);
}
.tv-pos-btn.tv-pos-short:hover, .tv-pos-btn.tv-pos-short:active, .tv-pos-btn.tv-pos-short.active {
  background: var(--color-bear);
  color: #ffffff;
  box-shadow: 0 0 10px rgba(246, 70, 93, 0.45);
}

/* Active HUD in Toolbar */
.pos-hud-active {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.pos-hud-active.hidden {
  display: none !important;
}

.pos-hud-divider {
  width: 1px;
  height: 14px;
  background: var(--border-light);
  margin: 0 2px;
}

.pos-hud-tag {
  font-size: 9px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.pos-hud-tag.long {
  background: var(--color-bull-bg);
  color: var(--color-bull);
  border: 1px solid rgba(14, 203, 129, 0.3);
}
.pos-hud-tag.short {
  background: var(--color-bear-bg);
  color: var(--color-bear);
  border: 1px solid rgba(246, 70, 93, 0.3);
}
/* Live Opened Position HUD */
.pos-hud-live-open {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  padding: 1px 4px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  transition: background 0.15s ease;
}
.pos-hud-live-open:hover {
  background: rgba(255, 255, 255, 0.08);
}
.pos-hud-live-open.hidden {
  display: none !important;
}
.pos-live-pill {
  font-size: 9px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  font-family: var(--font-ui);
}
.pos-live-pill.long {
  background: var(--color-bull-bg);
  color: var(--color-bull);
  border: 1px solid rgba(14, 203, 129, 0.4);
}
.pos-live-pill.short {
  background: var(--color-bear-bg);
  color: var(--color-bear);
  border: 1px solid rgba(246, 70, 93, 0.4);
}
.pos-live-pnl {
  font-size: 10px;
  font-family: var(--font-mono);
  font-weight: 700;
}
.pos-live-pnl.bull {
  color: var(--color-bull);
}
.pos-live-pnl.bear {
  color: var(--color-bear);
}
.pos-live-tpsl {
  font-size: 9.5px;
  color: var(--text-dim);
  font-family: var(--font-mono);
}


.pos-hud-stat {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  font-family: var(--font-mono);
}
.pos-hud-label {
  color: var(--text-dim);
  font-size: 9px;
}
.pos-hud-value {
  color: var(--binance-gold);
  font-weight: 700;
}

.pos-hud-presets {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.pos-hud-rr-btn {
  height: 20px;
  padding: 0 6px;
  font-size: 9px;
  font-weight: 700;
  font-family: var(--font-mono);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}
.pos-hud-rr-btn:hover, .pos-hud-rr-btn:active, .pos-hud-rr-btn.active {
  background: var(--binance-gold);
  color: #0b0e11;
  border-color: var(--binance-gold);
}

.pos-hud-btn {
  width: 21px;
  height: 21px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}
.pos-hud-btn:hover, .pos-hud-btn:active {
  background: var(--bg-active);
  color: var(--text-main);
}
.pos-hud-close:hover, .pos-hud-close:active {
  background: var(--color-bear-bg);
  color: var(--color-bear);
  border-color: var(--color-bear);
}

/* SVG Overlay Layer */
.tv-position-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 6;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

/* Target & Stop Rectangles */
.tv-rect {
  pointer-events: all !important;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.tv-rect-target {
  fill: rgba(14, 203, 129, 0.20);
  cursor: move;
}
.tv-rect-stop {
  fill: rgba(246, 70, 93, 0.20);
  cursor: move;
}

/* Boundary lines */
.tv-line {
  pointer-events: all !important;
  touch-action: none;
}
.tv-line-tp {
  stroke: var(--color-bull);
  stroke-width: 2;
}
.tv-line-sl {
  stroke: var(--color-bear);
  stroke-width: 2;
}
.tv-line-entry {
  stroke: rgba(234, 236, 239, 0.85);
  stroke-width: 1.5;
  stroke-dasharray: 4, 3;
}
.tv-border-line {
  stroke: rgba(255, 255, 255, 0.2);
  stroke-width: 1;
  pointer-events: all !important;
  touch-action: none;
}

/* Invisible wide hit-test lines for lines and borders */
.tv-line-hit {
  stroke: rgba(0, 0, 0, 0.001);
  fill: none;
  pointer-events: all !important;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

/* Drag Handles */
.tv-handle-group {
  pointer-events: all !important;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.tv-hit-area {
  fill: rgba(0, 0, 0, 0.001) !important;
  stroke: none;
  pointer-events: all !important;
  touch-action: none;
  cursor: inherit;
  -webkit-tap-highlight-color: transparent;
}
.tv-handle {
  stroke: #ffffff;
  stroke-width: 2;
  filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.7));
  transition: r 0.12s ease;
  cursor: inherit;
  pointer-events: none; /* Hit-area handles pointer hits */
}
.tv-handle:hover, .tv-handle-group:active .tv-handle {
  r: 7.5;
}
.tv-handle-tp {
  fill: var(--color-bull);
}
.tv-handle-sl {
  fill: var(--color-bear);
}
.tv-handle-entry {
  fill: #ffffff;
  stroke: #181a20;
}
.tv-handle-width {
  fill: var(--color-bb);
  stroke: #ffffff;
}

/* Info Badges inside and outside boxes */
.tv-info-group {
  pointer-events: all !important;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.tv-info-group text {
  pointer-events: none;
}

body.tv-dragging {
  user-select: none !important;
  -webkit-user-select: none !important;
  touch-action: none !important;
}
body.tv-dragging * {
  user-select: none !important;
  -webkit-user-select: none !important;
}
.tv-handle-group.dragging .tv-handle,
.tv-handle-group:active .tv-handle {
  r: 8.5;
  stroke-width: 3;
}
.tv-info-bg {
  fill: rgba(11, 14, 17, 0.90);
  stroke-width: 1;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.5));
}
.tv-info-bg-tp {
  stroke: rgba(14, 203, 129, 0.65);
}
.tv-info-bg-sl {
  stroke: rgba(246, 70, 93, 0.65);
}
.tv-info-bg-rr {
  stroke: rgba(240, 185, 11, 0.7);
  fill: rgba(11, 14, 17, 0.94);
}
.tv-info-bg-entry {
  stroke: rgba(234, 236, 239, 0.4);
}

.tv-info-txt {
  font-family: var(--font-mono);
  dominant-baseline: middle;
  text-anchor: middle;
}
.tv-txt-tp-badge {
  font-size: 10px;
  font-weight: 700;
  fill: var(--color-bull);
  letter-spacing: 0.2px;
}
.tv-txt-sl-badge {
  font-size: 10px;
  font-weight: 700;
  fill: var(--color-bear);
  letter-spacing: 0.2px;
}
.tv-txt-rr-badge {
  font-size: 10.5px;
  font-weight: 800;
  fill: #f0b90b;
  letter-spacing: 0.3px;
}
.tv-txt-entry {
  font-size: 9.5px;
  font-weight: 600;
  fill: var(--text-main);
  text-anchor: start;
}

