/* Badminton Historical Results — Frontend Styles */

/* ── Variables ──────────────────────────────────────────────────────────── */
:root {
    --bhr-table-bg:        #303582;
    --bhr-table-header-bg: #303582;
    --bhr-table-row-alt:   #2E327D;
    --bhr-table-hover:     #383D90;
    --bhr-table-open:      #383D90;
    --bhr-table-text:      #fff;
    --bhr-table-muted:     rgba(255,255,255,0.56);
    --bhr-table-border:    rgba(255,255,255,0.24);
    --bhr-primary:         #303582;
    --bhr-primary-hover:   #383D90;
    --bhr-secondary:       #C3996B;
    --bhr-grey-light:      #F7F8FB;
    --bhr-grey-border:     #E5E7EB;
    --bhr-grey-text:       #111827;
    --bhr-filter-width:    400px;
    --bhr-radius:          6px;
    --bhr-transition:      0.2s ease;
}

/* ── Page wrapper ───────────────────────────────────────────────────────── */

.bhr-page table tbody tr td {
    color: #fff
}

.bhr-page {
    font-family: 'Raleway', sans-serif;
    background: #F8F9FB;
    color: var(--bhr-grey-text);
    padding: 0 0 72px;
}

/* ── Inner wrapper ──────────────────────────────────────────────────────── */
.bhr-results-inner {
    width: 100%;
    max-width: 1040px;
    margin: 0 auto;
    padding: 46px 28px 0;
    box-sizing: border-box;
}

/* ── Stats row ──────────────────────────────────────────────────────────── */
.bhr-stats-row {
    display: flex;
    gap: 16px;
    padding: 0 0 30px;
    flex-wrap: wrap;
}

.bhr-stat-card {
    flex: 1;
    min-width: 0;
    min-height: 156px;
    background: #F3F4F8;
    border: 1px solid #EEF0F4;
    border-radius: 9px;
    padding: 28px 24px 22px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 11px;
    box-shadow: 0 1px 8px rgba(17,24,39,0.03);
    box-sizing: border-box;
}

.bhr-stat-icon {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bhr-stat-icon img {
    width: 42px;
    height: 42px;
    display: block;
}

.bhr-stat-number {
    font-size: 2.375rem;
    font-weight: 700;
    line-height: 1;
    color: var(--bhr-grey-text);
    letter-spacing: -0.02em;
}

.bhr-stat-label {
    font-size: 1.5rem;
    color: #8A8F9E;
    font-weight: 600;
    line-height: 1.35;
}

/* ── Content section ────────────────────────────────────────────────────── */
.bhr-content-section {
    padding: 0;
}

.bhr-section-title {
    font-size: 2.3125rem;
    font-weight: 700;
    color: var(--bhr-grey-text);
    margin: 0 0 13px;
    letter-spacing: -0.02em;
}

/* ── Toolbar (search + filters) ─────────────────────────────────────────── */
.bhr-toolbar {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 64px;
    flex-wrap: wrap;
}

.bhr-search-wrap {
    position: relative;
    flex: 0 1 300px;
    min-width: 240px;
    max-width: 300px;
    display: flex;
    align-items: center;
}

.bhr-search-wrap input[type="text"] {
    width: 100%;
    height: 39px;
    padding: 0 44px 0 18px;
    border: 1px solid #ECEFF4;
    border-radius: 20px;
    font-size: 1.3125rem;
    font-family: inherit;
    background: #fff;
    color: var(--bhr-grey-text);
    outline: none;
    box-sizing: border-box;
    transition: border-color var(--bhr-transition), box-shadow var(--bhr-transition);
}

.bhr-search-wrap input[type="text"]:focus {
    border-color: var(--bhr-primary);
    box-shadow: 0 0 0 3px rgba(27,40,72,0.1);
}

/* Filled circle search button on the right of the input */
.bhr-search-submit {
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    width: 29px;
    height: 29px;
    border-radius: 50%;
    background: var(--bhr-primary);
    border: none;
    cursor: pointer;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--bhr-transition);
    padding: 0;
}

