body {
    background: #111;
    color: #eee;
    font-family: sans-serif;
    margin: 0;
    overflow-x: hidden; /* FIX: Prevents horizontal scroll */
    overflow-y: auto;
}

/* Samsung DeX / Mobile Browser Safety */
@media (max-height: 800px) {
    body {
        overflow-y: auto;
    }
}

.hidden { display: none !important; }

/* --- EDITOR MODAL: make the whole overlay scrollable --- */
#editor-modal {
    overflow-y: auto;          
    align-items: center;  
}

#editor-modal .modal-content {
    display: block;           
    max-height: none;
    width: 90vw;
    max-width: 600px;
}

#editor-modal .editor-scroll-body {
    overflow-y: visible;
    max-height: none;
}

/* --- Modals (Password & Editor) --- */
/* Update this selector to include #category-editor-modal */
#password-modal, #editor-modal, #category-editor-modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200; 
    backdrop-filter: blur(5px);
}

.modal-content {
    background: #222;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(0,0,0,0.7);
    border: 1px solid #444;
    min-width: 300px;
}

.modal-content h2 {
    margin-top: 0;
    color: #fff;
}

#password-input {
    font-size: 1.5rem;
    padding: 0.5rem;
    width: 100%;
    box-sizing: border-box;
    background: #111;
    color: #fff;
    border: 1px solid #555;
    border-radius: 4px;
}
#password-input:focus {
    outline: 2px solid #0af;
}

/* --- Admin Editor Specifics --- */
#editor-modal .scrollable-modal-content {
    max-height: 90vh; 
    padding-bottom: 0; 
    padding-left: 0;
    padding-right: 0;
}

.editor-scroll-body {
    overflow-y: auto; 
    padding: 2rem; 
    padding-bottom: 1rem;
    max-height: calc(90vh - 120px); 
}

#editor-modal label {
    display: block;
    margin-top: 1rem;
    color: #aaa;
    font-size: 0.9rem;
}
#edit-title, #edit-category, #edit-thumb-input {
    width: 100%;
    padding: 0.5rem;
    margin-top: 0.25rem;
    box-sizing: border-box;
    background: #333;
    color: #fff;
    border: 1px solid #555;
    border-radius: 4px;
}
#edit-thumb-preview {
    display: block;
    margin-top: 1rem;
    max-width: 200px;
    max-height: 150px;
    border: 1px solid #444;
    background: #000;
    object-fit: contain;
}
.modal-buttons {
    margin-top: 2rem;
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

/* --- Main Menu Layout --- */
#main-menu {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: 100%; /* FIX: Changed from 100vw to prevents scrollbar width conflict */
}

/* --- Header --- */
#main-header {
    display: flex;
    flex-direction: row;
    align-items: center;
    padding: 1rem 2rem;
    gap: 1rem;
    background: #1a1a1a;
    border-bottom: 1px solid #333;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5);
    z-index: 10;
}

#logo {
    height: 40px;
    width: auto;
}

#search-bar {
    flex-grow: 1;
    font-size: 1.2rem;
    padding: 0.5rem 1rem;
    background: #111;
    border: 1px solid #444;
    color: #fff;
    border-radius: 4px;
}
#search-bar:focus {
    outline: none;
    border-color: #0af;
}

#logout-button, .btn-secondary {
    background: #333;
    color: #eee;
    border: 1px solid #555;
    padding: 0.5rem 1rem;
    font-size: 1rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}
#logout-button:hover, .btn-secondary:hover {
    background: #c00;
    border-color: #f00;
    color: #fff;
}

.btn-primary {
    background: #0af;
    color: #000;
    border: none;
    padding: 0.5rem 1rem;
    font-size: 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
}
.btn-primary:hover {
    background: #0088cc;
}

/* --- Category Container --- */
#category-container {
    flex-grow: 1;
    overflow-y: auto; 
    padding: 1rem 0;
}

.category-row {
    margin-bottom: 2rem;
    /* Min height to prevent jitter during lazy load */
    min-height: 200px; 
}

.category-row h2 {
    font-size: 1.5rem;
    margin: 0 0 0.5rem 2rem;
    color: #ddd;
}

/* --- Horizontal Scroll Container (For Categories) --- */
.video-scroll-container {
    display: flex;
    flex-wrap: wrap; 
    gap: 1.5rem; 
    padding: 1rem 2rem;
    position: relative;
    -webkit-mask-image: none;
    mask-image: none;
    overflow-x: visible; 
}
.video-scroll-container::-webkit-scrollbar {
    display: none; 
}

/* --- Grid Container (For Uncategorized & Category Views) --- */
.video-grid-container {
    display: grid;
    /* MODIFIED: auto-fit and minmax ensures items stretch and center */
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    padding: 1rem 2rem;
    /* MODIFIED: Centers the grid content if items don't fill row */
    justify-content: center; 
}

