.abfm-bp {
    position: relative;
    margin: 2rem 0;
    color: var(--color-text);
}

.abfm-bp .hidden {
    display: none !important;
}

/* Layout */
.abfm-bp-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 16px;
    align-items: stretch;
}

/* Each column spans two parent rows (heading + card) via subgrid, so every
   heading shares the tallest heading's height and the cards line up. */
.abfm-bp-column {
    display: grid;
    grid-row: span 2;
    grid-template-rows: subgrid;
    row-gap: 0;
    min-width: 0;
}

.abfm-bp-heading {
    align-self: start;
    margin: 0 0 12px;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.4;
    text-align: center;
}

.abfm-bp-card {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 12px 10px;
    border: 1px solid var(--color-border);
    background: var(--color-container-bg);
}

.abfm-bp.is-initializing .abfm-bp-grid,
.abfm-bp.is-initializing .abfm-bp-disclaimer {
    visibility: hidden;
}

.abfm-bp.is-loading .abfm-bp-bars {
    opacity: 0.6;
}

/* Bars */
.abfm-bp-bars {
    --abfm-bp-row-font: 0.8rem;
    --abfm-bp-label-em: 4.5;
    --abfm-bp-tag-em: 6.5;
    --abfm-bp-row-gap: 6px;

    position: relative;
    display: flex;
    flex: 1;
    flex-direction: column;
    justify-content: space-around;
    gap: 2px;
    transition: opacity 0.15s;
}

/* Axis line running the full height of the chart at the left edge of the bars */
.abfm-bp-bars:not(:empty)::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: calc(var(--abfm-bp-label-em) * var(--abfm-bp-row-font) + var(--abfm-bp-row-gap) - 1px);
    width: 1px;
    background: var(--color-secondary);
    pointer-events: none;
}

.abfm-bp-row {
    display: grid;
    grid-template-columns: calc(var(--abfm-bp-label-em) * 1em) minmax(0, 1fr) calc(var(--abfm-bp-tag-em) * 1em);
    align-items: center;
    gap: var(--abfm-bp-row-gap);
    position: relative;
    width: 100%;
    margin: 0;
    padding: 1px 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    font-size: var(--abfm-bp-row-font);
    line-height: 1.2;
    letter-spacing: normal;
    text-align: left;
    text-transform: none;
    box-shadow: none;
}

button.abfm-bp-row {
    cursor: pointer;
}

button.abfm-bp-row:hover,
button.abfm-bp-row:focus {
    background: color-mix(in srgb, var(--color-secondary) 8%, transparent);
    color: inherit;
}

button.abfm-bp-row:focus-visible {
    outline: 2px solid var(--color-secondary);
    outline-offset: 1px;
}

.abfm-bp-label {
    text-align: right;
    white-space: nowrap;
}

.abfm-bp-row.is-selected .abfm-bp-label,
.abfm-bp-tag {
    color: var(--color-accent);
    font-weight: 700;
}

/* Placed by placeTag() in the JS: just past the bar end, or inside the bar (.is-inside) when the
   gutter is too narrow. right: 0 is only the fallback before it runs. */
.abfm-bp-tag {
    position: absolute;
    top: 50%;
    right: 0;
    z-index: 1;
    transform: translateY(-50%);
    white-space: nowrap;
    pointer-events: none;
}

.abfm-bp-tag.is-inside {
    color: #fff;
}

/* Dashed passing line on the boundary between the lowest passing bin and the first failing one. */
.abfm-bp-row.has-pass-line::after {
    content: "";
    position: absolute;
    left: calc(var(--abfm-bp-label-em) * 1em + var(--abfm-bp-row-gap));
    right: 0;
    bottom: -2px;
    border-top: 2px dashed var(--color-text);
    pointer-events: none;
}

.abfm-bp-pass-label {
    position: absolute;
    right: 0;
    bottom: -1px;
    z-index: 1;
    padding-left: 4px;
    background: var(--color-container-bg);
    color: var(--color-text);
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1;
    transform: translateY(50%);
    pointer-events: none;
}

.abfm-bp-track {
    display: block;
    height: 100%;
    min-height: 14px;
}

