/* ===============================
   COMPONENTES REUTILIZABLES SNP
   =============================== */

/* BOTONES BASE */
.btn-base {
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: #28a745;
  color: white;
}

.btn-primary:hover {
  background: #218838;
  color: white;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(40, 167, 69, 0.3);
}

.btn-danger {
  background: #e74c3c;
  color: white;
}

.btn-danger:hover {
  background: #c0392b;
}

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

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

/* BOTONES ESPECÍFICOS DE CHARTS */
.btn-view-measure {
  background: #28a745;
  color: white;
  text-decoration: none;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
}

.btn-view-measure:hover {
  background: #218838;
  color: white;
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(40, 167, 69, 0.3);
}

.btn-clear-selection {
  background: #e74c3c;
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background-color 0.2s;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-clear-selection:hover {
  background: #c0392b;
}

.btn-regions, .btn-reset {
  background: #007bff;
  color: white;
  border: none;
  padding: 0.375rem 0.75rem;
  border-radius: 4px;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background-color 0.2s;
}

.btn-regions:hover, .btn-reset:hover {
  background: #0056b3;
}

.btn-regions-sm, .btn-reset-sm {
  background: #007bff;
  color: white;
  border: none;
  padding: 0.25rem 0.5rem;
  border-radius: 3px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background-color 0.2s;
}

.btn-regions-sm:hover, .btn-reset-sm:hover {
  background: #0056b3;
}

/* SECCIONES DE CHART */
.chart-title-section {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: #f8f9fa;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  gap: 2rem;
}

.chart-title-content {
  flex: 1;
}

.chart-title-content .title--slab {
  margin: 0 0 0.5rem 0;
  color: #2c3e50;
  font-size: 1.5rem;
}

.chart-subtitle {
  margin: 0;
  color: #6c757d;
  font-size: 0.95rem;
  font-style: italic;
}

.chart-title-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-shrink: 0;
}

.chart-component {
  width: 100%;
  height: 100%;
}

.chart-container {
  position: relative;
  background: white;
  border: 1px solid #e1e8ed;
  border-radius: 8px;
  padding: 1.5rem;
  border-radius: var(--border-radius-s);
}

.chart-internal-filters {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding: 1rem;
  background: #f8f9fa;
  border: 1px solid #e1e8ed;
  border-radius: 6px;
  gap: 1rem;
}

.chart-canvas {
  width: 100%;
  height: 500px;
  min-height: 500px;
}

.chart-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 500px;
  color: #6c757d;
  font-size: 1.1rem;
  gap: 0.5rem;
}

.chart-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.1);
  z-index: 10;
}

/* SECCIONES DE MEDIDAS/ESCENARIOS */
.medidas-chart-section {
  display: flex;
  gap: 2rem;
  margin-top: 1.5rem;
  min-height: 600px;
}

.medidas-sidebar {
  flex: 0 0 350px;
  background: #f8f9fa;
  border-radius: 8px;
  padding: 1.5rem;
  overflow-y: auto;
  max-height: 600px;
}

.medidas-chart-container {
  flex: 1;
  background: white;
  border: 1px solid #e1e8ed;
  border-radius: 8px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
}

.medidas-chart {
  width: 100%;
  height: 500px;
  min-height: 500px;
}

/* SIDEBAR GENÉRICO */
.sidebar-header {
  margin-bottom: 1.5rem;
}

.sidebar-title {
  margin: 0 0 0.5rem 0;
  color: #2c3e50;
  font-size: 1.25rem;
  font-weight: 600;
  border-bottom: 2px solid #3498db;
  padding-bottom: 0.5rem;
}

.selection-counter {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.5rem;
  padding: 0.5rem;
  background: #e8f4f8;
  border-radius: 4px;
  font-size: 0.875rem;
}

.counter-text {
  color: #2c3e50;
  font-weight: 500;
}

.limit-reached {
  color: #e74c3c;
  font-weight: 600;
  font-size: 0.75rem;
  background: #ffebee;
  padding: 0.2rem 0.5rem;
  border-radius: 3px;
}

/* BADGES DE MEDIDAS SELECCIONADAS */
.selected-measures-list {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.5rem;
  margin-top: 1rem;
}

.selected-measure-badge {
  background: #28a745;
  color: white;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  min-height: 36px;
}

.selected-measure-badge--clickable {
  cursor: pointer;
  transition: all 0.2s ease;
  gap: 0.3rem;
}

