/* Shared styles for Race Finder applications */

/* ── GB Point-to-Point brand palette (gbpointing.co.uk) ─────────────── */
:root {
    --brand-navy: #0A2D4B;          /* primary: buttons, headers, headings */
    --brand-navy-dark: #082238;     /* hover for navy surfaces */
    --brand-red: #E6373C;           /* accent: key figures / highlights */
    --brand-border: #9BB9D2;        /* steel-blue borders */
    --brand-tint: #F0F7FD;          /* light hover background */
    --brand-disabled: #E6EAEC;      /* disabled background */
    --brand-disabled-text: rgba(10, 45, 75, 0.5);
}

body {
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    max-width: 1800px;
    margin: 0 auto;
    padding: 20px;
    background-color: #f0f0f0;
    color: #333;
}

/* Custom branded scrollbars (page, sidebar, table, modals) */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--brand-border) var(--brand-tint);
}

*::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

*::-webkit-scrollbar-track {
    background: var(--brand-tint);
    border-radius: 8px;
}

*::-webkit-scrollbar-thumb {
    background-color: var(--brand-border);
    border-radius: 8px;
    border: 3px solid var(--brand-tint);
}

*::-webkit-scrollbar-thumb:hover {
    background-color: var(--brand-navy);
}

*::-webkit-scrollbar-corner {
    background: var(--brand-tint);
}

h1, h2 {
    color: var(--brand-navy);
    text-align: center;
}

.control-panel, #results {
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

/* App shell: sticky controls sidebar + results main area */
.app-layout {
    display: flex;
    align-items: flex-start;
    gap: 20px;
    margin-bottom: 20px;
}

.sidebar {
    flex: 0 0 300px;
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: sticky;
    top: 20px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
}

.sidebar > :first-child {
    margin-top: 0;
}

.main-content {
    /* min-width: 0 lets the results table scroll horizontally inside the flex row */
    flex: 1 1 auto;
    min-width: 0;
}

input, button, select {
    margin: 10px 0;
    padding: 10px;
    border: 1px solid var(--brand-border);
    border-radius: 4px;
    font-size: 16px;
}

input, select {
    width: calc(100% - 22px);
}

button {
    background-color: var(--brand-navy);
    color: white;
    border: none;
    cursor: pointer;
    transition: background-color 0.3s;
}

button:hover {
    background-color: var(--brand-navy-dark);
}

button:disabled {
    background-color: var(--brand-disabled);
    color: var(--brand-disabled-text);
    cursor: not-allowed;
}

/* Full-width search bar */
.search-bar {
    display: flex;
    gap: 10px;
    align-items: center;
    background-color: #fff;
    padding: 16px 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

.search-bar #searchTerm {
    flex: 1 1 auto;
    box-sizing: border-box;
    width: auto;
    margin: 0;
}

#searchButton {
    flex: 0 0 auto;
    width: auto;
    margin: 0;
    padding: 10px 28px;
    background-color: var(--brand-navy);
}

#searchButton:hover {
    background-color: var(--brand-navy-dark);
}

/* Icon action buttons above the table (discrepancies, CSV) */
.icon-button {
    width: 42px;
    height: 42px;
    padding: 0;
    margin: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: #fff;
    color: var(--brand-navy);
    border: 1px solid var(--brand-border);
}

.icon-button:hover {
    background-color: var(--brand-tint);
}

.icon-button:disabled {
    background-color: var(--brand-disabled);
    color: var(--brand-disabled-text);
    border-color: var(--brand-border);
    cursor: not-allowed;
}

/* Labelled toolbar button — for non-obvious actions that need a written label */
.toolbar-button {
    width: auto;
    margin: 0;
    padding: 8px 14px;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

/* Discrepancies keeps its red accent so it stands out as a special action */
#discrepancyButton {
    background-color: var(--brand-red);
}

#discrepancyButton:hover {
    background-color: #c52a2f;
}

#fetchFeedButton {
    width: auto;
    margin: 0;
    padding: 6px 12px;
    font-size: 13px;
}

#localBaseYear, #equisoftLocalBaseYear {
    margin: 0;
    padding: 5px 8px;
    font-size: 13px;
}

