/* SICAS Core — movimiento, carga y mensajes (20261115).
   Se carga al final: completa lo existente sin reescribirlo. Reglas:
   - transiciones para estados interactivos, keyframes solo para secuencias de una vez;
   - se anima solo transform/opacity; nada de `transition: all`;
   - los keyframes de entrada usan fill-mode «backwards»: al terminar no dejan transform residual (no crean contexto de apilado);
   - todo tiene salida para prefers-reduced-motion al final del archivo. */

:root {
  --mo-ease: cubic-bezier(.2, 0, 0, 1);
  --mo-ease-in: cubic-bezier(.4, 0, 1, 1);
  --mo-fast: 140ms;
  --mo-med: 240ms;
  --mo-slow: 420ms;
  --mo-ok: #168267; --mo-err: #b54444; --mo-warn: #a96e16; --mo-info: #294b70;
}

/* ------------------------------------------------------------------ Pantalla de arranque */
#boot { position: fixed; inset: 0; z-index: 10002; display: grid; place-items: center; background: var(--cc-sidebar, #172b46);
  background-image: radial-gradient(900px 520px at 20% -10%, #2b4d78 0%, transparent 60%), radial-gradient(800px 480px at 100% 110%, #1d5f66 0%, transparent 55%);
  transition: opacity var(--mo-slow) var(--mo-ease), visibility 0s linear var(--mo-slow);
  /* guarda: si el script no llega a retirarla, desaparece sola a los 6 s */
  animation: boot-failsafe .4s ease 6s forwards; }