.bhr-search-submit:hover {
    background: var(--bhr-primary-hover);
}

.bhr-search-clear {
    position: absolute;
    right: 42px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: #9CA3AF;
    padding: 4px;
    line-height: 1;
    display: flex;
    align-items: center;
}

.bhr-search-clear:hover {
    color: var(--bhr-grey-text);
}

.bhr-filters-btn {
    height: 39px;
    padding: 0 21px;
    border: 1px solid #ECEFF4;
    border-radius: 20px;
    background: #F3F4F9;
    color: var(--bhr-grey-text);
    font-size: 1.3125rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    transition: background var(--bhr-transition), color var(--bhr-transition), border-color var(--bhr-transition);
    position: relative;
}

.bhr-filters-btn:hover {
    border-color: var(--bhr-primary);
    background: var(--bhr-grey-light);
}

.bhr-filters-active-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--bhr-secondary);
    color: #fff;
    font-size: 1.125rem;
    font-weight: 700;
    position: absolute;
    top: -6px;
    right: -6px;
}

/* ── Table container ────────────────────────────────────────────────────── */
.bhr-table-container {
    position: relative;
    border-radius: 4px;
    overflow: hidden;
    margin: 0 0 24px;
    background: var(--bhr-table-bg);
    box-shadow: none;
}

.bhr-table-container.bhr-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.4);
    border-radius: var(--bhr-radius);
    z-index: 2;
}

/* ── Results table ──────────────────────────────────────────────────────── */
.bhr-results-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bhr-table-bg);
    color: var(--bhr-table-text);
    font-size: 1.3125rem;
    table-layout: auto;
}

.bhr-results-table thead tr {
    background: var(--bhr-table-header-bg);
}

.bhr-results-table th {
    padding: 25px 16px 18px;
    text-align: center;
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: 0;
    text-transform: none;
    color: rgba(255,255,255,0.88);
    border: 1.5px solid #fff;
    white-space: normal;
}

.bhr-results-table th.bhr-col-rider,
.bhr-results-table td.bhr-col-rider {
    text-align: left;
}

.bhr-results-table th.bhr-col-score {
    text-align: center;
}

.bhr-results-table th.bhr-col-result {
    text-align: center;
}

/* ── Table body rows ────────────────────────────────────────────────────── */
.bhr-result-row {
    transition: background var(--bhr-transition);
}

.bhr-result-row:nth-child(odd) {
    background: var(--bhr-table-bg);
}

.bhr-result-row:nth-child(even) {
    background: var(--bhr-table-row-alt);
}

.bhr-result-row:hover {
    background: var(--bhr-table-hover);
}

.bhr-result-row td {
    padding: 14px 16px;
    vertical-align: middle;
    border: 1.5px solid #fff;
}

/* ── Year column ────────────────────────────────────────────────────────── */
.bhr-col-year {
    width: 72px;
    white-space: nowrap;
}

.bhr-year {
    display: block;
    font-size: 1.3125rem;
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.01em;
}

/* ── Event column ───────────────────────────────────────────────────────── */
.bhr-col-event {
    min-width: 140px;
    text-align: left;
}

/* ── Rider/Horse column ─────────────────────────────────────────────────── */
.bhr-col-rider {
    min-width: 230px;
}

