/* ========================================
   Reports Module Styles
   Global (not component-scoped): scoped CSS bundles are unreliable in
   production, and the report catalog's selected-row state is feature-critical.
   ======================================== */

/* ========================================
   Report catalog list — row states

   Bootstrap 5.3 paints an opaque background on every CELL
   (`.table > :not(caption) > * > * { background-color: var(--bs-table-bg) }`,
   where --bs-table-bg resolves to the body background). That cell background
   covers anything set on the <tr>, which is why row highlighting applied to the
   row element never appeared. Row states must be painted on the cells.
   ======================================== */
.reports-list .reports-table tbody tr {
    cursor: pointer;
}

.reports-list .reports-table tbody tr > td {
    transition: background-color 0.12s ease-in-out;
}

.reports-list .reports-table tbody tr:hover > td {
    background-color: rgba(var(--bs-primary-rgb), 0.07);
}

.reports-list .reports-table tbody tr.reports-row-selected > td,
.reports-list .reports-table tbody tr.reports-row-selected:hover > td {
    background-color: rgba(var(--bs-primary-rgb), 0.18);
}

/* The accent bar lives on the first cell: under border-collapse a border on the
   <tr> itself is unreliable, and this keeps row content from shifting. */
.reports-list .reports-table tbody tr > td:first-child {
    border-left: 3px solid transparent;
}

.reports-list .reports-table tbody tr.reports-row-selected > td:first-child {
    border-left-color: var(--bs-primary);
}

.reports-list .reports-table tbody tr.reports-row-selected strong {
    color: var(--bs-primary);
}

/* Keyboard focus stays visible but is not the only selection cue. */
.reports-list .reports-table tbody tr:focus-visible {
    outline: 2px solid var(--bs-primary);
    outline-offset: -2px;
}

/* ========================================
   Report viewer — subtotal and total rows

   Same cell-painting rule as the catalog above: Bootstrap's opaque per-cell
   background covers anything set on the <tr>, so these paint on the cells and
   carry enough specificity to win the tie against `.table > * > * > *`.
   ======================================== */
.report-viewer-modal .report-grid-table tbody tr.report-subtotal-row > td {
    background-color: var(--bg-tertiary);
    font-weight: 600;
    font-style: italic;
}

/* The report total is pinned to the bottom of the scroll container, mirroring the
   sticky header, so it stays readable on a long report without scrolling to the
   end. The background must be OPAQUE — data rows scroll underneath it. The top
   rule is an inset shadow because the table collapses borders and a collapsed
   border on a sticky cell scrolls away with the rows above it. */
.report-viewer-modal .report-grid-table tfoot.report-grand-total > tr > td {
    position: sticky;
    bottom: 0;
    z-index: 3;
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    font-weight: 700;
    box-shadow: inset 0 2px 0 var(--bs-primary);
}

.report-viewer-modal .report-total-label {
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 0.78em;
    letter-spacing: 0.03em;
    white-space: nowrap;
}


/* Migrated Reports component styles */

/* ReportsModule */
.reports-module-container {
    height: 100%;
    overflow-y: auto;
    min-width: 0;
    padding: 1rem;
}

.reports-module-container .reports-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.5rem;
    margin-bottom: 0.75rem;
}

.reports-module-container .reports-active-badge {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    font-weight: 500;
}

@media (max-width: 768px) {
    .reports-module-container {
        padding: 0.75rem;
    }

    .reports-module-container .reports-header {
        flex-direction: column;
        align-items: stretch;
    }
}


/* Components/ReportsList */
/* ========================================
   Toolbar: search, category filter and "Add a Report" share one line.
   Nothing stretches: the leftover width becomes a gap before the right-aligned add control.
   ======================================== */
.reports-list .reports-list-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.reports-list .reports-search {
    flex: 0 1 22rem;
    min-width: 12rem;
    max-width: 33%;
    width: auto;
}

/* The field renders its own clear button, so suppress the browser's native one -- otherwise the two
   sit side by side and only one of them is ours. */
