/* chart.css - Canvas Viewport & Legend */
/* Windows are placed by MultiChartManager._applyGeometry (left/top/width/height as calc of this box) */
.charts-grid-container {
  position: relative;
}

.chart-instance-wrapper {
  position: absolute;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  background: var(--bg-primary);
  border-radius: var(--panel-radius);
  overflow: hidden;
  border: 1px solid transparent;
  transition: border-color 0.15s ease;
}

.chart-instance-wrapper.active-chart-pane {
  border: 1px solid var(--accent-blue);
  box-shadow: inset 0 0 6px rgba(41, 98, 255, 0.15);
}

/* A single chart is always the active one, so it needs no highlight */
.grid-1x1 .chart-instance-wrapper.active-chart-pane {
  border-color: transparent;
  box-shadow: none;
}

/* Draggable border in the gap between two windows */
.chart-splitter {
  position: absolute;
  z-index: 15;
  border-radius: 3px;
  transition: background-color 0.15s ease;
  touch-action: none;
}
.chart-splitter.splitter-v { cursor: col-resize; }
.chart-splitter.splitter-h { cursor: row-resize; }
.chart-splitter:hover,
.chart-splitter.dragging {
  background: var(--accent-blue);
  opacity: 0.55;
}

/* While dragging, the cursor stays and no text gets selected */
body.resizing-charts,
body.resizing-charts * {
  cursor: col-resize !important;
  user-select: none !important;
}
body.resizing-charts-h,
body.resizing-charts-h * {
  cursor: row-resize !important;
}

.chart-canvas-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

/* Legend in Light Mode matching TradingView Status Line */
.chart-legend-overlay {
  position: absolute;
  top: 8px;
  left: 10px;
  background: transparent;
  padding: 0;
  border: none;
  font-size: 12px;
  pointer-events: auto;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: none;
  direction: ltr; /* Legend flows LTR starting from the left of the chart area */
  user-select: none;
  font-family: -apple-system, BlinkMacSystemFont, 'Trebuchet MS', Roboto, Ubuntu, sans-serif;
  max-width: calc(100% - 95px);
  overflow: hidden;
  white-space: nowrap;
}

