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

:root {
    --primary-color: #00D7B6;
    --secondary-color: #67696A;
    --text-color: #333;
    --bg-color: #f5f5f5;
    --card-bg: #ffffff;
    --border-color: #e0e0e0;
    --restricted-color: #e74c3c;
    --accessible-color: #27ae60;
    --unknown-color: #95a5a6;
}

body {
    font-family: 'Raleway', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    overflow-x: hidden;
    /* Prevent horizontal scroll "zoomed" effect */
    width: 100%;
}

html {
    overflow-x: hidden;
    width: 100%;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
header {
    background: linear-gradient(135deg, #000 0%, #333 100%);
    color: white;
    padding: 2rem 0;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

header h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

header h1 a {
    color: white;
    text-decoration: none;
}

header h1 a:hover {
    opacity: 0.9;
}

.logo-accent {
    color: #00d7b6;
}

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

.header-back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    background: rgba(255, 255, 255, 0.1);
    padding: 0.5rem;
    border-radius: 50%;
    transition: background-color 0.2s, transform 0.2s;
    width: 40px;
    height: 40px;
}

.header-back-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateX(-3px);
}

.header-titles {
    flex: 1;
}

.subtitle {
    font-size: 1rem;
    opacity: 0.9;
}

/* Main Content */
main {
    padding: 2rem 0;
}

/* Statistics Overview */
.stats-overview {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 3rem;
}

.stat-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    text-align: center;
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
}

.stat-value {
    font-size: 2.5rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.stat-label {
    font-size: 0.9rem;
    color: var(--secondary-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Charts Section */
.charts-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 2rem;
    margin-bottom: 3rem;
}

.chart-container {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.chart-container h2 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    color: var(--text-color);
}

.chart-container canvas {
    max-height: 300px;
}

/* Info Section */
.info-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
    margin-bottom: 3rem;
}

.info-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.info-card h3 {
    margin-bottom: 1rem;
    color: var(--text-color);
}

.info-card ul {
    list-style: none;
}

.info-card ul li {
    margin-bottom: 0.5rem;
}

.info-card a {
    color: var(--primary-color);
    text-decoration: none;
}

.info-card a:hover {
    text-decoration: underline;
}

/* Filters Section */
.filters-section {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    margin-bottom: 2rem;
    align-items: end;
    flex-direction: column;
    gap: 0;
}

/* Desktop: Hide button-based filters, show dropdowns */
.filter-segmented,
.filter-chips {
    display: none;
}

.clear-filters-btn {
    display: none;
}

/* Desktop: Show search wrapper (contains the input) */
.search-input-wrapper {
    display: block;
}

.search-input-wrapper input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.9rem;
}

.search-clear-btn {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    padding: 0.25rem;
    cursor: pointer;
    color: var(--secondary-color);
}

/* Desktop: Show original select dropdowns (override inline styles) */
.filter-group select,
.filter-group button#clear-filters {
    display: block !important;
}

.filter-group label {
    display: block;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    color: var(--secondary-color);
    font-weight: 500;
}

.filter-group label svg {
    display: none;
}

.filters-header {
    display: none;
    /* Hidden on desktop by default */
    width: 100%;
}

/* Base styles for filter elements (Desktop) */
.filters-container {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: end;
    width: 100%;
}

.filter-group {
    display: flex;
    flex-direction: column;
    min-width: 150px;
}

.filter-group label {
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    color: var(--secondary-color);
    font-weight: 500;
}

.filter-group input,
.filter-group select {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.9rem;
}

.filter-group button#clear-filters {
    padding: 0.5rem 1rem;
    background: var(--secondary-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
}

.filter-group button#clear-filters:hover {
    background: #555;
}

/* Table Section */
.table-section {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.table-info {
    margin-bottom: 1rem;
    font-weight: 500;
    color: var(--secondary-color);
}

.table-wrapper {
    overflow-x: auto;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1rem;
    gap: 1rem;
    font-size: 0.9rem;
    color: var(--secondary-color);
}

.pagination-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.pagination-left label {
    font-weight: 500;
}

.pagination-left select {
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    font-size: 0.9rem;
}

.pagination-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.pagination-right button {
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background: #fff;
    cursor: pointer;
    font-size: 0.85rem;
}

.pagination-right button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination-right button:hover:not(:disabled) {
    background: var(--bg-color);
}

.pagination-right #page-info {
    font-weight: 500;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background: var(--bg-color);
}

