:root {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-hover: #272727;
    --text-primary: #ffffff;
    --text-secondary: #aaaaaa;
    --accent: #ff0000;
    --accent-hover: #cc0000;
    --border: #303030;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Roboto', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.4;
}

/* === HEADER === */
.header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 24px;
    padding: 12px 16px;

    position: sticky;
    top: 0;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    z-index: 100;
    padding: 0 16px;
}

.header-container {
    height: 58px;
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.logo a {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 700;
    font-size: 1.2rem;
}

.logo-icon {
    color: var(--accent);
    font-size: 1.4rem;
}

/* === NAV TABS === */
.nav-tabs {
    display: flex;
    gap: 4px;
    margin-right: 16px;
}

.nav-tab {
    padding: 8px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 8px;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.nav-tab:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-tab.active {
    background: var(--accent);
    color: white;
}

/* === SEARCH FORM === */
.search-form {
    flex: 1;
    max-width: 640px;
    display: flex;
}

.search-form input {
    flex: 1;
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-right: none;
    border-radius: 20px 0 0 20px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1rem;
}

.search-form input:focus {
    outline: none;
    border-color: #1c62b9;
}

.search-form button {
    padding: 0 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-left: none;
    border-radius: 0 20px 20px 0;
    cursor: pointer;
    color: var(--text-secondary);
}

.header-actions {
    display: flex;
    gap: 8px;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
}

.btn-icon:hover {
    background: var(--bg-hover);
}

/* === MAIN LAYOUT === */
.main {
    max-width: 1600px;
    margin: 0 auto;
    padding: 24px 16px;
    min-height: calc(100vh - 140px);
}

/* === VIDEO GRID === */
.video-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px 16px;
}

.video-grid.compact {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
}

/* === VIDEO CARDS === */
.video-card {
    display: block;
    color: inherit;
    text-decoration: none;
    transition: transform 0.1s;
}

.video-card:hover {
    transform: translateY(-8px) scale(1.1);
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--accent);
    border-color: var(--accent-hover);
    box-shadow: 0 2px 8px rgba(255, 0, 0, 0.25);
    z-index: 10;
}

.thumbnail-wrapper {
    position: relative;
    aspect-ratio: 16/9;
    background: var(--bg-secondary);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 12px;
}

.thumbnail-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.thumbnail-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    color: var(--text-secondary);
}

.duration {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
}

.video-info h3 {
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.video-meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* === VIDEO PAGE (2-COLUMN LAYOUT) === */
.video-page-layout {
    display: flex;
    height: calc(100vh - 140px);
    gap: 24px;
    max-width: 1600px;
    margin: 0 auto;
}

/* Left Column: Player + Related */
.left-column {
    width: 65%;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding-right: 10px;
    overflow-x: hidden; /* 👈 Важно: запрещаем горизонтальную прокрутку */
    word-break: break-word; /* 👈 Важно: переносим длинные слова/ссылки */
}

.left-column::-webkit-scrollbar {
    width: 8px;
}
.left-column::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border-radius: 4px;
}

.video-player-container {
    background: black;
    border-radius: 12px;
    margin-bottom: 24px;
    flex-shrink: 0;
}

.video-player {
    width: 100%;
    aspect-ratio: 16/9;
    display: block;
}

.related-videos-section {
    margin-top: 10px;
}

.related-videos-section h3 {
    margin-bottom: 16px;
    font-size: 1.2rem;
}

.related-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); /* Было 220px, стало 180px */
    gap: 12px;
}

/* Right Column: Info + Comments */
.right-column {
    width: 35%;
    overflow-y: auto;
    padding-left: 10px;
    overflow-x: hidden; /* 👈 Важно: запрещаем горизонтальную прокрутку */
    word-break: break-word; /* 👈 Важно: переносим длинные слова/ссылки */
}

.right-column::-webkit-scrollbar {
    width: 8px;
}
.right-column::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border-radius: 4px;
}

.video-details {
    padding-bottom: 40px;
}

.video-title-main {
    font-size: 1.4rem;
    margin-bottom: 12px;
    line-height: 1.3;
}

.video-stats {
    display: flex;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 16px;
}

.channel-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
}

.channel-avatar {
    width: 40px;
    height: 40px;
    background: var(--bg-secondary);
    border-radius: 50%;
}

.video-description {
    background: var(--bg-secondary);
    padding: 12px 16px;
    border-radius: 12px;
    margin-bottom: 24px;
    font-size: 0.95rem;
    white-space: pre-wrap;
}

.video-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 24px;
}

.tag {
    background: var(--bg-secondary);
    color: var(--accent);
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 0.85rem;
    text-decoration: none;
}

.tag:hover {
    background: var(--bg-hover);
}

/* Comments */
.comments-section {
    margin-top: 24px;
}

.comments-section h3 {
    margin-bottom: 16px;
    font-size: 1.2rem;
}

