/*
    Entity grid toolbar, search, column header, empty state and footer, in the same family as the dialog header/footer
    (egk-dialog-header.css). The column header, row hover, search marks and pager also apply to every
    hand-built MudTable/MudDataGrid, so all list screens read alike. Global on purpose: MudFab, MudChip and MudTablePager render these
    elements, so EntityTable's scoped CSS cannot reach them. Colors come from the MudBlazor palette.
*/

/*
    Toolbar band: spans the grid, tinted like the dialog headers, actions at the start and search at
    the end. The doubled class outranks EntityTable's scoped .eg-toolbar box (border, shadow, padding),
    which otherwise floats as a short card inside the table toolbar.
*/
.eg-table-shell .mud-table-toolbar {
    height: auto;
    min-height: 60px;
    padding-block: 8px;
    border-bottom: 1px solid color-mix(in srgb, var(--mud-palette-primary) 14%, var(--mud-palette-lines-default));
    background: linear-gradient(180deg,
        color-mix(in srgb, var(--mud-palette-primary) 5%, var(--mud-palette-surface)) 0%,
        var(--mud-palette-surface) 100%);
}

.eg-table-shell .eg-toolbar.eg-toolbar {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    flex-wrap: wrap;
    gap: 12px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
}

.eg-table-shell .eg-toolbar > .eg-spacer {
    flex: 1 1 auto;
}

.eg-table-shell .eg-toolbar > .eg-search {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-inline-start: auto;
    min-width: 0;
}

.eg-table-shell .eg-toolbar .eg-search .eg-search-field {
    margin: 0 !important;
    flex: 0 1 320px;
}

.eg-table-shell .eg-toolbar .eg-search .eg-search-field .mud-input.mud-input-outlined {
    height: 38px;
    width: 100%;
}

.eg-table-shell .eg-toolbar .eg-search .eg-search-field .mud-input-helper-text,
.eg-table-shell .eg-toolbar .eg-search .eg-search-field .mud-input-control-helper-container {
    display: none;
}

.eg-table-shell .eg-toolbar .eg-search .eg-chips {
    margin: 0;
}

