/* =========================================================
   BOAZ ENTERPRISE TABLE PRIMITIVES

   Supported hooks and modifiers:
   - [data-boaz-enterprise-table]: opt-in root for shared table behavior.
   - [data-boaz-table-viewport]: horizontal/vertical responsive viewport.
   - .is-vertically-scrollable / .is-collapsed: enable vertical scrolling and sticky headers.
   - .has-vertical-overflow, .is-at-top, .is-at-bottom: JS-managed vertical scroll overlays.
   - [data-boaz-protected-column] or .boaz-table-actions-sticky: explicit sticky/action column opt-in.
     Do not rely on :last-child; detail/editor tables may end with non-action data.
   - .boaz-table-card, .boaz-table-wrap, .boaz-table-shell: shared table card containers.
   - .boaz-table-responsive, .boaz-table--comfortable, .boaz-table-empty-state: layout modifiers.
   - .boaz-enterprise-table__toolbar, __rows, __state, __pagination: chrome primitives.
   - .boaz-enterprise-table__action-list--desktop / --menu and [data-action-tone="danger"]: action layout.

   Page styles must not recreate table layout or interaction rules. Domain styles may
   decorate cell content (for example a product thumbnail or workflow indicator), but
   table/column sizing belongs to shell metadata and these primitives.
   ========================================================= */

[data-boaz-enterprise-table] {
    --boaz-enterprise-sticky-bg: var(--boaz-surface, var(--bs-body-bg));
    --boaz-enterprise-scroll-edge: color-mix(in srgb, var(--boaz-ink) 18%, transparent);
    --boaz-enterprise-scroll-surface: var(--boaz-surface, var(--bs-body-bg));
    --boaz-enterprise-scrollbar-thumb: var(--boaz-border-strong);
    position: relative;
}

.boaz-table-card,
.boaz-table-wrap,
.boaz-table-shell {
    background: var(--boaz-surface);
    border: 1px solid var(--boaz-border);
    border-radius: var(--boaz-radius-lg);
    box-shadow: var(--boaz-shadow-soft);
    overflow: hidden;
}

.boaz-table-responsive,
.boaz-table-card > .table-responsive,
.boaz-table-wrap > .table-responsive,
.boaz-table-shell > .table-responsive {
    -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
    border-radius: 0 0 var(--boaz-radius-lg) var(--boaz-radius-lg);
    overflow-x: auto;
    overflow-y: auto;
    scrollbar-width: none;
    touch-action: pan-x pan-y;
    width: 100%;
}

.boaz-table-responsive::-webkit-scrollbar,
.boaz-table-card > .table-responsive::-webkit-scrollbar,
.boaz-table-wrap > .table-responsive::-webkit-scrollbar,
.boaz-table-shell > .table-responsive::-webkit-scrollbar { display: none; height: 0; width: 0; }

