table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

thead {
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

th {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 12px 16px;
  text-align: left;
}

td {
  padding: 12px 16px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }

tbody tr {
  transition: background 140ms var(--ease);
}
tbody tr:hover { background: var(--bg-hover); }

.table-group-row,
.table-group-row:hover {
  background: var(--bg-elevated);
}

.table-group-row th {
  padding-top: 10px;
  padding-bottom: 10px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.05em;
}

.table-group-row td {
  background: var(--bg-elevated);
  border-bottom-color: var(--border);
}

.td-actions-inner {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  white-space: nowrap;
}

.table-row--subdued {
  opacity: 0.78;
}

.table-muted {
  color: var(--text-muted);
}

.table-overflow-visible {
  overflow: visible;
}

.table-scroll {
  overflow: auto;
  max-height: calc(100vh - 120px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
}

.table-scroll table {
  width: max-content;
  min-width: 100%;
  border: none;
  border-radius: 0;
  /* Let the wrapper own horizontal scrolling so the marker column can stick to it. */
  overflow: visible;
  border-collapse: separate;
  border-spacing: 0;
}

.table-scroll :is(th:first-child, td:first-child) {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--bg-surface);
  white-space: nowrap;
  box-shadow: 1px 0 0 var(--border);
}

.table-scroll thead th:first-child,
.table-scroll .table-group-row th {
  background: var(--bg-elevated);
}

.table-scroll thead th:first-child {
  z-index: 3;
}

.table-scroll .table-group-row {
  position: sticky;
  top: 0;
  z-index: 4;
}

.table-scroll .table-group-row th {
  top: 0;
}

.table-cell-sub {
  margin-top: 3px;
  font-size: 12px;
}

.document-cell {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
  max-width: 440px;
}

.document-cell-copy {
  min-width: 0;
  overflow-wrap: anywhere;
}

.document-cell-title {
  color: var(--text-primary);
  font-weight: 600;
  line-height: 1.5;
}

.document-cell-summary {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  margin-top: 3px;
  font-size: 12px;
  line-height: 1.5;
}

.count-summary {
  display: grid;
  gap: 4px;
  font-size: 12px;
  white-space: nowrap;
}

.count-summary strong {
  font-variant-numeric: tabular-nums;
}

.count-summary small {
  color: var(--text-secondary);
  font-size: 11px;
}

.table-detail-row,
.table-detail-row:hover {
  background: var(--bg-surface);
}

.table-detail-cell {
  padding-top: 0;
}

.table-detail-disclosure {
  margin-top: 0;
}

.grouped-records,
.grouped-record {
  min-width: 0;
}

.grouped-record + .grouped-record {
  margin-top: 20px;
}

.grouped-record h3 {
  margin-bottom: 8px;
  font-size: 13px;
}

.grouped-record-list {
  margin: 0;
  padding-left: 22px;
}

.grouped-record-list > li + li {
  margin-top: 10px;
}

.grouped-record-list p {
  margin: 0;
}

.grouped-record-list :is(ul, ol) {
  margin: 6px 0 0;
  padding-left: 20px;
}

.table-summary {
  margin-left: 8px;
  font-size: 12px;
}

.table-item-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  font-size: 12px;
}

.table-item-meta .status-detail {
  max-width: none;
  margin-top: 0;
}

.table-detail-empty {
  margin: 0;
  padding: 4px 0;
}

.inline-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: max-content;
  white-space: nowrap;
}

.action-menu {
  position: relative;
  width: max-content;
}

.action-menu-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 29px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  background: var(--bg-elevated);
  cursor: pointer;
  list-style: none;
  white-space: nowrap;
}

.action-menu-trigger::-webkit-details-marker {
  display: none;
}

.action-menu-trigger::after {
  content: "⋯";
  font-size: 18px;
  line-height: 1;
}

.action-menu[open] {
  z-index: 10;
}

.action-menu[open] .action-menu-trigger {
  border-color: var(--border);
  background: var(--bg-hover);
}

.action-menu[open] .action-menu-trigger::after {
  content: "×";
}

.action-menu-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 20;
  display: grid;
  gap: 2px;
  min-width: 130px;
  padding: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}

