@use 'variables' as *;

// ─── View controls bar ────────────────────────────────────────────────────────
.view-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.view-controls-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.view-controls-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.reset-scores-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 13px;
    font-size: 0.82rem;
    font-weight: 600;
    color: $gray-500;
    background: $gray-50;
    border: $border-width solid $border-color;
    border-radius: 10px;
    cursor: pointer;
    @include quick-transition(border-color, color, background);

    &:hover:not(:disabled) {
        border-color: $red-pale;
        color: $red-primary;
        background: $red-ghost;
    }

    &:disabled {
        opacity: 0.45;
        cursor: not-allowed;
    }
}

// ─── List wrapper ─────────────────────────────────────────────────────────────
.list-wrap {
    overflow-x: auto;
    border-radius: 14px;
    border: $border-width solid $border-color;
    background: $white;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}

// ─── Sticky header clone (JS-managed fixed replica of <thead>) ────────────────
.list-sticky-clone {
    position: fixed;
    overflow: hidden;
    z-index: 50;

    // Inner wrapper that clips the table's top corners. It is also a real
    // scrollport: the JS sets its scrollLeft from .list-wrap, which is what
    // lets position:sticky pin the same columns here as in the live table.
    &__inner {
        border-radius: 8px 8px 0 0;
        overflow: hidden;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);

        table {
            margin: 0;
        }
    }
}

// ─── Table ────────────────────────────────────────────────────────────────────
.charity-list {
    width: 100%;
    // `separate` (not `collapse`) is required for the pinned name/rating
    // columns: collapsed borders drop out from under position:sticky cells.
    // Every border below is therefore set on the cell, never the row.
    border-collapse: separate;
    border-spacing: 0;
    // Grow to fit the widest lens, but never force a scrollbar on a narrow one.
    min-width: max-content;

    thead {
        background: linear-gradient(135deg, $red-primary 0%, $red-dark 100%);

        th {
            padding: 13px 8px;
            font-size: 0.65rem;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 0.08em;
            color: rgb(from var(--white) r g b / 0.9);
            text-align: left;
            white-space: nowrap;

            &:first-child {
                padding-left: 18px;
            }

            &:last-child {
                padding-right: 18px;
            }

            &.col-score,
            &.col-composite {
                text-align: center;
                padding-left: 4px;
                padding-right: 4px;
            }

            &.col-stars {
                text-align: center;
            }

            &.col-composite,
            &.col-stars {
                background: rgba(0, 0, 0, 0.22);
            }

            &.col-group-start {
                border-left: 2px solid rgba(0, 0, 0, 0.38);
            }

            &.col-group-end {
                border-right: 2px solid rgba(0, 0, 0, 0.38);
            }

        }
    }

    tbody {
        td {
            padding: 5px 8px;
            vertical-align: middle;

            &:first-child {
                padding-left: 18px;
            }

            &:last-child {
                padding-right: 18px;
            }

            &.col-composite,
            &.col-stars {
                background: #fdeeed;
            }

            &.col-group-start {
                border-left: 2px solid $red-primary;
            }

            &.col-group-end {
                border-right: 2px solid $red-primary;
            }
        }
    }

    // ── Weight row ──────────────────────────────────────────────────────────
    .weight-row,
    .weight-row td {
        background: #f8f3f3;
    }

    .weight-row td {
        padding: 6px 8px;
        border-bottom: 1.5px solid rgb(from var(--red-primary) r g b / 0.12);

        &:first-child {
            padding-left: 18px;
        }

        &.col-composite,
        &.col-stars {
            background: #fbd8d8;
        }

        &.col-group-start {
            border-left: 2px solid $red-primary;
        }

        &.col-group-end {
            border-right: 2px solid $red-primary;
        }
    }
}

// ─── Column widths ────────────────────────────────────────────────────────────
.col-name {
    min-width: 170px;
}

.col-num {
    width: 1px;
    white-space: nowrap;
    text-align: center;
}

.col-score {
    width: 58px;
    text-align: center;
    padding-left: 4px !important;
    padding-right: 4px !important;
}

