/* EMERGENCY LAYOUT FIX V3 - MOBILE SAFE */
/* Loaded last to override styles */

/* =========================================
   1. GLOBAL: HIDE Grid Previews Everywhere
   ========================================= */
/* Default: Hide grid previews to prevent giant images in List View */
.grid-preview-container,
.grid-poster-toggle-btn {
    display: none !important;
}

/* Exception: Show them ONLY when explicitly in Grid Mode */
/* Using Body class OR Container class for robustness */
body.view-grid-active .grid-preview-container,
body.view-grid-active .grid-poster-toggle-btn,
.container.view-grid-active .grid-preview-container,
.container.view-grid-active .grid-poster-toggle-btn {
    display: flex !important;
}

/* =========================================
   2. DESKTOP ONLY: List View Fixes
   (min-width: 769px) - STOPS Mobile Conflict
   ========================================= */
@media (min-width: 769px) {

    /* Ensure the title cell behaves like a normal table cell in List View */
    /* This overrides any potential grid styles leaking into desktop list view */
    body:not(.view-grid-active) .title-cell {
        display: table-cell !important;
        max-width: 600px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap !important;
        padding: 8px !important;
        vertical-align: middle !important;
    }

    body:not(.view-grid-active) .title-cell .grid-title-text {
        display: inline !important;
        font-size: inherit;
        font-weight: normal;
    }
}

/* =========================================
   3. ULTRA-WIDE DESKTOP: Sidebar Feature
   (min-width: 1400px)
   ========================================= */
#desktopPreviewSidebar {
    display: none !important;
}

@media (min-width: 1400px) {

    /* Show sidebar ONLY in List View (not grid) */
    body:not(.view-grid-active) #desktopPreviewSidebar {
        display: flex !important;
        flex-direction: column;
        position: fixed;
        right: 20px;
        top: 90px;
        width: 360px;
        height: calc(100vh - 110px);
        background: var(--glass-bg, rgba(20, 30, 48, 0.6));
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.1));
        border-radius: 16px;
        padding: 0;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
        z-index: 900;
        overflow: hidden;
        transition: transform 0.3s ease;
    }

    /* Shift Main Container Left */
    body:not(.view-grid-active) .container {
        /* Calculated width to leave room for sidebar */
        width: calc(100% - 400px) !important;
        max-width: 1400px !important;
        margin-left: 20px !important;
        margin-right: auto !important;
    }
}

/* Sidebar Styling (Safe to be global as ID is unique) */
.sidebar-content {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    height: 100%;
    overflow-y: auto;
}

.sidebar-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
    margin-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 10px;
}

.sidebar-image-box {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-image-box span {
    position: absolute;
    top: 5px;
    left: 5px;
    background: rgba(0, 0, 0, 0.7);
    color: #ccc;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 4px;
}

.sidebar-image-box img {
    width: 100%;
    display: block;
}

.sidebar-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #666;
    font-style: italic;
}

.hidden {
    display: none !important;
}
/* FINAL FULL WIDTH OVERRIDE */
body.view-grid-active .container {
    width: 98% !important;
    max-width: none !important;
    margin: 0 auto !important;
    padding: 0 10px !important;
}

/* FINAL FULL WIDTH OVERRIDE V14 */
body.view-grid-active { padding: 0 !important; } /* REMOVE BODY PADDING */
body.view-grid-active .container {
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 10px !important;
}

/* FINAL FULL WIDTH OVERRIDE V15 */
body.view-grid-active { padding: 0 !important; }
body.view-grid-active .container {
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 10px !important;
}

/* FINAL FULL WIDTH OVERRIDE V16 */
body.view-grid-active { padding: 0 !important; }
body.view-grid-active .container {
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 10px !important;
}

/* FINAL FULL WIDTH OVERRIDE V17 */
body.view-grid-active { padding: 0 !important; }
body.view-grid-active .container {
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 4px !important; /* 4px total horizontal padding */
}

/* FINAL FULL WIDTH OVERRIDE V17 */
body.view-grid-active { padding: 0 !important; }
body.view-grid-active .container {
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 4px !important;
}

/* FINAL FULL WIDTH OVERRIDE V17 */
body.view-grid-active { padding: 0 !important; }
body.view-grid-active .container {
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 4px !important;
}

/* FINAL FULL WIDTH OVERRIDE V17 */
body.view-grid-active { padding: 0 !important; }
body.view-grid-active .container {
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 4px !important;
}

/* FIX 400px Overflow */
body.view-grid-active .container { padding: 0 4px !important; margin: 0 !important; width: 100% !important; max-width: none !important; }

/* 5. THUMBNAIL CELL - Hide by default (List View) */
.thumbnail-cell {
    display: none !important;
}

/* Show in Grid View */
body.view-grid-active .thumbnail-cell,
body.view-grid-active #torrentTable tbody tr td.thumbnail-cell {
    display: block !important;
}

