/* ==========================================================================
   FUNKY SPINNER COMPONENT
   Versatile loading spinners with multiple styles
   ========================================================================== */

/* --------------------------------------------------------------------------
   CSS CUSTOM PROPERTIES
   -------------------------------------------------------------------------- */

:root {
  --spinner-color: var(--pro-primary, #0d6efd);
  --spinner-size: 2rem;
  --spinner-border-width: 0.2em;
  --spinner-duration: 0.75s;
  --spinner-overlay-bg: rgba(255, 255, 255, 0.8);
}

[data-theme="dark"] {
  --spinner-overlay-bg: rgba(0, 0, 0, 0.7);
}

/* --------------------------------------------------------------------------
   BASE SPINNER
   -------------------------------------------------------------------------- */

.funky-spinner {
  display: inline-block;
  width: var(--spinner-size);
  height: var(--spinner-size);
  vertical-align: middle;
}

/* Screen reader text */
.funky-spinner-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --------------------------------------------------------------------------
   SPINNER STYLE: BORDER (default)
   -------------------------------------------------------------------------- */

.funky-spinner-border {
  border: var(--spinner-border-width) solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: funky-spinner-rotate var(--spinner-duration) linear infinite;
  color: var(--spinner-color);
}

@keyframes funky-spinner-rotate {
  to {
    transform: rotate(360deg);
  }
}

/* --------------------------------------------------------------------------
   SPINNER STYLE: GROW
   -------------------------------------------------------------------------- */

.funky-spinner-grow {
  background-color: var(--spinner-color);
  border-radius: 50%;
  animation: funky-spinner-grow var(--spinner-duration) ease-in-out infinite;
  opacity: 0;
}

@keyframes funky-spinner-grow {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 0;
  }
}

/* --------------------------------------------------------------------------
   SPINNER STYLE: DOTS
   -------------------------------------------------------------------------- */

.funky-spinner-dots {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25em;
  width: auto;
  height: var(--spinner-size);
}

.funky-spinner-dots .dot {
  width: calc(var(--spinner-size) * 0.25);
  height: calc(var(--spinner-size) * 0.25);
  background-color: var(--spinner-color);
  border-radius: 50%;
  animation: funky-spinner-bounce 1.4s ease-in-out infinite both;
}

.funky-spinner-dots .dot:nth-child(1) {
  animation-delay: -0.32s;
}

.funky-spinner-dots .dot:nth-child(2) {
  animation-delay: -0.16s;
}

.funky-spinner-dots .dot:nth-child(3) {
  animation-delay: 0s;
}

