/* =====================================================================
 * app-global.css — Capa GLOBAL "app-like" + responsive de MyTSG.
 * Se enlaza en el <head> de todas las páginas de la intranet.
 * Objetivo: que la intranet se comporte como una app nativa —
 *   · sin rebote/rubber-band que descoloca el contenido (overscroll),
 *   · sin arrastre horizontal a zonas vacías,
 *   · imágenes/tablas/medios que nunca desbordan el ancho del móvil,
 *   · respeto del notch/safe-area en iOS/Android.
 * No pisa el diseño de cada página; solo blinda el comportamiento base.
 * ===================================================================== */

/* 1) BLOQUEO DE OVERSCROLL / RUBBER-BAND ------------------------------
   La página no "tira" del contenido hacia zonas vacías ni activa el
   pull-to-refresh: se comporta como una app, no como una web suelta. */
html {
  overscroll-behavior: none;
  overflow-x: hidden;               /* nada se desplaza en horizontal */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  overscroll-behavior: none;
}

/* 2) NADA DESBORDA EL ANCHO DEL VIEWPORT ------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
img, svg, video, canvas, iframe, embed, object,
picture > img { max-width: 100%; }
img, video, canvas { height: auto; }

/* Sin flash azul del tap en móvil */
* { -webkit-tap-highlight-color: transparent; }

/* 3) TABLAS ANCHAS -> scroll dentro de su zona en móvil/tablet --------
   (fallback por si alguna tabla no está envuelta en un contenedor con
    overflow). Se puede desactivar poniendo class="no-resp" a la tabla. */
@media (max-width: 820px) {
  table:not(.no-resp) {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* 4) SAFE-AREA (notch / barra inferior del móvil) --------------------- */
@supports (padding: max(0px)) {
  body {
    padding-bottom: max(0px, env(safe-area-inset-bottom));
  }
}

/* 5) Scroll suave y sin barras horizontales fantasma ------------------ */
@media (max-width: 1024px) {
  html, body { max-width: 100%; }
}

/* =====================================================================
 * 6) CAPA "APP-LIKE" EXPRESIVA — PWA MyTSG (2026-07)
 *    Transiciones de página + morph tarjeta->detalle + micro-animaciones.
 *    Nivel expresivo, pero snappy (<400ms) y con guard de accesibilidad.
 * ===================================================================== */

/* --- keyframes (nivel superior; se aplican bajo prefers-reduced-motion) --- */
@keyframes mytsgCardIn  { from { opacity:0; transform: translateY(16px) scale(.985); } to { opacity:1; transform:none; } }
@keyframes mytsgVtOut   { to   { opacity:0; transform: translateY(-8px); } }
@keyframes mytsgVtIn    { from { opacity:0; transform: translateY(16px); } }
@keyframes mytsgShimmer { to   { transform: translateX(100%); } }
@keyframes mytsgDlgIn   { from { opacity:0; transform: translateY(14px) scale(.965); } to { opacity:1; transform:none; } }
@keyframes mytsgFade    { from { opacity:0; } to { opacity:1; } }

/* 6.1 TRANSICIONES DE PÁGINA (cross-document, MPA) — sin JS.
   Chrome/Edge 126+ y Safari 18.2+; Firefox degrada a navegación instantánea. */
@view-transition { navigation: auto; }

/* El "chrome" persistente no parpadea: se mantiene fijo entre páginas */
@media (min-width:761px){ #mytsg-rail { view-transition-name: mytsg-rail; } }
.topbar     { view-transition-name: mytsg-topbar; }

/* La región de contenido (snapshot root) entra con un fade-up expresivo */
::view-transition-old(root) { animation: mytsgVtOut 150ms cubic-bezier(.4,0,1,1) both; }
::view-transition-new(root) { animation: mytsgVtIn  340ms cubic-bezier(.16,.84,.44,1) both; }
/* El rail/topbar solo cruzan un fundido brevísimo */
::view-transition-group(mytsg-rail),
::view-transition-group(mytsg-topbar) { animation-duration: 170ms; }

/* 6.2 MORPH DE ELEMENTO COMPARTIDO: la tarjeta pulsada "se convierte" en su
   ficha. El JS del shell pone .vt-morph a UN solo elemento por snapshot
   (tarjeta en el estado viejo -> diálogo en el nuevo). */
.vt-morph { view-transition-name: mytsg-morph; }
::view-transition-group(mytsg-morph) {
  animation-duration: 400ms;
  animation-timing-function: cubic-bezier(.34,1.28,.64,1);   /* leve rebote (spring) */
}

@media (prefers-reduced-motion: no-preference) {

  /* 6.3 Entrada escalonada de tarjetas/paneles al cargar */
  .content .card, .content .modulo-card, .content .app-card,
  .main .panel, [data-anim="up"] {
    animation: mytsgCardIn .42s cubic-bezier(.16,.84,.44,1) both;
  }
  .content .card:nth-child(1), .content .modulo-card:nth-child(1), .content .app-card:nth-child(1) { animation-delay: 20ms; }
  .content .card:nth-child(2), .content .modulo-card:nth-child(2), .content .app-card:nth-child(2) { animation-delay: 70ms; }
  .content .card:nth-child(3), .content .modulo-card:nth-child(3), .content .app-card:nth-child(3) { animation-delay: 115ms; }
  .content .card:nth-child(4), .content .modulo-card:nth-child(4), .content .app-card:nth-child(4) { animation-delay: 160ms; }
  .content .card:nth-child(5), .content .modulo-card:nth-child(5), .content .app-card:nth-child(5) { animation-delay: 200ms; }
  .content .card:nth-child(6), .content .modulo-card:nth-child(6), .content .app-card:nth-child(6) { animation-delay: 235ms; }
  .content .card:nth-child(n+7), .content .modulo-card:nth-child(n+7), .content .app-card:nth-child(n+7) { animation-delay: 270ms; } /* tope */

  /* 6.4 Feedback al pulsar con leve rebote (complementa el :active existente) */
  .modulo-card, .app-card, .content .card {
    transition: transform .2s cubic-bezier(.34,1.4,.64,1), box-shadow .22s ease, border-color .2s ease;
  }
  .modulo-card:active, .app-card:active, .content .card:active { transform: scale(.975); }

  /* 6.5 Transición suave del cambio de tema en superficies grandes */
  #mytsg-root, #mytsg-rail, .topbar, .content .card, .modulo-card, .app-card, .foot {
    transition: background-color .28s ease, color .24s ease, border-color .24s ease;
  }

  /* 6.6 Aparición del <dialog> (fallback cuando no hay View Transitions) */
  dialog.det-dialog[open], dialog.tsg-dlg[open] {
    animation: mytsgDlgIn .28s cubic-bezier(.16,.84,.44,1);
  }
  dialog.det-dialog::backdrop, dialog.tsg-dlg::backdrop {
    animation: mytsgFade .28s ease;
  }
}

/* 6.7 SKELETON LOADERS (listas que se pintan por fetch+innerHTML) */
.skeleton {
  position: relative; overflow: hidden;
  background: #e6ebf2; border-radius: 8px; min-height: 1em;
}
#mytsg-root[data-tema="dark"] .skeleton { background: #1a2438; }
.skeleton::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.55), transparent);
  animation: mytsgShimmer 1.15s ease-in-out infinite;
}
#mytsg-root[data-tema="dark"] .skeleton::after {
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.09), transparent);
}