.reports-list .reports-search input[type="search"]::-webkit-search-cancel-button,
.reports-list .reports-search input[type="search"]::-webkit-search-decoration {
    -webkit-appearance: none;
    appearance: none;
    display: none;
}

.reports-list .reports-search input[type="search"]::-ms-clear {
    display: none;
    width: 0;
    height: 0;
}

.reports-list .reports-show-only {
    flex: 0 0 auto;
    width: auto;
    min-width: 11rem;
}

/* Pushes the add control to the right edge regardless of the filter's width. */
.reports-list .reports-add {
    flex: 0 0 auto;
    margin-left: auto;
}

.reports-list .reports-list-notice {
    margin-bottom: 0.75rem;
}

/* ========================================
   Report rows
   ======================================== */
.reports-list .reports-panel {
    border: 1px solid var(--border-color);
    background-color: var(--bg-primary);
    min-height: 100%;
}

.reports-list .reports-table-wrap {
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
}

.reports-list .reports-table {
    min-width: 960px;
}

/* Row states (hover, selection, accent bar, focus) live in
   wwwroot/css/reports.css — they must beat Bootstrap's opaque per-cell
   background, and scoped bundles are unreliable in production. */

.reports-list .reports-table td {
    white-space: nowrap;
}

.reports-list .reports-table .reports-description-cell {
    min-width: 20rem;
    white-space: normal;
}

.reports-list .reports-description-preview {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    line-height: 1.35;
    max-height: calc(1.35em * 2);
}

.reports-list .reports-report-cell {
    text-align: left !important;
}

/* Bootstrap's bare .badge sets a color but no background, which rendered the
   Type value as white-on-white. Give it an explicit themed chip treatment. */
.reports-list .reports-soft-badge {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    font-weight: 500;
}

.reports-list .reports-row-actions .btn {
    padding: 0 0.35rem;
    line-height: 1.2;
}

.reports-list .reports-selected-icon {
    color: var(--bs-primary);
}

/* ========================================
   Large-dataset prompt footer. Mirrors the Run Report modal's footer shape
   (scoped CSS can't be shared between components, so the rule is repeated).
   ======================================== */
.reports-list .report-prompt-footer {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
}

.reports-list .report-prompt-secondary {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: flex-end;
    width: 100%;
}

.reports-list .report-prompt-primary {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
    border-top: 1px solid var(--border-color);
    padding-top: 0.75rem;
}

@media (max-width: 768px) {
    .reports-list .reports-add {
        margin-left: 0;
    }
}


/* Components/ReportViewerDialog */
.report-viewer-modal .report-viewer-dialog {
    max-width: 95vw;
    width: 95vw;
    height: 92vh;
}