.col-composite {
    width: 72px;
    text-align: center;
    padding-left: 12px !important;
    padding-right: 12px !important;
}

.col-stars {
    width: 90px;
    text-align: center;
}

.col-link {
    width: 1px;
    white-space: nowrap;
    text-align: center;
}

// ─── Document link cell ───────────────────────────────────────────────────────
// A link column has room for one report and no more, so the cell is a small
// button: the icon says "document", the label says which year it covers, and
// the title attribute carries the rest. Every report a charity has is listed
// on its detail page.
.list-doc {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 9px;
    font-size: 0.76rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: $gray-600;
    background: $gray-50;
    border: $border-width solid $border-color;
    border-radius: 8px;
    text-decoration: none;
    @include quick-transition(border-color, color, background);

    &:hover {
        border-color: $red-pale;
        color: $red-primary;
        background: $red-ghost;
    }

    &:focus-visible {
        outline: 2px solid $red-primary;
        outline-offset: 2px;
    }
}

.list-doc__icon {
    flex: none;
    opacity: 0.75;
}

.list-doc__empty {
    color: $gray-400;
}

// ─── Row ──────────────────────────────────────────────────────────────────────
.list-row {
    cursor: pointer;
    transition: background 0.1s;

    // Row rule lives on the cells — see the border-collapse note above.
    > td {
        border-bottom: 1px solid #f0f0f5;
    }

    // Every list row is trailed by its (usually hidden) detail row, so the
    // last visible row is the second-to-last child.
    &:last-child > td,
    &:nth-last-child(2) > td {
        border-bottom: none;
    }

    &:hover {
        background: $red-ghost;

        td.col-composite,
        td.col-stars {
            background: $red-ghost;
        }

        .list-name {
            color: $red-primary;
        }
    }
}

// ─── Name cell ────────────────────────────────────────────────────────────────
.list-name-cell {
    display: flex;
    align-items: center;
    gap: 10px;
}

.list-logo-wrap {
    flex-shrink: 0;
    width: 62px;
    height: 40px;
    border-radius: 5px;
    overflow: hidden;
    border: 1px solid $border-color;
    background: $white;
}

.list-logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.list-logo-initials {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #d4d4d8;
    color: #71717a;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.list-name {
    font-weight: 700;
    color: $navy;
    font-size: 0.84rem;
    line-height: 1.3;
    transition: color 0.1s;

    // Without this the name is a flex item at its max-content width, which
    // sizes the whole column to the single longest charity name. The row is
    // tall enough for two lines (the logo is 58px), so wrap instead and clamp
    // the rare third line — the full name is on the row's title attribute.
    min-width: 0;
    max-width: 230px;
    overflow-wrap: anywhere;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
}

.list-ein {
    font-size: 0.67rem;
    color: $gray-400;
    font-family: $font-mono;
    margin-top: 2px;
}

// ─── Numeric cell ─────────────────────────────────────────────────────────────
.list-value {
    font-size: 0.84rem;
    font-weight: 700;
    color: $navy;
}

// ─── Score badges ─────────────────────────────────────────────────────────────
.list-score-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 0.7rem;
    font-weight: 800;
    color: $white;
    position: relative;

    &.score-modified::after {
        content: '';
        position: absolute;
        top: -3px;
        right: -3px;
        width: 9px;
        height: 9px;
        background: $red-primary;
        border-radius: 50%;
        border: 1.5px solid $white;
        pointer-events: none;
    }
}

.list-composite {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 0.85rem;
    font-weight: 800;
    color: $white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.22);
}

.col-composite {
    .star-rating--under-circle {
        margin-top: 4px;
        font-size: 0.85rem;
        line-height: 1;
    }
}

// ─── Column header tooltip badge ──────────────────────────────────────────────
.th-info {
    color: rgb(from var(--white) r g b / 0.6);
    font-size: 0.78rem;
    font-style: normal;
    font-weight: 400;
    cursor: default;
    margin-left: 2px;
    vertical-align: middle;
    transition: color 0.1s;

    &:hover {
        color: $white;
    }
}

