/* Constituency electoral report (views/constituencies/report.ejs). Tokens only, so dark mode follows variables.css. */

.report-page {
    max-width: 1080px;
}

.report-back {
    display: inline-block;
    margin-bottom: 12px;
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--dashboard-accent);
    text-decoration: none;
}

.report-back:hover {
    text-decoration: underline;
}

/* ---------- links between levels ---------- */

.report-related {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px 14px;
    margin-top: 12px;
    font-size: var(--fs-sm);
}

.report-related__label {
    color: var(--text-muted);
}

.report-related a {
    font-weight: 600;
    color: var(--dashboard-accent);
    text-decoration: none;
}

.report-related a:hover {
    text-decoration: underline;
}

/* ---------- party colours ---------- */

.report-party--jlp { color: var(--party-jlp-text); }
.report-party--pnp { color: var(--party-pnp-text); }
.report-party--other { color: var(--text-secondary); }

/* ---------- key numbers ---------- */

.report-highlights {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin: 16px 0 0;
    padding: 0;
    list-style: none;
}

.report-highlight {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
}

.report-highlight__value {
    font-size: var(--fs-xl);
    font-weight: 800;
    line-height: 1.1;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.report-highlight__label {
    font-size: var(--fs-sm);
    line-height: 1.4;
    color: var(--text-secondary);
}

/* ---------- results at a glance ---------- */

.report-years {
    display: grid;
    gap: 10px;
    margin: 0;
    padding: 16px;
    list-style: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
}

.report-year {
    display: grid;
    grid-template-columns: 110px minmax(0, 1fr);
    grid-template-areas:
        "label bar"
        "label legend";
    column-gap: 16px;
    row-gap: 4px;
    align-items: center;
}

.report-year__label {
    grid-area: label;
    display: flex;
    flex-direction: column;
    font-size: var(--fs-xs);
    color: var(--text-muted);
}

.report-year__label strong {
    font-size: var(--fs-md);
    color: var(--text-primary);
}

.report-bar {
    grid-area: bar;
    display: flex;
    height: 14px;
    overflow: hidden;
    border-radius: var(--radius-pill);
    background: var(--surface-muted);
}

.report-bar__seg--jlp { background: var(--party-jlp); }
.report-bar__seg--pnp { background: var(--party-pnp); }
.report-bar__seg--other { background: var(--border-strong); }

.report-year__legend {
    grid-area: legend;
    display: flex;
    flex-wrap: wrap;
    gap: 2px 16px;
    font-size: var(--fs-sm);
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.report-year__legend small {
    color: var(--text-muted);
}

/* ---------- collapsible extras ---------- */

.report-more {
    margin-top: 12px;
}

.report-more > summary,
.report-finding__source > summary {
    cursor: pointer;
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--dashboard-accent);
}

.report-more > .report-table-wrap {
    margin-top: 10px;
}

.report-method-box {
    margin-top: 28px;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface-soft);
}

.report-method {
    margin: 10px 0 0;
    padding-left: 20px;
    font-size: var(--fs-sm);
    line-height: 1.6;
    color: var(--text-secondary);
}

/* ---------- tables ---------- */

.report-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
}

.report-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--fs-sm);
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.report-table th,
.report-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
    white-space: nowrap;
}

.report-table thead th {
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--surface-soft);
}

.report-table tbody tr:last-child > * {
    border-bottom: 0;
}

.report-table--compact td {
    white-space: normal;
}

.report-sub {
    display: block;
    font-size: var(--fs-xs);
    color: var(--text-muted);
}

/* ---------- findings ---------- */

.report-parties {
    display: grid;
    gap: 12px;
}

/* Wide screens: one column per party, one row per finding, so paired cards share a row height. */
@media (min-width: 761px) {
    .report-parties {
        grid-template-columns: repeat(var(--party-count), minmax(0, 1fr));
        column-gap: 16px;
    }

    .report-parties > * {
        grid-column: var(--col);
        grid-row: var(--row);
    }
}

.report-party-cell,
.report-party-cell .report-findings,
.report-party-cell .report-finding {
    height: 100%;
}

.report-party-heading {
    margin: 0;
    padding-top: 10px;
    border-top: 4px solid var(--border-strong);
    font-size: var(--fs-lg);
    font-weight: 800;
}

.report-party-heading--jlp { border-top-color: var(--party-jlp); }
.report-party-heading--pnp { border-top-color: var(--party-pnp); }

@media (max-width: 760px) {
    .report-party-heading:not(:first-child) {
        margin-top: 12px;
    }
}