.action-menu-item {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 30px;
  padding: 7px 9px;
  border: 0;
  border-radius: calc(var(--radius) - 2px);
  color: var(--text-secondary);
  background: transparent;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.action-menu-item:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.table-action-disabled {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 29px;
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  cursor: not-allowed;
  user-select: none;
}

.action-menu--primary .action-menu-trigger {
  width: auto;
  height: auto;
  min-height: var(--control-height);
  padding: 9px 18px;
  color: var(--btn-primary-text);
  background: var(--btn-primary-bg);
  border: 0;
  box-shadow: var(--btn-primary-shadow);
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.action-menu--primary .action-menu-trigger::after {
  content: none;
}

.action-menu--primary .action-menu-trigger:hover,
.action-menu--primary[open] .action-menu-trigger {
  color: var(--btn-primary-text);
  background: var(--btn-primary-bg-hover);
  border: 0;
  box-shadow: var(--btn-primary-shadow-hover);
}

.action-menu--primary .action-menu-trigger:focus-visible {
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.action-menu--primary[open] {
  z-index: 30;
}

.action-menu--primary .action-menu-panel {
  right: 0;
  left: auto;
  min-width: 200px;
}

@media (max-width: 860px) {
  .table-scroll {
    overflow: visible;
    max-height: none;
    border: none;
    border-radius: 0;
    background: transparent;
  }

  .table-scroll table {
    width: auto;
    min-width: 0;
  }

  .table-scroll th:first-child,
  .table-scroll td:first-child {
    position: static;
    white-space: normal;
  }

  .inline-controls {
    min-width: 0;
    max-width: 100%;
    flex-wrap: wrap;
    white-space: normal;
  }

  table {
    display: block;
    border: none;
    border-radius: 0;
    background: transparent;
    overflow: visible;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 12px;
  }

  tr,
  tr:last-child {
    display: grid;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
  }

  .table-record-row {
    border-radius: var(--radius) var(--radius) 0 0;
  }

  .table-detail-row,
  .table-detail-row:last-child {
    margin-top: -12px;
    border-top: 0;
    border-radius: 0 0 var(--radius) var(--radius);
  }

  .table-detail-cell {
    display: block;
    padding: 0 14px 11px;
  }

  .table-detail-cell::before {
    content: none;
  }

  .table-group-row,
  .table-group-row:hover {
    display: block;
    background: var(--bg-elevated);
  }

  .table-group-row th {
    display: block;
    padding: 11px 14px;
  }

  .table-group-row td {
    display: none;
  }

  tbody tr:hover {
    background: var(--bg-surface);
  }

  td {
    display: grid;
    grid-template-columns: minmax(96px, 34%) minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    min-width: 0;
    padding: 11px 14px;
    border-bottom: 1px solid var(--border-subtle);
  }

  td::before {
    content: attr(data-label);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-muted);
  }

  tr:last-child td {
    border-bottom: 1px solid var(--border-subtle);
  }

  td:last-child {
    border-bottom: none;
  }

  .td-actions {
    display: grid;
    grid-template-columns: minmax(96px, 34%) minmax(0, 1fr);
    justify-content: stretch;
    white-space: normal;
  }

  .td-actions::before {
    align-self: center;
  }

  .td-actions-inner {
    display: contents;
  }

  .td-actions-inner > a,
  .td-actions-inner > form,
  .td-actions-inner > .table-action-disabled {
    justify-self: start;
  }

  .td-actions-inner > form {
    display: inline-flex;
  }

  td .control-stack {
    min-width: 0;
  }

  td .copyable-input {
    width: 100%;
    max-width: 100%;
  }
}

@media (max-width: 430px) {
  td,
  .td-actions {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  td::before {
    margin-bottom: 1px;
  }
}

.compact-table {
  font-size: 12.5px;
}

.compact-table th,
.compact-table td {
  padding: 9px 12px;
}

.compact-table th {
  font-size: 10px;
}

@media (min-width: 861px) {
  .table--fixed-rows {
    table-layout: fixed;
  }

  .table--fixed-rows thead tr {
    height: 34px;
  }

  .table--fixed-rows tbody tr,
  .table--fixed-rows tbody td {
    height: 62px;
  }

  .table--fixed-rows th,
  .table--fixed-rows td:not(.td-actions),
  .table--fixed-rows td:not(.td-actions) > * {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .table--fixed-rows td:not(.td-actions) > * {
    display: block;
  }

  .table--fixed-rows th:last-child,
  .table--fixed-rows td:last-child {
    width: 164px;
  }
}