/* Toolbar actions: soft round buttons; Create is the one filled, gradient action. */
.eg-toolbar .eg-actions .mud-fab:not(.mud-fab-menu-container *) {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid color-mix(in srgb, var(--mud-palette-primary) 18%, var(--mud-palette-lines-default));
    background-color: color-mix(in srgb, var(--mud-palette-primary) 5%, var(--mud-palette-surface));
    box-shadow: 0 1px 3px color-mix(in srgb, var(--mud-palette-text-primary) 10%, transparent);
    transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.eg-toolbar .eg-actions .mud-fab:not(.mud-fab-menu-container *) .mud-icon-root {
    width: 20px;
    height: 20px;
}

.eg-toolbar .eg-actions .mud-fab:not(.mud-fab-menu-container *):hover:not(:disabled) {
    transform: translateY(-1px);
    border-color: color-mix(in srgb, var(--mud-palette-primary) 40%, transparent);
    background-color: color-mix(in srgb, var(--mud-palette-primary) 12%, var(--mud-palette-surface));
    box-shadow: 0 5px 14px color-mix(in srgb, var(--mud-palette-primary) 22%, transparent);
}

.eg-toolbar .eg-actions .mud-fab:not(.mud-fab-menu-container *):focus-visible {
    outline: 2px solid var(--mud-palette-primary);
    outline-offset: 2px;
}

.eg-toolbar .eg-actions .mud-fab.eg-fab-create:not(:disabled) {
    border-color: transparent;
    background-color: var(--mud-palette-primary);
    background-image: linear-gradient(135deg,
        var(--mud-palette-primary) 0%,
        color-mix(in srgb, var(--mud-palette-primary) 55%, var(--mud-palette-info)) 100%);
    box-shadow: 0 4px 12px color-mix(in srgb, var(--mud-palette-primary) 35%, transparent);
}

.eg-toolbar .eg-actions .mud-fab.eg-fab-create:not(:disabled) .mud-icon-root {
    color: var(--mud-palette-primary-text) !important;
}

.eg-toolbar .eg-actions .mud-fab.eg-fab-create:hover:not(:disabled) {
    filter: brightness(1.06);
    background-color: var(--mud-palette-primary);
    box-shadow: 0 7px 18px color-mix(in srgb, var(--mud-palette-primary) 38%, transparent);
}

.eg-toolbar .eg-actions .mud-fab.eg-fab-create:hover:not(:disabled) .mud-icon-root {
    transform: rotate(90deg);
}

.eg-toolbar .eg-actions .mud-fab .mud-icon-root {
    transition: transform 0.3s ease;
}

.eg-toolbar .eg-actions .mud-fab.eg-fab-danger:hover:not(:disabled) {
    border-color: color-mix(in srgb, var(--mud-palette-error) 45%, transparent);
    background-color: color-mix(in srgb, var(--mud-palette-error) 12%, var(--mud-palette-surface));
    box-shadow: 0 5px 14px color-mix(in srgb, var(--mud-palette-error) 22%, transparent);
}

.eg-toolbar .eg-actions .mud-fab:not(.mud-fab-menu-container *):disabled {
    border: 1px dashed var(--mud-palette-lines-inputs);
    background-color: transparent;
    background-image: none;
    box-shadow: none;
}

.eg-toolbar .eg-actions .mud-fab:not(.mud-fab-menu-container *):disabled .mud-icon-root {
    color: var(--mud-palette-text-disabled) !important;
}

/* "More actions" (⋮) repeats Import, Refresh, Deleted, Columns and Close, which are hidden on small
   screens only; on wider screens it would be a duplicate. EntityTable's scoped rule for this cannot
   reach the MudMenu root, so the switch lives here. */
.eg-toolbar .eg-actions .eg-more-actions {
    display: none;
}

@media (max-width: 600px) {
    .eg-toolbar .eg-actions .eg-more-actions {
        display: inline-flex;
    }

    .eg-table-shell .eg-toolbar > .eg-search,
    .eg-table-shell .eg-toolbar .eg-search .eg-search-field {
        flex: 1 1 100%;
    }

    .eg-search .eg-search-field .mud-input.mud-input-outlined {
        min-width: 0;
    }
}

/* Search: a tinted pill with the magnifier first; it glows on focus and keeps a primary edge while filtering. */
.eg-search .eg-search-field .mud-input.mud-input-outlined {
    min-width: 260px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--mud-palette-primary) 4%, var(--mud-palette-surface));
    transition: background-color 0.15s ease, box-shadow 0.15s ease;
}

.eg-search .eg-search-field .mud-input.mud-input-outlined .mud-input-outlined-border {
    border-radius: 999px;
    border-color: color-mix(in srgb, var(--mud-palette-primary) 22%, var(--mud-palette-lines-default));
    transition: border-color 0.15s ease;
}

.eg-search .eg-search-field .mud-input.mud-input-outlined:hover .mud-input-outlined-border {
    border-color: color-mix(in srgb, var(--mud-palette-primary) 45%, transparent);
}

.eg-search .eg-search-field .mud-input.mud-input-outlined:focus-within {
    background: var(--mud-palette-surface);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--mud-palette-primary) 14%, transparent);
}

.eg-search .eg-search-field .mud-input.mud-input-outlined:focus-within .mud-input-outlined-border,
.eg-search .eg-search-field.has-value .mud-input.mud-input-outlined .mud-input-outlined-border {
    border-color: var(--mud-palette-primary);
}

.eg-search .eg-search-field .mud-input-adornment-start .mud-icon-root {
    color: var(--mud-palette-primary);
    transition: transform 0.2s ease;
}

.eg-search .eg-search-field .mud-input.mud-input-outlined:focus-within .mud-input-adornment-start .mud-icon-root {
    transform: scale(1.12);
}

.eg-search .eg-search-field input::placeholder {
    color: var(--mud-palette-text-secondary);
    opacity: 0.8;
    font-style: normal;
}

.eg-search .eg-search-field .mud-input-clear-button {
    padding: 2px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--mud-palette-text-primary) 8%, transparent);
}

.eg-search .eg-search-field .mud-input-clear-button:hover {
    background: color-mix(in srgb, var(--mud-palette-error) 14%, transparent);
    color: var(--mud-palette-error);
}

/* Active filter, sort, group and selection chips under the search. */
.eg-search .eg-chips .mud-chip {
    height: 26px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 650;
    background: color-mix(in srgb, currentColor 8%, var(--mud-palette-surface));
}