.boaz-table { border-color: var(--boaz-border); color: var(--boaz-ink); min-width: var(--boaz-enterprise-table-min-width, 760px); }
.boaz-table--comfortable thead th, .boaz-table--comfortable tbody td { padding: .82rem 1rem; }
.boaz-table thead th { background: linear-gradient(180deg, var(--boaz-surface-soft), var(--boaz-surface-2)); border-bottom: 1px solid var(--boaz-border-strong); color: var(--boaz-steel); font-size: .76rem; letter-spacing: .08em; position: relative; text-transform: uppercase; vertical-align: middle; }
.boaz-table tbody td { border-top: 1px solid var(--boaz-border); color: var(--boaz-ink); vertical-align: middle; }
.boaz-table [data-boaz-column-kind] { width: var(--boaz-column-width, auto); }
.boaz-table [data-boaz-column-align="start"] { text-align: left; }
.boaz-table [data-boaz-column-align="center"] { text-align: center; }
.boaz-table [data-boaz-column-align="end"] { text-align: right; }
.boaz-table [data-boaz-column-wrap="false"],
.boaz-table [data-boaz-column-kind="code"],
.boaz-table [data-boaz-column-kind="date"],
.boaz-table [data-boaz-column-kind="amount"],
.boaz-table [data-boaz-column-kind="number"],
.boaz-table [data-boaz-column-kind="actions"] { white-space: nowrap; }
.boaz-table [data-boaz-column-kind="code"] { min-width: var(--boaz-column-width, 8.75rem); }
.boaz-table [data-boaz-column-kind="date"] { min-width: var(--boaz-column-width, 8.5rem); }
.boaz-table [data-boaz-column-kind="amount"] { font-variant-numeric: tabular-nums; min-width: var(--boaz-column-width, 8rem); }
.boaz-table [data-boaz-column-kind="status"] { min-width: var(--boaz-column-width, 7.5rem); }
.boaz-table [data-boaz-column-kind="actions"] { min-width: var(--boaz-column-width, 7rem); }
.boaz-table tbody tr { background: var(--boaz-surface); transition: background-color var(--boaz-transition-fast), box-shadow var(--boaz-transition-fast); }
.boaz-table-hover-row, .boaz-table tbody tr:focus-within, .boaz-table.table-hover tbody tr:hover { background: var(--boaz-brand-soft); }
.boaz-table tbody tr:focus-within { box-shadow: inset 3px 0 0 var(--boaz-orange); }
.boaz-table a:focus-visible, .boaz-table button:focus-visible, .boaz-table input:focus-visible, .boaz-table select:focus-visible { box-shadow: var(--boaz-focus-ring); outline: 0; }
.boaz-table-meta-row, .boaz-table-compact-meta { align-items: center; color: var(--boaz-muted); display: flex; flex-wrap: wrap; font-size: .84rem; font-weight: 700; gap: .35rem .65rem; line-height: 1.35; }
.boaz-table-actions-sticky, [data-boaz-protected-column] { background-clip: padding-box; }
.boaz-table-actions-cell .boaz-table-row-actions { flex-wrap: nowrap; }
.boaz-table-actions-cell .boaz-table-btn { min-width: 2.25rem; padding-inline: .65rem; }
.boaz-table-actions-cell .boaz-table-btn i { pointer-events: none; }

.boaz-enterprise-table__toolbar { align-items: center; border-bottom: 1px solid var(--boaz-border); box-sizing: border-box; display: flex; flex-wrap: wrap; gap: .75rem; inline-size: 100%; justify-content: space-between; left: 0; overflow: visible; padding: .75rem 1rem; position: sticky; z-index: 12; }
.boaz-enterprise-table__toolbar--generated { justify-content: flex-end; position: relative; }
.boaz-enterprise-table__toolbar-start, .boaz-enterprise-table__actions { align-items: center; display: flex; flex-wrap: wrap; gap: .75rem; }
.boaz-enterprise-table__summary { color: var(--bs-secondary-color); font-size: .875rem; }
.boaz-enterprise-table__rows { align-items: center; display: flex; gap: .5rem; margin-left: auto; }
.boaz-enterprise-table__rows label { font-size: .8125rem; font-weight: 600; white-space: nowrap; }
.boaz-enterprise-table__rows select { min-width: 4.75rem; }

