{% extends "base.html" %} {% block content %}

    <div id="preloader" class="loader">
        <div class="loader-inner">
            <div class="loader-line-wrap">
                <div class="loader-line"></div>
            </div>
            <div class="loader-line-wrap">
                <div class="loader-line"></div>
            </div>
            <div class="loader-line-wrap">
                <div class="loader-line"></div>
            </div>
            <div class="loader-line-wrap">
                <div class="loader-line"></div>
            </div>
            <div class="loader-line-wrap">
                <div class="loader-line"></div>
            </div>
        </div>
    </div>
    <div id="yommi_wrapper" class="container-fluid mt-4 mx-auto content-cloak" style="max-width: 100%;">
        <!-- Search Section -->
        <div class="card p-4 mb-4 border-0" style="background: rgba(30,30,40,0.6); backdrop-filter: blur(10px); border-radius: 16px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);">
            <div class="row align-items-center">
                <div class="col-md-8 mx-auto">
                     <div class="input-group input-group-lg">
                        <input
                                id="input_search"
                                type="search"
                                class="form-control border-0 text-white"
                                placeholder="애니메이션 제목 검색..."
                                aria-label="Search"
                                style="background: rgba(0,0,0,0.4); border-radius: 12px 0 0 12px !important; box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);"
                        />
                        <div class="input-group-append">
                            <button id="btn_search" type="button" class="btn btn-primary px-4 font-weight-bold" style="border-radius: 0 12px 12px 0 !important; box-shadow: 0 0 15px rgba(59, 130, 246, 0.4);">
                                <i class="bi bi-search"></i> 검색
                            </button>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- Category Buttons -->
            <div class="row mt-4 justify-content-center">
                <div id="anime_category" class="d-flex flex-wrap justify-content-center gap-2" role="group">
                    <button id="ing" type="button" class="btn btn-outline-success btn-pill px-4 mx-1 active-glow">방영중</button>
                    <button id="theater" type="button" class="btn btn-outline-primary btn-pill px-4 mx-1 active-glow">극장판</button>
                    <button id="complete_anilist" type="button" class="btn btn-outline-light btn-pill px-4 mx-1 active-glow">완결</button>
                </div>
            </div>
        </div>

        <div>
            <form id="airing_list_form">
                <div id="airing_list"></div>
            </form>
            <form id="screen_movie_list_form">
                <div id="screen_movie_list" class="container-fluid px-0"></div>
            </form>

            <form id="program_auto_form">
                <div id="episode_list"></div>
            </form>
        </div>
    </div>
    <!--전체-->

    <script
            type="text/javascript"
            src="https://cdn.jsdelivr.net/npm/lozad/dist/lozad.min.js"
    ></script>
    <script src="{{ url_for('.static', filename='js/sjva_ui14.js') }}"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.lazyload/1.9.1/jquery.lazyload.min.js"
            integrity="sha512-jNDtFf7qgU0eH/+Z42FG4fw3w7DM/9zbgNPe3wfJlCylVDTT3IgKW5r92Vy9IHa6U50vyMz5gRByIu4YIXFtaQ=="
            crossorigin="anonymous" referrerpolicy="no-referrer"></script>
    <script type="text/javascript">
        const package_name = "{{arg['package_name'] }}";
        const sub = "{{arg['sub'] }}";
        const anilife_url = "{{arg['anilife_url']}}";
        // let current_data = null;
        let page = 1;
        let next_page = Number
        let current_cate = ''
        let current_query = ''

        const loader = document.getElementById("preloader");

        const dismissLoadingScreen = function () {
            loader.style.display = "none";
        };

        const wait3seconds = function () {
            // REFERENCE:  https://www.w3schools.com/jsref/met_win_settimeout.asp
            const result = setTimeout(dismissLoadingScreen, 2000);
        };

        window.addEventListener("load", wait3seconds);
        // window.addEventListener("load", dismissLoadingScreen);


        const observer = lozad('.lozad', {
            rootMargin: '10px 0px', // syntax similar to that of CSS Margin
            threshold: 0.1, // ratio of element convergence
            enableAutoReload: true // it will reload the new image when validating attributes changes
        });
        observer.observe();


        const get_anime_list = (type, page) => {
            console.log(`type: ${type}, page: ${page}`)
            let url = ''
            let data = {"page": page, "type": type}

            switch (type) {
                case 'ing':
                    url = '/' + package_name + '/ajax/' + sub + '/anime_list'
                    current_cate = 'ing'
                    break;
                case 'movie':
                    url = '/' + package_name + '/ajax/' + sub + '/screen_movie_list'
                    current_cate = 'movie'
                    break;
                case 'theater':
                    url = '/' + package_name + '/ajax/' + sub + '/anime_list'
                    current_cate = 'theater'
                    break;
                case 'fin':
                    url = '/' + package_name + '/ajax/' + sub + '/complete_list'
                    current_cate = 'fin'
                    break
                default:
                    break;
            }

            $.ajax({
                url: url,
                type: "POST",
                data: data,
                cache: false,
                dataType: "json",
                success: (ret) => {
                    let current_screen_movie_data = ret
                    console.log('ret::>', ret)

                    if (current_screen_movie_data !== '') {
                        if (type === "ing") {
                            make_airing_list(ret.data, page)
                            {#observer.observe();#}
                        } else if (type === "fin") {
                            make_screen_movie_list(ret.data, page)
                            {#observer.observe();#}
                        } else if (type === "theater") {
                            make_screen_movie_list(ret.data, page)
                            {#observer.observe();#}
                        } else {
                            make_screen_movie_list(ret.data, page)
                        }
                        {#div_visible = true#}
                        {#console.log(div_visible)#}
                    }
                    next_page = page + 1
                }
            })
        }

        // Common card HTML generator to ensure consistency
        function generate_card_html(item, linkUrl) {
            let tmp = '<div class="anime-card-wrapper">';
            tmp += '<div class="card glass-card w-100 border-0 h-100">';
            tmp += '<div class="position-relative overflow-hidden" style="border-radius: 12px 12px 0 0;">';
            
            // Image with hover effect wrapper
            tmp += '<div class="img-wrapper">';
            tmp += '<img class="card-img-top lazyload" src="../static/img_loader_x200.svg" data-original="' + item.image_link + '" style="cursor: pointer; aspect-ratio: 2/3; object-fit: cover;" onclick="location.href=\'' + linkUrl + '\'"/>';
            tmp += '</div>'; // End img-wrapper
            
            tmp += '</div>'; // End relative container

            tmp += '<div class="card-body p-3 d-flex flex-column">';
            
            // Title
            tmp += '<h6 class="card-title text-white font-weight-bold mb-2 text-truncate" title="' + item.title + '">' + item.title + '</h6>';
            
            // Code & Heart Button Row
            tmp += '<div class="d-flex justify-content-between align-items-center mt-auto mb-3">';
            tmp += '<span class="badge badge-secondary opacity-75 small">' + item.code + '</span>';
            tmp += '<button id="add_whitelist" name="add_whitelist" class="btn btn-sm btn-circle btn-outline-danger border-0" data-code="' + item.code + '" title="스케쥴링 추가"><i class="bi bi-heart-fill"></i></button>';
            tmp += '</div>';
            
            // Action Button
            tmp += '<a href="' + linkUrl + '" class="btn btn-primary btn-sm btn-block shadow-sm">상세보기</a>';
            
            tmp += '</div>'; // End card-body
            tmp += '</div>'; // End card
            tmp += '</div>'; // End wrapper
            return tmp;
        }

        function make_airing_list(data, page) {
            let str = ''
            
            str += '<div class="d-flex justify-content-between align-items-center mb-3">';
            str += '<h5 class="text-white font-weight-bold border-left pl-3" style="border-width: 4px !important; border-color: #00d4ff !important;">방영중 애니메이션</h5>';
            str += '<button type="button" class="btn btn-sm btn-dark rounded-pill px-3">Page <span class="badge badge-warning ml-1">' + page + '</span></button>';
            str += '</div>';
            
            str += '<div id="inner_screen_movie" class="anime-grid infinite-scroll">';
            for (let i in data.anime_list) {
                let item = data.anime_list[i];
                let request_url = './request?code=' + item.code;
                str += generate_card_html(item, request_url);
            }
            str += '</div>';
            
            str += m_hr_black();

            if (page > 1) {
                const temp = document.createElement('div')
                temp.innerHTML = str;
                while (temp.firstChild) {
                    document.getElementById("screen_movie_list").appendChild(temp.firstChild);
                }
                page++
            } else {
                document.getElementById("screen_movie_list").innerHTML = str;
            }

            $("img.lazyload").lazyload({
                threshold: 10,
                effect: "fadeIn",
            });
        }

        function make_search_result_list(data, page) {
            let str = ''
            let list = data.anime_list || [];
            
            str += '<div class="d-flex justify-content-between align-items-center mb-3">';
            str += '<h5 class="text-white font-weight-bold border-left pl-3" style="border-width: 4px !important; border-color: #ff007f !important;">검색 결과</h5>';
            str += '<button type="button" class="btn btn-sm btn-dark rounded-pill px-3">Page <span class="badge badge-warning ml-1">' + page + '</span></button>';
            str += '</div>';
            
            str += '<div id="inner_screen_movie" class="anime-grid infinite-scroll">';
            
            for (let i in list) {
                let item = list[i];
                let request_url = './request?code=' + item.code;
                
                 if (item.wr_id !== '' && item.wr_id !== undefined) {
                    const re = /bo_table=([^&]+)/
                    const bo_table = item.link.match(re)
                    if (bo_table != null) {
                        request_url += '&amp;wr_id=' + item.wr_id + '&amp;bo_table=' + bo_table[1];
                    }
                }
                
                str += generate_card_html(item, request_url);
            }
            str += '</div>';
            str += m_hr_black();

            if (page > 1) {
                const temp = document.createElement('div')
                temp.innerHTML = str;
                while (temp.firstChild) {
                    document.getElementById("screen_movie_list").appendChild(temp.firstChild);
                }
                page++
            } else {
                document.getElementById("screen_movie_list").innerHTML = str;
            }
        }

        function make_screen_movie_list(data, page) {
             let str = '';
            
            str += '<div class="d-flex justify-content-between align-items-center mb-3">';
             let title = current_cate === 'movie' ? '극장판' : (current_cate === 'theater' ? '극장판(구)' : '완결 애니메이션');
            str += '<h5 class="text-white font-weight-bold border-left pl-3" style="border-width: 4px !important; border-color: #ffd700 !important;">' + title + '</h5>';
            str += '<button type="button" class="btn btn-sm btn-dark rounded-pill px-3">Page <span class="badge badge-warning ml-1">' + page + '</span></button>';
            str += '</div>';
            
            str += '<div id="inner_screen_movie" class="anime-grid infinite-scroll">';
            for (let i in data.anime_list) {
                let item = data.anime_list[i];
                 let request_url = './request?code=' + item.code;
                 
                str += generate_card_html(item, request_url);
            }
            str += '</div>';
            str += m_hr_black();

            if (page > 1) {
                const temp = document.createElement('div')
                temp.innerHTML = str;
                while (temp.firstChild) {
                    document.getElementById("screen_movie_list").appendChild(temp.firstChild);
                }
                page++
            } else {
                document.getElementById("screen_movie_list").innerHTML = str;
            }
            $("img.lazyload").lazyload({
                threshold: 10,
                effect: "fadeIn",
            });
        }


        $(document).ready(function () {
             // Force parent container to be fluid to allow full width
             $("#main_container").removeClass("container").addClass("container-fluid");

            // if ( "{{arg['anilife_current_code']}}" !== "" ) {
            //     document.getElementById("code").value = "{{arg['anilife_current_code']}}";
            //     // 값이 공백이 아니면 분석 버튼 계속 누름
            //     document.getElementById("analysis_btn").click();
            // }
            $("#input_search").keydown(function (key) {
                if (key.keyCode === 13) {
                    $("#btn_search").trigger("click");
                }
            })

            get_anime_list("ing", 1)


            const observer = lozad('.lozad', {
                rootMargin: '10px 0px', // syntax similar to that of CSS Margin
                threshold: 0.1, // ratio of element convergence
                enableAutoReload: true // it will reload the new image when validating attributes changes
            });
            observer.observe();

        });

        $("body").on("click", "#btn_search", function (e) {
            e.preventDefault();
            let query = $("#input_search").val();
            console.log(query);
            current_cate = "search"
            current_query = query

            if ($("#input_search").val() === "") {
                console.log("search keyword nothing");
                return false;
            }

            $.ajax({
                url: "/" + package_name + "/ajax/" + sub + "/search",
                type: "POST",
                cache: false,
                data: {query: query, type: current_cate, page: page},
                // dataType: "json",
                contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                success: function (ret) {
                    if (ret.ret) {
                        console.log('ret:::', ret)
                        make_search_result_list(ret.data, 1);
                        next_page = page + 1
                    } else {
                        $.notify("<strong>분석 실패</strong><br>" + ret.log, {
                            type: "warning",
                        });
                    }
                },
            });
        });

        $('#anime_category #ing').on("click", function () {
            // {#console.log(this.id)#}
            // let spinner = document.getElementById('spinner');
            // spinner.style.visibility = 'visible';
            get_anime_list("ing", 1)
        })

        $('#anime_category #complete_anilist').on("click", function () {
            // {#console.log(this.id)#}
            // let spinner = document.getElementById('spinner');
            // spinner.style.visibility = 'visible';
            get_anime_list("fin", 1)
        })

        $('#anime_category #theater').on("click", function () {
            // {#console.log(this.id)#}
            // let spinner = document.getElementById('spinner');
            // spinner.style.visibility = 'visible';
            get_anime_list("theater", 1)
        })

        // 분석 버튼 클릭시 호출
        $("body").on('click', '#analysis_btn', function (e) {
            e.preventDefault();
            const code = document.getElementById("code").value
            console.log(code)
            $.ajax({
                url: '/' + package_name + '/ajax/' + sub + '/analysis',
                type: "POST",
                cache: false,
                data: {code: code},
                dataType: "json",
                success: function (ret) {
                    if (ret.ret === 'success' && ret.data != null) {
                        // console.log(ret.code)
                        console.log(ret.data)
                        make_program(ret.data)
                    } else {
                        $.notify('<strong>분석 실패</strong><br>' + ret.log, {type: 'warning'});
                    }
                }
            });
        });


        $("body").on('click', '#go_anilife_btn', function (e) {
            e.preventDefault();
            window.open("{{arg['anilife_url']}}", "_blank");
        });

        $("body").on("click", "#add_whitelist", function (e) {
            e.preventDefault();
            let data_code = $(this).attr("data-code");
            console.log(data_code);
            $.ajax({
                url: "/" + package_name + "/ajax/" + sub + "/add_whitelist",
                type: "POST",
                cache: false,
                data: JSON.stringify({data_code: data_code}),
                contentType: "application/json;charset=UTF-8",
                dataType: "json",
                success: function (ret) {
                    if (ret.ret) {
                        $.notify("<strong>추가하였습니다.</strong><br>", {
                            type: "success",
                        });
                        // make_program(ret);
                    } else {
                        $.notify("<strong>추가 실패</strong><br>" + ret.log, {
                            type: "warning",
                        });
                    }
                },
            });
        });

        $("body").on('click', '#all_check_on_btn', function (e) {
            e.preventDefault();
            $('input[id^="checkbox_"]').bootstrapToggle('on')
        });

        $("body").on('click', '#all_check_off_btn', function (e) {
            e.preventDefault();
            $('input[id^="checkbox_"]').bootstrapToggle('off')
        });

        $("body").on('click', '#add_queue_btn', function (e) {
            e.preventDefault();
            data = current_data.episode[$(this).data('idx')];
            console.log('data:::>', data)
            $.ajax({
                url: '/' + package_name + '/ajax/' + sub + '/add_queue',
                type: "POST",
                cache: false,
                data: {data: JSON.stringify(data)},
                dataType: "json",
                success: function (data) {
                    if (data.ret == 'enqueue_db_append' || data.ret == 'enqueue_db_exist') {
                        $.notify('<strong>다운로드 작업을 추가 하였습니다.</strong>', {type: 'success'});
                    } else if (data.ret == 'queue_exist') {
                        $.notify('<strong>이미 큐에 있습니다. 삭제 후 추가하세요.</strong>', {type: 'warning'});
                    } else if (data.ret == 'db_completed') {
                        $.notify('<strong>DB에 완료 기록이 있습니다.</strong>', {type: 'warning'});
                    } else {
                        $.notify('<strong>추가 실패</strong><br>' + ret.log, {type: 'warning'});
                    }
                }
            });
        });
        // const observer = lozad();
        //  	const el = document.querySelector('img');
        // const observer = lozad(el); // passing a `NodeList` (e.g. `document.querySelectorAll()`) is also valid
        // observer.observe();
        const loadNextAnimes = (cate, page) => {
            {#spinner.style.display = "block";#}
            let data = {type: cate, page: String(page)};
            let url = ''
            switch (cate) {
                case 'ing':
                    url = '/' + package_name + '/ajax/' + sub + '/anime_list'
                    current_cate = 'ing'
                    break;
                case 'movie':
                    url = '/' + package_name + '/ajax/' + sub + '/screen_movie_list'
                    current_cate = 'movie'
                    break;
                case 'theater':
                    url = '/' + package_name + '/ajax/' + sub + '/anime_list'
                    current_cate = 'theater'
                    break;
                case 'fin':
                    url = '/' + package_name + '/ajax/' + sub + '/complete_list'
                    current_cate = 'fin'
                    break
                case 'search':
                    url = "/" + package_name + "/ajax/" + sub + "/search"
                    current_cate = 'search'
                    data.query = current_query
                    break;
                default:
                    break;
            }

            fetch(url, {
                method: "POST",
                cache: "no-cache",
                headers: {
                    "Content-Type": "application/x-www-form-urlencoded",
                },
                body: new URLSearchParams(data),
            })
                .then((res) => res.json())
                .then((response) => {
                    // console.log("Success:", JSON.stringify(response));
                    // {#imagesContainer.appendChild()#}
                    console.log("return page:::> ", String(response.page));
                    // {#page = response.page#}
                    if (current_cate === 'search') {
                        make_search_result_list(response.data, response.page);

                    } else {
                        make_screen_movie_list(response.data, response.page);
                    }
                    page++;
                    next_page++;
                })
                .catch((error) => console.error("Error:", error));
        };


        const onScroll = (e) => {
            console.dir(e.target.scrollingElement.scrollHeight);
            const {scrollTop, scrollHeight, clientHeight} = e.target.scrollingElement;
            if (Math.round(scrollHeight - scrollTop) <= clientHeight) {
                {#document.getElementById("spinner").style.display = "block";#}
                console.log("loading");
                console.log("now page::> ", page);
                console.log("next_page::> ", String(next_page));
                loadNextAnimes(current_cate, next_page);
            }
        };

        const debounce = (func, delay) => {
            let timeoutId = null;
            return (...args) => {
                clearTimeout(timeoutId);
                timeoutId = setTimeout(func.bind(null, ...args), delay);
            };
        };

        document.addEventListener("scroll", debounce(onScroll, 300));
    </script>
    <style>
        body {
            font-family: 'NamumSquareNeo', system-ui, -apple-system, Segoe UI, Roboto, Helvetica Neue, Noto Sans, Liberation Sans, Arial, sans-serif;
            background-image: linear-gradient(135deg, #1f2937, #111827, #0f172a);
            color: #e2e8f0;
            min-height: 100vh;
        }

        /* Responsive Grid System */
        .anime-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
            gap: 20px;
            width: 100%;
        }

        .anime-card-wrapper {
             width: 100%;
             height: 100%;
        }
        
        /* Adjust for smaller screens */
        @media (max-width: 576px) {
            .anime-grid {
                grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
                gap: 15px;
            }
        }

    /* Navigation Menu Override */
    ul.nav.nav-pills.bg-light {
        background-color: rgba(30, 41, 59, 0.6) !important;
        backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.08);
        border-radius: 50rem !important;
        padding: 6px !important;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2) !important;
        display: inline-flex !important;
        flex-wrap: wrap;
        justify-content: center;
        width: auto !important;
        margin-bottom: 20px;
    }

    ul.nav.nav-pills .nav-item {
        margin: 0 2px;
    }

    ul.nav.nav-pills .nav-link {
        border-radius: 50rem !important;
        padding: 8px 20px !important;
        color: #94a3b8 !important;
        font-weight: 600;
        transition: all 0.3s ease;
    }

    ul.nav.nav-pills .nav-link:hover {
        background-color: rgba(255, 255, 255, 0.1);
        color: #fff !important;
        transform: translateY(-1px);
    }

    ul.nav.nav-pills .nav-link.active {
        background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%) !important;
        color: #fff !important;
        box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
    }

        /* Glassmorphism Cards */
        .glass-card {
            background: rgba(30, 41, 59, 0.7) !important;
            backdrop-filter: blur(12px) !important;
            border: 1px solid rgba(255, 255, 255, 0.08) !important;
            border-radius: 16px !important;
            transition: transform 0.3s ease, box-shadow 0.3s ease !important;
            overflow: hidden;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }

        .glass-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2), 0 10px 10px -5px rgba(0, 0, 0, 0.1) !important;
            border-color: rgba(96, 165, 250, 0.5) !important;
        }
        
        /* Image Wrapper for Hover Zoom */
        .img-wrapper {
            overflow: hidden;
            border-bottom: 1px solid rgba(255,255,255,0.05);
        }
        
        .img-wrapper img {
            transition: transform 0.5s ease;
        }
        
        .glass-card:hover .img-wrapper img {
            transform: scale(1.05);
        }

        /* Category Buttons */
        .btn-pill {
            border-radius: 50rem !important;
            font-weight: 600;
            border-width: 2px;
            transition: all 0.2s;
        }
        
        .btn-pill:hover, .btn-pill:focus, .btn-pill.active {
             transform: translateY(-2px);
             box-shadow: 0 4px 12px rgba(0,0,0,0.3);
        }

        /* Preloader (Original but styled) */
        #preloader {
            background-color: #0f172a;
            position: fixed;
            top: 0; left: 0; right: 0; bottom: 0;
            z-index: 9999;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        
        .loader-inner {
            position: relative;
        }

        /* Scrollbar */
        ::-webkit-scrollbar {
            width: 8px;
        }
        ::-webkit-scrollbar-track {
            background: #0f172a; 
        }
        ::-webkit-scrollbar-thumb {
            background: #475569; 
            border-radius: 4px;
        }
        ::-webkit-scrollbar-thumb:hover {
            background: #64748b; 
        }

        /* Utilities */
        .cut-text {
            text-overflow: ellipsis;
            overflow: hidden;
            white-space: nowrap;
        }
        
        .btn-circle {
            width: 32px;
            height: 32px;
            padding: 0;
            border-radius: 50%;
            display: inline-flex;
            align-items: center;
            justify-content: center;
        }
    </style>
    <link href="{{ url_for('.static', filename='css/bootstrap.min.css') }}" type="text/css" rel="stylesheet" />
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css">

<style>
    /* Smooth Load Transition */
    .content-cloak, 
    #menu_module_div, 
    #menu_page_div {
        opacity: 0;
        transition: opacity 0.5s ease-out;
    }
    
    /* Staggered Delays for Natural Top-Down Flow */
    #menu_module_div.visible {
        opacity: 1;
        transition-delay: 0ms;
    }

    #menu_page_div.visible {
        opacity: 1;
        transition-delay: 150ms;
    }

    .content-cloak.visible {
        opacity: 1;
        transition-delay: 300ms;
    }
    
    /* Navigation Menu Override (Top Sub-menu) */
    ul.nav.nav-pills.bg-light {
        background-color: rgba(30, 41, 59, 0.6) !important;
        backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.08);
        border-radius: 50rem !important;
        padding: 6px !important;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2) !important;
        display: inline-flex !important;
        flex-wrap: wrap;
        justify-content: center;
        width: auto !important;
        margin-bottom: 20px;
    }

    ul.nav.nav-pills .nav-item { margin: 0 2px; }
    ul.nav.nav-pills .nav-link {
        border-radius: 50rem !important;
        padding: 8px 20px !important;
        color: #94a3b8 !important;
        font-weight: 600;
        transition: all 0.3s ease;
    }
    ul.nav.nav-pills .nav-link:hover {
        background-color: rgba(255, 255, 255, 0.1);
        color: #fff !important;
        transform: translateY(-1px);
    }
    ul.nav.nav-pills .nav-link.active {
        background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%) !important;
        color: #fff !important;
        box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
    }
