/**
 * Serendipia Charts - Estilos Base Responsive
 * 
 * Estilos compartidos para todas las visualizaciones D3.js
 * Mobile-first approach con breakpoints estandarizados
 * 
 * @author Serendipia
 * @version 1.0.0
 */

/* ==================================
   Contenedores de gráficas
   ================================== */

.sp-chart-container {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  position: relative;
  box-sizing: border-box;
}

.sp-chart-container svg {
  display: block;
  width: 100%;
  height: auto;
  font-family: "Titillium Web", Helvetica, sans-serif;
}

/* SVG generado por el sistema de gráficas (aplica a cualquier contenedor) */
svg.sp-chart-svg {
  display: block;
  width: 100%;
  height: auto;
  font-family: "Titillium Web", Helvetica, sans-serif;
}

/* ==================================
   Tooltips (tooltip-sp)
   ================================== */

.tooltip-sp {
  position: absolute;
  text-align: center;
  padding: 8px 12px;
  font-family: "Titillium Web", Helvetica, sans-serif;
  font-size: 14px;
  background: rgba(0, 0, 0, 0.8);
  color: #ffffff;
  border-radius: 4px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 1000;
  max-width: 250px;
  line-height: 1.4;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
}

.tooltip-sp.active {
  opacity: 1;
}

.tooltip-sp strong {
  color: #333;
}

/* ==================================
   Ejes D3
   ================================== */

.sp-chart-container .axis path,
.sp-chart-container .axis line {
  stroke: rgba(0, 0, 0, 0.05);
  shape-rendering: crispEdges;
}

.sp-chart-container .axis text {
  font-family: "Titillium Web", Helvetica, sans-serif;
  font-size: 12px;
  fill: #666;
  font-weight: 500;
}

.sp-chart-container .axis .domain {
  stroke: rgba(0, 0, 0, 0.1);
}

.sp-chart-container .tick line {
  stroke: transparent;
}

/* Grid lines */
.sp-chart-container .grid line {
  stroke: rgba(0, 0, 0, 0.05);
  stroke-dasharray: 3, 3;
}

.sp-chart-container .grid path {
  stroke-width: 0;
}

/* ==================================
   Leyendas
   ================================== */

.sp-chart-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 15px;
  margin-top: 20px;
  font-family: "Titillium Web", Helvetica, sans-serif;
}

.sp-chart-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #666;
  cursor: pointer;
  user-select: none;
}

.sp-chart-legend-item:hover {
  color: #333;
}

.sp-chart-legend-item.inactive {
  opacity: 0.4;
}

.sp-chart-legend-color {
  width: 15px;
  height: 15px;
  border-radius: 3px;
}

/* ==================================
   Título y subtítulos
   ================================== */

.sp-chart-title {
  font-family: "Titillium Web", Helvetica, sans-serif;
  font-size: 26px;
  font-weight: 700;
  color: #333328;
  margin-bottom: 10px;
  line-height: 1.2;
}

.sp-chart-subtitle {
  font-family: "Titillium Web", Helvetica, sans-serif;
  font-size: 17px;
  font-weight: 400;
  color: #666;
  margin-bottom: 20px;
  line-height: 1.4;
}

.sp-chart-note {
  font-family: "Titillium Web", Helvetica, sans-serif;
  font-size: 14px;
  color: #999;
  margin-top: 15px;
  font-style: italic;
}

/* ==================================
   Filtros y controles
   ================================== */

.sp-chart-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  margin-bottom: 20px;
  align-items: center;
}

.sp-chart-select,
.sp-chart-input {
  font-family: "Titillium Web", Helvetica, sans-serif;
  font-size: 15px;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #fff;
  color: #333;
  cursor: pointer;
  transition: border-color 0.2s ease;
}

.sp-chart-select:hover,
.sp-chart-select:focus,
.sp-chart-input:hover,
.sp-chart-input:focus {
  border-color: #efca33;
  outline: none;
}

.sp-chart-button {
  font-family: "Titillium Web", Helvetica, sans-serif;
  font-size: 15px;
  padding: 8px 16px;
  border: 1px solid #333;
  border-radius: 4px;
  background: #333;
  color: #fff;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
}

.sp-chart-button:hover {
  background: #efca33;
  border-color: #efca33;
  color: #333;
}

