/* Page Layout */
.page-layout {
    display: grid !important;
    grid-template-columns: 200px 1fr 200px;
    gap: 25px;
    padding: 20px;
    max-width: 1600px;
    margin: 0 auto;
}

/* When no ads are present, center the content */
.page-layout.no-ads {
    grid-template-columns: 1fr;
    max-width: 100%;
    display: flex !important;
    justify-content: center;
}

.page-layout.no-ads .main-content {
    grid-column: 1;
    margin: 0 auto;
    width: 100%;
    max-width: 1200px;
    text-align: center;
    display: flex;
    justify-content: center;
}

/* When only one ad is present, adjust layout */
.page-layout.single-ad {
    grid-template-columns: 200px 1fr;
    max-width: 1400px;
}

.page-layout.single-ad .main-content {
    grid-column: 2;
}

.page-layout.single-ad .sidebar-ad.right {
    display: none;
}

/* Main Content Area */
.main-content {
    grid-column: 2;
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
}

/* Sidebar Ads */
.sidebar-ad {
    position: sticky;
    top: 100px;
    height: fit-content;
    display: flex !important;
    justify-content: flex-start;
    align-items: center;
    width: 200px;
    z-index: 10;
}

.sidebar-ad.left {
    grid-column: 1;
    padding-right: 0;
    justify-content: flex-start;
}

.sidebar-ad.right {
    grid-column: 3;
    padding-left: 0;
    justify-content: flex-end;
}

/* Add styles to handle footer overlap */
.sidebar-ad.right.stop-scrolling,
.sidebar-ad.left.stop-scrolling {
    position: absolute;
    bottom: 100px; /* Space between ads and footer */
    top: auto;
}

/* Ad Container Styling */
.ad-container {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    background: #f8f8f8;
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    width: 180px;
    visibility: visible !important;
    opacity: 1 !important;
}

.ad-label {
    font-size: 12px;
    color: #666;
    margin-bottom: 5px;
    text-transform: uppercase;
}

.ad-container img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Add new styles to handle footer overlap */
body {
    position: relative; /* Ensure body is a positioning context */
}

footer {
    position: relative;
    z-index: 11; /* Make footer appear above ads */
}

/* Responsive Design */
@media (max-width: 1400px) {
    .page-layout {
        max-width: 1400px;
    }
}

@media (max-width: 1200px) {
    .page-layout {
        grid-template-columns: 180px 1fr 180px;
        gap: 20px;
    }
}

@media (max-width: 768px) {
    .page-layout,
    .page-layout.no-ads,
    .page-layout.single-ad {
        display: block !important;
        grid-template-columns: none !important;
        gap: 0 !important;
        padding: 10px !important;
        max-width: 100% !important;
        width: 100% !important;
    }

    .main-content {
        grid-column: unset !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 auto !important;
        display: block !important;
        padding: 0 !important;
        text-align: center !important;
    }

    .sidebar-ad {
        display: none !important;
    }
}

@media (max-width: 480px) {
    .page-layout,
    .page-layout.no-ads,
    .page-layout.single-ad {
        padding: 5px !important;
        display: block !important;
        grid: none !important;
        grid-template: none !important;
        grid-template-columns: none !important;
        grid-template-rows: none !important;
        grid-template-areas: none !important;
        grid-auto-columns: none !important;
        grid-auto-rows: none !important;
        grid-auto-flow: none !important;
        grid-column-gap: none !important;
        grid-row-gap: none !important;
        gap: 0 !important;
    }
    
    .main-content {
        padding: 0 !important;
        display: block !important;
        grid-column: unset !important;
        grid-row: unset !important;
        grid-area: unset !important;
        text-align: center !important;
        margin: 0 auto !important;
    }
}

/* Add JavaScript visibility control class */
.hide-ad {
    display: none !important;
}

/* Mobile content centering */
@media (max-width: 768px) {
    .page-layout.no-ads {
        display: flex !important;
        grid-template-columns: none !important;
        text-align: center;
        justify-content: center;
    }
    
    .page-layout.no-ads .main-content {
        grid-column: unset !important;
        text-align: center !important;
        margin: 0 auto !important;
        width: 100% !important;
        max-width: 100% !important;
        display: flex;
        justify-content: center;
    }
    
    .channel-content {
        text-align: center;
        margin: 0 auto;
        padding: 0 10px;
        display: flex;
        justify-content: center;
    }
    
    .sort-buttons-channel {
        text-align: center;
        margin: 20px auto;
    }
    
    .channel-tabs {
        text-align: center;
        margin: 20px auto;
    }
}