.report-viewer-modal .report-viewer-dialog .modal-content {
    height: 92vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.report-viewer-modal .report-viewer-header {
    background-color: var(--bg-dark);
    color: var(--text-light);
}

.report-viewer-modal .report-viewer-header .modal-title {
    color: var(--text-light);
}

.report-viewer-modal .report-viewer-subtitle {
    font-size: 0.8rem;
    color: var(--text-light);
    opacity: 0.85;
}

/* The global `.modal-header .btn-close` rule already paints the X white for dark
   headers — do NOT re-filter it here or it inverts back to black-on-black. */
.report-viewer-modal .report-viewer-close-btn {
    opacity: 0.85;
}

.report-viewer-modal .report-viewer-close-btn:hover {
    opacity: 1;
}

.report-viewer-modal .report-viewer-toolbar {
    background-color: var(--bg-secondary);
    border-color: var(--border-color) !important;
    flex: 0 0 auto;
}

/* The toolbar sits on --bg-secondary, so give the outline buttons their own surface
   to lift them off it. */
.report-viewer-modal .report-viewer-toolbar .btn-theme-outline-secondary {
    background-color: var(--bg-primary);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.report-viewer-modal .report-viewer-toolbar .btn-theme-outline-secondary:hover:not(:disabled) {
    background-color: rgba(var(--bs-primary-rgb), 0.1);
    border-color: var(--bs-primary);
    color: var(--bs-primary);
}

/* Toggle state (Wrap Text). */
.report-viewer-modal .report-viewer-toolbar .btn-theme-outline-secondary.active {
    background-color: rgba(var(--bs-primary-rgb), 0.16);
    border-color: var(--bs-primary);
    color: var(--bs-primary);
}

/* Wrap Text + zoom read as one control cluster. */
.report-viewer-modal .report-zoom-group {
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    background-color: var(--bg-secondary);
    padding: 0.25rem 0.5rem;
}

.report-viewer-modal .report-viewer-body {
    flex: 1 1 auto;
    overflow-x: hidden;
    overflow-y: auto;
    background-color: var(--bg-primary);
    display: flex;
    flex-direction: column;
}

.report-viewer-modal .report-viewer-columns-panel {
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    background-color: var(--bg-secondary);
}

.report-viewer-modal .report-viewer-columns-title {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-primary);
}

/* ========================================
   Edit Layout: options on the left, the column list on the right. One row per
   column — drag handle, checkbox, name, header override, then the action
   buttons. Without these the children stacked and the header input stretched
   the full panel width.
   ======================================== */
.report-viewer-modal .report-columns-editor {
    max-height: 22rem;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    background-color: var(--bg-primary);
    padding: 0.25rem 0.5rem;
}

.report-viewer-modal .report-column-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0.25rem;
    border-bottom: 1px solid var(--border-light, var(--border-color));
    border-left: 3px solid transparent;
    border-radius: 0.25rem;
    cursor: pointer;
}

.report-viewer-modal .report-column-row:hover {
    background-color: rgba(var(--bs-primary-rgb), 0.06);
}

/* Selection is tracked by column key, so the highlight follows the row while it
   is moved with the arrows or dragged. */
.report-viewer-modal .report-column-row.selected {
    background-color: rgba(var(--bs-primary-rgb), 0.14);
    border-left-color: var(--bs-primary);
}

.report-viewer-modal .report-column-row:last-child {
    border-bottom: 0;
}

/* Fixed-width label column keeps the header inputs vertically aligned. */
.report-viewer-modal .report-column-name {
    flex: 0 0 10rem;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.report-viewer-modal .report-column-header-input {
    flex: 1 1 auto;
    min-width: 6rem;
    /* Was stretching edge-to-edge; cap it so the action buttons stay reachable. */
    max-width: 18rem;
}

/* Bootstrap's .btn is inline-block with asymmetric padding, which left the icons
   hugging the left edge of their hit box. Square, centred flex boxes instead. */
.report-viewer-modal .report-column-row .btn {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    line-height: 1;
}

.report-viewer-modal .report-column-row .btn i {
    line-height: 1;
}

.report-viewer-modal .report-drag-handle {
    flex: 0 0 auto;
    cursor: grab;
    color: var(--text-secondary);
}

/* Expanded per-column styling controls, indented under their row. */
.report-viewer-modal .report-column-style-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.75rem;
    padding: 0.5rem 0 0.75rem 2rem;
    border-bottom: 1px solid var(--border-light, var(--border-color));
    background-color: var(--bg-secondary);
}

.report-viewer-modal .report-style-field {
    flex: 0 0 9rem;
}

.report-viewer-modal .report-style-field .form-label {
    font-size: 0.75rem;
    margin-bottom: 0.15rem;
    color: var(--text-secondary);
}

.report-viewer-modal .report-style-check {
    flex: 0 0 auto;
    padding-bottom: 0.4rem;
}

.report-viewer-modal .report-groupby-list {
    max-height: 9rem;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    background-color: var(--bg-primary);
    padding: 0.5rem;
}

.report-viewer-modal .report-layout-options .form-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* Inline panels (save / save-as / shared-change confirmation). */
.report-viewer-modal .report-viewer-panel {
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    background-color: var(--bg-secondary);
}

.report-viewer-modal .report-viewer-notice {
    margin-bottom: 0.75rem;
}

/* ========================================
   Grouped result rows
   ======================================== */
.report-viewer-modal .report-group-row td {
    background-color: var(--bg-tertiary);
    font-weight: 600;
}

