/* Figures and charts (phase 13, P13-06; 13-Dashboard.md section 4.2, DESIGN-SYSTEM.md sections 4.1 and 5.4). A file of its own,
   linked after app.css, so the dashboard lanes never collide with other runs in app.css. Tokens only (tokens.css: --chart-*,
   --font-size-hero). The emphasis form: ink marks, grey context, orange only on the one mark that matters; text never in a series
   colour; status colours only for good and bad. Charts are SVG drawn on the server with a fixed height and a fluid width; hover
   and focus show their tooltips by CSS alone. Motion: the refetch fade only (opacity), and the shared press feedback. */

/* The fifth template (.page-dashboard): header, an optional filter toolbar, then a 12-column grid of cards, grouped in bands each
   under an .eyebrow label. The page scrolls; cards do not, except the long lists (attention, To do now). */
.page-dashboard {
    display: flex;
    flex: 1 0 auto;
    flex-direction: column;
    min-width: 0;
}

.dash-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: var(--gap-cards);
    align-items: start;
}

.dash-grid > * {
    min-width: 0;
}

.dash-span-2 { grid-column: span 2; }
.dash-span-3 { grid-column: span 3; }
.dash-span-4 { grid-column: span 4; }
.dash-span-6 { grid-column: span 6; }
.dash-span-8 { grid-column: span 8; }
.dash-span-12 { grid-column: 1 / -1; }

