/* Three Column Grid Layout - Responsive grid that displays 3 columns on desktop */

/* Three column grid container - used for cards that should display 3 per row */
.three-column-grid,
.card-grid-three {
  display: grid;
  gap: 2rem;
  margin: 3rem auto;
  max-width: 1200px;
  padding: 0 1rem;
}

/* Desktop: 3 columns */
@media (min-width: 1024px) {
  .three-column-grid,
  .card-grid-three {
    grid-template-columns: repeat(3, 1fr);
  }
  
  /* If there are only 2 items, center them */
  .three-column-grid:has(> :nth-child(2):last-child),
  .card-grid-three:has(> :nth-child(2):last-child) {
    grid-template-columns: repeat(2, minmax(320px, 400px));
    justify-content: center;
  }
  
  /* If there's only 1 item, center it */
  .three-column-grid:has(> :only-child),
  .card-grid-three:has(> :only-child) {
    grid-template-columns: minmax(320px, 400px);
    justify-content: center;
  }
}

/* Tablet: 2 columns */
@media (min-width: 640px) and (max-width: 1023px) {
  .three-column-grid,
  .card-grid-three {
    grid-template-columns: repeat(2, 1fr);
  }
  
  /* If there's only 1 item, make it full width but max 400px */
  .three-column-grid:has(> :only-child),
  .card-grid-three:has(> :only-child) {
    grid-template-columns: minmax(320px, 400px);
    justify-content: center;
  }
}

/* Mobile: 1 column */
@media (max-width: 639px) {
  .three-column-grid,
  .card-grid-three {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
}

/* Plan groups container */
.plan-groups-container {
  display: flex;
  flex-direction: column;
  gap: 4rem;
  margin: 2rem 0;
}

/* Each plan group */
.plan-group {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* Plan group header */
.plan-group-header {
  text-align: center;
  margin-bottom: 1rem;
}

/* Special plans section (Free and Custom) */
.special-plans-grid {
  display: grid;
  gap: 2rem;
  margin: 3rem auto;
  max-width: 1200px;
  padding: 0 1rem;
}

@media (min-width: 768px) {
  .special-plans-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 767px) {
  .special-plans-grid {
    grid-template-columns: 1fr;
  }
}

/* Ensure cards have equal height within grid */
.three-column-grid > *,
.card-grid-three > * {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Plan card should fill available height */
.plan-card {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.plan-card .card-body {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.plan-card .plan-features {
  flex: 1;
}

.plan-card .card-footer {
  margin-top: auto;
}

/* Recommended plan emphasis on desktop */
@media (min-width: 1024px) {
  .plan-card.recommended {
    transform: scale(1.05);
    z-index: 1;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
  }
}

/* Animation for grid appearance */
.three-column-grid > *,
.card-grid-three > * {
  animation: fadeInUp 0.4s ease-out;
  animation-fill-mode: both;
}

.three-column-grid > :nth-child(1),
.card-grid-three > :nth-child(1) {
  animation-delay: 0.1s;
}

.three-column-grid > :nth-child(2),
.card-grid-three > :nth-child(2) {
  animation-delay: 0.2s;
}

.three-column-grid > :nth-child(3),
.card-grid-three > :nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Loading state for grid updates */
.three-column-grid.loading,
.card-grid-three.loading {
  opacity: 0.6;
  pointer-events: none;
}

.three-column-grid.loading::after,
.card-grid-three.loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}