/**
 * Unified Loading Animation Styles
 * Consistent loading experience across all analyzer pages
 * Modal overlay format
 */

/* Modal Overlay Background */
.analyzer-loading-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  z-index: 99999;
  justify-content: center;
  align-items: center;
  animation: fadeIn 0.3s ease-in;
}

.analyzer-loading-overlay.active {
  display: flex;
}

/* Loading Container - Now a modal card */
.analyzer-loading {
  display: none;
  background: linear-gradient(135deg, rgba(26, 35, 50, 0.98) 0%, rgba(18, 25, 35, 0.98) 100%);
  border: 2px solid rgba(var(--accent-primary-rgb), 0.3);
  border-radius: 16px;
  padding: 2rem;
  margin: 1.5rem auto;
  max-width: 700px;
  width: 90%;
  box-shadow: 0 8px 48px rgba(var(--accent-primary-rgb), 0.2), 0 0 100px rgba(var(--accent-primary-rgb), 0.1);
  backdrop-filter: blur(10px);
  position: relative;
}

/* When inside overlay, center it */
.analyzer-loading-overlay .analyzer-loading {
  margin: 0;
  animation: scaleIn 0.3s ease-out;
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes fadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

.analyzer-loading-overlay:not(.active) {
  animation: fadeOut 0.3s ease-out forwards;
}

.analyzer-loading.active {
  display: block;
  animation: fadeIn 0.3s ease-in;
}

/* Loading Header */
.loading-header {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.loading-brand {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 1em 0;
}

.loading-logo {
  display: block;
  height: 52px;
  width: auto;
  max-width: min(520px, 100%);
}

.loading-logo-light {
  display: none;
}

body.white-theme .loading-logo-dark {
  display: none;
}

body.white-theme .loading-logo-light {
  display: block;
}

.loading-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
}

.loading-url-row {
  margin: 0 0 0.85rem 0;
  text-align: left;
}

.loading-scan-url {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
  font-size: 0.85rem;
  line-height: 1.2;
  color: rgba(255, 255, 255, 0.75);
  padding: 0.2rem 0.5rem;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.15);
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

body.white-theme .loading-scan-url {
  color: rgba(0, 0, 0, 0.65);
  border-color: rgba(0, 0, 0, 0.12);
  background: rgba(255, 255, 255, 0.55);
}

/* StartedAt + Duration (always visible) */
.loading-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: space-between;
  margin: 0.75rem 0 1rem;
  padding: 0.75rem;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.02);
}

.loading-meta__item {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.75);
  line-height: 1.3;
}

/* Long scan indicator */
.loading-long-scan {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin-top: 0.75rem;
  padding: 0.75rem;
  border-radius: 10px;
  border: 1px solid rgba(var(--accent-primary-rgb), 0.25);
  background: rgba(var(--accent-primary-rgb), 0.05);
}

.loading-spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(var(--accent-primary-rgb), 0.25);
  border-top-color: var(--accent-primary);
  animation: spin 0.9s linear infinite;
  flex-shrink: 0;
  margin-top: 2px;
}

.loading-long-scan__title {
  font-weight: 700;
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.85rem;
  margin-bottom: 0.15rem;
}

.loading-long-scan__message {
  color: rgba(255, 255, 255, 0.75);
  font-size: 0.8rem;
  line-height: 1.35;
}

.loading-title {
  font-size: 1.1rem;
  color: var(--accent-primary);
  margin: 0;
  font-weight: 600;
  letter-spacing: 0.3px;
  flex: 1;
}

.loading-subtitle {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.6);
  margin: 0;
}

/* Progress Indicators */
.progress-steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin: 1rem 0;
}

.progress-step {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.625rem 0.75rem;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  min-height: 60px;
}

.progress-step::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: transparent;
  transition: background 0.3s ease;
}

.progress-step.pending {
  opacity: 0.4;
}

.progress-step.pending::before {
  background: rgba(255, 255, 255, 0.15);
}