th {
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-color);
    border-bottom: 2px solid var(--border-color);
    cursor: pointer;
    user-select: none;
    position: relative;
}

th:hover {
    background: #f0f0f0;
}

.sort-indicator {
    margin-left: 0.5rem;
    opacity: 0.5;
}

th[data-sort-direction="asc"] .sort-indicator::after {
    content: " ▲";
    opacity: 1;
}

th[data-sort-direction="desc"] .sort-indicator::after {
    content: " ▼";
    opacity: 1;
}

td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

/* Hide Type column */
th[data-sort="type"],
td:nth-child(4) {
    display: none;
}

/* 
 * IMPORTANT: Column visibility rules
 * 
 * The table has 10 columns (see index.html and content.js for structure):
 * 1. Empty (expand button), 2. Image, 3. Title, 4. Type, 5. Age, 6. Languages,
 * 7. Duration, 8. Year, 9. Geo-Restriction, 10. Platform (LAST)
 * 
 * WARNING: If you use nth-child() selectors to hide/show columns, be careful!
 * The column order must match between HTML, JavaScript, and CSS.
 * 
 * Previously, we had: td:nth-child(10) { display: none; } to hide restriction_type.
 * This was removed because restriction_type column was removed and platform is now column 10.
 * If you need to hide a column in the future, update this comment and verify the column number.
 */

tbody tr:hover {
    background: var(--bg-color);
}

/* Expanded detail row under main content rows */
.detail-row td {
    padding: 0;
    border-bottom: none;
    background: #f9fafb;
}

.detail-container {
    display: flex;
    gap: 1.5rem;
    padding: 1rem 1.5rem 1.25rem 3.5rem;
    /* indent to align with title column */
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}

.detail-poster-wrapper {
    flex: 0 0 auto;
}

.detail-poster {
    /* Slightly larger than table thumbnail (60x40), but not a full poster */
    width: 100px;
    max-width: 20vw;
    height: auto;
    border-radius: 6px;
    object-fit: cover;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.detail-content {
    flex: 1 1 auto;
    font-size: 0.9rem;
    color: var(--secondary-color);
}

.detail-meta-line {
    margin-bottom: 0.25rem;
}

.detail-meta-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
}

.detail-media-type {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--secondary-color);
}

.detail-media-type svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
}

.detail-episode-info {
    font-weight: 600;
    color: var(--text-color);
}

.detail-genres {
    font-style: italic;
}

.detail-platforms .platform-badge {
    margin-top: 0.1rem;
}

.detail-description {
    margin-top: 0.5rem;
    white-space: pre-wrap;
    color: var(--text-color);
}

.status-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 500;
}

.status-restricted {
    background: #fee;
    color: var(--restricted-color);
}

.status-accessible {
    background: #efe;
    color: var(--accessible-color);
}

.status-unknown {
    background: #f5f5f5;
    color: var(--unknown-color);
}

/* Series and Episode Rows */
.series-row {
    background: #f8f9fa;
    font-weight: 600;
}

.series-row:hover {
    background: #e9ecef;
}

.episode-row {
    background: #fafafa;
}

.episode-row:hover {
    background: #f0f0f0;
}

.series-episode-count {
    font-size: 0.85rem;
    font-weight: normal;
    color: var(--secondary-color);
}