.abfm-bp-bar {
    display: block;
    height: 100%;
    min-height: 14px;
    min-width: 2px;
    transition: width 0.25s ease, background-color 0.15s;
}

.abfm-bp-bar.is-default {
    background: color-mix(in srgb, var(--color-text) 45%, var(--color-container-bg));
}

.abfm-bp-bar.is-accent {
    background: var(--color-secondary);
}

.abfm-bp-bar.is-selected {
    background: var(--color-accent);
}

.abfm-bp-bar.is-pass {
    background: var(--color-success);
}

.abfm-bp-bar.is-fail {
    background: var(--color-error);
}

/* USMLE / COMLEX toggle */
.abfm-bp-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-bottom: 12px;
}

.abfm-bp-toggle-option {
    margin: 0;
    padding: 2px 4px;
    border: 0;
    background: none;
    color: var(--color-text);
    font: inherit;
    font-size: 0.8rem;
    letter-spacing: normal;
    cursor: pointer;
}

.abfm-bp-toggle-option.is-active {
    color: var(--color-secondary);
    font-weight: 700;
}

/* Pill with a knob: left = USMLE, right (.is-on) = COMLEX */
.abfm-bp-toggle-switch {
    position: relative;
    flex-shrink: 0;
    width: 24px;
    height: 14px;
    border: 2px solid var(--color-secondary);
    border-radius: 7px;
    box-sizing: border-box;
    cursor: pointer;
}

.abfm-bp-toggle-switch::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 1px;
    width: 8px;
    height: 8px;
    border: 2px solid var(--color-secondary);
    border-radius: 50%;
    box-sizing: border-box;
    transform: translateY(-50%);
    transition: left 0.15s ease;
}

.abfm-bp-toggle-switch.is-on::after {
    left: 11px;
}

.abfm-bp.is-loading .abfm-bp-toggle-switch {
    cursor: default;
}

/* Result column */
.abfm-bp-run,
.abfm-bp-clear {
    width: 100%;
    margin: 0 0 12px;
    padding: 8px;
    border: 0;
    border-radius: 3px;
    color: #fff;
    font: inherit;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: normal;
    cursor: pointer;
}

.abfm-bp-run {
    background: var(--color-accent);
}

.abfm-bp-clear {
    background: var(--color-error);
}

.abfm-bp-run:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.abfm-bp-result-body {
    position: relative;
    display: flex;
    flex: 1;
    flex-direction: column;
}

.abfm-bp-result .abfm-bp-row {
    grid-template-columns: 4.5em minmax(0, 1fr);
}

.abfm-bp-result .abfm-bp-tag {
    display: none;
}

.abfm-bp-likelihood {
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 5.5em;
    padding: 8px 4px;
    border: 1px solid var(--color-border);
    background: var(--color-container-bg);
    text-align: center;
}

.abfm-bp-likelihood-value {
    color: var(--color-secondary);
    font-size: 1.4rem;
    font-weight: 700;
    line-height: 1.1;
}

.abfm-bp-likelihood-label {
    font-size: 0.6rem;
    font-weight: 700;
}

/* Status */
.abfm-bp-error {
    margin: 0 0 12px;
    color: var(--color-error);
    text-align: center;
}

.abfm-bp-disclaimer {
    margin-top: 12px;
    font-size: 1rem;
    font-style: italic;
}

.abfm-bp-loading {
    position: absolute;
    top: 45%;
    left: 50%;
    z-index: 2;
    transform: translate(-50%, -50%);
}

/* Same spinner as Find a Physician (find-physician.css), repeated so it works when that CSS isn't loaded. */
.abfm-bp .spinner-loader {
    width: 48px;
    height: 48px;
    border: 5px solid;
    border-color: var(--color-accent) transparent;
    border-radius: 50%;
    display: inline-block;
    box-sizing: border-box;
    animation: abfm-bp-rotation 1s linear infinite;
}

@keyframes abfm-bp-rotation {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Narrow screens: stack the charts */
@media (max-width: 1024px) {
    .abfm-bp-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .abfm-bp-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .abfm-bp-heading {
        min-height: 0;
    }

    .abfm-bp-bars {
        --abfm-bp-row-font: 0.75rem;
    }
}
