/* Lo mínimo que necesitan los JS de djangom/ui (nucleo.js y los que le siguen): avisos flotantes, errores por campo,
   resumen de errores, diálogos y confirmación, botón ocupado y centinelas del foco. Estado: en incubación.
   Sin marca: colores en tokens --dm-* con un valor neutro de respaldo; el proyecto (o ui.css) los define en su :root.
   El resto de los componentes (dm-btn, dm-campo, dm-form…) vive en ui.css. */

/* ---------- Avisos flotantes (.dm-toasts > .dm-toast[data-tono]) ---------- */
.dm-toasts {
  position: fixed; z-index: 1000; right: 16px; bottom: 16px; left: auto;
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
  max-width: min(440px, calc(100vw - 32px)); pointer-events: none;
}
dialog > .dm-toasts { position: sticky; right: auto; bottom: 0; margin-top: 12px; max-width: none; align-items: stretch; }
.dm-toast {
  pointer-events: auto; display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 10px 10px 12px; border: 0; border-radius: var(--dm-radio, 10px);
  background: var(--dm-superficie, #fff); color: var(--dm-tinta, #18202b);
  box-shadow: var(--dm-sombra-3, 0 18px 48px rgba(0, 0, 0, .22)); font-size: 13.5px; line-height: 1.45;
}
/* El tono lo dice el punto de color: el aviso flota sobre cualquier fondo y un tinte en alfa se perdería. */
.dm-toast::before { content: ""; flex: none; width: 8px; height: 8px; margin-top: 6px; border-radius: 50%;
  background: var(--dm-bien-tinta, #166534); }
.dm-toast[data-tono="aviso"]::before { background: var(--dm-aviso-tinta, #9a4a06); }
.dm-toast[data-tono="error"]::before { background: var(--dm-error-tinta, #c2261c); }
.dm-toast[data-tono="info"]::before { background: var(--dm-info-tinta, #1d4ed8); }
.dm-toast-texto { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.dm-toast-accion {
  flex: none; font: inherit; font-weight: 600; background: none; cursor: pointer;
  border: 0; border-radius: var(--dm-radio-chico, 6px); padding: 2px 8px; color: var(--dm-primario, #1d4ed8);
}
.dm-toast-x {
  flex: none; display: inline-grid; place-items: center; width: 28px; height: 28px; margin: -4px -4px -4px 0;
  border: 0; border-radius: 50%; background: none; color: inherit; cursor: pointer;
}
.dm-toast-x { color: var(--dm-tenue, #5a6472); }
.dm-toast-x:hover, .dm-toast-accion:hover { background: var(--dm-hover, rgba(0, 0, 0, .04)); }
@media (max-width: 500px) {
  .dm-toasts { right: 8px; left: 8px; bottom: 8px; max-width: none; align-items: stretch; }
}
/* Entrada y salida (curva ease-out de la skill de movimiento). Transiciones y no keyframes: un aviso que se cierra
   mientras entra sale desde donde iba. nucleo.js marca la salida con data-dm-saliendo, fija antes el alto en línea y
   quita el aviso al terminar; el alto baja a cero y el margen negativo se come el gap de .dm-toasts (8 px), así los
   vecinos se acomodan sin saltar. Con movimiento reducido, solo opacidad (los vecinos sí saltan al final). */
.dm-toast { transition: opacity .2s var(--dm-curva, cubic-bezier(.23, 1, .32, 1)), transform .2s var(--dm-curva, cubic-bezier(.23, 1, .32, 1)); }
@starting-style { .dm-toast { opacity: 0; } }
.dm-toast[data-dm-saliendo] { opacity: 0; overflow: hidden; pointer-events: none;
  transition: opacity .15s var(--dm-curva, cubic-bezier(.23, 1, .32, 1)), height .15s var(--dm-curva, cubic-bezier(.23, 1, .32, 1)),
    padding .15s var(--dm-curva, cubic-bezier(.23, 1, .32, 1)), margin .15s var(--dm-curva, cubic-bezier(.23, 1, .32, 1)),
    border-width .15s var(--dm-curva, cubic-bezier(.23, 1, .32, 1)); }
@media (prefers-reduced-motion: no-preference) {
  @starting-style { .dm-toast { transform: translateY(8px); } }
  .dm-toast[data-dm-saliendo] { height: 0 !important; padding-block: 0; border-block-width: 0; margin-bottom: -8px; }
}

/* ---------- Errores por campo y resumen ---------- */
.dm-con-error :is(input, select, textarea), [aria-invalid="true"] { border-color: var(--dm-error-tinta, #c2261c); }
ul.dm-errores[data-dm-error] { list-style: none; margin: 4px 0 0; padding: 0; font-size: 13px; color: var(--dm-error-tinta, #c2261c); }
.dm-resumen-errores {
  margin: 0 0 14px; padding: 10px 14px; border: 0; border-radius: var(--dm-radio, 10px);
  background: var(--dm-error-fondo, #fdf0f0); color: var(--dm-error-tinta, #c2261c); font-size: 13.5px;
}
.dm-resumen-errores:focus { outline: 2px solid var(--dm-error-tinta, #c2261c); outline-offset: 2px; }
.dm-resumen-errores p { margin: 0; }
.dm-resumen-errores .dm-resumen-general + .dm-resumen-titulo { margin-top: 6px; }
.dm-resumen-titulo { font-weight: 600; }
.dm-resumen-errores ul { margin: 6px 0 0; padding-left: 20px; }
.dm-resumen-errores a { color: inherit; text-decoration: underline; }
.dm-aviso-borrador {
  margin: 0 0 14px; padding: 10px 14px; border: 0; border-radius: var(--dm-radio, 10px);
  background: var(--dm-aviso-fondo, #fdf6ea); color: var(--dm-aviso-tinta, #9a4a06); font-size: 13.5px;
}

/* ---------- Diálogos ---------- */
dialog.dm-dialogo, dialog.dm-confirmar {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: auto; margin: auto; /* centrado aunque un reset le quite el margin del navegador */
  padding: 22px; border: 0; border-radius: var(--dm-radio-grande, 14px);
  background: var(--dm-superficie, #fff); color: var(--dm-tinta, #18202b);
  box-shadow: var(--dm-sombra-3, 0 18px 48px rgba(0, 0, 0, .22));
}
dialog.dm-confirmar { width: min(420px, calc(100vw - 24px)); }
/* Abre en 200 ms y cierra en 150 ms. display y overlay discretos mantienen el diálogo en la capa superior mientras
   sale tras dialog.close(); el evento close, el foco y Esc no cambian. Sin @starting-style ni allow-discrete (Safari
   antes de 17.4) la declaración no vale y abre y cierra sin animar. Con movimiento reducido, solo opacidad. */
dialog.dm-dialogo, dialog.dm-confirmar {
  opacity: 0;
  transition: opacity .15s var(--dm-curva, cubic-bezier(.23, 1, .32, 1)), transform .15s var(--dm-curva, cubic-bezier(.23, 1, .32, 1)),
    overlay .15s allow-discrete, display .15s allow-discrete;
}
dialog.dm-dialogo[open], dialog.dm-confirmar[open] { opacity: 1; transition-duration: .2s; }
@starting-style { dialog.dm-dialogo[open], dialog.dm-confirmar[open] { opacity: 0; } }
dialog.dm-dialogo::backdrop, dialog.dm-confirmar::backdrop {
  background: rgb(15 23 42 / .4); opacity: 0;
  transition: opacity .15s var(--dm-curva, cubic-bezier(.23, 1, .32, 1)), overlay .15s allow-discrete, display .15s allow-discrete;
}
dialog.dm-dialogo[open]::backdrop, dialog.dm-confirmar[open]::backdrop { opacity: 1; transition-duration: .2s; }
@starting-style { dialog.dm-dialogo[open]::backdrop, dialog.dm-confirmar[open]::backdrop { opacity: 0; } }
@media (prefers-reduced-motion: no-preference) {
  dialog.dm-dialogo, dialog.dm-confirmar { transform: scale(.96); }
  dialog.dm-dialogo[open], dialog.dm-confirmar[open] { transform: none; }
  @starting-style { dialog.dm-dialogo[open], dialog.dm-confirmar[open] { transform: scale(.96); } }
}
.dm-confirmar h2 { margin: 0 0 6px; font-size: 16px; font-weight: 650; letter-spacing: -.01em; }
.dm-confirmar p { margin: 0 0 18px; color: var(--dm-tenue, #5a6472); }
.dm-confirmar-pie { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
/* Centinelas del foco atrapado: enfocables pero sin ocupar lugar ni verse. */
.dm-centinela { position: fixed; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- Botón ocupado (un solo envío, descargas) ---------- */
.dm-ocupado, [aria-busy="true"] > .dm-ocupado { cursor: progress; opacity: .7; }
.dm-ocupado::after {
  content: ""; display: inline-block; width: .9em; height: .9em; margin-left: 8px; vertical-align: -.1em;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: dm-girar .8s linear infinite;
}
@keyframes dm-girar { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .dm-ocupado::after { animation: none; } }

/* ---------- Filas enlace ---------- */
tr[data-href] { cursor: pointer; }

/* ---------- Autocompletar (autocompletar.js) ---------- */
.dm-autocompletar { position: relative; min-width: 0; }
.dm-autocompletar > input[data-dm-autocompletar] { width: 100%; }
.dm-autocompletar-lista {
  position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; right: 0; max-height: 280px; overflow-y: auto;
  margin: 0; padding: 4px; list-style: none; border: 0;
  border-radius: var(--dm-radio, 10px); background: var(--dm-superficie, #fff);
  box-shadow: var(--dm-sombra-2, 0 10px 28px rgba(0, 0, 0, .14));
}
.dm-autocompletar-opcion { display: grid; gap: 2px; padding: 8px 10px; border-radius: var(--dm-radio-chico, 6px);
  cursor: pointer; overflow-wrap: anywhere; }
.dm-autocompletar-opcion:hover { background: var(--dm-hover, #f4f6f6); }
/* La opción activa del teclado: fondo de selección y barra del primario a la izquierda (se ve sin depender del color). */
.dm-autocompletar-opcion[aria-selected="true"] { background: var(--dm-seleccion, #e6effc);
  box-shadow: inset 2px 0 0 var(--dm-primario, #1d4ed8); }
.dm-autocompletar-detalle { color: var(--dm-tenue, #5a6472); font-size: 12.5px; }
.dm-autocompletar-vacio { padding: 8px 10px; color: var(--dm-tenue, #5a6472); font-size: 13px; }
.dm-autocompletar-estado { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (pointer: coarse) { .dm-autocompletar-opcion { min-height: 44px; } }

/* Alto contraste: las sombras desaparecen; la opción activa, los avisos y los diálogos recuperan un contorno. */
@media (forced-colors: active) {
  .dm-autocompletar-opcion[aria-selected="true"] { outline: 2px solid Highlight; outline-offset: -2px; }
  .dm-toast, .dm-autocompletar-lista, dialog.dm-dialogo, dialog.dm-confirmar { border: 1px solid CanvasText; }
}