/* ---------- seat verdict ---------- */

.report-verdict {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 16px 24px;
    align-items: center;
    margin-top: 16px;
    padding: 18px 20px;
    border: 1px solid var(--border);
    border-left: 6px solid var(--verdict-accent, var(--border-strong));
    border-radius: var(--radius-lg);
    background: var(--surface);
}

/* Verdict colours describe closeness only, never a party. */
.report-verdict--battleground { --verdict-accent: var(--danger); }
.report-verdict--competitive { --verdict-accent: var(--warning); }
.report-verdict--comfortable { --verdict-accent: var(--info); }
.report-verdict--safe { --verdict-accent: var(--text-muted); }

.report-verdict__eyebrow {
    display: block;
    font-size: var(--fs-2xs);
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.report-verdict__label {
    display: block;
    margin-top: 2px;
    font-size: var(--fs-2xl);
    font-weight: 800;
    line-height: 1.15;
    color: var(--text-primary);
}

.report-verdict__label span {
    font-size: var(--fs-lg);
}

.report-verdict__reason {
    margin: 6px 0 0;
    font-size: var(--fs-base);
    line-height: 1.55;
    color: var(--text-secondary);
}

.report-verdict__context {
    margin: 4px 0 0;
    font-size: var(--fs-sm);
    line-height: 1.5;
    color: var(--text-muted);
}

.report-verdict__bands {
    display: grid;
    grid-template-columns: repeat(4, minmax(84px, 1fr));
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.report-verdict__bands li {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 10px;
    border-radius: var(--radius-md);
    background: var(--surface-soft);
    border: 1px solid var(--border);
}

.report-verdict__year {
    font-size: var(--fs-xs);
    color: var(--text-muted);
}

.report-verdict__band {
    font-size: var(--fs-sm);
    font-weight: 700;
    color: var(--text-primary);
}

.report-verdict__margin {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

@media (max-width: 760px) {
    .report-verdict {
        grid-template-columns: 1fr;
    }

    .report-verdict__bands {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.report-findings {
    display: grid;
    gap: 12px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.report-finding {
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
}

.report-finding__title {
    margin: 0 0 6px;
    font-size: var(--fs-md);
    font-weight: 700;
    color: var(--text-primary);
}

.report-finding__text {
    margin: 0;
    font-size: var(--fs-base);
    line-height: 1.65;
    color: var(--text-secondary);
}

.report-finding__source {
    margin-top: 10px;
}

.report-finding__meta {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
    margin: 8px 0;
    font-size: var(--fs-xs);
    color: var(--text-muted);
}

.report-finding__source .report-table {
    border: 1px solid var(--border);
}

/* ---------- candidates ---------- */

.report-candidates {
    display: grid;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.report-candidates li {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px 18px;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    font-size: var(--fs-sm);
    color: var(--text-primary);
}

.report-candidates li > strong {
    min-width: 44px;
    font-size: var(--fs-md);
}

.report-candidate small {
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

/* ---------- candidate profile (views/candidates/show.ejs) ---------- */

.candidate-notice {
    margin: 16px 0 0;
    font-size: var(--fs-sm);
    color: var(--text-secondary);
}

.candidate-muted {
    color: var(--text-muted);
}

.candidate-source {
    margin-left: auto;
    font-size: var(--fs-xs);
    color: var(--dashboard-accent);
}

.candidate-footnote {
    padding-left: 0;
    list-style: none;
    color: var(--text-muted);
}

.candidate-page .reference-section {
    margin-top: 28px;
}

.candidate-page .report-highlights {
    margin-top: 20px;
}

/* Where → the dashboard at that election and place. */
.candidate-place {
    font-weight: 600;
    color: var(--dashboard-accent);
    text-decoration: none;
}

.candidate-place:hover {
    text-decoration: underline;
}

.candidate-record .report-sub a {
    color: var(--text-muted);
}

/* Result chip: same build as the Transitions chips (party text on its soft fill). */
.candidate-result {
    display: inline-flex;
    align-items: center;
    min-height: 20px;
    padding: 0 0.5rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--surface-muted);
}

.candidate-result--jlp {
    color: var(--party-jlp-text);
    background: var(--party-jlp-soft);
    border-color: color-mix(in srgb, var(--party-jlp) 20%, transparent);
}

.candidate-result--pnp {
    color: var(--party-pnp-text);
    background: var(--party-pnp-soft);
    border-color: color-mix(in srgb, var(--party-pnp) 20%, transparent);
}

/* Phones: one fixed shape per role row and per contest card, whatever the text length. */
@media (max-width: 640px) {
    /* Section description under the heading, full width. */
    .candidate-page .reference-section__head {
        grid-template-columns: minmax(0, 1fr);
    }

    .candidate-page .reference-section__head p {
        padding-top: 0;
    }

    /* Key numbers: one value size for all four tiles that keeps "2011–2020" on one line at 360px. */
    .candidate-page .report-highlight__value {
        font-size: clamp(1.125rem, 5.4vw, 1.375rem);
        white-space: nowrap;
    }

    /* Roles: years + source on line 1, title · portfolio on line 2. */
    .candidate-page .report-candidates li {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: baseline;
        gap: 4px 12px;
    }

    .candidate-page .report-candidates li > strong {
        grid-column: 1;
        grid-row: 1;
        font-size: var(--fs-base);
    }

    .candidate-page .report-candidates li > span {
        grid-column: 1 / -1;
        grid-row: 2;
    }

    .candidate-page .report-candidates li small {
        font-size: var(--fs-sm);
    }

    /* 24px+ tap area around the small link without making the row taller. */
    .candidate-source {
        position: relative;
        grid-column: 2;
        grid-row: 1;
        margin-left: 0;
    }

    .candidate-source::after {
        content: "";
        position: absolute;
        inset: -8px -10px;
    }

    /* Contest cards: "2020 · General   [Won]" / place / parent · Report / "PNP · 4,929 votes · 55.2%". */
    .candidate-record-wrap {
        overflow: visible;
        border: 0;
        background: transparent;
    }

    .candidate-record thead {
        display: none;
    }

    .candidate-record,
    .candidate-record tbody,
    .candidate-record tr {
        display: block;
    }

    /* Wrapping row, not a grid: each line sizes to its own text (no column shared across lines). */
    .candidate-record tr {
        display: flex;
        flex-wrap: wrap;
        align-items: baseline;
        gap: 4px 6px;
        margin-bottom: 10px;
        padding: 12px 14px;
        border: 1px solid var(--border);
        border-radius: var(--radius-md);
        background: var(--surface);
    }

    .candidate-record th,
    .candidate-record td {
        padding: 0;
        border: 0;
        white-space: normal;
    }

    /* Visual labels off; screen readers still get the column headers from the table. */
    .candidate-record td::before {
        content: none;
    }

    .candidate-record th[scope="row"] {
        order: 1;
        font-size: var(--fs-md);
    }

    .candidate-record td[data-label="Election"] {
        order: 2;
        color: var(--text-secondary);
    }

    .candidate-record td[data-label="Result"] {
        order: 3;
        margin-left: auto;
        align-self: center;
    }

    .candidate-record td[data-label="Where"] {
        order: 4;
        flex-basis: 100%;
    }

    /* Report line always under the place, so every card has the same lines. */
    .candidate-record td[data-label="Where"] .report-sub {
        display: block;
    }

    .candidate-record td[data-label="Party"] {
        order: 5;
    }

    .candidate-record td[data-label="Votes"] {
        order: 6;
    }

    .candidate-record td[data-label="Share"] {
        order: 7;
    }

    .candidate-record td[data-label="Election"]::before,
    .candidate-record td[data-label="Votes"]::before,
    .candidate-record td[data-label="Share"]::before {
        content: "· ";
        color: var(--text-muted);
    }

    .candidate-record td[data-label="Votes"]::after {
        content: " votes";
    }
}

/* Candidate names that link to their profile (reports and dashboard). */
.candidate-link {
    color: inherit;
    text-decoration: underline;
    text-decoration-color: var(--border-strong);
    text-underline-offset: 2px;
}

.candidate-link:hover {
    color: var(--dashboard-accent);
    text-decoration-color: currentColor;
}

/* ---------- small screens ---------- */

@media (max-width: 760px) {
    .report-highlights {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .report-year {
        grid-template-columns: 1fr;
        grid-template-areas:
            "label"
            "bar"
            "legend";
    }

    .report-year__label {
        flex-direction: row;
        gap: 10px;
        align-items: baseline;
    }
}

/* ---------- dashboard button (shown only for constituencies with a report) ---------- */

.dashboard-report-link {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    background: var(--dashboard-accent);
    color: var(--text-inverse);
    font-size: var(--fs-sm);
    font-weight: 600;
    text-decoration: none;
}

.dashboard-report-link:hover {
    background: var(--dashboard-accent-hover);
}

.dashboard-report-link[hidden] {
    display: none;
}