/* Top header: title left, feed-status widget right */
.app-header {
    display: flex;
    align-items: center;
    gap: 12px 24px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.app-header h1 {
    margin: 0;
    text-align: left;
}

/* Feed-age widget sits at the far right; feed controls fill the gap between. */
.app-header .feed-status {
    margin-left: auto;
}

.feed-status {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    color: var(--brand-navy);
}

.feed-age {
    white-space: nowrap;
    color: #777;
}

.feed-age.has-feed {
    color: var(--brand-navy);
    font-weight: bold;
}

.feed-clear {
    width: auto;
    margin: 0;
    padding: 6px 12px;
    font-size: 13px;
    background-color: #fff;
    color: var(--brand-navy);
    border: 1px solid var(--brand-border);
}

.feed-clear:hover {
    background-color: var(--brand-tint);
}

.feed-clear i {
    margin-right: 5px;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-top: 20px;
}

th, td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #e0e0e0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: wrap;
    min-width: 50px;
}

td {
    font-size: 14px;
}

th {
    background-color: var(--brand-navy);
    color: white;
    font-weight: bold;
    cursor: pointer;
    position: relative;
    padding-right: 20px;
}

th:hover {
    background-color: var(--brand-navy-dark);
}

tr:nth-child(even) {
    background-color: #f8f8f8;
}

tr:hover {
    background-color: var(--brand-tint);
}

.result-count {
    font-weight: bold;
    color: var(--brand-navy);
    margin-bottom: 10px;
    font-size: 18px;
}

.notification {
    padding: 10px;
    margin: 10px 0;
    border-radius: 4px;
    text-align: center;
    font-weight: bold;
}

.notification.success {
    background-color: #d4edda;
    border: 1px solid #c3e6cb;
    color: #155724;
}

.notification.error {
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
}

.stats {
    background-color: #ecf0f1;
    padding: 15px;
    border-radius: 4px;
    margin-bottom: 20px;
}

.stats h3 {
    margin-top: 0;
    color: var(--brand-navy);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-top: 10px;
}

.stat-item {
    background-color: white;
    padding: 10px;
    border-radius: 4px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.stat-value {
    font-size: 24px;
    font-weight: bold;
    color: var(--brand-red);
}

.stat-label {
    font-size: 14px;
    color: #7f8c8d;
    margin-top: 5px;
}

.xml-download {
    margin-top: 20px;
    text-align: center;
}

.xml-download a {
    color: var(--brand-navy);
    text-decoration: none;
    font-weight: bold;
}

.xml-download a:hover {
    text-decoration: underline;
}

/* Column resizing */
.column-resizer, .resizer {
    position: absolute;
    top: 0;
    right: 0;
    width: 5px;
    height: 100%;
    cursor: col-resize;
    user-select: none;
}

.column-resizer:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

.resizer:hover,
.resizing {
    border-right: 2px solid var(--brand-navy);
}

/* Spinning animation for fetch button */
.spinning {
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Notification toast */
#notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background-color: var(--brand-navy);
    color: white;
    padding: 15px;
    border-radius: 5px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    display: none;
    z-index: 1000;
}

/* Column and filter selector styling */
#columnSelector, #filterSelector {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
}

.column-checkbox, .filter-checkbox {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 13px;
    color: #3c4858;
    cursor: pointer;
    padding: 4px 7px;
    margin: 0 -7px;                 /* bleed so hover aligns with the group edge */
    border-radius: 6px;
    line-height: 1.35;
    transition: background 0.1s ease, color 0.1s ease;
}

.column-checkbox:hover, .filter-checkbox:hover {
    background: var(--brand-tint);
    color: var(--brand-navy);
}

.column-checkbox input, .filter-checkbox input {
    width: auto;
    margin: 0;
    flex: none;
    accent-color: var(--brand-navy);
}

.column-selector {
    display: none;
    background-color: #f8f9fa;
    border: 1px solid var(--brand-border);
    border-radius: 4px;
    padding: 15px;
    margin-bottom: 20px;
}

.column-selector.show {
    display: block;
}

.column-selector h3 {
    margin-top: 0;
    color: var(--brand-navy);
}

.column-selector label {
    display: block;
    margin: 5px 0;
    cursor: pointer;
}

.column-selector input[type="checkbox"] {
    margin-right: 8px;
    width: auto;
}

.search-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
}

