/**
 * TikNia Pro Video Studio - Professional Video Editor Interface (Desktop & Mobile - Pro Edition)
 * Inspired by CapCut, InShot, and modern NLE suites.
 */

html, body.editor-mode {
    height: 100vh;
    height: 100dvh;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #07090E;
    color: #F3F4F6;
    user-select: none;
    -webkit-user-select: none;
}

/* Master Grid Layout */
.editor-layout {
    display: grid;
    grid-template-rows: 52px 1fr 300px;
    grid-template-columns: 64px 320px 1fr 300px;
    grid-template-areas:
        "header header header header"
        "tools drawer stage inspector"
        "tools timeline timeline timeline";
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
    position: relative;
}

/* 1. Header Bar */
.editor-header {
    grid-area: header;
    background: #0E131F;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    z-index: 1000;
}
.editor-header .header-left,
.editor-header .header-center,
.editor-header .header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.project-title-input {
    background: transparent;
    border: 1px solid transparent;
    color: #F9FAFB;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1rem;
    padding: 0.2rem 0.5rem;
    border-radius: var(--radius-sm);
    max-width: 220px;
    transition: all 0.15s ease;
}
.project-title-input:hover, .project-title-input:focus {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.15);
    outline: none;
}

/* 2. Left Tool Tabs */
.editor-tools-sidebar {
    grid-area: tools;
    background: #0A0D15;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.75rem 0;
    gap: 0.35rem;
    z-index: 900;
}
.tool-tab-btn {
    width: 52px;
    height: 52px;
    border-radius: var(--radius-md);
    background: transparent;
    border: none;
    color: #9CA3AF;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font-size: 0.65rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}
.tool-tab-btn i {
    font-size: 1.25rem;
}
.tool-tab-btn:hover {
    color: #FFFFFF;
    background: rgba(255, 255, 255, 0.05);
}
.tool-tab-btn.active {
    color: #FFFFFF;
    background: var(--accent-light);
    color: var(--accent);
}

/* 3. Tool Drawer / Library Panel */
.editor-drawer {
    grid-area: drawer;
    background: #111624;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 850;
    position: relative;
}
.drawer-header {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.drawer-title {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 0.95rem;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.drawer-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

/* Upload Dropzone inside Drawer */
.upload-dropzone {
    border: 2px dashed rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.02);
    border-radius: var(--radius-lg);
    padding: 1.5rem 1rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
}
.upload-dropzone:hover, .upload-dropzone.dragover {
    border-color: var(--accent);
    background: var(--accent-light);
}

/* Media Item Grid */
.media-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.65rem;
    margin-top: 0.75rem;
}
.media-card-item {
    background: #192032;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-md);
    overflow: hidden;
    position: relative;
    cursor: grab;
    transition: all 0.2s ease;
}
.media-card-item:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}
.media-card-item .preview-thumb {
    width: 100%;
    aspect-ratio: 16/9;
    object-fit: cover;
    background: #000;
    display: block;
}
.media-card-item .media-info {
    padding: 0.4rem 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.media-card-item .media-title {
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #E5E7EB;
}
.media-card-item .btn-add-track {
    position: absolute;
    top: 6px;
    right: 6px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s ease;
}
.media-card-item:hover .btn-add-track {
    opacity: 1;
}

/* 4. Canvas Stage / Preview Area */
.editor-stage {
    grid-area: stage;
    background: #06080D;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    padding: 1rem;
}
.canvas-wrapper {
    position: relative;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
    border-radius: 4px;
    overflow: hidden;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: width 0.25s ease, height 0.25s ease;
}
#mainPreviewCanvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    cursor: crosshair;
}

/* Safe Area Overlays (TikTok/Reels UI simulator) */
.safe-area-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    border: 1px dashed rgba(255, 255, 255, 0.3);
    display: none;
}
.safe-area-overlay.active {
    display: block;
}
.safe-area-overlay .social-hud-mock {
    position: absolute;
    right: 12px;
    bottom: 80px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
    color: rgba(255, 255, 255, 0.6);
    font-size: 1.25rem;
}

/* Transport Controls Floating Bar */
.stage-transport-bar {
    position: absolute;
    bottom: 16px;
    background: rgba(17, 24, 39, 0.85);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 30px;
    padding: 0.4rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    z-index: 50;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}
