/* ===========================================================================
   EL BOTÓN — [UI6.1] y sus seis subsecciones · 13-10-2026
   ===========================================================================

   Una sola implementación, y la usa el componente Blade `<x-boton>`. No hay
   una segunda: [UI10.2] lo prohíbe con el argumento del maestro —dos
   implementaciones de la misma pieza acaban diciendo cosas distintas— y aquí
   lo que diría distinto es qué parece pulsable.

   ---- DE DÓNDE SALE CADA NÚMERO -------------------------------------------

   Ninguno está escrito aquí: todos vienen de `tokens.css`, que es lo que pide
   [UI10.2]. Las tres alturas (32/40/48), los tres rellenos horizontales
   (12/16/20), los tres tamaños de fuente (12,8/14/16), los tres anchos mínimos
   (64/88/104), el tope de 320 px, la separación de 8 px entre icono y etiqueta
   y el área táctil de 44 px están en [UI6.1.1] y viven en tokens como
   `--btn-*`.

   ---- LAS CINCO VARIANTES, Y CUÁL ES LA DIFERENCIA DE VERDAD --------------

   | primario           | relleno de acento. La acción de la pantalla. Una.   |
   | secundario         | superficie con borde de control. Las que acompañan. |
   | sutil              | sin relleno ni borde. Acciones de fila.             |
   | destructivo        | relleno `--danger`. Borrar, revocar, cancelar.      |
   | destructivo sutil  | solo texto `--danger-text`. Borrar dentro de fila.  |

   Las dos sólidas cambian de RELLENO al interactuar; las tres planas usan las
   capas de estado de [UI4.5]. Y eso no es gusto: `--state-pressed` se compone
   sobre la superficie, así que sobre un relleno de acento no produce ningún
   cambio visible — el vacío que [UI6.1.2] vino a cerrar con `--accent-pressed`
   y `--danger-pressed`.

   ---- EL ANCHO MÍNIMO NO RIGE PARA LAS DOS SUTILES ------------------------

   [UI6.1.1]. Existe para que «Sí», «Ver» o «Editar» no produzcan un botón
   cuadrado que se confunde con uno solo-icono; pero las dos sutiles viven en
   filas de tabla y un «Ver» de 88 px ENSANCHA SU COLUMNA y empuja a las demás.
   Sin relleno ni borde, un sutil estrecho no se confunde con un solo-icono,
   que es el riesgo que el mínimo evitaba.

   ---- Y NO HAY SOLO-ICONO EN UNA FILA DE TABLA ---------------------------

   [UI6.1.5]. El área táctil de 44×44 [FIJO] no cabe en una fila de 40 px, así
   que varios solo-icono en la misma fila tendrían áreas solapadas con las
   filas vecinas y en pantalla táctil eso produce pulsaciones en la fila
   equivocada. Las acciones de fila van a un disparador único de
   desbordamiento, que sí alcanza sus 44×44 porque es uno solo. Ver
   `<x-acciones-de-fila>`.
   =========================================================================== */

.boton {
  /* `inline-flex` y no `flex`: un botón mide lo que mide su etiqueta. */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--btn-gap);

  box-sizing: border-box;
  height: var(--control-h);
  min-width: var(--btn-min-w);
  max-width: var(--btn-max-w);
  padding: 0 var(--btn-pad-x);

  border: var(--border-width) solid transparent;
  border-radius: var(--radius-md);

  font-family: inherit;
  font-size: var(--fs-button);
  font-weight: var(--fw-button);
  /* Interlínea 1 y no 1.5: el texto se centra por la altura del control, y una
     interlínea mayor descentra la etiqueta respecto del icono ([UI3.2]). */
  line-height: var(--lh-button);
  text-align: center;
  text-decoration: none;

  /* LA ETIQUETA NO SE TRUNCA NUNCA Y NO AJUSTA A DOS LÍNEAS ([UI6.1.6]).
     «Generar paquete de pos…» no se puede entender, y a diferencia de una
     celda de tabla no hay detalle al que ir a mirar. Si una etiqueta no cabe
     en 320 px el problema es el texto: se reescribe según [UI8]. Por eso aquí
     no hay `overflow: hidden` — que truncaría — y el desborde se ve. */
  white-space: nowrap;

  cursor: pointer;
  position: relative;
  user-select: none;
  transition:
    background-color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out);
}

