/* ============================================================================
   Matrize UX States — shared skeleton loaders + error/empty state styles.
   Themeable via the existing token set (--bg/--fg/--surface/--border/--hair/
   --accent/--ink-*). Works on both the public site (site.css) and the admin
   shell (admin-shell.css). Pair with /assets/js/ux-states.js (window.MatrizeUX).
   ========================================================================== */

/* Local fallbacks so the file is usable even on pages that miss a token. */
.mz-skeleton,
.mz-state,
.mz-offline-banner,
.mz-toast {
  --mz-bone:      var(--ink-10, rgba(14,42,92,0.10));
  --mz-bone-hi:   var(--ink-20, rgba(14,42,92,0.20));
  --mz-line:      var(--hair, rgba(14,42,92,0.18));
  --mz-fg:        var(--fg, #0E2A5C);
  --mz-muted:     var(--ink-40, rgba(14,42,92,0.55));
  --mz-accent:    var(--accent, #A86A2C);
  --mz-surface:   var(--surface, var(--bg, #FFFCF7));
}

/* ── Skeleton primitives ─────────────────────────────────────────────────── */
.mz-skeleton { display: block; }

.mz-bone {
  position: relative;
  overflow: hidden;
  display: block;
  background: var(--mz-bone, rgba(14,42,92,0.10));
  border-radius: 6px;
  /* prevents collapse so layout reserves real space (anti-CLS) */
  min-height: 12px;
}
.mz-bone::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background-image: linear-gradient(
    90deg,
    transparent 0,
    var(--mz-bone-hi, rgba(14,42,92,0.20)) 50%,
    transparent 100%
  );
  animation: mz-shimmer 1.35s ease-in-out infinite;
}

.mz-bone.text   { height: 12px; margin: 0 0 8px; border-radius: 4px; }
.mz-bone.text.lg{ height: 18px; }
.mz-bone.text.sm{ height: 9px; }
.mz-bone.w-90 { width: 90%; } .mz-bone.w-80 { width: 80%; }
.mz-bone.w-70 { width: 70%; } .mz-bone.w-60 { width: 60%; }
.mz-bone.w-50 { width: 50%; } .mz-bone.w-40 { width: 40%; }
.mz-bone.w-30 { width: 30%; } .mz-bone.w-25 { width: 25%; }
.mz-bone.circle { border-radius: 50%; }
.mz-bone.pill   { border-radius: 999px; }
.mz-bone.mz-gap { margin-bottom: 22px; }

@keyframes mz-shimmer { 100% { transform: translateX(100%); } }

/* ── Composed skeleton layouts ───────────────────────────────────────────── */
.mz-skel-card {
  border: 1px solid var(--mz-line);
  border-radius: 12px;
  padding: 20px;
  background: var(--mz-surface);
}
.mz-skel-card .mz-bone.chart { height: 140px; border-radius: 8px; margin-top: 16px; }

.mz-skel-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
}

.mz-skel-chart {
  border: 1px solid var(--mz-line);
  border-radius: 12px;
  padding: 20px;
}
.mz-skel-chart .plot {
  height: 220px;
  border-radius: 8px;
  margin-top: 14px;
}

.mz-skel-profile { display: flex; align-items: center; gap: 16px; }
.mz-skel-profile .avatar { width: 56px; height: 56px; flex: 0 0 56px; }
.mz-skel-profile .meta { flex: 1 1 auto; }

.mz-skel-list > * + * { margin-top: 12px; }
.mz-skel-list .row {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 0; border-bottom: 1px solid var(--mz-line);
}
.mz-skel-list .row .dot { width: 32px; height: 32px; flex: 0 0 32px; }
.mz-skel-list .row .body { flex: 1 1 auto; }

/* Table skeleton: real <tr>/<td> so it slots into existing tbodies w/o CLS. */
tr.mz-skel-row td { padding: 12px 10px; }
tr.mz-skel-row .mz-bone { margin: 0; }

/* ── State blocks (error / empty / offline / 403 / 404) ──────────────────── */
.mz-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  padding: 44px 24px;
  color: var(--mz-fg);
}
.mz-state .mz-state-icon {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  margin-bottom: 6px;
  color: var(--mz-accent);
}
.mz-state .mz-state-icon svg { width: 100%; height: 100%; }
.mz-state h3 {
  margin: 0;
  font-family: var(--font-display, Georgia, serif);
  font-weight: 400;
  font-size: 20px;
  letter-spacing: -0.01em;
}
.mz-state p {
  margin: 0;
  max-width: 42ch;
  color: var(--mz-muted);
  font-size: 14px;
  line-height: 1.55;
}
.mz-state .mz-state-actions {
  display: inline-flex; gap: 10px; flex-wrap: wrap;
  justify-content: center; margin-top: 14px;
}
.mz-state.error   .mz-state-icon { color: var(--red, #B5483A); }
.mz-state.compact { padding: 24px 16px; }

/* request id / technical hint shown subtly under the message */
.mz-state .mz-state-ref {
  margin-top: 10px;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--mz-muted);
  opacity: 0.8;
}

/* Buttons inside state blocks — neutral, inherit token palette. */
.mz-btn {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 9px 16px;
  border: 1px solid var(--mz-line);
  border-radius: 8px;
  background: transparent;
  color: var(--mz-fg);
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.mz-btn:hover { border-color: var(--mz-accent); color: var(--mz-accent); }
.mz-btn.primary {
  background: var(--mz-accent); color: var(--bg, #fff); border-color: var(--mz-accent);
}
.mz-btn.primary:hover { filter: brightness(1.05); color: var(--bg, #fff); }
.mz-btn:focus-visible { outline: 2px solid var(--mz-accent); outline-offset: 2px; }
.mz-btn[disabled] { opacity: 0.55; cursor: progress; }

/* ── Offline banner (fixed, dismissible) ─────────────────────────────────── */
.mz-offline-banner {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 9000;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 10px 16px;
  background: var(--red, #B5483A);
  color: #fff;
  font-size: 13px;
  font-family: var(--font-body, system-ui, sans-serif);
  box-shadow: 0 -4px 18px rgba(0,0,0,0.18);
  transform: translateY(100%);
  transition: transform .25s ease;
}
.mz-offline-banner.show { transform: translateY(0); }
.mz-offline-banner.online { background: #2E7D52; }

/* ── Button loading state (inline spinner) ───────────────────────────────── */
.mz-is-loading { position: relative; color: transparent !important; pointer-events: none; }
.mz-is-loading::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  width: 14px; height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  color: var(--mz-fg);
  animation: mz-spin 0.7s linear infinite;
}
@keyframes mz-spin { to { transform: rotate(360deg); } }

/* Standalone inline spinner */
.mz-spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid var(--mz-bone-hi);
  border-top-color: var(--mz-accent);
  border-radius: 50%;
  animation: mz-spin 0.7s linear infinite;
  vertical-align: middle;
}

/* ── Toast (global error boundary fallback) ──────────────────────────────── */
.mz-toast {
  position: fixed;
  right: 18px; bottom: 18px;
  z-index: 9500;
  max-width: 340px;
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid var(--mz-line);
  background: var(--mz-surface);
  color: var(--mz-fg);
  box-shadow: 0 8px 30px rgba(0,0,0,0.22);
  font-size: 13px;
  line-height: 1.45;
}
.mz-toast strong { display: block; margin-bottom: 4px; }
.mz-toast .mz-toast-close {
  position: absolute; top: 8px; right: 10px;
  background: none; border: none; color: var(--mz-muted);
  cursor: pointer; font-size: 16px; line-height: 1;
}

/* ── Fade-in for resolved content (smooth swap from skeleton) ────────────── */
.mz-fade-in { animation: mz-fade .28s ease both; }
@keyframes mz-fade { from { opacity: 0; } to { opacity: 1; } }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .mz-state { padding: 32px 16px; }
  .mz-state h3 { font-size: 18px; }
  .mz-skel-cards { grid-template-columns: 1fr; }
  .mz-skel-chart .plot { height: 160px; }
  .mz-toast { left: 12px; right: 12px; max-width: none; }
}

/* ── Accessibility: honour reduced-motion ────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .mz-bone::after { animation: none; }
  .mz-bone { background: var(--mz-bone-hi); }
  .mz-is-loading::after,
  .mz-spinner { animation-duration: 1.4s; }
  .mz-offline-banner,
  .mz-fade-in { transition: none; animation: none; }
}
