/* erp-table.css split (6/6): Vue crud-table engine only (erp-table-card--vue
 * modifier) — sticky selection/actions columns, touch behavior, filter/
 * column-manager popover panels, keyboard-resize focus rings. See
 * table-contract.md "Vue Crud-Table Engine". */

/* --------------------------------------------------------------------------
 * Vue crud-table engine (Phase 7). The Vue engine renders one semantic table
 * and keeps selection and row actions as sticky edge columns instead of the
 * Blade engine's JS-synced side rails. Popover surfaces are positioned by
 * KviewPopover; these panel classes therefore carry visuals only, never
 * positioning.
 * ------------------------------------------------------------------------ */

.erp-vue-panel {
    width: min(320px, calc(100vw - 2rem));
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius-popover);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    color: var(--color-ink);
}

.erp-vue-panel--filter {
    width: min(300px, calc(100vw - 2rem));
    /* Head, body and actions already own their insets. Keeping the outer
     * surface flush prevents a second padding layer around every section. */
    padding: var(--space-0);
}

.erp-vue-panel--export {
    width: min(420px, calc(100vw - 2rem));
}

.erp-table .erp-table-select-head,
.erp-table .erp-table-select-cell {
    box-sizing: border-box;
    position: sticky;
    left: 0;
    z-index: 4;
    width: 44px;
    min-width: 44px;
    max-width: 44px;
    padding: 0;
    text-align: center;
    background: var(--surface);
}

.erp-table-card--vue .erp-table-stage {
    --erp-actions-overlay-width: 112px;
}

.erp-table-card--vue .erp-table .erp-table-actions-head,
.erp-table-card--vue .erp-table .erp-table-actions-cell {
    box-sizing: border-box;
    position: sticky;
    right: 0;
    z-index: 4;
    width: 0;
    min-width: 0;
    max-width: 0;
    padding: 0;
    text-align: end;
    background: transparent;
    overflow: visible;
}

.erp-table thead .erp-table-select-head {
    z-index: 5;
    background: var(--surface-sunken);
}

.erp-table thead .erp-table-actions-head {
    z-index: 5;
    background: transparent;
}

/* Scrolling data cells carry no stacking context, so they never paint over
 * the sticky edge columns and cannot intercept their clicks. */
.erp-table-card--vue tbody td:not(.erp-table-select-cell):not(.erp-table-actions-cell) {
    z-index: 0;
}

/* Selection owns a real leading gutter at every input mode. The checkbox may
 * stay visually quiet on pointer devices, but its reserved space prevents it
 * from ever covering the first data label or value. */
.erp-table-card--vue .erp-table .erp-table-select-head,
.erp-table-card--vue .erp-table .erp-table-select-cell {
    width: 44px;
    min-width: 44px;
    max-width: 44px;
    border-right: 0;
    box-shadow: none;
    overflow: hidden;
}

.erp-table-card--vue .erp-table .erp-table-select-head {
    background: var(--surface-sunken);
}

.erp-table-card--vue .erp-table .erp-table-select-cell {
    background: var(--surface);
}

/* The depth cue is contextual rather than permanent: it appears only when a
 * visible checkbox sits above horizontally scrolled data. */
.erp-table-card--vue .erp-table-scroll.is-scrolled-x thead tr:hover .erp-table-select-head,
.erp-table-card--vue .erp-table-scroll.is-scrolled-x thead tr:focus-within .erp-table-select-head,
.erp-table-card--vue .erp-table-scroll.is-scrolled-x .erp-table-select-head:has(input:checked),
.erp-table-card--vue .erp-table-scroll.is-scrolled-x .erp-table-select-head:has(input:indeterminate),
.erp-table-card--vue .erp-table-scroll.is-scrolled-x tbody tr:hover .erp-table-select-cell,
.erp-table-card--vue .erp-table-scroll.is-scrolled-x tbody tr:focus-within .erp-table-select-cell,
.erp-table-card--vue .erp-table-scroll.is-scrolled-x .erp-table-select-cell:has(input:checked) {
    box-shadow: 8px 0 12px -12px color-mix(in srgb, var(--color-kview) 35%, transparent);
}

