@use 'variables' as *;

// ─── Nav bar (back button + mode toggle) ─────────────────────────────────────
.detail-nav-bar {
    max-width: 820px;
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;

    .back-btn-wrap { margin: 0; }
}

// ─── Back button ──────────────────────────────────────────────────────────────
.back-btn-wrap {
    max-width: 820px;
    margin: 0 auto 16px;
}

.back-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 16px 8px 12px;
    background: $white;
    border: $border-width solid $border-color;
    border-radius: 20px;
    color: $gray-700;
    font-size: 0.84rem;
    font-weight: 600;
    text-decoration: none;
    @include quick-transition(border-color, background, color, box-shadow);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);

    &:hover {
        border-color: $red-primary;
        color: $red-primary;
        background: #fff5f5;
        box-shadow: 0 2px 8px rgb(from var(--red-primary) r g b / 0.12);
    }

    svg { transition: transform 0.15s; }

    &:hover svg { transform: translateX(-2px); }
}

// ─── Mode switch (Basic / Advanced) ──────────────────────────────────────────
.mode-switch {
    display: flex;
    align-items: center;
    background: $gray-100;
    border: $border-width solid $border-color;
    border-radius: 20px;
    padding: 3px;
    gap: 2px;
}

.mode-btn {
    position: relative;
    padding: 6px 15px;
    border: none;
    border-radius: 16px;
    background: transparent;
    color: $gray-500;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    letter-spacing: 0.01em;
    transition: color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease, transform 0.12s ease;

    &:not(.mode-active):hover {
        color: $gray-700;
        background: rgb(from var(--white) r g b / 0.6);
    }

    &:active { transform: scale(0.94); }

    &.mode-active {
        background: $white;
        color: $gray-900;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1), 0 0 0 $border-width $border-color;

        &:active { transform: scale(0.96); }
    }
}

// ─── Detail card ──────────────────────────────────────────────────────────────
.detail-card {
    max-width: 820px;
    margin: 0 auto;
    background: $white;
    border: $border-width solid $border-color;
    border-radius: 16px;
    overflow: hidden;

    > * {
        border-bottom: $border-width solid $gray-100;
        padding: 24px 28px;
    }

    > *:last-child { border-bottom: none; }

    // Org header override for detail layout
    .org-header {
        padding: 28px 32px 40px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 24px;
    }

    // Spacing between weight row and bars
    .score-bars { margin-top: 18px; }

    // Modified score indicator on bar track
    .score-bar-wrap:has(.score-bar-fill.score-modified) {
        overflow: visible;

        &::after {
            content: '';
            position: absolute;
            top: -4px;
            right: -4px;
            width: 10px;
            height: 10px;
            background: $red-primary;
            border-radius: 50%;
            border: 2px solid $white;
            pointer-events: none;
            z-index: 2;
        }
    }
}

// ─── Org header text / logo layout ───────────────────────────────────────────
.org-header-text {
    flex: 1;
    min-width: 0;
}

// ─── Where to find them (website + social profiles, in the red header) ───────
// Sits directly under the mono meta line, so the header reads identity →
// filing facts → where the charity speaks for itself. Chips rather than bare
// icons: a globe alone does not say which site it opens, and the handle is
// what a reader recognises.
.org-social {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}

.org-social__link {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 12px 6px 10px;
    // Translucent white, not a solid fill: the header is a gradient and a
    // flat chip colour banks against it at one end.
    background: rgb(from var(--white) r g b / 0.14);
    border: $border-width solid rgb(from var(--white) r g b / 0.28);
    border-radius: 20px;
    color: $white;
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1.2;
    text-decoration: none;
    @include quick-transition(background, border-color, transform, box-shadow);

    &:hover {
        background: rgb(from var(--white) r g b / 0.26);
        border-color: rgb(from var(--white) r g b / 0.55);
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.14);
    }

    &:active { transform: scale(0.97); }

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

.org-social__icon {
    flex: none;
    opacity: 0.95;
}

.org-social__handle {
    // The address the chip opens: present but secondary to the platform name.
    font-family: $font-mono;
    font-size: 0.72rem;
    font-weight: 500;
    opacity: 0.75;
    max-width: 15ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;

    &::before {
        content: '·';
        margin-right: 6px;
        opacity: 0.7;
    }
}

@media (max-width: $bp-mobile) {
    // Four chips with handles do not fit a phone; the icon and the platform
    // name still say where each one goes.
    .org-social__handle { display: none; }

    .org-social { gap: 6px; }

    .org-social__link {
        padding: 6px 11px 6px 9px;
        font-size: 0.76rem;
    }
}