// ─── Column headers ───────────────────────────────────────────────────────────
.charity-list thead th {
    // Non-sortable headers that carry a tooltip signal hoverability.
    &[data-tooltip]:not(.sort-col) {
        cursor: help;
    }

    &.sort-col {
        cursor: pointer;
        user-select: none;

        &:hover {
            background: rgb(from var(--white) r g b / 0.12);
        }
    }

    &.sort-active {
        color: $white;
    }
}

.sort-icon {
    vertical-align: middle;
    margin-left: 3px;
    flex-shrink: 0;

    &--idle {
        color: rgb(from var(--white) r g b / 0.8);
    }

    &--active {
        color: $white;
    }
}

// ─── Floating tooltip popup ───────────────────────────────────────────────────
.th-tooltip-popup {
    position: fixed;
    background: #1e293b;
    color: #f8fafc;
    font-size: 0.75rem;
    font-weight: 400;
    line-height: 1.45;
    padding: 6px 10px;
    border-radius: 5px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.12s;
    z-index: $z-tooltip;
    max-width: 240px;
    white-space: normal;
    text-align: left;
    transform: translate(-50%, calc(-100% - 8px));

    &.is-visible {
        opacity: 1;
    }
}

// ─── Weight row label & badge ─────────────────────────────────────────────────

// The label sits in the first weight cell that has no badge, which is whichever
// column the active lens happens to put first. Left in flow it sets that
// column's width: make Size the first column and a 60px figure column is
// stretched to fit "Weights / significance". Taking it out of flow lets it run
// across the empty weight cells to its right instead — positioned content
// paints above table-cell backgrounds, and the pinned cells (z-index 3) still
// cover it at either edge. `padding-left: inherit` picks up whatever padding
// the cell has at this breakpoint, so it stays aligned with the column below.
.charity-list .weight-row td:not(.col-pin-l):not(.col-pin-r) {
    position: relative; // sticky cells are already a containing block
}

// With the label out of flow its cell has no content, so a lens whose columns
// carry no weight badge at all would collapse the row to its padding. A
// zero-width strut holds the height without holding any width.
.charity-list .weight-row td:has(> .weight-row-label)::after {
    content: '';
    display: inline-block;
    width: 0;
    height: 1.3em;
    vertical-align: middle;
}

.weight-row-label {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    padding-left: inherit;
    z-index: 1;
    white-space: nowrap;
    text-align: left;
    pointer-events: none;
    font-size: 0.62rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: $gray-400;
}

.weight-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 7px;
    border-radius: 6px;
    font-size: 0.68rem;
    font-weight: 700;
    background: $gray-100;
    color: $gray-700;
    cursor: pointer;
    border: $border-width solid $border-color;
    @include quick-transition(background, border-color, color);
    user-select: none;

    &:hover {
        background: $red-ghost;
        border-color: $red-pale;
        color: $red-primary;
    }

    &.weight-modified {
        background: $red-ghost;
        border-color: $red-primary;
        color: $red-primary;
    }
}

// ─── Star rating ──────────────────────────────────────────────────────────────
.star-rating {
    position: relative;
    display: inline-block;
    font-size: 1.2rem;
    line-height: 1;
    white-space: nowrap;
    // Keep bg text left-anchored so the absolute fg overlay (left:0) always
    // aligns, even if the box ever stretches (e.g. display:block in a centered cell).
    text-align: left;
}

.stars-bg {
    color: $gray-300;
}

.stars-fg {
    position: absolute;
    top: 0;
    left: 0;
    overflow: hidden;
    color: $red-primary;
    white-space: nowrap;
}

// ─── Empty state ──────────────────────────────────────────────────────────────
.empty-state {
    padding: 48px 24px;
    text-align: center;
    color: $gray-400;
    font-size: 0.95rem;
}