.erp-table-card--vue .erp-table-actions-head,
.erp-table-card--vue .erp-table-actions-cell {
    box-shadow: none;
    pointer-events: none;
}

/* Match the historical side rail without recreating it: selection stays
 * quiet until the relevant row/head is hovered, focused, or selected. */
.erp-table-card--vue .erp-table-select-head input,
.erp-table-card--vue .erp-table-select-cell input {
    position: absolute;
    z-index: 2;
    top: 50%;
    left: 14px;
    display: block;
    width: 1rem;
    height: 1rem;
    margin: 0;
    accent-color: var(--primary);
    opacity: 0;
    pointer-events: none;
    transform: translateY(-50%);
    transition: opacity var(--transition-fast), box-shadow var(--transition-fast);
}

.erp-table-card--vue thead tr:hover .erp-table-select-head input,
.erp-table-card--vue thead tr:focus-within .erp-table-select-head input,
.erp-table-card--vue tbody tr:hover .erp-table-select-cell input,
.erp-table-card--vue tbody tr:focus-within .erp-table-select-cell input,
.erp-table-card--vue .erp-table-select-head input:checked,
.erp-table-card--vue .erp-table-select-head input:indeterminate,
.erp-table-card--vue .erp-table-select-cell input:checked,
.erp-table-card--vue .erp-table-select-head input:focus-visible,
.erp-table-card--vue .erp-table-select-cell input:focus-visible {
    opacity: 1;
    pointer-events: auto;
}

/* Row commands are an overlay, not a table column. Its veil is absent at rest,
 * then becomes fully opaque beneath the icons so clipped cell ellipses never
 * read as a fourth action. */
.erp-table-card--vue .erp-table-actions-cell::before {
    position: absolute;
    z-index: 1;
    top: 0;
    right: 0;
    bottom: 0;
    width: var(--erp-actions-overlay-width, 112px);
    background: linear-gradient(
        90deg,
        transparent 0%,
        var(--surface-alt) 18%,
        var(--surface-alt) 100%
    );
    content: "";
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-fast);
}

.erp-table-card--vue tbody tr:hover .erp-table-actions-cell::before,
.erp-table-card--vue tbody tr:focus-within .erp-table-actions-cell::before {
    opacity: 1;
}

/* Vue mirrors the Blade engine's scroll-state classes from its owning
 * component. The shared overflow rule above then stays authoritative. */

/* The legacy 991px viewport breakpoint is deliberately overridden for the
 * Vue engine. Flex wrapping lets the three groups stay on one line whenever
 * their real translated content fits, instead of relying on a magic width. */
.erp-table-card--vue .erp-table-footer {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
}

.erp-table-card--vue .erp-table-footnote {
    min-width: max-content;
    flex: 1 1 auto;
    white-space: nowrap;
}

.erp-table-card--vue .erp-page-size-form,
.erp-table-card--vue .erp-table-pagination:not(:empty) {
    flex: 0 0 auto;
}

.erp-table-card--vue .erp-table-pagination:not(:empty) {
    margin-left: auto;
}

/* The Vue template keeps the pagination slot mounted even for a single page.
 * Removing that empty grid item prevents a phantom second footer row. */
.erp-table-card--vue .erp-table-pagination:empty {
    display: none;
}

/* The select-all checkbox shows the partial-selection tri-state. */
.erp-table-card--vue .erp-table-select-head input:indeterminate {
    accent-color: var(--primary);
}

/* On a narrow container the toolbar stacks: search on its own row, while the
 * command cluster wraps without splitting the contextual count/delete pair. */
@container erp-table (max-width: 620px) {
    .erp-table-card--vue .erp-table-toolbar {
        grid-template-columns: minmax(0, 1fr);
    }

    .erp-table-card--vue .erp-table-toolbar-actions {
        flex-wrap: wrap;
        justify-content: flex-start;
    }
}

