/* =====================================================
   INRADR Design System — Cards (Ch. 04)
   Ported from .docs/context/design/design-system-inradr.html
   inradr-design layer · KPI card, KPI row and ranking card

   Consumers: InradrKpiCard.razor (dashboards), InradrKpiRow.razor and SparklineRenderer.razor (DetailView KPI items),
   InradrRankingCards.razor (the income statement's top/flop objects). The spec's card grid still has no consumer (OQ-35).
   ===================================================== */

/* --- KPI card --- */
.inradr-kpi-card {
    background: var(--inradr-color-surface);
    border: 1px solid var(--inradr-color-border);
    border-radius: var(--inradr-radius-lg); /* 25px */
    padding: var(--inradr-kpi-card-padding);
    box-sizing: border-box;
    width: 100%;
    height: var(--inradr-kpi-card-height);
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: var(--inradr-space-xs); /* minimum body-to-trend gap when space-between has nothing to distribute */

    .inradr-kpi-card__body {
        display: flex;
        flex-direction: column;
        gap: var(--inradr-kpi-label-gap);
        min-width: 0; /* lets the body shrink: flex items default to min-width:auto */
    }

    /* On a narrow tile the LABEL truncates, the figure always stays complete.
       The full text is on the title attribute of the tile (or of the label). */
    .inradr-kpi-card__label {
        font-size: var(--inradr-text-kpi-label-size);
        font-weight: var(--inradr-text-kpi-label-weight);
        line-height: var(--inradr-text-kpi-label-line-height);
        color: var(--inradr-color-text-secondary);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Never wraps: with min-width:0 on the body the number could otherwise break into two
       lines ("1.542.512" / "€") and overflow the 86px tile. */
    .inradr-kpi-card__value {
        font-size: var(--inradr-text-h1-size);
        font-weight: var(--inradr-text-h1-weight);
        line-height: var(--inradr-text-h1-line-height);
        color: var(--inradr-color-text-primary);
        white-space: nowrap;

        /* Dark appearance (spec): KPI values in the heading colour (#F5F5F5), not the white primary text. */
        :root[data-theme="dark"] & {
            color: var(--inradr-color-text-heading);
        }
    }

    .inradr-kpi-card__trend {
        display: flex;
        align-items: center;
        gap: var(--inradr-space-sm);
        flex: 0 0 auto; /* the delta never wraps or leaves the tile */
    }

    .inradr-kpi-card__trend-value {
        font-size: var(--inradr-text-h1-size);
        font-weight: var(--inradr-text-h1-weight);
        line-height: var(--inradr-text-h1-line-height);
        color: var(--inradr-color-status-ok);
        white-space: nowrap;
    }

    /* SVG stroke colors via CSS variables — no hardcoded HEX in SVG attributes */
    .inradr-kpi-card__trend--up polyline {
        stroke: var(--inradr-color-status-ok);
    }

    .inradr-kpi-card__trend--flat line {
        stroke: var(--inradr-color-text-muted);
    }

    .inradr-kpi-card__trend--down polyline {
        stroke: var(--inradr-color-status-danger-text);
    }

    /* Icon geometry lives here so the Razor markup carries no hard values. */
    .inradr-kpi-card__trend svg {
        flex: 0 0 auto;
        fill: none;
        stroke: currentColor;
        stroke-width: 2;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

    /* Delta text colour per direction. The base .inradr-kpi-card__trend-value is green (= up); without these two
       a falling figure renders a red arrow next to green text. */
    .inradr-kpi-card__trend--down .inradr-kpi-card__trend-value {
        color: var(--inradr-color-status-danger-text);
    }

    .inradr-kpi-card__trend--flat .inradr-kpi-card__trend-value {
        color: var(--inradr-color-text-muted);
    }
}

/* --- KPI row ---
   The KPI cards above a dashboard (InradrKpiRow.razor): as many equal columns as fit at the card's narrowest
   readable width, so four cards stand in one row on a desktop and wrap in pairs on a narrow window. Below the row the
   distance of the predecessor's card grid, as the selection band keeps it. */
.inradr-kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(var(--inradr-kpi-card-min-width), 1fr));
    gap: var(--inradr-space-sm);
    margin-bottom: var(--inradr-space-md);
}

/* One row whatever the number of cards (InradrKpiRow.SingleRow) - the predecessor's grid of the data deliveries: every
   card an implicit column of equal width that may shrink below its readable width; a window too narrow scrolls the row. */
.inradr-kpi-row--single-row {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    overflow-x: auto;
}

/* --- Ranking cards (InradrRankingCards.razor) ---
   The design spec's ranking card (design-system-inradr.html, .ranking-card): an asset and its fund on the left, a label
   and the figure on the right; the figure is coloured by its sign, without a direction arrow (spec since 2026-09-30).
   Its first consumer is the income statement's top/flop objects; the cards stand in columns under a heading, one column
   below 1024px. */
.inradr-ranking-columns {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--inradr-space-lg);
}

.inradr-ranking-columns__column {
    display: grid;
    align-content: start;
    gap: 10px;
}

.inradr-ranking-columns__heading {
    font-size: var(--inradr-text-h3-size);
    font-weight: var(--inradr-text-h3-weight);
    line-height: var(--inradr-text-h3-line-height);
    color: var(--inradr-color-text-primary);
}

.inradr-ranking-list {
    display: grid;
    gap: var(--inradr-space-xs);
}

.inradr-ranking-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--inradr-space-xxs);
    box-sizing: border-box;
    width: 100%;
    min-height: 68px;
    padding: var(--inradr-space-xs);
    border: 1px solid var(--inradr-color-border);
    border-radius: var(--inradr-radius-sm);
    background: var(--inradr-color-surface-muted);
}

.inradr-ranking-card__left {
    display: flex;
    flex-direction: column;
    gap: var(--inradr-space-xxs);
    min-width: 0;
}

.inradr-ranking-card__asset,
.inradr-ranking-card__fund {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.inradr-ranking-card__asset {
    font-size: var(--inradr-text-body-size);
    font-weight: var(--inradr-text-body-weight);
    line-height: var(--inradr-text-body-line-height);
    color: var(--inradr-color-text-primary);
}

.inradr-ranking-card__fund {
    font-size: var(--inradr-text-caption-size);
    font-weight: var(--inradr-text-caption-weight);
    line-height: var(--inradr-text-caption-line-height);
    color: var(--inradr-color-text-secondary);
}

.inradr-ranking-card__right {
    display: inline-flex;
    align-items: center;
    gap: var(--inradr-space-xxs);
    margin-left: auto;
    padding-left: var(--inradr-space-2xs);
    text-align: right;
    white-space: nowrap;
}

.inradr-ranking-card__label {
    font-size: var(--inradr-text-kpi-label-size);
    font-weight: var(--inradr-text-kpi-label-weight);
    line-height: var(--inradr-text-kpi-label-line-height);
    color: var(--inradr-color-text-secondary);
}

.inradr-ranking-card__value {
    font-size: var(--inradr-text-body-bold-size);
    font-weight: var(--inradr-text-body-bold-weight);
    line-height: var(--inradr-text-body-bold-line-height);
    color: var(--inradr-color-text-primary);
}

/* The tones after the base rules: same specificity, so the later rule wins. */
.inradr-ranking-card__value--up {
    color: var(--inradr-color-status-ok);
}

.inradr-ranking-card__value--down {
    color: var(--inradr-color-status-danger-text);
}

@media (max-width: 1024px) {
    .inradr-ranking-columns {
        grid-template-columns: 1fr;
    }
}
