.table-wrapper {
    width: 100%;
    overflow-x: auto;
    /* This makes the table scroll horizontally BY DEFAULT */
    background-color: var(--color-white);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.race-results-table {
    width: 100%;
    min-width: 1600px;
    /* Force scrolling on smaller screens */
    border-collapse: collapse;
}

.race-results-table th {
    background-color: var(--color-primary);
    color: var(--color-white);
    padding: 0.75rem 0.5rem;
    text-align: left;
    font-size: 0.8rem;
    text-transform: uppercase;
    font-weight: 700;
    white-space: nowrap;
}

.race-results-table tbody tr {
    transition: background-color 0.2s ease;
}

.race-results-table tbody tr:nth-child(even) {
    background-color: #f9f9f9;
}

.race-results-table tbody tr:hover {
    background-color: #f0f8ff;
    /* Light blue hover */
}

.race-results-table td {
    padding: 0.75rem 0.5rem;
    font-size: 0.85rem;
    color: var(--color-text-dark);
    border-bottom: 1px solid #eee;
    white-space: nowrap;
}

.race-results-table td strong {
    color: #000;
}

.race-results-table td a {
    color: var(--color-primary);
    text-decoration: none;
}

/*
 * Styles for scratched horses in race-results.css
 */
tr.is-scratched,
tr.is-refused {
    /* Fades out the entire row */
    opacity: 0.6;

    /* Adds a line-through to all text in the row */
    text-decoration: line-through;

    /* Optional: A neutral background. Use !important to override inline styles */
    background-color: #f8f8f8 !important;
}

/* * This keeps the "SCR" text itself clean:
 * - Removes the line-through
 * - Makes it red and bold so it stands out
 */
tr.is-scratched td:first-child strong,
tr.is-refused td:first-child strong {
    text-decoration: none;
    color: #d9534f;
    /* A shade of red */
    font-weight: bold;
}


tr.is-dnf {
    /* Fades out the entire row */
    opacity: 0.6;

    /* Adds a line-through to all text in the row */
    text-decoration: line-through;

    /* Optional: A neutral background. Use !important to override inline styles */
    background-color: #ffa2a5 !important;
}

/* --- Desktop Table Logic (1200px and up) --- */
@media (min-width: 1200px) {
    .table-wrapper {
        overflow-x: hidden;
        /* Disable horizontal scroll on desktop */
    }

    .race-results-table {
        table-layout: fixed;
        /* Force table to fit 100% width */
        min-width: 100%;
        /* Override the min-width */
    }

    .race-results-table th,
    .race-results-table td {
        white-space: normal;
        /* Allow text to wrap */
        word-break: break-word;
        /* Break long words */
    }

    /* --- Set specific widths for 14 columns --- */

    /* 1. Finish */
    .race-results-table th:nth-child(1),
    .race-results-table td:nth-child(1) {
        width: 5%;
    }

    /* 2. No */
    .race-results-table th:nth-child(2),
    .race-results-table td:nth-child(2) {
        width: 4%;
    }

    /* 3. Horse Name */
    .race-results-table th:nth-child(3),
    .race-results-table td:nth-child(3) {
        width: 15%;
    }

    /* 4. Rating */
    .race-results-table th:nth-child(4),
    .race-results-table td:nth-child(4) {
        width: 5%;
    }

    /* 5. Horse Wt */
    .race-results-table th:nth-child(5),
    .race-results-table td:nth-child(5) {
        width: 6%;
    }

    /* 6. Rider Wt */
    .race-results-table th:nth-child(6),
    .race-results-table td:nth-child(6) {
        width: 6%;
    }

    /* 7. Jockey */
    .race-results-table th:nth-child(7),
    .race-results-table td:nth-child(7) {
        width: 12%;
    }

    /* 8. Act Wt */
    .race-results-table th:nth-child(8),
    .race-results-table td:nth-child(8) {
        width: 6%;
    }

    /* 9. Trainer */
    .race-results-table th:nth-child(9),
    .race-results-table td:nth-child(9) {
        width: 12%;
    }

    /* 10. Bar */
    .race-results-table th:nth-child(10),
    .race-results-table td:nth-child(10) {
        width: 4%;
    }

    /* 11. 800m */
    .race-results-table th:nth-child(11),
    .race-results-table td:nth-child(11) {
        width: 5%;
    }

    /* 12. 400m */
    .race-results-table th:nth-child(12),
    .race-results-table td:nth-child(12) {
        width: 5%;
    }

    /* 13. Finish Time */
    .race-results-table th:nth-child(13),
    .race-results-table td:nth-child(13) {
        width: 8%;
    }

    /* 14. Margin */
    .race-results-table th:nth-child(14),
    .race-results-table td:nth-child(14) {
        width: 7%;
    }
}


/*
 * NEW RESPONSIVE STYLES
 */
@media (max-width: 768px) {
    .race-title-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .prev-results-nav {
        order: 2;
        /* Move it below the title */
        margin: 0.75rem 0 0.5rem 0;
        /* Adjust margin for mobile */
        width: 100%;
        min-width: 0;
    }

    .race-date {
        order: 1;
        /* Move date above the nav */
        text-align: left;
    }
}


/*
 * NEW STYLES FOR PREVIOUS RESULTS NAV
 */
.race-title-bar {
    display: flex;
    /* justify-content: space-between; <-- REMOVED */
    align-items: center;
    flex-wrap: wrap;
    /* Allow wrapping on small screens */
}

.prev-results-nav {
    display: flex;
    align-items: center;
    margin: 0 1rem 0 auto;
    /* <-- UPDATED: top right bottom left */
    /* Add some space */
    /* flex-grow: 1; <-- REMOVED */
    /* Allow it to take up space */
    /* min-width: 250px; <-- REMOVED */
    /* Prevent it from getting too small */
}

.prev-results-nav .form-control-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.9rem;
    border-radius: 0.25rem;
    border: 1px solid #ced4da;
    background-color: #fff;
    color: #495057;
    height: 38px;
    flex-grow: 1;
    /* Allow select to grow */
}

