/* ========== STYLE DLA FILMÓW YOUTUBE ========== */

.ytvm-video-container {
    margin: 20px 0;
    padding: 0;
    background: #fff;
    border: none;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,.08), 0 1px 3px rgba(0,0,0,.1);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    height: auto;
    overflow: hidden;
    box-sizing: border-box;
    position: relative;
    max-width: 100%; /* Zawsze ogranicz do dostępnej szerokości */
    width: auto; /* Pozwól na elastyczność */
}

.ytvm-video-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #ff0000, #ff4444);
    z-index: 1;
}

.ytvm-video-container:hover {
    box-shadow: 0 8px 30px rgba(0,0,0,.12), 0 2px 6px rgba(0,0,0,.1);
    transform: translateY(-2px);
}

.ytvm-video-title {
    font-size: 18px;
    font-weight: 700;
    margin: 0;
    padding: 20px 20px 15px 20px;
    color: #1a1a1a;
    line-height: 1.4;
    flex-shrink: 0;
    letter-spacing: -0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.ytvm-video-wrapper {
    position: relative;
    padding-bottom: 56.25%;
    height: 0;
    overflow: hidden;
    margin: 0;
    border-radius: 0;
    background: #000;
    flex-shrink: 0;
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
}

.ytvm-video-wrapper iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
}

.ytvm-video-description-wrapper {
    margin: 0;
    padding: 15px 20px 20px 20px;
    position: relative;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    z-index: 1;
}

/* Przycisk "Czytaj opis" */
.ytvm-read-description-btn {
    margin: 0;
    padding: 10px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 8px;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    width: 100%;
    justify-content: center;
}

.ytvm-read-description-btn:hover {
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    transform: translateY(-1px);
}

.ytvm-read-description-btn:active {
    transform: translateY(0);
}

.ytvm-read-description-btn:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.3);
}

.ytvm-read-description-btn svg {
    transition: transform 0.3s ease;
}

.ytvm-read-description-btn:hover svg {
    transform: translateX(2px);
}

/* ========== POPUP Z OPISEM ========== */

.ytvm-popup {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.ytvm-popup.ytvm-popup-active {
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
}

.ytvm-popup-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(2px);
}

.ytvm-popup-content {
    position: relative;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    max-width: 700px;
    width: 90%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    z-index: 1;
    animation: ytvm-popup-slide-in 0.3s ease;
}

@keyframes ytvm-popup-slide-in {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.ytvm-popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 25px;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
}

.ytvm-popup-title {
    margin: 0;
    margin-right: auto;
    font-size: 20px;
    font-weight: 600;
    color: #333;
    line-height: 1.4;
    text-align: left;
    flex: 0 1 auto;
}

.ytvm-popup-close {
    background: transparent;
    border: none;
    font-size: 28px;
    line-height: 1;
    color: #666;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
    margin-left: auto;
    flex-shrink: 0;
}

.ytvm-popup-close:hover {
    background: #f5f5f5;
    color: #333;
}

.ytvm-popup-close:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

.ytvm-popup-body {
    padding: 25px;
    overflow-y: auto;
    flex: 1;
}

.ytvm-popup-description {
    color: #4a5568;
    line-height: 1.8;
    font-size: 15px;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.ytvm-popup-description p {
    margin: 0 0 15px 0;
    color: #4a5568;
}

.ytvm-popup-description p:last-child {
    margin-bottom: 0;
}

.ytvm-popup-body::-webkit-scrollbar {
    width: 8px;
}

.ytvm-popup-body::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.ytvm-popup-body::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 4px;
}

.ytvm-popup-body::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
}

/* ========== ROZMIARY FILMÓW ========== */

.ytvm-video-container {
    max-width: 100%;
    /* Zapewnij, że kontener zawsze mieści się w dostępnej przestrzeni */
    box-sizing: border-box;
}

/* Responsywne skalowanie - gdy kontener nie mieści się, zmniejsz go */
.ytvm-video-container[data-size],
.ytvm-video-container[data-width] {
    max-width: 100% !important; /* Zawsze ogranicz do 100% dostępnej szerokości */
}

