/**
 * Video Player Styles
 * Self-Hosted Video Management System
 */

/* Light Theme Variables */
:root {
    --player-bg: #f8f9fa;
    --player-controls-bg: rgba(255, 255, 255, 0.95);
    --player-text: #212529;
    --player-text-secondary: #6c757d;
    --player-border: #dee2e6;
    --player-hover: #e9ecef;
    --player-primary: #0d6efd;
    --player-shadow: rgba(0, 0, 0, 0.1);
}

/* Player Container */
.player-container {
    position: relative;
    width: 100%;
    background-color: var(--player-bg);
    aspect-ratio: 16/9;
    overflow: hidden;
    border-radius: var(--bs-border-radius, 0.375rem);
    border: 1px solid var(--player-border);
}

.video-player-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    background-color: var(--player-bg);
}

.video-player-wrapper video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* Download protection */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    pointer-events: none;
}

/* Re-enable pointer events for controls interaction via overlay */
.video-player-click-overlay {
    pointer-events: auto;
}

/* Prevent text selection on player */
.video-player-wrapper {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Click Overlay */
.video-player-click-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: calc(100% - 50px);
    cursor: pointer;
    z-index: 1;
}

/* Big Play Button */
.video-player-big-play {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80px;
    height: 80px;
    background: var(--player-primary);
    border: 4px solid white;
    box-shadow: 0 4px 20px rgba(13, 110, 253, 0.3);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    z-index: 2;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.video-player-big-play svg {
    width: 40px;
    height: 40px;
    fill: white;
    margin-left: 5px;
}

.video-player-big-play:hover {
    background: #0b5ed7;
    box-shadow: 0 6px 25px rgba(13, 110, 253, 0.4);
    transform: translate(-50%, -50%) scale(1.1);
}

.video-player-wrapper.playing .video-player-big-play {
    display: none;
}

/* Loader */
.video-player-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 3;
    display: none;
}

.video-player-wrapper.loading .video-player-loader {
    display: block;
}

.video-player-wrapper.loading .video-player-big-play {
    display: none;
}

.video-player-loader-spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Controls */
.video-player-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--player-controls-bg);
    border-top: 1px solid var(--player-border);
    box-shadow: 0 -2px 10px var(--player-shadow);
    padding: 12px;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.video-player-wrapper:hover .video-player-controls,
.video-player-wrapper.controls-visible .video-player-controls,
.video-player-wrapper.paused .video-player-controls {
    opacity: 1;
}

/* Progress Bar */
.video-player-progress {
    position: relative;
    height: 5px;
    background: var(--player-border);
    border-radius: 3px;
    cursor: pointer;
    margin-bottom: 10px;
}

.video-player-progress:hover {
    height: 7px;
}

.video-player-progress-buffered {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: rgba(13, 110, 253, 0.2);
    border-radius: 3px;
    transition: width 0.1s ease;
}

.video-player-progress-played {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: var(--player-primary);
    border-radius: 3px;
}

/* Watch Percentage Indicator */
.video-player-watch-percentage {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: linear-gradient(
        90deg,
        rgba(25, 135, 84, 0.5) 0%,
        rgba(25, 135, 84, 0.3) 100%
    );
    pointer-events: none;
    z-index: 1;
    border-radius: 3px;
    box-shadow: inset 0 -2px 0 rgba(25, 135, 84, 0.8);
}

