/* Posicionar el contenedor para superponer la grilla semanal */
#timelineChart {
  position: relative;
}

/* For the day range under the label title */
.timeline-label .small {
  display: block;            /* force a separate line */
  margin-top: 2px;
  font-size: 0.68rem;        /* slightly smaller */
  font-weight: 400;          /* lighter */
  color: #6c757d !important; /* neutral gray, not link-like blue */
}

/* Overlay de líneas semanales (Lunes/Viernes) que cruzan toda la altura */
.timeline-grid-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 1; /* Debajo de las barras para no tapar interacción */
}

.timeline-grid-overlay .grid-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(0,0,0,0.08);
}

.timeline-grid-overlay .grid-line.monday {
  background: rgba(0,0,0,0.12);
}

.timeline-grid-overlay .grid-line.friday {
  background: rgba(0,0,0,0.08);
}

/* Marcadores en la escala superior */
.timeline-scale {
  position: relative;
}

.timeline-scale .scale-marker {
  position: absolute;
  transform: translateX(-50%);
}

.timeline-scale .scale-line {
  width: 1px;
  height: 16px;
  background: rgba(0,0,0,0.2);
  margin: 0 auto 2px;
}

.timeline-scale .scale-line.monday {
  height: 20px;
  background: rgba(0,0,0,0.35);
}

.timeline-scale .scale-line.friday {
  background: rgba(0,0,0,0.25);
}

.timeline-scale .scale-label {
  font-size: 12px;
  color: #6c757d;
  white-space: nowrap;
}

/* Header del timeline (título + controles) - STICKY */
.timeline-header-sticky {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  z-index: 1050; /* Mayor que navbar de Bootstrap (1030) */
  background: white;
  padding: 15px;
  margin: -15px -15px 15px -15px;
  border-bottom: 2px solid #dee2e6;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  will-change: transform;
}

/* Cuando el header está fijo */
.timeline-header-sticky.is-fixed {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  padding: 15px;
  margin: 0;
  max-width: 1140px;
  margin-left: auto;
  margin-right: auto;
}

/* Placeholder para evitar salto cuando el header se vuelve fixed */
.timeline-visual.has-fixed-header::before {
  content: '';
  display: block;
  height: 70px; /* Altura aproximada del header */
}

/* Scroll flotante superior - STICKY */
.timeline-top-scroll {
  position: relative;
  z-index: 1040;
  background: white;
  border-bottom: 1px solid #e9ecef;
  overflow-x: auto;
  overflow-y: hidden;
  height: 20px;
  margin-bottom: 10px;
}

/* Cuando el scroll flotante está fijo */
.timeline-top-scroll.is-fixed {
  position: fixed;
  top: 70px; /* Debajo del header fijo */
  left: 0;
  right: 0;
  width: 100%;
  max-width: 1140px;
  margin-left: auto;
  margin-right: auto;
}

.timeline-top-scroll-inner {
  height: 1px;
}

/* Timeline general styles */
.timeline-visual {
  background: #fff;
  padding: 10px 0;
  margin-top: 10px;
  font-size: 0.875rem;
  line-height: 1.3;
  padding-bottom: 1200px; /* ventana mucho más larga para scroll */
  position: relative; /* Necesario para que sticky funcione */
  min-height: 100vh; /* Asegurar altura mínima para scroll */
}
/* Contenedor con scroll horizontal para el timeline */
.timeline-chart {
  background: white;
  border: none;
  border-top: 1px solid #e9ecef;
  overflow-x: auto;
  overflow-y: visible;
  min-height: 120vh; /* hacer la ventana notablemente más alta */
}

.timeline-content {
  position: relative;
  display: block;
}

/* Barra de fechas/títulos - STICKY */
.timeline-dates {
  position: relative;
  z-index: 1030;
  background: white;
  border-bottom: 2px solid #dee2e6;
  overflow-x: auto;
  overflow-y: hidden;
}

/* Cuando la barra de fechas está fija */
.timeline-dates.is-fixed {
  position: fixed;
  top: 90px; /* Debajo del header fijo (70px) + scroll flotante (20px) */
  left: 0;
  right: 0;
  width: 100%;
  max-width: 1140px;
  margin-left: auto;
  margin-right: auto;
  padding-bottom: 5px; /* Espacio para que no se corte */
}

