/* Resized Column Styles */
/* Reserve a right gutter on every resizable header so the sort icon/label
   never collides with the resize handle bar sitting at the right edge. */
.group\/column-resize {
    padding-inline-end: 1rem !important;
    overflow: hidden;
}

/* Resize handle — painted via CSS so it appears with the header HTML. */
thead th.fi-ta-header-cell[data-column-name]::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 0.625rem;
    z-index: 2;
    cursor: col-resize;
    user-select: none;
    touch-action: none;
    pointer-events: auto;
    background: linear-gradient(
        to right,
        transparent calc(100% - 1px),
        rgb(203 213 225 / 0.4) calc(100% - 1px),
        rgb(203 213 225 / 0.4) 100%
    );
    transition: background 150ms ease;
}

.dark thead th.fi-ta-header-cell[data-column-name]::after {
    background: linear-gradient(
        to right,
        transparent calc(100% - 1px),
        rgb(148 163 184 / 0.35) calc(100% - 1px),
        rgb(148 163 184 / 0.35) 100%
    );
}

.group\/column-resize:hover::after,
thead th.fi-ta-header-cell[data-column-name].resized-column-is-resizing::after {
    background: linear-gradient(
        to right,
        transparent calc(100% - 2px),
        rgb(var(--primary-500, 59 130 246) / 0.85) calc(100% - 2px),
        rgb(var(--primary-500, 59 130 246) / 0.85) 100%
    );
}

/* Legacy DOM handle (older cached assets). */
.column-resize-handle-bar {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    width: 0.625rem;
    cursor: col-resize;
    user-select: none;
    touch-action: none;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 0;
    padding: 0;
    margin: 0;
    appearance: none;
    pointer-events: auto;
}

.column-resize-handle-line {
    display: block;
    width: 1px;
    height: 66.666667%;
    flex-shrink: 0;
    border-radius: 1px;
    background-color: rgb(203 213 219);
    opacity: 0.4;
    pointer-events: auto;
    transition: opacity 150ms ease, background-color 150ms ease, width 150ms ease;
}

.dark .column-resize-handle-line {
    background-color: rgb(148 163 184);
    opacity: 0.35;
}

.fi-main .fi-ta .fi-ta-header-cell .column-resize-handle-line {
    background-color: rgb(203 213 219);
}

.dark .fi-main .fi-ta .fi-ta-header-cell .column-resize-handle-line {
    background-color: rgb(148 163 184);
}

.group\/column-resize:hover .column-resize-handle-line,
.column-resize-handle-bar:hover .column-resize-handle-line,
.column-resize-handle-bar.active .column-resize-handle-line {
    width: 2px;
    opacity: 0.85;
    background-color: rgb(var(--primary-500, 59 130 246));
}

/* Table header cell styles */
.fi-ta-header-cell {
    position: relative;
}

.fi-ta-header-cell .fi-ta-header-cell-sort-btn,
.fi-ta-header-cell .fi-ta-header-cell-tooltip {
    position: relative;
    z-index: 1;
}

.fi-ta-header-cell .column-resize-handle-bar {
    z-index: 2;
}

/* Only elevate the column actively being resized. */
thead th.fi-ta-header-cell.resized-column-is-resizing {
    z-index: 100 !important;
}

/* Visibility while scrolled is toggled via JS on the header cell. */
.fi-ta-table.resized-column-is-scrolled th[data-column-name]:not(.resized-column-handle-visible):not(.resized-column-is-resizing)::after {
    visibility: hidden;
    pointer-events: none;
}

.fi-ta-table.resized-column-is-scrolled th[data-column-name].resized-column-handle-visible::after,
.fi-ta-table.resized-column-is-scrolled th[data-column-name].resized-column-is-resizing::after {
    visibility: visible;
    pointer-events: auto;
}

.fi-ta-table.resized-column-is-scrolled .column-resize-handle-bar:not(.active):not(.is-visible) {
    visibility: hidden;
    pointer-events: none;
}

