/* ==========================================================================
   SparkHub Utilities - Mobile-First Helper Classes
   - Complementary to Tailwind utilities
   - Custom utilities for specific needs
   ========================================================================== */

/* ==========================================================================
   Display Utilities (Mobile-First)
   ========================================================================== */

/* Hide on mobile, show on tablet+ */
.hide-mobile {
  display: none;
}

@media (min-width: 640px) {
  .hide-mobile {
    display: block;
  }
}

/* Show on mobile, hide on tablet+ */
.show-mobile {
  display: block;
}

@media (min-width: 640px) {
  .show-mobile {
    display: none;
  }
}

/* Hide on tablet, show on desktop */
.hide-tablet {
  display: block;
}

@media (min-width: 640px) and (max-width: 1023px) {
  .hide-tablet {
    display: none;
  }
}

/* Show on tablet only */
.show-tablet {
  display: none;
}

@media (min-width: 640px) and (max-width: 1023px) {
  .show-tablet {
    display: block;
  }
}

/* Hide on desktop */
.hide-desktop {
  display: block;
}

@media (min-width: 1024px) {
  .hide-desktop {
    display: none;
  }
}

/* Show on desktop only */
.show-desktop {
  display: none;
}

@media (min-width: 1024px) {
  .show-desktop {
    display: block;
  }
}

/* ==========================================================================
   Flex Utilities (Mobile-First)
   ========================================================================== */

/* Responsive flex direction */
.flex-col-mobile {
  flex-direction: column;
}

@media (min-width: 640px) {
  .flex-col-mobile {
    flex-direction: row;
  }
}