/* Collapsible accordion sections in the sidebar (crisp, card-like) */
.sidebar .accordion {
    border: 1px solid #e6ebf1;
    border-radius: 10px;
    margin-bottom: 12px;
    background: #fff;
    overflow: hidden;
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.sidebar .accordion[open] {
    border-color: #dbe3ec;
    box-shadow: 0 1px 2px rgba(10, 45, 75, 0.06), 0 6px 16px rgba(10, 45, 75, 0.05);
}

.sidebar .accordion > summary {
    list-style: none;
    cursor: pointer;
    padding: 13px 14px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.005em;
    color: var(--brand-navy);
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    user-select: none;
    transition: background 0.12s ease;
}

.sidebar .accordion > summary:hover {
    background: var(--brand-tint);
}

.sidebar .accordion > summary:focus-visible {
    outline: 2px solid var(--brand-red);
    outline-offset: -2px;
}

.sidebar .accordion[open] > summary {
    border-bottom: 1px solid #eef2f7;
}

.sidebar .accordion > summary::-webkit-details-marker {
    display: none;
}

/* Thin caret that rotates from "down" (closed) to "up" (open) */
.sidebar .accordion > summary::after {
    content: '';
    width: 7px;
    height: 7px;
    border-right: 2px solid #8a99ab;
    border-bottom: 2px solid #8a99ab;
    border-radius: 1px;
    transform: rotate(45deg);
    transition: transform 0.2s ease;
    flex: none;
    margin-top: -3px;
}

.sidebar .accordion[open] > summary::after {
    transform: rotate(-135deg);
    margin-top: 3px;
}

.sidebar .accordion-body {
    padding: 14px;
}

.sidebar .accordion-body #columnSelector,
.sidebar .accordion-body #filterSelector {
    margin-bottom: 0;
}

/* "XML feed" vs "REST API" groupings inside a selector */
.selector-group + .selector-group {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid #eef2f7;
}

.selector-group-title {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: #6b7a8d;
    margin-bottom: 9px;
}

/* Coloured dot encodes the data source: navy = XML, red = REST */
.selector-group-title::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--brand-border);
    flex: none;
}

.selector-group.is-xml .selector-group-title::before { background: var(--brand-navy); }
.selector-group.is-rest .selector-group-title::before { background: var(--brand-red); }

.selector-group-count {
    margin-left: auto;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0;
    color: #6b7a8d;
    background: var(--brand-tint);
    border: 1px solid #e6ebf1;
    border-radius: 10px;
    padding: 1px 8px;
}

.selector-group-items {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Collapsed sidebar: hide it and let the table take the full width */
.app-layout.sidebar-collapsed .sidebar {
    display: none;
}

/* Toolbar above the results table */
.results-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.sidebar-toggle {
    width: auto;
    margin: 0;
    padding: 8px 14px;
    font-size: 14px;
    background-color: #fff;
    color: var(--brand-navy);
    border: 1px solid var(--brand-border);
}

.sidebar-toggle:hover {
    background-color: var(--brand-tint);
}

.sidebar-toggle i {
    margin-right: 6px;
}

.feed-stats {
    font-size: 13px;
    color: #777;
}

.toolbar-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

/* Table / Map view switch */
.view-switch {
    display: inline-flex;
    border: 1px solid var(--brand-border);
    border-radius: 4px;
    overflow: hidden;
}

.view-btn {
    width: auto;
    margin: 0;
    border: none;
    border-radius: 0;
    padding: 8px 14px;
    font-size: 14px;
    background-color: #fff;
    color: var(--brand-navy);
}

.view-btn:hover {
    background-color: var(--brand-tint);
}

.view-btn.active {
    background-color: var(--brand-navy);
    color: #fff;
}

.view-btn i {
    margin-right: 6px;
}

/* Map view */
#mapContainer {
    height: 600px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    overflow: hidden;
    margin-bottom: 12px;
}

.map-info {
    font-size: 13px;
    color: #777;
    margin-bottom: 20px;
}

.map-controls {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 10px;
}

.map-date-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--brand-navy);
    font-weight: 500;
}

#mapMonthFilter, #mapDayFilter {
    width: auto;
    margin: 0;
    padding: 6px 10px;
    font-size: 14px;
}

.map-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    margin: 10px 0;
    font-size: 12px;
    color: #555;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
    border: 1px solid rgba(0,0,0,0.25);
}

.map-popup {
    min-width: 240px;
}

.map-popup strong {
    color: var(--brand-navy);
    font-size: 15px;
}

.map-popup-venue {
    font-size: 12px;
    color: #777;
    margin: 2px 0 4px;
}

.map-popup-fixture {
    font-weight: 600;
    color: var(--brand-navy);
    font-size: 13px;
    margin: 8px 0 2px;
}