/* ---- EL ÁREA TÁCTIL DE 44×44, POR RELLENO INVISIBLE ----------------------
   [UI6.1.7] [FIJO]. Un botón de 32 px de alto sigue teniendo 44 px de
   objetivo: la zona crece hacia fuera sin mover el dibujo ni empujar al
   vecino, que es lo que haría un `padding` de verdad.

   `pointer-events: none` en el botón NO: lo que se amplía es el pseudo-elemento
   y el clic lo recibe el botón igual. Y va con `z-index: -1` para que no tape
   lo que esté encima. */
.boton::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: var(--touch-min);
  transform: translateY(-50%);
  min-width: var(--touch-min);
  z-index: -1;
}

/* ---- TAMAÑOS ---- */
.boton--sm {
  height: var(--control-h-sm);
  min-width: var(--btn-min-w-sm);
  padding: 0 var(--btn-pad-x-sm);
  font-size: var(--fs-button-sm);
}
.boton--lg {
  height: var(--control-h-lg);
  min-width: var(--btn-min-w-lg);
  padding: 0 var(--btn-pad-x-lg);
  font-size: var(--fs-button-lg);
}

/* El icono de cada tamaño es el DIBUJADO para ese tamaño ([UI6.12]): reducir
   uno de 24 adelgaza el trazo por debajo de un píxel y el icono se desvanece.
   Aquí solo se fija la caja. */
.boton .icono { width: var(--icon-sm); height: var(--icon-sm); flex: 0 0 auto; }
.boton--sm .icono { width: var(--icon-xs); height: var(--icon-xs); }
.boton--lg .icono { width: var(--icon-md); height: var(--icon-md); }

/* ---- PRIMARIO ---- */
.boton--primario {
  background-color: var(--accent);
  color: var(--on-accent);
}
.boton--primario:hover { background-color: var(--accent-hover); }
.boton--primario:active { background-color: var(--accent-pressed); }

