/* ============================================================================
   SECURE VIDEO PLAYER STYLES (TIẾNG VIỆT HAY LMS)
   Shared across: Sandbox Player, Course Intro Video, Preview Modal & Classroom.
   Brand Guidelines: Pink (#ff4b82 / #ee5d9d), Dark (#020617 / #0f172a).
   ============================================================================ */

/* Secure Player Container */
.secure-player-container {
    position: relative;
    background-color: #020617;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2), 0 10px 10px -5px rgba(0, 0, 0, 0.1);
    border: 1px solid #1e293b;
    width: 100%;
}

.video-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background-color: #000000;
    overflow: hidden;
    -webkit-user-select: none;
    user-select: none;
}

/* HTML5 Video Element */
#secureVideo {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* Loader Screen Overlay */
.video-loader {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(2, 6, 23, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #f1f5f9;
    z-index: 50;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.video-loader i {
    font-size: 40px;
    color: #ff4b82; /* Pink brand color */
    margin-bottom: 15px;
}

.video-loader p {
    font-size: 14px;
    font-weight: 500;
    color: #94a3b8;
}

/* Mobile/Static Floating Watermark Overlay */
.watermark-overlay {
    position: absolute;
    color: rgba(255, 255, 255, 0.15); /* Semi-transparent white */
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.5px;
    pointer-events: none; /* Make click-through */
    z-index: 40;
    -webkit-user-select: none;
    user-select: none;
    white-space: nowrap;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
    transition: top 0.5s ease-in-out, left 0.5s ease-in-out;
}

/* Customizing Plyr CSS Variables to match brand color guidelines */
.plyr {
    --plyr-color-main: #ff4b82; /* Pink Accent color */
    --plyr-video-background: #000000;
    --plyr-border-radius: 16px;
    height: 100%;
}

.plyr .watermark-overlay {
    z-index: 3 !important;
}

.plyr .video-loader {
    z-index: 4 !important;
}

/* Fullscreen Mode Overrides */
.video-wrapper:fullscreen #secureVideo {
    object-fit: contain;
}

.video-wrapper:fullscreen .custom-video-controls {
    bottom: 10px;
    width: 96%;
    left: 2%;
    border-radius: 12px;
}

/* Disable double-tap-to-zoom on player areas */
.video-wrapper, .plyr, .plyr__video-wrapper, .plyr__video-container {
    touch-action: manipulation !important;
}

/* 1. Clean Initial State / Stopped State */
.player-not-started .plyr__controls {
    opacity: 0 !important;
    pointer-events: none !important;
    transform: translateY(15px);
}
.plyr__controls {
    transition: opacity 0.4s ease, transform 0.4s ease !important;
}
/* Force controls visibility on hotkey press (Normal & Fullscreen) */
.plyr--controls-visible .plyr__controls {
    opacity: 1 !important;
    pointer-events: auto !important;
    transform: translateY(0) !important;
}
.player-not-started .watermark-overlay,
.player-not-started .video-loader {
    display: none !important;
}

/* 2. Big Center Play Button (Clean Initial State Poster Only) */
.plyr-center-play-btn {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(1);
    width: 76px;
    height: 76px;
    background-color: rgba(255, 75, 130, 0.9);
    border: none;
    border-radius: 50%;
    color: #ffffff;
    font-size: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 45;
    box-shadow: 0 0 25px rgba(255, 75, 130, 0.5);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.plyr-center-play-btn i {
    margin-left: 5px; /* Offset to center the play icon triangle */
}
.plyr-center-play-btn:hover {
    background-color: #ff4b82;
    transform: translate(-50%, -50%) scale(1.1);
    box-shadow: 0 0 35px rgba(255, 75, 130, 0.8);
}
.plyr-center-play-btn::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid rgba(255, 75, 130, 0.5);
    animation: centerPlayPulse 2s infinite;
}
@keyframes centerPlayPulse {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(1.6); opacity: 0; }
}
/* Hide center button when video is playing or loading has started */
.secure-player-container:not(.player-not-started) .plyr-center-play-btn {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    transform: translate(-50%, -50%) scale(0.8);
}
.plyr--loading .plyr-center-play-btn {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

/* 4. Center Play/Pause Ripple Indicator (Desktop & Fullscreen feedback) */
.center-ripple-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    width: 80px;
    height: 80px;
    background-color: rgba(0, 0, 0, 0.65);
    border-radius: 50%;
    color: #ffffff;
    font-size: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 44;
    pointer-events: none;
    opacity: 0;
    transition: all 0.4s ease-out;
}
.center-ripple-indicator.animate {
    animation: centerRippleScale 0.6s ease-out forwards;
}
@keyframes centerRippleScale {
    0% { transform: translate(-50%, -50%) scale(0.8); opacity: 0; }
    50% { opacity: 0.9; }
    100% { transform: translate(-50%, -50%) scale(1.6); opacity: 0; }
}

