/* ==========================================================================
   sx-table: Sproutt data table (pilot: parts-list costing preview)
   Opt-in only. Add `.sx-table` to a <table> and `.sx-scroll` to its scroll
   container. Nothing here changes Bootstrap's global `.table`.
   See docs/ui-cleanup-guidance.md, section "Data tables (sx-table)".
   ========================================================================== */

.sx-scroll {
    --sx-ink: #1d2939;
    --sx-text: #344054;
    --sx-muted: #667085;
    --sx-faint: #98a2b3;
    --sx-line: #eaecf0;
    --sx-line-soft: #f2f4f7;
    --sx-line-strong: #d0d5dd;
    --sx-surface: #ffffff;
    --sx-head-bg: #f9fafb;
    --sx-hover: #f3f7fc;
    --sx-focus: #2e6db4;
    --sx-focus-ring: rgba(46, 109, 180, 0.16);
    --sx-dirty: #fffaeb;
    --sx-dirty-hover: #fef3d4;
    --sx-dirty-rail: #f0a92b;
    /* No `position` here: Select2 dropdowns parented to the scroller rely on
       it staying static so they are positioned against the card instead. */
    overflow: auto;
    background: var(--sx-surface);
    scrollbar-width: thin;
    scrollbar-color: #c4cbd6 transparent;
}

.sx-table {
    width: 100%;
    margin: 0 !important;
    border-collapse: separate !important;
    border-spacing: 0;
    font: 400 var(--sx-body-size, 13px)/1.45 Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
    color: var(--sx-text);
    font-variant-numeric: tabular-nums;
}

/* ---- Header ------------------------------------------------------------ */
.sx-table > thead > tr > th {
    position: sticky !important;
    top: 0 !important;
    z-index: 3;
    padding: 10px 12px !important;
    background: var(--sx-head-bg) !important;
    background-clip: padding-box;
    border: 0 !important;
    border-bottom: 1px solid var(--sx-line-strong) !important;
    box-shadow: var(--sx-cell-shadow, none) !important;
    color: var(--sx-muted) !important;
    font: 600 var(--sx-header-size, 11px)/1.4 Inter, system-ui, sans-serif !important;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
    vertical-align: middle;
}

.sx-table > thead { z-index: 5 !important; }

.sx-table > thead > tr > th :is(button, a) {
    font: inherit !important;
    letter-spacing: inherit;
    text-transform: inherit;
    color: inherit !important;
}

.sx-table > thead > tr > th :is(button, a):hover { color: var(--sx-ink) !important; }

/* ---- Body cells -------------------------------------------------------- */
/* Cells paint from row-level variables so every state has one source of
   truth and legacy row/cell colours (has-cost, editable-cell:hover,
   Bootstrap hover overlays) cannot mask it. */
.sx-table > tbody > tr {
    --sx-cell-bg: var(--sx-surface);
    background: transparent !important;
    border: 0 !important;
}

.sx-table > tbody > tr > td {
    padding: 6px 12px !important;
    background-color: var(--sx-cell-bg) !important;
    border: 0 !important;
    border-bottom: 1px solid var(--sx-line) !important;
    box-shadow: var(--sx-cell-shadow, none) !important;
    color: var(--sx-text);
    vertical-align: middle;
    transition: background-color 0.12s ease;
}

.sx-table > tbody > tr:last-child > td { border-bottom-color: transparent !important; }

.sx-table .sx-num { text-align: right; font-variant-numeric: tabular-nums; }
.sx-table .sx-center { text-align: center; }
.sx-table .sx-nowrap { white-space: nowrap; }
.sx-table .sx-strong { color: var(--sx-ink); font-weight: 600; }
.sx-table .sx-subtle { color: var(--sx-muted); font-size: var(--sx-secondary-size, 12px); }