.map-popup-date {
    font-weight: normal;
    color: #777;
    font-size: 12px;
}

.map-popup-races {
    margin: 0 0 4px;
    padding-left: 16px;
    max-height: 220px;
    overflow-y: auto;
}

.map-popup-races li {
    margin: 2px 0;
}

.map-popup-races a {
    color: var(--brand-navy);
}

/* Year-on-year compare */
.compare-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.compare-status {
    font-size: 13px;
    color: #777;
}

.compare-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 18px;
    font-size: 14px;
    color: var(--brand-navy);
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--brand-border);
}

.compare-hint {
    color: #777;
    font-size: 14px;
}

.compare-group {
    border: 1px solid var(--brand-border);
    border-radius: 6px;
    margin-bottom: 10px;
    overflow: hidden;
}

.compare-group > summary {
    list-style: none;
    cursor: pointer;
    padding: 10px 12px;
    background-color: var(--brand-tint);
    color: var(--brand-navy);
}

.compare-group > summary::-webkit-details-marker { display: none; }

.compare-dates {
    font-weight: normal;
    color: #777;
    font-size: 13px;
}

.compare-race {
    padding: 10px 12px;
    border-top: 1px solid #eee;
}

.compare-race-name {
    font-weight: 600;
    color: var(--brand-navy);
    font-size: 13px;
    margin-bottom: 6px;
}

.compare-badge {
    font-size: 11px;
    font-weight: bold;
    padding: 1px 7px;
    border-radius: 10px;
    margin-left: 4px;
}

