/* Vertical Timeline - Inspired by Cruip Example 2 */

/* Theme variables with light-mode fallbacks */
.timeline-wrapper {
  --tl-surface: var(--surface-primary, #ffffff);
  --tl-surface-alt: var(--surface-secondary, #f8fafc);
  --tl-surface-muted: var(--surface-tertiary, #f1f5f9);
  --tl-text: var(--text-primary, #1e293b);
  --tl-text-secondary: var(--text-secondary, #475569);
  --tl-text-muted: var(--text-muted, #64748b);
  --tl-border: var(--border-light, #e2e8f0);
  --tl-border-strong: var(--border-medium, #cbd5e1);
  --tl-shadow-sm: var(--shadow-sm, rgba(0,0,0,0.05));
  --tl-shadow-md: var(--shadow-md, rgba(0,0,0,0.1));
  --tl-shadow-lg: var(--shadow-lg, rgba(0,0,0,0.15));
  --tl-accent: var(--accent-primary, #6366f1);
}

/* Container */
.timeline-wrapper {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

.timeline-intro {
  text-align: center;
  margin-bottom: 3rem;
}

.timeline-intro p {
  color: var(--tl-text-muted);
  font-size: 1.1rem;
  line-height: 1.7;
  max-width: 700px;
  margin: 0 auto;
}

/* Legend */
.timeline-legend {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  padding: 1rem 1.5rem;
  background: var(--tl-surface);
  border: 1px solid var(--tl-border);
  border-radius: 12px;
  margin-bottom: 3rem;
  flex-wrap: wrap;
  box-shadow: 0 1px 3px var(--tl-shadow-sm);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--tl-text-secondary);
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--tl-surface);
  box-shadow: 0 0 0 1px var(--tl-shadow-md);
}

.legend-dot.architectures { background: #3b82f6; }
.legend-dot.scale { background: #f97316; }
.legend-dot.training { background: #22c55e; }
.legend-dot.capabilities { background: #a855f7; }
.legend-dot.problem { background: #fecaca; border-color: #ef4444; }

/* Era Section Headers */
.era-header {
  text-align: center;
  margin: 3rem 0 2rem;
  position: relative;
}

.era-header::before,
.era-header::after {
  content: '';
  position: absolute;
  top: 50%;
  width: calc(50% - 120px);
  height: 1px;
  background: linear-gradient(to var(--dir), transparent, var(--tl-border-strong));
}

.era-header::before {
  left: 0;
  --dir: right;
}

.era-header::after {
  right: 0;
  --dir: left;
}

.era-label {
  display: inline-block;
  background: var(--tl-surface-alt);
  border: 1px solid var(--tl-border);
  border-radius: 9999px;
  padding: 0.5rem 1.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--tl-text-secondary);
  letter-spacing: 0.025em;
}

/* Timeline Container */
.timeline-container {
  position: relative;
  /* Vertical line - left on mobile, center on desktop */
  --line-left: 20px;
}

.timeline-container::before {
  content: '';
  position: absolute;
  left: var(--line-left);
  top: 0;
  bottom: 0;
  width: 2px;
  background: linear-gradient(
    to bottom,
    transparent,
    var(--tl-border-strong) 5%,
    var(--tl-border-strong) 95%,
    transparent
  );
}

@media (min-width: 768px) {
  .timeline-container {
    --line-left: 50%;
  }

  .timeline-container::before {
    transform: translateX(-50%);
  }
}

/* Timeline Item */
.timeline-item {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding-left: 50px;
  margin-bottom: 2rem;
}

@media (min-width: 768px) {
  .timeline-item {
    padding-left: 0;
    justify-content: flex-start;
  }

  .timeline-item.timeline-left {
    flex-direction: row-reverse;
    text-align: right;
  }

  .timeline-item.timeline-left .timeline-card {
    margin-right: calc(50% + 2rem);
    margin-left: 0;
  }

  .timeline-item.timeline-right .timeline-card {
    margin-left: calc(50% + 2rem);
    margin-right: 0;
  }
}

/* Timeline Node (circle on the line) */
.timeline-node {
  position: absolute;
  left: var(--line-left);
  top: 0.5rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid var(--tl-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px var(--tl-shadow-lg);
  z-index: 10;
  transform: translateX(-50%);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.timeline-node:hover {
  transform: translateX(-50%) scale(1.1);
  box-shadow: 0 4px 12px var(--tl-shadow-lg);
}

/* Node colors by track */
.timeline-node.architectures { background: #3b82f6; }
.timeline-node.scale { background: #f97316; }
.timeline-node.training { background: #22c55e; }
.timeline-node.capabilities { background: #a855f7; }

/* Major milestone nodes */
.timeline-node.major {
  width: 48px;
  height: 48px;
  border-width: 4px;
}

/* Problem nodes */
.timeline-node.problem {
  background: #fef2f2;
  border-color: #fecaca;
}

.timeline-node svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: white;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.timeline-node.problem svg {
  fill: #dc2626;
  stroke: none;
}

/* Year badge on node */
.timeline-year {
  position: absolute;
  top: -24px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--tl-text-muted);
  white-space: nowrap;
}

/* Timeline Card */
.timeline-card {
  flex: 1;
  max-width: calc(50% - 3rem);
  background: var(--tl-surface);
  border: 1px solid var(--tl-border);
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: 0 1px 3px var(--tl-shadow-sm);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.timeline-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px var(--tl-shadow-md);
  border-color: var(--tl-border-strong);
}

@media (max-width: 767px) {
  .timeline-card {
    max-width: none;
    flex: 1;
  }
}

/* Card header */
.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--tl-text);
  margin: 0;
  line-height: 1.4;
}

.card-year {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--tl-accent);
  white-space: nowrap;
  font-family: 'Georgia', serif;
}

@media (min-width: 768px) {
  .timeline-item.timeline-left .card-header {
    flex-direction: row-reverse;
  }

  .timeline-item.timeline-left .related-milestones {
    justify-content: flex-end;
  }
}

/* Track badge */
.track-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  margin-bottom: 0.5rem;
}

.track-badge.architectures { background: #dbeafe; color: #1d4ed8; }
.track-badge.scale { background: #ffedd5; color: #c2410c; }
.track-badge.training { background: #dcfce7; color: #15803d; }
.track-badge.capabilities { background: #f3e8ff; color: #7e22ce; }

/* Card description */
.card-description {
  font-size: 0.875rem;
  color: var(--tl-text-muted);
  line-height: 1.6;
  margin: 0;
}

/* Problem card variant */
.timeline-card.problem-card {
  border-color: #fecaca;
  background: linear-gradient(135deg, #fef2f2 0%, var(--tl-surface) 100%);
}

.timeline-card.problem-card:hover {
  border-color: #f87171;
}

.problem-status {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  padding: 0.25rem 0.6rem;
  border-radius: 9999px;
  margin-bottom: 0.5rem;
}

.problem-status.active {
  background: #fef3c7;
  color: #92400e;
}

.problem-status.solved {
  background: #d1fae5;
  color: #065f46;
}

.problem-status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.problem-status.active::before {
  background: #f59e0b;
}

.problem-status.solved::before {
  background: #10b981;
}

/* Related milestones chips in problem cards */
.related-milestones {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.75rem;
}

.related-chip {
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  background: var(--tl-surface-muted);
  border-radius: 9999px;
  color: var(--tl-text-muted);
}

/* Side Popup Styles */
.timeline-popup {
  position: absolute;
  background: var(--tl-surface);
  border-radius: 12px;
  width: 380px;
  max-height: 500px;
  overflow-y: auto;
  box-shadow: 0 10px 40px var(--tl-shadow-lg), 0 0 0 1px var(--tl-shadow-sm);
  z-index: 1000;
  opacity: 0;
  transform: translateX(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.timeline-popup.active {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

/* Popup positioning - adjacent to clicked cards (positioned via JS) */
.timeline-popup.popup-left {
  transform: translateX(-10px);
}

.timeline-popup.popup-left.active {
  transform: translateX(0);
}

.timeline-popup.popup-right {
  transform: translateX(10px);
}

.timeline-popup.popup-right.active {
  transform: translateX(0);
}

.popup-header {
  display: flex;
  align-items: flex-start;
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--tl-border);
  gap: 0.75rem;
  position: sticky;
  top: 0;
  background: var(--tl-surface);
  border-radius: 12px 12px 0 0;
}

.popup-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.popup-icon svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: white;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.popup-title-group {
  flex: 1;
  min-width: 0;
}

.popup-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--tl-text);
  margin: 0 0 0.2rem;
  line-height: 1.3;
}

.popup-meta {
  font-size: 0.8rem;
  color: var(--tl-text-muted);
}

.popup-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--tl-text-muted);
  cursor: pointer;
  padding: 0.2rem;
  line-height: 1;
  border-radius: 6px;
  transition: background 0.15s ease, color 0.15s ease;
}

.popup-close:hover {
  background: var(--tl-surface-muted);
  color: var(--tl-text-secondary);
}

.popup-body {
  padding: 1rem;
}

.popup-section {
  margin-bottom: 1rem;
}

.popup-section:last-child {
  margin-bottom: 0;
}

.popup-section-title {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--tl-text-muted);
  margin-bottom: 0.4rem;
}

.popup-section-content {
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--tl-text-secondary);
}

/* Problem popup variant */
.timeline-popup.problem-popup .popup-header {
  border-bottom-color: #fecaca;
}

.timeline-popup.problem-popup .popup-icon {
  background: #fef2f2;
}

.timeline-popup.problem-popup .popup-icon svg {
  fill: #dc2626;
  stroke: none;
}

/* Mobile: popups become bottom sheets */
@media (max-width: 767px) {
  .timeline-popup {
    position: fixed;
    left: 0 !important;
    right: 0 !important;
    bottom: 0;
    top: auto !important;
    width: 100%;
    max-height: 70vh;
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
  }

  .timeline-popup.active {
    transform: translateY(0);
  }

  .timeline-popup.popup-left,
  .timeline-popup.popup-right {
    transform: translateY(100%);
  }

  .timeline-popup.popup-left.active,
  .timeline-popup.popup-right.active {
    transform: translateY(0);
  }
}

/* Papers list */
.papers-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.papers-list li {
  margin-bottom: 0.35rem;
}

.papers-list a {
  color: #3b82f6;
  text-decoration: none;
  font-size: 0.9375rem;
}

.papers-list a:hover {
  text-decoration: underline;
}

/* Connection chips */
.connections-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.connection-chip {
  background: var(--tl-surface-muted);
  border: 1px solid var(--tl-border);
  border-radius: 9999px;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  color: var(--tl-text-secondary);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.connection-chip:hover {
  background: var(--tl-border);
  border-color: var(--tl-border-strong);
}

/* Problems revealed list */
.problems-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.problems-list li {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  color: #dc2626;
}

.problems-list li::before {
  content: '?';
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  background: #fecaca;
  border-radius: 50%;
  font-size: 0.65rem;
  font-weight: 700;
}

/* Problem modal variant */
.timeline-modal.problem-modal .modal-header {
  border-bottom-color: #fecaca;
}

.timeline-modal.problem-modal .modal-icon {
  background: #fef2f2;
}

.timeline-modal.problem-modal .modal-icon svg {
  fill: #dc2626;
  stroke: none;
}

/* Scroll to top button */
.scroll-top-btn {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 48px;
  height: 48px;
  background: var(--tl-surface);
  border: 1px solid var(--tl-border);
  border-radius: 50%;
  box-shadow: 0 4px 12px var(--tl-shadow-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
  z-index: 100;
}

.scroll-top-btn.visible {
  opacity: 1;
  visibility: visible;
}

.scroll-top-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px var(--tl-shadow-lg);
}

.scroll-top-btn svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: var(--tl-text-secondary);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Filter controls */
.filter-controls {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  font-weight: 500;
  border: 1px solid var(--tl-border);
  border-radius: 9999px;
  background: var(--tl-surface);
  color: var(--tl-text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.filter-btn:hover {
  border-color: var(--tl-border-strong);
  color: var(--tl-text-secondary);
}

.filter-btn.active {
  background: var(--tl-text);
  border-color: var(--tl-text);
  color: var(--tl-surface);
}

/* Responsive adjustments */
@media (max-width: 767px) {
  .timeline-wrapper {
    padding: 1rem 0.75rem;
  }

  .timeline-legend {
    gap: 0.75rem;
    padding: 0.75rem 1rem;
  }

  .legend-item {
    font-size: 0.75rem;
  }

  .era-header::before,
  .era-header::after {
    width: calc(50% - 80px);
  }

  .timeline-item {
    padding-left: 55px;
    margin-bottom: 1.5rem;
  }

  .timeline-node {
    width: 36px;
    height: 36px;
  }

  .timeline-node.major {
    width: 42px;
    height: 42px;
  }

  .timeline-card {
    padding: 1rem;
  }

  .card-title {
    font-size: 0.9375rem;
  }

}

/* Print styles */
@media print {
  .timeline-container::before {
    background: #cbd5e1;
  }

  .timeline-card {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid #e2e8f0;
  }

  .timeline-popup,
  .scroll-top-btn,
  .filter-controls {
    display: none !important;
  }
}