.transport-btn {
    background: transparent;
    border: none;
    color: #D1D5DB;
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s ease, transform 0.15s ease;
}
.transport-btn:hover {
    color: #FFFFFF;
    transform: scale(1.1);
}
.transport-btn.btn-play-pause {
    background: var(--accent);
    color: #FFF;
    width: 36px;
    height: 36px;
    border-radius: 50%;
}
.timecode-display {
    font-family: monospace;
    font-size: 0.85rem;
    color: #9CA3AF;
    font-weight: 600;
}
.timecode-display .current-time {
    color: #FFFFFF;
}

/* 5. Right Inspector / Properties Panel */
.editor-inspector {
    grid-area: inspector;
    background: #111624;
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    z-index: 850;
}
.inspector-header {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.inspector-body {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.property-group {
    background: #171E30;
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-md);
    padding: 0.85rem;
}
.property-group-title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #9CA3AF;
    margin-bottom: 0.65rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* 6. Multi-Track Timeline */
.editor-timeline {
    grid-area: timeline;
    background: #0C101A;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 800;
    position: relative;
}

/* Timeline Toolbar */
.timeline-toolbar {
    height: 42px;
    background: #111625;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
}
.timeline-tools-left, .timeline-tools-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.t-tool-btn {
    background: transparent;
    border: 1px solid transparent;
    color: #9CA3AF;
    border-radius: var(--radius-sm);
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    transition: all 0.15s ease;
}
.t-tool-btn:hover {
    color: #FFF;
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
}
.t-tool-btn.active {
    color: var(--accent);
    background: var(--accent-light);
}

/* Timeline Content Area (Ruler + Tracks) */
.timeline-viewport {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* Time Ruler */
.timeline-ruler-container {
    height: 28px;
    background: #0E1321;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    position: relative;
    user-select: none;
}
.track-headers-spacer {
    width: 140px;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    background: #0D121F;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    padding-left: 0.75rem;
    color: #6B7280;
    font-weight: 600;
}
.timeline-ruler-canvas-wrap {
    flex: 1;
    overflow-x: hidden;
    position: relative;
    cursor: pointer;
}
#timelineRulerCanvas {
    height: 28px;
    display: block;
}

/* Track Scroll Area */
.timeline-tracks-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Individual Track Row */
.timeline-track-row {
    display: flex;
    min-height: 52px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    position: relative;
    background: rgba(14, 19, 33, 0.5);
}
.timeline-track-row:hover {
    background: rgba(20, 27, 46, 0.6);
}
.track-header {
    width: 140px;
    min-width: 140px;
    background: #0D121F;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    padding: 0.5rem 0.75rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: sticky;
    left: 0;
    z-index: 20;
}
.track-header .track-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: #E5E7EB;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.track-header .track-actions {
    display: flex;
    gap: 0.4rem;
    margin-top: 0.2rem;
}
.track-action-btn {
    background: transparent;
    border: none;
    color: #6B7280;
    font-size: 0.75rem;
    padding: 0;
    cursor: pointer;
}
.track-action-btn:hover, .track-action-btn.active {
    color: #FFF;
}

/* Track Clips Lane */
.track-clips-lane {
    flex: 1;
    position: relative;
    min-width: 2000px;
    height: 100%;
}

/* Timeline Clip Item */
.timeline-clip {
    position: absolute;
    top: 5px;
    height: 42px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    padding: 0 0.5rem;
    color: #FFFFFF;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.15);
    overflow: hidden;
    user-select: none;
    transition: border-color 0.1s ease, box-shadow 0.1s ease;
}
.timeline-clip.selected {
    border: 2px solid #FFFFFF;
    box-shadow: 0 0 16px rgba(99, 102, 241, 0.7);
    z-index: 10;
}

/* Keyframe Diamond Markers */
.clip-keyframe-diamond {
    position: absolute;
    top: 3px;
    width: 8px;
    height: 8px;
    background: #FBBF24;
    transform: rotate(45deg);
    border: 1px solid #000;
    z-index: 6;
}

