/* Shorts Video Manager - Frontend Styles */

.shorts-video-container {
    max-width: 100%;
    margin: 0 auto;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* Сетка для видео */
.shorts-videos-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin: 0;
    padding: 0;
}

/* Контейнер для видео */
.shorts-video-item {
    margin: 0;
    background: #fff;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    position: relative;
}

.shorts-video-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
}

/* Плеер видео */
.video-player {
    position: relative;
    width: 100%;
    background: #000;
    overflow: hidden;
}

.shorts-video {
    width: 100%;
    height: auto;
    display: block;
    aspect-ratio: 9/16; /* Вертикальное видео для шортсов */
    object-fit: cover;
    background: #000;
}

/* Превью видео */
.shorts-video[poster] {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

/* Элементы управления */
.video-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
    padding: 20px 15px 15px;
    opacity: 0;
    transition: opacity 0.3s ease;
    display: flex;
    align-items: center;
    gap: 15px;
}

.video-player:hover .video-controls,
.video-player:focus-within .video-controls {
    opacity: 1;
}

/* Кнопка воспроизведения/паузы */
.play-pause-btn {
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.play-pause-btn:hover {
    background: #fff;
    transform: scale(1.1);
}

.play-pause-btn .play-icon,
.play-pause-btn .pause-icon {
    font-size: 18px;
    color: #333;
    font-weight: bold;
}

.play-pause-btn .pause-icon {
    display: none;
}

.shorts-video.playing .play-icon {
    display: none;
}

.shorts-video.playing .pause-icon {
    display: block;
}

/* Прогресс-бар */
.progress-bar {
    flex: 1;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #ff6b6b, #ff8e53);
    width: 0%;
    transition: width 0.1s ease;
    border-radius: 2px;
    position: relative;
}

.progress-fill::after {
    content: '';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 12px;
    height: 12px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Отображение времени */
.time-display {
    display: flex;
    align-items: center;
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    flex-shrink: 0;
}

.current-time {
    background: rgba(0, 0, 0, 0.5);
    padding: 4px 8px;
    border-radius: 12px;
    font-family: 'Monaco', 'Menlo', monospace;
}

/* Кнопка полноэкранного режима */
.fullscreen-btn {
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.fullscreen-btn:hover {
    background: #fff;
    transform: scale(1.1);
}

.fullscreen-btn::before {
    content: '⛶';
    font-size: 18px;
    color: #333;
}

/* Информация о видео */
.video-info {
    padding: 20px;
    background: #fff;
}

.video-title {
    margin: 0 0 12px 0;
    font-size: 18px;
    font-weight: 600;
    color: #1a1a1a;
    line-height: 1.4;
}

.video-description {
    margin: 0;
    font-size: 14px;
    color: #666;
    line-height: 1.5;
    font-style: italic;
}

/* Адаптивность для мобильных устройств */
@media (max-width: 768px) {
    .shorts-video-container {
        padding: 0 10px;
    }
    
    .shorts-videos-list {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }
    
    .shorts-video-item {
        margin: 0;
        border-radius: 12px;
    }
    
    .shorts-load-more,
    .shorts-no-more {
        grid-column: 1 / -1;
    }
    
    .video-controls {
        padding: 15px 10px 10px;
        gap: 10px;
    }
    
    .play-pause-btn,
    .fullscreen-btn {
        width: 40px;
        height: 40px;
    }
    
    .play-pause-btn .play-icon,
    .play-pause-btn .pause-icon {
        font-size: 16px;
    }
    
    .fullscreen-btn::before {
        font-size: 16px;
    }
    
    .video-info {
        padding: 15px;
    }
    
    .video-title {
        font-size: 16px;
    }
    
    .video-description {
        font-size: 13px;
    }
    
    .video-error {
        padding: 15px;
        font-size: 14px;
    }
    
    .retry-btn {
        padding: 6px 12px;
        font-size: 13px;
    }
}

@media (max-width: 480px) {
    .shorts-video-container {
        padding: 0 5px;
    }
    
    .shorts-videos-list {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    
    .shorts-video-item {
        margin: 0;
        border-radius: 8px;
    }
    
    .shorts-load-more,
    .shorts-no-more {
        grid-column: 1 / -1;
    }
    
    .video-controls {
        padding: 10px 8px 8px;
        gap: 8px;
    }
    
    .play-pause-btn,
    .fullscreen-btn {
        width: 36px;
        height: 36px;
    }
    
    .play-pause-btn .play-icon,
    .play-pause-btn .pause-icon {
        font-size: 14px;
    }
    
    .fullscreen-btn::before {
        font-size: 14px;
    }
    
    .time-display {
        font-size: 12px;
    }
    
    .current-time {
        padding: 3px 6px;
        border-radius: 8px;
    }
    
    .video-info {
        padding: 12px;
    }
    
    .video-title {
        font-size: 15px;
    }
    
    .video-description {
        font-size: 12px;
    }
    
    .video-error {
        padding: 12px;
        font-size: 13px;
    }
    
    .retry-btn {
        padding: 5px 10px;
        font-size: 12px;
    }
}

/* Планшеты в портретной ориентации */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {
    .shorts-video-container {
        max-width: 100%;
        padding: 0 20px;
    }
    
    .shorts-videos-list {
        grid-template-columns: repeat(3, 1fr);
        gap: 25px;
    }
    
    .shorts-load-more,
    .shorts-no-more {
        grid-column: 1 / -1;
    }
    
    .video-error {
        padding: 18px;
        font-size: 15px;
    }
    
    .retry-btn {
        padding: 7px 14px;
        font-size: 14px;
    }
}

/* Планшеты в ландшафтной ориентации */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
    .shorts-video-container {
        max-width: 100%;
        padding: 0 30px;
    }
    
    .shorts-videos-list {
        grid-template-columns: repeat(4, 1fr);
        gap: 25px;
    }
    
    .shorts-load-more,
    .shorts-no-more {
        grid-column: 1 / -1;
    }
    
    .video-error {
        padding: 18px;
        font-size: 15px;
    }
    
    .retry-btn {
        padding: 7px 14px;
        font-size: 14px;
    }
}

/* Десктопы */
@media (min-width: 1025px) {
    .shorts-video-container {
        max-width: 100%;
        padding: 0 40px;
    }
    
    .shorts-videos-list {
        grid-template-columns: repeat(4, 1fr);
        gap: 30px;
    }
    
    .shorts-load-more,
    .shorts-no-more {
        grid-column: 1 / -1;
    }
    
    .video-controls {
        padding: 25px 20px 20px;
        gap: 20px;
    }
    
    .play-pause-btn,
    .fullscreen-btn {
        width: 48px;
        height: 48px;
    }
    
    .play-pause-btn .play-icon,
    .play-pause-btn .pause-icon {
        font-size: 20px;
    }
    
    .fullscreen-btn::before {
        font-size: 20px;
    }
    
    .video-info {
        padding: 25px;
    }
    
    .video-title {
        font-size: 20px;
    }
    
    .video-description {
        font-size: 15px;
    }
    
    .video-error {
        padding: 20px;
        font-size: 16px;
    }
    
    .retry-btn {
        padding: 8px 16px;
        font-size: 15px;
    }
}

/* Большие экраны */
@media (min-width: 1440px) {
    .shorts-video-container {
        max-width: 100%;
        padding: 0 60px;
    }
    
    .shorts-videos-list {
        grid-template-columns: repeat(4, 1fr);
        gap: 35px;
    }
    
    .shorts-load-more,
    .shorts-no-more {
        grid-column: 1 / -1;
    }
    
    .video-error {
        padding: 22px;
        font-size: 17px;
    }
    
    .retry-btn {
        padding: 9px 18px;
        font-size: 16px;
    }
}

/* Темная тема */
@media (prefers-color-scheme: dark) {
    .shorts-video-item {
        background: #1a1a1a;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    }
    
    .video-info {
        background: #1a1a1a;
    }
    
    .video-title {
        color: #fff;
    }
    
    .video-description {
        color: #aaa;
    }
    
    .play-pause-btn,
    .fullscreen-btn {
        background: rgba(255, 255, 255, 0.1);
    }
    
    .play-pause-btn:hover,
    .fullscreen-btn:hover {
        background: rgba(255, 255, 255, 0.2);
    }
    
    .play-pause-btn .play-icon,
    .play-pause-btn .pause-icon,
    .fullscreen-btn::before {
        color: #fff;
    }
    
    .shorts-load-more {
        background: #2a2a2a;
        border-color: #444;
    }
    
    .shorts-no-more {
        color: #aaa;
        border-color: #444;
    }
    
    .video-error {
        background: rgba(0, 0, 0, 0.9);
        color: #fff;
    }
    
    .retry-btn {
        background: #0073aa;
        color: #fff;
    }
    
    .retry-btn:hover {
        background: #005a87;
    }
}

/* Анимации */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.shorts-video-item {
    animation: fadeInUp 0.6s ease;
}

/* Анимация появления для сетки */
.shorts-video-item:nth-child(4n+1) {
    animation-delay: 0.1s;
}

.shorts-video-item:nth-child(4n+2) {
    animation-delay: 0.2s;
}

.shorts-video-item:nth-child(4n+3) {
    animation-delay: 0.3s;
}

.shorts-video-item:nth-child(4n+4) {
    animation-delay: 0.4s;
}

/* Состояния загрузки */
.shorts-video.loading {
    opacity: 0.7;
}

.shorts-video.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Загрузка для сетки */
.shorts-video-item.loading {
    opacity: 0.7;
    pointer-events: none;
}

/* Стили для ошибок в сетке */
.video-error {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 20px;
    border-radius: 8px;
    text-align: center;
    z-index: 10;
}

.retry-btn {
    background: #0073aa;
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    margin-top: 10px;
}

.retry-btn:hover {
    background: #005a87;
}

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

/* Улучшения для сенсорных устройств */
@media (hover: none) and (pointer: coarse) {
    .video-controls {
        opacity: 1;
        background: linear-gradient(transparent, rgba(0, 0, 0, 0.9));
    }
    
    .play-pause-btn,
    .fullscreen-btn {
        min-width: 44px;
        min-height: 44px;
    }
    
    .progress-bar {
        height: 6px;
    }
    
    .progress-fill::after {
        width: 16px;
        height: 16px;
    }
    
    .shorts-videos-list {
        gap: 12px; /* Уменьшаем отступы для сенсорных устройств */
    }
    
    .video-error {
        padding: 14px;
        font-size: 14px;
    }
    
    .retry-btn {
        padding: 7px 14px;
        font-size: 13px;
        min-height: 44px; /* Минимальная высота для сенсорных устройств */
    }
}

/* Высокое разрешение */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .shorts-video-item {
        border-radius: 20px;
    }
    
    .play-pause-btn,
    .fullscreen-btn {
        border: 1px solid rgba(255, 255, 255, 0.2);
    }
    
    .shorts-videos-list {
        gap: 22px; /* Увеличиваем отступы для высокого разрешения */
    }
    
    .video-error {
        padding: 24px;
        font-size: 18px;
    }
    
    .retry-btn {
        padding: 10px 20px;
        font-size: 17px;
    }
}

/* Печать */
@media print {
    .shorts-video-container {
        display: none;
    }
    
    .shorts-videos-list {
        display: block; /* Отключаем сетку для печати */
    }
    
    .shorts-video-item {
        display: block;
        margin-bottom: 20px;
        page-break-inside: avoid;
    }
    
    .video-error {
        display: none; /* Скрываем ошибки при печати */
    }
    
    .retry-btn {
        display: none; /* Скрываем кнопки при печати */
    }
}

/* Доступность */
.shorts-video:focus {
    outline: 3px solid #0073aa;
    outline-offset: 2px;
}

.play-pause-btn:focus,
.fullscreen-btn:focus {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

/* Фокус для сетки */
.shorts-video-item:focus-within {
    outline: 3px solid #0073aa;
    outline-offset: 2px;
    border-radius: 16px;
}

/* Улучшения для скринридеров */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Сетка для скринридеров */
.shorts-videos-list[role="grid"] {
    display: grid;
}

.shorts-video-item[role="gridcell"] {
    /* Сетка уже определена выше */
}

/* Скрытие элементов управления для скринридеров */
.video-error .sr-only,
.retry-btn .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Кастомные скроллбары */
.shorts-video-container::-webkit-scrollbar {
    width: 8px;
}

.shorts-video-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.shorts-video-container::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

/* Скроллбары для сетки */
.shorts-videos-list::-webkit-scrollbar {
    width: 6px;
}

.shorts-videos-list::-webkit-scrollbar-track {
    background: #f8f9fa;
    border-radius: 3px;
}

.shorts-videos-list::-webkit-scrollbar-thumb {
    background: #dee2e6;
    border-radius: 3px;
}

/* Стили для сетки */
.shorts-videos-list {
    /* Сетка уже определена выше */
}

/* Обеспечиваем правильное отображение сетки */
.shorts-video-item {
    break-inside: avoid;
    page-break-inside: avoid;
}

/* Плавные переходы для сетки */
.shorts-video-item {
    transition: all 0.3s ease, transform 0.2s ease;
}

.shorts-video-item:hover {
    transform: translateY(-5px);
    z-index: 1;
}

/* Анимация загрузки для сетки */
.shorts-video-item.loading {
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

/* Бесконечный скролл */
.shorts-load-more {
    text-align: center;
    padding: 30px 20px;
    background: #f8f9fa;
    border-radius: 16px;
    margin: 20px 0;
    border: 2px dashed #dee2e6;
    grid-column: 1 / -1; /* Растягиваем на всю ширину сетки */
    transition: all 0.3s ease;
}

.shorts-load-more:hover {
    background: #e9ecef;
    border-color: #adb5bd;
}

.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #0073aa;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-spinner span {
    color: #666;
    font-size: 14px;
    font-weight: 500;
}

/* Анимация для спиннера в сетке */
.shorts-load-more .spinner {
    transition: all 0.3s ease;
}

.shorts-load-more:hover .spinner {
    border-top-color: #005a87;
}

.shorts-no-more {
    text-align: center;
    padding: 20px;
    color: #666;
    font-style: italic;
    border-top: 1px solid #dee2e6;
    margin-top: 20px;
    grid-column: 1 / -1; /* Растягиваем на всю ширину сетки */
    transition: all 0.3s ease;
}

.shorts-no-more:hover {
    color: #495057;
    border-color: #adb5bd;
}

/* Анимация появления новых видео */
.shorts-video-item {
    animation: fadeInUp 0.6s ease;
}

.shorts-video-item.new-item {
    animation: slideInUp 0.8s ease;
}

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

/* Анимация для сетки */
.shorts-video-item.new-item:nth-child(4n+1) {
    animation-delay: 0.1s;
}

.shorts-video-item.new-item:nth-child(4n+2) {
    animation-delay: 0.2s;
}

.shorts-video-item.new-item:nth-child(4n+3) {
    animation-delay: 0.3s;
}

.shorts-video-item.new-item:nth-child(4n+4) {
    animation-delay: 0.4s;
}

/* Анимация для мобильных устройств (2 колонки) */
@media (max-width: 768px) {
    .shorts-video-item:nth-child(2n+1) {
        animation-delay: 0.1s;
    }
    
    .shorts-video-item:nth-child(2n+2) {
        animation-delay: 0.2s;
    }
}

/* Анимация для планшетов (3 колонки) */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {
    .shorts-video-item:nth-child(3n+1) {
        animation-delay: 0.1s;
    }
    
    .shorts-video-item:nth-child(3n+2) {
        animation-delay: 0.2s;
    }
    
    .shorts-video-item:nth-child(3n+3) {
        animation-delay: 0.3s;
    }
}

/* Оптимизация для бесконечного скролла */
.shorts-video-container[data-infinite-scroll="true"] {
    min-height: 100vh;
}

.shorts-videos-list {
    position: relative;
    /* Сетка уже определена выше */
}

/* Индикатор загрузки для мобильных */
@media (max-width: 768px) {
    .shorts-load-more {
        padding: 20px 15px;
        margin: 15px 0;
        grid-column: 1 / -1;
    }
    
    .shorts-no-more {
        grid-column: 1 / -1;
    }
    
    .spinner {
        width: 32px;
        height: 32px;
        border-width: 3px;
    }
    
    .loading-spinner span {
        font-size: 13px;
    }
    
    .shorts-load-more {
        padding: 20px 15px;
        margin: 15px 0;
        grid-column: 1 / -1;
    }
    
    .shorts-no-more {
        grid-column: 1 / -1;
    }
}