</style>

<script type="text/javascript">
$(document).ready(function(){
  // Smooth Load Trigger
  setTimeout(function() {
      $('.content-cloak, #menu_module_div, #menu_page_div').addClass('visible');
  }, 100);
});
</script>
<style>
/* Mobile Margin Fix */
@media (max-width: 768px) {
    body { overflow-x: hidden !important; padding: 0 !important; margin: 0 !important; }
    .container, .container-fluid, .row, form, #program_list, #program_auto_form, #episode_list, .queue-container, #yommi_wrapper, #main_container {
        width: 100% !important; max-width: 100% !important;
        padding-left: 4px !important; padding-right: 4px !important;
        margin-left: 0 !important; margin-right: 0 !important;
        box-sizing: border-box !important;
    }
    .form-group, .form-inline, [class*="col-"] {
        flex: 0 0 100% !important; max-width: 100% !important; width: 100% !important;
        padding-left: 0 !important; padding-right: 0 !important;
    }
    .row { margin-left: 0 !important; margin-right: 0 !important; }
    .card, .card.p-4, .card.p-lg-5, .card.border-light {
         width: calc(100% - 8px) !important; max-width: 100% !important;
         padding: 8px !important; margin: 4px !important;
         border-radius: 12px !important; box-sizing: border-box !important;
    }
    .badge {
        white-space: normal !important; text-align: left !important;
        line-height: 1.4 !important; height: auto !important; display: inline-block !important;
    }
}
</style>
{% endblock %}