/* ---- Row states: base < hover/focus < unsaved ---------------------------- */
.sx-table > tbody > tr:is(:hover, :focus-within) { --sx-cell-bg: var(--sx-hover); }
.sx-table > tbody > tr.is-dirty,
.sx-table > tbody > tr.row-modified { --sx-cell-bg: var(--sx-dirty); }
.sx-table > tbody > tr:is(.is-dirty, .row-modified):is(:hover, :focus-within) { --sx-cell-bg: var(--sx-dirty-hover); }

/* ---- Grouped rows (parent line + price breaks / sub-lines) --------------- */
/* Rows inside one group share a soft divider; the group itself gets a quiet
   rail. Works with existing `group-line-parent` / `group-line-child`
   classes or the generic `sx-group-parent` / `sx-group-child`. */
.sx-table > tbody > tr:has(+ tr:is(.group-line-child, .sx-group-child)) > td {
    border-bottom-color: var(--sx-line-soft) !important;
}
.sx-table > tbody > tr:is(.group-line-child, .sx-group-child) > td:first-child,
.sx-table > tbody > tr:is(.group-line-parent, .sx-group-parent):has(+ tr:is(.group-line-child, .sx-group-child)) > td:first-child {
    --sx-cell-shadow: inset 2px 0 0 #c7d3e2;
}
.sx-table > tbody > tr:is(.group-line-child, .sx-group-child) > td:first-child {
    position: relative;
    padding-left: 26px !important;
    color: var(--sx-faint) !important;
}
.sx-table > tbody > tr:is(.group-line-child, .sx-group-child) > td:first-child::before {
    content: '';
    position: absolute;
    left: 12px;
    top: 0;
    width: 8px;
    height: 50%;
    border-left: 1px solid #c7d3e2;
    border-bottom: 1px solid #c7d3e2;
    border-bottom-left-radius: 4px;
    color: transparent;
}

/* Unsaved rail wins over the group rail. */
.sx-table > tbody > tr:is(.is-dirty, .row-modified) > td:first-child {
    --sx-cell-shadow: inset 3px 0 0 var(--sx-dirty-rail) !important;
}