.selected-measure-badge--clickable:hover {
  background: #218838;
  color: white;
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(40, 167, 69, 0.3);
}

.selected-measure-badge--clickable i {
  font-size: 0.6rem;
  opacity: 0.8;
}

/* CARDS COMPACTAS PARA MÚLTIPLES MEDIDAS */
.selected-measure-card {
  display: flex;
  align-items: center;
  background: #28a745;
  border-radius: 6px;
  overflow: hidden;
  min-height: 40px;
  margin: 0;
  padding: 0;
  gap: 0;
}

/* Link clickeable con icono y texto */
.measure-card-link {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  color: white;
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.2s;
}

.measure-card-link:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
  text-decoration: none;
}

.measure-card-link i {
  font-size: 0.75rem;
  opacity: 0.9;
}

/* Botón X pequeño y rojo suave */
.btn-card-remove {
  width: 32px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-left: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 0;
  border-top-right-radius: 6px;
  border-bottom-right-radius: 6px;
  background: rgba(220, 53, 69, 0.3);
  color: white;
  cursor: pointer;
  transition: background 0.2s;
  padding: 0;
}

.btn-card-remove:hover {
  background: rgba(220, 53, 69, 0.7);
  color: white;
}

.btn-card-remove i {
  font-size: 0.75rem;
}

/* BOTÓN LIMPIAR TODAS LAS SELECCIONES */
.clear-selection-container {
  display: flex;
  justify-content: center;
  margin: 1.5rem 0;
}

.btn-clear-all-selection {
  background: #e74c3c;
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-clear-all-selection:hover {
  background: #c0392b;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(231, 76, 60, 0.3);
}

.btn-clear-all-selection i {
  font-size: 0.8rem;
}

/* SEPARADORES ENTRE MEDIDAS */
.measure-divider {
  height: 1px;
  background: #e9ecef;
  margin: 0.25rem 0.5rem;
  opacity: 0.6;
}

/* CARDS BAJO TÍTULO EMISIONES */
.selected-measures-under-title {
  margin-top: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.measures-by-sector {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* GRUPOS DE SECTORES */
.sector-group {
  border: 1px solid #e1e8ed;
  border-radius: 8px;
  background: white;
  margin-bottom: 1rem;
  overflow: hidden;
}

.sector-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  background: #f8f9fa;
  border-bottom: 1px solid #e1e8ed;
  font-weight: 600;
  color: #2c3e50;
}

.sector-header i {
  width: 18px;
  text-align: center;
  font-size: 1.1rem;
}

.sector-name {
  flex: 1;
}

.sector-count {
  font-size: 0.875rem;
  color: #6c757d;
  font-weight: 400;
}

.sector-toggle {
  margin-left: auto;
  color: #6c757d;
  font-size: 0.75rem;
  transition: transform 0.2s ease, color 0.2s ease;
}

.sector-header:hover .sector-toggle {
  color: #2c3e50;
}

.sector-header:hover {
  background-color: #f8f9fa;
  border-radius: 4px;
}

/* LISTAS DE MEDIDAS */
.measures-list {
  padding: 0.75rem;
}

.measure-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  cursor: pointer;
  border-radius: 4px;
  margin: 0;
  font-size: 0.9rem;
  transition: all 0.2s ease;
  position: relative;
}

.measure-item:hover:not(.measure-item--disabled) {
  background: #f8f9fa;
}

.measure-item--selected {
  background: #e8f5e8;
  border: 1px solid #28a745;
  color: #155724;
  font-weight: 500;
}

.measure-item--disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: #f8f9fa;
}

.measure-item--disabled span {
  color: #6c757d;
}

.measure-selected-icon {
  color: #28a745;
  font-size: 0.8rem;
  margin-left: auto;
}

.measure-item input[type="checkbox"],
.measure-item input[type="radio"] {
  margin: 0;
  width: 14px;
  height: 14px;
}

.measure-item input[type="checkbox"]:disabled {
  cursor: not-allowed;
}

.loading-measures {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem;
  color: #6c757d;
  font-style: italic;
}

/* GRILLAS DE MEDIDAS */
.measures-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.measure-card {
  background: #f8f9fa;
  border: 1px solid #e9ecef;
  border-radius: 6px;
  padding: 1rem;
  transition: all 0.3s ease;
  opacity: 0;
  transform: translateY(20px);
  animation: fadeInUp 0.4s ease forwards;
}

.measure-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 25px rgba(0,0,0,0.15);
  border-color: #3498db;
}

