/**
 * @file
 * Styling for charts and data visualizations in EV Regional Analysis module.
 * 
 * Includes Chart.js customizations, responsive chart containers, 
 * and custom chart elements.
 */

/* =============================================================================
   Chart Containers
   ========================================================================== */

.charts-section {
  margin: 3rem 0;
  padding: 0;
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 2rem;
  margin-top: 2rem;
}

.chart-container {
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 1px 3px rgba(0, 0, 0, 0.08);
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.chart-container:hover {
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15), 0 3px 6px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
}

.chart-container h3 {
  margin: 0 0 1.5rem 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: #2c3e50;
  text-align: center;
  border-bottom: 2px solid #17D377;
  padding-bottom: 0.75rem;
}

.chart-wrapper {
  position: relative;
  height: 400px;
  margin: 1rem 0;
}

.chart-wrapper canvas {
  max-height: 100%;
  width: 100% !important;
  height: auto !important;
}

/* Chart loading state */
.chart-container.loading {
  opacity: 0.7;
  pointer-events: none;
}

.chart-container.loading::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border: 3px solid #f3f3f3;
  border-top: 3px solid #17D377;
  border-radius: 50%;
  animation: chartSpin 1s linear infinite;
  z-index: 10;
}

@keyframes chartSpin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* =============================================================================
   Chart Notes and Labels
   ========================================================================== */

.chart-note {
  font-size: 0.85rem;
  color: #6c757d;
  font-style: italic;
  text-align: center;
  margin-top: 1rem;
  padding: 0.5rem;
  background: rgba(108, 117, 125, 0.1);
  border-radius: 6px;
  border-left: 3px solid #6c757d;
}

.chart-description {
  font-size: 0.9rem;
  color: #495057;
  margin-bottom: 1rem;
  line-height: 1.5;
}

.chart-source {
  font-size: 0.8rem;
  color: #868e96;
  text-align: right;
  margin-top: 0.5rem;
  font-style: italic;
}

.chart-source::before {
  content: "Zdroj: ";
  font-weight: 500;
}

/* =============================================================================
   Chart Controls
   ========================================================================== */

.chart-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: #f8f9fa;
  border-radius: 8px;
  border: 1px solid #dee2e6;
}

.chart-controls label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: #495057;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  transition: background-color 0.2s ease;
}

.chart-controls label:hover {
  background-color: rgba(23, 211, 119, 0.1);
}

.chart-controls input[type="checkbox"],
.chart-controls input[type="radio"] {
  width: 16px;
  height: 16px;
  accent-color: #17D377;
  cursor: pointer;
}

.chart-controls select {
  padding: 0.375rem 0.75rem;
  border: 1px solid #ced4da;
  border-radius: 4px;
  background-color: #fff;
  font-size: 0.9rem;
  color: #495057;
  cursor: pointer;
}

.chart-controls select:focus {
  outline: none;
  border-color: #17D377;
  box-shadow: 0 0 0 2px rgba(23, 211, 119, 0.25);
}

/* Chart control buttons */
.chart-btn {
  background: #17D377;
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.chart-btn:hover {
  background: #14b866;
  transform: translateY(-1px);
}

.chart-btn:active {
  transform: translateY(0);
}

.chart-btn.secondary {
  background: #6c757d;
}

.chart-btn.secondary:hover {
  background: #5a6268;
}

/* =============================================================================
   Chart Types Specific Styling
   ========================================================================== */

/* Pie and Doughnut Charts */
.chart-container.pie-chart,
.chart-container.doughnut-chart {
  text-align: center;
}

.chart-container.pie-chart .chart-wrapper,
.chart-container.doughnut-chart .chart-wrapper {
  height: 350px;
}

/* Bar Charts */
.chart-container.bar-chart .chart-wrapper {
  height: 450px;
}

/* Line Charts */
.chart-container.line-chart .chart-wrapper {
  height: 400px;
}

/* Scatter Charts */
.chart-container.scatter-chart .chart-wrapper {
  height: 500px;
}

/* Bubble Charts */
.chart-container.bubble-chart .chart-wrapper {
  height: 600px;
}

/* =============================================================================
   Chart Legends
   ========================================================================== */

.custom-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1rem;
  margin: 1rem 0;
  padding: 1rem;
  background: #f8f9fa;
  border-radius: 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: #495057;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  transition: background-color 0.2s ease;
}

.legend-item:hover {
  background-color: rgba(23, 211, 119, 0.1);
}

.legend-item.disabled {
  opacity: 0.5;
  text-decoration: line-through;
}

