/*
 * The blog's charts: on the page, and on their own as the images app:blog:images saves for
 * journalists (.blog-chart--image).
 * Bar charts have one bar per row with the value at its tip; the bar the article is about is
 * darker. Range charts show two prices as dots on one scale.
 */
.blog-chart {
    --blog-chart-bar: #d07ba8;
    --blog-chart-highlight: #9c3f71;
    --blog-chart-surface: var(--bs-body-bg, #fff);
    --blog-bar-label-width: 9.5rem;
    --blog-bar-gap: 0.75rem;
    margin: 1.75rem 0 1.5rem;
}

.blog-chart-head {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.blog-chart-headline {
    font-size: 2.3rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.15;
    margin-bottom: 0.4rem;
}

.blog-chart-title {
    font-weight: 600;
}

.blog-chart-subtitle,
.blog-chart-source {
    color: var(--bs-secondary-color);
    font-size: 0.9rem;
}

.blog-bars,
.blog-ranges {
    --blog-bar-room-used: var(--blog-bar-room, 6ch);
    display: grid;
    gap: 0.55rem;
    list-style: none;
    margin: 1rem 0 0.75rem;
    padding: 0;
}

.blog-bar,
.blog-range {
    align-items: center;
    display: grid;
    gap: var(--blog-bar-gap);
    grid-template-columns: var(--blog-bar-label-width) minmax(0, 1fr);
}

.blog-bar-group {
    color: var(--bs-secondary-color);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    margin-top: 0.4rem;
    text-transform: uppercase;
}

.blog-bar-label {
    align-items: center;
    display: flex;
    font-size: 0.95rem;
    gap: 0.5rem;
    line-height: 1.25;
}

.blog-bar-photo {
    background-color: #fff;
    border-radius: 0.35rem;
    flex: none;
    height: 2rem;
    object-fit: contain;
    width: 2rem;
}

.blog-bar-logo {
    flex: none;
    height: 1.4rem;
    max-width: 4.5rem;
    object-fit: contain;
}

.blog-bar-example {
    background-color: var(--blog-chart-surface);
    font-size: 0.85rem;
    grid-column: 1 / -1;
    line-height: 1.4;
    margin-top: -0.25rem;
    position: relative;
    z-index: 1;
}

.blog-bar-example-detail {
    color: var(--bs-secondary-color);
}

.blog-bar-plot {
    align-items: center;
    display: flex;
    gap: 0.5rem;
}

/* The longest bar ends where its value still fits: the plot less the room the longest value needs. */
.blog-bar-fill {
    background-color: var(--blog-chart-bar);
    border-radius: 0 4px 4px 0;
    display: block;
    flex: none;
    height: 1.1rem;
    max-height: 24px;
    min-width: 2px;
    position: relative;
    width: calc((100% - var(--blog-bar-room-used) - 0.5rem) * var(--blog-bar-value, 0));
    z-index: 1;
}

.blog-bar-value {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    white-space: nowrap;
}

.blog-bar--highlight {
    & .blog-bar-fill {
        background-color: var(--blog-chart-highlight);
    }

    & .blog-bar-label,
    & .blog-bar-value {
        font-weight: 700;
    }
}

/* A line across the bars for comparison, e.g. all bottles against single brands; it runs behind the bars. */
.blog-bars--reference {
    --blog-chart-reference-x: calc(var(--blog-bar-label-width) + var(--blog-bar-gap) + (100% - var(--blog-bar-label-width) - var(--blog-bar-gap) - var(--blog-bar-room-used) - 0.5rem) * var(--blog-chart-reference));
    padding-top: 1.6rem;
    position: relative;

    &::before {
        border-left: 2px solid rgba(33, 37, 41, 0.45);
        bottom: 0;
        content: "";
        left: var(--blog-chart-reference-x);
        position: absolute;
        top: 1.35rem;
    }

    &::after {
        color: var(--bs-secondary-color);
        content: attr(data-reference);
        font-size: 0.85rem;
        left: var(--blog-chart-reference-x);
        position: absolute;
        top: 0;
        transform: translateX(-50%);
        white-space: nowrap;
    }

    & .blog-bar-value {
        background-color: var(--blog-chart-surface);
        padding: 0 0.2rem;
        position: relative;
        z-index: 1;
    }
}

.blog-ranges {
    --blog-bar-label-width: 13rem;
}

.blog-range-detail {
    color: var(--bs-secondary-color);
    display: block;
    font-size: 0.85rem;
}

.blog-range-plot {
    --blog-range-axis: 70%;
    display: block;
    height: 3rem;
    position: relative;
}

.blog-range-difference {
    bottom: calc(100% - var(--blog-range-axis) + 1rem);
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    left: calc((var(--from) + var(--to)) / 2 * 100%);
    line-height: 1.2;
    position: absolute;
    transform: translateX(-50%);
    white-space: nowrap;
}

.blog-range-line {
    background-color: rgba(156, 63, 113, 0.35);
    border-radius: 3px;
    height: 6px;
    left: calc(var(--from) * 100%);
    position: absolute;
    top: calc(var(--blog-range-axis) - 3px);
    width: calc((var(--to) - var(--from)) * 100%);
}

.blog-range-dot,
.blog-range-key {
    border-radius: 50%;
    box-shadow: 0 0 0 2px var(--blog-chart-surface);
    height: 12px;
    width: 12px;
}

.blog-range-dot {
    position: absolute;
    top: var(--blog-range-axis);
    transform: translate(-50%, -50%);
}

.blog-range-key {
    display: inline-block;
    margin: 0 0.15rem 0 0.4rem;
    vertical-align: -1px;

    &:first-child {
        margin-left: 0;
    }
}

.blog-range-dot--min,
.blog-range-key--min {
    background-color: var(--blog-chart-highlight);
}

/* The highest price in near-black; the lowest in the brand's plum. */
.blog-range-dot--max,
.blog-range-key--max {
    background-color: #3b3b42;
}

.blog-range-dot--min {
    left: calc(var(--from) * 100%);
}

.blog-range-dot--max {
    left: calc(var(--to) * 100%);
}

.blog-range-value {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    position: absolute;
    top: var(--blog-range-axis);
    transform: translateY(-50%);
    white-space: nowrap;
}

.blog-range-value--min {
    right: calc(100% - var(--from) * 100% + 12px);
}

.blog-range-value--max {
    left: calc(var(--to) * 100% + 12px);
}

.blog-chart-source {
    margin: 0;
}

.blog-logo {
    align-items: center;
    display: inline-flex;
    font-weight: 600;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

.blog-logo-divider {
    background-color: currentcolor;
    display: inline-block;
    height: 1.1em;
    margin: 0 0.35em;
    width: 2px;
}

.blog-logo-accent {
    color: var(--logo-color, #d28baf);
    font-weight: 700;
}

.blog-chart--image {
    --blog-bar-label-width: 260px;
    --blog-bar-gap: 24px;
    background-color: #fff;
    display: flex;
    flex-direction: column;
    font-size: 24px;
    height: 675px;
    margin: 0;
    padding: 52px 64px 40px;
    width: 1200px;

    & .blog-chart-headline {
        font-size: 44px;
    }

    & .blog-chart-title {
        color: var(--bs-secondary-color);
        font-weight: 400;
    }

    & .blog-chart-subtitle,
    & .blog-chart-source {
        font-size: 20px;
    }

    & .blog-bars,
    & .blog-ranges {
        gap: 18px;
        margin: auto 0;
    }

    & .blog-ranges {
        --blog-bar-label-width: 380px;
    }

    & .blog-bar-group {
        font-size: 16px;
        margin-top: 6px;
    }

    & .blog-bar-label {
        font-size: 24px;
    }

    & .blog-bar-fill {
        height: 24px;
    }

    & .blog-bars--reference {
        padding-top: 30px;

        &::before {
            top: 26px;
        }

        &::after {
            font-size: 17px;
        }
    }

    & .blog-chart-foot {
        align-items: center;
        display: flex;
        gap: 32px;
        justify-content: space-between;
    }

    & .blog-logo {
        font-size: 26px;
    }

    &.blog-chart--dense {
        & .blog-chart-headline {
            font-size: 40px;
        }

        & .blog-ranges {
            gap: 8px;
        }

        & .blog-bars {
            gap: 4px;
            margin-bottom: 16px;
        }

        & .blog-bar {
            line-height: 1.2;
        }

        & .blog-bar-label {
            font-size: 21px;
        }

        & .blog-bar-group {
            font-size: 15px;
            margin-top: 2px;
        }

        & .blog-range-detail {
            display: inline;
            font-size: 18px;
            margin-left: 4px;
        }

        & .blog-bar-fill {
            height: 20px;
        }

        & .blog-range-plot {
            height: 34px;
        }

        & .blog-range-difference {
            bottom: calc(100% - var(--blog-range-axis) + 8px);
            font-size: 14px;
        }
    }
}

@media (max-width: 575.98px) {
    .blog-chart {
        --blog-bar-label-width: 7.5rem;
        --blog-bar-gap: 0.5rem;
    }

    /* On a phone the label needs the room more than the bottle photo. */
    .blog-bar-label .blog-bar-photo {
        display: none;
    }

    .blog-bars {
        --blog-bar-room-used: var(--blog-bar-room-short, var(--blog-bar-room, 6ch));
    }

    .blog-bar-unit {
        display: none;
    }

    .blog-bar-label {
        font-size: 0.85rem;
    }

    /* A range gets the whole width under its label, so both prices fit beside their dots. */
    .blog-range {
        gap: 0.15rem;
        grid-template-columns: minmax(0, 1fr);
    }
}
