.table-prefs-shell {
    position: relative;
    margin: 0 0 16px;
}

.table-prefs-button {
    position: static;
    display: inline-grid;
    place-items: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
    font: inherit;
    font-size: 0.9rem;
    line-height: 1;
}

.table-prefs-button:hover {
    transform: translateY(-1px);
}

.table-prefs-filter-overlay {
    position: absolute;
    min-width: 240px;
    max-width: min(320px, calc(100vw - 32px));
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.18);
    z-index: 30;
}

.table-prefs-filter-overlay__title {
    font-weight: 700;
    margin-bottom: 10px;
}

.table-prefs-filter-overlay__row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.table-prefs-filter-overlay__button {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 10px;
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
    font: inherit;
    font-size: 0.92rem;
}

.table-prefs-filter-overlay__button:hover {
    background: var(--surface-3);
}

.table-prefs-filter-overlay__label {
    display: block;
    margin-top: 10px;
    font-size: 0.9rem;
}

.table-prefs-filter-overlay__input {
    width: 100%;
    margin-top: 6px;
    box-sizing: border-box;
}

.table-prefs-filter-overlay__help {
    margin-top: 6px;
    color: var(--muted);
    font-size: 0.85rem;
}

.table-prefs-header {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin: 0 0 8px;
}

.table-prefs-editor {
    display: none;
    margin: 0 0 8px;
}

.table-prefs-shell.is-editing .table-prefs-editor {
    display: none;
}

.table-prefs-col-title,
.table-prefs-col-controls {
    display: inline-flex;
    align-items: center;
}

.table-prefs-col-title {
    display: inline-block;
    min-width: 0;
    padding-right: 30px;
}

.table-prefs-sort-indicator {
    display: inline-block;
    margin-left: 6px;
    font-size: 0.8em;
    line-height: 1;
    color: var(--link);
    vertical-align: baseline;
}

.table-prefs-col-controls {
    position: absolute;
    top: 50%;
    right: 4px;
    transform: translateY(-50%);
    display: none;
    gap: 6px;
}

.table-prefs-col-checkbox {
    width: 14px;
    height: 14px;
    margin: 0;
}

.table-prefs-col-drag {
    display: inline-grid;
    place-items: center;
    width: 18px;
    height: 18px;
    border-radius: 4px;
    color: var(--muted);
    cursor: grab;
    user-select: none;
}

.table-prefs-shell.is-editing thead th,
.table-prefs-shell.is-editing tr:first-child th {
    position: sticky;
    top: 0;
    z-index: 2;
    overflow: visible;
}

.table-prefs-shell.is-editing thead th {
    background: var(--surface-2);
}

.table-prefs-shell.is-editing thead th.is-drop-before::before,
.table-prefs-shell.is-editing thead th.is-drop-after::after {
    content: "";
    position: absolute;
    top: 0;
    width: 8px;
    height: 100%;
    background: linear-gradient(90deg, rgba(79, 128, 255, 0), rgba(79, 128, 255, 0.8), rgba(79, 128, 255, 0));
    pointer-events: none;
    z-index: 4;
}

.table-prefs-shell.is-editing thead th.is-drop-before::before {
    left: 0;
}

.table-prefs-shell.is-editing thead th.is-drop-after::after {
    right: 0;
}

.table-prefs-shell.is-editing thead th.is-drop-before,
.table-prefs-shell.is-editing thead th.is-drop-after {
    box-shadow: inset 0 0 0 1px rgba(79, 128, 255, 0.25);
}

.table-prefs-drop-phantom {
    position: absolute;
    display: block;
    border: 2px dashed rgba(79, 128, 255, 0.95);
    background: rgba(79, 128, 255, 0.14);
    border-radius: 8px;
    pointer-events: none;
    z-index: 20;
    box-shadow: 0 10px 24px rgba(79, 128, 255, 0.18);
}

body.theme-dark .table-prefs-drop-phantom {
    background: rgba(79, 128, 255, 0.18);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}

.table-prefs-shell.is-editing .table-prefs-col-controls {
    display: inline-flex;
}

.table-prefs-shell.is-editing .table-prefs-resize-handle {
    opacity: 1;
}

.table-prefs-editor__item {
    display: grid;
    grid-template-columns: auto auto 1fr;
    gap: 8px;
    align-items: center;
    color: var(--text);
    font-size: 0.92rem;
    padding: 6px 8px;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: grab;
}

.table-prefs-editor__item.is-dragging {
    opacity: 0.6;
    border-color: var(--border);
}

.table-prefs-editor__drag {
    color: var(--muted);
    font-size: 1rem;
    letter-spacing: -1px;
}

.table-prefs-shell.is-scrollable .table-prefs-scroll {
    overflow: auto;
    max-width: 100%;
    max-height: 70vh;
    border: 1px solid var(--border);
    border-radius: 12px;
}

.table-prefs-shell.is-scrollable table {
    margin-bottom: 0;
    min-width: max-content;
}

.table-prefs-shell table {
    width: 100%;
    table-layout: auto;
}

.table-prefs-shell .table-prefs-scroll table {
    border: 0;
}

.table-prefs-shell thead th,
.table-prefs-shell tr:first-child th {
    position: sticky;
    top: 0;
    z-index: 2;
}

.table-prefs-shell thead th,
.table-prefs-shell tr:first-child th {
    cursor: pointer;
}

.table-prefs-filter-overlay {
    position: fixed;
}

.table-prefs-shell table.is-cols-hidden td,
.table-prefs-shell table.is-cols-hidden th {
    transition: opacity 0.15s ease;
}

.table-prefs-resize-handle {
    position: absolute;
    top: 0;
    right: -5px;
    width: 10px;
    height: 100%;
    cursor: default;
    touch-action: none;
    opacity: 0;
}

.table-prefs-resize-handle::after {
    content: "";
    position: absolute;
    top: 0;
    right: 4px;
    width: 2px;
    height: 100%;
    background: transparent;
}

.table-prefs-shell.is-editing .table-prefs-resize-handle,
.table-prefs-shell.is-editing thead th:hover .table-prefs-resize-handle::after,
.table-prefs-shell.is-editing .table-prefs-resize-handle:active::after {
    background: var(--link);
}

.table-prefs-shell.is-editing .table-prefs-resize-handle {
    cursor: col-resize;
}

.table-prefs-shell.is-editing .table-prefs-col-drag {
    cursor: grab;
}

body.theme-dark .table-prefs-panel {
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.4);
}
