/* ─────────────────────────────────────────────────────────────────────────
   Global activity loader.

   Two levels, on purpose:

   1. A full-screen overlay for anything that navigates away or replaces the
      page (form POSTs, htmx swaps). It blocks input, which is what you want
      while a save is in flight - the page is about to be gone anyway.

   2. An inline button spinner for the submit control that triggered it. This
      is the part that actually prevents duplicate records: the button is
      disabled for the whole round trip.

   File downloads (CSV/Excel/PDF export) deliberately get NEITHER. A download
   response never unloads the page, so an overlay would sit there forever
   with nothing to dismiss it. Those get a small spinner on the clicked menu
   item instead - see .izr-item-busy.
   ───────────────────────────────────────────────────────────────────────── */

.izr-loader {
  position: fixed;
  inset: 0;
  z-index: 20000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, .72);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  opacity: 0;
  visibility: hidden;
  transition: opacity .18s ease, visibility .18s ease;
}

.izr-loader.is-visible {
  opacity: 1;
  visibility: visible;
}

.izr-loader__box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .875rem;
  padding: 1.5rem 2rem;
  border-radius: .75rem;
  background: #fff;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .12);
  /* Nudged up slightly: dead-centre reads as low on tall screens. */
  transform: translateY(-6vh);
  max-width: min(90vw, 22rem);
  text-align: center;
}

.izr-loader__spinner {
  width: 2.5rem;
  height: 2.5rem;
  border: 3px solid rgba(105, 108, 255, .18);
  border-top-color: var(--izr-primary, var(--primary-purple, #696cff));
  border-radius: 50%;
  animation: izr-spin .7s linear infinite;
}

.izr-loader__text {
  font-size: .9375rem;
  font-weight: 500;
  color: #4b5563;
  line-height: 1.4;
}

@keyframes izr-spin {
  to { transform: rotate(360deg); }
}

/* ─── Dark mode ─── */
[data-bs-theme="dark"] .izr-loader {
  background: rgba(23, 25, 37, .76);
}

[data-bs-theme="dark"] .izr-loader__box {
  background: #232333;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .45);
}

[data-bs-theme="dark"] .izr-loader__text {
  color: #cbd5e1;
}

/* ─── Inline spinner on the submit button that triggered the request ─── */
.izr-btn-busy {
  position: relative;
  pointer-events: none;
}

/* Hide the label rather than replacing it, so the button keeps its width and
   the layout does not jump when the spinner appears. */
.izr-btn-busy > * {
  opacity: 0;
}

.izr-btn-busy::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1rem;
  height: 1rem;
  margin: -.5rem 0 0 -.5rem;
  border: 2px solid rgba(255, 255, 255, .45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: izr-spin .6s linear infinite;
}

/* Outline / light buttons have a light face, so a white spinner vanishes. */
.izr-btn-busy.btn-outline-primary::after,
.izr-btn-busy.btn-outline-secondary::after,
.izr-btn-busy.btn-label-secondary::after,
.izr-btn-busy.btn-secondary::after,
.izr-btn-busy.btn-light::after {
  border-color: rgba(105, 108, 255, .25);
  border-top-color: var(--izr-primary, var(--primary-purple, #696cff));
}

/* ─── Busy state for a clicked download/export item ─── */
.izr-item-busy {
  position: relative;
  pointer-events: none;
  opacity: .65;
}

.izr-item-busy::after {
  content: "";
  position: absolute;
  top: 50%;
  inset-inline-end: .75rem;   /* logical property - flips under RTL */
  width: .875rem;
  height: .875rem;
  margin-top: -.4375rem;
  border: 2px solid rgba(105, 108, 255, .25);
  border-top-color: var(--izr-primary, var(--primary-purple, #696cff));
  border-radius: 50%;
  animation: izr-spin .6s linear infinite;
}

/* ─── Reduced motion: keep the feedback, drop the spin ─── */
@media (prefers-reduced-motion: reduce) {
  .izr-loader__spinner,
  .izr-btn-busy::after,
  .izr-item-busy::after {
    animation-duration: 2.4s;
  }
  .izr-loader {
    transition: none;
  }
}