/* ---- Inline edit controls: quiet at rest, clear on hover/focus ------------ */
.sx-table :is(.form-control, .form-select),
.sx-table .select2-container--default .select2-selection--single {
    height: var(--sx-control-height, 30px);
    min-height: var(--sx-control-height, 30px) !important;
    padding: 4px 8px !important;
    font: 400 var(--sx-body-size, 13px)/var(--sx-control-line-height, 20px) Inter, system-ui, sans-serif !important;
    color: var(--sx-ink) !important;
    background-color: transparent;
    border: 1px solid transparent !important;
    border-radius: 6px !important;
    box-shadow: none !important;
    transition: border-color 0.12s ease, background-color 0.12s ease, box-shadow 0.12s ease;
}
.sx-table .form-select {
    padding-right: 24px !important;
    background-position: right 6px center;
    background-size: 12px 10px;
}
/* Empty editable fields keep a faint well so blanks read as "to do". */
.sx-table .form-control:placeholder-shown { background-color: #f6f7f9; }
.sx-table > tbody > tr:is(:hover, :focus-within) :is(.form-control, .form-select),
.sx-table > tbody > tr:is(:hover, :focus-within) .select2-selection--single {
    background-color: #fff;
    border-color: var(--sx-line-strong) !important;
}
.sx-table :is(.form-control, .form-select):focus,
.sx-table .select2-container--open .select2-selection--single,
.sx-table .select2-container--focus .select2-selection--single {
    background-color: #fff !important;
    border-color: var(--sx-focus) !important;
    box-shadow: 0 0 0 3px var(--sx-focus-ring) !important;
    outline: 0;
}
.sx-table .form-control::placeholder { color: var(--sx-faint); font-style: normal; font-size: var(--sx-secondary-size, 12px); }
.sx-table input[type="number"] { -moz-appearance: textfield; appearance: textfield; text-align: right; }
.sx-table input[type="number"]::-webkit-inner-spin-button,
.sx-table input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* Select2 inside rows */
.sx-table .select2-container { min-width: 0; }
.sx-table .select2-selection__rendered {
    padding: 0 18px 0 0 !important;
    line-height: var(--sx-control-line-height, 20px) !important;
    color: var(--sx-ink) !important;
}
.sx-table .select2-selection__placeholder { color: var(--sx-faint) !important; font-size: var(--sx-secondary-size, 12px); }
.sx-table .select2-selection__arrow { height: var(--sx-icon-button-size, 28px) !important; right: 4px !important; opacity: 0.55; }
.sx-table .select2-selection__clear { color: var(--sx-faint); margin-right: 4px; font-weight: 400; }

/* ---- Pills: bootstrap badges inside an sx-table become tinted pills ----- */
.sx-table .badge,
.sx-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px !important;
    margin: 0 !important;
    border: 0 !important;
    border-radius: 999px !important;
    font: 500 var(--sx-badge-size, 11.5px)/18px Inter, system-ui, sans-serif !important;
    letter-spacing: 0;
    white-space: nowrap;
    background: #f2f4f7 !important;
    color: #475467 !important;
}
.sx-table .badge.bg-success, .sx-pill--ok { background: #ecfdf3 !important; color: var(--control-ink, #202c3c) !important; }
.sx-table .badge.bg-warning, .sx-pill--warn { background: #fffaeb !important; color: #b54708 !important; }
.sx-table .badge.bg-danger, .sx-pill--danger { background: #fef3f2 !important; color: #b42318 !important; }
.sx-table .badge:is(.bg-primary, .bg-info, .bg-primary-subtle), .sx-pill--info { background: #eff4fb !important; color: #2e5f99 !important; }

/* Interactive pill (e.g. Bid / No Bid toggle) */
.sx-table .sx-pill-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 2px 10px 2px 8px !important;
    border: 1px solid var(--sx-line) !important;
    border-radius: 999px !important;
    background: #fff !important;
    color: #475467 !important;
    font: 500 var(--sx-secondary-size, 12px)/var(--sx-control-line-height, 20px) Inter, system-ui, sans-serif !important;
    box-shadow: none !important;
}
.sx-table .sx-pill-btn::before {
    content: ''; width: 6px; height: 6px; border-radius: 50%; background: #98a2b3;
}
.sx-table .sx-pill-btn:hover { border-color: var(--sx-line-strong) !important; color: var(--sx-ink) !important; }
.sx-table .sx-pill-btn.status-no-bid { background: #fef3f2 !important; border-color: #fecdca !important; color: #b42318 !important; }
.sx-table .sx-pill-btn.status-no-bid::before { background: #f04438; }

/* ---- Icon actions -------------------------------------------------------- */
.sx-table .sx-icon-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 4px;
    min-width: var(--sx-icon-button-size, 28px); height: var(--sx-icon-button-size, 28px);
    padding: 0 6px !important;
    border: 0 !important;
    border-radius: 6px !important;
    background: transparent !important;
    color: var(--sx-faint) !important;
    box-shadow: none !important;
    font: 500 var(--sx-secondary-size, 12px)/1 Inter, system-ui, sans-serif !important;
    transition: background-color 0.12s ease, color 0.12s ease;
}
.sx-table .sx-icon-btn i { font-size: var(--sx-icon-size, 15px); line-height: 1; }
.sx-table > tbody > tr:is(:hover, :focus-within) .sx-icon-btn { color: var(--sx-muted) !important; }
.sx-table .sx-icon-btn:hover,
.sx-table .sx-icon-btn[aria-expanded="true"] { background: #e9eef5 !important; color: var(--sx-ink) !important; }
.sx-table .sx-icon-btn:disabled { opacity: 0.5; }

/* Reveal-on-hover helpers (still visible to keyboard focus) */
.sx-table .sx-reveal { opacity: 0; transition: opacity 0.12s ease; }
.sx-table > tbody > tr:is(:hover, :focus-within) .sx-reveal,
.sx-table .sx-reveal:focus-visible { opacity: 1; }
@media (hover: none) { .sx-table .sx-reveal { opacity: 1; } }

/* Row overflow menu */
.sx-row-menu .dropdown-menu {
    min-width: 200px;
    padding: 6px;
    border: 1px solid var(--sx-line, #eaecf0);
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(16, 24, 40, 0.12), 0 2px 6px rgba(16, 24, 40, 0.06);
    font: 400 var(--sx-body-size, 13px)/1.4 Inter, system-ui, sans-serif;
}
.sx-row-menu .dropdown-item {
    display: flex !important; align-items: center; gap: 10px;
    width: 100%;
    padding: 8px 10px !important;
    border: 0 !important; border-radius: 6px;
    background: transparent !important;
    color: #344054 !important;
    font: inherit !important;
    text-align: left;
    box-shadow: none !important;
}
.sx-row-menu .dropdown-item i { width: 16px; color: #667085; font-size: 14px; }
.sx-row-menu .dropdown-item:hover,
.sx-row-menu .dropdown-item:focus { background: #f2f4f7 !important; }
.sx-row-menu .dropdown-item.text-danger,
.sx-row-menu .dropdown-item.text-danger i { color: #b42318 !important; }
.sx-row-menu .dropdown-item.text-danger:hover { background: #fef3f2 !important; }
.sx-row-menu .dropdown-divider { margin: 4px 2px; border-color: #f2f4f7; }

/* ---- Pinned columns ------------------------------------------------------ */
.sx-table :is(th, td).sx-pin-start,
.sx-table :is(th, td).sx-pin-end { position: sticky !important; z-index: 2; }
.sx-table > thead > tr > th:is(.sx-pin-start, .sx-pin-end) { z-index: 4; }
/* An open row menu must sit above later pinned rows and the sticky header. */
.sx-table > tbody > tr.sx-menu-open > td:is(.sx-pin-start, .sx-pin-end) { z-index: 6; }
.sx-table :is(th, td).sx-pin-end { right: 0; }
/* Edge shadows only appear once content is scrolled underneath. */
.sx-scroll.is-scrolled-x .sx-table :is(th, td).sx-pin-start.sx-pin-edge {
    --sx-cell-shadow: inset -1px 0 0 var(--sx-line), 6px 0 8px -6px rgba(16, 24, 40, 0.12);
}
.sx-scroll.has-more-x .sx-table :is(th, td).sx-pin-end {
    --sx-cell-shadow: inset 1px 0 0 var(--sx-line), -6px 0 8px -6px rgba(16, 24, 40, 0.12);
}
/* Keep the unsaved rail when the first pinned cell also casts an edge shadow. */
.sx-scroll.is-scrolled-x .sx-table > tbody > tr:is(.is-dirty, .row-modified) > td.sx-pin-start.sx-pin-edge:first-child {
    --sx-cell-shadow: inset 3px 0 0 var(--sx-dirty-rail), 6px 0 8px -6px rgba(16, 24, 40, 0.12) !important;
}

/* ---- Accessibility ------------------------------------------------------- */
.sx-table :is(a, button, input, select, textarea):focus-visible { outline: 2px solid var(--sx-focus); outline-offset: 1px; }
.sx-table .sx-icon-btn:focus-visible { outline-offset: 0; }
@media (prefers-reduced-motion: reduce) {
    .sx-table *, .sx-table > tbody > tr > td { transition: none !important; animation: none !important; }
}

/* Narrow screens: keep pinned identity column but drop pin-end so the
   action column scrolls naturally rather than covering content. */
@media (max-width: 1100px) {
    .sx-table :is(th, td).sx-pin-end { position: static !important; }
}