/* Stack on mobile, inline on desktop */
.stack-mobile {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (min-width: 640px) {
  .stack-mobile {
    flex-direction: row;
    align-items: center;
  }
}

/* ==========================================================================
   Grid Utilities (Mobile-First)
   ========================================================================== */

/* Responsive grid: 1 col mobile, 2 cols tablet, 3+ cols desktop */
.grid-responsive {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

@media (min-width: 640px) {
  .grid-responsive {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
  }
}

@media (min-width: 1024px) {
  .grid-responsive {
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
  }
}

@media (min-width: 1280px) {
  .grid-responsive {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* 2-column grid (mobile 1, tablet+ 2) */
.grid-2 {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

@media (min-width: 640px) {
  .grid-2 {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
  }
}

/* 3-column grid (mobile 1, tablet 2, desktop 3) */
.grid-3 {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

@media (min-width: 640px) {
  .grid-3 {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
  }
}

@media (min-width: 1024px) {
  .grid-3 {
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
  }
}

/* Auto-fit grid (responsive columns based on min-width) */
.grid-auto-fit {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

@media (min-width: 640px) {
  .grid-auto-fit {
    gap: 1.5rem;
  }
}

/* ==========================================================================
   Spacing Utilities (Mobile-First)
   ========================================================================== */

/* Responsive spacing */
.space-y-responsive > * + * {
  margin-top: 1rem;
}

@media (min-width: 640px) {
  .space-y-responsive > * + * {
    margin-top: 1.5rem;
  }
}

@media (min-width: 1024px) {
  .space-y-responsive > * + * {
    margin-top: 2rem;
  }
}

/* Section spacing */
.section-spacing {
  padding-top: 2rem;
  padding-bottom: 2rem;
}

@media (min-width: 640px) {
  .section-spacing {
    padding-top: 3rem;
    padding-bottom: 3rem;
  }
}

@media (min-width: 1024px) {
  .section-spacing {
    padding-top: 4rem;
    padding-bottom: 4rem;
  }
}

/* ==========================================================================
   Typography Utilities
   ========================================================================== */

/* Responsive font sizes */
.text-responsive-sm {
  font-size: 0.875rem;      /* 14px */
}

@media (min-width: 1024px) {
  .text-responsive-sm {
    font-size: 0.9375rem;   /* 15px */
  }
}

.text-responsive-base {
  font-size: 0.9375rem;     /* 15px */
}

@media (min-width: 1024px) {
  .text-responsive-base {
    font-size: 1rem;        /* 16px */
  }
}

.text-responsive-lg {
  font-size: 1.125rem;      /* 18px */
}

@media (min-width: 1024px) {
  .text-responsive-lg {
    font-size: 1.25rem;     /* 20px */
  }
}

/* Heading sizes (mobile-first) */
.heading-1 {
  font-size: 1.875rem;      /* 30px mobile */
  font-weight: 700;
  line-height: 1.2;
  font-family: var(--font-display, inherit);
}

@media (min-width: 640px) {
  .heading-1 {
    font-size: 2.25rem;     /* 36px tablet */
  }
}

@media (min-width: 1024px) {
  .heading-1 {
    font-size: 3rem;        /* 48px desktop */
  }
}

.heading-2 {
  font-size: 1.5rem;        /* 24px mobile */
  font-weight: 700;
  line-height: 1.3;
  font-family: var(--font-display, inherit);
}

@media (min-width: 640px) {
  .heading-2 {
    font-size: 1.875rem;    /* 30px tablet */
  }
}

@media (min-width: 1024px) {
  .heading-2 {
    font-size: 2.25rem;     /* 36px desktop */
  }
}

.heading-3 {
  font-size: 1.25rem;       /* 20px mobile */
  font-weight: 600;
  line-height: 1.4;
  font-family: var(--font-display, inherit);
}

@media (min-width: 640px) {
  .heading-3 {
    font-size: 1.5rem;      /* 24px tablet */
  }
}

@media (min-width: 1024px) {
  .heading-3 {
    font-size: 1.875rem;    /* 30px desktop */
  }
}

/* Text truncation */
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.line-clamp-2 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.line-clamp-3 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

/* ==========================================================================
   Interactive Utilities
   ========================================================================== */

/* Touch-friendly interactive elements */
.touch-target {
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Remove tap highlight on mobile */
.no-tap-highlight {
  -webkit-tap-highlight-color: transparent;
}

/* Smooth scrolling */
.scroll-smooth {
  scroll-behavior: smooth;
}

/* Custom scrollbar (webkit) */
.scrollbar-custom {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.scrollbar-custom::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.scrollbar-custom::-webkit-scrollbar-track {
  background: transparent;
}

.scrollbar-custom::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

.scrollbar-custom::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Hide scrollbar but keep functionality */
.scrollbar-hide {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.scrollbar-hide::-webkit-scrollbar {
  display: none;
}

/* ==========================================================================
   Animation Utilities
   ========================================================================== */

/* Fade in */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.animate-fade-in {
  animation: fadeIn 0.3s ease-in;
}

/* Slide in from bottom */
@keyframes slideInBottom {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.animate-slide-in-bottom {
  animation: slideInBottom 0.4s ease-out;
}

/* Slide in from right */
@keyframes slideInRight {
  from {
    transform: translateX(20px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.animate-slide-in-right {
  animation: slideInRight 0.3s ease-out;
}

/* Scale up */
@keyframes scaleUp {
  from {
    transform: scale(0.95);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.animate-scale-up {
  animation: scaleUp 0.2s ease-out;
}

/* Spin (for loaders) */
@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.animate-spin {
  animation: spin 1s linear infinite;
}

/* Pulse */
@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.animate-pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* ==========================================================================
   Position Utilities
   ========================================================================== */

/* Sticky header */
.sticky-header {
  position: sticky;
  top: 0;
  z-index: 30;
}

/* Fixed bottom (for mobile actions) */
.fixed-bottom {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
}

/* Center absolute */
.center-absolute {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/* ==========================================================================
   Layout Utilities
   ========================================================================== */

/* Aspect ratio containers */
.aspect-square {
  aspect-ratio: 1 / 1;
}

.aspect-video {
  aspect-ratio: 16 / 9;
}

.aspect-4-3 {
  aspect-ratio: 4 / 3;
}

/* Object fit */
.object-cover {
  object-fit: cover;
}

.object-contain {
  object-fit: contain;
}

/* Full bleed (break out of container) */
.full-bleed {
  width: 100vw;
  margin-left: calc(50% - 50vw);
  margin-right: calc(50% - 50vw);
}

/* ==========================================================================
   Visual Effects
   ========================================================================== */

/* Glass effect */
.glass {
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Gradient text */
.text-gradient {
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Glow effect */
.glow-primary {
  box-shadow: 0 0 20px var(--glow-primary);
}

.glow-accent {
  box-shadow: 0 0 20px rgba(34, 197, 94, 0.3);
}

/* ==========================================================================
   Accessibility Utilities
   ========================================================================== */

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Focus visible (keyboard navigation) */
.focus-visible-ring:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Skip to content link */
.skip-link {
  position: absolute;
  top: -100px;
  left: 0;
  background: var(--color-primary);
  color: white;
  padding: 1rem 1.5rem;
  border-radius: 0 0 var(--radius-sm) 0;
  z-index: 100;
  transition: top 0.3s;
}

.skip-link:focus {
  top: 0;
}

/* ==========================================================================
   Print Utilities
   ========================================================================== */
@media print {
  .no-print {
    display: none !important;
  }
  
  .print-only {
    display: block !important;
  }
  
  /* Ensure proper page breaks */
  .page-break-before {
    page-break-before: always;
  }
  
  .page-break-after {
    page-break-after: always;
  }
  
  .page-break-avoid {
    page-break-inside: avoid;
  }
}

/* ==========================================================================
   Debug Utilities (Development Only - Remove in Production)
   ========================================================================== */

/* Visual grid overlay */
.debug-grid {
  background-image: 
    linear-gradient(rgba(255, 0, 0, 0.1) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 0, 0, 0.1) 1px, transparent 1px);
  background-size: 20px 20px;
}

/* Outline all elements */
.debug-outline * {
  outline: 1px solid rgba(255, 0, 0, 0.3);
}

/* Show current breakpoint */
body::before {
  content: 'Mobile (<640px)';
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  z-index: 9999;
  pointer-events: none;
  display: none; /* Enable for debugging: display: block; */
}

@media (min-width: 640px) {
  body::before {
    content: 'Tablet (≥640px)';
  }
}

@media (min-width: 768px) {
  body::before {
    content: 'Tablet-MD (≥768px)';
  }
}

@media (min-width: 1024px) {
  body::before {
    content: 'Desktop (≥1024px)';
  }
}

@media (min-width: 1280px) {
  body::before {
    content: 'Desktop-XL (≥1280px)';
  }
}

@media (min-width: 1536px) {
  body::before {
    content: 'Desktop-2XL (≥1536px)';
  }
}