:root {
    /* Color Palette - Premium Dark Theme */
    --bg-base: #09090b;
    --bg-surface: rgba(24, 24, 27, 0.6);
    --bg-surface-hover: rgba(39, 39, 42, 0.8);

    --primary: #6366f1;
    /* Indigo */
    --primary-glow: rgba(99, 102, 241, 0.5);
    --secondary: #8b5cf6;
    /* Violet */
    --accent: #0ea5e9;
    /* Sky blue */

    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --danger: #ef4444;

    --border: rgba(255, 255, 255, 0.08);
    --border-light: rgba(255, 255, 255, 0.15);

    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;

    --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Outfit', sans-serif;
}

body {
    background-color: var(--bg-base);
    color: var(--text-main);
    min-height: 100vh;
    overflow: hidden;
    /* Prevent body scroll, manage scroll internally for TV feel */
}

/* Background Orbs for Premium glowing feel */
.bg-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    z-index: -1;
    opacity: 0.4;
    animation: float 20s ease-in-out infinite alternate;
}

.orb-1 {
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, var(--primary) 0%, transparent 70%);
    top: -200px;
    left: -200px;
}

.orb-2 {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, var(--secondary) 0%, transparent 70%);
    bottom: -100px;
    right: -100px;
    animation-delay: -5s;
}

.orb-3 {
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, var(--accent) 0%, transparent 70%);
    top: 40%;
    left: 60%;
    animation-delay: -10s;
}

@keyframes float {
    0% {
        transform: translate(0, 0) scale(1);
    }

    100% {
        transform: translate(50px, 30px) scale(1.1);
    }
}

/* Material Icons Baseline */
.material-symbols-rounded {
    font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    vertical-align: middle;
}

#app {
    display: flex;
    width: 100vw;
    height: 100vh;
}

/* Visibility Control */
.hidden {
    display: none !important;
}

.view,
.content-view {
    display: none;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.view.active,
.content-view.active {
    display: flex;
    opacity: 1;
}

/* Glassmorphism Generic Panel */
.glass-panel {
    background: var(--bg-surface);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
}

/* ===== LOGIN SCREEN ===== */
#login-view {
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
}

.login-panel {
    width: 100%;
    max-width: 420px;
    padding: 3rem;
    border-radius: var(--radius-lg);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin-bottom: 0.5rem;
}

.logo-icon {
    font-size: 2.5rem;
    color: var(--accent);
    text-shadow: 0 0 20px rgba(14, 165, 233, 0.5);
}

.login-panel h1 {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.subtitle {
    color: var(--text-muted);
    margin-bottom: 2.5rem;
    font-size: 0.95rem;
}

.input-group {
    position: relative;
    margin-bottom: 1.5rem;
    width: 100%;
}

.input-group.hidden {
    display: none;
}

.input-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 1.2rem;
    transition: var(--transition);
}

.input-group input,
.input-group select {
    width: 100%;
    padding: 1rem 1rem 1rem 3rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.2);
    color: var(--text-main);
    font-size: 1rem;
    outline: none;
    transition: var(--transition);
}

.input-group select {
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
}

.input-group input:focus,
.input-group select:focus {
    border-color: var(--primary);
    background: rgba(0, 0, 0, 0.4);
    box-shadow: 0 0 0 4px var(--primary-glow);
}

.input-group input:focus+.input-icon,
.input-group select:focus+.input-icon {
    color: var(--primary);
}

/* Buttons */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    color: white;
    outline: none;
}

.btn.primary {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    width: 100%;
}

.btn.primary:hover,
.btn.primary:focus {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px -10px var(--primary);
}

.btn.secondary {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
}

.btn.secondary:hover,
.btn.secondary:focus {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--border-light);
}

.icon-btn {
    padding: 0.5rem;
    border-radius: var(--radius-sm);
}

/* Custom TV Focus State (Spatial Navigation) */
:focus-visible,
.nav-item:focus,
.game-card.focused,
.btn:focus {
    outline: none;
    box-shadow: 0 0 0 4px var(--primary-glow), 0 0 20px rgba(99, 102, 241, 0.4);
    border-color: var(--primary);
    transform: scale(1.02);
    z-index: 10;
}

/* Override input focus to not scale up */
input:focus {
    transform: none !important;
}


/* ===== MAIN LAYOUT (TV STYLE) ===== */
#main-layout {
    width: 100%;
    flex-direction: row;
}

.sidebar {
    width: 280px;
    height: 100%;
    display: flex;
    flex-direction: column;
    border-radius: 0;
    border-top: none;
    border-bottom: none;
    border-left: none;
    padding: 2rem 1.5rem;
    flex-shrink: 0;
}

.logo-container.sm {
    margin-bottom: 3rem;
    padding: 0 1rem;
}

.logo-container.sm h2 {
    font-size: 1.5rem;
    font-weight: 600;
}

.text-glow {
    text-shadow: 0 0 15px currentColor;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.2rem;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    font-size: 1.05rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
    outline: none;
}

.nav-item:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
}

.nav-item.active {
    background: linear-gradient(90deg, rgba(99, 102, 241, 0.15), transparent);
    color: var(--primary);
    border-left: 3px solid var(--primary);
}

.nav-item:focus {
    background: var(--primary);
    color: white;
    border-color: transparent;
    transform: scale(1.05);
    box-shadow: 0 10px 20px -5px rgba(99, 102, 241, 0.5);
}

.sidebar-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
    margin-top: 1rem;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    overflow: hidden;
    /* Added to constrain child text overflow */
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--secondary), var(--primary));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
    /* Prevent avatar from shrinking */
}

