/* Keep table headers and values on the same alignment and preserve compact actions. */
.ant-table :is(.ant-table-thead, .ant-table-tbody) > tr > :is(th, td).ant-table-cell {
  vertical-align: middle;
}

.ant-table-tbody > tr > td.ant-table-cell:has(> .ant-tag:only-child),
.ant-table :is(th, td).workspace-fixed-action {
  text-align: center;
}

.ant-table-tbody > tr > td.ant-table-cell > .ant-tag:only-child {
  margin-inline-end: 0;
  vertical-align: middle;
}

.inventory-page .ant-table :is(th, td):is(.inventory-category-cell, .inventory-number-cell, .inventory-compact-cell, .inventory-action-cell) {
  text-align: center !important;
  white-space: nowrap;
}

.inventory-page .ant-table :is(th, td).inventory-description-cell {
  text-align: left !important;
}

.inventory-page .inventory-category-cell .ant-tag {
  white-space: nowrap;
}

.customer-records-card .v2-desktop-data .ant-table tr > :is(th, td):nth-child(2) {
  white-space: nowrap;
  word-break: normal;
  font-variant-numeric: tabular-nums;
}

.customer-records-card .v2-desktop-data .ant-table tr > :is(th, td):not(:nth-child(7)),
.home-template-focus .ant-table tr > :is(th, td):not(:first-child),
.home-template-stock .ant-table tr > :is(th, td):not(:first-child),
.home-template-staff .ant-table tr > :is(th, td) {
  text-align: center !important;
}

.customer-records-card .v2-desktop-data .ant-table tr > :is(th, td):nth-child(7),
:is(.home-template-focus, .home-template-stock) .ant-table tr > :is(th, td):first-child {
  text-align: left !important;
}

.customer-records-card .ant-table-column-sorters {
  justify-content: center;
  gap: 6px;
}

.customer-records-card .ant-table-column-title {
  flex: none;
}

@media (min-width: 768px) {
  .inventory-page .ant-table :is(.ant-table-content, .ant-table-body) > table:has(.inventory-description-cell):has(.inventory-row-actions) {
    min-width: 1060px;
    table-layout: fixed;
  }

  .inventory-page .ant-table table:has(.inventory-description-cell):has(.inventory-row-actions) > colgroup {
    & > col:nth-child(1) { width: 26% !important; }
    & > col:nth-child(2) { width: 15% !important; }
    & > col:nth-child(3) { width: 10% !important; }
    & > col:nth-child(4),
    & > col:nth-child(5) { width: 9% !important; }
    & > col:nth-child(6) { width: 8% !important; }
    & > col:nth-child(7) { width: 23% !important; }
  }

  .inventory-page .inventory-row-actions {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-wrap: nowrap !important;
    gap: 6px !important;
  }

  .inventory-page .inventory-row-actions .ant-btn {
    min-width: 44px;
    white-space: nowrap;
  }

  .customer-records-card .v2-desktop-data .ant-table table:has(th:nth-child(11)) {
    min-width: 1140px;
  }

  .customer-records-card .v2-desktop-data .ant-table table:has(th:nth-child(11)) > colgroup {
    & > col:nth-child(1) { width: 7.5% !important; }
    & > col:nth-child(2) { width: 12% !important; }
    & > col:nth-child(3) { width: 10% !important; }
    & > col:nth-child(4) { width: 5.5% !important; }
    & > col:nth-child(5) { width: 8.5% !important; }
    & > col:nth-child(6) { width: 6.5% !important; }
    & > col:nth-child(7) { width: 8.5% !important; }
    & > col:nth-child(8) { width: 6% !important; }
    & > col:nth-child(9) { width: 10% !important; }
    & > col:nth-child(10) { width: 10% !important; }
    & > col:nth-child(11) { width: 15.5% !important; }
  }

  .home-template-focus .ant-table colgroup {
    & > col:nth-child(1) { width: 37% !important; }
    & > col:nth-child(2) { width: 16% !important; }
    & > col:nth-child(3) { width: 22% !important; }
    & > col:nth-child(4) { width: 25% !important; }
  }
}

/* The appointment and settlement lists use the same eight-column appointment table. */
:is(body:has(nav[aria-label="预约子导航"]), .settlement-list-card)
  .v2-desktop-data .ant-table table:has(> thead > tr > th:nth-child(8):last-child) {
  & > :is(thead, tbody) > tr > :is(th, td).ant-table-cell:not([colspan]):not(:nth-child(4)) {
    text-align: center !important;
  }

  & > :is(thead, tbody) > tr > :is(th, td).ant-table-cell:nth-child(4) {
    text-align: left !important;
  }

  & > tbody > tr > td.ant-table-cell:is(:nth-child(1), :nth-child(3), :nth-child(7), :nth-child(8)) {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }
}

/* The settled-visit list has a separate nine-column layout. */
.settlement-list-card .v2-desktop-data .ant-table table:has(> thead > tr > th:nth-child(9):last-child) {
  min-width: 1060px;

  & > colgroup > col:nth-child(3) {
    width: 164px !important;
  }

  & > :is(thead, tbody) > tr > :is(th, td).ant-table-cell:not([colspan]) {
    text-align: center !important;
  }

  & > tbody > tr > td.ant-table-cell:is(:first-child, :nth-last-child(2), :last-child) {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }
}