/* The Vue column manager adds keyboard reorder buttons and a focusable drag
 * handle, so its rows use their own grid (handle, toggle, move buttons)
 * instead of the Blade label layout. It is teleported to <body> by
 * KviewPopover, so these rules are scoped to the panel class that travels
 * with the teleported content, not to the .erp-table-card--vue section. */
.erp-vue-panel .erp-column-manager {
    margin: 0;
    list-style: none;
}

.erp-vue-panel .erp-column-manager-item {
    grid-template-columns: 18px minmax(0, 1fr) auto;
    column-gap: 0.5rem;
}

.erp-vue-panel .erp-drag-handle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    cursor: grab;
}

.erp-vue-panel .erp-column-manager-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-width: 0;
    cursor: pointer;
}

.erp-vue-panel .erp-column-manager-toggle span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.erp-vue-panel .erp-column-manager-move {
    display: inline-flex;
    gap: 0.1rem;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.erp-vue-panel .erp-column-manager-item:hover .erp-column-manager-move,
.erp-vue-panel .erp-column-manager-item:focus-within .erp-column-manager-move {
    opacity: 1;
}

.erp-vue-panel .erp-drag-handle:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 1px;
    border-radius: var(--radius-sm);
}

.erp-table-card--vue .erp-column-resize:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 1px;
    border-radius: var(--radius-sm);
}

/* Row commands stay quiet until the row is active, like the Blade rail.
 * The base .erp-row-actions class ships opacity: 0 and pointer-events: none
 * for the Blade rail; the row-driven states below must restore BOTH. Genuine
 * touch-only viewports use the row-detail path and hide this redundant column
 * in the media rule below. */
.erp-table-card--vue .erp-table-actions-cell .erp-row-actions {
    position: absolute;
    z-index: 2;
    top: 50%;
    right: 0.45rem;
    transform: translateY(-50%);
    opacity: 0;
    pointer-events: none;
    transition: opacity 120ms ease;
}

.erp-table-card--vue tbody tr:hover .erp-table-actions-cell .erp-row-actions,
.erp-table-card--vue tbody tr:focus-within .erp-table-actions-cell .erp-row-actions {
    padding: 0.1rem 0.15rem;
    border-radius: var(--radius-sm);
    background: var(--surface-alt);
    opacity: 1;
    pointer-events: auto;
}

@media (hover: none) and (pointer: coarse) and (any-hover: none) {
    .erp-table-card--vue .erp-table-persistent-horizontal-scroll {
        display: none;
    }

    .erp-table-card--vue .erp-table-scroll.is-horizontally-scrollable .erp-table-main-scroll {
        scrollbar-width: thin;
    }

    .erp-table-card--vue .erp-table-scroll.is-horizontally-scrollable .erp-table-main-scroll::-webkit-scrollbar {
        width: 8px;
        height: 8px;
    }

    .erp-table-card--vue .erp-table-select-head input,
    .erp-table-card--vue .erp-table-select-cell input {
        position: static;
        margin: 0 auto;
        opacity: 1;
        pointer-events: auto;
        transform: none;
    }

    /* Touch has no hover discovery state, so its checkbox is always visible
     * inside the same reserved 44px gutter. */
    .erp-table-card--vue .erp-table-scroll.is-scrolled-x .erp-table-select-head,
    .erp-table-card--vue .erp-table-scroll.is-scrolled-x .erp-table-select-cell {
        box-shadow: 8px 0 12px -12px color-mix(in srgb, var(--color-kview) 35%, transparent);
    }

    /* Touch: the trailing per-row action buttons are both unreliable (tiny
     * targets inside a horizontally-scrolling table, whose tooltip wrappers
     * intercept taps against the scroll container) and redundant — tapping
     * the full-width row navigates to the detail page where every action
     * lives. Hide the column rather than ship a broken affordance (the Blade
     * engine still shows these buttons visible-but-untappable on mobile).
     * Selection checkboxes stay for bulk actions. This is the production
     * mobile contract verified during the completed Phase 7 cutover. */
    .erp-table-card--vue .erp-table-actions-head,
    .erp-table-card--vue .erp-table-actions-cell {
        display: none;
    }
}