/*
    Column header of every MudTable/MudDataGrid in the app (EntityTable and hand-built tables alike):
    tinted band, firmer labels. Kept at low specificity so a page that styles its own header wins.
    The tint is resolved on the table root and handed to the head as its surface color, because
    MudBlazor's sticky-header rule paints header cells with --mud-palette-surface at high specificity.
*/
:where(.mud-table-root) {
    --egk-table-head-bg: color-mix(in srgb, var(--mud-palette-primary) 5%, var(--mud-palette-surface));
}

:where(.mud-table-root) .mud-table-head {
    --mud-palette-surface: var(--egk-table-head-bg);
}

:where(.mud-table-root) .mud-table-head .mud-table-cell {
    font-weight: 700;
    letter-spacing: 0.01em;
    color: color-mix(in srgb, var(--mud-palette-text-primary) 80%, var(--mud-palette-primary));
    background-color: var(--egk-table-head-bg);
    border-bottom: 1px solid color-mix(in srgb, var(--mud-palette-primary) 18%, var(--mud-palette-lines-default));
}

/* Quiet column filter buttons (EntityTable) that light up when the column is filtered. */

.eg-table-shell .eg-col-menu .mud-icon-button {
    width: 26px;
    height: 26px;
    padding: 3px;
    margin-inline-start: 4px;
    border-radius: 50%;
    color: var(--mud-palette-text-secondary);
    opacity: 0.6;
    transition: opacity 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.eg-table-shell .eg-col-menu .mud-icon-button .mud-icon-root {
    width: 18px;
    height: 18px;
}

.eg-table-shell .mud-table-head .mud-table-cell:hover .eg-col-menu .mud-icon-button,
.eg-table-shell .eg-col-menu .mud-icon-button:focus-visible {
    opacity: 1;
}

.eg-table-shell .eg-col-menu .mud-icon-button:hover {
    opacity: 1;
    color: var(--mud-palette-primary);
    background: color-mix(in srgb, var(--mud-palette-primary) 12%, transparent);
}

.eg-table-shell .eg-col-menu.is-filtered .mud-icon-button {
    opacity: 1;
    color: var(--mud-palette-primary-text);
    background: var(--mud-palette-primary);
    box-shadow: 0 2px 6px color-mix(in srgb, var(--mud-palette-primary) 35%, transparent);
}

/* Rows of hoverable tables: a soft primary wash; the EntityTable row's "⋮" wakes up with it. */
.eg-table-shell .mud-table-body .mud-table-row:hover > .mud-table-cell,
.mud-table-hover :where(.mud-table-root) .mud-table-body .mud-table-row:hover > .mud-table-cell {
    background-color: color-mix(in srgb, var(--mud-palette-primary) 4%, transparent);
}

.eg-table-shell .eg-quick-actions {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.eg-table-shell .eg-row-actions-trigger.mud-button-root,
.eg-table-shell .eg-row-restore.mud-button-root,
.eg-table-shell .eg-row-no-actions.mud-button-root {
    width: 30px;
    height: 30px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid transparent;
}

.eg-table-shell .mud-table-row:hover .eg-row-actions-trigger.mud-button-root,
.eg-table-shell .eg-row-actions-trigger.mud-button-root:focus-visible {
    border-color: color-mix(in srgb, var(--mud-palette-primary) 26%, transparent);
    background-color: color-mix(in srgb, var(--mud-palette-primary) 8%, var(--mud-palette-surface));
    color: var(--mud-palette-primary);
}

.eg-table-shell .eg-row-restore.mud-button-root {
    border-color: color-mix(in srgb, var(--mud-palette-tertiary) 35%, transparent);
    background-color: color-mix(in srgb, var(--mud-palette-tertiary) 10%, var(--mud-palette-surface));
}

.eg-table-shell .eg-row-restore.mud-button-root:hover:not(:disabled) .mud-icon-root {
    transform: rotate(-200deg);
}

.eg-table-shell .eg-row-restore .mud-icon-root {
    transition: transform 0.45s ease;
}

.eg-table-shell .eg-row-no-actions.mud-button-root {
    border: 1px dashed var(--mud-palette-lines-inputs);
}

/* Row menu: each item's icon sits in a tinted disc; Delete warms to the error color. */
.mud-popover.eg-row-actions-popover .mud-list-item .mud-list-item-icon .mud-icon-root {
    box-sizing: content-box;
    width: 18px;
    height: 18px;
    padding: 5px;
    border-radius: 50%;
    background: color-mix(in srgb, currentColor 12%, transparent);
}

.mud-popover.eg-row-actions-popover .mud-list-item:has(.mud-error-text):hover {
    background-color: color-mix(in srgb, var(--mud-palette-error) 10%, transparent);
    color: var(--mud-palette-error);
}

.mud-popover.eg-row-actions-popover .mud-list-item:has(.mud-primary-text):hover {
    background-color: color-mix(in srgb, var(--mud-palette-primary) 10%, transparent);
    color: var(--mud-palette-primary);
}

/* Search matches inside cells of any table. */
:where(.mud-table-root) .mud-table-body mark {
    padding: 0 3px;
    border-radius: 4px;
    color: inherit;
    background: color-mix(in srgb, var(--mud-palette-warning) 30%, transparent);
    box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--mud-palette-warning) 70%, transparent);
}