.bhr-rider-cell {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.bhr-rider-meta {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 24px;
    flex-shrink: 0;
    padding-top: 1px;
}

.bhr-rider-names {
    min-width: 0;
}

.bhr-rider-num {
    display: block;
    font-size: 1.3125rem;
    font-weight: 700;
    color: #fff;
    line-height: 1.2;
}

.bhr-flag {
    font-size: 1.4375rem;
    display: block;
    line-height: 1;
}

.bhr-rider-name {
    font-weight: 600;
    font-size: 1.3125rem;
    display: block;
    line-height: 1.3;
}

.bhr-horse-name {
    display: block;
    font-size: 1.125rem;
    margin-top: 4px;
    line-height: 1.3;
    font-style: italic;
}

/* ── Score columns ──────────────────────────────────────────────────────── */
.bhr-col-score {
    text-align: center;
    width: 118px;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    font-size: 1.3125rem;
    font-weight: 500;
}

/* ── Place column ───────────────────────────────────────────────────────── */
.bhr-col-place {
    text-align: center;
    width: 56px;
    white-space: nowrap;
    font-weight: 700;
    font-size: 1.3125rem;
    font-variant-numeric: tabular-nums;
}

/* ── Final result column ──────────────────────────────────────────────────── */
.bhr-col-result {
    text-align: center;
    min-width: 180px;
    width: 180px;
    font-weight: 700;
    font-size: 1.3125rem;
    white-space: normal;
    line-height: 1.35;
}

/* ── Flag tooltip ──────────────────────────────────────────────────────────── */
.bhr-flag--tooltip {
    position: relative;
    cursor: default;
}

.bhr-flag--tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 5px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.82);
    color: #fff;
    font-size: 1.125rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 3px 7px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 20;
}

.bhr-flag--tooltip:hover::after {
    opacity: 1;
}

/* Code-only display (no emoji flag) */
.bhr-flag--code {
    font-size: 1.0625rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    background: rgba(255,255,255,0.12);
    border-radius: 3px;
    padding: 1px 4px;
    line-height: 1.6;
}

.bhr-dnf-badge {
    font-size: 1.125rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: rgba(255,255,255,0.35);
    text-transform: uppercase;
}

/* ── DNF rows ───────────────────────────────────────────────────────────── */
.bhr-row--dnf .bhr-rider-name,
.bhr-row--dnf .bhr-year {
    opacity: 0.65;
}

/* ── Empty state ────────────────────────────────────────────────────────── */
.bhr-empty-state {
    background: var(--bhr-table-bg);
    padding: 64px 24px;
    text-align: center;
    color: var(--bhr-table-text);
    border-radius: var(--bhr-radius);
}

.bhr-empty-state svg {
    color: rgba(255,255,255,0.2);
    margin-bottom: 16px;
}

.bhr-empty-heading {
    font-size: 1.625rem;
    font-weight: 600;
    margin: 0 0 8px;
}

.bhr-empty-sub {
    font-size: 1.375rem;
    color: rgba(255,255,255,0.5);
    margin: 0 0 24px;
}

.bhr-reset-all {
    background: transparent;
    border: 1.5px solid rgba(255,255,255,0.35);
    color: #fff;
    border-radius: 24px;
    padding: 9px 22px;
    font-size: 1.3125rem;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: border-color var(--bhr-transition), background var(--bhr-transition);
}

.bhr-reset-all:hover {
    border-color: #fff;
    background: rgba(255,255,255,0.1);
}

/* ── Pagination ─────────────────────────────────────────────────────────── */
.bhr-pagination {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    padding: 17px 16px 21px;
    flex-wrap: wrap;
    background: var(--bhr-table-bg);
}

.bhr-page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    height: 30px;
    padding: 0 9px;
    border-radius: 50%;
    font-size: 1.25rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    background: transparent;
    color: #fff;
    border: 1px solid rgba(255,255,255,0.38);
    transition: background var(--bhr-transition), color var(--bhr-transition), border-color var(--bhr-transition);
    box-sizing: border-box;
}

.bhr-page-btn:hover {
    background: rgba(255,255,255,0.14);
    color: #fff;
    border-color: rgba(255,255,255,0.8);
    text-decoration: none;
}

.bhr-page-current {
    background: #fff;
    color: var(--bhr-primary);
    border-color: #fff;
    cursor: default;
}