/* ---- SECUNDARIO ---- */
.boton--secundario {
  background-color: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.boton--secundario:hover { background-color: var(--state-hover); }
.boton--secundario:active { background-color: var(--state-pressed); }

/* ---- SUTIL ---- */
.boton--sutil {
  background-color: transparent;
  color: var(--accent);
  /* Sin ancho mínimo: vive en una fila de tabla. El ancho lo da el contenido
     más el relleno chico ([UI6.1.1]). */
  min-width: 0;
  padding: 0 var(--btn-pad-x-sm);
}
.boton--sutil:hover { background-color: var(--state-hover); }
.boton--sutil:active { background-color: var(--state-pressed); }

/* ---- DESTRUCTIVO ---- */
.boton--destructivo {
  background-color: var(--danger);
  color: var(--on-danger);
}
.boton--destructivo:hover { background-color: var(--danger-hover); }
.boton--destructivo:active { background-color: var(--danger-pressed); }

/* ---- DESTRUCTIVO SUTIL ---- */
.boton--destructivo-sutil {
  background-color: transparent;
  color: var(--danger-text);
  min-width: 0;
  padding: 0 var(--btn-pad-x-sm);
}
.boton--destructivo-sutil:hover { background-color: var(--danger-soft); }
.boton--destructivo-sutil:active { background-color: var(--danger-soft); }

/* ---- FOCO [FIJO] --------------------------------------------------------
   Anillo SÓLIDO de 3 px en `--accent` con offset de 2 px, en todas las
   variantes incluida la destructiva: el foco señala dónde está el teclado, no
   de qué color es la acción.

   El halo translúcido de [UI4.5] es decoración y nunca el indicador — al 25 %
   da 1,47:1 por sí solo, medido. Y `outline: none` sin reemplazo está
   prohibido en todo el proyecto ([UI9]). */
.boton:focus-visible {
  outline: var(--focus-ring-w) solid var(--accent);
  outline-offset: var(--focus-ring-offset);
}

/* ---- DESHABILITADO ------------------------------------------------------
   Relleno, borde y texto con tokens PROPIOS, y NUNCA con `opacity`: un texto
   al 45 % sobre blanco da 2,72:1 mientras el token sólido da 3,58 ([UI4.5]).
   Mismo aspecto, distinto resultado.

   `--btn-disabled-text` es `#767A81` y no `--text-disabled`, porque sobre el
   relleno `#E8EAED` ese cae a 2,59 — el fondo deja de ser blanco. WCAG exime a
   los controles inactivos del umbral, pero el usuario tiene que poder leer QUÉ
   botón está apagado. */
.boton[disabled],
.boton[aria-disabled="true"] {
  background-color: var(--btn-disabled-bg);
  color: var(--btn-disabled-text);
  border-color: transparent;
  cursor: not-allowed;
}
.boton--secundario[disabled],
.boton--secundario[aria-disabled="true"] {
  /* El control inactivo CONSERVA su contorno: la señal de apagado la dan el
     relleno y el texto. Un control sin contorno deja de leerse como control. */
  border-color: var(--btn-disabled-border);
}
.boton--sutil[disabled],
.boton--sutil[aria-disabled="true"],
.boton--destructivo-sutil[disabled],
.boton--destructivo-sutil[aria-disabled="true"] {
  background-color: transparent;
  border-color: transparent;
}

/* El motivo por el que está apagado, a la vista y en texto ([UI6.1.7]). No es
   un tooltip: un tooltip no existe en una pantalla táctil. */
.boton-motivo {
  display: block;
  margin-top: var(--sp-1);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  line-height: var(--lh-xs);
  max-width: var(--btn-max-w);
  white-space: normal;
}

/* Un botón que dispara una operación lenta lo dice. El `disabled` lo pone el
   servidor, no el script: si el JS no corre, el botón queda habilitado y
   rechaza el servidor, que es el lado barato del fallo. */
.boton[aria-busy="true"] { cursor: progress; }

/* ---- GRUPOS Y ORDEN ----------------------------------------------------
   [UI6.1.5]. El primario va a la DERECHA: es el final del recorrido de lectura
   y coincide con la acción primaria que [UI5.2] sitúa arriba a la derecha.
   Máximo tres visibles; el resto, al desbordamiento. */
.boton-grupo {
  display: flex;
  align-items: center;
  gap: var(--btn-gap-group);
  flex-wrap: wrap;
}
.boton-grupo + .boton-grupo { margin-left: var(--btn-gap-between-groups); }

/* El destructivo nunca queda pegado al primario: en un pie de modal va a la
   izquierda del todo, separado por el espacio flexible. */
.boton-grupo--pie { justify-content: flex-end; }
.boton-grupo--pie .boton--destructivo,
.boton-grupo--pie .boton--destructivo-sutil { margin-right: auto; }

/* ---- MÓVIL, POR DEBAJO DE `sm` ([UI6.1.6]) ----------------------------
   Los botones de pie de formulario y de modal pasan a ancho completo y se
   apilan con 8 px, el primario arriba. Los de fila de tabla y de barra de
   herramientas NO: conservan su ancho automático, porque a ancho completo una
   fila de tabla se convertiría en una columna de botones. */
/* 639 px escrito a mano, y es la ÚNICA medida suelta de este archivo: una
   consulta de medios NO puede leer una variable CSS —`@media (max-width:
   var(--bp-sm))` no funciona en ningún navegador— así que el punto de quiebre
   de [UI5.1] no se puede tokenizar. Es 639 y no 640 porque `--bp-sm` es el
   primer ancho en que YA no aplica. Queda anotado en README-ui.md. */
@media (max-width: 639px) {
  .boton-grupo--pie {
    flex-direction: column-reverse; /* el primario, que va último, queda arriba */
    align-items: stretch;
  }
  .boton-grupo--pie .boton { width: 100%; max-width: none; }
  .boton-grupo--pie .boton--destructivo,
  .boton-grupo--pie .boton--destructivo-sutil { margin-right: 0; }
}

/* ===========================================================================
   ACCIONES DE FILA: UN DISPARADOR ÚNICO DE DESBORDAMIENTO — [UI6.1.5]
   ===========================================================================
   `<details>`/`<summary>` y no un menú de JS: [UI9] exige que toda función
   crítica funcione sin JavaScript, y un `<details>` ya trae teclado, foco y
   anuncio de estado resueltos por el navegador.
   =========================================================================== */
.acciones-fila { position: relative; display: inline-block; }

.acciones-fila > summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* AQUÍ SÍ hay 44×44 de verdad y no por relleno invisible: es UNO solo por
     fila, así que no compite con las filas vecinas. Era el argumento entero de
     la decisión de [UI6.1.5]. */
  width: var(--touch-min);
  height: var(--touch-min);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  cursor: pointer;
  list-style: none;
}
.acciones-fila > summary::-webkit-details-marker { display: none; }
.acciones-fila > summary:hover { background-color: var(--state-hover); color: var(--text); }
.acciones-fila > summary:focus-visible {
  outline: var(--focus-ring-w) solid var(--accent);
  outline-offset: var(--focus-ring-offset);
}