/* Watch Percentage Badge */
.video-player-watch-badge {
    position: absolute;
    top: -30px;
    right: 12px;
    background: linear-gradient(135deg, #198754 0%, #157347 100%);
    color: white;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
    box-shadow: 0 2px 8px rgba(25, 135, 84, 0.3);
    z-index: 11;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

.video-player-watch-badge svg {
    width: 12px;
    height: 12px;
    fill: currentColor;
}

.video-player-progress-handle {
    position: absolute;
    top: 50%;
    width: 14px;
    height: 14px;
    background: #0d6efd;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.video-player-progress:hover .video-player-progress-handle {
    opacity: 1;
}

/* Thumbnail Preview */
.video-player-thumbnail-preview {
    position: absolute;
    bottom: 20px;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    border-radius: 4px;
    padding: 4px;
    display: none;
    z-index: 5;
}

.video-player-thumbnail-preview-image {
    width: 160px;
    height: 90px;
    background-size: cover;
    border-radius: 2px;
}

.video-player-thumbnail-preview-time {
    text-align: center;
    color: #fff;
    font-size: 12px;
    padding-top: 4px;
}

/* Controls Bar */
.video-player-controls-bar {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Buttons */
.video-player-btn {
    background: transparent;
    border: none;
    padding: 8px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--player-text);
    opacity: 0.75;
}

.video-player-btn svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

.video-player-btn:hover {
    background: var(--player-hover);
    opacity: 1;
}

/* Play/Pause Icons */
.video-player-btn-play .icon-pause {
    display: none;
}

.video-player-wrapper.playing .video-player-btn-play .icon-play {
    display: none;
}

.video-player-wrapper.playing .video-player-btn-play .icon-pause {
    display: block;
}

/* Mute Icons */
.video-player-btn-mute .icon-muted {
    display: none;
}

.video-player-wrapper.muted .video-player-btn-mute .icon-unmuted {
    display: none;
}

.video-player-wrapper.muted .video-player-btn-mute .icon-muted {
    display: block;
}

/* Like Icons */
.video-player-btn-like .icon-liked {
    display: none;
}

.video-player-wrapper.liked .video-player-btn-like .icon-like {
    display: none;
}

.video-player-wrapper.liked .video-player-btn-like .icon-liked {
    display: block;
    fill: #dc3545;
}

/* Fullscreen Icons */
.video-player-btn-fullscreen .icon-exit-fullscreen {
    display: none;
}

.video-player-wrapper.fullscreen .video-player-btn-fullscreen .icon-enter-fullscreen {
    display: none;
}

.video-player-wrapper.fullscreen .video-player-btn-fullscreen .icon-exit-fullscreen {
    display: block;
}

/* Subtitle Icons */
.video-player-btn-subtitles .icon-subtitles-on {
    display: block;
}

.video-player-btn-subtitles .icon-subtitles-off {
    display: none;
}

.video-player-wrapper.subtitles-enabled .video-player-btn-subtitles .icon-subtitles-on {
    display: none;
}

.video-player-wrapper.subtitles-enabled .video-player-btn-subtitles .icon-subtitles-off {
    display: block;
}

/* Audio Mode Icons */
.video-player-btn-audio-mode .icon-video-mode {
    display: none;
}

.video-player-wrapper.audio-only .video-player-btn-audio-mode .icon-audio-mode {
    display: none;
}

.video-player-wrapper.audio-only .video-player-btn-audio-mode .icon-video-mode {
    display: block;
}

/* Hide video-specific controls in audio mode */
.video-player-wrapper.audio-only .video-player-btn-fullscreen,
.video-player-wrapper.audio-only .video-player-btn-pip,
.video-player-wrapper.audio-only .video-player-btn-subtitles {
    display: none;
}

/* Active Button States */
.video-player-wrapper.subtitles-enabled .video-player-btn-subtitles,
.video-player-wrapper.audio-only .video-player-btn-audio-mode,
.video-player-wrapper.liked .video-player-btn-like,
.video-player-wrapper.muted .video-player-btn-mute {
    color: var(--player-primary);
    background: rgba(13, 110, 253, 0.1);
    opacity: 1;
}

/* Transcript Button Active State */
.video-player-wrapper.transcript-open .video-player-btn-transcript {
    color: var(--player-primary);
    background: rgba(13, 110, 253, 0.1);
    opacity: 1;
}

/* Volume */
.video-player-volume {
    display: flex;
    align-items: center;
    gap: 0;
}

.video-player-volume-slider-container {
    width: 0;
    overflow: hidden;
    transition: width 0.2s ease;
}

.video-player-volume:hover .video-player-volume-slider-container {
    width: 80px;
}

.video-player-volume-slider {
    width: 80px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--player-border);
    border-radius: 2px;
    cursor: pointer;
}

.video-player-volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    background: var(--player-primary);
    border-radius: 50%;
    cursor: pointer;
}

.video-player-volume-slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    background: var(--player-primary);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

/* Time Display */
.video-player-time {
    color: var(--player-text);
    font-size: 13px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    white-space: nowrap;
}

/* Spacer */
.video-player-spacer {
    flex: 1;
}

/* Settings Menu */
.video-player-settings {
    position: relative;
}

.video-player-settings-menu {
    position: absolute;
    bottom: 100%;
    right: 0;
    min-width: 220px;
    background: #ffffff;
    border-radius: 8px;
    padding: 8px 0;
    margin-bottom: 8px;
    display: none;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    border: 1px solid #dee2e6;
    z-index: 100;
}