.org-logo-wrap {
    flex-shrink: 0;
    background: $white;
    border-radius: 10px;
    padding: 10px;
    align-self: flex-start;
    margin-top: 4px;
}

.org-logo {
    display: block;
    width: 100px;
    height: 80px;
    object-fit: contain;
}

// ─── Score weight row ─────────────────────────────────────────────────────────
.score-weight-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding-bottom: 16px;
    margin-bottom: 2px;
    border-bottom: 1px solid #f0f0f2;
}

.score-weight-badges {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.score-weight-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}

.score-weight-item-label {
    font-size: 0.62rem;
    color: $gray-400;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

// ─── Religious note ───────────────────────────────────────────────────────────
.religious-note {
    margin-top: 14px;
    font-size: 0.75rem;
    color: $gray-400;
}

// ─── Programs / mission section ───────────────────────────────────────────────
.programs-section {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.program-block-title {
    @include section-label;
    margin-bottom: 6px;
}

.program-text {
    font-size: 0.9rem;
    line-height: 1.65;
    color: $gray-700;
}

// ─── Editorial description (rich content above mission) ───────────────────────
.charity-description {
    margin-bottom: 26px;
    font-size: 0.9rem;
    line-height: 1.65;
    color: $gray-700;

    h2 { font-size: 1.15rem; margin: 18px 0 8px; }
    h3 { font-size: 1rem; margin: 16px 0 6px; }
    h2:first-child, h3:first-child, p:first-child { margin-top: 0; }

    p { margin: 0 0 10px; }

    a {
        color: var(--color-primary, #2563eb);
        text-decoration: underline;
    }

    // Document references bring their own colour and shape — without this the
    // generic rule above wins on specificity and underlines them in blue.
    a.doc-chip {
        color: $red-primary;
        text-decoration: none;

        &.doc-chip--missing { color: $gray-500; }
    }

    a.doc-cta {
        color: $gray-700;
        text-decoration: none;

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

    ul, ol { margin: 0 0 10px; padding-left: 1.4em; }

    blockquote {
        margin: 0 0 12px;
        padding-left: 14px;
        border-left: 3px solid $gray-200;
        color: $gray-500;
    }

    img {
        max-width: 100%;
        height: auto;
        border-radius: 8px;
    }

    // Side-by-side Columns custom block
    .rc-columns {
        display: flex;
        flex-wrap: wrap;
        gap: 16px;
        margin: 14px 0;
    }

    .rc-column {
        // --col-grow is the per-column relative width set in the editor (1–3);
        // flex-basis 0 makes the grow weights distribute width proportionally.
        flex: var(--col-grow, 1) 1 0;
        min-width: 180px;

        img { display: block; width: 100%; }
    }

    .rc-column-text {
        margin: 8px 0 0;
        font-size: 0.9rem;
        line-height: 1.6;
        color: $gray-700;
    }
}

// ─── Reports & documents ──────────────────────────────────────────────────────
// The full list of what the charity publishes; the homepage link column shows
// only the newest of one kind, because a table cell has room for one button.
.documents-section {
    margin-bottom: 26px;
}

.documents-title {
    @include section-label;
    margin-bottom: 16px;
}

.documents-group {
    margin-bottom: 16px;

    &:last-of-type {
        margin-bottom: 0;
    }
}

.documents-group__label {
    margin-bottom: 8px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: $gray-400;
}

.documents-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 10px;
}

// The card, plus — when we serve a copy rather than the charity's own server
// — the address that copy was taken from underneath it. A sibling, because
// the card is itself an anchor.
.documents-item {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.doc-origin {
    padding-left: 4px;
    font-size: 0.68rem;
    color: $gray-400;
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;

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

.doc-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: $gray-50;
    border: $border-width solid $border-color;
    border-radius: 10px;
    text-decoration: none;
    color: $gray-700;
    @include quick-transition(border-color, color, background);

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

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

.doc-link__icon {
    flex: none;
    opacity: 0.7;
}

.doc-link__text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.doc-link__title {
    font-size: 0.86rem;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.doc-link__meta {
    font-size: 0.72rem;
    color: $gray-400;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.documents-note {
    margin-top: 12px;
    font-size: 0.72rem;
    color: $gray-400;
}

// ─── Document references inside the description ───────────────────────────────
// Written as merge tags in the rich editor and rendered from the row
// (partials/documents/*.blade.php), so a reference in the prose keeps pointing
// at the right file — including at a copy held here — with no edit to the text.

.doc-chip {
    display: inline-flex;
    align-items: baseline;
    gap: 5px;
    padding: 1px 9px 2px;
    // Keeps the pill from stretching the line it sits in.
    margin: 0 1px;
    background: $red-ghost;
    border: $border-width solid $red-pale;
    border-radius: 9999px;
    font-size: 0.82rem;
    font-weight: 600;
    line-height: 1.45;
    color: $red-primary;
    text-decoration: none;
    @include quick-transition(background, border-color, color);

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

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

// Masked spans rather than inline <svg>: this markup is rendered through the
// rich editor's own pipeline, which sanitises with Symfony's
// allowSafeElements() and drops svg entirely. class and style survive, so the
// shape lives here.
@mixin masked-icon($mask) {
    background-color: currentColor;
    -webkit-mask: #{$mask} no-repeat center / contain;
    mask: #{$mask} no-repeat center / contain;
}

.doc-chip__icon {
    flex: none;
    // Baseline alignment lands the icon a touch high next to the label.
    align-self: center;
    width: 11px;
    height: 13px;
    opacity: 0.75;
    @include masked-icon(url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 28' fill='none' stroke='%23000' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14 1H4a3 3 0 0 0-3 3v20a3 3 0 0 0 3 3h16a3 3 0 0 0 3-3V10z'/%3E%3Cpath d='M14 1v9h9'/%3E%3C/svg%3E"));
}

.doc-chip__meta {
    font-size: 0.72rem;
    font-weight: 600;
    opacity: 0.7;
}

// A document that has been deleted since the description referred to it: the
// name still reads, but there is nothing to open.
.doc-chip--missing {
    background: $gray-100;
    border-color: $border-color;
    color: $gray-500;
}

.doc-cta {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    max-width: 100%;
    margin: 6px 0;
    padding: 11px 16px;
    background: $white;
    border: $border-width solid $border-color;
    border-radius: 12px;
    text-decoration: none;
    color: $gray-700;
    @include quick-transition(border-color, background, color, box-shadow);

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

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

.doc-cta__badge {
    display: flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    background: $red-ghost;
    border-radius: 9px;
    color: $red-primary;
}

.doc-cta__glyph {
    width: 16px;
    height: 19px;
    @include masked-icon(url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 28' fill='none' stroke='%23000' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14 1H4a3 3 0 0 0-3 3v20a3 3 0 0 0 3 3h16a3 3 0 0 0 3-3V10z'/%3E%3Cpath d='M14 1v9h9'/%3E%3C/svg%3E"));
}

.doc-cta__text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.doc-cta__title {
    font-size: 0.88rem;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.doc-cta__meta {
    font-size: 0.72rem;
    color: $gray-400;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.doc-cta__arrow {
    flex: none;
    width: 16px;
    height: 16px;
    margin-left: auto;
    opacity: 0.45;
    @include masked-icon(url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12h14'/%3E%3Cpath d='M13 5l7 7-7 7'/%3E%3C/svg%3E"));
}

// ─── Governance section ───────────────────────────────────────────────────────
.governance-title {
    @include section-label;
    margin-bottom: 16px;
}

.governance-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 10px;
    margin-bottom: 20px;
}

.governance-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.84rem;
    color: $gray-700;
}

.gov-check {
    font-size: 0.95rem;
    font-weight: 800;
    flex-shrink: 0;
    width: 20px;
    text-align: center;

    &.yes { color: $green; }
    &.no  { color: $gray-300; }
}

.gov-label { color: $gray-600; }

// ─── Org stats row ────────────────────────────────────────────────────────────
.org-stats-grid {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
    margin-top: 4px;
    padding-top: 16px;
    border-top: 1px solid $gray-100;
}

.org-stat {
    text-align: center;
    min-width: 60px;
}

.org-stat-val {
    font-size: 1.35rem;
    font-weight: 700;
    color: $gray-900;
    line-height: 1.1;
}

.org-stat-label {
    font-size: 0.7rem;
    color: $gray-400;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 3px;
}

// ─── CEO empty state ──────────────────────────────────────────────────────────
.ceo-empty {
    color: $gray-400;
    font-size: 0.9rem;
}

// ─── Advanced score pillars ──────────────────────────────────────────────────
[x-cloak] { display: none !important; }

.score-pillars {
    margin-top: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.score-pillar {
    border: $border-width solid $border-color;
    border-radius: 12px;
    background: $white;
    overflow: hidden;

    &.pillar-open {
        border-color: $gray-300;
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
    }
}

.pillar-header {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    background: transparent;
    border: none;
    cursor: pointer;
    text-align: left;
    @include quick-transition(background);

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

.pillar-chevron {
    flex-shrink: 0;
    display: inline-flex;
    color: $gray-400;
    transition: transform 0.18s ease;

    .pillar-open & { transform: rotate(90deg); color: $gray-700; }
}

.pillar-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: $gray-900;
    letter-spacing: 0.01em;
}

.pillar-weight {
    font-size: 0.7rem;
    font-weight: 700;
    color: $gray-500;
    background: $gray-100;
    padding: 2px 8px;
    border-radius: 10px;
    letter-spacing: 0.04em;
}

.pillar-method {
    font-size: 0.72rem;
    font-weight: 600;
    color: $gray-600;
    margin-left: auto;
    padding: 3px 10px;
    background: $gray-50;
    border: 1px solid $gray-200;
    border-radius: 10px;
    white-space: nowrap;
}

.pillar-score {
    flex-shrink: 0;
    min-width: 38px;
    height: 28px;
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    color: $white;
    font-weight: 700;
    font-size: 0.85rem;
}

.pillar-body {
    padding: 4px 18px 18px;
    border-top: 1px solid $gray-100;
    background: $gray-50;
}

.pillar-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-top: 14px;
}

// ─── Methodology callout ──
.pillar-methodology {
    background: $white;
    border-left: 3px solid $green;
    padding: 12px 14px;
    border-radius: 0 8px 8px 0;
}

.pillar-methodology-label {
    @include section-label;
    color: $green;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.pillar-confidence {
    display: inline-flex;
    align-items: center;
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    padding: 2px 7px;
    border-radius: 9999px;
    color: $white;
    background: $gray-500;

    &.pillar-confidence-high   { background: #15803d; }
    &.pillar-confidence-medium { background: #d97706; }
    &.pillar-confidence-low    { background: #b91c1c; }
}

.pillar-methodology-text {
    font-size: 0.84rem;
    line-height: 1.55;
    color: $gray-700;
    margin: 0;
}

// ─── Component breakdown table ──
.pillar-components-header {
    @include section-label;
    margin-bottom: 6px;
}

.pillar-component-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    background: $white;
    border: 1px solid $gray-200;
    border-radius: 8px;
    overflow: hidden;

    th, td {
        padding: 8px 10px;
        text-align: left;
        vertical-align: top;
    }
    th {
        font-size: 0.65rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        color: $gray-500;
        background: $gray-50;
        border-bottom: 1px solid $gray-200;
    }
    tbody tr + tr td { border-top: 1px solid $gray-100; }

    .num { text-align: right; font-variant-numeric: tabular-nums; }
    .comp-label { color: $gray-900; font-weight: 600; }
    .comp-max { color: $gray-500; }
    .comp-earned { color: $green; font-weight: 700; }
    .comp-explain { color: $gray-600; font-size: 0.78rem; }
}

// ─── IRS raw data (collapsed by default) ──
.pillar-irs {
    background: $white;
    border: 1px solid $gray-200;
    border-radius: 8px;

    > summary {
        list-style: none;
        cursor: pointer;
        padding: 10px 14px;
        font-size: 0.78rem;
        font-weight: 700;
        color: $gray-700;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        position: relative;
        @include quick-transition(background);

        &::-webkit-details-marker { display: none; }
        &::after {
            content: '+';
            position: absolute;
            right: 14px;
            top: 50%;
            transform: translateY(-50%);
            font-size: 1.1rem;
            color: $gray-400;
            font-weight: 400;
        }
        &:hover { background: $gray-50; }
    }

    &[open] > summary {
        border-bottom: 1px solid $gray-100;
        &::after { content: '−'; }
    }
}

.pillar-irs-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;

    td {
        padding: 7px 14px;
        vertical-align: middle;
    }
    tr + tr td { border-top: 1px solid $gray-100; }

    .field { color: $gray-700; }
    .value {
        text-align: right;
        font-variant-numeric: tabular-nums;
        font-weight: 600;
        color: $gray-900;
        white-space: nowrap;
    }
    .note {
        text-align: right;
        color: $gray-500;
        font-size: 0.74rem;
    }

    .yoy {
        margin-left: 4px;
        font-weight: 600;
        &.yoy-up   { color: $green; }
        &.yoy-down { color: $red-primary; }
    }
}

// ─── Suggested score footer ──
.pillar-suggested {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding-top: 8px;
}

.pillar-suggested-label {
    font-size: 0.75rem;
    color: $gray-500;
    font-weight: 600;
}

.pillar-suggested-value {
    background: $gray-900;
    color: $white;
    font-weight: 700;
    font-size: 0.85rem;
    padding: 3px 12px;
    border-radius: 10px;
    font-variant-numeric: tabular-nums;
}

// ─── Component sub-totals (Religious identity/integrity, etc.) ───
.pillar-components-header {
    display: flex;
    align-items: center;
    gap: 10px;
}

.pillar-subtotal {
    font-size: 0.7rem;
    font-weight: 700;
    color: $gray-500;
    background: $gray-100;
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: none;
    letter-spacing: 0;
    font-variant-numeric: tabular-nums;
}

// ─── Religious: keyword chips ──
.pillar-keywords {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.pillar-kw-count {
    font-size: 0.7rem;
    font-weight: 600;
    color: $gray-500;
    background: $white;
    padding: 2px 8px;
    border-radius: 10px;
    border: 1px solid $gray-200;
    text-transform: none;
    letter-spacing: 0;
}

.kw-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.kw-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 14px;
    font-size: 0.78rem;
    font-weight: 600;
    background: $white;
    border: 1px solid $gray-200;

    .kw-text { color: $gray-900; }
    .kw-weight {
        font-size: 0.68rem;
        font-weight: 700;
        color: $gray-500;
        font-variant-numeric: tabular-nums;
    }
    .kw-src {
        font-size: 0.65rem;
        color: $gray-400;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        font-weight: 700;
    }

    &.kw-strong {
        background: #fef2f2;
        border-color: $red-pale;
        .kw-text   { color: $red-dark; }
        .kw-weight { color: $red-primary; }
    }
    &.kw-moderate {
        background: #fef3c7;
        border-color: #fde68a;
        .kw-text   { color: #92400e; }
        .kw-weight { color: #b45309; }
    }
}

.kw-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin-top: 4px;
    font-size: 0.72rem;
    color: $gray-500;
}

.kw-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.kw-swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 3px;

    &.kw-strong   { background: #fecaca; border: 1px solid $red-pale; }
    &.kw-moderate { background: #fde68a; border: 1px solid #fcd34d; }
}

.kw-empty-text {
    margin: 0;
    font-size: 0.84rem;
    color: $gray-500;
    font-style: italic;
}

.pillar-keywords-empty {
    padding: 12px 14px;
    background: $white;
    border: 1px dashed $gray-200;
    border-radius: 8px;
}

// ─── Religious: integrity manual-note ──
.pillar-integrity-note {
    padding: 12px 14px;
    background: $white;
    border: 1px solid $gray-200;
    border-radius: 8px;
    font-size: 0.82rem;
    line-height: 1.55;
    color: $gray-700;
}

// ─── Religious: source text + highlight ──
.pillar-source-list {
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.pillar-source-block {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.pillar-source-label {
    @include section-label;
    color: $gray-500;
}

.pillar-source-text {
    font-size: 0.83rem;
    line-height: 1.55;
    color: $gray-700;
}

mark.kw-hit {
    background: #fef08a;
    color: $gray-900;
    padding: 0 3px;
    border-radius: 3px;
    font-weight: 600;
}

.pillar-source-flags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-top: 6px;
    margin-top: 4px;
    border-top: 1px solid $gray-100;
}

.src-flag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 10px;
    font-size: 0.76rem;
    font-weight: 600;
    background: $gray-50;
    border: 1px solid $gray-200;
    color: $gray-700;

    &.yes { color: $green; border-color: #bbf7d0; background: #f0fdf4; }
    &.no  { color: $gray-400; }
}

// ─── Recipient table ──
.pillar-recipient-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    background: $white;
    border: 1px solid $gray-200;
    border-radius: 8px;
    overflow: hidden;

    th, td {
        padding: 8px 12px;
        text-align: left;
        vertical-align: middle;
    }
    th {
        font-size: 0.65rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        color: $gray-500;
        background: $gray-50;
        border-bottom: 1px solid $gray-200;
    }
    tbody tr + tr td { border-top: 1px solid $gray-100; }

    .num { text-align: right; font-variant-numeric: tabular-nums; }

    .rec-name {
        font-weight: 600;
        color: $gray-900;
        text-transform: capitalize;
    }
    .rec-code {
        font-family: $font-mono;
        font-weight: 700;
        color: $gray-900;
        background: $gray-100;
        padding: 2px 8px;
        border-radius: 6px;
        display: inline-block;
        font-size: 0.78rem;
    }
    .rec-median, .rec-amount, .rec-recipients { color: $gray-700; }
    .rec-need { min-width: 140px; }
}

.rec-need-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

.rec-need-track {
    flex: 1;
    height: 8px;
    background: $gray-100;
    border-radius: 4px;
    overflow: hidden;
}

.rec-need-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
}

.rec-need-val {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    font-size: 0.82rem;
    color: $gray-900;
    min-width: 28px;
    text-align: right;
}

.pillar-recipient-footnote {
    margin: 8px 0 0;
    font-size: 0.72rem;
    color: $gray-500;
    line-height: 1.5;
    font-style: italic;
}

.pillar-recipient-empty {
    padding: 14px 16px;
    background: $white;
    border: 1px dashed $gray-200;
    border-radius: 8px;

    p {
        margin: 0;
        font-size: 0.84rem;
        color: $gray-600;
        line-height: 1.55;
    }
}

// ─── Direct beneficiary bonus grid ──
.pillar-bonus-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.bonus-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: $white;
    border: 1px solid $gray-200;
    border-radius: 8px;
}

.bonus-flag {
    flex-shrink: 0;
    min-width: 44px;
    padding: 4px 10px;
    text-align: center;
    border-radius: 14px;
    font-size: 0.82rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    background: $gray-100;
    color: $gray-500;

    &.yes     { background: #d1fae5; color: $green; }
    &.partial { background: #fef3c7; color: #b45309; }
    &.no      { background: $gray-100; color: $gray-400; }
}

.bonus-label {
    font-size: 0.84rem;
    font-weight: 600;
    color: $gray-900;
}

.bonus-sub {
    margin-top: 2px;
    font-size: 0.74rem;
    color: $gray-500;
}

// ─── Country code chips (IRS source data) ──
.country-code-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    justify-content: flex-end;
}

.cc-chip {
    font-family: $font-mono;
    font-size: 0.72rem;
    font-weight: 700;
    background: $gray-100;
    color: $gray-700;
    padding: 2px 7px;
    border-radius: 5px;
}

// ─── Results: 3-component visual grid ──
.pillar-results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}

.result-component {
    background: $white;
    border: 1px solid $gray-200;
    border-radius: 8px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.result-component-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
}

.result-component-name {
    font-size: 0.84rem;
    font-weight: 700;
    color: $gray-900;
}

.result-component-score {
    font-size: 0.78rem;
    color: $gray-500;
    font-variant-numeric: tabular-nums;

    strong { color: $gray-900; font-weight: 700; font-size: 0.95rem; }
}

.result-bar-track {
    height: 8px;
    background: $gray-100;
    border-radius: 4px;
    overflow: hidden;
}

.result-bar-fill {
    height: 100%;
    background: $indigo;
    border-radius: 4px;
    transition: width 0.3s ease;
}

.result-subrows {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-top: 2px;
}

.result-subrow {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 10px;
    align-items: baseline;
    font-size: 0.78rem;
}

.result-subrow-label  { color: $gray-600; }
.result-subrow-value  { color: $gray-900; font-weight: 600; font-variant-numeric: tabular-nums; }
.result-subrow-pts    {
    color: $gray-500;
    font-size: 0.72rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.result-formula {
    margin-top: 2px;
    padding-top: 8px;
    border-top: 1px dashed $gray-100;
    font-family: $font-mono;
    font-size: 0.7rem;
    color: $gray-500;
    line-height: 1.5;
}

// ─── Results: governance proxy detail ──
.result-gov-grid {
    background: $white;
    border: 1px solid $gray-200;
    border-radius: 8px;
    overflow: hidden;
}

.result-gov-row {
    display: grid;
    grid-template-columns: 28px 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;

    & + & { border-top: 1px solid $gray-100; }

    .gov-check { font-size: 0.95rem; text-align: center; }
}

.result-gov-label {
    font-size: 0.84rem;
    color: $gray-900;
    font-weight: 500;
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 6px;
}

.result-gov-detail {
    font-size: 0.72rem;
    color: $gray-500;
    font-weight: 400;
}

.result-gov-pts {
    font-size: 0.78rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;

    &.on  { color: $green; }
    &.off { color: $gray-300; }
}