/* Audio Waveform Mock Background */
.clip-audio-wave {
    position: absolute;
    inset: 0;
    opacity: 0.25;
    background: repeating-linear-gradient(90deg, #FFFFFF, #FFFFFF 2px, transparent 2px, transparent 6px);
    pointer-events: none;
}

/* Track Type Coloring */
.timeline-clip[data-type="video"] {
    background: linear-gradient(135deg, #3B82F6 0%, #1D4ED8 100%);
}
.timeline-clip[data-type="text"] {
    background: linear-gradient(135deg, #F59E0B 0%, #D97706 100%);
    color: #000;
}
.timeline-clip[data-type="sticker"] {
    background: linear-gradient(135deg, #8B5CF6 0%, #6D28D9 100%);
}
.timeline-clip[data-type="audio"] {
    background: linear-gradient(135deg, #10B981 0%, #047857 100%);
}

/* Clip Trim Handles */
.clip-handle-left, .clip-handle-right {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 8px;
    background: rgba(255, 255, 255, 0.4);
    cursor: ew-resize;
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 5;
}
.clip-handle-left { left: 0; border-top-left-radius: 4px; border-bottom-left-radius: 4px; }
.clip-handle-right { right: 0; border-top-right-radius: 4px; border-bottom-right-radius: 4px; }
.timeline-clip:hover .clip-handle-left,
.timeline-clip:hover .clip-handle-right,
.timeline-clip.selected .clip-handle-left,
.timeline-clip.selected .clip-handle-right {
    opacity: 1;
}

/* Red Playhead Needle */
.timeline-playhead {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 140px;
    width: 2px;
    background: #EF4444;
    pointer-events: none;
    z-index: 30;
    transform: translateX(0);
}
.playhead-head {
    width: 14px;
    height: 16px;
    background: #EF4444;
    clip-path: polygon(0% 0%, 100% 0%, 50% 100%);
    position: absolute;
    top: 0;
    left: -6px;
    cursor: grab;
    pointer-events: auto;
}

/* ==========================================================
   MOBILE APP-LIKE REDESIGN (< 768px)
   ========================================================== */
@media (max-width: 768px) {
    .editor-layout {
        display: flex;
        flex-direction: column;
        height: 100vh;
        height: 100dvh;
    }

    .editor-header {
        height: 48px;
        padding: 0 0.5rem;
    }
    .project-title-input {
        max-width: 130px;
        font-size: 0.85rem;
    }
    .header-btn-text {
        display: none;
    }

    .editor-tools-sidebar {
        display: none;
    }
    .editor-drawer {
        position: fixed;
        bottom: 56px;
        left: 0;
        right: 0;
        height: 380px;
        border-radius: 20px 20px 0 0;
        border-right: none;
        border-top: 1px solid rgba(255, 255, 255, 0.15);
        box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.8);
        transform: translateY(110%);
        transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
        z-index: 1050;
    }
    .editor-drawer.open {
        transform: translateY(0);
    }

    .editor-inspector {
        position: fixed;
        bottom: 56px;
        left: 0;
        right: 0;
        height: 360px;
        border-radius: 20px 20px 0 0;
        border-left: none;
        border-top: 1px solid rgba(255, 255, 255, 0.15);
        box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.8);
        transform: translateY(110%);
        transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
        z-index: 1050;
    }
    .editor-inspector.open {
        transform: translateY(0);
    }

    .editor-stage {
        flex: 1;
        min-height: 220px;
        padding: 0.5rem;
    }
    .canvas-wrapper {
        max-height: 50vh;
    }

    .editor-timeline {
        height: 190px;
        min-height: 190px;
    }
    .track-headers-spacer, .track-header {
        width: 80px;
        min-width: 80px;
        padding: 0.25rem 0.4rem;
    }
    .track-header .track-title {
        font-size: 0.65rem;
    }
    .timeline-playhead {
        left: 80px;
    }

    .mobile-bottom-bar {
        height: 56px;
        background: #0B0E17;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        display: flex;
        align-items: center;
        overflow-x: auto;
        padding: 0 0.5rem;
        gap: 0.4rem;
        z-index: 1000;
    }
    .mobile-bottom-bar::-webkit-scrollbar {
        display: none;
    }
    .mob-action-btn {
        flex: 0 0 auto;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        background: transparent;
        border: none;
        color: #9CA3AF;
        font-size: 0.65rem;
        font-weight: 600;
        padding: 0.35rem 0.65rem;
        border-radius: var(--radius-sm);
    }
    .mob-action-btn i {
        font-size: 1.15rem;
    }
    .mob-action-btn:active, .mob-action-btn.active {
        color: var(--accent);
        background: var(--accent-light);
    }
}