// ─── Responsive shrink ────────────────────────────────────────────────────────
@media (max-width: 1280px) {
    .charity-list {
        thead th {
            padding: 11px 6px;

            &:first-child {
                padding-left: 14px;
            }

            &:last-child {
                padding-right: 14px;
            }
        }

        tbody td {
            padding: 5px 6px;

            &:first-child {
                padding-left: 14px;
            }

            &:last-child {
                padding-right: 14px;
            }
        }

        .weight-row td {
            &:first-child {
                padding-left: 14px;
            }
        }
    }

    .list-logo-wrap {
        width: 54px;
        height: 36px;
    }

    .list-score-badge {
        width: 26px;
        height: 26px;
        font-size: 0.68rem;
    }

    .list-composite {
        width: 36px;
        height: 36px;
        font-size: 0.8rem;
    }

    .star-rating {
        font-size: 1.05rem;
    }

    .list-name {
        font-size: 0.8rem;
    }

    .list-value {
        font-size: 0.8rem;
    }
}

@media (max-width: 1024px) {
    .charity-list {
        min-width: 820px;

        thead th {
            padding: 9px 4px;
            font-size: 0.6rem;
            letter-spacing: 0.05em;

            &:first-child {
                padding-left: 10px;
            }

            &:last-child {
                padding-right: 10px;
            }
        }

        tbody td {
            padding: 4px 4px;

            &:first-child {
                padding-left: 10px;
            }

            &:last-child {
                padding-right: 10px;
            }
        }

        .weight-row td {
            padding: 5px 4px;

            &:first-child {
                padding-left: 10px;
            }
        }
    }

    .list-logo-wrap {
        width: 46px;
        height: 30px;
        border-radius: 4px;
    }

    .list-logo-initials {
        font-size: 0.6rem;
    }

    .list-name-cell {
        gap: 7px;
    }

    .list-score-badge {
        width: 24px;
        height: 24px;
        font-size: 0.62rem;
    }

    .col-score {
        width: 46px;
    }

    .list-composite {
        width: 32px;
        height: 32px;
        font-size: 0.74rem;
    }

    .col-composite {
        width: 58px;
    }

    .star-rating {
        font-size: 0.92rem;
    }

    .col-stars {
        width: 74px;
    }

    .list-name {
        font-size: 0.77rem;
    }

    .list-value {
        font-size: 0.77rem;
    }

    .col-name {
        min-width: 140px;
    }
}

// ─── "Show more" ──────────────────────────────────────────────────────────────
.list-more {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-top: 18px;
}

.list-more__btn {
    font: inherit;
    font-size: 0.84rem;
    font-weight: 700;
    color: $gray-700;
    background: $white;
    border: $border-width solid $border-color;
    border-radius: 10px;
    padding: 10px 26px;
    cursor: pointer;
    @include quick-transition(border-color, color, background);

    &:hover:not(:disabled) {
        border-color: $red-pale;
        color: $red-primary;
        background: $red-ghost;
    }

    &:disabled {
        opacity: 0.6;
        cursor: progress;
    }
}

.list-more__count {
    @include section-label;
    margin: 0;
}

// ─── Column lenses ────────────────────────────────────────────────────────────
// Named column sets (admin: Content → Column Lenses). Switching lens is a
// Livewire round trip and writes ?lens=… so a view can be shared.
.list-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
}

.lens-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.lens-chip {
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    color: $gray-500;
    background: $white;
    border: $border-width solid $border-color;
    border-radius: 999px;
    padding: 6px 14px;
    cursor: pointer;
    @include quick-transition(background, border-color, color);

    &:hover {
        border-color: $red-pale;
        color: $red-primary;
        background: $red-ghost;
    }

    &--active,
    &--active:hover {
        background: $red-primary;
        border-color: $red-primary;
        color: $white;
    }
}

// ─── Per-visitor controls: bar switch + column picker ─────────────────────────
.list-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.list-control {
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    color: $gray-500;
    background: $white;
    border: $border-width solid $border-color;
    border-radius: 10px;
    padding: 6px 12px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    @include quick-transition(border-color, color);

    &:hover {
        border-color: $red-pale;
        color: $red-primary;
    }

    &:focus-visible {
        outline: 2px solid $red-primary;
        outline-offset: 2px;
    }
}

.list-control__track {
    width: 30px;
    height: 17px;
    border-radius: 999px;
    background: $gray-300;
    position: relative;
    flex-shrink: 0;
    @include quick-transition(background);

    &::after {
        content: '';
        position: absolute;
        top: 2px;
        left: 2px;
        width: 13px;
        height: 13px;
        border-radius: 50%;
        background: $white;
        @include quick-transition(transform);
    }
}

