/* ==========================================================================
   uji-tablas.css — Tablas del lector de temario
   Proyecto: oposiciones-ujier.es
   Todo el CSS cuelga de clases con prefijo uji-, sin selectores de elemento
   sueltos, para que el tema opositatis no interfiera ni se vea afectado.
   ========================================================================== */

.uji-tabla-wrap,
.uji-tabla {
  --uji-t-navy:    #1b1b8f;
  --uji-t-navy-90: #24248f;
  --uji-t-crema:   #faf7f0;
  --uji-t-crema-2: #f2ede1;
  --uji-t-borde:   #d9d4c7;
  --uji-t-carmesi: #9b1b30;
  --uji-t-oro:     #b08d2f;
  --uji-t-texto:   #23262f;
  --uji-t-tenue:   #5d6272;
  --uji-t-acento:  var(--uji-t-navy);
}

/* --------------------------------------------------------------------------
   0. Contención: que ninguna tabla ensanche la columna de texto
   Los hijos de un grid/flex tienen min-width:auto y se estiran al ancho de
   su contenido; con esto el scroll se queda dentro del wrap.
   -------------------------------------------------------------------------- */

.uji-cuerpo,
.uji-tema,
.uji-sec,
.uji-ap,
.uji-ap__cuerpo,
.uji-sub {
  min-width: 0;
  max-width: 100%;
}

.uji-tabla-wrap {
  display: block;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

/* --------------------------------------------------------------------------
   1. Contenedor con scroll horizontal
   -------------------------------------------------------------------------- */

.uji-tabla-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1.75rem 0;
  border-radius: 3px;
  background:
    linear-gradient(to right, var(--uji-t-crema) 30%, rgba(250, 247, 240, 0)) left / 32px 100% no-repeat,
    linear-gradient(to left,  var(--uji-t-crema) 30%, rgba(250, 247, 240, 0)) right / 32px 100% no-repeat,
    radial-gradient(farthest-side at 0 50%, rgba(27, 27, 143, .16), transparent) left / 12px 100% no-repeat,
    radial-gradient(farthest-side at 100% 50%, rgba(27, 27, 143, .16), transparent) right / 12px 100% no-repeat;
  background-attachment: local, local, scroll, scroll;
}