.measure-title {
  margin: 0 0 0.75rem 0;
  font-size: 1rem;
  font-weight: 600;
  color: #2c3e50;
  line-height: 1.3;
}

.measure-description {
  margin: 0 0 1rem 0;
  font-size: 0.875rem;
  color: #5a6c7d;
  line-height: 1.4;
}

.measure-link {
  color: #3498db;
  text-decoration: none;
  font-weight: 500;
  font-size: 0.875rem;
  transition: color 0.2s;
}

.measure-link:hover {
  color: #2980b9;
  text-decoration: underline;
}

.measure-meta {
  margin: 0.5rem 0 1rem 0;
}

.measure-category {
  display: inline-block;
  background: #e3f2fd;
  color: #1976d2;
  padding: 0.25rem 0.5rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.measure-link-accordion {
  color: #3498db;
  text-decoration: none;
  font-size: 0.9rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid #f1f3f4;
  transition: all 0.2s ease;
  display: block;
}

.measure-link-accordion:hover {
  color: #2980b9;
  text-decoration: underline;
  padding-left: 0.5rem;
  background: #f8f9fa;
}

/* ACORDEONES - Usar estilos base de style.css pero personalizar */
.accordion-button .first {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 150px;
}

.accordion-button .first i {
  font-size: 1.5rem;
  width: 24px;
  text-align: center;
}

.accordion-button .title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.accordion-button .subtitle {
  margin: 0 0 0.25rem 0;
  font-size: 0.75rem;
  font-weight: 600;
  color: #6c757d;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.accordion-button .text {
  margin: 0;
  font-size: 0.9rem;
  color: #495057;
}

.accordion-body {
  padding: 1.5rem;
  background: white;
  border: 1px solid #e5e7eb;
  border-top: none;
  border-radius: 0 0 8px 8px;
}

.category-group {
  margin-bottom: 2rem;
}

.category-title {
  margin: 0 0 1rem 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: #2c3e50;
  border-bottom: 2px solid #3498db;
  padding-bottom: 0.5rem;
}

.measures-links {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* COLORES DE SECTORES */
.icon--energia { color: var(--focus-color); }
.icon--agricultura { color: var(--green-500); }
.icon--ippu { color: var(--info-500); }
.icon--utcuts { color: var(--warning-500); }
.icon--residuos { color: var(--dark-500); }

/* ANIMACIONES */
.loading-measures i,
.loading-sector-measures i,
.chart-loading i {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes fadeIn {
  to { opacity: 1; }
}

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

/* DELAYS ESCALONADOS PARA CARDS */
.measure-card:nth-child(1) { animation-delay: 0.1s; }
.measure-card:nth-child(2) { animation-delay: 0.2s; }
.measure-card:nth-child(3) { animation-delay: 0.3s; }
.measure-card:nth-child(4) { animation-delay: 0.4s; }
.measure-card:nth-child(5) { animation-delay: 0.5s; }
.measure-card:nth-child(n+6) { animation-delay: 0.6s; }

.loading-sector-measures {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 2rem;
  color: #6c757d;
  font-style: italic;
  opacity: 0;
  animation: fadeIn 0.3s ease forwards;
}

/* FILTROS DE CHART */
.filters-left, .filters-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.filter-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: #6c757d;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.filter-select, .filter-select-sm {
  padding: 0.375rem 0.75rem;
  border: 1px solid #ced4da;
  border-radius: 4px;
  background: white;
  font-size: 0.875rem;
  min-width: 100px;
}

.filter-select-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  min-width: 80px;
}

/* RESPONSIVE */
@media (max-width: 768px) {
  .chart-title-section {
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
  }
  
  .chart-title-actions {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }
  
  .btn-view-measure {
    justify-content: center;
  }

  .medidas-chart-section {
    flex-direction: column;
    gap: 1rem;
  }
  
  .medidas-sidebar {
    flex: none;
    max-height: 400px;
  }
  
  .measures-grid {
    grid-template-columns: 1fr;
  }
  
  .accordion-button {
    flex-direction: column;
    gap: 1rem;
    text-align: center;
  }
  
  .accordion-button .first {
    min-width: auto;
    flex-direction: column;
    text-align: center;
  }
  
  .chart-internal-filters {
    flex-direction: column;
    gap: 0.5rem;
  }
  
  .filters-left, .filters-right {
    justify-content: center;
    flex-wrap: wrap;
  }
}