[data-boaz-table-viewport] { -ms-overflow-style: none; -webkit-overflow-scrolling: touch; border-radius: var(--boaz-radius-md); box-sizing: border-box; inline-size: 100%; max-inline-size: 100%; min-inline-size: 0; overflow-x: auto; overflow-y: auto; overscroll-behavior-x: contain; overscroll-behavior-y: auto; scroll-behavior: auto; scrollbar-width: none; touch-action: pan-x pan-y; }
[data-boaz-table-viewport].is-vertically-scrollable, [data-boaz-table-viewport].is-collapsed { max-height: var(--boaz-enterprise-table-height); overflow-y: auto; }
[data-boaz-table-viewport].is-vertically-scrollable { border-block: 1px solid var(--boaz-border); }
[data-boaz-table-viewport]::-webkit-scrollbar { display: none; height: 0; width: 0; }
[data-boaz-table-viewport]::before, [data-boaz-table-viewport]::after { content: ""; display: block; height: 1.5rem; left: 0; opacity: 0; pointer-events: none; position: sticky; right: 0; transition: opacity var(--boaz-transition); z-index: 4; }
[data-boaz-table-viewport]::before { background: linear-gradient(to bottom, var(--boaz-enterprise-scroll-surface), transparent), radial-gradient(100% 100% at 50% 0, var(--boaz-enterprise-scroll-edge), transparent 70%); margin-bottom: -1.5rem; top: 0; }
[data-boaz-table-viewport]::after { background: linear-gradient(to top, var(--boaz-enterprise-scroll-surface), transparent), radial-gradient(100% 100% at 50% 100%, var(--boaz-enterprise-scroll-edge), transparent 70%); bottom: 0; margin-top: -1.5rem; }
[data-boaz-table-viewport].has-vertical-overflow:not(.is-at-top)::before, [data-boaz-table-viewport].has-vertical-overflow:not(.is-at-bottom)::after { opacity: 1; }
[data-boaz-enterprise-table] thead th, [data-boaz-table-viewport].is-collapsed thead th { background: var(--boaz-enterprise-sticky-bg); box-shadow: inset 0 -1px 0 var(--boaz-border); position: sticky; top: 0; z-index: 2; }
[data-boaz-protected-column], .boaz-table-actions-sticky { background: var(--boaz-enterprise-sticky-bg); position: sticky; right: 0; z-index: 1; }
thead [data-boaz-protected-column], .boaz-table thead .boaz-table-actions-sticky { z-index: 3; }
.boaz-table.table-hover tbody tr:hover [data-boaz-protected-column], .boaz-table tbody tr:focus-within [data-boaz-protected-column], .boaz-table.table-hover tbody tr:hover .boaz-table-actions-sticky, .boaz-table tbody tr:focus-within .boaz-table-actions-sticky { background: color-mix(in srgb, var(--boaz-orange) 8%, var(--boaz-surface)); }
.boaz-enterprise-table__state-cell { background: color-mix(in srgb, var(--boaz-surface-soft) 72%, transparent); border-top: 1px dashed var(--boaz-border-strong); }
.boaz-enterprise-table__state, .boaz-table-empty-state { align-items: center; display: flex; flex-direction: column; gap: .5rem; justify-content: center; min-height: 12rem; padding: 2rem; text-align: center; }
.boaz-table-empty-state { border-style: dashed; box-shadow: none; min-height: 15rem; }
.boaz-enterprise-table__state h3, .boaz-enterprise-table__state p { margin: 0; }
.boaz-enterprise-table__state-icon, .boaz-empty-state__icon.boaz-empty-icon, .boaz-table-empty-state .boaz-empty-icon { background: var(--boaz-orange-50); border-color: var(--boaz-orange-100); color: var(--boaz-orange); }
[data-boaz-table-state="loading"] .boaz-enterprise-table__state-icon { animation: boaz-enterprise-spin .9s linear infinite; }
[data-boaz-table-state="load-failure"] .boaz-enterprise-table__state-icon { background: color-mix(in srgb, var(--boaz-danger) 12%, var(--boaz-surface)); border-color: color-mix(in srgb, var(--boaz-danger) 26%, var(--boaz-border)); color: var(--boaz-danger); }
.boaz-enterprise-table__state-actions { align-items: center; display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; }
.boaz-enterprise-table__pagination { align-items: center; background: var(--boaz-surface); border-top: 1px solid var(--boaz-border); box-sizing: border-box; display: flex; flex-wrap: wrap; gap: .5rem; inline-size: 100%; justify-content: flex-end; left: 0; padding: .75rem 1rem; position: sticky; }
.boaz-enterprise-table__pagination[hidden] { display: none; }
.boaz-enterprise-table__page-numbers { align-items: center; display: flex; flex-wrap: wrap; gap: .25rem; }
.boaz-enterprise-table__page-numbers .btn { min-width: 2.25rem; }
.boaz-enterprise-table__page-gap { color: var(--boaz-muted); padding-inline: .25rem; }
.boaz-enterprise-table__action-group { display: inline-block; position: relative; }
.boaz-enterprise-table__action-menu { display: none; position: relative; }
.boaz-enterprise-table__action-menu > summary { display: none; }
.boaz-enterprise-table__action-list { align-items: stretch; display: inline-flex; gap: .375rem; justify-content: flex-end; }
.boaz-enterprise-table__action { align-items: center; background: transparent; border: 1px solid var(--boaz-border); border-radius: .375rem; color: var(--bs-body-color); display: inline-flex; font: inherit; font-size: .8125rem; font-weight: 600; gap: .375rem; justify-content: center; min-height: 2.25rem; min-width: 2.25rem; padding: .375rem .625rem; text-decoration: none; }
.boaz-enterprise-table__action:hover { background: var(--bs-tertiary-bg); color: var(--boaz-title); }
.boaz-enterprise-table__action:focus-visible, .boaz-enterprise-table__action-menu > summary:focus-visible { box-shadow: var(--boaz-focus-ring); outline: 0; }
.boaz-enterprise-table__action[aria-disabled="true"], .boaz-enterprise-table__action:disabled { cursor: not-allowed; opacity: .55; pointer-events: none; }
.boaz-enterprise-table__action[data-action-tone="danger"] { border-color: var(--boaz-danger); color: var(--boaz-danger); }
.boaz-enterprise-table__action[data-action-tone="danger"]:hover, .boaz-enterprise-table__action[data-action-tone="danger"]:focus-visible { background: var(--boaz-danger); color: var(--boaz-white); }