/* 5. Accumulative Seek Side Overlays (YouTube Style) */
.seek-overlay {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 25%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 42;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}
.seek-overlay-left {
    left: 0;
    border-radius: 0 100% 100% 0 / 0 50% 50% 0;
    background: linear-gradient(to right, rgba(0, 0, 0, 0.45), transparent);
}
.seek-overlay-right {
    right: 0;
    border-radius: 100% 0 0 100% / 50% 0 0 50%;
    background: linear-gradient(to left, rgba(0, 0, 0, 0.45), transparent);
}
.seek-overlay-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    gap: 6px;
}
.seek-overlay-content i {
    font-size: 24px;
}
.seek-overlay-left i {
    animation: arrowBounceLeft 0.5s infinite alternate ease-in-out;
}
.seek-overlay-right i {
    animation: arrowBounceRight 0.5s infinite alternate ease-in-out;
}
@keyframes arrowBounceLeft {
    0% { transform: translateX(0); }
    100% { transform: translateX(-6px); }
}
@keyframes arrowBounceRight {
    0% { transform: translateX(0); }
    100% { transform: translateX(6px); }
}
.seek-seconds {
    font-size: 13px;
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
}
.seek-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* 6. Timeline Hover Preview Card & Hide redundant Plyr seek tooltip */
.plyr__progress .plyr__tooltip {
    display: none !important;
}
.plyr-hover-preview {
    position: absolute;
    bottom: 65px;
    left: 0;
    transform: translateX(-50%);
    z-index: 50;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}
.plyr-hover-preview.visible {
    opacity: 1;
    visibility: visible;
}
.plyr-hover-preview-card {
    position: relative;
    background-color: #000000;
    border: 2px solid #ffffff;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    width: 140px;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.plyr-hover-preview-card::after {
    content: '';
    position: absolute;
    bottom: -7px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 7px solid #ffffff;
    z-index: 51;
}
.plyr-hover-preview-video {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    background-color: #000000;
    border-radius: 6px 6px 0 0;
}
.plyr-hover-preview-time {
    color: #ffffff;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 0;
    background-color: rgba(0, 0, 0, 0.7);
    width: 100%;
    text-align: center;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0 0 6px 6px;
}

/* 7. YouTube-Style Controls Layout (Fix Overlap & Compact Spacing) */
.plyr__controls {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 2px 14px 6px 14px !important;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0.3) 70%, rgba(0, 0, 0, 0) 100%) !important;
    gap: 0 !important;
}

/* Freeze controls visibility ONLY while popover settings menu is active */
.plyr--popover-open .plyr__controls,
.plyr--popover-open.plyr--hide-controls .plyr__controls,
.plyr:has(button[data-plyr="settings"][aria-expanded="true"]) .plyr__controls,
.plyr:has(button[data-plyr="settings"][aria-expanded="true"]).plyr--hide-controls .plyr__controls {
    opacity: 1 !important;
    pointer-events: auto !important;
    transform: translateY(0) !important;
    visibility: visible !important;
}

