/* =====================================================
   VIDEO PLAYER CSS
   Styling untuk video player dengan fitur PIP (Picture-in-Picture)
   ===================================================== */

/* ---------------------------------
   Video Wrapper (Container Utama)
--------------------------------- */
.video-wrapper {
    margin-bottom: 25px;
}

.video-container {
    position: relative;
    width: 100%;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    z-index: 10;
    /* Tidak ada transition di sini untuk mencegah CLS */
}

/* ---------------------------------
   Video Embed (Aspect Ratio 16:9)
--------------------------------- */
.video-embed {
    position: relative;
    width: 100%;
    padding-top: 56.25%; /* 16:9 aspect ratio */
    background: #1a1a2e;
}

.video-embed iframe,
.video-embed video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
}

/* Thumbnail untuk lazy-load */
.video-thumbnail {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Video Player Wrapper */
.video-player-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.video-player-wrapper iframe,
.video-player-wrapper video {
    width: 100%;
    height: 100%;
    border: none;
}

/* ---------------------------------
   Video Click Overlay
   Untuk mendeteksi klik user pada iframe
--------------------------------- */
.video-click-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    transition: all 0.3s ease;
}

.video-click-overlay:hover {
    background: rgba(0, 0, 0, 0.3);
}

.video-click-overlay:hover .play-button-overlay {
    transform: scale(1.1);
    background: rgba(129, 215, 66, 1);
}

.play-button-overlay {
    width: 80px;
    height: 80px;
    background: #dd3333;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.play-button-overlay svg {
    width: 40px;
    height: 40px;
    fill: #fff;
    /* margin-left: 5px; */ /* offset karena shape triangle */
}

.overlay-text {
    color: #fff;
    font-size: 14px;
    margin-top: 15px;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.video-click-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

/* ---------------------------------
   Video Caption
--------------------------------- */
.video-caption {
    font-size: 13px;
    color: #666;
    margin-top: 10px;
    font-style: italic;
    line-height: 1.5;
}

/* ---------------------------------
   Video Badge (Label Video)
--------------------------------- */
.video-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: linear-gradient(135deg, #ff0844 0%, #ffb199 100%);
    color: #fff !important;
    padding: 5px 12px;
    border-radius: 3px;
    font-size: 12px;
    font-weight: 600;
}

.video-badge svg {
    fill: #fff;
}

.video-badge a {
    color: #fff !important;
    text-decoration: none;
}

/* ---------------------------------
   Video Duration Badge
--------------------------------- */
.meta-duration {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.meta-duration svg {
    fill: #666;
}

/* ---------------------------------
   PIP Controls (Tombol di video floating)
--------------------------------- */
.pip-controls {
    position: absolute;
    top: 8px;
    right: 8px;
    display: none; /* Tersembunyi by default */
    gap: 5px;
    z-index: 100;
}

.pip-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: rgba(0,0,0,0.7);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    backdrop-filter: blur(4px);
}

.pip-btn:hover {
    background: rgba(0,0,0,0.9);
    transform: scale(1.1);
}

.pip-btn svg {
    width: 16px;
    height: 16px;
    fill: #fff;
}

.pip-drag {
    cursor: grab;
}

.pip-drag:active {
    cursor: grabbing;
}

.pip-close:hover {
    background: #dc3545;
}

.pip-expand:hover {
    background: #81d742;
}

/* ---------------------------------
   Position Selector (Pilih posisi PIP)
--------------------------------- */
.pip-position-selector {
    position: absolute;
    bottom: 8px;
    left: 8px;
    display: none; /* Tersembunyi by default */
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
    background: rgba(0,0,0,0.7);
    padding: 6px;
    border-radius: 6px;
    backdrop-filter: blur(4px);
    z-index: 100;
}

.pos-btn {
    width: 20px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.5);
    border-radius: 2px;
    background: transparent;
    cursor: pointer;
    transition: all 0.2s ease;
}

.pos-btn:hover {
    border-color: #81d742;
    background: rgba(129, 215, 66, 0.3);
}

.pos-btn.active {
    border-color: #81d742;
    background: #81d742;
}

/* ---------------------------------
   PIP Mode (Floating State)
--------------------------------- */
.video-container.pip-mode {
    position: fixed;
    width: 400px;
    height: 225px;
    border-radius: 8px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.3);
    z-index: 9999;
    /* Default position - bottom right */
    bottom: 20px;
    right: 20px;
}