.video-player-settings.active .video-player-settings-menu {
    display: block;
}

.video-player-settings-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    color: #212529;
    font-size: 14px;
    font-weight: 600;
    border-bottom: 1px solid #dee2e6;
    margin-bottom: 4px;
}

.video-player-settings-back {
    background: transparent;
    border: none;
    padding: 4px;
    cursor: pointer;
    color: #212529;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.video-player-settings-back:hover {
    background: #e9ecef;
}

.video-player-settings-back svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.video-player-settings-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    color: #212529;
    cursor: pointer;
    transition: background 0.2s ease;
}

.video-player-settings-item:hover {
    background: #e9ecef;
}

.video-player-settings-item-label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
}

.video-player-settings-item-label svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
    opacity: 0.7;
}

.video-player-settings-item-value {
    font-size: 13px;
    color: #6c757d;
}

.video-player-settings-item-check {
    width: 20px;
    height: 20px;
    fill: #0d6efd;
    opacity: 0;
}

.video-player-settings-item.active .video-player-settings-item-check {
    opacity: 1;
}

.video-player-settings-item.active {
    background: rgba(13, 110, 253, 0.1);
    color: #0d6efd;
}

.video-player-quality-badge {
    font-size: 10px;
    background: #e9ecef;
    color: #495057;
    padding: 2px 6px;
    border-radius: 3px;
    margin-left: 6px;
}

/* Audio Only Mode */
.video-player-audio-mode {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #fff;
    z-index: 2;
}

.video-player-wrapper.audio-only .video-player-audio-mode {
    display: flex;
}

.video-player-wrapper.audio-only video {
    visibility: hidden;
}

.video-player-audio-icon {
    width: 80px;
    height: 80px;
    fill: #0d6efd;
    margin-bottom: 20px;
}

.video-player-audio-title {
    font-size: 20px;
    font-weight: 500;
    margin-bottom: 8px;
}

.video-player-audio-subtitle {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 24px;
}

.video-player-audio-visualizer {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 40px;
}

.video-player-audio-visualizer-bar {
    width: 6px;
    background: #0d6efd;
    border-radius: 3px;
    animation: audioVisualize 0.6s ease-in-out infinite;
}

.video-player-audio-visualizer-bar:nth-child(1) { animation-delay: 0s; height: 20px; }
.video-player-audio-visualizer-bar:nth-child(2) { animation-delay: 0.1s; height: 30px; }
.video-player-audio-visualizer-bar:nth-child(3) { animation-delay: 0.2s; height: 40px; }
.video-player-audio-visualizer-bar:nth-child(4) { animation-delay: 0.3s; height: 25px; }
.video-player-audio-visualizer-bar:nth-child(5) { animation-delay: 0.4s; height: 35px; }

@keyframes audioVisualize {
    0%, 100% { transform: scaleY(0.5); }
    50% { transform: scaleY(1); }
}

.video-player-wrapper:not(.playing) .video-player-audio-visualizer-bar {
    animation: none;
    transform: scaleY(0.3);
}

/* Subtitles */
.video-player-subtitles {
    position: absolute;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    z-index: 5;
    pointer-events: none;
}

.video-player-subtitle-text {
    display: inline-block;
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 18px;
    line-height: 1.4;
    max-width: 80%;
}

.video-player-subtitle-text:empty {
    display: none;
}

/* Keyboard Hint */
.video-player-keyboard-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 16px 24px;
    border-radius: 8px;
    font-size: 18px;
    font-weight: 500;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    z-index: 20;
}

.video-player-keyboard-hint.visible {
    opacity: 1;
}

/* Transcript Panel */
.video-player-transcript-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: 360px;
    height: 100%;
    background: #ffffff;
    display: none;
    flex-direction: column;
    z-index: 15;
    border-left: 1px solid #e2e8f0;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
}

.video-player-wrapper.transcript-open .video-player-transcript-panel {
    display: flex;
}

.video-player-transcript-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}

.video-player-transcript-title {
    color: #1e293b;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.video-player-transcript-close {
    background: transparent;
    border: none;
    color: #64748b;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.video-player-transcript-close:hover {
    background: #e0f2fe;
    color: #0284c7;
    transform: scale(1.05);
}

