/* === 2. Horizontal Sub-Navigation === */
.page-sub-nav {
    background-color: var(--color-primary);
    border-top: 4px solid var(--color-secondary-dark);
    padding: 0;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    position: relative;
    /* Z-index to ensure arrows sit above content if needed */
    z-index: 50;
}

/* Wrapper to position arrows relative to the nav */
.scroll-nav-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

/* Navigation Arrows - Shared Styles */
.nav-arrow {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 40px;
    border: none;
    cursor: pointer;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease, background-color 0.3s ease;
    opacity: 0;
    /* Hidden by default, JS toggles this */
    pointer-events: none;
    /* Click-through when hidden */
    padding: 0;
    font-size: 1rem;
}

/* Show arrow state */
.nav-arrow.visible {
    opacity: 1;
    pointer-events: auto;
}

/* Main Nav (Dark) Arrow Specifics */
.page-sub-nav .nav-arrow {
    color: white;
    background: rgba(0, 0, 0, 0.2);
    /* Fallback */
}

.page-sub-nav .left-arrow {
    left: 0;
    background: linear-gradient(to right, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0.4) 60%, transparent 100%);
}

.page-sub-nav .right-arrow {
    right: 0;
    background: linear-gradient(to left, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0.4) 60%, transparent 100%);
}

.page-sub-nav .nav-arrow:hover {
    color: var(--color-secondary-dark);
}

.page-sub-nav .container {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    max-width: 100% !important;
    margin: 0 auto;
    /* Removed padding to let arrows sit flush, or keep minimal padding */
    padding: 0 2.5rem;
    /* Add padding so items aren't hidden under arrows at ends */
    overflow-x: auto;
    -ms-overflow-style: none;
    scrollbar-width: none;
    scroll-behavior: smooth;
    /* Smooth scrolling */
}

.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,
.betting-caret {
    margin-left: 0.5rem;
    transition: transform 0.3s ease;
}

/* --- Rotate caret when menu is open --- */
.page-sub-nav a.is-open .racing-caret,
.page-sub-nav a.is-open .betting-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;
    display: none;
    /* Hidden by default */
}

.racing-sub-menu.is-open {
    display: block;
}

/* Sub Menu (White) Arrow Specifics */
.racing-sub-menu .nav-arrow {
    color: var(--color-primary);
}

.racing-sub-menu .left-arrow {
    left: 0;
    background: linear-gradient(to right, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0.8) 50%, transparent 100%);
}

.racing-sub-menu .right-arrow {
    right: 0;
    background: linear-gradient(to left, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0.8) 50%, transparent 100%);
}

.racing-sub-menu .nav-arrow:hover {
    color: var(--color-secondary-dark);
}

.racing-sub-menu .container {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    max-width: 100% !important;
    margin: 0 auto;
    padding: 0 2.5rem;
    /* Padding to prevent content hiding behind arrows */
    overflow-x: auto;
    -ms-overflow-style: none;
    scrollbar-width: none;
    scroll-behavior: smooth;
}

.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;
    padding: 2.5rem 0;
}

.page-content .container {
    max-width: 98%;
    /* Expanded for maximum visibility on wide screens */
    margin: 0 auto;
}

/* --- Race Title Bar & Upcoming Nav --- */
.race-title-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 2rem;
    filter: drop-shadow(0 4px 3px rgba(0, 0, 0, 0.1));
    position: relative;
    z-index: 20; /* High enough to be above other content boxes */
}

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

.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;
    clip-path: polygon(10% 0, 100% 0, 90% 100%, 0% 100%);
    z-index: 1;
    height: 100%;
}

/* --- NEW: Upcoming Events Navigation --- */
.prev-results-nav {
    display: flex;
    align-items: center;
    margin: 0 1rem 0 auto;
}

.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;
    min-width: 200px;
}

.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);
}

