/*
 * Shared dense-table contract.
 *
 * Module styles may describe the meaning of individual columns, but table
 * density and desktop overflow belong here.  Keeping these rules last in the
 * stylesheet stack prevents individual pages from drifting back to oversized
 * 1600-2100px tables.
 */

.table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
}

.table-wrap:focus-visible {
    outline: 3px solid rgba(11, 107, 79, 0.2);
    outline-offset: -3px;
    border-radius: 8px;
}

.data-table {
    width: 100%;
    min-width: 100%;
    font-size: 13px;
}

.data-table th,
.data-table td {
    height: 36px;
    padding: 6px 8px;
    line-height: 1.3;
    vertical-align: middle;
}

.data-table th {
    font-size: 12px;
    letter-spacing: 0;
}

.data-table td {
    max-width: 220px;
}

/* Every empty table uses the same centered state.  Templates historically
 * mixed plain colspan cells with module-specific empty-state wrappers, which
 * made some empty lists look like ordinary data rows. */
.data-table tbody > tr > td[colspan]:only-child {
    height: 88px;
    max-width: none;
    padding: 22px 16px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 800;
    text-align: center;
    white-space: normal;
}

.data-table tbody > tr > td[colspan]:only-child > :is(.empty-state, .erp-empty, .srm-empty) {
    display: flex;
    min-height: 0;
    margin: 0;
    padding: 0;
    align-items: center;
    justify-content: center;
    gap: 0;
    color: var(--muted);
    background: transparent;
    border: 0;
    border-radius: 0;
    text-align: center;
}

.data-table tbody > tr > td[colspan]:only-child > :is(.empty-state, .erp-empty, .srm-empty) :is(h2, strong) {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
    font-weight: 800;
}

.data-table tbody > tr > td[colspan]:only-child > .empty-state p,
.data-table tbody > tr > td[colspan]:only-child > :is(.erp-empty, .srm-empty) span {
    display: none;
}

/* A wide table should be wider than its container only when its column count
 * actually requires it.  The old global 2100px minimum caused empty space and
 * hid half of ordinary approval/order rows on a desktop viewport. */
.data-table-wide {
    min-width: 1180px;
    table-layout: fixed;
}

.data-table-wide:has(thead th:nth-child(12)) {
    min-width: 1280px;
}

.data-table-wide:has(thead th:nth-child(15)) {
    min-width: 1420px;
}

.data-table-wide th,
.data-table-wide td {
    overflow: hidden;
    text-overflow: ellipsis;
}

.surface-header {
    padding: var(--ui-panel-head-padding);
}

.surface-header h2 {
    font-size: 17px;
}

.surface-header p {
    margin-top: 3px;
    line-height: 1.4;
}

.pagination-bar {
    gap: 10px;
    padding: 10px 14px 12px;
}

.data-table button,
.data-table .primary-action,
.data-table .secondary-action,
.data-table .approval-open-button,
.data-table .approval-flow-button {
    min-height: 30px;
    padding-inline: 9px;
    font-size: 12px;
}

/* OA approvals: keep the complete approval row visible at common desktop
 * widths.  Long business names truncate; the modal remains the detail view. */
.quotation-approval-table {
    min-width: 100%;
    table-layout: fixed;
}

.quotation-approval-table th:nth-child(1) { width: 19%; }
.quotation-approval-table th:nth-child(2) { width: 20%; }
.quotation-approval-table th:nth-child(3) { width: 12%; }
.quotation-approval-table th:nth-child(4) { width: 14%; }
.quotation-approval-table th:nth-child(5) { width: 15%; }
.quotation-approval-table th:nth-child(6) { width: 20%; }

.quotation-approval-table .approval-list-stack {
    display: grid;
    min-width: 0;
    gap: 2px;
}

