/* Lightweight list grid — demand-plans-inspired, tuned for ReflectionListView pilot */

.lw-datagrid {
    width: 100%;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: #fff;
    border: 1px solid #eef2f6;
    border-radius: 8px;
    overflow: hidden;
}

.lw-datagrid-scroll {
    position: relative;
    width: 100%;
    overflow: auto;
    max-height: min(70vh, 900px);
}

.lw-datagrid-body-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    min-height: min(40vh, 320px);
    padding: 24px;
    color: #64748b;
    font-size: 13px;
    font-weight: 500;
}

.lw-datagrid-body-loading-text {
    color: #64748b;
}

/* Dimmed cover while expand/collapse (or group-tree load) rebuilds visible rows. */
.lw-datagrid-busy-overlay {
    position: absolute;
    inset: 0;
    z-index: 6;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(248, 250, 252, 0.72);
    pointer-events: all;
}

.lw-datagrid-busy-overlay .lw-group-busy-spin {
    width: 28px;
    height: 28px;
    border-width: 3px;
}

.lw-datagrid-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    table-layout: fixed;
}

.lw-datagrid-table thead th.lw-datagrid-th {
    background: #f8fafc;
    color: #475569;
    font-weight: 600;
    text-align: start;
    padding: 10px 12px;
    border-bottom: 1px solid #e2e8f0;
    white-space: nowrap;
    font-size: 12px;
    letter-spacing: 0.02em;
    position: sticky;
    top: 0;
    z-index: 2;
    cursor: default;
    user-select: none;
}

.lw-datagrid-table thead th.lw-datagrid-th:has(.lw-datagrid-sort) {
    cursor: pointer;
}

.lw-datagrid-th-inner {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.lw-datagrid-title {
    overflow: hidden;
    text-overflow: ellipsis;
}

.lw-datagrid-sort {
    color: #94a3b8;
    font-size: 11px;
    flex-shrink: 0;
}

.lw-datagrid-filter-row th {
    background: #fff;
    padding: 6px 8px;
    border-bottom: 1px solid #e2e8f0;
    top: 40px;
}

.lw-datagrid-filter-input {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 12px;
    background: #fbfcfe;
}

.lw-datagrid-filter-input:focus {
    outline: none;
    border-color: #94a3b8;
    background: #fff;
}

.lw-datagrid-td {
    padding: 10px 12px;
    border-bottom: 1px solid #f1f5f9;
    color: #1f2937;
    vertical-align: middle;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lw-datagrid-row:nth-child(even) {
    background: #fbfcfe;
}

.lw-datagrid-row:hover {
    background: #f1f5f9;
}

.lw-datagrid-empty {
    text-align: center;
    color: #94a3b8;
    padding: 24px 12px !important;
}

.lw-frozen-left {
    position: sticky;
    left: 0;
    z-index: 1;
}

.lw-frozen-right {
    position: sticky;
    right: 0;
    z-index: 1;
}

/* Frozen cells must be opaque. `background: inherit` resolves to transparent on odd rows (only even rows
   declare a background), so rows scrolling underneath showed through the pinned actions column. Parity and
   hover are repeated here because the colour lives on the row while the sticky context is the cell. */
tbody .lw-datagrid-row > .lw-frozen-left,
tbody .lw-datagrid-row > .lw-frozen-right {
    background: #fff;
}

tbody .lw-datagrid-row:nth-child(even) > .lw-frozen-left,
tbody .lw-datagrid-row:nth-child(even) > .lw-frozen-right {
    background: #fbfcfe;
}

tbody .lw-datagrid-row:hover > .lw-frozen-left,
tbody .lw-datagrid-row:hover > .lw-frozen-right {
    background: #f1f5f9;
}

/* Selected rows are highlighted from the tick box's own class rather than a class on the row, because the row is
   painted by the grid and the tick box paints itself — that is what lets a selection change skip a grid render.
   Listed after the parity/hover rules so a selected row stays highlighted while the pointer is elsewhere. */
tbody .lw-datagrid-row:has(.lw-sel.is-on) > .lw-datagrid-td,
tbody .lw-datagrid-row:has(.lw-sel.is-on) > .lw-frozen-left,
tbody .lw-datagrid-row:has(.lw-sel.is-on) > .lw-frozen-right {
    background: #eff6ff;
}

tbody .lw-datagrid-row:has(.lw-sel.is-on):hover > .lw-datagrid-td,
tbody .lw-datagrid-row:has(.lw-sel.is-on):hover > .lw-frozen-left,
tbody .lw-datagrid-row:has(.lw-sel.is-on):hover > .lw-frozen-right {
    background: #e0edff;
}

.lw-sel {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.lw-sel-box {
    cursor: pointer;
}

/* Edge shadow so the pinned column reads as floating above the scrolled content. */
.lw-frozen-right {
    box-shadow: -6px 0 8px -6px rgba(15, 23, 42, 0.18);
}

.lw-frozen-left {
    box-shadow: 6px 0 8px -6px rgba(15, 23, 42, 0.18);
}

thead .lw-frozen-left,
thead .lw-frozen-right {
    z-index: 3;
    background: #f8fafc;
}

.lw-datagrid-filter-row .lw-frozen-left,
.lw-datagrid-filter-row .lw-frozen-right {
    background: #fff;
}

/* ---- Column header filter button ---- */

.lw-datagrid-filter-btn {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: #94a3b8;
    cursor: pointer;
    font-size: 10px;
    line-height: 1;
}

.lw-datagrid-filter-btn:hover {
    background: #e2e8f0;
    color: #334155;
}

.lw-datagrid-filter-btn.is-active {
    background: #dbeafe;
    color: #1d4ed8;
}

/* ---- Column filter panel ---- */

.lw-filter-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1200;
    background: transparent;
}

.lw-filter-panel {
    position: fixed;
    z-index: 1201;
    /* Script sets left/top from the header button; stay hidden until then to avoid a visible jump. */
    visibility: hidden;
    top: 0;
    left: 0;
    width: 280px;
    max-height: 420px;
    display: flex;
    flex-direction: column;
    /* Clip children so a long value list cannot grow past max-height and cover the grid. */
    overflow: hidden;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.18);
    font-size: 13px;
    color: #1f2937;
}

.lw-filter-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid #eef2f6;
}