/* Override aspect ratio in PIP mode */
.video-container.pip-mode .video-embed {
    padding-top: 0;
    height: 100%;
}

/* Show controls in PIP mode */
.video-container.pip-mode .pip-controls {
    display: flex;
}

.video-container.pip-mode:hover .pip-position-selector {
    display: grid;
}

/* Position presets */
.video-container.pip-mode.pos-top-left {
    top: 20px;
    left: 20px;
    bottom: auto;
    right: auto;
}

.video-container.pip-mode.pos-top-right {
    top: 20px;
    right: 20px;
    bottom: auto;
    left: auto;
}

.video-container.pip-mode.pos-bottom-left {
    bottom: 20px;
    left: 20px;
    top: auto;
    right: auto;
}

.video-container.pip-mode.pos-bottom-right {
    bottom: 20px;
    right: 20px;
    top: auto;
    left: auto;
}

/* Custom position (saat di-drag) - posisi via inline style */
.video-container.pip-mode.pos-custom {
    /* Posisi di-set via inline style oleh JavaScript */
    /* Jangan gunakan !important di sini */
}

/* Placeholder saat video floating */
.video-placeholder {
    width: 100%;
    padding-top: 56.25%;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border-radius: 8px;
    position: relative;
}

.video-placeholder::after {
    content: 'Video sedang dalam mode floating. Klik untuk kembali.';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: rgba(255,255,255,0.7);
    font-size: 14px;
    text-align: center;
    padding: 0 20px;
    cursor: pointer;
}

/* ---------------------------------
   Related Videos
--------------------------------- */
.related-videos .section-title {
    display: flex;
    align-items: center;
    gap: 8px;
}

.related-videos .section-title svg {
    fill: #81d742;
}

.video-item {
    position: relative;
}

.video-thumb {
    display: block;
    position: relative;
    overflow: hidden;
    border-radius: 5px;
}

.video-thumb img {
    transition: transform 0.3s ease;
}

.video-thumb:hover img {
    transform: scale(1.05);
}

.video-duration {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0,0,0,0.8);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 3px;
}

.video-play-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 50px;
    height: 50px;
    background: rgba(129, 215, 66, 0.9);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    opacity: 0;
}

.video-thumb:hover .video-play-icon {
    opacity: 1;
}

.video-play-icon svg {
    width: 24px;
    height: 24px;
    fill: #fff;
    margin-left: 3px;
}

/* ---------------------------------
   Animasi
--------------------------------- */
@keyframes pipSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Animasi masuk PIP - smooth slide in */
.video-container.pip-mode {
    animation: pipSlideIn 0.25s ease-out forwards;
}

/* Tidak ada animasi keluar - langsung kembali untuk mencegah CLS */

/* ---------------------------------
   Responsive
--------------------------------- */
@media (max-width: 991px) {
    .video-container.pip-mode {
        width: 360px;
        height: 202px;
    }
}

@media (max-width: 767px) {
    .video-container.pip-mode {
        width: 280px;
        height: 157px;
        bottom: 10px;
        right: 10px;
    }
    
    .video-container.pip-mode.pos-top-left,
    .video-container.pip-mode.pos-top-right {
        top: 70px; /* Di bawah header sticky */
    }
    
    .video-container.pip-mode.pos-bottom-left,
    .video-container.pip-mode.pos-bottom-right {
        bottom: 10px;
    }
    
    .video-container.pip-mode.pos-top-left,
    .video-container.pip-mode.pos-bottom-left {
        left: 10px;
    }
    
    .video-container.pip-mode.pos-top-right,
    .video-container.pip-mode.pos-bottom-right {
        right: 10px;
    }
    
    .pip-btn {
        width: 28px;
        height: 28px;
    }
    
    .pip-btn svg {
        width: 14px;
        height: 14px;
    }
    
    .pip-position-selector {
        display: none !important; /* Hide on mobile, use drag instead */
    }
    
    .video-caption {
        font-size: 12px;
    }
}

/* ---------------------------------
   Dragging State
--------------------------------- */
.video-container.pip-mode.dragging {
    cursor: grabbing;
    transition: none !important;
    user-select: none;
}

.video-container.pip-mode.dragging iframe,
.video-container.pip-mode.dragging video {
    pointer-events: none;
}

/* ---------------------------------
   Dark overlay saat drag
--------------------------------- */
.pip-drag-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9998;
    display: none;
}

.pip-drag-overlay.active {
    display: block;
}