.sp-chart-button:active {
  transform: scale(0.98);
}

/* ==================================
   Estados de interacción
   ================================== */

.sp-chart-interactive {
  cursor: pointer;
  transition: all 0.2s ease;
}

.sp-chart-interactive:hover {
  opacity: 0.8;
}

.sp-chart-highlight {
  stroke: #efca33;
  stroke-width: 2px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

/* ==================================
   Loading state
   ================================== */

.sp-chart-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  color: #999;
  font-family: "Titillium Web", Helvetica, sans-serif;
}

.sp-chart-loading::after {
  content: '';
  width: 40px;
  height: 40px;
  margin-left: 10px;
  border: 3px solid #f2f2f2;
  border-top-color: #efca33;
  border-radius: 50%;
  animation: sp-chart-spin 0.8s linear infinite;
}

@keyframes sp-chart-spin {
  to { transform: rotate(360deg); }
}

/* ==================================
   Error state
   ================================== */

.sp-chart-error {
  padding: 20px;
  background: #ffebee;
  border: 1px solid #ef9a9a;
  border-radius: 8px;
  color: #c62828;
  font-family: "Titillium Web", Helvetica, sans-serif;
  text-align: center;
}

/* ==================================
   RESPONSIVE - Mobile (<768px)
   ================================== */

@media (max-width: 768px) {
  .sp-chart-container {
    padding: 0 10px;
  }

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

  .sp-chart-title {
    font-size: 21px;
  }

  .sp-chart-subtitle {
    font-size: 15px;
  }

  .tooltip-sp {
    font-size: 12px;
    padding: 6px 10px;
    max-width: 200px;
  }

  .sp-chart-legend {
    font-size: 11px;
    gap: 10px;
  }

  .sp-chart-legend-color {
    width: 12px;
    height: 12px;
  }

  .sp-chart-controls {
    flex-direction: column;
    width: 100%;
  }

  .sp-chart-select,
  .sp-chart-input,
  .sp-chart-button {
    width: 100%;
    font-size: 14px;
  }

  .sp-chart-container .axis text {
    font-size: 10px;
  }
}

/* ==================================
   RESPONSIVE - Tablet (768px - 1024px)
   ================================== */

@media (min-width: 768px) and (max-width: 1024px) {
  .sp-chart-container svg {
    font-size: 11px;
  }

  .sp-chart-title {
    font-size: 23px;
  }

  .tooltip-sp {
    font-size: 13px;
  }
}

/* ==================================
   RESPONSIVE - Desktop (>1024px)
   ================================== */

@media (min-width: 1024px) {
  .sp-chart-container {
    max-width: 900px;
  }
}

/* ==================================
   Print styles
   ================================== */

@media print {
  .sp-chart-controls,
  .sp-chart-button {
    display: none;
  }

  .tooltip-sp {
    display: none !important;
  }

  .sp-chart-container svg {
    max-width: 100%;
    page-break-inside: avoid;
  }
}

/* ==================================
   Accessibility
   ================================== */

.sp-chart-container:focus {
  outline: 2px solid #efca33;
  outline-offset: 4px;
}

.sp-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Screen reader only content for accessibility */
.sp-chart-sr-only {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* ==================================
   Bootstrap Grid (solo lo necesario)
   ================================== */

.row {
  display: flex;
  flex-wrap: wrap;
  margin-right: -15px;
  margin-left: -15px;
}

.col-2, .col-10 {
  position: relative;
  width: 100%;
  padding-right: 15px;
  padding-left: 15px;
}

.col-2 { flex: 0 0 16.666667%; max-width: 16.666667%; }
.col-10 { flex: 0 0 83.333333%; max-width: 83.333333%; }

/* Utilidades */
.mt-4 { margin-top: 1.5rem !important; }
.m-0 { margin: 0 !important; }
.text-right { text-align: right !important; }

/* ==================================
   Fuente con logo Serendipia
   ================================== */

#fuente_sp {
  margin-top: 15px;
}

#fuente_sp p {
  color: #666;
  line-height: 1.4;
}



/* Mobile: Stack en columna */
@media (max-width: 768px) {
  .col-2, .col-10 {
    flex: 0 0 100%;
    max-width: 100%;
  }
  
  .text-right {
    text-align: left !important;
  }
  
  #fuente_sp .row {
    flex-direction: column;
  }
}
