:root {
    --bg-color: #0f172a;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --primary-color: #8b5cf6;
    --primary-hover: #a78bfa;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --card-bg: rgba(15, 23, 42, 0.6);
    --card-hover: rgba(30, 41, 59, 0.8);
    --active-bg: rgba(139, 92, 246, 0.2);
    --active-border: #8b5cf6;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Background Animated Shapes */
.bg-shape {
    position: absolute;
    filter: blur(100px);
    z-index: -1;
    opacity: 0.5;
}
.shape-1 {
    top: -100px;
    left: -100px;
    width: 400px;
    height: 400px;
    background: #4c1d95;
    border-radius: 50%;
}
.shape-2 {
    bottom: -150px;
    right: -50px;
    width: 500px;
    height: 500px;
    background: #1e3a8a;
    border-radius: 50%;
}
.shape-3 {
    top: 30%;
    left: 40%;
    width: 300px;
    height: 300px;
    background: #064e3b;
    border-radius: 50%;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 10;
}

/* Header */
.top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: var(--glass-bg);
    border-bottom: 1px solid var(--glass-border);
    backdrop-filter: blur(10px);
    z-index: 20;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    font-size: 1.5rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-action {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.45rem 0.85rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--glass-border);
    border-radius: 0.65rem;
    color: #e2e8f0;
    font-size: 0.82rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: all 0.2s ease;
}

.btn-action:hover {
    background: rgba(139, 92, 246, 0.25);
    border-color: var(--primary-color);
    color: #ffffff;
    transform: translateY(-1px);
}

.brand h1 {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    background: linear-gradient(to right, #e2e8f0, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.menu-toggle {
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 0.5rem;
    transition: background 0.2s;
    display: flex;
}

.menu-toggle:hover {
    background: var(--glass-border);
}

/* Video Area */
.video-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    gap: 1rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.video-container {
    position: relative;
    flex: 1;
    background: #000;
    border-radius: 1rem;
    overflow: hidden;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    border: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.video-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(5px);
    transition: opacity 0.3s;
}

.overlay-content {
    text-align: center;
    animation: fadeIn 0.5s ease-out;
}

.pulse-icon {
    font-size: 3rem;
    color: var(--primary-color);
    display: block;
    margin-bottom: 1rem;
    animation: pulse 2s infinite;
}

#nowPlayingText {
    font-size: 1.25rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.channel-info-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background: var(--glass-bg);
    border-radius: 1rem;
    border: 1px solid var(--glass-border);
}

.current-channel-badge {
    background: var(--active-bg);
    color: var(--primary-hover);
    padding: 0.25rem 0.75rem;
    border-radius: 2rem;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    border: 1px solid var(--active-border);
}

#currentChannelName {
    font-size: 1.125rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Sidebar / Bottom Sheet */
.sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 70vh;
    background: var(--glass-bg);
    border-top: 1px solid var(--glass-border);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    flex-direction: column;
    z-index: 30;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.3);
    border-radius: 1.5rem 1.5rem 0 0;
}

.sidebar.open {
    transform: translateY(0);
}

.sidebar-header {
    padding: 1.5rem 1.5rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    border-bottom: 1px solid var(--glass-border);
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 1rem;
    color: var(--text-secondary);
}

#searchInput {
    width: 100%;
    padding: 0.875rem 1rem 0.875rem 3rem;
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.search-sort-bar {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 1rem;
}

.search-sort-bar .search-box {
    flex: 1;
    margin-bottom: 0;
}

.sort-select {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--glass-border);
    color: #e2e8f0;
    padding: 0.75rem 0.5rem;
    border-radius: 0.85rem;
    font-size: 0.82rem;
    outline: none;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: all 0.2s;
}

.sort-select:focus, .sort-select:hover {
    border-color: var(--primary-color);
    background: rgba(255, 255, 255, 0.1);
}

.sort-select option {
    background: #1e1b4b;
    color: #e2e8f0;
}

#searchInput:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.2);
}

/* Category Pills (Horizontal Scroll) */
.category-scroll-container {
    overflow-x: auto;
    padding-bottom: 1rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
}
.category-scroll-container::-webkit-scrollbar {
    display: none;
}

.category-pills {
    display: flex;
    gap: 0.5rem;
    white-space: nowrap;
}

.pill {
    background: var(--card-bg);
    color: var(--text-secondary);
    border: 1px solid var(--glass-border);
    padding: 0.5rem 1.25rem;
    border-radius: 2rem;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
}

.pill:hover {
    background: var(--card-hover);
    color: var(--text-primary);
}

.pill.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* Channel List */
.channel-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.channel-list::-webkit-scrollbar {
    width: 6px;
}
.channel-list::-webkit-scrollbar-track {
    background: transparent;
}
.channel-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}

.channel-item {
    display: flex;
    align-items: center;
    padding: 1rem;
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.channel-item:hover {
    background: var(--card-hover);
    transform: translateY(-2px);
}

.channel-item.active {
    background: var(--active-bg);
    border-color: var(--active-border);
}

.channel-status {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.55rem;
    border-radius: 12px;
    font-size: 0.72rem;
    font-weight: 500;
    margin-left: auto;
    flex-shrink: 0;
    transition: all 0.3s ease;
}

.channel-status.online {
    background: rgba(34, 197, 94, 0.12);
    color: #4ade80;
    border: 1px solid rgba(34, 197, 94, 0.25);
}

.channel-status.offline {
    background: rgba(239, 68, 68, 0.12);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.25);
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: currentColor;
    box-shadow: 0 0 6px currentColor;
}

.channel-logo {
    width: 48px;
    height: 48px;
    border-radius: 0.75rem;
    margin-right: 1rem;
    object-fit: contain;
    background: rgba(0, 0, 0, 0.2);
    padding: 0.25rem;
}

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

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

.channel-group {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Loading Spinner */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    gap: 1rem;
}

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

@keyframes spin {
    to { transform: rotate(360deg); }
}
@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Desktop Layout (Desktop-first override) */
@media (min-width: 768px) {
    .app-container {
        flex-direction: row;
    }

    .top-nav {
        display: none; /* Hide top nav on desktop, brand goes to sidebar */
    }

    .sidebar {
        position: static;
        width: 380px;
        height: 100vh;
        transform: none;
        border-radius: 0;
        border-top: none;
        border-right: 1px solid var(--glass-border);
        box-shadow: none;
    }

    .video-wrapper {
        padding: 2rem;
        max-width: none;
    }

    .sidebar-header::before {
        content: "📺 Global IPTV";
        display: block;
        font-size: 1.5rem;
        font-weight: 600;
        margin-bottom: 1.5rem;
        background: linear-gradient(to right, #e2e8f0, #94a3b8);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
    }

    .category-scroll-container {
        max-height: 115px;
        overflow-y: auto;
        overflow-x: hidden;
        padding-right: 4px;
        position: relative;
    }
    
    /* Custom Scrollbar for Category Container */
    .category-scroll-container::-webkit-scrollbar {
        width: 5px;
    }

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

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

    .category-scroll-container::-webkit-scrollbar-thumb:hover {
        background: rgba(99, 102, 241, 0.6);
    }
    
    .category-pills {
        flex-wrap: wrap;
        white-space: normal;
    }
}
