/* FormFieldBuilder — Bewertungsfeld (Feedbackmodul KAN-47). Farben folgen dem Design-Preset. */

/*
 * KAN-150: zuvor über @media (prefers-color-scheme) umgeschaltet, also über die
 * Einstellung des Betriebssystems statt über das site-seitig gewählte Design
 * (ADR-0023). Diese Datei wird global eingebunden (setup.typoscript) und war
 * damit auf jeder Formularseite betroffen.
 *
 * Neutrales aus den Bootstrap-Tokens, Akzente aus den Preset-Tokens — jede
 * var(--gym-…) mit Fallback auf den bisherigen Wert (Konvention aus
 * designs.scss), damit Presets ohne eigene Tokens unverändert rendern.
 */
:root {
    /* Leerer Stern = Kontur im Ton der Feldränder (KAN-581: mindestens 3:1, Rückfall wie in theme.scss). */
    --gym-rating-star-empty: var(--gym-field-border, color-mix(in srgb, var(--bs-body-color) 60%, var(--bs-body-bg)));
    --gym-rating-star-active: var(--gym-primary, #e8a33d);

    --gym-rating-pill-bg: var(--bs-body-bg);
    --gym-rating-pill-text: var(--bs-body-color);
    --gym-rating-pill-border: var(--gym-field-border, color-mix(in srgb, var(--bs-body-color) 60%, var(--bs-body-bg)));
    --gym-rating-pill-hover-bg: var(--bs-tertiary-bg);
    /* Gewählte Stufe trägt die Primärfarbe samt der dazu geprüften Schriftfarbe
       (--gym-on-primary ist je Preset auf Kontrast abgenommen). */
    --gym-rating-pill-active-bg: var(--gym-primary, #2d6a4f);
    --gym-rating-pill-active-text: var(--gym-on-primary, #ffffff);
    --gym-rating-pill-active-border: var(--gym-primary, #2d6a4f);

    --gym-rating-focus-ring: var(--gym-primary, #2d6a4f);
}

/* --- Group --- */
.gym-rating {
    border: 0;
    padding: 0;
    margin-bottom: 1rem;
}

/*
 * KAN-570: Ein abgelehntes Pflicht-Rating ist an der Gruppe sichtbar markiert, nicht nur per aria-invalid. Der Balken am Rand und die
 * Fehlerfarbe der Legende kommen aus den Bootstrap-Tokens (hell wie dunkel); das Symbol vor der Meldung (theme.scss) sorgt dafür, dass der
 * Fehler nicht allein an der Farbe hängt (WCAG 1.4.1).
 */
.gym-rating[aria-invalid="true"] {
    border-inline-start: 0.25rem solid var(--bs-form-invalid-border-color, var(--bs-danger));
    padding-inline-start: 0.75rem;
}

.gym-rating[aria-invalid="true"] .gym-rating__legend {
    color: var(--bs-form-invalid-color, var(--bs-danger-text-emphasis));
}

/* <legend> ignores the form-label sizing, so it is restated here. */
.gym-rating__legend {
    float: none;
    width: auto;
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

.gym-rating__items {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem;
}

.gym-rating__item {
    position: relative;
    display: flex;
}

/*
 * The radio stays in the accessibility tree and in the tab order — it is moved
 * out of sight, NOT display:none (which would make the group unreachable by
 * keyboard and invisible to screen readers).
 */
.gym-rating__input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.gym-rating__label {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.gym-rating__input:focus-visible + .gym-rating__label {
    outline: 2px solid var(--gym-rating-focus-ring);
    outline-offset: 2px;
    /* Der Fokusring folgt der Form des Elements, das er umschließt — sonst läge
       ein eckiger Rahmen um eine runde Stufe. */
    border-radius: var(--gym-radius-control, 0.25rem);
}

/* --- Star scale (1-5) --- */
.gym-rating__items--stars .gym-rating__label {
    padding: 0.125rem;
}

.gym-rating__glyph {
    width: 2rem;
    height: 2rem;
    fill: currentColor;
    color: var(--gym-rating-star-empty);
    transition: color 0.12s ease-in-out;
}

@media (prefers-reduced-motion: reduce) {
    .gym-rating__glyph {
        transition: none;
    }
}

/*
 * Fill "up to and including" the selected star without JS: a star is active if
 * its own radio is checked, or if any LATER sibling is checked. Requires :has()
 * with a sibling combinator — where it is unsupported, only the selected star
 * fills, which still communicates the value.
 *
 * The stored-value rules and the pointer-preview rules below are mutually
 * exclusive (:not(:hover) vs :hover on the same element), so they never compete
 * on specificity — the preview simply replaces the stored value while hovering.
 */
.gym-rating__items--stars:not(:hover) .gym-rating__item:has(.gym-rating__input:checked) .gym-rating__glyph,
.gym-rating__items--stars:not(:hover) .gym-rating__item:has(~ .gym-rating__item .gym-rating__input:checked) .gym-rating__glyph {
    color: var(--gym-rating-star-active);
}

.gym-rating__items--stars:hover .gym-rating__item:hover .gym-rating__glyph,
.gym-rating__items--stars:hover .gym-rating__item:has(~ .gym-rating__item:hover) .gym-rating__glyph {
    color: var(--gym-rating-star-active);
}

/* --- Numeric scale (1-10 / NPS 0-10) --- */
.gym-rating__items--scale .gym-rating__label {
    min-width: 2.5rem;
    padding: 0.375rem 0.5rem;
    border: 1px solid var(--gym-rating-pill-border);
    /* Gleicher Radius wie Eingabefeld, Auswahlfeld und Button (designs.scss).
       Der Chip ist niedriger als der Radius groß ist — der Browser skaliert den
       Wert dann proportional herunter, die Stufe wird also rund statt eckig. */
    border-radius: var(--gym-radius-control, 0.375rem);
    background-color: var(--gym-rating-pill-bg);
    color: var(--gym-rating-pill-text);
    font-variant-numeric: tabular-nums;
}

.gym-rating__items--scale .gym-rating__label:hover {
    background-color: var(--gym-rating-pill-hover-bg);
}

/* Unlike stars, only the selected step is highlighted — a 0-10 scale is a
   single choice, not a filled bar. */
.gym-rating__items--scale .gym-rating__input:checked + .gym-rating__label {
    background-color: var(--gym-rating-pill-active-bg);
    border-color: var(--gym-rating-pill-active-border);
    color: var(--gym-rating-pill-active-text);
}