.list-control[aria-pressed='true'] {
    color: $red-primary;
    border-color: $red-pale;

    .list-control__track {
        background: $red-primary;

        &::after {
            transform: translateX(13px);
        }
    }
}

.list-colpicker {
    position: relative;
}

.list-colmenu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: $z-dropdown;
    width: 232px;
    max-height: 320px;
    overflow-y: auto;
    background: $white;
    border: $border-width solid $border-color;
    border-radius: 12px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.13);
    padding: 8px;

    &__head {
        @include section-label(0.1em);
        font-size: 0.62rem;
        margin: 0;
        padding: 6px 8px 4px;
    }

    label {
        display: flex;
        align-items: center;
        gap: 9px;
        font-size: 0.8rem;
        color: $gray-700;
        padding: 6px 8px;
        border-radius: 7px;
        cursor: pointer;

        &:hover {
            background: $gray-50;
        }

        &.is-locked {
            opacity: 0.55;
            cursor: not-allowed;
        }

        em {
            margin-left: auto;
            font-size: 0.62rem;
            font-style: normal;
            color: $gray-400;
        }
    }

    &__reset {
        font: inherit;
        font-size: 0.74rem;
        font-weight: 600;
        width: 100%;
        margin-top: 6px;
        padding: 7px 8px;
        color: $gray-500;
        background: none;
        border: 0;
        border-top: 1px solid $border-color;
        border-radius: 0 0 7px 7px;
        cursor: pointer;
        text-align: left;
        @include quick-transition(color, background);

        &:hover {
            color: $red-primary;
            background: $red-ghost;
        }
    }
}

// ─── Pinned columns ───────────────────────────────────────────────────────────
// Only bite when the table is wider than its wrapper. The edge shadows are
// toggled by charity-list-expand.js so they never show without overflow.
.col-pin-l,
.col-pin-r {
    position: sticky;
    z-index: 3;
    background: $white;
}

.col-pin-l { left: 0; }
.col-pin-r { right: 0; }

// Header cells must be fully opaque: the unpinned ones scroll underneath.
// These mirror the two ends of the thead gradient.
.charity-list thead th.col-pin-l { background: $red-primary; }
.charity-list thead th.col-pin-r { background: $red-dark; }

.charity-list .weight-row td.col-pin-l,
.charity-list .weight-row td.col-pin-r {
    background: #f8f3f3;
}

.charity-list .weight-row td.col-composite.col-pin-r,
.charity-list .weight-row td.col-stars.col-pin-r {
    background: #fbd8d8;
}

.charity-list tbody td.col-composite.col-pin-r,
.charity-list tbody td.col-stars.col-pin-r {
    background: #fdeeed;
}

.list-row:hover > td.col-pin-l,
.list-row:hover > td.col-pin-r {
    background: $red-ghost;
}

.list-wrap.is-scrolled-x .col-pin-l::after,
.list-wrap.has-scroll-right .col-pin-r::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 14px;
    pointer-events: none;
}

.list-wrap.is-scrolled-x .col-pin-l::after {
    right: -14px;
    background: linear-gradient(90deg, rgb(from var(--navy) r g b / 0.13), rgb(from var(--navy) r g b / 0));
}

.list-wrap.has-scroll-right .col-pin-r::after {
    left: -14px;
    background: linear-gradient(270deg, rgb(from var(--navy) r g b / 0.13), rgb(from var(--navy) r g b / 0));
}

// ─── In-cell magnitude bars ───────────────────────────────────────────────────
// Toggled per column with ColumnTooltip.show_bar; width comes from
// CharityPresenter::barPercent(), scaled to the largest value on screen.
.list-figure {
    display: inline-flex;
    flex-direction: column;
    gap: 4px;
    min-width: 68px;
}

.list-figure .list-value {
    font-variant-numeric: tabular-nums;
}