.lw-filter-title {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lw-filter-x {
    margin-inline-start: auto;
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: #64748b;
    cursor: pointer;
}

.lw-filter-x:hover {
    background: #f1f5f9;
    color: #0f172a;
}

.lw-filter-search {
    width: calc(100% - 24px);
    box-sizing: border-box;
    margin: 10px 12px 6px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 6px 8px;
    font-size: 12px;
}

.lw-filter-search:focus {
    outline: none;
    border-color: #2563eb;
}

.lw-filter-contains {
    display: flex;
    align-items: center;
    gap: 8px;
    width: calc(100% - 24px);
    margin: 0 12px 6px;
    padding: 6px 8px;
    border: 1px dashed #cbd5e1;
    border-radius: 6px;
    background: #f8fafc;
    cursor: pointer;
    text-align: start;
    font-size: 12px;
    color: #334155;
}

.lw-filter-contains-on {
    border-style: solid;
    border-color: #2563eb;
    background: #eff6ff;
    color: #1d4ed8;
}

.lw-filter-toolbar {
    display: flex;
    gap: 12px;
    padding: 0 12px 6px;
}

.lw-filter-link {
    border: none;
    background: transparent;
    padding: 0;
    color: #2563eb;
    cursor: pointer;
    font-size: 12px;
}

.lw-filter-link:hover {
    text-decoration: underline;
}

.lw-filter-list {
    /* min-height:0 lets the flex item shrink so only this region scrolls; Apply/Clear stay pinned. */
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    padding: 0 6px 6px;
}

.lw-filter-body {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

.lw-filter-list-virtual {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    max-height: none;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
}

.lw-filter-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 6px;
    border-radius: 4px;
    cursor: pointer;
}

.lw-filter-item:hover {
    background: #f1f5f9;
}

.lw-filter-item-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lw-filter-status {
    padding: 10px 8px;
    color: #94a3b8;
    font-size: 12px;
}

.lw-filter-status-warn {
    color: #b45309;
}

.lw-filter-tristate {
    display: flex;
    gap: 6px;
    padding: 12px;
}

.lw-filter-tri {
    flex: 1;
    padding: 7px 0;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #fff;
    color: #475569;
    cursor: pointer;
    font-size: 12px;
}

.lw-filter-tri-on {
    border-color: #2563eb;
    background: #2563eb;
    color: #fff;
    font-weight: 600;
}

.lw-filter-date {
    padding: 10px 12px 4px;
}

/* Numeric range, above the list of exact values in the same panel. */
.lw-filter-range {
    padding: 10px 12px 2px;
    border-bottom: 1px solid #eef2f6;
}

.lw-filter-range-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.lw-filter-range-row > span {
    width: 56px;
    color: #64748b;
    font-size: 12px;
}

.lw-filter-num {
    flex: 1;
    min-width: 0;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 5px 8px;
    background: #fff;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.lw-filter-num:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

.lw-filter-date-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.lw-filter-date-row > span {
    width: 56px;
    color: #64748b;
    font-size: 12px;
}

.lw-filter-select {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 5px 8px;
    background: #fff;
    font-size: 12px;
}

.lw-filter-hint {
    margin: 0 0 6px;
    color: #94a3b8;
    font-size: 11px;
    line-height: 1.4;
}

.lw-filter-head,
.lw-filter-toolbar,
.lw-filter-range,
.lw-filter-date,
.lw-filter-tristate,
.lw-filter-search,
.lw-filter-foot {
    flex-shrink: 0;
}

.lw-filter-foot {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #eef2f6;
    background: #fff;
}

.lw-filter-btn {
    padding: 6px 14px;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #334155;
    cursor: pointer;
    font-size: 12px;
}

.lw-filter-btn-quiet:hover {
    background: #f1f5f9;
}

.lw-filter-btn-primary {
    border-color: #2563eb;
    background: #2563eb;
    color: #fff;
    font-weight: 600;
}

.lw-filter-btn-primary:hover {
    background: #1d4ed8;
}

/* ---- Grouping ---- */

.lw-datagrid-group-btn {
    position: relative;
    border: 0;
    background: transparent;
    color: #94a3b8;
    padding: 2px 4px;
    cursor: pointer;
    border-radius: 4px;
    line-height: 1;
}

.lw-datagrid-group-btn:hover {
    background: #eef2f6;
    color: #475569;
}

.lw-datagrid-group-btn.is-active {
    color: #2563eb;
    background: #e6efff;
}

/* Which level a column sits at, for the reader who grouped by three things and needs to know the order. */
.lw-group-order {
    position: absolute;
    top: -2px;
    inset-inline-end: -2px;
    min-width: 12px;
    height: 12px;
    padding: 0 2px;
    border-radius: 6px;
    background: #2563eb;
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    line-height: 12px;
    text-align: center;
}

/* Whole-tree controls in the first heading, beside the select-all box. */
.lw-group-tools {
    display: inline-flex;
    align-items: center;
    gap: 1px;
    margin-inline-start: 2px;
}

.lw-group-tool {
    border: 0;
    background: transparent;
    color: #64748b;
    padding: 2px 3px;
    cursor: pointer;
    border-radius: 4px;
    line-height: 1;
    font-size: 11px;
}

.lw-group-tool:hover {
    background: #eef2f6;
    color: #1f2937;
}

.lw-group-tool-clear:hover {
    background: #fee2e2;
    color: #b91c1c;
}

.lw-group-row {
    cursor: pointer;
    background: #f8fafc;
}

.lw-group-row:hover {
    background: #f1f5f9;
}

/* The outermost grouping is the one that has to read as a break in the list, so it alone gets the rule above it. */
.lw-group-row.lw-group-master {
    background: #eef2ff;
    border-top: 2px solid #c7d2fe;
}

.lw-group-row.lw-group-l1 { background: #f5f7ff; }
.lw-group-row.lw-group-l2 { background: #f8fafc; }

.lw-group-cell {
    padding: 7px 12px;
    border-bottom: 1px solid #e5e9f0;
    white-space: nowrap;
}

.lw-group-indent {
    display: inline-block;
    width: var(--lw-group-indent, 0);
}

.lw-group-chevron {
    color: #64748b;
    font-size: 10px;
    width: 12px;
    margin-inline-end: 6px;
}

.lw-group-col {
    color: #64748b;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-inline-end: 6px;
}

/* The value is what the reader scans down the tree for. */
.lw-group-value {
    font-weight: 700;
    color: #0f172a;
}

.lw-group-count {
    margin-inline-start: 8px;
    padding: 1px 7px;
    border-radius: 10px;
    background: #e2e8f0;
    color: #475569;
    font-size: 11px;
    font-weight: 600;
}

.lw-group-agg {
    margin-inline-start: 14px;
    font-size: 11px;
}

.lw-group-child > td:first-child {
    padding-inline-start: calc(12px + var(--lw-group-indent, 0));
}

.lw-group-notice {
    color: #64748b;
}

/* In-group member pager — distinct from the footer so the two never look like a double footer. */
.lw-group-member-pager-cell {
    padding: 6px 12px;
    border-bottom: 1px solid #e5e9f0;
    background: #f1f5f9;
    white-space: nowrap;
}

.lw-group-member-pager-label {
    display: inline-block;
    margin-inline-end: 10px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: #64748b;
}

.lw-group-member-pager-btn {
    width: 28px;
    height: 28px;
}

.lw-datagrid-pager-grouped .lw-datagrid-pager-size-label {
    margin-inline-start: auto;
}

/* ---- Footer aggregates bar ---- */

.lw-datagrid-aggregates {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 18px;
    padding: 8px 12px;
    border-top: 1px solid #eef2f6;
    background: #f8fafc;
    font-size: 12px;
}

.lw-agg {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
}

.lw-agg-label {
    color: #64748b;
}

.lw-agg-op {
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: 0.04em;
    color: #94a3b8;
}

.lw-agg-value {
    font-weight: 600;
    color: #0f172a;
    font-variant-numeric: tabular-nums;
}

/* Stands in for one figure's value while its own query runs; sized to the digits it replaces so the bar does not jump. */
.lw-agg-spin {
    display: inline-block;
    width: 11px;
    height: 11px;
    border: 2px solid #cbd5e1;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: lw-agg-spin 0.7s linear infinite;
    vertical-align: -1px;
}

/* Grouped-view busy state sits on a pale row; force a black spinner so it stays visible. */
.lw-group-busy-spin,
.lw-datagrid-empty .lw-agg-spin {
    width: 18px;
    height: 18px;
    border-width: 2px;
    border-color: rgba(15, 23, 42, 0.25) !important;
    border-top-color: #000 !important;
}

.lw-date-group-options {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px 10px 4px;
}

.lw-date-group-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    color: #1f2937;
}

.lw-date-group-option.is-active {
    background: #eef2ff;
}

.lw-date-group-option input {
    margin: 0;
}

.lw-date-group-parts {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    padding: 2px 8px 0 28px;
}

.lw-date-group-part {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #334155;
    cursor: pointer;
}

.lw-date-group-part input {
    margin: 0;
}

@keyframes lw-agg-spin {
    to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
    .lw-agg-spin {
        animation-duration: 2s;
    }
}

.lw-datagrid-pager {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-top: 1px solid #eef2f6;
    background: #fafbfc;
    flex-wrap: wrap;
}

.lw-datagrid-pager-btn {
    width: 32px;
    height: 32px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #fff;
    color: #475569;
    cursor: pointer;
}

.lw-datagrid-pager-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.lw-datagrid-pager-summary {
    font-size: 13px;
    color: #334155;
    font-variant-numeric: tabular-nums;
}

.lw-datagrid-pager-size-label {
    margin-inline-start: auto;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #64748b;
}

.lw-datagrid-pager-size {
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 4px 8px;
    background: #fff;
}
