/* === 2. Horizontal Sub-Navigation === */
.page-sub-nav {
    background-color: var(--color-primary);
    border-top: 4px solid var(--color-secondary-dark);
    padding: 0;
    /* Removed side padding */
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    position: relative;
    /* For positioning the fade */
}

.page-sub-nav .container {
    display: flex;
    justify-content: flex-start;
    /* Aligns items to the left */
    align-items: center;
    max-width: 100% !important;
    /* Overrides default container width */
    margin: 0 auto;
    padding: 0 1rem;
    /* Padding on the sides of the scroll area */
    overflow-x: auto;
    -ms-overflow-style: none;
    /* IE and Edge */
    scrollbar-width: none;
    /* Firefox */
}

.page-sub-nav .container::-webkit-scrollbar {
    display: none;
}

.page-sub-nav a {
    color: var(--color-text-white);
    text-decoration: none;
    font-weight: 700;
    font-size: 0.9rem;
    text-transform: uppercase;
    padding: 1.25rem 1.5rem;
    transition: all 0.3s ease;
    border-bottom: 4px solid transparent;
    margin-bottom: -4px;
    white-space: nowrap;
    flex-shrink: 0;
}

.page-sub-nav a:hover {
    color: var(--color-white);
    background-color: rgba(255, 255, 255, 0.05);
}

.page-sub-nav a.active {
    color: var(--color-white);
    border-bottom-color: var(--color-secondary-dark);
}

/* --- Styles for the dropdown caret --- */
.racing-caret {
    margin-left: 0.5rem;
    transition: transform 0.3s ease;
}

/* --- Rotate caret when menu is open --- */
.page-sub-nav a.is-open .racing-caret {
    transform: rotate(180deg);
}


/* --- Racing Sub-Menu Styles --- */
.racing-sub-menu {
    background-color: #fff;
    border-bottom: 1px solid #ddd;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    padding: 0;
    position: relative;
    /* For positioning the fade */
    /* Hide by default */
    display: none;
}

/* --- Show menu when .is-open class is added by JS --- */
.racing-sub-menu.is-open {
    display: block;
}