/* Inline editing: round confirm/cancel buttons in the form's colors. */
.eg-table-shell .eg-inline-commit.mud-button-root,
.eg-table-shell .eg-inline-cancel.mud-button-root {
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid color-mix(in srgb, currentColor 35%, transparent);
    background-color: color-mix(in srgb, currentColor 10%, var(--mud-palette-surface));
}

.eg-table-shell .eg-inline-commit.mud-button-root:hover,
.eg-table-shell .eg-inline-cancel.mud-button-root:hover {
    background-color: color-mix(in srgb, currentColor 20%, var(--mud-palette-surface));
}

/* Grouped view: each group is a tinted band with a count pill and a quiet Clear pill. */
.eg-grouped-container .eg-group-header.mud-paper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-block: 6px 2px;
    padding: 6px 12px;
    border-radius: 10px;
    border: 1px solid color-mix(in srgb, var(--mud-palette-primary) 16%, var(--mud-palette-lines-default));
    background: color-mix(in srgb, var(--mud-palette-primary) 5%, var(--mud-palette-surface));
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.eg-grouped-container .eg-group-header.mud-paper:hover {
    border-color: color-mix(in srgb, var(--mud-palette-primary) 35%, transparent);
    background: color-mix(in srgb, var(--mud-palette-primary) 10%, var(--mud-palette-surface));
}

.eg-grouped-container .eg-group-header > span {
    display: inline-flex;
    align-items: center;
}

.eg-grouped-container .eg-group-header > span > .mud-icon-root {
    color: var(--mud-palette-primary);
}

.eg-grouped-container .eg-group-header .eg-group-count {
    padding: 2px 10px;
    border-radius: 999px;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
    color: var(--mud-palette-primary);
    background: color-mix(in srgb, var(--mud-palette-primary) 12%, var(--mud-palette-surface));
}

.eg-grouped-container .eg-group-header .eg-group-clear.mud-button-root {
    min-height: 28px;
    padding-inline: 8px 12px;
    border-radius: 999px;
    text-transform: none;
    font-weight: 650;
}

.eg-grouped-container .eg-group-header .eg-group-clear.mud-button-root:hover {
    background: color-mix(in srgb, var(--mud-palette-error) 10%, transparent);
}

/* Empty state: the icon sits in a tinted disc; Create is the gradient pill beside the Help pill. */
.eg-empty-overlay > .mud-icon-root {
    box-sizing: content-box;
    padding: 14px;
    border-radius: 50%;
    color: var(--mud-palette-primary);
    background: color-mix(in srgb, var(--mud-palette-primary) 10%, var(--mud-palette-surface));
    box-shadow: 0 0 0 6px color-mix(in srgb, var(--mud-palette-primary) 5%, transparent);
    opacity: 1 !important;
}

.eg-empty-overlay .eg-empty-actions {
    align-items: center;
}

