/* gvs-reports.css — GVS.Components.Reports: KPI tiles, info tips, chart cards and their detailed view,
   report tables, tabs and the 12-column card grid. Charts, tables, buttons, empty states and skeletons are
   the shared GVS.Components ones; this file lays them out and styles only the parts with no shared equivalent. */

.rp-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* ---------- Tabs --------------------------------------------------------- */
.rp-tabs { display: flex; align-items: center; gap: 16px; padding: 0 clamp(16px, 3vw, 24px); }
.rp-tablist { display: flex; gap: 32px; min-width: 0; overflow-x: auto; scrollbar-width: thin; }
.rp-tab { position: relative; flex-shrink: 0; padding: 16px 8px; border: none; background: none; font: inherit; font-size: 14px; font-weight: 500; color: var(--gvs-fg-3); white-space: nowrap; cursor: pointer; transition: color .2s; }
.rp-tab::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: var(--gvs-primary); transform: scaleX(0); transition: transform .3s ease-out; }
.rp-tab:hover, .rp-tab.active { color: var(--gvs-fg-1); }
.rp-tab:hover::after { transform: scaleX(.75); }
.rp-tab.active::after { transform: scaleX(1); }
.rp-tab:focus-visible { outline: none; box-shadow: inset var(--gvs-focus-ring); border-radius: 6px; }
.rp-tab-tools { margin-left: auto; display: flex; align-items: center; gap: 4px; flex-shrink: 0; }

/* ---------- Card grid ---------------------------------------------------- */
.rp-page { display: flex; flex-direction: column; gap: 24px; }
/* Cards sit in a 12-column grid. Each cell carries its span per breakpoint (--rp-xs … --rp-xl, already resolved
   mobile-first by GvsReportLayout), and the breakpoints match MudBlazor's. */
.rp-cell { display: flex; flex-direction: column; min-width: 0; grid-column: span var(--rp-xs, 12); }
.rp-cell > * { flex: 1; }
@media (min-width: 600px) { .rp-cell { grid-column: span var(--rp-sm, 12); } }
@media (min-width: 960px) { .rp-cell { grid-column: span var(--rp-md, 12); } }
@media (min-width: 1280px) { .rp-cell { grid-column: span var(--rp-lg, 12); } }
@media (min-width: 1920px) { .rp-cell { grid-column: span var(--rp-xl, 12); } }

/* ---------- Loading skeletons ------------------------------------------- */
/* The same 24px rhythm as .rp-page, so the KPIs and the chart do not touch while loading. */
.rp-skeleton-body { display: flex; flex-direction: column; gap: 24px; }

/* ---------- KPI tiles ---------------------------------------------------- */
/* Tiles share the cards' 12-column grid, so the definition sizes them the same way. */
.rp-kpis { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 12px; }
.rp-kpi { position: relative; display: flex; flex-direction: column; padding: 12px; background: var(--gvs-surface); border: 1px solid var(--gvs-border); border-radius: var(--gvs-radius-md); box-shadow: var(--gvs-elev-1); }
.rp-kpi p { margin: 0; }
.rp-kpi-label { padding-right: 32px; font-size: 11px; line-height: 1.3; color: var(--gvs-fg-3); }
.rp-kpi-value { font-size: 18px; font-weight: 700; line-height: 1.4; color: var(--gvs-fg-1); font-variant-numeric: tabular-nums; }
.rp-kpi-caption { margin-top: auto; padding-top: 4px; font-size: 11px; line-height: 1.4; color: var(--gvs-fg-3); }
.rp-kpi-info { position: absolute; top: 10px; right: 10px; }
.rp-kpi-compact { padding: 8px 12px; }
.rp-kpi-compact .rp-kpi-value { font-size: 16px; }
.rp-kpi-tall { padding: 16px; }
.rp-kpi-tall .rp-kpi-label { font-size: 13px; }
.rp-kpi-tall .rp-kpi-value { font-size: 32px; line-height: 1.25; }
.rp-kpi-tall .rp-kpi-caption { font-size: 12px; }
.rp-tone-success { color: var(--gvs-success-500); }
.rp-tone-info { color: var(--gvs-info-500); }
.rp-tone-accent { color: var(--gvs-primary); }
/* Amber 500 is too pale for text on the white card (about 2:1); 700 reads there, and is too dark on navy. */
.rp-tone-warning { color: var(--gvs-warning-700); }
[data-theme="dark"] .rp-tone-warning { color: var(--gvs-warning-500); }
.rp-tone-danger { color: var(--gvs-danger-500); }

