/**
 * 全局表格样式
 * - 宽度 100%，自动列宽（按内容伸缩，不写死宽度）
 * - 单元格 max-width 上限，短内容列自动收窄
 * - 默认单行高度，超出显示省略号
 * - 内容单元格悬停可复制；表头标题行不出现复制按钮
 * - .table-no-ellipsis：关闭省略号/自动列宽，仍支持悬停复制
 * 排除省略布局：.table-no-ellipsis / .table-layout-fixed / .table-cell-wrap / .table-cell-actions
 */

:root {
    --table-row-height: 40px;
    --table-cell-max-width: 240px;
    --table-cell-max-width-narrow: 88px;
    --table-cell-max-width-medium: 160px;
    --table-cell-max-width-wide: 360px;
}

/* 默认：自动列宽，内容决定宽度，max-width 封顶 */
table:not(.table-no-ellipsis):not(.table-layout-fixed):not(.cancelled-table):not(.picking-table) {
    width: 100%;
    table-layout: auto;
}

/* 可选：固定布局（宽表、需精确列宽时使用） */
table.table-layout-fixed:not(.table-no-ellipsis) {
    width: 100%;
    table-layout: fixed;
}

table:not(.table-no-ellipsis):not(.table-layout-fixed):not(.cancelled-table):not(.picking-table) thead tr,
table:not(.table-no-ellipsis):not(.table-layout-fixed):not(.cancelled-table):not(.picking-table) tbody tr,
table.table-layout-fixed:not(.table-no-ellipsis) thead tr,
table.table-layout-fixed:not(.table-no-ellipsis) tbody tr {
    height: var(--table-row-height);
}

/* 自动列宽：width:1% 让列尽量收窄，max-width 限制上限，内容短时列窄、长时截断 */
table:not(.table-no-ellipsis):not(.table-layout-fixed):not(.cancelled-table):not(.picking-table) th,
table:not(.table-no-ellipsis):not(.table-layout-fixed):not(.cancelled-table):not(.picking-table) td {
    height: var(--table-row-height);
    max-height: var(--table-row-height);
    padding: 0 12px;
    vertical-align: middle;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 1%;
    max-width: var(--table-cell-max-width);
    line-height: var(--table-row-height);
}

/* 固定布局列：均分剩余空间 */
table.table-layout-fixed:not(.table-no-ellipsis) th,
table.table-layout-fixed:not(.table-no-ellipsis) td {
    height: var(--table-row-height);
    max-height: var(--table-row-height);
    padding: 0 12px;
    vertical-align: middle;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 0;
    line-height: var(--table-row-height);
}

/* 列宽档位：仅设 max-width，不写死 width */
table:not(.table-no-ellipsis) th.table-col-narrow,
table:not(.table-no-ellipsis) td.table-col-narrow {
    max-width: var(--table-cell-max-width-narrow);
}

table:not(.table-no-ellipsis) th.table-col-medium,
table:not(.table-no-ellipsis) td.table-col-medium {
    max-width: var(--table-cell-max-width-medium);
}

table:not(.table-no-ellipsis) th.table-col-wide,
table:not(.table-no-ellipsis) td.table-col-wide {
    max-width: var(--table-cell-max-width-wide);
}

/* 单元格内文本包裹层，配合自动列宽 ellipsis */
.table-cell-text {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}

/* 交互列 / 操作列：不参与收窄，按内容自然宽度 */
table:not(.table-no-ellipsis) th.table-cell-wrap,
table:not(.table-no-ellipsis) td.table-cell-wrap,
table:not(.table-no-ellipsis) th.table-cell-actions,
table:not(.table-no-ellipsis) td.table-cell-actions,
table:not(.table-no-ellipsis) th.table-col-fit,
table:not(.table-no-ellipsis) td.table-col-fit,
table:not(.table-no-ellipsis) th:has(> a),
table:not(.table-no-ellipsis) td:has(> a),
table:not(.table-no-ellipsis) th:has(> input:not([type="hidden"])),
table:not(.table-no-ellipsis) td:has(> input:not([type="hidden"])),
table:not(.table-no-ellipsis) th:has(> select),
table:not(.table-no-ellipsis) td:has(> select),
table:not(.table-no-ellipsis) th:has(> textarea),
table:not(.table-no-ellipsis) td:has(> textarea),
table:not(.table-no-ellipsis) th:has(> button),
table:not(.table-no-ellipsis) td:has(> button),
table:not(.table-no-ellipsis) th:has(> .btn),
table:not(.table-no-ellipsis) td:has(> .btn),
table:not(.table-no-ellipsis) th:has(> .btn-group),
table:not(.table-no-ellipsis) td:has(> .btn-group),
table:not(.table-no-ellipsis) th:has(> img),
table:not(.table-no-ellipsis) td:has(> img),
table:not(.table-no-ellipsis) th:has(input[type="checkbox"]),
table:not(.table-no-ellipsis) td:has(input[type="checkbox"]) {
    width: auto;
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
    max-width: none;
    line-height: normal;
}

/* 仅内容单元格（td）可悬停复制，表头 th 不展示复制交互
 * table-no-ellipsis 仅关闭省略布局，仍支持复制 */
td.table-ellipsis-hover {
    cursor: pointer;
}

td.table-ellipsis-hover:hover {
    color: #1890ff;
}

#tableCellPopover {
    display: none;
    position: fixed;
    z-index: 10050;
    max-width: 480px;
    min-width: 120px;
    padding: 10px 12px;
    background: #fff;
    border: 1px solid #d9d9d9;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
    font-size: 13px;
    line-height: 1.5;
    word-break: break-all;
    color: #333;
}

#tableCellPopover .table-cell-popover-text {
    margin-bottom: 8px;
    max-height: 240px;
    overflow-y: auto;
    white-space: pre-wrap;
    user-select: text;
}

#tableCellPopover .table-cell-copy-btn {
    padding: 2px 10px;
    font-size: 12px;
    border: 1px solid #1890ff;
    background: #fff;
    color: #1890ff;
    border-radius: 4px;
    cursor: pointer;
}

#tableCellPopover .table-cell-copy-btn:hover {
    background: #1890ff;
    color: #fff;
}

@media (max-width: 768px) {
    table:not(.table-no-ellipsis) th,
    table:not(.table-no-ellipsis) td {
        padding: 0 8px;
    }
}