/* Force progress bar to take 100% width on top row with tight spacing */
.plyr__controls .plyr__progress,
.plyr__controls .plyr__progress__container,
.plyr__controls [data-plyr="progress"] {
    position: relative !important;
    top: auto !important;
    bottom: auto !important;
    left: auto !important;
    right: auto !important;
    flex: 0 0 100% !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 0 2px 0 !important;
    padding: 0 !important;
    order: 1 !important;
    height: 14px !important;
    min-height: 14px !important;
    display: flex !important;
    align-items: center !important;
}

/* Tighten progress bar range input height */
.plyr__controls .plyr__progress input[type="range"] {
    height: 4px !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* Compact button height and alignment */
.plyr__controls > .plyr__control,
.plyr__controls > .plyr__volume,
.plyr__controls > .plyr__time,
.plyr__controls > .plyr__menu {
    height: 32px !important;
    padding: 4px 6px !important;
    display: flex !important;
    align-items: center !important;
}

/* Group left controls: Play, Volume, Time */
.plyr__controls > [data-plyr="play"],
.plyr__controls > .plyr__volume,
.plyr__controls > .plyr__time,
.plyr__controls > .plyr__time--current,
.plyr__controls > .plyr__time--duration {
    order: 2 !important;
    position: relative !important;
    top: auto !important;
    bottom: auto !important;
}

/* Group right controls: Settings, Fullscreen */
.plyr__controls > .plyr__menu,
.plyr__controls > [data-plyr="settings"],
.plyr__controls > [data-plyr="fullscreen"] {
    order: 3 !important;
    position: relative !important;
    top: auto !important;
    bottom: auto !important;
}

/* Desktop Slide-out Volume on Hover & Keyboard Adjustment */
@media (min-width: 769px) {
    .plyr__controls .plyr__volume {
        display: flex !important;
        align-items: center !important;
        max-width: 34px !important;
        transition: max-width 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
        overflow: hidden !important;
    }
    .plyr__controls .plyr__volume:hover,
    .plyr--volume-active .plyr__controls .plyr__volume {
        max-width: 110px !important;
    }
    .plyr__controls .plyr__volume input[type="range"] {
        width: 60px !important;
        min-width: 60px !important;
        transition: opacity 0.2s ease !important;
        opacity: 0 !important;
        margin-left: 6px !important;
    }
    .plyr__controls .plyr__volume:hover input[type="range"],
    .plyr--volume-active .plyr__controls .plyr__volume input[type="range"] {
        opacity: 1 !important;
    }
}

/* 8. Preview Expiry Modal */
.preview-modal-container {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.preview-modal-backdrop {
    position: absolute;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.65);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}
.preview-modal-content {
    position: relative;
    background-color: #ffffff;
    border-radius: 16px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    max-width: 420px;
    width: 100%;
    padding: 32px;
    text-align: center;
    border: 1px solid #e2e8f0;
    z-index: 2;
}
.preview-modal-icon {
    font-size: 44px;
    color: #ff4b82;
    margin-bottom: 16px;
}
.preview-modal-title {
    font-size: 19px;
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 12px;
    margin-top: 0;
}
.preview-modal-text {
    font-size: 14px;
    color: #475569;
    line-height: 1.6;
    margin-bottom: 24px;
    margin-top: 0;
}

/* 9. Mobile Layout Optimization overrides */
@media (max-width: 768px) {
    .plyr__controls {
        padding: 4px 10px !important;
    }
    .plyr__controls [data-plyr="play"] {
        display: flex !important;
    }
    .plyr__volume,
    .plyr--is-mobile .plyr__volume {
        display: none !important;
    }
    .plyr__menu__container {
        max-height: 135px !important;
        overflow: hidden !important;
    }
    .plyr__menu__container > div {
        max-height: 135px !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        overscroll-behavior: contain;
        -ms-overflow-style: none;
    }
    .plyr__menu__container [role="menu"] {
        max-height: none !important;
        overflow: visible !important;
    }
    .plyr__menu__container > div::-webkit-scrollbar {
        display: none !important;
        width: 0 !important;
        height: 0 !important;
    }
}
