/* Componente tabla-scroll: envoltorio con overflow horizontal seguro en móvil */

.tabla-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  margin: 1.5rem 0;
  border-radius: 0.25rem;
  box-shadow: inset -1px 0 0 rgba(0, 0, 0, 0.1);
}

.tabla-scroll:focus-within {
  outline: 2px solid var(--accent, #2563eb);
  outline-offset: 2px;
}

.tabla-scroll table {
  border-collapse: collapse;
  min-width: 34rem;
  width: 100%;
}

.tabla-scroll th,
.tabla-scroll td {
  padding: 0.75rem;
  text-align: left;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.tabla-scroll th {
  background-color: var(--bg-subtle, #f9fafb);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 10;
}

.tabla-scroll tbody tr:hover {
  background-color: var(--bg-hover, #f3f4f6);
}

.tabla-scroll tbody tr:last-child td {
  border-bottom: none;
}

/* Responsivo: en pantallas pequeñas, opción de tarjeta por fila */
@media (max-width: 640px) {
  .tabla-scroll table,
  .tabla-scroll thead,
  .tabla-scroll tbody,
  .tabla-scroll th,
  .tabla-scroll td,
  .tabla-scroll tr {
    display: block;
    width: 100%;
  }

  .tabla-scroll thead {
    display: none;
  }

  .tabla-scroll tbody tr {
    margin-bottom: 1rem;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 0.25rem;
    overflow: hidden;
  }

  .tabla-scroll td {
    padding-left: 50%;
    position: relative;
    min-height: 1.5rem;
    border: none;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  }

  .tabla-scroll td:last-child {
    border-bottom: none;
  }

  /* Mostrar el encabezado de columna vía ::before */
  .tabla-scroll td[data-th]::before {
    content: attr(data-th);
    position: absolute;
    left: 0.75rem;
    top: 0.75rem;
    font-weight: 600;
    width: calc(50% - 1.5rem);
    word-break: break-word;
  }
}

/* Accesibilidad: región anunciada */
.tabla-scroll[role="region"] {
  position: relative;
}

.tabla-scroll[role="region"]::after {
  content: "Scroll horizontal disponible";
  position: absolute;
  right: -999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}