.comment {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.comment-author {
    font-weight: 500;
    margin-bottom: 4px;
}

.comment-text {
    color: var(--text-secondary);
    margin-bottom: 4px;
    line-height: 1.5;
}

.comment-likes,
.comment-time {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Compact Cards (for related videos) */
.video-card.compact {
    display: flex;
    gap: 12px;
    text-decoration: none;
    color: inherit;
    margin-bottom: 12px;
}

.video-card.compact .thumbnail-wrapper {
    width: 140px;
    height: 80px;
    aspect-ratio: auto;
    margin-bottom: 0;
    flex-shrink: 0;
}

.video-card.compact .video-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.video-card.compact .video-title {
    font-size: 0.9rem;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* === CHANNELS PAGE === */
.channels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.channel-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg-secondary);
    border-radius: 12px;
    text-decoration: none;
    color: inherit;
    transition: transform 0.1s, background 0.2s;
}

.channel-card:hover {
    background: var(--bg-hover);
    transform: translateY(-2px);
}

.channel-avatar-lg {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--bg-hover);
    flex-shrink: 0;
}

.channel-avatar-lg img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: var(--text-secondary);
}

.channel-info-card {
    flex: 1;
    min-width: 0;
}

.channel-name {
    font-size: 1rem;
    font-weight: 500;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.channel-stats {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin: 4px 0 0;
}

.channels-header {
    margin-bottom: 24px;
}

.channels-header h2 {
    margin-bottom: 8px;
}

.channel-header {
    margin-bottom: 24px;
}

.channel-header h2 {
    margin-bottom: 8px;
}

.channel-header p {
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.channel-header .back-link {
    display: inline-block;
    color: var(--accent);
    text-decoration: none;
}

.channel-header .back-link:hover {
    text-decoration: underline;
}

/* === PAGINATION === */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin: 32px 0;
}

.pagination-btn {
    padding: 8px 16px;
    background: var(--bg-secondary);
    border: none;
    border-radius: 8px;
    color: var(--text-primary);
    text-decoration: none;
    cursor: pointer;
}

.pagination-btn:hover {
    background: var(--bg-hover);
}

.pagination-info {
    color: var(--text-secondary);
}

/* === SEARCH RESULTS === */
.search-header {
    margin-bottom: 24px;
}

.search-header h2 {
    margin-bottom: 8px;
}

.search-header p {
    color: var(--text-secondary);
}

.no-results {
    text-align: center;
    padding: 48px 16px;
    color: var(--text-secondary);
}

.no-results a {
    color: var(--accent);
    text-decoration: none;
    display: inline-block;
    margin-top: 16px;
}

/* === FOOTER === */
.footer {
    text-align: center;
    padding: 24px 16px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
}

/* === RESPONSIVE === */
@media (max-width: 900px) {
    .header-container {
        padding: 0 8px;
    }
    
    .video-grid {
        grid-template-columns: 1fr;
    }
    
    .nav-tabs {
        margin-right: 8px;
    }
    
    .nav-tab {
        padding: 6px 12px;
        font-size: 0.85rem;
    }

    /* Mobile Video Page */
    .video-page-layout {
        flex-direction: column;
        height: auto;
        overflow: visible;
    }
    
    .left-column,
    .right-column {
        width: 100%;
        overflow-y: visible;
        padding: 0;
    }
    
    .video-player-container {
        margin-bottom: 16px;
    }
}

.shuffle-container {
    text-align: center;
    margin: 32px 0;
}

.btn-shuffle {
    display: inline-block;
    padding: 10px 24px;
    background: var(--accent);
    color: white;
    text-decoration: none;
    border-radius: 20px;
    font-weight: 500;
    font-size: 0.95rem;
    transition: background 0.2s, transform 0.1s;
}

.btn-shuffle:hover {
    background: var(--accent-hover);
    transform: translateY(-2px);
}

.channel-avatar-placeholder {
    width: 40px;
    height: 40px;
    background: var(--bg-hover);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.1rem;
    color: var(--accent);
    text-transform: uppercase;
}

.channel-link {
    color: var(--text-primary);
    text-decoration: none;
    font-weight: bold;
}

.channel-link:hover {
    color: var(--accent);
    text-decoration: underline;
}

/* === ПАНЕЛЬ СОРТИРОВКИ === */
.sort-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 24px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid var(--border);
}

.sort-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
    margin-right: 8px;
}

.sort-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--bg-hover);
    color: var(--text-primary);
    text-decoration: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.sort-btn:hover {
    background: #333;
    border-color: #444;
    transform: translateY(-1px);
}

.sort-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent-hover);
    box-shadow: 0 2px 8px rgba(255, 0, 0, 0.25);
}

.refresh-btn {
    margin-left: auto; /* Отодвигает кнопку вправо на больших экранах */
    background: #2a2a2a;
    border: 1px dashed #555;
}

.refresh-btn:hover {
    background: #3a3a3a;
    border-color: #777;
}

@media (max-width: 600px) {
    .sort-controls {
        gap: 6px;
        padding: 10px 12px;
    }
    .sort-label { display: none; }
    .refresh-btn { margin-left: 0; width: 100%; justify-content: center; margin-top: 4px; }
    .sort-btn { flex: 1 1 calc(50% - 6px); justify-content: center; }
    .header-container { max-width:600 }
}