/* Symbol Badge / Widget with Blue Border */
.legend-symbol-widget {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 7px;
  border: 1px solid #2962ff;
  border-radius: 4px;
  background: var(--bg-glass);
  backdrop-filter: blur(4px);
  color: var(--text-primary);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.legend-symbol-widget:hover {
  background: var(--bg-panel);
  box-shadow: 0 1px 4px rgba(41, 98, 255, 0.18);
}

/* Status icons beside the legend: market hours and data freshness */
.legend-status-icons {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  cursor: default;
  outline: none;
}

.status-icon {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  flex-shrink: 0;
  color: var(--text-secondary);
  background: rgba(120, 123, 134, 0.16);
}

/* Market: a dot in a tinted ring */
.market-icon::after {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}
.market-icon.phase-open { color: #089981; background: rgba(8, 153, 129, 0.16); }
.market-icon.phase-pre,
.market-icon.phase-post { color: #ff9800; background: rgba(255, 152, 0, 0.16); }
.market-icon.phase-closed { color: #787b86; background: rgba(120, 123, 134, 0.16); }

/* Data: two waves */
.data-icon { border-radius: 6px; }
.data-icon.status-live { color: #089981; background: rgba(8, 153, 129, 0.16); }
.data-icon.status-delayed { color: #c2185b; background: rgba(194, 24, 91, 0.13); }
.data-icon.status-unavailable { color: #f23645; background: rgba(242, 54, 69, 0.13); }
.data-icon.status-simulated { color: #e65100; background: rgba(255, 152, 0, 0.2); }

.legend-status-icons:hover .status-icon,
.legend-status-icons:focus .status-icon { filter: brightness(0.95); box-shadow: 0 0 0 1px currentColor inset; }

/* Card opened from the icons */
.legend-status-popover {
  display: none;
  position: fixed;
  z-index: 3000;
  width: 330px;
  max-width: calc(100vw - 16px);
  background: var(--bg-panel);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  font-family: var(--font-main);
  font-size: 13px;
  line-height: 1.55;
}

.legend-status-popover .sp-section {
  padding: 14px 16px;
}

.legend-status-popover .sp-section + .sp-section {
  border-top: 1px solid var(--border-color);
}

.legend-status-popover .sp-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 6px;
}
.sp-title.phase-open,
.sp-title.data-live { color: #089981; }
.sp-title.phase-pre,
.sp-title.phase-post { color: #e65100; }
.sp-title.phase-closed { color: var(--text-secondary); }
.sp-title.data-delayed { color: #c2185b; }
.sp-title.data-unavailable { color: #f23645; }
.sp-title.data-simulated { color: #e65100; }

.legend-status-popover .sp-text {
  color: var(--text-primary);
}

.legend-status-popover .sp-timeline {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 16px;
}

.legend-status-popover .sp-day {
  font-size: 11px;
  line-height: 6px; /* Centred on the track */
  color: var(--text-secondary);
  flex-shrink: 0;
}

.legend-status-popover .sp-col {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.legend-status-popover .sp-track {
  position: relative;
  height: 6px;
  border-radius: 3px;
  background: var(--bg-tertiary);
}

.legend-status-popover .sp-seg {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: 3px;
}
.sp-seg.seg-open { background: #089981; }
.sp-seg.seg-ext { background: rgba(255, 152, 0, 0.55); }

.legend-status-popover .sp-now {
  position: absolute;
  top: -5px;
  bottom: -5px;
  width: 2px;
  margin-right: -1px;
  background: var(--text-primary);
  border-radius: 1px;
}

.legend-status-popover .sp-scale {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 6px;
}

.legend-status-popover .sp-note {
  font-size: 11.5px;
  color: var(--text-secondary);
  margin-top: 10px;
  text-align: center;
}

.legend-symbol-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 3px;
  background: #089981;
  color: #ffffff;
  font-size: 9px;
  flex-shrink: 0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.legend-symbol-text {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-primary);
  white-space: nowrap;
}

.legend-symbol-dot {
  color: var(--text-secondary);
  font-size: 11px;
}

.legend-symbol-flag {
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  padding: 0 1px;
  transition: color 0.15s ease;
}

.legend-symbol-flag:hover,
.legend-symbol-flag.flagged {
  color: #f23645;
}

.legend-symbol-dots-btn {
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  letter-spacing: -0.5px;
  padding: 0 3px;
  border-radius: 3px;
  font-weight: 800;
  transition: all 0.15s ease;
}

.legend-symbol-dots-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

/* Data Strip: Volume, Change, and OHLC */
.legend-data-strip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: -apple-system, BlinkMacSystemFont, 'JetBrains Mono', 'Segoe UI', Roboto, monospace;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.legend-vol-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.legend-vol-val {
  font-weight: 700;
}

.legend-vol-label {
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Trebuchet MS', Roboto, Ubuntu, sans-serif;
  font-size: 11.5px;
  font-weight: 600;
}

.legend-change-val {
  font-weight: 700;
}

.legend-ohlc-item {
  display: inline-flex;
  align-items: baseline;
  font-weight: 700;
}

.legend-ohlc-letter {
  font-weight: 800;
  font-size: 11px;
  margin-left: 1px;
}

/* ==========================================================================
   TradingView Price Scale Context Menu (RTL Light Theme)
   ========================================================================== */
.tv-context-menu {
  position: fixed;
  z-index: 999999;
  min-width: 260px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12), 0 1px 3px rgba(0, 0, 0, 0.08);
  padding: 5px 0;
  user-select: none;
  font-family: -apple-system, BlinkMacSystemFont, 'Trebuchet MS', Roboto, 'Segoe UI', sans-serif;
  direction: rtl;
  text-align: right;
  color: var(--text-primary);
  box-sizing: border-box;
}

.tv-context-item {
  position: relative;
  height: 32px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: background 0.1s ease;
  box-sizing: border-box;
}

.tv-context-item:hover {
  background-color: var(--bg-hover);
}

.tv-context-item:active {
  background-color: var(--bg-hover);
}

.tv-context-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  overflow: hidden;
}

.tv-context-slot {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-primary);
}

.tv-context-slot.check-slot {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
}

.tv-context-label {
  font-size: 13px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tv-context-left {
  display: flex;
  align-items: center;
  margin-right: 12px;
  flex-shrink: 0;
}

.tv-context-shortcut {
  font-size: 11.5px;
  color: var(--text-secondary);
  direction: ltr;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  letter-spacing: 0.2px;
}

.tv-context-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.tv-context-divider {
  height: 1px;
  background-color: var(--bg-pressed);
  margin: 4px 0;
}

/* Submenus */
.tv-context-submenu {
  display: none;
  position: absolute;
  top: -5px;
  right: 100%;
  min-width: 220px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12), 0 1px 3px rgba(0, 0, 0, 0.08);
  padding: 5px 0;
  z-index: 1000000;
  box-sizing: border-box;
}

.tv-context-item.has-submenu:hover > .tv-context-submenu {
  display: block;
}

.tv-context-submenu.flip-left {
  right: auto;
  left: 100%;
}