.bhr-page-prev,
.bhr-page-next {
    width: auto;
    min-width: 0;
    height: 30px;
    padding: 0;
    border: 0;
    border-radius: 0;
    font-size: 1.25rem;
    background: transparent;
}

.bhr-page-ellipsis {
    display: inline-flex;
    align-items: center;
    padding: 0 6px;
    color: rgba(255,255,255,0.78);
    font-size: 1.3125rem;
    letter-spacing: 0.1em;
}

/* ── Filter Panel ───────────────────────────────────────────────────────── */
.bhr-filter-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--bhr-filter-width);
    max-width: 100vw;
    height: 100%;
    background: #fff;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    box-shadow: -6px 0 32px rgba(0,0,0,0.15);
    transform: translateX(0);
    transition: transform var(--bhr-transition);
}

.bhr-filter-panel[hidden] {
    display: none;
}

.bhr-filter-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--bhr-grey-border);
    flex-shrink: 0;
}

.bhr-filter-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--bhr-grey-text);
    margin: 0;
}

.bhr-filter-close {
    background: none;
    border: none;
    cursor: pointer;
    color: #9CA3AF;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    transition: color var(--bhr-transition), background var(--bhr-transition);
}

.bhr-filter-close:hover {
    color: var(--bhr-grey-text);
    background: var(--bhr-grey-light);
}

.bhr-filter-body {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

.bhr-filter-section {
    padding: 20px 24px;
    border-bottom: 1px solid var(--bhr-grey-border);
}

.bhr-filter-section-title {
    font-size: 1.3125rem;
    font-weight: 700;
    color: var(--bhr-grey-text);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin: 0 0 14px;
    display: block;
}

button.bhr-filter-section-title {
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    padding: 0;
    width: 100%;
    text-align: left;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.bhr-collapse-icon {
    transition: transform var(--bhr-transition);
    color: #9CA3AF;
}

button.bhr-filter-section-title[aria-expanded="false"] .bhr-collapse-icon {
    transform: rotate(-90deg);
}

/* ── Year range ─────────────────────────────────────────────────────────── */
.bhr-filter-section-label {
    font-size: 1.3125rem;
    font-weight: 700;
    color: var(--bhr-grey-text);
    letter-spacing: 0.03em;
    text-transform: uppercase;
    margin: 0 0 14px;
    display: block;
}

.bhr-year-range-labels {
    display: flex;
    justify-content: space-between;
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--bhr-grey-text);
    margin-bottom: 14px;
}

.bhr-range-slider-wrap {
    position: relative;
    height: 36px;
    display: flex;
    align-items: center;
}

.bhr-range-track {
    position: absolute;
    left: 0;
    right: 0;
    height: 4px;
    background: #E5E7EB;
    border-radius: 2px;
    pointer-events: none;
}

.bhr-range-fill {
    position: absolute;
    height: 100%;
    background: var(--bhr-primary);
    border-radius: 2px;
    left: 0;
    right: 0;
}

.bhr-range-input {
    position: absolute;
    width: 100%;
    height: 4px;
    background: transparent;
    -webkit-appearance: none;
    appearance: none;
    pointer-events: none;
    left: 0;
    margin: 0;
}

.bhr-range-input::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--bhr-primary);
    border: 3px solid #fff;
    box-shadow: 0 1px 6px rgba(0,0,0,0.2);
    cursor: pointer;
    pointer-events: all;
    transition: transform var(--bhr-transition);
}

.bhr-range-input::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.bhr-range-input::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--bhr-primary);
    border: 3px solid #fff;
    box-shadow: 0 1px 6px rgba(0,0,0,0.2);
    cursor: pointer;
    pointer-events: all;
}

/* ── Checkboxes + radios ────────────────────────────────────────────────── */
.bhr-checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 0;
    cursor: pointer;
    font-size: 1.4375rem;
    color: var(--bhr-grey-text);
    line-height: 1.3;
}

