/* ===== TV PAGE - TOPIC-BASED STREAMING PLATFORM ===== */

/* CSS VARIABLES */
:root {
    --primary: #000000;
    --primary-light: #333333;
    --accent: #ffffff;
    --bg: #0a0a0a;
    --card-bg: #1a1a1a;
    --text: #ffffff;
    --text-muted: #999999;
    --border: #2a2a2a;
    --success: #2ecc71;
    --danger: #e74c3c;
    --warning: #f39c12;
    --info: #3498db;
    --purple: #9b59b6;
    --pink: #e91e63;

    --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 25px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.5);

    --transition-fast: 0.2s;
    --transition-medium: 0.4s;
    --cubic: cubic-bezier(0.4, 0, 0.2, 1);

    /* Sidebar Layout Variables */
    --sidebar-width: 260px;
    --sidebar-collapsed: 70px;
    --card-radius: 12px;
    --card-hover-scale: 1.03;
}

[data-theme="light"] {
    --bg: #fafafa;
    --card-bg: #ffffff;
    --text: #000000;
    --text-muted: #666666;
    --border: #e8e8e8;
    --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 8px 25px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.15);
}

/* ===== TV CONTAINER (SIDEBAR + CONTENT) ===== */
.tv-container {
    display: flex;
    min-height: 100vh;
    padding-top: 70px; /* Nav height */
    background: var(--bg);
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    box-sizing: border-box;
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--card-bg);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    right: 0;
    top: 70px;
    bottom: 0;
    z-index: 100;
    transition: transform var(--transition-medium) var(--cubic);
}

.sidebar-header {
    padding: 1.5rem 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--text);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: background var(--transition-fast);
    display: none; /* Hidden on desktop, visible on mobile */
}

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

.sidebar-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: visible;
    flex: 1;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0;
    overflow-y: auto;
}

.sidebar-btn {
    width: 100%;
    padding: 1rem 1.5rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 1rem;
    text-align: right;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: all var(--transition-fast);
    position: relative;
    white-space: nowrap;
    overflow: visible;
}

.sidebar-btn i {
    font-size: 1.2rem;
    min-width: 24px;
    flex-shrink: 0;
}

.sidebar-btn span {
    flex: 1;
    white-space: nowrap;
    overflow: visible;
    text-overflow: clip;
}

.sidebar-btn .badge {
    background: var(--danger);
    color: #fff;
    font-size: 0.75rem;
    padding: 0.2rem 0.5rem;
    border-radius: 12px;
    font-weight: 700;
}

.sidebar-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
}

.sidebar-btn.active {
    background: rgba(255, 255, 255, 0.1);
    color: var(--accent);
    font-weight: 600;
}

.sidebar-btn.active::before {
    content: '';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 70%;
    background: var(--accent);
    border-radius: 2px 0 0 2px;
}

.sidebar-footer {
    padding: 1rem 0;
    border-top: 1px solid var(--border);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 99;
    top: 70px;
}

/* ===== MAIN CONTENT AREA ===== */
.main-content {
    flex: 1;
    margin-left: 0;
    margin-right: var(--sidebar-width);
    padding: 2rem;
    max-width: calc(100% - var(--sidebar-width));
    width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
}

/* ===== VIEW CONTAINERS ===== */
.view-container {
    display: none;
    animation: fadeIn 0.3s ease-in;
    min-height: 60vh;
    width: 100%;
}

.view-container.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.view-header {
    margin-bottom: 2rem;
    max-width: 100%;
    overflow: visible;
}

.view-header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text);
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.2;
    max-width: 100%;
}

.view-header p {
    font-size: 1.1rem;
    color: var(--text-muted);
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.6;
    max-width: 100%;
}

.back-btn {
    background: var(--card-bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 1rem;
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    transition: all var(--transition-fast);
}

.back-btn:hover {
    background: var(--border);
    transform: translateX(5px);
}

.back-btn i {
    transition: transform var(--transition-fast);
}

.back-btn:hover i {
    transform: translateX(3px);
}

/* ===== TOPICS GRID ===== */
.topics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 2rem;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    min-height: 50vh;
}

/* When topics-grid contains only empty-state, make it full width */
.topics-grid:has(.empty-state) {
    display: flex;
    align-items: center;
    justify-content: center;
}

.topic-card {
    background: var(--card-bg);
    border-radius: var(--card-radius);
    overflow: hidden;
    cursor: pointer;
    transition: transform var(--transition-medium) var(--cubic), box-shadow var(--transition-medium);
    border: 1px solid var(--border);
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.topic-card:hover {
    transform: scale(var(--card-hover-scale));
    box-shadow: var(--shadow-lg);
}

.topic-card-image {
    width: 100%;
    aspect-ratio: 16 / 9;
    position: relative;
    overflow: hidden;
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--bg) 100%);
}

.topic-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--transition-medium);
}

.topic-card:hover .topic-card-image img {
    transform: scale(1.1);
}

