/*
 * dz.css — Transition and state classes for the Dazzle micro-runtime.
 * Replaces Alpine.js x-transition with CSS-only animations.
 * ~40 lines. Works with Tailwind/DaisyUI.
 */

/* ── Toggle show/hide with fade ─────────────────────────────────────── */

[data-dz-show] {
  transition: opacity 150ms ease-in, transform 150ms ease-in;
}

[data-dz-toggleable]:not([data-dz-open]) [data-dz-show] {
  display: none;
}

/* ── Dropdown animation ─────────────────────────────────────────────── */

[data-dz-show="dropdown"] {
  transition: opacity 150ms ease-out, transform 150ms ease-out;
  transform-origin: top right;
}

[data-dz-toggleable][data-dz-open] [data-dz-show="dropdown"] {
  opacity: 1;
  transform: scale(1) translateY(0);
}

/* ── Slide-over panel ───────────────────────────────────────────────── */

[data-dz-slide-over] [data-dz-show="backdrop"] {
  transition: opacity 200ms ease-out;
}

[data-dz-slide-over] [data-dz-show="panel"] {
  transition: transform 200ms ease-out;
  transform: translateX(100%);
}

[data-dz-slide-over][data-dz-open] [data-dz-show="panel"] {
  transform: translateX(0);
}

/* ── Bulk actions bar ───────────────────────────────────────────────── */

[data-dz-bulk-bar] {
  transition: opacity 200ms ease-out, transform 200ms ease-out;
}

/* ── Toast notifications ────────────────────────────────────────────── */

.dz-toast-enter {
  opacity: 0;
  transform: translateX(1rem);
  transition: opacity 200ms ease-out, transform 200ms ease-out;
}

.dz-toast-leave {
  opacity: 0;
  transform: translateX(1rem);
  transition: opacity 150ms ease-in, transform 150ms ease-in;
}

#dz-toast .alert {
  transition: opacity 200ms ease-out, transform 200ms ease-out;
}

/* ── Desktop sidebar (DaisyUI provides drawer base via @plugin;
     this adds data-dz-sidebar toggling for the Dazzle micro-runtime) ── */

@media (min-width: 1024px) {
  /* Two-column grid when sidebar is open */
  .drawer[data-dz-sidebar="open"] {
    grid-template-columns: max-content 1fr;
  }

  /* Show sidebar in-place (not overlay) */
  .drawer[data-dz-sidebar="open"] > .drawer-side {
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    visibility: visible;
    pointer-events: auto;
    opacity: 1;
    display: block;
    width: auto;
    overscroll-behavior: auto;
  }

  /* No overlay needed on desktop */
  .drawer[data-dz-sidebar="open"] > .drawer-side > .drawer-overlay {
    visibility: hidden;
  }

  /* Slide content into view */
  .drawer[data-dz-sidebar="open"] > .drawer-side > *:not(.drawer-overlay) {
    translate: 0%;
    transform: translateX(0);
  }

  /* Hide top navbar when sidebar provides navigation */
  .drawer[data-dz-sidebar="open"] > .drawer-content > [data-dz-sidebar-navbar] {
    display: none;
  }
}

/* ── Optimistic UI feedback ─────────────────────────────────────────── */

/* Row fades out during delete swap (swap:300ms on hx-swap) */
tr.htmx-swapping {
  opacity: 0;
  transform: translateX(1rem);
  transition: opacity 300ms ease-out, transform 300ms ease-out;
}

/* Row highlights briefly after creation or update */
tr.htmx-added,
tr.htmx-settling {
  animation: dz-row-highlight 600ms ease-out;
}

@keyframes dz-row-highlight {
  from { background-color: oklch(0.85 0.1 145 / 0.3); }
  to   { background-color: transparent; }
}

/* Form button feedback on successful submit */
.btn.htmx-request {
  pointer-events: none;
  opacity: 0.7;
}

/* ── HTMX indicator visibility ─────────────────────────────────────── */
/* Override htmx built-in opacity with display:none so hidden indicators
   don't occupy layout space (opacity:0 still reserves vertical space). */
.htmx-indicator {
  display: none;
}
/* Descendant case: indicator is a child of the requesting element */
.htmx-request .htmx-indicator {
  display: inline-block;
}
/* Same-element case: hx-indicator="#id" adds htmx-request to the indicator itself */
.htmx-request.htmx-indicator {
  display: inline-block;
}

/* ── Skeleton loading placeholders ──────────────────────────────────── */

.dz-skeleton {
  background: linear-gradient(90deg, oklch(0.8 0 0 / 0.3) 25%, oklch(0.85 0 0 / 0.5) 50%, oklch(0.8 0 0 / 0.3) 75%);
  background-size: 200% 100%;
  animation: dz-shimmer 1.5s ease-in-out infinite;
  border-radius: 0.25rem;
}

.dz-skeleton-text {
  height: 0.75rem;
  margin-bottom: 0.5rem;
}

.dz-skeleton-text-lg {
  height: 1rem;
  margin-bottom: 0.5rem;
  width: 60%;
}

.dz-skeleton-cell {
  height: 1rem;
}

@keyframes dz-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── View transitions for fragment navigation ──────────────────────── */

@view-transition {
  navigation: auto;
}

#main-content {
  view-transition-name: main-content;
}

::view-transition-old(main-content) {
  animation: dz-fade-out 150ms ease-in forwards;
}

::view-transition-new(main-content) {
  animation: dz-fade-in 200ms ease-out;
}

@keyframes dz-fade-out {
  to {
    opacity: 0;
    transform: translateY(4px);
  }
}

@keyframes dz-fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}

/* Reduce motion for accessibility */
/* Respect reduced motion for all Dazzle animations */
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(main-content),
  ::view-transition-new(main-content) {
    animation: none;
  }

  tr.htmx-swapping {
    transition: none;
  }

  tr.htmx-added,
  tr.htmx-settling {
    animation: none;
  }

  .dz-skeleton {
    animation: none;
  }
}

/* ── Native dialog backdrop ─────────────────────────────────────────── */

dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}

dialog[open] {
  animation: dz-dialog-in 200ms ease-out;
}

@keyframes dz-dialog-in {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}