.fi-ta-table.resized-column-is-scrolled .column-resize-handle-bar.is-visible,
.fi-ta-table.resized-column-is-scrolled .column-resize-handle-bar.active {
    visibility: visible;
    pointer-events: auto;
}

/* Keep sort label from covering the resize gutter inside the same header. */
.group\/column-resize .fi-ta-header-cell-sort-btn {
    width: calc(100% - 1rem);
    max-width: calc(100% - 1rem);
}

body.resized-column-resizing {
    cursor: col-resize !important;
    user-select: none;
}

body.resized-column-resizing * {
    cursor: col-resize !important;
}

/* Reserve space on the left of a reorderable header so the grip sits in a
   gutter instead of overlapping the label. */
.resized-reorderable-col,
thead th.fi-ta-header-cell.resized-reorderable-col {
    padding-inline-start: 1.75rem !important;
}

/* Theme header cells use overflow-hidden; keep the grip visible in the gutter. */
.fi-main .fi-ta .fi-ta-header-cell.resized-reorderable-col {
    overflow: visible;
}

/* Reorder grip — SVG ::before (same pattern as pin icon) paints with the HTML. */
thead th.fi-ta-header-cell.resized-reorderable-col:not([data-sticky])::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0.5rem;
    transform: translateY(-50%);
    display: block;
    width: 0.65rem;
    height: 0.85rem;
    pointer-events: none;
    z-index: 4;
    flex-shrink: 0;
    opacity: 0.55;
    transition: opacity 0.15s ease;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%2394a3b8'%3E%3Ccircle cx='7' cy='5' r='1.5'/%3E%3Ccircle cx='13' cy='5' r='1.5'/%3E%3Ccircle cx='7' cy='10' r='1.5'/%3E%3Ccircle cx='13' cy='10' r='1.5'/%3E%3Ccircle cx='7' cy='15' r='1.5'/%3E%3Ccircle cx='13' cy='15' r='1.5'/%3E%3C/svg%3E") center / contain no-repeat;
}

.dark thead th.fi-ta-header-cell.resized-reorderable-col:not([data-sticky])::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%23cbd5e1'%3E%3Ccircle cx='7' cy='5' r='1.5'/%3E%3Ccircle cx='13' cy='5' r='1.5'/%3E%3Ccircle cx='7' cy='10' r='1.5'/%3E%3Ccircle cx='13' cy='10' r='1.5'/%3E%3Ccircle cx='7' cy='15' r='1.5'/%3E%3Ccircle cx='13' cy='15' r='1.5'/%3E%3C/svg%3E");
}

.group\/column-resize:hover.resized-reorderable-col::before,
.resized-reorderable-col:hover::before {
    opacity: 1;
}

/* Transparent hit target for Sortable; visual grip is the header ::before above. */
.resized-col-drag {
    position: absolute;
    top: 50%;
    left: 0.5rem;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1rem;
    height: 1rem;
    padding: 0;
    margin: 0;
    border: 0;
    background: transparent;
    cursor: grab;
    opacity: 0;
    z-index: 5;
}

.resized-col-drag:active {
    cursor: grabbing;
}

.sortable-ghost {
    opacity: 0.4;
}

/* Pin icon on pinned column headers — CSS ::before paints with the HTML so
   icons do not wait for Alpine init + Livewire morph + scheduleStickyRefresh. */
thead th.fi-ta-header-cell[data-sticky]::before,
thead th.fi-ta-header-cell.resized-sticky::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0.75rem;
    transform: translateY(-50%);
    display: block;
    width: 0.85rem;
    height: 0.85rem;
    z-index: 2;
    flex-shrink: 0;
    pointer-events: none;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%236b7280'%3E%3Cpath d='M9.828.722a.5.5 0 0 1 .707 0l3.943 3.944a.5.5 0 0 1-.219.828l-2.31.66-2.573 2.573 1.06 3.006a.5.5 0 0 1-.117.518l-.707.707a.5.5 0 0 1-.707 0L6.229 9.7l-3.238 3.238a.5.5 0 0 1-.707-.707L5.522 8.99 2.79 6.257a.5.5 0 0 1 0-.707l.707-.707a.5.5 0 0 1 .518-.117l3.006 1.06 2.573-2.573.66-2.31a.5.5 0 0 1 .174-.281z'/%3E%3C/svg%3E") center / contain no-repeat;
}

