/*
 * Star rating component — from scratch, no framework.
 * Modeled on https://mazin-musleh.github.io/NDS-vanilla/components/rating.html
 * and https://design.dga.gov.sa/guidelines/components/feedback/rating, extended
 * with half-star hover/keyboard precision (the vendored NDS component only
 * supports whole-star selection; half-star display there is a fixed preset,
 * never something the user can land on by hovering or pressing a key).
 *
 * Layout uses `display:flex` + the page's own `dir`, so a 5-star row already
 * mirrors for RTL on its own (flex row direction follows `direction`, which
 * `dir` sets) — the only RTL-specific rule below is the per-star fill flip,
 * needed because each star's own left/right fill fraction is physical, not
 * logical.
 */

.rating {
    --size: 32px;
    --empty: #d7dbe0;
    --fill-color: #f5a623;
    --hover-color: #ffb938;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-family: system-ui, sans-serif;
}

.rating:focus-visible {
    outline: 2px solid #2f6fed;
    outline-offset: 4px;
    border-radius: 4px;
}

/* Size variants — same idea as the reference's nds-xs/sm/md/lg. */
.rating.rating-sm {
    --size: 20px;
}

.rating.rating-lg {
    --size: 44px;
}

.rating-star {
    position: relative;
    display: inline-block;
    width: var(--size);
    height: var(--size);
    color: var(--empty);
    flex-shrink: 0;
}

/* Base star silhouette — always visible, coloured by `color` (the "empty" state). */
.rating-star::before {
    content: "";
    position: absolute;
    inset: 0;
    background-color: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='42' height='40' viewBox='0 0 42 40' fill='none'%3e%3cpath d='M19.1839 1.93733C19.8987 0.387582 22.1013 0.387586 22.8161 1.93733L27.3024 11.6635C27.5937 12.2952 28.1923 12.73 28.883 12.8119L39.5195 14.0731C41.2143 14.274 41.8949 16.3688 40.6419 17.5275L32.7781 24.7998C32.2674 25.272 32.0388 25.9757 32.1744 26.6579L34.2618 37.1636C34.5944 38.8375 32.8125 40.1321 31.3233 39.2985L21.9769 34.0668C21.3699 33.7271 20.6301 33.7271 20.0231 34.0668L10.6767 39.2985C9.1875 40.1321 7.40558 38.8375 7.73819 37.1636L9.82565 26.6579C9.96121 25.9757 9.73257 25.272 9.2219 24.7998L1.35805 17.5275C0.105054 16.3688 0.78569 14.274 2.48048 14.0731L13.117 12.8119C13.8077 12.73 14.4063 12.2952 14.6976 11.6635L19.1839 1.93733Z' fill='black'/%3e%3c/svg%3e") no-repeat center / contain;
    mask: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='42' height='40' viewBox='0 0 42 40' fill='none'%3e%3cpath d='M19.1839 1.93733C19.8987 0.387582 22.1013 0.387586 22.8161 1.93733L27.3024 11.6635C27.5937 12.2952 28.1923 12.73 28.883 12.8119L39.5195 14.0731C41.2143 14.274 41.8949 16.3688 40.6419 17.5275L32.7781 24.7998C32.2674 25.272 32.0388 25.9757 32.1744 26.6579L34.2618 37.1636C34.5944 38.8375 32.8125 40.1321 31.3233 39.2985L21.9769 34.0668C21.3699 33.7271 20.6301 33.7271 20.0231 34.0668L10.6767 39.2985C9.1875 40.1321 7.40558 38.8375 7.73819 37.1636L9.82565 26.6579C9.96121 25.9757 9.73257 25.272 9.2219 24.7998L1.35805 17.5275C0.105054 16.3688 0.78569 14.274 2.48048 14.0731L13.117 12.8119C13.8077 12.73 14.4063 12.2952 14.6976 11.6635L19.1839 1.93733Z' fill='black'/%3e%3c/svg%3e") no-repeat center / contain;
}

