/* Frontend Styles for YouTube Playlist Player */

.ypp-player-wrapper {
    width: 100%;
    margin: 20px 0;
    text-align: center; /* Center inner inline-block/flex content on the page */
}

/* Single Video Mode */
.ypp-single-mode {
    width: 100%;
    max-width: 100%;
    display: flex;
    justify-content: center;
    padding: 0 20px;
}

/* Popup Style - Only main thumbnail */
.ypp-popup-style {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0 20px;
    box-sizing: border-box;
}

.ypp-popup-style .ypp-main-thumbnail {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    display: flex;
    justify-content: center;
}

/* Sidebar Style - Left thumbnail, Right playlist */
.ypp-sidebar-style {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start; /* Let left thumbnail define visual height */
    padding: 0 20px;
}

.ypp-main-thumbnail-sidebar {
    flex: 1;
    min-width: 300px;
    max-width: 800px;
}

.ypp-playlist-sidebar-frontend {
    flex: 0 0 350px;
    min-width: 300px;
    /* FRONTEND ONLY: visible playlist shorter than main thumbnail height (roughly one card less) */
    max-height: calc(var(--ypp-thumb-height, 720px) - 90px);
    overflow-y: auto;       /* Scroll inside if content is taller than main image */
    background: #f9f9f9;
    padding: 15px;
    border-radius: 8px;
}

.ypp-video-list-frontend {
    list-style: none;
    padding: 0;
    margin: 0;
}

.ypp-video-item-frontend {
    display: flex;
    gap: 12px;
    padding: 10px;
    margin-bottom: 8px;
    background: #fff;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease;
    border: 2px solid transparent;
}

.ypp-video-item-frontend:hover {
    background: #f0f0f0;
    transform: translateX(3px);
}

.ypp-video-item-frontend.active {
    background: #fff3cd;
    border-color: #ffc107;
}

.ypp-video-thumb-frontend {
    position: relative;
    flex-shrink: 0;
    width: 100px;
    height: 56px;
    border-radius: 4px;
    overflow: hidden;
}

.ypp-video-thumb-frontend img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ypp-video-info-frontend {
    flex: 1;
    min-width: 0;
}

