/**
 * Système visuel commun aux tableaux de résultats Hoopers Passion.
 *
 * Classes publiques :
 * - `.hp-results` délimite un classement complet ;
 * - `.hp-results-table` habille un tableau de résultats isolé ;
 * - `.hp-results-table__row--medal-yellow` représente une médaille jaune ;
 * - `.hp-results-table__row--medal-pink` représente une médaille rose.
 *
 * Les couleurs de médaille sont exclusivement pilotées par ces classes. Elles
 * ne dépendent jamais du rang : plusieurs lignes peuvent donc partager la même
 * couleur. Les tableaux Gutenberg existants placés dans un accordéon reçoivent
 * aussi la base visuelle, sans modifier leurs couleurs de lignes éditoriales.
 */
:root {
    --hp-results-cream: #f7f2e7;
    --hp-results-cream-light: #fffdf8;
    --hp-results-green-dark: #174f2a;
    --hp-results-green: #4d965e;
    --hp-results-green-light: #9bc59e;
    --hp-results-border: #d9d3c5;
    --hp-results-total: #eee7da;
    --hp-results-medal-yellow: #fff0bd;
    --hp-results-medal-pink: #f7d5dc;
}

/**
 * Accordéon Gutenberg principal qui contient un classement.
 *
 * `:has()` limite le style aux accordéons de résultats et évite d'altérer les
 * accordéons éditoriaux du reste du site.
 */
.entry-content .wp-block-accordion:has(.hp-results),
.entry-content .wp-block-accordion:has(table) {
    width: min(100%, 78rem);
    margin: 2.4rem auto;
}

.entry-content .wp-block-accordion:has(.hp-results) > .wp-block-accordion-item > .wp-block-accordion-heading,
.entry-content .wp-block-accordion:has(table) > .wp-block-accordion-item > .wp-block-accordion-heading {
    margin: 0;
}

.entry-content .wp-block-accordion:has(.hp-results) .wp-block-accordion-heading__toggle,
.entry-content .wp-block-accordion:has(table) .wp-block-accordion-heading__toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2rem;
    width: 100%;
    padding: 2rem 2.4rem;
    color: #ffffff;
    background: linear-gradient(120deg, #123e21, var(--hp-results-green-dark));
    border: 0;
    border-radius: 1rem;
    font-size: clamp(2rem, 2.5vw, 3rem);
    font-weight: 700;
    line-height: 1.2;
    text-align: left;
    text-decoration: none;
}

.entry-content .wp-block-accordion:has(.hp-results) .wp-block-accordion-heading__toggle[aria-expanded="true"],
.entry-content .wp-block-accordion:has(table) .wp-block-accordion-heading__toggle[aria-expanded="true"] {
    border-bottom-right-radius: 0;
    border-bottom-left-radius: 0;
}

.entry-content .wp-block-accordion:has(.hp-results) .wp-block-accordion-heading__toggle:hover,
.entry-content .wp-block-accordion:has(.hp-results) .wp-block-accordion-heading__toggle:focus,
.entry-content .wp-block-accordion:has(table) .wp-block-accordion-heading__toggle:hover,
.entry-content .wp-block-accordion:has(table) .wp-block-accordion-heading__toggle:focus {
    color: #ffffff;
    background: #216337;
    text-decoration: none;
}

.entry-content .wp-block-accordion:has(.hp-results) .wp-block-accordion-heading__toggle-title,
.entry-content .wp-block-accordion:has(table) .wp-block-accordion-heading__toggle-title {
    display: grid;
    gap: 0.25rem;
    text-decoration: none;
}

.hp-results-main-title {
    font-size: 1em;
    font-weight: 700;
}

.hp-results-main-title--mobile {
    display: none;
}

.hp-results-main-meta {
    font-size: 0.52em;
    font-weight: 400;
    line-height: 1.35;
}

/**
 * Le classement de compétition n'est pas toujours inséré dans un accordéon
 * Gutenberg. Cette variante autonome reprend le même déclencheur principal que
 * le RHC, sans coupler la présentation au point d'entrée API utilisé.
 */
.hp-results-main--standalone {
    width: min(100%, 78rem);
    margin: 2.4rem auto;
}

