/* ==========================================================================
   Design System & Custom Properties
   ========================================================================== */
:root {
    /* Color Palette - Premium Dark Theme */
    --bg-darker: #07090e;
    --bg-dark: #0f131a;
    --bg-card: #151b26;
    --bg-card-hover: #1e2636;
    --bg-control: rgba(15, 19, 26, 0.75);
    
    --primary: #ff4747; /* Electric Crimson/Orange */
    --primary-glow: rgba(255, 71, 71, 0.45);
    --secondary: #00d2ff; /* Cyber Blue */
    --secondary-glow: rgba(0, 210, 255, 0.3);
    --accent: #00ff66; /* Neon Live Green */
    --accent-glow: rgba(0, 255, 102, 0.4);

    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --text-dark: #64748b;
    
    --border-glass: rgba(255, 255, 255, 0.05);
    --border-active: rgba(255, 71, 71, 0.3);
    
    --radius-lg: 16px;
    --radius-md: 10px;
    --radius-sm: 6px;
    
    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 20px rgba(255, 71, 71, 0.15);
    
    --font-heading: 'Space Grotesk', sans-serif;
    --font-body: 'Outfit', sans-serif;
    
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: all 0.15s ease;
}

/* ==========================================================================
   Base Styles
   ========================================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-darker);
    color: var(--text-main);
    font-family: var(--font-body);
    font-weight: 400;
    line-height: 1.5;
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* On tablet/mobile, allow full page scroll */
@media (max-width: 1024px) {
    body {
        height: auto;
        overflow: auto;
    }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-darker);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-card);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-dark);
}

/* ==========================================================================
   App Layout
   ========================================================================== */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

/* Header styling */
.main-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    height: 70px;
    background-color: var(--bg-dark);
    border-bottom: 1px solid var(--border-glass);
    z-index: 10;
    box-shadow: var(--shadow-sm);
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-area h1 {
    font-family: var(--font-heading);
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 1px;
}

.logo-area h1 span {
    color: var(--primary);
    text-shadow: 0 0 10px var(--primary-glow);
}

.live-dot {
    width: 10px;
    height: 10px;
    background-color: var(--primary);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--primary);
    animation: pulse 1.5s infinite;
}

/* Search bar styling */
.search-bar-container {
    position: relative;
    width: 100%;
    max-width: 400px;
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-dark);
    font-size: 0.95rem;
}

#channel-search {
    width: 100%;
    background-color: var(--bg-darker);
    border: 1px solid var(--border-glass);
    padding: 10px 40px 10px 40px;
    border-radius: var(--radius-lg);
    color: var(--text-main);
    font-family: var(--font-body);
    font-size: 0.95rem;
    transition: var(--transition-smooth);
}

#channel-search:focus {
    outline: none;
    border-color: var(--primary-glow);
    box-shadow: 0 0 10px rgba(255, 71, 71, 0.1);
}

.clear-btn {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-dark);
    cursor: pointer;
    display: none;
    font-size: 0.95rem;
    transition: var(--transition-fast);
}

.clear-btn:hover {
    color: var(--text-main);
}

/* Header Actions */
.action-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, var(--bg-card), var(--bg-card-hover));
    border: 1px solid var(--border-glass);
    color: var(--text-main);
    padding: 10px 16px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 500;
    transition: var(--transition-smooth);
}

.action-btn:hover {
    border-color: var(--primary-glow);
    box-shadow: 0 0 10px rgba(255, 71, 71, 0.1);
    transform: translateY(-1px);
}

.action-btn i {
    font-size: 0.85rem;
}

/* Workspace Layout */
.main-content {
    display: grid;
    grid-template-columns: 1fr 380px;
    flex: 1;
    min-height: 0; /* Allow grid children to shrink and scroll */
    overflow: hidden;
    background-color: var(--bg-darker);
}

/* ==========================================================================
   Player Column
   ========================================================================== */
.player-section {
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    overflow-y: auto;
    gap: 1.5rem;
}

.video-container {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background-color: #000;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-glass);
}

#main-video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Custom Controls Overlay */
.player-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background: linear-gradient(to bottom, rgba(7, 9, 14, 0.6) 0%, rgba(7, 9, 14, 0) 25%, rgba(7, 9, 14, 0) 75%, rgba(7, 9, 14, 0.8) 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 5;
    pointer-events: none;
}

.video-container:hover .player-overlay,
.video-container:focus-within .player-overlay {
    opacity: 1;
}

.player-overlay * {
    pointer-events: auto;
}

/* Top bar details */
.player-top-bar {
    padding: 1.2rem;
    color: var(--text-main);
}

.now-playing-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background-color: var(--primary);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    letter-spacing: 1px;
    margin-bottom: 6px;
}

.pulse-icon {
    width: 6px;
    height: 6px;
    background-color: #fff;
    border-radius: 50%;
    animation: pulse 1s infinite alternate;
}

.player-top-bar h2 {
    font-family: var(--font-heading);
    font-size: 1.3rem;
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
}