.prev-results-nav .btn-go {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    width: 38px;
    height: 38px;
    border: 1px solid var(--color-primary);
    background-color: var(--color-primary);
    color: var(--color-white);
    border-radius: 0.25rem;
    margin-left: 0.5rem;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.prev-results-nav .btn-go:hover {
    background-color: var(--color-primary-dark);
    border-color: var(--color-primary-dark);
}

/* ----------------------------------------------------
   NEW RACE INFO BOX STYLES (Grid Layout)
   ---------------------------------------------------- */

.race-info-box {
    display: flex;
    flex-direction: column;
    background-color: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.race-info-box.active {
    display: flex;
}

/* --- Top Row: Details & Track Image --- */
.race-info-top-row {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    justify-content: space-between;
    align-items: flex-start;
}

.race-info-text {
    flex: 1;
    min-width: 280px;
}

.race-info-track {
    flex: 0 0 auto;
    display: flex;
    justify-content: center;
}

/* --- Bottom Row: Media Section (CSS Grid) --- */
.race-media-section {
    display: grid;
    /* Creates equal width columns, auto-fitting available space */
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 20px;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #eee;
    width: 100%;
}

.race-media-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.media-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    font-weight: 700;
    color: #0A4D0A;
    /* Dark green */
    text-transform: uppercase;
}

/* --- Shared Media Container (Aspect Ratio Enforcement) --- */
.media-content-wrapper {
    position: relative;
    width: 100%;
    /* 16:9 Aspect Ratio (9 / 16 * 100 = 56.25%) */
    /* padding-bottom: 56.25%; */
    height: 400px;
    background-color: #000;
    border-radius: 6px;
    border: 1px solid #ddd;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    max-width: 600px;
    max-height: 400px;
}

/* Ensure contents fill the wrapper perfectly */
.media-content-wrapper iframe,
.media-content-wrapper video,
.media-content-wrapper img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* Keeps image looking good */
    border: 0;
    display: block;
}

/* Specific styling for Photo Finish overlay */
.photo-container {
    cursor: zoom-in;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.photo-container:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-color: var(--color-primary);
}

.pf-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    padding: 8px;
    text-align: center;
    font-size: 0.8rem;
    pointer-events: none;
    /* Let clicks pass through to container */
    backdrop-filter: blur(2px);
}

/* --- Photo Finish Zoom Modal --- */
.pf-modal {
    display: none;
    position: fixed;
    z-index: 2000;
    padding-top: 50px;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.9);
}

.pf-modal-content {
    margin: auto;
    display: block;
    max-width: 90%;
    max-height: 90vh;
    border-radius: 4px;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.2);
}

#pf-caption {
    margin: auto;
    display: block;
    width: 80%;
    max-width: 700px;
    text-align: center;
    color: #ccc;
    padding: 10px 0;
    height: 150px;
}

.pf-close {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    transition: 0.3s;
    cursor: pointer;
}

.pf-close:hover,
.pf-close:focus {
    color: #bbb;
    text-decoration: none;
    cursor: pointer;
}

/* Mobile Adjustments */
@media (max-width: 768px) {
    .race-media-section {
        grid-template-columns: 1fr;
        /* Stack vertically on mobile */
    }

    /* Force track image to center on its own line when wrapped */
    .race-info-top-row {
        justify-content: center;
    }
}