/* Members → Pulse. Scoped to member-pulse (plus pulse-title in the page header) in the same way maintenance scopes
   itself to maintenance-management, so one page never restyles another's elements. Custom elements are inline by
   default, so every one used for layout states its display. */

pulse-title {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;

    h2 {
        margin: 0;
    }

    span {
        font-size: var(--font-size-small);
        color: var(--light-global-font-color);
    }
}

member-pulse {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    padding: 0 1rem 2rem;

    .pulse-eyebrow {
        font-size: var(--font-size-tiny);
        font-weight: 700;
        letter-spacing: 0.14em;
        text-transform: uppercase;
        color: var(--light-global-font-color);
    }

    pulse-notice {
        display: flex;
        align-items: center;
        gap: 0.6rem;
        padding: 0.75rem 1rem;
        border-radius: 0.6rem;
        font-size: var(--font-size-small);
        background: var(--status-pill-2-background);
        color: var(--status-pill-2-color);
    }

    /* The same surface as the Statistics stat cards (analytics.css). Pulse is a sibling page in the Members section,
       so it should look like one, not like a separate product. */
    pulse-movement,
    pulse-lane {
        background: var(--blue-gray);
        border: 1px solid var(--border-color);
        border-radius: 0.8rem;
        box-shadow: var(--soft-continer-outer-shadow);
    }

    /* Series colours, shared by the legend swatches and the bars. The sweep's departures are drawn darker than
       staff's, so a heavy cessation morning stands out at a glance. The two reds also differ in lightness, not only
       in hue, so they stay distinct for colour-blind staff. */
    [series="joined"] {
        background: var(--primary-green);
    }

    [series="system"] {
        background: var(--darker-danger-red);
    }

    [series="staff"] {
        background: var(--soft-danger-red);
    }

    /* #region Movement band */

    pulse-movement {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 1.75rem;
        padding: 1.4rem 1.5rem;
    }

    pulse-summary {
        display: flex;
        flex-direction: column;
        gap: 0.85rem;
        flex: 1 1 14rem;
        max-width: 19rem;
    }

    pulse-net {
        display: flex;
        align-items: baseline;
        gap: 0.6rem;

        strong {
            font-size: 3.5rem;
            font-weight: 800;
            line-height: 1;
            letter-spacing: -0.03em;
            font-variant-numeric: tabular-nums;
        }

        span {
            font-size: var(--font-size-small);
            font-weight: 600;
            color: var(--light-global-font-color);
        }
    }

    pulse-legend {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        font-size: var(--font-size-normal);

        > span {
            display: flex;
            align-items: center;
            gap: 0.6rem;
        }

        b {
            margin-left: auto;
            font-variant-numeric: tabular-nums;
        }

        [series] {
            flex: none;
            width: 0.75rem;
            height: 0.75rem;
            border-radius: 0.2rem;
        }
    }

    /* Takes the rest of the row, and drops beneath the summary on a narrow pane rather than squeezing thirty bars
       into what is left beside it. */
    pulse-chart {
        display: flex;
        gap: 0.6rem;
        flex: 999 1 35rem;
        min-width: 0;
    }

    pulse-chart-axis {
        display: flex;
        flex: none;
        flex-direction: column;
        /* Leaves room for the tick row, so the two labels line up with the halves of the chart rather than with the
           whole column. */
        padding-bottom: 1.5rem;

        span {
            display: flex;
            height: 3.25rem;
            font-size: var(--font-size-tiny);
            font-weight: 700;
            letter-spacing: 0.14em;
            text-transform: uppercase;
            color: var(--light-global-font-color);
        }

        span:first-child {
            align-items: flex-start;
        }

        span:last-child {
            align-items: flex-end;
            margin-top: 2px;
        }
    }

    pulse-days {
        display: flex;
        flex: 1 1 auto;
        min-width: 0;
    }

    /* The whole column is the day's hit target, so the pointer only has to be over the right date, not on a bar that
       may be a few pixels tall or not drawn at all. Relative positioning anchors its readout. */
    pulse-day {
        position: relative;
        display: flex;
        flex: 1 1 0;
        flex-direction: column;
        min-width: 0;
        padding: 0 0.12rem;
        border-radius: 0.35rem;
        outline: none;
    }

    pulse-day[today] {
        background: color-mix(in srgb, var(--primary-green) 18%, transparent);
    }

    pulse-bar-up,
    pulse-bar-down {
        display: flex;
        height: 3.25rem;
        align-items: center;
    }

    pulse-bar-up {
        flex-direction: column;
        justify-content: flex-end;
    }

    pulse-bar-down {
        flex-direction: column;
        justify-content: flex-start;
    }

    pulse-bar-up > span,
    pulse-bar-down > span {
        display: block;
        width: 100%;
        max-width: 1rem;
    }

    pulse-bar-up > span {
        border-radius: 0.25rem 0.25rem 0.06rem 0.06rem;
    }

    pulse-bar-down > span:last-child {
        border-radius: 0 0 0.25rem 0.25rem;
    }

    /* Bleeds through each day's side padding so the thirty segments join into one continuous line. */
    pulse-baseline {
        display: block;
        height: 2px;
        margin: 0 -0.12rem;
        background: var(--border-color);
    }

    pulse-tick {
        display: flex;
        height: 1.5rem;
        padding-top: 0.4rem;
        font-size: var(--font-size-tiny);
        font-weight: 600;
        white-space: nowrap;
        color: var(--light-global-font-color);
    }

    /* Today is the last column. Its label runs leftwards into the chart rather than off the panel's edge. */
    pulse-day[today] pulse-tick {
        justify-content: flex-end;
    }

    /* The day being read: the one under the pointer or, while the pointer is elsewhere, the one keyboard focus is on.
       Hover wins, so a mouse user never has two readouts open at once. focus-visible rather than focus, so clicking
       a day does not leave its readout pinned open after the pointer has moved off the chart. The column's wash stands
       in for a focus ring, which would be lost against thirty narrow columns. */
    pulse-days:hover pulse-day:hover,
    pulse-days:not(:hover) pulse-day:focus-visible {
        background: var(--hover-gray);

        &[today] {
            background: color-mix(in srgb, var(--primary-green) 32%, transparent);
        }

        pulse-tip {
            display: flex;
        }
    }

    pulse-days:not(:hover) pulse-day:focus-visible {
        box-shadow: inset 0 0 0 1.5px var(--primary-green);
    }

    /* The other days fade back while one is read, so the eye lands on the column the readout belongs to. */
    pulse-days:hover pulse-day:not(:hover),
    pulse-days:not(:hover):has(pulse-day:focus-visible) pulse-day:not(:focus-visible) {
        :is(pulse-bar-up, pulse-bar-down) > span {
            opacity: 0.35;
        }
    }

    /* Pointing at a legend entry picks its series out of the chart, so a heavy sweep morning or a run of staff
       departures can be found without reading every column. */
    pulse-movement:has(pulse-legend > span:hover > [series="joined"]) pulse-days :is(pulse-bar-up, pulse-bar-down) > :not([series="joined"]),
    pulse-movement:has(pulse-legend > span:hover > [series="system"]) pulse-days :is(pulse-bar-up, pulse-bar-down) > :not([series="system"]),
    pulse-movement:has(pulse-legend > span:hover > [series="staff"]) pulse-days :is(pulse-bar-up, pulse-bar-down) > :not([series="staff"]) {
        opacity: 0.2;
    }

    /* Opens beside its column, inside the chart's own height, so it never covers the bars it describes and never
       pokes out of the card where a scrolling pane would clip it. display (rather than visibility) keeps the hidden
       readouts out of the scrollable area on a narrow pane. pointer-events: none lets the pointer keep moving across
       the columns underneath it. */
    pulse-tip {
        position: absolute;
        z-index: 1;
        top: 0;
        left: calc(100% + 0.4rem);
        display: none;
        flex-direction: column;
        gap: 0.35rem;
        padding: 0.65rem 0.8rem;
        border: 1px solid var(--border-color);
        border-radius: 0.6rem;
        background: var(--deep-background-color);
        box-shadow: var(--soft-continer-outer-shadow);
        font-size: var(--font-size-small);
        white-space: nowrap;
        color: var(--light-global-font-color);
        pointer-events: none;

        > strong {
            font-size: var(--font-size-tiny);
            font-weight: 700;
            letter-spacing: 0.08em;
            text-transform: uppercase;
        }

        > span {
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        b {
            min-width: 2ch;
            font-size: var(--font-size-normal);
            font-variant-numeric: tabular-nums;
            text-align: right;
            color: var(--global-font-color);
        }

        [series] {
            flex: none;
            width: 0.7rem;
            height: 3px;
            border-radius: 2px;
        }
    }

    pulse-day[tip="before"] pulse-tip {
        right: calc(100% + 0.4rem);
        left: auto;
    }

    /* #endregion */

    /* #region Lanes */

    pulse-lanes {
        display: flex;
        flex-wrap: wrap;
        align-items: flex-start;
        gap: 1.25rem;
    }

    pulse-lane {
        display: flex;
        flex: 1 1 26rem;
        flex-direction: column;
        gap: 0.9rem;
        min-width: 0;
        padding: 1.3rem 1rem 0.9rem;
    }

    /* The lane's name, its count beside it as a list heading carries one, and one line on the rule. Padded like the
       group headers below so the heading, the morning titles and the names share one left edge. The secondary text
       is the heading colour at 80% rather than --light-global-font-color, which measures about 3.4:1 on the dark
       lane and fails 4.5:1; 80% gives about 6:1 there and 4.7:1 on the light lane. The px floor keeps the rule line
       readable where the root size shrinks below 1100px. */
    pulse-lane-header {
        display: block;
        padding: 0 0.5rem;

        h3 {
            display: flex;
            flex-wrap: wrap;
            align-items: baseline;
            gap: 0.55rem;
            margin: 0;
            font-size: var(--font-size-large);
            line-height: 1.25;
        }

        /* No measure cap: it is one line of rule, not a paragraph, and a 70ch cap broke it across two lines in a
           lane with room for one. */
        p {
            margin: 0.3rem 0 0;
            font-size: max(var(--font-size-small), 11px);
            line-height: 1.45;
            color: color-mix(in srgb, var(--global-font-color) 80%, transparent);
        }
    }

    /* The count reads as part of the heading, quieter than the name: same size, lighter weight, the secondary colour.
       Tabular figures keep it from shifting width as the number changes between visits. */
    pulse-lane-count {
        font-weight: 600;
        font-variant-numeric: tabular-nums;
        color: color-mix(in srgb, var(--global-font-color) 80%, transparent);
    }

    /* The next sweeps at a glance. Each cell takes its member pills' colour, so the strip and the rows below it agree
       on what "urgent" looks like. */
    pulse-countdown {
        display: flex;
        gap: 0.35rem;
        padding: 0 0.25rem;
    }

    pulse-countdown-day {
        display: flex;
        flex: 1 1 0;
        flex-direction: column;
        align-items: center;
        gap: 0.1rem;
        min-width: 0;
        padding: 0.6rem 0.2rem;
        border-radius: 0.6rem;
        background: var(--hover-gray);

        span {
            font-size: var(--font-size-tiny);
            font-weight: 700;
            letter-spacing: 0.08em;
            text-transform: uppercase;
        }

        strong {
            font-size: 1.35rem;
            font-weight: 800;
            line-height: 1.1;
            font-variant-numeric: tabular-nums;
        }

        small {
            font-size: var(--font-size-tiny);
            font-weight: 600;
        }
    }

    pulse-countdown-day[urgency="none"] {
        color: var(--light-global-font-color);
    }

    pulse-countdown-day[urgency="calm"] {
        background: var(--status-pill-0-background);
        color: var(--status-pill-0-color);
    }

    pulse-countdown-day[urgency="soon"] {
        background: var(--status-pill-2-background);
        color: var(--status-pill-2-color);
    }

    pulse-countdown-day[urgency="imminent"],
    pulse-countdown-day[urgency="overdue"] {
        background: var(--status-pill-3-background);
        color: var(--status-pill-3-color);
    }

    /* Overdue also carries an outline, so a missed sweep reads as something different from "tomorrow" rather than
       as a slightly redder tomorrow. */
    pulse-countdown-day[urgency="overdue"] {
        box-shadow: inset 0 0 0 1.5px currentColor;
    }

    pulse-group {
        display: block;
        padding: 0 0.25rem 0.25rem;
        border-radius: 0.7rem;
    }

    /* The morning a notification pointed at. scroll-margin keeps it clear of the window header when it is scrolled
       into view. */
    pulse-group[focused] {
        background: color-mix(in srgb, var(--primary-green) 14%, transparent);
        box-shadow: inset 0 0 0 1.5px var(--primary-green);
        scroll-margin: 1rem;
    }

    pulse-group-header {
        display: flex;
        flex-wrap: wrap;
        align-items: baseline;
        gap: 0.25rem 0.6rem;
        padding: 0.85rem 0.5rem 0.35rem;

        strong {
            font-size: var(--font-size-normal);
        }

        span {
            font-size: var(--font-size-small);
            color: var(--light-global-font-color);
        }
    }

    pulse-tag {
        display: inline-block;
        margin-left: auto;
        padding: 0.15rem 0.6rem;
        border-radius: 999px;
        font-size: var(--font-size-tiny);
        font-weight: 700;
        background: color-mix(in srgb, var(--primary-green) 30%, transparent);
        color: var(--global-font-color);
    }

    pulse-group > a {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        min-height: 3.5rem;
        padding: 0.5rem;
        border-radius: 0.6rem;
        color: var(--global-font-color);
        text-decoration: none;
    }

    pulse-group > a:hover,
    pulse-group > a:focus-visible {
        background: var(--hover-gray);
    }

    pulse-avatar {
        display: grid;
        flex: none;
        place-items: center;
        width: 2.25rem;
        height: 2.25rem;
        border-radius: 50%;
        font-size: var(--font-size-small);
        font-weight: 700;
        color: var(--light-global-font-color);
        background: var(--deep-background-color);
        box-shadow: var(--soft-container-inner-shadow);
    }

    pulse-who {
        display: flex;
        flex: 1 1 auto;
        flex-direction: column;
        gap: 0.2rem;
        min-width: 0;

        strong,
        span {
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
        }

        strong {
            font-size: var(--font-size-normal);
            font-weight: 600;
        }

        span {
            font-size: var(--font-size-small);
            color: var(--light-global-font-color);
        }
    }

    pulse-when {
        display: flex;
        flex: none;
        flex-direction: column;
        align-items: flex-end;
        gap: 0.25rem;

        > span {
            font-size: var(--font-size-tiny);
            color: var(--light-global-font-color);
        }
    }

    pulse-chevron {
        display: flex;
        flex: none;
        font-size: 0.7rem;
        color: var(--light-global-font-color);
    }

    pulse-empty {
        display: block;
        padding: 1.5rem 0.5rem;
        text-align: center;
        font-size: var(--font-size-normal);
        color: var(--light-global-font-color);
    }

    pulse-footnote {
        display: flex;
        align-items: flex-start;
        gap: 0.5rem;
        margin: 0 0.5rem;
        padding-top: 0.75rem;
        border-top: 1px solid var(--border-color);
        font-size: var(--font-size-small);
        color: var(--light-global-font-color);

        svg {
            flex: none;
            margin-top: 0.1rem;
        }
    }

    /* #endregion */
}

@media (prefers-reduced-motion: no-preference) {
    member-pulse pulse-group > a {
        transition: background-color 0.15s ease;
    }

    /* Short, so sweeping the pointer across the chart still feels immediate. */
    member-pulse :is(pulse-bar-up, pulse-bar-down) > span {
        transition: opacity 0.12s ease;
    }
}