.quotation-approval-table .approval-list-stack strong,
.quotation-approval-table .approval-list-stack small {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.quotation-approval-table .approval-list-stack small {
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
}

.quotation-approval-table .approval-list-stack.is-numeric strong,
.quotation-approval-table .approval-list-stack.is-numeric small {
    font-variant-numeric: tabular-nums;
}

.quotation-approval-table .approval-row-actions {
    min-width: 0;
    flex-wrap: nowrap;
    gap: 4px;
}

/* CRM lists */
.public-customer-table { min-width: 820px; }
.team-customer-table { min-width: 900px; }
.opportunity-table { min-width: 1120px; }
.followup-history-table { min-width: 980px; }
.contract-list-table {
    min-width: 100%;
    table-layout: fixed;
}

.contract-list-table th:nth-child(1) { width: 17%; }
.contract-list-table th:nth-child(2) { width: 22%; }
.contract-list-table th:nth-child(3) { width: 18%; }
.contract-list-table th:nth-child(4) { width: 14%; }
.contract-list-table th:nth-child(5) { width: 12%; }
.contract-list-table th:nth-child(6) { width: 17%; }

.contract-list-table .contract-list-stack {
    display: grid;
    min-width: 0;
    gap: 2px;
}

.contract-list-table .contract-list-stack strong,
.contract-list-table .contract-list-stack small {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.contract-list-table .contract-list-stack small {
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
}

.contract-list-table .contract-list-numeric small {
    font-variant-numeric: tabular-nums;
}
.crm-orders-table {
    min-width: 100%;
    table-layout: fixed;
}

.crm-orders-table th:nth-child(1) { width: 16%; }
.crm-orders-table th:nth-child(2) { width: 19%; }
.crm-orders-table th:nth-child(3) { width: 20%; }
.crm-orders-table th:nth-child(4) { width: 11%; }
.crm-orders-table th:nth-child(5) { width: 10%; }
.crm-orders-table th:nth-child(6) { width: 24%; }

.crm-orders-table .order-list-stack {
    display: grid;
    min-width: 0;
    gap: 2px;
}

.crm-orders-table .order-list-stack strong,
.crm-orders-table .order-list-stack small {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.crm-orders-table .order-list-stack small {
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
}

.crm-orders-table .order-list-numeric strong,
.crm-orders-table .order-list-numeric small {
    font-variant-numeric: tabular-nums;
}

.crm-orders-table .crm-order-action-cell {
    max-width: none;
    overflow: visible;
}

.crm-orders-table .crm-order-action-cell .workflow-action-stack {
    min-width: 0;
    flex-wrap: nowrap;
}

.crm-shipping-task-table {
    min-width: 100%;
    table-layout: fixed;
}

.crm-shipping-task-table th:nth-child(1) { width: 14%; }
.crm-shipping-task-table th:nth-child(2) { width: 15%; }
.crm-shipping-task-table th:nth-child(3) { width: 15%; }
.crm-shipping-task-table th:nth-child(4) { width: 18%; }
.crm-shipping-task-table th:nth-child(5) { width: 18%; }
.crm-shipping-task-table th:nth-child(6) { width: 12%; }
.crm-shipping-task-table th:nth-child(7) { width: 8%; }

.crm-shipping-task-table .shipping-task-stack,
.crm-shipping-task-table .shipping-task-products {
    display: grid;
    min-width: 0;
    gap: 2px;
}

.crm-shipping-task-table .shipping-task-stack strong,
.crm-shipping-task-table .shipping-task-stack small,
.crm-shipping-task-table .shipping-task-products strong,
.crm-shipping-task-table .shipping-task-products small {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.crm-shipping-task-table small {
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
}

/* Keep table-cell layout intact.  Turning a <td> into a flex container makes
 * its content escape the table row's height calculation, which caused action
 * buttons to overlap the following row.  Buttons remain intact and wrap only
 * between controls inside this compact action lane. */
.data-table td.public-action-cell,
.data-table td.workflow-action-stack {
    display: table-cell;
    height: auto;
    overflow: visible;
    vertical-align: middle;
    white-space: normal;
}

.data-table td.public-action-cell {
    width: 190px;
    min-width: 190px;
    max-width: 190px;
}

.data-table td.workflow-action-stack {
    width: 150px;
    min-width: 150px;
    max-width: 170px;
}

.data-table td.public-action-cell > button,
.data-table td.public-action-cell > a,
.data-table td.public-action-cell > form,
.data-table td.public-action-cell > .crm-status-pill,
.data-table td.workflow-action-stack > button,
.data-table td.workflow-action-stack > a,
.data-table td.workflow-action-stack > form,
.data-table td.workflow-action-stack > .crm-status-pill {
    display: inline-flex;
    align-items: center;
    margin: 2px 4px 2px 0;
    vertical-align: middle;
}

.data-table td.public-action-cell button,
.data-table td.workflow-action-stack button {
    min-height: 30px;
    padding-inline: 8px;
    white-space: nowrap;
}

/* Opportunity actions are a single workflow lane.  Keep the table cell itself
 * in table layout, then use an inner flex row so generic action-cell sizing
 * cannot stack the controls or make them overlap adjacent rows. */
.data-table.opportunity-table th:last-child,
.data-table.opportunity-table td.opportunity-action-cell {
    width: 262px;
    min-width: 262px;
    max-width: none;
}

.opportunity-action-row {
    display: inline-flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 6px;
    width: max-content;
    white-space: nowrap;
}

.opportunity-action-row > a,
.opportunity-action-row > button,
.opportunity-action-row > .crm-status-pill {
    flex: 0 0 auto;
    margin: 0;
}

.my-opportunity-summary-table {
    min-width: 100%;
    table-layout: fixed;
}

.my-opportunity-summary-table th:nth-child(1) { width: 5%; }
.my-opportunity-summary-table th:nth-child(2) { width: 15%; }
.my-opportunity-summary-table th:nth-child(3) { width: 15%; }
.my-opportunity-summary-table th:nth-child(4) { width: 14%; }
.my-opportunity-summary-table th:nth-child(5) { width: 16%; }
.my-opportunity-summary-table th:nth-child(6) { width: 7%; }
.my-opportunity-summary-table th:nth-child(7) { width: 28%; }

.my-opportunity-summary-table .my-opportunity-stack {
    display: grid;
    min-width: 0;
    gap: 2px;
}

.my-opportunity-summary-table .my-opportunity-stack strong,
.my-opportunity-summary-table .my-opportunity-stack small {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.my-opportunity-summary-table .my-opportunity-stack small {
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
}

.my-opportunity-summary-table .my-opportunity-numeric strong,
.my-opportunity-summary-table .my-opportunity-numeric small {
    font-variant-numeric: tabular-nums;
}

.data-table.my-opportunity-summary-table th:last-child,
.data-table.my-opportunity-summary-table td.opportunity-action-cell {
    width: 28%;
    min-width: 0;
}

.my-opportunity-summary-table .opportunity-action-row {
    width: 100%;
    justify-content: flex-start;
}

.my-opportunity-summary-table .opportunity-action-row > a,
.my-opportunity-summary-table .opportunity-action-row > button {
    min-height: 30px;
    padding-inline: 7px;
    font-size: 12px;
}

.team-opportunity-summary-table {
    min-width: 100%;
    table-layout: fixed;
}

.team-opportunity-summary-table th:nth-child(1) { width: 5%; }
.team-opportunity-summary-table th:nth-child(2) { width: 15%; }
.team-opportunity-summary-table th:nth-child(3) { width: 16%; }
.team-opportunity-summary-table th:nth-child(4) { width: 16%; }
.team-opportunity-summary-table th:nth-child(5) { width: 11%; }
.team-opportunity-summary-table th:nth-child(6) { width: 13%; }
.team-opportunity-summary-table th:nth-child(7) { width: 12%; }
.team-opportunity-summary-table th:nth-child(8) { width: 12%; }

.team-opportunity-summary-table .team-opportunity-stack {
    display: grid;
    min-width: 0;
    gap: 2px;
}

.team-opportunity-summary-table .team-opportunity-stack strong,
.team-opportunity-summary-table .team-opportunity-stack small {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.team-opportunity-summary-table .team-opportunity-stack small {
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
}

.team-opportunity-summary-table .team-opportunity-numeric strong,
.team-opportunity-summary-table .team-opportunity-numeric small {
    font-variant-numeric: tabular-nums;
}

.team-opportunity-summary-table .team-opportunity-action-cell {
    text-align: center;
    white-space: nowrap;
}

.team-opportunity-summary-table .team-opportunity-action-cell .workflow-inline-action {
    max-width: 100%;
    margin: 0;
    padding-inline: 6px;
}

.public-customer-table .table-fill-cell,
.my-customer-table .table-fill-cell {
    width: 140px;
    min-width: 140px;
    max-width: 180px;
}

.sticky-customer-table .sticky-serial {
    width: 52px;
    min-width: 52px;
    max-width: 52px;
}

.sticky-customer-table .sticky-customer-name {
    left: 52px;
    width: 180px;
    min-width: 180px;
    max-width: 180px;
}

/* ERP and system administration lists */
.erp-table { min-width: 960px; }
.erp-order-table {
    min-width: 100%;
    table-layout: fixed;
}
.erp-order-table th:nth-child(1) { width: 6%; }
.erp-order-table th:nth-child(2) { width: 18%; }
.erp-order-table th:nth-child(3) { width: 18%; }
.erp-order-table th:nth-child(4) { width: 14%; }
.erp-order-table th:nth-child(5) { width: 14%; }
.erp-order-table th:nth-child(6) { width: 15%; }
.erp-order-table th:nth-child(7) { width: 15%; }

.erp-order-table .erp-stack,
.erp-order-table .erp-primary-cell {
    min-width: 0;
}

.erp-order-table .erp-stack strong,
.erp-order-table .erp-stack small,
.erp-order-table .erp-primary-cell strong,
.erp-order-table .erp-primary-cell span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.erp-order-table .erp-order-numeric strong,
.erp-order-table .erp-order-numeric small {
    font-variant-numeric: tabular-nums;
}
.erp-shipping-history-table { min-width: 960px; }
.erp-order-item-table { min-width: 1040px; }
.system-user-table { min-width: 1080px; }

/* Finance actions must stay reachable while the reconciliation data scrolls.
 * Scope this to opt-in tables so ordinary list columns keep their natural
 * position and empty-state colspan rows are never pinned. */
.sticky-action-table th:last-child,
.sticky-action-table td:last-child:not([colspan]) {
    position: sticky;
    right: 0;
    z-index: 2;
    background: #fff;
    box-shadow: -8px 0 12px -12px rgba(0, 54, 39, 0.45);
}

.sticky-action-table thead th:last-child {
    z-index: 3;
    background: #f3f8f5;
}

@media (min-width: 1280px) {
    .quotation-approval-table,
    .public-customer-table,
    .opportunity-table,
    .quotation-requirement-table,
    .crm-orders-table,
    .erp-table,
    .system-user-table {
        min-width: 100%;
    }

    .team-customer-table {
        min-width: 100%;
        table-layout: fixed;
    }

    .team-customer-table.has-actions th:nth-child(1) { width: 8%; }
    .team-customer-table.has-actions th:nth-child(2) { width: 17%; }
    .team-customer-table.has-actions th:nth-child(3) { width: 10%; }
    .team-customer-table.has-actions th:nth-child(4) { width: 13%; }
    .team-customer-table.has-actions th:nth-child(5) { width: 10%; }
    .team-customer-table.has-actions th:nth-child(6) { width: 7%; }
    .team-customer-table.has-actions th:nth-child(7) { width: 11%; }
    .team-customer-table.has-actions th:nth-child(8) { width: 24%; }

    .team-customer-table.has-actions td.public-action-cell {
        width: auto;
        min-width: 0;
        max-width: none;
        white-space: nowrap;
    }
}

@media (max-width: 720px) {
    .data-table th,
    .data-table td {
        height: 34px;
        padding: 5px 7px;
    }

    .surface-header {
        padding: 12px 14px;
    }

    .pagination-bar {
        padding: 9px 12px 11px;
    }

    .quotation-approval-table {
        min-width: 720px;
    }

    .quotation-requirement-table {
        min-width: 820px;
    }

    .team-opportunity-summary-table {
        min-width: 820px;
    }

    .my-opportunity-summary-table {
        min-width: 760px;
    }

    .my-customer-summary-table {
        min-width: 900px;
    }

    .contract-list-table {
        min-width: 760px;
    }

    .crm-orders-table {
        min-width: 760px;
    }

    .crm-shipping-task-table {
        min-width: 940px;
    }

    .erp-order-table {
        min-width: 820px;
    }
}