@keyframes funky-spinner-bounce {
  0%, 80%, 100% {
    transform: scale(0.6);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* --------------------------------------------------------------------------
   SPINNER STYLE: PULSE
   -------------------------------------------------------------------------- */

.funky-spinner-pulse {
  position: relative;
}

.funky-spinner-pulse::before,
.funky-spinner-pulse::after {
  content: '';
  position: absolute;
  inset: 0;
  border: 2px solid var(--spinner-color);
  border-radius: 50%;
  animation: funky-spinner-pulse 1.5s ease-out infinite;
}

.funky-spinner-pulse::after {
  animation-delay: 0.5s;
}

@keyframes funky-spinner-pulse {
  0% {
    transform: scale(0.5);
    opacity: 1;
  }
  100% {
    transform: scale(1.2);
    opacity: 0;
  }
}

/* --------------------------------------------------------------------------
   SPINNER STYLE: RING
   -------------------------------------------------------------------------- */

.funky-spinner-ring {
  border-radius: 50%;
  background: conic-gradient(
    from 0deg,
    transparent 0deg 90deg,
    var(--spinner-color) 90deg 180deg,
    transparent 180deg 270deg,
    var(--spinner-color) 270deg 360deg
  );
  animation: funky-spinner-rotate 1s linear infinite;
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - var(--spinner-border-width)), #000 calc(100% - var(--spinner-border-width)));
  mask: radial-gradient(farthest-side, transparent calc(100% - var(--spinner-border-width)), #000 calc(100% - var(--spinner-border-width)));
}

/* --------------------------------------------------------------------------
   SIZES
   -------------------------------------------------------------------------- */

.funky-spinner-xs {
  --spinner-size: 1rem;
  --spinner-border-width: 0.15em;
}

.funky-spinner-sm {
  --spinner-size: 1.5rem;
  --spinner-border-width: 0.15em;
}

.funky-spinner-md {
  --spinner-size: 2rem;
  --spinner-border-width: 0.2em;
}

.funky-spinner-lg {
  --spinner-size: 3rem;
  --spinner-border-width: 0.25em;
}

.funky-spinner-xl {
  --spinner-size: 4rem;
  --spinner-border-width: 0.3em;
}

/* --------------------------------------------------------------------------
   COLOR VARIANTS
   -------------------------------------------------------------------------- */

.funky-spinner-primary { --spinner-color: var(--pro-primary, #0d6efd); }
.funky-spinner-secondary { --spinner-color: var(--pro-secondary, #6c757d); }
.funky-spinner-success { --spinner-color: var(--pro-success, #198754); }
.funky-spinner-warning { --spinner-color: var(--pro-warning, #ffc107); }
.funky-spinner-danger { --spinner-color: var(--pro-danger, #dc3545); }
.funky-spinner-info { --spinner-color: var(--pro-info, #0dcaf0); }
.funky-spinner-light { --spinner-color: var(--pro-light, #f8f9fa); }
.funky-spinner-dark { --spinner-color: var(--pro-dark, #212529); }

/* --------------------------------------------------------------------------
   CONTAINER SPINNER
   -------------------------------------------------------------------------- */

.funky-spinner-container {
  position: relative;
  min-height: 100px;
}

.funky-spinner-container.loading {
  pointer-events: none;
}

.funky-spinner-container .funky-spinner-wrapper {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: var(--spinner-overlay-bg);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  z-index: 10;
}

.funky-spinner-container.loading .funky-spinner-wrapper {
  opacity: 1;
  visibility: visible;
}

.funky-spinner-text {
  color: var(--pro-text-secondary, #6c757d);
  font-size: 0.875rem;
}

/* --------------------------------------------------------------------------
   OVERLAY SPINNER (Full-page)
   -------------------------------------------------------------------------- */

.funky-spinner-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: var(--spinner-overlay-bg);
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.funky-spinner-overlay.show {
  opacity: 1;
  visibility: visible;
}

.funky-spinner-overlay .funky-spinner-text {
  font-size: 1rem;
}

/* --------------------------------------------------------------------------
   INLINE SPINNER (next to text/buttons)
   -------------------------------------------------------------------------- */

.funky-spinner-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

/* Button spinner */
.btn .funky-spinner {
  --spinner-size: 1em;
  --spinner-border-width: 0.15em;
  margin-right: 0.5em;
}

/* --------------------------------------------------------------------------
   ACCESSIBILITY - REDUCED MOTION
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .funky-spinner-border,
  .funky-spinner-grow,
  .funky-spinner-ring,
  .funky-spinner-dots .dot,
  .funky-spinner-pulse::before,
  .funky-spinner-pulse::after {
    animation-duration: 1.5s;
  }
}

/* --------------------------------------------------------------------------
   HIGH CONTRAST MODE
   -------------------------------------------------------------------------- */

@media (prefers-contrast: high) {
  .funky-spinner-border {
    border-width: 0.3em;
  }

  .funky-spinner-pulse::before,
  .funky-spinner-pulse::after {
    border-width: 3px;
  }

  .funky-spinner-container .funky-spinner-wrapper,
  .funky-spinner-overlay {
    background: var(--pro-bg-primary, #000);
  }

  .funky-spinner-text {
    font-weight: 600;
  }
}

/* --------------------------------------------------------------------------
   SPINNER DEMO STYLES
   Playground demo-specific styling
   -------------------------------------------------------------------------- */

.spinner-demo__grid {
  display: flex;
  gap: 2rem;
  align-items: center;
  flex-wrap: wrap;
}

.spinner-demo__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  min-width: 60px;
}

.spinner-demo__button-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.spinner-demo__container {
  position: relative;
  min-height: 120px;
  padding: 1rem;
  background: var(--pro-bg-tertiary);
  border: 1px solid var(--pro-border);
  border-radius: 4px;
}

.spinner-demo__log {
  background: var(--pro-bg-tertiary);
  color: var(--pro-text-muted);
  padding: 1rem;
  border-radius: 4px;
  max-height: 200px;
  overflow: auto;
  font-size: 0.875rem;
  line-height: 1.5;
  margin: 0;
  border: 1px solid var(--pro-border);
}

/* Responsive adjustments */
@media (max-width: 576px) {
  .spinner-demo__grid {
    gap: 1rem;
    justify-content: center;
  }

  .spinner-demo__button-grid {
    flex-direction: column;
  }

  .spinner-demo__button-grid .btn {
    width: 100%;
  }
}

/* ============================================
   BOOTSTRAP SPINNER THEME OVERRIDES
   Using --pro-* variables for theme consistency
   ============================================ */

.spinner-border,
.spinner-grow {
  color: var(--pro-primary);
}