html[data-boaz-theme="dark"] [data-boaz-enterprise-table], html[data-bs-theme="dark"] [data-boaz-enterprise-table], html.dark [data-boaz-enterprise-table] { --boaz-enterprise-sticky-bg: var(--boaz-surface, var(--bs-body-bg)); --boaz-enterprise-scroll-edge: color-mix(in srgb, var(--boaz-white) 22%, transparent); --boaz-enterprise-scroll-surface: var(--boaz-surface, var(--bs-body-bg)); }

@media (max-width: 767.98px) {
    .boaz-enterprise-table__action-list--desktop { display: none; }
    .boaz-enterprise-table__action-menu { display: inline-block; }
    .boaz-enterprise-table__action-menu > summary { align-items: center; border: 1px solid var(--boaz-border); border-radius: .375rem; cursor: pointer; display: inline-flex; gap: .375rem; min-height: 2.25rem; padding: .375rem .625rem; }
    .boaz-enterprise-table__action-menu > summary::marker { content: ""; }
    .boaz-enterprise-table__action-menu:not([open]) .boaz-enterprise-table__action-list--menu { display: none; }
    .boaz-enterprise-table__action-list--menu { background: var(--boaz-surface); border: 1px solid var(--boaz-border); border-radius: .5rem; box-shadow: var(--boaz-shadow-md); flex-direction: column; min-width: 10rem; padding: .375rem; position: absolute; right: 0; top: calc(100% + .25rem); z-index: 10; }
    .boaz-enterprise-table__action-list--menu .boaz-enterprise-table__action { justify-content: flex-start; width: 100%; }
    .boaz-table-card, .boaz-table-wrap, .boaz-table-shell { border-radius: var(--boaz-radius-md); }
    .boaz-table { min-width: var(--boaz-enterprise-table-min-width, 680px); }
    .boaz-table--comfortable thead th, .boaz-table--comfortable tbody td { font-size: .86rem; padding: .7rem .78rem; }
    .boaz-table .badge-soft, .boaz-table .boaz-badge, .boaz-table .boaz-status-badge { line-height: 1.25; white-space: normal; }
    .boaz-table-empty-state { min-height: 12rem; padding: 1.5rem 1rem; }
    .boaz-table-actions-cell .boaz-table-btn { padding-inline: .55rem; }
}