.topic-card-badge {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    backdrop-filter: blur(10px);
}

.topic-card-content {
    padding: 1.5rem;
}

.topic-card-title {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text);
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.3;
}

.topic-card-description {
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.topic-card-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.topic-card-meta i {
    color: var(--info);
}

/* ===== EPISODES LIST ===== */
.episodes-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    min-height: 50vh;
}

/* When episodes-list contains only empty-state, center it */
.episodes-list:has(.empty-state) {
    align-items: center;
    justify-content: center;
}

.episode-item {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--card-radius);
    padding: 1.5rem;
    display: flex;
    gap: 1.5rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

.episode-item:hover {
    background: var(--primary-light);
    transform: translateX(-5px);
    box-shadow: var(--shadow-md);
}

.episode-number {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-muted);
    min-width: 50px;
    text-align: center;
    align-self: center;
}

.episode-thumbnail {
    width: 180px;
    aspect-ratio: 16 / 9;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    background: var(--bg);
    flex-shrink: 0;
}

.episode-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.episode-play-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.episode-item:hover .episode-play-overlay {
    opacity: 1;
}

.episode-play-icon {
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #000;
    font-size: 1.2rem;
}

.episode-progress-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
}

.episode-progress-fill {
    height: 100%;
    background: var(--danger);
    transition: width var(--transition-fast);
}

.episode-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.episode-title {
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text);
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.4;
}

.episode-description {
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
    line-height: 1.6;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.episode-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.episode-meta i {
    color: var(--info);
}

.episode-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-self: center;
}

.episode-action-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 0.5rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: 1.1rem;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.episode-action-btn:hover {
    background: var(--border);
    color: var(--text);
}

.episode-action-btn.active {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

/* Completed Episode */
.episode-item.completed .episode-number {
    color: var(--success);
}

.episode-item.completed::before {
    content: '\f00c'; /* Font Awesome check icon */
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--success);
    font-size: 1.2rem;
}

/* ===== HISTORY LIST (Timeline Style) ===== */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    min-height: 50vh;
}

/* When history-list contains only empty-state, center it */
.history-list:has(.empty-state) {
    align-items: center;
    justify-content: center;
}

.history-date-group {
    margin-bottom: 1rem;
}

.history-date {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border);
}

/* ===== PLAYER MODAL ===== */
.player-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.98);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
}

.player-modal.active {
    display: flex;
}

.close-player {
    position: absolute;
    top: 1.5rem;
    left: 1.5rem;
    background: rgba(0, 0, 0, 0.7);
    border: none;
    color: #fff;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.5rem;
    z-index: 10000;
    transition: all var(--transition-fast);
    backdrop-filter: blur(10px);
}

.close-player:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

/* ===== LOADING SKELETON ===== */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--card-bg) 25%,
        var(--border) 50%,
        var(--card-bg) 75%
    );
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

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

.skeleton-topic-card {
    width: 100%;
    aspect-ratio: 16 / 9;
    border-radius: var(--card-radius);
}

.skeleton-episode {
    width: 100%;
    height: 120px;
    border-radius: var(--card-radius);
}

/* ===== EMPTY STATES ===== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-muted);
    min-height: 50vh;
    width: 100%;
    max-width: 100%;
    grid-column: 1 / -1; /* Span all columns if in a grid */
}

.empty-state i {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--text);
}

.empty-state p {
    font-size: 1rem;
}

/* ===== MOBILE RESPONSIVE ===== */

/* Large tablets and small desktops */
@media (max-width: 1200px) {
    .main-content {
        max-width: 100%;
        padding: 1.5rem;
        width: 100%;
    }

    .topics-grid {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
        gap: 1.5rem;
    }
}

/* Medium sized devices */
@media (max-width: 900px) {
    .topics-grid {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
        gap: 1.25rem;
    }
}