.racing-sub-menu .container {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    max-width: 100% !important;
    margin: 0 auto;
    padding: 0 1rem;
    overflow-x: auto;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.racing-sub-menu .container::-webkit-scrollbar {
    display: none;
}

.racing-sub-menu a {
    color: var(--color-text-dark);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.85rem;
    padding: 0.8rem 1.25rem;
    transition: all 0.3s ease;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
    flex-shrink: 0;
}

.racing-sub-menu a:hover {
    color: var(--color-primary);
}

.racing-sub-menu a.active {
    color: var(--color-secondary-dark);
    border-bottom-color: var(--color-secondary-dark);
    font-weight: 700;
}


/* === 3. Page-Specific Content === */
.page-content {
    background-color: #f4f4f4;
    /* Light grey background for content */
    padding: 2.5rem 0;
}

.page-content .container {
    max-width: 90%;
    /* Let the content be wider */
    margin: 0 auto;
}

/* --- Race Title Bar --- */
.race-title-bar {
    display: flex;
    align-items: stretch;
    margin-bottom: 2rem;
    filter: drop-shadow(0 4px 3px rgba(0, 0, 0, 0.1));
}

.race-title {
    background-color: var(--color-primary);
    color: var(--color-white);
    font-weight: 700;
    font-size: 1.5rem;
    text-transform: uppercase;
    padding: 1.25rem 2.5rem;
    /* Angled on the right */
    clip-path: polygon(0 0, 100% 0, 90% 100%, 0% 100%);
    z-index: 2;
}

.race-date {
    background-color: var(--color-secondary-dark);
    color: var(--color-primary);
    font-weight: 700;
    font-size: 1.5rem;
    text-transform: uppercase;
    padding: 1.25rem 3rem 1.25rem 3.5rem;
    margin-left: -2.5rem;
    /* Overlap the title */
    /* Angled on both sides */
    clip-path: polygon(10% 0, 100% 0, 90% 100%, 0% 100%);
    z-index: 1;
}

/* --- Race Tabs --- */
.race-tabs {
    display: flex;
    flex-wrap: wrap;
    background-color: #ddd;
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
    border-bottom: 4px solid var(--color-secondary-dark);
    align-items: center;
}

.race-tabs-label {
    background-color: var(--color-primary);
    color: var(--color-white);
    font-weight: 700;
    font-size: 1rem;
    padding: 0.75rem 1.25rem;
    /* Match tab padding */
    margin-right: 1px;
    /* Separator */
    height: 100%;
    /* Fill height */
    display: flex;
    align-items: center;
    border-top-left-radius: 4px;
    /* Match container radius */
}


.race-tabs a {
    color: #444;
    text-decoration: none;
    font-weight: 700;
    font-size: 1rem;
    padding: 0.75rem 1.25rem;
    transition: all 0.2s ease;
    border-right: 1px solid #ccc;
}

.race-tabs a:hover {
    background-color: #eee;
}

.race-tabs a.active {
    background-color: var(--color-primary);
    color: var(--color-white);
}

.race-info-box {
    background-color: #ffffff;
    border-radius: 4px;
    padding: 1.5rem 1rem;
    /* Reduced padding */
    margin-bottom: 2rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    border: 1px solid #eee;
    /* Subtle border */

    /* 2-column flex layout */
    display: none;
    /* JS will change to 'flex' */
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1.5rem;
}

.race-info-text {
    flex: 3;
    /* Take more space */
    min-width: 300px;
}

.race-info-text h3 {
    color: var(--color-primary);
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0 0 0.75rem 0;
    /* Tighter margin */
    padding-bottom: 0;
    border-bottom: none;
    /* Removed border */
}

/* This new class styles each line of text */
.race-details-line {
    font-size: 0.95rem;
    color: var(--color-text-dark);
    margin-bottom: 0.3rem;
    /* Tighter line spacing */
    line-height: 1.5;
}

.race-info-track {
    flex: 1;
    /* Take less space */
    max-width: 250px;
    /* Max width for the image */
    min-width: 150px;
    background-color: #f9f9f9;
    border-radius: 4px;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    align-self: center;
    /* Center itself in the flex container */
}

.race-info-track img {
    width: 100%;
    height: auto;
    max-width: 100%;
}

/* --- Race Card Table --- */
.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-card-table {
    width: 100%;
    min-width: 1800px;
    /* Force scrolling on smaller screens */
    border-collapse: collapse;
}

.race-card-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-card-table tbody tr {
    transition: background-color 0.2s ease;
}

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

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

.race-card-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-card-table td strong {
    color: #000;
}

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

/* --- Base Silk Icon Style --- */
.silk-icon {
    display: inline-block;
    width: 20px;
    height: 20px;
    line-height: 20px;
    /* Vertically centers the number */
    text-align: center;
    border-radius: 3px;
    /* Rounded-square to match image */
    font-size: 0.75rem;
    font-weight: 700;
    vertical-align: middle;
    border: 1px solid rgba(0, 0, 0, 0.2);
    /* Subtle border */
    box-sizing: border-box;
    /* Include border in width/height */
}

/* --- Silk Icon Color Scheme --- */
.silk-1 {
    background-color: #D52B2B;
    color: #FFFFFF;
}

/* 1. Red */
.silk-2 {
    background-color: #FFFFFF;
    color: #000000;
}

/* 2. White */
.silk-3 {
    background-color: #3E4E88;
    color: #FFFFFF;
}

/* 3. Blue */
.silk-4 {
    background-color: #F0E548;
    color: #000000;
}

/* 4. Yellow */
.silk-5 {
    background-color: #52A84C;
    color: #FFFFFF;
}

/* 5. Green */
.silk-6 {
    background-color: #000000;
    color: #F0E548;
}

/* 6. Black w/ Gold */
.silk-7 {
    background-color: #F58233;
    color: #000000;
}

/* 7. Orange */
.silk-8 {
    background-color: #E58DC9;
    color: #000000;
}

/* 8. Pink */
.silk-9 {
    background-color: #40E0D0;
    color: #000000;
}

/* 9. Turquoise */
.silk-10 {
    background-color: #6A3F99;
    color: #FFFFFF;
}

/* 10. Purple */
.silk-11 {
    background-color: #9E9E9E;
    color: #D52B2B;
}

/* 11. Grey w/ Red */
.silk-12 {
    background-color: #BFEF56;
    color: #000000;
}

/* 12. Lime */
.silk-13 {
    background-color: #7B4F2F;
    color: #FFFFFF;
}

/* 13. Brown */
.silk-14 {
    background-color: #800000;
    color: #F0E548;
}

/* 14. Maroon w/ Yellow */
.silk-15 {
    background-color: #C3B091;
    color: #000000;
}

/* 15. Khaki */
.silk-16 {
    background-color: #ADD8E6;
    color: #D52B2B;
}

/* 16. Light Blue w/ Red */
.silk-17 {
    background-color: #000080;
    color: #FFFFFF;
}

/* 17. Navy */
.silk-18 {
    background-color: #228B22;
    color: #F0E548;
}

/* 18. Forest Green w/ Yellow */
.silk-19 {
    background-color: #002366;
    color: #D52B2B;
}

/* 19. Dark Royal Blue w/ Red */
.silk-20 {
    background-color: #FF00FF;
    color: #F0E548;
}

/* 20. Fuchsia w/ Yellow */
/* Add more classes as needed */


/* --- Legends Section Styles --- */
.race-legends {
    background-color: #ffffff;
    border-radius: 4px;
    padding: 1.5rem 2rem;
    margin-top: 2.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.race-legends h2 {
    color: var(--color-primary);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid #eee;
    padding-bottom: 1rem;
}

.race-legends h3 {
    color: #333;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 1rem;
    margin-bottom: 1rem;
}

.legends-grid {
    display: grid;
    /* Responsive grid: creates as many 250px columns as will fit */
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 0.75rem 1.5rem;
    /* Row and Column gap */
    margin-bottom: 1.5rem;
}

.legend-item {
    display: flex;
    font-size: 0.9rem;
}

.legend-item .code {
    font-weight: 700;
    color: #000;
    width: 170px;
    /* Fixed width for alignment */
    flex-shrink: 0;
    /* Prevents shrinking */
}

.legend-item .desc {
    color: #555;
}

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

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

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

    /* --- Set specific widths for columns (NOW 16 total) --- */

    /* 1. Silk Icon */
    .race-card-table th:nth-child(1),
    .race-card-table td:nth-child(1) {
        width: 3%;
        text-align: center;
    }

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

    /* 3. Last 5 Runs */
    .race-card-table th:nth-child(3),
    .race-card-table td:nth-child(3) {
        width: 5%;
    }

    /* 4. Horse Name */
    .race-card-table th:nth-child(4),
    .race-card-table td:nth-child(4) {
        width: 10%;
        /* CHANGED from 11% */
    }

    /* 5. Rtg */
    .race-card-table th:nth-child(5),
    .race-card-table td:nth-child(5) {
        width: 3%;
    }

    /* 6. EA */
    .race-card-table th:nth-child(6),
    .race-card-table td:nth-child(6) {
        width: 3%;
    }

    /* 7. Gears */
    .race-card-table th:nth-child(7),
    .race-card-table td:nth-child(7) {
        width: 5%;
    }

    /* 8. Jockey */
    .race-card-table th:nth-child(8),
    .race-card-table td:nth-child(8) {
        width: 9%;
        /* CHANGED from 10% */
    }

    /* 9. Wt */
    .race-card-table th:nth-child(9),
    .race-card-table td:nth-child(9) {
        width: 4%;
    }

    /* 10. Trainer */
    .race-card-table th:nth-child(10),
    .race-card-table td:nth-child(10) {
        width: 9%;
        /* CHANGED from 10% */
    }

    /* 11. Bar */
    .race-card-table th:nth-child(11),
    .race-card-table td:nth-child(11) {
        width: 3%;
    }

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

    /* 13. Sire */
    .race-card-table th:nth-child(13),
    .race-card-table td:nth-child(13) {
        width: 10%;
        /* CHANGED from 12% */
    }

    /* 14. Dam */
    .race-card-table th:nth-child(14),
    .race-card-table td:nth-child(14) {
        width: 10%;
        /* CHANGED from 12% */
    }

    /* 15. Owner */
    .race-card-table th:nth-child(15),
    .race-card-table td:nth-child(15) {
        width: 9%;
        /* CHANGED from 9% */
    }

    /* 16. Breeder --- ADDED --- */
    .race-card-table th:nth-child(16),
    .race-card-table td:nth-child(16) {
        width: 9%;
    }
}


/* --- Responsive for Table Section (Mobile) --- */
@media (max-width: 768px) {

    .page-sub-nav .container {
        padding: 0 0.5rem;
        /* Give a little space on the left */
    }

    /* --- ADDED: Fade effect for main sub-nav --- */
    .page-sub-nav::after {
        content: '';
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 40px;
        /* Width of the fade */
        background: linear-gradient(to left, var(--color-text-dark) 30%, transparent);
        pointer-events: none;
        /* Allows clicks to go through */
    }

    .page-sub-nav a {
        padding: 1rem 1rem;
        font-size: 0.8rem;
    }

    /* --- Mobile styles for Racing Sub-Menu --- */
    .racing-sub-menu .container {
        padding: 0 0.5rem;
    }

    /* --- ADDED: Fade effect for racing sub-menu --- */
    .racing-sub-menu::after {
        content: '';
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 40px;
        /* Width of the fade */
        background: linear-gradient(to left, #ffffff 30%, transparent);
        pointer-events: none;
        /* Allows clicks to go through */
    }

    .racing-sub-menu a {
        padding: 0.7rem 1rem;
        font-size: 0.8rem;
    }


    .page-content .container {
        max-width: 100%;
        padding: 0;
    }

    .race-title-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .race-title,
    .race-date {
        clip-path: none;
        /* Remove angles on mobile */
        margin-left: 0;
        width: 100%;
    }

    .race-date {
        padding-left: 2.5rem;
    }

    .race-tabs {
        border-radius: 0;
    }

    .race-tabs-label {
        font-size: 0.8rem;
        padding: 1rem 1rem;
        /* Match mobile tab padding */
        border-top-left-radius: 0;
        /* Match container */
    }

    .race-tabs a {
        padding: 1rem 1rem;
        font-size: 0.8rem;
    }

    /* --- ADDED: Mobile styles for Legends --- */
    .race-legends {
        border-radius: 0;
        /* Full width on mobile */
        padding: 1.5rem 1rem;
    }

    .race-legends h2 {
        font-size: 1.25rem;
    }

    .race-legends h3 {
        font-size: 0.9rem;
    }

    .legends-grid {
        /* Switch to a single column on small screens */
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .legend-item {
        font-size: 0.85rem;
    }

    .legend-item .code {
        width: 140px;
        /* Tighter width for mobile */
    }

    /* UPDATED: Mobile styles for info box */
    .race-info-box {
        flex-direction: column-reverse;
        /* Stack image *above* text */
        align-items: center;
        padding: 1rem;
    }

    .race-info-track {
        flex-basis: auto;
        /* Allow it to size naturally */
        width: 100%;
        max-width: 300px;
        /* Limit image size on mobile */
    }

    .race-info-text {
        width: 100%;
        text-align: center;
    }

    .race-info-text h3 {
        font-size: 1.25rem;
    }

    .race-details-line {
        font-size: 0.9rem;
    }
}