.report-viewer-modal .report-group-toggle {
    background: none;
    border: 0;
    padding: 0 0.35rem 0 0;
    color: var(--text-primary);
    cursor: pointer;
}

.report-viewer-modal .report-group-label {
    color: var(--text-primary);
}

.report-viewer-modal .report-group-count {
    color: var(--text-secondary);
    font-weight: 500;
    margin-left: 0.35rem;
}

/* Subtotal and report-total row styling lives in wwwroot/css/reports.css, not here:
   totals are feature-critical and the scoped bundle is not regenerated reliably in
   production. */

.report-viewer-modal .report-index-cell {
    color: var(--text-secondary);
    text-align: right;
}

.report-viewer-modal .report-grid-wrapper {
    min-width: 0;
    /* Fill the viewport when alone, but don't shrink when the Edit Layout panel
       opens above it — that panel pushes the report down and the body (whole
       window) scrolls vertically to reveal it. */
    flex: 0 0 auto;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Constrain the grid to the visible viewport WIDTH so the scroll container keeps
   its vertical scrollbar at the visible right edge, while the inner table still
   overflows to drive the pinned horizontal scrollbar. */
.report-viewer-modal .report-grid-scroll {
    height: 100%;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow: auto;
}

/* User zoom: scale the table itself (not the scroll container) so overflow and
   both scrollbars recalculate; zooming out to fit removes horizontal scroll. */
.report-viewer-modal .report-grid-table {
    zoom: var(--report-zoom, 1);
}

/* Keep the column titles visible while reading down a long report. The header
   sticks to the top of .report-grid-scroll, which is the element that owns the
   vertical overflow. The bottom rule is drawn with an inset shadow rather than
   a border because the table collapses borders, and a collapsed border on a
   sticky cell scrolls away with the rows underneath it. */
.report-viewer-modal .report-grid-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    box-shadow: inset 0 -1px 0 var(--primary-light);
}

/* Vertical dividing lines between columns. The right edge of the last cell is
   left to the table/scroll border so we don't double up on the outer edge. */
.report-viewer-modal .report-grid-table th,
.report-viewer-modal .report-grid-table td {
    border-right: 1px solid var(--border-color);
}

.report-viewer-modal .report-grid-table th:last-child,
.report-viewer-modal .report-grid-table td:last-child {
    border-right: 0;
}

/* Compact mode: keep each cell on one line with an ellipsis so rows stay short.
   The title attribute on .report-cell-text reveals the full value on hover. */
.report-viewer-modal .report-grid-wrapper.report-nowrap .report-grid-table th,
.report-viewer-modal .report-grid-wrapper.report-nowrap .report-grid-table td {
    white-space: nowrap;
}

/* Busy spinner floats over the grid while a layout change or export is in flight.
   The 200ms delay is done in CSS rather than C# on purpose: rebuilding the grid
   blocks the circuit's render loop, so a timer-driven spinner (DelayedSpinner)
   could not paint while the work is running. The browser animates independently,
   so if the rebuild finishes first the element is removed before it ever becomes
   visible — same "no flash on fast operations" result. */
.report-viewer-modal .report-busy-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-primary);
    z-index: 5;
    opacity: 0;
    animation: report-busy-fade-in 150ms ease-in 200ms forwards;
}

@keyframes report-busy-fade-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 0.6;
    }
}

.report-viewer-modal .report-index-header {
    width: 3.5rem;
}

.report-viewer-modal .report-grid-wrapper.report-nowrap  .report-cell-text {
    display: inline-block;
    max-width: var(--report-cell-maxw, 22rem);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
}

.report-viewer-modal .report-zoom-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.report-viewer-modal .report-zoom-value {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
    min-width: 3.25rem;
    text-align: center;
}


/* Components/ReportEditorDialog */
/* Dialog chrome. Mirrors the viewer dialog's header treatment so the two report
   dialogs read as one family (scoped CSS can't be shared between components). */
.report-viewer-modal .report-viewer-header {
    background-color: var(--bg-dark);
    color: var(--text-light);
}