.bhr-checkbox-label input[type="checkbox"],
.bhr-checkbox-label input[type="radio"] {
    width: 17px;
    height: 17px;
    cursor: pointer;
    flex-shrink: 0;
    accent-color: var(--bhr-primary);
}

/* ── Country list ───────────────────────────────────────────────────────── */
.bhr-country-list {
    list-style: none;
    margin: 10px 0 0;
    padding: 0;
    max-height: 240px;
    overflow-y: auto;
}

.bhr-country-item {
    padding: 2px 0;
}

.bhr-country-flag {
    font-size: 1.625rem;
    line-height: 1;
    flex-shrink: 0;
}

.bhr-country-name {
    flex: 1;
}

/* ── Filter footer ──────────────────────────────────────────────────────── */
.bhr-filter-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--bhr-grey-border);
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 12px;
    flex-shrink: 0;
}

.bhr-filter-count {
    grid-column: 1 / -1;
    font-size: 1.3125rem;
    font-weight: 700;
    color: var(--bhr-grey-text);
    text-align: center;
    white-space: nowrap;
}

.bhr-filter-clear,
.bhr-filter-apply {
    height: 42px;
    padding: 0;
    border-radius: 24px;
    font-size: 1.375rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bhr-filter-clear {
    border: 1.5px solid var(--bhr-grey-border);
    background: transparent;
    color: var(--bhr-grey-text);
    font-weight: 600;
    transition: background var(--bhr-transition), border-color var(--bhr-transition);
}

.bhr-filter-clear:hover {
    background: var(--bhr-grey-light);
    border-color: var(--bhr-grey-text);
}

.bhr-filter-apply {
    border: none;
    background: var(--bhr-primary);
    color: #fff;
    transition: background var(--bhr-transition);
}

.bhr-filter-apply:hover {
    background: var(--bhr-primary-hover);
}

/* ── Overlay ────────────────────────────────────────────────────────────── */
.bhr-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 9998;
}

.bhr-overlay.is-visible {
    display: block;
}

/* ── Loading state ──────────────────────────────────────────────────────── */
#bhr-table-wrap {
    position: relative;
    transition: opacity var(--bhr-transition);
}

#bhr-table-wrap.bhr-loading {
    opacity: 0.5;
    pointer-events: none;
}

/* ── Error ──────────────────────────────────────────────────────────────── */
.bhr-error {
    background: var(--bhr-table-bg);
    color: #FCA5A5;
    padding: 24px;
    border-radius: var(--bhr-radius);
    text-align: center;
}

/* ── Screen reader only ─────────────────────────────────────────────────── */
.screen-reader-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(1px,1px,1px,1px);
    word-wrap: normal;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    /* Table scrolls horizontally — all columns remain visible */
    .bhr-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .bhr-results-table {
        min-width: 860px;
    }
}

@media (max-width: 768px) {
    .bhr-results-inner {
        padding-left: 20px;
        padding-right: 20px;
    }

    .bhr-stats-row {
        gap: 10px;
    }

    .bhr-stat-card {
        min-width: calc(33.333% - 7px);
        min-height: 118px;
        padding: 20px 16px 18px;
    }

    .bhr-toolbar {
        align-items: center;
        gap: 10px;
        margin-bottom: 42px;
    }

    .bhr-search-wrap {
        flex: 0 1 260px;
        min-width: 190px;
        max-width: 260px;
    }

    .bhr-filters-btn {
        justify-content: center;
    }

    /* Keep the full table layout — scroll horizontally instead */
    .bhr-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .bhr-results-table {
        min-width: 860px;
    }

    .bhr-filter-panel {
        width: 100%;
        max-width: 100vw;
    }
}

@media (max-width: 480px) {
    .bhr-results-inner {
        padding-left: 16px;
        padding-right: 16px;
    }

    .bhr-stat-card {
        min-width: 100%;
    }

    .bhr-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .bhr-search-wrap {
        max-width: 100%;
    }
}
