/* Feedback visual para fluxos assíncronos (HTMX, forms, exports) */

#htmx-page-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
  background: transparent;
  transition: opacity 0.15s ease;
}

#htmx-page-progress::after {
  content: '';
  display: block;
  height: 100%;
  width: 35%;
  background: #00af4c;
  transform: translateX(-100%);
}

body.htmx-busy #htmx-page-progress,
body.async-busy #htmx-page-progress {
  opacity: 1;
}

body.htmx-busy #htmx-page-progress::after,
body.async-busy #htmx-page-progress::after {
  animation: async-progress 1.1s ease-in-out infinite;
}

@keyframes async-progress {
  0% { transform: translateX(-100%); width: 30%; }
  50% { transform: translateX(120%); width: 55%; }
  100% { transform: translateX(260%); width: 30%; }
}

body.htmx-busy #main-content {
  opacity: 0.55;
  transition: opacity 0.15s ease;
  pointer-events: none;
  cursor: wait;
}

.htmx-indicator {
  display: none;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  display: inline-flex;
  align-items: center;
}

.async-skeleton {
  display: none;
  pointer-events: none;
}

body.htmx-busy .async-skeleton-host > .async-skeleton {
  display: block;
}

body.htmx-busy .async-skeleton-host > .async-skeleton-content {
  display: none;
}

.async-skeleton-line {
  height: 0.75rem;
  border-radius: 0.375rem;
  background: linear-gradient(90deg, #e2e8f0 0%, #f1f5f9 50%, #e2e8f0 100%);
  background-size: 200% 100%;
  animation: async-skeleton-shimmer 1.2s ease-in-out infinite;
}

.dark .async-skeleton-line {
  background: linear-gradient(90deg, #1e293b 0%, #334155 50%, #1e293b 100%);
  background-size: 200% 100%;
}

@keyframes async-skeleton-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

button[data-async-busy="1"],
a[data-async-busy="1"] {
  opacity: 0.7;
  cursor: wait !important;
  pointer-events: none;
}

#async-toast-stack {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(22rem, calc(100vw - 2rem));
}

.async-toast {
  border-radius: 0.75rem;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  line-height: 1.35;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.15);
  background: #fff;
  border: 1px solid #e2e8f0;
  color: #0f172a;
}

.dark .async-toast {
  background: #0f172a;
  border-color: rgba(255, 255, 255, 0.1);
  color: #e2e8f0;
}

.async-toast--error {
  border-color: #fecaca;
  background: #fef2f2;
  color: #991b1b;
}

.dark .async-toast--error {
  border-color: rgba(248, 113, 113, 0.35);
  background: rgba(127, 29, 29, 0.35);
  color: #fecaca;
}

.async-toast--success {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: #166534;
}

.dark .async-toast--success {
  border-color: rgba(74, 222, 128, 0.35);
  background: rgba(20, 83, 45, 0.35);
  color: #bbf7d0;
}

.async-toast button {
  margin-top: 0.5rem;
  font-weight: 600;
  text-decoration: underline;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  color: inherit;
}

@media (prefers-reduced-motion: reduce) {
  body.htmx-busy #main-content,
  #htmx-page-progress {
    transition: none !important;
  }

  body.htmx-busy #htmx-page-progress::after,
  body.async-busy #htmx-page-progress::after,
  .async-skeleton-line,
  .animate-spin {
    animation: none !important;
  }

  body.htmx-busy #htmx-page-progress::after,
  body.async-busy #htmx-page-progress::after {
    width: 100%;
    transform: none;
    opacity: 0.85;
  }

  .async-skeleton-line {
    background: #e2e8f0;
  }

  .dark .async-skeleton-line {
    background: #334155;
  }
}
