/* ===========================================================================
   tables.css - data tables, sorting, row actions, pagination
   =========================================================================== */

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  white-space: nowrap;
}

.table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  text-align: left;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table thead th.t-right { text-align: right; }

.table tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }

.cell-strong { color: var(--text); font-weight: 550; }
.cell-link { color: var(--accent); }
.table td.t-right { text-align: right; }

.th-sort {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: inherit;
}
.th-sort:hover { color: var(--text); text-decoration: none; }
.th-sort .icon { opacity: .4; }
.th-sort.is-sorted { color: var(--accent); }
.th-sort.is-sorted .icon { opacity: 1; }

/* row actions ------------------------------------------------------------ */

.row-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}

.act {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  color: var(--text-3);
  background: transparent;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.act:hover { background: var(--surface-3); border-color: var(--border); text-decoration: none; }
.act.view:hover   { color: var(--info); }
.act.edit:hover   { color: var(--accent); }
.act.delete:hover { color: var(--danger); }
.act.more:hover   { color: var(--text); }
.row-actions .dropdown { display: flex; }

.table thead th:last-child,
.table tbody td:last-child { text-align: right; }

/* sticky first column on wide tables ------------------------------------- */
.table.sticky-first thead th:first-child,
.table.sticky-first tbody td:first-child {
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 1;
}
.table.sticky-first thead th:first-child { background: var(--surface-2); z-index: 3; }
.table.sticky-first tbody tr:hover td:first-child { background: var(--surface-2); }

/* table toolbar ----------------------------------------------------------- */

.table-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
}
.table-toolbar .count { font-size: 12.5px; color: var(--text-3); }
.table-toolbar .spacer { margin-left: auto; }

/* column chooser ---------------------------------------------------------- */
.col-chooser { max-height: 300px; overflow-y: auto; padding: 4px; }
.col-chooser .check { padding: 6px 8px; border-radius: var(--r-sm); }
.col-chooser .check:hover { background: var(--surface-3); }

/* pagination -------------------------------------------------------------- */

.pagination {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
}
.pagination .info { font-size: 12.5px; color: var(--text-3); }
.pagination .pages { margin-left: auto; display: flex; gap: 4px; align-items: center; }

.page-link {
  min-width: 32px; height: 32px;
  padding: 0 8px;
  display: inline-grid; place-items: center;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.page-link:hover { background: var(--surface-3); text-decoration: none; color: var(--text); }
.page-link.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.page-link.disabled { opacity: .45; pointer-events: none; }
.page-ellipsis { padding: 0 4px; color: var(--text-3); }

/* totals row -------------------------------------------------------------- */
.table tfoot td {
  padding: 12px 14px;
  border-top: 2px solid var(--border-strong);
  background: var(--surface-2);
  font-weight: 650;
  color: var(--text);
}

/* photo column -----------------------------------------------------------
   The first cell of a media table holds a thumbnail, so the asset tag that
   normally anchors a horizontally scrolled table is pinned alongside it. */

.table th.t-center, .table td.t-center { text-align: center; }
.table .th-static {
  font-size: inherit; font-weight: inherit; color: var(--text-2);
  display: inline-block; padding: 2px 0;
}
.table.has-thumb thead th:first-child,
.table.has-thumb tbody td:first-child { width: 64px; padding-left: 12px; padding-right: 8px; }

@media (min-width: 900px) {
  .table.sticky-first.has-thumb thead th:nth-child(2),
  .table.sticky-first.has-thumb tbody td:nth-child(2) {
    position: sticky; left: 64px; background: var(--surface); z-index: 1;
  }
  .table.sticky-first.has-thumb thead th:nth-child(2) { background: var(--surface-2); z-index: 3; }
  .table.sticky-first.has-thumb tbody tr:hover td:nth-child(2) { background: var(--surface-2); }
}