.uji-tabla-wrap:focus-visible {
  outline: 2px solid var(--uji-t-acento);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   2. Tabla base
   -------------------------------------------------------------------------- */

.uji-tabla {
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
  font-family: "Poppins", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: .94rem;
  line-height: 1.5;
  color: var(--uji-t-texto);
  background: #fff;
  border-top: 3px solid var(--uji-t-acento);
}

.uji-tabla caption {
  caption-side: top;
  text-align: left;
  padding: 0 0 .6rem;
  font-size: .95rem;
  font-weight: 600;
  color: var(--uji-t-acento);
}

.uji-tabla thead th {
  background: var(--uji-t-acento);
  color: #fff;
  font-weight: 600;
  font-size: .87rem;
  text-align: left;
  padding: .7rem .9rem;
  vertical-align: bottom;
  border-right: 1px solid rgba(255, 255, 255, .18);
}

.uji-tabla thead th:last-child { border-right: 0; }

.uji-tabla tbody td,
.uji-tabla tbody th {
  padding: .68rem .9rem;
  border-bottom: 1px solid var(--uji-t-borde);
  border-right: 1px solid var(--uji-t-borde);
  vertical-align: top;
  text-align: left;
  overflow-wrap: anywhere;
}

.uji-tabla tbody td:last-child,
.uji-tabla tbody th:last-child { border-right: 0; }

.uji-tabla tbody tr:nth-child(even) { background: var(--uji-t-crema); }

.uji-tabla tbody tr:last-child td,
.uji-tabla tbody tr:last-child th { border-bottom: 0; }

.uji-tabla tbody th[scope="row"] {
  font-weight: 600;
  color: var(--uji-t-navy);
  background: var(--uji-t-crema-2);
  white-space: normal;
  width: 26%;
}

.uji-tabla tfoot td,
.uji-tabla tfoot th {
  padding: .68rem .9rem;
  background: var(--uji-t-crema-2);
  border-top: 2px solid var(--uji-t-acento);
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   3. El dato que se pregunta
   -------------------------------------------------------------------------- */

.uji-tabla .uji-clave {
  font-weight: 600;
  color: var(--uji-t-carmesi);
  box-shadow: inset 0 -.42em 0 rgba(176, 141, 47, .18);
}

.uji-tabla .uji-na {
  color: var(--uji-t-tenue);
  font-style: italic;
}

/* --------------------------------------------------------------------------
   4. Variantes
   -------------------------------------------------------------------------- */

.uji-tabla--comparativa tbody td:first-of-type { border-left: 2px solid var(--uji-t-borde); }
.uji-tabla--comparativa thead th:nth-child(2)  { border-left: 2px solid rgba(255, 255, 255, .3); }
.uji-tabla--comparativa tbody td               { width: 37%; }
.uji-tabla--comparativa tbody th[scope="row"]  { width: 26%; white-space: normal; }

.uji-tabla--compacta { font-size: .88rem; }
.uji-tabla--compacta thead th,
.uji-tabla--compacta tbody td,
.uji-tabla--compacta tbody th { padding: .45rem .65rem; }

.uji-tabla--fija thead th {
  position: sticky;
  top: 0;
  z-index: 2;
}

/* --------------------------------------------------------------------------
   5. Móvil: la tabla se convierte en fichas
   Cada <td> necesita data-col="Congreso" (o lo que toque).
   -------------------------------------------------------------------------- */

@media (max-width: 620px) {

  .uji-tabla-wrap { background: none; overflow-x: visible; }

  .uji-tabla,
  .uji-tabla tbody,
  .uji-tabla tbody tr,
  .uji-tabla tbody td,
  .uji-tabla tbody th { display: block; width: auto; }

  .uji-tabla thead { display: none; }

  .uji-tabla tbody tr {
    margin-bottom: .9rem;
    border: 1px solid var(--uji-t-borde);
    border-left: 3px solid var(--uji-t-acento);
    border-radius: 2px;
    background: #fff;
  }

  .uji-tabla tbody tr:nth-child(even) { background: #fff; }

  .uji-tabla tbody th[scope="row"] {
    background: var(--uji-t-acento);
    color: #fff;
    white-space: normal;
    border: 0;
    padding: .55rem .8rem;
    width: auto;
  }

  .uji-tabla tbody td {
    border: 0;
    border-top: 1px solid var(--uji-t-borde);
    padding: .55rem .8rem;
  }

  .uji-tabla tbody td[data-col]::before {
    content: attr(data-col);
    display: block;
    margin-bottom: .15rem;
    font-size: .76rem;
    font-weight: 600;
    color: var(--uji-t-tenue);
  }

  .uji-tabla--comparativa tbody td:first-of-type { border-left: 0; }
  .uji-tabla--comparativa tbody td,
  .uji-tabla--comparativa tbody th[scope="row"] { width: auto; }
}

/* --------------------------------------------------------------------------
   6. Impresión
   -------------------------------------------------------------------------- */

@media print {
  .uji-tabla-wrap { overflow: visible; background: none; margin: 1rem 0; }

  .uji-tabla {
    font-size: 10pt;
    border-top: 2pt solid #000;
    page-break-inside: auto;
  }

  .uji-tabla thead { display: table-header-group; }
  .uji-tabla tfoot { display: table-footer-group; }
  .uji-tabla tr    { page-break-inside: avoid; }

  .uji-tabla thead th {
    background: #eee !important;
    color: #000 !important;
    border: .5pt solid #000;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .uji-tabla tbody td,
  .uji-tabla tbody th { border: .5pt solid #666; }
  .uji-tabla tbody tr:nth-child(even) { background: none; }
  .uji-tabla .uji-clave { box-shadow: none; text-decoration: underline; }
}

/* --------------------------------------------------------------------------
   7. Accesibilidad
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .uji-tabla-wrap { scroll-behavior: auto; }
}

@media (prefers-contrast: more) {
  .uji-tabla tbody td,
  .uji-tabla tbody th { border-color: #000; }
  .uji-tabla .uji-clave { box-shadow: none; text-decoration: underline; }
}