.reference-compact-catalog .ant-table table:has(> thead .ant-table-selection-column) {
  & > :is(thead, tbody) > tr > :is(th, td).ant-table-cell:nth-child(2) {
    text-align: left !important;
  }

  & > :is(thead, tbody) > tr > :is(th, td).ant-table-cell:nth-child(n+3) {
    text-align: center !important;
  }

  & > tbody > tr > td.ant-table-cell:nth-last-child(-n+3) {
    white-space: nowrap;
  }
}

@media (min-width: 601px) and (max-width: 767px) {
  .reference-cards-workspace .reference-card-types.reference-source-categories {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* Match headers and values in the record lists. Long descriptions retain natural wrapping. */
:is(
  .workspace-records[aria-label="库存变动明细"],
  .reference-cards-page [aria-label="已持卡分类"],
  .workspace-records[aria-label="结算流水"],
  .workspace-records[aria-label="历史打卡记录"],
  .workspace-records[aria-label="月度考勤汇总"]
) .ant-table :is(thead, tbody) > tr > :is(th, td).ant-table-cell {
  text-align: center !important;
}

.workspace-records[aria-label="库存变动明细"] .ant-table-content > table {
  table-layout: fixed !important;

  & > thead > tr > th:nth-child(1) { width: 13%; }
  & > thead > tr > th:nth-child(2) { width: 17%; }
  & > thead > tr > th:nth-child(3),
  & > thead > tr > th:nth-child(7) { width: 9%; }
  & > thead > tr > th:nth-child(4),
  & > thead > tr > th:nth-child(5) { width: 7%; }
  & > thead > tr > th:nth-child(6) { width: 10%; }
  & > thead > tr > th:nth-child(8) { width: 28%; }

  & > :is(thead, tbody) > tr > :is(th, td).ant-table-cell:is(:nth-child(2), :nth-child(8)) {
    text-align: left !important;
    overflow-wrap: anywhere;
  }

  & > tbody > tr > td.ant-table-cell:is(:first-child, :nth-child(3), :nth-child(4), :nth-child(5), :nth-child(6)) {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }
}

.reference-cards-page [aria-label="已持卡分类"] .ant-table-content > table {
  table-layout: fixed !important;

  & > thead > tr > th:nth-child(1) { width: 11%; }
  & > thead > tr > th:nth-child(2) { width: 27%; }
  & > thead > tr > th:nth-child(3),
  & > thead > tr > th:nth-child(7) { width: 9%; }
  & > thead > tr > th:nth-child(4) { width: 18%; }
  & > thead > tr > th:nth-child(5),
  & > thead > tr > th:nth-child(6) { width: 13%; }

  & > :is(thead, tbody) > tr > :is(th, td).ant-table-cell:is(:nth-child(2), :nth-child(4)) {
    text-align: left !important;
    overflow-wrap: anywhere;
  }

  & > tbody > tr > td.ant-table-cell:nth-last-child(-n+3) {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }
}

.workspace-records[aria-label="结算流水"] .ant-table-content > table {
  width: 1240px !important;

  & > colgroup > col:nth-child(1),
  & > colgroup > col:nth-child(11) { width: 148px !important; }
  & > colgroup > col:nth-child(2) { width: 92px !important; }
  & > colgroup > col:nth-child(3) { width: 90px !important; }
  & > colgroup > col:nth-child(4) { width: 156px !important; }
  & > colgroup > col:nth-child(5) { width: 80px !important; }
  & > colgroup > col:nth-child(6),
  & > colgroup > col:nth-child(7) { width: 94px !important; }
  & > colgroup > col:nth-child(8) { width: 112px !important; }
  & > colgroup > col:nth-child(9) { width: 140px !important; }
  & > colgroup > col:nth-child(10) { width: 86px !important; }

  & > :is(thead, tbody) > tr > :is(th, td).ant-table-cell:is(:nth-child(4), :nth-child(9)) {
    text-align: left !important;
    overflow-wrap: anywhere;
  }

  & > :is(thead, tbody) > tr > :is(th, td).ant-table-cell:is(:nth-child(6), :nth-child(7)) {
    text-align: right !important;
  }

  & > tbody > tr > td.ant-table-cell:is(:first-child, :nth-child(6), :nth-child(7), :last-child) {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }
}

.workspace-records[aria-label="历史打卡记录"] .ant-table-content > table > colgroup {
  & > col:is(:nth-child(1), :nth-child(2), :nth-child(6)) { width: 14% !important; }
  & > col:is(:nth-child(3), :nth-child(4)) { width: 21% !important; }
  & > col:nth-child(5) { width: 16% !important; }
}

.workspace-records[aria-label="月度考勤汇总"] .ant-table-content > table > colgroup > col {
  width: 20% !important;
}

:is(
  .workspace-records[aria-label="历史打卡记录"],
  .workspace-records[aria-label="月度考勤汇总"]
) .ant-table-tbody > tr > td.ant-table-cell:not([colspan]) {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