.dark thead th.fi-ta-header-cell[data-sticky]::before,
.dark thead th.fi-ta-header-cell.resized-sticky::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%239ca3af'%3E%3Cpath d='M9.828.722a.5.5 0 0 1 .707 0l3.943 3.944a.5.5 0 0 1-.219.828l-2.31.66-2.573 2.573 1.06 3.006a.5.5 0 0 1-.117.518l-.707.707a.5.5 0 0 1-.707 0L6.229 9.7l-3.238 3.238a.5.5 0 0 1-.707-.707L5.522 8.99 2.79 6.257a.5.5 0 0 1 0-.707l.707-.707a.5.5 0 0 1 .518-.117l3.006 1.06 2.573-2.573.66-2.31a.5.5 0 0 1 .174-.281z'/%3E%3C/svg%3E");
}

/* Legacy JS-injected span (kept for older cached assets / toggle variant). */
.resized-sticky-pin {
    position: absolute;
    top: 50%;
    left: 0.75rem;
    transform: translateY(-50%);
    display: block;
    width: 0.85rem;
    height: 0.85rem;
    z-index: 2;
    flex-shrink: 0;
    pointer-events: none;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%236b7280'%3E%3Cpath d='M9.828.722a.5.5 0 0 1 .707 0l3.943 3.944a.5.5 0 0 1-.219.828l-2.31.66-2.573 2.573 1.06 3.006a.5.5 0 0 1-.117.518l-.707.707a.5.5 0 0 1-.707 0L6.229 9.7l-3.238 3.238a.5.5 0 0 1-.707-.707L5.522 8.99 2.79 6.257a.5.5 0 0 1 0-.707l.707-.707a.5.5 0 0 1 .518-.117l3.006 1.06 2.573-2.573.66-2.31a.5.5 0 0 1 .174-.281z'/%3E%3C/svg%3E") center / contain no-repeat;
}

.dark .resized-sticky-pin {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%239ca3af'%3E%3Cpath d='M9.828.722a.5.5 0 0 1 .707 0l3.943 3.944a.5.5 0 0 1-.219.828l-2.31.66-2.573 2.573 1.06 3.006a.5.5 0 0 1-.117.518l-.707.707a.5.5 0 0 1-.707 0L6.229 9.7l-3.238 3.238a.5.5 0 0 1-.707-.707L5.522 8.99 2.79 6.257a.5.5 0 0 1 0-.707l.707-.707a.5.5 0 0 1 .518-.117l3.006 1.06 2.573-2.573.66-2.31a.5.5 0 0 1 .174-.281z'/%3E%3C/svg%3E");
}

thead th.fi-ta-header-cell[data-sticky="left"],
thead th.fi-ta-header-cell[data-sticky="right"],
thead th.fi-ta-header-cell.resized-sticky {
    padding-inline-start: 2rem !important;
}

/* Clickable toggle variant (stickable tables): faint when unpinned, solid
   when pinned, brighter on hover. */
.resized-sticky-pin.is-toggle {
    pointer-events: auto;
    cursor: pointer;
    opacity: 0.55;
    transition: opacity 0.15s ease;
}

.resized-sticky-pin.is-toggle:hover {
    opacity: 1;
}

.resized-sticky-pin.is-toggle.is-pinned {
    opacity: 1;
}

/* Sticky columns need border-collapse: separate for reliable sticky positioning. */
.fi-ta-content-ctn .fi-ta-table {
    border-collapse: separate;
    border-spacing: 0;
}

