/* ══════════════════════════════════════ TIMELINE ══ */

#timeline-section {
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border-subtle);
  height: var(--timeline-h);
  overflow: hidden;
  position: relative;
  min-width: 0;
  width: 100%;
}

/* ── Timeline Header (Ruler row) ── */
#timeline-header {
  display: flex;
  align-items: center;
  height: 32px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  min-width: 0;
  width: 100%;
}

.tl-layer-labels-header {
  width: var(--labels-w);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  border-right: 1px solid var(--border-subtle);
  height: 100%;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.tl-header-btns {
  display: flex;
  gap: 2px;
}
.tl-header-btns .icon-btn {
  width: 20px;
  height: 20px;
  font-size: 13px;
  font-weight: 600;
}

/* Ruler area */
.tl-ruler-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  height: 100%;
  min-width: 0;
  cursor: pointer;
}

/* Canvas wrapper fills the ruler-wrap */
.tl-ruler-canvas-wrap {
  position: absolute;
  inset: 0;
}

#ruler-canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

/* Playhead (in ruler) */
#playhead {
  position: absolute;
  top: 0;
  width: 2px;
  height: 100%;
  background: var(--accent);
  cursor: ew-resize;
  z-index: 20;
  transform: translateX(-50%);
  pointer-events: all;
}
#playhead::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 10px;
  height: 10px;
  background: var(--accent);
  clip-path: polygon(20% 0%, 80% 0%, 100% 30%, 50% 100%, 0% 30%);
}

/* ── Timeline Body ── */
#timeline-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
  min-width: 0;
  width: 100%;
}

/* Layer labels column */
#tl-layer-labels {
  width: var(--labels-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border-subtle);
  background: var(--bg-panel);
  overflow: hidden;
}
.tl-layer-label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  height: 46px;
  border-bottom: 1px solid var(--border-subtle);
  cursor: default;
  transition: background var(--transition);
  position: relative;
}
.tl-layer-label:hover { background: var(--bg-hover); }
.tl-layer-label:last-child { border-bottom: none; }
.tl-layer-label span {
  flex: 1;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.layer-controls {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity var(--transition);
}
.tl-layer-label:hover .layer-controls { opacity: 1; }
.layer-vis-btn,
.layer-lock-btn {
  width: 20px;
  height: 20px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  border-radius: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  padding: 0;
}
.layer-vis-btn:hover,
.layer-lock-btn:hover,
.layer-mute-btn:hover { background: var(--bg-active); color: var(--text-primary); }
.layer-vis-btn.active { color: var(--text-secondary); }
.layer-mute-btn {
  width: 20px;
  height: 20px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  border-radius: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  padding: 0;
}
.layer-mute-btn.muted { color: #e94560; }

/* Layer icons */
.layer-icon {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.layer-icon.video { background: rgba(233, 69, 96, 0.2);  color: var(--layer-video); }
.layer-icon.image { background: rgba(76, 175, 137, 0.2); color: var(--layer-image); }
.layer-icon.audio { background: rgba(245, 166, 35, 0.2); color: var(--layer-audio); }
.layer-icon.text  { background: rgba(91, 192, 222, 0.2); color: var(--layer-text);  }

/* ── Tracks (scrollable) ── */
#tl-tracks-wrap {
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  position: relative;
  min-width: 0;
}
#tl-tracks {
  position: relative;
  min-width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}
.tl-track {
  height: 46px;
  border-bottom: 1px solid var(--border-subtle);
  position: relative;
  overflow: visible;
  flex-shrink: 0;
}
.tl-track:last-of-type { border-bottom: none; }
.tl-track:hover { background: rgba(255,255,255,0.015); }

/* ── Playhead Line (across all tracks) ── */
#playhead-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--accent);
  z-index: 30;
  pointer-events: none;
  box-shadow: 0 0 8px var(--accent-glow);
  transform: translateX(-50%);
}

/* ── Clip Items ── */
.tl-clip {
  position: absolute;
  height: 34px;
  top: 6px;
  border-radius: 5px;
  cursor: grab;
  overflow: visible;
  z-index: 10;
  display: flex;
  align-items: center;
  user-select: none;
  transition: box-shadow 0.15s;
  min-width: 20px;
}
.tl-clip:active { cursor: grabbing; }
.tl-clip.selected {
  box-shadow: 0 0 0 2px white, 0 0 0 3px var(--accent);
  z-index: 20;
}
.tl-clip.dragging { opacity: 0.8; z-index: 50; }

/* Clip body */
.tl-clip-body {
  position: absolute;
  inset: 0;
  border-radius: 5px;
  overflow: hidden;
  display: flex;
  align-items: center;
  padding: 0 8px;
}
.tl-clip-body::before {
  content: '';
  position: absolute;
  inset: 0;
  background: inherit;
  filter: brightness(1.3);
  opacity: 0.15;
  border-radius: 5px;
}

.tl-clip-label {
  position: relative;
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: white;
  text-shadow: 0 1px 3px rgba(0,0,0,0.7);
  pointer-events: none;
  max-width: 100%;
  z-index: 1;
}

/* Clip waveform (for audio) */
.tl-clip-waveform {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 5px;
}

/* Clip thumbnails (for video/image) */
.tl-clip-thumbnails {
  position: absolute;
  inset: 0;
  display: flex;
  overflow: hidden;
  border-radius: 5px;
}
.tl-clip-thumb {
  height: 100%;
  object-fit: cover;
  flex-shrink: 0;
}

/* Trim handles */
.trim-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: ew-resize;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  background: rgba(255,255,255,0.15);
  opacity: 0;
  transition: opacity var(--transition), background var(--transition);
}
.tl-clip:hover .trim-handle,
.tl-clip.selected .trim-handle { opacity: 1; }
.trim-handle:hover { background: rgba(255,255,255,0.35); }
.trim-handle.left  { left: 0; border-radius: 5px 0 0 5px; }
.trim-handle.right { right: 0; border-radius: 0 5px 5px 0; }
.trim-handle svg { pointer-events: none; }

/* Duplicate button (appears on clip hover) */
.clip-dup-btn {
  position: absolute;
  top: 4px;
  right: 10px;
  width: 18px;
  height: 18px;
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px;
  color: rgba(255,255,255,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 26;
  opacity: 0;
  transition: opacity var(--transition), background var(--transition), transform 0.1s;
  padding: 0;
  line-height: 1;
}
.tl-clip:hover .clip-dup-btn,
.tl-clip.selected .clip-dup-btn { opacity: 1; }
.clip-dup-btn:hover {
  background: rgba(255,255,255,0.25);
  transform: scale(1.15);
}
.clip-dup-btn svg { pointer-events: none; display: block; }

/* Layer color coding */
.tl-track[data-layer="video"]  .tl-clip-body { background: var(--layer-video); }
.tl-track[data-layer="image"]  .tl-clip-body { background: var(--layer-image); }
.tl-track[data-layer="audio"]  .tl-clip-body { background: var(--layer-audio); }
.tl-track[data-layer="text"]   .tl-clip-body { background: var(--layer-text); }

/* Gap indicator */
.tl-track-empty-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--text-disabled);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}
.tl-track:not(:has(.tl-clip)) .tl-track-empty-hint { opacity: 1; }

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE DESIGN (Media Queries)
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 1024px) {
  .tl-layer-label span {
    font-size: 9px;
  }
}

@media (max-width: 768px) {
  .tl-header-btns .icon-btn {
    width: 16px;
    height: 16px;
    font-size: 10px;
  }
  .tl-layer-labels-header {
    padding: 0 4px;
    font-size: 9px;
  }
}