.report-viewer-modal .report-viewer-header .modal-title {
    color: var(--text-light);
}

/* The global `.modal-header .btn-close` rule already paints the X white for dark
   headers — do NOT re-filter it here or it inverts back to black-on-black. */
.report-viewer-modal .report-viewer-close-btn {
    opacity: 0.85;
}

.report-viewer-modal .report-viewer-close-btn:hover {
    opacity: 1;
}

.report-viewer-modal .report-editor-body {
    max-height: 70vh;
    overflow-y: auto;
    background-color: var(--bg-primary);
}

.report-viewer-modal .report-editor-section-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.report-viewer-modal .report-editor-subheading {
    font-size: 0.875rem;
    color: var(--text-primary);
}

/* Replaces MudPaper Outlined: a bordered well grouping repeated rows. */
.report-viewer-modal .report-editor-panel {
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    background-color: var(--bg-secondary);
    padding: 0.5rem;
}

.report-viewer-modal .report-editor-column-name {
    min-width: 150px;
    color: var(--text-primary);
}

.report-viewer-modal .report-editor-checklist {
    max-height: 12rem;
    overflow-y: auto;
}


/* Components/DynamicParameterForm */
.report-run-modal .report-run-dialog {
    max-width: 46rem;
}

.report-run-modal .report-run-body {
    max-height: 70vh;
    overflow-y: auto;
    background-color: var(--bg-primary);
}

.report-run-modal .report-run-checklist {
    border-color: var(--border-color) !important;
    background-color: var(--bg-secondary);
}

/* ========================================
   Footer: secondary actions on their own row, then Cancel (left) and
   Run (right) on a row of their own.
   ======================================== */
.report-run-modal .report-run-footer {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
}

.report-run-modal .report-run-secondary {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: flex-end;
    width: 100%;
}

/* Sits between the action row and the Cancel/Run row, so the sentence explaining what Run will do
   appears directly above the button it describes. */
.report-run-modal .report-run-selected {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    width: 100%;
    color: var(--text-muted);
}

.report-run-modal .report-run-primary {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
    border-top: 1px solid var(--border-color);
    padding-top: 0.75rem;
}


/* Components/ReportExportStatusBanner */
.reports-export-status.report-export-toasts {
    position: fixed;
    top: 5rem;
    right: 1.25rem;
    z-index: 1080;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: min(24rem, calc(100vw - 2.5rem));
    pointer-events: none;
}

.reports-export-status .report-export-toast {
    position: relative;
    display: flex;
    gap: 0.75rem;
    padding: 0.875rem 2.25rem 0.875rem 1rem;
    border-radius: 0.5rem;
    border-left: 4px solid var(--bs-secondary);
    background-color: var(--bg-primary);
    color: var(--bs-body-color);
    box-shadow: 0 0.5rem 1.5rem var(--shadow);
    pointer-events: auto;
    animation: report-export-toast-in 0.18s ease-out;
}

@keyframes report-export-toast-in {
    from {
        opacity: 0;
        transform: translateY(-0.5rem);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.reports-export-status .report-export-toast-busy {
    border-left-color: var(--bs-info);
}

.reports-export-status .report-export-toast-success {
    border-left-color: var(--bs-success);
}

.reports-export-status .report-export-toast-error {
    border-left-color: var(--bs-danger);
}

.reports-export-status .report-export-toast-icon {
    flex: 0 0 auto;
    font-size: 1.35rem;
    line-height: 1.2;
}

.reports-export-status .report-export-toast-success .report-export-toast-icon {
    color: var(--bs-success);
}

.reports-export-status .report-export-toast-error .report-export-toast-icon {
    color: var(--bs-danger);
}

.reports-export-status .report-export-toast-busy .report-export-toast-icon {
    color: var(--bs-info);
}

.reports-export-status .report-export-toast-body {
    flex: 1 1 auto;
    min-width: 0;
}

.reports-export-status .report-export-toast-title {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.reports-export-status .report-export-toast-text {
    font-size: 0.875rem;
    opacity: 0.85;
}

.reports-export-status .report-export-toast-close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    padding: 0.35rem;
}

