/* =============================================================================
   AI GENERATION LOADER - CREATIVE ANIMATIONS
   ============================================================================= */

/* Main Loader Container */
.ai-loader-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.ai-loader-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* Loader Content Box */
.ai-loader-content {
  text-align: center;
  max-width: 400px;
  padding: 2rem;
  animation: loaderFadeIn 0.5s ease-out;
}

@keyframes loaderFadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Creative Loader Animation */
.ai-creative-loader {
  width: 120px;
  height: 120px;
  margin: 0 auto 2rem;
  position: relative;
}

/* Neural Network Animation */
.neural-network {
  width: 100%;
  height: 100%;
  position: relative;
}

.neural-node {
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--brand-color-dark);
  border-radius: 50%;
  box-shadow: 0 0 20px var(--brand-color-dark);
}

body.light-mode .neural-node {
  background: var(--brand-color-light);
  box-shadow: 0 0 20px var(--brand-color-light);
}

.neural-node:nth-child(1) { top: 0; left: 50%; transform: translateX(-50%); }
.neural-node:nth-child(2) { top: 25%; right: 0; }
.neural-node:nth-child(3) { bottom: 0; right: 25%; }
.neural-node:nth-child(4) { bottom: 0; left: 25%; }
.neural-node:nth-child(5) { top: 25%; left: 0; }
.neural-node:nth-child(6) { top: 50%; left: 50%; transform: translate(-50%, -50%); }

.neural-connection {
  position: absolute;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--brand-color-dark), transparent);
  transform-origin: left center;
  animation: pulseConnection 2s ease-in-out infinite;
}

body.light-mode .neural-connection {
  background: linear-gradient(90deg, transparent, var(--brand-color-light), transparent);
}

@keyframes pulseConnection {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

/* Rotating Brain Animation */
.ai-brain {
  width: 100px;
  height: 100px;
  margin: 0 auto;
  position: relative;
  animation: rotateBrain 4s linear infinite;
}

@keyframes rotateBrain {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.brain-hemisphere {
  position: absolute;
  width: 50%;
  height: 100%;
  background: var(--brand-color-dark);
  opacity: 0.8;
}

body.light-mode .brain-hemisphere {
  background: var(--brand-color-light);
}

.brain-left {
  left: 0;
  border-radius: 100% 0 0 100%;
  animation: brainPulseLeft 2s ease-in-out infinite;
}

.brain-right {
  right: 0;
  border-radius: 0 100% 100% 0;
  animation: brainPulseRight 2s ease-in-out infinite;
}

@keyframes brainPulseLeft {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1) translateX(-5px); }
}

@keyframes brainPulseRight {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1) translateX(5px); }
}

/* Magic Sparkles Animation */
.magic-sparkles {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
}

.sparkle {
  position: absolute;
  width: 4px;
  height: 4px;
  background: white;
  border-radius: 50%;
  animation: sparkleFloat 3s linear infinite;
}

@keyframes sparkleFloat {
  0% {
    transform: translateY(0) scale(0);
    opacity: 0;
  }
  10% {
    transform: translateY(-10px) scale(1);
    opacity: 1;
  }
  90% {
    transform: translateY(-90px) scale(1);
    opacity: 1;
  }
  100% {
    transform: translateY(-100px) scale(0);
    opacity: 0;
  }
}

.sparkle:nth-child(1) { left: 20%; animation-delay: 0s; }
.sparkle:nth-child(2) { left: 40%; animation-delay: 0.5s; }
.sparkle:nth-child(3) { left: 60%; animation-delay: 1s; }
.sparkle:nth-child(4) { left: 80%; animation-delay: 1.5s; }
.sparkle:nth-child(5) { left: 30%; animation-delay: 2s; }
.sparkle:nth-child(6) { left: 70%; animation-delay: 2.5s; }

/* Dynamic Loading Messages */
.ai-loader-message {
  color: white;
  font-size: 1.2rem;
  font-weight: 500;
  margin-bottom: 1rem;
  min-height: 30px;
  animation: messageChange 0.5s ease-out;
}

body.light-mode .ai-loader-message {
  color: white; /* Keep white in overlay */
}