/* Expand/Collapse Toggle */
.expand-toggle {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    color: var(--text-color);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: background 0.2s;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.expand-toggle:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Thumbnail Cell */
.thumbnail-cell {
    text-align: center;
    padding: 0.5rem !important;
}

.thumbnail-img {
    width: 60px;
    height: 40px;
    object-fit: cover;
    border-radius: 4px;
    cursor: pointer;
    transition: transform 0.2s;
}

.thumbnail-img:hover {
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* Age Rating Badge */
.age-rating-badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
    background: #FFC23B;
    color: #000;
}

/* Language Badge */
.language-badge {
    display: inline-block;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 500;
    background: var(--primary-color);
    color: white;
    margin-right: 0.25rem;
}

/* Platform Badge */
.platform-badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    color: white;
    margin-right: 0.3rem;
    margin-bottom: 0.2rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.platform-badge-primeran {
    background: #1a1a1a;
    color: #ffffff;
}

.platform-badge-makusi {
    background: #00E676;
    color: #000000;
}

.platform-badge-etbon {
    background: #FF5722;
    color: #ffffff;
}

/* Expiration Badge */
.expiration-badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    background: #FF9800;
    color: #000000;
    margin-right: 0.3rem;
    margin-bottom: 0.2rem;
}

/* Content Link */
/* Content Link Button */
.detail-meta-line .content-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background-color: var(--primary-color);
    color: white;
    text-decoration: none;
    border-radius: 4px;
    font-weight: 600;
    transition: background-color 0.2s;
    margin-top: 0.5rem;
}

.detail-meta-line .content-link:hover {
    background-color: #00bfa2;
    text-decoration: none;
}

.external-link-icon {
    font-size: 0.9rem;
    opacity: 0.9;
}

.content-title-tooltip {
    cursor: help;
    border-bottom: 1px dotted var(--secondary-color);
}

/* Tooltip Styles */
[title] {
    position: relative;
}

/* Description tooltip enhancement */
.content-title-tooltip:hover::after {
    content: attr(title);
    position: absolute;
    left: 0;
    top: 100%;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 0.5rem;
    border-radius: 4px;
    font-size: 0.85rem;
    white-space: normal;
    max-width: 300px;
    z-index: 1000;
    margin-top: 0.25rem;
    pointer-events: none;
}

.loading {
    text-align: center;
    padding: 2rem;
    color: var(--secondary-color);
}

/* Footer */
footer {
    background: #333;
    color: white;
    padding: 2rem 0;
    margin-top: 3rem;
    text-align: center;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}


/* Default State for Mobile Filter Elements (Hidden on Desktop) */
.filter-modal-header,
.filter-modal-actions {
    display: none;
}

/* Desktop: filter-modal-body should not interfere with layout */
.filter-modal-body {
    display: contents; /* Unwrap on desktop so filter-groups display inline */
}