/* ---------- Info tooltip ------------------------------------------------- */
.rp-info { position: relative; display: inline-flex; align-items: center; color: var(--gvs-fg-3); border-radius: 999px; }
.rp-info-btn { display: inline-flex; align-items: center; padding: 0; border: none; background: none; color: inherit; cursor: help; border-radius: 999px; }
.rp-info .material-symbols-rounded { font-size: 16px; }
.rp-info-btn:focus-visible { outline: none; box-shadow: var(--gvs-focus-ring); }
/* display rather than opacity: a hidden tip that is still laid out widens the page on a phone. */
.rp-info-tip { position: absolute; top: calc(100% + 8px); left: -4px; z-index: 60; display: none; width: min(16rem, calc(100vw - 48px)); padding: 6px 10px; border-radius: 6px; background: var(--gvs-surface); color: var(--gvs-fg-1); border: 1px solid var(--gvs-border); box-shadow: 0 4px 12px rgba(0, 0, 0, .15); font-size: 12px; font-weight: 500; line-height: 1.4; text-align: left; white-space: normal; pointer-events: none; }
.rp-info-end .rp-info-tip { left: auto; right: -4px; }
.rp-info:not(.rp-info-dismissed):hover .rp-info-tip, .rp-info:not(.rp-info-dismissed):has(.rp-info-btn:focus-visible) .rp-info-tip,
.rp-info-open .rp-info-tip { display: block; }

