/* ==========================================================================
   TABLAS — toda tabla del sistema toma este diseño por defecto, sin clase.
   Fila de una línea ≈ 36 px, encabezado en tipo oración, cifras tabulares.
   Los módulos solo definen anchos de columna y alineaciones.
   ========================================================================== */
:where(.content) table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  font-variant-numeric: tabular-nums;
}

:where(.content) th {
  padding: 7px var(--cell-x);
  border-bottom: 1px solid var(--line-strong);
  background: var(--table-head);
  color: var(--ink);
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  line-height: 1.3;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

:where(.content) td {
  padding: var(--cell-y) var(--cell-x);
  border-bottom: 1px solid var(--line);
  color: var(--text);
  font-size: var(--fs-md);
  line-height: 1.4;
  text-align: left;
  vertical-align: middle;
}

/* Filas alternadas: una blanca y otra gris para seguir cada renglón. No cuenta las
   filas ocultas ni las de detalle desplegable, así la alternancia no se rompe. */
:where(.content) tbody tr:nth-child(even of :where(:not([hidden], .ui-expandable-row, .ilp-detail-row))) > td {
  background: var(--row-stripe);
}

/* Al pasar el mouse, la fila se marca en azul claro (va después para ganarle a la alternancia). */
:where(.content) tbody tr:hover > td {
  background: var(--row-hover);
}

/* Tablas de listado: encabezado y filas de la misma altura (48 px, guía de IBM Carbon). */
:where(.content) table.table > thead > tr > th,
:where(.content) table.table > tbody > tr > td {
  height: var(--table-row-h);
}

/* Relleno vertical corto para que dos líneas (nombre + dato) o una miniatura quepan en 48 px
   y todas las filas queden iguales. */
:where(.content) table.table > tbody > tr > td {
  padding-top: 6px;
  padding-bottom: 6px;
}

:where(.content) tbody tr:last-child > td {
  border-bottom: 0;
}

:where(.content) td strong {
  color: var(--ink);
  font-weight: var(--fw-semibold);
}

:where(.content) td small {
  display: block;
  color: var(--muted);
  font-size: var(--fs-sm);
}

:where(.content) tfoot td {
  background: var(--surface-2);
  font-weight: var(--fw-semibold);
}

/* Fila seleccionada (su menú ⋯ está abierto): azul más firme que el de pasar el mouse. */
:where(.content) tbody tr.is-menu-active > td,
.table tr.is-menu-active > td {
  background: var(--row-selected);
}

.table-action-cell {
  white-space: nowrap;
}

/* Folio: enlace principal de cada fila */
.table-folio,
.inventory-folio,
.delivery-folio,
.quote-folio-link {
  color: var(--brand-strong);
  font-weight: var(--fw-semibold);
  white-space: nowrap;
}

.table-folio:hover,
.inventory-folio:hover,
.delivery-folio:hover,
.quote-folio-link:hover {
  color: var(--brand);
  text-decoration: underline;
  text-underline-offset: 3px;
}

:where(.content) td.nowrap {
  white-space: nowrap;
}

/* Alineación de números, fechas y acciones en cualquier tabla */
:where(.content) :is(th, td):is(.is-number, .numeric, .right, .cell-total) {
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

:where(.content) :is(th, td).is-date {
  white-space: nowrap;
}

:where(.content) :is(th, td).is-actions {
  width: 1%;
  text-align: right;
  white-space: nowrap;
}

/* Moneda: código atenuado junto al importe. */
.money-code {
  margin-left: 3px;
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
}

/* Texto secundario de celda y texto largo recortado a dos líneas con title. */
.cell-sub {
  display: block;
  color: var(--muted);
  font-size: var(--fs-sm);
  font-weight: 400;
}

.cell-clamp {
  display: -webkit-box;
  overflow: hidden;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

/* Miniatura compacta con respaldo cuando la imagen no existe. */
.thumb-36 {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  object-fit: contain;
}

/* Celda de nombre con miniatura: ocupa el espacio libre y recorta el texto secundario. */
td.catalog-name-cell {
  width: 100%;
  min-width: 240px;
  max-width: 0;
}

.catalog-name {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.catalog-name-text {
  min-width: 0;
}

.catalog-name-text > :is(a, strong, .cell-sub) {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.catalog-fiscal-missing {
  color: var(--warning);
}

/* ---- Tabla fluida: escala con la pantalla sin barra horizontal ----------
   Todas las filas miden lo mismo: cada celda es de una sola línea y el texto
   largo termina en «…» (el texto completo va en el title). Cifras, códigos y
   acciones no se parten. Al angostarse la pantalla se ocultan primero las
   columnas secundarias (.col-hide-lg, luego .col-hide-md).
   Anchos: .col-main (texto principal), .col-text (secundario) y .col-short (corto). */
:where(.content) .table-fluid tbody td {
  white-space: nowrap;
}

:where(.content) .table-fluid :is(th, td).col-main {
  width: 30%;
  min-width: 150px;
  max-width: 0;
}

:where(.content) .table-fluid :is(th, td).col-text {
  width: 22%;
  min-width: 110px;
  max-width: 0;
}

:where(.content) .table-fluid :is(th, td).col-short {
  width: 12%;
  min-width: 80px;
  max-width: 0;
}

:where(.content) .table-fluid :is(th, td).col-id {
  width: 1%;
}

:where(.content) .table-fluid td:is(.col-main, .col-text, .col-short) > * {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 1279px) {
  :where(.content) .table-fluid .col-hide-lg {
    display: none;
  }
}

@media (max-width: 1099px) {
  :where(.content) .table-fluid .col-hide-md {
    display: none;
  }
}

.table-card {
  position: relative;
}

/* Contenedor de tabla: tarjeta sin relleno, encabezado y paginador alineados.
   Con .table-scroll la tarjeta no recorta los resultados de los buscadores de filtros. */
.table-scroll {
  position: relative;
  overflow-x: auto;
}

.card.table-card:has(> .table-scroll),
.card.table-card:has(> form > .table-scroll) {
  overflow: visible;
}

.table-card,
.card:has(> table),
.card:has(> .ui-compact-table-wrap) {
  padding: 0;
  overflow-x: auto;
}

.table-card > .card-header,
.card:has(> table) > .card-header {
  position: sticky;
  left: 0;
  margin: 0;
  padding: 8px var(--gap-lg);
  border-bottom: 1px solid var(--line);
}

.table-card > :not(table, form, .card-header, .table-pager, .ui-compact-table-wrap, .table-scroll, .filter-bar, .filter-tabs, .list-summary),
.card:has(> table) > :not(table, form, .card-header, .table-pager, .ui-compact-table-wrap, .table-scroll, .filter-bar, .filter-tabs) {
  margin-inline: var(--gap-lg);
}

/* Paginación: una sola línea compacta. El paginador no se desplaza con la tabla. */
.table-pager {
  position: sticky;
  left: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap-xs) var(--gap-md);
  min-height: 44px;
  margin: 0;
  padding: 6px var(--gap-lg);
  border-top: 1px solid var(--line);
}

/* Paginador fuera de una tarjeta: alineado con el contenido de la página. */
:is(.content, .tools-shell, .revision-page, .task-list-results, .k4-pagination) > .table-pager {
  padding-inline: 0;
  border-top: 0;
}

.table-pager-left,
.table-pager-controls,
.table-pager-size {
  display: inline-flex;
  align-items: center;
  gap: var(--gap-xs);
}

.table-pager-left {
  gap: var(--gap-md);
}

.table-pager-summary,
.table-pager-size {
  color: var(--muted);
  font-size: var(--fs-md);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.table-pager-size {
  font-weight: 400;
}

.table-pager-size select {
  width: auto;
  min-width: 62px;
  min-height: var(--control-h-sm);
  padding: 2px 24px 2px 8px;
  background-position: right 7px center;
  border-color: var(--line-strong);
  font-size: var(--fs-md);
}

.table-pager-controls {
  gap: 2px;
}

.table-pager-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--control-h-sm);
  height: var(--control-h-sm);
  padding: 0 7px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: var(--fs-md);
  font-weight: var(--fw-medium);
  font-variant-numeric: tabular-nums;
  text-decoration: none;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}

.table-pager-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.table-pager-btn:hover:not(:disabled, .is-disabled, .is-active) {
  border-color: var(--line-strong);
  background: var(--surface-2);
  color: var(--ink);
}

.table-pager-btn:disabled:not(.is-active),
.table-pager-btn.is-disabled {
  color: var(--line-strong);
  cursor: default;
  pointer-events: none;
}

.table-pager-btn.is-active {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
  font-weight: var(--fw-semibold);
  cursor: default;
}

.table-pager-gap {
  min-width: 18px;
  color: var(--muted);
  font-size: var(--fs-md);
  text-align: center;
}

@media (max-width: 700px) {
  :where(.content) table {
    display: block;
    overflow-x: auto;
    max-width: 100%;
  }

  .table-pager-size-label {
    display: none;
  }
}
