/* Shared layout for the report chart cards: a header, the chart, and a column of tiles down the right hand side.
   Used by the cost breakdown and the cash flow chart so both cards look and behave the same.

   The dashboard scales its panels with the window, so everything in a card shrinks to fit rather than scrolling.
   Two named containers drive that: rc-card (the card's width) and rc-tile (each tile's own height). */

.rc-root {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 16px;
    container: rc-card / inline-size;
    overflow: hidden;
    color: var(--color-text-primary);
}

.rc-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 24px;
}

.rc-title {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 1rem;
}

.rc-badge {
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    background: rgba(var(--color-accent-rgb), 0.18);
    color: var(--color-accent-hover);
}

.rc-reset {
    border: 0;
    background: none;
    padding: 0;
    font-size: 0.8rem;
    color: var(--color-accent-hover);
    text-decoration: underline;
    cursor: pointer;
}

.rc-body {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    align-items: center;
    gap: 24px;
}

.rc-swatch {
    width: 12px;
    height: 12px;
    flex: 0 0 auto;
    border-radius: 3px;
    background: var(--swatch);
    border: 2px solid var(--swatch);
}

/* Tiles */
.rc-filters {
    flex: 0 0 132px;
    align-self: stretch;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
    overflow: hidden;
}

/* .rc-stat is the same tile as a filter button, just a summary figure rather than a toggle */
.rc-filter, .rc-stat {
    flex: 1 1 0;
    min-height: 0;
    max-height: 96px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    gap: 2px;
    padding: 4px 10px;
    border: 1px solid color-mix(in srgb, var(--swatch) 45%, transparent);
    border-left: 4px solid var(--swatch);
    border-radius: 4px;
    background: color-mix(in srgb, var(--swatch) 10%, var(--color-bg-surface));
    color: var(--color-text-primary);
    text-align: left;
    overflow: hidden;
    container: rc-tile / size;
    cursor: pointer;
    transition: background 0.15s ease, box-shadow 0.15s ease;
}

    .rc-filter > *, .rc-stat > * {
        max-width: 100%;
    }

    .rc-filter:hover {
        box-shadow: var(--shadow-sm);
        background: color-mix(in srgb, var(--swatch) 18%, var(--color-bg-surface));
    }

.rc-stat {
    cursor: default;
}

.rc-stat-strong {
    background: color-mix(in srgb, var(--swatch) 22%, var(--color-bg-surface));
}

    .rc-stat-strong .rc-filter-value {
        font-size: 1rem;
        font-weight: 600;
    }

