/**
 * 3Syxty Studio — Timeline Component
 *
 * A professional video/animation timeline with keyframe tracks, playhead,
 * zoom controls, layer management, and scrubbing. Inspired by After Effects
 * and Premiere Pro but with 3Syxty's elegant design language.
 */

/* -----------------------------------------------------------------------
   Timeline Container
   ----------------------------------------------------------------------- */

.timeline {
    display: flex;
    flex-direction: column;
    background: var(--surface-secondary);
    border-top: 1px solid var(--border-subtle);
    user-select: none;
    overflow: hidden;
}

.timeline-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-1) var(--space-3);
    border-bottom: 1px solid var(--border-subtle);
    background: var(--surface-secondary);
    min-height: 32px;
}

.timeline-header-left {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.timeline-header-right {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.timeline-title {
    font: var(--type-overline);
    color: var(--text-muted);
    letter-spacing: 0.06em;
}

.timeline-timecode {
    font: var(--type-mono);
    font-size: 11px;
    color: var(--accent-primary);
    min-width: 64px;
    text-align: center;
    padding: 2px var(--space-2);
    background: var(--surface-tertiary);
    border-radius: var(--radius-sm);
}

/* -----------------------------------------------------------------------
   Transport Controls
   ----------------------------------------------------------------------- */

.timeline-transport {
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.timeline-transport-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: background-color var(--motion-instant), color var(--motion-instant);
}

.timeline-transport-btn:hover {
    background: var(--surface-tertiary);
    color: var(--text-primary);
}

.timeline-transport-btn[aria-pressed="true"],
.timeline-transport-btn-active {
    color: var(--accent-primary);
}

.timeline-transport-btn svg {
    width: 14px;
    height: 14px;
}

/* -----------------------------------------------------------------------
   Timeline Body (tracks area)
   ----------------------------------------------------------------------- */

.timeline-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Track labels (left sidebar) */
.timeline-labels {
    width: 140px;
    min-width: 140px;
    border-right: 1px solid var(--border-subtle);
    overflow-y: auto;
    scrollbar-width: none;
}

.timeline-labels::-webkit-scrollbar {
    display: none;
}

.timeline-label {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 0 var(--space-2);
    height: 28px;
    border-bottom: 1px solid var(--border-subtle);
    font: var(--type-caption);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background-color var(--motion-instant);
}

.timeline-label:hover {
    background: var(--surface-tertiary);
}

.timeline-label-selected {
    background: var(--accent-primary-subtle);
    color: var(--accent-primary);
}

.timeline-label-icon {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    opacity: 0.5;
}

.timeline-label-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.timeline-label-actions {
    display: flex;
    gap: var(--space-0-5);
    opacity: 0;
    transition: opacity var(--motion-instant);
}

.timeline-label:hover .timeline-label-actions {
    opacity: 1;
}

/* -----------------------------------------------------------------------
   Tracks Canvas
   ----------------------------------------------------------------------- */

.timeline-tracks {
    flex: 1;
    overflow-x: auto;
    overflow-y: auto;
    position: relative;
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

.timeline-tracks-inner {
    position: relative;
    min-width: 100%;
}

/* Ruler */
.timeline-ruler {
    height: 20px;
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--surface-secondary);
    border-bottom: 1px solid var(--border-subtle);
}

.timeline-ruler-tick {
    position: absolute;
    top: 0;
    width: 1px;
    background: var(--border-subtle);
}

.timeline-ruler-tick-major {
    height: 12px;
}

.timeline-ruler-tick-minor {
    height: 6px;
    opacity: 0.4;
}

.timeline-ruler-label {
    position: absolute;
    top: 2px;
    font: var(--type-caption);
    font-size: 9px;
    color: var(--text-muted);
    transform: translateX(-50%);
    white-space: nowrap;
}

/* Track rows */
.timeline-track {
    height: 28px;
    position: relative;
    border-bottom: 1px solid var(--border-subtle);
}

.timeline-track:hover {
    background: rgba(108, 92, 231, 0.02);
}

/* -----------------------------------------------------------------------
   Keyframes
   ----------------------------------------------------------------------- */

.timeline-keyframe {
    position: absolute;
    top: 50%;
    width: 10px;
    height: 10px;
    transform: translate(-50%, -50%) rotate(45deg);
    background: var(--accent-primary);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    cursor: pointer;
    transition: transform var(--motion-instant), box-shadow var(--motion-instant);
    z-index: 1;
}

.timeline-keyframe:hover {
    transform: translate(-50%, -50%) rotate(45deg) scale(1.3);
    box-shadow: 0 0 8px rgba(108, 92, 231, 0.5);
}

.timeline-keyframe-selected {
    background: var(--accent-secondary);
    border-color: rgba(255, 255, 255, 0.5);
    box-shadow: 0 0 12px rgba(240, 185, 77, 0.4);
}

/* Keyframe types */
.timeline-keyframe-ease {
    border-radius: 50%;
    transform: translate(-50%, -50%) rotate(0deg);
}

.timeline-keyframe-ease:hover {
    transform: translate(-50%, -50%) rotate(0deg) scale(1.3);
}

/* Clip regions */
.timeline-clip {
    position: absolute;
    top: 4px;
    height: 20px;
    border-radius: var(--radius-sm);
    background: var(--accent-primary-subtle);
    border: 1px solid var(--accent-primary);
    cursor: move;
    transition: opacity var(--motion-instant);
}

.timeline-clip:hover {
    opacity: 0.9;
}

.timeline-clip-label {
    font: var(--type-caption);
    font-size: 9px;
    color: var(--accent-primary);
    padding: 0 var(--space-1);
    line-height: 20px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* -----------------------------------------------------------------------
   Playhead
   ----------------------------------------------------------------------- */

.timeline-playhead {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--error);
    z-index: 3;
    pointer-events: none;
}

.timeline-playhead::before {
    content: '';
    position: absolute;
    top: 0;
    left: -5px;
    width: 11px;
    height: 8px;
    background: var(--error);
    clip-path: polygon(0 0, 100% 0, 50% 100%);
    pointer-events: auto;
    cursor: ew-resize;
}

/* -----------------------------------------------------------------------
   Zoom Controls
   ----------------------------------------------------------------------- */

.timeline-zoom {
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.timeline-zoom-slider {
    width: 80px;
    height: 4px;
    accent-color: var(--accent-primary);
}

/* -----------------------------------------------------------------------
   Resize Handle
   ----------------------------------------------------------------------- */

.timeline-resize-handle {
    height: 4px;
    cursor: ns-resize;
    background: var(--surface-secondary);
    position: relative;
}

.timeline-resize-handle::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 2px;
    border-radius: 1px;
    background: var(--border-subtle);
}

.timeline-resize-handle:hover::after {
    background: var(--accent-primary);
}

/* -----------------------------------------------------------------------
   Reduced Motion
   ----------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    .timeline-keyframe,
    .timeline-clip {
        transition: none;
    }
}
