/*
 * Proaqsa loading indicators for no-reload navigation (speed part B, 2026-10-27). Hostinger-style:
 * a thin top progress bar on click, shimmer skeleton cards over the outlet after ~150 ms, a busy state on the
 * clicked element, and a retry card on error / timeout. Shared class names with the workspace shell
 * (erp-topbar-progress, erp-skeleton, erp-skeleton-card, erp-skeleton-row).
 *
 * One file, byte-identical copies: public/assets/css/erp-loading.css (website),
 * superadmin/assets/css/erp-loading.css (Platform Control), assets/css/surface-loading.css (Personal Hub).
 * Colours come from each surface's own theme variables, so light and dark mode follow automatically.
 * Nothing here changes layout: the bar is fixed, the skeleton and retry layers sit absolutely over the outlet.
 */
.hub-body {
  --erp-loading-accent: var(--hub-accent, #4f46e5);
  --erp-loading-base: var(--hub-soft, #e9eef7);
  --erp-loading-shine: var(--hub-panel, #ffffff);
  --erp-loading-panel: var(--hub-bg, #f5f7fb);
  --erp-loading-card: var(--hub-panel, #ffffff);
  --erp-loading-line: var(--hub-line, #dbe4f2);
  --erp-loading-ink: var(--hub-muted, #5b6b82);
  --erp-loading-radius: var(--hub-radius, 14px);
}
.control-body {
  --erp-loading-accent: var(--control-indigo, #4f46e5);
  --erp-loading-base: var(--control-soft, #eef2f7);
  --erp-loading-shine: var(--control-white, #ffffff);
  --erp-loading-panel: var(--control-canvas, #f5f7fb);
  --erp-loading-card: var(--control-surface, #ffffff);
  --erp-loading-line: var(--control-border, #e2e8f0);
  --erp-loading-ink: var(--control-muted, #64748b);
  --erp-loading-radius: 14px;
}
.site-body {
  --erp-loading-accent: var(--brand, #4f46e5);
  --erp-loading-base: var(--surface-2, #eef2f7);
  --erp-loading-shine: var(--surface, #ffffff);
  --erp-loading-panel: var(--bg, #f7f8fc);
  --erp-loading-card: var(--surface, #ffffff);
  --erp-loading-line: var(--line, #e2e8f0);
  --erp-loading-ink: var(--muted, #64748b);
  --erp-loading-radius: var(--r, 16px);
}

/* ---------- top progress bar ---------- */
.erp-topbar-progress {
  position: fixed;
  inset-block-start: 0;
  inset-inline: 0;
  height: 3px;
  z-index: 2147483000;
  pointer-events: none;
  opacity: 0;
  transform: scaleX(0);
  transform-origin: 0 50%;
  background: var(--erp-loading-accent, #4f46e5);
  box-shadow: 0 0 10px var(--erp-loading-accent, #4f46e5);
  transition: opacity .2s ease;
}
[dir="rtl"] .erp-topbar-progress { transform-origin: 100% 50%; }
.erp-topbar-progress.is-active {
  opacity: 1;
  animation: erp-topbar-grow 9s cubic-bezier(.08, .7, .2, 1) forwards;
}
.erp-topbar-progress.is-done {
  opacity: 0;
  transform: scaleX(1);
  animation: none;
  transition: transform .18s ease, opacity .28s ease .14s;
}
@keyframes erp-topbar-grow {
  0% { transform: scaleX(0); }
  8% { transform: scaleX(.3); }
  40% { transform: scaleX(.65); }
  100% { transform: scaleX(.92); }
}

/* ---------- busy trigger (no double clicks) ---------- */
.erp-is-busy {
  cursor: progress !important;
  pointer-events: none;
  opacity: .72;
}

/* ---------- skeleton layer over the outlet ---------- */
.erp-loading-host { position: relative; }
.erp-skeleton-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
  overflow: hidden;
  box-sizing: border-box;
  padding: inherit;
  display: grid;
  align-content: start;
  gap: 16px;
  background: var(--erp-loading-panel, #f5f7fb);
  opacity: 0;
  animation: erp-loading-fade .14s ease forwards;
}
/* the website outlet (<main>) has no padding of its own: align the cards with the page column */
.site-body .erp-skeleton-layer { padding: 32px max(16px, calc((100% - var(--max, 1200px)) / 2)); }
.erp-skeleton-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr));
  gap: 16px;
}
.erp-skeleton {
  position: relative;
  overflow: hidden;
  display: block;
  border-radius: 8px;
  background: var(--erp-loading-base, #eef2f7);
}
.erp-skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, var(--erp-loading-shine, #ffffff), transparent);
  opacity: .75;
  animation: erp-skeleton-shimmer 1.25s ease-in-out infinite;
}
[dir="rtl"] .erp-skeleton::after { animation-direction: reverse; }
.erp-skeleton-card {
  display: grid;
  gap: 12px;
  padding: 18px;
  border: 1px solid var(--erp-loading-line, #e2e8f0);
  border-radius: var(--erp-loading-radius, 14px);
  background: var(--erp-loading-card, #ffffff);
}
.erp-skeleton-row { height: 12px; width: 100%; }
.erp-skeleton-row.is-title { height: 20px; width: 42%; }
.erp-skeleton-row.is-short { width: 58%; }
.erp-skeleton-row.is-tiny { width: 28%; }
.erp-skeleton-row.is-block { height: 64px; }
@keyframes erp-skeleton-shimmer { 100% { transform: translateX(100%); } }
@keyframes erp-loading-fade { to { opacity: 1; } }

/* ---------- retry card (error / timeout) ---------- */
.erp-loading-retry {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  box-sizing: border-box;
  padding: 48px 16px;
  background: var(--erp-loading-panel, #f5f7fb);
}
.erp-loading-retry-card {
  max-width: 440px;
  width: 100%;
  box-sizing: border-box;
  padding: 22px 24px;
  text-align: center;
  border: 1px solid var(--erp-loading-line, #e2e8f0);
  border-radius: var(--erp-loading-radius, 14px);
  background: var(--erp-loading-card, #ffffff);
}
.erp-loading-retry-card h2 { margin: 0 0 6px; font-size: 1.05rem; }
.erp-loading-retry-card p { margin: 0 0 16px; color: var(--erp-loading-ink, #64748b); }
.erp-loading-retry-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

@media (prefers-reduced-motion: reduce) {
  .erp-topbar-progress.is-active { animation: none; transform: scaleX(.6); }
  .erp-topbar-progress.is-done { transition: opacity .2s ease; }
  .erp-skeleton::after { animation: none; display: none; }
  .erp-skeleton-layer { animation: none; opacity: 1; }
}
@media print {
  .erp-topbar-progress, .erp-skeleton-layer, .erp-loading-retry { display: none !important; }
}