.rc-filter-name {
    display: block;
    font-weight: 600;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

    .rc-filter-name .rc-swatch {
        display: inline-block;
        width: 10px;
        height: 10px;
        margin-right: 6px;
        vertical-align: -1px;
    }

.rc-filter-value {
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.rc-filter-note {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rc-filter.rc-off {
    background: transparent;
    border-style: dashed;
    border-left-style: solid;
    border-color: rgba(var(--color-accent-rgb), 0.4);
    border-left-color: color-mix(in srgb, var(--swatch) 40%, transparent);
    color: var(--color-text-secondary);
}

    .rc-filter.rc-off .rc-filter-name, .rc-filter.rc-off .rc-filter-value {
        color: var(--color-text-secondary);
        text-decoration: line-through;
    }

/* Hidden: hollow swatch. Partly hidden: half filled */
.rc-off .rc-swatch {
    background: transparent;
}

.rc-partial .rc-swatch {
    background: linear-gradient(135deg, var(--swatch) 50%, transparent 50%);
}

.rc-filter:focus-visible, .rc-reset:focus-visible {
    outline: 2px solid var(--color-accent-hover);
    outline-offset: -2px;
}

/* Short tiles keep the name and figure and drop the note */
@container rc-tile (max-height: 62px) {
    .rc-filter-note {
        display: none;
    }
}

@container rc-tile (max-height: 40px) {
    .rc-filter-name, .rc-filter-value, .rc-stat-strong .rc-filter-value {
        font-size: 0.72rem;
    }
}

/* Narrow cards: the tiles become slim rows, the dashboard panels are too short there for two lines */
@container rc-card (max-width: 560px) {
    .rc-body {
        gap: 12px;
        justify-content: space-between;
    }

    .rc-filters {
        flex-basis: 120px;
        gap: 4px;
    }

    .rc-filter, .rc-stat {
        padding: 2px 8px;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 6px;
    }

    .rc-filter-name {
        min-width: 0;
    }

    .rc-filter-note {
        display: none;
    }

    .rc-filter-name, .rc-filter-value, .rc-stat-strong .rc-filter-value {
        font-size: 0.72rem;
    }
}

/* A chart that fills what the card's tiles leave, and the small swatch legend that names its series */
.rsc-chart {
    flex: 1 1 auto;
    align-self: stretch;
    min-width: 0;
    min-height: 0;
}

.rsc-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
    font-size: 0.75rem;
    color: var(--color-text-secondary);
}

    .rsc-legend > span {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        white-space: nowrap;
    }

/* Every report page's header: the title, actions menu and whatever pills follow. A wrapping flex row rather than Bootstrap columns,
   whose ps-0 left a wrapped item 12px outside the title's line on a phone */
.rpp-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
}

/* Phones, where it never fits on one line: each line centred rather than ragged on the right */
@media (max-width: 575px) {
    .rpp-toolbar {
        justify-content: center;
    }
}

/* The card a headline tile sits in, on the renovation and completed pages. Each page lays the tiles out in its own grid */
.rpp-tile {
    min-width: 0;
    overflow: hidden;
    border: var(--tpt-border);
    border-radius: 4px;
    background: var(--color-bg-surface);
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

    .rpp-tile:hover {
        box-shadow: var(--shadow-md);
        border: var(--tpt-border-hover);
    }

/* Headline figures (ReportKpiTile). Each tile watches its own size so short panels shed detail rather than scroll */
.rk-tile {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-start; /* Labels line up across tiles whatever each one shows below */
    align-items: flex-start;
    gap: 4px;
    padding: 14px 18px;
    border: 0;
    background: transparent;
    color: var(--color-text-primary);
    text-align: left;
    overflow: hidden;
    container: rk-tile / size;
}

    .rk-tile > * {
        max-width: 100%;
    }

.rk-clickable {
    cursor: pointer;
}

    .rk-clickable:focus-visible {
        outline: 2px solid var(--color-accent-hover);
        outline-offset: -2px;
    }

.rk-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
}

.rk-label {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rk-action {
    flex: 0 0 auto;
    font-size: 0.75rem;
    color: var(--color-accent-hover);
    white-space: nowrap;
}

    .rk-action .e-icons {
        font-size: 9px;
    }

.rk-clickable:hover .rk-action {
    text-decoration: underline;
}

.rk-value {
    font-size: clamp(1.1rem, 9cqi, 1.75rem);
    font-weight: 600;
    line-height: 1.15;
    white-space: nowrap;
}

.rk-change {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
}

.rk-chip {
    flex: 0 0 auto;
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    background: rgba(var(--color-accent-rgb), 0.15);
    color: var(--color-accent-hover);
}

    .rk-chip.rk-good {
        background: color-mix(in srgb, var(--color-success) 18%, transparent);
        color: #2E7D52;
    }

    .rk-chip.rk-bad {
        background: color-mix(in srgb, var(--color-danger) 18%, transparent);
        color: #A8302F;
    }

.rk-change-text {
    overflow: hidden;
    text-overflow: ellipsis;
}

.rk-context {
    margin-top: auto; /* Sits at the foot of the tile */
    padding-top: 6px;
    font-size: 0.78rem;
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

    /* A context that carries the news, in the change chips' colours */
    .rk-context.rk-good {
        font-weight: 600;
        color: #2E7D52;
    }

    .rk-context.rk-bad {
        font-weight: 600;
        color: #A8302F;
    }

@container rk-tile (max-height: 120px) {
    .rk-context {
        display: none;
    }
}

@container rk-tile (max-height: 84px) {
    .rk-tile {
        padding: 6px 10px;
        gap: 2px;
    }

    .rk-change, .rk-action {
        display: none;
    }

    .rk-label {
        font-size: 0.66rem;
    }
}

/* Cost lists (GeneratedCostsComponent's accordions and the renovation page's maintenance card): an accent header with the
   total, then sections of name/figure rows ending in a total */
.gcc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.gcc-header-title {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.gcc-header-figure {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    white-space: nowrap;
}

.gcc-body {
    padding: 6px 16px 12px;
    font-size: 0.9rem;
}

.gcc-section {
    padding: 10px 0;
}

    .gcc-section + .gcc-section {
        border-top: 1px dashed rgba(var(--color-accent-rgb), 0.35);
    }

.gcc-section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-text-secondary);
}

.gcc-body .gcc-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 16px;
    padding: 3px 0;
    color: var(--color-text-secondary);
}

    .gcc-body .gcc-row > span:last-child {
        color: var(--color-text-primary);
        font-variant-numeric: tabular-nums;
        white-space: nowrap;
    }

.gcc-body .gcc-row-lead {
    font-size: 1rem;
    color: var(--color-text-primary);
}

    .gcc-body .gcc-row-lead > span:last-child {
        font-weight: 600;
    }

.gcc-body .gcc-total {
    margin-top: 4px;
    padding-top: 6px;
    border-top: 1px solid rgba(var(--color-accent-rgb), 0.5);
    color: var(--color-text-primary);
    font-weight: 600;
}

/* Two figures per row (a month, then the whole duration), lined up in columns under their headings */
.gcc-body .gcc-cols .gcc-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    column-gap: 16px;
}

    .gcc-body .gcc-cols .gcc-row > span:not(:first-child) {
        min-width: 6.5em;
        color: var(--color-text-primary);
        font-variant-numeric: tabular-nums;
        text-align: right;
        white-space: nowrap;
    }