.video-player-transcript-search {
    padding: 14px 20px;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}

.video-player-transcript-search input {
    width: 100%;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 10px 14px;
    color: #1e293b;
    font-size: 14px;
    transition: all 0.2s ease;
}

.video-player-transcript-search input::placeholder {
    color: #94a3b8;
}

.video-player-transcript-search input:focus {
    outline: none;
    border-color: #3b82f6;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.video-player-transcript-content {
    flex: 1;
    overflow-y: auto;
    padding: 14px 20px;
    background: #ffffff;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

.video-player-transcript-content::-webkit-scrollbar {
    width: 6px;
}

.video-player-transcript-content::-webkit-scrollbar-track {
    background: transparent;
}

.video-player-transcript-content::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.video-player-transcript-content::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.video-player-transcript-item {
    padding: 12px 14px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 8px;
    border: 1px solid transparent;
}

.video-player-transcript-item:hover {
    background: #f0f9ff;
    border-color: #bae6fd;
    transform: translateX(2px);
}

.video-player-transcript-item.active {
    background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
    border-color: #3b82f6;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.15);
}

.video-player-transcript-time {
    color: #0284c7;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 6px;
    font-family: 'Segoe UI', system-ui, sans-serif;
    letter-spacing: 0.3px;
}

.video-player-transcript-text {
    color: #334155;
    font-size: 14px;
    line-height: 1.6;
    font-family: 'Segoe UI', system-ui, sans-serif;
}

.video-player-transcript-item.active .video-player-transcript-time {
    color: #0369a1;
}

.video-player-transcript-item.active .video-player-transcript-text {
    color: #1e293b;
    font-weight: 500;
}

/* Search highlighting */
.video-player-transcript-text mark {
    background: #fef3c7;
    color: #92400e;
    padding: 2px 4px;
    border-radius: 3px;
    font-weight: 500;
}

/* Empty state styling */
.video-player-transcript-empty {
    padding: 40px 20px;
    text-align: center;
    color: #64748b;
}

.video-player-transcript-empty svg {
    opacity: 0.4;
    margin-bottom: 16px;
}

.video-player-transcript-empty strong {
    color: #475569;
    font-size: 16px;
    display: block;
    margin-bottom: 8px;
}

.video-player-transcript-empty small {
    color: #94a3b8;
    font-size: 13px;
}

/* Error Display */
.video-player-error {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 30;
    color: #fff;
    text-align: center;
    padding: 20px;
}

.video-player-wrapper.error .video-player-error {
    display: flex;
}

.video-player-wrapper.error .video-player-big-play,
.video-player-wrapper.error .video-player-loader,
.video-player-wrapper.error .video-player-controls {
    display: none;
}

.video-player-error-icon {
    width: 64px;
    height: 64px;
    fill: #dc3545;
    margin-bottom: 16px;
}

.video-player-error-title {
    font-size: 20px;
    font-weight: 500;
    margin-bottom: 8px;
}

.video-player-error-message {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 24px;
    max-width: 400px;
}

.video-player-error-actions {
    display: flex;
    gap: 12px;
}

.video-player-error-btn {
    background: #0d6efd;
    color: #fff;
    border: none;
    padding: 10px 24px;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.video-player-error-btn:hover {
    background: #0b5ed7;
}

.video-player-error-btn-secondary {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.video-player-error-btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Fullscreen Mode */
.video-player-wrapper.fullscreen {
    width: 100vw;
    height: 100vh;
}

/* PiP Button (hide if not supported) */
.video-player-btn-pip {
    display: none;
}

.video-player-wrapper.pip-supported .video-player-btn-pip {
    display: flex;
}

/* Responsive */
@media (max-width: 768px) {
    .video-player-controls-bar {
        gap: 4px;
    }

    .video-player-btn {
        padding: 6px;
    }

    .video-player-btn svg {
        width: 20px;
        height: 20px;
    }

    .video-player-time {
        font-size: 12px;
    }

    .video-player-btn-restart,
    .video-player-btn-audio-mode {
        display: none;
    }

    .video-player-transcript-panel {
        width: 100%;
    }

    .video-player-subtitle-text {
        font-size: 14px;
        padding: 6px 12px;
    }
}

@media (max-width: 480px) {
    .video-player-btn-transcript,
    .video-player-btn-pip {
        display: none;
    }

    .video-player-volume-slider-container {
        display: none;
    }
}