.progress-step.active {
  background: rgba(var(--accent-primary-rgb), 0.04);
  border-color: rgba(var(--accent-primary-rgb), 0.3);
  opacity: 1;
  box-shadow: 0 0 20px rgba(var(--accent-primary-rgb), 0.1);
}

.progress-step.active::before {
  background: var(--accent-primary);
  box-shadow: 0 0 10px rgba(var(--accent-primary-rgb), 0.5);
}

.progress-step.complete {
  opacity: 0.8;
}

.progress-step.complete::before {
  background: var(--accent-primary);
}

.progress-step.error::before {
  background: #ff4444;
}

/* Step Icon */
.step-icon {
  font-size: 1.2rem;
  min-width: 24px;
  text-align: center;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.progress-step.pending .step-icon::before {
  content: '◯';
  color: rgba(255, 255, 255, 0.25);
  font-weight: 300;
}

.progress-step.active .step-icon::before {
  content: '◉';
  color: var(--accent-primary);
  font-weight: 400;
}

.progress-step.complete .step-icon::before {
  content: '✓';
  color: var(--accent-primary);
  font-weight: 600;
}

.progress-step.error .step-icon::before {
  content: '✗';
  color: #ff4444;
  font-weight: 600;
}

/* Step Text */
.step-text {
  flex: 1;
  min-width: 0;
}

.step-label {
  font-size: 0.75rem;
  color: var(--text-primary);
  font-weight: 500;
  margin: 0 0 0.25rem 0;
  line-height: 1.3;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: normal;
}

.step-detail {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin: 0;
  line-height: 1.3;
  opacity: 0.7;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: normal;
}

.progress-step.active .step-label {
  color: var(--accent-primary);
}

.progress-step.active .step-detail {
  color: rgba(var(--accent-primary-rgb), 0.8);
  opacity: 1;
}

/* Spinner Animation - DISABLED */
.analyzer-spinner {
  width: 60px;
  height: 60px;
  margin: 2rem auto;
  border: 4px solid rgba(var(--accent-primary-rgb), 0.1);
  border-top: 4px solid var(--accent-primary);
  border-radius: 50%;
}

/* Progress Bar */
.loading-progress-bar {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 2px;
  overflow: hidden;
  margin: 0;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-primary-dark));
  border-radius: 2px;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 8px rgba(var(--accent-primary-rgb), 0.4);
}

/* Estimated Time */
.estimated-time {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.time-label {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.5);
  margin: 0;
  font-weight: 500;
}

.time-value {
  font-size: 0.9rem;
  color: var(--accent-primary);
  font-weight: 600;
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.time-label.overrun {
  color: #ffd166;
}

.time-value.overrun {
  color: #ffd166;
}

/* Loading Messages */
.loading-messages {
  text-align: center;
  margin: 1.5rem 0;
}

.loading-message {
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.8);
  margin: 0.5rem 0;
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.15);
    opacity: 0.8;
  }
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

@keyframes fadeInOut {
  0%, 100% {
    opacity: 0.5;
  }
  50% {
    opacity: 1;
  }
}

@keyframes etaPulse {
  0%, 100% {
    opacity: 0.8;
  }
  50% {
    opacity: 1;
  }
}

/* Dots Animation - DISABLED */
.dots::after {
  content: '...';
}

@keyframes dots {
  0%, 20% {
    content: '';
  }
  40% {
    content: '.';
  }
  60% {
    content: '..';
  }
  80%, 100% {
    content: '...';
  }
}

/* Responsive */
@media (max-width: 768px) {
  .analyzer-loading {
    padding: 1.25rem;
    margin: 1rem;
  }
  
  .loading-title {
    font-size: 1rem;
  }
  
  .progress-steps {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }
  
  .progress-step {
    padding: 0.6rem;
  }
  
  .step-label {
    font-size: 0.8rem;
  }
  
  .step-detail {
    font-size: 0.7rem;
  }
  
  .step-icon {
    font-size: 1rem;
    min-width: 20px;
  }
}

/* ========================================
   LIGHT THEME OVERRIDES
   ======================================== */