.gcc-body .gcc-cols .gcc-cols-head {
    align-items: end;
}

    .gcc-body .gcc-cols .gcc-cols-head .gcc-section-title {
        margin-bottom: 0;
    }

    .gcc-body .gcc-cols .gcc-cols-head > span:not(:first-child) {
        color: var(--color-text-secondary);
        font-size: 0.72rem;
        font-weight: 600;
        letter-spacing: 0.06em;
        text-transform: uppercase;
    }

.gcc-badge {
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: none;
    background: rgba(var(--color-accent-rgb), 0.18);
    color: var(--color-accent-hover);
}

.gcc-badge-on-accent {
    background: rgba(255, 255, 255, 0.22);
    color: var(--color-text-on-accent);
}

/* A cost list that is always open: the accordion's expanded card with its header bar, but nothing to toggle */
.gcc-card {
    display: flex;
    flex-direction: column;
    width: 100%;
    border: var(--tpt-border);
    border-radius: 4px;
    background: var(--color-bg-surface);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    color: var(--color-text-primary);
}

    .gcc-card > .gcc-header {
        padding: 10px 16px;
        background: var(--color-accent);
        color: var(--color-text-on-accent);
    }

    .gcc-card > .gcc-body {
        flex: 1 1 auto;
        overflow-y: auto;
    }

/* Local area detail (CrimeDetailView and IncomeDetailView, in their tiles' popups). Neutral throughout: the accent for marks, no good/bad colours */
.ar-detail {
    display: flex;
    flex-direction: column;
    gap: 14px;
    color: var(--color-text-primary);
}

