/**
 * Sereno Player - Player de Vídeo Avançado
 * Casa do Sereno - 2025
 *
 * Player customizado com:
 * - Lazy loading inteligente
 * - Proteções anti-download
 * - Controles elegantes estilo YouTube/Netflix
 * - Responsivo e acessível
 */

/* ===== CONTAINER PRINCIPAL ===== */
.sereno-player {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.sereno-player * {
    box-sizing: border-box;
}

/* ===== ELEMENTO DE VÍDEO ===== */
.sereno-video-element {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
    z-index: 1;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sereno-player.video-ready .sereno-video-element {
    opacity: 1;
}

/* Esconder controles nativos quando customizados estão ativos */
.sereno-video-element::-webkit-media-controls {
    display: none !important;
}

.sereno-video-element::-webkit-media-controls-enclosure {
    display: none !important;
}

.sereno-video-element::-webkit-media-controls-panel {
    display: none !important;
}

/* ===== POSTER/PREVIEW ===== */
.sereno-player-poster {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #1a1a2e;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: opacity 0.4s ease;
}

.sereno-player-poster::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0.1) 0%,
        rgba(0, 0, 0, 0.3) 50%,
        rgba(0, 0, 0, 0.6) 100%
    );
}

.sereno-player.video-started .sereno-player-poster {
    opacity: 0;
    pointer-events: none;
}

/* Botão de Play Grande */
.sereno-play-button {
    position: relative;
    z-index: 2;
    width: 80px;
    height: 80px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.95);
    color: #1a1a2e;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.sereno-play-button svg {
    width: 36px;
    height: 36px;
    margin-left: 4px; /* Ajuste visual para centralizar o play */
}

.sereno-play-button:hover {
    transform: scale(1.1);
    background: #fff;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.sereno-play-button:active {
    transform: scale(0.95);
}

/* Info no Poster */
.sereno-poster-info {
    position: absolute;
    bottom: 20px;
    right: 20px;
    z-index: 2;
}

.sereno-duration {
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* ===== LOADING OVERLAY ===== */
.sereno-player-loading {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.sereno-player.is-loading .sereno-player-loading {
    opacity: 1;
    pointer-events: auto;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-text {
    color: #fff;
    margin-top: 16px;
    font-size: 14px;
    font-weight: 500;
}

.loading-progress {
    width: 200px;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    margin-top: 12px;
    overflow: hidden;
}

.loading-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #8b5cf6);
    border-radius: 2px;
    width: 0%;
    transition: width 0.3s ease;
}

/* ===== CONTROLES ===== */
.sereno-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 15;
    padding: 0 16px 12px;
    background: linear-gradient(
        to top,
        rgba(0, 0, 0, 0.9) 0%,
        rgba(0, 0, 0, 0.6) 50%,
        transparent 100%
    );
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
}

.sereno-player:hover .sereno-controls,
.sereno-player.controls-visible .sereno-controls,
.sereno-player.is-paused .sereno-controls {
    opacity: 1;
    transform: translateY(0);
}

/* Progress Bar Container */
.sereno-progress-container {
    position: relative;
    width: 100%;
    z-index: 20; /* Garantir que barra de progresso fique acima do overlay de loading */
    padding: 12px 0 8px;
    cursor: pointer;
}

.sereno-progress-bar {
    position: relative;
    width: 100%;
    height: 5px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    overflow: visible;
    transition: height 0.15s ease;
}

.sereno-progress-container:hover .sereno-progress-bar {
    height: 7px;
}

.sereno-progress-buffered {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
    transition: width 0.1s linear;
}

.sereno-progress-played {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #8b5cf6);
    border-radius: 3px;
    transition: width 0.1s linear;
}

.sereno-progress-handle {
    position: absolute;
    top: 50%;
    width: 14px;
    height: 14px;
    background: #fff;
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    transition: transform 0.15s ease;
    z-index: 2;
}

.sereno-progress-container:hover .sereno-progress-handle {
    transform: translate(-50%, -50%) scale(1);
}

/* Time Tooltip */
.sereno-time-tooltip {
    position: absolute;
    bottom: 100%;
    left: 0;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    margin-bottom: 8px;
}

.sereno-progress-container:hover .sereno-time-tooltip {
    opacity: 1;
}

/* Controls Bottom */
.sereno-controls-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 4px;
}

.sereno-controls-left,
.sereno-controls-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Botões */
.sereno-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: #fff;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s ease;
    padding: 0;
}

.sereno-btn svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
}

.sereno-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.sereno-btn:active {
    transform: scale(0.9);
}

/* Play/Pause */
.sereno-play-pause .icon-pause {
    display: none;
}

.sereno-player.is-playing .sereno-play-pause .icon-play {
    display: none;
}

.sereno-player.is-playing .sereno-play-pause .icon-pause {
    display: block;
}

/* Mute/Volume */
.sereno-mute .icon-muted {
    display: none;
}

.sereno-player.is-muted .sereno-mute .icon-volume {
    display: none;
}

.sereno-player.is-muted .sereno-mute .icon-muted {
    display: block;
}

/* Volume Container */
.sereno-volume-container {
    display: flex;
    align-items: center;
    gap: 4px;
}