.acciones-fila__menu {
  position: absolute;
  right: 0;
  z-index: var(--z-dropdown);
  min-width: var(--menu-min-w);
  margin-top: var(--sp-1);
  padding: var(--sp-1);
  background-color: var(--surface);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius-md);
  /* Nivel 2: un desplegable flota sobre el contenido ([UI4.3]). */
  box-shadow: var(--shadow-2);
}
/* Abierto con JavaScript, el panel flota contra la ventana y no contra la
   tabla: así no lo recorta un envoltorio con `overflow`. Lo coloca
   `interfaz.js`; si hay muchas opciones, se desplaza dentro. */
.acciones-fila__menu--flotante {
  position: fixed;
  right: auto;
  margin-top: 0;
  max-height: calc(100vh - var(--sp-4));
  overflow-y: auto;
}
.acciones-fila__menu .boton {
  display: flex;
  justify-content: flex-start;
  width: 100%;
  min-width: 0;
  max-width: none;
}

/* El botón y su motivo son una unidad: el motivo no puede quedarse en otro
   sitio de la pantalla, porque entonces el botón apagado vuelve a ser mudo. */
.boton-con-motivo { display: inline-block; }

/* ===========================================================================
   EL «?» Y EL «NO APLICA» DE UN DOCUMENTO — 31-10-2026 (`x-papel`)
   =========================================================================== */
/* El «?» no baja solo a la línea siguiente: `nowrap` aquí y un U+2060 (`&NoBreak;`)
   entre el título y `x-papel` lo dejan pegado a la última palabra. */
.papel { display: inline; white-space: nowrap; }
.papel > * { margin-left: var(--sp-1); vertical-align: middle; }
.papel-fila .k-lista__titulo { display: inline; }
.papel__menu { position: relative; display: inline-block; }
/* Las filas y paneles que siguen se pintan encima: el que tiene el globo abierto
   sube sobre sus vecinos. */
:is(.k-panel, .k-rejilla, .k-tarjeta, .k-lista > li, .req, .bloque):has(.papel__menu[open]) {
  position: relative;
  z-index: var(--z-dropdown);
}
.papel__menu > summary { cursor: pointer; list-style: none; }
.papel__menu > summary::-webkit-details-marker { display: none; }
.papel__menu > summary:focus-visible {
  outline: var(--focus-ring-w) solid var(--accent);
  outline-offset: var(--focus-ring-offset);
}
.papel__ayuda {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.375rem;
  height: 1.375rem;
  border: var(--border-width) solid var(--border);
  border-radius: 50%;
  color: var(--text-muted);
  font-size: .75rem;
  font-weight: 600;
  line-height: 1;
}
.papel__ayuda:hover { background-color: var(--state-hover); color: var(--text); }
/* El `form-switch` de Tabler sobre un botón: `:checked` no existe aquí, así que
   encendido («lo necesito») es `aria-checked="false"`. Ver `x-papel`. Las medidas
   son las de Tabler, iguales en todas las filas. */
.papel__caja.form-check.form-switch {
  display: inline-flex;
  min-height: 0;
  margin-bottom: 0;
  padding: 0;
  vertical-align: middle;
}
.form-switch .form-check-input.papel__switch {
  --tblr-form-switch-color: var(--neutro-0);
  float: none;
  margin: 0;
  padding: 0;
  border-color: transparent;
  background-color: var(--border-strong);
  box-shadow: none;
  cursor: pointer;
  transition: background-color var(--dur-base) ease;
}
.form-switch .form-check-input.papel__switch::before {
  box-shadow: var(--shadow-1);
  transition: inset-inline-start var(--dur-base) ease;
}
.form-switch .form-check-input.papel__switch[aria-checked="false"] { background-color: var(--accent); }
.form-switch .form-check-input.papel__switch[aria-checked="false"]::before {
  inset-inline-start: calc(100% - var(--tblr-form-switch-knob-size) - var(--tblr-form-switch-knob-offset));
}
.form-switch .form-check-input.papel__switch:focus-visible {
  outline: var(--focus-ring-w) solid var(--accent);
  outline-offset: var(--focus-ring-offset);
}
.papel__motivo { display: flex; gap: var(--sp-2); align-items: center; margin-top: var(--sp-1); }
.papel__motivo input { flex: 1; min-width: 0; }
/* Las columnas de una fila: anchas fijas para que queden en línea vertical.
   Con dos clases porque `kit.css` carga después y `.k-lista__fin` es flex. */