/* Light frosted overlay to match light-mode page background */
body.white-theme .analyzer-loading-overlay {
  background: rgba(245, 245, 248, 0.88);
  backdrop-filter: blur(6px);
}

/* White modal card with subtle shadow */
body.white-theme .analyzer-loading {
  background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
  border: 1px solid rgba(0, 0, 0, 0.10);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.06);
}

/* Header */
body.white-theme .loading-header {
  border-bottom-color: rgba(0, 0, 0, 0.08);
}

body.white-theme .loading-title {
  color: var(--accent-primary);
}

body.white-theme .loading-subtitle {
  color: #555;
}

/* URL pill */
body.white-theme .loading-scan-url {
  color: rgba(0, 0, 0, 0.65);
  border-color: rgba(0, 0, 0, 0.12);
  background: rgba(0, 0, 0, 0.04);
}

/* Meta row (Started / Duration) */
body.white-theme .loading-meta {
  border-color: rgba(0, 0, 0, 0.08);
  background: rgba(0, 0, 0, 0.02);
}

body.white-theme .loading-meta__item {
  color: #444;
}

/* Progress steps */
body.white-theme .progress-step {
  background: rgba(0, 0, 0, 0.02);
  border-color: rgba(0, 0, 0, 0.08);
}

body.white-theme .progress-step.pending::before {
  background: rgba(0, 0, 0, 0.10);
}

body.white-theme .progress-step.active {
  background: rgba(var(--accent-primary-rgb), 0.06);
  border-color: rgba(var(--accent-primary-rgb), 0.35);
  box-shadow: 0 0 16px rgba(var(--accent-primary-rgb), 0.10);
}

body.white-theme .progress-step.active::before {
  background: var(--accent-primary);
  box-shadow: 0 0 8px rgba(var(--accent-primary-rgb), 0.4);
}

body.white-theme .progress-step.complete::before {
  background: var(--accent-primary);
}

body.white-theme .step-label {
  color: #1a1a1a;
}

body.white-theme .step-detail {
  color: #666;
}

body.white-theme .progress-step.active .step-label {
  color: var(--accent-primary);
}

body.white-theme .progress-step.active .step-detail {
  color: rgba(var(--accent-primary-rgb), 0.85);
}

body.white-theme .progress-step.pending .step-icon::before {
  color: rgba(0, 0, 0, 0.20);
  font-weight: 300;
}

body.white-theme .progress-step.active .step-icon::before {
  color: var(--accent-primary);
  font-weight: 500;
}

body.white-theme .progress-step.complete .step-icon::before {
  color: var(--accent-primary);
  font-weight: 600;
}

/* Progress bar */
body.white-theme .loading-progress-bar {
  background: rgba(0, 0, 0, 0.08);
}

body.white-theme .progress-bar-fill {
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-primary-dark));
  box-shadow: 0 0 8px rgba(var(--accent-primary-rgb), 0.4);
}

/* Long scan indicator */
body.white-theme .loading-long-scan {
  border-color: rgba(var(--accent-primary-rgb), 0.20);
  background: rgba(var(--accent-primary-rgb), 0.04);
}

body.white-theme .loading-long-scan__title {
  color: #1a1a1a;
}

body.white-theme .loading-long-scan__message {
  color: #555;
}

body.white-theme .loading-spinner {
  border-color: rgba(var(--accent-primary-rgb), 0.20);
  border-top-color: var(--accent-primary);
}

/* Estimated time */
body.white-theme .estimated-time {
  border-top-color: rgba(0, 0, 0, 0.08);
}

body.white-theme .time-label {
  color: #666;
}

body.white-theme .time-value {
  color: var(--accent-primary);
}

body.white-theme .time-label.overrun {
  color: #c2410c;
}

body.white-theme .time-value.overrun {
  color: #c2410c;
}

body.white-theme #progressPercentage {
  color: var(--accent-primary) !important;
}

/* Loading messages */
body.white-theme .loading-message {
  color: #333;
}
