/* =========================================
   CHANNEL LIST PRO - TV EDITION v3.3.2
   Full CSS Isolation (#clp-root)
   Mobile Optimized (Horizontal Menu)
   ========================================= */

/* --- 1. Root Container & Variables --- */
#clp-root {
    --tv-bg: #0b0b0b;
    --tv-sidebar: #111;
    --tv-accent: #00d1b2;
    --tv-text: #fff;
    --tv-border: rgba(255, 255, 255, 0.1);
    
    /* Reset & Isolation */
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.5;
    background: #1a1a1a;
    padding: 15px;
    border-radius: 20px;
    margin: 20px auto;
    max-width: 1200px;
    direction: ltr; /* Force LTR inside the player */
    position: relative;
    z-index: 1;
    color: #fff;
}

#clp-root *, #clp-root *::before, #clp-root *::after {
    box-sizing: inherit;
}

/* --- 2. TV Frame Layout (Desktop) --- */
#clp-root .clp-tv-frame {
    border: 8px solid #222;
    border-radius: 16px;
    background: var(--tv-bg);
    box-shadow: 0 0 40px rgba(0,0,0,0.8);
    overflow: hidden;
    position: relative;
}

#clp-root .clp-container {
    display: flex;
    /* Fixed height for Desktop to create the "App" feel */
    height: 700px; 
    overflow: hidden;
    background: radial-gradient(circle at top right, #1a1a1a, #000);
}

/* --- 3. Lock Screen (Overlay) --- */
#clp-root .clp-overlay {
    position: absolute; inset: 0;
    background: rgba(5, 5, 5, 0.98);
    z-index: 999;
    display: flex; align-items: center; justify-content: center;
}

#clp-root .clp-auth-card {
    background: #161616; padding: 40px; border-radius: 20px;
    text-align: center; border: 1px solid var(--tv-border);
    width: 300px; box-shadow: 0 20px 50px rgba(0,0,0,0.7);
}

#clp-root .clp-lock-icon { font-size: 50px; margin-bottom: 10px; display: block; }
#clp-root .clp-auth-card h3 { margin: 10px 0; color: #fff; font-size: 22px; }
#clp-root .clp-auth-card p { color: #888; font-size: 14px; margin-bottom: 20px; }

#clp-root .clp-pass-input {
    width: 100%; padding: 12px; background: #000; border: 2px solid #333;
    color: var(--tv-accent); text-align: center; font-size: 24px;
    letter-spacing: 5px; border-radius: 8px; margin-bottom: 20px; outline: none;
    display: block;
}
#clp-root .clp-pass-input:focus { border-color: var(--tv-accent); }

#clp-root .clp-unlock-btn {
    background: var(--tv-accent); color: #000; width: 100%; padding: 12px;
    border: none; border-radius: 8px; font-weight: bold; cursor: pointer; transition: 0.3s;
    font-size: 16px; display: block;
}
#clp-root .clp-unlock-btn:hover { background: #00b89c; transform: scale(1.02); }
#clp-root .clp-error-msg { color: #ff3860; display: none; margin-top: 15px; font-weight: bold; }

/* --- 4. Sidebar (Desktop) --- */
#clp-root .clp-sidebar {
    width: 260px; 
    background: var(--tv-sidebar);
    border-right: 1px solid var(--tv-border);
    padding: 20px;
    display: flex; flex-direction: column;
    flex-shrink: 0; text-align: left;
}

#clp-root .clp-brand { font-size: 28px; font-weight: 900; margin-bottom: 20px; color: #fff; display: block; }
#clp-root .clp-brand span { color: var(--tv-accent); }

#clp-root .clp-search-box input {
    width: 100%; background: #000; border: 1px solid #333;
    padding: 10px; border-radius: 6px; color: #fff; margin-bottom: 15px;
    font-size: 14px;
}

/* Vertical List for Desktop */
#clp-root .clp-country-list { 
    list-style: none !important; padding: 0 !important; margin: 0 !important; 
    overflow-y: auto; flex: 1; padding-right: 5px; 
}

/* Custom Scrollbar */
#clp-root .clp-country-list::-webkit-scrollbar { width: 4px; }
#clp-root .clp-country-list::-webkit-scrollbar-thumb { background: #333; border-radius: 10px; }
#clp-root .clp-country-list::-webkit-scrollbar-thumb:hover { background: var(--tv-accent); }

#clp-root .clp-country-list li {
    padding: 12px 15px; margin-bottom: 8px; border-radius: 8px; cursor: pointer;
    color: #aaa; transition: 0.2s; font-size: 15px; display: block; border: none;
}
#clp-root .clp-country-list li:hover { background: rgba(255,255,255,0.05); color: #fff; transform: translateX(5px); }
#clp-root .clp-country-list li.active { background: var(--tv-accent); color: #000; font-weight: bold; }

/* --- 5. Main Content --- */
#clp-root .clp-main { 
    flex: 1; padding: 30px; 
    display: flex; flex-direction: column; 
    position: relative; overflow: hidden; 
}

