/**
 * Body map + injury logging modal.
 *
 * The modal shell is its OWN class, not an override of
 * .session-change-modal__content. That class is shared by the sync, rebase and
 * day-action modals and is capped at max-width: 560px (style.css) — two
 * figures plus a panel will not fit, and widening it would move all three.
 */

/**
 * Severity is stored 0–10 and shown as four named bands. These mirror
 * SEVERITY_BANDS in body-map.js — that table is the source of truth and these
 * exist only so static markup (the diary page legend) can reach the same hex.
 *
 * Each fill has a paired text colour chosen for contrast: niggle 7.9:1,
 * moderate 7.1:1, severe 5.0:1. --injury-moderate-text is DARK deliberately —
 * white on #ff8fb6 is 2.0:1 and fails WCAG AA.
 *
 * The ramp is a single hue at H≈339°, the site's --color-accent. Severe is
 * --color-accent-dark rather than the brand pink itself: white on #ff2d78 is
 * 3.56:1 and fails AA.
 */
:root {
    --injury-accent: #d81165;
    --injury-mild: #ffe0eb;
    --injury-moderate: #ff8fb6;
    --injury-severe: #d81165;
    --injury-mild-text: #831843;
    --injury-moderate-text: #500724;
    --injury-severe-text: #ffffff;
}

/* ------------------------------------------------------------------ figure */

.body-map {
    display: flex;
    gap: 1.25rem;
    justify-content: center;
    align-items: flex-start;
}

.body-map__figure {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
}

.body-map__svg {
    display: block;
    max-width: 100%;
    height: auto;
    touch-action: manipulation;
}

.body-map__caption {
    font-size: 0.68rem;
    letter-spacing: 0.08em;
    font-weight: 600;
    color: #6b7280;
}

.body-map__zone {
    transition: fill 120ms linear;
}

.body-map--edit .body-map__zone,
.body-map--heatmap .body-map__zone {
    cursor: pointer;
}

.body-map--edit .body-map__zone:focus-visible,
.body-map--heatmap .body-map__zone:focus-visible {
    outline: 2px solid var(--injury-accent);
    outline-offset: 1px;
}

/* -------------------------------------------------------------- modal shell */