.ytvm-video-container[data-size="200px"] {
    width: min(200px, 100%) !important;
    max-width: min(200px, 100%) !important;
    flex-basis: min(200px, 100%);
}

.ytvm-video-container[data-size="200px"] .ytvm-video-wrapper {
    max-width: 100%;
    padding-bottom: 112.5px;
}

.ytvm-video-container[data-size="300px"] {
    width: min(300px, 100%) !important;
    max-width: min(300px, 100%) !important;
    flex-basis: min(300px, 100%);
}

.ytvm-video-container[data-size="300px"] .ytvm-video-wrapper {
    max-width: 100%;
    padding-bottom: 168.75px;
}

.ytvm-video-container[data-size="small"] {
    width: min(400px, 100%) !important;
    max-width: min(400px, 100%) !important;
    flex-basis: min(400px, 100%);
}

.ytvm-video-container[data-size="small"] .ytvm-video-wrapper {
    max-width: 100%;
    padding-bottom: 225px;
}

.ytvm-video-container[data-size="medium"] {
    width: min(600px, 100%) !important;
    max-width: min(600px, 100%) !important;
    flex-basis: min(600px, 100%);
}

.ytvm-video-container[data-size="medium"] .ytvm-video-wrapper {
    max-width: 100%;
    padding-bottom: 337.5px;
}

.ytvm-video-container[data-size="large"] {
    width: min(800px, 100%) !important;
    max-width: min(800px, 100%) !important;
    flex-basis: min(800px, 100%);
}

.ytvm-video-container[data-size="large"] .ytvm-video-wrapper {
    max-width: 100%;
    padding-bottom: 450px;
}

.ytvm-video-container[data-size="full"] {
    width: 100%;
    max-width: 100%;
}

.ytvm-video-container[data-size="full"] .ytvm-video-wrapper {
    max-width: 100%;
}

/* Niestandardowe wymiary przez width/height */
.ytvm-video-container[data-width] {
    width: var(--ytvm-width, 100%) !important;
    max-width: 100% !important; /* Zawsze ogranicz do 100% dostępnej szerokości */
    flex-basis: var(--ytvm-width, 100%);
}

.ytvm-video-container[data-width] .ytvm-video-wrapper {
    max-width: 100%;
}

.ytvm-video-container[data-width][data-height] .ytvm-video-wrapper {
    padding-bottom: 0;
    height: var(--ytvm-height, auto);
}

/* ========== GRUPY FILMÓW ========== */

.ytvm-video-group {
    margin: 30px 0;
    padding: 20px;
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 8px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden; /* Zapobiega przewijaniu poziomemu */
}

/* Grupa bez ramki tła */
.ytvm-video-group.ytvm-no-background {
    background: transparent;
    border: none;
    padding: 0;
    margin: 20px 0;
}

/* Nazwa grupy */
.ytvm-group-title {
    text-align: center;
    font-size: 24px;
    font-weight: 700;
    margin: 0 0 20px 0;
    padding: 0;
    color: #1a1a1a;
    line-height: 1.3;
}

/* Opis grupy */
.ytvm-group-description {
    font-size: 16px;
    line-height: 1.6;
    color: #555;
    margin: 0 0 20px 0;
    padding: 15px;
    background: #fff;
    border-radius: 6px;
    border: 1px solid #e0e0e0;
}

.ytvm-group-description-top {
    margin-bottom: 20px;
}

.ytvm-group-description-bottom {
    margin-top: 20px;
    margin-bottom: 0;
}

.ytvm-videos-grid {
    display: flex;
    flex-wrap: wrap;
    margin-top: 20px;
    align-items: flex-start;
    align-content: flex-start;
    width: 100%;
    box-sizing: border-box;
    /* Resetuj padding i margin dla precyzyjnego wyrównania */
    padding: 0;
    margin-left: 0;
    margin-right: 0;
    margin-bottom: 0;
    /* Użyj ujemnego marginesu zamiast gap dla lepszego wyrównania */
    margin: 20px -10px 0 -10px;
}