/* Big Play State */
.play-state-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background-color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.8rem;
    cursor: pointer;
    opacity: 0.9;
    box-shadow: 0 0 25px var(--primary-glow);
    transition: var(--transition-smooth);
}

.play-state-overlay:hover {
    transform: translate(-50%, -50%) scale(1.1);
    opacity: 1;
}

/* Loading & Error States — positioned OUTSIDE the overlay so they're always visible */
.player-loader,
.player-error {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-darker);
    z-index: 10; /* Above .player-overlay (z-index:5) */
}

.spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(255, 71, 71, 0.1);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 1s ease-in-out infinite;
    margin-bottom: 12px;
}

.loader-text {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.player-error {
    background-color: rgba(7, 9, 14, 0.95);
    padding: 2rem;
    text-align: center;
}

.error-icon {
    font-size: 3rem;
    color: var(--primary);
    margin-bottom: 15px;
    text-shadow: 0 0 15px rgba(255, 71, 71, 0.2);
}

.player-error h3 {
    font-family: var(--font-heading);
    font-size: 1.4rem;
    margin-bottom: 8px;
}

.player-error p {
    color: var(--text-muted);
    font-size: 0.9rem;
    max-width: 320px;
    margin-bottom: 20px;
}

.retry-btn {
    background-color: var(--primary);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 0.9rem;
    transition: var(--transition-smooth);
    box-shadow: 0 4px 10px rgba(255, 71, 71, 0.3);
}

.retry-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 15px rgba(255, 71, 71, 0.4);
}

/* Control Bar Bottom */
.player-control-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.2rem;
    background: linear-gradient(to top, rgba(7, 9, 14, 0.9) 0%, rgba(7, 9, 14, 0) 100%);
}

.control-left,
.control-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.control-btn {
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 1.1rem;
    cursor: pointer;
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
}

.control-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--primary);
    transform: scale(1.05);
}

.volume-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.vol-slider {
    -webkit-appearance: none;
    width: 70px;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    outline: none;
    transition: var(--transition-fast);
}

.vol-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    box-shadow: 0 0 5px rgba(255, 71, 71, 0.5);
    transition: var(--transition-fast);
}

.vol-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.live-indicator-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    background-color: rgba(0, 255, 102, 0.1);
    border: 1px solid rgba(0, 255, 102, 0.2);
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 20px;
}

.live-text-dot {
    width: 6px;
    height: 6px;
    background-color: var(--accent);
    border-radius: 50%;
    box-shadow: 0 0 5px var(--accent);
}

/* Channel Info Card */
.channel-info-card {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 1.5rem;
    background-color: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-glass);
    box-shadow: var(--shadow-sm);
}

.channel-info-card img {
    width: 65px;
    height: 65px;
    border-radius: var(--radius-md);
    object-fit: contain;
    background-color: #fff;
    padding: 5px;
    border: 1px solid var(--border-glass);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.channel-info-card .info-text h3 {
    font-family: var(--font-heading);
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.channel-info-card .info-text p {
    font-size: 0.88rem;
    color: var(--text-muted);
}

/* ==========================================================================
   Sidebar Column
   ========================================================================== */
.sidebar-section {
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--border-glass);
    background-color: var(--bg-dark);
    min-height: 0;  /* Critical: allows flex children to scroll */
    overflow: hidden; /* Contain scrolling to .channels-list-container */
}

/* Category Tabs */
.category-tabs {
    display: flex;
    gap: 8px;
    padding: 1rem 1.2rem;
    border-bottom: 1px solid var(--border-glass);
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
}

.category-tabs::-webkit-scrollbar {
    height: 4px;
}

.category-tabs::-webkit-scrollbar-track {
    background: transparent;
}

.category-tabs::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
}

.tab-btn {
    flex-shrink: 0;
    padding: 8px 16px;
    background: none;
    border: 1px solid var(--border-glass);
    color: var(--text-muted);
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition-smooth);
}

.tab-btn:hover {
    color: var(--text-main);
    background-color: rgba(255, 255, 255, 0.02);
}

.tab-btn.active {
    color: white;
    background-color: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 4px 10px rgba(255, 71, 71, 0.2);
}

/* Channels list container */
.channels-list-container {
    flex: 1;
    overflow-y: auto;
    padding: 1.2rem;
}

.channels-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

/* Channel Card styling */
.channel-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background-color: var(--bg-card);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition-smooth);
}

.channel-card:hover {
    background-color: var(--bg-card-hover);
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.channel-card.active {
    border-color: var(--primary-glow);
    background: linear-gradient(135deg, var(--bg-card), rgba(255, 71, 71, 0.05));
    box-shadow: var(--shadow-glow);
}

.channel-card .logo-container {
    position: relative;
    width: 46px;
    height: 46px;
    flex-shrink: 0;
}

.channel-card img {
    width: 100%;
    height: 100%;
    border-radius: var(--radius-sm);
    object-fit: contain;
    background-color: #fff;
    padding: 4px;
    border: 1px solid var(--border-glass);
}

.channel-card.active img {
    border-color: var(--primary);
}

.channel-card .logo-container::after {
    content: '';
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--accent);
    border: 2px solid var(--bg-card);
    opacity: 0;
    transition: var(--transition-fast);
}