/* Responsive */
/* Responsive */
@media (max-width: 768px) {
    .charts-section {
        grid-template-columns: 1fr;
    }

    .stats-overview {
        grid-template-columns: repeat(2, 1fr);
    }

    .pagination {
        flex-direction: column;
        align-items: flex-start;
    }

    /* Filters Mobile Styles */
    .filters-section {
        padding: 1rem 1.5rem;
        /* Match header padding style */
        gap: 0;
    }

    .filters-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 0;
    }

    .mobile-results-info {
        font-weight: 600;
        font-size: 1.1rem;
        color: var(--text-color);
    }

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

    .icon-btn {
        background: none;
        border: none;
        padding: 0.5rem;
        cursor: pointer;
        color: var(--text-color);
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        transition: background-color 0.2s;
        /* Ensure good touch target */
        width: 44px;
        height: 44px;
    }

    .icon-btn:hover,
    .icon-btn:active {
        background-color: #f0f0f0;
    }

    .table-info {
        display: none;
        /* Hide desktop results count */
    }

    .filters-container {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100dvh;
        /* Use dvh for mobile viewport */
        min-height: 0;
        /* Allow flex scrolling */
        background-color: var(--card-bg);
        z-index: 2000;
        flex-direction: column;
        padding: 0;
        margin: 0;
        overflow-y: auto;
        overflow-x: hidden;
        /* Prevent horizontal scroll */
        overscroll-behavior: contain;
        /* Prevent scroll chaining to body */
        touch-action: pan-y;
        /* Allow vertical scrolling only */
        -webkit-overflow-scrolling: touch;
        /* Smooth iOS scrolling */
    }

    .filters-container.open {
        display: flex;
        animation: slideUp 0.3s ease-out;
    }

    @keyframes slideUp {
        from {
            transform: translateY(100%);
        }

        to {
            transform: none;
            /* Ensure no transform context remains */
        }
    }

    /* Mobile Filter Header */
    .filter-modal-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 1rem 1.5rem;
        border-bottom: 1px solid #eee;
        background: var(--card-bg);
        position: sticky;
        top: 0;
        z-index: 10;
    }

    .filter-modal-header h3 {
        margin: 0;
        font-size: 1.25rem;
    }

    .filter-modal-close {
        background: none;
        border: none;
        font-size: 2rem;
        line-height: 1;
        cursor: pointer;
        padding: 0 0.5rem;
        color: var(--text-color);
    }

    /* Mobile Filter Body - Scrollable Content Area */
    .filter-modal-body {
        display: block; /* Override display: contents from desktop */
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        /* Smooth iOS scrolling */
        overscroll-behavior: contain;
        /* Prevent scroll chaining */
        padding-bottom: 1rem;
        /* Extra space at bottom */
        width: 100%;
        max-width: 100%;
    }

    /* Mobile Filter Actions */
    .filter-modal-actions {
        display: block;
        padding: 1rem 1.5rem;
        border-top: 1px solid #eee;
        background: var(--card-bg);
        position: sticky;
        bottom: 0;
        margin-top: auto;
        /* Push to bottom if content is short */
        flex-shrink: 0;
        /* Prevent shrinking */
    }

    .filter-apply-btn {
        width: 100%;
        padding: 1rem;
        background-color: var(--primary-color);
        color: white;
        border: none;
        border-radius: 8px;
        font-size: 1.1rem;
        font-weight: bold;
        cursor: pointer;
    }

    /* Mobile: Show button-based filters, hide selects */
    .filter-segmented,
    .filter-chips,
    .clear-filters-btn {
        display: flex;
    }

    .filter-group select,
    .filter-group button#clear-filters {
        display: none !important;
    }

    /* Mobile: Style labels with icons */
    .filter-group label {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        font-size: 0.85rem;
        font-weight: 600;
        color: var(--text-color);
        margin-bottom: 0.75rem;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }

    .filter-group label svg {
        display: block;
        flex-shrink: 0;
        opacity: 0.7;
    }

    /* Mobile specific adjustment for filter groups inside modal */
    .filter-modal-body .filter-group {
        padding: 0 1.5rem;
        margin-bottom: 1.5rem;
        box-sizing: border-box;
        width: 100%;
        /* Ensure padding doesn't cause overflow */
    }

    /* Filter group labels with icons */
    .filter-modal-body .filter-group label {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        font-size: 0.85rem;
        font-weight: 600;
        color: var(--text-color);
        margin-bottom: 0.75rem;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }

    .filter-modal-body .filter-group label svg {
        flex-shrink: 0;
        opacity: 0.7;
    }

    /* Search Input Wrapper */
    .search-input-wrapper {
        position: relative;
        width: 100%;
    }

    .search-input-wrapper input {
        width: 100%;
        padding: 0.75rem 3rem 0.75rem 1rem;
        font-size: 1rem;
        border: 2px solid var(--border-color);
        border-radius: 8px;
        box-sizing: border-box;
        min-height: 48px;
    }

    .search-input-wrapper input:focus {
        outline: none;
        border-color: var(--primary-color);
    }

    .search-clear-btn {
        position: absolute;
        right: 0.5rem;
        top: 50%;
        transform: translateY(-50%);
        background: none;
        border: none;
        padding: 0.5rem;
        cursor: pointer;
        color: var(--secondary-color);
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        transition: background-color 0.2s;
    }

    .search-clear-btn:hover,
    .search-clear-btn:active {
        background-color: #f0f0f0;
    }

    /* Segmented Control (for exclusive selections) */
    .filter-segmented {
        display: flex;
        flex-wrap: nowrap;
        border: 2px solid var(--border-color);
        border-radius: 8px;
        overflow: hidden;
        background: white;
        width: 100%;
        padding: 0;
    }

    .filter-segmented-btn {
        flex: 1 1 0;
        min-width: 0;
        padding: 0.75rem 0.35rem;
        border: none;
        background: white;
        color: var(--text-color);
        font-size: 0.8rem;
        font-weight: 500;
        cursor: pointer;
        transition: none;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.25rem;
        min-height: 44px;
        border-right: 1px solid var(--border-color);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        -webkit-tap-highlight-color: transparent;
        box-sizing: border-box;
    }

    .filter-segmented-btn:last-child {
        border-right: none;
    }

    .filter-segmented-btn svg {
        flex-shrink: 0;
        width: 14px;
        height: 14px;
    }

    .filter-segmented-btn:active {
        transform: scale(0.98);
    }

    .filter-segmented-btn.active {
        background: var(--primary-color) !important;
        color: white !important;
        font-weight: 600;
        transition: none !important;
        margin: -2px 0;
        padding-top: calc(0.75rem + 2px);
        padding-bottom: calc(0.75rem + 2px);
        border-top: 2px solid transparent;
        border-bottom: 2px solid transparent;
    }

    /* Instant visual feedback on tap */
    .filter-segmented-btn:active:not(.active) {
        background: rgba(0, 215, 182, 0.2);
    }

    /* Platform-specific colors for segmented control */
    .filter-segmented-platforms .filter-segmented-btn[data-platform="primeran"].active {
        background: #1a1a1a !important;
        color: #ffffff !important;
        margin: -2px 0;
        padding-top: calc(0.75rem + 2px);
        padding-bottom: calc(0.75rem + 2px);
        border-top: 2px solid transparent;
        border-bottom: 2px solid transparent;
    }

    .filter-segmented-platforms .filter-segmented-btn[data-platform="makusi"].active {
        background: #00E676 !important;
        color: #000000 !important;
        margin: -2px 0;
        padding-top: calc(0.75rem + 2px);
        padding-bottom: calc(0.75rem + 2px);
        border-top: 2px solid transparent;
        border-bottom: 2px solid transparent;
    }

    .filter-segmented-platforms .filter-segmented-btn[data-platform="etbon"].active {
        background: #FF5722 !important;
        color: #ffffff !important;
        margin: -2px 0;
        padding-top: calc(0.75rem + 2px);
        padding-bottom: calc(0.75rem + 2px);
        border-top: 2px solid transparent;
        border-bottom: 2px solid transparent;
    }

    /* Filter Chips (for multi-select) */
    .filter-chips {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        width: 100%;
    }

    .filter-chip {
        padding: 0.5rem 1rem;
        border: 2px solid var(--border-color);
        border-radius: 20px;
        background: white;
        color: var(--text-color);
        font-size: 0.85rem;
        font-weight: 500;
        cursor: pointer;
        transition: none;
        display: inline-flex;
        align-items: center;
        gap: 0.35rem;
        min-height: 44px;
        white-space: nowrap;
        -webkit-tap-highlight-color: transparent;
    }

    .filter-chip svg {
        flex-shrink: 0;
    }

    .filter-chip:active {
        transform: scale(0.95);
    }

    .filter-chip.active {
        background: var(--primary-color) !important;
        color: white !important;
        border-color: var(--primary-color) !important;
        font-weight: 600;
    }

    /* Platform-specific chip colors when active */
    .filter-chip[data-platform="primeran.eus"].active {
        background: #1a1a1a;
        border-color: #1a1a1a;
        color: #ffffff;
    }

    .filter-chip[data-platform="makusi.eus"].active {
        background: #00E676;
        border-color: #00E676;
        color: #000000;
    }

    .filter-chip[data-platform="etbon.eus"].active {
        background: #FF5722;
        border-color: #FF5722;
        color: #ffffff;
    }

    /* Clear Filters Button */
    .clear-filters-btn {
        width: 100%;
        padding: 0.75rem 1rem;
        background: white;
        color: var(--secondary-color);
        border: 2px solid var(--border-color);
        border-radius: 8px;
        font-size: 0.95rem;
        font-weight: 600;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        min-height: 48px;
        transition: all 0.2s;
    }

    .clear-filters-btn:hover,
    .clear-filters-btn:active {
        background: #f5f5f5;
        border-color: var(--secondary-color);
    }

    .clear-filters-btn svg {
        flex-shrink: 0;
    }

    /* Apply Button Enhancement */
    .filter-apply-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
    }

    .filter-apply-btn svg {
        flex-shrink: 0;
    }

    /* First group margin */
    .filter-modal-body .filter-group:first-child {
        margin-top: 1.5rem;
    }

    .filter-group {
        width: 100%;
        min-width: 0;
        box-sizing: border-box;
        /* Prevent overflow from padding */
    }

    .filter-group input,
    .filter-group select {
        width: 100%;
        box-sizing: border-box;
    }

    .filter-group button {
        width: 100%;
        margin-top: 0.5rem;
    }

    /* Table Mobile "Card" View */
    table,
    thead,
    tbody,
    th,
    td,
    tr {
        display: block;
    }

    /* Hide table headers (but not display: none;, for accessibility) */
    thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    tr {
        margin-bottom: 1rem;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        background: var(--card-bg);
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
        position: relative;
        padding-bottom: 0.5rem;
        padding-left: 70px;
        /* Reserve space for vertical thumbnail column */
        min-height: 95px;
        /* Ensure minimal height for vertical thumbnail */
    }

    /* Hide expand toggle column as own row, make it absolute or handled differently if needed.
       For now, we'll keep it but float it or positon it. */
    td:first-child {
        position: absolute;
        top: 0.5rem;
        right: 0.5rem;
        border: none;
        padding: 0 !important;
        background: none;
        width: auto;
    }

    /* Thumbnail */
    /* Thumbnail - Absolute positioning for left column */
    .thumbnail-cell {
        display: block;
        position: absolute;
        left: 0;
        top: 0;
        width: 70px;
        height: 100%;
        padding: 0.5rem 0 0 0.5rem !important;
        border: none;
        text-align: left;
    }

    .thumbnail-img {
        width: 50px;
        height: 75px;
        /* Vertical poster aspect ratio (2:3) */
        object-fit: cover;
        border-radius: 4px;
    }

    td {
        /* Behave like a "row" */
        border: none;
        border-bottom: none;
        position: relative;
        padding: 0.25rem 1rem;
        text-align: left;
    }

    /* Title Row - Vertically centered with thumbnail */
    td:nth-child(3) {
        display: block;
        /* Changed from flex to block to allow proper text flow */
        font-size: 1rem;
        font-weight: 500;
        line-height: 1.4;
        padding-right: 3rem;
        /* Space for expand button */
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
        min-height: 75px;
        /* Match thumbnail height for proper centering */
        display: flex;
        align-items: flex-start;
        /* Align to top so text flows naturally */
        flex-direction: column;
        justify-content: center;
        /* Center content vertically */
    }

    /* Ensure series episode count is visible and not cut off */
    .series-episode-count {
        display: inline-block;
        white-space: nowrap;
    }

    /* Metadata rows - Group them */
    /* Metadata rows - Group them */
    /* Metadata rows - Group them */
    /* Hide secondary badges on mobile: Age(5), Lang(6), Geo(9), Platform(10) */
    td:nth-child(5),
    td:nth-child(6),
    td:nth-child(9),
    td:nth-child(10) {
        display: none !important;
    }

    /* Duration (7) and Year (8) - Style as concise meta line with separator */
    /* Only show for regular content rows, not series rows */
    tr:not(.series-row) td:nth-child(7),
    tr:not(.series-row) td:nth-child(8) {
        display: inline-block;
        padding: 0 0.35rem 0.5rem 0;
        font-size: 0.8rem;
        color: #999;
        /* Lighter gray for subtle hierarchy */
        width: auto;
        font-weight: 400;
    }

    /* Hide duration and year for series rows in mobile */
    tr.series-row td:nth-child(7),
    tr.series-row td:nth-child(8) {
        display: none !important;
    }

    /* Add bullet separator before Year */
    tr:not(.series-row) td:nth-child(8)::before {
        content: "•";
        margin-right: 0.35rem;
        color: #ccc;
        /* Even lighter for separator */
    }

    /* Clear fix for floated thumbnail */
    /* Clear fix removed as no floats are used */
    tr::after {
        content: none;
    }

    /* Detail Row adjustments */
    /* Detail Row adjustments */
    .detail-container {
        display: flex;
        flex-direction: column;
        padding: 1rem;
        gap: 1rem;
    }

    .detail-poster-wrapper {
        text-align: center;
        margin-bottom: 0.5rem;
    }

    .detail-poster {
        max-width: 100%;
        width: 150px;
        /* Force a reasonable size for the poster */
        border-radius: 8px;
        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
    }

    .detail-content {
        padding: 0 0.5rem;
    }

    .detail-description {
        font-size: 0.95rem;
        line-height: 1.5;
        color: var(--text-color);
    }

    .detail-row td {
        display: block;
        width: 100%;
        padding: 0;
    }



    /* Fix detail row specifically */
    tr.detail-row {
        padding-left: 0;
        min-height: auto;
        border-top: none;
        margin-top: -1rem;
        /* Connect to the row above */
        border-top-left-radius: 0;
        border-top-right-radius: 0;
        background: #fafafa;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        z-index: 1;
        /* Ensure it stays on top if needed */
    }
}

