/* ===================================
   Стили для видео блоков с фиксированным размером
   =================================== */

.dialogue-card {
    display: block;
    margin-bottom: 20px;
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    background-color: #fff;
    clear: both;
}

.dialogue-card:hover {
    background-color: #f9f9f9;
}

.dialogue-text-cell {
    padding: 20px;
    box-sizing: border-box;
    min-width: 220px;
    vertical-align: top;
}

.dialogue-card {
    box-sizing: border-box; /* ensure padding is included in width calculations */
}

.dialogue-header {
    margin-bottom: 10px;
    font-size: 1.1em;
}

.dialogue-id {
    color: #666;
    font-size: 0.9em;
    margin-left: 5px;
}

.dialogue-types {
    margin-bottom: 12px;
    font-size: 0.95em;
    /* Render child type tags inline and allow wrapping */
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

/* Individual small tag for each dialogue type (light grey rounded rectangle) */
.dialogue-type {
    display: inline-block;
    background-color: #f1f3f5; /* light grey */
    color: #333;
    padding: 2px 8px;
    font-size: 0.85em;
    border-radius: 8px; /* rounded corners */
    line-height: 1.6;
    box-shadow: none;
}
.dialogue-type:first-child { margin-left: 0; }

.dialogue-content {
    line-height: 1.6;
    margin-bottom: 15px;
}

.dialogue-meta {
    color: #666;
    font-size: 0.9em;
    font-style: italic;
}

.dialogue-video-cell {
    padding: 15px;
    box-sizing: border-box;
    width: 360px;
    max-width: 360px;
    float: right;
    margin-left: 16px;
}

/* Видео блок: responsive wrapper that enforces an aspect ratio and maximum size
   The <video> element will fill this box without changing its dimensions. */
.video-block {
    position: relative;
    width: 100%;
    /* Ensure the video never exceeds its column width */
    max-width: 100%;
    margin: 0 auto;
    aspect-ratio: 16/9; /* modern browsers keep height in sync */
    background-color: #000;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.video-container {
    position: absolute;
    inset: 0; /* fill the wrapper */
    width: 100%;
    height: 100%;
}

/* The video fills the container and keeps the container size stable.
   We avoid absolute positioning on the video itself to reduce reflows. */
.dialogue-video {
    display: block;
    width: 100% !important;
    height: 100% !important; /* fill the container (which enforces aspect ratio) */
    object-fit: contain; /* the video will be letterboxed if necessary */
    object-position: center center;
    background-color: #000;
    border-radius: inherit;
    transition: none !important;
    transform: none !important;
    max-width: 100%;
    box-sizing: border-box;
}

/* Defend against inline styles added by scripts */
.dialogue-video[style] {
    width: 100% !important;
    height: auto !important;
}

/* Stronger safeguards: ensure the video column and video itself never overflow the dialogue card.
   These rules are specific to dialogue-card to avoid affecting other video elements site-wide. */
.dialogue-card .dialogue-video-cell {
    width: 360px !important;
    max-width: 360px !important;
    overflow: hidden !important;
}

.dialogue-card .video-block {
    max-width: 100% !important;
    width: 100% !important;
    box-sizing: border-box !important;
}

.dialogue-card .dialogue-video {
    max-width: 100% !important;
    width: 100% !important;
    height: auto !important;
    display: block !important;
}

/* If other styles try to expand the element, clip visually to the container */
.dialogue-card { overflow: hidden; }

/* Предотвращение изменения размера при воспроизведении */
.dialogue-video::-webkit-media-controls {
    width: 100%;
    height: 100%;
}

.dialogue-video::-webkit-media-controls-enclosure {
    width: 100%;
    height: 100%;
}

/* Индикатор загрузки */
.video-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: rgba(0, 0, 0, 0.5);
    color: white;
    z-index: 1;
    pointer-events: none !important; /* Never block clicks - let them pass through to video controls */
    transition: opacity 0.3s ease;
}

/* Hide browser's native loading spinner */
video::-webkit-media-controls-start-playback-button {
    opacity: 1;
}

.spinner {
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin-bottom: 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Респонсивность для меньших экранов */
@media (max-width: 768px) {
    .dialogue-video-cell {
        float: none;
        width: 100%;
        max-width: 100%;
        padding: 10px;
        margin-left: 0;
        margin-bottom: 12px;
    }
    .dialogue-text-cell { padding: 10px; }
    .video-block {
        width: 100%;
        height: 0;
        padding-bottom: 56.25%; /* 16:9 */
    }
    .video-container {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
    }
}

.video-loading p {
    margin: 0;
    font-size: 14px;
}

/* Сообщение об ошибке */
.video-error {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: rgba(220, 53, 69, 0.9);
    color: white;
    z-index: 10;
    padding: 20px;
    text-align: center;
}

.video-error .error-content {
    text-align: center;
}

.video-error .error-message {
    margin: 0 0 5px 0;
    font-size: 18px;
    font-weight: bold;
}

.video-error .error-details {
    margin: 0 0 15px 0;
    font-size: 14px;
    opacity: 0.9;
}

.retry-btn {
    background-color: white;
    color: #dc3545;
    border: none;
    padding: 8px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s ease;
}

.retry-btn:hover {
    background-color: #f8f9fa;
    transform: scale(1.05);
}

.show-placeholder-btn {
    background-color: white;
    color: #6c757d;
    border: none;
    padding: 8px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s ease;
    margin-left: 10px;
}

.show-placeholder-btn:hover {
    background-color: #f8f9fa;
    transform: scale(1.05);
}