@keyframes messageChange {
  0% {
    opacity: 0;
    transform: translateY(-10px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

.ai-loader-submessage {
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

/* Progress Bar */
.ai-progress-bar {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 2rem;
}

.ai-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--brand-color-dark), var(--brand-color-light));
  border-radius: 2px;
  width: 0%;
  animation: progressAnimation 20s ease-out forwards;
}

body.light-mode .ai-progress-fill {
  background: linear-gradient(90deg, var(--brand-color-light), var(--brand-color-dark));
}

@keyframes progressAnimation {
  0% { width: 0%; }
  10% { width: 15%; }
  30% { width: 35%; }
  50% { width: 55%; }
  70% { width: 75%; }
  90% { width: 90%; }
  100% { width: 95%; }
}

/* Platform-specific loaders */
.loader-instagram .neural-node,
.loader-instagram .ai-progress-fill {
  background: linear-gradient(45deg, #f09433, #e6683c, #dc2743, #cc2366, #bc1888);
}

.loader-facebook .neural-node,
.loader-facebook .ai-progress-fill {
  background: #1877f2;
}

.loader-linkedin .neural-node,
.loader-linkedin .ai-progress-fill {
  background: #0a66c2;
}

.loader-x .neural-node,
.loader-x .ai-progress-fill {
  background: #000;
  box-shadow: 0 0 20px #ff0050;
}

/* Typing Animation for Messages */
.typing-dots {
  display: inline-flex;
  align-items: center;
  margin-left: 5px;
}

.typing-dot {
  width: 8px;
  height: 8px;
  margin: 0 2px;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  animation: typingAnimation 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingAnimation {
  0%, 80%, 100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  40% {
    transform: scale(1.2);
    opacity: 1;
  }
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
  .ai-loader-content {
    padding: 1.5rem;
    max-width: 90%;
  }

  .ai-creative-loader {
    width: 80px;
    height: 80px;
  }

  .ai-loader-message {
    font-size: 1rem;
  }

  .ai-loader-submessage {
    font-size: 0.8rem;
  }
}

/* =============================================================================
   ASYNC JOB OVERLAY - In-page job status overlay
   ============================================================================= */

.async-job-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  padding: 1rem;
}

.async-job-overlay.active {
  opacity: 1;
  visibility: visible;
}

.overlay-card {
  background: var(--card-bg-dark, #2a2a2a);
  border-radius: 20px;
  padding: 40px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.1);
  min-width: 360px;
  max-width: 520px;
  width: 100%;
}

body.light-mode .overlay-card {
  background: var(--card-bg-light, #ffffff);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.overlay-title {
  color: var(--text-dark, #ffffff);
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 24px;
  text-align: center;
}

body.light-mode .overlay-title {
  color: var(--text-light, #212529);
}

.async-job-overlay .platform-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.async-job-overlay .platform-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition: all 0.3s ease;
}

body.light-mode .async-job-overlay .platform-item {
  background: rgba(0, 0, 0, 0.02);
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.async-job-overlay .platform-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: white;
  flex-shrink: 0;
}

.async-job-overlay .platform-name {
  color: var(--text-dark, #ffffff);
  font-size: 16px;
  font-weight: 500;
  flex: 1;
}

body.light-mode .async-job-overlay .platform-name {
  color: var(--text-light, #212529);
}

.async-job-overlay .platform-status {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
}

.async-job-overlay .loading-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}

.async-job-overlay .loading-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.6);
  animation: asyncLoadingDots 1.4s infinite ease-in-out both;
}

body.light-mode .async-job-overlay .loading-dots span {
  background: rgba(0, 0, 0, 0.6);
}

.async-job-overlay .loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.async-job-overlay .loading-dots span:nth-child(2) { animation-delay: -0.16s; }
.async-job-overlay .loading-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes asyncLoadingDots {
  0%, 80%, 100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  40% {
    transform: scale(1.2);
    opacity: 1;
  }
}

.async-job-overlay .gen-progress {
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 9999px;
  overflow: hidden;
  margin-top: 8px;
}

.async-job-overlay .gen-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--brand-color-dark, #bb86fc), #7c4dff);
  transition: width 0.4s ease;
  border-radius: 9999px;
}

body.light-mode .async-job-overlay .gen-progress {
  background: rgba(0, 0, 0, 0.08);
}

body.light-mode .async-job-overlay .gen-progress-bar {
  background: linear-gradient(90deg, var(--brand-color-light, #E1306C), #ff6b9a);
}

.overlay-message {
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
  text-align: center;
  line-height: 1.5;
  margin: 16px 0 0;
}

body.light-mode .overlay-message {
  color: rgba(0, 0, 0, 0.6);
}

.overlay-error {
  margin-top: 16px;
  text-align: center;
}

.btn-cancel-overlay {
  display: block;
  width: 100%;
  margin-top: 20px;
  padding: 12px 20px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.7);
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

body.light-mode .btn-cancel-overlay {
  border-color: rgba(0, 0, 0, 0.15);
  color: rgba(0, 0, 0, 0.6);
}

.btn-cancel-overlay:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

body.light-mode .btn-cancel-overlay:hover {
  background: rgba(0, 0, 0, 0.05);
  color: rgba(0, 0, 0, 0.8);
}

/* X logo icon for async overlay */
.async-job-overlay .x-logo-icon {
  display: inline-block;
  width: 18px;
  height: 18px;
}

.async-job-overlay .x-logo-icon::before {
  content: "";
  display: inline-block;
  width: 100%;
  height: 100%;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill='white' d='M14.258 10.152L23.176 0h-2.113l-7.747 8.813L7.133 0H0l9.352 13.328L0 23.973h2.113l8.176-9.309 6.531 9.309h7.133zm-2.895 3.293l-.949-1.328L2.875 1.56h3.246l6.086 8.523.945 1.328 7.91 11.078h-3.246zm0 0'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}

/* Responsive */
@media (max-width: 576px) {
  .overlay-card {
    min-width: 100%;
    padding: 28px;
  }

  .overlay-title {
    font-size: 20px;
  }

  .async-job-overlay .platform-item {
    padding: 12px;
  }

  .async-job-overlay .platform-icon {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }
}