.compare-badge.add { background-color: #d8f5dd; color: #1a7f37; }
.compare-badge.del { background-color: #ffe3e3; color: #b02a37; }

.compare-field { margin: 6px 0; }

.compare-field-name {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #888;
    margin-bottom: 2px;
}

.compare-diff {
    font-size: 14px;
    line-height: 1.5;
    color: #333;
    white-space: pre-wrap;
}

.compare-diff del { background-color: #ffe3e3; color: #b02a37; text-decoration: line-through; }
.compare-diff ins { background-color: #d8f5dd; color: #1a7f37; text-decoration: none; }

.compare-list { margin: 0; padding: 10px 12px 10px 30px; }
.compare-list li { margin: 4px 0; font-size: 14px; }

/* compare: file dropdown, search, race numbers, badges, remap */
.compare-toolbar { margin-bottom: 12px; }

.compare-search {
    box-sizing: border-box;
    width: 100%;
    max-width: 360px;
    margin: 0;
    padding: 7px 10px;
    font-size: 14px;
}

#compareFileSelect {
    width: auto;
    margin: 0;
    padding: 6px 10px;
    font-size: 14px;
}

.compare-or { color: #999; font-size: 13px; }

.compare-area { font-size: 12px; color: #777; font-weight: normal; }

.compare-num-changed { color: var(--brand-red); font-weight: normal; font-size: 12px; }

.compare-remap select { width: auto; margin: 0; padding: 3px 6px; font-size: 12px; }

.compare-race.unchanged { opacity: 0.65; }

.compare-badge.same { background-color: #eef1f4; color: #66707a; }
.compare-badge.chg { background-color: #fff3cd; color: #8a6d3b; }
.compare-badge.map { background-color: #e7f0ff; color: #1a4f8a; }

/* Loading indicator */
.loading-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 60px 20px;
    font-size: 18px;
    color: var(--brand-navy);
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.loading-indicator .fa-spinner {
    font-size: 22px;
}

/* Empty state for the results area */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 70px 20px;
    text-align: center;
    color: #888;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.empty-state i {
    font-size: 48px;
    color: var(--brand-border);
    margin-bottom: 8px;
}

.empty-state p {
    margin: 0;
    font-size: 18px;
    color: var(--brand-navy);
}

.empty-state .empty-state-hint {
    font-size: 14px;
    color: #888;
}

.inline-checkbox {
    display: flex;
    align-items: center;
    gap: 6px;
}

.inline-checkbox input {
    width: auto;
    margin: 0;
    accent-color: var(--brand-navy);
}

/* Table sorting indicators */
th::after {
    content: '\25B4';
    position: absolute;
    right: 5px;
    color: rgba(255,255,255,0.5);
}

th.sort-asc::after {
    content: '\25B4';
    color: white;
}

th.sort-desc::after {
    content: '\25BE';
    color: white;
}

/* Feed URL input styling */
#feedUrlInput {
    width: calc(100% - 110px);
    margin-right: 10px;
}

#feedUrlButton {
    width: 100px;
}

/* Table container (scrollable) */
.table-container {
    overflow-x: auto;
    overflow-y: auto;
    max-height: 800px;
}

table.resizable {
    width: max-content;
    min-width: 100%;
}

/* Fixture link styles */
.fixture-link {
    color: var(--brand-navy);
    text-decoration: none;
    font-weight: bold;
}

.fixture-link:hover {
    text-decoration: underline;
}

/* Secondary link to the public racecard, shown beside the fixture name */
.racecard-link {
    color: var(--brand-border);
    text-decoration: none;
    margin-left: 4px;
}

.racecard-link:hover {
    color: var(--brand-navy);
}

/* Pencil edit icon beside the fixture title */
.edit-link {
    color: var(--brand-border);
    text-decoration: none;
    margin-left: 4px;
}

.edit-link:hover {
    color: var(--brand-navy);
}

/* Expand icon before the race name (opens the preview popup) */
.preview-link {
    color: var(--brand-border);
    text-decoration: none;
    margin-right: 5px;
    font-size: 0.9em;
}

.preview-link:hover {
    color: var(--brand-navy);
}

/* Raw XML feed download — styled as a subtle pill */
.xml-download-link {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 14px;
    font-size: 13px;
    font-weight: 500;
    color: var(--brand-navy);
    background-color: #fff;
    border: 1px solid var(--brand-border);
    border-radius: 20px;
    text-decoration: none;
    transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}

.xml-download-link:hover {
    background-color: var(--brand-navy);
    color: #fff;
    border-color: var(--brand-navy);
}

/* Sticky table headers */
th.sticky {
    position: sticky;
    top: 0;
    border-bottom: 1px solid #e0e0e0;
}

/* Discrepancy report */
.discrepancy-report {
    margin-top: 10px;
}

.discrepancy-group {
    border: 1px solid var(--brand-border);
    border-radius: 6px;
    margin-bottom: 12px;
    background: #fff;
}

.discrepancy-group > summary {
    cursor: pointer;
    padding: 10px 12px;
    background: var(--brand-tint);
    border-radius: 6px;
    color: var(--brand-navy);
    font-size: 15px;
}

.discrepancy-field {
    padding: 8px 12px 12px;
    border-top: 1px solid #eef2f6;
}

.discrepancy-field-name {
    font-weight: bold;
    color: var(--brand-red);
    margin: 4px 0 8px;
}

.discrepancy-variant {
    border-left: 3px solid var(--brand-border);
    padding: 4px 0 4px 10px;
    margin: 0 0 8px;
}

.variant-meta {
    font-size: 12px;
    color: #5a6b7b;
    margin-bottom: 3px;
}

.variant-text {
    white-space: pre-wrap;
    font-size: 13px;
    color: #333;
}

.discrepancy-date {
    color: #7f8c8d;
}

/* Rows whose race carries an admin dispensation (special/penalties approval,
   hidden/added allowances, non-standard distance) */
tr.dispensation-row {
    background-color: #FFF6E6;
}

tr.dispensation-row td:first-child {
    border-left: 3px solid var(--brand-red);
}

tr.dispensation-row:hover {
    background-color: #FFE9C7;
}

/* Race Label lozenges — one colour per option (from the ACF race_label field).
   The base colour applies to any unmapped label; the per-option classes below
   override it. Class = lozenge-<slugified label>. */
.lozenge-cell { white-space: normal; }
.lozenge {
    display: inline-block;
    padding: 2px 9px;
    margin: 1px 2px 1px 0;
    border-radius: 11px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.7;
    color: #fff;
    background: #64748b; /* fallback for any new/unmapped label */
    white-space: nowrap;
}
.lozenge-classic               { background: #1d6fb8; }
.lozenge-adjacent              { background: #0f9b8e; }
.lozenge-keepers               { background: #7b4fb5; }
.lozenge-final                 { background: #c0392b; }
.lozenge-bha-rule-change       { background: #b45309; }
.lozenge-no-current-a-or-b-lic { background: #475569; }
.lozenge-distance              { background: #2e7d46; }

/* Drag-and-drop column reordering (header cells carry data-column) */
th[draggable="true"] { cursor: grab; }
th[draggable="true"]:active { cursor: grabbing; }
th.th-dragging { opacity: 0.45; }
th.th-dragover { box-shadow: inset 3px 0 0 0 var(--brand-red); }

/* Discrepancy report — race-type block headings */
.discrepancy-type {
    margin: 18px 0 8px;
    padding-bottom: 4px;
    border-bottom: 2px solid var(--brand-navy);
    color: var(--brand-navy);
    font-size: 17px;
}

.discrepancy-type-count {
    font-weight: normal;
    font-size: 13px;
    color: #7f8c8d;
}

/* Validation + spell-check reports */
.validation-report,
.spell-report {
    margin-top: 10px;
}

.validation-banner {
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 14px;
    border: 1px solid transparent;
}
.validation-banner.ok   { background: #e8f6ec; color: #1d6b34; border-color: #b6e0c2; }
.validation-banner.warn { background: #fff4e0; color: #8a5a00; border-color: #f3d59b; }
.validation-banner.err  { background: #fdeaea; color: #a11; border-color: #f3b6b6; }
.validation-banner.info { background: var(--brand-tint); color: var(--brand-navy); border-color: var(--brand-border); }

.validation-section {
    margin-bottom: 16px;
}
.validation-section > h3 {
    margin: 0 0 8px;
    padding-bottom: 4px;
    font-size: 15px;
    border-bottom: 2px solid var(--brand-navy);
    color: var(--brand-navy);
}
.validation-section.verrors > h3   { border-bottom-color: #c0392b; color: #a11; }
.validation-section.vwarnings > h3 { border-bottom-color: #d79a2b; color: #8a5a00; }
.vcount { font-weight: normal; font-size: 13px; color: #7f8c8d; }

.validation-item {
    border-left: 3px solid var(--brand-border);
    padding: 4px 0 6px 10px;
    margin: 0 0 8px;
}
.validation-section.verrors   .validation-item { border-left-color: #c0392b; }
.validation-section.vwarnings .validation-item { border-left-color: #d79a2b; }
.vmsg { font-size: 13px; color: #333; }
.vmult { color: #7f8c8d; font-size: 12px; }
.vloc { font-size: 12px; color: #5a6b7b; margin-top: 2px; }
.vsample {
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 12px;
    background: #f5f7fa;
    border: 1px solid #eef2f6;
    border-radius: 4px;
    padding: 3px 6px;
    margin-top: 4px;
    white-space: pre-wrap;
    word-break: break-word;
}

.spell-word {
    border: 1px solid var(--brand-border);
    border-radius: 6px;
    margin-bottom: 8px;
    background: #fff;
}
.spell-word > summary {
    cursor: pointer;
    padding: 8px 12px;
    background: var(--brand-tint);
    border-radius: 6px;
    color: var(--brand-navy);
    font-size: 14px;
}
.spell-suggest { color: #1d6b34; font-weight: 600; }
.spell-add {
    margin-left: 8px;
    padding: 1px 9px;
    font-size: 11px;
    font-weight: 600;
    border: 1px solid var(--brand-border);
    border-radius: 10px;
    background: #fff;
    color: var(--brand-navy);
    cursor: pointer;
}
.spell-add:hover { background: var(--brand-tint); border-color: var(--brand-navy); }
.spell-dict-footer {
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px solid #eef2f6;
    font-size: 13px;
    color: #5a6b7b;
}
.spell-export {
    margin-left: 8px;
    padding: 2px 10px;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid var(--brand-border);
    border-radius: 10px;
    background: #fff;
    color: var(--brand-navy);
    cursor: pointer;
}
.spell-export:hover:not(:disabled) { background: var(--brand-tint); border-color: var(--brand-navy); }
.spell-export:disabled { opacity: 0.5; cursor: default; }
.spell-export-box {
    width: 100%;
    box-sizing: border-box;
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 12px;
}
.spell-where {
    padding: 4px 12px;
    border-top: 1px solid #eef2f6;
    font-size: 12px;
}
.spell-loc { color: #5a6b7b; font-weight: 600; }
.spell-ctx { color: #333; }
.spell-where-more { padding: 4px 12px; font-size: 12px; color: #7f8c8d; }

/* Field-picker modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 45, 75, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal-box {
    background: #fff;
    border-radius: 8px;
    padding: 22px 24px;
    max-width: 460px;
    width: calc(100% - 40px);
    box-shadow: 0 8px 30px rgba(0,0,0,0.25);
}

.modal-box h3 {
    margin: 0 0 8px;
    color: var(--brand-navy);
}

.modal-intro {
    margin: 0 0 14px;
    font-size: 13px;
    color: #5a6b7b;
}

.modal-fields {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 18px;
}

.modal-field {
    font-size: 15px;
    color: #333;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.modal-actions button {
    width: auto;
    margin: 0;
    padding: 8px 16px;
}

.modal-cancel {
    background-color: #fff;
    color: var(--brand-navy);
    border: 1px solid var(--brand-border);
}

.modal-cancel:hover {
    background-color: var(--brand-tint);
}

/* Regex help: icon next to the checkbox + the examples popup */
.search-option-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.regex-help-link {
    color: var(--brand-border);
    text-decoration: none;
}

.regex-help-link:hover {
    color: var(--brand-navy);
}

.regex-help-intro {
    font-size: 13px;
    color: #555;
    margin: 0 0 14px;
}

.regex-help-list {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 7px 14px;
    align-items: baseline;
    font-size: 13px;
}

.regex-help-list .desc {
    color: #444;
}

.regex-help-list code,
.regex-help-tip code {
    background-color: var(--brand-tint);
    color: var(--brand-navy);
    padding: 1px 5px;
    border-radius: 3px;
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 12px;
    white-space: nowrap;
}

.regex-help-tip {
    font-size: 12px;
    color: #555;
    line-height: 2;
    margin: 16px 0 0;
    border-top: 1px solid #eee;
    padding-top: 12px;
}

/* Read-only info modal (race preview) */
.modal-box.info-modal {
    max-width: 640px;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
}

.modal-box.info-modal h3 {
    padding-right: 28px;
}

.modal-x {
    position: absolute;
    top: 8px;
    right: 12px;
    width: auto;
    margin: 0;
    padding: 0 6px;
    background: transparent;
    color: var(--brand-navy);
    border: none;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.modal-x:hover {
    background: transparent;
    color: var(--brand-red);
}

.modal-body {
    margin-bottom: 8px;
}

.rp-section {
    margin-bottom: 14px;
}

.rp-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: bold;
    color: var(--brand-navy);
    margin-bottom: 3px;
}

.rp-value {
    font-size: 14px;
    color: #333;
    line-height: 1.45;
    white-space: pre-wrap;
}

.rp-empty {
    color: #888;
}

.race-preview-link {
    color: var(--brand-navy);
    text-decoration: none;
    cursor: pointer;
}

.race-preview-link:hover {
    text-decoration: underline;
}

/* Feed source options styling */
/* Compact inline feed controls, sat in the header row */
.feed-source-options {
    display: flex;
    align-items: center;
    gap: 8px 18px;
    flex-wrap: wrap;
}

.feed-option {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
}

.feed-option-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: bold;
    color: var(--brand-navy);
    cursor: pointer;
    font-size: 13px;
}

.feed-option-label input[type="radio"] {
    margin: 0;
    width: auto;
}

.file-input-container {
    position: relative;
    display: inline-block;
}

#xmlFileInput {
    position: absolute;
    left: -9999px;
    opacity: 0;
}

.file-input-label {
    display: inline-block;
    padding: 6px 12px;
    background-color: var(--brand-navy);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: background-color 0.3s;
}

.file-input-label:hover {
    background-color: var(--brand-navy-dark);
}

.file-input-label i {
    margin-right: 6px;
}

/* Below this width the sidebar no longer fits beside the table — stack it on
   top and restore the original horizontal control layouts. */
@media (max-width: 900px) {
    .app-layout {
        flex-direction: column;
    }

    /* When stacked, the sidebar sits above the table at full width and the
       collapse toggle no longer applies. */
    .sidebar,
    .app-layout.sidebar-collapsed .sidebar {
        display: block;
        flex-basis: auto;
        width: auto;
        position: static;
        max-height: none;
        overflow-y: visible;
    }

    /* Use the extra horizontal width: lay the field/column lists out in rows. */
    .search-options,
    #columnSelector, #filterSelector {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 8px 16px;
    }

    /* The filters toggle is only useful beside the table, not when stacked. */
    .sidebar-toggle {
        display: none;
    }
}

/* Responsive design */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .control-panel, #results {
        padding: 15px;
    }

    th, td {
        padding: 8px 4px;
        font-size: 14px;
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        gap: 10px;
    }
}