.papel-cols, .k-lista__fin.papel-cols {
  display: grid;
  grid-template-columns: var(--papel-col-interruptor) var(--papel-col-estado) var(--papel-col-accion);
  gap: var(--sp-2);
  align-items: center;
}
.papel-cols--requisito {
  grid-template-columns: var(--papel-col-interruptor) var(--papel-col-estado) var(--papel-col-accion-larga);
}
.papel-col { min-width: 0; }
.papel-col--interruptor { justify-self: center; }
.papel-col--estado { justify-self: start; }
.papel-col--accion { display: flex; justify-content: flex-end; width: 100%; }
.papel-col--accion .boton { width: 100%; justify-content: flex-end; }
/* Aquí el botón lleva borde: estirado sería una caja vacía con el texto al final. */
.papel-cols--requisito .papel-col--accion .boton { width: auto; }
.papel-col .papel > * { margin-left: 0; }
.k-lista > li:has(.papel-cols) .k-lista__titulo { white-space: normal; }
.k-lista > li.papel-cabeza { padding-top: 0; padding-bottom: 0; }
.k-lista > li.papel-cabeza:hover { background: none; }
.papel-cabeza .papel-col {
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: 500;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  white-space: nowrap;
}
/* En el teléfono no caben nombre, interruptor, estado y botón en una línea. */
@media (max-width: 639px) {
  .papel-cols, .k-lista__fin.papel-cols { display: flex; justify-content: flex-end; }
  .papel-col--accion { width: auto; }
  .papel-col--accion .boton { width: auto; }
  .k-lista > li.papel-cabeza { display: none; }
  .k-lista > li:has(.papel) { flex-wrap: wrap; }
  .k-lista > li:has(.papel) .k-lista__titulo { white-space: normal; }
  .k-lista > li:has(.papel) .k-lista__fin { flex: 1 0 100%; justify-content: flex-end; }
  /* Y en un requisito, la nota de las bases no se puede quedar sin ancho. */
  .req > summary:has(.papel, .papel__nota) { flex-wrap: wrap; }
  .req > summary:has(.papel, .papel__nota) .req__nombre { flex-basis: 100%; white-space: normal; }
  .req > summary:has(.papel, .papel__nota) .req__acciones { flex: 1 0 100%; justify-content: flex-end; }
}
@media (prefers-reduced-motion: reduce) {
  .form-switch .form-check-input.papel__switch,
  .form-switch .form-check-input.papel__switch::before { transition: none; }
}
.papel__globo {
  width: min(20rem, calc(100vw - var(--sp-8)));
  padding: var(--sp-3);
  color: var(--text);
  font-size: .875rem;
  font-weight: 400;
  line-height: 1.45;
  text-align: left;
  white-space: normal;
  cursor: auto;
}
.acciones-fila__menu.papel__globo { display: block; }
/* Gana a `.acciones-fila__menu a`: aquí un enlace es un botón secundario entero. */
.acciones-fila__menu.papel__globo a.papel__enlace {
  display: flex;
  justify-content: center;
  width: 100%;
  min-height: var(--touch-min);
  margin-top: var(--sp-2);
}
.papel__linea { display: block; margin-top: var(--sp-2); }
.papel__aclara { color: var(--text-muted); }
/* En pantalla táctil, los dos controles chicos crecen por relleno invisible. */
@media (pointer: coarse) {
  .papel__ayuda { position: relative; }
  .papel__ayuda::after,
  .form-switch .form-check-input.papel__switch::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: var(--touch-min);
    height: var(--touch-min);
    transform: translate(-50%, -50%);
  }
}
.papel__nota { display: block; margin-top: var(--sp-1); color: var(--danger-text); font-weight: 600; }