/* Tablets */
@media (max-width: 1024px) {
    .main-content {
        margin-right: 0;
        padding: 1.5rem;
        max-width: 100%;
        width: 100%;
    }

    .sidebar {
        transform: translateX(100%);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .sidebar-toggle {
        display: block;
    }

    .sidebar-overlay.active {
        display: block;
    }

    .topics-grid {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
        gap: 1.5rem;
    }

    .episode-item {
        flex-direction: column;
        gap: 1rem;
    }

    .episode-thumbnail {
        width: 100%;
    }

    .episode-actions {
        flex-direction: row;
        justify-content: flex-start;
    }

    .view-header h1 {
        font-size: 2.2rem;
    }

    .empty-state {
        min-height: 45vh;
        padding: 3.5rem 2rem;
    }

    .empty-state i {
        font-size: 3.75rem;
    }

    .empty-state h3 {
        font-size: 1.4rem;
    }

    .empty-state p {
        font-size: 0.98rem;
    }
}

/* Mobile landscape and small tablets */
@media (max-width: 768px) {
    .tv-container {
        padding-top: 120px; /* Increased for wrapped navbar */
    }

    .sidebar {
        top: 60px;
        width: 280px;
    }

    .main-content {
        padding: 1.25rem;
        max-width: 100%;
        width: 100%;
    }

    .view-header {
        padding: 0;
        margin-bottom: 1.5rem;
    }

    .view-header h1 {
        font-size: 1.8rem;
        line-height: 1.3;
        margin-bottom: 0.75rem;
    }

    .view-header p {
        font-size: 1rem;
        line-height: 1.5;
    }

    .topics-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
        padding: 0;
    }

    .topic-card-title {
        font-size: 1.2rem;
        line-height: 1.4;
    }

    .topic-card-description {
        font-size: 0.9rem;
        line-height: 1.5;
    }

    .episode-number {
        font-size: 1.2rem;
        min-width: 40px;
    }

    .episode-title {
        font-size: 1.1rem;
        line-height: 1.4;
    }

    .episode-description {
        font-size: 0.9rem;
        line-height: 1.5;
    }

    .episode-item {
        padding: 1.25rem;
    }

    .sidebar-btn {
        padding: 0.875rem 1.25rem;
        font-size: 0.95rem;
    }

    .empty-state {
        min-height: 40vh;
        padding: 3rem 1.5rem;
    }

    .empty-state i {
        font-size: 3.5rem;
    }

    .empty-state h3 {
        font-size: 1.3rem;
    }

    .empty-state p {
        font-size: 0.95rem;
    }
}

/* Mobile portrait */
@media (max-width: 480px) {
    .tv-container {
        padding-top: 140px; /* Extra space for wrapped navbar */
    }

    .main-content {
        padding: 1rem;
        max-width: 100%;
        width: 100%;
    }

    .view-header {
        padding: 0;
        margin-bottom: 1.25rem;
    }

    .view-header h1 {
        font-size: 1.5rem;
        line-height: 1.3;
        margin-bottom: 0.5rem;
    }

    .view-header p {
        font-size: 0.9rem;
        line-height: 1.4;
    }

    .topic-card-content {
        padding: 1rem;
    }

    .topic-card-title {
        font-size: 1.1rem;
        line-height: 1.3;
    }

    .topic-card-description {
        font-size: 0.85rem;
        line-height: 1.4;
        -webkit-line-clamp: 2;
    }

    .episode-item {
        padding: 1rem;
        gap: 0.75rem;
    }

    .episode-number {
        font-size: 1rem;
        min-width: 35px;
    }

    .episode-title {
        font-size: 1rem;
        line-height: 1.3;
    }

    .episode-description {
        font-size: 0.85rem;
        line-height: 1.4;
    }

    .episode-meta {
        font-size: 0.8rem;
        flex-wrap: wrap;
    }

    .back-btn {
        font-size: 0.9rem;
        padding: 0.6rem 1rem;
    }

    .sidebar {
        width: 100%;
        max-width: 320px;
    }

    .sidebar-title {
        font-size: 1.1rem;
    }

    .sidebar-btn {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
        gap: 0.75rem;
    }

    .empty-state {
        min-height: 35vh;
        padding: 2.5rem 1rem;
    }

    .empty-state i {
        font-size: 3rem;
    }

    .empty-state h3 {
        font-size: 1.2rem;
    }

    .empty-state p {
        font-size: 0.9rem;
    }
}

/* Very small mobile devices */
@media (max-width: 360px) {
    .tv-container {
        padding-top: 150px;
    }

    .main-content {
        padding: 0.75rem;
        max-width: 100%;
        width: 100%;
    }

    .view-header {
        margin-bottom: 1rem;
    }

    .view-header h1 {
        font-size: 1.3rem;
        line-height: 1.2;
        margin-bottom: 0.4rem;
    }

    .view-header p {
        font-size: 0.85rem;
        line-height: 1.3;
    }

    .topic-card-content {
        padding: 0.875rem;
    }

    .topic-card-title {
        font-size: 1rem;
        line-height: 1.3;
    }

    .topic-card-description {
        font-size: 0.8rem;
        line-height: 1.3;
        -webkit-line-clamp: 2;
    }

    .episode-item {
        padding: 0.75rem;
    }

    .episode-title {
        font-size: 0.95rem;
        line-height: 1.3;
    }

    .episode-description {
        font-size: 0.8rem;
        line-height: 1.3;
    }

    .sidebar-title {
        font-size: 1rem;
    }

    .sidebar-btn {
        padding: 0.65rem 0.875rem;
        font-size: 0.85rem;
        gap: 0.65rem;
    }

    .empty-state {
        min-height: 30vh;
        padding: 2rem 0.75rem;
    }

    .empty-state i {
        font-size: 2.5rem;
        margin-bottom: 0.75rem;
    }

    .empty-state h3 {
        font-size: 1.1rem;
        margin-bottom: 0.4rem;
    }

    .empty-state p {
        font-size: 0.85rem;
    }
}