.injury-modal {
    position: fixed;
    inset: 0;
    z-index: 1200;
    background: rgba(15, 23, 42, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.injury-modal__content {
    background: #fff;
    border-radius: 14px;
    width: 100%;
    max-width: 900px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
}

.injury-modal__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.1rem 1.35rem 0.9rem;
    border-bottom: 1px solid #e5e7eb;
}

.injury-modal__title {
    margin: 0;
    font-size: 1.1rem;
}

.injury-modal__context {
    margin: 0.2rem 0 0;
    font-size: 0.85rem;
    color: #6b7280;
}

.injury-modal__close {
    background: none;
    border: 0;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    color: #6b7280;
    padding: 0 0.25rem;
    /* 44px hit area regardless of the glyph size. */
    min-width: 44px;
    min-height: 44px;
}

.injury-modal__body {
    padding: 1.15rem 1.35rem;
    overflow-y: auto;
    flex: 1 1 auto;
}

.injury-modal__loading {
    padding: 2rem 0;
    text-align: center;
    color: #6b7280;
}

.injury-modal__footer {
    display: flex;
    gap: 0.6rem;
    justify-content: flex-end;
    padding: 0.85rem 1.35rem;
    border-top: 1px solid #e5e7eb;
    background: #fff;
}

.injury-modal__footer .injury-delete {
    margin-right: auto;
}

/* Locks the page behind the sheet so the plan grid does not scroll under it. */
body.injury-modal-open {
    overflow: hidden;
}

/* ---------------------------------------------------------- desktop layout */

.injury-layout {
    display: grid;
    grid-template-columns: minmax(0, 460px) minmax(0, 1fr);
    gap: 1.5rem;
    align-items: start;
}

.injury-layout__map {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.injury-readout {
    margin: 0;
    min-height: 1.3em;
    font-size: 0.88rem;
    font-weight: 600;
    color: #374151;
    text-align: center;
}

.injury-map-host {
    display: flex;
    justify-content: center;
}

.injury-legend {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    gap: 0.9rem;
    justify-content: center;
    font-size: 0.78rem;
    color: #4b5563;
}

.injury-legend li {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.injury-legend__swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 1px solid #d1d5db;
}

/* The band's numeric range, so the colours on the figure are readable as
   numbers and the 6 = "stop" cut-point is visible without being stated. */
.injury-legend__range {
    color: #6b7280;
    font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------- marked areas */

.injury-panel__title {
    margin: 0 0 0.6rem;
    font-size: 0.92rem;
}

.injury-panel__empty {
    margin: 0 0 0.75rem;
    font-size: 0.85rem;
    color: #6b7280;
}

.injury-row {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 0.55rem 0.65rem;
    margin-bottom: 0.55rem;
}

.injury-row__head {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.injury-row__name {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 0.88rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.injury-row__view {
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #6b7280;
    background: #f3f4f6;
    border-radius: 4px;
    padding: 0.1rem 0.3rem;
}

.injury-row__note {
    width: 100%;
    margin-top: 0.45rem;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 0.35rem 0.45rem;
    font: inherit;
    font-size: 0.82rem;
    resize: vertical;
}

.injury-row__remove,
.injury-strip__remove {
    background: none;
    border: 0;
    font-size: 1.25rem;
    line-height: 1;
    color: #9ca3af;
    cursor: pointer;
    min-width: 32px;
    min-height: 32px;
}

/* ------------------------------------------------------- severity control */

.injury-sev {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.injury-sev__slider {
    /* Wide enough that eleven stops are ~11px apart — under that the control
       is a slider in name only and every drag overshoots. */
    flex: 1 1 120px;
    min-width: 110px;
    max-width: 190px;
    accent-color: var(--injury-accent);
    cursor: pointer;
    margin: 0;
}

/* The readout is the value, so it must not collapse or wrap as the band name
   changes length ("None" → "Moderate") and shove the row about. */
.injury-sev__value {
    flex: 0 0 auto;
    min-width: 88px;
    text-align: center;
    border-radius: 999px;
    border: 1px solid rgba(15, 23, 42, 0.12);
    padding: 0.15rem 0.5rem;
    font-size: 0.76rem;
    font-weight: 600;
    white-space: nowrap;
}

.injury-add-area {
    background: none;
    border: 1px dashed #ffc2d8;
    color: var(--injury-accent);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
}

/* ------------------------------------------------------------ region picker */

.injury-picker {
    margin: 0.6rem 0;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 0.65rem;
    max-height: 260px;
    overflow-y: auto;
    background: #fafafa;
}

.injury-picker__group + .injury-picker__group {
    margin-top: 0.7rem;
}

.injury-picker__group h5 {
    margin: 0 0 0.35rem;
    font-size: 0.72rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: #6b7280;
}

.injury-picker__items {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.injury-picker__item {
    border: 1px solid #d1d5db;
    background: #fff;
    border-radius: 999px;
    padding: 0.35rem 0.7rem;
    font-size: 0.8rem;
    cursor: pointer;
    /* The picker is the only route to hip and glute, so its targets must not
       be marginal even though it is a list rather than a map. */
    min-height: 36px;
}

.injury-picker__item.is-marked {
    background: var(--injury-mild);
    border-color: var(--injury-moderate);
    font-weight: 600;
}

/* --------------------------------------------------------------- day fields */

.injury-day-fields {
    margin-top: 1.1rem;
    display: grid;
    gap: 0.75rem;
}

.injury-field {
    display: block;
}

.injury-field__label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: #374151;
}

.injury-impact,
.injury-note {
    width: 100%;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 0.5rem 0.6rem;
    font: inherit;
    font-size: 0.88rem;
}

.injury-note {
    resize: vertical;
}

/* ------------------------------------------------------------ mobile sheet */

@media (max-width: 768px) {
    .injury-modal--sheet {
        padding: 0;
    }

    .injury-modal--sheet .injury-modal__content {
        max-width: 100%;
        border-radius: 0;
        max-height: none;
        /* dvh where supported, vh as the fallback. Without dvh the browser
           chrome overlaps the sticky footer and Save becomes unreachable. */
        height: 100vh;
        height: 100dvh;
    }

    .injury-modal--sheet .injury-modal__header {
        position: sticky;
        top: 0;
        z-index: 3;
        background: #fff;
    }

    /* Two sticky bars, so the whole sheet stays ONE vertical scroll. The map
       deliberately has no scroll box of its own: a scroller inside a scroller
       produces the scroll-chaining ambiguity that makes a map feel broken. */
    .injury-modal--sheet .injury-strip {
        position: sticky;
        bottom: 0;
        z-index: 2;
        display: flex;
        align-items: center;
        gap: 0.6rem;
        background: #fff;
        border-top: 1px solid #e5e7eb;
        padding: 0.6rem 0.15rem;
        margin-top: 0.5rem;
    }

    .injury-modal--sheet .injury-modal__footer {
        position: sticky;
        bottom: 0;
        z-index: 3;
    }

    .injury-strip__name {
        flex: 1 1 auto;
        min-width: 0;
        font-size: 0.88rem;
        font-weight: 600;
    }

    .injury-strip__hint {
        margin: 0;
        font-size: 0.85rem;
        color: #6b7280;
    }

    .injury-view-toggle {
        display: flex;
        gap: 0.35rem;
        background: #f3f4f6;
        border-radius: 999px;
        padding: 0.25rem;
        margin-bottom: 0.75rem;
    }

    .injury-view-toggle__btn {
        flex: 1;
        border: 0;
        background: none;
        border-radius: 999px;
        padding: 0.55rem;
        font-size: 0.85rem;
        font-weight: 600;
        color: #4b5563;
        cursor: pointer;
        min-height: 44px;
    }

    .injury-view-toggle__btn.active {
        background: #fff;
        color: var(--injury-accent);
        box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
    }

    /* The slider is a touch target on mobile, not a 16px desktop thumb. The
       track stays thin; only the thumb grows, so the control still reads as a
       slider while being draggable with a thumb-tip. Both vendor prefixes are
       needed and cannot be combined into one rule — an unrecognised selector
       invalidates the whole list. */
    .injury-sev__slider {
        /* Required for ::-webkit-slider-thumb to take any style at all. */
        -webkit-appearance: none;
        appearance: none;
        background: none;
        height: 44px;
        max-width: none;
    }

    .injury-sev__slider::-webkit-slider-thumb {
        -webkit-appearance: none;
        appearance: none;
        width: 44px;
        height: 44px;
        border-radius: 50%;
        border: 1px solid rgba(15, 23, 42, 0.25);
        background: var(--injury-accent);
        cursor: pointer;
        /* (track 6px - thumb 44px) / 2. WebKit aligns the thumb to the TOP of
           the track once appearance is none, so it needs centring by hand. */
        margin-top: -19px;
    }

    .injury-sev__slider::-moz-range-thumb {
        width: 44px;
        height: 44px;
        border-radius: 50%;
        border: 1px solid rgba(15, 23, 42, 0.25);
        background: var(--injury-accent);
        cursor: pointer;
    }

    /* Overriding the thumb on WebKit removes the default track with it. */
    .injury-sev__slider::-webkit-slider-runnable-track {
        height: 6px;
        border-radius: 3px;
        background: #e5e7eb;
    }

    .injury-sev__slider::-moz-range-track {
        height: 6px;
        border-radius: 3px;
        background: #e5e7eb;
    }

    .injury-row__remove,
    .injury-strip__remove {
        min-width: 44px;
        min-height: 44px;
    }
}

/* ---------------------------------------------------------------- day badge */

.injury-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: none;
    cursor: pointer;
    padding: 4px;
    line-height: 0;
    vertical-align: middle;
}

.injury-badge__dot {
    display: block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 1px solid rgba(15, 23, 42, 0.25);
}

/* Keyed on the BAND, not the 0–10 value: these are exact-match selectors, so
   keyed on the number they would silently lose all colour for 4–10. */
.injury-badge[data-band="none"] .injury-badge__dot { background: #e5e7eb; }
.injury-badge[data-band="niggle"] .injury-badge__dot { background: var(--injury-mild); }
.injury-badge[data-band="moderate"] .injury-badge__dot { background: var(--injury-moderate); }
.injury-badge[data-band="severe"] .injury-badge__dot { background: var(--injury-severe); }

.injury-badge:focus-visible {
    outline: 2px solid var(--injury-accent);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ---------------------------------------------------------- diary list cards */

.injury-diary-list {
    margin-top: 1.25rem;
}

.injury-diary-list__title {
    margin: 0 0 0.75rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: #374151;
}

.injury-card {
    border: 1px solid #e5e7eb;
    border-left: 3px solid var(--injury-accent);
    border-radius: 8px;
    padding: 0.75rem 0.9rem;
    background: #fff;
}

.injury-card + .injury-card {
    margin-top: 0.6rem;
}

.injury-card__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
}

.injury-card__date {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: #111827;
}

.injury-card__session {
    margin: 0.15rem 0 0;
    font-size: 0.85rem;
    color: #6b7280;
}

.injury-card__edit {
    flex-shrink: 0;
    border: 1px solid #d1d5db;
    background: #fff;
    border-radius: 6px;
    padding: 0.3rem 0.7rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: #4b5563;
    cursor: pointer;
}

.injury-card__edit:hover {
    border-color: var(--injury-accent);
    color: var(--injury-accent);
}

.injury-card__impact {
    margin: 0.5rem 0 0;
    font-size: 0.82rem;
    font-weight: 600;
    color: #b45309;
}

.injury-card__chips {
    display: flex;
    flex-wrap: wrap;
    /* Wider than the gap inside a region pair, so a row of regions reads as
       pairs rather than as one undifferentiated run of pills. */
    gap: 0.4rem 0.5rem;
    list-style: none;
    margin: 0.55rem 0 0;
    padding: 0;
}

/* One region = its tinted name chip + its band chip, kept together. inline-flex
   so the pair is one wrapping unit: split across lines, "Niggle" would appear
   to belong to whichever region ended up above it. */
.injury-card__region {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

/* Chips wrap rather than truncate: a region name is the record. */
.injury-chip {
    border-radius: 999px;
    padding: 0.2rem 0.6rem;
    font-size: 0.78rem;
    font-weight: 600;
    border: 1px solid rgba(15, 23, 42, 0.12);
    color: #500724;
}

.injury-chip[data-band="niggle"] { background: var(--injury-mild); color: var(--injury-mild-text); }
.injury-chip[data-band="moderate"] { background: var(--injury-moderate); color: var(--injury-moderate-text); }
.injury-chip[data-band="severe"] { background: var(--injury-severe); color: var(--injury-severe-text); }

/* Deliberately neutral, and deliberately NOT tinted to match its partner: two
   pink pills touching read as one chip that happened to wrap. Grey says "this
   is a label for the thing on my left". */
.injury-chip--level {
    background: var(--color-bg-alt, #f4f5fb);
    color: var(--color-text-light, #5b6480);
    font-weight: 500;
}

.injury-card__note {
    margin: 0.55rem 0 0;
    font-size: 0.85rem;
    color: #4b5563;
    white-space: pre-wrap;
}

@media (max-width: 768px) {
    /* Fact: the badge is the ONE-tap route to an existing entry, against three
       interactions to create one (the first of which is an invisible swipe).
       It has to be a real target. */
    .injury-badge {
        min-width: 44px;
        min-height: 44px;
        padding: 17px;
    }

    /* "Pain & Load" is a fourth button in a row sized for three. The toggle is
       inline-flex with no wrap in style.css, so without this it overflows the
       card rather than dropping to a second line. */
    .progress-chart-toggle {
        flex-wrap: wrap;
    }

    .injury-card__edit {
        min-width: 44px;
        min-height: 44px;
    }
}
