/* ============================================
   APP LOADER - Professional Loading States
   ============================================ */

/* CRITICAL: If loader was already shown this session, hide it INSTANTLY (no flash).
   This class is set by an inline script BEFORE the loader element renders. */
html.loader-already-shown #initial-loader {
  display: none !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

/* Base loader styles */
.app-loader {
  position: fixed;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bs-body-bg, #ffffff);
  z-index: 9999;
  opacity: 1;
  transition: opacity 0.3s ease-out;
  pointer-events: all;
}

/* Initial loader - full screen */
.app-loader-initial {
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100vh;
  z-index: 9999;
}

/* Navigation loader - content area only (right side) */
.app-loader-navigation {
  top: 0;
  left: 280px; /* Sidebar width */
  right: 0;
  bottom: 0;
}

/* Navigation loader starts hidden */
.app-loader-navigation.hidden {
  opacity: 0;
  pointer-events: none;
}

/* When sidebar is collapsed */
body.sidebar-collapsed .app-loader-navigation {
  left: 80px;
}

/* Mobile - no sidebar offset */
@media (max-width: 991px) {
  .app-loader-navigation {
    left: 0;
  }
}

/* Webview mode - no sidebar */
body.webview-mode .app-loader-navigation {
  left: 0;
}

/* Hidden state */
.app-loader.hidden {
  opacity: 0;
  pointer-events: none;
}

/* Loader content container */
.app-loader-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  max-width: 400px;
  padding: 2rem;
}

/* Logo */
.app-loader-logo {
  width: 80px;
  height: 80px;
  filter: drop-shadow(0 4px 12px rgba(0, 212, 170, 0.4));
  animation: pulse-logo 2s ease-in-out infinite;
}

@keyframes pulse-logo {
  0%, 100% {
    transform: scale(1);
    filter: drop-shadow(0 4px 12px rgba(0, 212, 170, 0.4));
  }
  50% {
    transform: scale(1.05);
    filter: drop-shadow(0 6px 16px rgba(0, 212, 170, 0.6));
  }
}

/* App brand name */
.app-loader-brand {
  font-size: 1.75rem;
  font-weight: 700;
  text-transform: capitalize;
  color: var(--text-primary, #ffffff);
  letter-spacing: 0.1em;
  margin-top: 0.5rem;
}

[data-theme="dark"] .app-loader-brand {
  color: var(--text-primary, #ffffff);
}

[data-theme="light"] .app-loader-brand {
  color: var(--text-primary, #1e293b);
}

/* Progress bar container */
.app-loader-progress-container {
  width: 100%;
  max-width: 300px;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 1rem;
}

[data-theme="light"] .app-loader-progress-container {
  background: rgba(0, 0, 0, 0.1);
}

/* Progress bar */
.app-loader-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-primary, #00d4aa) 0%, var(--accent-secondary, #00a8ff) 100%);
  border-radius: 2px;
  width: 0%;
  transition: width 0.3s ease;
  box-shadow: 0 0 10px rgba(0, 212, 170, 0.5);
}

/* Status text */
.app-loader-status {
  font-size: 0.875rem;
  color: var(--text-secondary, #94a3b8);
  margin-top: 0.5rem;
  text-align: center;
}

[data-theme="light"] .app-loader-status {
  color: var(--text-muted, #64748b);
}

/* Spinner container */
.app-loader-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

/* Spinner size */
.app-loader .spinner-border {
  width: 3rem;
  height: 3rem;
  border-width: 0.3rem;
}

/* Dark mode support */
[data-theme="dark"] .app-loader {
  background: var(--bs-dark, #1a1a1a);
}

/* Smooth fade-in for content */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.app-content-fade-in {
  animation: fadeIn 0.3s ease-in;
}

/* Hide scrollbar and prevent scrolling while initial loader is visible */
#initial-loader.app-loader-initial {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 99999;
}

/* When loader is visible, HIDE main scrollbar but ALLOW SCROLLING */
html:has(body[data-initial-load="true"]),
body[data-initial-load="true"] {
  scrollbar-width: none !important; /* Firefox - hide main scrollbar */
  -ms-overflow-style: none !important; /* IE/Edge - hide main scrollbar */
}

html:has(body[data-initial-load="true"])::-webkit-scrollbar,
body[data-initial-load="true"]::-webkit-scrollbar {
  display: none !important; /* Chrome/Safari - hide main scrollbar */
}

/* Hide elements while initial loader exists in DOM */
#initial-loader ~ .chatbot-widget-container {
  display: none !important;
}

