/* =================================
    CSS VARIABLES (Light & Dark Mode)
    ================================= */

:root {
    /* Light Mode */
    --body-background: #f8f8f8;
    --main-text-color: #333;
    --sidebar-border-color: #ccc;
    --sidebar-header-color: #333;
    --sidebar-link-color: #0066cc;
    --sidebar-link-hover-color: #005fa3;
    --sidebar-link-hover-background: #f0f8ff;
    --sidebar-link-selected-color: #004c87;
    --sidebar-link-selected-background: #e6f3ff;
    --collapsible-header-background: #f7f7f7;
    --collapsible-header-hover-background: #eee;
    --table-background: #fff;
    --table-text-color: #333;
    --table-border-color: #ddd;
    --table-header-background: #f2f2f2;
    --table-row-even-background: #fafafa;
    --status-linked-background: #405744; 
    --status-unlinked-background: #5f3e41; 
    --filter-tag-bg: #e9ecef;
    --filter-tag-color: #495057;
    --icon-button-color: #333;
    --table-row-hover-bg: #0000FF; 
    --table-row-hover-text: #FFFFFF; 

    /* Banner Variables - Light Mode */
    --banner-updating-bg: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%);
    --banner-updating-border: #ffc107;
    --banner-complete-bg: linear-gradient(135deg, #d4edda 0%, #c3e6cb 100%);
    --banner-complete-border: #28a745;
    --banner-text-color: #333;
}