.channel-card.active .logo-container::after {
    opacity: 1;
}

.channel-details {
    flex: 1;
    overflow: hidden;
}

.channel-name {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.channel-group-tag {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.channel-card.active .channel-name {
    color: var(--primary);
}

.play-icon-indicator {
    color: var(--text-dark);
    font-size: 0.8rem;
    opacity: 0;
    transform: translateX(-5px);
    transition: var(--transition-smooth);
}

.channel-card:hover .play-icon-indicator {
    opacity: 1;
    transform: translateX(0);
}

.channel-card.active .play-icon-indicator {
    opacity: 1;
    color: var(--primary);
    transform: translateX(0);
    animation: bounceRight 1s infinite alternate;
}

/* Skeletons */
.list-loader {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.skeleton-item {
    height: 68px;
    border-radius: var(--radius-md);
    background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-card-hover) 50%, var(--bg-card) 75%);
    background-size: 200% 100%;
    animation: skeletonShimmer 1.5s infinite;
}

/* No Results */
.no-results-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--text-dark);
}

.no-results-message i {
    font-size: 2.2rem;
    margin-bottom: 12px;
}

.no-results-message p {
    font-size: 0.92rem;
}

/* ==========================================================================
   Sync modal overlay (12MB downloader loading screen)
   ========================================================================== */
.sync-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(7, 9, 14, 0.92);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.sync-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-glass);
    padding: 2.5rem 2rem;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 480px;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.sync-icon-container {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background-color: rgba(255, 71, 71, 0.05);
    border: 1px solid rgba(255, 71, 71, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    box-shadow: 0 0 15px rgba(255, 71, 71, 0.05);
}

.sync-icon {
    font-size: 2.2rem;
    color: var(--primary);
}

.sync-card h2 {
    font-family: var(--font-heading);
    font-size: 1.45rem;
    font-weight: 700;
    margin-bottom: 10px;
}

.sync-card p {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 25px;
    line-height: 1.6;
}

.progress-bar-wrapper {
    background-color: var(--bg-darker);
    height: 6px;
    width: 100%;
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 12px;
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: 3px;
    transition: width 0.3s ease;
    box-shadow: 0 0 8px rgba(255, 71, 71, 0.5);
}

.sync-status {
    font-size: 0.82rem;
    color: var(--text-dark);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ==========================================================================
   Animations
   ========================================================================== */
@keyframes pulse {
    0% {
        transform: scale(0.9);
        box-shadow: 0 0 0 0 rgba(255, 71, 71, 0.7);
    }
    70% {
        transform: scale(1.1);
        box-shadow: 0 0 0 10px rgba(255, 71, 71, 0);
    }
    100% {
        transform: scale(0.9);
        box-shadow: 0 0 0 0 rgba(255, 71, 71, 0);
    }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes skeletonShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@keyframes bounceRight {
    0% { transform: translateX(-2px); }
    100% { transform: translateX(2px); }
}

.pulse-animation {
    animation: syncPulse 2s infinite alternate;
}

@keyframes syncPulse {
    0% { transform: scale(1); opacity: 0.8; }
    100% { transform: scale(1.1); opacity: 1; }
}

/* ==========================================================================
   Responsive Design Layouts
   ========================================================================== */
@media (max-width: 1024px) {
    .app-container {
        height: auto;
        min-height: 100vh;
    }
    
    .main-content {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto;
        overflow: visible;
    }
    
    .sidebar-section {
        border-left: none;
        border-top: 1px solid var(--border-glass);
        height: 70vh;
        min-height: 400px;
        overflow: hidden;
    }
    
    .player-section {
        overflow-y: visible;
        padding: 1.2rem;
    }
}

@media (max-width: 768px) {
    .main-header {
        padding: 0 1.2rem;
    }
    
    .logo-area h1 {
        font-size: 1.2rem;
    }
    
    .search-bar-container {
        display: none; /* Move to inside the list header or toggle on mobile */
    }
    
    .action-btn span {
        display: none;
    }
    
    .action-btn {
        padding: 10px;
    }
    
    .player-section {
        padding: 0.8rem;
        gap: 0.8rem;
    }
    
    .video-container {
        border-radius: var(--radius-md);
    }
    
    .channel-info-card {
        padding: 1rem;
        border-radius: var(--radius-md);
    }
    
    .channel-info-card img {
        width: 50px;
        height: 50px;
    }
    
    .channel-info-card .info-text h3 {
        font-size: 1.05rem;
    }
    
    .sidebar-section {
        height: 450px;
    }
}

@media (max-width: 480px) {
    .category-tabs {
        padding: 0.8rem;
    }
    
    .tab-btn {
        font-size: 0.8rem;
        padding: 8px 0;
    }
    
    .channels-list-container {
        padding: 0.8rem;
    }
}