@media (max-width: 575.98px) {
    .boaz-table-responsive, .boaz-table-card > .table-responsive, .boaz-table-wrap > .table-responsive, .boaz-table-shell > .table-responsive { border-radius: 0 0 var(--boaz-radius-md) var(--boaz-radius-md); }
    .boaz-table-toolbar, .boaz-table-card__header, .boaz-enterprise-table__toolbar { align-items: flex-start; flex-direction: column; }
    .boaz-table { min-width: var(--boaz-enterprise-table-min-width, 620px); }
}

@keyframes boaz-enterprise-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { [data-boaz-table-viewport] { scroll-behavior: auto; } [data-boaz-table-viewport]::before, [data-boaz-table-viewport]::after { transition: none; } }
@media (forced-colors: active) { .boaz-enterprise-table__action, .boaz-enterprise-table__action-menu > summary { border: 1px solid ButtonText; color: ButtonText; forced-color-adjust: auto; } .boaz-enterprise-table__action[data-action-tone="danger"] { border-style: double; border-width: 3px; color: ButtonText; } .boaz-enterprise-table__action:hover, .boaz-enterprise-table__action:focus-visible { background: Highlight; color: HighlightText; } [data-boaz-table-viewport]::before, [data-boaz-table-viewport]::after { display: none; } }


.boaz-enterprise-table__sort-link { align-items: center; color: inherit; display: inline-flex; gap: .35rem; text-decoration: none; }
.boaz-enterprise-table__sort-link:hover { color: var(--boaz-title); text-decoration: underline; }
.boaz-enterprise-table__sort-link i { color: var(--boaz-muted); font-size: .9rem; }
.boaz-table thead th[aria-sort="ascending"] .boaz-enterprise-table__sort-link i,
.boaz-table thead th[aria-sort="descending"] .boaz-enterprise-table__sort-link i { color: var(--boaz-orange); }
.boaz-enterprise-table__actions--display { align-items: center; display: flex; gap: .65rem; justify-content: flex-end; margin-left: auto; position: relative; z-index: 14; }
.boaz-enterprise-table__actions--display .boaz-enterprise-table__column-menu { order: 1; }
.boaz-enterprise-table__actions--display .boaz-enterprise-table__rows { margin-left: 0; order: 2; }
.boaz-enterprise-table__column-menu { flex: 0 0 auto; position: relative; }
.boaz-enterprise-table__column-trigger { align-items: center; border-radius: var(--boaz-radius-pill); cursor: pointer; display: inline-flex; gap: .45rem; list-style: none; min-height: 2.35rem; padding-inline: .8rem; white-space: nowrap; }
.boaz-enterprise-table__column-trigger::marker { content: ""; }
.boaz-enterprise-table__column-trigger::-webkit-details-marker { display: none; }
.boaz-enterprise-table__column-panel { background: var(--boaz-surface); border: 1px solid var(--boaz-border); border-radius: .85rem; box-shadow: var(--boaz-shadow-md); display: grid; gap: .2rem; left: auto; margin-top: .45rem; min-width: 13.5rem; padding: .45rem; position: absolute; right: 0; top: 100%; z-index: 100; }
.boaz-enterprise-table__column-menu:not([open]) .boaz-enterprise-table__column-panel { display: none; }
.boaz-enterprise-table__column-option { align-items: center; border-radius: .65rem; color: var(--boaz-ink); cursor: pointer; display: flex; font-size: .92rem; font-weight: 600; gap: .6rem; min-height: 2.15rem; padding: .45rem .55rem; text-transform: none; white-space: nowrap; }
.boaz-enterprise-table__column-option:hover, .boaz-enterprise-table__column-option:focus-within { background: var(--boaz-surface-soft); }
.boaz-enterprise-table__column-option input { accent-color: var(--boaz-orange); flex: 0 0 auto; height: 1rem; margin: 0; width: 1rem; }
@media (max-width: 575.98px) { .boaz-enterprise-table__actions--display { justify-content: flex-end; margin-left: auto; width: auto; } .boaz-enterprise-table__column-panel { left: auto; right: 0; } }
@media (forced-colors: active) { .boaz-enterprise-table__column-panel { border-color: ButtonText; } .boaz-enterprise-table__column-trigger { border-color: ButtonText; color: ButtonText; } }
.boaz-enterprise-table--generated-shell { overflow: visible !important; }