.loading-sentinel {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--text-secondary);
    gap: 12px;
    margin-top: 20px;
}
.spinner {
    width: 32px; height: 32px;
    border: 3px solid var(--bg-hover);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === NESTED COMMENTS === */
.comment {
    padding: 12px 0;
    position: relative;
}
.comment-depth-0 { border-bottom: 1px solid var(--border); }
.comment-depth-1, .comment-depth-2, .comment-depth-3 {
    border-left: 2px solid var(--border);
    padding-left: 16px;
    margin-top: 8px;
}
.comment-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.comment-actions { display: flex; gap: 12px; align-items: center; margin-top: 6px; }
.comment-reply-btn {
    background: none; border: none; color: var(--text-secondary);
    cursor: pointer; font-size: 0.85rem; padding: 0; font-weight: 500;
}
.comment-reply-btn:hover { color: var(--text-primary); }
.comment-replies { margin-top: 4px; }

/* Ограничиваем визуальную глубину, чтобы не ломать вёрстку */
.comment-depth-4, .comment-depth-5 { margin-left: 32px !important; opacity: 0.9; }
.comment-depth-6, .comment-depth-7 { margin-left: 40px !important; opacity: 0.8; }
.comment-depth-8 { margin-left: 48px !important; opacity: 0.7; }

.video-player:fullscreen {
    width: 100vw;
    height: 100vh;
    object-fit: contain; /* или cover, если нужно заполнить экран */
    margin: 0;
    padding: 0;
}

/* Safari / WebKit */
.video-player:-webkit-full-screen {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Firefox (старые версии) */
.video-player:-moz-full-screen {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.video-player-container:fullscreen,
.video-player-container:-webkit-full-screen,
.video-player-container:-moz-full-screen {
    border-radius: 0 !important;
    margin: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
}

/* Исправленные стили для video-player в fullscreen */
.video-player:fullscreen {
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    max-height: none !important;
    object-fit: contain;
    margin: 0;
    padding: 0;
}

.video-player:-webkit-full-screen {
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    max-height: none !important;
    object-fit: contain;
}

.video-player:-moz-full-screen {
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    max-height: none !important;
    object-fit: contain;
}

/* Разрешаем overflow для fullscreen элементов */
.left-column:has(.video-player:fullscreen),
.left-column:has(.video-player:-webkit-full-screen) {
    overflow-x: visible !important;
    overflow-y: visible !important;
}

.gradio-wrapper {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    border-radius: 12px;
    overflow: hidden;
    background: var(--bg-secondary);
}

/* Адаптив для мобильных */
@media (max-width: 768px) {
    .gradio-wrapper iframe {
        height: calc(100vh - 200px);
    }
}

.upload-container {
    max-width: 600px;
    margin: 0 auto;
    padding: 24px;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid var(--border);
}
.upload-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.form-group label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-secondary);
    font-weight: 500;
}
.form-group input, .form-group select {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.95rem;
}
.form-group input:focus, .form-group select:focus {
    outline: none;
    border-color: #1c62b9;
}
.form-hint {
    display: block;
    margin-top: 6px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}
.btn-upload {
    padding: 12px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}
.btn-upload:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}
.alert {
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.9rem;
}
.alert.success {
    background: rgba(40, 167, 69, 0.15);
    color: #4ade80;
    border: 1px solid rgba(40, 167, 69, 0.3);
}
.alert.error {
    background: rgba(220, 53, 69, 0.15);
    color: #f87171;
    border: 1px solid rgba(220, 53, 69, 0.3);
}
/* === КОМПАКТНЫЙ HEADER ДЛЯ МОБИЛЬНЫХ === */
@media (max-width: 600px) {
    .header {
        padding: 4px 8px;
        border-bottom: 1px solid var(--border);
    }
    .header-container {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: center;
        gap: 3px;
        height: auto;
        padding: 0;
    }
    
    /* Логотип: минимальный отступ, чуть меньше шрифт */
    .logo {
        width: 100%;
        display: flex;
        justify-content: center;
        margin: 0 0 2px;
    }
    .logo a { font-size: 0.85rem; }
    .logo-icon { font-size: 1rem; }

    /* Навигация: ровно 2 в ряд, компактные кнопки */
    .nav-tabs {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 4px;
        margin: 0 0 2px;
    }
    .nav-tab {
        padding: 4px 6px;
        font-size: 1.0rem;
        border-radius: 6px;
        text-align: center;
        line-height: 1.1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Иконки: в одну строку, уменьшены */
    .header-actions {
        width: 100%;
        display: flex;
        justify-content: center;
        gap: 8px;
        margin: 0 0 2px;
    }
    .btn-icon {
        padding: 4px;
        font-size: 1rem;
    }
    .search-form {
        display: flex !important;
        width: 100%;
        max-width: 350px;
        margin: 4px 0 2px;
        order: 0; /* После навигации, перед иконками */
    }
}

.disable {
    pointer-events: none;
}