.hp-results-main__summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2rem;
    padding: 2rem 2.4rem;
    color: #ffffff;
    background: linear-gradient(120deg, #123e21, var(--hp-results-green-dark));
    border-radius: 1rem;
    cursor: pointer;
    font-size: clamp(2rem, 2.5vw, 3rem);
    font-weight: 700;
    line-height: 1.2;
    list-style: none;
}

.hp-results-main__summary::-webkit-details-marker {
    display: none;
}

.hp-results-main__summary:hover,
.hp-results-main__summary:focus {
    color: #ffffff;
    background: #216337;
    text-decoration: none;
}

.hp-results-main__heading {
    display: grid;
    gap: 0.25rem;
    min-width: 0;
}

.hp-results-main--standalone .hp-results-main-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hp-results-main__chevron::before {
    content: "\f347";
    color: #ffffff;
    font-family: dashicons !important;
    font-size: 3rem;
    line-height: 1;
}

.hp-results-main[open] > .hp-results-main__summary {
    border-bottom-right-radius: 0;
    border-bottom-left-radius: 0;
}

.hp-results-main[open] > .hp-results-main__summary .hp-results-main__chevron::before {
    content: "\f343";
}

.entry-content .wp-block-accordion:has(.hp-results) .wp-block-accordion-heading__toggle-icon,
.entry-content .wp-block-accordion:has(table) .wp-block-accordion-heading__toggle-icon {
    width: auto;
    height: auto;
    overflow: visible;
    color: transparent;
    font-family: dashicons !important;
    font-size: 0;
    text-decoration: none;
    transform: none !important;
}

.entry-content .wp-block-accordion:has(.hp-results) .wp-block-accordion-heading__toggle-icon::before,
.entry-content .wp-block-accordion:has(table) .wp-block-accordion-heading__toggle-icon::before {
    content: "\f347";
    color: #ffffff;
    font-family: dashicons !important;
    font-size: 3rem;
    line-height: 1;
}

.entry-content .wp-block-accordion:has(.hp-results) .wp-block-accordion-heading__toggle[aria-expanded="true"] .wp-block-accordion-heading__toggle-icon::before,
.entry-content .wp-block-accordion:has(table) .wp-block-accordion-heading__toggle[aria-expanded="true"] .wp-block-accordion-heading__toggle-icon::before {
    content: "\f343";
}

.hp-results {
    display: grid;
    gap: 0.8rem;
    width: 100%;
    margin: 0.8rem auto 0;
    padding: 0;
}

/**
 * Le titre de saison reste disponible aux technologies d'assistance sans
 * occuper une ligne fantôme dans la grille visuelle des classes.
 */
.hp-results > .screen-reader-text {
    position: absolute !important;
}

.hp-results-class {
    margin: 0;
    overflow: hidden;
    background: var(--hp-results-cream-light);
    border: 1px solid var(--hp-results-border);
    border-radius: 1rem;
}