/* Wyrównanie grupy - do lewej (domyślne) */
.ytvm-video-group[data-align="left"] .ytvm-videos-grid,
.ytvm-video-group:not([data-align]) .ytvm-videos-grid {
    justify-content: flex-start;
}

/* Wyrównanie grupy - do środka */
.ytvm-video-group[data-align="center"] .ytvm-videos-grid {
    justify-content: center;
}

/* Wyrównanie grupy - do prawej */
.ytvm-video-group[data-align="right"] .ytvm-videos-grid {
    justify-content: flex-end;
}

.ytvm-videos-grid .ytvm-video-container {
    margin: 0 10px 20px 10px !important;
    overflow: visible;
    height: auto;
    flex-shrink: 0;
    box-sizing: border-box;
    align-self: flex-start;
}

/* Filmy z określonym rozmiarem - stała szerokość, nie rozciągają się */
.ytvm-videos-grid .ytvm-video-container[data-size],
.ytvm-videos-grid .ytvm-video-container[data-width] {
    /* flex-basis jest ustawione przez selektory powyżej dla każdego rozmiaru */
    flex-grow: 0 !important;
    flex-shrink: 0 !important;
    align-self: flex-start;
    min-width: 0;
    /* Marginesy są ustawione w .ytvm-videos-grid .ytvm-video-container */
}

/* Filmy bez określonego rozmiaru - elastyczna szerokość */
.ytvm-videos-grid .ytvm-video-container:not([data-size]):not([data-width]) {
    flex: 1 1 300px; /* Minimalna szerokość 300px, może się rozszerzać */
    min-width: 300px;
    max-width: 100%;
}

/* Rozmiary dla grup - priorytet nad rozmiarami filmów */
/* Rozmiary z grupy są aplikowane przez JavaScript na kontenery, więc używamy standardowych selektorów */

/* ========== FILMY W WPISACH ========== */

.ytvm-post-videos {
    margin-top: 30px;
    padding-top: 30px;
    border-top: 2px solid #eee;
}

.ytvm-post-videos .ytvm-video-container {
    margin-bottom: 30px;
}

/* ========== RESPONSYWNOŚĆ ========== */

@media screen and (max-width: 768px) {
    /* Na mniejszych ekranach filmy zajmują pełną szerokość */
    .ytvm-videos-grid .ytvm-video-container:not([data-size]):not([data-width]) {
        flex: 1 1 100%;
        min-width: 100%;
    }
    
    /* Wszystkie filmy z określonym rozmiarem skalują się do 100% szerokości na małych ekranach */
    .ytvm-video-container[data-size],
    .ytvm-video-container[data-width] {
        width: 100% !important;
        max-width: 100% !important;
        flex-basis: 100% !important;
    }
    
    .ytvm-video-container[data-size] .ytvm-video-wrapper,
    .ytvm-video-container[data-width] .ytvm-video-wrapper {
        max-width: 100%;
    }
    
    .ytvm-popup-content {
        width: 95%;
        max-height: 90vh;
    }
    
    .ytvm-popup-header {
        padding: 15px 20px;
    }
    
    .ytvm-popup-title {
        font-size: 18px;
    }
    
    .ytvm-popup-body {
        padding: 20px;
    }
    
    .ytvm-popup-description {
        font-size: 14px;
    }
}

@media screen and (max-width: 480px) {
    .ytvm-video-container {
        padding: 10px;
    }
    
    .ytvm-video-title {
        font-size: 16px;
    }
}

/* ========== DODATKOWE STYLE ========== */

.ytvm-video-container.alignleft {
    float: left;
    margin-right: 20px;
    margin-bottom: 20px;
}

.ytvm-video-container.alignright {
    float: right;
    margin-left: 20px;
    margin-bottom: 20px;
}

.ytvm-video-container.aligncenter {
    margin-left: auto;
    margin-right: auto;
    display: block;
}