.list-bar {
    display: block;
    height: 3px;
    border-radius: 2px;
    background: $gray-200;
    overflow: hidden;

    > i {
        display: block;
        height: 100%;
        border-radius: 2px;
        background: $navy;
    }
}

// ─── Row expander ─────────────────────────────────────────────────────────────
.list-expander {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: $white;
    border: $border-width solid $border-color;
    border-radius: 6px;
    color: $gray-500;
    cursor: pointer;
    @include quick-transition(transform, border-color, color);

    &:hover {
        border-color: $red-pale;
        color: $red-primary;
    }

    &:focus-visible {
        outline: 2px solid $red-primary;
        outline-offset: 2px;
    }

    &[aria-expanded='true'] {
        transform: rotate(90deg);
        border-color: $red-pale;
        color: $red-primary;
    }
}

// ─── Expanded detail row ──────────────────────────────────────────────────────
// Outranks the tbody td :first-child/:last-child padding rules above.
.charity-list tbody .list-detail-row > td {
    padding: 0;
    background: #fff8f8;
    border-bottom: $border-width solid $border-color;
}

// The panel stays inside the visible width instead of stretching to the full
// scrolled table width. --list-visible-width is the wrapper's clientWidth, set
// by charity-list-expand.js; the 100% fallback keeps it usable without JS.
.list-detail {
    position: sticky;
    left: 0;
    width: var(--list-visible-width, 100%);
    padding: 18px 20px 18px 56px;
    white-space: normal;
}

.list-detail__grid {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr);
    gap: 26px;
}

.list-detail__block {
    min-width: 0;
}

.list-detail__head {
    @include section-label(0.1em);
    font-size: 0.64rem;
    margin: 0 0 10px;
}

.list-detail__foot {
    font-size: 0.72rem;
    color: $gray-500;
    margin: 8px 0 0;
    line-height: 1.5;

    b {
        color: $navy;
        font-weight: 700;
    }
}

.detail-na {
    color: $gray-400;
    font-style: italic;
}

// 4R build-up
.detail-pillar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 84px 62px;
    align-items: center;
    gap: 10px;
    margin-bottom: 7px;
}

.detail-pillar__label {
    font-size: 0.76rem;
    font-weight: 700;
    color: $navy;
    line-height: 1.25;
}

.detail-pillar__note {
    display: block;
    font-size: 0.66rem;
    font-weight: 400;
    color: $gray-500;
}

.detail-pillar__track {
    height: 8px;
    border-radius: 4px;
    background: $gray-100;
    overflow: hidden;

    > i {
        display: block;
        height: 100%;
        border-radius: 4px;
    }
}