/* Escala de referencia del timeline */
.timeline-scale {
  position: relative;
  z-index: 10;
  height: 80px; /* Aumentado a 80px para que se vean bien los números */
  margin: 0;
  padding-bottom: 10px; /* Espacio adicional abajo */
  border-bottom: 1px solid #e9ecef;
  background: #f8f9fa;
  overflow: visible;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 0.75rem;
  line-height: 1.2;
  width: 100%;
}

.scale-marker {
  position: absolute;
  top: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  z-index: 11;
  transform: translateX(-50%);
  padding-top: 4px;
  box-sizing: border-box;
  transition: all 0.1s ease;
}

.scale-marker:hover {
  z-index: 12;
}

.scale-marker:hover .scale-line {
  background: #0d6efd;
  height: 35px;
}

.scale-marker:hover .scale-label {
  background: #0d6efd;
  color: white;
  transform: scale(1.05);
  box-shadow: 0 2px 8px rgba(13, 110, 253, 0.3);
}

.scale-line {
  width: 1px;
  height: 20px;
  background: #dee2e6;
  margin-bottom: 4px;
  position: relative;
  transition: all 0.1s ease;
}

/* Línea vertical que cruza todo el timeline */
.scale-line::after {
  content: '';
  position: absolute;
  top: 18px;
  left: 0;
  width: 1px;
  height: 2000px;
  background: rgba(173, 181, 189, 0.1);
  z-index: 1;
  transition: all 0.2s ease;
}

.scale-marker:hover .scale-line::after {
  background: rgba(13, 110, 253, 0.1);
}

.scale-label {
  font-size: 10px;
  font-weight: 500;
  color: #6c757d;
  white-space: nowrap;
  text-align: center;
  background: #fff;
  padding: 2px 6px;
  border: 1px solid #e9ecef;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  transition: all 0.1s ease;
  line-height: 1.1;
  min-width: 30px;
}

/* Estilos para el selector de vista del timeline */
.timeline-view-selector {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 20;
  display: flex;
  gap: 5px;
  background: white;
  padding: 4px;
  border-radius: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  border: 1px solid #e9ecef;
}

.timeline-view-btn {
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
  border: none;
  border-radius: 16px;
  background: transparent;
  color: #6c757d;
  cursor: pointer;
  transition: all 0.2s ease;
}

.timeline-view-btn:hover {
  background: #f1f3f5;
  color: #495057;
}

.timeline-view-btn.active {
  background: #0d6efd;
  color: white;
  box-shadow: 0 1px 3px rgba(13, 110, 253, 0.3);
}

.timeline-content {
  position: relative;
  z-index: 5;
  padding-top: 10px;
  padding-bottom: 80px; /* extiende aún más hacia abajo */
}

/* Fondo por etapa (aplica a la etapa y sus líneas/partes) */
.timeline-stage-group {
  background: var(--stage-bg, #f8f9fa);
  border-left: 3px solid rgba(0,0,0,0.05);
  padding: 6px 8px;
  border-radius: 8px;
  margin-bottom: 10px;
}

/* Evitar que el label opaque el fondo del grupo */
.timeline-stage-group .timeline-label {
  background: var(--stage-bg, transparent) !important; /* forzar mismo fondo que el grupo */
}

/* Afinar separación interna para que el fondo se vea continuo */
.timeline-stage-group .timeline-row {
  border-bottom-color: rgba(0,0,0,0.08);
}

/* Alternar colores para mayor contraste visual */
.timeline-stage-group.alt-blue {
  --stage-bg: #EAF6FF; /* celeste claro */
}

.timeline-stage-group.alt-white {
  --stage-bg: #FFFFFF; /* blanco */
}

/* Aumentar el grosor del borde lateral para separar grupos */
.timeline-stage-group.alt-blue {
  border-left-color: #B3E0FF;
}

.timeline-stage-group.alt-white {
  border-left-color: #E0E0E0;
}

.timeline-dates {
  background: white;
  padding: 15px;
  border-radius: 6px;
  margin-bottom: 20px;
  border: 1px solid #dee2e6;
  overflow-x: auto;
  overflow-y: hidden;
  position: relative;
}

.timeline-dates-inner {
  position: relative;
  display: block;
}

/* Estilos de barras de etapas */
.timeline-segment.etapa-segment {
  cursor: move;
  transition: all 0.1s ease;
  border: 1px solid rgba(0,0,0,0.15);
  z-index: 3;
  height: 16px;
  margin-top: -8px;
  top: 50%;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  border-radius: 0;
  user-select: none;
}

.timeline-segment.etapa-segment:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  border-color: rgba(0,0,0,0.3);
  z-index: 10;
}