#boot.out { opacity: 0; visibility: hidden; }
.boot-card { display: grid; justify-items: center; gap: 10px; color: #d7e1ee; animation: mo-rise var(--mo-slow) var(--mo-ease) backwards; }
.boot-card img { width: 56px; height: 56px; border-radius: 14px; animation: boot-breathe 2.2s ease-in-out infinite; }
.boot-name { margin: 6px 0 0; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; font-size: .86rem; color: #fff; }
.boot-text { margin: 0; font-size: .82rem; color: #94a8c1; }
.boot-bar { position: relative; width: 140px; height: 3px; border-radius: 3px; overflow: hidden; background: rgba(255, 255, 255, .14); }
.boot-bar::before { content: ""; position: absolute; inset: 0; width: 45%; border-radius: inherit;
  background: linear-gradient(90deg, transparent, #6fb3ff, #5ecbc4, transparent); animation: boot-slide 1.2s var(--mo-ease) infinite; }
body.booting > main, body.booting > #topbar { visibility: hidden; animation: boot-reveal .01s 6s forwards; }   /* sin parpadeo del login; la guarda lo revela a los 6 s */
@keyframes boot-reveal { to { visibility: visible; } }
@keyframes boot-failsafe { to { opacity: 0; visibility: hidden; } }
@keyframes boot-breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
@keyframes boot-slide { from { transform: translateX(-110%); } to { transform: translateX(320%); } }

/* ------------------------------------------------------------------ Entradas de pantalla */
@keyframes mo-rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes mo-fade { from { opacity: 0; } to { opacity: 1; } }

/* Contenido de una pantalla: aparece en bloques escalonados (los primeros ocho) en lugar de todo de golpe. */
.sicas-page-enter { animation: none; }
.sicas-page-enter > * { animation: mo-rise var(--mo-slow) var(--mo-ease) backwards; }
.sicas-page-enter > :nth-child(2) { animation-delay: 45ms; }
.sicas-page-enter > :nth-child(3) { animation-delay: 90ms; }
.sicas-page-enter > :nth-child(4) { animation-delay: 135ms; }
.sicas-page-enter > :nth-child(5) { animation-delay: 180ms; }
.sicas-page-enter > :nth-child(6) { animation-delay: 225ms; }
.sicas-page-enter > :nth-child(7) { animation-delay: 270ms; }
.sicas-page-enter > :nth-child(n+8) { animation-delay: 300ms; }

/* Paso entre ingreso y aplicación */
#view-app:not(.hidden) { animation: mo-fade var(--mo-slow) var(--mo-ease) backwards; }
#view-app:not(.hidden) #sidenav { animation: mo-nav var(--mo-slow) var(--mo-ease) backwards; }
@keyframes mo-nav { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: none; } }
#view-login:not(.hidden), #view-change:not(.hidden), #view-enroll:not(.hidden), #view-mfa:not(.hidden) { animation: mo-rise var(--mo-slow) var(--mo-ease) backwards; }

/* ------------------------------------------------------------------ Botones y controles */
button, input[type="button"], input[type="submit"], input[type="reset"] {
  transition: background-color var(--mo-fast) ease, border-color var(--mo-fast) ease, color var(--mo-fast) ease,
              box-shadow var(--mo-fast) ease, transform var(--mo-fast) ease, scale 120ms var(--mo-ease), opacity var(--mo-fast) ease; }
button:active:not(:disabled):not(.is-loading), input[type="button"]:active:not(:disabled), input[type="submit"]:active:not(:disabled) { scale: .97; }
button:disabled { cursor: not-allowed; }
button.is-loading { cursor: progress; }

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible { outline: 3px solid rgba(47, 109, 181, .45); outline-offset: 2px; }
:where(input, select, textarea) { transition: border-color var(--mo-fast) ease, box-shadow var(--mo-fast) ease, background-color var(--mo-fast) ease; }

/* Filas de tablas: el resaltado entra y sale suave */
tbody tr td, tr.clickable td { transition: background-color var(--mo-fast) ease; }

/* Pestañas y menú lateral */
#sidenav button { transition: background-color var(--mo-fast) ease, color var(--mo-fast) ease, box-shadow var(--mo-fast) ease, transform var(--mo-fast) var(--mo-ease), scale 120ms var(--mo-ease); }
@media (hover: hover) {  }

/* Tarjetas y paneles: elevación sutil solo en las que se pueden pulsar */
.card, .panel { transition: box-shadow var(--mo-med) ease, transform var(--mo-med) var(--mo-ease); }
@media (hover: hover) { .card.clickable:hover, .panel.clickable:hover { box-shadow: 0 10px 26px rgba(25, 40, 59, .1); transform: translateY(-2px); } }

/* Desplegables: el contenido aparece al abrir */
details[open] > :not(summary) { animation: mo-rise var(--mo-med) var(--mo-ease) backwards; }
summary { transition: color var(--mo-fast) ease; }

/* Insignias y avisos en línea que aparecen en la pantalla */
.badge { transition: background-color var(--mo-fast) ease, color var(--mo-fast) ease; }
.warn { animation: mo-rise var(--mo-med) var(--mo-ease) backwards; }
.hint, .muted { transition: color var(--mo-fast) ease; }

/* ------------------------------------------------------------------ Diálogos */
.overlay { animation: mo-fade var(--mo-med) ease backwards; backdrop-filter: blur(2px); }
.overlay > .modal { animation: mo-modal var(--mo-med) var(--mo-ease) backwards; }
.overlay.closing { animation: mo-fade-out 150ms var(--mo-ease-in) forwards; pointer-events: none; }
.overlay.closing > .modal { animation: mo-modal-out 150ms var(--mo-ease-in) forwards; }
@keyframes mo-modal { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes mo-modal-out { to { opacity: 0; transform: translateY(-8px) scale(.99); } }
@keyframes mo-fade-out { to { opacity: 0; } }

/* ------------------------------------------------------------------ Avisos (toasts) */
#msg { display: none; }
#toasts { position: fixed; z-index: 10001; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 10px;
  width: min(380px, calc(100vw - 32px)); pointer-events: none; }
#toasts .toast { position: relative; overflow: hidden; display: grid; grid-template-columns: auto 1fr auto; align-items: start; gap: 10px;
  padding: 12px 10px 14px 12px; border-radius: 13px; background: #fff; color: var(--cc-ink, #19283b); pointer-events: auto;
  border: 1px solid var(--cc-line, #e0e7ef); box-shadow: 0 14px 34px rgba(25, 40, 59, .22), 0 2px 6px rgba(25, 40, 59, .08);
  animation: toast-in var(--mo-med) var(--mo-ease) backwards; --tone: var(--mo-info); }
#toasts .toast.ok { --tone: var(--mo-ok); } #toasts .toast.err { --tone: var(--mo-err); } #toasts .toast.warn { --tone: var(--mo-warn); }
#toasts .toast::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--tone); }
#toasts .toast-ico { display: grid; place-items: center; width: 28px; height: 28px; margin-left: 4px; border-radius: 50%;
  color: var(--tone); background: color-mix(in srgb, var(--tone) 12%, #fff); }
#toasts .toast-ico svg { width: 17px; height: 17px; }
#toasts .toast.ok .toast-ico svg path { stroke-dasharray: 24; stroke-dashoffset: 24; animation: toast-draw .45s .12s var(--mo-ease) forwards; }
#toasts .toast-text { padding-top: 3px; font-size: .9rem; line-height: 1.4; font-weight: 550; overflow-wrap: anywhere; text-wrap: pretty; }
#toasts .toast-x { all: unset; box-sizing: border-box; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px;
  font-size: 1.25rem; line-height: 1; color: #69798d; cursor: pointer; transition: background-color var(--mo-fast) ease, color var(--mo-fast) ease, scale 120ms var(--mo-ease); }
#toasts .toast-x:hover { background: #eef2f7; color: var(--cc-ink, #19283b); }
#toasts .toast-x:active { scale: .92; }
#toasts .toast-x:focus-visible { outline: 3px solid rgba(47, 109, 181, .45); outline-offset: 1px; }
#toasts .toast-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--tone); opacity: .55; transform-origin: left;
  animation: toast-life var(--life, 6s) linear forwards; }
#toasts .toast.paused .toast-bar { animation-play-state: paused; }
#toasts .toast.bump { animation: toast-bump 280ms var(--mo-ease); }
#toasts .toast.leaving { animation: toast-out 180ms var(--mo-ease-in) forwards; pointer-events: none; }
@keyframes toast-in { from { opacity: 0; transform: translateY(16px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(24px) scale(.98); } }
@keyframes toast-bump { 0% { transform: none; } 35% { transform: translateX(-5px); } 70% { transform: translateX(3px); } 100% { transform: none; } }
@keyframes toast-life { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@keyframes toast-draw { to { stroke-dashoffset: 0; } }
@media (max-width: 640px) { #toasts { right: 16px; left: 16px; bottom: 12px; width: auto; } }

/* ------------------------------------------------------------------ Carga */
#sicas-loadbar { height: 3px; transition: opacity .25s ease; }
#sicas-loadbar::before { animation-timing-function: var(--mo-ease); }
.sicas-loading { animation: mo-fade var(--mo-med) ease backwards; animation-delay: 80ms; }   /* si responde rápido, ni se llega a ver */
.sicas-skeleton { max-width: 1100px; }
.sicas-skeleton .sk { border-radius: 9px; background: linear-gradient(100deg, #e7edf4 30%, #f6f9fc 50%, #e7edf4 70%); background-size: 300% 100%;
  animation: mo-shimmer 1.5s linear infinite; }
.sicas-skeleton .sk-title { height: 28px; width: 34%; } .sicas-skeleton .sk-line { height: 14px; width: 56%; }
.sk-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin: 8px 0 6px; }
.sk-cards .sk-card { height: 96px; border-radius: 13px; }
.sk-table { display: grid; gap: 9px; padding: 14px; border-radius: 13px; background: #fff; border: 1px solid var(--cc-line, #e0e7ef); }
.sk-table .sk-row { height: 16px; width: 100%; } .sk-table .sk-row.head { height: 20px; width: 60%; } .sk-table .sk-row.short { width: 44%; }
.sk-cards .sk:nth-child(2) { animation-delay: .1s; } .sk-cards .sk:nth-child(3) { animation-delay: .2s; } .sk-cards .sk:nth-child(4) { animation-delay: .3s; }
@keyframes mo-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* ------------------------------------------------------------------ Estado de error de una pantalla */
.sicas-error { display: grid; justify-items: center; gap: 8px; max-width: 520px; margin: clamp(24px, 7vh, 72px) auto; padding: 32px 26px 26px; text-align: center;
  background: #fff; border: 1px solid var(--cc-line, #e0e7ef); border-radius: 18px; box-shadow: var(--cc-shadow, 0 5px 22px rgba(25, 40, 59, .055));
  animation: mo-rise var(--mo-slow) var(--mo-ease) backwards; }
.sicas-error-ico { display: grid; place-items: center; width: 64px; height: 64px; border-radius: 50%; color: var(--mo-err);
  background: linear-gradient(160deg, #fdeeee, #f9dede); animation: err-wobble .6s .15s var(--mo-ease) backwards; }
.sicas-error-ico svg { width: 30px; height: 30px; }
/* !important: algunas vistas (p. ej. «general») estilizan sus h3 con más especificidad y dibujan un subrayado. */
#page .sicas-error h3 { margin: 8px 0 0 !important; padding: 0 !important; border: 0 !important; background: none !important; font-size: 1.15rem; }
.sicas-error p { margin: 0 0 8px; color: var(--cc-muted, #69798d); line-height: 1.5; max-width: 42ch; text-wrap: pretty; }
.sicas-error .row.center { justify-content: center; flex-wrap: wrap; }
#page .sicas-error .sicas-error-detail { margin-top: 10px; width: 100%; padding: 0; border: 0; background: none; box-shadow: none; text-align: left; font-size: .8rem; color: var(--cc-muted, #69798d); }
#page .sicas-error .sicas-error-detail summary { display: list-item; padding: 2px 0; border: 0; background: none; cursor: pointer; font-weight: 600; color: var(--cc-brand, #294b70); }
.sicas-error-detail code { display: block; margin-top: 6px; padding: 8px 10px; border-radius: 8px; background: #f3f6fa; overflow-wrap: anywhere; user-select: all; }
@keyframes err-wobble { 0% { transform: scale(.6) rotate(-10deg); opacity: 0; } 60% { transform: scale(1.06) rotate(3deg); opacity: 1; } 100% { transform: none; } }

/* ------------------------------------------------------------------ Menos movimiento */
@media (prefers-reduced-motion: reduce) {
  body.booting > main, body.booting > #topbar, #boot, .boot-card, .boot-card img, .boot-bar::before, #view-app, #view-app #sidenav, #view-login, #view-change, #view-enroll, #view-mfa,
  .sicas-page-enter > *, details[open] > :not(summary), .warn, .overlay, .overlay > .modal, .sicas-loading, .sicas-skeleton .sk,
  #toasts .toast, #toasts .toast-ico path, #toasts .toast-bar, .sicas-error, .sicas-error-ico { animation: none !important; }
  #toasts .toast.ok .toast-ico svg path { stroke-dashoffset: 0; }
  #toasts .toast-bar { transform: none; }
  #sidenav button:hover:not(:disabled):not(.active), .card.clickable:hover, .panel.clickable:hover { transform: none; }
  button:active:not(:disabled), input[type="button"]:active:not(:disabled) { scale: 1; }
  .boot-bar::before { width: 100%; opacity: .5; }
}