/* --- Video Items --- */
.video-item {
    background: #222;
    border-radius: 8px;
    border: 2px solid #333;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
    aspect-ratio: 16 / 9; 
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 1rem;
    box-sizing: border-box;
}

/* Styling specifically for items inside the SCROLL container */
.video-scroll-container .video-item {
    min-width: 280px;
    width: 280px;
    margin-left: 0 !important;
    /* Allow them to grow slightly to fill gaps */
    flex-grow: 1; 
    max-width: 350px; /* Prevent them from getting too huge on wide screens */
}
.video-scroll-container .video-item:first-child { margin-left: 0; }
.video-scroll-container .video-item:last-child { margin-right: 0; }

/* Styling specifically for items inside the GRID container */
.video-grid-container .video-item {
    width: 100%;
    margin: 0;
}

.video-item img {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border-radius: 4px 4px 0 0;
    display: block;
}

/* Title is now inside the box, larger, and centered */
.video-item p.centered-title {
    font-size: 1.4rem; 
    font-weight: bold;
    color: #fff;
    text-align: center;
    margin: 0;
    white-space: normal; 
    display: -webkit-box;
    -webkit-line-clamp: 3; 
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.2;
}

/* Hover/Selected state remains consistent */
.video-item.selected {
    border-color: #0af;
    background: #2a2a2a;
    transform: scale(1.05);
}

.video-item.admin-editable {
    border: 2px dashed #c00;
}
.video-item.admin-editable:hover {
    background: #300;
}

/* --- Player View --- */
#player-view {
    width: 100vw;
    height: 100vh;
    background: #000;
    position: relative;
    display: flex;
    flex-direction: column;
}

#video-player {
    width: 100%;
    height: 100%;
    outline: none;
}

/* --- Player Controls Overlay --- */
#player-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: linear-gradient(to top, rgba(0,0,0,0.9), rgba(0,0,0,0));
    display: flex;
    align-items: center;
    padding: 1.5rem 2rem;
    gap: 1rem;
    opacity: 1;
    transition: opacity 0.3s;
    z-index: 50;
    box-sizing: border-box;
}

#player-controls.controls-hidden {
    opacity: 0;
    pointer-events: none;
}

#player-controls button {
    background: rgba(255,255,255,0.1);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.2);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    min-width: 60px;
}
#player-controls button:hover {
    background: rgba(255,255,255,0.2);
}
#player-controls button:focus, 
#player-controls input:focus {
    outline: 2px solid #0af;
}

/* --- Scrubber Styling (Cross-browser) --- */
#ctrl-scrub {
    flex-grow: 1;
    -webkit-appearance: none;
    background: rgba(255,255,255,0.2);
    height: 6px;
    border-radius: 3px;
    cursor: pointer;
}
#ctrl-scrub::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: #0af;
    margin-top: 0;
}
#ctrl-scrub::-moz-range-thumb {
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: #0af;
    border: none;
}

/* --- Thumbnail Preview Video --- */
.video-item {
    position: relative; 
    overflow: hidden;
}

.preview-player {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover; 
    z-index: 2;
    background: #000;
    pointer-events: none; 
    opacity: 0; 
    transition: opacity 0.3s ease-in;
}

.preview-player.visible {
    opacity: 1;
}

/* --- Show More Card Style --- */
.show-more-item {
    min-width: 280px;
    width: 280px;
    border: 2px solid #0af !important;
    background: #151525 !important;
    color: #0af !important; 
    margin-left: 1rem;
    flex-grow: 1;
    max-width: 350px;
}

.show-more-item:hover {
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(0, 170, 255, 0.7);
    background: #22223c !important; 
}

.show-more-item h3 {
    font-size: 1.2rem;
    color: #0af;
}

/* --- Category View Layout --- */
#category-view {
    width: 100vw;
    height: 100vh;
    background: #111;
    position: relative;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

#category-header {
    display: flex;
    align-items: center;
    padding: 1rem 2rem;
    gap: 1.5rem;
    background: #1a1a1a;
    border-bottom: 1px solid #333;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5);
    z-index: 10;
}

#category-header h1 {
    flex-grow: 1;
    margin: 0;
    font-size: 1.8rem;
    color: #0af;
}

#category-pagination-info {
    font-size: 1rem;
    color: #aaa;
}

#category-content {
    flex-grow: 1;
    padding: 1rem 0;
}

#category-grid {
    padding: 1.5rem 2rem;
    overflow-y: visible;
}

#category-pagination-controls button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ========================================================= */
/* ===== HORIZONTAL EDITOR LAYOUT OVERRIDE (For Wide Screens) ======= */
/* ========================================================= */

