/**
 * @file
 * FlowDrop Grid Component Styles
 *
 * Provides consistent responsive grid layout for stat cards, action links,
 * and content cards. Uses CSS custom properties for customization.
 */

/* ========================================================================
 * CSS Custom Properties
 * ======================================================================== */

.fd-grid {
  /* Default minimum item width - can be overridden via inline style */
  --fd-grid-min-item-width: 280px;

  /* Gap sizes */
  --fd-grid-gap-sm: var(--fd-space-2);
  --fd-grid-gap-md: var(--fd-space-4);
  --fd-grid-gap-lg: var(--fd-space-6);
}

/* ========================================================================
 * BASE GRID LAYOUT
 * ======================================================================== */

.fd-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--fd-grid-min-item-width), 1fr));
  gap: var(--fd-grid-gap-md);
  align-items: start;
}

/* ========================================================================
 * GAP VARIANTS
 * ======================================================================== */

.fd-grid--gap-sm {
  gap: var(--fd-grid-gap-sm);
}

.fd-grid--gap-md {
  gap: var(--fd-grid-gap-md);
}

.fd-grid--gap-lg {
  gap: var(--fd-grid-gap-lg);
}

/* ========================================================================
 * LAYOUT VARIANTS
 * ======================================================================== */

/**
 * Default variant (stats/actions) - standard card grids.
 * Uses auto-fill for consistent item sizing across different content counts.
 * Both stats and actions use the same responsive behavior.
 */
.fd-grid--stats,
.fd-grid--actions {
  --fd-grid-min-item-width: 280px;
}

/**
 * Cards variant - optimized for content cards with richer content.
 * Slightly wider minimum width for better readability.
 */
.fd-grid--cards {
  --fd-grid-min-item-width: 320px;
}

/* ========================================================================
 * FIXED COLUMN VARIANTS
 * ======================================================================== */

.fd-grid--cols-1 {
  grid-template-columns: 1fr;
}

.fd-grid--cols-2 {
  grid-template-columns: repeat(2, 1fr);
}

.fd-grid--cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

.fd-grid--cols-4 {
  grid-template-columns: repeat(4, 1fr);
}

.fd-grid--cols-5 {
  grid-template-columns: repeat(5, 1fr);
}

.fd-grid--cols-6 {
  grid-template-columns: repeat(6, 1fr);
}

/* ========================================================================
 * RESPONSIVE ADJUSTMENTS
 * Unified breakpoints for consistent behavior across all variants
 * ======================================================================== */

/**
 * Mobile: Single column layout.
 * All grid variants collapse to single column for optimal readability.
 */
@media (max-width: 640px) {
  .fd-grid {
    grid-template-columns: 1fr;
    gap: var(--fd-space-3);
  }

  .fd-grid--gap-sm {
    gap: var(--fd-space-2);
  }

  .fd-grid--gap-md {
    gap: var(--fd-space-3);
  }

  .fd-grid--gap-lg {
    gap: var(--fd-space-4);
  }

  /* Fixed columns also collapse on mobile */
  .fd-grid--cols-2,
  .fd-grid--cols-3,
  .fd-grid--cols-4,
  .fd-grid--cols-5,
  .fd-grid--cols-6 {
    grid-template-columns: 1fr;
  }
}

/**
 * Tablet: Adjusted minimum widths for medium screens.
 * Allows 2-3 columns depending on container width.
 */
@media (min-width: 641px) and (max-width: 1024px) {
  .fd-grid--stats,
  .fd-grid--actions {
    --fd-grid-min-item-width: 240px;
  }

  .fd-grid--cards {
    --fd-grid-min-item-width: 280px;
  }

  /* Fixed columns adjust for tablet */
  .fd-grid--cols-4,
  .fd-grid--cols-5,
  .fd-grid--cols-6 {
    grid-template-columns: repeat(3, 1fr);
  }
}

/**
 * Large screens: Full grid with optimal column count.
 * Uses the default minimum widths defined in variants.
 */
@media (min-width: 1025px) {
  /* Fixed columns maintain their count on large screens */
  .fd-grid--cols-4 {
    grid-template-columns: repeat(4, 1fr);
  }

  .fd-grid--cols-5 {
    grid-template-columns: repeat(5, 1fr);
  }

  .fd-grid--cols-6 {
    grid-template-columns: repeat(6, 1fr);
  }
}

/* ========================================================================
 * STAGGER ANIMATION
 * Provides smooth entrance animation for grid items
 * ======================================================================== */

@keyframes fd-grid-fade-in {
  from {
    transform: translateY(8px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.fd-grid.fd-stagger-in > * {
  animation: fd-grid-fade-in var(--fd-transition-normal, 200ms) ease-out backwards;
}

.fd-grid.fd-stagger-in > *:nth-child(1) {
  animation-delay: 0ms;
}
.fd-grid.fd-stagger-in > *:nth-child(2) {
  animation-delay: 50ms;
}
.fd-grid.fd-stagger-in > *:nth-child(3) {
  animation-delay: 100ms;
}
.fd-grid.fd-stagger-in > *:nth-child(4) {
  animation-delay: 150ms;
}
.fd-grid.fd-stagger-in > *:nth-child(5) {
  animation-delay: 200ms;
}
.fd-grid.fd-stagger-in > *:nth-child(6) {
  animation-delay: 250ms;
}
.fd-grid.fd-stagger-in > *:nth-child(n + 7) {
  animation-delay: 300ms;
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .fd-grid.fd-stagger-in > * {
    animation: none;
  }
}