/* --- Modern Race Tabs --- */
.race-tabs {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    background-color: #ffffff;
    border: 1px solid #e2e8f0;
    border-bottom: 2px solid #edf2f7;
    align-items: stretch;
    gap: 0;
    border-radius: 8px;
    margin-bottom: 2rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.race-tabs::-webkit-scrollbar {
    display: none;
}

.race-tabs-label {
    background-color: var(--color-primary);
    color: #ffffff;
    font-weight: 800;
    font-size: 0.7rem;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    flex-shrink: 0;
    border-radius: 7px 0 0 7px;
}

.race-tabs a {
    color: #475569;
    text-decoration: none;
    font-weight: 700;
    font-size: 1rem;
    padding: 1rem 2.25rem;
    transition: all 0.2s ease;
    background-color: transparent;
    position: relative;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
    border-right: 1px solid #f1f5f9;
}

.race-tabs a:last-child {
    border-right: none;
}

.race-tabs a:hover {
    color: var(--color-primary);
    background-color: #f8fafc;
}

.race-tabs a.active {
    background-color: var(--color-primary);
    /* background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%); */
    color: #ffffff;
    font-weight: 800;
    box-shadow: 0 4px 12px rgba(0, 78, 56, 0.2);
    z-index: 2;
}

.race-tabs a.active::after {
    display: none;
    /* Removed the line indicator as background is now primary */
}

.race-info-box {
    background: linear-gradient(135deg, #ffffff 0%, #f9fafb 100%);
    border-radius: 12px;
    padding: 2rem;
    margin-bottom: 2.5rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(0, 0, 0, 0.05);
    display: none;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 2rem;
    position: relative;
    overflow: hidden;
}

.race-info-box::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 6px;
    height: 100%;
    background-color: var(--color-primary);
}

.race-info-text {
    flex: 2;
    min-width: 300px;
}

.race-info-text h3 {
    color: var(--color-primary);
    font-size: 1.75rem;
    font-weight: 800;
    margin: 0 0 1rem 0;
    letter-spacing: -0.02em;
    text-transform: uppercase;
}

.race-details-line {
    font-size: 1rem;
    color: #4b5563;
    margin-bottom: 0.5rem;
    line-height: 1.6;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.race-details-line:last-child {
    margin-bottom: 0;
    font-weight: 600;
    color: var(--color-text-dark);
}

.race-info-track {
    flex: 0 0 200px;
    background-color: #fff;
    border-radius: 10px;
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
    border: 1px solid #edf2f7;
}

.race-info-track img {
    width: 100%;
    height: auto;
    max-height: 120px;
    object-fit: contain;
}

/* --- Race Card Table --- */
.table-wrapper {
    width: 100%;
    overflow-x: auto !important;
    /* Ensure scrolling is enabled */
    background-color: var(--color-white);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
    border-radius: 12px;
    border: 1px solid #edf2f7;
    position: relative;
    /* Custom scrollbar for better aesthetics */
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 #f1f5f9;
    -webkit-overflow-scrolling: touch;
    /* Smooth scroll on iOS */
    margin-bottom: 2rem;
}

.table-wrapper::-webkit-scrollbar {
    height: 8px;
}

.table-wrapper::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

.table-wrapper::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 4px;
    border: 2px solid #f1f5f9;
}

.race-card-table {
    width: 100%;
    min-width: 1400px;
    border-collapse: separate;
    border-spacing: 0;
}

/* UPDATED HEADER STYLES */
.race-card-table th {
    background: linear-gradient(to bottom, var(--color-primary), var(--color-primary-dark));
    color: var(--color-white);
    padding: 0.8rem 0.25rem;
    /* Minimized padding */
    text-align: left;
    font-size: 0.65rem;
    /* Smaller headers */
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.02em;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 10;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

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

/* Darker zebra striping for better contrast */
.race-card-table tbody tr:nth-child(even) {
    background-color: #f2f4f6;
}

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

/* Status styles for Scratched, DNF, Refused, DQ */
tr.is-scratched td:first-child *,
tr.is-scratched td:nth-child(2) *,
tr.is-scratched td:nth-child(3) *,
tr.is-refused td:first-child *,
tr.is-dq td:first-child * {
    text-decoration: none;
    color: #d9534f !important;
    font-weight: bold;
}

/* Apply strikethrough only to horse name cell (Column 4) */
tr.is-scratched td:nth-child(4),
tr.is-scratched td:nth-child(4) * {
    text-decoration: line-through;
    color: #d9534f !important;
    font-weight: bold;
}

tr.is-scratched {
    opacity: 0.6;
    background-color: #f8dbdc !important;
}

/* SCRATCHED Watermark overlay removed */

/* Other non-finishers are just faded/highlighted, NOT strikethrough */
tr.is-dnf,
tr.is-refused,
tr.is-dq {
    background-color: transparent !important;
}

tr.is-dnf td,
tr.is-refused td,
tr.is-dq td {
    text-decoration: none !important;
}

/* cell styles reverted to middle for professionalism */
.race-card-table td {
    padding: 0.6rem 0.5rem;
    font-size: 0.82rem;
    color: #1a1a1a;
    font-weight: 400;
    border-bottom: 1px solid #eef0f2;
    white-space: normal;
    word-break: break-word;
    vertical-align: middle;
    /* Reverted to middle */
    line-height: 1.3;
    font-feature-settings: "tnum";
    font-variant-numeric: tabular-nums;
    background-color: #fff;
}

/* Completely Hide EA Column */
.col-ea {
    display: none !important;
}

/* Sticky Column Logic for Horse Name & Numbers */
@media (min-width: 480px) {
    .col-no {
        position: sticky;
        left: 0;
        z-index: 5;
        background-color: #e8f5e9;
    }

    th.col-no {
        background-color: var(--color-primary);
        z-index: 11;
    }

    .col-horse {
        position: sticky;
        left: 65px;
        /* Offset by No column width */
        z-index: 5;
        background-color: #fff;
        box-shadow: 2px 0 5px -2px rgba(0, 0, 0, 0.1);
    }

    th.col-horse {
        background-color: var(--color-primary);
        z-index: 11;
    }
}

.col-hwt { width: 45px; text-align: center; }

/* Status badge for Scr at Gates (SG) */
.badge-sg {
    background-color: #d9534f;
    color: white;
    font-size: 0.6rem;
    padding: 1px 4px;
    border-radius: 3px;
    font-weight: 800;
    margin-left: 4px;
    vertical-align: middle;
    text-decoration: none !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    height: 14px;
    transform: translateY(-1px);
}

td.col-gears { background-color: #fffde7 !important; }
.race-card-table td.col-last5 { background-color: #e8f5e9 !important; }
.race-card-table td.col-wt { background-color: #e8f5e9 !important; }
.race-card-table td.col-desc { background-color: #fffde7 !important; }
.race-card-table td.col-pedigree { background-color: #fffde7 !important; }
.race-card-table td.col-ownership { background-color: #e8f5e9 !important; }
.race-card-table td.col-no { background-color: #e8f5e9 !important; }




.col-no {
    white-space: nowrap;
    text-align: left;
    padding-left: 0.75rem !important;
}

.col-no .silk-icon {
    margin-right: 0.4rem;
}

.horse-num {
    font-weight: 700;
    color: #4b5563;
}

.race-card-table td a {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 700;
    transition: all 0.2s;
}

/* Stacked Column Styling */
.stacked-col {
    padding: 0.5rem !important;
    vertical-align: top !important;
}

.stacked-info {
    font-size: 0.7rem;
    /* Even smaller for stacked info */
    line-height: 1.1;
    margin-bottom: 0.2rem;
    color: #333;
}

.stacked-info .label {
    font-weight: 700;
    color: var(--color-primary);
    display: inline-block;
    width: 14px;
    /* Narrower label */
    font-size: 0.65rem;
}

.stacked-info:last-child {
    margin-bottom: 0;
    border-top: 1px solid #f1f5f9;
    padding-top: 0.35rem;
}

.stacked-info .label {
    font-weight: 700;
    color: var(--color-primary);
    display: inline-block;
    width: 18px;
    font-size: 0.7rem;
}

.race-card-table td strong {
    color: #000;
    font-weight: 700;
}

.silk-icon {
    display: inline-block;
    width: 20px;
    height: 20px;
    line-height: 20px;
    text-align: center;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 700;
    vertical-align: middle;
    border: 1px solid rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
}

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

.silk-2 {
    background-color: #FFFFFF;
    color: #000000;
}

.silk-3 {
    background-color: #3E4E88;
    color: #FFFFFF;
}

.silk-4 {
    background-color: #F0E548;
    color: #000000;
}

.silk-5 {
    background-color: #52A84C;
    color: #FFFFFF;
}

.silk-6 {
    background-color: #000000;
    color: #F0E548;
}

.silk-7 {
    background-color: #F58233;
    color: #000000;
}

.silk-8 {
    background-color: #E58DC9;
    color: #000000;
}

.silk-9 {
    background-color: #40E0D0;
    color: #000000;
}

.silk-10 {
    background-color: #6A3F99;
    color: #FFFFFF;
}

.silk-11 {
    background-color: #9E9E9E;
    color: #D52B2B;
}

.silk-12 {
    background-color: #BFEF56;
    color: #000000;
}

.silk-13 {
    background-color: #7B4F2F;
    color: #FFFFFF;
}

.silk-14 {
    background-color: #800000;
    color: #F0E548;
}

.silk-15 {
    background-color: #C3B091;
    color: #000000;
}

.silk-16 {
    background-color: #ADD8E6;
    color: #D52B2B;
}

.silk-17 {
    background-color: #000080;
    color: #FFFFFF;
}

.silk-18 {
    background-color: #228B22;
    color: #F0E548;
}

.silk-19 {
    background-color: #002366;
    color: #D52B2B;
}

.silk-20 {
    background-color: #FF00FF;
    color: #F0E548;
}


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

.race-legends h2 {
    color: var(--color-primary);
    font-weight: 800;
    text-transform: uppercase;
    font-size: 1.5rem;
    margin-bottom: 2rem;
    border-bottom: 1px solid #edf2f7;
    padding-bottom: 1rem;
    letter-spacing: -0.01em;
}

.race-legends h3 {
    color: #4b5563;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.9rem;
    margin: 2rem 0 1rem 0;
    letter-spacing: 0.05em;
}

.legends-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem 2rem;
    background-color: #f8fafc;
    padding: 1.5rem;
    border-radius: 8px;
    border: 1px solid #f1f5f9;
}

.legend-item {
    display: flex;
    align-items: center;
    font-size: 0.85rem;
    line-height: 1.4;
}

.legend-item .code {
    font-weight: 700;
    color: var(--color-primary);
    width: 140px;
    flex-shrink: 0;
    font-size: 0.8rem;
    letter-spacing: 0.02em;
}

.legend-item .desc {
    color: #64748b;
    font-weight: 500;
}

/* --- Global Table Styling (Matches MMTCI Look) --- */
.race-card-table thead th {
    background-color: var(--color-primary);
    /* Carbon */
    color: white;
    border-bottom: 3px solid var(--color-primary);
    text-transform: uppercase;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 0.5rem 0.25rem;
    vertical-align: bottom;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
}

.race-card-table td {
    padding: 0.6rem 0.5rem;
    border-bottom: 1px solid #eee;
    color: #333;
    font-size: 0.85rem;
    vertical-align: middle;
}

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

    .race-card-table {
        table-layout: auto;
        /* Switch to auto to prevent forced squeezing */
        width: 100%;
    }

    /* Professional width distribution for 1920px */
    .col-no {
        width: 85px;
    }

    /* Fixed width for icon + num */
    .col-last5 {
        width: 90px;
    }

    .col-horse {
        width: 220px;
    }

    .col-rtg {
        width: 50px;
    }

    .col-gears {
        width: 90px;
    }

    .col-jockey {
        width: 140px;
    }

    .col-wt {
        width: 65px;
    }

    .col-trainer {
        width: 160px;
    }

    .col-bar {
        width: 50px;
    }

    .col-desc {
        width: 130px;
    }

    .col-pedigree {
        width: 250px;
    }

    .col-ownership {
        width: 300px;
    }

    /* Sticky logic for No & Horse with Auto layout */
    .col-no,
    .col-horse {
        background-color: #fff;
        z-index: 5;
    }
}


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

    .page-sub-nav .container {
        padding: 0 2rem;
        /* Keep padding for arrows on mobile too */
    }

    /* Remove the old CSS-only fade since we have dynamic arrows now, 
       OR keep it as a subtle fallback. I'll comment it out to prefer the arrows. */
    /* .page-sub-nav::after,
    .racing-sub-menu::after {
        display: none;
    }
    */

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

    .racing-sub-menu .container {
        padding: 0 2rem;
    }

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


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

    /* --- UPDATED RACE TITLE BAR FOR MOBILE --- */
    .race-title-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .race-title,
    .race-date {
        clip-path: none;
        margin-left: 0;
        width: 100%;
    }

    .race-date {
        padding-left: 2.5rem;
        order: 1;
        text-align: left;
    }

    .race-title {
        order: 0;
    }

    .prev-results-nav {
        order: 2;
        margin: 0.75rem 0 0.5rem 0;
        width: 100%;
        justify-content: space-between;
    }

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

    .race-tabs-label {
        font-size: 0.8rem;
        padding: 1rem 1rem;
        border-top-left-radius: 0;
    }

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

    .race-legends {
        border-radius: 0;
        padding: 1.5rem 1rem;
    }

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

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

    .legends-grid {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

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

    .legend-item .code {
        width: 140px;
    }

    .race-info-box {
        flex-direction: column-reverse;
        align-items: center;
        padding: 1rem;
    }

    .race-info-track {
        flex-basis: auto;
        width: 100%;
        max-width: 300px;
    }

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

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

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

/* Wrapper to position the button to the right */
.calendar-widget-wrapper {
    position: relative;
    margin-left: auto;
}

/* The Toggle Button */
.btn-calendar-toggle {
    background-color: var(--color-primary);
    color: var(--color-white);
    border: 1px solid var(--color-primary);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: background 0.2s;
    height: 38px;
}

.btn-calendar-toggle:hover {
    background-color: var(--color-green);
}

/* Floating Popover Container */
.calendar-popover {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 10px;
    width: 300px;
    background-color: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    z-index: 2000; /* Added highest priority */
    padding: 1rem;
}

.calendar-popover.hide {
    display: none;
}

/* Calendar Header (Month/Nav) */
.calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

#cal-month-year {
    font-weight: 700;
    color: var(--color-primary);
    text-transform: uppercase;
}

.cal-nav-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #666;
    font-size: 1rem;
    padding: 5px;
}

.cal-nav-btn:hover {
    color: var(--color-primary);
}

/* Grid System */
.calendar-days-header {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    text-align: center;
    font-size: 0.75rem;
    font-weight: 700;
    color: #999;
    margin-bottom: 0.5rem;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.cal-day {
    aspect-ratio: 1/1;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.9rem;
    color: #ccc;
    border-radius: 4px;
    cursor: default;
    position: relative;
}

/* Days that have race events */
.cal-day.has-event {
    color: var(--color-text-dark);
    background-color: #f0f8f0;
    cursor: pointer;
    font-weight: 600;
}

.cal-day.has-event:hover {
    background-color: var(--color-secondary);
    color: #000;
}

/* The currently selected event */
.cal-day.is-selected {
    background-color: var(--color-primary);
    color: #fff;
}

/* Indicator dot for events */
.cal-day.has-event::after {
    content: '';
    position: absolute;
    bottom: 4px;
    width: 4px;
    height: 4px;
    background-color: var(--color-green);
    border-radius: 50%;
}

.cal-day.is-selected::after {
    background-color: #fff;
}

/* Responsive Adjustment */
@media (max-width: 768px) {
    .calendar-widget-wrapper {
        width: 100%;
        margin-top: 10px;
    }

    .btn-calendar-toggle {
        width: 100%;
        justify-content: center;
    }

    .calendar-popover {
        width: 100%;
        right: 0;
        left: 0;
    }
}

/* --- Race Controls Group (Calendar + Quick Link) --- */

.race-controls-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

.btn-quick-link {
    background-color: var(--color-white);
    color: var(--color-primary);
    border: 1px solid var(--color-primary);
    padding: 0 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    height: 38px;
    transition: all 0.2s ease;
}

.btn-quick-link:hover {
    background-color: var(--color-primary);
    color: var(--color-white);
}

.calendar-widget-wrapper {
    margin-left: 0;
    position: relative;
}

@media (max-width: 768px) {
    .race-controls-wrapper {
        width: 100%;
        flex-direction: column;
        gap: 0.5rem;
        margin-top: 0.5rem;
    }

    .btn-quick-link,
    .calendar-widget-wrapper,
    .btn-calendar-toggle {
        width: 100%;
        justify-content: center;
    }

    .calendar-popover {
        width: 100%;
    }
}