.timeline-segment.parte-segment {
  z-index: 1;
  opacity: 0.7;
  height: 12px;
  margin-top: -6px;
  border-radius: 0;
  user-select: none;
}

.timeline-segment.parte-segment:hover {
  opacity: 0.9;
  z-index: 5;
}

.partes-container {
  background: rgba(248, 249, 250, 0.5);
  border-left: 3px solid #dee2e6;
  margin-left: 15px;
  padding: 10px;
  border-radius: 0 0 8px 8px;
  margin-top: 5px;
}

.partes-container.show {
  display: block !important;
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from {
    opacity: 0;
    max-height: 0;
  }
  to {
    opacity: 1;
    max-height: 500px;
  }
}

.timeline-row {
  margin: 0;
  padding: 4px 0 6px 0;
  position: relative;
  width: 100%;
  min-height: 2.2rem;
  border-bottom: 1px solid #f0f0f0;
  transition: background-color 0.1s ease;
}

/* Compactar filas de líneas adicionales */
.linea-extra-row {
  padding: 0 0 2px 0;
  min-height: 1.4rem;
}

.linea-extra-row .timeline-label.top-line {
  padding: 0 8px 2px 0;
  margin-bottom: 0;
}

.linea-extra-row .timeline-bar-container {
  height: 16px;
  margin: 0;
}

.linea-extra-row .timeline-segment {
  font-size: 11px;
  padding: 0 6px;
}

.timeline-row:hover {
  background-color: #f8f9fa;
}

.timeline-row:last-child {
  border-bottom: none;
}

.timeline-label {
  font-weight: 500;
  font-size: 0.7rem;
  color: #333;
  position: sticky;
  left: 0;
  background: white;
  z-index: 20;
  padding: 0 10px 0 0;
  border-right: 2px solid #dee2e6;
  box-shadow: 2px 0 4px rgba(0,0,0,0.05);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.1;
  min-width: 300px;
  max-width: 300px;
}

/* Modo título arriba de la barra */
.timeline-label.top-line {
  display: block;
  width: 100%;
  padding: 2px 8px 4px 0;
  border-right: none;
  border-bottom: 1px solid rgba(0,0,0,0.06);
  margin-bottom: 2px;
}

/* Cuando el título está arriba, la barra ocupa toda la fila debajo */
.timeline-row .timeline-bar-container {
  height: 22px;
  margin: 4px 0 0 0;
}

.timeline-label .fechas {
  display: flex;
  gap: 5px;
  font-size: 0.65rem;
  color: #666;
  margin-top: 1px;
}

.timeline-label .fechas span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timeline-bar-container {
  position: relative;
  height: 20px;
  margin: 2px 0;
  background: transparent;
  overflow: visible;
  flex: 1;
}

.timeline-segment {
  position: absolute;
  height: 100%;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  padding: 0 8px;
  color: white;
  font-weight: 500;
  font-size: 12px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
  border: 2px solid rgba(255,255,255,0.3);
}

/* Resize handles for draggable bars */
.resize-handle {
  position: absolute;
  top: 0;
  width: 10px;
  height: 100%;
  cursor: ew-resize;
  background: rgba(255, 255, 255, 0.4);
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 10;
  border-radius: 2px;
}

.timeline-segment:hover .resize-handle {
  opacity: 1;
}

.timeline-segment.draggable-bar .resize-handle {
  display: block;
}

.timeline-segment:not(.draggable-bar) .resize-handle {
  display: none;
}

.resize-handle:hover {
  background: rgba(255, 255, 255, 0.8);
  opacity: 1;
  transform: scaleX(1.2);
}

.resize-left {
  left: -2px;
  border-radius: 4px 0 0 4px;
  border-right: 1px solid rgba(255,255,255,0.5);
}

.resize-right {
  right: -2px;
  border-radius: 0 4px 4px 0;
  border-left: 1px solid rgba(255,255,255,0.5);
}

/* Dragging states */
.timeline-segment.dragging {
  box-shadow: 0 8px 16px rgba(0,0,0,0.3);
  transform: translateY(-4px);
  z-index: 1000;
}

.timeline-segment.resizing {
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  z-index: 1000;
}