/* 6.8 BANNER DE INSTALACIÓN + PISTA iOS (los crea assets/app-pwa.js) */
#mytsg-install, #mytsg-ios-hint {
  position: fixed; left: 50%; z-index: 3000;
  bottom: calc(16px + env(safe-area-inset-bottom));
  max-width: min(440px, calc(100vw - 24px));
  transform: translate(-50%, 150%); opacity: 0;
  background: #101e34; color: #fff; border: 1px solid rgba(255,255,255,.12);
  box-shadow: 0 14px 44px rgba(5,11,24,.55);
  transition: transform .36s cubic-bezier(.16,.84,.44,1), opacity .36s ease;
}
#mytsg-install.show, #mytsg-ios-hint.show { transform: translate(-50%, 0); opacity: 1; }

#mytsg-install {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px 11px 16px; border-radius: 16px;
}
#mytsg-install .mytsg-install-txt { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
#mytsg-install .mytsg-install-txt strong { font: 700 14px 'Roboto', sans-serif; }
#mytsg-install .mytsg-install-txt span   { font: 400 12px 'Roboto', sans-serif; color: rgba(255,255,255,.66); }
#mytsg-install .mytsg-install-go {
  margin-left: 4px; border: 0; cursor: pointer; white-space: nowrap; color: #fff;
  padding: 9px 16px; border-radius: 11px; font: 600 13px 'Roboto', sans-serif;
  background: linear-gradient(135deg, #1a8dcf, #216CA8);
  transition: transform .15s ease, filter .2s ease;
}
#mytsg-install .mytsg-install-go:hover  { filter: brightness(1.07); }
#mytsg-install .mytsg-install-go:active { transform: scale(.96); }
#mytsg-install .mytsg-install-x {
  border: 0; background: transparent; color: rgba(255,255,255,.6); cursor: pointer;
  font-size: 22px; line-height: 1; width: 30px; height: 30px; border-radius: 8px;
}
#mytsg-install .mytsg-install-x:hover { color: #fff; background: rgba(255,255,255,.08); }

#mytsg-ios-hint {
  padding: 12px 16px; border-radius: 14px; text-align: center;
  font: 400 13px 'Roboto', sans-serif; line-height: 1.4;
}

/* 6.9 GUARD GLOBAL DE ACCESIBILIDAD — si el usuario pide "reduce motion",
   se desactiva TODA animación/transición, incluidas las View Transitions. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) { animation: none !important; }
}

/* =====================================================================
 * 7) REFUERZO ANTI SCROLL-HORIZONTAL + ajustes iOS (2026-07-13)
 *    La intranet no debe mostrar barra horizontal (ni dentro de .content).
 * ===================================================================== */
body { overflow-x: clip; }
#mytsg-main { min-width: 0; max-width: 100%; }
.content { overflow-x: clip; }

/* En movil el topbar NO participa en las View Transitions: un elemento
   sticky con view-transition-name puede provocar overflow/glitch en iOS. */
@media (max-width: 760px) {
  .topbar { view-transition-name: none; }
}

/* Banners PWA: centrar con left/right (sin translateX) para no arriesgar
   overflow subpixel en iOS Safari. Solo se desliza en vertical. */
#mytsg-install, #mytsg-ios-hint {
  left: 12px; right: 12px; margin-inline: auto; width: fit-content;
  transform: translateY(170%);
}
#mytsg-install.show, #mytsg-ios-hint.show { transform: translateY(0); }