/* ---------- Chart cards -------------------------------------------------- */
.rp-charts { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 24px; }
.rp-card { position: relative; display: flex; flex-direction: column; min-width: 0; padding: 20px 16px 16px; background: var(--gvs-surface); border: 1px solid var(--gvs-border); border-radius: var(--gvs-radius-lg); }
.rp-card:hover, .rp-card:focus-within { z-index: 20; }
.rp-card-head { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.rp-card-head h3 { margin: 0; font-size: 16px; font-weight: 600; color: var(--gvs-fg-1); }
.rp-column-picker { margin-left: auto; display: flex; align-items: center; gap: 4px; flex: none; }
.rp-column-select { width: 200px; }
.rp-card-sub { margin: 0 0 8px; font-size: 12px; color: var(--gvs-fg-3); }
.rp-card-body { flex: 1; min-height: 0; min-width: 0; }
.rp-card-foot { margin: 8px 0 0; font-size: 11px; color: var(--gvs-fg-3); }
/* The expand button sits in its own row under the plot, so it never covers a legend ApexCharts puts at the bottom. */
.rp-card-end { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; margin-top: 4px; }
.rp-card-end .rp-card-foot { flex: 1; min-width: 0; }
.rp-card-expand { flex-shrink: 0; margin: 0 -6px -6px 0; color: var(--gvs-fg-3); }
.rp-card-expand:hover { color: var(--gvs-fg-1); }
.rp-card-expand:focus-visible { outline: none; box-shadow: var(--gvs-focus-ring); }

/* ---------- Chart detail modal ------------------------------------------- */
.rp-modal.mh-modal { width: min(1100px, 100%); max-height: calc(100vh - 48px); display: flex; flex-direction: column; }
.rp-modal .mh-modal-body { overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.rp-modal-sub { margin: 0; font-size: 13px; color: var(--gvs-fg-3); }
.rp-modal-info { margin: 0; font-size: 14px; line-height: 1.5; color: var(--gvs-fg-2); }
.rp-modal-plot { min-width: 0; }
.rp-modal .rp-card-foot { margin: 0; }
.rp-modal .mh-modal-head { gap: 8px; }
.rp-modal-title { flex: 1; min-width: 0; }
.rp-modal-export { flex-shrink: 0; padding: 0 12px; }
/* The export button spins while the export runs. */
.rp-generating .material-symbols-rounded { display: inline-block; animation: rp-spin 1s linear infinite; }
@keyframes rp-spin { to { transform: rotate(360deg); } }

/* The shared charts leave text colours to ApexCharts, which assumes a light surface. CSS outranks
   the SVG attributes it writes, so the theme tokens win in both modes. Axis text only: the value
   labels share the .apexcharts-text class and sit on the series colour, not on the card. */
.rp-plot .apexcharts-xaxis-label, .rp-plot .apexcharts-yaxis-label { fill: var(--gvs-fg-3); }
/* Series colours run from navy to pale blue, so no single text colour reads on all of them. White
   with a dark outline does, whatever the fill. */
.rp-plot .apexcharts-datalabel, .rp-plot .apexcharts-pie-label {
    fill: #fff; paint-order: stroke; stroke: rgba(10, 26, 46, .6); stroke-width: 2.5px; stroke-linejoin: round;
}
.rp-plot .apexcharts-legend-text { color: var(--gvs-fg-2) !important; }
.rp-plot .apexcharts-gridline { stroke: var(--gvs-border); }
/* ApexCharts draws the gap between donut slices in white, which glares on the dark card. */
.rp-plot .apexcharts-pie-area { stroke: var(--gvs-surface); }
.rp-plot .apexcharts-tooltip { background: var(--gvs-surface) !important; color: var(--gvs-fg-1); border-color: var(--gvs-border) !important; }

/* ---------- Table widgets (GvsDataTable) --------------------------------- */
.rp-table-card { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.rp-table-title { margin: 0; font-size: 16px; font-weight: 600; color: var(--gvs-fg-1); }
.rp-table .gvs-dt th, .rp-table .gvs-dt td { white-space: nowrap; }
.rp-th-btn { display: inline-flex; align-items: center; gap: 6px; padding: 0; border: none; background: none; color: inherit; font: inherit; font-weight: inherit; cursor: pointer; border-radius: 4px; }
.rp-th-btn .material-symbols-rounded { font-size: 15px; color: var(--gvs-fg-3); }
.rp-th-btn:focus-visible { outline: none; box-shadow: var(--gvs-focus-ring); }
.rp-th-icon, .rp-td-icon { text-align: center; }
/* GvsDataTable left-aligns every header with a more specific rule, so the headers have to match it to follow their column. */
.rp-table .gvs-dt thead th.rp-th-num { text-align: right; }
.rp-table .gvs-dt thead th.rp-th-icon { text-align: center; }
.rp-th-icon .material-symbols-rounded { font-size: 16px; color: var(--gvs-fg-3); }
.rp-td-icon .material-symbols-rounded { font-size: 18px; color: var(--gvs-success-500); }
.rp-td-num { text-align: right; font-variant-numeric: tabular-nums; }
.rp-muted { color: var(--gvs-fg-3); }

/* A cell's quieter second line, and the key under a table. */
.rp-tcell { display: inline-block; }
.rp-tcell-detail { display: block; font-size: 11px; color: var(--gvs-fg-3); }
/* One line, side by side: wrapping lets the table squeeze the column to its narrowest badge and stack the rest. In a phone's
   row card, a cell as wide as three badges would size the card's auto column and crush the other, so it takes a whole row. */
.rp-badges { display: inline-flex; flex-wrap: nowrap; gap: 4px; }
@media (max-width: 700px) {
    .rp-badges { flex-wrap: wrap; }
    .rp-table .gvs-dt tbody td:has(.rp-badges) { grid-column: 1 / -1; }

    /* A row card's two columns share the width and wrap, since hiding columns can pair any two long values. */
    .rp-table .gvs-dt tbody tr { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
    .rp-table .gvs-dt tbody td { white-space: normal; overflow-wrap: anywhere; }
    .rp-table .gvs-dt tbody td.rp-td-num { text-align: left; }
    .rp-card-head { flex-wrap: wrap; }
    .rp-column-picker { margin-left: 0; width: 100%; }
    .rp-column-select { flex: 1; }
}
.rp-table-key { display: flex; flex-wrap: wrap; gap: 6px 12px; margin: 4px 0 0; padding: 0; list-style: none; font-size: 12px; }

/* ---------- Matrix tables ------------------------------------------------- */
/* The scroller is positioned so the cells' screen-reader text is clipped with them instead of widening the page. */
.rp-matrix-scroll { position: relative; max-height: max(420px, calc(100vh - 400px)); max-height: max(420px, calc(100dvh - 400px)); overflow: auto; border: 1px solid var(--gvs-border); border-radius: var(--gvs-radius-md); }
.rp-matrix-scroll:focus-visible { outline: none; box-shadow: var(--gvs-focus-ring); }
.rp-matrix { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12px; }
.rp-matrix th, .rp-matrix td { padding: 8px 10px; text-align: center; white-space: nowrap; background: var(--gvs-surface); border-bottom: 1px solid var(--gvs-border); }
.rp-matrix thead th { position: sticky; top: 0; z-index: 2; background: var(--gvs-surface-sunken); color: var(--gvs-fg-2); font-weight: 600; }
.rp-matrix tr > :first-child { position: sticky; left: 0; z-index: 1; text-align: left; border-right: 1px solid var(--gvs-border); }
.rp-matrix tbody tr > :first-child { font-weight: 400; }
/* A matrix centres its figures, but a column the report right-aligns stays right-aligned. */
.rp-matrix .rp-td-num, .rp-matrix th.rp-th-num { text-align: right; }
.rp-matrix thead tr > :first-child, .rp-matrix tfoot tr > :first-child { z-index: 3; }
.rp-matrix tfoot th, .rp-matrix tfoot td { position: sticky; bottom: 0; z-index: 2; background: var(--gvs-surface-sunken); font-weight: 700; border-bottom: none; border-top: 1px solid var(--gvs-border); }
.rp-matrix tbody th .rp-tcell-text { font-weight: 600; color: var(--gvs-fg-1); }

/* ---------- Progress while a report generates ---------------------------- */
.rp-progress { display: flex; flex-direction: column; gap: 6px; max-width: 480px; margin: 0 auto 20px; }
.rp-progress-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--gvs-fg-2); }
/* The darker teal and second text colour keep 4.5:1 on the page background at these small sizes. */
.rp-progress-percent { font-weight: 600; color: var(--gvs-primary-press); font-variant-numeric: tabular-nums; }
.rp-progress-countdown { display: flex; flex-direction: column; align-items: center; gap: 2px; margin: 0; font-size: 12px; color: var(--gvs-fg-2); font-variant-numeric: tabular-nums; }

/* ---------- Responsive --------------------------------------------------- */
/* Phones: tighter spacing, a detailed view that fills the screen, and tips kept inside their card. */
@media (max-width: 640px) {
    .rp-tabs { padding: 0 12px; }
    .rp-tablist { gap: 16px; }
    .rp-tab-tools { display: none; }
    .rp-kpis { gap: 10px; }
    .rp-card { padding: 16px 12px 12px; }
    .mh-scrim:has(.rp-modal) { padding: 12px; }
    .rp-modal.mh-modal { max-height: calc(100vh - 24px); }
    .rp-modal .mh-modal-body { padding: 16px; }
    /* The title needs the width on a phone, so the export keeps only its icon; its name stays for screen readers. */
    .rp-modal-export { width: 44px; padding: 0; }
    .rp-modal-export-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
    /* The icon can sit anywhere along a title, so pin the tip to the card instead. */
    .rp-card .rp-info { position: static; }
    .rp-card .rp-info-tip { top: 48px; left: 8px; right: 8px; width: auto; }
    /* KPI tiles are half the screen wide; keep their tips inside the tile. */
    .rp-kpi .rp-info-tip { width: calc(50vw - 28px); }
}

@media (prefers-reduced-motion: reduce) {
    .rp-tab::after { transition: none; }
    .rp-generating .material-symbols-rounded { animation: none; }
}
.rp-table-error { margin: 0 0 6px; padding: 0 12px; font-size: 12px; color: var(--gvs-danger, #b3261e); }