@media (max-width: 480px) {
    .page-layout.no-ads {
        padding: 5px !important;
        display: flex !important;
        justify-content: center;
    }
    
    .page-layout.no-ads .main-content {
        padding: 0 5px !important;
        display: flex;
        justify-content: center;
    }
    
    .channel-content {
        padding: 0 5px;
        display: flex;
        justify-content: center;
    }
    
    .sort-buttons-channel {
        margin: 15px auto;
    }
    
    .channel-tabs {
        margin: 15px auto;
    }
} 

/* A4 Modal Overlay */
.a4-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.a4-modal {
    position: relative;
    max-width: 800px;
    width: min(92vw, 800px);
    max-height: 90vh;
    background: transparent; /* Remove white frame */
    border-radius: 12px;
    overflow: hidden;
    padding-top: 0; /* No reserved space; button overlays media */
}

.a4-modal a {
    display: block;
}

.a4-modal img,
.a4-modal video {
    width: 100%;
    height: auto;
    max-height: 90vh;
    display: block;
    object-fit: contain;
    background: transparent;
}

.a4-close {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0,0,0,0.7);
    color: #fff;
    border: none;
    border-radius: 16px;
    padding: 8px 12px;
    font-size: 14px;
    cursor: not-allowed;
    opacity: 0.8;
    z-index: 2;
}

.a4-close.enabled {
    cursor: pointer;
    background: rgba(0,0,0,0.85);
    opacity: 1;
}

/* Prevent body scroll when modal is open */
body.a4-modal-open {
    overflow: hidden;
}

/* Sticky Footer Ad */
.sticky-footer-ad {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9998;
    display: flex;
    justify-content: center;
    pointer-events: none; /* container ignores clicks; child handles */
}

.sticky-footer-ad .sticky-inner {
    pointer-events: auto;
    background: rgba(255,255,255,0.98);
    box-shadow: 0 -4px 16px rgba(0,0,0,0.12);
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    padding: 8px 12px;
    max-width: 1024px;
    width: min(96vw, 1024px);
    display: flex;
    align-items: center;
    gap: 12px;
    box-sizing: border-box;
    overflow: hidden; /* prevent media from spilling */
}

.sticky-footer-ad .sticky-inner a {
    display: block;
    max-width: 100%;
    flex: 1 1 auto;
    overflow: hidden;
}

.sticky-footer-ad img,
.sticky-footer-ad video {
    max-height: 80px;
    max-width: 100%;
    width: auto;
    height: auto;
    border-radius: 8px;
    display: block;
    object-fit: contain;
}

.sticky-footer-close {
    margin-left: auto;
    background: #000;
    color: #fff;
    border: none;
    border-radius: 14px;
    padding: 6px 10px;
    cursor: pointer;
}

@media (max-height: 500px) {
    .sticky-footer-ad img,
    .sticky-footer-ad video {
        max-height: 60px;
    }
}

/* Small screens general */
@media (max-width: 768px) {
    .a4-modal {
        width: 95vw;
        max-height: 88vh;
        border-radius: 10px;
        padding-top: 0;
    }
    .a4-modal img,
    .a4-modal video {
        max-height: 88vh;
    }
    .a4-close {
        font-size: 15px;
        padding: 9px 14px;
    }
}

/* Portrait optimization */
@media (orientation: portrait) {
    .a4-modal {
        width: 94vw;
        max-height: 88vh;
    }
    .a4-modal img,
    .a4-modal video {
        max-height: 88vh;
    }
}

/* Landscape optimization (short viewports) */
@media (orientation: landscape) and (max-height: 600px) {
    .a4-modal {
        width: 90vw;
        max-height: 82vh;
        border-radius: 10px;
        padding-top: 0;
    }
    .a4-modal img,
    .a4-modal video {
        max-height: 82vh;
    }
}

/* Account for safe-area insets (notches) */
.a4-modal-overlay {
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}