/* Fill overlay — the same star shape, intersected with a gradient sized by
   --fill (0, .5 or 1), so only that fraction of the star silhouette shows
   the filled colour. This is one rule for empty/half/full alike: --fill
   just moves the gradient's hard stop. */
.rating-star::after {
    content: "";
    position: absolute;
    inset: 0;
    background-color: var(--fill-color);
    -webkit-mask:
        url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='42' height='40' viewBox='0 0 42 40' fill='none'%3e%3cpath d='M19.1839 1.93733C19.8987 0.387582 22.1013 0.387586 22.8161 1.93733L27.3024 11.6635C27.5937 12.2952 28.1923 12.73 28.883 12.8119L39.5195 14.0731C41.2143 14.274 41.8949 16.3688 40.6419 17.5275L32.7781 24.7998C32.2674 25.272 32.0388 25.9757 32.1744 26.6579L34.2618 37.1636C34.5944 38.8375 32.8125 40.1321 31.3233 39.2985L21.9769 34.0668C21.3699 33.7271 20.6301 33.7271 20.0231 34.0668L10.6767 39.2985C9.1875 40.1321 7.40558 38.8375 7.73819 37.1636L9.82565 26.6579C9.96121 25.9757 9.73257 25.272 9.2219 24.7998L1.35805 17.5275C0.105054 16.3688 0.78569 14.274 2.48048 14.0731L13.117 12.8119C13.8077 12.73 14.4063 12.2952 14.6976 11.6635L19.1839 1.93733Z' fill='black'/%3e%3c/svg%3e") no-repeat center / contain,
        linear-gradient(to right, black calc(var(--fill, 0) * 100%), transparent calc(var(--fill, 0) * 100%));
    -webkit-mask-composite: source-in;
    mask:
        url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='42' height='40' viewBox='0 0 42 40' fill='none'%3e%3cpath d='M19.1839 1.93733C19.8987 0.387582 22.1013 0.387586 22.8161 1.93733L27.3024 11.6635C27.5937 12.2952 28.1923 12.73 28.883 12.8119L39.5195 14.0731C41.2143 14.274 41.8949 16.3688 40.6419 17.5275L32.7781 24.7998C32.2674 25.272 32.0388 25.9757 32.1744 26.6579L34.2618 37.1636C34.5944 38.8375 32.8125 40.1321 31.3233 39.2985L21.9769 34.0668C21.3699 33.7271 20.6301 33.7271 20.0231 34.0668L10.6767 39.2985C9.1875 40.1321 7.40558 38.8375 7.73819 37.1636L9.82565 26.6579C9.96121 25.9757 9.73257 25.272 9.2219 24.7998L1.35805 17.5275C0.105054 16.3688 0.78569 14.274 2.48048 14.0731L13.117 12.8119C13.8077 12.73 14.4063 12.2952 14.6976 11.6635L19.1839 1.93733Z' fill='black'/%3e%3c/svg%3e") no-repeat center / contain,
        linear-gradient(to right, black calc(var(--fill, 0) * 100%), transparent calc(var(--fill, 0) * 100%));
    mask-composite: intersect;
    transition: background-color .15s ease;
}

/* Each star's fill grows from its own reading-start edge — physical, so it
   needs an explicit flip for RTL (the flex row itself already mirrors via
   `direction`, this just keeps the *inside* of each star consistent with it). */
[dir="rtl"] .rating-star::after {
    transform: scaleX(-1);
}

/* ---- interactive (default) ---- */

.rating:not([data-readonly]) {
    cursor: pointer;
}

.rating:not([data-readonly]):hover .rating-star::after {
    background-color: var(--hover-color);
}

.rating[data-disabled] {
    cursor: not-allowed;
    opacity: .5;
}

/* ---- readonly / display-only ---- */

.rating[data-readonly] .rating-star::after {
    transition: none;
}

/* Optional live numeric readout next to the stars — purely decorative
   (aria-hidden), the accessible value already lives in aria-valuetext. */
.rating-value {
    margin-inline-start: 4px;
    font-size: .875rem;
    color: #4b5563;
    min-width: 2.5ch;
}
