/* The grid must be the thing that scrolls. Left to size itself, .task-grid-scroll's
   max-height:100% resolves against an auto-height parent and is dropped, so the table
   grows past the page and the nearest scroll container becomes the page shell — which
   makes the sticky header stick to the top of the *page*, over the toolbar above it,
   and leaves no way back out of grid mode. Both hosts (.grid-page, .tasks-grid-body)
   are bounded flex columns, so claiming the remaining height here bounds the scroller. */
.task-grid {
    outline: none;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.task-grid-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    max-height: 100%;
    border: 1px solid var(--mud-palette-lines-default);
}

.task-grid-table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    table-layout: fixed;
}

.task-grid-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--mud-palette-surface);
    color: var(--mud-palette-text-secondary);
    text-align: left;
    padding: 6px 8px;
    border-bottom: 1px solid var(--mud-palette-lines-default);
    border-right: 1px solid var(--mud-palette-lines-default);
}

.task-grid-table th.grid-col-frozen,
.task-grid-table td.grid-col-frozen {
    position: sticky;
    z-index: 1;
    background: var(--mud-palette-surface);
}

.task-grid-table thead th.grid-col-frozen {
    z-index: 3;
}

.grid-row td {
    padding: 0;
    border-bottom: 1px solid var(--mud-palette-lines-default);
    border-right: 1px solid var(--mud-palette-lines-default);
    overflow: hidden;
}

.grid-row.zebra td {
    background: var(--mud-palette-table-striped);
}

.grid-row-separator td,
.grid-row-blank td {
    background: var(--mud-palette-background-grey);
    color: var(--mud-palette-text-secondary);
    font-weight: 500;
    padding: 4px 8px;
}

.grid-row-placeholder td {
    color: var(--mud-palette-text-disabled);
    font-style: italic;
    padding: 4px 8px;
}

.grid-cell-text {
    display: block;
    padding: 4px 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.grid-cell-active {
    outline: 2px solid var(--mud-palette-primary);
    outline-offset: -2px;
}

.grid-cell-range {
    background: var(--mud-palette-primary-hover);
}

.grid-cell-editor {
    width: 100%;
}

/* Editing in place must not move the text. MudBlazor's input carries its own type scale
   (mud-typography-subtitle1), dense vertical margins, a min-height and an underline — all
   of which shift the value away from where .grid-cell-text painted it. Pin the editor to
   the static cell's metrics: same padding, same inherited font, no underline. */
.grid-cell-editor.mud-input-control,
.grid-cell-editor .mud-input-control-input-container,
.grid-cell-editor .mud-input {
    margin: 0;
    min-height: 0;
}

.grid-cell-editor .mud-input,
.grid-cell-editor input.mud-input-slot {
    font: inherit;
    letter-spacing: inherit;
    line-height: inherit;
}

.grid-cell-editor .mud-input.mud-input-underline::before,
.grid-cell-editor .mud-input.mud-input-underline::after {
    display: none;
}

.grid-cell-editor input.mud-input-slot {
    padding: 4px 8px;
    height: auto;
    min-height: 0;
}

.grid-cell-error {
    display: block;
    padding: 2px 8px;
    color: var(--mud-palette-error);
    font-size: 0.75rem;
}

.grid-cell {
    position: relative;
}

.grid-fill-handle {
    position: absolute;
    right: -3px;
    bottom: -3px;
    width: 6px;
    height: 6px;
    background: var(--mud-palette-primary);
    cursor: crosshair;
    z-index: 1;
}

.grid-col-gutter {
    width: 24px;
}

.grid-gutter {
    padding: 0;
    text-align: center;
}

.grid-drag-handle {
    display: inline-block;
    width: 12px;
    height: 12px;
    cursor: grab;
    opacity: 0.5;
}

.grid-drag-handle::before {
    content: "\22EE\22EE";
    letter-spacing: -3px;
}

.grid-row-context-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 9;
    background: transparent;
}

.grid-row-context-menu {
    position: fixed;
    z-index: 10;
    min-width: 180px;
}

.grid-row-context-menu-list {
    list-style: none;
    margin: 0;
    padding: 4px 0;
}

.grid-row-context-menu-list li {
    padding: 6px 16px;
    cursor: pointer;
}

.grid-row-context-menu-list li:hover,
.grid-row-context-menu-list li:focus {
    background: var(--mud-palette-action-default-hover);
    outline: none;
}