.user-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Constrain text */
}

.user-name {
    font-weight: 600;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.user-role {
    font-size: 0.75rem;
    color: var(--accent);
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.5px;
}


/* Content Area */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: relative;
    overflow: hidden;
    /* Critical: prevent main itself from scrolling */
}

.content-header {
    height: 100px;
    padding: 0 3rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 0;
    border-top: none;
    border-left: none;
    border-right: none;
    flex-shrink: 0;
}

.header-title h2 {
    font-size: 1.8rem;
    font-weight: 600;
    margin-bottom: 0.2rem;
}

.header-title p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.clock {
    font-size: 1.5rem;
    font-weight: 300;
    letter-spacing: 1px;
    color: var(--text-muted);
}

.scrollable-content {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 3rem;
    min-height: 0;
    /* Critical for nested flex scrolling */

    /* Hide scrollbar for TV appearance but keep functionality */
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.scrollable-content::-webkit-scrollbar {
    display: none;
}

/* Grid System */
.games-list-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
    padding-bottom: 3rem;
}

/* Cards */
.game-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.2rem;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 1.2rem;
    position: relative;
    overflow: hidden;
}

.game-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--primary);
    opacity: 0;
    transition: var(--transition);
}

.game-card:hover,
.game-card.focused {
    background: var(--bg-surface-hover);
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 15px 30px -10px rgba(0, 0, 0, 0.6);
    border-color: var(--border-light);
}

.game-card:hover::before,
.game-card.focused::before {
    opacity: 1;
}

/* TV Specific Focus for Cards */
.game-card.focused {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-glow), 0 20px 40px -10px rgba(0, 0, 0, 0.8);
    background: linear-gradient(to right, rgba(39, 39, 42, 0.9), rgba(99, 102, 241, 0.1));
}

.channel-icon {
    width: 70px;
    height: 70px;
    object-fit: contain;
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.3);
    padding: 8px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

.channel-info {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    flex: 1;
}

.channel-info h3 {
    font-size: 1.15rem;
    font-weight: 600;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.category-badge {
    background: rgba(99, 102, 241, 0.2);
    color: var(--primary);
    border: 1px solid rgba(99, 102, 241, 0.3);
    font-size: 0.75rem;
    padding: 0.3rem 0.6rem;
    border-radius: 20px;
    width: fit-content;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.5px;
}


/* ===== PLAYER VIEW ===== */
#player-view {
    padding: 0;
}

.player-mode {
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 20;
    padding: 1rem 3rem;
    height: 80px;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.8) 0%, transparent 100%);
    pointer-events: none;
    /* Let clicks pass through to player unless interacting with header */
}

.player-mode>* {
    pointer-events: auto;
}

.player-header-info {
    text-align: right;
}

.player-header-info h3 {
    font-size: 1.5rem;
    font-weight: 600;
}

.player-container {
    width: 100%;
    height: 100%;
    background: #000;
    position: relative;
    border-radius: 0;
    border: none;
}

#iframe-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#iframe-wrapper iframe {
    width: 100%;
    height: 100%;
    border: none;
}


/* Loaders */
.loader-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    width: 100%;
    grid-column: 1 / -1;
    gap: 1.5rem;
    color: var(--text-muted);
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ===== ADMIN PANEL & TABLES ===== */
.premium-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.premium-table th {
    padding: 1.2rem;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
}

.premium-table td {
    padding: 1.2rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    color: var(--text-main);
}

.premium-table tr:last-child td {
    border-bottom: none;
}

.premium-table tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

.table-container {
    border-radius: var(--radius-md);
    overflow-x: auto;
}

.action-buttons {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
}

.modal.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    border-radius: var(--radius-lg);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transform: translateY(20px) scale(0.95);
    transition: var(--transition);
}

.modal.active .modal-content {
    transform: translateY(0) scale(1);
}

/* Media Queries for Mobile/Tablet */
@media (max-width: 900px) {
    #main-layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        padding: 1rem;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        flex-wrap: wrap;
        /* Fix overlapping elements */
        border-bottom: 1px solid var(--border);
        gap: 1rem;
    }

    .logo-container.sm {
        margin-bottom: 0;
        padding: 0;
        width: auto;
        flex: 1;
        /* Allow logo to take up available space on top row if needed */
    }

    .nav-menu {
        flex-direction: row;
        gap: 0.5rem;
        overflow-x: auto;
        flex: unset;
        width: 100%;
        /* Force nav to its own row */
        order: 3;
        /* Move to bottom of the header */
        padding-bottom: 0.5rem;

        /* Hide scrollbar */
        -ms-overflow-style: none;
        scrollbar-width: none;
    }

    .nav-menu::-webkit-scrollbar {
        display: none;
    }

    .nav-item {
        padding: 0.5rem 1rem;
        white-space: nowrap;
        /* Prevent text wrapping inside buttons */
    }

    .nav-item span {
        display: none;
    }

    /* Hide icons on mobile nav */
    .sidebar-footer {
        border: none;
        margin: 0;
        padding: 0;
        order: 2;
        /* Keep logout button next to logo */
        gap: 0.8rem;
    }

    .user-info {
        display: none;
    }

    .avatar {
        width: 32px;
        height: 32px;
    }

    .icon-btn {
        padding: 0.5rem;
    }

    .content-header {
        height: auto;
        padding: 1rem;
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .scrollable-content {
        padding: 1rem;
    }

    .games-list-container {
        grid-template-columns: 1fr;
    }
}