/* Mobile Full Screen Detail Modal */
.mobile-detail-modal {
    display: none;
    /* Hidden by default */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    max-width: 100vw;
    /* Strict constraint for Firefox */
    /* Use dvh to respect mobile address bars */
    height: 100dvh;
    z-index: 2000;
    background-color: #000;
    /* Layout: Flex column to manage header/content/footer */
    flex-direction: column;
    overflow: hidden;
    /* Frame itself never scrolls */
    touch-action: none;
    /* Prevent any touch actions on the modal backdrop from propagating */
}

.mobile-detail-modal.open {
    display: flex;
    /* IMPORTANT: Must be flex, not block, to enable flex-direction: column */
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: none;
        /* Clear transform to avoid stacking context issues */
    }
}

.mobile-detail-content {
    position: relative;
    display: flex;
    flex-direction: column;
    /* This area scrolls inside the fixed modal frame */
    flex: 1;
    min-height: 0;
    /* CRITICAL: Allows flex item to shrink below content size, enabling scrolling */
    overflow-y: auto;
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
    /* Strict constraint for Firefox */
    /* No bottom padding needed - actions section handles its own spacing */
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    /* Smooth momentum scrolling on iOS */
    overscroll-behavior: contain;
    /* CRITICAL: Prevents scroll chaining to parent/body */
    touch-action: pan-y;
    /* Allow vertical scrolling only, prevent other touch gestures from propagating */
}

