/* Legend Panel Styles */

.legend-panel {
  position: fixed;
  right: var(--spacing-md);
  bottom: var(--spacing-md);
  width: var(--panel-width-narrow);
  background: var(--bg-panel-executive);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--exec-shadow);
  z-index: var(--z-panel);
  display: flex;
  flex-direction: column;
  max-height: var(--panel-height-standard);
  min-width: var(--panel-width-narrow);
  max-width: var(--panel-width-standard);
  transition: all var(--duration-professional) var(--ease-professional);
  padding: var(--executive-panel-padding);
}

/* Legend Header */
.legend-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-sm, 8px) var(--spacing-md, 12px);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
  border-radius: var(--border-radius-md, 8px) var(--border-radius-md, 8px) 0 0;
  cursor: move;
  user-select: none;
}

.legend-header .header-main {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs, 4px);
}

.legend-header .header-icon {
  font-size: var(--text-base);
}

.legend-header h3 {
  margin: 0;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
}

.legend-header .header-controls {
  display: flex;
  gap: var(--spacing-xs, 4px);
}

/* Legend Content */
.legend-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--spacing-sm, 8px);
  min-height: 50px;
}

.legend-items {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs, 4px);
}

/* Legend Item - Professional Data Visualization */
.legend-item {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--radius-md);
  transition: var(--transition-professional);
  background: var(--data-highlight-bg);
  border: 1px solid transparent;
}

.legend-item:hover {
  background: var(--data-hover-bg);
  border-color: var(--chart-highlight);
  transform: var(--hover-elevation);
  box-shadow: var(--chart-shadow-sm);
}

/* Legend Swatch - Professional Chart Series */
.legend-swatch {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--glass-border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  box-shadow: var(--chart-shadow-sm);
  transition: var(--transition-micro);
}

.legend-item:hover .legend-swatch {
  transform: scale(1.1);
  box-shadow: var(--chart-glow);
}

/* Legend Label - Professional Data Typography */
.legend-label {
  font-size: var(--text-sm);
  color: var(--text-primary);
  font-weight: var(--font-weight-professional);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: var(--letter-spacing-normal);
  line-height: var(--line-height-professional);
}

.legend-item:hover .legend-label {
  color: var(--chart-highlight);
  font-weight: var(--font-weight-executive);
}

/* Empty State */
.legend-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-style: italic;
  padding: var(--spacing-md, 12px);
}

/* Collapse Button */
.legend-collapse-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: var(--spacing-xs, 4px);
  font-size: var(--text-xs);
  transition: all var(--duration-fast) var(--ease-out);
  border-radius: var(--border-radius-sm, 4px);
}

.legend-collapse-btn:hover {
  background: var(--bg-surface);
  color: var(--text-primary);
}

/* Collapsed State */
.legend-panel.collapsed {
  width: 120px;
  height: 40px;
  flex-direction: row;
  align-items: center;
}

.legend-panel.collapsed .legend-content {
  display: none;
}

.legend-panel.collapsed .legend-header {
  flex-direction: row;
  padding: var(--spacing-xs, 4px) var(--spacing-sm, 8px);
  border-bottom: none;
  border-radius: var(--border-radius-md, 8px);
  width: 100%;
  justify-content: space-between;
}

.legend-panel.collapsed .header-main {
  flex-direction: row;
  gap: var(--spacing-xs, 4px);
}

.legend-panel.collapsed .header-icon {
  font-size: var(--text-sm);
}

.legend-panel.collapsed h3 {
  font-size: var(--text-sm);
  white-space: nowrap;
}

.legend-panel.collapsed .header-controls {
  position: static;
  transform: none;
}

.legend-panel.collapsed .legend-collapse-btn {
  font-size: var(--text-xs);
  padding: var(--spacing-xs);
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
  .legend-panel {
    width: 200px;
    max-height: 200px;
    left: 5px;
    bottom: 80px;
  }
  
  .legend-panel.collapsed {
    width: 100px;
    bottom: 80px;
  }
}

/* High Contrast Theme */
[data-high-contrast="true"] .legend-panel {
  border-color: var(--border-primary);
  box-shadow: var(--shadow-md);
}

[data-high-contrast="true"] .legend-swatch {
  border-width: 2px;
  border-color: var(--border-primary);
}

/* Animations */
.legend-panel {
  animation: legendSlideIn 200ms ease;
}

@keyframes legendSlideIn {
  from {
    opacity: 0;
    transform: translateX(10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  .legend-panel {
    transition: none;
    animation: none;
  }
  
  .legend-item {
    transition: none;
  }
  
  .legend-collapse-btn {
    transition: none;
  }
}