.legend-color {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

/* =============================================================================
   Chart Tooltips (Custom)
   ========================================================================== */

.custom-chart-tooltip {
  background: rgba(0, 0, 0, 0.9);
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: 6px;
  font-size: 0.85rem;
  line-height: 1.4;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  pointer-events: none;
  z-index: 1000;
  max-width: 250px;
}

.custom-chart-tooltip::before {
  content: '';
  position: absolute;
  bottom: -5px;
  left: 50%;
  margin-left: -5px;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid rgba(0, 0, 0, 0.9);
}

.tooltip-title {
  font-weight: 600;
  margin-bottom: 0.25rem;
  color: #17D377;
}

.tooltip-body {
  font-size: 0.8rem;
}

.tooltip-value {
  font-weight: 600;
  color: #fff;
}

/* =============================================================================
   Chart Error States
   ========================================================================== */

.chart-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 300px;
  color: #6c757d;
  text-align: center;
  padding: 2rem;
}

.chart-error-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.chart-error-message {
  font-size: 1.1rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
}

.chart-error-details {
  font-size: 0.9rem;
  color: #868e96;
}

.chart-retry-btn {
  margin-top: 1rem;
  background: #17D377;
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}

.chart-retry-btn:hover {
  background: #14b866;
}

/* =============================================================================
   Chart Data Labels
   ========================================================================== */

.chart-data-label {
  font-size: 11px;
  font-weight: 600;
  fill: #2c3e50;
  text-anchor: middle;
  pointer-events: none;
}

.chart-data-label.light {
  fill: #fff;
}

.chart-data-label.small {
  font-size: 9px;
}

/* =============================================================================
   Chart Comparison Grid
   ========================================================================== */

.chart-comparison {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin: 2rem 0;
}

.chart-comparison .chart-container {
  margin: 0;
}

.chart-comparison-title {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: linear-gradient(135deg, #f8f9fa, #e9ecef);
  border-radius: 8px;
}

/* =============================================================================
   Chart Export Controls
   ========================================================================== */

.chart-export {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: flex;
  gap: 0.5rem;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.chart-container:hover .chart-export {
  opacity: 1;
}

.chart-export-btn {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(0, 0, 0, 0.1);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.chart-export-btn:hover {
  background: #17D377;
  color: white;
  border-color: #17D377;
}

/* =============================================================================
   Chart Responsive Design
   ========================================================================== */

@media (max-width: 1200px) {
  .charts-grid {
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 1.5rem;
  }
  
  .chart-comparison {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
}

@media (max-width: 768px) {
  .charts-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  
  .chart-container {
    padding: 1rem;
    margin: 0 0 1rem 0;
  }
  
  .chart-wrapper {
    height: 300px;
  }
  
  .chart-container.bubble-chart .chart-wrapper,
  .chart-container.scatter-chart .chart-wrapper {
    height: 400px;
  }
  
  .chart-controls {
    flex-direction: column;
    gap: 0.5rem;
  }
  
  .custom-legend {
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
  }
  
  .chart-export {
    position: static;
    opacity: 1;
    justify-content: center;
    margin-top: 1rem;
  }
}

@media (max-width: 480px) {
  .chart-container {
    padding: 0.75rem;
    border-radius: 8px;
  }
  
  .chart-wrapper {
    height: 250px;
  }
  
  .chart-container h3 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
  }
  
  .chart-note {
    font-size: 0.8rem;
    padding: 0.4rem;
  }
}

/* =============================================================================
   Chart Animation Classes
   ========================================================================== */

.chart-fade-in {
  opacity: 0;
  transform: scale(0.95);
  animation: chartFadeIn 0.6s ease forwards;
}

@keyframes chartFadeIn {
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.chart-slide-up {
  opacity: 0;
  transform: translateY(30px);
  animation: chartSlideUp 0.8s ease forwards;
}

@keyframes chartSlideUp {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Chart hover effects */
.chart-hover-effect {
  transition: all 0.3s ease;
}

.chart-hover-effect:hover {
  transform: scale(1.02);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
}

/* =============================================================================
   Print Styles for Charts
   ========================================================================== */

@media print {
  .charts-section {
    break-inside: avoid;
    page-break-inside: avoid;
  }
  
  .chart-container {
    break-inside: avoid;
    page-break-inside: avoid;
    box-shadow: none;
    border: 1px solid #000;
    margin-bottom: 1cm;
  }
  
  .chart-controls,
  .chart-export {
    display: none;
  }
  
  .chart-wrapper {
    height: auto !important;
    min-height: 300px;
  }
  
  .charts-grid {
    grid-template-columns: 1fr;
    gap: 1cm;
  }
  
  .chart-comparison {
    grid-template-columns: 1fr;
    gap: 0.5cm;
  }
}