/* Dark Mode - Activated by System Preference or Manual Toggle */
@media (prefers-color-scheme: dark) {
    :root {
        --body-background: #1a1a1a;
        --main-text-color: #e0e0e0;
        --sidebar-border-color: #444;
        --sidebar-header-color: #e0e0e0;
        --sidebar-link-color: #79a1d1;
        --sidebar-link-hover-color: #62707D;
        --sidebar-link-hover-background: #2a2a2a;
        --sidebar-link-selected-color: #79a1d1;
        --sidebar-link-selected-background: #333;
        --collapsible-header-background: #222;
        --collapsible-header-hover-background: #333;
        --table-background: #2a2a2a;
        --table-text-color: #e0e0e0;
        --table-border-color: #444;
        --table-header-background: #333;
        --table-row-even-background: #2a2a2a;
        --status-linked-background: #405744; 
        --status-unlinked-background: #5f3e41; 
        --icon-button-color: #fff;
        --table-row-hover-bg: #008000; 
        --table-row-hover-text: #FFFFFF; 

        /* Banner Variables - Dark Mode */
        --banner-updating-bg: linear-gradient(135deg, #4d3d1a 0%, #3a2e10 100%);
        --banner-updating-border: #ffc107;
        --banner-complete-bg: linear-gradient(135deg, #1e3d26 0%, #142819 100%);
        --banner-complete-border: #28a745;
        --banner-text-color: #e0e0e0;
    }
}

body[data-theme='dark'] {
    --body-background: #1a1a1a;
    --main-text-color: #e0e0e0;
    --sidebar-border-color: #444;
    --sidebar-header-color: #e0e0e0;
    --sidebar-link-color: #79a1d1;
    --sidebar-link-hover-color: #62707D;
    --sidebar-link-hover-background: #2a2a2a;
    --sidebar-link-selected-color: #79a1d1;
    --sidebar-link-selected-background: #333;
    --collapsible-header-background: #222;
    --collapsible-header-hover-background: #333;
    --table-background: #2a2a2a;
    --table-text-color: #e0e0e0;
    --table-border-color: #444;
    --table-header-background: #333;
    --table-row-even-background: #2a2a2a;
    --status-linked-background: #405744; 
    --status-unlinked-background: #5f3e41; 
    --table-row-hover-bg: #008000; 
    --table-row-hover-text: #FFFFFF; 

    /* Banner Variables - Manual Dark Toggle */
    --banner-updating-bg: linear-gradient(135deg, #4d3d1a 0%, #3a2e10 100%);
    --banner-updating-border: #ffc107;
    --banner-complete-bg: linear-gradient(135deg, #1e3d26 0%, #142819 100%);
    --banner-complete-border: #28a745;
    --banner-text-color: #e0e0e0;
}

/* =================================
    GENERAL STYLES & STRICT VERTICAL CONTAINMENT
    ================================= */
html, body {
    height: 100vh;
    width: 100vw;
    overflow: hidden; /* Prevents the whole browser page from scrolling */
    margin: 0;
    padding: 0;
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--body-background);
    color: var(--main-text-color);
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Main app parent container */
.game-content-wrapper {
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    padding: 0px 20px 20px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

/* Holds sidebar and primary visual area side-by-side */
.game-page {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    width: 100%;
    flex: 1;             /* Absorbs all remaining layout height dynamically */
    min-height: 0;       /* Critical layout anchor for child elements to scroll internally */
    box-sizing: border-box;
    overflow: hidden;        
}

#filter-slideout {
    width: 260px;
    flex-shrink: 0;
    overflow-y: auto;
    background-color: var(--table-background);
    border: 1px solid var(--sidebar-border-color);
    border-radius: 6px;
    padding: 15px;
    box-sizing: border-box;
    height: 100%;
}

.filter-section {
    margin-bottom: 18px;
    border-bottom: 1px solid var(--sidebar-border-color);
    padding-bottom: 12px;
}
.filter-section:last-of-type {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}
.filter-header {
    font-weight: 600;
    font-size: 14px;
    color: var(--sidebar-header-color);
    padding: 6px 8px;
    margin-bottom: 8px;
    background-color: var(--collapsible-header-background);
    border-radius: 4px;
}
.filter-links {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.filter-btn {
    padding: 6px 10px;
    border-radius: 4px;
    border: 1px solid transparent;
    background-color: transparent;
    color: var(--main-text-color);
    cursor: pointer;
    font-size: 0.85em;
    text-align: left;
    width: 100%;
    transition: background-color 0.2s ease, color 0.2s ease;
}
.filter-btn:hover {
    background-color: var(--sidebar-link-hover-background);
    color: var(--sidebar-link-hover-color);
}
.filter-btn.active {
    background-color: var(--sidebar-link-selected-background);
    color: var(--sidebar-link-selected-color);
    font-weight: bold;
    border-color: var(--sidebar-border-color);
}
.search-input {
    width: 100%;
    padding: 7px 14px;
    border: 1px solid var(--sidebar-border-color);
    border-radius: 4px;
    background-color: var(--table-background);
    color: var(--main-text-color);
    font-size: 0.9em;
    outline: none;
    transition: border-color 0.2s ease;
    box-sizing: border-box;
}
.search-input:focus { border-color: #3498db; }

/* The container panel to the right of the sidebar filter */
.main-content-area {
    flex: 1;
    min-width: 0;       /* Critical structural property: allows flex items to shrink correctly */
    display: flex;
    flex-direction: column;
    overflow: hidden;        
    height: 100%;
}

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin: 0 0 8px 0;
    width: 100%;
    flex-shrink: 0;
}
.toolbar-metrics {
    display: flex;
    align-items: center;
}
.filter-reset-btn {
    padding: 6px 14px;
    border-radius: 8px;
    border: 1px solid var(--sidebar-border-color);
    background-color: var(--table-header-background);
    color: var(--main-text-color);
    cursor: pointer;
    font-size: 0.85em;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}
.filter-reset-btn:hover { border-color: #3498db; color: #3498db; }

@media (max-width: 900px) {
    .game-page { flex-direction: column; overflow-y: auto; }
    #filter-slideout { width: 100%; height: auto; overflow-y: visible; flex-shrink: 0; }
    .main-content-area { height: auto; overflow: visible; }
    html, body, .game-content-wrapper { height: auto; overflow: auto; }
}

/* Structural Container Enclosures to safeguard horizontal scroll tracks */
.table-container {
    flex: 1;            /* Forces container to perfectly absorb screen height layout fragments */
    min-height: 0;       
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.table-wrapper {
    flex: 1;
    min-height: 0;
    width: 100%;
    max-width: 100%;
    overflow-y: auto !important; 
    overflow-x: auto !important; /* Force explicit horizontal viewport scroll channels */
    -webkit-overflow-scrolling: touch; 
    border: 1px solid var(--table-border-color);
    box-sizing: border-box;
}

/* =================================
    PLATFORM TABLE
    ================================= */
.platform-table {
    width: max-content !important;    /* Forces table to retain full required column lengths */
    min-width: 100% !important; 
    border-collapse: collapse;
    border-spacing: 0; 
    background-color: var(--table-background);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    color: var(--table-text-color);
    transition: background-color 0.3s ease, color 0.3s ease;
}

.platform-table th,
.platform-table td {
    border: 1px solid var(--table-border-color);
    padding: 10px 12px;
    text-align: left;
    vertical-align: middle;
    white-space: nowrap !important;  /* Locks content cells to single string lanes */
    overflow: visible !important;
    text-overflow: clip !important;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.platform-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: var(--table-header-background);
}

.platform-table tr:nth-child(even) {
    background-color: var(--table-row-even-background);
}

.platform-table th.generation,
.platform-table td.generation { width: 80px; }

.platform-table th.family,
.platform-table td.family { width: 120px; }

.platform-table th.device-type,
.platform-table td.device-type { width: 150px; }

.platform-table th.first-game,
.platform-table td.first-game,
.platform-table th.last-game,
.platform-table td.last-game {
    width: 75px;
    text-align: center;
}

.platform-table th.games,
.platform-table td.games {
    width: 45px;
    text-align: center;
}

.platform-table th.Status,
.platform-table td.Status {
    width: 45px;
    min-width: 45px;
}

.platform-table th.platform-id,
.platform-table td.platform-id {
    display: none;
}

/* === Slide-out Menu === */
.slideout-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 99;
    display: none;
    cursor: pointer;
}

.slideout-menu {
    position: fixed;
    top: 0;
    left: -350px; 
    width: 300px;
    max-width: 90%;
    height: 100%;
    background-color: var(--body-background);
    color: var(--main-text-color);
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.2);
    transition: left 0.3s ease-in-out;
    z-index: 100;
    display: flex;
    flex-direction: column;
}

.slideout-menu.active { left: 0; }

.slideout-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid var(--sidebar-border-color);
}

.slideout-menu-header h2 { margin: 0; font-size: 1.5em; }

.slideout-menu .close-btn {
    background: none;
    border: none;
    font-size: 2em;
    cursor: pointer;
    color: var(--main-text-color);
    line-height: 1;
    padding: 0;
}

.slideout-menu-content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px;
}

.sidebar-scroll-area { width: 100%; }

/* === Main Heading & Count === */
.main-heading-container {
    border-bottom: 2px solid var(--main-heading-border);
    padding-bottom: 10px;
    margin-bottom: 15px;
    margin-top: 80px; /* Aligns below the header.php navigation area */
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}
.main-heading-container h1 { margin: 0; font-size: 2em; }

.datfile-count {
    background-color: #0F9ED5;
    color: #FFFFFF;
    padding: 5px 10px;
    border-radius: 4px;
    font-weight: bold;
    white-space: nowrap;
    font-size: 14px;
}

/* === Main Search and Filter Sections === */
.filter-and-buttons-container {
    display: flex;
    align-items: center;
    gap: 10px; 
    margin-bottom: 20px;
}

/* Sort Indicators */
th.sortable {
    position: relative;
    padding-right: 25px; 
    cursor: pointer;
}

th.sortable::after {
    content: "⇅";
    position: absolute;
    right: 10px;
    font-size: 0.7em;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.3;
    transition: opacity 0.2s, transform 0.2s;
    line-height: 1; 
}

th.sortable:hover::after { opacity: 0.6; }

th.sortable[data-sort-direction="asc"]::after {
    opacity: 1;
    transform: translateY(-50%) rotate(180deg);
}

th.sortable[data-sort-direction="desc"]::after {
    opacity: 1;
    transform: translateY(-50%) rotate(0deg);
}

.intro-text {
    padding-bottom: 15px;
    width: 100%;
    max-width: 800px; 
    margin: 0; 
    flex-shrink: 0;
}

.disallowed-row {
    cursor: not-allowed !important;
    opacity: 0.6;
}

#active-filters-display {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.filter-tag,
.sort-tag {
    display: inline-block;
    padding: 5px 10px;
    margin-right: 10px;
    margin-bottom: 0;
    background-color: #FFEB3B;
    color: #000000;
    font-size: 14px;
    white-space: nowrap;
    border-radius: 4px;
    font-weight: bold;
}

.no-filter { color: black; }

.platform-table tbody tr:hover {
    background-color: var(--table-row-hover-bg);
    color: var(--table-row-hover-text);
    cursor: pointer;
}

.filter-buttons-container {
    display: flex;
    gap: 10px; 
}

.text-button {
    background-color: var(--table-header-background); 
    color: var(--main-text-color);
    border: 1px solid var(--sidebar-border-color);
    padding: 8px 16px;
    cursor: pointer;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.text-button:hover {
    background-color: var(--sidebar-link-hover-background);
    border-color: var(--sidebar-link-color);
    color: var(--sidebar-link-color);
}

.divider {
    width: 1px;
    height: 25px;
    background-color: var(--sidebar-border-color);
    margin: 0 10px;
}

/* =================================
    UPDATE STATUS BANNER STYLES
    ================================= */
.update-status-banner {
    margin: 10px 0 15px 0;
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    flex-shrink: 0;
}

.update-status-banner.updating {
    background: var(--banner-updating-bg);
    border-left: 5px solid var(--banner-updating-border);
}

.update-status-banner.complete {
    background: var(--banner-complete-bg);
    border-left: 5px solid var(--banner-complete-border);
}

.update-status-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.update-status-icon { font-size: 24px; flex-shrink: 0; }

.update-status-message {
    font-size: 16px;
    font-weight: 500;
    color: var(--banner-text-color);
    line-height: 1.5;
}