/* Horizontal scroll wrappers (adapted from filament-sticky-columns). */
.fi-ta-table-wrapper,
.fi-ta-content-ctn.fi-fixed-positioning-context,
[data-sticky-wrapper] {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/*
 * Sticky surface tokens — opaque backgrounds so scrolled columns do not bleed through.
 * Defaults resolve to Filament's own table surface variables (light + dark).
 *
 * Override any of these anywhere (:root, .fi-ta-ctn, a single table) and it wins,
 * because the defaults live in the var() fallback chain, not in a competing declaration:
 *
 * --resized-sticky-header-bg        Pinned header cells
 * --resized-sticky-cell-bg          Pinned body cells (default row)
 * --resized-sticky-cell-bg-emphasis Pinned body cells (striped, hover, selected)
 */
:root {
    --resized-sticky-surface: var(--color-white, #fff);
    /* Filament tints the header row: .fi-ta-table > thead > tr { background: --gray-50 } */
    --resized-sticky-surface-header: var(--gray-50, #f9fafb);
    --resized-sticky-surface-emphasis: var(--gray-50, #f9fafb);
}

/* Filament toggles `.dark` on <html>, so scope the dark surfaces there — a table
   rendered outside .fi-ta-ctn (modal, widget, custom view) still resolves.
   Filament's dark tints are translucent (5% white over the surface); a pinned cell
   has to be opaque, so composite the same colour instead. */
.dark,
.dark .fi-ta-ctn,
.dark .fi-ta-content-ctn {
    --resized-sticky-surface: var(--gray-900, #111827);
    --resized-sticky-surface-header: color-mix(in oklab, var(--color-white, #fff) 5%, var(--gray-900, #111827));
    --resized-sticky-surface-emphasis: color-mix(in oklab, var(--color-white, #fff) 5%, var(--gray-900, #111827));
}

/* JS-applied sticky cells */
[data-sticky-applied] {
    transition: box-shadow 150ms ease;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    overflow: hidden !important;
    min-width: 0;
    isolation: isolate;
}

/* Every pinned cell is opaque — body, footer/summary, selection cell, whatever
   Filament renders. Keyed off the attribute alone so a cell without .fi-ta-cell
   never scrolls transparent. */
[data-sticky-applied] {
    background-color: var(--resized-sticky-cell-bg, var(--resized-sticky-surface)) !important;
}

thead [data-sticky-applied],
[data-sticky-applied].fi-ta-header-cell {
    background-color: var(--resized-sticky-header-bg, var(--resized-sticky-surface-header)) !important;
}

/* Striped/hover/selected rows: Filament tints the <tr>, so the pinned cell has to
   repaint that tint opaquely or the scrolled columns show through it. */
.fi-ta-row.fi-striped [data-sticky-applied],
.fi-ta-row.fi-clickable:hover [data-sticky-applied],
.fi-ta-row.fi-selected [data-sticky-applied] {
    background-color: var(--resized-sticky-cell-bg-emphasis, var(--resized-sticky-surface-emphasis)) !important;
}

[data-sticky-applied="left"],
[data-sticky-applied="right"] {
    box-shadow: none;
}

/* Inset edge on last pinned column when scrolled (body rows only). */
[data-sticky-applied="left"].sticky-shadow-active:not(.fi-ta-header-cell) {
    box-shadow: inset -6px 0 8px -6px var(--sticky-shadow-color, rgba(0, 0, 0, 0.18));
}

[data-sticky-applied="right"].sticky-shadow-active:not(.fi-ta-header-cell) {
    box-shadow: inset 6px 0 8px -6px var(--sticky-shadow-color, rgba(0, 0, 0, 0.18));
}

.dark [data-sticky-applied="left"].sticky-shadow-active:not(.fi-ta-header-cell),
.dark [data-sticky-applied="right"].sticky-shadow-active:not(.fi-ta-header-cell) {
    --sticky-shadow-color: rgba(0, 0, 0, 0.45);
}

thead [data-sticky-applied] {
    z-index: 20 !important;
}

/* Clip overflowing cell text inside sticky cells. */
.fi-ta-cell.resized-sticky .fi-ta-col,
.fi-ta-cell.resized-sticky .fi-ta-text,
.fi-ta-header-cell.resized-sticky .fi-ta-header-cell-sort-btn,
[data-sticky-applied] .fi-ta-col,
[data-sticky-applied] .fi-ta-text,
[data-sticky-applied] .fi-ta-header-cell-sort-btn,
[data-sticky-applied] .fi-ta-header-cell-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
    min-width: 0;
}

/* "Pin columns" toolbar dropdown panel */
.resized-sticky-panel {
    position: relative;
    display: inline-flex;
    align-items: center;
}

/* Container + trigger styled here (Filament's fi-dropdown-panel sets
   width:100vw and expects its floating-ui parent, so it can't be reused
   standalone). Only the checkbox reuses Filament's fi-checkbox-input. */
.resized-sticky-panel-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 0.5rem;
    color: rgb(113 113 122);
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.resized-sticky-panel-trigger svg {
    width: 1.25rem;
    height: 1.25rem;
}

.resized-sticky-panel-trigger:hover {
    background-color: rgb(244 244 245);
    color: rgb(63 63 70);
}

.dark .resized-sticky-panel-trigger {
    color: rgb(161 161 170);
}

.dark .resized-sticky-panel-trigger:hover {
    background-color: rgb(39 39 42);
    color: rgb(228 228 231);
}

.resized-sticky-panel-menu {
    position: absolute;
    top: calc(100% + 0.25rem);
    inset-inline-end: 0;
    z-index: 40;
    min-width: 14rem;
    max-height: 20rem;
    overflow-y: auto;
    padding: 0.375rem;
    border-radius: 0.75rem;
    background-color: rgb(255 255 255);
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    border: 1px solid rgb(228 228 231);
}

.dark .resized-sticky-panel-menu {
    background-color: rgb(24 24 27);
    border-color: rgb(39 39 42);
}

.resized-sticky-panel-heading {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: rgb(113 113 122);
}

.dark .resized-sticky-panel-heading {
    color: rgb(161 161 170);
}

.resized-sticky-panel-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.5rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    color: rgb(39 39 42);
    cursor: pointer;
}

.resized-sticky-panel-item:hover {
    background-color: rgb(244 244 245);
}

.dark .resized-sticky-panel-item {
    color: rgb(228 228 231);
}

.dark .resized-sticky-panel-item:hover {
    background-color: rgb(39 39 42);
}

.resized-sticky-panel-item--locked {
    cursor: not-allowed;
    opacity: 0.85;
}

.resized-sticky-panel-item--locked:hover {
    background-color: transparent;
}

.dark .resized-sticky-panel-item--locked:hover {
    background-color: transparent;
}

.resized-sticky-panel-empty {
    padding: 0.5rem;
    font-size: 0.875rem;
    color: rgb(161 161 170);
}

.resized-sticky-panel-bulk {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 0.5rem;
    padding: 0.125rem 0.5rem 0.375rem;
}

.resized-sticky-panel-bulk-btn {
    padding: 0;
    border: 0;
    background: transparent;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
}

.resized-sticky-panel-bulk-btn--select {
    color: rgb(var(--primary-500, 234 179 8));
}

.resized-sticky-panel-bulk-btn--select:hover {
    color: rgb(var(--primary-600, 202 138 4));
}

.resized-sticky-panel-bulk-btn--deselect {
    color: rgb(220 38 38);
}

.resized-sticky-panel-bulk-btn--deselect:hover {
    color: rgb(185 28 28);
}

.dark .resized-sticky-panel-bulk-btn--deselect {
    color: rgb(248 113 113);
}

.dark .resized-sticky-panel-bulk-btn--deselect:hover {
    color: rgb(252 165 165);
}

.resized-sticky-panel-footer {
    display: flex;
    justify-content: flex-start;
    padding: 0.375rem 0.5rem 0.25rem;
    margin-top: 0.25rem;
    border-top: 1px solid rgb(228 228 231);
}

.dark .resized-sticky-panel-footer {
    border-top-color: rgb(39 39 42);
}

[x-cloak] {
    display: none !important;
}
