/* ============================================================================
 * data-table-pro.css
 * Estilos compartidos para tablas con filtros por columna, sort, selección
 * múltiple, chips de filtros activos, atajos y acciones masivas.
 *
 * Activación: añadir clase .dt-pro al <table> y atributo [data-dt-pro].
 * El JS gemelo (data-table-pro.js) detecta este marcador y monta toda la UI.
 * ========================================================================= */

/* === Wrap con scroll horizontal y vertical === */
.dt-pro-wrap {
  position: relative;
  max-height: calc(100vh - 280px);
  overflow: auto;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 8px;
  background: var(--surface, #fff);
}
table.dt-pro {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
}

/* === Header pegajoso (cabecera + fila de filtros) === */
table.dt-pro thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--surface, #fff);
  border-bottom: 1px solid var(--border, #e5e7eb);
}
table.dt-pro thead .dt-pro-filters th {
  top: 38px;
  z-index: 2;
  background: var(--bg-soft, #f8fafc);
  padding: 5px 6px;
}

/* === Cabecera sortable === */
table.dt-pro thead .dt-pro-headers th {
  cursor: pointer;
  user-select: none;
  padding-right: 18px;
  position: sticky;
}
table.dt-pro thead .dt-pro-headers th:hover { background: var(--bg-soft, #f3f4f6); }
table.dt-pro thead .dt-pro-headers th[data-sort-active="asc"]::after  { content: "▲"; position: absolute; right: 6px; font-size: 10px; color: #2563eb; }
table.dt-pro thead .dt-pro-headers th[data-sort-active="desc"]::after { content: "▼"; position: absolute; right: 6px; font-size: 10px; color: #2563eb; }
table.dt-pro thead .dt-pro-headers th[data-sortable="0"] { cursor: default; }
table.dt-pro thead .dt-pro-headers th[data-sortable="0"]:hover { background: var(--surface, #fff); }

/* === Inputs de filtros === */
table.dt-pro thead .dt-pro-filters input,
table.dt-pro thead .dt-pro-filters select {
  width: 100%;
  box-sizing: border-box;
  padding: 5px 8px;
  font-size: 12px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: var(--surface, #fff);
  color: inherit;
  transition: border-color .12s, box-shadow .12s;
}
table.dt-pro thead .dt-pro-filters input::placeholder { color: #9ca3af; font-style: italic; }
table.dt-pro thead .dt-pro-filters input:hover,
table.dt-pro thead .dt-pro-filters select:hover  { border-color: var(--border, #e5e7eb); }
table.dt-pro thead .dt-pro-filters input:focus,
table.dt-pro thead .dt-pro-filters select:focus  { outline: none; border-color: #2563eb; box-shadow: 0 0 0 2px #2563eb22; }
table.dt-pro thead .dt-pro-filters input[type="number"] { min-width: 0; text-align: right; }
.dt-pro-filters .dt-pro-pair { display: flex; gap: 3px; }
.dt-pro-filters .dt-pro-pair input { padding: 5px 4px; font-size: 11px; }
.dt-pro-filters input.has-value,
.dt-pro-filters select.has-value { background: #fff7ed; border-color: #fdba74; }

/* === Selección múltiple (col sticky a la izquierda) === */
table.dt-pro .col-check,
table.dt-pro .td-check {
  width: 42px; text-align: center; padding: 0 6px;
  position: sticky; left: 0; z-index: 2;
  background: var(--surface, #fff);
  border-right: 1px solid var(--border, #e5e7eb);
}
table.dt-pro thead .dt-pro-headers th.col-check  { z-index: 4; background: var(--surface, #fff); }
table.dt-pro thead .dt-pro-filters th.col-check  { z-index: 3; background: var(--bg-soft, #f8fafc); }
table.dt-pro .col-check input,
table.dt-pro .td-check input {
  cursor: pointer; width: 16px; height: 16px; accent-color: #2563eb;
}
table.dt-pro tbody tr:hover .td-check { background: var(--bg-soft, #f9fafb); }
table.dt-pro tbody tr.is-selected { background: #eff6ff !important; }
table.dt-pro tbody tr.is-selected .td-check {
  background: #dbeafe;
  border-right: 2px solid #2563eb;
}
table.dt-pro tbody tr.is-selected .td-actions { background: #eff6ff; }

/* === Columna acciones (sticky a la derecha) === */
table.dt-pro .col-actions,
table.dt-pro .td-actions {
  width: 96px; text-align: right; white-space: nowrap;
  position: sticky; right: 0; background: var(--surface, #fff); z-index: 1;
}
table.dt-pro tbody tr:hover .td-actions { background: var(--bg-soft, #f9fafb); }
.dt-pro-row-actions { display: inline-flex; gap: 4px; opacity: .55; transition: opacity .15s; }
table.dt-pro tbody tr:hover .dt-pro-row-actions { opacity: 1; }
.dt-pro-row-actions form { display: inline; margin: 0; }
.dt-pro-btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; padding: 0; border-radius: 6px;
  border: 1px solid var(--border, #d1d5db); background: var(--surface, #fff); cursor: pointer;
  font-size: 14px; line-height: 1; color: #374151;
  transition: background .12s, border-color .12s, transform .08s;
}
.dt-pro-btn-icon:hover { background: #eff6ff; border-color: #2563eb; color: #1d4ed8; text-decoration: none; }
.dt-pro-btn-icon:active { transform: scale(.94); }
.dt-pro-btn-icon.is-danger { color: #dc2626; }
.dt-pro-btn-icon.is-danger:hover { background: #fef2f2; border-color: #dc2626; color: #b91c1c; }

/* === Toolbar superior (limpiar + chips + atajos + contador) === */
.dt-pro-toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 6px 0 8px; font-size: 12.5px;
}
.dt-pro-toolbar .dt-pro-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 4px 3px 10px; border-radius: 999px;
  background: #fff7ed; border: 1px solid #fdba74; color: #9a3412;
  font-size: 11.5px; font-weight: 500;
}
.dt-pro-toolbar .dt-pro-chip button {
  all: unset; cursor: pointer; width: 18px; height: 18px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: #fdba7433; color: #9a3412; font-size: 13px; line-height: 1;
}
.dt-pro-toolbar .dt-pro-chip button:hover { background: #fdba7466; }
.dt-pro-clear-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; font-size: 12px; border-radius: 6px;
  border: 1px solid var(--border, #d1d5db); background: var(--surface, #fff); cursor: pointer;
  color: #6b7280;
}
.dt-pro-clear-btn:hover { background: #fef2f2; color: #b91c1c; border-color: #fca5a5; }
.dt-pro-clear-btn[hidden] { display: none; }
.dt-pro-counter { font-size: 12px; color: var(--text-muted, #6b7280); margin-left: auto; }
.dt-pro-kbd-hint { font-size: 11px; color: #9ca3af; }
.dt-pro-kbd-hint kbd { background: #f3f4f6; border: 1px solid #e5e7eb; border-radius: 3px; padding: 0 4px; font-size: 10.5px; color: #374151; }

/* === Highlight de coincidencias === */
mark.dt-pro-hl { background: #fde68a; color: inherit; padding: 0 1px; border-radius: 2px; }

/* === Filas más respirables === */
table.dt-pro tbody tr { transition: background .1s; }
table.dt-pro tbody tr:hover { background: var(--bg-soft, #f9fafb); }
table.dt-pro tbody tr[data-href] { cursor: pointer; }

/* === Barra de selección masiva (sticky abajo) === */
.dt-pro-bulkbar {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px; margin-top: -1px;
  background: linear-gradient(180deg, var(--navy-500, #2E4763), var(--navy-600, #0F2A44)); color: #fff;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 -4px 16px -8px rgba(15, 42, 68, .5);
  font-size: 13px;
  transform: translateY(8px); opacity: 0; pointer-events: none;
  transition: transform .18s ease, opacity .18s ease;
}
.dt-pro-bulkbar.is-visible { transform: translateY(0); opacity: 1; pointer-events: auto; }
.dt-pro-bulkbar strong { font-weight: 700; }
.dt-pro-bulkbar form { margin: 0; display: inline; }
.dt-pro-bulkbar .dt-pro-bulk-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dt-pro-bulkbar button,
.dt-pro-bulkbar .dt-pro-bulk-btn {
  all: unset; cursor: pointer; padding: 6px 12px; border-radius: 6px;
  font-size: 12.5px; font-weight: 500; line-height: 1;
  background: rgba(255, 255, 255, .15); color: #fff;
  transition: background .12s;
}
.dt-pro-bulkbar button:hover,
.dt-pro-bulkbar .dt-pro-bulk-btn:hover { background: rgba(255, 255, 255, .28); }
.dt-pro-bulkbar button.is-danger { background: #dc2626; }
.dt-pro-bulkbar button.is-danger:hover { background: #b91c1c; }
.dt-pro-bulkbar button.is-ghost { background: transparent; border: 1px solid rgba(255, 255, 255, .4); }
.dt-pro-bulkbar select {
  padding: 6px 28px 6px 12px; border-radius: 6px;
  background: rgba(255, 255, 255, .15) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'><path fill='%23fff' d='M5 7L1 3h8z'/></svg>") no-repeat right 10px center;
  color: #fff; border: 1px solid rgba(255, 255, 255, .25);
  font-size: 12.5px; appearance: none;
}
.dt-pro-bulkbar select option { color: #111; }

/* === Mobile === */
@media (max-width: 900px) {
  .dt-pro-wrap { max-height: none; }
  table.dt-pro thead th { position: static; }
  table.dt-pro .col-actions,
  table.dt-pro .td-actions { position: static; }
  table.dt-pro .col-check,
  table.dt-pro .td-check { position: static; }
}

/* ============================================================
   Responsive <768px: las tablas pasan a tarjetas apiladas.
   Cada celda muestra su cabecera vía data-label (lo pone el JS).
   ============================================================ */
@media (max-width: 768px) {
  .dt-pro-wrap { overflow-x: visible; }
  table.data-table,
  table.data-table tbody,
  table.data-table tbody tr,
  table.data-table tbody td { display: block; width: 100%; }
  table.data-table thead { display: none; }
  table.data-table tbody tr {
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 10px;
    margin-bottom: 8px;
    padding: 4px 12px;
    background: var(--surface, #fff);
  }
  table.data-table tbody td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    border: none;
    padding: 6px 0;
    text-align: right;
    min-height: 0;
    font-size: 14.5px;
  }
  table.data-table tbody td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .02em;
    text-transform: uppercase;
    color: var(--text-muted, #5C6B7A);
    text-align: left;
  }
  table.data-table tbody td:not([data-label])::before { content: none; }
  /* Checkbox de selección: bulk-actions es un flujo de escritorio; en
     móvil ocupa una fila entera para algo que casi nadie usa a una mano. */
  table.data-table tbody td.td-check { display: none; }
  /* Identidad de la tarjeta: el campo justo después del ID (Cliente,
     Proyecto, Proveedor…) es siempre el nombre humano-legible — mismo
     orden de columnas en las 8 páginas que usan esta tabla. Se destaca
     como título en vez de otro par etiqueta:valor igual a los demás,
     así la tarjeta tiene una jerarquía clara en vez de una lista plana. */
  table.data-table tbody td.td-id {
    padding-top: 8px;
    font-size: 11.5px;
    opacity: .65;
  }
  table.data-table tbody td.td-id::before { font-size: 10.5px; }
  table.data-table tbody td.td-id + td {
    padding-bottom: 9px;
    border-bottom: 1px solid var(--border, #e2e8f0);
    margin-bottom: 3px;
  }
  table.data-table tbody td.td-id + td::before { content: none; }
  table.data-table tbody td.td-id + td {
    font-size: 17px;
    font-weight: 700;
    color: var(--text, #18181B);
  }
  /* Acciones: alineadas a la derecha, sin etiqueta */
  table.data-table tbody td.td-actions { justify-content: flex-end; }
  table.data-table tbody td.td-actions::before { content: none; }
  /* Celdas vacías no pintan fila fantasma */
  table.data-table tbody td:empty { display: none; }
}