.sereno-volume-slider {
    width: 0;
    opacity: 0;
    transition: all 0.3s ease;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    cursor: pointer;
}

.sereno-volume-container:hover .sereno-volume-slider {
    width: 80px;
    opacity: 1;
}

.sereno-volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: #fff;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.sereno-volume-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: #fff;
    border-radius: 50%;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* Time Display */
.sereno-time {
    display: flex;
    align-items: center;
    gap: 4px;
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    margin-left: 8px;
}

.sereno-time-separator {
    opacity: 0.7;
}

/* Fullscreen */
.sereno-fullscreen .icon-compress {
    display: none;
}

.sereno-player.is-fullscreen .sereno-fullscreen .icon-expand {
    display: none;
}

.sereno-player.is-fullscreen .sereno-fullscreen .icon-compress {
    display: block;
}

/* ===== SETTINGS MENU ===== */
.sereno-settings-menu {
    position: absolute;
    bottom: 70px;
    right: 16px;
    background: rgba(20, 20, 30, 0.95);
    border-radius: 12px;
    padding: 8px 0;
    min-width: 200px;
    z-index: 20;
    opacity: 0;
    transform: translateY(10px) scale(0.95);
    pointer-events: none;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.sereno-player.settings-open .sereno-settings-menu {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.sereno-settings-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.sereno-settings-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.sereno-settings-label {
    color: #fff;
    font-size: 14px;
    font-weight: 500;
}

.sereno-settings-value {
    color: rgba(255, 255, 255, 0.7);
    font-size: 13px;
}

/* ===== ERROR OVERLAY ===== */
.sereno-error-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 20;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.sereno-player.has-error .sereno-error-overlay {
    opacity: 1;
    pointer-events: auto;
}

.sereno-error-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.sereno-error-message {
    color: #fff;
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 20px;
}

.sereno-error-retry {
    padding: 12px 24px;
    background: #3b82f6;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.sereno-error-retry:hover {
    background: #2563eb;
    transform: translateY(-2px);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .sereno-play-button {
        width: 64px;
        height: 64px;
    }

    .sereno-play-button svg {
        width: 28px;
        height: 28px;
    }

    .sereno-controls {
        padding: 0 12px 8px;
    }

    .sereno-btn {
        width: 36px;
        height: 36px;
    }

    .sereno-btn svg {
        width: 18px;
        height: 18px;
    }

    .sereno-time {
        font-size: 11px;
    }

    .sereno-volume-container:hover .sereno-volume-slider {
        width: 60px;
    }
}

@media (max-width: 480px) {
    .sereno-play-button {
        width: 56px;
        height: 56px;
    }

    .sereno-play-button svg {
        width: 24px;
        height: 24px;
    }

    .sereno-duration {
        font-size: 11px;
        padding: 4px 8px;
    }

    .sereno-poster-info {
        bottom: 12px;
        right: 12px;
    }

    .sereno-controls-bottom {
        gap: 4px;
    }

    .sereno-btn {
        width: 32px;
        height: 32px;
    }

    .sereno-time {
        font-size: 10px;
        margin-left: 4px;
    }

    .sereno-volume-slider {
        display: none !important;
    }

    .sereno-settings-menu {
        right: 8px;
        min-width: 180px;
    }
}

/* ===== FULLSCREEN ADJUSTMENTS ===== */
.sereno-player.is-fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    padding-bottom: 0 !important;
    z-index: 999999 !important;
    border-radius: 0 !important;
}

.sereno-player.is-fullscreen .sereno-play-button {
    width: 100px;
    height: 100px;
}

.sereno-player.is-fullscreen .sereno-play-button svg {
    width: 44px;
    height: 44px;
}

.sereno-player.is-fullscreen .sereno-controls {
    padding: 0 24px 20px;
}

.sereno-player.is-fullscreen .sereno-btn {
    width: 48px;
    height: 48px;
}

.sereno-player.is-fullscreen .sereno-btn svg {
    width: 26px;
    height: 26px;
}

.sereno-player.is-fullscreen .sereno-time {
    font-size: 15px;
}

/* ===== PROTEÇÕES ANTI-DOWNLOAD ===== */
.sereno-player::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2;
    pointer-events: none;
}

/* Overlay transparente que impede clique direto no vídeo (bypass controles) */
.sereno-player::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 60px; /* Deixa espaço para os controles */
    z-index: 3;
    cursor: pointer;
}

/* Esconder elementos de download/save */
.sereno-video-element::-internal-media-controls-download-button,
.sereno-video-element::-webkit-media-controls-download-button {
    display: none !important;
}

/* Double-click para fullscreen */
.sereno-player.double-click-fs::after {
    pointer-events: auto;
}

/* ===== ANIMAÇÕES ===== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

.sereno-player.video-ready {
    animation: fadeIn 0.3s ease;
}

/* ===== ACESSIBILIDADE ===== */
.sereno-btn:focus-visible,
.sereno-play-button:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

.sereno-progress-bar:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 4px;
}

/* ===== DARK MODE PREFERENCE ===== */
@media (prefers-color-scheme: dark) {
    .sereno-settings-menu {
        background: rgba(10, 10, 20, 0.98);
    }
}

/* ===== PRINT ===== */
@media print {
    .sereno-player {
        display: none !important;
    }
}