/* Custom scrollbar for webkit browsers (optional, subtle) */
.mobile-detail-content::-webkit-scrollbar {
    width: 4px;
}

.mobile-detail-content::-webkit-scrollbar-track {
    background: transparent;
}

.mobile-detail-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

.mobile-detail-content::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

.mobile-detail-close {
    position: absolute;
    /* Absolute within the fixed modal frame = pinned to screen */
    top: 1rem;
    right: 1rem;
    z-index: 2010;
    background: rgba(0, 0, 0, 0.5);
    border: none;
    color: white;
    font-size: 2rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    backdrop-filter: blur(4px);
}

.mobile-detail-image-container {
    position: relative;
    width: 100%;
    /* Fixed height relative to viewport height, not content */
    height: 45vh;
    flex-shrink: 0;
}

.mobile-detail-poster {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.mobile-detail-gradient {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 80%;
    background: linear-gradient(to bottom, transparent 0%, #121212 90%);
    pointer-events: none;
}

.mobile-detail-info {
    position: relative;
    padding: 1.25rem;
    margin-top: -4rem;
    /* Overlap with gradient */
    background: #121212;
    /* Match dark theme bg */
    color: #e0e0e0;
    padding-bottom: 1rem;
    /* Reduced padding since actions are now inside */
    max-width: 100vw;
    box-sizing: border-box;
    flex-shrink: 0;
    /* Don't shrink, but don't grow either - natural size based on content */
}

#mobile-detail-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
    margin-bottom: 0.5rem;
    line-height: 1.2;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.mobile-detail-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    font-size: 0.85rem;
    color: #b0b0b0;
    margin-bottom: 1rem;
    align-items: center;
}

.mobile-detail-badges {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

#mobile-detail-description {
    font-size: 0.95rem;
    line-height: 1.5;
    color: #d0d0d0;
    margin-bottom: 1.5rem;
    /* Add margin for spacing before button */
    word-wrap: break-word;
    overflow-wrap: break-word;
}

#mobile-detail-actions {
    /* Now inside scrollable content, not fixed */
    width: 100%;
    padding: 1rem 1.25rem;
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
    /* Extra bottom padding for safe area */
    background: #121212;
    /* Maintain background for visual separation */
}