.ypp-video-info-frontend h4 {
    margin: 0;
    font-size: 0.9em;
    font-weight: 600;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* Legacy Playlist Mode (for backward compatibility) */
.ypp-playlist-mode {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.ypp-main-thumbnail {
    flex: 1;
    min-width: 300px;
    max-width: 800px;
}

.ypp-playlist-sidebar {
    flex: 0 0 350px;
    min-width: 300px;
}

.ypp-playlist-title {
    margin: 0 0 15px 0;
    font-family: var(--ypp-playlist-title-font-family, 'Marcellus SC', serif);
    font-size: var(--ypp-playlist-title-font-size, 24px);
    font-weight: var(--ypp-playlist-title-font-weight, bold);
    font-style: var(--ypp-playlist-title-font-style, normal);
    color: var(--ypp-playlist-title-font-color, #000000);
}

.ypp-video-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 600px;
    overflow-y: auto;
}

.ypp-video-item {
    display: flex;
    gap: 12px;
    padding: 10px;
    margin-bottom: 8px;
    background: #f5f5f5;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease;
}

.ypp-video-item:hover {
    background: #e8e8e8;
    transform: translateX(3px);
}

.ypp-video-item.active {
    background: #fff3cd;
    border-left: 3px solid #ffc107;
}

.ypp-video-thumb {
    position: relative;
    flex-shrink: 0;
    width: 120px;
    height: 68px;
    border-radius: 6px;
    overflow: hidden;
}

.ypp-video-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ypp-play-icon-small {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ypp-play-icon-small::after {
    content: '';
    width: 0;
    height: 0;
    border-left: 8px solid rgba(0, 0, 0, 0.8);
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    margin-left: 2px;
}

.ypp-video-info {
    flex: 1;
    min-width: 0;
}

.ypp-video-info h4 {
    margin: 0 0 5px 0;
    font-size: 0.95em;
    font-weight: 600;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.ypp-time-range {
    display: none !important; /* Hide time codes as per user request */
}

/* Thumbnail Wrapper - Same style as original plugin, fully responsive */
.ypp-thumb-wrapper {
    position: relative;
    width: 100%;
    max-width: calc(100vw - 40px); /* always fit within viewport with padding on large screens */
    overflow: hidden;
    cursor: pointer;
    border: 2px solid #ffffff;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    display: block;
    margin: 0 auto;
    box-sizing: border-box;
}

/* Use CSS variables as maximum dimensions (never force bigger than viewport) */
.ypp-player-wrapper[style*="--ypp-thumb-height"] .ypp-thumb-wrapper {
    max-height: var(--ypp-thumb-height, 720px);
}
.ypp-player-wrapper[style*="--ypp-thumb-width"] .ypp-thumb-wrapper {
    max-width: min(var(--ypp-thumb-width, 9999px), calc(100vw - 40px));
}

/* If width is 0 (auto), compute from height at 16:9, still clamped to viewport */
.ypp-player-wrapper[style*="--ypp-thumb-width: 0px"] .ypp-thumb-wrapper,
.ypp-player-wrapper[style*="--ypp-thumb-width: 0"] .ypp-thumb-wrapper {
    max-width: min(calc(var(--ypp-thumb-height, 720px) * 16 / 9), calc(100vw - 40px));
}

.ypp-thumb-wrapper picture,
.ypp-thumb-wrapper .ypp-thumb-img,
.ypp-thumb-wrapper > picture > img {
    position: relative;
    display: block;
    width: 100%;
    height: auto;           /* keep full image, no cropping */
    object-fit: contain;    /* fit entirely inside wrapper */
}

/* Ensure thumbnail container takes full width */
.ypp-main-thumbnail,
.ypp-main-thumbnail-sidebar {
    width: 100%;
    max-width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.ypp-popup-style .ypp-main-thumbnail,
.ypp-sidebar-style .ypp-main-thumbnail-sidebar {
    width: 100%;
    max-width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Centered golden play icon */
.ypp-play-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 72px;
    height: 72px;
    transform: translate(-50%, -50%);
    border-radius: 999px;
    background: linear-gradient(135deg, #f5d76e, #c6970b);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
    opacity: 0.95;
    z-index: 10;
}

.ypp-play-icon .ypp-play-triangle {
    width: 0;
    height: 0;
    border-left: 18px solid rgba(0, 0, 0, 0.85);
    border-top: 11px solid transparent;
    border-bottom: 11px solid transparent;
    margin-left: 3px;
}

.ypp-thumb-wrapper:hover .ypp-play-icon {
    transform: translate(-50%, -50%) scale(1.05);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}

/* Video Overlay Popup */
#ypp-video-overlay {
    position: fixed;
    z-index: 999999;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

#ypp-video-overlay-inner {
    position: relative;
    width: 100%;
    max-width: 1200px;
    margin: 0 20px;
    display: flex;
    gap: 20px;
    max-height: 90vh;
}

#ypp-video-player-container {
    flex: 1;
    min-width: 0;
    aspect-ratio: 16/9;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
}

#ypp-video-player-container iframe,
#ypp-video-player-container video {
    width: 100%;
    height: 100%;
    border: 0;
}

#ypp-playlist-overlay {
    flex: 0 0 350px;
    background: #1a1a1a;
    border-radius: 8px;
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden; /* Prevent horizontal scroll bar */
    max-height: calc(90vh - 40px);
}

#ypp-playlist-overlay h3 {
    color: #fff;
    margin: 0 0 15px 0;
    font-size: 1.1em;
}

#ypp-playlist-overlay .ypp-video-list {
    max-height: none;
}

