.timeline-header-sticky {
  position: sticky;
  top: 0;
  z-index: 22;
  background: var(--bg);
  overflow-x: hidden;
  border-bottom: 1px solid var(--border);
  min-height: 2rem;
}

.timeline-wrapper {
  overflow-x: hidden;
  padding: 0 0 1rem;
  min-height: 100vh;
}

.timeline-grid {
  min-width: max-content;
}

/* Row layout: sticky date cell + scrollable slots */
.tl-row {
  display: flex;
  position: relative;
  border-bottom: 1px solid var(--border);
}

.tl-header-row {
  background: var(--bg);
  height: auto;
}

/* Sticky date column */
.tl-date-cell {
  position: sticky;
  left: 0;
  z-index: 10;
  background: var(--bg);
  width: 120px;
  min-width: 120px;
  max-width: 120px;
  border-right: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0 0.5rem;
  font-size: 0.78rem;
}

.tl-header-corner {
  z-index: 25;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-secondary);
  justify-content: center;
  padding: 0.5rem;
}

.tl-day {
  font-weight: 700;
  color: var(--text);
}

.tl-monthday {
  color: var(--text-secondary);
  font-size: 0.72rem;
}

/* Scrollable slots area */
.tl-slots-container {
  position: relative;
  flex-shrink: 0;
}

/* Header time labels */
.tl-slot-header {
  position: absolute;
  top: 0;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-secondary);
  border-right: 1px solid rgba(42, 49, 66, 0.3);
  padding: 0.5rem 0;
}

.tl-slot-header.tl-hour-mark {
  border-right: 1px solid var(--border);
}

/* Grid lines in data rows */
.tl-gridline {
  position: absolute;
  top: 0;
  border-right: 1px solid rgba(42, 49, 66, 0.25);
}

.tl-gridline-hour {
  border-right: 1px solid rgba(42, 49, 66, 0.6);
}

/* Match blocks */
.tl-match {
  position: absolute;
  border-radius: 3px;
  display: flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0 0.4rem;
  font-size: 0.68rem;
  font-weight: 600;
  color: #fff;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: default;
  z-index: 5;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.tl-match-full {
  display: none;
}

.tl-match:hover {
  opacity: 0.88;
  z-index: 6;
}

.tl-match.tl-has-full:hover {
  z-index: 20;
  width: auto !important;
  min-width: max-content;
  white-space: nowrap;
}

.tl-match:hover .tl-match-short:has(~ .tl-match-full) {
  display: none;
}

.tl-match:hover .tl-match-full {
  display: inline;
}

/* Fallback for browsers without :has() */
.tl-match.tl-has-full:hover .tl-match-short {
  display: none;
}

.tl-match-dimmed {
  opacity: 0.15;
  filter: grayscale(0.8);
}

.tl-match-dimmed:hover {
  opacity: 0.35;
}

.tl-match-highlighted {
  box-shadow: 0 0 0 2px #fff, 0 2px 8px rgba(0, 0, 0, 0.5);
  z-index: 7;
}

.tl-match-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.tl-match-tbd {
  opacity: 0.5;
  border: 1px dashed rgba(255, 255, 255, 0.2);
}

.tl-tbd {
  background: rgba(255, 255, 255, 0.15);
  padding: 1px 0.2em;
  border-radius: 2px;
  font-style: italic;
  opacity: 0.8;
}

.tl-match-num {
  opacity: 0.6;
  font-size: 0.6rem;
  flex-shrink: 0;
}

.tl-match-group {
  font-size: 0.9rem;
  font-weight: 800;
  opacity: 0.2;
  position: absolute;
  right: 0.3rem;
}

.tl-match.tl-has-full:hover .tl-match-group {
  position: static;
  font-size: 0.6rem;
  opacity: 0.6;
  margin-left: 0.25rem;
}

/* Legend */
.timeline-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  padding: 0.75rem 1rem;
  max-width: 900px;
  margin: 0 auto;
}

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

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
}

@media (min-width: 640px) {
  .tl-match {
    font-size: 0.72rem;
  }

  .tl-date-cell {
    width: 130px;
    min-width: 130px;
    max-width: 130px;
    font-size: 0.82rem;
  }
}