.mobile-content-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 1rem;
    background-color: var(--primary-color);
    color: white;
    font-weight: bold;
    text-decoration: none;
    border-radius: 8px;
    font-size: 1.1rem;
    gap: 0.5rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
}

.mobile-content-link:active {
    transform: scale(0.98);
}

/* Ensure no scrolling on body when modal is open */
body.modal-open {
    overflow: hidden;
    /* Standard overflow hidden */
    position: fixed;
    /* iOS Safari fix: position fixed prevents scrolling */
    width: 100%;
    /* Maintain width when position fixed */
    height: 100%;
    /* Maintain height */
    overscroll-behavior: none;
    /* Prevent pull-to-refresh and overscroll effects */
}

/* Mobile Navigation Buttons */
.mobile-nav-btn {
    position: absolute;
    /* Absolute within fixed modal */
    /* Use absolute to stay on screen even if modal contents scroll */
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    width: 40px;
    height: 60px;
    font-size: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2002;
    /* Above modal content */
    border-radius: 4px;
    transition: background 0.2s, opacity 0.3s ease-in-out;
    user-select: none;
    opacity: 1;
}

.mobile-nav-btn:hover {
    background: rgba(0, 0, 0, 0.8);
}

.mobile-nav-btn:disabled,
.mobile-nav-btn[disabled] {
    opacity: 0.3;
    pointer-events: none;
    cursor: default;
}