.eg-empty-overlay .eg-empty-actions .mud-button-root:is(.eg-empty-create, .eg-empty-reset) {
    min-height: 36px;
    padding-block: 0;
    padding-inline: 14px 18px;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 650;
    letter-spacing: 0.01em;
    text-transform: none;
    transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.eg-empty-overlay .eg-empty-create.mud-button-filled:not(:disabled) {
    background-image: linear-gradient(135deg,
        var(--mud-palette-primary) 0%,
        color-mix(in srgb, var(--mud-palette-primary) 55%, var(--mud-palette-info)) 100%);
    box-shadow: 0 4px 12px color-mix(in srgb, var(--mud-palette-primary) 32%, transparent);
}

.eg-empty-overlay .eg-empty-create:hover:not(:disabled) {
    transform: translateY(-1px);
    filter: brightness(1.06);
    box-shadow: 0 7px 18px color-mix(in srgb, var(--mud-palette-primary) 34%, transparent);
}

.eg-empty-overlay .eg-empty-reset:hover:not(:disabled) {
    transform: translateY(-1px);
}

/* Footer: tinted bar, statistic pills, round pager buttons. */
.eg-table-footer {
    border-top: 1px solid color-mix(in srgb, var(--mud-palette-primary) 14%, var(--mud-palette-lines-default));
    background: linear-gradient(0deg,
        color-mix(in srgb, var(--mud-palette-primary) 5%, var(--mud-palette-surface)) 0%,
        var(--mud-palette-surface) 100%);
}

.eg-table-footer .eg-footer-left .mud-chip {
    height: 26px;
    margin: 0;
    padding-inline: 4px 10px;
    border-radius: 999px;
    border: 1px solid color-mix(in srgb, var(--mud-palette-primary) 20%, var(--mud-palette-lines-default));
    background: color-mix(in srgb, var(--mud-palette-primary) 5%, var(--mud-palette-surface));
    color: var(--mud-palette-text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.eg-table-footer .eg-footer-left .mud-chip .mud-chip-icon {
    box-sizing: content-box;
    width: 14px;
    height: 14px;
    margin-inline: 0 6px;
    padding: 2px;
    border-radius: 50%;
    color: var(--mud-palette-primary);
    background: color-mix(in srgb, var(--mud-palette-primary) 14%, transparent);
}

.mud-table-pagination-toolbar {
    gap: 6px;
}

.mud-table-pagination-caption {
    font-size: 0.8rem;
    color: var(--mud-palette-text-secondary);
    font-variant-numeric: tabular-nums;
}

.mud-table-pagination-select .mud-select-input {
    font-weight: 650;
}

.mud-table-pagination-actions .mud-icon-button {
    width: 32px;
    height: 32px;
    padding: 0;
    margin-inline: 2px;
    border-radius: 50%;
    border: 1px solid color-mix(in srgb, var(--mud-palette-primary) 22%, var(--mud-palette-lines-default));
    background: var(--mud-palette-surface);
    color: var(--mud-palette-primary);
    transition: transform 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.mud-table-pagination-actions .mud-icon-button:hover:not(:disabled) {
    transform: translateY(-1px);
    background: color-mix(in srgb, var(--mud-palette-primary) 12%, var(--mud-palette-surface));
    box-shadow: 0 4px 10px color-mix(in srgb, var(--mud-palette-primary) 20%, transparent);
}

.mud-table-pagination-actions .mud-icon-button:disabled {
    border-style: dashed;
    border-color: var(--mud-palette-lines-default);
    color: var(--mud-palette-text-disabled);
}

.mud-table-pagination-actions .mud-icon-button:focus-visible {
    outline: 2px solid var(--mud-palette-primary);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .eg-toolbar .eg-actions .mud-fab,
    .eg-toolbar .eg-actions .mud-fab .mud-icon-root,
    .eg-search .eg-search-field .mud-input.mud-input-outlined,
    .eg-search .eg-search-field .mud-input-adornment-start .mud-icon-root,
    .eg-table-shell .eg-col-menu .mud-icon-button,
    .eg-table-shell .eg-row-restore .mud-icon-root,
    .eg-grouped-container .eg-group-header.mud-paper,
    .eg-empty-overlay .eg-empty-actions .mud-button-root,
    .mud-table-pagination-actions .mud-icon-button {
        transition: none;
    }

    .eg-toolbar .eg-actions .mud-fab:hover,
    .eg-toolbar .eg-actions .mud-fab:hover .mud-icon-root,
    .eg-search .eg-search-field .mud-input.mud-input-outlined:focus-within .mud-input-adornment-start .mud-icon-root,
    .eg-table-shell .eg-row-restore.mud-button-root:hover .mud-icon-root,
    .eg-empty-overlay .eg-empty-actions .mud-button-root:hover,
    .mud-table-pagination-actions .mud-icon-button:hover {
        transform: none;
    }
}

@media print {
    .eg-table-footer {
        background: none;
    }
}