/* A band's label: the one place besides the sidebar groups where small text is uppercase (DESIGN-SYSTEM.md section 6). */
.eyebrow {
    margin: 0;
    color: var(--color-text-muted);
    font-size: var(--font-size-caption);
    font-weight: var(--weight-emph);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.dash-band {
    grid-column: 1 / -1;
    margin-top: var(--space-4);
}

.dash-band:first-child {
    margin-top: 0;
}

@media (max-width: 1439px) {
    .dash-span-2 { grid-column: span 3; }
}

@media (max-width: 1199px) {
    .dash-grid {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }

    .dash-span-8, .dash-span-6 { grid-column: 1 / -1; }
    .dash-span-4 { grid-column: span 3; }
    .dash-span-3 { grid-column: span 3; }
}

@media (max-width: 599px) {
    .dash-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dash-span-4, .dash-span-6, .dash-span-8 { grid-column: 1 / -1; }
    .dash-span-2, .dash-span-3 { grid-column: span 1; }
}

/* Figures: the hero and the tiles. The whole card is the link; it answers the hover with a firmer edge and the press with the
   shared scale. Proportional figures for big standalone numbers (tabular only in columns). */
.hero-figure, .stat-tile {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    min-width: 0;
    color: var(--color-text);
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    transition: transform var(--press-duration) ease-out, opacity 150ms ease-out;
}

.hero-figure {
    padding: var(--space-5);
}

.stat-tile {
    padding: var(--space-4);
}

a.hero-figure:hover, a.stat-tile:hover {
    border-color: var(--line-strong);
    color: var(--color-text);
}

a.hero-figure:active, a.stat-tile:active {
    transform: scale(0.99);
}

.hero-label, .stat-label {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    font-weight: var(--weight-emph);
}

.hero-value {
    font-size: var(--font-size-hero);
    font-weight: var(--weight-title);
    font-variant-numeric: proportional-nums;
    letter-spacing: var(--tracking-display);
    line-height: var(--leading-display);
}

.stat-value {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0 var(--space-2);
    font-size: var(--font-size-xl);
    font-weight: var(--weight-title);
    font-variant-numeric: proportional-nums;
    letter-spacing: var(--tracking-title);
    line-height: var(--leading-title);
}

/* The value never breaks inside ("48,2 mila €"): a narrow tile takes it down a size step by its own width instead. */
.stat-tile {
    container-type: inline-size;
}

.stat-value-main {
    font-size: clamp(var(--font-size-lg), 15cqi, var(--font-size-xl));
    white-space: nowrap;
}

.stat-aside {
    color: var(--color-text-muted);
    font-size: var(--font-size-base);
    font-weight: var(--weight-body);
    letter-spacing: 0;
}

.hero-meta {
    min-height: 1.25rem;
}

.hero-trend {
    margin-top: var(--space-2);
}

.stat-trend {
    margin-top: auto;
}

.figure-foot {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    color: var(--color-text-muted);
    font-size: var(--font-size-caption);
}

.figure-foot-warning {
    color: var(--color-warning);
    font-weight: var(--weight-emph);
}

/* Compact tiles (My work's "This month"): rows in one card, no card of their own, a hairline between them. */
.stat-tile.stat-tile-compact {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: baseline;
    gap: var(--space-1) var(--space-3);
    padding: var(--space-3) 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}

.stat-tile-compact + .stat-tile-compact {
    border-top: 1px solid var(--line);
}

.stat-tile-compact .stat-value {
    justify-content: flex-end;
}

.stat-tile-compact .stat-value-main {
    font-size: var(--font-size-lg);
}

.stat-tile-compact .delta, .stat-tile-compact .figure-foot {
    grid-column: 1 / -1;
}

a.stat-tile.stat-tile-compact:hover {
    background: var(--hover-tint);
}

/* The delta: an arrow, the signed percent, "vs <compare>". Good and bad in the status colours, always with the arrow and sign. */
.delta {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem;
    font-size: var(--font-size-sm);
    font-weight: var(--weight-emph);
}

.delta-good {
    color: var(--color-success);
}

.delta-bad {
    color: var(--color-danger);
}

.delta-neutral {
    color: var(--color-text-muted);
}

.delta-vs {
    margin-left: var(--space-1);
    color: var(--color-text-muted);
    font-weight: var(--weight-body);
}

/* Sparkline: context grey, the current point in the accent with a surface ring. */
.sparkline {
    display: block;
    overflow: visible;
}

.sparkline-line {
    fill: none;
    stroke: var(--chart-context);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sparkline-dot {
    fill: var(--chart-accent);
    stroke: var(--surface);
    stroke-width: 2;
}

/* Meter: the track a light step of the fill; ink, warning or danger, with the word beside it. */
.meter {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.meter-bar {
    display: block;
}

.meter-track {
    fill: color-mix(in srgb, var(--chart-mark) 12%, var(--surface));
}

.meter-fill {
    fill: var(--chart-mark);
}

.meter-warning .meter-track {
    fill: var(--color-warning-bg);
}

.meter-warning .meter-fill {
    fill: var(--color-warning);
}

.meter-danger .meter-track {
    fill: var(--color-danger-bg);
}

.meter-danger .meter-fill {
    fill: var(--color-danger);
}

.meter-text {
    color: var(--color-text-muted);
    font-size: var(--font-size-caption);
}

.meter-warning .meter-text {
    color: var(--color-warning);
    font-weight: var(--weight-emph);
}

.meter-danger .meter-text {
    color: var(--color-danger);
    font-weight: var(--weight-emph);
}

/* Charts: an axis column and a fluid plot of the same fixed height. */
.chart-frame {
    display: flex;
    align-items: stretch;
}

.chart-yaxis {
    flex: none;
    overflow: visible;
}

.chart-plot {
    display: block;
    flex: 1 1 auto;
    min-width: 0;
    overflow: visible;
    border-radius: var(--radius-sm);
}

.chart-plot:focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 4px;
}

.chart text {
    font-family: var(--font-sans);
}

.chart-tick {
    fill: var(--chart-axis);
    font-size: var(--font-size-caption);
    font-variant-numeric: tabular-nums;
}

.chart-grid {
    stroke: var(--chart-grid);
    stroke-width: 1;
    shape-rendering: crispEdges;
}

.chart-baseline {
    stroke: var(--line-strong);
    stroke-width: 1;
    shape-rendering: crispEdges;
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-4);
    margin: 0 0 var(--space-3);
    padding: 0;
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    list-style: none;
}

.chart-legend li {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
}

.chart-swatch {
    width: 0.625rem;
    height: 0.625rem;
    border-radius: 3px;
}

.chart-swatch-mark {
    background: var(--chart-mark);
}

.chart-swatch-context {
    background: var(--chart-context);
}

.chart-swatch-1 {
    background: var(--chart-1);
}

.chart-swatch-2 {
    background: var(--chart-2);
}

/* Columns: ink, the current one in the accent, last year in the context grey; the value on the current cap only. */
.chart-col {
    fill: var(--chart-mark);
}

.chart-col-context {
    fill: var(--chart-context);
}

.chart-col-accent {
    fill: var(--chart-accent);
}

.chart-col-1 {
    fill: var(--chart-1);
}

.chart-col-2 {
    fill: var(--chart-2);
}

.chart-cap {
    fill: var(--color-text);
    font-size: var(--font-size-caption);
    font-weight: var(--weight-emph);
}

/* Lines: 2px ink, a faint wash, solid hairline references with direct labels, the below-zero band. */
.chart-line-path {
    fill: none;
    stroke: var(--chart-mark);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.chart-area {
    fill: var(--chart-mark);
    opacity: 0.08;
}

.chart-ref {
    stroke: var(--line-strong);
    stroke-width: 1;
    shape-rendering: crispEdges;
}

.chart-ref-zero {
    stroke: var(--chart-axis);
}

.chart-ref-label {
    fill: var(--color-text-muted);
    font-size: var(--font-size-caption);
}

.chart-below-zero {
    fill: var(--color-danger);
    opacity: 0.06;
}

.chart-below-zero-label {
    fill: var(--color-danger);
    font-size: var(--font-size-caption);
    font-weight: var(--weight-emph);
}

.chart-dot {
    fill: var(--chart-mark);
    stroke: var(--surface);
    stroke-width: 2;
}

.chart-dot-accent {
    fill: var(--chart-accent);
}

/* A direct label over the line keeps a surface halo, so it reads where it crosses a mark. */
.chart-marker-label {
    fill: var(--color-text);
    font-size: var(--font-size-caption);
    font-weight: var(--weight-emph);
    paint-order: stroke;
    stroke: var(--surface);
    stroke-width: 3px;
    stroke-linejoin: round;
}

/* Hover and focus: each column (or stretch of days) has a hit area over its whole band; its tooltip shows by CSS alone. */
.chart-hit {
    outline: none;
}

.chart-hit-area {
    fill: transparent;
}

.chart-hit:hover .chart-hit-area {
    fill: var(--hover-tint);
}

.chart-hit-line:hover .chart-hit-area {
    fill: transparent;
}

.chart-hit:focus-visible .chart-hit-area {
    stroke: var(--color-focus);
    stroke-width: 2;
}

.chart-tip {
    visibility: hidden;
    pointer-events: none;
}

.chart-hit:hover .chart-tip, .chart-hit:focus-visible .chart-tip {
    visibility: visible;
}

/* The tooltip: a white box with a hairline; the period muted, each value strong before its series name. */
.chart-tip rect {
    fill: var(--surface);
    stroke: var(--line-strong);
    stroke-width: 1;
}

.chart-tip text {
    fill: var(--color-text-muted);
    font-size: var(--font-size-caption);
}

.chart-tip .chart-tip-value {
    fill: var(--color-text);
    font-size: var(--font-size-sm);
    font-weight: var(--weight-title);
    font-variant-numeric: tabular-nums;
}

.chart-crosshair {
    stroke: var(--line-strong);
    stroke-width: 1;
    shape-rendering: crispEdges;
}

/* Bar lists: label, bar, value in a column of its own; on a phone the bar goes under the label. */
.bar-list {
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
    list-style: none;
}

.bar-row {
    display: grid;
    grid-template-columns: minmax(6rem, 32%) minmax(0, 1fr) auto;
    align-items: center;
    gap: var(--space-3);
    min-height: var(--row-height-dense);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    text-decoration: none;
}

a.bar-row:hover {
    background: var(--hover-tint);
    color: var(--color-text);
}

.bar-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.bar-label, .bar-secondary {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bar-secondary {
    color: var(--color-text-muted);
    font-size: var(--font-size-caption);
}

.bar-track {
    display: block;
}

.bar-fill {
    fill: var(--chart-mark);
}

.bar-fill-other {
    fill: var(--chart-context);
}

.bar-fill-ramp-1 { fill: var(--chart-ramp-1); }
.bar-fill-ramp-2 { fill: var(--chart-ramp-2); }
.bar-fill-ramp-3 { fill: var(--chart-ramp-3); }
.bar-fill-ramp-4 { fill: var(--chart-ramp-4); }

.bar-value {
    min-width: 4.5rem;
    font-variant-numeric: tabular-nums;
    font-weight: var(--weight-emph);
    text-align: right;
    white-space: nowrap;
}

/* A narrow list (a phone, a 4-column card, a column inside a card) puts the bar under its label, so labels stay whole. */
.bar-list {
    container-type: inline-size;
}

@container (max-width: 28rem) {
    .bar-row {
        grid-template-columns: minmax(0, 1fr) auto;
        gap: var(--space-1) var(--space-3);
    }

    .bar-track {
        grid-row: 2;
        grid-column: 1 / -1;
    }
}

@media (max-width: 599px) {
    .chart-tick-alt {
        display: none;
    }
}

/* The card around a chart: title, Chart / Table, "View all"; the body keeps its final height while it loads; a refetch fades
   the current content (opacity only, under 200 ms; instant with reduced motion). */
.chart-card {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chart-card-tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
}

.chart-card-link .icon {
    margin-left: 0.125rem;
}

.chart-card-body {
    min-width: 0;
    transition: opacity 150ms ease-out;
}

.chart-card-body.is-refetching, .hero-figure.is-refetching, .stat-tile.is-refetching {
    opacity: 0.5;
}

.chart-body-columns {
    min-height: 254px;
}

.chart-body-line {
    min-height: 240px;
}

.chart-card-body > .bar-list + .meter {
    margin-top: var(--space-4);
}

.chart-card-foot {
    margin: var(--space-3) 0 0;
    color: var(--color-text-muted);
    font-size: var(--font-size-caption);
}

.segmented-sm .segmented-option {
    min-height: calc(var(--control-height-sm) - 4px);
    padding: 0 var(--space-2);
    font-size: var(--font-size-sm);
}

/* The table twin: the shared table look, numbers right-aligned in tabular figures; it scrolls inside its card when wide. */
.chart-table-wrap {
    overflow-x: auto;
    overscroll-behavior-x: contain;
}

.chart-table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
    line-height: var(--leading-dense);
}

.chart-table th, .chart-table td {
    height: var(--row-height-dense);
    padding: 0 var(--space-3);
    border-bottom: 1px solid var(--line);
    text-align: left;
    white-space: nowrap;
}

.chart-table thead th {
    color: var(--color-text-muted);
    font-size: var(--font-size-caption);
    font-weight: var(--weight-emph);
}

.chart-table tbody th {
    font-weight: var(--weight-body);
}

.chart-table tbody tr:last-child > * {
    border-bottom-color: transparent;
}

.chart-table tbody tr:hover {
    background: var(--hover-tint);
}

.chart-table .num {
    text-align: right;
}

/* Skeleton blocks: static grey shapes at the final height (no shimmer, skill rule 0.3). */
.skeleton-block {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.skeleton-block-hero {
    min-height: 13rem;
}

.skeleton-block-tile {
    min-height: 6.5rem;
}

.skeleton-figure {
    width: 55%;
    height: 1.75rem;
    border-radius: var(--radius-sm);
}

.skeleton-block-hero .skeleton-figure {
    height: var(--font-size-hero);
}

.skeleton-w-40 {
    width: 40%;
}

.skeleton-w-60 {
    width: 60%;
}

.skeleton-block-columns {
    justify-content: flex-end;
    height: 254px;
}

.skeleton-columns {
    display: flex;
    align-items: flex-end;
    gap: var(--space-2);
    height: 194px;
    padding: 0 0 26px 48px;
}

.skeleton-column {
    flex: 1 1 0;
    max-width: 24px;
    margin: 0 auto;
    border-radius: 4px 4px 0 0;
    background: var(--surface-sunken);
}

.skeleton-column-0 { height: 45%; }
.skeleton-column-1 { height: 70%; }
.skeleton-column-2 { height: 55%; }
.skeleton-column-3 { height: 85%; }
.skeleton-column-4 { height: 35%; }

.skeleton-block-line {
    height: 240px;
}

.skeleton-area {
    flex: 1;
    margin: 18px 0 26px 56px;
    border-radius: var(--radius-md);
    background: var(--surface-sunken);
}

.skeleton-block .skeleton-row {
    padding: 0;
}

/* Inside a dashboard card: a row of figures under a chart, columns of small lists, a figure that links to its list. */
.chart-figures {
    margin-top: var(--space-4);
}

.chart-figures .delta {
    margin-top: var(--space-1);
}

.figure-link {
    color: inherit;
    text-decoration: none;
}

.figure-link:hover {
    color: inherit;
    text-decoration: underline;
}

.dash-columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
    gap: var(--space-4) var(--space-6);
    margin-top: var(--space-4);
}

.dash-columns > div {
    min-width: 0;
}

.dash-columns-flush {
    margin-top: 0;
}

.dash-columns .eyebrow, .dash-list-label {
    margin-bottom: var(--space-2);
}

.dash-list-label {
    margin-top: var(--space-4);
}

.dash-figure {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-3) 0;
}

/* The attention list scrolls inside its card when it is long, so it never stretches the row beside the forecast. */
.attention-body {
    max-height: 23rem;
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* Data health: two columns of checks on a wide card. */
@media (min-width: 1200px) {
    .health-list {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        column-gap: var(--space-6);
    }

    .health-list > li + li {
        border-top: 0;
    }

    .health-list > li {
        border-bottom: 1px solid var(--line);
    }
}

.health-list .row-list-secondary {
    white-space: normal;
}

/* My work's To do now: groups under small labels with their count; long lists scroll inside the card on a wide screen. */
.work-group + .work-group {
    margin-top: var(--space-4);
}

.work-group > .eyebrow {
    margin-bottom: var(--space-1);
}

.work-group-count {
    margin-left: var(--space-1);
    color: var(--color-text);
}

.work-group-more {
    margin-top: var(--space-1);
}

@media (min-width: 1200px) {
    .todo-now-body {
        max-height: calc(100dvh - var(--header-height) - 12rem);
        min-height: 20rem;
        overflow-y: auto;
        overscroll-behavior: contain;
    }
}

/* Action rows (My work, the attention list): kind icon, text, trailing value or chip, chevron; the row is the link. */
.action-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.action-list > li + li {
    border-top: 1px solid var(--line);
}

.action-row.row-list-item {
    min-height: 3.5rem;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
}

.action-row-icon {
    position: relative;
    display: grid;
    flex: none;
    place-items: center;
    width: 2rem;
    height: 2rem;
    border-radius: var(--radius-sm);
    background: var(--surface-sunken);
    color: var(--color-text-muted);
}

/* The attention list's severity: a dot on the icon, beside the words that say what is wrong. */
.action-row-icon-critical::after, .action-row-icon-warning::after, .action-row-icon-info::after {
    content: "";
    position: absolute;
    top: -2px;
    right: -2px;
    width: 8px;
    height: 8px;
    border: 2px solid var(--surface);
    border-radius: 50%;
}

.action-row-icon-critical::after {
    background: var(--color-danger);
}

.action-row-icon-warning::after {
    background: var(--color-warning);
}

.action-row-icon-info::after {
    background: var(--chart-context);
}

.action-row-trailing {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-1) var(--space-2);
}

.action-row-value {
    color: var(--color-text);
    font-variant-numeric: tabular-nums;
    font-weight: var(--weight-emph);
}

.action-row-chevron {
    flex: none;
    width: 16px;
    height: 16px;
    background: var(--color-text-muted);
    -webkit-mask: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'><path d='m9 18 6-6-6-6'/></svg>") center / 16px no-repeat;
    mask: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'><path d='m9 18 6-6-6-6'/></svg>") center / 16px no-repeat;
}

/* A phone keeps the row's text whole: the amount and the chip move to a line of their own under it. */
@media (max-width: 599px) {
    .action-row.row-list-item {
        flex-wrap: wrap;
        row-gap: var(--space-1);
    }

    .action-row-chevron {
        order: 2;
    }

    .action-row-trailing {
        flex: 1 0 100%;
        justify-content: flex-start;
        order: 3;
        padding-left: calc(2rem + var(--space-3));
    }
}

@media (prefers-reduced-motion: reduce) {
    .chart-card-body, .hero-figure, .stat-tile {
        transition: none;
    }
}