.detail-pillar__pts {
    font-size: 0.78rem;
    font-weight: 700;
    color: $navy;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.detail-pillar__of {
    color: $gray-400;
    font-weight: 600;
}

// Fact grids
.detail-facts {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 16px;
}

.detail-fact__k {
    font-size: 0.62rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: $gray-400;
}

.detail-fact__v {
    font-size: 0.84rem;
    font-weight: 700;
    color: $navy;
    font-variant-numeric: tabular-nums;
}

.detail-meter {
    margin-top: 12px;
}

.detail-meter__row {
    display: flex;
    justify-content: space-between;
    font-size: 0.74rem;
    color: $gray-500;
    margin-bottom: 4px;

    b {
        color: $navy;
        font-variant-numeric: tabular-nums;
    }
}

.detail-meter__track {
    height: 8px;
    border-radius: 4px;
    background: $gray-100;
    overflow: hidden;

    > i {
        display: block;
        height: 100%;
        border-radius: 4px;
        background: $indigo;
    }
}

// Governance signals
.detail-flags {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 12px;
}

.detail-flag {
    font-size: 0.67rem;
    font-weight: 600;
    border-radius: 999px;
    padding: 2px 9px;
    background: $gray-100;
    color: $gray-400;
    border: 1px solid $border-color;

    &--yes {
        background: rgb(from var(--green) r g b / 0.1);
        color: $green;
        border-color: rgb(from var(--green) r g b / 0.3);
    }
}

.list-detail__cta {
    display: flex;
    justify-content: flex-end;
    margin-top: 14px;

    a {
        font-size: 0.78rem;
        font-weight: 700;
        color: $red-primary;
        text-decoration: none;
        border-bottom: $border-width solid $red-pale;
        padding-bottom: 1px;

        &:hover {
            border-color: $red-primary;
        }
    }
}

@media (max-width: $bp-tablet) {
    .list-detail {
        padding: 16px;
    }

    .list-detail__grid {
        grid-template-columns: minmax(0, 1fr);
        gap: 20px;
    }

    // ── Phones ───────────────────────────────────────────────────────────
    // The pinned name and appraisal columns are always on screen, so their
    // width is subtracted from the viewport before anything can scroll. At
    // the 1024px sizes that came to roughly 390px on a 390px phone: the name
    // column filled the screen and there was nothing to scroll *to*.

    .charity-list {
        // Undo the 1024px floor. Any fixed minimum is worse than none here:
        // every other column has a set width, so the name column is the only
        // one that can absorb slack — a 560px floor on a 324px scrollport
        // simply made the name cell 307px wide and there was still nothing to
        // scroll. Sizing to content lets it be as narrow as its text.
        min-width: max-content;

        thead th,
        tbody td,
        .weight-row td {
            padding-left: 3px;
            padding-right: 3px;
        }

        thead th:first-child,
        tbody td:first-child,
        .weight-row td:first-child {
            padding-left: 8px;
        }

        thead th:last-child,
        tbody td:last-child {
            padding-right: 8px;
        }
    }

    // Swiping lands on a column boundary instead of halfway through one.
    // `proximity`, not `mandatory`: the visitor stays in charge, and a
    // half-swipe that was meant to peek does not get yanked onward. The
    // padding keeps the snapped column clear of the pinned name cell —
    // charity-list-expand.js measures it into --list-pin-left.
    .list-wrap {
        scroll-snap-type: x proximity;
        scroll-padding-left: var(--list-pin-left, 0px);
    }

    // One snap point per column, taken from the header rather than from every
    // cell in the body — same positions, a fraction of the work.
    .charity-list thead th:not(.col-pin-l):not(.col-pin-r) {
        scroll-snap-align: start;
    }

    // Full bleed. Two nested 16px paddings cost 64px of a 390px screen —
    // a fifth of the scrollport — and a table is the one thing on the page
    // that has a use for every pixel. The toolbar above it stays inset.
    .list-wrap {
        margin-left: -32px;
        margin-right: -32px;
        width: calc(100% + 64px);
        border-radius: 0;
        border-left: 0;
        border-right: 0;
    }

    // The first thing to go. It is decoration, and it was spending 60px of a
    // 390px screen inside the one column that can never be scrolled away.
    .list-logo-wrap {
        display: none;
    }

    .col-name {
        min-width: 0;
    }

    .list-name-cell {
        gap: 6px;
    }

    .list-name {
        max-width: 118px;
        font-size: 0.74rem;
    }

    .list-value {
        font-size: 0.74rem;
    }

    .list-figure {
        min-width: 52px;
    }

    // The appraisal is pinned too, so it comes out of the same budget.
    .col-composite {
        width: 50px;
        padding-left: 6px !important;
        padding-right: 6px !important;
    }

    .list-composite {
        width: 34px;
        height: 34px;
        font-size: 0.72rem;
    }

    .col-stars {
        width: 62px;
    }

    .star-rating {
        font-size: 0.8rem;
    }

    .list-score-badge {
        width: 24px;
        height: 24px;
        font-size: 0.62rem;
    }

    .col-score {
        width: 38px;
    }

    // ── Toolbar buttons ──────────────────────────────────────────────────
    // Four buttons side by side do not fit; laid out in a row they either
    // overflow or squeeze their labels to nothing. One per line instead.
    .view-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .view-controls-left,
    .view-controls-right {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        width: 100%;
    }

    // .add-custom-score-btn is styled in _custom-score.scss, but it shares
    // this bar and has to stack with the rest of it.
    .view-controls .reset-scores-btn,
    .view-controls .add-custom-score-btn {
        width: 100%;
        justify-content: center;
    }
}