@media (min-width: 900px) {
    #editor-modal .modal-content.horizontal-editor {
        width: 70vw !important; 
        max-width: 950px !important; 
        height: 80vh !important; 
        overflow: hidden !important;
        display: flex !important; 
        flex-direction: column !important; 
        padding: 1rem !important; 
    }

    .editor-horizontal-layout {
        display: flex !important;
        flex-direction: row !important;
        gap: 1.5rem !important;
        width: 100% !important;
        flex: 1 !important; 
        overflow: hidden !important; 
    }

    .editor-left {
        width: 340px !important; 
        flex-shrink: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 0.8rem !important;
        overflow-y: auto !important;
        border-right: none !important;
        padding-right: 8px !important; 
        padding-top: 0.5rem !important; 
    }

    .editor-right {
        flex: 1 !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 0.8rem !important;
        overflow-y: auto !important; 
        border-left: 1px solid #444 !important;
        padding-left: 1.5rem !important;
        padding-right: 10px !important;
        padding-top: 0.5rem !important; 
    }

    .editor-button-bar {
        margin-top: auto !important;
        display: flex !important;
        gap: 1rem !important;
        justify-content: flex-end !important;
        padding-top: 1rem !important;
        border-top: 1px solid #444 !important;
        background: #222 !important;
        position: sticky !important;
        bottom: -0.5rem !important; 
        z-index: 5 !important;
        margin-bottom: 0 !important;
        padding-bottom: 0.5rem !important;
    }

    #edit-thumb-preview {
        max-width: 100% !important;
        max-height: 200px !important;
        object-fit: contain !important;
    }

    #thumb-selector-player {
        width: 100% !important;
        max-height: none !important; 
        background: #000 !important;
    }

    #editor-modal .editor-scroll-body {
        max-height: none !important;
        overflow: visible !important;
    }
}

/* --- All Categories View --- */
#all-categories-view {
    width: 100vw;
    height: 100vh;
    background: #111;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

#all-categories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    padding: 2rem;
    justify-items: center;
}

.category-card {
    background: #222;
    border: 1px solid #444;
    border-radius: 8px;
    width: 100%;
    aspect-ratio: 3/2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    padding: 1rem;
    box-sizing: border-box;
    text-align: center;
}

.category-card:hover {
    background: #2a2a2a;
    border-color: #0af;
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0, 170, 255, 0.3);
}

.category-card h3 {
    margin: 0;
    color: #fff;
    font-size: 1.2rem;
}

.category-card span {
    color: #0af;
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

/* Bulk Toolbar */
#bulk-toolbar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: #222;
    border-top: 2px solid #0af;
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    z-index: 300;
    box-shadow: 0 -5px 20px rgba(0,0,0,0.8);
}
#bulk-toolbar.hidden { display: none; }

#bulk-count {
    font-weight: bold;
    color: #fff;
    margin-right: auto; /* Pushes buttons to right */
    font-size: 1.2rem;
}

#bulk-category-select {
    padding: 0.5rem;
    background: #333;
    color: #fff;
    border: 1px solid #555;
    border-radius: 4px;
    font-size: 1rem;
    max-width: 200px;
}

/* Selection Mode - Visual Indicators */
.video-item.selecting-mode {
    cursor: pointer; /* Ensure pointer shows */
}
/* When selected, add a blue border */
.video-item.bulk-selected {
    border: 2px solid #0af !important;
    background: #111;
    position: relative;
}
/* Checkmark overlay */
.video-item.bulk-selected::after {
    content: "✔";
    position: absolute;
    top: 5px;
    right: 5px;
    background: #0af;
    color: #000;
    width: 25px;
    height: 25px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1rem;
    box-shadow: 0 2px 5px rgba(0,0,0,0.5);
    z-index: 10;
}

/* Add to style.css */

.video-item {
    position: relative; /* Ensure absolute children stick to this box */
    /* ... existing styles ... */
}

/* The Progress Bar Container (Background) */
.progress-bar-bg {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 6px;
    background: rgba(0,0,0,0.5);
    z-index: 5;
}

/* The Progress Fill (Red) */
.progress-bar-fill {
    height: 100%;
    background: #c00; /* Bright Red */
    width: 0%; /* Default to 0 */
    transition: width 0.3s;
}

/* --- Up Next Overlay --- */
#up-next-overlay {
    position: absolute;
    top: 40px; /* Near the top */
    right: 40px;
    background: rgba(0, 0, 0, 0.85);
    border: 1px solid #444;
    border-left: 4px solid #0af; /* Visual accent */
    padding: 1.5rem;
    border-radius: 8px;
    max-width: 350px;
    z-index: 60; /* Above controls */
    backdrop-filter: blur(5px);
    transition: opacity 0.5s;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0,0,0,0.8);
}

.up-next-label {
    margin: 0;
    font-size: 0.8rem;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#up-next-title {
    margin: 0.5rem 0;
    color: #fff;
    font-size: 1.1rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.up-next-timer {
    font-size: 0.85rem;
    color: #0af;
    margin: 0 0 1rem 0;
}

#btn-play-next-now {
    background: #0af;
    color: #000;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    width: 100%;
}
#btn-play-next-now:hover {
    background: #0088cc;
}

/* --- Still Watching Modal Specifics --- */
#still-watching-modal {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.9);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}