.ar-lead {
    margin: 0;
    font-size: 1rem;
    line-height: 1.5;
}

.ar-note {
    margin: 0;
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--color-text-secondary);
}

.ar-callout {
    padding: 8px 12px;
    border-left: 3px solid var(--color-accent);
    background: rgba(var(--color-accent-rgb), 0.08);
}

.ar-muted {
    color: var(--color-text-secondary);
    font-weight: 400;
}

.ar-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 10px;
}

.ar-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 14px;
    border: var(--tpt-border);
    border-radius: 4px;
    background: var(--color-bg-surface);
    min-width: 0;
}

.ar-stat-label {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ar-stat-value {
    font-size: 1.4rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.ar-stat-note {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
}

.ar-heading {
    margin: 4px 0 0;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-text-secondary);
}

/* One series of yearly totals with the council area's typical neighbourhood as a labelled reference line */
.ar-chart {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ar-plot {
    padding-top: 22px; /* Room for the value above the tallest bar */
    border-bottom: 1px solid rgba(var(--color-accent-rgb), 0.35);
}

.ar-bars {
    position: relative;
    display: flex;
    gap: 2px;
    height: 160px;
}

.ar-column {
    flex: 1 1 0;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    min-width: 0;
}

    .ar-column:hover .ar-bar {
        background: var(--color-accent-hover);
    }

.ar-bar {
    position: relative;
    width: min(56px, 60%);
    min-height: 2px;
    border-radius: 4px 4px 0 0;
    background: var(--color-accent);
}

/* Sits just above its bar */
.ar-column-value {
    position: absolute;
    bottom: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
    color: var(--color-text-secondary);
    white-space: nowrap;
}

.ar-reference {
    position: absolute;
    left: 0;
    right: 0;
    border-top: 1.5px dashed var(--color-text-secondary);
    pointer-events: none;
    z-index: 1;
}

    .ar-reference > span {
        position: absolute;
        right: 0;
        bottom: 2px;
        padding: 0 4px;
        font-size: 0.72rem;
        color: var(--color-text-secondary);
        background: var(--color-bg-surface);
    }

.ar-axis {
    display: flex;
    gap: 2px;
}

    .ar-axis > span {
        flex: 1 1 0;
        min-width: 0;
        text-align: center;
        font-size: 0.72rem;
        color: var(--color-text-secondary);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

.ar-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

    .ar-table th {
        padding: 6px 8px;
        font-size: 0.72rem;
        font-weight: 600;
        text-align: left;
        color: var(--color-text-secondary);
        border-bottom: 1px solid rgba(var(--color-accent-rgb), 0.5);
        white-space: nowrap;
    }

    .ar-table td {
        padding: 5px 8px;
        border-bottom: 1px solid rgba(var(--color-accent-rgb), 0.12);
    }

    .ar-table .ar-num {
        text-align: right;
        font-variant-numeric: tabular-nums;
        white-space: nowrap;
    }

    .ar-table .ar-total td {
        font-weight: 600;
        border-top: 1px solid rgba(var(--color-accent-rgb), 0.5);
    }

    .ar-table .ar-aside td {
        color: var(--color-text-secondary);
        border-bottom: 0;
    }

/* Affordability over time (IncomeDetailView): the council area in the accent, the country as a dashed reference, keyed above */
.ar-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 18px;
    font-size: 0.8rem;
    color: var(--color-text-primary);
}

    .ar-legend > span {
        display: inline-flex;
        align-items: center;
        gap: 6px;
    }

.ar-key {
    display: inline-block;
    width: 18px;
    height: 0;
    border-top: 2px solid var(--color-accent);
}

.ar-key-reference {
    border-top: 2px dashed var(--color-text-secondary);
}

.ar-line-chart {
    width: 100%;
    height: auto;
    overflow: visible;
}

    .ar-line-chart .ar-grid {
        stroke: rgba(var(--color-accent-rgb), 0.18);
        stroke-width: 1;
    }

    .ar-line-chart .ar-axis {
        font-size: 11px;
        fill: var(--color-text-secondary);
    }

    .ar-line-chart .ar-series-area {
        fill: none;
        stroke: var(--color-accent);
        stroke-width: 2;
        stroke-linejoin: round;
    }

    .ar-line-chart .ar-series-reference {
        fill: none;
        stroke: var(--color-text-secondary);
        stroke-width: 1.5;
        stroke-dasharray: 5 4;
    }

    .ar-line-chart .ar-dot-area {
        fill: var(--color-accent);
        stroke: var(--color-bg-surface);
        stroke-width: 2;
    }

    /* Invisible, larger than the line, so a year is easy to hover */
    .ar-line-chart .ar-hit {
        fill: transparent;
    }

        .ar-line-chart .ar-hit:hover {
            fill: rgba(var(--color-accent-rgb), 0.25);
        }

    .ar-line-chart .ar-end-label {
        font-size: 12px;
        font-weight: 600;
        fill: var(--color-text-primary);
    }

    .ar-line-chart .ar-end-reference {
        font-weight: 400;
        fill: var(--color-text-secondary);
    }

/* Phones: the crime and income popups' figures pair up, and their period labels ("Sept 25 – Aug 26") wrap onto two lines rather
   than pushing the table off the side or being cut short under the bars */
@media (max-width: 600px) {
    .ar-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .ar-stat {
        padding: 8px 10px;
    }

    .ar-stat-label {
        white-space: normal;
    }

    .ar-stat-value {
        font-size: 1.2rem;
    }

    .ar-axis > span {
        white-space: normal;
        overflow: visible;
        line-height: 1.2;
    }

    .ar-table {
        font-size: 0.8rem;
    }

        .ar-table th, .ar-table td {
            padding-left: 4px;
            padding-right: 4px;
        }

        .ar-table th, .ar-table th.ar-num {
            white-space: normal;
            vertical-align: bottom;
        }
}

/* Phones: a column of figures beside a chart cuts their names to "Cas...", so they go in a row underneath it, two rows of two
   when there are four. Each page sets its chart cards' heights to suit */
@media (max-width: 600px) {
    .rc-body:has(> .rsc-chart), .rc-body:has(> .cfw-chart) {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

        .rc-body:has(> .rsc-chart) > .rc-filters, .rc-body:has(> .cfw-chart) > .rc-filters {
            flex: 0 0 auto;
            display: grid;
            grid-auto-flow: column;
            grid-auto-columns: minmax(0, 1fr);
            gap: 4px;
        }

            .rc-body:has(> .rsc-chart) > .rc-filters:has(> :nth-child(4)), .rc-body:has(> .cfw-chart) > .rc-filters:has(> :nth-child(4)) {
                grid-auto-flow: row;
                grid-template-columns: repeat(2, minmax(0, 1fr));
            }

            .rc-body:has(> .rsc-chart) > .rc-filters > .rc-stat, .rc-body:has(> .cfw-chart) > .rc-filters > .rc-stat {
                height: 40px;
                flex-direction: column;
                align-items: flex-start;
                justify-content: center;
                gap: 0;
            }

    /* The renovation and completed pages' tiles pair up, so their context line wraps onto a second line rather than being cut short */
    .rpp-tile .rk-tile {
        padding: 10px 12px;
    }

    .rpp-tile .rk-context {
        display: -webkit-box !important;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        line-height: 1.25;
        white-space: normal;
    }
}

/* Only stack when there is no room for the chart and tiles side by side */
@container rc-card (max-width: 280px) {
    .rc-body {
        flex-direction: column;
        align-items: stretch;
    }

    .rc-filters {
        flex-basis: auto;
    }

    /* Tiles are size containers, so they need a height of their own once the column sizes to its content */
    .rc-filter, .rc-stat {
        flex: 0 0 28px;
    }
}
