/* Filter row: reuse app theming (let table/card styles apply) */
.table-filters-row {
  background-color: inherit;
}

.table-filter-cell {
  padding: 4px !important;
  vertical-align: middle;
  background-color: inherit;
  width: auto !important;
  position: relative;
  min-width: 0;
}

/* Wrapper para etiquetas + input (comportamiento de "input con chips" inline) */
.tf-filter-wrapper {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  width: 100%;
  gap: 2px;
  padding: 2px 6px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 4px;
  background-color: #fff;
  cursor: text;
}

.tf-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
}

.tf-chip {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  cursor: default;
}

.tf-chip-label {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tf-chip-remove {
  cursor: pointer;
  font-weight: bold;
}

/* Asegurar que todos los inputs y selects dentro de las celdas ocupen el 100% del ancho */
.table-filter-cell input,
.table-filter-cell select,
.table-filter-cell .form-control {
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
  margin: 0 !important;
  padding: 1px !important;
  height: auto !important;
  display: block;
}

.table-column-filter {
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
  flex: 1 1 40px;
  width: auto !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
  min-width: 60px;
  border: none !important;
  box-shadow: none !important;
  padding: 2px 0;
  background: transparent;
}

.table-column-filter::placeholder {
  opacity: 0.6;
  font-size: 11px;
}

/* Fixed headers when scrolling - Only applied if enabled */
body.table-filters-sticky-enabled .dataTables_wrapper .dataTables_scrollHead {
  position: sticky;
  top: 0;
  z-index: 10;
  background-color: inherit;
}

body.table-filters-sticky-enabled
  .dataTables_wrapper
  .dataTables_scrollHead
  thead {
  position: sticky;
  top: 0;
  z-index: 11;
  background-color: inherit;
}

body.table-filters-sticky-enabled
  .dataTables_wrapper
  .dataTables_scrollHead
  .table-filters-row {
  position: sticky;
  top: 0;
  z-index: 12;
}

/* For tables without scroll, apply sticky directly to thead */
body.table-filters-sticky-enabled .table-responsive {
  max-height: none;
  overflow: visible; /* allow sticky */
}

body.table-filters-sticky-enabled .dataTables_wrapper {
  overflow: visible; /* allow sticky */
}

body.table-filters-sticky-enabled .table-responsive table thead {
  position: sticky;
  top: 0;
  z-index: 20;
  background-color: inherit;
}

body.table-filters-sticky-enabled
  .table-responsive
  table
  thead
  tr:first-child
  th {
  position: sticky;
  top: 0;
  z-index: 21;
  background-color: inherit;
}

body.table-filters-sticky-enabled
  .table-responsive
  table
  thead
  .table-filters-row
  th {
  position: sticky;
  top: var(--tf-header-height, 42px);
  z-index: 22;
  background-color: inherit;
  border: 0px !important;
}

/* Keep app defaults for thead (colors/borders come from theme) */

/* Ensure that the headers have a solid background */
.dataTables_wrapper table thead th {
  position: relative;
}

/* Adjustments for responsive */
@media (max-width: 768px) {
  .table-column-filter {
    font-size: 11px;
    padding: 2px 0;
  }

  .table-filter-cell {
    padding: 2px !important;
  }

  .table-filter-cell input,
  .table-filter-cell select {
    width: 100% !important;
    max-width: 100% !important;
  }
}

table.dataTable thead th {
  padding-bottom: 0 !important;
}

/* Reglas adicionales para asegurar que los inputs se ajusten al ancho de la columna */
table.dataTable thead .table-filter-cell {
  width: auto !important;
  min-width: 0;
  padding: 5px !important;
}

table.dataTable thead .table-filter-cell input,
table.dataTable thead .table-filter-cell select {
  width: calc(100% - 0px) !important;
  max-width: 100% !important;
}

/* Style for number inputs */
.table-column-filter[type="number"] {
  text-align: right;
}

/* Ensure that the headers remain visible during scroll */
.dataTables_scrollBody {
  overflow-y: auto;
}

.dataTables_scrollHead {
  overflow: visible !important;
}

/* ============================================
   Column reorder via drag & drop on table headers
   ============================================ */

.tf-reorder-header {
  cursor: move;
}

thead th.tf-dragging {
  opacity: 0.5;
  background-color: #f8f9fa;
}

thead th.tf-drag-over {
  border-left: 2px solid #0d6efd;
  border-right: 2px solid #0d6efd;
}

/* ============================================
   Floating header for tables with display:block + overflow-x
   Alternative to CSS sticky when table is its own scroll container
   ============================================ */

.tf-floating-wrapper {
  position: fixed;
  top: 0;
  left: 0;
  visibility: hidden;
  z-index: 100;
  pointer-events: auto;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  background-color: #fff;
}

.tf-floating-inner {
  overflow-x: auto;
  overflow-y: hidden;
  width: 100%;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.tf-floating-inner::-webkit-scrollbar {
  display: none;
}

.tf-floating-inner table {
  display: table;
  table-layout: auto;
  margin: 0;
  border-collapse: collapse;
}

/* ============================================
   Pinned columns (horizontal freeze)
   ============================================ */

table.tf-has-pinned-columns {
  border-collapse: separate !important;
  border-spacing: 0 !important;
}

/* A sticky thead is one box, so a pinned header cell inside it scrolls
   sideways with the row. Each header cell has to stick on its own.
   !important beats host rules such as `#table thead th { position: relative }`. */
table.tf-has-pinned-columns > thead {
  position: static !important;
  top: auto !important;
  z-index: auto !important;
}

/* Wide table with pinned columns: the wrapper is the single scroll box for
   both axes (set from JS). Hosts that define their own scroll box keep it. */
.table-responsive.tf-pin-scroll {
  overflow: auto !important;
  max-height: calc(100vh - 220px) !important;
}

.tf-col-pinned {
  position: sticky;
  z-index: 3;
  background-color: var(--tf-pin-bg, #fff);
  background-clip: padding-box;
  box-shadow: 2px 0 0 rgba(0, 0, 0, 0.06);
}

thead th.tf-col-pinned {
  position: sticky !important;
  z-index: 40 !important;
  background-color: var(--tf-pin-bg, #fff) !important;
}

/* With a column pinned, thead is static so cells can stick sideways.
   Each header cell still sticks to the top when sticky headers are on. */
body.table-filters-sticky-enabled table.tf-has-pinned-columns > thead > tr:first-child > th {
  position: sticky !important;
  top: 0 !important;
  z-index: 30;
}

body.table-filters-sticky-enabled table.tf-has-pinned-columns > thead > tr.table-filters-row > th {
  position: sticky !important;
  top: var(--tf-header-height, 42px) !important;
  z-index: 29;
}

.popover .toggle-table-column {
  display: flex;
  align-items: center;
  gap: 8px;
}

thead th > .tf-header-pin {
  float: none;
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  margin: 0 4px 0 0;
  padding: 0;
  min-width: 0;
  min-height: 0;
}

.tf-pin-icon {
  width: 15px;
  height: 15px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tf-pin-column {
  margin-left: auto;
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  padding: 4px;
  min-width: 28px;
  min-height: 28px;
  line-height: 1;
  cursor: pointer;
  color: currentColor;
  opacity: 0.45;
}

.tf-pin-column.is-pinned .tf-pin-icon {
  fill: currentColor;
}

.tf-pin-column.is-pinned,
.tf-pin-column:hover,
.tf-pin-column:focus {
  opacity: 1;
}

.tf-pin-column:focus-visible {
  outline: 2px solid #0d6efd;
  outline-offset: 2px;
}

/* ============================================
   Column resize handle
   ============================================ */

table.dataTable thead > tr:first-child > th {
  position: relative;
}

.tf-col-resize {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 6;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  touch-action: none;
}

.tf-col-resize::after {
  content: "";
  position: absolute;
  top: 15%;
  bottom: 15%;
  right: 3px;
  width: 2px;
  border-radius: 1px;
  background: transparent;
}

.tf-col-resize:hover::after,
body.tf-col-resizing .tf-col-resize::after {
  background: currentColor;
  opacity: 0.35;
}

body.tf-col-resizing,
body.tf-col-resizing * {
  cursor: col-resize !important;
  user-select: none;
}

table.tf-has-resized-columns {
  table-layout: fixed;
}

table.dataTable.tf-has-resized-columns thead th.tf-width-locked,
table.dataTable.tf-has-resized-columns thead th.table-filter-cell.tf-width-locked,
table.dataTable.tf-has-resized-columns tbody td.tf-width-locked {
  width: var(--tf-col-width) !important;
  min-width: var(--tf-col-width) !important;
  max-width: var(--tf-col-width) !important;
  box-sizing: border-box;
}

table.dataTable.tf-has-resized-columns tbody td.tf-width-locked {
  overflow: hidden;
  white-space: normal !important;
  overflow-wrap: anywhere;
  word-break: break-word;
}