/* The shell viewport is the sole two-axis scrolling surface. */
.boaz-enterprise-table__viewport { overflow: auto; overscroll-behavior: auto; scrollbar-width: none; -ms-overflow-style: none; -webkit-overflow-scrolling: touch; }
.boaz-enterprise-table__viewport::-webkit-scrollbar { width: 0; height: 0; }
.boaz-enterprise-table__viewport:focus-visible { outline: 3px solid var(--boaz-focus-ring, rgba(230, 126, 34, .45)); outline-offset: -3px; }
[data-bs-theme="dark"] .boaz-enterprise-table__viewport:focus-visible, .dark-mode .boaz-enterprise-table__viewport:focus-visible { outline-color: var(--boaz-focus-ring-dark, rgba(255, 172, 79, .72)); }

.boaz-enterprise-table__column-placeholder {
    align-items: center;
    display: inline-flex;
    flex: 0 0 auto;
    font-size: .78rem;
    font-weight: 700;
    gap: .35rem;
    min-height: 2rem;
    padding-inline: .65rem;
    white-space: nowrap;
}

/* Compact, formal display controls shared by Products and every listing table. */
.boaz-enterprise-table__toolbar { gap: .5rem; padding: .55rem .75rem; }
.boaz-enterprise-table__toolbar-start,
.boaz-enterprise-table__actions,
.boaz-enterprise-table__actions--display { gap: .5rem; }
.boaz-enterprise-table__column-trigger { font-size: .78rem; min-height: 2rem; padding-inline: .65rem; }
.boaz-enterprise-table__rows { gap: .35rem; }
.boaz-enterprise-table__rows label { font-size: .75rem; }
.boaz-enterprise-table__rows select { min-height: 2rem; min-width: 3.75rem; padding-block: .2rem; padding-inline: .5rem 1.75rem; }

/* Compact mobile listing chrome follows the proven Proforma Details table:
   display controls stay together at the right edge and dense tables spend
   space on data rather than oversized toolbar or row padding. Opt-in keeps
   unrelated operational tables on their established responsive treatment. */
.boaz-compact-mobile-table .boaz-enterprise-table__toolbar {
    justify-content: flex-end;
}

.boaz-compact-mobile-table .boaz-enterprise-table__actions,
.boaz-compact-mobile-table .boaz-enterprise-table__actions--display {
    justify-content: flex-end;
    margin-left: auto;
}

@media (max-width: 575.98px) {
    .boaz-compact-mobile-table .boaz-enterprise-table__toolbar {
        align-items: flex-end;
        padding: .32rem .5rem;
    }

    .boaz-compact-mobile-table .boaz-enterprise-table__toolbar-start {
        display: none;
    }

    .boaz-compact-mobile-table .boaz-enterprise-table__actions,
    .boaz-compact-mobile-table .boaz-enterprise-table__actions--display {
        justify-content: flex-end;
        margin-left: auto;
        width: auto;
    }

    .boaz-compact-mobile-table .boaz-enterprise-table__column-panel {
        left: auto;
        right: 0;
    }

    .boaz-compact-mobile-table .boaz-enterprise-table__column-trigger,
    .boaz-compact-mobile-table .boaz-enterprise-table__rows,
    .boaz-compact-mobile-table .boaz-enterprise-table__rows select {
        min-height: 2rem;
        font-size: .7rem;
    }

    .boaz-compact-mobile-table .boaz-table {
        min-width: 100% !important;
        font-size: .75rem;
    }

    .boaz-compact-mobile-table .boaz-table--comfortable thead th,
    .boaz-compact-mobile-table .boaz-table--comfortable tbody td {
        padding-top: .32rem;
        padding-bottom: .32rem;
    }
}
