/* 全局表格组件样式 */

/* 表格容器 */
.table {
    width: 100%;
    border: 1px solid var(--color-neutral-border);
    border-radius: var(--radius-base);
    background-color: var(--color-neutral-bg);
    overflow: hidden;
}

/* 表格主体 */
.table > table {
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
}

/* 表头 */
.table-header {
    background-color: var(--color-console-bg);
    border-bottom: 1px solid var(--color-neutral-border);
}

.table-header-cell {
    padding: var(--spacing-4) var(--spacing-4);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-neutral-title);
    text-align: left;
    vertical-align: middle;
    position: relative;
}

.table-header-cell:first-child {
    padding-left: var(--spacing-6);
}

.table-header-cell:last-child {
    padding-right: var(--spacing-6);
}

/* 表格内容 */
.table-body {
    background-color: var(--color-neutral-bg);
}

.table-body-row {
    border-bottom: 1px solid var(--color-neutral-border-secondary);
    transition: background-color var(--transition-fast);
}

.table-body-row:last-child {
    border-bottom: none;
}

.table-body-row:hover {
    background-color: var(--color-console-bg);
}

.table-body-row.selected {
    background-color: var(--color-primary-bg);
}

.table-body-cell {
    padding: var(--spacing-3) var(--spacing-4);
    font-size: var(--font-size-sm);
    color: var(--color-neutral-text);
    text-align: left;
    vertical-align: middle;
    line-height: 1.5;
}

.table-body-cell:first-child {
    padding-left: var(--spacing-6);
}

.table-body-cell:last-child {
    padding-right: var(--spacing-6);
}

/* 选择列 */
.selection-column {
    width: 48px;
    min-width: 48px;
    text-align: center;
}

/* 空状态 */
.table-empty {
    padding: var(--spacing-12) var(--spacing-6);
    text-align: center;
    color: var(--color-neutral-text-tertiary);
}

/* 紧凑模式 */
.table-compact .table-header-cell {
    padding: var(--spacing-3) var(--spacing-3);
}

.table-compact .table-body-cell {
    padding: var(--spacing-2) var(--spacing-3);
}

/* 边框模式 */
.table-bordered {
    border: 1px solid var(--color-neutral-border);
}

.table-bordered .table-header-cell,
.table-bordered .table-body-cell {
    border-right: 1px solid var(--color-neutral-border);
}

.table-bordered .table-header-cell:last-child,
.table-bordered .table-body-cell:last-child {
    border-right: none;
}


/* 表格选择复选框 */
.table-checkbox {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    margin: 0 auto;
    position: relative;
}

.table-checkbox input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
    margin: 0;
    z-index: 1;
}

.table-checkbox__custom {
    width: 16px;
    height: 16px;
    border: 1px solid var(--color-neutral-border);
    border-radius: var(--radius-sm);
    background-color: var(--color-neutral-bg);
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.table-checkbox input[type="checkbox"]:checked + .table-checkbox__custom {
    background-color: var(--color-primary);
    border-color: var(--color-primary);
}

.table-checkbox input[type="checkbox"]:checked + .table-checkbox__custom::after {
    content: '';
    width: 8px;
    height: 5px;
    border-left: 2px solid white;
    border-bottom: 2px solid white;
    transform: rotate(-45deg) translate(0, -1px);
}

.table-checkbox input[type="checkbox"]:hover + .table-checkbox__custom {
    border-color: var(--color-primary);
}

.table-checkbox input[type="checkbox"]:focus + .table-checkbox__custom {
    box-shadow: var(--shadow-focus);
    outline: none;
}

/* 禁用状态 */
.table-checkbox input[type="checkbox"]:disabled + .table-checkbox__custom {
    background-color: var(--color-neutral-bg-disabled);
    border-color: var(--color-neutral-border);
    cursor: not-allowed;
}

/* 修复选择状态问题 */
.table-body-row.selected {
    background-color: var(--color-primary-bg) !important;
}

/* 确保选中样式在悬停时也显示 */
.table-body-row.selected:hover {
    background-color: var(--color-primary-bg) !important;
    filter: brightness(0.95);
}

/* 复选框状态同步 */
.table-checkbox input[type="checkbox"]:checked + .table-checkbox__custom {
    background-color: var(--color-primary) !important;
    border-color: var(--color-primary) !important;
}

/* 防止行内其他元素干扰点击 */
.table-body-cell * {
    pointer-events: none;
}

.table-body-cell.selection-column * {
    pointer-events: auto;
}

/* 表格对齐样式 */

/* 列对齐基础样式 */
.table-cell--left {
    text-align: left;
}

.table-cell--center {
    text-align: center;
}

.table-cell--right {
    text-align: right;
}

/* 应用到表头 */
.table-header-cell.table-cell--left {
    text-align: left;
    justify-content: flex-start;
}

.table-header-cell.table-cell--center {
    text-align: center;
    justify-content: center;
}

.table-header-cell.table-cell--right {
    text-align: right;
    justify-content: flex-end;
}

/* 应用到表格内容 */
.table-body-cell.table-cell--left {
    text-align: left;
}

.table-body-cell.table-cell--center {
    text-align: center;
}

.table-body-cell.table-cell--right {
    text-align: right;
}

/* 支持内容的弹性布局对齐 */
.table-header-cell,
.table-body-cell {
    display: table-cell;
}

/* 如果需要flex布局，可以这样设置 */
.table-flex .table-header-cell,
.table-flex .table-body-cell {
    display: flex;
    align-items: center;
}

.table-flex .table-cell--left {
    justify-content: flex-start;
}

.table-flex .table-cell--center {
    justify-content: center;
}

.table-flex .table-cell--right {
    justify-content: flex-end;
}

/* 数字列推荐右对齐 */
.table-cell--number {
    text-align: right;
    font-family: var(--font-family-mono);
    font-variant-numeric: tabular-nums;
}

/* 金额列特殊样式 */
.table-cell--amount {
    text-align: right;
    font-family: var(--font-family-mono);
    font-variant-numeric: tabular-nums;
    color: var(--color-primary);
}

/* 状态列推荐居中 */
.table-cell--status {
    text-align: center;
}

/* 操作列推荐居中或右对齐 */
.table-cell--action {
    text-align: center;
}

/* 对于图标按钮的操作列 */
.table-cell--action-buttons {
    display: flex;
    gap: var(--spacing-2);
    justify-content: center;
    align-items: center;
}