/**
 * Unified Chart Styling
 * Professional chart theme with cohesive visuals across all D3 charts
 */

/* Chart Container */
.chart-container {
  position: relative;
  width: 100%;
  min-height: 450px;
  overflow: hidden;
}

/* SVG Base Styles */
.chart-container svg {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Grid Lines - Unified Style */
.chart-container .grid-line-y,
.chart-container .grid-line-x {
  stroke: var(--border-subtle, #2a2a2d);
  stroke-width: 1px;
  stroke-dasharray: 2, 2;
  opacity: 0.3;
  shape-rendering: crispEdges;
}

/* Axes - Unified Style */
.chart-container .x-axis path.domain,
.chart-container .y-axis path.domain,
.chart-container .y-axis-price path.domain {
  stroke: var(--border-default, #444);
  stroke-width: 1px;
}

.chart-container .x-axis line,
.chart-container .y-axis line,
.chart-container .y-axis-price line {
  stroke: var(--border-default, #444);
  stroke-width: 1px;
}

.chart-container .x-axis text,
.chart-container .y-axis text {
  fill: var(--text-secondary, #9ca3af);
  font-size: 11px;
  font-weight: 500;
}

/* Right-side price axis - muted */
.chart-container .y-axis-price text {
  fill: var(--text-tertiary, #6b7280);
  font-size: 10px;
  font-weight: 400;
  opacity: 0.7;
}

.chart-container .y-axis-price path.domain,
.chart-container .y-axis-price line {
  stroke: var(--border-subtle, #2a2a2d);
  opacity: 0.5;
}

/* Axis Labels */
.chart-container .axis-label {
  fill: var(--text-primary, #f3f4f6);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.025em;
}

.chart-container .axis-label-price {
  fill: var(--text-tertiary, #6b7280);
  font-size: 11px;
  font-weight: 500;
  opacity: 0.8;
}

/* Line Charts - Area Shadow/Glow */
.chart-container .area-with-shadow {
  filter: drop-shadow(0 2px 8px rgba(124, 77, 255, 0.15));
}

.chart-container .line-with-glow {
  filter: drop-shadow(0 1px 4px rgba(124, 77, 255, 0.3));
}

/* Bar Charts - Subtle Depth */
.chart-container .bar-buy,
.chart-container .bar-sell {
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
  transition: opacity 150ms ease-out, filter 150ms ease-out;
}

.chart-container .bar-buy:hover,
.chart-container .bar-sell:hover {
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

/* Legend - Unified Style */
.chart-container .legend {
  font-size: 11px;
  font-weight: 500;
}

.chart-container .legend text {
  fill: var(--text-primary, #f3f4f6);
}

.chart-container .legend rect,
.chart-container .legend circle {
  transition: opacity 150ms ease-out;
}

.chart-container .legend-item {
  cursor: pointer;
}

.chart-container .legend-item:hover text {
  fill: var(--accent-400, #a78bfa);
}

/* Crosshair */
.chart-container .crosshair-line-x,
.chart-container .crosshair-line-y {
  stroke: var(--accent-400, #a78bfa);
  stroke-width: 1px;
  stroke-dasharray: 4, 4;
  opacity: 0.7;
  shape-rendering: crispEdges;
}

.chart-container .crosshair-dot {
  fill: var(--accent-500, #7c3aed);
  stroke: white;
  stroke-width: 2px;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.3));
}

/* Tooltips - Unified Style */
.volume-chart-tooltip,
.count-chart-tooltip,
.price-tooltip {
  position: absolute;
  background: var(--surface-overlay, rgba(28, 28, 31, 0.98));
  border: 1px solid var(--border-default, #444);
  border-radius: 8px;
  padding: 12px;
  pointer-events: none;
  z-index: 10000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  font-size: 13px;
  line-height: 1.5;
  backdrop-filter: blur(8px);
  transition: opacity 150ms ease-out;
}

/* Loading State - Skeleton */
.chart-skeleton {
  width: 100%;
  height: 450px;
  background: linear-gradient(
    90deg,
    var(--surface-hover, #1a1a1c) 25%,
    var(--surface-raised, #18181b) 50%,
    var(--surface-hover, #1a1a1c) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 2s infinite;
  border-radius: 8px;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* Error State */
.chart-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  padding: 3rem;
  text-align: center;
}

.chart-error-icon {
  font-size: 3rem;
  color: var(--warning-400, #fbbf24);
  margin-bottom: 1rem;
}

.chart-error-message {
  color: var(--text-secondary, #9ca3af);
  font-size: 1rem;
  margin-bottom: 0.5rem;
}

.chart-error-detail {
  color: var(--text-tertiary, #6b7280);
  font-size: 0.875rem;
}

/* Semantic Colors - Fixed (Never Themed) */
.chart-container .buy-color {
  fill: #10b981 !important;
  stroke: #10b981 !important;
}

.chart-container .sell-color {
  fill: #ef4444 !important;
  stroke: #ef4444 !important;
}

/* Text color utilities for buy/sell */
.text-buy-color {
  color: #10b981 !important;
}

.text-sell-color {
  color: #ef4444 !important;
}

.bg-buy-color {
  background-color: #10b981 !important;
}

.bg-sell-color {
  background-color: #ef4444 !important;
}

/* Party Colors - Fixed (Never Themed) */
.chart-container .democrat-color {
  fill: #3b82f6 !important;
  stroke: #3b82f6 !important;
}

.chart-container .republican-color {
  fill: #ef4444 !important;
  stroke: #ef4444 !important;
}

.chart-container .independent-color {
  fill: #8b5cf6 !important;
  stroke: #8b5cf6 !important;
}

/* Chart Controls */
.chart-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
  padding: 0 1rem;
}

.chart-controls button {
  padding: 0.375rem 0.75rem;
  background: var(--surface-raised, #18181b);
  border: 1px solid var(--border-default, #444);
  border-radius: 0.375rem;
  color: var(--text-secondary, #9ca3af);
  font-size: 0.875rem;
  transition: all 150ms ease-out;
  cursor: pointer;
}

.chart-controls button:hover:not(:disabled) {
  background: var(--surface-hover, #1a1a1c);
  color: var(--text-primary, #f3f4f6);
  border-color: var(--border-emphasis, #666);
}

.chart-controls button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.chart-controls-hint {
  font-size: 0.75rem;
  color: var(--text-tertiary, #6b7280);
  margin-left: auto;
}

/* Zoom Overlay */
.chart-container .zoom-overlay {
  cursor: grab;
}

.chart-container .zoom-overlay:active {
  cursor: grabbing;
}

/* Responsive Adjustments */
@media (max-width: 640px) {
  .chart-container {
    min-height: 350px;
  }

  .chart-container .axis-label {
    font-size: 11px;
  }

  .chart-container .legend {
    font-size: 10px;
  }

  .chart-controls {
    flex-wrap: wrap;
  }

  .chart-controls-hint {
    width: 100%;
    margin-left: 0;
    margin-top: 0.5rem;
    text-align: center;
  }
}

/* Print Styles */
@media print {
  .chart-container {
    break-inside: avoid;
  }

  .chart-controls {
    display: none;
  }

  .chart-container .crosshair {
    display: none;
  }

  .volume-chart-tooltip,
  .count-chart-tooltip,
  .price-tooltip {
    display: none;
  }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
  .chart-container .grid-line-y,
  .chart-container .grid-line-x {
    opacity: 0.5;
  }

  .chart-container .x-axis text,
  .chart-container .y-axis text,
  .chart-container .y-axis-price text {
    font-weight: 600;
  }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  .chart-container *,
  .volume-chart-tooltip,
  .count-chart-tooltip,
  .price-tooltip {
    transition: none !important;
    animation: none !important;
  }

  .chart-skeleton {
    animation: none;
    background: var(--surface-hover, #1a1a1c);
  }
}

/* D3 Brush Styles */
.brush .overlay {
  fill: transparent;
  pointer-events: all;
  cursor: crosshair;
}

.brush .selection {
  fill: var(--chart-primary, #7c4dff);
  fill-opacity: 0.2;
  stroke: var(--chart-primary, #7c4dff);
  stroke-width: 2px;
  stroke-opacity: 0.6;
  shape-rendering: crispEdges;
}

.brush .handle {
  fill: var(--chart-primary, #7c4dff);
  fill-opacity: 0.8;
  stroke: var(--chart-primary, #7c4dff);
  stroke-width: 1px;
  cursor: ew-resize;
}

/* Brush Minimap Specific Styles */
.brush-minimap {
  position: relative;
  overflow: hidden;
}

.brush-minimap .brush .selection {
  fill: rgba(124, 77, 255, 0.25);
  stroke: #7c4dff;
  stroke-width: 2px;
}

.brush-minimap .brush .handle {
  fill: #7c4dff;
  width: 6px;
}

.brush-minimap .minimap-area {
  opacity: 0.4;
}

.brush-minimap .minimap-line {
  opacity: 0.8;
}