.timeline-segment:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.2);
  border-color: rgba(255,255,255,0.6);
}

.etapa-segment {
  font-size: 13px;
  font-weight: 600;
}

.parte-segment {
  font-size: 11px;
  height: 30px;
  margin: 2px 0;
  cursor: move;
  border: 1px solid rgba(255,255,255,0.4);
}

.parte-segment:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.parte-segment .resize-handle {
  height: 30px;
  width: 6px;
}

.parte-segment.dragging {
  box-shadow: 0 6px 12px rgba(0,0,0,0.25);
  transform: translateY(-2px);
  z-index: 999;
}

.parte-segment.resizing {
  box-shadow: 0 3px 8px rgba(0,0,0,0.18);
  z-index: 999;
}

.etapa-nombre, .parte-nombre {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.partes-timeline {
  background: #f8f9fa;
  border-top: 1px solid #e9ecef;
  padding: 10px 0;
}

.parte-timeline-row {
  margin: 8px 0;
  padding: 0;
  display: flex;
  align-items: center;
  min-height: 40px;
}

.parte-timeline-row .parte-label {
  min-width: 200px;
  margin-right: 15px;
  flex-shrink: 0;
}

.parte-timeline-row .timeline-bar-container {
  flex: 1;
  height: 35px;
  margin: 0;
  background: rgba(241, 243, 244, 0.7);
}

.parte-label {
  padding: 6px 10px;
  background: #e9ecef;
  border-radius: 4px;
  font-size: 12px;
  border: 1px solid #dee2e6;
}

.parte-label .small {
  font-weight: 500;
  color: #495057;
}

.parte-label .tiny {
  color: #6c757d;
  margin-top: 2px;
}

.tiny {
  font-size: 10px;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .timeline-label {
    min-width: 200px;
  }
  
  .timeline-segment {
    font-size: 10px;
    padding: 0 4px;
  }
  
  .etapa-segment {
    font-size: 11px;
  }
}

/* Animation for expanding parts */
.partes-timeline {
  transition: all 0.3s ease;
}

.timeline-row:hover .timeline-label {
  background: #e3f2fd;
}

/* Color variations for better visibility */
.timeline-segment.overlapping {
  opacity: 0.8;
  border-style: dashed;
}

/* Loading state */
.timeline-loading {
  text-align: center;
  padding: 40px;
  color: #6c757d;
}

.timeline-loading .spinner-border {
  width: 3rem;
  height: 3rem;
}

/* Overlay de procesamiento */
.timeline-processing-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.7);
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
}

.timeline-processing-overlay.show {
  display: flex;
}

.timeline-processing-overlay .msg {
  background: #fff;
  border: 1px solid #e9ecef;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  border-radius: 8px;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #495057;
}

.etapa-meta-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.etapa-meta-badges {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.etapa-fechas-container {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Apilar chips de líneas en tarjetas uno debajo del otro */
.lineas-container {
  display: block;
}

.lineas-container .linea-chip {
  display: block; /* forzar salto de línea entre chips */
}

.lineas-container .linea-chip + .linea-chip {
  margin-top: 4px; /* pequeño espacio vertical entre chips */
}

/* En pantallas pequeñas, apilar los badges y las fechas */
@media (max-width: 992px) {
  .etapa-meta-container {
    flex-direction: column;
    align-items: flex-start;
  }

  .etapa-fechas-container {
    margin-top: 0.5rem;
  }
}

/* Reducir tamaño de letra del nombre de cada etapa */
.etapa-card .card-title {
  font-size: 1rem; /* antes ~1.25rem por h5 */
  line-height: 1.2;
}

/* Ajustar levemente el tamaño del ícono dentro del título */
.etapa-card .card-title i {
  font-size: 0.95em;
}

/* Estilos para las filas de la escala del timeline */
.timeline-scale-row {
  position: relative;
  width: 100%;
  height: 18px;
}

.timeline-scale-row.month-row {
  height: 20px;
  margin-bottom: 2px;
}

.timeline-scale-row.dow-row {
  height: 16px;
}

/* Bloques de mes en la escala */
.month-block {
  position: absolute;
  top: 0;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  border-right: 1px solid #dee2e6;
  box-sizing: border-box;
}

.month-block.alt0 {
  background: #e7f3ff;
  color: #0d6efd;
}

.month-block.alt1 {
  background: #f8f9fa;
  color: #6c757d;
}