#ypp-playlist-overlay .ypp-video-item {
    background: #2a2a2a;
    color: #fff;
}

#ypp-playlist-overlay .ypp-video-item:hover {
    background: #3a3a3a;
}

#ypp-playlist-overlay .ypp-video-item.active {
    background: #4a4a2a;
    border-left-color: #ffc107;
}

#ypp-playlist-overlay .ypp-video-info h4 {
    color: #fff;
}

#ypp-playlist-overlay .ypp-time-range {
    display: none !important; /* Hide time codes in popup playlist */
}

/* Custom scrollbar styling for popup playlist and inline sidebar playlist */
#ypp-playlist-overlay,
.ypp-playlist-sidebar-frontend .ypp-video-list-frontend {
    /* Firefox scrollbar */
    scrollbar-width: thin;
    scrollbar-color: #c6970b #000000;
}

/* WebKit scrollbars (Chrome, Edge, Safari) */
#ypp-playlist-overlay::-webkit-scrollbar,
.ypp-playlist-sidebar-frontend .ypp-video-list-frontend::-webkit-scrollbar {
    width: 12px;
}

#ypp-playlist-overlay::-webkit-scrollbar-track,
.ypp-playlist-sidebar-frontend .ypp-video-list-frontend::-webkit-scrollbar-track {
    background: #000000; /* Black background */
    border-radius: 999px;
}

#ypp-playlist-overlay::-webkit-scrollbar-thumb,
.ypp-playlist-sidebar-frontend .ypp-video-list-frontend::-webkit-scrollbar-thumb {
    border-radius: 999px; /* Oval / pill shape */
    background: linear-gradient(135deg, #f5d76e, #c6970b); /* Golden gradient */
    border: 2px solid #000000; /* Separate from track */
}

/* Scrollbar buttons (top and bottom arrows) */
#ypp-playlist-overlay::-webkit-scrollbar-button,
.ypp-playlist-sidebar-frontend .ypp-video-list-frontend::-webkit-scrollbar-button {
    height: 12px;
    background: linear-gradient(135deg, rgba(245, 215, 110, 0.5), rgba(198, 151, 11, 0.5)); /* Softer gold */
    border-radius: 999px;
}


#ypp-video-overlay-close {
    position: fixed;
    top: 20px;
    right: 20px;
    color: #ffffff;
    font-size: 32px;
    cursor: pointer;
    z-index: 1000000;
    font-weight: 700;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    transition: background 0.2s ease;
}

#ypp-video-overlay-close:hover {
    background: rgba(0, 0, 0, 0.8);
}

/* Responsive */
@media (max-width: 768px) {
    .ypp-popup-style,
    .ypp-sidebar-style {
        padding: 0 20px;
    }
    
    .ypp-popup-style .ypp-main-thumbnail,
    .ypp-main-thumbnail-sidebar {
        width: 100%;
        max-width: 100%;
        justify-content: center;
    }
    
    /* On mobile, ignore admin height and just make thumbnail fully responsive */
    .ypp-player-wrapper .ypp-thumb-wrapper {
        max-width: calc(100vw - 40px);
        width: 100%;
        max-height: none;
    }
    
    .ypp-player-wrapper .ypp-thumb-wrapper picture,
    .ypp-player-wrapper .ypp-thumb-wrapper img {
        width: 100%;
        height: auto;
        object-fit: contain;
    }
    
    .ypp-sidebar-style {
        flex-direction: column;
    }
    
    .ypp-playlist-sidebar-frontend {
        flex: 1;
        max-width: 100%;
    }
    
    #ypp-video-overlay-inner {
        flex-direction: column;
        max-height: 95vh;
    }
    
    #ypp-video-player-container {
        aspect-ratio: 16/9;
        max-height: 50vh;
    }
    
    #ypp-playlist-overlay {
        flex: 1;
        max-height: 40vh;
    }
}