#clp-root .clp-screen-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 20px; border-bottom: 1px solid var(--tv-border); padding-bottom: 15px;
}

#clp-root .clp-current-title { margin: 0; font-size: 24px; color: #fff; line-height: 1.2; }
#clp-root .clp-header-tools { display: flex; align-items: center; gap: 15px; }

#clp-root .clp-status-badge {
    background: rgba(255, 56, 96, 0.2); color: #ff3860; padding: 5px 12px;
    border-radius: 20px; font-size: 12px; font-weight: bold; animation: clpPulse 2s infinite;
}
@keyframes clpPulse { 0% { opacity: 0.6; } 50% { opacity: 1; } 100% { opacity: 0.6; } }

#clp-root .clp-channel-filter {
    background: #000; border: 1px solid #333; padding: 8px 15px;
    border-radius: 20px; color: #fff; outline: none; width: 200px; font-size: 14px;
}

/* --- 6. Grid & Items --- */
#clp-root .clp-channels-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px; flex: 1; overflow-y: auto; padding-right: 5px; padding-bottom: 10px;
}
#clp-root .clp-channels-grid::-webkit-scrollbar { width: 6px; }
#clp-root .clp-channels-grid::-webkit-scrollbar-thumb { background: #444; border-radius: 10px; }

#clp-root .clp-channel-item {
    background: #181818; padding: 20px 10px; text-align: center;
    border-radius: 12px; border: 1px solid #2a2a2a;
    transition: 0.3s; font-size: 13px; font-weight: 600; cursor: pointer;
    display: flex; align-items: center; justify-content: center; min-height: 80px;
    color: #fff; word-break: break-word;
}
#clp-root .clp-channel-item:hover {
    background: #fff; color: #000; transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0,0,0,0.5);
}

/* --- 7. Pagination & Footer --- */
#clp-root .clp-pagination {
    margin-top: 15px; display: flex; justify-content: center; align-items: center; gap: 20px;
    padding-top: 15px; border-top: 1px solid var(--tv-border);
}
#clp-root .clp-nav-btn {
    background: #222; color: #fff; border: 1px solid #444; padding: 8px 20px;
    border-radius: 6px; cursor: pointer; transition: 0.2s; font-size: 14px;
}
#clp-root .clp-nav-btn:hover:not(:disabled) { background: var(--tv-accent); color: #000; }
#clp-root .clp-nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* --- 8. Loader --- */
#clp-root .clp-loader-overlay {
    position: absolute; inset: 0; background: rgba(0,0,0,0.7); display: none;
    align-items: center; justify-content: center; z-index: 50;
}
#clp-root .clp-spinner {
    width: 40px; height: 40px; border: 4px solid rgba(255,255,255,0.1);
    border-top-color: var(--tv-accent); border-radius: 50%;
    animation: clpSpin 0.8s linear infinite;
}
@keyframes clpSpin { to { transform: rotate(360deg); } }

/* =========================================
   MOBILE FIX (The Important Part) 📱
   ========================================= */
@media (max-width: 768px) {
    
    /* 1. Main Container: Stack elements vertically */
    #clp-root .clp-container {
        flex-direction: column;
        height: 80vh; /* Dynamic height for mobile */
        min-height: 550px;
    }

    /* 2. Sidebar: Become a top horizontal bar */
    #clp-root .clp-sidebar {
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--tv-border);
        padding: 10px;
        flex-shrink: 0;
        z-index: 10;
        background: #111;
    }

    /* Hide Brand on mobile to save space */
    #clp-root .clp-brand { display: none; }

    /* Compact Search Box */
    #clp-root .clp-search-box input {
        margin-bottom: 8px;
        padding: 6px;
        font-size: 12px;
    }

    /* 3. Country List: Horizontal Scroll (Chips Style) */
    #clp-root .clp-country-list {
        display: flex;
        flex-direction: row; /* Horizontal */
        overflow-x: auto;   /* Scroll sideways */
        overflow-y: hidden;
        gap: 8px;
        padding-bottom: 5px;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Hide scrollbar for cleaner look on mobile */
    #clp-root .clp-country-list::-webkit-scrollbar { display: none; }

    #clp-root .clp-country-list li {
        white-space: nowrap;
        margin: 0;
        flex-shrink: 0;
        padding: 6px 14px;
        background: #222;
        border-radius: 20px;
        font-size: 12px;
        border: 1px solid #333;
    }

    #clp-root .clp-country-list li.active {
        background: var(--tv-accent);
        color: #000;
        border-color: var(--tv-accent);
    }

    /* 4. Main Content Area */
    #clp-root .clp-main {
        padding: 15px;
    }

    #clp-root .clp-screen-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    #clp-root .clp-header-tools {
        width: 100%;
        justify-content: space-between;
    }

    #clp-root .clp-channel-filter {
        width: 140px;
    }

    /* 5. Grid Adjustment */
    #clp-root .clp-channels-grid {
        grid-template-columns: repeat(2, 1fr); /* 2 Columns on mobile */
        gap: 10px;
    }

    #clp-root .clp-channel-item {
        min-height: 60px;
        font-size: 11px;
    }
}