.hp-results-class__summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2rem;
    padding: 1.25rem 1.8rem;
    color: #ffffff;
    background: linear-gradient(120deg, color-mix(in srgb, var(--hp-results-class-color, var(--hp-results-green)) 82%, #000000), var(--hp-results-class-color, var(--hp-results-green)));
    cursor: pointer;
    list-style: none;
    text-decoration: none;
}

.hp-results-class[open] .hp-results-class__summary {
    border-bottom-right-radius: 0;
    border-bottom-left-radius: 0;
}

.hp-results-class__summary::-webkit-details-marker {
    display: none;
}

.hp-results-class__summary:hover,
.hp-results-class__summary:focus {
    color: #ffffff;
    background: linear-gradient(120deg, color-mix(in srgb, var(--hp-results-class-color, var(--hp-results-green)) 72%, #000000), color-mix(in srgb, var(--hp-results-class-color, var(--hp-results-green)) 90%, #ffffff));
    text-decoration: none;
}

.hp-results-class__heading {
    display: grid;
    gap: 0.25rem;
    min-width: 0;
}

.hp-results-class__title {
    font-size: clamp(1.7rem, 1.8vw, 2.1rem);
    font-weight: 700;
    line-height: 1.15;
}

.hp-results-class__meta {
    font-size: 1.35rem;
    font-weight: 400;
    line-height: 1.35;
}

.hp-results-class__chevron::before {
    content: "\f347";
    color: #ffffff;
    font-family: dashicons !important;
    font-size: 3rem;
    line-height: 1;
}

.hp-results-class[open] .hp-results-class__chevron::before {
    content: "\f343";
}

.hp-results-class__content {
    padding: 1.8rem;
}

.hp-results-table-wrap,
.entry-content .wp-block-accordion:has(table) .wp-block-table {
    width: 100%;
    margin: 0;
    overflow-x: visible;
}

.hp-results-table,
.entry-content .wp-block-accordion:has(table) table {
    width: 100%;
    max-width: 100%;
    margin: 0;
    overflow: hidden;
    background: var(--hp-results-cream-light);
    border: 1px solid var(--hp-results-border);
    border-collapse: separate;
    border-spacing: 0;
    border-radius: 0.8rem;
    font-size: 1.4rem;
    font-variant-numeric: tabular-nums;
    line-height: 1.35;
    table-layout: fixed;
}

.hp-results-table th,
.hp-results-table td,
.entry-content .wp-block-accordion:has(table) table th,
.entry-content .wp-block-accordion:has(table) table td {
    padding: 1.3rem 1.5rem;
    border: 0;
    border-bottom: 1px solid var(--hp-results-border);
    text-align: left;
    vertical-align: middle;
    overflow-wrap: anywhere;
}

.hp-results-table thead th,
.entry-content .wp-block-accordion:has(table) table thead th {
    color: #132016;
    background: var(--hp-results-green-light);
    font-weight: 700;
}

.hp-results-table tbody tr:last-child > *,
.entry-content .wp-block-accordion:has(table) table tbody tr:last-child > * {
    border-bottom: 0;
}

/**
 * Les anciens tableaux de compétition utilisent parfois la variante rayée de
 * Gutenberg. Le système de résultats neutralise ce zébrage historique afin
 * que leurs lignes neutres aient le même fond que celles du RHC. Les couleurs
 * de médaille, appliquées directement aux cellules par les classes dédiées,
 * conservent leur priorité.
 */
.entry-content .wp-block-accordion:has(table) .wp-block-table.is-style-stripes tbody tr:nth-child(odd) {
    background: transparent;
}

.hp-results-table .hp-results-table__rank,
.hp-results-table thead th:first-child {
    width: 8%;
    min-width: 2.5rem;
    padding-right: 0.6rem;
    padding-left: 0.6rem;
    white-space: nowrap;
    text-align: right;
}

.hp-results-table__participant {
    font-weight: 400;
    text-align: left;
}

.hp-results-table__participant-line {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hp-results-table__dog {
    overflow: hidden;
    font-weight: 700;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Les proportions fixes concernent le tableau RHC à quatre colonnes. */
.dogpod-rhc .hp-results-table__participant {
    width: 42%;
}

.dogpod-competition-ranking .hp-results-table--cumulative .hp-results-table__participant {
    width: 42%;
}

.dogpod-rhc .hp-results-table__dog {
    width: 32%;
}

.dogpod-competition-ranking .hp-results-table--cumulative .hp-results-table__dog {
    width: 32%;
}

/**
 * Le mode détaillé ajoute les deux manches au cumul existant. Les proportions
 * sont recalibrées pour six colonnes sans réintroduire de défilement horizontal.
 */
.dogpod-competition-ranking .hp-results-table--detailed .hp-results-table__participant {
    width: 26%;
}

.dogpod-competition-ranking .hp-results-table--detailed .hp-results-table__dog {
    width: auto;
}

.dogpod-competition-ranking .hp-results-table--detailed tbody tr {
    height: 5.4rem;
}

.dogpod-competition-ranking .hp-results-table--detailed .hp-results-table__rank,
.dogpod-competition-ranking .hp-results-table--detailed .hp-results-table__run,
.dogpod-competition-ranking .hp-results-table--detailed .hp-results-table__points {
    width: 3ch;
    min-width: 3ch;
    max-width: 3ch;
    padding-right: 0.3rem;
    padding-left: 0.25rem;
    overflow-wrap: normal;
    text-align: right;
    white-space: nowrap;
}
.dogpod-competition-ranking .hp-results-table--detailed .hp-results-table__rank {
    width: 2ch;
    min-width: 2ch;
    max-width: 2ch;
}

.hp-results-table__run {
    min-width: 3rem;
    font-variant-numeric: tabular-nums;
    text-align: right;
    white-space: nowrap;
}

.hp-results-table__rank-label--mobile,
.hp-results-table__run-label--mobile {
    display: none;
}

.hp-results-table__run--medal-gold,
.hp-results-table__run--medal-silver,
.hp-results-table__run--medal-bronze,
.dogpod-competition-ranking .hp-results-table--detailed tbody .hp-results-table__points {
    position: relative;
    isolation: isolate;
    background: transparent;
}

.hp-results-table__run--medal-gold::before,
.hp-results-table__run--medal-silver::before,
.hp-results-table__run--medal-bronze::before,
.dogpod-competition-ranking .hp-results-table--detailed tbody .hp-results-table__points::before {
    position: absolute;
    z-index: -1;
    inset: 1rem 0.1rem;
    border-radius: 0.35rem;
    content: "";
}

.hp-results-table__run--medal-gold::before {
    background: #fff3bf;
}

.hp-results-table__run--medal-silver::before {
    background: #e9ecef;
}

.hp-results-table__run--medal-bronze::before {
    background: #f3d2b3;
}

.entry-content .hp-results-table .hp-results-table__points,
.hp-results-table__points,
.hp-results-table thead .hp-results-table__points {
    width: 18%;
    min-width: 3rem;
    text-align: right;
    white-space: nowrap;
}

/* Dans le détail d'un concours, les quatre colonnes chiffrées restent compactes. */
.entry-content .dogpod-competition-ranking .hp-results-table--detailed .hp-results-table__points {
    width: 3ch;
    min-width: 3ch;
    max-width: 3ch;
}

.dogpod-competition-ranking .hp-results-table--detailed tbody .hp-results-table__points {
    font-weight: 700;
}

.dogpod-competition-ranking .hp-results-table--detailed tbody .hp-results-table__points::before {
    background: var(--hp-results-total);
}

/* Les libellés restent centrés, quelle que soit l'orientation des données. */
.hp-results-table thead th,
.entry-content .dogpod-competition-ranking .hp-results-table--detailed thead th,
.entry-content .wp-block-accordion:has(table) table thead th {
    text-align: center;
    vertical-align: middle;
}

/* Les dimensions compactes ci-dessus restent la référence mobile. */
@media only screen and (min-width: 701px) {
    .dogpod-competition-ranking .hp-results-table--detailed .hp-results-table__rank,
    .dogpod-competition-ranking .hp-results-table--detailed .hp-results-table__run,
    .dogpod-competition-ranking .hp-results-table--detailed .hp-results-table__points {
        padding-right: 1rem;
        padding-left: 1rem;
    }
}

.hp-results-table__row--medal-yellow > * {
    background: var(--hp-results-medal-yellow);
}

.hp-results-table__row--medal-pink > * {
    background: var(--hp-results-medal-pink);
}

.hp-results-contact-note,
.entry-content .hp-results-contact-note {
    margin: 1.4rem 0.4rem 0;
    padding-left: 0.8rem;
    color: #707871;
    border-left: 2px solid var(--hp-results-border);
    font-size: 1.05rem;
    font-style: italic;
    line-height: 1.4;
    text-align: left;
}

.hp-results-contact-note a {
    color: inherit;
    font-weight: 500;
}

@media only screen and (max-width: 700px) {
    .entry-content .wp-block-accordion:has(.hp-results) .wp-block-accordion-heading__toggle,
    .entry-content .wp-block-accordion:has(table) .wp-block-accordion-heading__toggle {
        padding: 1.6rem;
    }

    .hp-results-main__summary {
        padding: 1.6rem;
    }

    .hp-results-class__summary {
        gap: 1rem;
        padding: 1.1rem 1.3rem;
    }

    .hp-results-class__meta {
        font-size: 1.35rem;
    }

    .hp-results-class__content {
        padding: 1.2rem;
    }

    .hp-results-table,
    .entry-content .wp-block-accordion:has(table) table {
        font-size: 1.2rem;
    }

    .hp-results-table th,
    .hp-results-table td,
    .entry-content .wp-block-accordion:has(table) table th,
    .entry-content .wp-block-accordion:has(table) table td {
        padding: 0.9rem 0.55rem;
    }

    .hp-results-main-title--desktop {
        display: none;
    }

    .hp-results-main-title--mobile {
        display: inline;
    }

    .hp-results-table__rank-label--desktop,
    .hp-results-table__run-label--desktop {
        display: none;
    }

    .hp-results-table__rank-label--mobile,
    .hp-results-table__run-label--mobile {
        display: inline;
    }
}