/* Auto-hide state for navigation buttons */
.mobile-nav-btn.nav-hidden {
    opacity: 0;
    pointer-events: none;
}

.mobile-nav-prev {
    left: 10px;
}

.mobile-nav-next {
    right: 10px;
}

/* Series Episode List Styles */
.series-episode-list {
    padding: 0 !important;
    margin: 0 !important;
}

.episode-list-container {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin-top: 1rem;
    background: #1a1a1a;
    border-radius: 8px;
    overflow: hidden;
}

.episode-season-header {
    padding: 0.75rem 1rem;
    background: #252525;
    color: var(--primary-color);
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--primary-color);
    position: sticky;
    top: 0;
    z-index: 1;
}

.episode-list-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: #1a1a1a;
    border-bottom: 1px solid #2a2a2a;
    cursor: pointer;
    transition: background 0.2s;
}

.episode-list-item:hover,
.episode-list-item:active {
    background: #252525;
}

.episode-list-item:last-child {
    border-bottom: none;
}

.episode-thumbnail {
    flex-shrink: 0;
    width: 80px;
    height: 45px;
    border-radius: 4px;
    overflow: hidden;
    background: #2a2a2a;
}

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

.episode-thumbnail-placeholder {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #2a2a2a 0%, #1a1a1a 100%);
}

.episode-info {
    flex: 1;
    min-width: 0;
}

.episode-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.episode-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--primary-color);
    text-transform: uppercase;
}

.episode-geo-badge {
    font-size: 0.7rem;
}

.episode-geo-badge.restricted {
    color: var(--restricted-color);
}

.episode-geo-badge.accessible {
    color: var(--accessible-color);
}

.episode-title {
    font-size: 0.9rem;
    font-weight: 500;
    color: #e0e0e0;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.episode-duration {
    font-size: 0.75rem;
    color: #999;
    margin-top: 0.15rem;
}

.episode-arrow {
    font-size: 1.5rem;
    color: #666;
    flex-shrink: 0;
}

.no-episodes {
    text-align: center;
    padding: 2rem;
    color: #999;
    font-style: italic;
}

@media (max-width: 768px) {

    /* Ensure modal handles the new buttons */

}