.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 {
    /* 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;
}

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: #ffb0ab !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 {
    text-decoration: none;
    color: #d9534f;
    /* A shade of red */
    font-weight: bold;
}

/* --- 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);
}